Example usage for org.hibernate Query list

List of usage examples for org.hibernate Query list

Introduction

In this page you can find the example usage for org.hibernate Query list.

Prototype

List<R> list();

Source Link

Document

Return the query results as a List.

Usage

From source file:au.edu.anu.metadatastores.services.aries.ContractId.java

License:Open Source License

/**
 * Get the grants associated with the given university
 * /*from  w  w w  .  java  2 s . c  o  m*/
 * @param uniID The university id
 * @return The array of grants
 */
public ANUActivity[] getActivitiesByUniID(String uniID) {
    Session session = AriesHibernateUtil.getSessionFactory().openSession();
    try {
        Query query = session.createQuery("from ContractsGrantsInvestigators where chrStaffNumber = :uniID");
        query.setParameter("uniID", uniID);
        @SuppressWarnings("unchecked")
        List<ContractsGrantsInvestigators> investigators = query.list();
        List<ANUActivity> activities = new ArrayList<ANUActivity>();

        ANUActivityImpl tempActivity = null;
        String investigatorCode = null;

        for (ContractsGrantsInvestigators investigator : investigators) {
            investigatorCode = investigator.getChrContractInvestigatorCode();
            investigatorCode = investigatorCode.substring(0, investigatorCode.indexOf(uniID));
            if (investigatorCode != null) {
                tempActivity = new ANUActivityImpl();
                tempActivity.setActivityId(investigatorCode);
                //TODO flesh this out
                //   tempActivity.setFirstInvestigatorId(uniID);
                activities.add(tempActivity);
            }
        }

        return activities.toArray(new ANUActivity[0]);
    } finally {
        session.close();
    }

}

From source file:au.edu.anu.metadatastores.services.aries.DepartmentId.java

License:Open Source License

/**
 * Get an array of department names given the department ids
 * /*from  w ww .  j av a  2 s . c  o m*/
 * @param departmentIDs The department ids to get the name of
 * @return The array of department names
 */
public String[] getDepartmentNames(String[] departmentIDs) {
    Session session = AriesHibernateUtil.getSessionFactory().openSession();
    try {
        Query query = session.createQuery("from Departments where trim(chrTier3code) in :departmentIDs");
        query.setParameterList("departmentIDs", departmentIDs);

        @SuppressWarnings("unchecked")
        List<Departments> departments = query.list();

        String[] departmentNames = new String[departmentIDs.length];
        boolean foundDepartment = false;
        String departmentName = null;
        for (int i = 0; i < departmentIDs.length; i++) {
            for (Departments department : departments) {
                if (department != null) {
                    department.getId().getChrTier3code().trim();
                    if (department.getId().getChrTier3code().trim().equals(departmentIDs[i])) {
                        departmentName = department.getId().getChrTier3name();
                        foundDepartment = true;
                        break;
                    }
                }
            }

            if (foundDepartment) {
                departmentNames[i] = departmentName;
            } else {
                departmentNames[i] = "No name found for this department ID";
            }
            foundDepartment = false;
        }

        return departmentNames;
    } finally {
        session.close();
    }
}

From source file:au.edu.anu.metadatastores.services.aries.PublicationId.java

License:Open Source License

/**
 * Retrieve all the publications for a given year
 * /* ww w.  java  2s.c  o m*/
 * @param year The year to retrieve publications for
 * @return The list of publications
 */
public Publication[] getPublicationsForYear(String year) {
    Session session = AriesHibernateUtil.getSessionFactory().openSession();
    try {
        Query query = session.createQuery("from ResearchOutputsData1 where chrReportingYear = :year");
        query.setParameter("year", year);

        Publication tempPublication = null;
        List<Publication> publications = new ArrayList<Publication>();

        @SuppressWarnings("unchecked")
        List<ResearchOutputsData1> researchOutputs = query.list();
        for (ResearchOutputsData1 output : researchOutputs) {
            tempPublication = getPublication(output);
            publications.add(tempPublication);
        }

        return publications.toArray(new Publication[0]);
    } finally {
        session.close();
    }
}

From source file:au.edu.anu.metadatastores.services.aries.PublicationId.java

License:Open Source License

/**
 * Retrieve the first authors // w w  w  .java  2 s .  c o m
 * 
 * @param publicationCodes The publication codes
 * @return The university ids of the first authors
 */
