Search in sources :

Example 1 with IPortletLifecycleEntry

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

the class PortletDefinitionImpl method getLifecycleState.

@Override
public PortletLifecycleState getLifecycleState() {
    final Date now = new Date();
    final IPortletLifecycleEntry currentEntry = lifecycleEntries.stream().filter(// Not entries in the future
    entry -> entry.getDate().before(now)).reduce((e1, e2) -> e1.getDate().after(e2.getDate()) ? e1 : // Only the latest
    e2).orElse(// Possible if the portlet is not yet fully created
    null);
    return currentEntry != null ? currentEntry.getLifecycleState() : null;
}
Also used : IPortletDescriptorKey(org.apereo.portal.portlet.om.IPortletDescriptorKey) Date(java.util.Date) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) MapKey(javax.persistence.MapKey) MapKeyColumn(javax.persistence.MapKeyColumn) SequenceGenerator(javax.persistence.SequenceGenerator) FetchMode(org.hibernate.annotations.FetchMode) Map(java.util.Map) PortletLifecycleState(org.apereo.portal.portlet.om.PortletLifecycleState) IPortletLifecycleEntry(org.apereo.portal.portlet.om.IPortletLifecycleEntry) IPortletDefinitionParameter(org.apereo.portal.portlet.om.IPortletDefinitionParameter) Version(javax.persistence.Version) IMarketplaceRating(org.apereo.portal.portlet.marketplace.IMarketplaceRating) Entity(javax.persistence.Entity) ManyToOne(javax.persistence.ManyToOne) CascadeType(javax.persistence.CascadeType) IPortletType(org.apereo.portal.portlet.om.IPortletType) Set(java.util.Set) IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) Collectors(java.util.stream.Collectors) Type(org.hibernate.annotations.Type) Column(javax.persistence.Column) List(java.util.List) GeneratedValue(javax.persistence.GeneratedValue) Index(org.hibernate.annotations.Index) ToStringBuilder(org.apache.commons.lang3.builder.ToStringBuilder) Validate(org.apache.commons.lang.Validate) IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Table(javax.persistence.Table) TableGenerator(javax.persistence.TableGenerator) NaturalIdCache(org.hibernate.annotations.NaturalIdCache) PostLoad(javax.persistence.PostLoad) OrderBy(javax.persistence.OrderBy) IPerson(org.apereo.portal.security.IPerson) CollectionTable(javax.persistence.CollectionTable) LinkedHashSet(java.util.LinkedHashSet) Id(javax.persistence.Id) Fetch(org.hibernate.annotations.Fetch) PostPersist(javax.persistence.PostPersist) Embedded(javax.persistence.Embedded) JoinColumn(javax.persistence.JoinColumn) Cacheable(javax.persistence.Cacheable) OneToMany(javax.persistence.OneToMany) CacheConcurrencyStrategy(org.hibernate.annotations.CacheConcurrencyStrategy) Cache(org.hibernate.annotations.Cache) OneToOne(javax.persistence.OneToOne) NaturalId(org.hibernate.annotations.NaturalId) Transient(javax.persistence.Transient) EntityIdentifier(org.apereo.portal.EntityIdentifier) FetchType(javax.persistence.FetchType) ElementCollection(javax.persistence.ElementCollection) PostUpdate(javax.persistence.PostUpdate) Collections(java.util.Collections) PostRemove(javax.persistence.PostRemove) StringUtils(org.springframework.util.StringUtils) IPortletLifecycleEntry(org.apereo.portal.portlet.om.IPortletLifecycleEntry) Date(java.util.Date)

Example 2 with IPortletLifecycleEntry

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

the class PortletDefinitionImpl method updateLifecycleState.

/**
 * In {@link PortletDefinitionImpl}, this overload does all the work. (The other overload
 * forwards.) Adding <code>synchronized</code> in case two threads try to modify the collection
 * at the same time.
 */
