From 3b2bde68ffba3e42835d7e443b490c3303c23238 Mon Sep 17 00:00:00 2001 From: Drew Wills Date: Tue, 23 Jan 2018 09:23:18 -0700 Subject: [PATCH 1/6] UP-4994: Some light refactoring and general cleanup ahead of the real work --- .../xml/dlm/FragmentDefinitionImporter.java | 2 +- .../portal/layout/IUserLayoutStore.java | 2 +- .../portal/layout/dlm/FragmentDefinition.java | 4 +- .../layout/dlm/DistributedLayoutManager.java | 166 ++++++++---------- .../portal/layout/dlm/FragmentActivator.java | 14 +- .../dlm/RDBMDistributedLayoutStore.java | 2 +- .../portal/utils/FragmentDefinitionUtils.java | 60 +++---- .../utils/IFragmentDefinitionUtils.java | 7 - .../io/import-fragment-definition_v3-1.crn | 20 +-- 9 files changed, 117 insertions(+), 160 deletions(-) diff --git a/uPortal-io/uPortal-io-types/src/main/java/org/apereo/portal/io/xml/dlm/FragmentDefinitionImporter.java b/uPortal-io/uPortal-io-types/src/main/java/org/apereo/portal/io/xml/dlm/FragmentDefinitionImporter.java index 47c770fc484..2f3bd5ac043 100644 --- a/uPortal-io/uPortal-io-types/src/main/java/org/apereo/portal/io/xml/dlm/FragmentDefinitionImporter.java +++ b/uPortal-io/uPortal-io-types/src/main/java/org/apereo/portal/io/xml/dlm/FragmentDefinitionImporter.java @@ -97,7 +97,7 @@ public void importData(Tuple data) { fragmentDefinition = new FragmentDefinition(fragmentDefElement); } - fragmentDefinition.loadFromEelement(fragmentDefElement); + fragmentDefinition.loadFromElement(fragmentDefElement); this.fragmentDefinitionDao.updateFragmentDefinition(fragmentDefinition); } diff --git a/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/IUserLayoutStore.java b/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/IUserLayoutStore.java index a27dd59f414..c2290d473aa 100644 --- a/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/IUserLayoutStore.java +++ b/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/IUserLayoutStore.java @@ -14,7 +14,6 @@ */ package org.apereo.portal.layout; -/** Interface by which portal talks to the database */ import com.google.common.cache.Cache; import java.util.Hashtable; import java.util.Map; @@ -27,6 +26,7 @@ import org.apereo.portal.utils.Tuple; import org.w3c.dom.Document; +/** Interface by which portal talks to the database */ public interface IUserLayoutStore { void setLayoutImportExportCache(Cache, Document> layoutCache); diff --git a/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/FragmentDefinition.java b/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/FragmentDefinition.java index 31f55ea7ed3..53ffbed1957 100755 --- a/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/FragmentDefinition.java +++ b/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/FragmentDefinition.java @@ -94,10 +94,10 @@ public FragmentDefinition(Element e) { NamedNodeMap atts = e.getAttributes(); this.name = loadAttribute("name", atts, true, e); - loadFromEelement(e); + loadFromElement(e); } - public void loadFromEelement(Element e) { + public void loadFromElement(Element e) { final boolean REQUIRED = true; final boolean NOT_REQUIRED = false; diff --git a/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/DistributedLayoutManager.java b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/DistributedLayoutManager.java index 44a1f1d286a..ad5333dbd35 100644 --- a/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/DistributedLayoutManager.java +++ b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/DistributedLayoutManager.java @@ -121,7 +121,7 @@ public DistributedLayoutManager(IPerson owner, IUserProfile profile) throws Port this.profile = profile; // Must always initialize the cacheKey to a generated value - this.updateCacheKey(); + updateCacheKey(); } @Autowired @@ -163,41 +163,26 @@ public void setPortalEventFactory(IPortalLayoutEventFactory portalEventFactory) public void afterPropertiesSet() throws Exception { // Ensure a new layout gets loaded whenever a user logs in except for guest users if (!owner.isGuest()) { - this.layoutCachingService.removeCachedLayout(owner, profile); + layoutCachingService.removeCachedLayout(owner, profile); } - this.loadUserLayout(); + loadUserLayout(); // verify that we have the minimum layout necessary to render the // portal and reset it if we do not. - this.getRootFolderId(); - - // This listener determines if one or more channels have been - // added, and sets a state variable which is reset when the - // layout saved event is triggered. - // this.addLayoutEventListener(new LayoutEventListenerAdapter() - // { - // @Override - // public void channelAdded(LayoutEvent ev) { - // channelsAdded = true; - // } - // @Override - // public void layoutSaved() { - // channelsAdded = false; - // } - // }); + getRootFolderId(); } private void setUserLayoutDOM(DistributedUserLayout userLayout) { - this.layoutCachingService.cacheLayout(owner, profile, userLayout); - this.updateCacheKey(); + layoutCachingService.cacheLayout(owner, profile, userLayout); + updateCacheKey(); // determine if this is a layout fragment by looking at the root node // for a cp:fragment attribute. Element layout = userLayout.getLayout().getDocumentElement(); Node attr = layout.getAttributeNodeNS(Constants.NS_URI, Constants.LCL_FRAGMENT_NAME); - this.isFragmentOwner = attr != null; + isFragmentOwner = attr != null; } @SuppressWarnings("deprecation") @@ -210,12 +195,12 @@ public Document getUserLayoutDOM() { protected DistributedUserLayout getDistributedUserLayout() { DistributedUserLayout userLayout = - this.layoutCachingService.getCachedLayout(owner, profile); + layoutCachingService.getCachedLayout(owner, profile); if (null == userLayout) { if (LOG.isDebugEnabled()) { LOG.debug("Load from store for " + owner.getAttribute(IPerson.USERNAME)); } - userLayout = this.distributedLayoutStore.getUserLayout(this.owner, this.profile); + userLayout = distributedLayoutStore.getUserLayout(owner, profile); final Document userLayoutDocument = userLayout.getLayout(); @@ -258,7 +243,6 @@ protected DistributedUserLayout getDistributedUserLayout() { } } } catch (Throwable t) { - // Log this... LOG.warn( "RDBMUserLayoutStore was unable to analyze channel element with Id=" + ch.getAttribute("chanID"), @@ -275,14 +259,14 @@ protected DistributedUserLayout getDistributedUserLayout() { @Override public XMLEventReader getUserLayoutReader() { - Document ul = this.getUserLayoutDOM(); + Document ul = getUserLayoutDOM(); if (ul == null) { throw new PortalException( "User layout has not been initialized for " + owner.getAttribute(IPerson.USERNAME)); } - final XMLInputFactory xmlInputFactory = this.xmlUtilities.getXmlInputFactory(); + final XMLInputFactory xmlInputFactory = xmlUtilities.getXmlInputFactory(); final DOMSource layoutSoure = new DOMSource(ul); try { @@ -296,7 +280,7 @@ public XMLEventReader getUserLayoutReader() { } public synchronized void loadUserLayout() throws PortalException { - this.loadUserLayout(false); + loadUserLayout(false); } public synchronized void loadUserLayout(boolean reload) throws PortalException { @@ -304,7 +288,7 @@ public synchronized void loadUserLayout(boolean reload) throws PortalException { try { // Clear the loaded document first if this is a forced reload if (reload) { - this.layoutCachingService.removeCachedLayout(owner, profile); + layoutCachingService.removeCachedLayout(owner, profile); } uli = getUserLayoutDOM(); @@ -312,9 +296,9 @@ public synchronized void loadUserLayout(boolean reload) throws PortalException { throw new PortalException( "Exception encountered while " + "reading a layout for userId=" - + this.owner.getID() + + owner.getID() + ", profileId=" - + this.profile.getProfileId(), + + profile.getProfileId(), e); } if (uli == null) { @@ -331,7 +315,7 @@ public synchronized void loadUserLayout(boolean reload) throws PortalException { } public synchronized void saveUserLayout() throws PortalException { - Document uld = this.getUserLayoutDOM(); + Document uld = getUserLayoutDOM(); if (uld == null) { throw new PortalException( @@ -340,23 +324,23 @@ public synchronized void saveUserLayout() throws PortalException { + "."); } try { - this.distributedLayoutStore.setUserLayout(this.owner, this.profile, uld, channelsAdded); + distributedLayoutStore.setUserLayout(owner, profile, uld, channelsAdded); } catch (Exception e) { throw new PortalException( "Exception encountered while " + "saving layout for userId=" - + this.owner.getID() + + owner.getID() + ", profileId=" - + this.profile.getProfileId(), + + profile.getProfileId(), e); } - this.channelsAdded = false; + channelsAdded = false; } @Override public Set getAllSubscribedChannels() { - final Document uld = this.getUserLayoutDOM(); + final Document uld = getUserLayoutDOM(); if (uld == null) { throw new PortalException( @@ -380,7 +364,7 @@ public Set getAllSubscribedChannels() { public IUserLayoutNodeDescription getNode(String nodeId) throws PortalException { if (nodeId == null) return null; - Document uld = this.getUserLayoutDOM(); + Document uld = getUserLayoutDOM(); if (uld == null) throw new PortalException( @@ -407,15 +391,15 @@ public IUserLayoutNodeDescription addNode( IUserLayoutNodeDescription node, String parentId, String nextSiblingId) throws PortalException { boolean isChannel = false; - IUserLayoutNodeDescription parent = this.getNode(parentId); + IUserLayoutNodeDescription parent = getNode(parentId); if (canAddNode(node, parent, nextSiblingId)) { // assign new Id try { if (node instanceof IUserLayoutChannelDescription) { isChannel = true; - node.setId(this.distributedLayoutStore.generateNewChannelSubscribeId(owner)); + node.setId(distributedLayoutStore.generateNewChannelSubscribeId(owner)); } else { - node.setId(this.distributedLayoutStore.generateNewFolderId(owner)); + node.setId(distributedLayoutStore.generateNewFolderId(owner)); } } catch (Exception e) { throw new PortalException( @@ -437,21 +421,21 @@ public IUserLayoutNodeDescription addNode( // register element id childElement.setIdAttribute(Constants.ATT_ID, true); childElement.setAttribute(Constants.ATT_ID, node.getId()); - this.updateCacheKey(); + updateCacheKey(); // push into the user's real layout that gets persisted. HandlerUtils.createPlfNodeAndPath(childElement, isChannel, owner); // fire event - final int layoutId = this.getLayoutId(); + final int layoutId = getLayoutId(); if (isChannel) { - this.channelsAdded = true; + channelsAdded = true; final String fname = ((IUserLayoutChannelDescription) node).getFunctionalName(); - this.portalEventFactory.publishPortletAddedToLayoutPortalEvent( - this, this.owner, layoutId, parent.getId(), fname); + portalEventFactory.publishPortletAddedToLayoutPortalEvent( + this, owner, layoutId, parent.getId(), fname); } else { - this.portalEventFactory.publishFolderAddedToLayoutPortalEvent( - this, this.owner, layoutId, node.getId()); + portalEventFactory.publishFolderAddedToLayoutPortalEvent( + this, owner, layoutId, node.getId()); } return node; @@ -461,12 +445,12 @@ public IUserLayoutNodeDescription addNode( public boolean moveNode(String nodeId, String parentId, String nextSiblingId) throws PortalException { - IUserLayoutNodeDescription parent = this.getNode(parentId); - IUserLayoutNodeDescription node = this.getNode(nodeId); + IUserLayoutNodeDescription parent = getNode(parentId); + IUserLayoutNodeDescription node = getNode(nodeId); String oldParentNodeId = getParentId(nodeId); if (canMoveNode(node, parent, nextSiblingId)) { // must be a folder - Document uld = this.getUserLayoutDOM(); + Document uld = getUserLayoutDOM(); Element childElement = uld.getElementById(nodeId); Element parentElement = uld.getElementById(parentId); if (nextSiblingId == null) { @@ -475,21 +459,21 @@ public boolean moveNode(String nodeId, String parentId, String nextSiblingId) Node nextSibling = uld.getElementById(nextSiblingId); parentElement.insertBefore(childElement, nextSibling); } - this.updateCacheKey(); + updateCacheKey(); // propagate the change into the PLF Element oldParent = uld.getElementById(oldParentNodeId); TabColumnPrefsHandler.moveElement(childElement, oldParent, owner); // fire event - final int layoutId = this.getLayoutId(); + final int layoutId = getLayoutId(); if (node instanceof IUserLayoutChannelDescription) { - this.channelsAdded = true; + channelsAdded = true; final String fname = ((IUserLayoutChannelDescription) node).getFunctionalName(); - this.portalEventFactory.publishPortletMovedInLayoutPortalEvent( - this, this.owner, layoutId, oldParentNodeId, parent.getId(), fname); + portalEventFactory.publishPortletMovedInLayoutPortalEvent( + this, owner, layoutId, oldParentNodeId, parent.getId(), fname); } else { - this.portalEventFactory.publishFolderMovedInLayoutPortalEvent( - this, this.owner, layoutId, oldParentNodeId, parent.getId()); + portalEventFactory.publishFolderMovedInLayoutPortalEvent( + this, owner, layoutId, oldParentNodeId, parent.getId()); } return true; } @@ -498,10 +482,10 @@ public boolean moveNode(String nodeId, String parentId, String nextSiblingId) public boolean deleteNode(String nodeId) throws PortalException { if (canDeleteNode(nodeId)) { - IUserLayoutNodeDescription nodeDescription = this.getNode(nodeId); - String parentNodeId = this.getParentId(nodeId); + IUserLayoutNodeDescription nodeDescription = getNode(nodeId); + String parentNodeId = getParentId(nodeId); - Document uld = this.getUserLayoutDOM(); + Document uld = getUserLayoutDOM(); Element ilfNode = uld.getElementById(nodeId); Node parent = ilfNode.getParentNode(); if (parent != null) { @@ -514,25 +498,25 @@ public boolean deleteNode(String nodeId) throws PortalException { + owner.getAttribute(IPerson.USERNAME) + "."); } - this.updateCacheKey(); + updateCacheKey(); // now push into the PLF TabColumnPrefsHandler.deleteNode(ilfNode, owner); // inform the listeners - final int layoutId = this.getLayoutId(); + final int layoutId = getLayoutId(); if (nodeDescription instanceof IUserLayoutChannelDescription) { final IUserLayoutChannelDescription userLayoutChannelDescription = (IUserLayoutChannelDescription) nodeDescription; - this.portalEventFactory.publishPortletDeletedFromLayoutPortalEvent( + portalEventFactory.publishPortletDeletedFromLayoutPortalEvent( this, - this.owner, + owner, layoutId, parentNodeId, userLayoutChannelDescription.getFunctionalName()); } else { - this.portalEventFactory.publishFolderDeletedFromLayoutPortalEvent( + portalEventFactory.publishFolderDeletedFromLayoutPortalEvent( this, - this.owner, + owner, layoutId, parentNodeId, nodeDescription.getId(), @@ -579,7 +563,7 @@ public synchronized boolean updateNode(IUserLayoutNodeDescription node) throws P updateFolderNode(nodeId, newFolderDesc, oldFolderDesc); } } - this.updateCacheKey(); + updateCacheKey(); return true; } return false; @@ -679,7 +663,7 @@ private void updateNodeAttribute( * Is a change to this attribute allowed? */ FragmentNodeInfo fragNodeInf = - this.distributedLayoutStore.getFragmentNodeInfo(nodeId); + distributedLayoutStore.getFragmentNodeInfo(nodeId); if (fragNodeInf == null) { /* * null should only happen if a node was deleted in the @@ -787,7 +771,7 @@ private void updateChannelNode( Map pubParms = getPublishedChannelParametersMap(newChanDesc.getChannelPublishId()); if (isIncorporated) - fragChanInf = this.distributedLayoutStore.getFragmentChannelInfo(nodeId); + fragChanInf = distributedLayoutStore.getFragmentChannelInfo(nodeId); Map oldParms = new HashMap(oldChanDesc.getParameterMap()); for (Iterator itr = newChanDesc.getParameterMap().entrySet().iterator(); itr.hasNext(); ) { Map.Entry e = (Entry) itr.next(); @@ -911,7 +895,7 @@ private Map getPublishedChannelParametersMap(String channelPublishId) throws Por public boolean canAddNode( IUserLayoutNodeDescription node, String parentId, String nextSiblingId) throws PortalException { - return this.canAddNode(node, this.getNode(parentId), nextSiblingId); + return canAddNode(node, getNode(parentId), nextSiblingId); } protected boolean canAddNode( @@ -980,7 +964,7 @@ protected boolean canAddNode( public boolean canMoveNode(String nodeId, String parentId, String nextSiblingId) throws PortalException { - return this.canMoveNode(this.getNode(nodeId), this.getNode(parentId), nextSiblingId); + return canMoveNode(getNode(nodeId), getNode(parentId), nextSiblingId); } protected boolean canMoveNode( @@ -998,7 +982,7 @@ protected boolean canMoveNode( && canAddNode(node, parent, nextSiblingId); // same parent. which direction are we moving? - Document uld = this.getUserLayoutDOM(); + Document uld = getUserLayoutDOM(); Element parentE = uld.getElementById(parent.getId()); Element child = (Element) parentE.getFirstChild(); int idx = 0; @@ -1058,7 +1042,7 @@ private boolean canMoveLeft(String nodeId, String targetNextSibId) throws Portal } public boolean canDeleteNode(String nodeId) throws PortalException { - return canDeleteNode(this.getNode(nodeId)); + return canDeleteNode(getNode(nodeId)); } /** @@ -1106,7 +1090,7 @@ public void markMoveTargets(String nodeId) throws PortalException { } public String getParentId(String nodeId) throws PortalException { - Document uld = this.getUserLayoutDOM(); + Document uld = getUserLayoutDOM(); Element nelement = uld.getElementById(nodeId); if (nelement != null) { Node parent = nelement.getParentNode(); @@ -1131,7 +1115,7 @@ public String getParentId(String nodeId) throws PortalException { } public String getNextSiblingId(String nodeId) throws PortalException { - Document uld = this.getUserLayoutDOM(); + Document uld = getUserLayoutDOM(); Element nelement = uld.getElementById(nodeId); if (nelement != null) { Node nsibling = nelement.getNextSibling(); @@ -1155,7 +1139,7 @@ public String getNextSiblingId(String nodeId) throws PortalException { } public String getPreviousSiblingId(String nodeId) throws PortalException { - Document uld = this.getUserLayoutDOM(); + Document uld = getUserLayoutDOM(); Element nelement = uld.getElementById(nodeId); if (nelement != null) { Node nsibling = nelement.getPreviousSibling(); @@ -1190,7 +1174,7 @@ private Enumeration getChildIds(String nodeId, boolean visibleOnly) Vector v = new Vector(); IUserLayoutNodeDescription node = getNode(nodeId); if (node instanceof IUserLayoutFolderDescription) { - Document uld = this.getUserLayoutDOM(); + Document uld = getUserLayoutDOM(); Element felement = uld.getElementById(nodeId); for (Node n = felement.getFirstChild(); n != null; n = n.getNextSibling()) { if (n.getNodeType() == Node.ELEMENT_NODE @@ -1211,7 +1195,7 @@ private Enumeration getChildIds(String nodeId, boolean visibleOnly) @Override public String getCacheKey() { - return this.cacheKey; + return cacheKey; } /** @@ -1222,7 +1206,7 @@ public String getCacheKey() { * changes to the user layout are cyclic. */ private void updateCacheKey() { - this.cacheKey = Long.toString(rnd.nextLong()); + cacheKey = Long.toString(rnd.nextLong()); } public int getLayoutId() { @@ -1235,7 +1219,7 @@ public int getLayoutId() { */ @Override public String getSubscribeId(String fname) { - final Document userLayout = this.getUserLayoutDOM(); + final Document userLayout = getUserLayoutDOM(); return new PortletSubscribeIdResolver(fname).traverseDocument(userLayout); } @@ -1244,9 +1228,9 @@ public String getSubscribeId(String parentFolderId, String fname) { variables.put("parentFolderId", parentFolderId); variables.put("fname", fname); - final Document userLayout = this.getUserLayoutDOM(); + final Document userLayout = getUserLayoutDOM(); final Element fnameNode = - this.xpathOperations.evaluate( + xpathOperations.evaluate( "//folder[@ID=$parentFolderId]/descendant::channel[@fname=$fname]", variables, userLayout, @@ -1265,7 +1249,7 @@ public IUserLayout getUserLayout() throws PortalException { // Copied from SimpleLayoutManager since our layouts are regular // simple layouts, ie Documents. return new SimpleLayout( - this.getDistributedUserLayout(), String.valueOf(profile.getLayoutId())); + getDistributedUserLayout(), String.valueOf(profile.getLayoutId())); } /* Returns the ID attribute of the root folder of the layout. This folder @@ -1279,7 +1263,7 @@ public String getRootFolderId() { Document layout = getUserLayoutDOM(); Element rootNode = - this.xpathOperations.evaluate("//layout/folder", layout, XPathConstants.NODE); + xpathOperations.evaluate("//layout/folder", layout, XPathConstants.NODE); if (rootNode == null || !rootNode.getAttribute(Constants.ATT_TYPE) .equals(Constants.ROOT_FOLDER_ID)) { @@ -1290,7 +1274,7 @@ public String getRootFolderId() { resetLayout((String) null); rootNode = - this.xpathOperations.evaluate( + xpathOperations.evaluate( "//layout/folder", layout, XPathConstants.NODE); if (rootNode == null || !rootNode.getAttribute(Constants.ATT_TYPE) @@ -1395,7 +1379,7 @@ private boolean resetLayout(IPerson person) { * isFramentOwner variable in this class since we could be resetting * another user's layout. */ - if (this.distributedLayoutStore.isFragmentOwner(person)) { + if (distributedLayoutStore.isFragmentOwner(person)) { // set template user override so reload of layout comes from // fragment template user person.setAttribute( @@ -1409,15 +1393,11 @@ private boolean resetLayout(IPerson person) { // see if the current user was the one to reset their layout and if // so we need to refresh our local copy of their layout if (person == owner) { - this.layoutCachingService.removeCachedLayout(person, profile); + layoutCachingService.removeCachedLayout(person, profile); updateCacheKey(); getUserLayoutDOM(); } - // if (isFragmentOwner) - // { - // - // store.updateOwnerLayout(person); - // } + layoutWasReset = true; } catch (Exception e) { LOG.error( diff --git a/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/FragmentActivator.java b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/FragmentActivator.java index d0d2097e276..8aa37c1d57a 100644 --- a/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/FragmentActivator.java +++ b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/FragmentActivator.java @@ -52,11 +52,11 @@ public class FragmentActivator { private final LoadingCache> fragmentOwnerLocales = CacheBuilder.newBuilder() - .>build( + .build( new CacheLoader>() { @Override public List load(String key) throws Exception { - return new CopyOnWriteArrayList(); + return new CopyOnWriteArrayList<>(); } }); @@ -239,10 +239,6 @@ public UserView getUserView(final FragmentDefinition fd, final Locale locale) { /** * Saves the loaded layout in the database for the user and profile. - * - * @param view - * @param owner - * @throws Exception */ private void saveLayout(UserView view, IPerson owner) throws Exception { IUserProfile profile = new UserProfile(); @@ -275,8 +271,8 @@ private IPerson bindToOwner(FragmentDefinition fragment) { } private int createOwner(IPerson owner, FragmentDefinition fragment) { - String defaultUser = null; - int userID = -1; + String defaultUser; + int userID; if (fragment.defaultLayoutOwnerID != null) { defaultUser = fragment.defaultLayoutOwnerID; @@ -351,7 +347,7 @@ private void loadLayout( // and will have a hard coded id of 1 which is the default for profiles. // If anyone changes this user all heck could break loose for dlm. :-( - Document layout = null; + Document layout; try { // fix hard coded 1 later for multiple profiles diff --git a/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/RDBMDistributedLayoutStore.java b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/RDBMDistributedLayoutStore.java index 49297c12ed2..2eb65a0a8e1 100644 --- a/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/RDBMDistributedLayoutStore.java +++ b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/RDBMDistributedLayoutStore.java @@ -1246,7 +1246,7 @@ private DistributedUserLayout _getUserLayout(IPerson person, IUserProfile profil final FragmentDefinition ownedFragment = this.fragmentUtils.getFragmentDefinitionByOwner(person); final boolean isLayoutOwnerDefault = this.isLayoutOwnerDefault(person); - final Set fragmentNames = new LinkedHashSet(); + final Set fragmentNames = new LinkedHashSet<>(); final Document ILF; final Document PLF = this.getPLF(person, profile); diff --git a/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/utils/FragmentDefinitionUtils.java b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/utils/FragmentDefinitionUtils.java index 4858709bc6e..e4b29913e88 100644 --- a/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/utils/FragmentDefinitionUtils.java +++ b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/utils/FragmentDefinitionUtils.java @@ -76,48 +76,26 @@ public FragmentDefinition getFragmentDefinitionByOwner(final String ownerId) { @Override public List getFragmentDefinitionsApplicableToPerson(final IPerson person) { - final List result = new ArrayList(); + final List result = new ArrayList<>(); final List definitions = this.configurationLoader.getFragments(); logger.debug("About to check applicability of {} fragments", definitions.size()); - if (definitions != null) { - for (final FragmentDefinition fragmentDefinition : definitions) { - logger.debug( - "Checking applicability of the following fragment: {}", - fragmentDefinition.getName()); - if (fragmentDefinition.isApplicable(person)) { - result.add(fragmentDefinition); - } + for (final FragmentDefinition fragmentDefinition : definitions) { + logger.debug( + "Checking applicability of the following fragment: {}", + fragmentDefinition.getName()); + if (fragmentDefinition.isApplicable(person)) { + result.add(fragmentDefinition); } } - return result; - } - - @Override - public List getFragmentDefinitionUserViews(final Locale locale) { - return this.getFragmentDefinitionUserViews(this.getFragmentDefinitions(), locale); - } - @Override - public List getFragmentDefinitionUserViews( - final List fragmentDefinitions, final Locale locale) { - final List result = new LinkedList(); - if (fragmentDefinitions != null) { - final FragmentActivator activator = this.fragmentActivator; - for (FragmentDefinition definition : fragmentDefinitions) { - final UserView userView = activator.getUserView(definition, locale); - if (userView != null) { - result.add(userView); - } - } - } return result; } @Override public List getFragmentDefinitionUserViewLayouts( final List fragmentDefinitions, final Locale locale) { - final List result = new LinkedList(); + final List result = new LinkedList<>(); final List userViews = this.getFragmentDefinitionUserViews(fragmentDefinitions, locale); for (UserView userView : userViews) { @@ -126,14 +104,9 @@ public List getFragmentDefinitionUserViewLayouts( return result; } - @Override - public Set getFragmentNames() { - return this.getFragmentNames(this.getFragmentDefinitions()); - } - @Override public Set getFragmentNames(final Collection fragmentDefinitions) { - final Set result = new HashSet(fragmentDefinitions.size()); + final Set result = new HashSet<>(fragmentDefinitions.size()); for (FragmentDefinition definition : fragmentDefinitions) { result.add(definition.getName()); } @@ -144,4 +117,19 @@ public Set getFragmentNames(final Collection fragmen public UserView getUserView(final FragmentDefinition fragmentDefinition, final Locale locale) { return this.fragmentActivator.getUserView(fragmentDefinition, locale); } + + private List getFragmentDefinitionUserViews( + final List fragmentDefinitions, final Locale locale) { + final List result = new LinkedList<>(); + if (fragmentDefinitions != null) { + final FragmentActivator activator = this.fragmentActivator; + for (FragmentDefinition definition : fragmentDefinitions) { + final UserView userView = activator.getUserView(definition, locale); + if (userView != null) { + result.add(userView); + } + } + } + return result; + } } diff --git a/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/utils/IFragmentDefinitionUtils.java b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/utils/IFragmentDefinitionUtils.java index 18e4f87f978..73e15dd2f9a 100644 --- a/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/utils/IFragmentDefinitionUtils.java +++ b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/utils/IFragmentDefinitionUtils.java @@ -36,16 +36,9 @@ public interface IFragmentDefinitionUtils { List getFragmentDefinitionsApplicableToPerson(final IPerson person); - List getFragmentDefinitionUserViews(final Locale locale); - - List getFragmentDefinitionUserViews( - final List fragmentDefinitions, final Locale locale); - List getFragmentDefinitionUserViewLayouts( final List fragmentDefinitions, final Locale locale); - Set getFragmentNames(); - Set getFragmentNames(final Collection fragmentDefinitions); UserView getUserView(final FragmentDefinition fragmentDefinition, final Locale locale); diff --git a/uPortal-webapp/src/main/resources/org/jasig/portal/io/import-fragment-definition_v3-1.crn b/uPortal-webapp/src/main/resources/org/jasig/portal/io/import-fragment-definition_v3-1.crn index 7ed9487a51b..2b93851a0f9 100644 --- a/uPortal-webapp/src/main/resources/org/jasig/portal/io/import-fragment-definition_v3-1.crn +++ b/uPortal-webapp/src/main/resources/org/jasig/portal/io/import-fragment-definition_v3-1.crn @@ -19,8 +19,8 @@ --> ${groovy(PORTAL_CONTEXT.getBean('fragmentDefinitionDao'))} - ${valueOf(dlm:fragment/@name)} - + ${valueOf(dlm:fragment/@name)} + From 8acf73ff7df53c173f5ad1df4e7b77df35b223df Mon Sep 17 00:00:00 2001 From: Drew Wills Date: Tue, 23 Jan 2018 09:24:14 -0700 Subject: [PATCH 2/6] UP-4994: Add IUserView abstraction --- .../apereo/portal/layout/dlm/IUserView.java | 44 +++++++++++++++++++ .../apereo/portal/layout/dlm/UserView.java | 9 +++- .../portal/layout/dlm/FragmentActivator.java | 16 +++---- .../dlm/RDBMDistributedLayoutStore.java | 8 ++-- .../portal/utils/FragmentDefinitionUtils.java | 14 +++--- .../utils/IFragmentDefinitionUtils.java | 4 +- 6 files changed, 73 insertions(+), 22 deletions(-) create mode 100644 uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/IUserView.java diff --git a/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/IUserView.java b/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/IUserView.java new file mode 100644 index 00000000000..cbf153be7e1 --- /dev/null +++ b/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/IUserView.java @@ -0,0 +1,44 @@ +/** + * Licensed to Apereo under one or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information regarding copyright ownership. Apereo + * licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the License at the + * following location: + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apereo.portal.layout.dlm; + +import org.w3c.dom.Document; + +/** + * Represents a ready-to-use DLM fragment and supports pluggable strategies for layout content. The + * {@link UserView} class has existed since the dawn of DLM, but this interface is a recent + * addition. Originally DLM supported only one strategy for layout content: the layout owner's + * persisted layout. Refactoring the UserView into an interface-based abstraction + * opens the door to pluggable strategies, such as metadata matching. + * + * @since 5.1 + */ +public interface IUserView { + + int getUserId(); + + Document getLayout(); + + void setLayout(Document layout); + + int getLayoutId(); + + void setLayoutId(int layoutId); + + int getProfileId(); + + void setProfileId(int profileId); + +} diff --git a/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/UserView.java b/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/UserView.java index d1bc6ba159f..5122baf527d 100755 --- a/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/UserView.java +++ b/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/UserView.java @@ -17,7 +17,7 @@ import org.w3c.dom.Document; /** @since 2.5 */ -public class UserView { +public class UserView implements IUserView { private final int userId; private Document layout = null; @@ -28,30 +28,37 @@ public class UserView { this.userId = fragmentOwnerUserId; } + @Override public int getUserId() { return this.userId; } + @Override public Document getLayout() { return layout; } + @Override public void setLayout(Document layout) { this.layout = layout; } + @Override public int getLayoutId() { return layoutId; } + @Override public void setLayoutId(int layoutId) { this.layoutId = layoutId; } + @Override public int getProfileId() { return profileId; } + @Override public void setProfileId(int profileId) { this.profileId = profileId; } diff --git a/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/FragmentActivator.java b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/FragmentActivator.java index 8aa37c1d57a..63fc8bad1ce 100644 --- a/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/FragmentActivator.java +++ b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/FragmentActivator.java @@ -178,7 +178,7 @@ public String toString() { } } - private UserView activateFragment(final UserViewKey userViewKey) { + private IUserView activateFragment(final UserViewKey userViewKey) { final String ownerId = userViewKey.getOwnerId(); final FragmentDefinition fd = configurationLoader.getFragmentByOwnerId(ownerId); @@ -203,7 +203,7 @@ private UserView activateFragment(final UserViewKey userViewKey) { } IPerson owner = bindToOwner(fd); - UserView view = new UserView(owner.getID()); + IUserView view = new UserView(owner.getID()); loadLayout(view, fd, owner, locale); // if owner just created we need to push the layout into @@ -231,16 +231,16 @@ private UserView activateFragment(final UserViewKey userViewKey) { return view; } - public UserView getUserView(final FragmentDefinition fd, final Locale locale) { + public IUserView getUserView(final FragmentDefinition fd, final Locale locale) { final UserViewKey userViewKey = new UserViewKey(fd.getOwnerId(), locale); final net.sf.ehcache.Element userViewElement = this.userViews.get(userViewKey); - return (UserView) userViewElement.getObjectValue(); + return (IUserView) userViewElement.getObjectValue(); } /** * Saves the loaded layout in the database for the user and profile. */ - private void saveLayout(UserView view, IPerson owner) throws Exception { + private void saveLayout(IUserView view, IPerson owner) throws Exception { IUserProfile profile = new UserProfile(); profile.setProfileId(view.getProfileId()); userLayoutStore.setUserLayout(owner, profile, view.getLayout(), true, false); @@ -334,7 +334,7 @@ private int createOwner(IPerson owner, FragmentDefinition fragment) { } private void loadLayout( - UserView view, FragmentDefinition fragment, IPerson owner, Locale locale) { + IUserView view, FragmentDefinition fragment, IPerson owner, Locale locale) { // if fragment not bound to user can't return any layouts. if (view.getUserId() == -1) return; @@ -381,7 +381,7 @@ private void loadLayout( } } - private void loadPreferences(UserView view, FragmentDefinition fragment) { + private void loadPreferences(IUserView view, FragmentDefinition fragment) { // if fragment not bound to user can't return any preferences. if (view.getUserId() == -1) return; @@ -394,7 +394,7 @@ private void loadPreferences(UserView view, FragmentDefinition fragment) { * Removes unwanted and hidden folders, then changes all node ids to their globally safe * incorporated version. */ - private void fragmentizeLayout(UserView view, FragmentDefinition fragment) { + private void fragmentizeLayout(IUserView view, FragmentDefinition fragment) { // if fragment not bound to user or layout empty due to error, return if (view.getUserId() == -1 || view.getLayout() == null) { return; diff --git a/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/RDBMDistributedLayoutStore.java b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/RDBMDistributedLayoutStore.java index 2eb65a0a8e1..bb1c9fc63b0 100644 --- a/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/RDBMDistributedLayoutStore.java +++ b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/RDBMDistributedLayoutStore.java @@ -203,7 +203,7 @@ public Map getFragmentLayoutCopies() { final List definitions = this.fragmentUtils.getFragmentDefinitions(); for (final FragmentDefinition fragmentDefinition : definitions) { final Document layout = DocumentFactory.getThreadDocument(); - final UserView userView = + final IUserView userView = this.fragmentUtils.getUserView(fragmentDefinition, defaultLocale); if (userView == null) { logger.warn( @@ -245,7 +245,7 @@ private IStylesheetUserPreferences loadDistributedStylesheetUserPreferences( this.fragmentUtils.getFragmentDefinitionByName(fragName); // UserView may be missing if the fragment isn't defined correctly - final UserView userView = this.fragmentUtils.getUserView(fragmentDefinition, locale); + final IUserView userView = this.fragmentUtils.getUserView(fragmentDefinition, locale); if (userView == null) { logger.warn( "No UserView is present for fragment {} it will be skipped when loading distributed stylesheet user preferences", @@ -1399,7 +1399,7 @@ private void updateCachedLayout( // Fix later to handle multiple profiles final Element root = layout.getDocumentElement(); - final UserView userView = this.fragmentUtils.getUserView(fragment, locale); + final IUserView userView = this.fragmentUtils.getUserView(fragment, locale); if (userView == null) { throw new IllegalStateException( "No UserView found for fragment: " + fragment.getName()); @@ -1544,7 +1544,7 @@ public FragmentNodeInfo getFragmentNodeInfo(String sId) { if (info == null) { for (final FragmentDefinition fragmentDefinition : fragments) { - final UserView userView = + final IUserView userView = this.fragmentUtils.getUserView(fragmentDefinition, defaultLocale); if (userView == null) { logger.warn( diff --git a/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/utils/FragmentDefinitionUtils.java b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/utils/FragmentDefinitionUtils.java index e4b29913e88..ffedfc5b50e 100644 --- a/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/utils/FragmentDefinitionUtils.java +++ b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/utils/FragmentDefinitionUtils.java @@ -24,7 +24,7 @@ import org.apereo.portal.layout.dlm.ConfigurationLoader; import org.apereo.portal.layout.dlm.FragmentActivator; import org.apereo.portal.layout.dlm.FragmentDefinition; -import org.apereo.portal.layout.dlm.UserView; +import org.apereo.portal.layout.dlm.IUserView; import org.apereo.portal.security.IPerson; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -96,9 +96,9 @@ public List getFragmentDefinitionsApplicableToPerson(final I public List getFragmentDefinitionUserViewLayouts( final List fragmentDefinitions, final Locale locale) { final List result = new LinkedList<>(); - final List userViews = + final List userViews = this.getFragmentDefinitionUserViews(fragmentDefinitions, locale); - for (UserView userView : userViews) { + for (IUserView userView : userViews) { result.add(userView.getLayout()); } return result; @@ -114,17 +114,17 @@ public Set getFragmentNames(final Collection fragmen } @Override - public UserView getUserView(final FragmentDefinition fragmentDefinition, final Locale locale) { + public IUserView getUserView(final FragmentDefinition fragmentDefinition, final Locale locale) { return this.fragmentActivator.getUserView(fragmentDefinition, locale); } - private List getFragmentDefinitionUserViews( + private List getFragmentDefinitionUserViews( final List fragmentDefinitions, final Locale locale) { - final List result = new LinkedList<>(); + final List result = new LinkedList<>(); if (fragmentDefinitions != null) { final FragmentActivator activator = this.fragmentActivator; for (FragmentDefinition definition : fragmentDefinitions) { - final UserView userView = activator.getUserView(definition, locale); + final IUserView userView = activator.getUserView(definition, locale); if (userView != null) { result.add(userView); } diff --git a/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/utils/IFragmentDefinitionUtils.java b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/utils/IFragmentDefinitionUtils.java index 73e15dd2f9a..7aec945c466 100644 --- a/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/utils/IFragmentDefinitionUtils.java +++ b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/utils/IFragmentDefinitionUtils.java @@ -19,7 +19,7 @@ import java.util.Locale; import java.util.Set; import org.apereo.portal.layout.dlm.FragmentDefinition; -import org.apereo.portal.layout.dlm.UserView; +import org.apereo.portal.layout.dlm.IUserView; import org.apereo.portal.security.IPerson; import org.w3c.dom.Document; @@ -41,5 +41,5 @@ List getFragmentDefinitionUserViewLayouts( Set getFragmentNames(final Collection fragmentDefinitions); - UserView getUserView(final FragmentDefinition fragmentDefinition, final Locale locale); + IUserView getUserView(final FragmentDefinition fragmentDefinition, final Locale locale); } From 9bb09a4622130330ed9c4ccc892532ee92f7111f Mon Sep 17 00:00:00 2001 From: Drew Wills Date: Tue, 23 Jan 2018 09:24:52 -0700 Subject: [PATCH 3/6] UP-4994: Add the plumbing for pluggable IUserView implementations --- .../portal/layout/dlm/FragmentDefinition.java | 19 ++++++++++++++++++ .../apereo/portal/layout/dlm/IUserView.java | 6 +++++- ...UserView.java => OwnerLayoutUserView.java} | 20 ++++++++++++------- .../portal/layout/dlm/FragmentActivator.java | 17 +++++++++++++++- 4 files changed, 53 insertions(+), 9 deletions(-) rename uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/{UserView.java => OwnerLayoutUserView.java} (80%) diff --git a/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/FragmentDefinition.java b/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/FragmentDefinition.java index 53ffbed1957..4b0d4a94309 100755 --- a/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/FragmentDefinition.java +++ b/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/FragmentDefinition.java @@ -63,6 +63,14 @@ public class FragmentDefinition extends EvaluatorGroup { @Column(name = "PRECEDENCE") private double precedence = 0.0; // precedence of fragment + /** + * Name of the concrete {@link IUserView} implementation class. Nullable + * + * @since 5.1 + */ + @Column(name = "USER_VIEW") + private String userView; + @Column(name = "DESCRIPTION") private String description; @@ -105,6 +113,7 @@ public void loadFromElement(Element e) { this.ownerID = loadAttribute("ownerID", atts, REQUIRED, e); this.defaultLayoutOwnerID = loadAttribute("defaultLayoutOwnerID", atts, NOT_REQUIRED, e); + this.userView = loadAttribute("userView", atts, NOT_REQUIRED, e); this.description = loadAttribute("description", atts, NOT_REQUIRED, e); String precedence = loadAttribute("precedence", atts, REQUIRED, e); @@ -139,6 +148,16 @@ public double getPrecedence() { return this.precedence; } + /** + * Name of the concrete {@link IUserView} implementation class, or null to use the + * default of {@link OwnerLayoutUserView}. + * + * @since 5.1 + */ + public String getUserView() { + return userView; + } + public String getDescription() { return description; } diff --git a/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/IUserView.java b/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/IUserView.java index cbf153be7e1..6884eb7d5d8 100644 --- a/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/IUserView.java +++ b/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/IUserView.java @@ -18,17 +18,21 @@ /** * Represents a ready-to-use DLM fragment and supports pluggable strategies for layout content. The - * {@link UserView} class has existed since the dawn of DLM, but this interface is a recent + * UserView concept has existed since the dawn of DLM, but this interface is a recent * addition. Originally DLM supported only one strategy for layout content: the layout owner's * persisted layout. Refactoring the UserView into an interface-based abstraction * opens the door to pluggable strategies, such as metadata matching. * + *

Concrete implementations must provide a no-arg constructor. + * * @since 5.1 */ public interface IUserView { int getUserId(); + void setUserId(int userId); + Document getLayout(); void setLayout(Document layout); diff --git a/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/UserView.java b/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/OwnerLayoutUserView.java similarity index 80% rename from uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/UserView.java rename to uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/OwnerLayoutUserView.java index 5122baf527d..72d88db90c7 100755 --- a/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/UserView.java +++ b/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/OwnerLayoutUserView.java @@ -16,23 +16,29 @@ import org.w3c.dom.Document; -/** @since 2.5 */ -public class UserView implements IUserView { +/** + * Strategy for content of a DLM fragment based on the fragment owner's persisted layout. This is + * the original approach to DLM; previous to 5.1, it was the exclusive strategy. + * + * @since 5.1 + */ +public class OwnerLayoutUserView implements IUserView { - private final int userId; + private int userId; private Document layout = null; private int layoutId = 0; private int profileId = 1; - UserView(int fragmentOwnerUserId) { - this.userId = fragmentOwnerUserId; - } - @Override public int getUserId() { return this.userId; } + @Override + public void setUserId(int userId) { + this.userId = userId; + } + @Override public Document getLayout() { return layout; diff --git a/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/FragmentActivator.java b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/FragmentActivator.java index 63fc8bad1ce..88c5053ad8d 100644 --- a/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/FragmentActivator.java +++ b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/FragmentActivator.java @@ -22,9 +22,11 @@ import java.util.Locale; import java.util.concurrent.CopyOnWriteArrayList; import java.util.regex.Pattern; + import net.sf.ehcache.Ehcache; import net.sf.ehcache.constructs.blocking.CacheEntryFactory; import net.sf.ehcache.constructs.blocking.SelfPopulatingCache; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apereo.portal.AuthorizationException; @@ -50,6 +52,8 @@ public class FragmentActivator { private static final String NEWLY_CREATED_ATTR = "newlyCreated"; private static final Log LOG = LogFactory.getLog(FragmentActivator.class); + private static final Class DEFAULT_USER_VIEW = OwnerLayoutUserView.class; + private final LoadingCache> fragmentOwnerLocales = CacheBuilder.newBuilder() .build( @@ -203,7 +207,18 @@ private IUserView activateFragment(final UserViewKey userViewKey) { } IPerson owner = bindToOwner(fd); - IUserView view = new UserView(owner.getID()); + + IUserView view; + try { + Class userViewImpl = StringUtils.isNotBlank(fd.getUserView()) + ? (Class) Class.forName(fd.getUserView()) + : DEFAULT_USER_VIEW; + view = userViewImpl.newInstance(); + } catch (Exception e) { + throw new RuntimeException("Invalid UserView: " + fd.getUserView(), e); + } + + view.setUserId(owner.getID()); loadLayout(view, fd, owner, locale); // if owner just created we need to push the layout into From 9de71be38e5112418502ec6ba12b62a18bf3a4b5 Mon Sep 17 00:00:00 2001 From: Drew Wills Date: Tue, 23 Jan 2018 09:25:39 -0700 Subject: [PATCH 4/6] UP-4994: Add method 'IUserView.getFragmentContentForUser(IPerson user)' and update DLM to call it when building user layouts --- .../apereo/portal/layout/dlm/IUserView.java | 34 +++++++++++++++++++ .../layout/dlm/OwnerLayoutUserView.java | 10 ++++++ .../dlm/RDBMDistributedLayoutStore.java | 2 +- .../portal/utils/FragmentDefinitionUtils.java | 19 +++++------ .../utils/IFragmentDefinitionUtils.java | 2 +- 5 files changed, 55 insertions(+), 12 deletions(-) diff --git a/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/IUserView.java b/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/IUserView.java index 6884eb7d5d8..8912e505dc1 100644 --- a/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/IUserView.java +++ b/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/IUserView.java @@ -14,6 +14,7 @@ */ package org.apereo.portal.layout.dlm; +import org.apereo.portal.security.IPerson; import org.w3c.dom.Document; /** @@ -29,20 +30,53 @@ */ public interface IUserView { + /** + * Obtains the userId (numeric) of the fragment owner account. + */ int getUserId(); + /** + * Updates the userId (numeric) of the fragment owner account. + */ void setUserId(int userId); + /** + * Obtains the "fragmentized" (processed) layout Document of the fragment owner account. + */ Document getLayout(); + /** + * Updates the "fragmentized" (processed) layout Document of the fragment owner account. + */ void setLayout(Document layout); + /** + * Obtains the id of the fragment owner's layout associated with the fragment. + */ int getLayoutId(); + /** + * Updates the id of the fragment owner's layout associated with the fragment. + */ void setLayoutId(int layoutId); + /** + * Obtains the id of the fragment owner's profile associated with the fragment. + */ int getProfileId(); + /** + * Updates the id of the fragment owner's profile associated with the fragment. + */ void setProfileId(int profileId); + /** + * Obtains the content stemming from this fragment that will be applied to the specified user's + * layout. The returned Document may or may not be the same as the value of + * getLayout. + * + * @since 5.1 + */ + Document getFragmentContentForUser(IPerson user); + } diff --git a/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/OwnerLayoutUserView.java b/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/OwnerLayoutUserView.java index 72d88db90c7..02c9313669d 100755 --- a/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/OwnerLayoutUserView.java +++ b/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/OwnerLayoutUserView.java @@ -14,6 +14,7 @@ */ package org.apereo.portal.layout.dlm; +import org.apereo.portal.security.IPerson; import org.w3c.dom.Document; /** @@ -68,4 +69,13 @@ public int getProfileId() { public void setProfileId(int profileId) { this.profileId = profileId; } + + @Override + public Document getFragmentContentForUser(IPerson user) { + /* + * This concrete IUserView implementation represents the "classic" DLM strategy of defining + * fragment content based on the fragment owner's personal layout. + */ + return getLayout(); + } } diff --git a/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/RDBMDistributedLayoutStore.java b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/RDBMDistributedLayoutStore.java index bb1c9fc63b0..1fb2f289fa8 100644 --- a/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/RDBMDistributedLayoutStore.java +++ b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/RDBMDistributedLayoutStore.java @@ -1290,7 +1290,7 @@ private DistributedUserLayout _getUserLayout(IPerson person, IUserProfile profil this.fragmentUtils.getFragmentDefinitionsApplicableToPerson(person); final List applicableLayouts = this.fragmentUtils.getFragmentDefinitionUserViewLayouts( - applicableFragmentDefinitions, locale); + applicableFragmentDefinitions, person, locale); final IntegrationResult integrationResult = new IntegrationResult(); ILF = this.createCompositeILF(person, PLF, applicableLayouts, integrationResult); // push optimizations made during merge back into db. diff --git a/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/utils/FragmentDefinitionUtils.java b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/utils/FragmentDefinitionUtils.java index ffedfc5b50e..eaf6c2e71fc 100644 --- a/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/utils/FragmentDefinitionUtils.java +++ b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/utils/FragmentDefinitionUtils.java @@ -61,23 +61,23 @@ public final List getFragmentDefinitions() { @Override public FragmentDefinition getFragmentDefinitionByName(final String fragmentName) { - return this.configurationLoader.getFragmentByName(fragmentName); + return configurationLoader.getFragmentByName(fragmentName); } @Override public FragmentDefinition getFragmentDefinitionByOwner(final IPerson person) { - return this.getFragmentDefinitionByOwner(person.getUserName()); + return getFragmentDefinitionByOwner(person.getUserName()); } @Override public FragmentDefinition getFragmentDefinitionByOwner(final String ownerId) { - return this.configurationLoader.getFragmentByOwnerId(ownerId); + return configurationLoader.getFragmentByOwnerId(ownerId); } @Override public List getFragmentDefinitionsApplicableToPerson(final IPerson person) { final List result = new ArrayList<>(); - final List definitions = this.configurationLoader.getFragments(); + final List definitions = configurationLoader.getFragments(); logger.debug("About to check applicability of {} fragments", definitions.size()); for (final FragmentDefinition fragmentDefinition : definitions) { @@ -94,12 +94,12 @@ public List getFragmentDefinitionsApplicableToPerson(final I @Override public List getFragmentDefinitionUserViewLayouts( - final List fragmentDefinitions, final Locale locale) { + final List fragmentDefinitions, final IPerson user, final Locale locale) { final List result = new LinkedList<>(); final List userViews = - this.getFragmentDefinitionUserViews(fragmentDefinitions, locale); + getFragmentDefinitionUserViews(fragmentDefinitions, locale); for (IUserView userView : userViews) { - result.add(userView.getLayout()); + result.add(userView.getFragmentContentForUser(user)); } return result; } @@ -115,16 +115,15 @@ public Set getFragmentNames(final Collection fragmen @Override public IUserView getUserView(final FragmentDefinition fragmentDefinition, final Locale locale) { - return this.fragmentActivator.getUserView(fragmentDefinition, locale); + return fragmentActivator.getUserView(fragmentDefinition, locale); } private List getFragmentDefinitionUserViews( final List fragmentDefinitions, final Locale locale) { final List result = new LinkedList<>(); if (fragmentDefinitions != null) { - final FragmentActivator activator = this.fragmentActivator; for (FragmentDefinition definition : fragmentDefinitions) { - final IUserView userView = activator.getUserView(definition, locale); + final IUserView userView = fragmentActivator.getUserView(definition, locale); if (userView != null) { result.add(userView); } diff --git a/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/utils/IFragmentDefinitionUtils.java b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/utils/IFragmentDefinitionUtils.java index 7aec945c466..6824c1a2cb5 100644 --- a/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/utils/IFragmentDefinitionUtils.java +++ b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/utils/IFragmentDefinitionUtils.java @@ -37,7 +37,7 @@ public interface IFragmentDefinitionUtils { List getFragmentDefinitionsApplicableToPerson(final IPerson person); List getFragmentDefinitionUserViewLayouts( - final List fragmentDefinitions, final Locale locale); + final List fragmentDefinitions, final IPerson user, final Locale locale); Set getFragmentNames(final Collection fragmentDefinitions); From 1a6bd642948f5c6f1d50c59c63dfb3246eaf3401 Mon Sep 17 00:00:00 2001 From: Drew Wills Date: Tue, 23 Jan 2018 09:26:22 -0700 Subject: [PATCH 5/6] UP-4994: Introduce IUserViewFactory and make instances Spring-managed beans --- .../portal/layout/dlm/FragmentDefinition.java | 17 +++++----- .../apereo/portal/layout/dlm/IUserView.java | 15 +++++++++ .../portal/layout/dlm/IUserViewFactory.java | 27 ++++++++++++++++ .../portal/layout/dlm/FragmentActivator.java | 27 ++++++++++++---- .../layout/dlm/OwnerLayoutUserView.java | 0 .../dlm/OwnerLayoutUserViewFactory.java | 31 +++++++++++++++++++ .../portal/utils/FragmentDefinitionUtils.java | 8 ++++- 7 files changed, 110 insertions(+), 15 deletions(-) create mode 100644 uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/IUserViewFactory.java rename uPortal-layout/{uPortal-layout-core => uPortal-layout-impl}/src/main/java/org/apereo/portal/layout/dlm/OwnerLayoutUserView.java (100%) create mode 100644 uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/OwnerLayoutUserViewFactory.java diff --git a/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/FragmentDefinition.java b/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/FragmentDefinition.java index 4b0d4a94309..79fd316870f 100755 --- a/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/FragmentDefinition.java +++ b/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/FragmentDefinition.java @@ -64,12 +64,13 @@ public class FragmentDefinition extends EvaluatorGroup { private double precedence = 0.0; // precedence of fragment /** - * Name of the concrete {@link IUserView} implementation class. Nullable + * Name of the concrete factory class that knows how to construct {@link IUserView} objects of + * the appropriate type. Nullable. * * @since 5.1 */ - @Column(name = "USER_VIEW") - private String userView; + @Column(name = "USER_VIEW_FACTORY") + private String userViewFactory; @Column(name = "DESCRIPTION") private String description; @@ -113,7 +114,7 @@ public void loadFromElement(Element e) { this.ownerID = loadAttribute("ownerID", atts, REQUIRED, e); this.defaultLayoutOwnerID = loadAttribute("defaultLayoutOwnerID", atts, NOT_REQUIRED, e); - this.userView = loadAttribute("userView", atts, NOT_REQUIRED, e); + this.userViewFactory = loadAttribute("userViewFactory", atts, NOT_REQUIRED, e); this.description = loadAttribute("description", atts, NOT_REQUIRED, e); String precedence = loadAttribute("precedence", atts, REQUIRED, e); @@ -149,13 +150,13 @@ public double getPrecedence() { } /** - * Name of the concrete {@link IUserView} implementation class, or null to use the - * default of {@link OwnerLayoutUserView}. + * Name of the concrete factory class that knows how to construct {@link IUserView} objects of + * the appropriate type. Nullable. * * @since 5.1 */ - public String getUserView() { - return userView; + public String getUserViewFactory() { + return userViewFactory; } public String getDescription() { diff --git a/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/IUserView.java b/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/IUserView.java index 8912e505dc1..f7c40b1bbb1 100644 --- a/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/IUserView.java +++ b/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/IUserView.java @@ -79,4 +79,19 @@ public interface IUserView { */ Document getFragmentContentForUser(IPerson user); +// Sample XML Output for getFragmentContentForUser() +// +// +// +// +// } diff --git a/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/IUserViewFactory.java b/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/IUserViewFactory.java new file mode 100644 index 00000000000..1b08af593f2 --- /dev/null +++ b/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/IUserViewFactory.java @@ -0,0 +1,27 @@ +/** + * Licensed to Apereo under one or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information regarding copyright ownership. Apereo + * licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the License at the + * following location: + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apereo.portal.layout.dlm; + +/** + * Concrete implementations of this interface know how to create an {@link IUserView} object of the + * appropriate type. Instances of this interface are Spring-managed beans. + * + * @since 5.1 + */ +public interface IUserViewFactory { + + IUserView createUserView(); + +} diff --git a/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/FragmentActivator.java b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/FragmentActivator.java index 88c5053ad8d..1741d0c4693 100644 --- a/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/FragmentActivator.java +++ b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/FragmentActivator.java @@ -18,8 +18,12 @@ import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import java.io.Serializable; +import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Locale; +import java.util.Map; +import java.util.Set; import java.util.concurrent.CopyOnWriteArrayList; import java.util.regex.Pattern; @@ -52,7 +56,7 @@ public class FragmentActivator { private static final String NEWLY_CREATED_ATTR = "newlyCreated"; private static final Log LOG = LogFactory.getLog(FragmentActivator.class); - private static final Class DEFAULT_USER_VIEW = OwnerLayoutUserView.class; + private static final Class DEFAULT_USER_VIEW_FACTORY_CLASS = OwnerLayoutUserViewFactory.class; private final LoadingCache> fragmentOwnerLocales = CacheBuilder.newBuilder() @@ -69,6 +73,7 @@ public List load(String key) throws Exception { private IUserIdentityStore identityStore; private IUserLayoutStore userLayoutStore; private ConfigurationLoader configurationLoader; + private Map,IUserViewFactory> userViewFactories; private static final String PROPERTY_ALLOW_EXPANDED_CONTENT = "org.apereo.portal.layout.dlm.allowExpandedContent"; @@ -128,6 +133,15 @@ public void setUserLayoutStore(IUserLayoutStore userLayoutStore) { this.userLayoutStore = userLayoutStore; } + @Autowired + public void setUserViewFactories(Set userViewFactoryBeans) { + Map,IUserViewFactory> map = new HashMap<>(); + for (IUserViewFactory fac : userViewFactoryBeans) { + map.put(fac.getClass(), fac); + } + userViewFactories = Collections.unmodifiableMap(map); + } + private static class UserViewKey implements Serializable { private static final long serialVersionUID = 1L; private final String ownerId; @@ -210,12 +224,13 @@ private IUserView activateFragment(final UserViewKey userViewKey) { IUserView view; try { - Class userViewImpl = StringUtils.isNotBlank(fd.getUserView()) - ? (Class) Class.forName(fd.getUserView()) - : DEFAULT_USER_VIEW; - view = userViewImpl.newInstance(); + Class userViewFactoryClass = StringUtils.isNotBlank(fd.getUserViewFactory()) + ? (Class) Class.forName(fd.getUserViewFactory()) + : DEFAULT_USER_VIEW_FACTORY_CLASS; + final IUserViewFactory factory = userViewFactories.get(userViewFactoryClass); + view = factory.createUserView(); } catch (Exception e) { - throw new RuntimeException("Invalid UserView: " + fd.getUserView(), e); + throw new RuntimeException("Invalid user view factory class: " + fd.getUserViewFactory(), e); } view.setUserId(owner.getID()); diff --git a/uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/OwnerLayoutUserView.java b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/OwnerLayoutUserView.java similarity index 100% rename from uPortal-layout/uPortal-layout-core/src/main/java/org/apereo/portal/layout/dlm/OwnerLayoutUserView.java rename to uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/OwnerLayoutUserView.java diff --git a/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/OwnerLayoutUserViewFactory.java b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/OwnerLayoutUserViewFactory.java new file mode 100644 index 00000000000..0f44ec96696 --- /dev/null +++ b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/OwnerLayoutUserViewFactory.java @@ -0,0 +1,31 @@ +/** + * Licensed to Apereo under one or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information regarding copyright ownership. Apereo + * licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the License at the + * following location: + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apereo.portal.layout.dlm; + +import org.springframework.stereotype.Component; + +/** + * Creates {@link IUserView} instances that implement the original DLM content strategy based on the + * fragment owner's personal layout. + */ +@Component +public class OwnerLayoutUserViewFactory implements IUserViewFactory { + + @Override + public IUserView createUserView() { + return new OwnerLayoutUserView(); + } + +} diff --git a/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/utils/FragmentDefinitionUtils.java b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/utils/FragmentDefinitionUtils.java index eaf6c2e71fc..1af76cce1ee 100644 --- a/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/utils/FragmentDefinitionUtils.java +++ b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/utils/FragmentDefinitionUtils.java @@ -26,6 +26,7 @@ import org.apereo.portal.layout.dlm.FragmentDefinition; import org.apereo.portal.layout.dlm.IUserView; import org.apereo.portal.security.IPerson; +import org.apereo.portal.xml.XmlUtilitiesImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -99,7 +100,12 @@ public List getFragmentDefinitionUserViewLayouts( final List userViews = getFragmentDefinitionUserViews(fragmentDefinitions, locale); for (IUserView userView : userViews) { - result.add(userView.getFragmentContentForUser(user)); + final Document content = userView.getFragmentContentForUser(user); + if (logger.isDebugEnabled()) { // XmlUtilitiesImpl.toString() is too expensive + logger.debug("UserView with userId='{}' returned the following content for user '{}'\n{}", + userView.getUserId(), user.getUserName(), XmlUtilitiesImpl.toString(content)); + } + result.add(content); } return result; } From f6f79de29765be772a7e29e7453d759de5d187d3 Mon Sep 17 00:00:00 2001 From: Drew Wills Date: Tue, 23 Jan 2018 09:53:02 -0700 Subject: [PATCH 6/6] UP-4994: Beginnings of PluggableBeanUserView and supporting Java types (WIP) --- .../pluggable/IPluggableBeanComponent.java | 29 +++++++++++ .../dlm/pluggable/IPluggableBeanFolder.java | 27 ++++++++++ .../PluggableBeanBasedUserViewFactory.java | 33 ++++++++++++ .../dlm/pluggable/PluggableBeanUserView.java | 50 +++++++++++++++++++ 4 files changed, 139 insertions(+) create mode 100644 uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/pluggable/IPluggableBeanComponent.java create mode 100644 uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/pluggable/IPluggableBeanFolder.java create mode 100644 uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/pluggable/PluggableBeanBasedUserViewFactory.java create mode 100644 uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/pluggable/PluggableBeanUserView.java diff --git a/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/pluggable/IPluggableBeanComponent.java b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/pluggable/IPluggableBeanComponent.java new file mode 100644 index 00000000000..03106b54f7b --- /dev/null +++ b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/pluggable/IPluggableBeanComponent.java @@ -0,0 +1,29 @@ +/** + * Licensed to Apereo under one or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information regarding copyright ownership. Apereo + * licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the License at the + * following location: + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apereo.portal.layout.dlm.pluggable; + +import org.w3c.dom.Node; + +/** + * Beans that implement this interface will be detected by uPortal automatically and used in + * generating content within the {@link PluggableBeanUserView}. + * + * @since 5.1 + */ +public interface IPluggableBeanComponent { + + void addContentToNode(Node parentNode); + +} diff --git a/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/pluggable/IPluggableBeanFolder.java b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/pluggable/IPluggableBeanFolder.java new file mode 100644 index 00000000000..6eedbfe30df --- /dev/null +++ b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/pluggable/IPluggableBeanFolder.java @@ -0,0 +1,27 @@ +/** + * Licensed to Apereo under one or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information regarding copyright ownership. Apereo + * licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the License at the + * following location: + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apereo.portal.layout.dlm.pluggable; + +/** + * Beans that implement this interface will be detected by uPortal automatically and used in + * generating content within the {@link PluggableBeanUserView}. Folders are branch nodes; they may + * contain other folders as well as content objects. + * + * @since 5.1 + */ +public interface IPluggableBeanFolder extends IPluggableBeanComponent { + + +} diff --git a/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/pluggable/PluggableBeanBasedUserViewFactory.java b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/pluggable/PluggableBeanBasedUserViewFactory.java new file mode 100644 index 00000000000..649e9b126c4 --- /dev/null +++ b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/pluggable/PluggableBeanBasedUserViewFactory.java @@ -0,0 +1,33 @@ +/** + * Licensed to Apereo under one or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information regarding copyright ownership. Apereo + * licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the License at the + * following location: + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apereo.portal.layout.dlm.pluggable; + +import org.apereo.portal.layout.dlm.IUserView; +import org.apereo.portal.layout.dlm.IUserViewFactory; + +/** + * This {@link IUserViewFactory} implementation produces instances of + * {@link PluggableBeanUserView} by sharing with them beans from the Spring ApplicationContext + * that they require. + * + * @since 5.1 + */ +public class PluggableBeanBasedUserViewFactory implements IUserViewFactory { + + @Override + public IUserView createUserView() { + return new PluggableBeanUserView(); + } +} diff --git a/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/pluggable/PluggableBeanUserView.java b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/pluggable/PluggableBeanUserView.java new file mode 100644 index 00000000000..878cbeafa0a --- /dev/null +++ b/uPortal-layout/uPortal-layout-impl/src/main/java/org/apereo/portal/layout/dlm/pluggable/PluggableBeanUserView.java @@ -0,0 +1,50 @@ +/** + * Licensed to Apereo under one or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information regarding copyright ownership. Apereo + * licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the License at the + * following location: + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apereo.portal.layout.dlm.pluggable; + +import org.apereo.portal.layout.dlm.IUserView; +import org.apereo.portal.layout.dlm.OwnerLayoutUserView; +import org.apereo.portal.security.IPerson; +import org.w3c.dom.Document; + +/** + * This {@link IUserView} implementation provides fragment content based on Spring-managed beans. + * + * @since 5.1 + */ +public class PluggableBeanUserView extends OwnerLayoutUserView { + + @Override + public Document getFragmentContentForUser(IPerson user) { + throw new UnsupportedOperationException("WIP"); + } + +// Sample XML Output for getFragmentContentForUser() +// +// +// +// +// + +}