use of com.serotonin.m2m2.module.SystemActionDefinition in project ma-modules-public by infiniteautomation.
the class SystemActionRestV2Controller method list.
@ApiOperation(value = "List Available Actions", notes = "", response = List.class, responseContainer = "Array")
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<List<String>> list() {
Map<String, SystemActionDefinition> defs = ModuleRegistry.getSystemActionDefinitions();
List<String> model = new ArrayList<String>();
for (SystemActionDefinition def : defs.values()) model.add(def.getKey());
return new ResponseEntity<>(model, HttpStatus.OK);
}
use of com.serotonin.m2m2.module.SystemActionDefinition in project ma-modules-public by infiniteautomation.
the class SystemActionRestV2Controller method performAction.
@ApiOperation(value = "Perform an Action", notes = "Kicks off action and returns temporary URL for status")
@ApiResponses({ @ApiResponse(code = 500, message = "Internal error", response = ResponseEntity.class), @ApiResponse(code = 404, message = "Not Found", response = ResponseEntity.class) })
@RequestMapping(method = RequestMethod.PUT, value = "/trigger/{action}")
public ResponseEntity<SystemActionTemporaryResource> performAction(@ApiParam(value = "Valid System Action", required = true, allowMultiple = false) @PathVariable String action, @ApiParam(value = "Input for task", required = false, allowMultiple = false) @RequestBody(required = false) JsonNode input, @AuthenticationPrincipal User user, UriComponentsBuilder builder) {
// Kick off action
SystemActionDefinition def = ModuleRegistry.getSystemActionDefinition(action);
if (def == null)
throw new NotFoundRestException();
String resourceId = resources.generateResourceId();
SystemActionTemporaryResource resource = new SystemActionTemporaryResource(resourceId, def.getTask(user, input), resources, new Date(System.currentTimeMillis() + 600000));
// Resource can live for up to 10 minutes (TODO Configurable?)
resources.put(resourceId, resource);
URI location = builder.path("/v2/actions/status/{resourceId}").buildAndExpand(resourceId).toUri();
HttpHeaders headers = new HttpHeaders();
headers.setLocation(location);
return new ResponseEntity<>(resource, headers, HttpStatus.OK);
}
Aggregations