Search in sources :

Example 1 with ExoContainerContext

use of org.exoplatform.container.ExoContainerContext in project social by Meeds-io.

the class SpaceSearchConnector method search.

@Override
public Collection<SearchResult> search(SearchContext context, String query, Range range, Sorting sorting) {
    List<SearchResult> results = new ArrayList<SearchResult>();
    SpaceFilter filter = new SpaceFilter();
    filter.setSpaceNameSearchCondition(query);
    filter.setSorting(sorting);
    // if condition only have special characters or empty
    if (filter.getSpaceNameSearchCondition().isEmpty()) {
        return results;
    }
    ExoContainerContext eXoContext = (ExoContainerContext) ExoContainerContext.getCurrentContainer().getComponentInstanceOfType(ExoContainerContext.class);
    String portalName = eXoContext.getPortalContainerName();
    ListAccess<Space> la = spaceService.getUnifiedSearchSpacesWithListAccess(getCurrentUserName(), filter);
    // 
    try {
        Space[] spaces = la.load(range.offset, range.limit);
        // 
        RowIterator rowIt = rows(buildQuery(filter), range.offset, range.limit);
        Row row = null;
        // 
        for (Space s : spaces) {
            // 
            if (Space.HIDDEN.equals(s.getVisibility()) && !spaceService.isMember(s, getCurrentUserName()))
                continue;
            // 
            StringBuilder sb = new StringBuilder(s.getDisplayName());
            sb.append(String.format(" - %s Member(s)", s.getMembers().length));
            if (Space.OPEN.equals(s.getRegistration())) {
                sb.append(" - Free to Join");
            } else if (Space.VALIDATION.equals(s.getRegistration())) {
                sb.append(" - Register");
            } else if (Space.CLOSE.equals(s.getRegistration())) {
                sb.append(" - Invitation Only");
            } else {
                LOG.debug(s.getRegistration() + " registration unknown");
            }
            // 
            row = (rowIt != null && rowIt.hasNext()) ? rowIt.nextRow() : null;
            // 
            SearchResult result = new SearchResult(getSpaceUrl(context, s, portalName), s.getDisplayName(), // getExcerpt(row),
            s.getDescription(), sb.toString(), s.getAvatarUrl() != null ? s.getAvatarUrl() : LinkProvider.SPACE_DEFAULT_AVATAR_URL, s.getCreatedTime(), getRelevancy(row));
            results.add(result);
        }
    } catch (Exception e) {
        LOG.error(e);
    }
    // 
    return results;
}
Also used : Space(org.exoplatform.social.core.space.model.Space) ArrayList(java.util.ArrayList) SearchResult(org.exoplatform.commons.api.search.data.SearchResult) SpaceFilter(org.exoplatform.social.core.space.SpaceFilter) RowIterator(javax.jcr.query.RowIterator) ExoContainerContext(org.exoplatform.container.ExoContainerContext) Row(javax.jcr.query.Row)

Example 2 with ExoContainerContext

use of org.exoplatform.container.ExoContainerContext in project social by Meeds-io.

the class SpaceElasticUnifiedSearchServiceConnector method getUrlFromJsonResult.

private String getUrlFromJsonResult(Space space, SearchContext context) {
    if (space == null || context == null) {
        return null;
    }
    try {
        String permanentSpaceName = space.getPrettyName();
        String groupId = space.getGroupId();
        // 
        String siteName = groupId.replaceAll("/", ":");
        String siteType = SiteType.GROUP.getName();
        ExoContainerContext eXoContext = (ExoContainerContext) ExoContainerContext.getCurrentContainer().getComponentInstanceOfType(ExoContainerContext.class);
        String portalName = eXoContext.getPortalContainerName();
        String spaceURI = context.handler(portalName).lang("").siteName(siteName).siteType(siteType).path(permanentSpaceName).renderLink();
        return URLDecoder.decode(String.format("/%s%s", portalName, spaceURI), "UTF-8");
    } catch (Exception e) {
        LOG.error("Cannot compute space url for " + space.getDisplayName(), e);
        return "";
    }
}
Also used : ExoContainerContext(org.exoplatform.container.ExoContainerContext) ElasticSearchException(org.exoplatform.commons.search.es.ElasticSearchException) ParseException(org.json.simple.parser.ParseException)

Example 3 with ExoContainerContext

use of org.exoplatform.container.ExoContainerContext in project social by Meeds-io.

the class UIUserActivityStreamPortlet method redirectActivity.

/**
 * Redirects to activity page viewer (single page) if user has been logged in successfully.
 * Resolves problem query params are removing by portal in case of logging in is required. (SOC-3832).
 *
 * @throws Exception
 */
public void redirectActivity() throws Exception {
    String path = Utils.getSelectedNode();
    if (path.contains(SINGLE_ACTIVITY_REDIRECT_LINK_PREFIX)) {
        PortalRequestContext portalRequestContext = Util.getPortalRequestContext();
        HttpServletResponse response = portalRequestContext.getResponse();
        ExoContainerContext context = CommonsUtils.getService(ExoContainerContext.class);
        String link = new StringBuffer(CommonsUtils.getCurrentDomain()).append("/").append(context.getRestContextName()).append(NOTIFICATION_REST_PREFIX).append(path.replace(SINGLE_ACTIVITY_REDIRECT_LINK_PREFIX, "")).toString();
        response.sendRedirect(link);
    }
}
Also used : PortalRequestContext(org.exoplatform.portal.application.PortalRequestContext) ExoContainerContext(org.exoplatform.container.ExoContainerContext) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Aggregations

ExoContainerContext (org.exoplatform.container.ExoContainerContext)3 ArrayList (java.util.ArrayList)1 Row (javax.jcr.query.Row)1 RowIterator (javax.jcr.query.RowIterator)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 SearchResult (org.exoplatform.commons.api.search.data.SearchResult)1 ElasticSearchException (org.exoplatform.commons.search.es.ElasticSearchException)1 PortalRequestContext (org.exoplatform.portal.application.PortalRequestContext)1 SpaceFilter (org.exoplatform.social.core.space.SpaceFilter)1 Space (org.exoplatform.social.core.space.model.Space)1 ParseException (org.json.simple.parser.ParseException)1