use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.
the class JpaMarketplaceRatingDao method aggregateMarketplaceRating.
@Override
@PortalTransactional
public void aggregateMarketplaceRating() {
//setup
EntityManager em = this.getEntityManager();
//get list of average ratings
Query aggregatedQuery = em.createQuery("SELECT AVG(m.rating) as rating, " + " count(m.marketplaceRatingPK.portletDefinition.internalPortletDefinitionId) as theCount, " + " m.marketplaceRatingPK.portletDefinition.internalPortletDefinitionId as portletId " + " FROM MarketplaceRatingImpl m " + " GROUP BY m.marketplaceRatingPK.portletDefinition.internalPortletDefinitionId");
@SuppressWarnings("unchecked") List<Object[]> aggregatedResults = aggregatedQuery.getResultList();
//update the portlet definition with the average rating
for (Object[] result : aggregatedResults) {
if (result != null && result.length == 3) {
try {
Double averageRating = (Double) result[0];
Long usersRated = (Long) result[1];
String portletId = ((Long) result[2]).toString();
IPortletDefinition portletDefinition = portletDefinitionDao.getPortletDefinition(portletId);
if (portletDefinition != null) {
portletDefinition.setRating(averageRating);
portletDefinition.setUsersRated(usersRated);
em.persist(portletDefinition);
}
} catch (Exception ex) {
logger.warn("Issue aggregating portlet ratings, recoverable", ex);
}
}
}
}
use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.
the class JpaPortletDefinitionDao method deletePortletDefinition.
@Override
@PortalTransactional
public void deletePortletDefinition(IPortletDefinition definition) {
Validate.notNull(definition, "definition can not be null");
final IPortletDefinition persistentPortletDefinition;
final EntityManager entityManager = this.getEntityManager();
if (entityManager.contains(definition)) {
persistentPortletDefinition = definition;
} else {
persistentPortletDefinition = entityManager.merge(definition);
}
entityManager.remove(persistentPortletDefinition);
}
use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.
the class JpaPortletEntityDao method createPortletEntity.
@Override
@PortalTransactional
public IPortletEntity createPortletEntity(IPortletDefinitionId portletDefinitionId, String layoutNodeId, int userId) {
Validate.notNull(portletDefinitionId, "portletDefinitionId can not be null");
Validate.notEmpty(layoutNodeId, "layoutNodeId can not be null");
final IPortletDefinition portletDefinition = this.portletDefinitionDao.getPortletDefinition(portletDefinitionId);
if (portletDefinition == null) {
throw new DataRetrievalFailureException("No IPortletDefinition exists for IPortletDefinitionId='" + portletDefinitionId + "'");
}
IPortletEntity portletEntity = new PortletEntityImpl(portletDefinition, layoutNodeId, userId);
this.getEntityManager().persist(portletEntity);
return portletEntity;
}
use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.
the class PortletDelegationLocatorImpl method createRequestDispatcher.
/* (non-Javadoc)
* @see org.apereo.portal.api.portlet.PortletDelegationLocator#createRequestDispatcher(java.lang.String)
*/
@Override
public PortletDelegationDispatcher createRequestDispatcher(PortletRequest portletRequest, String fName) {
final IPortletDefinition portletDefinition = this.portletDefinitionRegistry.getPortletDefinitionByFname(fName);
final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
return this.createRequestDispatcher(portletRequest, portletDefinitionId);
}
use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.
the class MarketplaceSearchService method getSearchResults.
/**
* Returns a list of search results that pertain to the marketplace query is the query to search
* will search name, title, description, fname, and captions
*/
@Override
public SearchResults getSearchResults(PortletRequest request, SearchRequest query) {
final String queryString = query.getSearchTerms().toLowerCase();
final List<IPortletDefinition> portlets = portletDefinitionRegistry.getAllPortletDefinitions();
final HttpServletRequest httpServletRequest = this.portalRequestUtils.getPortletHttpRequest(request);
final SearchResults results = new SearchResults();
for (IPortletDefinition portlet : portlets) {
if (this.matches(queryString, new MarketplacePortletDefinition(portlet, this.marketplaceService, this.portletCategoryRegistry))) {
final SearchResult result = new SearchResult();
result.setTitle(portlet.getTitle());
result.setSummary(portlet.getDescription());
result.getType().add("marketplace");
final IPortletWindow portletWindow = this.portletWindowRegistry.getOrCreateDefaultPortletWindowByFname(httpServletRequest, portlet.getFName());
// If user does not have browse permission, exclude the portlet.
if (portletWindow != null && authorizationService.canPrincipalBrowse(authorizationService.newPrincipal(request.getRemoteUser(), EntityEnum.PERSON.getClazz()), portlet)) {
final IPortletWindowId portletWindowId = portletWindow.getPortletWindowId();
final IPortalUrlBuilder portalUrlBuilder = this.portalUrlProvider.getPortalUrlBuilderByPortletFName(httpServletRequest, portlet.getFName(), UrlType.RENDER);
final IPortletUrlBuilder portletUrlBuilder = portalUrlBuilder.getPortletUrlBuilder(portletWindowId);
portletUrlBuilder.setWindowState(PortletUtils.getWindowState("maximized"));
result.setExternalUrl(portalUrlBuilder.getUrlString());
PortletUrl url = new PortletUrl();
url.setType(PortletUrlType.RENDER);
url.setPortletMode("VIEW");
url.setWindowState("maximized");
PortletUrlParameter actionParam = new PortletUrlParameter();
actionParam.setName("action");
actionParam.getValue().add("view");
url.getParam().add(actionParam);
PortletUrlParameter fNameParam = new PortletUrlParameter();
fNameParam.setName("fName");
fNameParam.getValue().add(portlet.getFName());
url.getParam().add(fNameParam);
result.setPortletUrl(url);
//Add the result to list to return
results.getSearchResult().add(result);
}
}
}
return results;
}
Aggregations