use of org.folio.rest.acq.model.Ongoing in project mod-gobi by folio-org.
the class Mapper method mapPurchaseOrder.
private void mapPurchaseOrder(List<CompletableFuture<?>> futures, CompositePurchaseOrder compPo, Document doc) {
Optional.ofNullable(mappings.get(Mapping.Field.ORDER_TYPE)).ifPresent(orderTypeField -> futures.add(orderTypeField.resolve(doc).thenApply(o -> {
compPo.setOrderType(CompositePurchaseOrder.OrderType.fromValue((String) o));
return CompositePurchaseOrder.OrderType.fromValue((String) o);
}).thenAccept(orderType -> {
if (orderType == CompositePurchaseOrder.OrderType.ONGOING) {
Ongoing ongoing = new Ongoing();
mapOngoing(futures, ongoing, doc);
compPo.setOngoing(ongoing);
}
}).exceptionally(Mapper::logException)));
Optional.ofNullable(mappings.get(Mapping.Field.APPROVED)).ifPresent(field -> futures.add(field.resolve(doc).thenAccept(o -> compPo.setApproved((Boolean) o)).exceptionally(Mapper::logException)));
Optional.ofNullable(mappings.get(Mapping.Field.ASSIGNED_TO)).ifPresent(field -> futures.add(field.resolve(doc).thenAccept(o -> compPo.setAssignedTo((String) o)).exceptionally(Mapper::logException)));
Optional.ofNullable(mappings.get(Mapping.Field.MANUAL_PO)).ifPresent(field -> futures.add(field.resolve(doc).thenAccept(o -> compPo.setManualPo((Boolean) o)).exceptionally(Mapper::logException)));
Optional.ofNullable(mappings.get(Mapping.Field.NOTES)).ifPresent(field -> futures.add(field.resolve(doc).thenAccept(o -> {
List<String> notes = new ArrayList<>();
notes.add((String) o);
compPo.setNotes(notes);
}).exceptionally(Mapper::logException)));
Optional.ofNullable(mappings.get(Mapping.Field.RE_ENCUMBER)).ifPresent(field -> futures.add(field.resolve(doc).thenAccept(o -> compPo.setReEncumber((Boolean) o)).exceptionally(Mapper::logException)));
Optional.ofNullable(mappings.get(Mapping.Field.TOTAL_ESTIMATED_PRICE)).ifPresent(field -> futures.add(field.resolve(doc).thenAccept(o -> compPo.setTotalEstimatedPrice((Double) o)).exceptionally(Mapper::logException)));
Optional.ofNullable(mappings.get(Mapping.Field.WORKFLOW_STATUS)).ifPresent(field -> futures.add(field.resolve(doc).thenAccept(o -> compPo.setWorkflowStatus(CompositePurchaseOrder.WorkflowStatus.fromValue((String) o))).exceptionally(Mapper::logException)));
Optional.ofNullable(mappings.get(Mapping.Field.DATE_ORDERED)).ifPresent(field -> futures.add(field.resolve(doc).thenAccept(o -> compPo.setDateOrdered((Date) o)).exceptionally(Mapper::logException)));
}
use of org.folio.rest.acq.model.Ongoing in project mod-orders by folio-org.
the class PurchaseOrdersApiTest method testPostListedPrintSerialInOpenStatus.
@Test
@Disabled
// TODO Must be fixed in scope of https://issues.folio.org/browse/MODORDERS-587
void testPostListedPrintSerialInOpenStatus() throws Exception {
logger.info("=== Test Listed Print Monograph in Open status ===");
CompositePurchaseOrder reqData = new JsonObject(getMockData(LISTED_PRINT_SERIAL_PATH)).mapTo(CompositePurchaseOrder.class);
String orderId = UUID.randomUUID().toString();
reqData.setWorkflowStatus(WorkflowStatus.OPEN);
MockServer.addMockTitles(reqData.getCompositePoLines());
prepareOrderForPostRequest(reqData);
reqData.setId(orderId);
reqData.getCompositePoLines().forEach(poLine -> {
poLine.setPaymentStatus(CompositePoLine.PaymentStatus.PENDING);
poLine.setReceiptStatus(ReceiptStatus.PENDING);
});
LocalDate now = LocalDate.now();
final CompositePurchaseOrder resp = verifyPostResponse(COMPOSITE_ORDERS_PATH, JsonObject.mapFrom(reqData).toString(), prepareHeaders(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10, X_OKAPI_USER_ID), APPLICATION_JSON, 201).as(CompositePurchaseOrder.class);
LocalDate dateOrdered = resp.getDateOrdered().toInstant().atZone(ZoneId.of(ZoneOffset.UTC.getId())).toLocalDate();
assertThat(dateOrdered.getMonth(), equalTo(now.getMonth()));
assertThat(dateOrdered.getYear(), equalTo(now.getYear()));
logger.info(JsonObject.mapFrom(resp));
String poId = resp.getId();
String poNumber = resp.getPoNumber();
assertNotNull(poId);
assertNotNull(poNumber);
assertEquals(reqData.getCompositePoLines().size(), resp.getCompositePoLines().size());
for (int i = 0; i < resp.getCompositePoLines().size(); i++) {
CompositePoLine line = resp.getCompositePoLines().get(i);
String polNumber = line.getPoLineNumber();
String polId = line.getId();
assertEquals(poId, line.getPurchaseOrderId());
assertNotNull(polId);
assertNotNull(polNumber);
assertTrue(polNumber.startsWith(poNumber));
assertNotNull(line.getInstanceId());
line.getLocations().forEach(location -> verifyLocationQuantity(location, line.getOrderFormat()));
line.getLocations().forEach(location -> {
assertNull(location.getLocationId());
assertNotNull(location.getHoldingId());
});
}
int polCount = resp.getCompositePoLines().size();
List<JsonObject> instancesSearches = getInstancesSearches();
assertNotNull(instancesSearches);
assertEquals(polCount, instancesSearches.size());
CompositePoLine respLine1 = resp.getCompositePoLines().get(0);
List<JsonObject> createdInstances = getCreatedInstances();
assertEquals(1, createdInstances.size(), "Quantity of created instance must be equal of line, if create inventory include instance");
assertNotNull("Line must be connected to instance, if create inventory include instance", respLine1.getInstanceId());
List<JsonObject> createdHoldings = getCreatedHoldings();
assertEquals(1, createdHoldings.size(), "Quantity of created holding must be depended of quantity in the locations and create inventory include holding");
verifyHoldingsCreated(1, createdHoldings, respLine1);
// All existing and created items
List<JsonObject> items = joinExistingAndNewItems();
verifyItemsCreated(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10, 1, items, respLine1);
List<JsonObject> createdPieces = getCreatedPieces();
verifyOpenOrderPiecesCreated(items, resp.getCompositePoLines(), createdPieces, 0);
createdPieces.stream().map(json -> json.mapTo(Piece.class)).filter(piece -> PHYSICAL.equals(piece.getFormat())).forEach(piece -> {
assertNull(piece.getLocationId());
assertNotNull(piece.getHoldingId());
});
createdPieces.stream().map(json -> json.mapTo(Piece.class)).filter(piece -> ELECTRONIC.equals(piece.getFormat())).forEach(piece -> {
assertNotNull(piece.getLocationId());
assertNull(piece.getHoldingId());
});
verifyEncumbrancesOnPoCreation(reqData, resp);
assertThat(getExistingOrderSummaries(), hasSize(0));
verifyCalculatedData(resp);
// MODORDERS-459 - check status changed to ONGOING
verifyReceiptStatusChangedTo(ReceiptStatus.ONGOING.value(), reqData.getCompositePoLines().size());
verifyPaymentStatusChangedTo(CompositePoLine.PaymentStatus.ONGOING.value(), reqData.getCompositePoLines().size());
}
use of org.folio.rest.acq.model.Ongoing in project mod-orders by folio-org.
the class PurchaseOrdersApiTest method testUpdateOrderWithProtectedFieldsChanging.
@Test
void testUpdateOrderWithProtectedFieldsChanging() {
logger.info("=== Test case when OPEN order errors if protected fields are changed ===");
JsonObject reqData = getMockAsJson(COMP_ORDER_MOCK_DATA_PATH, PO_ID_OPEN_STATUS);
assertThat(reqData.getString("workflowStatus"), is(CompositePurchaseOrder.WorkflowStatus.OPEN.value()));
Map<String, Object> allProtectedFieldsModification = new HashMap<>();
allProtectedFieldsModification.put(POProtectedFields.APPROVED.getFieldName(), true);
allProtectedFieldsModification.put(POProtectedFields.PO_NUMBER.getFieldName(), "testPO");
allProtectedFieldsModification.put(POProtectedFields.MANUAL_PO.getFieldName(), true);
allProtectedFieldsModification.put(POProtectedFields.RE_ENCUMBER.getFieldName(), true);
allProtectedFieldsModification.put(POProtectedFields.ORDER_TYPE.getFieldName(), CompositePurchaseOrder.OrderType.ONGOING.value());
Ongoing ongoing = new Ongoing();
ongoing.setManualRenewal(true);
allProtectedFieldsModification.put(POProtectedFields.ONGOING.getFieldName(), JsonObject.mapFrom(ongoing));
checkPreventProtectedFieldsModificationRule(COMPOSITE_ORDERS_BY_ID_PATH, reqData, allProtectedFieldsModification);
}
Aggregations