use of org.apereo.portal.portlet.om.IPortletDescriptorKey in project uPortal by Jasig.
the class HtmlPortletPreferenceSearchContentExtractorTest method testAppliesToMatchAll.
@Test
public void testAppliesToMatchAll() {
final IPortletDescriptorKey portletDescriptorKey = mock(IPortletDescriptorKey.class);
when(portletDescriptorKey.getPortletName()).thenAnswer(invocation -> PORTLET_NAME);
when(portletDescriptorKey.getWebAppName()).thenAnswer(invocation -> WEBAPP_NAME);
final IPortletPreference portletPreference = mock(IPortletPreference.class);
when(portletPreference.getName()).thenAnswer(invocation -> PREFERENCE_NAME);
final IPortletDefinition portletDefinition = mock(IPortletDefinition.class);
when(portletDefinition.getPortletDescriptorKey()).thenAnswer(invocation -> portletDescriptorKey);
when(portletDefinition.getPortletPreferences()).thenAnswer(invocation -> Collections.singletonList(portletPreference));
assertTrue(EXTRACTOR.appliesTo(portletDefinition));
}
use of org.apereo.portal.portlet.om.IPortletDescriptorKey in project uPortal by Jasig.
the class HtmlPortletPreferenceSearchContentExtractorTest method testAppliesToWebappMatch.
@Test
public void testAppliesToWebappMatch() {
final IPortletDescriptorKey portletDescriptorKey = mock(IPortletDescriptorKey.class);
when(portletDescriptorKey.getPortletName()).thenAnswer(invocation -> NOT_A_MATCH);
when(portletDescriptorKey.getWebAppName()).thenAnswer(invocation -> WEBAPP_NAME);
final IPortletDefinition portletDefinition = mock(IPortletDefinition.class);
when(portletDefinition.getPortletDescriptorKey()).thenAnswer(invocation -> portletDescriptorKey);
when(portletDefinition.getPortletPreferences()).thenAnswer(invocation -> Collections.emptyList());
assertFalse(EXTRACTOR.appliesTo(portletDefinition));
}
use of org.apereo.portal.portlet.om.IPortletDescriptorKey in project uPortal by Jasig.
the class PortletExecutionManager method getPortletExecutionCounts.
@Override
public Map<String, Integer> getPortletExecutionCounts() {
final Map<String, Integer> counts = new TreeMap<String, Integer>();
for (final Map.Entry<IPortletDescriptorKey, AtomicInteger> entry : this.executionCount.entrySet()) {
final IPortletDescriptorKey key = entry.getKey();
final AtomicInteger value = entry.getValue();
counts.put(key.getWebAppName() + "/" + key.getPortletName(), value.get());
}
return counts;
}
use of org.apereo.portal.portlet.om.IPortletDescriptorKey in project uPortal by Jasig.
the class ExternalPortletDefinitionUnmarshaller method unmarshall.
/* package-private */
IPortletDefinition unmarshall(ExternalPortletDefinition epd) {
final PortletDescriptor portletDescriptor = epd.getPortletDescriptor();
final Boolean isFramework = portletDescriptor.isIsFramework();
if (isFramework != null && isFramework && "UPGRADED_CHANNEL_IS_NOT_A_PORTLET".equals(portletDescriptor.getPortletName())) {
if (errorOnChannel) {
throw new IllegalArgumentException(epd.getFname() + " is not a portlet. It was likely an IChannel from a previous version of uPortal and cannot be imported.");
}
logger.warn(epd.getFname() + " is not a portlet. It was likely an IChannel from a previous version of uPortal and will not be imported.");
return null;
}
// get the portlet type
final IPortletType portletType = portletTypeRegistry.getPortletType(epd.getType());
if (portletType == null) {
throw new IllegalArgumentException("No portlet type registered for: " + epd.getType());
}
final String fname = epd.getFname();
IPortletDefinition rslt = portletDefinitionDao.getPortletDefinitionByFname(fname);
if (rslt == null) {
rslt = new PortletDefinitionImpl(portletType, fname, epd.getName(), epd.getTitle(), portletDescriptor.getWebAppName(), portletDescriptor.getPortletName(), isFramework != null ? isFramework : false);
} else {
final IPortletDescriptorKey portletDescriptorKey = rslt.getPortletDescriptorKey();
portletDescriptorKey.setPortletName(portletDescriptor.getPortletName());
if (isFramework != null && isFramework) {
portletDescriptorKey.setFrameworkPortlet(true);
portletDescriptorKey.setWebAppName(null);
} else {
portletDescriptorKey.setFrameworkPortlet(false);
portletDescriptorKey.setWebAppName(portletDescriptor.getWebAppName());
}
rslt.setName(epd.getName());
rslt.setTitle(epd.getTitle());
rslt.setType(portletType);
}
rslt.setDescription(epd.getDesc());
final BigInteger timeout = epd.getTimeout();
if (timeout != null) {
rslt.setTimeout(timeout.intValue());
}
final BigInteger actionTimeout = epd.getActionTimeout();
if (actionTimeout != null) {
rslt.setActionTimeout(actionTimeout.intValue());
}
final BigInteger eventTimeout = epd.getEventTimeout();
if (eventTimeout != null) {
rslt.setEventTimeout(eventTimeout.intValue());
}
final BigInteger renderTimeout = epd.getRenderTimeout();
if (renderTimeout != null) {
rslt.setRenderTimeout(renderTimeout.intValue());
}
final BigInteger resourceTimeout = epd.getResourceTimeout();
if (resourceTimeout != null) {
rslt.setResourceTimeout(resourceTimeout.intValue());
}
unmarshallLifecycle(epd.getLifecycle(), rslt);
final Set<IPortletDefinitionParameter> parameters = new LinkedHashSet<>();
for (ExternalPortletParameter param : epd.getParameters()) {
parameters.add(new PortletDefinitionParameterImpl(param.getName(), param.getValue()));
}
rslt.setParameters(parameters);
final ArrayList<IPortletPreference> preferenceList = new ArrayList<>();
for (ExternalPortletPreference pref : epd.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));
}
rslt.setPortletPreferences(preferenceList);
return rslt;
}
use of org.apereo.portal.portlet.om.IPortletDescriptorKey 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;
}
Aggregations