Search in sources :

Example 1 with PortletDescriptor

use of org.apereo.portal.xml.PortletDescriptor in project uPortal by Jasig.

the class PortletAdministrationHelper method offerPortletSelection.

public boolean offerPortletSelection(PortletDefinitionForm form) {
    final IPortletType portletType = this.portletTypeRegistry.getPortletType(form.getTypeId());
    final PortletPublishingDefinition portletPublishingDefinition = this.portletPublishingDefinitionDao.getChannelPublishingDefinition(portletType.getId());
    final PortletDescriptor portletDescriptor = portletPublishingDefinition.getPortletDescriptor();
    if (portletDescriptor == null) {
        return true;
    }
    final Boolean isFramework = portletDescriptor.isIsFramework();
    if (isFramework != null && isFramework) {
        form.setFramework(isFramework);
    } else {
        final String webAppName = portletDescriptor.getWebAppName();
        form.setApplicationId(webAppName);
    }
    final String portletName = portletDescriptor.getPortletName();
    form.setPortletName(portletName);
    return false;
}
Also used : PortletDescriptor(org.apereo.portal.xml.PortletDescriptor) IPortletType(org.apereo.portal.portlet.om.IPortletType) PortletPublishingDefinition(org.apereo.portal.portletpublishing.xml.PortletPublishingDefinition)

Example 2 with PortletDescriptor

use of org.apereo.portal.xml.PortletDescriptor in project uPortal by Jasig.

the class PortletDefinitionImporterExporter method convert.

protected ExternalPortletDefinition convert(IPortletDefinition def) {
    ExternalPortletDefinition rep = new ExternalPortletDefinition();
    rep.setFname(def.getFName());
    rep.setDesc(def.getDescription());
    rep.setName(def.getName());
    rep.setTimeout(BigInteger.valueOf(def.getTimeout()));
    rep.setActionTimeout(convertToBigInteger(def.getActionTimeout()));
    rep.setEventTimeout(convertToBigInteger(def.getEventTimeout()));
    rep.setRenderTimeout(convertToBigInteger(def.getRenderTimeout()));
    rep.setResourceTimeout(convertToBigInteger(def.getResourceTimeout()));
    rep.setTitle(def.getTitle());
    rep.setType(def.getType().getName());
    if (def.getLifecycleState().isEqualToOrAfter(PortletLifecycleState.APPROVED)) {
        Lifecycle lifecycle = new Lifecycle();
        LifecycleEntry approved = new LifecycleEntry();
        approved.setUser(getUsernameForUserId(def.getApproverId()));
        approved.setValue(getCalendar(def.getApprovalDate()));
        lifecycle.setApproved(approved);
        if (def.getLifecycleState().isEqualToOrAfter(PortletLifecycleState.PUBLISHED)) {
            LifecycleEntry published = new LifecycleEntry();
            published.setUser(getUsernameForUserId(def.getPublisherId()));
            published.setValue(getCalendar(def.getPublishDate()));
            lifecycle.setPublished(published);
        }
        /* An EXPIRED record in the lifecycle history requires two things:
             *   - Current lifecycle state >= EXPIRED
             *   - An expiration date
             */
        if (def.getLifecycleState().isEqualToOrAfter(PortletLifecycleState.EXPIRED) && def.getExpirationDate() != null) {
            LifecycleEntry expired = new LifecycleEntry();
            expired.setUser(getUsernameForUserId(def.getExpirerId()));
            expired.setValue(getCalendar(def.getExpirationDate()));
            lifecycle.setExpiration(expired);
        }
        // Maintenance mode is handled via a portlet publishing parameter and not a lifecycle
        rep.setLifecycle(lifecycle);
    }
    final org.apereo.portal.xml.PortletDescriptor portletDescriptor = new org.apereo.portal.xml.PortletDescriptor();
    final IPortletDescriptorKey portletDescriptorKey = def.getPortletDescriptorKey();
    if (portletDescriptorKey.isFrameworkPortlet()) {
        portletDescriptor.setIsFramework(true);
    } else {
        portletDescriptor.setWebAppName(portletDescriptorKey.getWebAppName());
    }
    portletDescriptor.setPortletName(portletDescriptorKey.getPortletName());
    rep.setPortletDescriptor(portletDescriptor);
    final List<ExternalPortletParameter> parameterList = rep.getParameters();
    for (IPortletDefinitionParameter param : def.getParameters()) {
        final ExternalPortletParameter externalPortletParameter = new ExternalPortletParameter();
        externalPortletParameter.setName(param.getName());
        externalPortletParameter.setDescription(param.getDescription());
        externalPortletParameter.setValue(param.getValue());
        parameterList.add(externalPortletParameter);
    }
    Collections.sort(parameterList, ExternalPortletParameterNameComparator.INSTANCE);
    final List<ExternalPortletPreference> portletPreferenceList = rep.getPortletPreferences();
    for (IPortletPreference pref : def.getPortletPreferences()) {
        final ExternalPortletPreference externalPortletPreference = new ExternalPortletPreference();
        externalPortletPreference.setName(pref.getName());
        externalPortletPreference.setReadOnly(pref.isReadOnly());
        final List<String> value = externalPortletPreference.getValues();
        value.addAll(Arrays.asList(pref.getValues()));
        //no sorting of preference values, order is specified by the portlet
        portletPreferenceList.add(externalPortletPreference);
    }
    Collections.sort(portletPreferenceList, ExternalPortletPreferenceNameComparator.INSTANCE);
    final List<String> categoryList = rep.getCategories();
    final IGroupMember gm = GroupService.getGroupMember(def.getPortletDefinitionId().getStringId(), IPortletDefinition.class);
    @SuppressWarnings("unchecked") final Iterator<IEntityGroup> categories = GroupService.getCompositeGroupService().findParentGroups(gm);
    while (categories.hasNext()) {
        IEntityGroup category = categories.next();
        categoryList.add(category.getName());
    }
    Collections.sort(categoryList);
    // handle the SUBSCRIBER_ACTIVITY perm separately...
    final List<String> groupList = rep.getGroups();
    final List<String> userList = rep.getUsers();
    exportPermission(def, ExternalPermissionDefinition.SUBSCRIBE, groupList, userList);
    // handle other supported perms (currently just BROWSE)
    ExternalPermissions externalPermissions = new ExternalPermissions();
    for (ExternalPermissionDefinition perm : ExternalPermissionDefinition.values()) {
        if (!perm.getExportForPortletDef()) {
            continue;
        }
        ExternalPermissionMemberList members = new ExternalPermissionMemberList();
        members.setSystem(perm.getSystem());
        members.setActivity(perm.getActivity());
        List<String> groups = members.getGroups();
        boolean found = exportPermission(def, perm, groups, null);
        if (found) {
            externalPermissions.getPermissions().add(members);
        }
    }
    if (!externalPermissions.getPermissions().isEmpty()) {
        rep.setPermissions(externalPermissions);
    }
    return rep;
}
Also used : IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) IPortletDescriptorKey(org.apereo.portal.portlet.om.IPortletDescriptorKey) PortletDescriptor(org.apereo.portal.xml.PortletDescriptor) IPortletDefinitionParameter(org.apereo.portal.portlet.om.IPortletDefinitionParameter) ExternalPermissionDefinition(org.apereo.portal.io.xml.portlettype.ExternalPermissionDefinition) PortletDescriptor(org.apereo.portal.xml.PortletDescriptor) IEntityGroup(org.apereo.portal.groups.IEntityGroup) IGroupMember(org.apereo.portal.groups.IGroupMember)

