Example usage for com.liferay.portal.kernel.dao.orm ProjectionFactoryUtil property

List of usage examples for com.liferay.portal.kernel.dao.orm ProjectionFactoryUtil property

Introduction

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

Prototype

public static Projection property(String propertyName) 

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 {/*from  w w  w .j a  va 2 s  .com*/
        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.rdconnect.service.impl.SearchIndexLocalServiceImpl.java

License:Open Source License

/**
 * Search for Reporting system for general user
 * // w ww . j av  a 2  s. c  o  m
 * @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:blade.servicebuilder.service.persistence.test.FooPersistenceTest.java

License:Open Source License

@Test
public void testDynamicQueryByProjectionExisting() throws Exception {
    Foo newFoo = addFoo();/*from w  ww. ja  va 2  s.com*/

    DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(Foo.class, _dynamicQueryClassLoader);

    dynamicQuery.setProjection(ProjectionFactoryUtil.property("fooId"));

    Object newFooId = newFoo.getFooId();

    dynamicQuery.add(RestrictionsFactoryUtil.in("fooId", new Object[] { newFooId }));

    List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(1, result.size());

    Object existingFooId = result.get(0);

    Assert.assertEquals(existingFooId, newFooId);
}

From source file:blade.servicebuilder.service.persistence.test.FooPersistenceTest.java

License:Open Source License

@Test
public void testDynamicQueryByProjectionMissing() throws Exception {
    DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(Foo.class, _dynamicQueryClassLoader);

    dynamicQuery.setProjection(ProjectionFactoryUtil.property("fooId"));

    dynamicQuery.add(RestrictionsFactoryUtil.in("fooId", new Object[] { RandomTestUtil.nextLong() }));

    List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(0, result.size());
}

From source file:ch.inofix.referencemanager.service.persistence.test.ReferencePersistenceTest.java

License:Open Source License

@Test
public void testDynamicQueryByProjectionExisting() throws Exception {
    Reference newReference = addReference();

    DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(Reference.class, _dynamicQueryClassLoader);

    dynamicQuery.setProjection(ProjectionFactoryUtil.property("referenceId"));

    Object newReferenceId = newReference.getReferenceId();

    dynamicQuery.add(RestrictionsFactoryUtil.in("referenceId", new Object[] { newReferenceId }));

    List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(1, result.size());

    Object existingReferenceId = result.get(0);

    Assert.assertEquals(existingReferenceId, newReferenceId);
}

From source file:ch.inofix.referencemanager.service.persistence.test.ReferencePersistenceTest.java

License:Open Source License

@Test
public void testDynamicQueryByProjectionMissing() throws Exception {
    DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(Reference.class, _dynamicQueryClassLoader);

    dynamicQuery.setProjection(ProjectionFactoryUtil.property("referenceId"));

    dynamicQuery.add(RestrictionsFactoryUtil.in("referenceId", new Object[] { RandomTestUtil.nextLong() }));

    List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(0, result.size());
}

From source file:com.bemis.portal.customer.service.persistence.test.CustomerLocationPersistenceTest.java

License:Open Source License

@Test
public void testDynamicQueryByProjectionExisting() throws Exception {
    CustomerLocation newCustomerLocation = addCustomerLocation();

    DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(CustomerLocation.class,
            _dynamicQueryClassLoader);/*  w  w w  .jav  a 2 s  . c o m*/

    dynamicQuery.setProjection(ProjectionFactoryUtil.property("customerLocationId"));

    Object newCustomerLocationId = newCustomerLocation.getCustomerLocationId();

    dynamicQuery.add(RestrictionsFactoryUtil.in("customerLocationId", new Object[] { newCustomerLocationId }));

    List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(1, result.size());

    Object existingCustomerLocationId = result.get(0);

    Assert.assertEquals(existingCustomerLocationId, newCustomerLocationId);
}

From source file:com.bemis.portal.customer.service.persistence.test.CustomerLocationPersistenceTest.java

License:Open Source License

@Test
public void testDynamicQueryByProjectionMissing() throws Exception {
    DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(CustomerLocation.class,
            _dynamicQueryClassLoader);/*w w  w  .  j a  v a2  s .  c o  m*/

    dynamicQuery.setProjection(ProjectionFactoryUtil.property("customerLocationId"));

    dynamicQuery
            .add(RestrictionsFactoryUtil.in("customerLocationId", new Object[] { RandomTestUtil.nextLong() }));

    List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(0, result.size());
}

From source file:com.bemis.portal.inventory.service.persistence.test.InventoryPersistenceTest.java

License:Open Source License

@Test
public void testDynamicQueryByProjectionExisting() throws Exception {
    Inventory newInventory = addInventory();

    DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(Inventory.class, _dynamicQueryClassLoader);

    dynamicQuery.setProjection(ProjectionFactoryUtil.property("inventoryId"));

    Object newInventoryId = newInventory.getInventoryId();

    dynamicQuery.add(RestrictionsFactoryUtil.in("inventoryId", new Object[] { newInventoryId }));

    List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(1, result.size());

    Object existingInventoryId = result.get(0);

    Assert.assertEquals(existingInventoryId, newInventoryId);
}

From source file:com.bemis.portal.inventory.service.persistence.test.InventoryPersistenceTest.java

License:Open Source License

@Test
public void testDynamicQueryByProjectionMissing() throws Exception {
    DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(Inventory.class, _dynamicQueryClassLoader);

    dynamicQuery.setProjection(ProjectionFactoryUtil.property("inventoryId"));

    dynamicQuery.add(RestrictionsFactoryUtil.in("inventoryId", new Object[] { RandomTestUtil.nextLong() }));

    List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(0, result.size());
}