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;
}
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);
}
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;
}
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);
}
}
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);
}
Aggregations