Search in sources :

Example 76 with IPortletDefinition

use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.

the class PortletsRESTController method getManageablePortlets.

/**
 * Provides information about all portlets in the portlet registry. NOTE: The response is
 * governed by the <code>IPermission.PORTLET_MANAGER_xyz</code> series of permissions. The
 * actual level of permission required is based on the current lifecycle state of the portlet.
 */
@RequestMapping(value = "/portlets.json", method = RequestMethod.GET)
public ModelAndView getManageablePortlets(HttpServletRequest request, HttpServletResponse response) throws Exception {
    // get a list of all channels
    List<IPortletDefinition> allPortlets = portletDefinitionRegistry.getAllPortletDefinitions();
    IAuthorizationPrincipal ap = getAuthorizationPrincipal(request);
    List<PortletTuple> rslt = new ArrayList<PortletTuple>();
    for (IPortletDefinition pdef : allPortlets) {
        if (ap.canManage(pdef.getPortletDefinitionId().getStringId())) {
            rslt.add(new PortletTuple(pdef));
        }
    }
    return new ModelAndView("json", "portlets", rslt);
}
Also used : IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 77 with IPortletDefinition

use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.

the class PortletsSearchStrategy method search.

@Override
public List<?> search(String query, HttpServletRequest request) {
    final List<Object> rslt = new ArrayList<>();
    final List<IPortletDefinition> portlets = portletDefinitionRegistry.getAllPortletDefinitions();
    for (IPortletDefinition portlet : portlets) {
        if (portletRegistryUtil.matches(query, portlet)) {
            /* requester permissions checked in buildPortletUrl() */
            final String url = portletRegistryUtil.buildPortletUrl(request, portlet);
            if (url != null) {
                rslt.add(getPortletAttrs(portlet, url));
            }
        }
    }
    return rslt;
}
Also used : ArrayList(java.util.ArrayList) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 78 with IPortletDefinition

use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.

the class PortletDefinitionSearcher method searchForEntities.

// Internal search, so shouldn't be called as case insensitive.
@Override
public EntityIdentifier[] searchForEntities(String query, SearchMethod method) throws GroupsException {
    boolean allowPartial = true;
    switch(method) {
        case DISCRETE:
            allowPartial = false;
            break;
        case STARTS_WITH:
            query = query + "%";
            break;
        case ENDS_WITH:
            query = "%" + query;
            break;
        case CONTAINS:
            query = "%" + query + "%";
            break;
        default:
            throw new GroupsException("Unknown search type");
    }
    // get the list of matching portlet definitions
    final List<IPortletDefinition> definitions = this.portletDefinitionRegistry.searchForPortlets(query, allowPartial);
    if (log.isDebugEnabled()) {
        log.debug("Found " + definitions.size() + " matching definitions for query " + query);
    }
    // initialize an appropriately-sized array of EntityIdentifiers
    final EntityIdentifier[] identifiers = new EntityIdentifier[definitions.size()];
    // add an identifier for each matching portlet
    for (final ListIterator<IPortletDefinition> defIter = definitions.listIterator(); defIter.hasNext(); ) {
        final IPortletDefinition definition = defIter.next();
        identifiers[defIter.previousIndex()] = new EntityIdentifier(definition.getPortletDefinitionId().getStringId(), this.getType());
    }
    return identifiers;
}
Also used : GroupsException(org.apereo.portal.groups.GroupsException) EntityIdentifier(org.apereo.portal.EntityIdentifier) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 79 with IPortletDefinition

use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.

the class GetMemberKeyPhrase method getPhrase.