@Override
public synchronized void updateLifecycleState(PortletLifecycleState lifecycleState, IPerson user, Date timestamp) {
    /*
         * Lifecycle entries that are scheduled for an instant
         * on or after the new entry must be cleared.
         */
    final Set<IPortletLifecycleEntry> canceledStateChanges = lifecycleEntries.stream().filter(entry -> entry.getDate().compareTo(timestamp) >= 0).collect(Collectors.toSet());
    lifecycleEntries.removeAll(canceledStateChanges);
    final IPortletLifecycleEntry newEntry = new PortletLifecycleEntryImpl(user.getID(), lifecycleState, timestamp);
    lifecycleEntries.add(newEntry);
}
Also used : IPortletDescriptorKey(org.apereo.portal.portlet.om.IPortletDescriptorKey) Date(java.util.Date) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) MapKey(javax.persistence.MapKey) MapKeyColumn(javax.persistence.MapKeyColumn) SequenceGenerator(javax.persistence.SequenceGenerator) FetchMode(org.hibernate.annotations.FetchMode) Map(java.util.Map) PortletLifecycleState(org.apereo.portal.portlet.om.PortletLifecycleState) IPortletLifecycleEntry(org.apereo.portal.portlet.om.IPortletLifecycleEntry) IPortletDefinitionParameter(org.apereo.portal.portlet.om.IPortletDefinitionParameter) Version(javax.persistence.Version) IMarketplaceRating(org.apereo.portal.portlet.marketplace.IMarketplaceRating) Entity(javax.persistence.Entity) ManyToOne(javax.persistence.ManyToOne) CascadeType(javax.persistence.CascadeType) IPortletType(org.apereo.portal.portlet.om.IPortletType) Set(java.util.Set) IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) Collectors(java.util.stream.Collectors) Type(org.hibernate.annotations.Type) Column(javax.persistence.Column) List(java.util.List) GeneratedValue(javax.persistence.GeneratedValue) Index(org.hibernate.annotations.Index) ToStringBuilder(org.apache.commons.lang3.builder.ToStringBuilder) Validate(org.apache.commons.lang.Validate) IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Table(javax.persistence.Table) TableGenerator(javax.persistence.TableGenerator) NaturalIdCache(org.hibernate.annotations.NaturalIdCache) PostLoad(javax.persistence.PostLoad) OrderBy(javax.persistence.OrderBy) IPerson(org.apereo.portal.security.IPerson) CollectionTable(javax.persistence.CollectionTable) LinkedHashSet(java.util.LinkedHashSet) Id(javax.persistence.Id) Fetch(org.hibernate.annotations.Fetch) PostPersist(javax.persistence.PostPersist) Embedded(javax.persistence.Embedded) JoinColumn(javax.persistence.JoinColumn) Cacheable(javax.persistence.Cacheable) OneToMany(javax.persistence.OneToMany) CacheConcurrencyStrategy(org.hibernate.annotations.CacheConcurrencyStrategy) Cache(org.hibernate.annotations.Cache) OneToOne(javax.persistence.OneToOne) NaturalId(org.hibernate.annotations.NaturalId) Transient(javax.persistence.Transient) EntityIdentifier(org.apereo.portal.EntityIdentifier) FetchType(javax.persistence.FetchType) ElementCollection(javax.persistence.ElementCollection) PostUpdate(javax.persistence.PostUpdate) Collections(java.util.Collections) PostRemove(javax.persistence.PostRemove) StringUtils(org.springframework.util.StringUtils) IPortletLifecycleEntry(org.apereo.portal.portlet.om.IPortletLifecycleEntry)

Example 3 with IPortletLifecycleEntry

use of org.apereo.portal.portlet.om.IPortletLifecycleEntry 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());
    final Lifecycle lifecycle = new Lifecycle();
    for (IPortletLifecycleEntry ple : def.getLifecycle()) {
        final LifecycleEntry entry = new LifecycleEntry();
        entry.setName(ple.getLifecycleState().toString());
        entry.setUser(getUsernameForUserId(ple.getUserId()));
        entry.setValue(getCalendar(ple.getDate()));
        lifecycle.getEntries().add(entry);
    }
    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);
    }
    parameterList.sort(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);
    }
    portletPreferenceList.sort(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) IPortletDefinitionParameter(org.apereo.portal.portlet.om.IPortletDefinitionParameter) ExternalPermissionDefinition(org.apereo.portal.io.xml.portlettype.ExternalPermissionDefinition) IPortletLifecycleEntry(org.apereo.portal.portlet.om.IPortletLifecycleEntry) IPortletLifecycleEntry(org.apereo.portal.portlet.om.IPortletLifecycleEntry) IEntityGroup(org.apereo.portal.groups.IEntityGroup) IGroupMember(org.apereo.portal.groups.IGroupMember)

Example 4 with IPortletLifecycleEntry

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

the class ExternalPortletDefinitionUnmarshallerTest method testUnmarshallLifecycle.

