[Major] Implemented Control REST Service
This commit is contained in:
parent
534b555af4
commit
22883faa0d
|
@ -147,31 +147,66 @@ public enum State {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return true if {@link #EXECUTION}
|
||||
* @return true if {@link #CREATED} or {@link #PLANNING} or {@link #PLANNED} or {@link #STOPPED}
|
||||
*/
|
||||
public boolean canSetToCreated() {
|
||||
return this == CREATED || this == PLANNING || this == PLANNED || this == STOPPED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if {@link #CREATED} or {@link #PLANNING}
|
||||
*/
|
||||
public boolean canSetToPlanning() {
|
||||
return this == CREATED || this == PLANNING;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if {@link #CREATED} or {@link #PLANNING} or {@link #PLANNED}
|
||||
*/
|
||||
public boolean canSetToPlanned() {
|
||||
return this == CREATED || this == PLANNING || this == PLANNED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if {@link #CREATED} or {@link #PLANNING} or {@link #PLANNED} or {@link #EXECUTION}
|
||||
*/
|
||||
public boolean canSetToExecution() {
|
||||
return this == CREATED || this == PLANNING || this == PLANNED || this == EXECUTION;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if {@link #EXECUTION} or {@link #WARNING}
|
||||
*/
|
||||
public boolean canSetToWarning() {
|
||||
return this == EXECUTION || this == WARNING;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if {@link #ERROR} or {@link #STOPPED}
|
||||
* @return true if {@link #ERROR} or {@link #STOPPED} or {@link #WARNING}
|
||||
*/
|
||||
public boolean canSetToStopped() {
|
||||
return this == ERROR || this == State.STOPPED || this == State.WARNING;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if {@link #EXECUTION} or {@link #WARNING}
|
||||
* @return true if {@link #EXECUTION} or {@link #WARNING} or {@link #ERROR}
|
||||
*/
|
||||
public boolean canSetToError() {
|
||||
return this == EXECUTION || this == WARNING || this == ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if {@link #EXECUTION} or {@link #WARNING} or {@link #STOPPED}
|
||||
* @return true if {@link #EXECUTION} or {@link #WARNING} or {@link #STOPPED} or {@link #EXECUTED}
|
||||
*/
|
||||
public boolean canSetToExecuted() {
|
||||
return this == EXECUTION || this == WARNING || this == STOPPED;
|
||||
return this == EXECUTION || this == WARNING || this == STOPPED || this == EXECUTED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if {@link #EXECUTED}
|
||||
*/
|
||||
public boolean canSetToClosed() {
|
||||
return this == EXECUTED;
|
||||
}
|
||||
|
||||
public static State parseAllowNull(String s) {
|
||||
|
|
|
@ -39,6 +39,7 @@ public class StrolchRestfulClasses {
|
|||
restfulClasses.add(AuthenticationService.class);
|
||||
restfulClasses.add(StrolchJobsResource.class);
|
||||
restfulClasses.add(ReportResource.class);
|
||||
restfulClasses.add(ControlResource.class);
|
||||
restfulClasses.add(Inspector.class);
|
||||
restfulClasses.add(VersionQuery.class);
|
||||
restfulClasses.add(ModelQuery.class);
|
||||
|
|
|
@ -0,0 +1,265 @@
|
|||
package li.strolch.rest.endpoint;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import li.strolch.execution.ExecutionHandler;
|
||||
import li.strolch.execution.service.*;
|
||||
import li.strolch.model.Locator;
|
||||
import li.strolch.model.State;
|
||||
import li.strolch.model.activity.Activity;
|
||||
import li.strolch.model.json.StrolchElementToJsonVisitor;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.privilege.model.Certificate;
|
||||
import li.strolch.rest.RestfulStrolchComponent;
|
||||
import li.strolch.rest.StrolchRestfulConstants;
|
||||
import li.strolch.rest.helper.ResponseUtil;
|
||||
import li.strolch.service.LocatorArgument;
|
||||
import li.strolch.service.api.ServiceArgument;
|
||||
import li.strolch.service.api.ServiceResult;
|
||||
|
||||
@Path("strolch/control")
|
||||
public class ControlResource {
|
||||
|
||||
private static String getContext() {
|
||||
StackTraceElement element = new Throwable().getStackTrace()[2];
|
||||
return element.getClassName() + "." + element.getMethodName();
|
||||
}
|
||||
|
||||
private StrolchTransaction openTx(Certificate certificate, String realm) {
|
||||
return RestfulStrolchComponent.getInstance().openTx(certificate, realm, getContext());
|
||||
}
|
||||
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response getActivities(@Context HttpServletRequest request, @QueryParam("realm") String realm) {
|
||||
|
||||
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
|
||||
|
||||
StrolchElementToJsonVisitor visitor = new StrolchElementToJsonVisitor().withVersion().withLocator();
|
||||
|
||||
List<JsonElement> activities;
|
||||
try (StrolchTransaction tx = openTx(cert, realm)) {
|
||||
activities = tx.getContainer().getComponent(ExecutionHandler.class).getActiveActivitiesLocator(realm)
|
||||
.stream().map(locator -> tx.getActivityBy(locator.get(1), locator.get(2))).filter(Objects::nonNull)
|
||||
.sorted(Comparator.comparing(Activity::getId)).map(activity -> activity.accept(visitor))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
return ResponseUtil.toResponse(activities);
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("all")
|
||||
public Response clearAllActivities(@Context HttpServletRequest request, @QueryParam("realm") String realm) {
|
||||
|
||||
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
|
||||
|
||||
RestfulStrolchComponent instance = RestfulStrolchComponent.getInstance();
|
||||
|
||||
ClearAllCurrentExecutionsService svc = new ClearAllCurrentExecutionsService();
|
||||
ServiceArgument arg = svc.getArgumentInstance();
|
||||
arg.realm = realm;
|
||||
|
||||
ServiceResult svcResult = instance.getServiceHandler().doService(cert, svc, arg);
|
||||
|
||||
return ResponseUtil.toResponse(svcResult);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("state")
|
||||
public Response executeActivity(@Context HttpServletRequest request, @QueryParam("realm") String realm,
|
||||
@QueryParam("locator") String locatorS, @QueryParam("state") String stateS) {
|
||||
|
||||
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
|
||||
|
||||
Locator locator = Locator.valueOf(locatorS);
|
||||
|
||||
RestfulStrolchComponent instance = RestfulStrolchComponent.getInstance();
|
||||
|
||||
StartActivityExecutionService svc = new StartActivityExecutionService();
|
||||
LocatorArgument arg = svc.getArgumentInstance();
|
||||
arg.locator = locator;
|
||||
|
||||
ServiceResult svcResult = instance.getServiceHandler().doService(cert, svc, arg);
|
||||
|
||||
return ResponseUtil.toResponse(svcResult);
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("state")
|
||||
public Response removeActivityFromExecution(@Context HttpServletRequest request, @QueryParam("realm") String realm,
|
||||
@QueryParam("locator") String locatorS) {
|
||||
|
||||
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
|
||||
|
||||
RestfulStrolchComponent instance = RestfulStrolchComponent.getInstance();
|
||||
|
||||
Locator locator = Locator.valueOf(locatorS);
|
||||
|
||||
RemoveActivityFromExecutionService svc = new RemoveActivityFromExecutionService();
|
||||
LocatorArgument arg = svc.getArgumentInstance();
|
||||
arg.realm = realm;
|
||||
arg.locator = locator;
|
||||
|
||||
ServiceResult svcResult = instance.getServiceHandler().doService(cert, svc, arg);
|
||||
|
||||
return ResponseUtil.toResponse(svcResult);
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("state")
|
||||
public Response setElementState(@Context HttpServletRequest request, @QueryParam("realm") String realm,
|
||||
@QueryParam("locator") String locatorS, @QueryParam("state") String stateS) {
|
||||
|
||||
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
|
||||
|
||||
RestfulStrolchComponent instance = RestfulStrolchComponent.getInstance();
|
||||
|
||||
if (stateS.equals("Trigger")) {
|
||||
|
||||
TriggerExecutionForRealmService svc = new TriggerExecutionForRealmService();
|
||||
ServiceArgument arg = svc.getArgumentInstance();
|
||||
arg.realm = realm;
|
||||
|
||||
ServiceResult svcResult = instance.getServiceHandler().doService(cert, svc, arg);
|
||||
return ResponseUtil.toResponse(svcResult);
|
||||
|
||||
} else if (stateS.equals("ReloadActivities")) {
|
||||
|
||||
ReloadActivitiesInExecutionService svc = new ReloadActivitiesInExecutionService();
|
||||
ServiceArgument arg = svc.getArgumentInstance();
|
||||
arg.realm = realm;
|
||||
|
||||
ServiceResult svcResult = instance.getServiceHandler().doService(cert, svc, arg);
|
||||
return ResponseUtil.toResponse(svcResult);
|
||||
}
|
||||
|
||||
State state = State.parse(stateS);
|
||||
Locator locator = Locator.valueOf(locatorS);
|
||||
|
||||
ServiceResult svcResult;
|
||||
switch (state) {
|
||||
case CREATED: {
|
||||
|
||||
SetActionToCreatedService svc = new SetActionToCreatedService();
|
||||
LocatorArgument arg = svc.getArgumentInstance();
|
||||
arg.realm = realm;
|
||||
arg.locator = locator;
|
||||
|
||||
svcResult = instance.getServiceHandler().doService(cert, svc, arg);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case PLANNING: {
|
||||
|
||||
SetActionToPlanningService svc = new SetActionToPlanningService();
|
||||
LocatorArgument arg = svc.getArgumentInstance();
|
||||
arg.realm = realm;
|
||||
arg.locator = locator;
|
||||
|
||||
svcResult = instance.getServiceHandler().doService(cert, svc, arg);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case PLANNED: {
|
||||
|
||||
SetActionToPlannedService svc = new SetActionToPlannedService();
|
||||
LocatorArgument arg = svc.getArgumentInstance();
|
||||
arg.realm = realm;
|
||||
arg.locator = locator;
|
||||
|
||||
svcResult = instance.getServiceHandler().doService(cert, svc, arg);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case EXECUTION: {
|
||||
|
||||
SetToExecutionService svc = new SetToExecutionService();
|
||||
LocatorArgument arg = svc.getArgumentInstance();
|
||||
arg.realm = realm;
|
||||
arg.locator = locator;
|
||||
|
||||
svcResult = instance.getServiceHandler().doService(cert, svc, arg);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case WARNING: {
|
||||
|
||||
SetActionToWarningService svc = new SetActionToWarningService();
|
||||
LocatorArgument arg = svc.getArgumentInstance();
|
||||
arg.realm = realm;
|
||||
arg.locator = locator;
|
||||
|
||||
svcResult = instance.getServiceHandler().doService(cert, svc, arg);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case ERROR: {
|
||||
|
||||
SetActionToErrorService svc = new SetActionToErrorService();
|
||||
LocatorArgument arg = svc.getArgumentInstance();
|
||||
arg.realm = realm;
|
||||
arg.locator = locator;
|
||||
|
||||
svcResult = instance.getServiceHandler().doService(cert, svc, arg);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case STOPPED: {
|
||||
|
||||
SetActionToStoppedService svc = new SetActionToStoppedService();
|
||||
LocatorArgument arg = svc.getArgumentInstance();
|
||||
arg.realm = realm;
|
||||
arg.locator = locator;
|
||||
|
||||
svcResult = instance.getServiceHandler().doService(cert, svc, arg);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case EXECUTED: {
|
||||
|
||||
SetActionToExecutedService svc = new SetActionToExecutedService();
|
||||
LocatorArgument arg = svc.getArgumentInstance();
|
||||
arg.realm = realm;
|
||||
arg.locator = locator;
|
||||
|
||||
svcResult = instance.getServiceHandler().doService(cert, svc, arg);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case CLOSED: {
|
||||
|
||||
SetActionToClosedService svc = new SetActionToClosedService();
|
||||
LocatorArgument arg = svc.getArgumentInstance();
|
||||
arg.realm = realm;
|
||||
arg.locator = locator;
|
||||
|
||||
svcResult = instance.getServiceHandler().doService(cert, svc, arg);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
throw new UnsupportedOperationException("Unhandled state " + state);
|
||||
}
|
||||
|
||||
return ResponseUtil.toResponse(svcResult);
|
||||
}
|
||||
}
|
|
@ -415,7 +415,7 @@ public class Inspector {
|
|||
// build JSON response
|
||||
ResourceVisitor<JsonObject> visitor;
|
||||
if (overview == null || !overview) {
|
||||
visitor = new StrolchRootElementToJsonVisitor().asResourceVisitor();
|
||||
visitor = new StrolchRootElementToJsonVisitor().withLocator().asResourceVisitor();
|
||||
} else {
|
||||
visitor = e -> {
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
|
@ -423,6 +423,7 @@ public class Inspector {
|
|||
jsonObject.addProperty(Json.ID, e.getId());
|
||||
jsonObject.addProperty(Json.NAME, e.getName());
|
||||
jsonObject.addProperty(Json.TYPE, e.getType());
|
||||
jsonObject.addProperty(Json.LOCATOR, e.getLocator().toString());
|
||||
return jsonObject;
|
||||
};
|
||||
}
|
||||
|
@ -459,7 +460,7 @@ public class Inspector {
|
|||
// build JSON response
|
||||
OrderVisitor<JsonObject> visitor;
|
||||
if (overview == null || !overview) {
|
||||
visitor = new StrolchRootElementToJsonVisitor().asOrderVisitor();
|
||||
visitor = new StrolchRootElementToJsonVisitor().withLocator().asOrderVisitor();
|
||||
} else {
|
||||
visitor = e -> {
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
|
@ -467,6 +468,7 @@ public class Inspector {
|
|||
jsonObject.addProperty(Json.ID, e.getId());
|
||||
jsonObject.addProperty(Json.NAME, e.getName());
|
||||
jsonObject.addProperty(Json.TYPE, e.getType());
|
||||
jsonObject.addProperty(Json.LOCATOR, e.getLocator().toString());
|
||||
jsonObject.addProperty(Json.STATE, e.getState().name());
|
||||
jsonObject.addProperty(Json.DATE, ISO8601FormatFactory.getInstance().formatDate(e.getDate()));
|
||||
return jsonObject;
|
||||
|
@ -505,7 +507,7 @@ public class Inspector {
|
|||
// build JSON response
|
||||
ActivityVisitor<JsonObject> visitor;
|
||||
if (overview == null || !overview) {
|
||||
visitor = new StrolchRootElementToJsonVisitor().asActivityVisitor();
|
||||
visitor = new StrolchRootElementToJsonVisitor().withLocator().asActivityVisitor();
|
||||
} else {
|
||||
visitor = e -> {
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
|
@ -513,6 +515,7 @@ public class Inspector {
|
|||
jsonObject.addProperty(Json.ID, e.getId());
|
||||
jsonObject.addProperty(Json.NAME, e.getName());
|
||||
jsonObject.addProperty(Json.TYPE, e.getType());
|
||||
jsonObject.addProperty(Json.LOCATOR, e.getLocator().toString());
|
||||
jsonObject.addProperty(Json.STATE, e.getState().name());
|
||||
jsonObject.addProperty(Json.TIME_ORDERING, e.getTimeOrdering().name());
|
||||
return jsonObject;
|
||||
|
@ -639,7 +642,7 @@ public class Inspector {
|
|||
throw new StrolchException(MessageFormat.format("No Resource exists for {0}/{1}", type, id)); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
StrolchElementToJsonVisitor visitor = new StrolchElementToJsonVisitor().withVersion();
|
||||
StrolchElementToJsonVisitor visitor = new StrolchElementToJsonVisitor().withLocator().withVersion();
|
||||
if (Boolean.parseBoolean(flat))
|
||||
visitor.flat();
|
||||
|
||||
|
@ -682,7 +685,7 @@ public class Inspector {
|
|||
throw new StrolchException(MessageFormat.format("No Order exists for {0}/{1}", type, id)); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
StrolchElementToJsonVisitor visitor = new StrolchElementToJsonVisitor().withVersion();
|
||||
StrolchElementToJsonVisitor visitor = new StrolchElementToJsonVisitor().withLocator().withVersion();
|
||||
if (Boolean.parseBoolean(flat))
|
||||
visitor.flat();
|
||||
return Response.ok().entity(toString(order.accept(visitor))).build();
|
||||
|
@ -724,7 +727,7 @@ public class Inspector {
|
|||
throw new StrolchException(MessageFormat.format("No Activity exists for {0}/{1}", type, id)); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
StrolchElementToJsonVisitor visitor = new StrolchElementToJsonVisitor().withVersion();
|
||||
StrolchElementToJsonVisitor visitor = new StrolchElementToJsonVisitor().withLocator().withVersion();
|
||||
if (Boolean.parseBoolean(flat))
|
||||
visitor.flat();
|
||||
return Response.ok().entity(toString(activity.accept(visitor))).build();
|
||||
|
@ -818,7 +821,7 @@ public class Inspector {
|
|||
// do service
|
||||
ServiceResult result = RestfulStrolchComponent.getInstance().getServiceHandler().doService(cert, svc, arg);
|
||||
if (result.isOk()) {
|
||||
StrolchElementToJsonVisitor toJsonVisitor = new StrolchElementToJsonVisitor().withVersion();
|
||||
StrolchElementToJsonVisitor toJsonVisitor = new StrolchElementToJsonVisitor().withLocator().withVersion();
|
||||
if (flat)
|
||||
toJsonVisitor.flat();
|
||||
return Response.ok().entity(toString(resource.accept(toJsonVisitor))).build();
|
||||
|
@ -895,7 +898,7 @@ public class Inspector {
|
|||
// do service
|
||||
ServiceResult result = RestfulStrolchComponent.getInstance().getServiceHandler().doService(cert, svc, arg);
|
||||
if (result.isOk()) {
|
||||
StrolchElementToJsonVisitor toJsonVisitor = new StrolchElementToJsonVisitor().withVersion();
|
||||
StrolchElementToJsonVisitor toJsonVisitor = new StrolchElementToJsonVisitor().withLocator().withVersion();
|
||||
if (flat)
|
||||
toJsonVisitor.flat();
|
||||
return Response.ok().entity(toString(order.accept(toJsonVisitor))).build();
|
||||
|
@ -972,7 +975,7 @@ public class Inspector {
|
|||
// do service
|
||||
ServiceResult result = RestfulStrolchComponent.getInstance().getServiceHandler().doService(cert, svc, arg);
|
||||
if (result.isOk()) {
|
||||
StrolchElementToJsonVisitor toJsonVisitor = new StrolchElementToJsonVisitor().withVersion();
|
||||
StrolchElementToJsonVisitor toJsonVisitor = new StrolchElementToJsonVisitor().withLocator().withVersion();
|
||||
if (flat)
|
||||
toJsonVisitor.flat();
|
||||
return Response.ok().entity(toString(activity.accept(toJsonVisitor))).build();
|
||||
|
@ -1073,7 +1076,7 @@ public class Inspector {
|
|||
|
||||
ServiceResult result = RestfulStrolchComponent.getInstance().getServiceHandler().doService(cert, svc, arg);
|
||||
if (result.isOk()) {
|
||||
StrolchElementToJsonVisitor toJsonVisitor = new StrolchElementToJsonVisitor().withVersion();
|
||||
StrolchElementToJsonVisitor toJsonVisitor = new StrolchElementToJsonVisitor().withLocator().withVersion();
|
||||
return Response.ok().entity(toString(resource.accept(toJsonVisitor))).build();
|
||||
}
|
||||
|
||||
|
@ -1099,7 +1102,7 @@ public class Inspector {
|
|||
|
||||
ServiceResult result = RestfulStrolchComponent.getInstance().getServiceHandler().doService(cert, svc, arg);
|
||||
if (result.isOk()) {
|
||||
StrolchElementToJsonVisitor toJsonVisitor = new StrolchElementToJsonVisitor().withVersion();
|
||||
StrolchElementToJsonVisitor toJsonVisitor = new StrolchElementToJsonVisitor().withLocator().withVersion();
|
||||
if (flat)
|
||||
toJsonVisitor.flat();
|
||||
return Response.ok().entity(toString(resource.accept(toJsonVisitor))).build();
|
||||
|
@ -1152,7 +1155,7 @@ public class Inspector {
|
|||
|
||||
ServiceResult result = RestfulStrolchComponent.getInstance().getServiceHandler().doService(cert, svc, arg);
|
||||
if (result.isOk()) {
|
||||
StrolchElementToJsonVisitor toJsonVisitor = new StrolchElementToJsonVisitor().withVersion();
|
||||
StrolchElementToJsonVisitor toJsonVisitor = new StrolchElementToJsonVisitor().withLocator().withVersion();
|
||||
return Response.ok().entity(toString(order.accept(toJsonVisitor))).build();
|
||||
}
|
||||
|
||||
|
@ -1178,7 +1181,7 @@ public class Inspector {
|
|||
|
||||
ServiceResult result = RestfulStrolchComponent.getInstance().getServiceHandler().doService(cert, svc, arg);
|
||||
if (result.isOk()) {
|
||||
StrolchElementToJsonVisitor toJsonVisitor = new StrolchElementToJsonVisitor().withVersion();
|
||||
StrolchElementToJsonVisitor toJsonVisitor = new StrolchElementToJsonVisitor().withLocator().withVersion();
|
||||
if (flat)
|
||||
toJsonVisitor.flat();
|
||||
return Response.ok().entity(toString(order.accept(toJsonVisitor))).build();
|
||||
|
@ -1233,7 +1236,7 @@ public class Inspector {
|
|||
|
||||
ServiceResult result = RestfulStrolchComponent.getInstance().getServiceHandler().doService(cert, svc, arg);
|
||||
if (result.isOk()) {
|
||||
StrolchElementToJsonVisitor toJsonVisitor = new StrolchElementToJsonVisitor().withVersion();
|
||||
StrolchElementToJsonVisitor toJsonVisitor = new StrolchElementToJsonVisitor().withLocator().withVersion();
|
||||
return Response.ok().entity(toString(activity.accept(toJsonVisitor))).build();
|
||||
}
|
||||
|
||||
|
@ -1259,7 +1262,7 @@ public class Inspector {
|
|||
|
||||
ServiceResult result = RestfulStrolchComponent.getInstance().getServiceHandler().doService(cert, svc, arg);
|
||||
if (result.isOk()) {
|
||||
StrolchElementToJsonVisitor toJsonVisitor = new StrolchElementToJsonVisitor().withVersion();
|
||||
StrolchElementToJsonVisitor toJsonVisitor = new StrolchElementToJsonVisitor().withLocator().withVersion();
|
||||
if (flat)
|
||||
toJsonVisitor.flat();
|
||||
return Response.ok().entity(toString(activity.accept(toJsonVisitor))).build();
|
||||
|
|
|
@ -86,7 +86,11 @@ public class ResponseUtil {
|
|||
return toResponse(member, list.stream().map(toJson).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
public static Response toResponse(String member, List<JsonObject> jsonObjects) {
|
||||
public static Response toResponse(List<? extends JsonElement> jsonObjects) {
|
||||
return toResponse(DATA, jsonObjects);
|
||||
}
|
||||
|
||||
public static Response toResponse(String member, List<? extends JsonElement> jsonObjects) {
|
||||
JsonObject response = new JsonObject();
|
||||
response.addProperty(MSG, StringHelper.DASH);
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@ package li.strolch.execution;
|
|||
|
||||
import static li.strolch.runtime.StrolchConstants.SYSTEM_USER_AGENT;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
@ -22,7 +24,6 @@ import li.strolch.model.policy.PolicyDef;
|
|||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.policy.PolicyHandler;
|
||||
import li.strolch.privilege.model.PrivilegeContext;
|
||||
import li.strolch.runtime.StrolchConstants;
|
||||
import li.strolch.runtime.configuration.ComponentConfiguration;
|
||||
import li.strolch.utils.collections.MapOfSets;
|
||||
import li.strolch.utils.dbc.DBC;
|
||||
|
@ -81,6 +82,16 @@ public class EventBasedExecutionHandler extends ExecutionHandler {
|
|||
super.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Locator> getActiveActivitiesLocator(String realm) {
|
||||
if (this.registeredActivities == null || !this.registeredActivities.containsSet(realm))
|
||||
return Collections.emptySet();
|
||||
|
||||
synchronized (this.registeredActivities) {
|
||||
return new HashSet<>(this.registeredActivities.getSet(realm));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addForExecution(String realm, Locator activityLoc) {
|
||||
Locator rootElemLoc = activityLoc.trim(3);
|
||||
|
@ -98,50 +109,58 @@ public class EventBasedExecutionHandler extends ExecutionHandler {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearAllCurrentExecutions(String realm) {
|
||||
this.registeredActivities.removeSet(realm);
|
||||
}
|
||||
|
||||
private void restartActivityExecution(PrivilegeContext ctx) {
|
||||
|
||||
// iterate the realms
|
||||
for (String realmName : getContainer().getRealmNames()) {
|
||||
|
||||
// open a TX for each realm
|
||||
try (StrolchTransaction tx = openTx(realmName, ctx.getCertificate())) {
|
||||
|
||||
// iterate all activities
|
||||
tx.streamActivities().forEach(activity -> {
|
||||
|
||||
if (activity.isReadOnly())
|
||||
activity = activity.getClone(true);
|
||||
|
||||
// we only want to restart activities which were in execution
|
||||
State state = activity.getState();
|
||||
if (!state.inExecutionPhase())
|
||||
return;
|
||||
|
||||
logger.info("Starting Execution of " + activity.getLocator() + " on realm " + realmName);
|
||||
|
||||
// Activities need to be in state STOPPED to restart
|
||||
if (state == State.ERROR) {
|
||||
activity.getActionsWithState(State.ERROR).forEach(a -> a.setState(State.STOPPED));
|
||||
} else if (state == State.WARNING) {
|
||||
activity.getActionsWithState(State.WARNING).forEach(a -> a.setState(State.STOPPED));
|
||||
} else if (state == State.EXECUTION) {
|
||||
activity.getActionsWithState(State.EXECUTION).forEach(a -> a.setState(State.STOPPED));
|
||||
}
|
||||
tx.update(activity);
|
||||
|
||||
// register for execution
|
||||
this.registeredActivities.addElement(realmName, activity.getLocator());
|
||||
});
|
||||
|
||||
// commit changes to state
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
// trigger execution of the registered activities
|
||||
triggerExecution(realmName);
|
||||
reloadActivitiesInExecution(ctx, realmName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reloadActivitiesInExecution(PrivilegeContext ctx, String realmName) {
|
||||
try (StrolchTransaction tx = openTx(realmName, ctx.getCertificate())) {
|
||||
|
||||
// iterate all activities
|
||||
tx.streamActivities().forEach(activity -> {
|
||||
|
||||
if (activity.isReadOnly())
|
||||
activity = activity.getClone(true);
|
||||
|
||||
// we only want to restart activities which were in execution
|
||||
State state = activity.getState();
|
||||
if (!state.inExecutionPhase())
|
||||
return;
|
||||
|
||||
logger.info("Starting Execution of " + activity.getLocator() + " on realm " + realmName);
|
||||
|
||||
// Activities need to be in state STOPPED to restart
|
||||
if (state == State.ERROR) {
|
||||
activity.getActionsWithState(State.ERROR).forEach(a -> a.setState(State.STOPPED));
|
||||
} else if (state == State.WARNING) {
|
||||
activity.getActionsWithState(State.WARNING).forEach(a -> a.setState(State.STOPPED));
|
||||
} else if (state == State.EXECUTION) {
|
||||
activity.getActionsWithState(State.EXECUTION).forEach(a -> a.setState(State.STOPPED));
|
||||
}
|
||||
tx.update(activity);
|
||||
|
||||
// register for execution
|
||||
this.registeredActivities.addElement(realmName, activity.getLocator());
|
||||
});
|
||||
|
||||
// commit changes to state
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
// trigger execution of the registered activities
|
||||
triggerExecution(realmName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void triggerExecution(String realm) {
|
||||
synchronized (this.registeredActivities) {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package li.strolch.execution;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import li.strolch.agent.api.ComponentContainer;
|
||||
import li.strolch.agent.api.StrolchComponent;
|
||||
import li.strolch.execution.policy.DurationExecution;
|
||||
|
@ -9,6 +11,7 @@ import li.strolch.model.State;
|
|||
import li.strolch.model.activity.Action;
|
||||
import li.strolch.model.activity.Activity;
|
||||
import li.strolch.model.activity.TimeOrdering;
|
||||
import li.strolch.privilege.model.PrivilegeContext;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -55,6 +58,24 @@ public abstract class ExecutionHandler extends StrolchComponent {
|
|||
*/
|
||||
public abstract void removeFromExecution(String realm, Locator activityLoc);
|
||||
|
||||
/**
|
||||
* Restarts all existing Activities which are not yet executed and already in state of execution
|
||||
*
|
||||
* @param ctx
|
||||
* the privilege context
|
||||
* @param realm
|
||||
* the realm for which to restart activities
|
||||
*/
|
||||
public abstract void reloadActivitiesInExecution(PrivilegeContext ctx, String realm);
|
||||
|
||||
/**
|
||||
* Removes all currently registered {@link Activity Activities} from execution
|
||||
*
|
||||
* @param realm
|
||||
* the realm for which to restart activities
|
||||
*/
|
||||
public abstract void clearAllCurrentExecutions(String realm);
|
||||
|
||||
/**
|
||||
* Triggers a to execution for all registered activities in the given realm
|
||||
*
|
||||
|
@ -73,6 +94,17 @@ public abstract class ExecutionHandler extends StrolchComponent {
|
|||
*/
|
||||
public abstract void archiveActivity(String realm, Locator activityLoc);
|
||||
|
||||
/**
|
||||
* Returns the {@link Set} of {@link Locator Locators} of {@link Activity Activities} which are registered for
|
||||
* execution for the given realm
|
||||
*
|
||||
* @param realm
|
||||
* the realm for which to return the registered activities
|
||||
*
|
||||
* @return a set of locators
|
||||
*/
|
||||
public abstract Set<Locator> getActiveActivitiesLocator(String realm);
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Returns the {@link DelayedExecutionTimer}
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
package li.strolch.execution.command;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import li.strolch.agent.api.ComponentContainer;
|
||||
import li.strolch.exception.StrolchException;
|
||||
import li.strolch.model.State;
|
||||
import li.strolch.model.activity.Action;
|
||||
import li.strolch.model.activity.Activity;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.utils.dbc.DBC;
|
||||
|
||||
public class SetActionToClosedCommand extends ExecutionCommand {
|
||||
|
||||
private Action action;
|
||||
|
||||
public SetActionToClosedCommand(ComponentContainer container, StrolchTransaction tx) {
|
||||
super(container, tx);
|
||||
}
|
||||
|
||||
public void setAction(Action action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() {
|
||||
DBC.PRE.assertNotNull("action can not be null", this.action);
|
||||
|
||||
tx().lock(this.action.getRootElement());
|
||||
tx().lock(getResourceLocator(this.action));
|
||||
|
||||
if (!this.action.getState().canSetToClosed()) {
|
||||
String msg = "Current state is {0} and can not be changed to {1} for action {2}";
|
||||
msg = MessageFormat.format(msg, this.action.getState(), State.CLOSED, this.action.getLocator());
|
||||
throw new StrolchException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doCommand() {
|
||||
Activity rootElement = this.action.getRootElement();
|
||||
tx().lock(rootElement);
|
||||
tx().lock(getResourceLocator(this.action));
|
||||
|
||||
if (this.action.getState() == State.CLOSED) {
|
||||
logger.warn("Action " + this.action.getLocator() + " is already in CLOSED! Not changing.");
|
||||
return;
|
||||
}
|
||||
|
||||
State currentState = rootElement.getState();
|
||||
|
||||
this.action.setState(State.CLOSED);
|
||||
|
||||
getConfirmationPolicy(this.action).toClosed(this.action);
|
||||
|
||||
updateOrderState(rootElement, currentState, rootElement.getState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
// can not undo
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package li.strolch.execution.command;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import li.strolch.agent.api.ComponentContainer;
|
||||
import li.strolch.exception.StrolchException;
|
||||
import li.strolch.model.State;
|
||||
import li.strolch.model.activity.Action;
|
||||
import li.strolch.model.activity.Activity;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.utils.dbc.DBC;
|
||||
|
||||
public class SetActionToCreatedCommand extends ExecutionCommand {
|
||||
|
||||
private Action action;
|
||||
|
||||
public SetActionToCreatedCommand(ComponentContainer container, StrolchTransaction tx) {
|
||||
super(container, tx);
|
||||
}
|
||||
|
||||
public void setAction(Action action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() {
|
||||
DBC.PRE.assertNotNull("action can not be null", this.action);
|
||||
|
||||
tx().lock(this.action.getRootElement());
|
||||
tx().lock(getResourceLocator(this.action));
|
||||
|
||||
if (!this.action.getState().canSetToCreated()) {
|
||||
String msg = "Current state is {0} and can not be changed to {1} for action {2}";
|
||||
msg = MessageFormat.format(msg, this.action.getState(), State.CREATED, this.action.getLocator());
|
||||
throw new StrolchException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doCommand() {
|
||||
Activity rootElement = this.action.getRootElement();
|
||||
tx().lock(rootElement);
|
||||
tx().lock(getResourceLocator(this.action));
|
||||
|
||||
if (this.action.getState() == State.CREATED) {
|
||||
logger.warn("Action " + this.action.getLocator() + " is already in CREATED! Not changing.");
|
||||
return;
|
||||
}
|
||||
|
||||
State currentState = rootElement.getState();
|
||||
|
||||
this.action.setState(State.CREATED);
|
||||
|
||||
getConfirmationPolicy(this.action).toCreated(this.action);
|
||||
|
||||
updateOrderState(rootElement, currentState, rootElement.getState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
// can not undo
|
||||
}
|
||||
}
|
|
@ -30,7 +30,7 @@ public class SetActionToErrorCommand extends ExecutionCommand {
|
|||
tx().lock(getResourceLocator(this.action));
|
||||
|
||||
if (!this.action.getState().canSetToError()) {
|
||||
String msg = "Current state is {0} and canot be changed to {1} for action {2}";
|
||||
String msg = "Current state is {0} and can not be changed to {1} for action {2}";
|
||||
msg = MessageFormat.format(msg, this.action.getState(), State.ERROR, this.action.getLocator());
|
||||
throw new StrolchException(msg);
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ public class SetActionToExecutedCommand extends ExecutionCommand {
|
|||
tx().lock(getResourceLocator(this.action));
|
||||
|
||||
if (!this.action.getState().canSetToExecuted()) {
|
||||
String msg = "Current state is {0} canot be changed to {1} for action {2}";
|
||||
String msg = "Current state is {0} can not be changed to {1} for action {2}";
|
||||
msg = MessageFormat.format(msg, this.action.getState(), State.EXECUTED, this.action.getLocator());
|
||||
throw new StrolchException(msg);
|
||||
}
|
||||
|
@ -42,6 +42,11 @@ public class SetActionToExecutedCommand extends ExecutionCommand {
|
|||
tx().lock(rootElement);
|
||||
tx().lock(getResourceLocator(this.action));
|
||||
|
||||
if (this.action.getState() == State.EXECUTED) {
|
||||
logger.warn("Action " + this.action.getLocator() + " is already in EXECUTED! Not changing.");
|
||||
return;
|
||||
}
|
||||
|
||||
State currentState = rootElement.getState();
|
||||
|
||||
getExecutionPolicy(this.action).toExecuted(this.action);
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
package li.strolch.execution.command;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import li.strolch.agent.api.ComponentContainer;
|
||||
import li.strolch.exception.StrolchException;
|
||||
import li.strolch.model.State;
|
||||
import li.strolch.model.activity.Action;
|
||||
import li.strolch.model.activity.Activity;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.utils.dbc.DBC;
|
||||
|
||||
public class SetActionToPlannedCommand extends ExecutionCommand {
|
||||
|
||||
private Action action;
|
||||
|
||||
public SetActionToPlannedCommand(ComponentContainer container, StrolchTransaction tx) {
|
||||
super(container, tx);
|
||||
}
|
||||
|
||||
public void setAction(Action action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() {
|
||||
DBC.PRE.assertNotNull("action can not be null", this.action);
|
||||
|
||||
tx().lock(this.action.getRootElement());
|
||||
tx().lock(getResourceLocator(this.action));
|
||||
|
||||
if (!this.action.getState().canSetToPlanned()) {
|
||||
String msg = "Current state is {0} and can not be changed to {1} for action {2}";
|
||||
msg = MessageFormat.format(msg, this.action.getState(), State.PLANNED, this.action.getLocator());
|
||||
throw new StrolchException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doCommand() {
|
||||
Activity rootElement = this.action.getRootElement();
|
||||
tx().lock(rootElement);
|
||||
tx().lock(getResourceLocator(this.action));
|
||||
|
||||
if (this.action.getState() == State.PLANNED) {
|
||||
logger.warn("Action " + this.action.getLocator() + " is already in PLANNED! Not changing.");
|
||||
return;
|
||||
}
|
||||
|
||||
State currentState = rootElement.getState();
|
||||
|
||||
this.action.setState(State.PLANNED);
|
||||
|
||||
getConfirmationPolicy(this.action).toPlanned(this.action);
|
||||
|
||||
updateOrderState(rootElement, currentState, rootElement.getState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
// can not undo
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package li.strolch.execution.command;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import li.strolch.agent.api.ComponentContainer;
|
||||
import li.strolch.exception.StrolchException;
|
||||
import li.strolch.model.State;
|
||||
import li.strolch.model.activity.Action;
|
||||
import li.strolch.model.activity.Activity;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.utils.dbc.DBC;
|
||||
|
||||
public class SetActionToPlanningCommand extends ExecutionCommand {
|
||||
|
||||
private Action action;
|
||||
|
||||
public SetActionToPlanningCommand(ComponentContainer container, StrolchTransaction tx) {
|
||||
super(container, tx);
|
||||
}
|
||||
|
||||
public void setAction(Action action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() {
|
||||
DBC.PRE.assertNotNull("action can not be null", this.action);
|
||||
|
||||
tx().lock(this.action.getRootElement());
|
||||
tx().lock(getResourceLocator(this.action));
|
||||
|
||||
if (!this.action.getState().canSetToPlanning()) {
|
||||
String msg = "Current state is {0} and can not be changed to {1} for action {2}";
|
||||
msg = MessageFormat.format(msg, this.action.getState(), State.PLANNING, this.action.getLocator());
|
||||
throw new StrolchException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doCommand() {
|
||||
Activity rootElement = this.action.getRootElement();
|
||||
tx().lock(rootElement);
|
||||
tx().lock(getResourceLocator(this.action));
|
||||
|
||||
if (this.action.getState() == State.PLANNING) {
|
||||
logger.warn("Action " + this.action.getLocator() + " is already in PLANNING! Not changing.");
|
||||
return;
|
||||
}
|
||||
|
||||
State currentState = rootElement.getState();
|
||||
|
||||
this.action.setState(State.PLANNING);
|
||||
|
||||
getConfirmationPolicy(this.action).toPlanning(this.action);
|
||||
|
||||
updateOrderState(rootElement, currentState, rootElement.getState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
// can not undo
|
||||
}
|
||||
}
|
|
@ -30,7 +30,7 @@ public class SetActionToStoppedCommand extends ExecutionCommand {
|
|||
tx().lock(getResourceLocator(this.action));
|
||||
|
||||
if (!this.action.getState().canSetToStopped()) {
|
||||
String msg = "Current state is {0} and canot be changed to {1} for action {2}";
|
||||
String msg = "Current state is {0} and can not be changed to {1} for action {2}";
|
||||
msg = MessageFormat.format(msg, this.action.getState(), State.STOPPED, this.action.getLocator());
|
||||
throw new StrolchException(msg);
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ public class SetActionToWarningCommand extends ExecutionCommand {
|
|||
tx().lock(getResourceLocator(this.action));
|
||||
|
||||
if (!this.action.getState().canSetToWarning()) {
|
||||
String msg = "Current state is {0} and canot be changed to {1} for action {2}";
|
||||
String msg = "Current state is {0} and can not be changed to {1} for action {2}";
|
||||
msg = MessageFormat.format(msg, this.action.getState(), State.WARNING, this.action.getLocator());
|
||||
throw new StrolchException(msg);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package li.strolch.execution.service;
|
||||
|
||||
import li.strolch.execution.ExecutionHandler;
|
||||
import li.strolch.runtime.StrolchConstants;
|
||||
import li.strolch.service.api.AbstractService;
|
||||
import li.strolch.service.api.ServiceArgument;
|
||||
import li.strolch.service.api.ServiceResult;
|
||||
import li.strolch.service.api.ServiceResultState;
|
||||
import li.strolch.utils.helper.StringHelper;
|
||||
|
||||
public class ClearAllCurrentExecutionsService extends AbstractService<ServiceArgument, ServiceResult> {
|
||||
|
||||
@Override
|
||||
protected ServiceResult getResultInstance() {
|
||||
return new ServiceResult(ServiceResultState.FAILED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServiceArgument getArgumentInstance() {
|
||||
return new ServiceArgument();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ServiceResult internalDoService(ServiceArgument arg) throws Exception {
|
||||
|
||||
String realm = StringHelper.isEmpty(arg.realm) ? StrolchConstants.DEFAULT_REALM : arg.realm;
|
||||
|
||||
ExecutionHandler executionHandler = getContainer().getComponent(ExecutionHandler.class);
|
||||
executionHandler.clearAllCurrentExecutions(realm);
|
||||
|
||||
return ServiceResult.success();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package li.strolch.execution.service;
|
||||
|
||||
import li.strolch.execution.ExecutionHandler;
|
||||
import li.strolch.runtime.StrolchConstants;
|
||||
import li.strolch.service.api.AbstractService;
|
||||
import li.strolch.service.api.ServiceArgument;
|
||||
import li.strolch.service.api.ServiceResult;
|
||||
import li.strolch.service.api.ServiceResultState;
|
||||
import li.strolch.utils.helper.StringHelper;
|
||||
|
||||
public class ReloadActivitiesInExecutionService extends AbstractService<ServiceArgument, ServiceResult> {
|
||||
|
||||
@Override
|
||||
protected ServiceResult getResultInstance() {
|
||||
return new ServiceResult(ServiceResultState.FAILED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServiceArgument getArgumentInstance() {
|
||||
return new ServiceArgument();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ServiceResult internalDoService(ServiceArgument arg) throws Exception {
|
||||
|
||||
String realm = StringHelper.isEmpty(arg.realm) ? StrolchConstants.DEFAULT_REALM : arg.realm;
|
||||
|
||||
ExecutionHandler executionHandler = getContainer().getComponent(ExecutionHandler.class);
|
||||
executionHandler.reloadActivitiesInExecution(getPrivilegeContext(), realm);
|
||||
|
||||
return ServiceResult.success();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package li.strolch.execution.service;
|
||||
|
||||
import li.strolch.execution.ExecutionHandler;
|
||||
import li.strolch.runtime.StrolchConstants;
|
||||
import li.strolch.service.LocatorArgument;
|
||||
import li.strolch.service.api.AbstractService;
|
||||
import li.strolch.service.api.ServiceResult;
|
||||
import li.strolch.service.api.ServiceResultState;
|
||||
import li.strolch.utils.helper.StringHelper;
|
||||
|
||||
public class RemoveActivityFromExecutionService extends AbstractService<LocatorArgument, ServiceResult> {
|
||||
|
||||
@Override
|
||||
protected ServiceResult getResultInstance() {
|
||||
return new ServiceResult(ServiceResultState.FAILED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocatorArgument getArgumentInstance() {
|
||||
return new LocatorArgument();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ServiceResult internalDoService(LocatorArgument arg) throws Exception {
|
||||
|
||||
String realm = StringHelper.isEmpty(arg.realm) ? StrolchConstants.DEFAULT_REALM : arg.realm;
|
||||
|
||||
ExecutionHandler executionHandler = getContainer().getComponent(ExecutionHandler.class);
|
||||
executionHandler.removeFromExecution(realm, arg.locator);
|
||||
|
||||
return ServiceResult.success();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package li.strolch.execution.service;
|
||||
|
||||
import li.strolch.execution.command.SetActionToClosedCommand;
|
||||
import li.strolch.model.activity.Action;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.service.LocatorArgument;
|
||||
import li.strolch.service.api.AbstractService;
|
||||
import li.strolch.service.api.ServiceResult;
|
||||
import li.strolch.service.api.ServiceResultState;
|
||||
|
||||
public class SetActionToClosedService extends AbstractService<LocatorArgument, ServiceResult> {
|
||||
|
||||
@Override
|
||||
protected ServiceResult getResultInstance() {
|
||||
return new ServiceResult(ServiceResultState.FAILED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocatorArgument getArgumentInstance() {
|
||||
return new LocatorArgument();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ServiceResult internalDoService(LocatorArgument arg) throws Exception {
|
||||
|
||||
try (StrolchTransaction tx = openArgOrUserTx(arg)) {
|
||||
|
||||
Action action = tx.findElement(arg.locator);
|
||||
|
||||
SetActionToClosedCommand command = new SetActionToClosedCommand(getContainer(), tx);
|
||||
command.setAction(action);
|
||||
tx.addCommand(command);
|
||||
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
return ServiceResult.success();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package li.strolch.execution.service;
|
||||
|
||||
import li.strolch.execution.command.SetActionToCreatedCommand;
|
||||
import li.strolch.model.activity.Action;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.service.LocatorArgument;
|
||||
import li.strolch.service.api.AbstractService;
|
||||
import li.strolch.service.api.ServiceResult;
|
||||
import li.strolch.service.api.ServiceResultState;
|
||||
|
||||
public class SetActionToCreatedService extends AbstractService<LocatorArgument, ServiceResult> {
|
||||
|
||||
@Override
|
||||
protected ServiceResult getResultInstance() {
|
||||
return new ServiceResult(ServiceResultState.FAILED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocatorArgument getArgumentInstance() {
|
||||
return new LocatorArgument();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ServiceResult internalDoService(LocatorArgument arg) throws Exception {
|
||||
|
||||
try (StrolchTransaction tx = openArgOrUserTx(arg)) {
|
||||
|
||||
Action action = tx.findElement(arg.locator);
|
||||
|
||||
SetActionToCreatedCommand command = new SetActionToCreatedCommand(getContainer(), tx);
|
||||
command.setAction(action);
|
||||
tx.addCommand(command);
|
||||
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
return ServiceResult.success();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package li.strolch.execution.service;
|
||||
|
||||
import li.strolch.execution.command.SetActionToErrorCommand;
|
||||
import li.strolch.model.activity.Action;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.service.LocatorArgument;
|
||||
import li.strolch.service.api.AbstractService;
|
||||
import li.strolch.service.api.ServiceResult;
|
||||
import li.strolch.service.api.ServiceResultState;
|
||||
|
||||
public class SetActionToErrorService extends AbstractService<LocatorArgument, ServiceResult> {
|
||||
|
||||
@Override
|
||||
protected ServiceResult getResultInstance() {
|
||||
return new ServiceResult(ServiceResultState.FAILED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocatorArgument getArgumentInstance() {
|
||||
return new LocatorArgument();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ServiceResult internalDoService(LocatorArgument arg) throws Exception {
|
||||
|
||||
try (StrolchTransaction tx = openArgOrUserTx(arg)) {
|
||||
|
||||
Action action = tx.findElement(arg.locator);
|
||||
|
||||
SetActionToErrorCommand command = new SetActionToErrorCommand(getContainer(), tx);
|
||||
command.setAction(action);
|
||||
tx.addCommand(command);
|
||||
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
return ServiceResult.success();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package li.strolch.execution.service;
|
||||
|
||||
import li.strolch.execution.command.SetActionToPlannedCommand;
|
||||
import li.strolch.model.activity.Action;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.service.LocatorArgument;
|
||||
import li.strolch.service.api.AbstractService;
|
||||
import li.strolch.service.api.ServiceResult;
|
||||
import li.strolch.service.api.ServiceResultState;
|
||||
|
||||
public class SetActionToPlannedService extends AbstractService<LocatorArgument, ServiceResult> {
|
||||
|
||||
@Override
|
||||
protected ServiceResult getResultInstance() {
|
||||
return new ServiceResult(ServiceResultState.FAILED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocatorArgument getArgumentInstance() {
|
||||
return new LocatorArgument();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ServiceResult internalDoService(LocatorArgument arg) throws Exception {
|
||||
|
||||
try (StrolchTransaction tx = openArgOrUserTx(arg)) {
|
||||
|
||||
Action action = tx.findElement(arg.locator);
|
||||
|
||||
SetActionToPlannedCommand command = new SetActionToPlannedCommand(getContainer(), tx);
|
||||
command.setAction(action);
|
||||
tx.addCommand(command);
|
||||
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
return ServiceResult.success();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package li.strolch.execution.service;
|
||||
|
||||
import li.strolch.execution.command.SetActionToPlanningCommand;
|
||||
import li.strolch.model.activity.Action;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.service.LocatorArgument;
|
||||
import li.strolch.service.api.AbstractService;
|
||||
import li.strolch.service.api.ServiceResult;
|
||||
import li.strolch.service.api.ServiceResultState;
|
||||
|
||||
public class SetActionToPlanningService extends AbstractService<LocatorArgument, ServiceResult> {
|
||||
|
||||
@Override
|
||||
protected ServiceResult getResultInstance() {
|
||||
return new ServiceResult(ServiceResultState.FAILED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocatorArgument getArgumentInstance() {
|
||||
return new LocatorArgument();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ServiceResult internalDoService(LocatorArgument arg) throws Exception {
|
||||
|
||||
try (StrolchTransaction tx = openArgOrUserTx(arg)) {
|
||||
|
||||
Action action = tx.findElement(arg.locator);
|
||||
|
||||
SetActionToPlanningCommand command = new SetActionToPlanningCommand(getContainer(), tx);
|
||||
command.setAction(action);
|
||||
tx.addCommand(command);
|
||||
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
return ServiceResult.success();
|
||||
}
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
package li.strolch.execution.service;
|
||||
|
||||
import li.strolch.execution.ExecutionHandler;
|
||||
import li.strolch.runtime.StrolchConstants;
|
||||
import li.strolch.execution.command.SetActionToStoppedCommand;
|
||||
import li.strolch.model.activity.Action;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.service.LocatorArgument;
|
||||
import li.strolch.service.api.AbstractService;
|
||||
import li.strolch.service.api.ServiceResult;
|
||||
import li.strolch.service.api.ServiceResultState;
|
||||
import li.strolch.utils.helper.StringHelper;
|
||||
|
||||
public class SetActionToStoppedService extends AbstractService<LocatorArgument, ServiceResult> {
|
||||
|
||||
|
@ -23,10 +23,16 @@ public class SetActionToStoppedService extends AbstractService<LocatorArgument,
|
|||
@Override
|
||||
protected ServiceResult internalDoService(LocatorArgument arg) throws Exception {
|
||||
|
||||
String realm = StringHelper.isEmpty(arg.realm) ? StrolchConstants.DEFAULT_REALM : arg.realm;
|
||||
try (StrolchTransaction tx = openArgOrUserTx(arg)) {
|
||||
|
||||
ExecutionHandler executionHandler = getContainer().getComponent(ExecutionHandler.class);
|
||||
executionHandler.toStopped(realm, arg.locator);
|
||||
Action action = tx.findElement(arg.locator);
|
||||
|
||||
SetActionToStoppedCommand command = new SetActionToStoppedCommand(getContainer(), tx);
|
||||
command.setAction(action);
|
||||
tx.addCommand(command);
|
||||
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
return ServiceResult.success();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package li.strolch.execution.service;
|
||||
|
||||
import li.strolch.execution.command.SetActionToWarningCommand;
|
||||
import li.strolch.model.activity.Action;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.service.LocatorArgument;
|
||||
import li.strolch.service.api.AbstractService;
|
||||
import li.strolch.service.api.ServiceResult;
|
||||
import li.strolch.service.api.ServiceResultState;
|
||||
|
||||
public class SetActionToWarningService extends AbstractService<LocatorArgument, ServiceResult> {
|
||||
|
||||
@Override
|
||||
protected ServiceResult getResultInstance() {
|
||||
return new ServiceResult(ServiceResultState.FAILED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocatorArgument getArgumentInstance() {
|
||||
return new LocatorArgument();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ServiceResult internalDoService(LocatorArgument arg) throws Exception {
|
||||
|
||||
try (StrolchTransaction tx = openArgOrUserTx(arg)) {
|
||||
|
||||
Action action = tx.findElement(arg.locator);
|
||||
|
||||
SetActionToWarningCommand command = new SetActionToWarningCommand(getContainer(), tx);
|
||||
command.setAction(action);
|
||||
tx.addCommand(command);
|
||||
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
return ServiceResult.success();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package li.strolch.execution.service;
|
||||
|
||||
import static li.strolch.utils.helper.StringHelper.isEmpty;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import li.strolch.exception.StrolchException;
|
||||
import li.strolch.execution.ExecutionHandler;
|
||||
import li.strolch.model.State;
|
||||
import li.strolch.model.activity.IActivityElement;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.runtime.StrolchConstants;
|
||||
import li.strolch.service.LocatorArgument;
|
||||
import li.strolch.service.api.AbstractService;
|
||||
import li.strolch.service.api.ServiceResult;
|
||||
import li.strolch.service.api.ServiceResultState;
|
||||
|
||||
public class SetToExecutionService extends AbstractService<LocatorArgument, ServiceResult> {
|
||||
|
||||
@Override
|
||||
protected ServiceResult getResultInstance() {
|
||||
return new ServiceResult(ServiceResultState.FAILED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocatorArgument getArgumentInstance() {
|
||||
return new LocatorArgument();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ServiceResult internalDoService(LocatorArgument arg) throws Exception {
|
||||
|
||||
String realm = isEmpty(arg.realm) ? StrolchConstants.DEFAULT_REALM : arg.realm;
|
||||
|
||||
try (StrolchTransaction tx = openTx(realm)) {
|
||||
tx.lock(arg.locator);
|
||||
|
||||
IActivityElement element = tx.findElement(arg.locator);
|
||||
if (!element.getState().canSetToExecution()) {
|
||||
String msg = "Current state is {0} and can not be changed to {1} for action {2}";
|
||||
msg = MessageFormat.format(msg, element.getState(), State.EXECUTION, element.getLocator());
|
||||
throw new StrolchException(msg);
|
||||
}
|
||||
|
||||
ExecutionHandler executionHandler = getContainer().getComponent(ExecutionHandler.class);
|
||||
executionHandler.toExecution(realm, arg.locator);
|
||||
}
|
||||
|
||||
return ServiceResult.success();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package li.strolch.execution.service;
|
||||
|
||||
import li.strolch.execution.ExecutionHandler;
|
||||
import li.strolch.runtime.StrolchConstants;
|
||||
import li.strolch.service.api.AbstractService;
|
||||
import li.strolch.service.api.ServiceArgument;
|
||||
import li.strolch.service.api.ServiceResult;
|
||||
import li.strolch.service.api.ServiceResultState;
|
||||
import li.strolch.utils.helper.StringHelper;
|
||||
|
||||
public class TriggerExecutionForRealmService extends AbstractService<ServiceArgument, ServiceResult> {
|
||||
|
||||
@Override
|
||||
protected ServiceResult getResultInstance() {
|
||||
return new ServiceResult(ServiceResultState.FAILED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServiceArgument getArgumentInstance() {
|
||||
return new ServiceArgument();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ServiceResult internalDoService(ServiceArgument arg) throws Exception {
|
||||
|
||||
String realm = StringHelper.isEmpty(arg.realm) ? StrolchConstants.DEFAULT_REALM : arg.realm;
|
||||
|
||||
ExecutionHandler executionHandler = getContainer().getComponent(ExecutionHandler.class);
|
||||
executionHandler.triggerExecution(realm);
|
||||
|
||||
return ServiceResult.success();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue