/** * This function expects to receive a list ordered by number (Ascending) and version (Descending) * * @param guides * @return The latest version for the guides */ private List getLatestVersions(List guides) { List result = new ArrayList(); Integer numberAux = null; Collections.reverse(guides); Iterator iterator = guides.iterator(); while (iterator.hasNext()) { Guide guide = (Guide) iterator.next(); if ((numberAux == null) || (numberAux.intValue() != guide.getNumber().intValue())) { numberAux = guide.getNumber(); InfoGuide infoGuide = InfoGuideWithPersonAndExecutionDegreeAndContributor.newInfoFromDomain(guide); List infoReimbursementGuides = new ArrayList(); if (guide.getReimbursementGuides() != null) { Iterator iter = guide.getReimbursementGuides().iterator(); while (iter.hasNext()) { ReimbursementGuide reimbursementGuide = (ReimbursementGuide) iter.next(); InfoReimbursementGuide infoReimbursementGuide = InfoReimbursementGuide.newInfoFromDomain(reimbursementGuide); infoReimbursementGuides.add(infoReimbursementGuide); } } infoGuide.setInfoReimbursementGuides(infoReimbursementGuides); result.add(infoGuide); } } Collections.reverse(result); return result; }
public List run(Integer guideNumber, Integer guideYear) throws FenixServiceException { List guides = null; guides = Guide.readByNumberAndYear(guideNumber, guideYear); if (guides == null || guides.isEmpty()) { throw new NonExistingServiceException(); } Iterator iterator = guides.iterator(); List result = new ArrayList(); while (iterator.hasNext()) { Guide guide = (Guide) iterator.next(); InfoGuide infoGuide = InfoGuideWithPersonAndExecutionDegreeAndContributor.newInfoFromDomain(guide); List infoReimbursementGuides = new ArrayList(); if (guide.getReimbursementGuides() != null) { Iterator iter = guide.getReimbursementGuides().iterator(); while (iter.hasNext()) { ReimbursementGuide reimbursementGuide = (ReimbursementGuide) iter.next(); InfoReimbursementGuide infoReimbursementGuide = InfoReimbursementGuide.newInfoFromDomain(reimbursementGuide); infoReimbursementGuides.add(infoReimbursementGuide); } } infoGuide.setInfoReimbursementGuides(infoReimbursementGuides); result.add(infoGuide); } return result; }
@Checked("RolePredicates.MASTER_DEGREE_ADMINISTRATIVE_OFFICE_PREDICATE") @Service public static InfoGuide run( InfoGuide infoGuide, String othersRemarks, Double othersPrice, String remarks, GuideState situationOfGuide, String paymentType) throws FenixServiceException { GuideSituation guideSituation = null; // Check the Guide Situation if (situationOfGuide.equals(GuideState.ANNULLED)) { throw new InvalidSituationServiceException(); } InfoGuideEntry infoGuideEntry = new InfoGuideEntry(); if ((othersPrice != null) && (othersPrice.floatValue() > 0)) { infoGuideEntry.setDescription(othersRemarks); infoGuideEntry.setPrice(othersPrice); infoGuideEntry.setInfoGuide(infoGuide); infoGuideEntry.setDocumentType(DocumentType.OTHERS); infoGuideEntry.setGraduationType(GraduationType.MASTER_DEGREE); infoGuideEntry.setQuantity(Integer.valueOf(1)); List entries = infoGuide.getInfoGuideEntries(); entries.add(infoGuideEntry); infoGuide.setInfoGuideEntries(entries); } // Calculate the Guide Total Price infoGuide.setTotal(CalculateGuideTotal.calculate(infoGuide)); // Get the Guide Number Integer guideNumber = Guide.generateGuideNumber(); infoGuide.setNumber(guideNumber); // Create the new Guide Situation InfoGuideSituation infoGuideSituation = new InfoGuideSituation(); infoGuideSituation.setState(new State(State.ACTIVE)); infoGuideSituation.setRemarks(remarks); infoGuideSituation.setInfoGuide(infoGuide); Calendar calendar = Calendar.getInstance(); infoGuideSituation.setDate(calendar.getTime()); infoGuideSituation.setSituation(situationOfGuide); Person person = (Person) rootDomainObject.readPartyByOID(infoGuide.getInfoPerson().getIdInternal()); ExecutionDegree executionDegree = rootDomainObject.readExecutionDegreeByOID( infoGuide.getInfoExecutionDegree().getIdInternal()); final Party contributor = infoGuide.getInfoContributor() != null ? rootDomainObject.readPartyByOID(infoGuide.getInfoContributor().getIdInternal()) : person; Guide guide = new Guide(); guide.setExecutionDegree(executionDegree); guide.setContributorParty(contributor); guide.setPerson(person); guide.setCreationDate(infoGuide.getCreationDate()); guide.setGuideRequester(infoGuide.getGuideRequester()); guide.setNumber(infoGuide.getNumber()); guide.setPaymentDate(infoGuide.getPaymentDate()); guide.setPaymentType(infoGuide.getPaymentType()); guide.setRemarks(infoGuide.getRemarks()); guide.setTotal(infoGuide.getTotal()); guide.setVersion(infoGuide.getVersion()); guide.setYear(infoGuide.getYear()); if (situationOfGuide.equals(GuideState.PAYED)) { guide.setPaymentType(PaymentType.valueOf(paymentType)); guide.setPaymentDate(calendar.getTime()); } // Write the new Entries of the Guide for (InfoGuideEntry infoGuideEntryIter : infoGuide.getInfoGuideEntries()) { GuideEntry guideEntry = new GuideEntry(); guideEntry.setDescription(infoGuideEntryIter.getDescription()); guideEntry.setDocumentType(infoGuideEntryIter.getDocumentType()); guideEntry.setGraduationType(infoGuideEntryIter.getGraduationType()); guideEntry.setPrice(infoGuideEntryIter.getPrice()); guideEntry.setQuantity(infoGuideEntryIter.getQuantity()); guide.addGuideEntries(guideEntry); } // Write the New Guide Situation guideSituation = new GuideSituation( situationOfGuide, remarks, calendar.getTime(), guide, new State(State.ACTIVE)); InfoGuide result = InfoGuideWithPersonAndExecutionDegreeAndContributor.newInfoFromDomain(guide); result.setInfoGuideEntries(infoGuide.getInfoGuideEntries()); result.setInfoGuideSituation(infoGuideSituation); result.setInfoGuideSituations(new ArrayList(1)); result.getInfoGuideSituations().add(infoGuideSituation); return result; }