Search in sources :

Example 16 with Request

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);
}
Also used : Request(cern.modesti.request.Request)

Example 17 with Request

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);
}
Also used : Request(cern.modesti.request.Request)

Example 18 with 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;
}
Also used : HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) Request(cern.modesti.request.Request) ArrayList(java.util.ArrayList) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance)

Example 19 with Request

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) User(cern.modesti.user.User) Request(cern.modesti.request.Request) Resource(org.springframework.hateoas.Resource) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Request (cern.modesti.request.Request)19 Resource (org.springframework.hateoas.Resource)5 ArrayList (java.util.ArrayList)4 ResponseEntity (org.springframework.http.ResponseEntity)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 Point (cern.modesti.point.Point)3 RequestImpl (cern.modesti.request.RequestImpl)3 TaskInfo (cern.modesti.workflow.task.TaskInfo)3 User (cern.modesti.user.User)2 Task (org.activiti.engine.task.Task)2 Link (org.springframework.hateoas.Link)2 RequestProvider (cern.modesti.plugin.RequestProvider)1 UnsupportedRequestException (cern.modesti.plugin.UnsupportedRequestException)1 RequestParseResult (cern.modesti.request.upload.parser.RequestParseResult)1 ObjectDiffer (de.danielbechler.diff.ObjectDiffer)1 DiffNode (de.danielbechler.diff.node.DiffNode)1 HashMap (java.util.HashMap)1 HistoricActivityInstance (org.activiti.engine.history.HistoricActivityInstance)1 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)1 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)1