use of org.apereo.portal.portlet.om.IPortletDefinitionParameter in project uPortal by Jasig.
the class PortalSearchIndexer method indexPortlet.
private void indexPortlet(IPortletDefinition portlet, IndexWriter indexWriter) {
// Unique identifier, hashed to eliminate special character concerns, such as hyphens
final String fnameHash = Hashing.sha256().hashString(portlet.getFName(), StandardCharsets.UTF_8).toString();
try {
final Document doc = new Document();
doc.add(new TextField(LUCENE_DOC_ID_FIELD, fnameHash, Field.Store.YES));
doc.add(new TextField(SearchField.FNAME.getValue(), portlet.getFName(), Field.Store.YES));
doc.add(new TextField(SearchField.NAME.getValue(), portlet.getName(), Field.Store.YES));
doc.add(new TextField(SearchField.TITLE.getValue(), portlet.getTitle(), Field.Store.YES));
final String description = portlet.getDescription();
if (StringUtils.isNotBlank(description)) {
doc.add(new TextField(SearchField.DESCRIPTION.getValue(), description, Field.Store.YES));
}
final IPortletDefinitionParameter keywords = portlet.getParameter("keywords");
if (keywords != null && StringUtils.isNotBlank(keywords.getValue())) {
doc.add(new TextField(SearchField.KEYWORDS.getValue(), keywords.getValue(), Field.Store.YES));
}
final String content = extractContent(portlet);
if (StringUtils.isNotBlank(content)) {
doc.add(new TextField(SearchField.CONTENT.getValue(), content, Field.Store.YES));
}
indexWriter.updateDocument(new Term(LUCENE_DOC_ID_FIELD, fnameHash), doc);
} catch (IOException ioe) {
logger.warn("Unable to index portlet with fname='{}' and hash='{}'", portlet.getFName(), fnameHash);
return;
}
logger.debug("Indexed portlet '{}' (hash='{}')", portlet.getFName(), fnameHash);
}
use of org.apereo.portal.portlet.om.IPortletDefinitionParameter in project uPortal by Jasig.
the class PortletExecutionManager method startPortletRenderInternal.
/**
* create and submit the portlet content rendering job to the thread pool
*/
protected IPortletRenderExecutionWorker startPortletRenderInternal(IPortletWindowId portletWindowId, HttpServletRequest request, HttpServletResponse response) {
// first check to see if there is a Throwable in the session for this IPortletWindowId
final Map<IPortletWindowId, Exception> portletFailureMap = getPortletErrorMap(request);
final Exception cause = portletFailureMap.remove(portletWindowId);
final IPortletRenderExecutionWorker portletRenderExecutionWorker;
if (null != cause) {
// previous action failed, dispatch to errorPortlet immediately
portletRenderExecutionWorker = this.portletWorkerFactory.createFailureWorker(request, response, portletWindowId, cause);
} else {
IPortletWindow portletWindow = portletWindowRegistry.getPortletWindow(request, portletWindowId);
IPortletDefinition portletDef = portletWindow.getPortletEntity().getPortletDefinition();
if (portletDef.getLifecycleState().equals(PortletLifecycleState.MAINTENANCE)) {
// Prevent the portlet from rendering; replace with a helpful "Out of Service"
// message
final IPortletDefinitionParameter messageParam = portletDef.getParameter(PortletLifecycleState.CUSTOM_MAINTENANCE_MESSAGE_PARAMETER_NAME);
final Exception mme = messageParam != null && StringUtils.isNotBlank(messageParam.getValue()) ? new MaintenanceModeException(messageParam.getValue()) : new MaintenanceModeException();
portletRenderExecutionWorker = this.portletWorkerFactory.createFailureWorker(request, response, portletWindowId, mme);
} else {
// Happy path
portletRenderExecutionWorker = this.portletWorkerFactory.createRenderWorker(request, response, portletWindowId);
}
}
portletRenderExecutionWorker.submit();
final Map<IPortletWindowId, IPortletRenderExecutionWorker> portletRenderingMap = this.getPortletRenderingMap(request);
portletRenderingMap.put(portletWindowId, portletRenderExecutionWorker);
return portletRenderExecutionWorker;
}
use of org.apereo.portal.portlet.om.IPortletDefinitionParameter in project uPortal by Jasig.
the class PortletExecutionManager method doPortletAction.
/* (non-Javadoc)
* @see org.apereo.portal.portlet.rendering.IPortletExecutionManager#doPortletAction(org.apereo.portal.portlet.om.IPortletWindowId, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
public void doPortletAction(IPortletWindowId portletWindowId, HttpServletRequest request, HttpServletResponse response) {
final long timeout = getPortletActionTimeout(portletWindowId, request);
final IPortletExecutionWorker<Long> portletActionExecutionWorker = this.portletWorkerFactory.createActionWorker(request, response, portletWindowId);
portletActionExecutionWorker.submit();
try {
portletActionExecutionWorker.get(timeout);
} catch (Exception e) {
// put the exception into the error map for the session
final Map<IPortletWindowId, Exception> portletFailureMap = getPortletErrorMap(request);
portletFailureMap.put(portletWindowId, e);
}
// If the worker is still running add it to the hung-workers queue
if (!portletActionExecutionWorker.isComplete()) {
cancelWorker(request, portletActionExecutionWorker);
}
// Is this portlet permitted to emit events? (Or is it disablePortletEvents=true?)
final IPortletWindow portletWindow = portletWindowRegistry.getPortletWindow(request, portletWindowId);
IPortletDefinition portletDefinition = portletWindow.getPortletEntity().getPortletDefinition();
IPortletDefinitionParameter disablePortletEvents = portletDefinition.getParameter(DISABLE_PORTLET_EVENTS_PARAMETER);
if (disablePortletEvents != null && Boolean.parseBoolean(disablePortletEvents.getValue())) {
logger.info("Ignoring portlet events for portlet '{}' because they have been disabled.", portletDefinition.getFName());
} else {
// Proceed with events...
final PortletEventQueue portletEventQueue = this.eventCoordinationService.getPortletEventQueue(request);
this.doPortletEvents(portletEventQueue, request, response);
}
}
use of org.apereo.portal.portlet.om.IPortletDefinitionParameter in project uPortal by Jasig.
the class PortletDefinitionBeanTest method testFromMarketplacePortletDefinition.
@Test
public void testFromMarketplacePortletDefinition() {
Long id = 345L;
String name = "testName";
String[] keywords = new String[] { "val1", "val2" };
List<IPortletPreference> prefs = new ArrayList<>();
prefs.add(portletPref);
Mockito.when(portletPref.getName()).thenReturn("keywords");
Mockito.when(portletPref.getValues()).thenReturn(keywords);
Map<String, IPortletDefinitionParameter> params = new HashMap<>();
params.put("test1", portletDefParam);
MarketplacePortletDefinition mpd = buildMarketplacePortletDefinition(id, name, prefs, params);
PortletDefinitionBean pdb = PortletDefinitionBean.fromMarketplacePortletDefinition(mpd, Locale.ENGLISH, false);
assertEquals(averageRating, pdb.getAverageRating());
assertEquals(id, (Long) pdb.getId());
assertEquals(fName, pdb.getFname());
assertEquals(title, pdb.getTitle());
assertEquals(name, pdb.getName());
assertEquals(description, pdb.getDescription());
assertEquals(state.toString(), pdb.getState());
assertEquals(typeId, pdb.getTypeId());
assertEquals(usersRated, (Long) pdb.getRatingsCount());
assertEquals(params, pdb.getParameters());
assertEquals(Arrays.asList(keywords), pdb.getKeywords());
}
use of org.apereo.portal.portlet.om.IPortletDefinitionParameter in project uPortal by Jasig.
the class PortletDefinitionImpl method addParameter.
@Override
public void addParameter(IPortletDefinitionParameter parameter) {
final String name = parameter.getName();
final IPortletDefinitionParameter existingParameter = this.parameters.get(name);
if (existingParameter != null) {
existingParameter.setDescription(parameter.getDescription());
existingParameter.setValue(parameter.getValue());
} else {
this.parameters.put(name, parameter);
}
}
Aggregations