Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] UP-4994: Enhance DLM to support pluggable content strategies (beyond 'the content is the layout of the fragment owner') #1120

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void importData(Tuple<String, Document> data) {
fragmentDefinition = new FragmentDefinition(fragmentDefElement);
}

fragmentDefinition.loadFromEelement(fragmentDefElement);
fragmentDefinition.loadFromElement(fragmentDefElement);

this.fragmentDefinitionDao.updateFragmentDefinition(fragmentDefinition);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Tuple<String, String>, Document> layoutCache);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ public class FragmentDefinition extends EvaluatorGroup {
@Column(name = "PRECEDENCE")
private double precedence = 0.0; // precedence of fragment

/**
* 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_FACTORY")
private String userViewFactory;

@Column(name = "DESCRIPTION")
private String description;

Expand Down Expand Up @@ -94,17 +103,18 @@ 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;

NamedNodeMap atts = e.getAttributes();

this.ownerID = loadAttribute("ownerID", atts, REQUIRED, e);
this.defaultLayoutOwnerID = loadAttribute("defaultLayoutOwnerID", 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);
Expand Down Expand Up @@ -139,6 +149,16 @@ public double getPrecedence() {
return this.precedence;
}

/**
* Name of the concrete factory class that knows how to construct {@link IUserView} objects of
* the appropriate type. Nullable.
*
* @since 5.1
*/
public String getUserViewFactory() {
return userViewFactory;
}

public String getDescription() {
return description;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/**
* 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:
*
* <p>http://www.apache.org/licenses/LICENSE-2.0
*
* <p>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.apereo.portal.security.IPerson;
import org.w3c.dom.Document;

/**
* Represents a ready-to-use DLM fragment and supports pluggable strategies for layout content. The
* 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 <code>UserView</code> into an interface-based abstraction
* opens the door to pluggable strategies, such as metadata matching.
*
* <p>Concrete implementations must provide a no-arg constructor.
*
* @since 5.1
*/
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 <code>Document</code> may or may not be the same as the value of
* <code>getLayout</code>.
*
* @since 5.1
*/
Document getFragmentContentForUser(IPerson user);

// Sample XML Output for getFragmentContentForUser()
//
// <?xml version="1.0"?>
// <layout xmlns:dlm="http://www.uportal.org/layout/dlm" ID="u25l1">
// <folder ID="u25l1s1" dlm:fragment="0" dlm:precedence="80.0" hidden="false" immutable="false" locale="en_US" name="Root folder" type="root" unremovable="true">
// <folder ID="u25l1s100" dlm:fragment="0" dlm:precedence="80.0" hidden="false" immutable="true" locale="en_US" name="Page Top folder" type="page-top" unremovable="true">
// <channel ID="u25l1n110" chanID="41" description="Compiles Bootstrap LESS dynamically, allowing administrators to make some skin configuration choices in a UI. Supports the optional 'dynamic' strategy for Respondr." dlm:fragment="0" dlm:precedence="80.0" fname="dynamic-respondr-skin" hidden="false" immutable="false" locale="en_US" name="Dynamic Respondr Skin" timeout="30000" title="Dynamic Respondr Skin" typeID="3" unremovable="false">
// <parameter name="mobileIconUrl" value="/ResourceServingWebapp/rs/tango/0.8.90/32x32/apps/preferences-desktop-theme.png"/>
// <parameter name="iconUrl" value="/ResourceServingWebapp/rs/tango/0.8.90/32x32/apps/preferences-desktop-theme.png"/>
// <parameter name="disableDynamicTitle" value="true"/>
// <parameter name="configurable" value="true"/>
// </channel>
// </folder>
// </folder>
// </layout>
}
Original file line number Diff line number Diff line change
@@ -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:
*
* <p>http://www.apache.org/licenses/LICENSE-2.0
*
* <p>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();

}
Loading