Example usage for com.liferay.portal.kernel.search Field ORGANIZATION_ID

List of usage examples for com.liferay.portal.kernel.search Field ORGANIZATION_ID

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.search Field ORGANIZATION_ID.

Prototype

String ORGANIZATION_ID

To view the source code for com.liferay.portal.kernel.search Field ORGANIZATION_ID.

Click Source Link

Usage

From source file:com.bemis.portal.customer.service.impl.CustomerProfileLocalServiceImpl.java

License:Open Source License

@Override
public List<CustomerProfile> searchCustomer(String criteria, int start, int end) throws PortalException {

    long companyId = _bemisPortalService.getDefaultCompanyId();

    List<CustomerProfile> customerProfiles = new ArrayList<>();

    LinkedHashMap<String, Object> params = new LinkedHashMap<>();

    params.put(_EXPANDO_ATTRIBUTES, criteria);

    Hits hits = _organizationLocalService.search(companyId,
            OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID, criteria, params, start, end, null);

    Document[] documents = hits.getDocs();

    for (Document doc : documents) {
        long orgId = GetterUtil.getLong(doc.get(Field.ORGANIZATION_ID));

        Organization org = _organizationLocalService.getOrganization(orgId);

        customerProfiles.add(asCustomerProfile(org));
    }/* w ww.j  a va 2 s. com*/

    return customerProfiles;
}

From source file:com.liferay.portlet.usersadmin.util.OrganizationIndexer.java

License:Open Source License

@Override
protected Document doGetDocument(Object obj) throws Exception {
    Organization organization = (Organization) obj;

    Document document = getBaseModelDocument(PORTLET_ID, organization);

    document.addKeyword(Field.COMPANY_ID, organization.getCompanyId());
    document.addText(Field.NAME, organization.getName());
    document.addKeyword(Field.ORGANIZATION_ID, organization.getOrganizationId());
    document.addKeyword(Field.TYPE, organization.getType());

    document.addKeyword("parentOrganizationId", organization.getParentOrganizationId());

    String treePath = organization.buildTreePath();

    document.addKeyword("treePath", treePath);

    populateAddresses(document, organization.getAddresses(), organization.getRegionId(),
            organization.getCountryId());

    return document;
}

From source file:com.liferay.portlet.usersadmin.util.OrganizationIndexer.java

License:Open Source License

@Override
protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletURL portletURL) {

    String title = document.get("name");

    String content = null;//w w w . j a  va 2 s .c o  m

    String organizationId = document.get(Field.ORGANIZATION_ID);

    portletURL.setParameter("struts_action", "/users_admin/edit_organization");
    portletURL.setParameter("organizationId", organizationId);

    return new Summary(title, content, portletURL);
}

From source file:com.liferay.portlet.usersadmin.util.UsersAdminImpl.java

License:Open Source License

public Tuple getOrganizations(Hits hits) throws PortalException, SystemException {

    List<Organization> organizations = new ArrayList<Organization>();
    boolean corruptIndex = false;

    List<Document> documents = hits.toList();

    for (Document document : documents) {
        long organizationId = GetterUtil.getLong(document.get(Field.ORGANIZATION_ID));

        try {/*from   w w  w.j  a va  2  s  . com*/
            Organization organization = OrganizationLocalServiceUtil.getOrganization(organizationId);

            organizations.add(organization);
        } catch (NoSuchOrganizationException nsoe) {
            corruptIndex = true;

            Indexer indexer = IndexerRegistryUtil.getIndexer(Organization.class);

            long companyId = GetterUtil.getLong(document.get(Field.COMPANY_ID));

            indexer.delete(companyId, document.getUID());
        }
    }

    return new Tuple(organizations, corruptIndex);
}

From source file:org.fit.portlet.service.service.impl.InserFitxaPersonalLocalServiceImpl.java

License:Open Source License

