use of org.apereo.portal.layout.dlm.FragmentDefinition in project uPortal by Jasig.
the class FragmentDefinitionExporter method exportDataElement.
/* (non-Javadoc)
* @see org.apereo.portal.io.xml.crn.AbstractDom4jExporter#exportDataElement(java.lang.String)
*/
@Override
protected Element exportDataElement(String id) {
final FragmentDefinition fragmentDefinition = fragmentDefinitionDao.getFragmentDefinition(id);
if (fragmentDefinition == null) {
return null;
}
final org.dom4j.Document fragmentDefDoc = new org.dom4j.DocumentFactory().createDocument();
final Element fragmentDefElement = fragmentDefDoc.addElement("fragment-definition");
fragmentDefElement.addNamespace("dlm", Constants.NS_URI);
fragmentDefElement.addAttribute("script", "classpath://org/jasig/portal/io/import-fragment-definition_v3-1.crn");
fragmentDefinition.toElement(fragmentDefElement);
return fragmentDefElement;
}
use of org.apereo.portal.layout.dlm.FragmentDefinition in project uPortal by Jasig.
the class LayoutsDataFunction method apply.
@Override
public Iterable<? extends IPortalData> apply(IPortalDataType input) {
final List<FragmentDefinition> fragments = this.configurationLoader.getFragments();
final Set<String> fragmentOwners = new LinkedHashSet<String>();
for (final FragmentDefinition fragmentDefinition : fragments) {
fragmentOwners.add(fragmentDefinition.getOwnerId());
}
final List<String> userList = this.jdbcOperations.queryForList("SELECT USER_NAME FROM UP_USER WHERE USER_NAME NOT IN (:userNames)", Collections.singletonMap("userNames", fragmentOwners), String.class);
return Lists.transform(userList, new Function<String, IPortalData>() {
@Override
public IPortalData apply(final String userName) {
return new SimpleStringPortalData(userName, null, null);
}
});
}
use of org.apereo.portal.layout.dlm.FragmentDefinition in project uPortal by Jasig.
the class FragmentListController method listFragments.
/**
* Returns a model of fragments --> List<FragmentBean> , sorted by precedence (default) or by
* fragment name depending on sort parameter, to be rendered by the jsonView.
*
* @param req the servlet request, bound via SpringWebMVC to GET method invocations of this
* controller.
* @param sortParam PRECEDENCE, NAME, or null.
* @return ModelAndView with a List of FragmentBeans to be rendered by the jsonView.
* @throws ServletException on Exception in underlying attempt to get at the fragments
* @throws AuthorizationException if request is for any user other than a Portal Administrator.
* @throws IllegalArgumentException if sort parameter has an unrecognized value
*/
@RequestMapping(method = RequestMethod.GET)
public ModelAndView listFragments(HttpServletRequest req, @RequestParam(value = "sort", required = false) String sortParam) throws ServletException {
// Verify that the user is allowed to use this service
IPerson user = personManager.getPerson(req);
if (!AdminEvaluator.isAdmin(user)) {
throw new AuthorizationException("User " + user.getUserName() + " not an administrator.");
}
Map<String, Document> fragmentLayoutMap = null;
if (userLayoutStore != null) {
try {
fragmentLayoutMap = userLayoutStore.getFragmentLayoutCopies();
} catch (Exception e) {
String msg = "Failed to access fragment layouts";
log.error(msg, e);
throw new ServletException(msg, e);
}
}
List<FragmentBean> fragments = new ArrayList<FragmentBean>();
for (FragmentDefinition frag : dlmConfig.getFragments()) {
Document layout = fragmentLayoutMap != null ? fragmentLayoutMap.get(frag.getOwnerId()) : null;
List<String> portlets = null;
if (layout != null) {
portlets = new ArrayList<String>();
NodeList channelFNames = this.xpathOperations.evaluate(CHANNEL_FNAME_XPATH, layout, XPathConstants.NODESET);
for (int i = 0; i < channelFNames.getLength(); i++) {
String fname = channelFNames.item(i).getTextContent();
IPortletDefinition pDef = portletRegistry.getPortletDefinitionByFname(fname);
if (null != pDef) {
portlets.add(pDef.getTitle());
}
}
}
fragments.add(FragmentBean.create(frag, portlets));
}
// Determine & follow sorting preference...
Sort sort = DEFAULT_SORT;
if (sortParam != null) {
sort = Sort.valueOf(sortParam);
}
Collections.sort(fragments, sort.getComparator());
return new ModelAndView("jsonView", "fragments", fragments);
}
use of org.apereo.portal.layout.dlm.FragmentDefinition in project uPortal by Jasig.
the class FragmentDefinitionUtils method getFragmentDefinitionsApplicableToPerson.
@Override
public List<FragmentDefinition> getFragmentDefinitionsApplicableToPerson(final IPerson person) {
final List<FragmentDefinition> result = new ArrayList<FragmentDefinition>();
final List<FragmentDefinition> 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);
}
}
}
return result;
}
Aggregations