Loading src/main/java/org/etsi/osl/tmf/so641/reposervices/ServiceOrderRepoService.java +42 −6 Changes for src/main/java/org/etsi/osl/tmf/so641/reposervices/ServiceOrderRepoService.java: 42 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -975,17 +975,25 @@ public class ServiceOrderRepoService { * <li>the items named in dropItemIds become CANCELLED, so that they are neither fulfilled nor awaited; * every other item becomes INITIAL and keeps its action</li> * <li>the order becomes INITIAL, so it waits to be planned and acknowledged again</li> * <li>when given, the order is re-dated to the new window: the failed run's start is in the past, and * an order that starts in the past cannot be planned. Both names of each date are set, as an approval * that re-dates an order does</li> * </ul> * * @param id the service order id * @param dropItemIds ids of the order items to cancel, may be null * @param note the operator's reason, added as a note if not empty * @return the order, unchanged when it is not FAILED, or null when there is no such order * @param startDate the new start, or null to keep the order's * @param expectedCompletionDate the new completion, or null to keep the order's * @return the order, unchanged when it is not FAILED or the completion is not after the start, or * null when there is no such order */ @Transactional public ServiceOrder resetServiceOrder(String id, List<String> dropItemIds, String note) { public ServiceOrder resetServiceOrder(String id, List<String> dropItemIds, String note, OffsetDateTime startDate, OffsetDateTime expectedCompletionDate) { logger.info("Will resetServiceOrder:" + id + " dropItemIds=" + dropItemIds); logger.info("Will resetServiceOrder:" + id + " dropItemIds=" + dropItemIds + " startDate=" + startDate + " expectedCompletionDate=" + expectedCompletionDate); ServiceOrder so = this.findByUuid(id); if (so == null) { Loading @@ -995,6 +1003,14 @@ public class ServiceOrderRepoService { logger.warn("resetServiceOrder: order " + id + " is " + so.getState() + ", not FAILED - not reset"); return so; } OffsetDateTime newStart = (startDate != null) ? startDate : so.getStartDate(); OffsetDateTime newEnd = (expectedCompletionDate != null) ? expectedCompletionDate : so.getExpectedCompletionDate(); boolean reDated = (startDate != null) || (expectedCompletionDate != null); if (reDated && (newStart != null) && (newEnd != null) && !newEnd.isAfter(newStart)) { logger.warn("resetServiceOrder: order " + id + " completion " + newEnd + " is not after start " + newStart + " - not reset"); return so; } Set<String> drop = (dropItemIds != null) ? new HashSet<>(dropItemIds) : Collections.emptySet(); for (ServiceOrderItem soi : so.getOrderItem()) { Loading @@ -1008,10 +1024,20 @@ public class ServiceOrderRepoService { so.setState(ServiceOrderStateType.INITIAL); so.setCompletionDate((OffsetDateTime) null); if (startDate != null) { so.setStartDate(startDate); so.setRequestedStartDate(startDate); } if (expectedCompletionDate != null) { so.setExpectedCompletionDate(expectedCompletionDate); so.setRequestedCompletionDate(expectedCompletionDate); } Note resetNote = new Note(); resetNote.setText("Service Order reset from FAILED to INITIAL" + (drop.isEmpty() ? "" : ", dropped order items " + drop) + (reDated ? ", re-dated to " + newStart + " - " + newEnd : "") + (((note != null) && !note.isBlank()) ? ": " + note.trim() : "")); resetNote.setAuthor("SO641API-failedOrderReset"); resetNote.setDate(OffsetDateTime.now(ZoneOffset.UTC)); Loading @@ -1023,8 +1049,9 @@ public class ServiceOrderRepoService { } /** * Same as {@link #resetServiceOrder(String, List, String)}, for the message bus: the request is a map * with "dropItemIds" (a list of order item ids) and "note", the reply the eager order as JSON. * Same as {@link #resetServiceOrder(String, List, String, OffsetDateTime, OffsetDateTime)}, for the * message bus: the request is a map with "dropItemIds" (a list of order item ids), "note", and the * optional ISO-8601 "startDate" / "expectedCompletionDate"; the reply is the eager order as JSON. * <p> * The transaction is opened here, not by {@link #resetServiceOrder}: that call is made on this, so it * does not pass through the transactional proxy, and the order's lazy item collection would have no Loading @@ -1045,7 +1072,8 @@ public class ServiceOrderRepoService { note = String.valueOf(request.get("note")); } } ServiceOrder so = resetServiceOrder(id, dropItemIds, note); ServiceOrder so = resetServiceOrder(id, dropItemIds, note, dateOf(request, "startDate"), dateOf(request, "expectedCompletionDate")); if (so == null) { return null; } Loading @@ -1064,6 +1092,14 @@ public class ServiceOrderRepoService { return mapper.writeValueAsString(so); } /** An ISO-8601 date of the reset request, or null when it is absent or blank */ private static OffsetDateTime dateOf(Map<String, Object> request, String key) { if ((request == null) || (request.get(key) == null) || String.valueOf(request.get(key)).isBlank()) { return null; } return OffsetDateTime.parse(String.valueOf(request.get(key)).trim()); } public ServiceOrder findByUuid(String id) { Optional<ServiceOrder> optionalCat = this.serviceOrderRepo.findByUuid(id); return optionalCat.orElse(null); Loading src/test/java/org/etsi/osl/services/api/so641/ServiceOrderRepoServiceTest.java +10 −3 Changes for src/test/java/org/etsi/osl/services/api/so641/ServiceOrderRepoServiceTest.java: 10 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -607,7 +607,7 @@ public class ServiceOrderRepoServiceTest extends BaseIT { String soId = createdServiceOrder.getId(); ServiceOrderStateType before = serviceOrderFromDb(soId).getState(); ServiceOrder notReset = serviceOrderRepoService.resetServiceOrder(soId, List.of(), null); ServiceOrder notReset = serviceOrderRepoService.resetServiceOrder(soId, List.of(), null, null, null); assertThat(notReset.getState()).isEqualTo(before); assertThat(serviceOrderFromDb(soId).getState()).isEqualTo(before); Loading Loading @@ -643,13 +643,20 @@ public class ServiceOrderRepoServiceTest extends BaseIT { } serviceOrderRepoService.updateServiceOrder(soId, failed); String json = serviceOrderRepoService.resetServiceOrderAsString(soId, Map.of("note", "bus call")); OffsetDateTime newStart = OffsetDateTime.now(ZoneOffset.UTC).plusDays(1).withNano(0); OffsetDateTime newEnd = newStart.plusHours(4); String json = serviceOrderRepoService.resetServiceOrderAsString(soId, Map.of("note", "bus call", "startDate", newStart.toString(), "expectedCompletionDate", newEnd.toString())); ServiceOrder reset = JsonUtils.toJsonObj(json, ServiceOrder.class); assertThat(reset.getState()).isEqualTo(ServiceOrderStateType.INITIAL); // committed: a separate session reads the reset back // committed: a separate session reads the reset back, re-dated to the new window ServiceOrder stored = serviceOrderFromDb(soId); assertThat(stored.getState()).isEqualTo(ServiceOrderStateType.INITIAL); assertThat(stored.getStartDate().toInstant()).isEqualTo(newStart.toInstant()); assertThat(stored.getRequestedStartDate().toInstant()).isEqualTo(newStart.toInstant()); assertThat(stored.getExpectedCompletionDate().toInstant()).isEqualTo(newEnd.toInstant()); assertThat(stored.getRequestedCompletionDate().toInstant()).isEqualTo(newEnd.toInstant()); assertThat(stored.getOrderItem()).allSatisfy(soi -> { assertThat(soi.getState()).isEqualTo(ServiceOrderStateType.INITIAL); assertThat(soi.getService().getSupportingService()).isEmpty(); Loading Loading
src/main/java/org/etsi/osl/tmf/so641/reposervices/ServiceOrderRepoService.java +42 −6 Changes for src/main/java/org/etsi/osl/tmf/so641/reposervices/ServiceOrderRepoService.java: 42 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -975,17 +975,25 @@ public class ServiceOrderRepoService { * <li>the items named in dropItemIds become CANCELLED, so that they are neither fulfilled nor awaited; * every other item becomes INITIAL and keeps its action</li> * <li>the order becomes INITIAL, so it waits to be planned and acknowledged again</li> * <li>when given, the order is re-dated to the new window: the failed run's start is in the past, and * an order that starts in the past cannot be planned. Both names of each date are set, as an approval * that re-dates an order does</li> * </ul> * * @param id the service order id * @param dropItemIds ids of the order items to cancel, may be null * @param note the operator's reason, added as a note if not empty * @return the order, unchanged when it is not FAILED, or null when there is no such order * @param startDate the new start, or null to keep the order's * @param expectedCompletionDate the new completion, or null to keep the order's * @return the order, unchanged when it is not FAILED or the completion is not after the start, or * null when there is no such order */ @Transactional public ServiceOrder resetServiceOrder(String id, List<String> dropItemIds, String note) { public ServiceOrder resetServiceOrder(String id, List<String> dropItemIds, String note, OffsetDateTime startDate, OffsetDateTime expectedCompletionDate) { logger.info("Will resetServiceOrder:" + id + " dropItemIds=" + dropItemIds); logger.info("Will resetServiceOrder:" + id + " dropItemIds=" + dropItemIds + " startDate=" + startDate + " expectedCompletionDate=" + expectedCompletionDate); ServiceOrder so = this.findByUuid(id); if (so == null) { Loading @@ -995,6 +1003,14 @@ public class ServiceOrderRepoService { logger.warn("resetServiceOrder: order " + id + " is " + so.getState() + ", not FAILED - not reset"); return so; } OffsetDateTime newStart = (startDate != null) ? startDate : so.getStartDate(); OffsetDateTime newEnd = (expectedCompletionDate != null) ? expectedCompletionDate : so.getExpectedCompletionDate(); boolean reDated = (startDate != null) || (expectedCompletionDate != null); if (reDated && (newStart != null) && (newEnd != null) && !newEnd.isAfter(newStart)) { logger.warn("resetServiceOrder: order " + id + " completion " + newEnd + " is not after start " + newStart + " - not reset"); return so; } Set<String> drop = (dropItemIds != null) ? new HashSet<>(dropItemIds) : Collections.emptySet(); for (ServiceOrderItem soi : so.getOrderItem()) { Loading @@ -1008,10 +1024,20 @@ public class ServiceOrderRepoService { so.setState(ServiceOrderStateType.INITIAL); so.setCompletionDate((OffsetDateTime) null); if (startDate != null) { so.setStartDate(startDate); so.setRequestedStartDate(startDate); } if (expectedCompletionDate != null) { so.setExpectedCompletionDate(expectedCompletionDate); so.setRequestedCompletionDate(expectedCompletionDate); } Note resetNote = new Note(); resetNote.setText("Service Order reset from FAILED to INITIAL" + (drop.isEmpty() ? "" : ", dropped order items " + drop) + (reDated ? ", re-dated to " + newStart + " - " + newEnd : "") + (((note != null) && !note.isBlank()) ? ": " + note.trim() : "")); resetNote.setAuthor("SO641API-failedOrderReset"); resetNote.setDate(OffsetDateTime.now(ZoneOffset.UTC)); Loading @@ -1023,8 +1049,9 @@ public class ServiceOrderRepoService { } /** * Same as {@link #resetServiceOrder(String, List, String)}, for the message bus: the request is a map * with "dropItemIds" (a list of order item ids) and "note", the reply the eager order as JSON. * Same as {@link #resetServiceOrder(String, List, String, OffsetDateTime, OffsetDateTime)}, for the * message bus: the request is a map with "dropItemIds" (a list of order item ids), "note", and the * optional ISO-8601 "startDate" / "expectedCompletionDate"; the reply is the eager order as JSON. * <p> * The transaction is opened here, not by {@link #resetServiceOrder}: that call is made on this, so it * does not pass through the transactional proxy, and the order's lazy item collection would have no Loading @@ -1045,7 +1072,8 @@ public class ServiceOrderRepoService { note = String.valueOf(request.get("note")); } } ServiceOrder so = resetServiceOrder(id, dropItemIds, note); ServiceOrder so = resetServiceOrder(id, dropItemIds, note, dateOf(request, "startDate"), dateOf(request, "expectedCompletionDate")); if (so == null) { return null; } Loading @@ -1064,6 +1092,14 @@ public class ServiceOrderRepoService { return mapper.writeValueAsString(so); } /** An ISO-8601 date of the reset request, or null when it is absent or blank */ private static OffsetDateTime dateOf(Map<String, Object> request, String key) { if ((request == null) || (request.get(key) == null) || String.valueOf(request.get(key)).isBlank()) { return null; } return OffsetDateTime.parse(String.valueOf(request.get(key)).trim()); } public ServiceOrder findByUuid(String id) { Optional<ServiceOrder> optionalCat = this.serviceOrderRepo.findByUuid(id); return optionalCat.orElse(null); Loading
src/test/java/org/etsi/osl/services/api/so641/ServiceOrderRepoServiceTest.java +10 −3 Changes for src/test/java/org/etsi/osl/services/api/so641/ServiceOrderRepoServiceTest.java: 10 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -607,7 +607,7 @@ public class ServiceOrderRepoServiceTest extends BaseIT { String soId = createdServiceOrder.getId(); ServiceOrderStateType before = serviceOrderFromDb(soId).getState(); ServiceOrder notReset = serviceOrderRepoService.resetServiceOrder(soId, List.of(), null); ServiceOrder notReset = serviceOrderRepoService.resetServiceOrder(soId, List.of(), null, null, null); assertThat(notReset.getState()).isEqualTo(before); assertThat(serviceOrderFromDb(soId).getState()).isEqualTo(before); Loading Loading @@ -643,13 +643,20 @@ public class ServiceOrderRepoServiceTest extends BaseIT { } serviceOrderRepoService.updateServiceOrder(soId, failed); String json = serviceOrderRepoService.resetServiceOrderAsString(soId, Map.of("note", "bus call")); OffsetDateTime newStart = OffsetDateTime.now(ZoneOffset.UTC).plusDays(1).withNano(0); OffsetDateTime newEnd = newStart.plusHours(4); String json = serviceOrderRepoService.resetServiceOrderAsString(soId, Map.of("note", "bus call", "startDate", newStart.toString(), "expectedCompletionDate", newEnd.toString())); ServiceOrder reset = JsonUtils.toJsonObj(json, ServiceOrder.class); assertThat(reset.getState()).isEqualTo(ServiceOrderStateType.INITIAL); // committed: a separate session reads the reset back // committed: a separate session reads the reset back, re-dated to the new window ServiceOrder stored = serviceOrderFromDb(soId); assertThat(stored.getState()).isEqualTo(ServiceOrderStateType.INITIAL); assertThat(stored.getStartDate().toInstant()).isEqualTo(newStart.toInstant()); assertThat(stored.getRequestedStartDate().toInstant()).isEqualTo(newStart.toInstant()); assertThat(stored.getExpectedCompletionDate().toInstant()).isEqualTo(newEnd.toInstant()); assertThat(stored.getRequestedCompletionDate().toInstant()).isEqualTo(newEnd.toInstant()); assertThat(stored.getOrderItem()).allSatisfy(soi -> { assertThat(soi.getState()).isEqualTo(ServiceOrderStateType.INITIAL); assertThat(soi.getService().getSupportingService()).isEmpty(); Loading