/** * This method walks up the tree to the root unit, adding the unit ids to the set along the way. * * @param currentUnitNumber the current unit * @param topUnitNumber the root unit * @param unitIds the set of unit ids * @return */ private Set<String> getParentUnitIds( String currentUnitNumber, String topUnitNumber, Set<String> unitIds) { while (!(currentUnitNumber.equals(topUnitNumber))) { String parentUnitNumber = getUnitService().getUnit(currentUnitNumber).getParentUnitNumber(); Unit parentUnit = getUnitService().getUnit(parentUnitNumber); unitIds.add(parentUnit.getUnitNumber()); currentUnitNumber = parentUnit.getUnitNumber(); } return unitIds; }
@Test public void testOK() throws Exception { Unit unit = new Unit(); String unitNumber = "BL-RCEN"; unit.setUnitName(unitNumber); unit.setUnitNumber("BL-RCEN"); unit.setParentUnitNumber("IN-IN"); unit.setOrganizationId("00001"); MaintenanceDocument unitmaintenancedocument = newMaintDoc(unit); assertTrue(rule.processCustomApproveDocumentBusinessRules(unitmaintenancedocument)); }
/** * This method returns a set of unit ids that match the lead unit of the protocol, all of the * sub-units of the protocol lead unit, as well as all units between the protocol lead unit and * the root. * * @return a set of unit ids. */ private Set<String> getProtocolUnitIds(String protocolLeadUnit) { Set<String> unitIds = new HashSet<String>(); if (StringUtils.isNotBlank(protocolLeadUnit)) { // Add the protocol lead unit unitIds.add(protocolLeadUnit); // Add all sub units List<Unit> subUnits = getUnitService().getAllSubUnits(protocolLeadUnit); for (Unit unit : subUnits) { unitIds.add(unit.getUnitNumber()); } // Add all units between the lead unit and the root unit String topUnitNumber = getUnitService().getTopUnit().getUnitNumber(); unitIds = getParentUnitIds(protocolLeadUnit, topUnitNumber, unitIds); } return unitIds; }
@Test public void testMoveUnitOwnDescendant() throws Exception { Unit unit = new Unit(); unit.setUnitName("IN-IN"); unit.setUnitNumber("IN-IN"); unit.setParentUnitNumber("IN-MED"); unit.setOrganizationId("00001"); MaintenanceDocument unitmaintenancedocument = newMaintDoc(unit); assertFalse(rule.processCustomRouteDocumentBusinessRules(unitmaintenancedocument)); List errors = GlobalVariables.getMessageMap() .getMessages("ddocument.newMaintainableObject.parentUnitNumber"); errors = GlobalVariables.getMessageMap() .getMessages("document.newMaintainableObject.parentUnitNumber"); assertTrue(errors.size() == 1); ErrorMessage message = (ErrorMessage) errors.get(0); assertEquals(message.getErrorKey(), KeyConstants.MOVE_UNIT_OWN_DESCENDANTS); }
/** * This method... * * @param bo * @param propertyName * @return */ protected HtmlData getUnitNumberInquiryUrl(Award award) { Unit inqBo = new Unit(); Unit leadUnit = award.getLeadUnit(); inqBo.setUnitNumber(leadUnit != null ? leadUnit.getUnitNumber() : null); return super.getInquiryUrl(inqBo, UNIT_NUMBER); }