public String[] getFirstAuthorsUniIDs(String[] publicationCodes) {
    Session session = AriesHibernateUtil.getSessionFactory().openSession();

    try {
        Query query = session.createQuery(
                "from ResearchOutputsDataAuthors where chrOutputInvestigatorCode like :publicationCode and chrOrder = '01'");

        List<ResearchOutputsDataAuthors> outputAuthors = null;

        String outputInvestigatorCode = null;

        List<String> uniIDs = new ArrayList<String>();
        String staffCode = null;

        for (String publicationCode : publicationCodes) {
            query.setParameter("publicationCode", publicationCode + "x%");

            //@SuppressWarnings("unchecked")
            outputAuthors = query.list();
            for (ResearchOutputsDataAuthors outputAuthor : outputAuthors) {
                outputInvestigatorCode = outputAuthor.getChrOutputInvestigatorCode();
                if (publicationCode != null && outputInvestigatorCode.indexOf(publicationCode) != -1) {
                    staffCode = outputAuthor.getChrStaffNumber();
                    uniIDs.add(staffCode);
                }
            }
        }

        return uniIDs.toArray(new String[0]);
    } finally {
        session.close();
    }
}

From source file:au.edu.anu.metadatastores.services.aries.PublicationId.java

License:Open Source License

/**
 * Retrieve the first authors/*from  ww  w  .  j ava 2 s .  co m*/
 * 
 * @param publicationCodes The publication codes
 * @return The first named authors
 */
public String[] getFirstAuthors(String[] publicationCodes) {
    Session session = AriesHibernateUtil.getSessionFactory().openSession();
    try {
        Query query = session
                .createQuery("from ResearchOutputsData1 where chrOutput6code in :publicationCodes");
        query.setParameterList("publicationCodes", publicationCodes);

        @SuppressWarnings("unchecked")
        List<ResearchOutputsData1> researchOutputs = query.list();

        List<String> firstAuthors = new ArrayList<String>();
        for (ResearchOutputsData1 researchOutput : researchOutputs) {
            if (researchOutput != null && researchOutput.getChrFirstNamedAuthor() != null) {
                firstAuthors.add(researchOutput.getChrFirstNamedAuthor());
            }
        }

        return firstAuthors.toArray(new String[0]);
    } finally {
        session.close();
    }
}

From source file:au.edu.anu.metadatastores.services.aries.StaffId.java

License:Open Source License

/**
 * Get the contracts/grants for the given staff member
 * // www .  j  a  va 2s  .  c o m
 * @param staffId The id of the staff member
 * @return The activities associated with the staff member
 */
public ANUActivity[] getContracts(String staffId) {
    Session session = AriesHibernateUtil.getSessionFactory().openSession();
    try {
        Query query = session.createQuery("from ContractsGrantsInvestigators where chrStaffNumber = :staffId");
        query.setParameter("staffId", staffId);

        @SuppressWarnings("unchecked")
        List<ContractsGrantsInvestigators> results = query.list();

        ANUActivityImpl tempActivity = null;
        List<ANUActivity> activityResults = new ArrayList<ANUActivity>();

        ContractsGrantsInvestigators investigator = null;
        ContractsGrantsMain contract = null;
        for (int i = 0; i < results.size(); i++) {
            investigator = results.get(i);
            contract = investigator.getContractsGrantsMain();

            if (investigator.getChrStaffNumber() != null
                    && investigator.getChrContractInvestigatorCode() != null) {
                tempActivity = new ANUActivityImpl();
                tempActivity.setActivityId(contract.getChrContractCode());
                List<String> invesitgatorIds = new ArrayList<String>();
                for (ContractsGrantsInvestigators inv : contract.getContractsGrantsInvestigators()) {
                    invesitgatorIds.add(inv.getChrStaffNumber());
                    if ("Yes".equals(inv.getChrPrimary())) {
                        tempActivity.setFirstInvestigatorId(inv.getChrStaffNumber());
                    }
                }
                tempActivity.setInvestigators(invesitgatorIds.toArray(new String[0]));
                tempActivity.setActivityTitle(contract.getChrShortTitle());
                tempActivity.setStartDate(contract.getChrGrantStartDate());
                tempActivity.setEndDate(contract.getChrCompletionDate());
                tempActivity.setStatus(contract.getChrStatus());

                if (contract.getForCodes1() != null) {
                    Subject forSubject = new FORSubjectImpl(contract.getForCodes1().getChrForObjectiveCode(),
                            contract.getForCodes1().getChrForDescription(), contract.getChrForpercentage1());
                    tempActivity.setForSubject1(forSubject);
                }
                if (contract.getForCodes2() != null) {
                    Subject forSubject = new FORSubjectImpl(contract.getForCodes2().getChrForObjectiveCode(),
                            contract.getForCodes2().getChrForDescription(), contract.getChrForpercentage2());
                    tempActivity.setForSubject2(forSubject);
                }
                if (contract.getForCodes3() != null) {
                    Subject forSubject = new FORSubjectImpl(contract.getForCodes3().getChrForObjectiveCode(),
                            contract.getForCodes3().getChrForDescription(), contract.getChrForpercentage3());
                    tempActivity.setForSubject3(forSubject);
                }

                tempActivity.setFundsProvider(contract.getChrPrimaryFundsProvider());
                try {
                    String schemeRef = new String(contract.getChrSchemeRef().getBytes(), "UTF8");
                    //Check for if the schema is null, and if it is a non-breaking space
                    //The database character encoding appears to at least sometimes be in Cp1250 (i.e. windows encoding)
                    if (schemeRef != null && !"&nbsp;".equals(schemeRef)
                            && (new String(schemeRef.getBytes("Cp1250"), "UTF8").replaceFirst("^[\\xA0]+", "")
                                    .trim().length() > 0)) {
                        tempActivity.setSchemeReference(schemeRef);
                    }
                } catch (UnsupportedEncodingException e) {
                    LOGGER.error("Unsupported encoding UTF8");
                }

                activityResults.add(tempActivity);
            }
        }

        return activityResults.toArray(new ANUActivity[0]);
    } finally {
        session.close();
    }
}

