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