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;
}
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());
}
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;
}
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;
}
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());
}
Aggregations