Example 3 with PortletDescriptor

use of org.apereo.portal.xml.PortletDescriptor in project uPortal by Jasig.

the class PortletDefinitionImporterExporter method importData.

@Transactional
@Override
public void importData(ExternalPortletDefinition portletRep) {
    final PortletDescriptor portletDescriptor = portletRep.getPortletDescriptor();
    final Boolean isFramework = portletDescriptor.isIsFramework();
    if (isFramework != null && isFramework && "UPGRADED_CHANNEL_IS_NOT_A_PORTLET".equals(portletDescriptor.getPortletName())) {
        if (errorOnChannel) {
            throw new IllegalArgumentException(portletRep.getFname() + " is not a portlet. It was likely an IChannel from a previous version of uPortal and cannot be imported.");
        }
        logger.warn(portletRep.getFname() + " is not a portlet. It was likely an IChannel from a previous version of uPortal and will not be imported.");
        return;
    }
    // get the portlet type
    final IPortletType portletType = portletTypeRegistry.getPortletType(portletRep.getType());
    if (portletType == null) {
        throw new IllegalArgumentException("No portlet type registered for: " + portletRep.getType());
    }
    final List<PortletCategory> categories = new ArrayList<PortletCategory>();
    for (String categoryName : portletRep.getCategories()) {
        EntityIdentifier[] cats = GroupService.searchForGroups(categoryName, IGroupConstants.IS, IPortletDefinition.class);
        PortletCategory category = null;
        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);
            }
        }
    }
    IPortletDefinition def = portletDefinitionDao.getPortletDefinitionByFname(fname);
    if (def == null) {
        def = new PortletDefinitionImpl(portletType, fname, portletRep.getName(), portletRep.getTitle(), portletDescriptor.getWebAppName(), portletDescriptor.getPortletName(), isFramework != null ? isFramework : false);
    } else {
        final IPortletDescriptorKey portletDescriptorKey = def.getPortletDescriptorKey();
        portletDescriptorKey.setPortletName(portletDescriptor.getPortletName());
        if (isFramework != null && isFramework) {
            portletDescriptorKey.setFrameworkPortlet(true);
            portletDescriptorKey.setWebAppName(null);
        } else {
            portletDescriptorKey.setFrameworkPortlet(false);
            portletDescriptorKey.setWebAppName(portletDescriptor.getWebAppName());
        }
        def.setName(portletRep.getName());
        def.setTitle(portletRep.getTitle());
        def.setType(portletType);
    }
    def.setDescription(portletRep.getDesc());
    final BigInteger timeout = portletRep.getTimeout();
    if (timeout != null) {
        def.setTimeout(timeout.intValue());
    }
    final BigInteger actionTimeout = portletRep.getActionTimeout();
    if (actionTimeout != null) {
        def.setActionTimeout(actionTimeout.intValue());
    }
    final BigInteger eventTimeout = portletRep.getEventTimeout();
    if (eventTimeout != null) {
        def.setEventTimeout(eventTimeout.intValue());
    }
    final BigInteger renderTimeout = portletRep.getRenderTimeout();
    if (renderTimeout != null) {
        def.setRenderTimeout(renderTimeout.intValue());
    }
    final BigInteger resourceTimeout = portletRep.getResourceTimeout();
    if (resourceTimeout != null) {
        def.setResourceTimeout(resourceTimeout.intValue());
    }
    handleLifecycleApproval(def, portletRep.getLifecycle());
    handleLifecyclePublished(def, portletRep.getLifecycle());
    handleLifecycleExpired(def, portletRep.getLifecycle());
    final Set<IPortletDefinitionParameter> parameters = new LinkedHashSet<IPortletDefinitionParameter>();
    for (ExternalPortletParameter param : portletRep.getParameters()) {
        parameters.add(new PortletDefinitionParameterImpl(param.getName(), param.getValue()));
    }
    def.setParameters(parameters);
    final ArrayList<IPortletPreference> preferenceList = new ArrayList<IPortletPreference>();
    for (ExternalPortletPreference pref : portletRep.getPortletPreferences()) {
        final List<String> valueList = pref.getValues();
        final String[] values = valueList.toArray(new String[valueList.size()]);
        final Boolean readOnly = pref.isReadOnly();
        preferenceList.add(new PortletPreferenceImpl(pref.getName(), readOnly != null ? readOnly : false, values));
    }
    def.setPortletPreferences(preferenceList);
    savePortletDefinition(def, systemUser, categories, permissions);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EntityIdentifier(org.apereo.portal.EntityIdentifier) IPortletDescriptorKey(org.apereo.portal.portlet.om.IPortletDescriptorKey) PortletDescriptor(org.apereo.portal.xml.PortletDescriptor) IPortletDefinitionParameter(org.apereo.portal.portlet.om.IPortletDefinitionParameter) ExternalPermissionDefinition(org.apereo.portal.io.xml.portlettype.ExternalPermissionDefinition) PortletPreferenceImpl(org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl) PortletCategory(org.apereo.portal.portlet.om.PortletCategory) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) IGroupMember(org.apereo.portal.groups.IGroupMember) IPortletType(org.apereo.portal.portlet.om.IPortletType) BigInteger(java.math.BigInteger) PortletDefinitionImpl(org.apereo.portal.portlet.dao.jpa.PortletDefinitionImpl) PortletDefinitionParameterImpl(org.apereo.portal.portlet.dao.jpa.PortletDefinitionParameterImpl) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with PortletDescriptor

