List of usage examples for org.apache.commons.beanutils PropertyUtils isReadable
public static boolean isReadable(Object bean, String name)
Return true
if the specified property name identifies a readable property on the specified bean; otherwise, return false
.
For more details see PropertyUtilsBean
.
From source file:org.ms123.common.data.TriggerServiceImpl.java
private boolean testTriggerConditions(SessionContext sessionContext, Map triggerMap, StoreDesc sdesc, String entity, String config, Object insert, Object preUpdate, Map triggerInfo) throws Exception { int operation = (Integer) triggerInfo.get("operation"); List<Map> conditions = (List) triggerMap.get("conditions"); Map fieldSets = m_settingService.getFieldSets(config, sdesc.getNamespace(), m_inflector.getEntityName(entity)); boolean ok = false; if (conditions.size() == 0) { return true; }//from ww w. ja v a 2s .com for (Map cond : conditions) { if (cond.size() == 0) { ok = true; continue; } QueryBuilder qb = new QueryBuilder("mvel", sdesc, entity, false, config, sessionContext, null, cond, null, fieldSets); String evalString = qb.getWhere(); Map props = new HashMap(); props.putAll(qb.getQueryParams()); props.put(m_inflector.getEntityName(entity), insert); if (PropertyUtils.isReadable(insert, "_team_list")) { Set nowList = (Set) PropertyUtils.getProperty(insert, "_team_list"); Set preList = (Set) ((Map) preUpdate).get("_team_list"); if (nowList != null || preList != null) { Map tc = _getTeamChangedFlags(preList, nowList); props.put("team_changed", tc); triggerInfo.put("teamsChanged", _getTeamChangedList(tc, preList, nowList)); } } props.put(m_inflector.getEntityName(entity) + "_pre", preUpdate); debug("TestTrigger.evalString:" + evalString); if (isDebug()) { debug("TestTrigger.properties:" + m_js.deepSerialize(props)); } ok = MVEL.evalToBoolean(evalString, props); debug("\tTestTrigger.ok:" + ok); if (!ok) { return ok; } } return ok; }
From source file:org.ms123.common.data.Utils.java
public static List<Map> getTeamChangedList(TeamService ts, Object object, Object objectPre) { List<Map> answer = null; if (PropertyUtils.isReadable(object, "_team_list")) { try {/*from w ww . j a v a2 s . com*/ Set nowList = (Set) PropertyUtils.getProperty(object, "_team_list"); Set preList = null; if (objectPre != null) { preList = (Set) PropertyUtils.getProperty(objectPre, "_team_list"); } if (nowList != null || preList != null) { answer = getTeamChangedList(ts, null, preList, nowList); } } catch (Exception e) { e.printStackTrace(); } } return answer; }
From source file:org.openmrs.module.amrsreports.db.hibernate.MohHibernateCoreDAO.java
/** * @see MohCoreDAO#getPatientObservationsWithEncounterRestrictions(Integer, java.util.Map, java.util.Map, org.openmrs.module.amrsreports.util.MohFetchRestriction, java.util.Date) *//*from w w w. j a v a 2 s. c o m*/ @Override public List<Obs> getPatientObservationsWithEncounterRestrictions(final Integer patientId, final Map<String, Collection<OpenmrsObject>> obsRestrictions, final Map<String, Collection<OpenmrsObject>> encounterRestrictions, final MohFetchRestriction mohFetchRestriction, final Date evaluationDate) { // build the criteria Criteria criteria = buildPatientObservationsCriteria(patientId, obsRestrictions, mohFetchRestriction, evaluationDate); // add encounter criteria subquery Encounter encounter = new Encounter(); Criteria encounterCriteria = criteria.createCriteria("encounter"); for (String property : encounterRestrictions.keySet()) { Collection<OpenmrsObject> propertyValues = encounterRestrictions.get(property); if (CollectionUtils.isNotEmpty(propertyValues) && PropertyUtils.isReadable(encounter, property)) { encounterCriteria.add(Restrictions.in(property, propertyValues)); encounterCriteria.addOrder(Order.asc(property)); } } // process the observations List<Obs> observations = processObs(criteria, mohFetchRestriction); return observations; }
From source file:org.openmrs.module.amrsreports.db.hibernate.MohHibernateCoreDAO.java
/** * creates a Criteria from restrictions provided * * @param patientId the patient connected to the desired observations * @param restrictions a map of restrictions on the observations * @param mohFetchRestriction a map of fetch restrictions * @return a Criteria for use in evaluation *///from ww w.j a va2 s.co m private Criteria buildPatientObservationsCriteria(final Integer patientId, final Map<String, Collection<OpenmrsObject>> restrictions, final MohFetchRestriction mohFetchRestriction, final Date evaluationDate) { Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Obs.class); criteria.add(Restrictions.eq("personId", patientId)); criteria.setFirstResult(0); if (mohFetchRestriction.getStart() != null) { criteria.setFirstResult(mohFetchRestriction.getStart()); } if (mohFetchRestriction.getSize() != null && mohFetchRestriction.getSize() == 1) { criteria.setMaxResults(mohFetchRestriction.getSize()); } Order order = Order.desc("obsDatetime"); if (OpenmrsUtil.nullSafeEquals(MohFetchOrdering.ORDER_ASCENDING, mohFetchRestriction.getFetchOrdering())) { order = Order.asc("obsDatetime"); } criteria.addOrder(order); Obs observation = new Obs(); for (String property : restrictions.keySet()) { Collection<OpenmrsObject> propertyValues = restrictions.get(property); if (CollectionUtils.isNotEmpty(propertyValues) && PropertyUtils.isReadable(observation, property)) { criteria.add(Restrictions.in(property, propertyValues)); criteria.addOrder(Order.asc(property)); } } criteria.add(Restrictions.eq("voided", Boolean.FALSE)); criteria.add(Restrictions.le("obsDatetime", evaluationDate)); return criteria; }
From source file:org.openmrs.module.amrsreports.db.hibernate.MohHibernateCoreDAO.java
/** * @see MohCoreDAO#getPatientEncounters(Integer, java.util.Map, org.openmrs.module.amrsreports.util.MohFetchRestriction, java.util.Date) *//*from w w w . java2 s . c o m*/ @Override public List<Encounter> getPatientEncounters(final Integer patientId, final Map<String, Collection<OpenmrsObject>> restrictions, final MohFetchRestriction mohFetchRestriction, final Date evaluationDate) throws DAOException { // create a hibernate criteria on the encounter object Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Encounter.class); // restrict the encounter that will be returned to specific patient only criteria.add(Restrictions.eq("patientId", patientId)); // default ordering for the returned encounter is descending on encounter datetime Order order = Order.desc("encounterDatetime"); // change the default ordering if the user pass the ascending ordering in the parameters if (OpenmrsUtil.nullSafeEquals(MohFetchOrdering.ORDER_ASCENDING, mohFetchRestriction.getFetchOrdering())) { order = Order.asc("encounterDatetime"); } // add the ordering object to the criteria criteria.addOrder(order); // make sure we don't go past the evaluationDate criteria.add(Restrictions.le("encounterDatetime", evaluationDate)); // always get from the first result criteria.setFirstResult(0); // set the first result to a number if the user pass any value on this parameter (currently not being used) if (mohFetchRestriction.getStart() != null) { criteria.setFirstResult(mohFetchRestriction.getStart()); } // specify how many records should be returned if (mohFetchRestriction.getSize() != null) { criteria.setMaxResults(mohFetchRestriction.getSize()); } // create a dummy encounter object Encounter encounter = new Encounter(); // iterate over each property in the restriction map for (String property : restrictions.keySet()) { // get the actual object that will restrict the encounter. this will contains the list of encounter type or list of location // or list of provider (currently not being used) passed from caller Collection<OpenmrsObject> propertyValues = restrictions.get(property); // check to make sure the list is not empty and the property is readable. example of the property for encounter are // encounterType or location of the encounter if (CollectionUtils.isNotEmpty(propertyValues) && PropertyUtils.isReadable(encounter, property)) { // create a restriction on the property with the above list as the value criteria.add(Restrictions.in(property, propertyValues)); // add ordering on that property to prevent slowness when ordering only on encounter datetime (1.6.x only) criteria.addOrder(Order.asc(property)); } } // exclude all voided encounters criteria.add(Restrictions.eq("voided", Boolean.FALSE)); List<Encounter> encounters = new ArrayList<Encounter>(); // scroll the results and add them to the above list of encounter Integer counter = 0; ScrollableResults scrollableResults = criteria.scroll(ScrollMode.FORWARD_ONLY); while (scrollableResults.next()) { encounters.add((Encounter) scrollableResults.get(0)); } scrollableResults.close(); return encounters; }
From source file:org.openmrs.module.clinicalsummary.db.hibernate.HibernateCoreDAO.java
/** * @see CoreDAO#getPatientObservations(Integer, java.util.Map, org.openmrs.module.clinicalsummary.util.FetchRestriction) *//* w ww . j a v a 2 s . com*/ @Override public List<Obs> getPatientObservations(final Integer patientId, final Map<String, Collection<OpenmrsObject>> restrictions, final FetchRestriction fetchRestriction) throws DAOException { Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Obs.class); criteria.createAlias("person", "person"); criteria.add(Restrictions.eq("person.personId", patientId)); criteria.setFirstResult(0); if (fetchRestriction.getStart() != null) criteria.setFirstResult(fetchRestriction.getStart()); if (fetchRestriction.getSize() != null && fetchRestriction.getSize() == 1) criteria.setMaxResults(fetchRestriction.getSize()); Order order = Order.desc("obsDatetime"); if (OpenmrsUtil.nullSafeEquals(FetchOrdering.ORDER_ASCENDING, fetchRestriction.getFetchOrdering())) order = Order.asc("obsDatetime"); criteria.addOrder(order); Obs observation = new Obs(); for (String property : restrictions.keySet()) { Collection<OpenmrsObject> propertyValues = restrictions.get(property); if (CollectionUtils.isNotEmpty(propertyValues) && PropertyUtils.isReadable(observation, property)) { criteria.add(Restrictions.in(property, propertyValues)); criteria.addOrder(Order.asc(property)); } } criteria.add(Restrictions.eq("voided", Boolean.FALSE)); List<Obs> observations = new ArrayList<Obs>(); // TODO: further optimization would be adding start date and end date parameter in the obs restrictions ScrollableResults scrollableResults = criteria.scroll(ScrollMode.FORWARD_ONLY); Integer size = fetchRestriction.getSize(); // scroll the results Obs processedObs = null; while (scrollableResults.next() && OpenmrsUtil.compareWithNullAsGreatest(observations.size(), size) == -1) { Obs obs = (Obs) scrollableResults.get(0); // TODO: thanks to Ampath for the duplicate data, we need to sanitize the query results here if (processedObs != null && !obs.isObsGrouping()) { if (DateUtils.isSameDay(processedObs.getObsDatetime(), obs.getObsDatetime()) && OpenmrsUtil.nullSafeEquals(processedObs.getConcept(), obs.getConcept()) && OpenmrsUtil.nullSafeEquals(processedObs.getValueCoded(), obs.getValueCoded()) && (OpenmrsUtil.nullSafeEquals(processedObs.getValueNumeric(), obs.getValueNumeric()))) continue; } processedObs = obs; observations.add(obs); } scrollableResults.close(); return observations; }
From source file:org.openmrs.module.clinicalsummary.db.hibernate.HibernateCoreDAO.java
/** * @see CoreDAO#getPatientEncounters(Integer, java.util.Map, org.openmrs.module.clinicalsummary.util.FetchRestriction) *//* w w w . ja v a 2 s . c o m*/ @Override public List<Encounter> getPatientEncounters(final Integer patientId, final Map<String, Collection<OpenmrsObject>> restrictions, final FetchRestriction fetchRestriction) throws DAOException { // create a hibernate criteria on the encounter object Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Encounter.class); // restrict the encounter that will be returned to specific patient only criteria.createAlias("patient", "patient"); criteria.add(Restrictions.eq("patient.patientId", patientId)); // default ordering for the returned encounter is descending on encounter datetime Order order = Order.desc("encounterDatetime"); // change the default ordering if the user pass the ascending ordering in the parameters if (OpenmrsUtil.nullSafeEquals(FetchOrdering.ORDER_ASCENDING, fetchRestriction.getFetchOrdering())) order = Order.asc("encounterDatetime"); // add the ordering object to the criteria criteria.addOrder(order); // always get from the first result criteria.setFirstResult(0); // set the first result to a number if the user pass any value on this parameter (currently not being used) if (fetchRestriction.getStart() != null) criteria.setFirstResult(fetchRestriction.getStart()); // specify how many records should be returned if (fetchRestriction.getSize() != null) criteria.setMaxResults(fetchRestriction.getSize()); // create a dummy encounter object Encounter encounter = new Encounter(); // iterate over each property in the restriction map for (String property : restrictions.keySet()) { // get the actual object that will restrict the encounter. this will contains the list of encounter type or list of location // or list of provider (currently not being used) passed from caller Collection<OpenmrsObject> propertyValues = restrictions.get(property); // check to make sure the list is not empty and the property is readable. example of the property for encounter are // encounterType or location of the encounter if (CollectionUtils.isNotEmpty(propertyValues) && PropertyUtils.isReadable(encounter, property)) { // create a restriction on the property with the above list as the value criteria.add(Restrictions.in(property, propertyValues)); // add ordering on that property to prevent slowness when ordering only on encounter datetime (1.6.x only) criteria.addOrder(Order.asc(property)); } } // exclude all voided encounters criteria.add(Restrictions.eq("voided", Boolean.FALSE)); List<Encounter> encounters = new ArrayList<Encounter>(); // scroll the results and add them to the above list of encounter Integer counter = 0; ScrollableResults scrollableResults = criteria.scroll(ScrollMode.FORWARD_ONLY); while (scrollableResults.next()) encounters.add((Encounter) scrollableResults.get(0)); scrollableResults.close(); return encounters; }
From source file:org.openmrs.module.clinicalsummary.db.hibernate.HibernateReminderDAO.java
/** * @see ReminderDAO#getReminders(java.util.Map, java.util.Date, java.util.Date) *//*from w w w . j a v a 2s . c om*/ @Override @SuppressWarnings("unchecked") public List<Reminder> getReminders(final Map<String, Collection<OpenmrsObject>> restrictions, final Date reminderStart, final Date reminderEnd) throws DAOException { Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Reminder.class); if (MapUtils.isNotEmpty(restrictions)) { Reminder reminder = new Reminder(); for (String property : restrictions.keySet()) { Collection<OpenmrsObject> objects = restrictions.get(property); if (CollectionUtils.isNotEmpty(objects) && PropertyUtils.isReadable(reminder, property)) criteria.add(Restrictions.in(property, objects)); } } if (reminderStart != null) criteria.add(Restrictions.ge("reminderDatetime", reminderStart)); if (reminderEnd != null) criteria.add(Restrictions.le("reminderDatetime", reminderEnd)); return criteria.list(); }
From source file:org.openmrs.module.clinicalsummary.db.hibernate.HibernateReminderDAO.java
/** * @see ReminderDAO#aggregateReminders(java.util.Map, java.util.Collection, java.util.Date, java.util.Date) */// w w w.j av a 2s . c om @Override @SuppressWarnings("unchecked") public List<Object[]> aggregateReminders(final Map<String, Collection<OpenmrsObject>> restrictions, final Collection<String> groupingProperties, final Date reminderStart, final Date reminderEnd) throws DAOException { Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Reminder.class); if (MapUtils.isNotEmpty(restrictions)) { Reminder reminder = new Reminder(); for (String property : restrictions.keySet()) { Collection<OpenmrsObject> objects = restrictions.get(property); if (CollectionUtils.isNotEmpty(objects) && PropertyUtils.isReadable(reminder, property)) criteria.add(Restrictions.in(property, objects)); } } if (reminderStart != null) criteria.add(Restrictions.ge("reminderDatetime", reminderStart)); if (reminderEnd != null) criteria.add(Restrictions.le("reminderDatetime", reminderEnd)); ProjectionList projectionList = Projections.projectionList(); for (String groupingProperty : groupingProperties) { // group by the property and order by the same property desc and the property must not null criteria.add(Restrictions.isNotNull(groupingProperty)); projectionList.add(Projections.groupProperty(groupingProperty)); criteria.addOrder(Order.asc(groupingProperty)); } // add the row count projection to the projection list projectionList.add(Projections.rowCount()); criteria.setProjection(projectionList); return criteria.list(); }
From source file:org.openmrs.module.clinicalsummary.db.hibernate.HibernateUtilDAO.java
/** * @see UtilDAO#getOrderedObs(java.util.Map, java.util.Date, java.util.Date) *//*from ww w.ja v a2 s.c o m*/ @Override @SuppressWarnings("unchecked") public List<OrderedObs> getOrderedObs(final Map<String, Collection<OpenmrsObject>> restrictions, final Date startTime, final Date endTime) throws DAOException { Criteria criteria = sessionFactory.getCurrentSession().createCriteria(OrderedObs.class); if (MapUtils.isNotEmpty(restrictions)) { OrderedObs orderedObs = new OrderedObs(); for (String property : restrictions.keySet()) { Collection<OpenmrsObject> objects = restrictions.get(property); if (CollectionUtils.isNotEmpty(objects) && PropertyUtils.isReadable(orderedObs, property)) criteria.add(Restrictions.in(property, objects)); } } if (startTime != null) criteria.add(Restrictions.ge("orderedDatetime", startTime)); if (endTime != null) criteria.add(Restrictions.le("orderedDatetime", endTime)); return criteria.list(); }