From source file:au.edu.anu.metadatastores.services.aries.StaffId.java

License:Open Source License

/**
 * Get the publications that the staff member has been involved with
 * /*www  . java 2 s . co m*/
 * @param staffId The staff id to find publications for
 * @return A list of publications
 */
public Publication[] getPublications(String staffId) {
    Session session = AriesHibernateUtil.getSessionFactory().openSession();
    try {
        Query query = session
                .createQuery("from ResearchOutputsDataAuthors where lower(chrStaffNumber) = :staffId");
        query.setParameter("staffId", staffId);

        @SuppressWarnings("unchecked")
        List<ResearchOutputsDataAuthors> authors = query.list();

        Vector<String> uniqueOutputs = new Vector<String>();

        String outputDataCode = "";

        ResearchOutputsData1 outputCode = null;
        PublicationImpl tempPublication = null;
        List<Publication> publications = new ArrayList<Publication>();

        for (ResearchOutputsDataAuthors author : authors) {
            outputDataCode = author.getResearchOutputsData1().getChrOutput6code();
            if (!uniqueOutputs.contains(outputDataCode)) {
                outputCode = author.getResearchOutputsData1();
                tempPublication = new PublicationImpl();

                // It appears that some rows have a number in an appropriate row to fetch data however there is no data associated with that row
                try {
                    if (outputCode.getResearchOutputsJournals() != null) {
                        tempPublication.setPublicationType("Journal");
                        tempPublication.setPublicationName(
                                outputCode.getResearchOutputsJournals().getChrJournalName());
                        tempPublication.setISSN(outputCode.getResearchOutputsJournals().getChrISSN());
                    } else if (outputCode.getResearchOutputsConferences() != null) {
                        tempPublication.setPublicationType("Conference");
                        tempPublication.setPublicationName(
                                outputCode.getResearchOutputsConferences().getChrConferenceName());
                        tempPublication.setISBN(outputCode.getResearchOutputsConferences().getChrISBN());
                    } else if (outputCode.getResearchOutputsBooks() != null) {
                        tempPublication.setPublicationType("Book Chapter");
                        tempPublication
                                .setPublicationName(outputCode.getResearchOutputsBooks().getChrBookName());
                        tempPublication.setISBN(outputCode.getResearchOutputsBooks().getChrISBN());
                    }
                } catch (ObjectNotFoundException e) {
                    LOGGER.error(
                            "Error retrieving either Journal, Conference or Book Information for record: {}",
                            outputCode.getChrOutput6code());
                }
                tempPublication.setPublicationDate(outputCode.getChrReportingYear());
                tempPublication.setPublicationCategory(
                        outputCode.getResearchOutputsLevel2().getChrOutput2Description());
                List<String> authorsList = new ArrayList<String>();

                for (ResearchOutputsDataAuthors auth : outputCode.getResearchOutputsDataAuthorses()) {
                    authorsList.add(auth.getChrStaffNumber());
                }
                tempPublication.setAuthors(authorsList.toArray(new String[0]));

                tempPublication.setPublicationTitle(outputCode.getChrPublicationTitle());

                if (outputCode.getForCodes1() != null) {
                    Subject forSubject = new FORSubjectImpl(outputCode.getForCodes1().getChrForObjectiveCode(),
                            outputCode.getForCodes1().getChrForDescription(),
                            outputCode.getChrForpercentage1());
                    tempPublication.setForSubject1(forSubject);
                }
                if (outputCode.getForCodes2() != null) {
                    Subject forSubject = new FORSubjectImpl(outputCode.getForCodes2().getChrForObjectiveCode(),
                            outputCode.getForCodes2().getChrForDescription(),
                            outputCode.getChrForpercentage2());
                    tempPublication.setForSubject2(forSubject);
                }
                if (outputCode.getForCodes3() != null) {
                    Subject forSubject = new FORSubjectImpl(outputCode.getForCodes3().getChrForObjectiveCode(),
                            outputCode.getForCodes3().getChrForDescription(),
                            outputCode.getChrForpercentage3());
                    tempPublication.setForSubject3(forSubject);
                }

                tempPublication.setAriesId(outputCode.getChrOutput6code());

                publications.add(tempPublication);
            }
        }

        return publications.toArray(new Publication[0]);
    } finally {
        session.close();
    }
}