@Test
public void testUnmarshallLifecycle() {
    final long currentTimeMillis = System.currentTimeMillis();
    final String createdUser = "createdUser";
    final String approvedUser = "approvedUser";
    final String publishedUser = "publishedUser";
    final String expiredUser = "expiredUser";
    final String maintenanceUser = "maintenanceUser";
    final Calendar createdCalendar = getCalendarForMillis(currentTimeMillis - (5L * MILLIS_IN_ONE_DAY));
    final Calendar approvedCalendar = getCalendarForMillis(currentTimeMillis - (4L * MILLIS_IN_ONE_DAY));
    final Calendar publishedCalendar = getCalendarForMillis(currentTimeMillis - (3L * MILLIS_IN_ONE_DAY));
    final Calendar expiredCalendar = getCalendarForMillis(currentTimeMillis + MILLIS_IN_ONE_DAY);
    final Calendar maintenanceCalendar = getCalendarForMillis(currentTimeMillis - (2L * MILLIS_IN_ONE_DAY));
    // Created 5 days in the past
    final LifecycleEntry created = new LifecycleEntry();
    created.setName("CREATED");
    created.setUser(createdUser);
    created.setValue(createdCalendar);
    // Approved 4 days in the past
    final LifecycleEntry approved = new LifecycleEntry();
    approved.setName("APPROVED");
    approved.setUser(approvedUser);
    approved.setValue(approvedCalendar);
    // Published 3 days in the past
    final LifecycleEntry published = new LifecycleEntry();
    published.setName("PUBLISHED");
    published.setUser(publishedUser);
    published.setValue(publishedCalendar);
    // Expired 1 day in the future
    final LifecycleEntry expired = new LifecycleEntry();
    expired.setName("EXPIRED");
    expired.setUser(expiredUser);
    expired.setValue(expiredCalendar);
    // Maintenance mode 2 days in the past
    final LifecycleEntry maintenance = new LifecycleEntry();
    maintenance.setName("MAINTENANCE");
    maintenance.setUser(maintenanceUser);
    maintenance.setValue(maintenanceCalendar);
    final Lifecycle lifecycle1 = new Lifecycle();
    lifecycle1.getEntries().add(created);
    final Lifecycle lifecycle2 = new Lifecycle();
    lifecycle2.getEntries().add(created);
    lifecycle2.getEntries().add(approved);
    final Lifecycle lifecycle3 = new Lifecycle();
    lifecycle3.getEntries().add(published);
    lifecycle3.getEntries().add(expired);
    final Lifecycle lifecycle4 = new Lifecycle();
    lifecycle4.getEntries().add(created);
    lifecycle4.getEntries().add(approved);
    lifecycle4.getEntries().add(published);
    lifecycle4.getEntries().add(maintenance);
    lifecycle4.getEntries().add(expired);
    final Lifecycle[] lifecyclesToTest = new Lifecycle[] { lifecycle1, lifecycle2, lifecycle3, lifecycle4 };
    final IPortletLifecycleEntry[][] expectedPortletLifecycles = new IPortletLifecycleEntry[][] { // 1
    new IPortletLifecycleEntry[] { new PortletLifecycleEntryImpl(createdUser.hashCode(), PortletLifecycleState.CREATED, createdCalendar.getTime()) }, // 2
    new IPortletLifecycleEntry[] { new PortletLifecycleEntryImpl(createdUser.hashCode(), PortletLifecycleState.CREATED, createdCalendar.getTime()), new PortletLifecycleEntryImpl(approvedUser.hashCode(), PortletLifecycleState.APPROVED, approvedCalendar.getTime()) }, // 3
    new IPortletLifecycleEntry[] { new PortletLifecycleEntryImpl(publishedUser.hashCode(), PortletLifecycleState.PUBLISHED, publishedCalendar.getTime()), new PortletLifecycleEntryImpl(expiredUser.hashCode(), PortletLifecycleState.EXPIRED, expiredCalendar.getTime()) }, // 4
    new IPortletLifecycleEntry[] { new PortletLifecycleEntryImpl(createdUser.hashCode(), PortletLifecycleState.CREATED, createdCalendar.getTime()), new PortletLifecycleEntryImpl(approvedUser.hashCode(), PortletLifecycleState.APPROVED, approvedCalendar.getTime()), new PortletLifecycleEntryImpl(publishedUser.hashCode(), PortletLifecycleState.PUBLISHED, publishedCalendar.getTime()), new PortletLifecycleEntryImpl(maintenanceUser.hashCode(), PortletLifecycleState.MAINTENANCE, maintenanceCalendar.getTime()), new PortletLifecycleEntryImpl(expiredUser.hashCode(), PortletLifecycleState.EXPIRED, expiredCalendar.getTime()) } };
    final ExternalPortletDefinitionUnmarshaller unmarshaller = new ExternalPortletDefinitionUnmarshaller();
    unmarshaller.setUserIdentityStore(new MockUserIdentityStore());
    final IPortletType portletType = new PortletTypeImpl("FakePortletType", "http://not/a/real/uri");
    for (int i = 0; i < lifecyclesToTest.length; i++) {
        final Lifecycle lifecycle = lifecyclesToTest[i];
        final IPortletDefinition pDef = new PortletDefinitionImpl(portletType, "fake-portlet", "Fake Portlet", "Fake Portlet", "FakePortletApp", "fake-portlet-def", false);
        unmarshaller.unmarshallLifecycle(lifecycle, pDef);
        final IPortletLifecycleEntry[] expectedLifecycle = expectedPortletLifecycles[i];
        for (IPortletLifecycleEntry y : pDef.getLifecycle()) {
            System.out.println(" ## ");
            System.out.println(" ## y.getLifecycleState()=" + y.getLifecycleState());
        }
        assertArrayEquals(pDef.getLifecycle().toArray(), expectedLifecycle);
    }
}
Also used : IPortletLifecycleEntry(org.apereo.portal.portlet.om.IPortletLifecycleEntry) PortletTypeImpl(org.apereo.portal.portlet.dao.jpa.PortletTypeImpl) Calendar(java.util.Calendar) PortletLifecycleEntryImpl(org.apereo.portal.portlet.dao.jpa.PortletLifecycleEntryImpl) IPortletLifecycleEntry(org.apereo.portal.portlet.om.IPortletLifecycleEntry) IPortletType(org.apereo.portal.portlet.om.IPortletType) PortletDefinitionImpl(org.apereo.portal.portlet.dao.jpa.PortletDefinitionImpl) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) Test(org.junit.Test)