private Hits searchFitxaPersonalHits(long companyId, long groupId, long[] organizationIds, String searchText,
        long tecnicReferent, long codiProjecte, long serveiSocial, int start, int end, String orderByCol,
        String orderByType) {/*w  w w.ja  v a2 s . c  om*/

    try {
        String searchEngineId = SearchEngineUtil.getDefaultSearchEngineId();

        SearchEngine searchEngine = SearchEngineUtil.getSearchEngine(searchEngineId);

        BooleanQueryFactory booleanQueryFactory = searchEngine.getBooleanQueryFactory();

        BooleanQuery query = booleanQueryFactory.create();

        // Context query
        query.addRequiredTerm(Field.COMPANY_ID, companyId);

        query.addRequiredTerm(Field.CLASS_NAME_ID, InserFitxaPersonal.class.getName());

        if (groupId > -1) {
            query.addRequiredTerm(Field.GROUP_ID, groupId);
        }

        if (Validator.isNotNull(organizationIds)) {

            BooleanQuery organizationQuery = booleanQueryFactory.create();

            if (organizationIds.length > 1 && organizationIds[0] == -2) {

                BooleanQuery q = booleanQueryFactory.create();

                SearchContext searchContext = new SearchContext();
                TermRangeQuery oq = TermRangeQueryFactoryUtil.create(searchContext, Field.ORGANIZATION_ID, "-1",
                        "0", true, false);

                q.add(oq, BooleanClauseOccur.SHOULD);

                // L'usuari vol veure tots els que estan sense localitzaci
                query.add(q, BooleanClauseOccur.MUST);
            } else {

                for (long idorg : organizationIds) {
                    if (idorg > -1) {
                        organizationQuery.addTerm(Field.ORGANIZATION_ID, idorg);
                    }
                }
            }

            if (organizationQuery.hasClauses()) {
                query.add(organizationQuery, BooleanClauseOccur.MUST);
            }

        }

        if (Validator.isNotNull(searchText)) {

            BooleanQuery searchTextQuery = booleanQueryFactory.create();

            searchTextQuery.addExactTerm(GestioPersonesIndexConstants.NUM_EXPEDIENT, searchText);
            searchTextQuery.addExactTerm(GestioPersonesIndexConstants.DNI, searchText);
            searchTextQuery.addTerm(Field.DESCRIPTION, searchText);
            searchTextQuery.addTerm(Field.TITLE, searchText);
            searchTextQuery.addTerm(GestioPersonesIndexConstants.TECNIC_REFERENT, searchText);
            searchTextQuery.addTerm(GestioPersonesIndexConstants.OBSERVACIONS, searchText);
            searchTextQuery.addTerm(GestioPersonesIndexConstants.SEGUIMENT_ITINERARI, searchText);
            searchTextQuery.addTerm(GestioPersonesIndexConstants.SEGUIMENT_ITINERARI, searchText);

            query.add(searchTextQuery, BooleanClauseOccur.MUST);

        }
        // Cerca avanada
        if (tecnicReferent > -1) {
            query.addRequiredTerm(GestioPersonesIndexConstants.TECNIC_REFERENT_ID, tecnicReferent);
        }

        if (codiProjecte > -1) {
            query.addRequiredTerm(GestioPersonesIndexConstants.CODI_PROJECTE_ID, codiProjecte);
        }

        if (serveiSocial > -1) {
            query.addRequiredTerm(GestioPersonesIndexConstants.SERVEI_SOCIAL_ID, serveiSocial);
        }

        Sort sort = new Sort();
        sort.setReverse(false);

        if (Validator.isNotNull(orderByCol)) {

            int type = getType(orderByCol);

            sort.setType(type);

            sort.setFieldName(orderByCol);

            if (Validator.isNotNull(orderByType)) {

                if (orderByType.equalsIgnoreCase("desc")) {
                    sort.setReverse(true);
                }

            }

        }

        log.info(query.toString() + " " + sort.toString());

        Hits search = SearchEngineUtil.search(searchEngineId, companyId, query, sort, start, end);

        return search;
    } catch (SearchException e) {
        log.error(e);
    } catch (ParseException e) {
        log.error(e);
    }

    return null;
}