Example usage for com.liferay.portal.kernel.dao.orm DynamicQuery setProjection

List of usage examples for com.liferay.portal.kernel.dao.orm DynamicQuery setProjection

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.dao.orm DynamicQuery setProjection.

Prototype

public DynamicQuery setProjection(Projection projection);

Source Link

Usage

From source file:at.meduni.liferay.portlet.bbmrieric.service.impl.BioBankLocalServiceImpl.java

License:Open Source License

public String getBioBankFiltered(String keyword, String country, String materialtype, String diagnosisavailable,
        String biobanksize, String typeofbiobank) {
    String array = "";
    try {//  w  ww. j a  v a  2 s. c om
        DynamicQuery dynamicQuery = BioBankLocalServiceUtil.dynamicQuery();
        Criterion criterion = null;

        if (!keyword.equalsIgnoreCase("")) {
            DynamicQuery subQuery = DynamicQueryFactoryUtil.forClass(SearchIndex.class);
            subQuery.add(RestrictionsFactoryUtil.ilike("searchindexvalue", "%" + keyword + "%"));
            subQuery.setProjection(ProjectionFactoryUtil.property("organisationid"));

            if (criterion == null) {
                criterion = PropertyFactoryUtil.forName("organisationid").in(subQuery);
            } else {
                criterion = RestrictionsFactoryUtil.and(criterion,
                        PropertyFactoryUtil.forName("organisationid").in(subQuery));
            }
        }
        if (!country.equalsIgnoreCase("")) {
            DynamicQuery subQuery = DynamicQueryFactoryUtil.forClass(SearchIndex.class);
            subQuery.add(PropertyFactoryUtil.forName("searchindexvalue").eq(country));
            subQuery.setProjection(ProjectionFactoryUtil.property("organisationid"));

            if (criterion == null) {
                criterion = PropertyFactoryUtil.forName("organisationid").in(subQuery);
            } else {
                criterion = RestrictionsFactoryUtil.and(criterion,
                        PropertyFactoryUtil.forName("organisationid").in(subQuery));
            }
        }
        if (!diagnosisavailable.equalsIgnoreCase("")) {
            Criterion criterion_sub = createSearchDiagnosisString(diagnosisavailable);
            DynamicQuery subQuery = DynamicQueryFactoryUtil.forClass(SearchIndex.class);
            subQuery.add(criterion_sub);
            subQuery.setProjection(ProjectionFactoryUtil.property("organisationid"));

            if (criterion == null) {
                criterion = PropertyFactoryUtil.forName("organisationid").in(subQuery);
            } else {
                criterion = RestrictionsFactoryUtil.and(criterion,
                        PropertyFactoryUtil.forName("organisationid").in(subQuery));
            }
        }
        if (!materialtype.equalsIgnoreCase("")) {
            DynamicQuery subQuery = DynamicQueryFactoryUtil.forClass(SearchIndex.class);
            Criterion criterion_sub = RestrictionsFactoryUtil.like("searchindexkey", materialtype);
            criterion_sub = RestrictionsFactoryUtil.and(criterion_sub,
                    RestrictionsFactoryUtil.like("searchindexvalue", "TRUE"));
            subQuery.add(criterion_sub);
            subQuery.setProjection(ProjectionFactoryUtil.property("organisationid"));

            if (criterion == null) {
                criterion = PropertyFactoryUtil.forName("organisationid").in(subQuery);
            } else {
                criterion = RestrictionsFactoryUtil.and(criterion,
                        PropertyFactoryUtil.forName("organisationid").in(subQuery));
            }
        }
        if (!typeofbiobank.equalsIgnoreCase("")) {
            DynamicQuery subQuery = DynamicQueryFactoryUtil.forClass(SearchIndex.class);
            Criterion criterion_sub = RestrictionsFactoryUtil.like("searchindexkey", "objectClass");
            criterion_sub = RestrictionsFactoryUtil.and(criterion_sub,
                    RestrictionsFactoryUtil.like("searchindexvalue", "%" + typeofbiobank + "%"));
            subQuery.add(criterion_sub);
            subQuery.setProjection(ProjectionFactoryUtil.property("organisationid"));

            if (criterion == null) {
                criterion = PropertyFactoryUtil.forName("organisationid").in(subQuery);
            } else {
                criterion = RestrictionsFactoryUtil.and(criterion,
                        PropertyFactoryUtil.forName("organisationid").in(subQuery));
            }
        }
        if (!biobanksize.equalsIgnoreCase("")) {

            String bbsize = "";
            if (biobanksize.equalsIgnoreCase("< 10 Samples")) {
                bbsize = "0";
            } else if (biobanksize.equalsIgnoreCase("10 - 100 Samples")) {
                bbsize = "1";
            } else if (biobanksize.equalsIgnoreCase("100 - 1.000 Samples")) {
                bbsize = "2";
            } else if (biobanksize.equalsIgnoreCase("1.000 - 10.000 Samples")) {
                bbsize = "3";
            } else if (biobanksize.equalsIgnoreCase("10.000 - 100.000 Samples")) {
                bbsize = "4";
            } else if (biobanksize.equalsIgnoreCase("100.000 - 1.000.000 Samples")) {
                bbsize = "5";
            } else if (biobanksize.equalsIgnoreCase("1.000.000 - 10.000.000 Samples")) {
                bbsize = "6";
            } else if (biobanksize.equalsIgnoreCase("10.000.000 - 100.000.000 Samples")) {
                bbsize = "7";
            } else if (biobanksize.equalsIgnoreCase("100.000.000 - 1.000.000.000 Samples")) {
                bbsize = "8";
            }

            DynamicQuery subQuery = DynamicQueryFactoryUtil.forClass(SearchIndex.class);
            Criterion criterion_sub = RestrictionsFactoryUtil.like("searchindexkey", "biobankSize");
            criterion_sub = RestrictionsFactoryUtil.and(criterion_sub,
                    RestrictionsFactoryUtil.like("searchindexvalue", bbsize));
            subQuery.add(criterion_sub);
            subQuery.setProjection(ProjectionFactoryUtil.property("organisationid"));

            if (criterion == null) {
                criterion = PropertyFactoryUtil.forName("organisationid").in(subQuery);
            } else {
                criterion = RestrictionsFactoryUtil.and(criterion,
                        PropertyFactoryUtil.forName("organisationid").in(subQuery));
            }
        }
        // Add Criterion to the Main Biobank Query
        if (criterion != null) {
            dynamicQuery.add(criterion);
        }
        List<BioBank> biobanks = BioBankLocalServiceUtil.dynamicQuery(dynamicQuery);
        String seperator = "";
        for (BioBank biobank : biobanks) {
            String diagnosis_avialavble = "";
            SearchIndex searchindex = SearchIndexLocalServiceUtil.getSearchIndex(biobank.getOrganisationid(),
                    "diagnosisAvailable");
            if (searchindex != null) {
                diagnosis_avialavble = searchindex.getSearchindexvalue().replaceAll("urn:miriam:", "");
            }
            array += seperator + "{";
            //Country
            array += "Country: '" + biobank.getBiobankcountry().replaceAll("'", "\\\\'") + "',";
            //BB ID
            array += "'BB_ID': '" + biobank.getLdapbiobankID().replaceAll("'", "\\\\'") + "',";
            //BB Diagnosis
            array += "'Diagnosis': '" + diagnosis_avialavble.replaceAll("'", "\\\\'") + "',";
            //Name
            array += "Name: '" + biobank.getBiobankname().replaceAll("'", "\\\\'") + "',";
            //Type
            array += "Type: '" + biobank.getBiobanktype().replaceAll("'", "\\\\'") + "',";
            //Size
            array += "Size: '" + biobank.getBiobanksize().replaceAll("'", "\\\\'") + "',";
            //Juristic Person
            array += "'Juristic Person': '" + biobank.getBiobankjuristicperson().replaceAll("'", "\\\\'") + "'";
            array += "}";
            seperator = ",";
        }
    } catch (Exception ex) {
        System.out.println("[" + date_format_apache_error.format(new Date())
                + "] [info] [BBMRIERICDatabase-portlet::at.meduni.liferay.portlet.bbmrieric.service.impl.BioBankLocalServiceImpl::getBioBankFiltered] Could not get Biobank List filtered ("
                + keyword + ", " + country + ", " + materialtype + ", " + diagnosisavailable + ", "
                + biobanksize + ").");
        ex.printStackTrace();
    }
    return array;
}

