Search in sources :

Example 1 with Request

use of cern.modesti.request.Request in project modesti by jlsalmon.

the class CoreWorkflowServiceImpl method startProcessInstance.

/**
 * Start a new workflow process instance for the given request.
 *
 * @param request the request to be associated with the newly created
 *                workflow process instance
 * @return the newly started process instance object
 */
public ProcessInstance startProcessInstance(final Request request) {
    log.info(format("starting process for %s request %s", request.getDomain(), request.getRequestId()));
    // Figure out which process to start, based on the domain and type
    RequestProvider plugin = requestProviderRegistry.getPluginFor(request, new UnsupportedRequestException(request));
    String processKey = plugin.getMetadata().getProcessKey(request.getType());
    Map<String, Object> variables = new HashMap<>();
    variables.put("requestId", request.getRequestId());
    variables.put("creator", request.getCreator());
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processKey, request.getRequestId(), variables);
    // After initializing the process instance, sets the request status (it might have been modified by some Activiti tasks)
    Request savedRequest = getRequest(request.getRequestId());
    request.setStatus(savedRequest.getStatus());
    request.setErrors(savedRequest.getErrors());
    request.setPoints(savedRequest.getPoints());
    request.setSkipCoreValidation(savedRequest.isSkipCoreValidation());
    return processInstance;
}
Also used : HashMap(java.util.HashMap) RequestProvider(cern.modesti.plugin.RequestProvider) Request(cern.modesti.request.Request) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) UnsupportedRequestException(cern.modesti.plugin.UnsupportedRequestException)

Example 2 with Request

use of cern.modesti.request.Request in project modesti by jlsalmon.

the class CoreWorkflowServiceImpl method splitRequest.

/**
 * Split a set of points from a request into a child request.
 * <p>
 * The points to split must be specified in an execution variable named
 * {@literal points} which is a list of line numbers corresponding to the
 * lines to be split.
 *
 * @param requestId the id of the request to split
 * @param execution the Activiti execution object
 */
public void splitRequest(String requestId, DelegateExecution execution) {
    log.info(format("splitting request id %s...", requestId));
    List<Long> pointsToSplit = execution.getVariable("points", List.class);
    log.info(format("splitting points [%s]", StringUtils.join(pointsToSplit, ", ")));
    Request parent = getRequest(requestId);
    List<Point> childPoints = new ArrayList<>();
    // Give the split points to the child.
    for (Long lineNo : pointsToSplit) {
        Point pointToSplit = null;
        for (Point point : parent.getPoints()) {
            if (point.getLineNo().equals(lineNo)) {
                pointToSplit = point;
                break;
            }
        }
        if (pointToSplit != null) {
            childPoints.add(pointToSplit);
            parent.getPoints().remove(pointToSplit);
            pointToSplit.setLineNo((long) (childPoints.indexOf(pointToSplit) + 1));
        }
    }
    // Rebase the point IDs back to starting from 1.
    for (Point point : parent.getPoints()) {
        // if (pointIdsToSplit.contains(point.getId())) {
        point.setLineNo((long) (parent.getPoints().indexOf(point) + 1));
    // }
    }
    // Generate a request ID for the new child
    String childRequestId = counterService.getNextSequence(CounterService.REQUEST_ID_SEQUENCE).toString();
    // Create the new child
    Request child = createChildRequest(childRequestId, parent, childPoints);
    // Set back reference to the child
    parent.getChildRequestIds().add(childRequestId);
    // Store the requests
    requestRepository.save((RequestImpl) parent);
    requestRepository.save((RequestImpl) child);
    // Add variables to the execution so that they are available to the
    // recursive process invocation
    execution.setVariable("childRequestId", child.getRequestId());
    execution.setVariable("childCreator", child.getCreator());
}
Also used : Request(cern.modesti.request.Request) ArrayList(java.util.ArrayList) Point(cern.modesti.point.Point)

Example 3 with Request

use of cern.modesti.request.Request in project modesti by jlsalmon.

the class UploadService method parseRequestFromExcelSheet.

/**
 * Delegate the parsing of the uploaded Excel sheet to a specific plugin
 * implementation.
 *
 * @param description the description of the uploaded request
 * @param stream      the Excel sheet to be parsed
 * @return the result of the request parse
 */
public RequestParseResult parseRequestFromExcelSheet(String description, InputStream stream) {
    RequestParseResult result = requestParserFactory.parseRequest(stream);
    Request request = result.getRequest();
    if (request.getDescription() == null) {
        request.setDescription(description);
    }
    requestService.insert(request);
    return result;
}
Also used : RequestParseResult(cern.modesti.request.upload.parser.RequestParseResult) Request(cern.modesti.request.Request)

Example 4 with Request

use of cern.modesti.request.Request in project modesti by jlsalmon.

the class RequestResourceAssembler method toResources.

@Override
public List<Resource> toResources(Iterable<? extends Request> requests) {
    List<Resource> resources = new ArrayList<>();
    for (Request request : requests) {
        Link self = entityLinks.linkToSingleResource(RequestImpl.class, request.getRequestId());
        resources.add(new Resource<>(request, self));
    }
    return resources;
}
Also used : Resource(org.springframework.hateoas.Resource) ArrayList(java.util.ArrayList) Request(cern.modesti.request.Request) Link(org.springframework.hateoas.Link)

Example 5 with Request

use of cern.modesti.request.Request in project modesti by jlsalmon.

the class CoreWorkflowServiceTest method assertTaskNameAndRequestStatus.

/**
 * @param requestId
 * @param taskName
 * @param status
 */
private void assertTaskNameAndRequestStatus(String requestId, String taskName, String status) {
    if (taskName != null) {
        TaskInfo task = taskService.getTask(requestId, taskName);
        assertEquals(taskName, task.getName());
    }
    Request request = requestRepository.findOneByRequestId(requestId);
    assertEquals(status, request.getStatus());
}
Also used : TaskInfo(cern.modesti.workflow.task.TaskInfo) Request(cern.modesti.request.Request)

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