Provide information for linking Sponsors and partners in project detail view

refs #3139, #3136


git-svn-id: https://svn.libreccm.org/ccm/trunk@5880 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2019-03-25 17:29:47 +00:00
parent 10c0dc99ce
commit 2fcae22fe7
2 changed files with 132 additions and 61 deletions

View File

@ -190,6 +190,9 @@
<xsl:with-param name="funding-code" <xsl:with-param name="funding-code"
tunnel="yes" tunnel="yes"
select="./@fundingCode"/> select="./@fundingCode"/>
<xsl:with-param name="sponsor-link"
tunnel="yes"
select="./@href" />
</xsl:apply-templates> </xsl:apply-templates>
</xsl:for-each> </xsl:for-each>
</xsl:template> </xsl:template>
@ -202,9 +205,21 @@
</foundry:doc-desc> </foundry:doc-desc>
</foundry:doc> </foundry:doc>
<xsl:template match="content-item-layout//*[starts-with(name(), 'orgaunit')]//sponsors//sponsor//sponsor-name"> <xsl:template match="content-item-layout//*[starts-with(name(), 'orgaunit')]//sponsors//sponsor//sponsor-name">
<xsl:param name="sponsor-name" tunnel="yes"/>
<xsl:param name="sponsor-name" tunnel="yes" />
<xsl:param name="sponsor-link" tunnel="yes" />
<xsl:choose>
<xsl:when test="$sponsor-link">
<a href="{$sponsor-link}">
<xsl:value-of select="$sponsor-name"/> <xsl:value-of select="$sponsor-name"/>
</a>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$sponsor-name"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template> </xsl:template>
<foundry:doc section="user" type="template-tag"> <foundry:doc section="user" type="template-tag">
@ -218,6 +233,7 @@
<xsl:param name="funding-code" tunnel="yes"/> <xsl:param name="funding-code" tunnel="yes"/>
<xsl:value-of select="$funding-code"/> <xsl:value-of select="$funding-code"/>
</xsl:template> </xsl:template>
<foundry:doc section="user" type="template-tag"> <foundry:doc section="user" type="template-tag">
@ -475,14 +491,27 @@
<xsl:for-each select="$orgaunit-data/involvedOrganizations/organization"> <xsl:for-each select="$orgaunit-data/involvedOrganizations/organization">
<xsl:apply-templates select="$layout-tree"> <xsl:apply-templates select="$layout-tree">
<xsl:with-param name="involved-organization-name" select="./title" tunnel="yes" /> <xsl:with-param name="involved-organization-name" select="./title" tunnel="yes" />
<xsl:with-param name="involved-organization-link" select="./links[1]/targetURI" tunnel="yes" />
</xsl:apply-templates> </xsl:apply-templates>
</xsl:for-each> </xsl:for-each>
</xsl:template> </xsl:template>
<xsl:template match="content-item-layout//*[starts-with(name(), 'orgaunit')]//involved-organizations//involved-organization//involved-organization-name"> <xsl:template match="content-item-layout//*[starts-with(name(), 'orgaunit')]//involved-organizations//involved-organization//involved-organization-name">
<xsl:param name="involved-organization-name" tunnel="yes" />
<xsl:param name="involved-organization-name" tunnel="yes" />
<xsl:param name="involved-organization-link" tunnel="yes" />
<xsl:choose>
<xsl:when test="$involved-organization-link">
<a href="{$involved-organization-link}">
<xsl:value-of select="$involved-organization-name" /> <xsl:value-of select="$involved-organization-name" />
</a>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$involved-organization-name" />
</xsl:otherwise>
</xsl:choose>
</xsl:template> </xsl:template>
</xsl:stylesheet> </xsl:stylesheet>

View File

