@Test public void shouldPopulateRnrDTOFromRequisition() throws Exception { Rnr rnr = make(a(defaultRequisition)); rnr.add(new RnrLineItem(), false); RnrLineItemDTO expectedLineItemDTO = new RnrLineItemDTO(new RnrLineItem()); whenNew(RnrLineItemDTO.class).withAnyArguments().thenReturn(expectedLineItemDTO); Order order = new Order(rnr.getId()); order.setStatus(OrderStatus.RELEASED); order.setOrderNumber("ONI101"); SupplyLine supplyLine = make(a(SupplyLineBuilder.defaultSupplyLine)); order.setSupplyLine(supplyLine); ReplenishmentDTO replenishmentDTO = ReplenishmentDTO.prepareForREST(rnr, order); assertThat(rnr.getId(), is(replenishmentDTO.getId())); assertThat(rnr.getFacility().getCode(), is(replenishmentDTO.getAgentCode())); assertThat(rnr.getProgram().getCode(), is(replenishmentDTO.getProgramCode())); assertThat(rnr.isEmergency(), is(replenishmentDTO.isEmergency())); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy"); assertThat(simpleDateFormat.format(rnr.getPeriod().getStartDate()), is(replenishmentDTO.getStringPeriodStartDate())); assertThat(simpleDateFormat.format(rnr.getPeriod().getEndDate()), is(replenishmentDTO.getStringPeriodEndDate())); assertThat(rnr.getStatus().name(), is(replenishmentDTO.getRequisitionStatus())); assertThat(replenishmentDTO.getProducts().size(), is(2)); assertThat(replenishmentDTO.getOrderId(), is(order.getOrderNumber())); assertThat(replenishmentDTO.getOrderStatus(), is(order.getStatus().name())); assertThat(replenishmentDTO.getSupplyingFacilityCode(), is(supplyLine.getSupplyingFacility().getCode())); }
public static ReplenishmentDTO prepareForREST(final Rnr rnr, Order order) { ReplenishmentDTO replenishmentDTO = new ReplenishmentDTO(); replenishmentDTO.setId(rnr.getId()); replenishmentDTO.setAgentCode(rnr.getFacility().getCode()); replenishmentDTO.setProgramCode(rnr.getProgram().getCode()); replenishmentDTO.setRequisitionStatus(rnr.getStatus().name()); replenishmentDTO.setEmergency(rnr.isEmergency()); replenishmentDTO.setPeriodEndDate(rnr.getPeriod().getEndDate()); replenishmentDTO.setPeriodStartDate(rnr.getPeriod().getStartDate()); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy"); replenishmentDTO.setStringPeriodEndDate(simpleDateFormat.format(rnr.getPeriod().getEndDate())); replenishmentDTO.setStringPeriodStartDate(simpleDateFormat.format(rnr.getPeriod().getStartDate())); ArrayList<RnrLineItem> lineItems = new ArrayList<RnrLineItem>() {{ addAll(rnr.getNonFullSupplyLineItems()); addAll(rnr.getFullSupplyLineItems()); }}; replenishmentDTO.setProducts((List<RnrLineItemDTO>) collect(lineItems, new Transformer() { @Override public Object transform(Object o) { return new RnrLineItemDTO((RnrLineItem) o); } })); if (order != null) { replenishmentDTO.orderId = order.getOrderNumber(); replenishmentDTO.orderStatus = order.getStatus().name(); Facility supplyingFacility = order.getSupplyingFacility(); replenishmentDTO.supplyingFacilityCode = supplyingFacility == null ? null : supplyingFacility.getCode(); } return replenishmentDTO; }
ReplenishmentDTO extends RnrDTO { public static ReplenishmentDTO prepareForREST(final Rnr rnr, Order order) { ReplenishmentDTO replenishmentDTO = new ReplenishmentDTO(); replenishmentDTO.setId(rnr.getId()); replenishmentDTO.setAgentCode(rnr.getFacility().getCode()); replenishmentDTO.setProgramCode(rnr.getProgram().getCode()); replenishmentDTO.setRequisitionStatus(rnr.getStatus().name()); replenishmentDTO.setEmergency(rnr.isEmergency()); replenishmentDTO.setPeriodEndDate(rnr.getPeriod().getEndDate()); replenishmentDTO.setPeriodStartDate(rnr.getPeriod().getStartDate()); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy"); replenishmentDTO.setStringPeriodEndDate(simpleDateFormat.format(rnr.getPeriod().getEndDate())); replenishmentDTO.setStringPeriodStartDate(simpleDateFormat.format(rnr.getPeriod().getStartDate())); ArrayList<RnrLineItem> lineItems = new ArrayList<RnrLineItem>() {{ addAll(rnr.getNonFullSupplyLineItems()); addAll(rnr.getFullSupplyLineItems()); }}; replenishmentDTO.setProducts((List<RnrLineItemDTO>) collect(lineItems, new Transformer() { @Override public Object transform(Object o) { return new RnrLineItemDTO((RnrLineItem) o); } })); if (order != null) { replenishmentDTO.orderId = order.getOrderNumber(); replenishmentDTO.orderStatus = order.getStatus().name(); Facility supplyingFacility = order.getSupplyingFacility(); replenishmentDTO.supplyingFacilityCode = supplyingFacility == null ? null : supplyingFacility.getCode(); } return replenishmentDTO; } }
ReplenishmentDTO extends RnrDTO { public static ReplenishmentDTO prepareForREST(final Rnr rnr, Order order) { ReplenishmentDTO replenishmentDTO = new ReplenishmentDTO(); replenishmentDTO.setId(rnr.getId()); replenishmentDTO.setAgentCode(rnr.getFacility().getCode()); replenishmentDTO.setProgramCode(rnr.getProgram().getCode()); replenishmentDTO.setRequisitionStatus(rnr.getStatus().name()); replenishmentDTO.setEmergency(rnr.isEmergency()); replenishmentDTO.setPeriodEndDate(rnr.getPeriod().getEndDate()); replenishmentDTO.setPeriodStartDate(rnr.getPeriod().getStartDate()); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy"); replenishmentDTO.setStringPeriodEndDate(simpleDateFormat.format(rnr.getPeriod().getEndDate())); replenishmentDTO.setStringPeriodStartDate(simpleDateFormat.format(rnr.getPeriod().getStartDate())); ArrayList<RnrLineItem> lineItems = new ArrayList<RnrLineItem>() {{ addAll(rnr.getNonFullSupplyLineItems()); addAll(rnr.getFullSupplyLineItems()); }}; replenishmentDTO.setProducts((List<RnrLineItemDTO>) collect(lineItems, new Transformer() { @Override public Object transform(Object o) { return new RnrLineItemDTO((RnrLineItem) o); } })); if (order != null) { replenishmentDTO.orderId = order.getOrderNumber(); replenishmentDTO.orderStatus = order.getStatus().name(); Facility supplyingFacility = order.getSupplyingFacility(); replenishmentDTO.supplyingFacilityCode = supplyingFacility == null ? null : supplyingFacility.getCode(); } return replenishmentDTO; }  }
ReplenishmentDTO extends RnrDTO { public static ReplenishmentDTO prepareForREST(final Rnr rnr, Order order) { ReplenishmentDTO replenishmentDTO = new ReplenishmentDTO(); replenishmentDTO.setId(rnr.getId()); replenishmentDTO.setAgentCode(rnr.getFacility().getCode()); replenishmentDTO.setProgramCode(rnr.getProgram().getCode()); replenishmentDTO.setRequisitionStatus(rnr.getStatus().name()); replenishmentDTO.setEmergency(rnr.isEmergency()); replenishmentDTO.setPeriodEndDate(rnr.getPeriod().getEndDate()); replenishmentDTO.setPeriodStartDate(rnr.getPeriod().getStartDate()); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy"); replenishmentDTO.setStringPeriodEndDate(simpleDateFormat.format(rnr.getPeriod().getEndDate())); replenishmentDTO.setStringPeriodStartDate(simpleDateFormat.format(rnr.getPeriod().getStartDate())); ArrayList<RnrLineItem> lineItems = new ArrayList<RnrLineItem>() {{ addAll(rnr.getNonFullSupplyLineItems()); addAll(rnr.getFullSupplyLineItems()); }}; replenishmentDTO.setProducts((List<RnrLineItemDTO>) collect(lineItems, new Transformer() { @Override public Object transform(Object o) { return new RnrLineItemDTO((RnrLineItem) o); } })); if (order != null) { replenishmentDTO.orderId = order.getOrderNumber(); replenishmentDTO.orderStatus = order.getStatus().name(); Facility supplyingFacility = order.getSupplyingFacility(); replenishmentDTO.supplyingFacilityCode = supplyingFacility == null ? null : supplyingFacility.getCode(); } return replenishmentDTO; }  static ReplenishmentDTO prepareForREST(final Rnr rnr, Order order); }
ReplenishmentDTO extends RnrDTO { public static ReplenishmentDTO prepareForREST(final Rnr rnr, Order order) { ReplenishmentDTO replenishmentDTO = new ReplenishmentDTO(); replenishmentDTO.setId(rnr.getId()); replenishmentDTO.setAgentCode(rnr.getFacility().getCode()); replenishmentDTO.setProgramCode(rnr.getProgram().getCode()); replenishmentDTO.setRequisitionStatus(rnr.getStatus().name()); replenishmentDTO.setEmergency(rnr.isEmergency()); replenishmentDTO.setPeriodEndDate(rnr.getPeriod().getEndDate()); replenishmentDTO.setPeriodStartDate(rnr.getPeriod().getStartDate()); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy"); replenishmentDTO.setStringPeriodEndDate(simpleDateFormat.format(rnr.getPeriod().getEndDate())); replenishmentDTO.setStringPeriodStartDate(simpleDateFormat.format(rnr.getPeriod().getStartDate())); ArrayList<RnrLineItem> lineItems = new ArrayList<RnrLineItem>() {{ addAll(rnr.getNonFullSupplyLineItems()); addAll(rnr.getFullSupplyLineItems()); }}; replenishmentDTO.setProducts((List<RnrLineItemDTO>) collect(lineItems, new Transformer() { @Override public Object transform(Object o) { return new RnrLineItemDTO((RnrLineItem) o); } })); if (order != null) { replenishmentDTO.orderId = order.getOrderNumber(); replenishmentDTO.orderStatus = order.getStatus().name(); Facility supplyingFacility = order.getSupplyingFacility(); replenishmentDTO.supplyingFacilityCode = supplyingFacility == null ? null : supplyingFacility.getCode(); } return replenishmentDTO; }  static ReplenishmentDTO prepareForREST(final Rnr rnr, Order order);  }