use of org.apereo.portal.xml.PortletDescriptor in project uPortal by Jasig.

the class PortletDefinitionForm method setChannelPublishingDefinition.

/**
     * Sets the Java class name and parameter defaults based on the PortletPublishingDefinition.
     *
     * @param cpd
     */
public void setChannelPublishingDefinition(PortletPublishingDefinition cpd) {
    // portlet, the applicationId is /uPortal.
    if (cpd.getPortletDescriptor() != null) {
        final PortletDescriptor pDesc = cpd.getPortletDescriptor();
        // PortletDescriptor is a class generated from XSD.  The value of
        // isIsFramework() will commonly be null.
        final boolean isFramework = pDesc.isIsFramework() != null ? pDesc.isIsFramework() : false;
        applicationId = isFramework ? FRAMEWORK_PORTLET_URL : pDesc.getWebAppName();
        portletName = pDesc.getPortletName();
    }
    // set default values for all portlet parameters
    for (Step step : cpd.getSteps()) {
        if (step.getParameters() != null) {
            for (Parameter param : step.getParameters()) {
                // if this parameter doesn't currently have a value, check
                // for a default in the CPD
                Attribute attribute = this.parameters.get(param.getName());
                if (attribute == null || attribute.getValue() == null || attribute.getValue().trim().equals("")) {
                    // use the default value if one exists
                    ParameterInputType input = param.getParameterInput().getValue();
                    if (input != null) {
                        this.parameters.put(param.getName(), new Attribute(input.getDefault()));
                    }
                }
            }
        }
        if (step.getPreferences() != null) {
            for (Preference pref : step.getPreferences()) {
                // for a default in the CPD
                if (!this.portletPreferences.containsKey(pref.getName()) || this.portletPreferences.get(pref.getName()).getValue().size() == 0 || (this.portletPreferences.get(pref.getName()).getValue().size() == 1 && this.portletPreferences.get(pref.getName()).getValue().get(0).trim().equals(""))) {
                    if (!this.portletPreferences.containsKey(pref.getName())) {
                        this.portletPreferences.put(pref.getName(), new StringListAttribute());
                    }
                    // use the default value if one exists
                    PreferenceInputType input = pref.getPreferenceInput().getValue();
                    if (input instanceof SingleValuedPreferenceInputType) {
                        SingleValuedPreferenceInputType singleValued = (SingleValuedPreferenceInputType) input;
                        if (singleValued.getDefault() != null) {
                            this.portletPreferences.get(pref.getName()).getValue().add(singleValued.getDefault());
                        }
                    } else if (input instanceof MultiValuedPreferenceInputType) {
                        MultiValuedPreferenceInputType multiValued = (MultiValuedPreferenceInputType) input;
                        if (multiValued.getDefaults() != null) {
                            this.portletPreferences.get(pref.getName()).getValue().addAll(multiValued.getDefaults());
                        }
                    }
                }
            }
        }
    }
}
Also used : ParameterInputType(org.apereo.portal.portletpublishing.xml.ParameterInputType) MultiValuedPreferenceInputType(org.apereo.portal.portletpublishing.xml.MultiValuedPreferenceInputType) PortletDescriptor(org.apereo.portal.xml.PortletDescriptor) StringListAttribute(org.apereo.portal.portlets.StringListAttribute) BooleanAttribute(org.apereo.portal.portlets.BooleanAttribute) Attribute(org.apereo.portal.portlets.Attribute) Preference(org.apereo.portal.portletpublishing.xml.Preference) IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) SingleValuedPreferenceInputType(org.apereo.portal.portletpublishing.xml.SingleValuedPreferenceInputType) PreferenceInputType(org.apereo.portal.portletpublishing.xml.PreferenceInputType) MultiValuedPreferenceInputType(org.apereo.portal.portletpublishing.xml.MultiValuedPreferenceInputType) Parameter(org.apereo.portal.portletpublishing.xml.Parameter) IPortletDefinitionParameter(org.apereo.portal.portlet.om.IPortletDefinitionParameter) StringListAttribute(org.apereo.portal.portlets.StringListAttribute) Step(org.apereo.portal.portletpublishing.xml.Step) SingleValuedPreferenceInputType(org.apereo.portal.portletpublishing.xml.SingleValuedPreferenceInputType)

Aggregations

PortletDescriptor (org.apereo.portal.xml.PortletDescriptor)4 IPortletDefinitionParameter (org.apereo.portal.portlet.om.IPortletDefinitionParameter)3 IPortletPreference (org.apereo.portal.portlet.om.IPortletPreference)3 IGroupMember (org.apereo.portal.groups.IGroupMember)2 ExternalPermissionDefinition (org.apereo.portal.io.xml.portlettype.ExternalPermissionDefinition)2 IPortletDescriptorKey (org.apereo.portal.portlet.om.IPortletDescriptorKey)2 IPortletType (org.apereo.portal.portlet.om.IPortletType)2 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 EntityIdentifier (org.apereo.portal.EntityIdentifier)1 IEntityGroup (org.apereo.portal.groups.IEntityGroup)1 PortletDefinitionImpl (org.apereo.portal.portlet.dao.jpa.PortletDefinitionImpl)1 PortletDefinitionParameterImpl (org.apereo.portal.portlet.dao.jpa.PortletDefinitionParameterImpl)1 PortletPreferenceImpl (org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl)1 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)1 PortletCategory (org.apereo.portal.portlet.om.PortletCategory)1