use of com.infiniteautomation.mango.rest.latest.exception.NotFoundRestException in project ma-modules-public by infiniteautomation.
the class EventDetectorsRestController method getState.
@ApiOperation(value = "Get Event Detector's internal state", notes = "User must have read permission for the data point", response = AbstractEventDetectorRTModel.class)
@RequestMapping(method = RequestMethod.GET, value = "/runtime/{xid}")
public AbstractEventDetectorRTModel<?> getState(@ApiParam(value = "ID of Event detector", required = true, allowMultiple = false) @PathVariable String xid, @AuthenticationPrincipal PermissionHolder user, UriComponentsBuilder builder) {
AbstractEventDetectorVO vo = service.get(xid);
// For now all detectors are data point type
DataPointRT rt = Common.runtimeManager.getDataPoint(vo.getSourceId());
if (rt == null) {
throw new TranslatableIllegalStateException(new TranslatableMessage("rest.error.pointNotEnabled", xid));
}
for (PointEventDetectorRT<?> edrt : rt.getEventDetectors()) {
if (edrt.getVO().getId() == vo.getId()) {
return modelMapper.map(edrt, AbstractEventDetectorRTModel.class, user);
}
}
throw new NotFoundRestException();
}
use of com.infiniteautomation.mango.rest.latest.exception.NotFoundRestException in project ma-modules-public by infiniteautomation.
the class LoggingRestController method getLogFile.
private ResponseEntity<FileSystemResource> getLogFile(String filename, boolean download) {
Path file = Common.getLogsPath().resolve(filename);
if (!filterFiles(file)) {
throw new NotFoundRestException();
}
// TODO There is a known bug here where if the file rolls over during download/transmission the request will fail
HttpHeaders responseHeaders = new HttpHeaders();
String fileNameFromFile = file.getFileName().toString();
if (fileNameFromFile.endsWith(".gz")) {
responseHeaders.set(HttpHeaders.CONTENT_ENCODING, "gzip");
fileNameFromFile = fileNameFromFile.substring(0, fileNameFromFile.length() - ".gz".length());
}
String contentDisposition = ContentDisposition.builder(download ? "attachment" : "inline").filename(fileNameFromFile).build().toString();
responseHeaders.set(HttpHeaders.CONTENT_DISPOSITION, contentDisposition);
return new ResponseEntity<>(new FileSystemResource(file), responseHeaders, HttpStatus.OK);
}
use of com.infiniteautomation.mango.rest.latest.exception.NotFoundRestException in project ma-modules-public by infiniteautomation.
the class JsonDataRestController method getNode.
JsonNode getNode(final JsonNode existingData, final String[] dataPath) {
JsonNode node = existingData;
for (int i = 0; i < dataPath.length; i++) {
String fieldName = dataPath[i];
if (node.isObject()) {
ObjectNode objectNode = (ObjectNode) node;
node = objectNode.get(fieldName);
} else if (node.isArray()) {
ArrayNode arrayNode = (ArrayNode) node;
int index = toArrayIndex(fieldName);
node = arrayNode.get(index);
} else {
throw new BadRequestException(new TranslatableMessage("rest.error.cantGetFieldOfNodeType", node.getNodeType()));
}
if (node == null) {
throw new NotFoundRestException();
}
}
return node;
}
use of com.infiniteautomation.mango.rest.latest.exception.NotFoundRestException in project ma-modules-public by infiniteautomation.
the class SystemActionRestController 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, @RequestParam(required = false, defaultValue = "12000000") Long timeout, @AuthenticationPrincipal PermissionHolder 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() + timeout));
// Resource can live for up to 10 minutes (TODO Configurable?)
resources.put(resourceId, resource);
URI location = builder.path("/actions/status/{resourceId}").buildAndExpand(resourceId).toUri();
HttpHeaders headers = new HttpHeaders();
headers.setLocation(location);
return new ResponseEntity<>(resource, headers, HttpStatus.OK);
}
use of com.infiniteautomation.mango.rest.latest.exception.NotFoundRestException in project ma-modules-public by infiniteautomation.
the class PartialUpdateArgumentResolver method resolveArgument.
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
ServletServerHttpRequest req = createInputMessage(webRequest);
PatchVORequestBody patch = parameter.getParameterAnnotation(PatchVORequestBody.class);
Class<?> serviceClass = patch.service();
AbstractVOService<?, ?> service = (AbstractVOService<?, ?>) context.getBean(serviceClass);
PermissionHolder user = Common.getUser();
// Set the source class into the request scope to use if validation fails
webRequest.setAttribute(MangoRequestBodyAdvice.MODEL_CLASS, patch.modelClass(), RequestAttributes.SCOPE_REQUEST);
Object vo;
switch(patch.idType()) {
case ID:
Integer id = Integer.parseInt(getPathVariables(webRequest).get(ID));
vo = service.get(id);
if (vo == null)
throw new NotFoundRestException();
else {
Object model = modelMapper.map(vo, patch.modelClass(), user);
return readJavaType(model, req);
}
case XID:
String xid = getPathVariables(webRequest).get(XID);
vo = service.get(xid);
if (vo == null)
throw new NotFoundRestException();
else {
Object model = modelMapper.map(vo, patch.modelClass(), user);
return readJavaType(model, req);
}
default:
case OTHER:
String other = getPathVariables(webRequest).get(patch.urlPathVariableName());
vo = service.get(other);
if (vo == null)
throw new NotFoundRestException();
else {
Object model = modelMapper.map(vo, patch.modelClass(), user);
return readJavaType(model, req);
}
}
}
Aggregations