// Internal search, thus case sensitive.
public static String getPhrase(String name, String memberValue) {
    String rslt = null;
    // We can cut & run now if the element is a <literal>...
    if (name.equals("literal")) {
        return memberValue;
    }
    try {
        // Next see if it's a <channel> element...
        if (name.equals("channel")) {
            IPortletDefinition def = PortletDefinitionRegistryLocator.getPortletDefinitionRegistry().getPortletDefinitionByFname(memberValue);
            return String.valueOf(def.getPortletDefinitionId().getStringId());
        }
        // Must be a group...
        Class[] leafTypes = new Class[] { IPerson.class, IPortletDefinition.class };
        for (int i = 0; i < leafTypes.length && rslt == null; i++) {
            EntityIdentifier[] eis = GroupService.searchForGroups(memberValue, IGroupConstants.SearchMethod.DISCRETE, leafTypes[i]);
            if (eis.length == 1) {
                // Match!
                IEntityGroup g = GroupService.findGroup(eis[0].getKey());
                rslt = g.getLocalKey();
                break;
            } else if (eis.length > 1) {
                String msg = "Ambiguous member name:  " + memberValue;
                throw new RuntimeException(msg);
            }
        }
    } catch (Throwable t) {
        String msg = "Error looking up the specified member:  " + memberValue;
        throw new RuntimeException(msg, t);
    }
    if (rslt == null) {
        String msg = "The specified member was not found:  " + memberValue;
        throw new RuntimeException(msg);
    }
    return rslt;
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) IPerson(org.apereo.portal.security.IPerson) EntityIdentifier(org.apereo.portal.EntityIdentifier) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 80 with IPortletDefinition

use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.

the class PortletDefinitionImporterExporter method importData.

@Transactional
@Override
public void importData(ExternalPortletDefinition portletRep) {
    final IPortletDefinition def = portletDefinitionUnmarshaller.unmarshall(portletRep);
    final List<PortletCategory> categories = new ArrayList<>();
    for (String categoryName : portletRep.getCategories()) {
        // Import/Export function, thus the group search is case sensitive.
        EntityIdentifier[] cats = GroupService.searchForGroups(categoryName, IGroupConstants.SearchMethod.DISCRETE, IPortletDefinition.class);
        PortletCategory category;
        if (cats != null && cats.length > 0) {
            category = portletCategoryRegistry.getPortletCategory(cats[0].getKey());
        } else {
            category = portletCategoryRegistry.getPortletCategory(categoryName);
        }
        if (category == null) {
            throw new IllegalArgumentException("No category '" + categoryName + "' found when importing portlet: " + portletRep.getFname());
        }
        categories.add(category);
    }
    final String fname = portletRep.getFname();
    final Map<ExternalPermissionDefinition, Set<IGroupMember>> permissions = new HashMap<>();
    final Set<IGroupMember> subscribeMembers = toGroupMembers(portletRep.getGroups(), fname);
    permissions.put(ExternalPermissionDefinition.SUBSCRIBE, subscribeMembers);
    if (portletRep.getPermissions() != null && portletRep.getPermissions().getPermissions() != null) {
        for (ExternalPermissionMemberList perm : portletRep.getPermissions().getPermissions()) {
            Set<IGroupMember> members = toGroupMembers(perm.getGroups(), fname);
            ExternalPermissionDefinition permDef = toExternalPermissionDefinition(perm.getSystem(), perm.getActivity());
            if (permissions.containsKey(permDef)) {
                permissions.get(permDef).addAll(members);
            } else {
                permissions.put(permDef, members);
            }
        }
    }
    savePortletDefinition(def, categories, permissions);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EntityIdentifier(org.apereo.portal.EntityIdentifier) IGroupMember(org.apereo.portal.groups.IGroupMember) ExternalPermissionDefinition(org.apereo.portal.io.xml.portlettype.ExternalPermissionDefinition) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) PortletCategory(org.apereo.portal.portlet.om.PortletCategory) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)109 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)24 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)22 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)17 ArrayList (java.util.ArrayList)16 IPortletDefinitionId (org.apereo.portal.portlet.om.IPortletDefinitionId)14 HashSet (java.util.HashSet)13 IPerson (org.apereo.portal.security.IPerson)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 PortletCategory (org.apereo.portal.portlet.om.PortletCategory)12 EntityIdentifier (org.apereo.portal.EntityIdentifier)11 IUserLayoutManager (org.apereo.portal.layout.IUserLayoutManager)9 HashMap (java.util.HashMap)8 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)8 IPortletDefinitionParameter (org.apereo.portal.portlet.om.IPortletDefinitionParameter)7 IPortletPreference (org.apereo.portal.portlet.om.IPortletPreference)7 IUserInstance (org.apereo.portal.user.IUserInstance)7 Locale (java.util.Locale)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 PortletDefinition (org.apache.pluto.container.om.portlet.PortletDefinition)6