Example 5 with IPortletLifecycleEntry

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

the class AuthorizationImpl method canPrincipalManage.

/**
 * Answers if the principal has permission to MANAGE this Channel.
 *
 * @param principal IAuthorizationPrincipal The user who wants to manage the portlet
 * @param portletDefinitionId The Id of the portlet being managed
 * @return True if the specified user is allowed to manage the specified portlet; otherwise
 *     false
 * @exception AuthorizationException indicates authorization information could not be retrieved.
 */
@Override
@RequestCache
public boolean canPrincipalManage(IAuthorizationPrincipal principal, String portletDefinitionId) throws AuthorizationException {
    final String owner = IPermission.PORTAL_PUBLISH;
    final String target = IPermission.PORTLET_PREFIX + portletDefinitionId;
    // Retrieve the indicated portlet from the portlet registry store and
    // determine its current lifecycle state.
    IPortletDefinition portlet = this.portletDefinitionRegistry.getPortletDefinition(portletDefinitionId);
    if (portlet == null) {
        /*
             * Is this what happens when a portlet is new?  Shouldn't we
             * be checking PORTLET_MANAGER_CREATED_ACTIVITY in that case?
             */
        return doesPrincipalHavePermission(principal, owner, IPermission.PORTLET_MANAGER_APPROVED_ACTIVITY, target);
    }
    /*
         * The following code assumes that later lifecycle states imply permission
         * for earlier lifecycle states.  For example, if a user has permission to
         * manage an expired channel, we assume s/he also has permission to
         * create, approve, and publish channels.  The following code counts
         * channels with auto-publish or auto-expiration dates set as requiring
         * publish or expiration permissions for management, even though the channel
         * may not yet be published or expired.
         */
    final IPortletLifecycleEntry highestLifecycleEntryDefined = portlet.getLifecycle().get(portlet.getLifecycle().size() - 1);
    String activity;
    switch(highestLifecycleEntryDefined.getLifecycleState()) {
        case CREATED:
            activity = IPermission.PORTLET_MANAGER_CREATED_ACTIVITY;
            break;
        case APPROVED:
            activity = IPermission.PORTLET_MANAGER_APPROVED_ACTIVITY;
            break;
        case PUBLISHED:
            activity = IPermission.PORTLET_MANAGER_ACTIVITY;
            break;
        case EXPIRED:
            activity = IPermission.PORTLET_MANAGER_EXPIRED_ACTIVITY;
            break;
        case MAINTENANCE:
            activity = IPermission.PORTLET_MANAGER_MAINTENANCE_ACTIVITY;
            break;
        default:
            final String msg = "Unrecognized portlet lifecycle state:  " + highestLifecycleEntryDefined.getLifecycleState();
            throw new IllegalStateException(msg);
    }
    return doesPrincipalHavePermission(principal, owner, activity, target);
}
Also used : IPortletLifecycleEntry(org.apereo.portal.portlet.om.IPortletLifecycleEntry) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) RequestCache(org.apereo.portal.concurrency.caching.RequestCache)

Aggregations

IPortletLifecycleEntry (org.apereo.portal.portlet.om.IPortletLifecycleEntry)5 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)4 IPortletDefinitionParameter (org.apereo.portal.portlet.om.IPortletDefinitionParameter)3 IPortletDescriptorKey (org.apereo.portal.portlet.om.IPortletDescriptorKey)3 IPortletPreference (org.apereo.portal.portlet.om.IPortletPreference)3 IPortletType (org.apereo.portal.portlet.om.IPortletType)3 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 Date (java.util.Date)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Cacheable (javax.persistence.Cacheable)2 CascadeType (javax.persistence.CascadeType)2 CollectionTable (javax.persistence.CollectionTable)2 Column (javax.persistence.Column)2 ElementCollection (javax.persistence.ElementCollection)2