Skip to content

Commit

Permalink
ProcessingOrder: Implementation of the order history class and the us…
Browse files Browse the repository at this point in the history
…age of it.

Odip: Fix in findProductsByClassAndStartStop, use Map<...> instead of RestProduct
  • Loading branch information
emelchinger committed Aug 28, 2024
1 parent 5bc08db commit e629c52
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import de.dlr.proseo.model.dao.MonServiceStateRepository;
import de.dlr.proseo.model.dao.OrbitRepository;
import de.dlr.proseo.model.dao.OrderRepository;
import de.dlr.proseo.model.dao.ProcessingOrderHistoryRepository;
import de.dlr.proseo.model.dao.ClassOutputParameterRepository;
import de.dlr.proseo.model.dao.ProcessorClassRepository;
import de.dlr.proseo.model.dao.ProcessorRepository;
Expand Down Expand Up @@ -182,6 +183,10 @@ public class RepositoryService {
@Autowired
private MonExtServiceStateOperationMonthRepository monExtServiceStateOperationMonthRepository;

/** The repository for the ProcessingOrder class */
@Autowired
private ProcessingOrderHistoryRepository processingOrderHistoryRepository;

/** The repository for the Workflow class */
@Autowired
private WorkflowRepository workflowRepository;
Expand Down Expand Up @@ -464,14 +469,21 @@ public static MonServiceStateOperationMonthRepository getMonServiceStateOperatio
public static MonExtServiceStateOperationDayRepository getMonExtServiceStateOperationDayRepository() {
return theRepositoryService.monExtServiceStateOperationDayRepository;
}

/**
* @return the monExtServiceStateOperationMonthRepository
*/
public static MonExtServiceStateOperationMonthRepository getMonExtServiceStateOperationMonthRepository() {
return theRepositoryService.monExtServiceStateOperationMonthRepository;
}

/**
* @return the processingOrderHistoryRepository
*/
public static ProcessingOrderHistoryRepository getProcessingOrderHistoryRepository() {
return theRepositoryService.processingOrderHistoryRepository;
}

/**
* @return the workflowRepository
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import de.dlr.proseo.model.Parameter;
import de.dlr.proseo.model.ProcessingFacility;
import de.dlr.proseo.model.ProcessingOrder;
import de.dlr.proseo.model.ProcessingOrderHistory;
import de.dlr.proseo.model.Product;
import de.dlr.proseo.model.ProductClass;
import de.dlr.proseo.model.ProductQuery;
Expand Down Expand Up @@ -340,7 +341,17 @@ public RestOrder createOrder(RestOrder order) throws IllegalArgumentException, S
// Everything OK, store new order in database
modelOrder = RepositoryService.getOrderRepository().save(modelOrder);
logger.log(OrderMgrMessage.ORDER_CREATED, order.getIdentifier(), order.getMissionCode());


// Create and initialize the history element of the processing order.
ProcessingOrderHistory orderHistory = new ProcessingOrderHistory();
orderHistory.setIdentifier(modelOrder.getIdentifier());
orderHistory.setMissionCode(modelOrder.getMission().getCode());
orderHistory.setCreationTime(Instant.now());
orderHistory.setOrderState(modelOrder.getOrderState());
for (ProductClass pc : modelOrder.getRequestedProductClasses()) {
orderHistory.getProductTypes().add(pc.getProductType());
}
RepositoryService.getProcessingOrderHistoryRepository().save(orderHistory);
return OrderUtil.toRestOrder(modelOrder);

} catch (org.springframework.dao.DataIntegrityViolationException e) {
Expand Down Expand Up @@ -431,6 +442,12 @@ private void deleteOrder(ProcessingOrder order) throws EntityNotFoundException,
prepareOrderToDelete(order);
// Delete the order
long id = order.getId();
ProcessingOrderHistory history = RepositoryService.getProcessingOrderHistoryRepository()
.findByMissionCodeAndIdentifier(order.getMission().getCode(), order.getIdentifier());
if (history != null) {
history.setDeletionTime(Instant.now());
RepositoryService.getProcessingOrderHistoryRepository().save(history);
}
RepositoryService.getOrderRepository().delete(order);
// Test whether the deletion was successful
Optional<ProcessingOrder> modelOrder = RepositoryService.getOrderRepository().findById(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ public PlannerResultMessage prepareExpectedJobs(long orderId, ProcessingFacility
order.setStateMessage(ProductionPlanner.STATE_MESSAGE_COMPLETED);

answer.setMessage(PlannerMessage.ORDER_ALREADY_COMPLETED);
UtilService.getOrderUtil().setOrderHistory(order);
}
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ public PlannerResultMessage plan(long orderId) throws InterruptedException {
UtilService.getOrderUtil().setTimes(lambdaOrder);
UtilService.getOrderUtil().setStateMessage(lambdaOrder, ProductionPlanner.STATE_MESSAGE_COMPLETED);
lambdaAnswer.setMessage(PlannerMessage.ORDER_PRODUCT_EXIST);
UtilService.getOrderUtil().setOrderHistory(lambdaOrder);
} else {
lambdaOrder.setOrderState(OrderState.PLANNED);
UtilService.getOrderUtil().setStateMessage(lambdaOrder, ProductionPlanner.STATE_MESSAGE_QUEUED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ public int compare(Job o1, Job o2) {
UtilService.getOrderUtil().setTimes(lambdaOrder);
UtilService.getOrderUtil().setStateMessage(lambdaOrder, ProductionPlanner.STATE_MESSAGE_COMPLETED);
lambdaAnswer.setMessage(PlannerMessage.ORDER_PRODUCT_EXIST);
UtilService.getOrderUtil().setOrderHistory(lambdaOrder);
} else {
// check whether order is already running
Boolean running = false;
Expand All @@ -449,6 +450,7 @@ public int compare(Job o1, Job o2) {
}
}
lambdaAnswer.setMessage(PlannerMessage.ORDER_RELEASED);
UtilService.getOrderUtil().setOrderHistory(lambdaOrder);
}
lambdaAnswer.setText(logger.log(lambdaAnswer.getMessage(), lambdaOrder.getIdentifier()));
lambdaOrder.incrementVersion();
Expand Down Expand Up @@ -485,6 +487,8 @@ public int compare(Job o1, Job o2) {
logger.debug("... exception in getOrderRepository.save2(" + lambdaOrder.getIdentifier() + "): ", e);
throw e;
}

UtilService.getOrderUtil().setOrderHistory(lambdaOrder);
}
return lambdaAnswer;
});
Expand Down
64 changes: 63 additions & 1 deletion planner/src/main/java/de/dlr/proseo/planner/util/OrderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import de.dlr.proseo.model.JobStep;
import de.dlr.proseo.model.ProcessingFacility;
import de.dlr.proseo.model.ProcessingOrder;
import de.dlr.proseo.model.ProcessingOrderHistory;
import de.dlr.proseo.model.Product;
import de.dlr.proseo.model.ProductFile;
import de.dlr.proseo.model.enums.OrderSource;
Expand Down Expand Up @@ -121,6 +122,7 @@ public PlannerResultMessage cancel(ProcessingOrder orderX) {
order.incrementVersion();
RepositoryService.getOrderRepository().save(order);
logOrderState(order);
UtilService.getOrderUtil().setOrderHistory(order);
answer.setMessage(PlannerMessage.ORDER_CANCELED);
break;
case RELEASED:
Expand Down Expand Up @@ -358,6 +360,7 @@ public PlannerResultMessage delete(ProcessingOrder order) {
case INITIAL:
case APPROVED:
// jobs are in initial state, no change
UtilService.getOrderUtil().setOrderHistoryOrderDeleted(order);
RepositoryService.getOrderRepository().delete(order);
answer.setMessage(PlannerMessage.ORDER_DELETED);
break;
Expand All @@ -383,6 +386,7 @@ public PlannerResultMessage delete(ProcessingOrder order) {
RepositoryService.getJobRepository().delete(job);
}
}
UtilService.getOrderUtil().setOrderHistoryOrderDeleted(order);
RepositoryService.getOrderRepository().delete(order);
answer.setMessage(PlannerMessage.ORDER_DELETED);
break;
Expand Down Expand Up @@ -915,7 +919,8 @@ public PlannerResultMessage suspend(long id, Boolean force) {
setStateMessage(orderz, ProductionPlanner.STATE_MESSAGE_COMPLETED);
checkAutoClose(orderz);
RepositoryService.getOrderRepository().save(orderz);
logOrderState(orderz);
logOrderState(orderz);
UtilService.getOrderUtil().setOrderHistory(orderz);
return new PlannerResultMessage(PlannerMessage.ORDER_COMPLETED);
} else {
orderz.setOrderState(OrderState.PLANNED);
Expand Down Expand Up @@ -1229,6 +1234,7 @@ public PlannerResultMessage retry(ProcessingOrder order) {
order.incrementVersion();
RepositoryService.getOrderRepository().save(order);
answer.setMessage(PlannerMessage.ORDER_COMPLETED);
UtilService.getOrderUtil().setOrderHistory(order);
} else {
if (order.getOrderState() == OrderState.RUNNING) {
order.setOrderState(OrderState.SUSPENDING);
Expand Down Expand Up @@ -1322,6 +1328,7 @@ public PlannerResultMessage close(Long orderId) {
locOrder.setOrderState(OrderState.CLOSED);
if (locOrder.getHasFailedJobSteps()) {
setStateMessage(locOrder, ProductionPlanner.STATE_MESSAGE_FAILED);
UtilService.getOrderUtil().setOrderHistory(locOrder);
} else {
setStateMessage(locOrder, ProductionPlanner.STATE_MESSAGE_COMPLETED);
}
Expand Down Expand Up @@ -1408,12 +1415,14 @@ public Boolean checkFinish(Long orderId) {
checkAutoClose(order);
setTimes(order);
setStateMessage(order, ProductionPlanner.STATE_MESSAGE_COMPLETED);
UtilService.getOrderUtil().setOrderHistory(order);
} else {
order.setOrderState(OrderState.FAILED);
setStateMessage(order, ProductionPlanner.STATE_MESSAGE_FAILED);
}
checkFurther = true;
RepositoryService.getOrderRepository().save(order);
UtilService.getOrderUtil().setOrderHistory(order);
em.merge(order);
hasChanged = true;
}
Expand Down Expand Up @@ -1457,12 +1466,14 @@ public Boolean checkFinish(Long orderId) {
order.setOrderState(OrderState.FAILED);
setStateMessage(order, ProductionPlanner.STATE_MESSAGE_FAILED);
RepositoryService.getOrderRepository().save(order);
UtilService.getOrderUtil().setOrderHistory(order);
em.merge(order);
} else {
order.setOrderState(OrderState.COMPLETED);
setTimes(order);
setStateMessage(order, ProductionPlanner.STATE_MESSAGE_COMPLETED);
checkAutoClose(order);
UtilService.getOrderUtil().setOrderHistory(order);
sendNotification(order);
}
hasChanged = true;
Expand Down Expand Up @@ -1531,6 +1542,57 @@ public void setStateMessage(ProcessingOrder order, String stateMessage) {
}
}

/**
* Set the order state and time of an order history object.
* The time setting depends on the current order state.
*
* @param order The processing order
*/
@Transactional(isolation = Isolation.REPEATABLE_READ)
public void setOrderHistory(ProcessingOrder order) {
if (order != null) {
ProcessingOrderHistory history = RepositoryService.getProcessingOrderHistoryRepository()
.findByMissionCodeAndIdentifier(order.getMission().getCode(), order.getIdentifier());
if (history != null) {
history.setOrderState(order.getOrderState());
switch (order.getOrderState()) {
case RELEASED:
case RUNNING:
if (history.getReleaseTime() == null) {
history.setReleaseTime(Instant.now());
}
break;
case FAILED:
case COMPLETED:
if (history.getCompletionTime() == null) {
history.setCompletionTime(Instant.now());
}
break;
default:
break;
}
RepositoryService.getProcessingOrderHistoryRepository().save(history);
}
}
}

/**
* Set the deletion time of an order history object.
*
* @param order The processing order
*/
@Transactional(isolation = Isolation.REPEATABLE_READ)
public void setOrderHistoryOrderDeleted(ProcessingOrder order) {
if (order != null) {
ProcessingOrderHistory history = RepositoryService.getProcessingOrderHistoryRepository()
.findByMissionCodeAndIdentifier(order.getMission().getCode(), order.getIdentifier());
if (history != null) {
history.setDeletionTime(Instant.now());
RepositoryService.getProcessingOrderHistoryRepository().save(history);
}
}
}

@Transactional(isolation = Isolation.REPEATABLE_READ)
public Boolean
sendNotification(ProcessingOrder order) {
Expand Down

0 comments on commit e629c52

Please sign in to comment.