From source file:au.edu.anu.metadatastores.services.aries.StaffId.java

License:Open Source License

/**
 * Find the staff by a name/*from  w w  w. j ava2 s . co m*/
 * 
 * @param surname The surname of the person to find
 * @param givenName The given name of the person to find
 * @return An array of staff
 */
public ANUStaff[] findStaff(String surname, String givenName) {
    Session session = AriesHibernateUtil.getSessionFactory().openSession();
    try {
        Query query = session.createQuery(
                "from Useraccounts where lower(chrFirstname) = :firstname and lower(chrSurname) = :surname");
        query.setParameter("firstname", givenName);
        query.setParameter("surname", surname);

        @SuppressWarnings("unchecked")
        List<Useraccounts> users = query.list();
        List<ANUStaff> anuStaff = new ArrayList<ANUStaff>();
        ANUStaff staff = null;
        for (Useraccounts user : users) {
            staff = setStaffInformation(user, session);
            anuStaff.add(staff);
        }

        return anuStaff.toArray(new ANUStaff[0]);
    } finally {
        session.close();
    }
}

From source file:au.edu.anu.metadatastores.services.aries.StaffId.java

License:Open Source License

/**
 * Find staff by their surname//from   w w w  .j  a  v a2  s  .c  o m
 * 
 * @param surname The surname of the people to find
 * @return Staff members with the given surname
 */
public ANUStaff[] findStaffBySurname(String surname) {
    Session session = AriesHibernateUtil.getSessionFactory().openSession();
    try {
        Query query = session.createQuery("from Useraccounts where lower(chrSurname) = :surname");
        query.setParameter("surname", surname.toLowerCase());

        @SuppressWarnings("unchecked")
        List<Useraccounts> users = query.list();
        List<ANUStaff> anuStaff = new ArrayList<ANUStaff>();
        ANUStaff staff = null;
        for (Useraccounts user : users) {
            staff = setStaffInformation(user, session);
            anuStaff.add(staff);
        }

        return anuStaff.toArray(new ANUStaff[0]);
    } finally {
        session.close();
    }
}

From source file:au.edu.anu.metadatastores.services.aries.StaffId.java

License:Open Source License

/**
 * Find staff by their given name//from w  w  w .  j av  a  2 s. c o m
 * 
 * @param givenName The given name of the people to find
 * @return Staff members with the provided given name
 */
public ANUStaff[] findStaffByGivenName(String givenName) {
    Session session = AriesHibernateUtil.getSessionFactory().openSession();
    try {
        Query query = session.createQuery("from Useraccounts where lower(chrFirstname) = :firstname");
        query.setParameter("firstname", givenName.toLowerCase());

        @SuppressWarnings("unchecked")
        List<Useraccounts> users = query.list();
        List<ANUStaff> anuStaff = new ArrayList<ANUStaff>();
        ANUStaff staff = null;
        for (Useraccounts user : users) {
            staff = setStaffInformation(user, session);
            anuStaff.add(staff);
        }

        return anuStaff.toArray(new ANUStaff[0]);
    } finally {
        session.close();
    }
}