use of cern.modesti.request.Request in project modesti by jlsalmon.
the class RequestHistoryServiceImpl method saveChangeHistory.
@Override
public void saveChangeHistory(Request modified) {
log.info(format("processing change history for request #%s", modified.getRequestId()));
RequestHistoryImpl entry = requestHistoryRepository.findOneByRequestId(modified.getRequestId());
if (entry == null) {
initialiseChangeHistory(modified);
return;
}
Request original = entry.getOriginalRequest();
Assert.notNull(modified);
Assert.notNull(original);
Assert.isTrue(modified.getRequestId().equals(original.getRequestId()));
entry.setEvents(Collections.singletonList(RequestDiffer.diff(modified, original, entry.getIdProperty())));
requestHistoryRepository.save(entry);
}
use of cern.modesti.request.Request in project modesti by jlsalmon.
the class CoreWorkflowServiceImpl method setRequestStatus.
/**
* Update the status of a particular request.
* <p>
* A status is simply a string. Conventionally, it should be in
* {@literal UPPER_UNDERSCORE} format, e.g. {@literal IN_PROGRESS}.
*
* @param requestId the id of the request to update
* @param status the new workflow status string
*/
public void setRequestStatus(String requestId, String status) {
log.info(format("setting status %s on request id %s", status, requestId));
Request request = getRequest(requestId);
request.setStatus(status);
requestRepository.save((RequestImpl) request);
}
use of cern.modesti.request.Request in project modesti by jlsalmon.
the class HistoryService method getHistoryForRequest.
/**
* Retrieve the workflow history for a particular request.
*
* @param requestId the id of the request
* @return the list of historic events
*/
public List<HistoricEvent> getHistoryForRequest(String requestId) {
log.info("querying history for request id " + requestId + "...");
Request request = requestRepository.findOneByRequestId(requestId);
if (request == null) {
throw new IllegalArgumentException("No request with id " + requestId + " was found");
}
List<HistoricEvent> history = new ArrayList<>();
// Find the process instance for this request
HistoricProcessInstance process = historyService.createHistoricProcessInstanceQuery().processInstanceBusinessKey(requestId).singleResult();
// Find all the activities that happened so far for this process
List<HistoricTaskInstance> tasks = historyService.createHistoricTaskInstanceQuery().processInstanceId(process.getId()).orderByTaskCreateTime().asc().list();
// Find all the activities that happened so far for this process
List<HistoricActivityInstance> activities = historyService.createHistoricActivityInstanceQuery().processInstanceId(process.getId()).orderByHistoricActivityInstanceStartTime().asc().list();
for (HistoricActivityInstance activity : activities) {
// Only interested in user tasks
if (activity.getActivityType().equals("userTask")) {
String description = "";
for (HistoricTaskInstance task : tasks) {
if (task.getId().equals(activity.getTaskId())) {
description = task.getDescription();
}
}
HistoricEvent event = new HistoricEvent(activity.getStartTime(), activity.getEndTime(), activity.getDurationInMillis(), activity.getActivityName(), activity.getActivityType(), description, activity.getAssignee());
history.add(event);
}
}
return history;
}
use of cern.modesti.request.Request in project modesti by jlsalmon.
the class RequestController method action.
@RequestMapping(path = "/requests/{id}", value = "/requests/{id}", method = POST, produces = "application/hal+json")
@PreAuthorize("permitAll")
public HttpEntity<Resource<Request>> action(@PathVariable("id") String requestId, @RequestBody RequestAction action, Principal principal) {
User user = (User) ((UsernamePasswordAuthenticationToken) principal).getPrincipal();
Request request = requestService.execute(requestId, action, user);
if (request != null) {
Resource<Request> resource = new Resource<>(request);
resource.add(linkTo(methodOn(RequestController.class).action(requestId, action, principal)).withSelfRel());
return new ResponseEntity<>(resource, HttpStatus.OK);
}
return new ResponseEntity<>(HttpStatus.OK);
}
Aggregations