From source file:at.meduni.liferay.portlet.bbmrieric.service.impl.D2BiobankLocalServiceImpl.java

License:Open Source License

private DynamicQuery getBiobankQueryForKeywords(String keyword) {
    DynamicQuery dynamicQuery = D2BiobankLocalServiceUtil.dynamicQuery();
    ProjectionList projectionList = ProjectionFactoryUtil.projectionList();
    projectionList.add(ProjectionFactoryUtil.groupProperty("biobankId"));
    dynamicQuery.setProjection(projectionList);
    String[] keywords = keyword.split(" ");
    Criterion criterion = null;/*from   w  w w . ja v  a  2s  .  c  om*/
    if (!keyword.equals("")) {
        for (String search : keywords) {
            if (criterion == null) {
                criterion = RestrictionsFactoryUtil.ilike("bbmribiobankID", "%" + search + "%");
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("biobankName", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("biobankJurisdicalPerson", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("biobankCountry", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("bioresourceReference", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("biobankAcronym", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("biobankDescription", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("biobankHeadFirstName", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("biobankHeadLastName", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("biobankHeadRole", "%" + search + "%"));
            } else {
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("bbmribiobankID", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("biobankName", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("biobankJurisdicalPerson", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("biobankCountry", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("bioresourceReference", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("biobankAcronym", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("biobankDescription", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("biobankHeadFirstName", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("biobankHeadLastName", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("biobankHeadRole", "%" + search + "%"));
            }
        }
    }
    if (criterion != null) {
        dynamicQuery.add(criterion);
    }
    return dynamicQuery;
}

From source file:at.meduni.liferay.portlet.bbmrieric.service.impl.D2BiobankLocalServiceImpl.java

License:Open Source License

private DynamicQuery getCollectionSubqueryForKeywords(String keyword) {
    DynamicQuery dynamicQuery = D2CollectionLocalServiceUtil.dynamicQuery();
    ProjectionList projectionList = ProjectionFactoryUtil.projectionList();
    projectionList.add(ProjectionFactoryUtil.groupProperty("biobankId"));
    dynamicQuery.setProjection(projectionList);
    String[] keywords = keyword.split(" ");
    Criterion criterion = null;/*  ww w .  j a va 2  s.  com*/
    if (!keyword.equals("")) {
        for (String search : keywords) {
            if (criterion == null) {
                criterion = RestrictionsFactoryUtil.ilike("bbmricollectionID", "%" + search + "%");
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("collectionName", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("materialStoredOther", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("collectionTypeOther", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("bioresourceReference", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("collectionAcronym", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("collectionDescription", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("temperatureOther", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("diagnosisAvailable", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("collectionHeadFirstName", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("collectionHeadLastName", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("collectionHeadRole", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("collectionSampleAccessDescription", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("collectionDataAccessDescription", "%" + search + "%"));
            } else {
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("bbmricollectionID", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("collectionName", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("materialStoredOther", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("collectionTypeOther", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("bioresourceReference", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("collectionAcronym", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("collectionDescription", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("temperatureOther", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("diagnosisAvailable", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("collectionHeadFirstName", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("collectionHeadLastName", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("collectionHeadRole", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("collectionSampleAccessDescription", "%" + search + "%"));
                criterion = RestrictionsFactoryUtil.or(criterion,
                        RestrictionsFactoryUtil.ilike("collectionDataAccessDescription", "%" + search + "%"));
            }
        }
    }
    if (criterion != null) {
        dynamicQuery.add(criterion);
    }
    return dynamicQuery;
}

From source file:at.meduni.liferay.portlet.bbmrieric.service.impl.D2BiobankLocalServiceImpl.java

License:Open Source License

private DynamicQuery getCollectionSubquery(String materialtype, String diagnosisavailable, String biobanksize,
        long powerof, String typeofcollection) {
    DynamicQuery dynamicQuery = D2CollectionLocalServiceUtil.dynamicQuery();
    ProjectionList projectionList = ProjectionFactoryUtil.projectionList();
    projectionList.add(ProjectionFactoryUtil.groupProperty("biobankId"));
    dynamicQuery.setProjection(projectionList);

    Criterion criterion = null;/*w  w w .  j av a  2s  .  com*/

    if (!materialtype.equals("")) {
        String[] materialtypes = { "Plasma", "Serum", "Urine", "Saliva", "Faeces", "RNA", "Blood",
                "Tissue Frozen", "Tissue FFPE", "Immortalized Cell Lines", "Isolated Pathogen" };
        boolean others = true;

        for (String materialtypes_tmp : materialtypes) {
            if (materialtype.equalsIgnoreCase(materialtypes_tmp)) {
                String colname = "materialStored" + materialtypes_tmp.replaceAll(" ", "");
                if (criterion == null) {
                    criterion = RestrictionsFactoryUtil.eq(colname, true);
                } else {
                    criterion = RestrictionsFactoryUtil.and(criterion,
                            RestrictionsFactoryUtil.eq(colname, true));
                }
                others = false;
            }
        }
        if (others) {
            if (criterion == null) {
                criterion = RestrictionsFactoryUtil.ilike("materialStoredOther", "%" + materialtype + "%");
            } else {
                criterion = RestrictionsFactoryUtil.and(criterion,
                        RestrictionsFactoryUtil.ilike("materialStoredOther", "%" + materialtype + "%"));
            }
        }
    }
    if (!diagnosisavailable.equals("")) {
        if (criterion == null) {
            criterion = createSearchDiagnosisString(diagnosisavailable);
        } else {
            criterion = RestrictionsFactoryUtil.and(criterion, createSearchDiagnosisString(diagnosisavailable));
        }
    }
    if (!biobanksize.equals("")) {
        if (criterion == null) {
            criterion = RestrictionsFactoryUtil.eq("collectionOrderOfMagnitude", powerof);
        } else {
            criterion = RestrictionsFactoryUtil.and(criterion,
                    RestrictionsFactoryUtil.eq("collectionOrderOfMagnitude", powerof));
        }
    }
    if (!typeofcollection.equals("")) {
        String[] typeofcollections = { "Case Control", "Cohort", "Cross Sectional", "Longitudinal",
                "Twin Study", "Quality Control", "Population Based", "Disease Specific", "Birth Cohort" };
        boolean others = true;
        for (String typeofcollection_tmp : typeofcollections) {
            if (typeofcollection.equalsIgnoreCase(typeofcollection_tmp)) {
                String colname = "collectionType" + typeofcollection_tmp.replaceAll(" ", "");
                if (criterion == null) {
                    criterion = RestrictionsFactoryUtil.eq(colname, true);
                } else {
                    criterion = RestrictionsFactoryUtil.and(criterion,
                            RestrictionsFactoryUtil.eq(colname, true));
                }
                others = false;
            }
        }
        if (others) {
            if (criterion == null) {
                criterion = RestrictionsFactoryUtil.ilike("collectionTypeOther", "%" + typeofcollection + "%");
            } else {
                criterion = RestrictionsFactoryUtil.and(criterion,
                        RestrictionsFactoryUtil.ilike("collectionTypeOther", "%" + typeofcollection + "%"));
            }
        }
    }
    dynamicQuery.add(criterion);
    return dynamicQuery;
}

From source file:at.meduni.liferay.portlet.bbmrieric.service.impl.D2BiobankLocalServiceImpl.java

License:Open Source License

private DynamicQuery getContactInformationSubquery(String keyword) {
    DynamicQuery dynamicQuery = D2BiobankLocalServiceUtil.dynamicQuery();
    ProjectionList projectionList = ProjectionFactoryUtil.projectionList();
    projectionList.add(ProjectionFactoryUtil.groupProperty("biobankId"));
    dynamicQuery.setProjection(projectionList);

    DynamicQuery dynamicQuerySub = ContactInformationLocalServiceUtil.dynamicQuery();
    ProjectionList projectionList_Sub = ProjectionFactoryUtil.projectionList();
    projectionList_Sub.add(ProjectionFactoryUtil.groupProperty("contactID"));
    dynamicQuerySub.setProjection(projectionList_Sub);
    String[] keywords = keyword.split(" ");
    Criterion criterion = null;/*from  w w  w.java  2 s  . c o m*/
    for (String search : keywords) {
        if (criterion == null) {
            criterion = RestrictionsFactoryUtil.ilike("contactID", "%" + search + "%");
            criterion = RestrictionsFactoryUtil.or(criterion,
                    RestrictionsFactoryUtil.ilike("contactEmail", "%" + search + "%"));
            criterion = RestrictionsFactoryUtil.or(criterion,
                    RestrictionsFactoryUtil.ilike("contactCountry", "%" + search + "%"));
            criterion = RestrictionsFactoryUtil.or(criterion,
                    RestrictionsFactoryUtil.ilike("contactFirstName", "%" + search + "%"));
            criterion = RestrictionsFactoryUtil.or(criterion,
                    RestrictionsFactoryUtil.ilike("contactLastName", "%" + search + "%"));
            criterion = RestrictionsFactoryUtil.or(criterion,
                    RestrictionsFactoryUtil.ilike("contactPhone", "%" + search + "%"));
            criterion = RestrictionsFactoryUtil.or(criterion,
                    RestrictionsFactoryUtil.ilike("contactAddress", "%" + search + "%"));
            criterion = RestrictionsFactoryUtil.or(criterion,
                    RestrictionsFactoryUtil.ilike("contactZIP", "%" + search + "%"));
            criterion = RestrictionsFactoryUtil.or(criterion,
                    RestrictionsFactoryUtil.ilike("contactCity", "%" + search + "%"));
        } else {
            criterion = RestrictionsFactoryUtil.or(criterion,
                    RestrictionsFactoryUtil.ilike("contactID", "%" + search + "%"));
            criterion = RestrictionsFactoryUtil.or(criterion,
                    RestrictionsFactoryUtil.ilike("contactEmail", "%" + search + "%"));
            criterion = RestrictionsFactoryUtil.or(criterion,
                    RestrictionsFactoryUtil.ilike("contactCountry", "%" + search + "%"));
            criterion = RestrictionsFactoryUtil.or(criterion,
                    RestrictionsFactoryUtil.ilike("contactFirstName", "%" + search + "%"));
            criterion = RestrictionsFactoryUtil.or(criterion,
                    RestrictionsFactoryUtil.ilike("contactLastName", "%" + search + "%"));
            criterion = RestrictionsFactoryUtil.or(criterion,
                    RestrictionsFactoryUtil.ilike("contactPhone", "%" + search + "%"));
            criterion = RestrictionsFactoryUtil.or(criterion,
                    RestrictionsFactoryUtil.ilike("contactAddress", "%" + search + "%"));
            criterion = RestrictionsFactoryUtil.or(criterion,
                    RestrictionsFactoryUtil.ilike("contactZIP", "%" + search + "%"));
            criterion = RestrictionsFactoryUtil.or(criterion,
                    RestrictionsFactoryUtil.ilike("contactCity", "%" + search + "%"));
        }
    }
    dynamicQuerySub.add(criterion);
    dynamicQuery.add(PropertyFactoryUtil.forName("contactIDRef").in(dynamicQuerySub));
    return dynamicQuery;
}

From source file:at.meduni.liferay.portlet.bbmrieric.service.impl.SearchIndexLocalServiceImpl.java

License:Open Source License

public String[] getMaterialTypes() {
    try {/*  w  w  w  .  ja  va2  s  .com*/
        DynamicQuery dynamicQuery = SearchIndexLocalServiceUtil.dynamicQuery();
        Criterion criterion = RestrictionsFactoryUtil.like("searchindexkey", "biobankMaterialStored%");
        dynamicQuery.add(criterion);
        ProjectionList projectionList = ProjectionFactoryUtil.projectionList();
        projectionList.add(ProjectionFactoryUtil.groupProperty("searchindexkey"));
        //projectionList.add(ProjectionFactoryUtil.rowCount());
        dynamicQuery.setProjection(projectionList);
        List<Object> results = SearchIndexLocalServiceUtil.dynamicQuery(dynamicQuery);
        /*for(Object result : results) {
           System.out.println(result);   
        }*/
        return results.toArray(new String[results.size()]);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return new String[] {};
}

From source file:at.meduni.liferay.portlet.bbmrieric.service.impl.SearchIndexLocalServiceImpl.java

License:Open Source License

public String[] getCountry() {
    try {/*from ww  w .  j a  va  2s  .  co  m*/
        DynamicQuery dynamicQuery = SearchIndexLocalServiceUtil.dynamicQuery();
        Criterion criterion = RestrictionsFactoryUtil.like("searchindexkey", "biobankCountry");
        dynamicQuery.add(criterion);
        ProjectionList projectionList = ProjectionFactoryUtil.projectionList();
        projectionList.add(ProjectionFactoryUtil.groupProperty("searchindexvalue"));
        //projectionList.add(ProjectionFactoryUtil.rowCount());
        dynamicQuery.setProjection(projectionList);
        Order defaultOrder = OrderFactoryUtil.desc("searchindexvalue");
        dynamicQuery.addOrder(defaultOrder);
        List<Object> results = SearchIndexLocalServiceUtil.dynamicQuery(dynamicQuery);
        /*for(Object result : results) {
           System.out.println(result);   
        }*/
        return results.toArray(new String[results.size()]);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return new String[] {};
}

From source file:at.meduni.liferay.portlet.bbmrieric.service.impl.SearchIndexLocalServiceImpl.java

License:Open Source License

public String[] getTypeOfBiobank() {
    try {/*from  w  w  w . j a va 2s.co  m*/
        HashSet<String> resultcleand = new HashSet<String>();
        DynamicQuery dynamicQuery = SearchIndexLocalServiceUtil.dynamicQuery();
        Criterion criterion = RestrictionsFactoryUtil.like("searchindexkey", "objectClass");
        dynamicQuery.add(criterion);
        ProjectionList projectionList = ProjectionFactoryUtil.projectionList();
        projectionList.add(ProjectionFactoryUtil.groupProperty("searchindexvalue"));
        dynamicQuery.setProjection(projectionList);
        List<Object> results = SearchIndexLocalServiceUtil.dynamicQuery(dynamicQuery);
        for (Object result : results) {
            for (String split : result.toString().split(", ")) {
                if (split.equalsIgnoreCase("biobankContact")) {
                    continue;
                }
                if (!resultcleand.contains(split)) {
                    resultcleand.add(split);
                }
            }
        }
        return resultcleand.toArray(new String[resultcleand.size()]);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return new String[] {};
}

From source file:at.meduni.liferay.portlet.rdconnect.service.impl.SearchIndexLocalServiceImpl.java

License:Open Source License

/**
 * Search for Reporting system for general user
 * // w  w  w.j  a v a2 s.  com
 * @param keyword
 * @param type
 * @return
 */
public String getSearchIndexByKeyword(String keyword, String type, ThemeDisplay themeDisplay,
        String contextpath, long maincontactrole) {
    keyword = keyword.trim();
    type = type.trim();
    String searchresultstring = "";
    try {
        DynamicQuery dynamicQuery = null;
        if (type.equalsIgnoreCase("all")) {
            dynamicQuery = DynamicQueryFactoryUtil.forClass(SearchIndex.class);
            Criterion criterion = RestrictionsFactoryUtil.ilike("value",
                    StringPool.PERCENT + keyword + StringPool.PERCENT);
            //if(!type.equalsIgnoreCase("all")) {
            //Criterion criterion_type = RestrictionsFactoryUtil.ilike("value", type);
            //criterion_type = RestrictionsFactoryUtil.and(criterion_type, RestrictionsFactoryUtil.ilike("key", StringPool.PERCENT + "Type" + StringPool.PERCENT));
            //criterion = RestrictionsFactoryUtil.and(criterion, criterion_type);

            dynamicQuery.add(criterion);
        } else {
            DynamicQuery subQuery = DynamicQueryFactoryUtil.forClass(SearchIndex.class)
                    .add(PropertyFactoryUtil.forName("value").eq(type));
            subQuery.setProjection(ProjectionFactoryUtil.property("organisationid"));

            dynamicQuery = DynamicQueryFactoryUtil.forClass(SearchIndex.class)
                    .add(PropertyFactoryUtil.forName("value")
                            .like(StringPool.PERCENT + keyword + StringPool.PERCENT))
                    .add(PropertyFactoryUtil.forName("organisationid").in(subQuery));
        }

        Order order_organisationid = OrderFactoryUtil.asc("organisationid");
        Order order_location = OrderFactoryUtil.asc("location");
        Order order_locationid = OrderFactoryUtil.asc("locationid");
        dynamicQuery.addOrder(order_organisationid);
        dynamicQuery.addOrder(order_location);
        dynamicQuery.addOrder(order_locationid);
        List<SearchIndex> serachresults = SearchIndexLocalServiceUtil.dynamicQuery(dynamicQuery);
        // Format the result
        long oldorganizationid = 0;
        Organization organization = null;
        int regcount = 0;
        int bbcount = 0;
        SearchIndex oldsearchindex = null;
        String organizationline = "";
        String maincontactline = "";
        String organizationurl = "";
        HashMap<String, String> hits = null;
        boolean first = true;
        for (SearchIndex serachresult : serachresults) {
            try {
                if (oldorganizationid == 0 || oldorganizationid != serachresult.getOrganisationid()) {
                    if (!first) {
                        searchresultstring += ",";
                    }
                    first = false;
                    organization = OrganizationLocalServiceUtil
                            .getOrganization(serachresult.getOrganisationid());
                    // Disease Matrix
                    List<DiseaseMatrix> diseasematrixes = DiseaseMatrixLocalServiceUtil
                            .getDiseaseMatrixs(organization.getOrganizationId(), -1, -1);
                    long diseascount = 0;
                    Date tmp_lastupdated = null;
                    for (DiseaseMatrix diseasematrix : diseasematrixes) {
                        try {
                            if (tmp_lastupdated == null) {
                                tmp_lastupdated = diseasematrix.getModifieddate();
                            }
                            if (tmp_lastupdated.before(diseasematrix.getModifieddate())) {
                                tmp_lastupdated = diseasematrix.getModifieddate();
                            }

                            diseascount += Long.parseLong(diseasematrix.getPatientcount());
                        } catch (Exception ex) {

                        }
                    }
                    String lastupdated = "";
                    if (tmp_lastupdated != null) {
                        String date_format_pattern = "yyyy/MM";
                        SimpleDateFormat date_format = new SimpleDateFormat(date_format_pattern);
                        lastupdated = date_format.format(tmp_lastupdated);
                    }

                    String organizationtype = organization.getExpandoBridge().getAttribute("Organization Type")
                            .toString();
                    String orgPath = themeDisplay.getURLPortal() + "/web"
                            + organization.getGroup().getFriendlyURL();
                    String imgPath = themeDisplay.getPathImage() + "/layout_set_logo?img_id="
                            + organization.getLogoId();
                    int numberofacces = RDCOrganizationUserAccessLocalServiceUtil
                            .countRDCOrganizationUserAccess(organization.getOrganizationId());
                    if (organizationtype.equalsIgnoreCase("Biobank")) {
                        if (organization.getLogoId() == 0) {
                            imgPath = "/BiBBoxCommonServices-portlet/images/Biobank.png";
                        }
                        orgPath = orgPath + "/bb_home";
                    } else {
                        if (organization.getLogoId() == 0) {
                            imgPath = "/BiBBoxCommonServices-portlet/images/Registry.png";
                        }
                        orgPath = orgPath + "/reg_home";
                    }

                    // Data in DDL
                    String core_name = "core";
                    String countryCode_value = "countryCode";
                    if (organizationtype.equalsIgnoreCase("Biobank")) {
                        core_name = "bb_core";
                    }
                    String countryCode = "not specified";
                    List<DDLRecordSet> rdc_recordlist = DDLRecordSetLocalServiceUtil
                            .getRecordSets(organization.getGroupId());
                    for (DDLRecordSet rdc_rs : rdc_recordlist) {
                        String rdc_rsname = String.valueOf(rdc_rs.getNameCurrentValue());
                        if (rdc_rsname.equals(core_name)) {
                            List<DDLRecord> records = rdc_rs.getRecords();
                            for (DDLRecord record : records) {
                                try {
                                    countryCode = record.getFieldValue(countryCode_value).toString()
                                            .replaceAll("\"\\]|\\[\"", "");
                                } catch (Exception ex) {

                                }
                            }
                        }
                    }

                    String maincontactmail = "";
                    User maincontact = null;
                    List<User> userlist = UserLocalServiceUtil
                            .getOrganizationUsers(organization.getOrganizationId());
                    for (User usertmp : userlist) {
                        List<UserGroupRole> usergrouprolles = UserGroupRoleLocalServiceUtil
                                .getUserGroupRoles(usertmp.getUserId(), organization.getGroup().getGroupId());
                        for (UserGroupRole ugr : usergrouprolles) {
                            if (ugr.getRoleId() == maincontactrole) {
                                maincontact = usertmp;
                            }
                        }
                    }
                    if (maincontact != null) {
                        maincontactmail = maincontact.getEmailAddress();
                    }
                    searchresultstring += "{Name: '" + organization.getName().replaceAll("'", "&lsquo;") + "', "
                            + "OrganizationLink: '" + orgPath + "'," + "OrganizationImageLink: '" + imgPath
                            + "'," + "Type: '"
                            + organization.getExpandoBridge().getAttribute("Organization Type").toString()
                            + "'," + "'NumberofCases': " + diseascount + "," + "'CountryCode': '" + countryCode
                            + "'," + "'Request data':  '" + maincontactmail + "', " + "'lastupdated':  '"
                            + lastupdated + "', " + "'Number of access': " + numberofacces + "}";
                    // New Hit
                    oldorganizationid = serachresult.getOrganisationid();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (searchresultstring.length() == 0) {
        searchresultstring = "No Results for the query.";
    }
    return searchresultstring;
}

From source file:at.pw.service.impl.InventoryLocalServiceImpl.java

License:Open Source License

public Inventory addInventoryWithAutoincrement() {
    try {/*from w  w  w  .  ja  v  a  2s  .  com*/
        InventoryImpl inventory = new InventoryImpl();
        inventory.setInventoryId(CounterLocalServiceUtil.increment());
        DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(Inventory.class);
        dynamicQuery.setProjection(ProjectionFactoryUtil.max("inventarnummer"));
        List results = InventoryLocalServiceUtil.dynamicQuery(dynamicQuery);
        long id = 0;
        for (Object obj : results) {
            try {
                id = Long.parseLong(obj.toString());
            } catch (Exception ex) {

            }
        }
        inventory.setInventarnummer(id + 1);
        return InventoryLocalServiceUtil.addInventory(inventory);
    } catch (SystemException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}