public MUSTVoCollection listMUSTByCareContext(CareContextRefVo voCareContextRef) { DomainFactory factory = getDomainFactory(); StringBuffer hql = new StringBuffer(" "); String query = "from MUST m "; ArrayList markers = new ArrayList(); ArrayList values = new ArrayList(); String andStr = " "; if (voCareContextRef != null) { hql.append(andStr + " m.careContext.id = :id_CareContext"); markers.add("id_CareContext"); values.add(voCareContextRef.getID_CareContext()); andStr = " and "; } if (markers.size() > 0) query += " where "; query += hql.toString(); List must = factory.find(query, markers, values); MUSTVoCollection collMUSTVo = MUSTVoAssembler.createMUSTVoCollectionFromMUST(must); if(collMUSTVo != null) return collMUSTVo.sort(); return null; }
public MUSTVo getLastComplementedMustRecord(CareContextRefVo voCareContextRef) { DomainFactory factory = getDomainFactory(); StringBuffer hql = new StringBuffer("from MUST m "); ArrayList markers = new ArrayList(); ArrayList values = new ArrayList(); String andStr = " "; if (voCareContextRef != null) { hql.append(" where "); hql.append(andStr + " m.careContext.id = :id_CareContext"); markers.add("id_CareContext"); values.add(voCareContextRef.getID_CareContext()); andStr = " and "; } hql.append(" order by m.authoringInformation.authoringDateTime desc "); List list = factory.find(hql.toString(), markers, values); //Get only the first record (to optimise the work of the assembler) if(list != null && list.size() > 1) { Object firstItem = list.get(0); list.removeAll(list); list.add(firstItem); } MUSTVoCollection collMUSTVo = MUSTVoAssembler.createMUSTVoCollectionFromMUST(list); if (collMUSTVo != null && collMUSTVo.size() > 0) return collMUSTVo.get(0); return null; }
public MUSTVo saveMUST(MUSTVo voMUST) throws StaleObjectException { if(!voMUST.isValidated()) throw new DomainRuntimeException("This MUST has not been validated"); DomainFactory factory = getDomainFactory(); MUST doMUST = MUSTVoAssembler.extractMUST(factory, voMUST); factory.save(doMUST); return MUSTVoAssembler.create(doMUST); }