Search in sources :

Example 11 with Request

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

the class SignalController method getSignals.

@RequestMapping(method = GET)
public ResponseEntity<Resources<Resource<SignalInfo>>> getSignals(@PathVariable("id") String id) {
    Request request = getRequest(id);
    if (request == null) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }
    List<SignalInfo> signals = new ArrayList<>();
    Task task = taskService.createTaskQuery().processInstanceBusinessKey(request.getRequestId()).active().singleResult();
    if (task == null) {
        return new ResponseEntity<>(new Resources<>(Collections.emptyList()), HttpStatus.OK);
    }
    // Query the signals that are subscribed to by the current process instance.
    // TODO this is a non-public API, is there a supported way of doing this?
    CommandExecutor executor = ((ProcessEngineConfigurationImpl) ProcessEngines.getDefaultProcessEngine().getProcessEngineConfiguration()).getCommandExecutor();
    EventSubscriptionQueryImpl query = new EventSubscriptionQueryImpl(executor);
    for (EventSubscriptionEntity signal : query.processInstanceId(task.getProcessInstanceId()).list()) {
        signals.add(new SignalInfo(signal.getEventName()));
    }
    Resources<Resource<SignalInfo>> resources = Resources.wrap(signals);
    for (Resource<SignalInfo> resource : resources) {
        resource.add(linkTo(methodOn(SignalController.class).getSignal(id, resource.getContent().getName())).withSelfRel());
    }
    return new ResponseEntity<>(resources, HttpStatus.OK);
}
Also used : Task(org.activiti.engine.task.Task) Request(cern.modesti.request.Request) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) Resource(org.springframework.hateoas.Resource) ResponseEntity(org.springframework.http.ResponseEntity) EventSubscriptionQueryImpl(org.activiti.engine.impl.EventSubscriptionQueryImpl) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) EventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with Request

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

the class RequestDifferTest method createRequest.

private Request createRequest(int numPoints, int numProperties) {
    Request request = new RequestImpl();
    request.setType(RequestType.UPDATE);
    request.setDescription("Test description");
    request.setDomain("Unit Test");
    ArrayList<Point> points = new ArrayList<>();
    for (int i = 1; i <= numPoints; i++) {
        Point p = createPoint(i, numProperties);
        points.add(p);
    }
    request.setPoints(points);
    return request;
}
Also used : Request(cern.modesti.request.Request) ArrayList(java.util.ArrayList) Point(cern.modesti.point.Point) RequestImpl(cern.modesti.request.RequestImpl) Point(cern.modesti.point.Point)

Example 13 with Request

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

the class TestUtil method getDummyRequest.

public static Request getDummyRequest() {
    Request request = new RequestImpl();
    request.setType(RequestType.CREATE);
    request.setDescription("description");
    request.setDomain("DUMMY");
    request.setPoints(getDummyPoints());
    return request;
}
Also used : Request(cern.modesti.request.Request) RequestImpl(cern.modesti.request.RequestImpl)

Example 14 with Request

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

the class RequestResourceProcessor method process.

@Override
public Resource<Request> process(Resource<Request> resource) {
    Request request = resource.getContent();
    log.trace("adding links to request " + request.getRequestId());
    resource.add(requestLinks.getSchemaLink(request));
    List<Link> taskLinks = requestLinks.getTaskLinks(request);
    if (!taskLinks.isEmpty()) {
        resource.add(taskLinks);
    }
    List<Link> signalLinks = requestLinks.getSignalLinks(request);
    if (!signalLinks.isEmpty()) {
        resource.add(signalLinks);
    }
    return resource;
}
Also used : Request(cern.modesti.request.Request) Link(org.springframework.hateoas.Link)

Example 15 with Request

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

the class RequestDiffer method diff.

public static ChangeEvent diff(Request modified, Request original, String idProperty) {
    List<Point> originalPointsStillPresentCurrently = deleteRemovedPoints(original.getPoints(), modified.getPoints(), idProperty);
    original.setPoints(originalPointsStillPresentCurrently);
    ChangeEvent event = new ChangeEvent(new DateTime(DateTimeZone.UTC));
    Request modifiedClone = new RequestImpl();
    Request originalClone = new RequestImpl();
    ChangeVisitor visitor = new ChangeVisitor(event, modifiedClone, originalClone);
    Map<Object, Point> modifiedPointMap = getPointsMap(modified.getPoints(), idProperty);
    for (Point originalPoint : original.getPoints()) {
        Point modifiedPoint = modifiedPointMap.get(originalPoint.getValueByPropertyName(idProperty));
        originalClone.setPoints(Arrays.asList((Point[]) new Point[] { originalPoint }));
        if (modifiedPoint != null) {
            modifiedClone.setPoints(Arrays.asList((Point[]) new Point[] { modifiedPoint }));
        }
        ObjectDiffer differ = ObjectDifferBuilder.startBuilding().identity().ofCollectionItems(NodePath.with("points")).via(new PointIdentityStrategy(idProperty)).and().build();
        DiffNode root = differ.compare(modifiedClone, originalClone);
        if (root.hasChanges()) {
            root.visit(visitor);
        }
    }
    return event;
}
Also used : Request(cern.modesti.request.Request) DiffNode(de.danielbechler.diff.node.DiffNode) Point(cern.modesti.point.Point) DateTime(org.joda.time.DateTime) RequestImpl(cern.modesti.request.RequestImpl) ObjectDiffer(de.danielbechler.diff.ObjectDiffer)

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