@ -14,14 +14,22 @@ import com.arsdigita.cms.contenttypes.SciProject;
import com.arsdigita.cms.contenttypes.SciProjectSponsorCollection; import com.arsdigita.cms.contenttypes.SciProjectSponsorCollection;
import com.arsdigita.cms.dispatcher.SimpleXMLGenerator; import com.arsdigita.cms.dispatcher.SimpleXMLGenerator;
import com.arsdigita.globalization.GlobalizationHelper; import com.arsdigita.globalization.GlobalizationHelper;
import com.arsdigita.persistence.DataCollection;
import com.arsdigita.persistence.DataObject;
import com.arsdigita.persistence.Session;
import com.arsdigita.persistence.SessionManager;
import com.arsdigita.xml.Element; import com.arsdigita.xml.Element;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.Locale; import java.util.Locale;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import java.util.Optional;
/** /**
* Summary tab for projects, displays lifespan of the project, the short * Summary tab for projects, displays lifespan of the project, the short
* description, the project team (aka members), a contact, the involved * description, the project team (aka members), a contact, the involved
@ -33,8 +41,8 @@ import org.apache.log4j.Logger;
public class SciProjectSummaryTab implements GenericOrgaUnitTab { public class SciProjectSummaryTab implements GenericOrgaUnitTab {
private final Logger logger = Logger.getLogger(SciProjectSummaryTab.class); private final Logger logger = Logger.getLogger(SciProjectSummaryTab.class);
private final static SciProjectSummaryTabConfig config = private final static SciProjectSummaryTabConfig config
new SciProjectSummaryTabConfig(); = new SciProjectSummaryTabConfig();
private String key; private String key;
static { static {
@ -250,7 +258,6 @@ public class SciProjectSummaryTab implements GenericOrgaUnitTab {
* membersElem, members.getRoleName(), state); } * membersElem, members.getRoleName(), state); }
} }
*/ */
logger.debug(String.format("Generated members XML for project '%s'" logger.debug(String.format("Generated members XML for project '%s'"
+ "in '%d ms'. MergeMembers is set to '%b'.", + "in '%d ms'. MergeMembers is set to '%b'.",
project.getName(), project.getName(),
@ -320,7 +327,8 @@ public class SciProjectSummaryTab implements GenericOrgaUnitTab {
final PageState state) { final PageState state) {
if (contact == null) { if (contact == null) {
logger.warn("Provided contact is null. Will not continue with XML generation for contact."); logger.warn(
"Provided contact is null. Will not continue with XML generation for contact.");
return; return;
} }
@ -337,8 +345,8 @@ public class SciProjectSummaryTab implements GenericOrgaUnitTab {
} }
private String getContactTypeName(final String contactTypeKey) { private String getContactTypeName(final String contactTypeKey) {
final RelationAttributeCollection relAttrs = final RelationAttributeCollection relAttrs
new RelationAttributeCollection(); = new RelationAttributeCollection();
relAttrs.addFilter(String.format("attribute = '%s'", relAttrs.addFilter(String.format("attribute = '%s'",
"GenericOrganizationContactTypes")); "GenericOrganizationContactTypes"));
relAttrs.addFilter(String.format("attr_key = '%s'", contactTypeKey)); relAttrs.addFilter(String.format("attr_key = '%s'", contactTypeKey));
@ -407,8 +415,8 @@ public class SciProjectSummaryTab implements GenericOrgaUnitTab {
final Element parent, final Element parent,
final PageState state) { final PageState state) {
final long start = System.currentTimeMillis(); final long start = System.currentTimeMillis();
final GenericOrganizationalUnitSubordinateCollection subProjects = final GenericOrganizationalUnitSubordinateCollection subProjects
project. = project.
getSubordinateOrgaUnits(); getSubordinateOrgaUnits();
if (subProjects == null) { if (subProjects == null) {
@ -460,11 +468,19 @@ public class SciProjectSummaryTab implements GenericOrgaUnitTab {
final SciProjectSponsorCollection sponsors = project.getSponsors(); final SciProjectSponsorCollection sponsors = project.getSponsors();
final Element sponsorsElem = parent.newChildElement("sponsors"); final Element sponsorsElem = parent.newChildElement("sponsors");
while (sponsors.next()) { while (sponsors.next()) {
final Element sponsorElem = sponsorsElem.newChildElement("sponsor"); final Element sponsorElem = sponsorsElem.newChildElement(
"sponsor");
final GenericOrganizationalUnit sponsor = sponsors.getSponsor(); final GenericOrganizationalUnit sponsor = sponsors.getSponsor();
sponsorElem.setText(sponsor.getTitle()); sponsorElem.setText(sponsor.getTitle());
final Optional<String> link = getSponsorLink(sponsor);
if (link.isPresent()) {
sponsorElem.addAttribute("href", link.get());
}
if ((sponsors.getFundingCode() != null) && !sponsors.isEmpty()) { if ((sponsors.getFundingCode() != null) && !sponsors.isEmpty()) {
sponsorElem.addAttribute("fundingCode", sponsors.getFundingCode()); sponsorElem.addAttribute("fundingCode", sponsors
.getFundingCode());
} }
} }
} }
@ -483,6 +499,31 @@ public class SciProjectSummaryTab implements GenericOrgaUnitTab {
} }
} }
private Optional<String> getSponsorLink(
final GenericOrganizationalUnit orga) {
Session session = SessionManager.getSession();
DataCollection links = session
.retrieve("com.arsdigita.cms.contentassets.RelatedLink");
links.addEqualsFilter("linkOwner.id", orga.getID());
links.addEqualsFilter("linkListName", "NONE");
links.addOrder("linkOrder");
if (links.next()) {
final DataObject link = links.getDataObject();
final String targetUri = (String) link.get("targetURI");
if (targetUri == null || targetUri.isEmpty()) {
return Optional.empty();
} else {
return Optional.of(targetUri);
}
} else {
return Optional.empty();
}
}
private class XmlGenerator extends SimpleXMLGenerator { private class XmlGenerator extends SimpleXMLGenerator {
private final ContentItem item; private final ContentItem item;
@ -498,4 +539,5 @@ public class SciProjectSummaryTab implements GenericOrgaUnitTab {
} }
} }
} }