From 6d9b30e68216aa782e80b74290858f72ecddcc83 Mon Sep 17 00:00:00 2001 From: jensp Date: Sat, 31 Dec 2011 14:25:41 +0000 Subject: [PATCH] =?UTF-8?q?Verbesserung=20des=20Verhaltens=20von=20PublicP?= =?UTF-8?q?ersonalProfile=20f=C3=BCr=20Sprachumschaltung=20(Ticket=20994)?= =?UTF-8?q?=20sowie=20Verbesserung=20des=20404=20Handlings=20in=20PublicPe?= =?UTF-8?q?rsonalProfile=20(Ticket=201000)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.libreccm.org/ccm/trunk@1411 8810af33-2d31-482b-a856-94f89814c4df --- .../PublicPersonalProfile.pdl | 17 + .../PublicPersonalProfileXmlUtil.java | 20 +- ...ublicPersonalProfileNavigationAddForm.java | 83 ++- ...onalProfileNavigationGeneratedAddForm.java | 4 +- .../PublicPersonalProfileNavigationStep.java | 4 +- .../PublicPersonalProfileNavigationTable.java | 26 +- .../ContentGenerator.java | 6 +- .../PublicPersonalProfilesServlet.java | 658 +++++++++++++++++- .../src/com/arsdigita/cms/ContentBundle.java | 1 - .../PersonalProjects.java | 84 ++- .../PersonalPublications.java | 51 +- .../arsdigita/content-types/Publication.pdl | 5 +- .../ui/SciDepartmentSummaryTab.java | 58 +- .../ui/SciInstituteSummaryTab.java | 34 +- .../contenttypes/ui/SciProjectSummaryTab.java | 31 +- 15 files changed, 948 insertions(+), 134 deletions(-) diff --git a/ccm-cms-publicpersonalprofile/pdl/com/arsdigita/publicpersonalprofile/PublicPersonalProfile.pdl b/ccm-cms-publicpersonalprofile/pdl/com/arsdigita/publicpersonalprofile/PublicPersonalProfile.pdl index 00e15de99..743d14351 100644 --- a/ccm-cms-publicpersonalprofile/pdl/com/arsdigita/publicpersonalprofile/PublicPersonalProfile.pdl +++ b/ccm-cms-publicpersonalprofile/pdl/com/arsdigita/publicpersonalprofile/PublicPersonalProfile.pdl @@ -5,3 +5,20 @@ import com.arsdigita.web.Application; object type PublicPersonalProfile extends Application { reference key (publicpersonalprofile.application_id); } + +// Subquery for AbstractObjectList used as a filter +// to figure out which object have a match in the +// selected languages and don't have to match to a +// language independent content item +query getParentIDsOfMatchedItems { + BigDecimal parent; + + do { + select parent_id + from cms_items + where version = 'live' + and language = :language + } map { + parent = parent_id; + } +} \ No newline at end of file diff --git a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/PublicPersonalProfileXmlUtil.java b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/PublicPersonalProfileXmlUtil.java index 46aba275b..53e2be842 100644 --- a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/PublicPersonalProfileXmlUtil.java +++ b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/PublicPersonalProfileXmlUtil.java @@ -24,7 +24,6 @@ import com.arsdigita.cms.contentassets.RelatedLink; import com.arsdigita.cms.publicpersonalprofile.PublicPersonalProfiles; // import com.arsdigita.dispatcher.DispatcherHelper; import com.arsdigita.domain.DomainObjectFactory; -import com.arsdigita.globalization.GlobalizationHelper; import com.arsdigita.persistence.DataCollection; import com.arsdigita.ui.UI; import com.arsdigita.xml.Element; @@ -105,8 +104,9 @@ public class PublicPersonalProfileXmlUtil { } navHome.addAttribute("sortKey", ""); - String homeLabel = homeLabels.get(GlobalizationHelper. - getNegotiatedLocale().getLanguage()); + /*String homeLabel = homeLabels.get(GlobalizationHelper. + getNegotiatedLocale().getLanguage());*/ + String homeLabel = homeLabels.get(profile.getLanguage()); if (homeLabel == null) { navHome.addAttribute("title", "Home"); } else { @@ -122,8 +122,9 @@ public class PublicPersonalProfileXmlUtil { //Get the available Navigation items PublicPersonalProfileNavItemCollection navItems = new PublicPersonalProfileNavItemCollection(); - navItems.addLanguageFilter(GlobalizationHelper.getNegotiatedLocale(). - getLanguage()); + /*navItems.addLanguageFilter(GlobalizationHelper.getNegotiatedLocale(). + getLanguage());*/ + navItems.addLanguageFilter(profile.getLanguage()); final Map navItemMap = new HashMap(); PublicPersonalProfileNavItem navItem; @@ -175,8 +176,13 @@ public class PublicPersonalProfileXmlUtil { if (!(targetItem instanceof PublicPersonalProfile) && (targetItem instanceof ContentPage)) { ContentPage targetPage = (ContentPage) targetItem; - if (!(targetPage.getContentBundle().hasInstance(GlobalizationHelper. - getNegotiatedLocale().getLanguage(), + /*if (!(targetPage.getContentBundle().hasInstance(GlobalizationHelper. + getNegotiatedLocale().getLanguage(), + false))) { + continue; + }*/ + if (!(targetPage.getContentBundle().hasInstance(profile. + getLanguage(), false))) { continue; } diff --git a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfileNavigationAddForm.java b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfileNavigationAddForm.java index 5cc8f01ab..3c5184ef9 100644 --- a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfileNavigationAddForm.java +++ b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfileNavigationAddForm.java @@ -31,6 +31,8 @@ import com.arsdigita.globalization.GlobalizationHelper; import com.arsdigita.globalization.GlobalizedMessage; import com.arsdigita.mimetypes.MimeType; import com.arsdigita.util.UncheckedWrapperException; +import java.util.ArrayList; +import java.util.List; import java.util.TooManyListenersException; import org.apache.log4j.Logger; @@ -52,6 +54,7 @@ public class PublicPersonalProfileNavigationAddForm private final String ITEM_SEARCH = "itemSearch"; private ItemSelectionModel itemModel; private SimpleEditStep editStep; + private List autoNavItemKeys = new ArrayList(); public PublicPersonalProfileNavigationAddForm( final ItemSelectionModel itemModel, @@ -92,18 +95,26 @@ public class PublicPersonalProfileNavigationAddForm navItems.addLanguageFilter(GlobalizationHelper. getNegotiatedLocale(). getLanguage()); - if (showGenerated()) { - navItems.addFilter("generatorClass is not null"); + /*if (showGenerated()) { + navItems.addFilter("generatorClass is not null"); } else { - navItems.addFilter("generatorClass is null"); - } + navItems.addFilter("generatorClass is null"); + }*/ PublicPersonalProfileNavItem navItem; + String label; while (navItems.next()) { navItem = navItems.getNavItem(); - select.addOption(new Option(navItem.getKey(), - navItem.getLabel())); + if (navItem.getGeneratorClass() == null) { + label = navItem.getLabel(); + } else { + label = String.format("%s (auto)", + navItem.getLabel()); + autoNavItemKeys.add(navItem.getKey()); + } + + select.addOption(new Option(navItem.getKey(), label)); } } }); @@ -112,35 +123,34 @@ public class PublicPersonalProfileNavigationAddForm } /*navItemSelect.addOption(new Option("", "")); - + PublicPersonalProfileNavItemCollection navItems = - new PublicPersonalProfileNavItemCollection(); + new PublicPersonalProfileNavItemCollection(); navItems.addLanguageFilter(GlobalizationHelper.getNegotiatedLocale(). - getLanguage()); + getLanguage()); if (showGenerated()) { - navItems.addFilter("generatorClass is not null"); + navItems.addFilter("generatorClass is not null"); } else { - navItems.addFilter("generatorClass is null"); + navItems.addFilter("generatorClass is null"); } - + PublicPersonalProfileNavItem navItem; while (navItems.next()) { - navItem = navItems.getNavItem(); - - navItemSelect.addOption(new Option(navItem.getKey(), - navItem.getLabel())); + navItem = navItems.getNavItem(); + + navItemSelect.addOption(new Option(navItem.getKey(), + navItem.getLabel())); }*/ add(navItemSelect); - if (!showGenerated()) { - add(new Label((String) PublicPersonalProfileGlobalizationUtil. - globalize( - "publicpersonalprofile.ui.nav.select_target"). - localize())); - itemSearch = new ItemSearchWidget(ITEM_SEARCH); - itemSearch.addValidationListener(this); - add(this.itemSearch); - } + //if (!showGenerated()) { + add(new Label((String) PublicPersonalProfileGlobalizationUtil.globalize( + "publicpersonalprofile.ui.nav.select_target"). + localize())); + itemSearch = new ItemSearchWidget(ITEM_SEARCH); + itemSearch.addValidationListener(this); + add(this.itemSearch); + //} } @Override @@ -178,11 +188,15 @@ public class PublicPersonalProfileNavigationAddForm link.setTargetType(Link.INTERNAL_LINK); ContentItem targetItem; - if (showGenerated()) { - //For generated content the target is the profile itself. + //if (showGenerated()) { + //For generated content the target is the profile itself. + //targetItem = profile; + //} else { + targetItem = (ContentItem) data.get(ITEM_SEARCH); + // + //} + if (targetItem == null) { targetItem = profile; - } else { - targetItem = (ContentItem) data.get(ITEM_SEARCH); } if (targetItem.getParent() instanceof ContentBundle) { @@ -200,7 +214,10 @@ public class PublicPersonalProfileNavigationAddForm PageState state = fse.getPageState(); FormData data = fse.getFormData(); - if (!showGenerated() && data.get(ITEM_SEARCH) == null) { + //if (!showGenerated() && data.get(ITEM_SEARCH) == null) { + if (!(autoNavItemKeys.contains( + (String) data.get(PublicPersonalProfileNavItem.KEY))) + && data.get(ITEM_SEARCH) == null) { data.addError( new GlobalizedMessage( "parameter_is_required", @@ -209,7 +226,7 @@ public class PublicPersonalProfileNavigationAddForm } - protected boolean showGenerated() { - return false; - } + /*protected boolean showGenerated() { + return false; + }*/ } diff --git a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfileNavigationGeneratedAddForm.java b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfileNavigationGeneratedAddForm.java index 56ca6ad61..cb9c96b37 100644 --- a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfileNavigationGeneratedAddForm.java +++ b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfileNavigationGeneratedAddForm.java @@ -16,8 +16,8 @@ public class PublicPersonalProfileNavigationGeneratedAddForm extends PublicPerso super("PublicPersonalProfileNavGeneratedAddForm", itemModel, editStep); } - @Override + /*@Override public boolean showGenerated() { return true; - } + }*/ } diff --git a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfileNavigationStep.java b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfileNavigationStep.java index d64765b6c..6def22309 100644 --- a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfileNavigationStep.java +++ b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfileNavigationStep.java @@ -38,7 +38,7 @@ public class PublicPersonalProfileNavigationStep extends SimpleEditStep { new WorkflowLockedComponentAccess(editNavItemSheet, itemModel), editNavItemSheet.getSaveCancelSection().getCancelButton()); - BasicItemForm editGeneratedNavItemSheet = + /*BasicItemForm editGeneratedNavItemSheet = new PublicPersonalProfileNavigationGeneratedAddForm( itemModel, this); @@ -48,7 +48,7 @@ public class PublicPersonalProfileNavigationStep extends SimpleEditStep { localize(), new WorkflowLockedComponentAccess(editGeneratedNavItemSheet, itemModel), - editGeneratedNavItemSheet.getSaveCancelSection().getCancelButton()); + editGeneratedNavItemSheet.getSaveCancelSection().getCancelButton());*/ PublicPersonalProfileNavigationTable navTable = new PublicPersonalProfileNavigationTable( diff --git a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfileNavigationTable.java b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfileNavigationTable.java index 313dec005..ea0287e49 100644 --- a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfileNavigationTable.java +++ b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfileNavigationTable.java @@ -26,6 +26,7 @@ import com.arsdigita.cms.dispatcher.ItemResolver; import com.arsdigita.cms.dispatcher.Utilities; import com.arsdigita.cms.ui.authoring.SimpleEditStep; import com.arsdigita.globalization.GlobalizationHelper; +import com.arsdigita.kernel.Kernel; import com.arsdigita.persistence.DataCollection; import com.arsdigita.util.LockableImpl; import java.math.BigDecimal; @@ -134,7 +135,7 @@ public class PublicPersonalProfileNavigationTable } @Override - public boolean nextRow() { + public boolean nextRow() { return linkCollection.next(); } @@ -146,19 +147,32 @@ public class PublicPersonalProfileNavigationTable PublicPersonalProfileNavItem navItem; navItem = navItems.getNavItem(key, GlobalizationHelper. - getNegotiatedLocale(). - getLanguage()); + getNegotiatedLocale().getLanguage()); + navItems.reset(); + if ((navItem == null) && (Kernel.getConfig().languageIndependentItems())) { + navItem = navItems.getNavItem(key, GlobalizationHelper. + LANG_INDEPENDENT); + } navItems.reset(); switch (columnIndex) { case 0: //return mockNav[index]; - return navItem.getLabel(); - case 1: if (navItem.getGeneratorClass() == null) { - return targetItem; + return navItem.getLabel(); } else { + return String.format("%s (auto)", navItem.getLabel()); + } + case 1: + /*if (navItem.getGeneratorClass() == null) { + return targetItem; + } else { + return null; + }*/ + if (targetItem instanceof PublicPersonalProfile) { return null; + } else { + return targetItem; } case 2: return PublicPersonalProfileGlobalizationUtil.globalize( diff --git a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/ContentGenerator.java b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/ContentGenerator.java index 5b7134f4e..f5b0a05b4 100644 --- a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/ContentGenerator.java +++ b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/ContentGenerator.java @@ -19,7 +19,11 @@ public interface ContentGenerator { * @param parent XML element to attach the content to * @param person The person to be used as data source * @param state The current page state. + * @param profileLanguage */ - void generateContent(Element parent, GenericPerson person, PageState state); + void generateContent(Element parent, + GenericPerson person, + PageState state, + String profileLanguage); } diff --git a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/PublicPersonalProfilesServlet.java b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/PublicPersonalProfilesServlet.java index 097abb362..a85ed7c11 100644 --- a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/PublicPersonalProfilesServlet.java +++ b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/PublicPersonalProfilesServlet.java @@ -37,6 +37,8 @@ import com.arsdigita.globalization.GlobalizationHelper; import com.arsdigita.kernel.Kernel; import com.arsdigita.persistence.DataCollection; import com.arsdigita.persistence.DataObject; +import com.arsdigita.persistence.Filter; +import com.arsdigita.persistence.FilterFactory; import com.arsdigita.persistence.OID; import com.arsdigita.persistence.Session; import com.arsdigita.persistence.SessionManager; @@ -82,6 +84,270 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet { final HttpServletResponse response, final Application app) throws ServletException, IOException { + + logger.debug("PublicPersonalProfileServlet is starting..."); + logger.debug(String.format("pathInfo = '%s'", request.getPathInfo())); + + logger.debug("Extracting path from pathInfo by removing leading and " + + "trailing slashes..."); + + final String pathStr = getPath(request); + + logger.debug(String.format("path = %s", pathStr)); + + //Displays a text/plain page with a message. + if (pathStr.isEmpty()) { + logger.debug("pathInfo is null, responding with default..."); + + response.setContentType("text/plain"); + response.getWriter().append("Please choose an application."); + } else { + final Path path; + try { + path = new Path(pathStr); + } catch (IllegalArgumentException ex) { + response.sendError(HttpServletResponse.SC_BAD_REQUEST, + ex.getMessage()); + return; + } + + final Page page = PageFactory.buildPage("PublicPersonalProfile", + ""); + + if (path.getAdmin()) { + showAdminPage(page, request, response); + return; + } + + page.lock(); + + final Document document = page.buildDocument(request, response); + final Element root = document.getRootElement(); + + final Session session = SessionManager.getSession(); + + /*final DataCollection profiles = getProfiles(session, + path.getProfileOwner(), + path.getPreview(), + GlobalizationHelper. + getNegotiatedLocale().getLanguage()); + + if (profiles.isEmpty()) { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + return; + } else if (profiles.size() > 1) { + throw new IllegalStateException( + "More than one matching members found."); + } + + profiles.next(); + PublicPersonalProfile profile = + (PublicPersonalProfile) DomainObjectFactory. + newInstance(profiles.getDataObject()); + profiles.close();*/ + + PublicPersonalProfile profile = getProfile( + session, + path.getProfileOwner(), + path.getPreview(), + GlobalizationHelper.getNegotiatedLocale().getLanguage()); + + if (profile == null) { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + return; + } + + if (path.getNavPath() != null) { + final DataCollection links = RelatedLink.getRelatedLinks( + profile, + PublicPersonalProfile.LINK_LIST_NAME); + links.addFilter(String.format("linkTitle = '%s'", + path.getNavPath())); + if (links.isEmpty()) { + profile = getProfile(session, + path.getProfileOwner(), + path.getPreview(), + GlobalizationHelper.LANG_INDEPENDENT, + false); + } else { + links.next(); + final RelatedLink link = (RelatedLink) DomainObjectFactory. + newInstance( + links.getDataObject()); + links.close(); + + ContentItem item = link.getTargetItem(); + + if ((item instanceof ContentPage) + && !(item instanceof PublicPersonalProfile)) { + ContentPage contentPage = + (ContentPage) item; + + if (contentPage.getContentBundle().hasInstance(profile. + getLanguage(), + false)) { + contentPage = + (ContentPage) contentPage.getContentBundle(). + getInstance(profile.getLanguage()); + item = (ContentItem) contentPage; + } else { + profile = + getProfile(session, + path.getProfileOwner(), + path.getPreview(), + GlobalizationHelper.LANG_INDEPENDENT); + } + } + } + } + + final PageState state = new PageState(page, + request, + response); + + if (path.getPreview()) { + if (Kernel.getContext().getParty() == null) { + throw new LoginSignal(request); + } else { + + com.arsdigita.cms.SecurityManager securityManager = + Utilities. + getSecurityManager(state); + + final boolean canEdit = securityManager.canAccess( + state.getRequest(), + com.arsdigita.cms.SecurityManager.PREVIEW_PAGES, + profile); + + if (!canEdit) { + throw new AccessDeniedException("user " + + Kernel.getContext(). + getParty().getOID() + + " doesn't have the " + + com.arsdigita.cms.SecurityManager.EDIT_ITEM + + " privilege on " + + profile.getOID(). + toString()); + } + } + } + + if (config.getEmbedded()) { + final ContentSection section = + profile.getContentSection(); + final ItemResolver resolver = section.getItemResolver(); + + String context; + if (path.getPreview()) { + context = CMSDispatcher.PREVIEW; + } else { + context = ContentItem.LIVE; + } + + final String url = String.format("/ccm%s", resolver. + generateItemURL(state, + profile, + section, + context)); + + throw new RedirectSignal(url, false); + } + + Element profileElem = + root.newChildElement("ppp:profile", PPP_NS); + GenericPerson owner = profile.getOwner(); + if (owner == null) { + throw new IllegalStateException( + "Failed to get owner of profile."); + } + Element profileOwnerName = profileElem.newChildElement( + "ppp:ownerName", PPP_NS); + profileOwnerName.setText(owner.getFullName()); + //Add an attribute with the lang of the owner item of debugging. + profileOwnerName.addAttribute("ownerItemLang", owner.getLanguage()); + + final DataCollection images = ItemImageAttachment. + getImageAttachments(profile); + if (!images.isEmpty()) { + images.next(); + final Element profileImageElem = + profileElem.newChildElement("ppp:profileImage", + PPP_NS); + final Element attachmentElem = profileImageElem.newChildElement( + "imageAttachments"); + final ItemImageAttachment attachment = + new ItemImageAttachment(images. + getDataObject()); + attachmentElem.addAttribute("oid", attachment.getOID(). + toString()); + final Element caption = attachmentElem.newChildElement( + "caption"); + caption.setText(attachment.getCaption()); + final ReusableImageAsset image = attachment.getImage(); + final Element imageElem = + attachmentElem.newChildElement("image"); + imageElem.addAttribute("oid", image.getOID().toString()); + final Element widthElem = imageElem.newChildElement( + "width"); + widthElem.setText(image.getWidth().toString()); + final Element heightElem = imageElem.newChildElement( + "height"); + heightElem.setText(image.getHeight().toString()); + final Element descElem = imageElem.newChildElement( + "description"); + descElem.setText(image.getDescription()); + final Element nameElem = imageElem.newChildElement( + "name"); + nameElem.setText(image.getName()); + final Element idElem = imageElem.newChildElement("id"); + idElem.setText(image.getID().toString()); + final Element displayNameElem = imageElem.newChildElement( + "displayName"); + displayNameElem.setText(image.getDisplayName()); + + images.close(); + } + + final PublicPersonalProfileXmlUtil util = + new PublicPersonalProfileXmlUtil(); + String prefix = + DispatcherHelper.getDispatcherPrefix(request); + if (prefix == null) { + prefix = ""; + } + util.createNavigation(profile, + root, + path.getNavPath(), + prefix, + app.getPath(), + path.getPreview()); + + if (path.getNavPath() == null) { + final PublicPersonalProfileXmlGenerator generator = + new PublicPersonalProfileXmlGenerator( + profile); + generator.generateXML(state, root, ""); + } else { + if (path.getItemPath() == null) { + showNavItem(response, profile, path, root, + profileElem, state); + } else { + showItem(response, profile, path, root, + profileElem, state); + } + } + + PresentationManager presentationManager = Templating. + getPresentationManager(); + presentationManager.servePage(document, request, response); + } + } + + //@Override + protected void olddoService(final HttpServletRequest request, + final HttpServletResponse response, + final Application app) throws ServletException, + IOException { String path = ""; logger.debug("PublicPersonalProfileServlet is starting..."); @@ -179,17 +445,19 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet { profileOwner, preview, GlobalizationHelper. - getNegotiatedLocale().getLanguage()); + getNegotiatedLocale().getLanguage(), + Kernel.getConfig(). + languageIndependentItems()); /*if (profiles.isEmpty()) { - profiles = getProfiles(session, - profileOwner, - preview, - GlobalizationHelper.LANG_INDEPENDENT); + profiles = getProfiles(session, + profileOwner, + preview, + GlobalizationHelper.LANG_INDEPENDENT); }*/ if (profiles.size() == 0) { - response.setStatus(HttpServletResponse.SC_NOT_FOUND); + response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } else if (profiles.size() > 1) { throw new IllegalStateException( @@ -337,7 +605,7 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet { navPath)); if (links.size() == 0) { - response.setStatus( + response.sendError( HttpServletResponse.SC_NOT_FOUND); return; } else { @@ -370,7 +638,8 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet { generator.generateContent( profileElem, owner, - state); + state, + profile.getLanguage()); } else { throw new ServletException(String. @@ -440,7 +709,7 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet { Kernel.getConfig(). languageIndependentItems(), GlobalizationHelper.LANG_INDEPENDENT)); - response.setStatus( + response.sendError( HttpServletResponse.SC_NOT_FOUND); return; } @@ -497,7 +766,7 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet { Kernel.getConfig(). languageIndependentItems(), GlobalizationHelper.LANG_INDEPENDENT)); - response.setStatus( + response.sendError( HttpServletResponse.SC_NOT_FOUND); return; } @@ -520,7 +789,7 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet { "Item '%s' not found: ", itemPath), ex); - response.setStatus( + response.sendError( HttpServletResponse.SC_NOT_FOUND); return; } @@ -694,12 +963,229 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet { } + private void showNavItem(final HttpServletResponse response, + final PublicPersonalProfile profile, + final Path path, + final Element root, + final Element profileElem, + final PageState state) throws IOException, + ServletException { + final DataCollection links = + RelatedLink.getRelatedLinks( + profile, + PublicPersonalProfile.LINK_LIST_NAME); + links.addFilter(String.format("linkTitle = '%s'", + path.getNavPath())); + + if (links.size() == 0) { + response.sendError( + HttpServletResponse.SC_NOT_FOUND); + return; + } + + if (config.getShowPersonInfoEverywhere()) { + generateProfileOwnerXml(profileElem, profile.getOwner(), state); + } + + final PublicPersonalProfileNavItemCollection navItems = + new PublicPersonalProfileNavItemCollection(); + navItems.addLanguageFilter(profile.getLanguage()); + navItems.addKeyFilter(path.getNavPath()); + navItems.next(); + + links.next(); + final RelatedLink link = (RelatedLink) DomainObjectFactory.newInstance( + links.getDataObject()); + links.close(); + + ContentItem item = link.getTargetItem(); + + if ((item instanceof ContentPage) + && !(item instanceof PublicPersonalProfile)) { + ContentPage contentPage = + (ContentPage) item; + /*logger.debug("contentPage.getContentBundle().hasInstance(GlobalizationHelper.getNegotiatedLocale().getLanguage()) = " + + contentPage.getContentBundle(). + hasInstance(GlobalizationHelper.getNegotiatedLocale(). + getLanguage())); + if (contentPage.getContentBundle(). + hasInstance(GlobalizationHelper.getNegotiatedLocale(). + getLanguage())) { + contentPage = + (ContentPage) contentPage.getContentBundle(). + getInstance(GlobalizationHelper.getNegotiatedLocale(). + getLanguage()); + item = (ContentItem) contentPage; + } else { + logger.error( + String.format( + "Item '%s' not found in a suitable language variant. Negotiated langauge: %s, langugage independent items allowed is %s, language independent code is %s ", + path.getNavPath(), + GlobalizationHelper.getNegotiatedLocale(). + getLanguage(), + Kernel.getConfig(). + languageIndependentItems(), + GlobalizationHelper.LANG_INDEPENDENT)); + response.sendError( + HttpServletResponse.SC_NOT_FOUND); + return; + }*/ + if (contentPage.getContentBundle().hasInstance(profile.getLanguage(), + false)) { + contentPage = + (ContentPage) contentPage.getContentBundle(). + getInstance(profile.getLanguage()); + item = (ContentItem) contentPage; + } else { + response.sendError( + HttpServletResponse.SC_NOT_FOUND); + return; + } + + + final Element contentPanelElem = + root.newChildElement("cms:contentPanel", + CMS.CMS_XML_NS); + final PublicPersonalProfileXmlGenerator generator = + new PublicPersonalProfileXmlGenerator( + item); + generator.generateXML(state, + contentPanelElem, + ""); + } + + if (navItems.getNavItem().getGeneratorClass() != null) { + try { + Object generatorObj = + Class.forName(navItems.getNavItem(). + getGeneratorClass()). + getConstructor(). + newInstance(); + + if (generatorObj instanceof ContentGenerator) { + final ContentGenerator generator = + (ContentGenerator) generatorObj; + + generator.generateContent(profileElem, + profile.getOwner(), + state, + profile.getLanguage()); + + } else { + throw new ServletException(String.format( + "Class '%s' is not a ContentGenerator.", + navItems.getNavItem(). + getGeneratorClass())); + } + + } catch (InstantiationException ex) { + throw new ServletException( + "Failed to create generator", ex); + } catch (IllegalAccessException ex) { + throw new ServletException( + "Failed to create generator", ex); + } catch (IllegalArgumentException ex) { + throw new ServletException( + "Failed to create generator", ex); + } catch (InvocationTargetException ex) { + throw new ServletException( + "Failed to create generator", ex); + } catch (ClassNotFoundException ex) { + throw new ServletException( + "Failed to create generator", ex); + } catch (NoSuchMethodException ex) { + throw new ServletException( + "Failed to create generator", ex); + } + } + + navItems.close(); + } + + private void showItem(final HttpServletResponse response, + final PublicPersonalProfile profile, + final Path path, + final Element root, + final Element profileElem, + final PageState state) throws IOException { + if (config.getShowPersonInfoEverywhere()) { + generateProfileOwnerXml(profileElem, profile.getOwner(), state); + } + + final OID itemOid = OID.valueOf(path.getItemPath()); + + try { + ContentItem item = + (ContentItem) DomainObjectFactory.newInstance( + itemOid); + + if (item instanceof ContentPage) { + ContentPage contentPage = (ContentPage) item; + /*logger.debug("contentPage.getContentBundle().hasInstance(GlobalizationHelper.getNegotiatedLocale().getLanguage()) = " + + contentPage.getContentBundle(). + hasInstance(GlobalizationHelper.getNegotiatedLocale(). + getLanguage())); + if (contentPage.getContentBundle(). + hasInstance(GlobalizationHelper.getNegotiatedLocale(). + getLanguage())) { + contentPage = (ContentPage) contentPage.getContentBundle(). + getInstance(GlobalizationHelper.getNegotiatedLocale(). + getLanguage()); + item = (ContentItem) contentPage; + } else { + logger.error( + String.format( + "Item '%s' not found in a suitable language variant. Negotiated langauge: %s, langugage independent items allowed is %s, language independent code is %s ", + path.getItemPath(), + GlobalizationHelper.getNegotiatedLocale(). + getLanguage(), + Kernel.getConfig(). + languageIndependentItems(), + GlobalizationHelper.LANG_INDEPENDENT)); + response.sendError( + HttpServletResponse.SC_NOT_FOUND); + return; + }*/ + if (contentPage.getContentBundle().hasInstance(profile. + getLanguage(), false)) { + contentPage = (ContentPage) contentPage.getContentBundle(). + getInstance(profile.getLanguage()); + } else { + response.sendError( + HttpServletResponse.SC_NOT_FOUND); + return; + } + } + + + final Element contentPanelElem = + root.newChildElement("cms:contentPanel", + CMS.CMS_XML_NS); + + final PublicPersonalProfileXmlGenerator generator = + new PublicPersonalProfileXmlGenerator( + item); + generator.generateXML(state, + contentPanelElem, + ""); + } catch (DataObjectNotFoundException ex) { + logger.error(String.format( + "Item '%s' not found: ", + path.getItemPath()), + ex); + response.sendError( + HttpServletResponse.SC_NOT_FOUND); + return; + } + } + private DataCollection getProfiles(final Session session, final String profileOwner, final boolean preview, - final String language) { - DataCollection profiles = - session.retrieve( + final String language, + final boolean allowLangIndependent) { + final DataCollection profiles = + session.retrieve( com.arsdigita.cms.contenttypes.PublicPersonalProfile.BASE_DATA_OBJECT_TYPE); profiles.addFilter(String.format("profileUrl = '%s'", profileOwner)); @@ -711,8 +1197,150 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet { ContentItem.LIVE)); } - profiles.addFilter(String.format("language = '%s'", language)); + if (allowLangIndependent) { + FilterFactory ff = profiles.getFilterFactory(); + Filter filter = ff.or(). + addFilter(ff.equals("language", language)). + addFilter(ff.and(). + addFilter(ff.equals("language", + GlobalizationHelper.LANG_INDEPENDENT)). + addFilter(ff.notIn("parent", + "com.arsdigita.navigation.getParentIDsOfMatchedItems"). + set("language", language))); + profiles.addFilter(filter); + } else { + profiles.addFilter(String.format("language = '%s'", language)); + } return profiles; } + + private PublicPersonalProfile getProfile(final Session session, + final String profileOwner, + final boolean preview, + final String language) { + return getProfile(session, + profileOwner, + preview, + language, + Kernel.getConfig().languageIndependentItems()); + } + + private PublicPersonalProfile getProfile(final Session session, + final String profileOwner, + final boolean preview, + final String language, + final boolean allowLangIndependent) { + final DataCollection profiles = getProfiles(session, + profileOwner, + preview, + language, + allowLangIndependent); + + if (profiles.isEmpty()) { + return null; + } else if (profiles.size() > 1) { + throw new IllegalStateException( + "More than one matching members found."); + } else { + profiles.next(); + PublicPersonalProfile profile = + (PublicPersonalProfile) DomainObjectFactory. + newInstance(profiles.getDataObject()); + profiles.close(); + + return profile; + } + } + + private String getPath(final HttpServletRequest request) { + String path = ""; + + if (request.getPathInfo() != null) { + if ("/".equals(request.getPathInfo())) { + path = ""; + } else if (request.getPathInfo().startsWith("/") + && request.getPathInfo().endsWith("/")) { + path = request.getPathInfo().substring(1, request.getPathInfo(). + length() - 1); + } else if (request.getPathInfo().startsWith("/")) { + path = request.getPathInfo().substring(1); + } else if (request.getPathInfo().endsWith("/")) { + path = request.getPathInfo().substring(0, request.getPathInfo(). + length() - 1); + } else { + path = request.getPathInfo(); + } + } + + return path; + } + + private class Path { + + private final boolean admin; + private final boolean preview; + private final String profileOwner; + private final String navPath; + private final String itemPath; + + public Path(final String path) { + final String[] pathTokens = path.split("/"); + final int ownerTokenPos; + + if (pathTokens.length < 1) { + throw new IllegalArgumentException( + "Illegal path. Missing profile owner."); + } else { + admin = ADMIN.equals(pathTokens[0]); + + preview = PREVIEW.equals(pathTokens[0]); + + if (preview) { + ownerTokenPos = 1; + } else { + ownerTokenPos = 0; + } + + if (pathTokens.length < (ownerTokenPos + 1)) { + throw new IllegalArgumentException( + "Illegal path. Missing profile owner."); + } else { + profileOwner = pathTokens[ownerTokenPos]; + } + + if (pathTokens.length > (ownerTokenPos + 1)) { + navPath = pathTokens[ownerTokenPos + 1]; + } else { + navPath = null; + } + + if (pathTokens.length > (ownerTokenPos + 2)) { + itemPath = pathTokens[ownerTokenPos + 2]; + } else { + itemPath = null; + } + } + } + + public boolean getAdmin() { + return admin; + } + + public boolean getPreview() { + return preview; + } + + public String getProfileOwner() { + return profileOwner; + } + + public String getNavPath() { + return navPath; + } + + public String getItemPath() { + return itemPath; + } + } } diff --git a/ccm-cms/src/com/arsdigita/cms/ContentBundle.java b/ccm-cms/src/com/arsdigita/cms/ContentBundle.java index 45bcae7bb..e0a2fe86b 100755 --- a/ccm-cms/src/com/arsdigita/cms/ContentBundle.java +++ b/ccm-cms/src/com/arsdigita/cms/ContentBundle.java @@ -34,7 +34,6 @@ import com.arsdigita.kernel.permissions.PermissionService; import com.arsdigita.persistence.DataAssociation; import com.arsdigita.persistence.DataAssociationCursor; import com.arsdigita.persistence.DataObject; -import com.arsdigita.persistence.FilterFactory; import com.arsdigita.persistence.OID; import com.arsdigita.persistence.metadata.Property; import com.arsdigita.util.Assert; diff --git a/ccm-sci-personalprojects/src/com/arsdigita/cms/publicpersonalprofile/PersonalProjects.java b/ccm-sci-personalprojects/src/com/arsdigita/cms/publicpersonalprofile/PersonalProjects.java index ceebca7d6..7b0b3b967 100644 --- a/ccm-sci-personalprojects/src/com/arsdigita/cms/publicpersonalprofile/PersonalProjects.java +++ b/ccm-sci-personalprojects/src/com/arsdigita/cms/publicpersonalprofile/PersonalProjects.java @@ -14,10 +14,9 @@ import com.arsdigita.domain.DomainObjectFactory; import com.arsdigita.globalization.GlobalizationHelper; import com.arsdigita.kernel.Kernel; import com.arsdigita.persistence.DataCollection; -import com.arsdigita.persistence.Filter; -import com.arsdigita.persistence.FilterFactory; import com.arsdigita.persistence.OID; import com.arsdigita.xml.Element; +import java.math.BigDecimal; import java.text.DateFormat; import java.util.ArrayList; import java.util.Calendar; @@ -56,8 +55,10 @@ public class PersonalProjects implements ContentGenerator { public void generateContent(final Element parent, final GenericPerson person, - final PageState state) { - final List projects = collectProjects(person); + final PageState state, + final String profileLanguage) { + final List projects = collectProjects(person, + profileLanguage); final Element personalProjectsElem = parent.newChildElement( "personalProjects"); @@ -87,45 +88,74 @@ public class PersonalProjects implements ContentGenerator { } } - private List collectProjects(final GenericPerson person) { + private List collectProjects(final GenericPerson person, + final String language) { final List projects = new ArrayList(); + /*final DataCollection collection = (DataCollection) person.get( + "organizationalunit"); + if (Kernel.getConfig().languageIndependentItems()) {*/ + /* FilterFactory ff = collection.getFilterFactory(); + Filter filter = ff.or().*/ + /*addFilter(ff.equals("language", + com.arsdigita.globalization.GlobalizationHelper. + getNegotiatedLocale().getLanguage())).*/ + /*addFilter(ff.equals("language", language)). + addFilter(ff.and(). + addFilter(ff.equals("language", + GlobalizationHelper.LANG_INDEPENDENT)). + addFilter(ff.notIn("parent", + "com.arsdigita.london.navigation.getParentIDsOfMatchedItems"). + set("language", + com.arsdigita.globalization.GlobalizationHelper. + getNegotiatedLocale().getLanguage()))); + collection.addFilter(filter);*/ + /*collection.addFilter( + String.format("(language = '%s' or language = '%s')", + language, + GlobalizationHelper.LANG_INDEPENDENT)); + } else { + /*collection.addEqualsFilter("language", + com.arsdigita.globalization.GlobalizationHelper. + getNegotiatedLocale().getLanguage());*/ + /* collection.addEqualsFilter("language", language); + }*/ + final List processed = new ArrayList(); final DataCollection collection = (DataCollection) person.get( "organizationalunit"); - if (Kernel.getConfig().languageIndependentItems()) { - FilterFactory ff = collection.getFilterFactory(); - Filter filter = ff.or(). - addFilter(ff.equals("language", - com.arsdigita.globalization.GlobalizationHelper. - getNegotiatedLocale().getLanguage())). - addFilter(ff.and(). - addFilter(ff.equals("language", - GlobalizationHelper.LANG_INDEPENDENT)). - addFilter(ff.notIn("parent", - "com.arsdigita.london.navigation.getParentIDsOfMatchedItems"). - set("language", - com.arsdigita.globalization.GlobalizationHelper. - getNegotiatedLocale().getLanguage()))); - collection.addFilter(filter); - } else { - collection.addEqualsFilter("language", - com.arsdigita.globalization.GlobalizationHelper. - getNegotiatedLocale().getLanguage()); - } + collection.addFilter(String.format("language = '%s'", language)); DomainObject obj; while (collection.next()) { obj = DomainObjectFactory.newInstance(collection.getDataObject()); if (obj instanceof SciProject) { + processed.add(((SciProject) obj).getParent().getID()); projects.add((SciProject) obj); } } + if (Kernel.getConfig().languageIndependentItems()) { + final DataCollection collectionLi = (DataCollection) person.get( + "organizationalunit"); + collectionLi.addFilter( + String.format("language = '%s'", + GlobalizationHelper.LANG_INDEPENDENT)); + + while (collectionLi.next()) { + obj = + DomainObjectFactory.newInstance(collectionLi.getDataObject()); + if (obj instanceof SciProject) { + if (!(processed.contains(((SciProject) obj).getParent(). + getID()))) { + projects.add((SciProject) obj); + } + } + } + } + if (person.getAlias() != null) { collectProjects(person.getAlias(), projects); } - - return projects; } diff --git a/ccm-sci-personalpublications/src/com/arsdigita/cms/publicpersonalprofile/PersonalPublications.java b/ccm-sci-personalpublications/src/com/arsdigita/cms/publicpersonalprofile/PersonalPublications.java index ea8150197..cc63db4ec 100644 --- a/ccm-sci-personalpublications/src/com/arsdigita/cms/publicpersonalprofile/PersonalPublications.java +++ b/ccm-sci-personalpublications/src/com/arsdigita/cms/publicpersonalprofile/PersonalPublications.java @@ -11,6 +11,8 @@ import com.arsdigita.domain.DomainObjectFactory; import com.arsdigita.globalization.GlobalizationHelper; import com.arsdigita.kernel.Kernel; import com.arsdigita.persistence.DataQuery; +import com.arsdigita.persistence.Filter; +import com.arsdigita.persistence.FilterFactory; import com.arsdigita.persistence.OID; import com.arsdigita.persistence.SessionManager; import com.arsdigita.xml.Element; @@ -46,12 +48,13 @@ public class PersonalPublications implements ContentGenerator { @Override public void generateContent(final Element parent, final GenericPerson person, - final PageState state) { + final PageState state, + final String language) { final long start = System.currentTimeMillis(); final DataQuery allQuery = SessionManager.getSession().retrieveQuery( "com.arsdigita.cms.contenttypes.getPublicationsForAuthor"); - applyAuthorFilter(person, allQuery, true); + applyAuthorFilter(person, allQuery, true, language); final Element personalPubsElem = parent.newChildElement( "personalPublications"); @@ -83,7 +86,8 @@ public class PersonalPublications implements ContentGenerator { createGroupQuery(person, entry.getKey(), entry.getValue(), - groupQueries); + groupQueries, + language); logger.debug(String.format("3: %d ms until now...", System. currentTimeMillis() - start)); } @@ -92,7 +96,7 @@ public class PersonalPublications implements ContentGenerator { final DataQuery miscQuery = SessionManager.getSession(). retrieveQuery( "com.arsdigita.cms.contenttypes.getPublicationsForAuthor"); - applyAuthorFilter(person, miscQuery, true); + applyAuthorFilter(person, miscQuery, true, language); miscQuery.addFilter(miscFilter); groupQueries.put(MISC, miscQuery); logger.debug(String.format("4: %d ms until now...", System. @@ -192,7 +196,8 @@ public class PersonalPublications implements ContentGenerator { private void applyAuthorFilter(final GenericPerson person, final DataQuery query, - final boolean addOrders) { + final boolean addOrders, + final String language) { final StringBuilder authorFilterBuilder = new StringBuilder(); authorFilterBuilder.append('('); authorFilterBuilder.append(String.format("authorId = %s", @@ -208,23 +213,27 @@ public class PersonalPublications implements ContentGenerator { /*query.addFilter(String.format("authorId = %s", person.getID().toString()));*/ if (Kernel.getConfig().languageIndependentItems()) { - /*FilterFactory ff = query.getFilterFactory(); + FilterFactory ff = query.getFilterFactory(); Filter filter = ff.or(). - addFilter(ff.equals("language", com.arsdigita.globalization.GlobalizationHelper.getNegotiatedLocale().getLanguage())). + addFilter(ff.equals("language", language)). addFilter(ff.and(). addFilter(ff.equals("language", GlobalizationHelper.LANG_INDEPENDENT)). addFilter(ff.notIn("parent", "com.arsdigita.navigation.getParentIDsOfMatchedItems") - .set("language", com.arsdigita.globalization.GlobalizationHelper.getNegotiatedLocale().getLanguage()))); - query.addFilter(filter);*/ - query.addFilter( - String.format("(language = '%s' or language = '%s')", - GlobalizationHelper.getNegotiatedLocale(). - getLanguage(), - GlobalizationHelper.LANG_INDEPENDENT)); + .set("language", language))); + query.addFilter(filter); + /*query.addFilter( + String.format("(language = '%s' or language = '%s')", + GlobalizationHelper.getNegotiatedLocale(). + getLanguage(), + GlobalizationHelper.LANG_INDEPENDENT));*/ + /*query.addFilter(String.format("language = '%s' or language = '%s'", + language, + GlobalizationHelper.LANG_INDEPENDENT));*/ } else { - query.addEqualsFilter("language", - com.arsdigita.globalization.GlobalizationHelper. - getNegotiatedLocale().getLanguage()); + /*query.addEqualsFilter("language", + com.arsdigita.globalization.GlobalizationHelper. + getNegotiatedLocale().getLanguage());*/ + query.addEqualsFilter("language", language); } if (addOrders) { final String[] orders = config.getOrder().split(","); @@ -236,7 +245,8 @@ public class PersonalPublications implements ContentGenerator { private void addAliasToFilter(final StringBuilder builder, final GenericPerson alias) { - builder.append(String.format("or authorId = %s", alias.getID().toString())); + builder.append(String.format("or authorId = %s", + alias.getID().toString())); if (alias.getAlias() != null) { addAliasToFilter(builder, alias.getAlias()); @@ -430,10 +440,11 @@ public class PersonalPublications implements ContentGenerator { private void createGroupQuery(final GenericPerson author, final String groupName, final List typeTokens, - final Map groupQueries) { + final Map groupQueries, + final String language) { final DataQuery query = SessionManager.getSession().retrieveQuery( "com.arsdigita.cms.contenttypes.getPublicationsForAuthor"); - applyAuthorFilter(author, query, true); + applyAuthorFilter(author, query, true, language); applyFiltersForTypeTokens(typeTokens, query); groupQueries.put(groupName, query); diff --git a/ccm-sci-publications/pdl/com/arsdigita/content-types/Publication.pdl b/ccm-sci-publications/pdl/com/arsdigita/content-types/Publication.pdl index fdf76e143..57ff55925 100644 --- a/ccm-sci-publications/pdl/com/arsdigita/content-types/Publication.pdl +++ b/ccm-sci-publications/pdl/com/arsdigita/content-types/Publication.pdl @@ -172,6 +172,7 @@ query getPublicationsForAuthor { String language; Boolean reviewed; String authors; + BigDecimal parent; do { select cms_pages.item_id, @@ -181,7 +182,8 @@ query getPublicationsForAuthor { ct_publications.year, cms_items.language, ct_publications.reviewed, - ct_publications.authors + ct_publications.authors, + cms_items.parent_id from cms_pages join ct_publications on cms_pages.item_id = ct_publications.publication_id join ct_publications_authorship on ct_publications.publication_id = ct_publications_authorship.publication_id @@ -196,6 +198,7 @@ query getPublicationsForAuthor { language = ct_items.language; reviewed = ct_publications.reviewed; authors = ct_publications.authors; + parent = cms_items.parent_id; } } diff --git a/ccm-sci-types-department/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentSummaryTab.java b/ccm-sci-types-department/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentSummaryTab.java index df89db5aa..9c908be86 100644 --- a/ccm-sci-types-department/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentSummaryTab.java +++ b/ccm-sci-types-department/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentSummaryTab.java @@ -2,6 +2,7 @@ package com.arsdigita.cms.contenttypes.ui; import com.arsdigita.bebop.PageState; import com.arsdigita.cms.ContentItem; +import com.arsdigita.cms.RelationAttributeCollection; import com.arsdigita.cms.contenttypes.GenericContact; import com.arsdigita.cms.contenttypes.GenericOrganizationalUnit; import com.arsdigita.cms.contenttypes.GenericOrganizationalUnitContactCollection; @@ -10,6 +11,7 @@ import com.arsdigita.cms.contenttypes.GenericOrganizationalUnitSubordinateCollec import com.arsdigita.cms.contenttypes.GenericPerson; import com.arsdigita.cms.contenttypes.SciDepartment; import com.arsdigita.cms.dispatcher.SimpleXMLGenerator; +import com.arsdigita.globalization.GlobalizationHelper; import com.arsdigita.xml.Element; import java.math.BigDecimal; import org.apache.log4j.Logger; @@ -60,7 +62,7 @@ public class SciDepartmentSummaryTab implements GenericOrgaUnitTab { if (config.isShowingSubDepartment()) { generateSubDepartmentsXml(department, departmentSummaryElem, state); } - + if (config.isShowingContacts()) { generateContactsXml(department, departmentSummaryElem, state); } @@ -172,22 +174,24 @@ public class SciDepartmentSummaryTab implements GenericOrgaUnitTab { final long start = System.currentTimeMillis(); if (!(orgaunit instanceof SciDepartment)) { - throw new IllegalArgumentException(String.format("Can't process " + throw new IllegalArgumentException(String.format( + "Can't process " + "orgaunit '%s' as sub department because the orgaunit is " + "not a SciDepartment but of type '%s'.", orgaunit.getName(), - orgaunit.getClass().getName())); + orgaunit.getClass(). + getName())); } - + final SciDepartment subDepartment = (SciDepartment) orgaunit; - + final Element subDepElem = parent.newChildElement("subDepartment"); subDepElem.addAttribute("oid", subDepartment.getOID().toString()); final Element nameElem = subDepElem.newChildElement("title"); nameElem.setText(subDepartment.getTitle()); - + generateHeadOfDepartmentXml(subDepartment, subDepElem, state); - + logger.debug(String.format("Generated XML for sub department '%s' " + "in %d ms", orgaunit.getName(), @@ -195,8 +199,8 @@ public class SciDepartmentSummaryTab implements GenericOrgaUnitTab { } protected void generateHeadXml(final BigDecimal memberId, - final Element parent, - final PageState state) { + final Element parent, + final PageState state) { final long start = System.currentTimeMillis(); final GenericPerson member = new GenericPerson(memberId); logger.debug(String.format("Got domain object for member '%s' " @@ -207,8 +211,8 @@ public class SciDepartmentSummaryTab implements GenericOrgaUnitTab { } protected void generateHeadXml(final GenericPerson member, - final Element parent, - final PageState state) { + final Element parent, + final PageState state) { final long start = System.currentTimeMillis(); final XmlGenerator generator = new XmlGenerator(member); generator.setUseExtraXml(false); @@ -219,7 +223,7 @@ public class SciDepartmentSummaryTab implements GenericOrgaUnitTab { System.currentTimeMillis() - start)); } - protected void generateContactsXml(final SciDepartment department, + protected void generateContactsXml(final SciDepartment department, final Element parent, final PageState state) { final long start = System.currentTimeMillis(); @@ -233,7 +237,10 @@ public class SciDepartmentSummaryTab implements GenericOrgaUnitTab { final Element contactsElem = parent.newChildElement("contacts"); while (contacts.next()) { - generateContactXml(contacts.getContact(), contactsElem, state); + generateContactXml(contacts.getContact(), + contacts.getContactType(), + contactsElem, + state); } logger.debug(String.format("Generated XML for contacts of project '%s'" + " in %d ms.", @@ -242,18 +249,41 @@ public class SciDepartmentSummaryTab implements GenericOrgaUnitTab { } protected void generateContactXml(final GenericContact contact, + final String contactType, final Element parent, final PageState state) { final long start = System.currentTimeMillis(); final XmlGenerator generator = new XmlGenerator(contact); generator.setUseExtraXml(false); generator.setItemElemName("contact", ""); + generator.addItemAttribute("contactType", + getContactTypeName(contactType)); generator.generateXML(state, parent, ""); logger.debug(String.format("Generated XML for contact '%s' in %d ms.", contact.getName(), System.currentTimeMillis() - start)); } - + + private String getContactTypeName(final String contactTypeKey) { + final RelationAttributeCollection relAttrs = + new RelationAttributeCollection(); + relAttrs.addFilter(String.format("attribute = '%s'", + "GenericContactTypes")); + relAttrs.addFilter(String.format("attr_key = '%s'", contactTypeKey)); + relAttrs.addFilter(String.format("lang = '%s'", GlobalizationHelper. + getNegotiatedLocale().getLanguage())); + + if (relAttrs.isEmpty()) { + return contactTypeKey; + } else { + relAttrs.next(); + final String result = relAttrs.getName(); + relAttrs.close(); + return result; + } + + } + private class XmlGenerator extends SimpleXMLGenerator { private final ContentItem item; diff --git a/ccm-sci-types-institute/src/com/arsdigita/cms/contenttypes/ui/SciInstituteSummaryTab.java b/ccm-sci-types-institute/src/com/arsdigita/cms/contenttypes/ui/SciInstituteSummaryTab.java index a609c9882..9883f5ecd 100644 --- a/ccm-sci-types-institute/src/com/arsdigita/cms/contenttypes/ui/SciInstituteSummaryTab.java +++ b/ccm-sci-types-institute/src/com/arsdigita/cms/contenttypes/ui/SciInstituteSummaryTab.java @@ -2,6 +2,7 @@ package com.arsdigita.cms.contenttypes.ui; import com.arsdigita.bebop.PageState; import com.arsdigita.cms.ContentItem; +import com.arsdigita.cms.RelationAttributeCollection; import com.arsdigita.cms.contenttypes.GenericContact; import com.arsdigita.cms.contenttypes.GenericOrganizationalUnit; import com.arsdigita.cms.contenttypes.GenericOrganizationalUnitContactCollection; @@ -10,6 +11,7 @@ import com.arsdigita.cms.contenttypes.GenericOrganizationalUnitSubordinateCollec import com.arsdigita.cms.contenttypes.GenericPerson; import com.arsdigita.cms.contenttypes.SciInstitute; import com.arsdigita.cms.dispatcher.SimpleXMLGenerator; +import com.arsdigita.globalization.GlobalizationHelper; import com.arsdigita.xml.Element; import java.math.BigDecimal; import org.apache.log4j.Logger; @@ -271,8 +273,8 @@ public class SciInstituteSummaryTab implements GenericOrgaUnitTab { member.getFullName(), System.currentTimeMillis() - start)); } - - protected void generateContactsXml(final SciInstitute department, + + protected void generateContactsXml(final SciInstitute department, final Element parent, final PageState state) { final long start = System.currentTimeMillis(); @@ -286,7 +288,10 @@ public class SciInstituteSummaryTab implements GenericOrgaUnitTab { final Element contactsElem = parent.newChildElement("contacts"); while (contacts.next()) { - generateContactXml(contacts.getContact(), contactsElem, state); + generateContactXml(contacts.getContact(), + contacts.getContactType(), + contactsElem, + state); } logger.debug(String.format("Generated XML for contacts of project '%s'" + " in %d ms.", @@ -295,18 +300,41 @@ public class SciInstituteSummaryTab implements GenericOrgaUnitTab { } protected void generateContactXml(final GenericContact contact, + final String contactType, final Element parent, final PageState state) { final long start = System.currentTimeMillis(); final XmlGenerator generator = new XmlGenerator(contact); generator.setUseExtraXml(false); generator.setItemElemName("contact", ""); + generator.addItemAttribute("contactType", + getContactTypeName(contactType)); generator.generateXML(state, parent, ""); logger.debug(String.format("Generated XML for contact '%s' in %d ms.", contact.getName(), System.currentTimeMillis() - start)); } + private String getContactTypeName(final String contactTypeKey) { + final RelationAttributeCollection relAttrs = + new RelationAttributeCollection(); + relAttrs.addFilter(String.format("attribute = '%s'", + "GenericContactTypes")); + relAttrs.addFilter(String.format("attr_key = '%s'", contactTypeKey)); + relAttrs.addFilter(String.format("lang = '%s'", GlobalizationHelper. + getNegotiatedLocale().getLanguage())); + + if (relAttrs.isEmpty()) { + return contactTypeKey; + } else { + relAttrs.next(); + final String result = relAttrs.getName(); + relAttrs.close(); + return result; + } + + } + private class XmlGenerator extends SimpleXMLGenerator { private final ContentItem item; diff --git a/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/ui/SciProjectSummaryTab.java b/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/ui/SciProjectSummaryTab.java index fea69754d..24ccf715b 100644 --- a/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/ui/SciProjectSummaryTab.java +++ b/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/ui/SciProjectSummaryTab.java @@ -2,6 +2,7 @@ package com.arsdigita.cms.contenttypes.ui; import com.arsdigita.bebop.PageState; import com.arsdigita.cms.ContentItem; +import com.arsdigita.cms.RelationAttributeCollection; import com.arsdigita.cms.contenttypes.GenericContact; import com.arsdigita.cms.contenttypes.GenericOrganizationalUnit; import com.arsdigita.cms.contenttypes.GenericOrganizationalUnitContactCollection; @@ -293,7 +294,10 @@ public class SciProjectSummaryTab implements GenericOrgaUnitTab { final Element contactsElem = parent.newChildElement("contacts"); while (contacts.next()) { - generateContactXml(contacts.getContact(), contactsElem, state); + generateContactXml(contacts.getContact(), + contacts.getContactType(), + contactsElem, + state); } logger.debug(String.format("Generated XML for contacts of project '%s'" + " in %d ms.", @@ -302,18 +306,41 @@ public class SciProjectSummaryTab implements GenericOrgaUnitTab { } protected void generateContactXml(final GenericContact contact, + final String contactType, final Element parent, final PageState state) { final long start = System.currentTimeMillis(); final XmlGenerator generator = new XmlGenerator(contact); generator.setUseExtraXml(false); generator.setItemElemName("contact", ""); + generator.addItemAttribute("contactType", + getContactTypeName(contactType)); generator.generateXML(state, parent, ""); logger.debug(String.format("Generated XML for contact '%s' in %d ms.", contact.getName(), System.currentTimeMillis() - start)); } + private String getContactTypeName(final String contactTypeKey) { + final RelationAttributeCollection relAttrs = + new RelationAttributeCollection(); + relAttrs.addFilter(String.format("attribute = '%s'", + "GenericContactTypes")); + relAttrs.addFilter(String.format("attr_key = '%s'", contactTypeKey)); + relAttrs.addFilter(String.format("lang = '%s'", GlobalizationHelper. + getNegotiatedLocale().getLanguage())); + + if (relAttrs.isEmpty()) { + return contactTypeKey; + } else { + relAttrs.next(); + final String result = relAttrs.getName(); + relAttrs.close(); + return result; + } + + } + protected void generateInvolvedOrgasXml(final SciProject project, final Element parent, final PageState state) { @@ -354,7 +381,7 @@ public class SciProjectSummaryTab implements GenericOrgaUnitTab { final XmlGenerator generator = new XmlGenerator(involved); generator.setUseExtraXml(false); generator.setItemElemName("organization", ""); - generator.generateXML(state, parent, ""); + generator.generateXML(state, parent, ""); logger.debug(String.format("Generated XML for involved organization " + "'%s' in %d ms.", involved.getName(),