List of usage examples for org.hibernate Query setParameter
@SuppressWarnings("unchecked") Query<R> setParameter(int position, Object val);
From source file:au.edu.anu.metadatastores.services.aries.StaffId.java
License:Open Source License
/** * Get the contracts/grants for the given staff member * /*from www.j a va 2 s . 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 && !" ".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 * //from w ww .j ava 2 s . c o 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
/** * Get the information about the staff member * /* ww w.j a v a2 s.com*/ * @param staffId The staff member to get information about * @return The staff members information */ public ANUStaff getStaffInformation(String staffId) { Session session = AriesHibernateUtil.getSessionFactory().openSession(); try { Query query = session.createQuery("from Useraccounts where lower(chrStaffNumber) = :staffId"); query.setParameter("staffId", staffId.toLowerCase()); Useraccounts userAccount = (Useraccounts) query.uniqueResult(); if (userAccount == null) { return null; } ANUStaff staff = setStaffInformation(userAccount, session); return staff; } finally { session.close(); } }
From source file:au.edu.anu.metadatastores.services.aries.StaffId.java
License:Open Source License
/** * Get external staff members information * //w ww. j a va 2 s. co m * @param staffId The id of the person to get staff information from * @return The external staff member information */ public ExternalStaff getExternalStaffInformation(String staffId) { Session session = AriesHibernateUtil.getSessionFactory().openSession(); try { Query query = session.createQuery("from ExternalUsers where lower(chrCode) = :staffId"); query.setParameter("staffId", staffId); ExternalUsers externalUser = (ExternalUsers) query.uniqueResult(); if (externalUser == null) { return null; } ExternalStaff externalStaff = setExternalStaffInformation(externalUser); return externalStaff; } finally { session.close(); } }
From source file:au.edu.anu.metadatastores.services.aries.StaffId.java
License:Open Source License
/** * Find the staff by a name// w w w. j av a 2s . c o 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/* ww w .j ava2 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 ww .j a va 2 s . co 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(); } }
From source file:au.edu.anu.metadatastores.services.aries.StaffId.java
License:Open Source License
/** * Populates the ANUStaff object with the staff information from aries * //from w w w . ja v a2s . c om * @param userAccount The useraccount * @param session The hibernate session object * @return The ANUStaff information */ private ANUStaff setStaffInformation(Useraccounts userAccount, Session session) { ANUStaff staff = new ANUStaffImpl(); staff.setAriesId(userAccount.getIntSystemCounter()); staff.setUniId(userAccount.getChrStaffNumber()); staff.setTitle(userAccount.getChrTitle()); staff.setGivenName(userAccount.getChrFirstname()); staff.setSurname(userAccount.getChrSurname()); staff.setFax(userAccount.getChrFax()); staff.setPhone(userAccount.getChrTelephone()); staff.setEmail(userAccount.getChrEmail()); if (userAccount.getForCodes1() != null) { Subject forSubject = new FORSubjectImpl(userAccount.getForCodes1().getChrForObjectiveCode(), userAccount.getForCodes1().getChrForDescription(), userAccount.getChrForpercentage1()); staff.setForSubject1(forSubject); } if (userAccount.getForCodes2() != null) { Subject forSubject = new FORSubjectImpl(userAccount.getForCodes2().getChrForObjectiveCode(), userAccount.getForCodes2().getChrForDescription(), userAccount.getChrForpercentage2()); staff.setForSubject2(forSubject); } if (userAccount.getForCodes3() != null) { Subject forSubject = new FORSubjectImpl(userAccount.getForCodes3().getChrForObjectiveCode(), userAccount.getForCodes3().getChrForDescription(), userAccount.getChrForpercentage3()); staff.setForSubject3(forSubject); } Query departmentQuery = session.createQuery("from Departments where chrTier3Code = :departmentId"); departmentQuery.setParameter("departmentId", userAccount.getChrDepartmentCode()); Departments departmentRes = (Departments) departmentQuery.uniqueResult(); if (departmentRes != null) { Departments department = (Departments) departmentRes; staff.setDepartmentName(department.getId().getChrTier3name()); } return staff; }
From source file:au.edu.anu.metadatastores.services.aries.StaffId.java
License:Open Source License
/** * Find external staff by their name//from w ww . ja v a2 s .c o m * * @param surname The surname of the person to find * @param givenName The given name of the person to find * @return A list of external staff members who match the provided name */ public ExternalStaff[] findExternalStaff(String surname, String givenName) { Session session = AriesHibernateUtil.getSessionFactory().openSession(); try { List<ExternalStaff> externalStaff = new ArrayList<ExternalStaff>(); Query query = session.createQuery( "from ExternalUsers where lower(chrFirstname) = :firstname and lower(chrSurname) = :surname"); query.setParameter("firstname", givenName); query.setParameter("surname", surname); @SuppressWarnings("unchecked") List<ExternalUsers> users = query.list(); ExternalStaff staff = null; for (ExternalUsers user : users) { staff = setExternalStaffInformation(user); externalStaff.add(staff); } return externalStaff.toArray(new ExternalStaff[0]); } finally { session.close(); } }
From source file:au.edu.anu.metadatastores.services.aries.StaffId.java
License:Open Source License
/** * Find external staff by their surname//from ww w . ja v a 2 s . c om * * @param surname The surname to search on * @return The external staff members with the provided surname */ public ExternalStaff[] findExternalStaffBySurname(String surname) { Session session = AriesHibernateUtil.getSessionFactory().openSession(); try { List<ExternalStaff> externalStaff = new ArrayList<ExternalStaff>(); Query query = session.createQuery("from ExternalUsers where lower(chrSurname) = :surname"); query.setParameter("surname", surname.toLowerCase()); @SuppressWarnings("unchecked") List<ExternalUsers> users = query.list(); ExternalStaff staff = null; for (ExternalUsers user : users) { staff = setExternalStaffInformation(user); externalStaff.add(staff); } return externalStaff.toArray(new ExternalStaff[0]); } finally { session.close(); } }