use of com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult in project ma-modules-public by infiniteautomation.
the class ModulesRestController method getPublicAngularJSModules.
@ApiOperation(value = "AngularJS Modules", notes = "Publicly Available Angular JS Modules")
@RequestMapping(method = RequestMethod.GET, value = "/angularjs-modules/public", produces = { "application/json" })
public ResponseEntity<AngularJSModuleDefinitionGroupModel> getPublicAngularJSModules(HttpServletRequest request) {
RestProcessResult<AngularJSModuleDefinitionGroupModel> result = new RestProcessResult<AngularJSModuleDefinitionGroupModel>(HttpStatus.OK);
List<AngularJSModuleDefinition> definitions = ModuleRegistry.getAngularJSDefinitions();
List<String> urls = new ArrayList<String>();
for (AngularJSModuleDefinition def : definitions) urls.add(def.getModule().getWebPath() + WEB + def.getJavaScriptFilename());
AngularJSModuleDefinitionGroupModel model = new AngularJSModuleDefinitionGroupModel();
model.setUrls(urls);
return result.createResponseEntity(model);
}
use of com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult in project ma-modules-public by infiniteautomation.
the class ModulesRestController method listModules.
@ApiOperation(value = "List Current Installed Modules", notes = "List all installed")
@RequestMapping(method = RequestMethod.GET, value = "/list", produces = { "application/json" })
public ResponseEntity<List<ModuleModel>> listModules(HttpServletRequest request) {
RestProcessResult<List<ModuleModel>> result = new RestProcessResult<List<ModuleModel>>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
if (Permissions.hasAdmin(user)) {
List<ModuleModel> models = new ArrayList<ModuleModel>();
ModuleModel core = getCoreModule();
List<Module> modules = ModuleRegistry.getModules();
models.add(core);
for (Module module : modules) models.add(new ModuleModel(module));
// Add the unloaded modules at the end?
List<Module> unloaded = ModuleRegistry.getUnloadedModules();
for (Module module : unloaded) {
ModuleModel model = new ModuleModel(module);
model.setUnloaded(true);
models.add(model);
}
return result.createResponseEntity(models);
} else {
result.addRestMessage(this.getUnauthorizedMessage());
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult in project ma-modules-public by infiniteautomation.
the class PointValueRestController method getLatestPointValuesForDataSourceAsSingleArray.
/**
* Get the latest point values a set of points return as map of xid to array of values
*
* @param xid
* @param limit
* @return
*/
@ApiOperation(value = "Get Latest Point Values for all points on a data source directly from the Runtime Manager, this makes Cached and Intra-Interval data available.", notes = "Default limit 100, time descending order, Default to return cached data. Returns as single time ordered array.")
@RequestMapping(method = RequestMethod.GET, value = "/{dataSourceXid}/latest-data-source-single-array", produces = { "application/json", "text/csv" })
public ResponseEntity<QueryArrayStream<PointValueTimeModel>> getLatestPointValuesForDataSourceAsSingleArray(HttpServletRequest request, @ApiParam(value = "Data source xid", required = true, allowMultiple = false) @PathVariable String dataSourceXid, @ApiParam(value = "Return rendered value as String", required = false, defaultValue = "false", allowMultiple = false) @RequestParam(required = false, defaultValue = "false") boolean useRendered, @ApiParam(value = "Return converted value using displayed unit", required = false, defaultValue = "false", allowMultiple = false) @RequestParam(required = false, defaultValue = "false") boolean unitConversion, @ApiParam(value = "Limit results", allowMultiple = false, defaultValue = "100") @RequestParam(value = "limit", defaultValue = "100") int limit, @ApiParam(value = "Return cached data?", allowMultiple = false, defaultValue = "true") @RequestParam(value = "useCache", defaultValue = "true") boolean useCache, @ApiParam(value = "Date Time format pattern for timestamps as strings, if not included epoch milli number is used", required = false, allowMultiple = false) @RequestParam(value = "dateTimeFormat", required = false) String dateTimeFormat, @ApiParam(value = "Time zone of output, used if formatted times are returned", required = false, allowMultiple = false) @RequestParam(value = "timezone", required = false) String timezone) {
RestProcessResult<QueryArrayStream<PointValueTimeModel>> result = new RestProcessResult<QueryArrayStream<PointValueTimeModel>>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
DataSourceVO<?> ds = DataSourceDao.instance.getByXid(dataSourceXid);
if (ds == null)
throw new NotFoundRestException();
if (dateTimeFormat != null) {
try {
DateTimeFormatter.ofPattern(dateTimeFormat);
} catch (IllegalArgumentException e) {
RestValidationResult vr = new RestValidationResult();
vr.addError("validate.invalidValue", "dateTimeFormat");
throw new ValidationFailedRestException(vr);
}
}
if (timezone != null) {
try {
ZoneId.of(timezone);
} catch (Exception e) {
RestValidationResult vr = new RestValidationResult();
vr.addError("validate.invalidValue", "timezone");
throw new ValidationFailedRestException(vr);
}
}
List<DataPointVO> points = DataPointDao.instance.getDataPointsForDataSourceStart(ds.getId());
Map<Integer, DataPointVO> pointIdMap = new HashMap<Integer, DataPointVO>(points.size());
for (DataPointVO vo : points) {
if (Permissions.hasDataPointReadPermission(user, vo))
pointIdMap.put(vo.getId(), vo);
else {
// Abort, invalid permissions
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
}
// Do we have any valid points?
if (pointIdMap.size() == 0) {
result.addRestMessage(getDoesNotExistMessage());
return result.createResponseEntity();
}
try {
IdPointValueTimeLatestPointValueFacadeStream pvtDatabaseStream = new IdPointValueTimeLatestPointValueFacadeStream(pointIdMap, useRendered, unitConversion, limit, useCache, dateTimeFormat, timezone);
return result.createResponseEntity(pvtDatabaseStream);
} catch (PermissionException e) {
LOG.error(e.getMessage(), e);
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
} else {
return result.createResponseEntity();
}
}
use of com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult in project ma-modules-public by infiniteautomation.
the class PointValueRestController method latestPointValuesForMultiplePointsAsSingleArray.
private ResponseEntity<QueryArrayStream<PointValueTimeModel>> latestPointValuesForMultiplePointsAsSingleArray(HttpServletRequest request, String[] xids, boolean useRendered, boolean unitConversion, int limit, boolean useCache, String dateTimeFormat, String timezone) {
RestProcessResult<QueryArrayStream<PointValueTimeModel>> result = new RestProcessResult<QueryArrayStream<PointValueTimeModel>>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
if (dateTimeFormat != null) {
try {
DateTimeFormatter.ofPattern(dateTimeFormat);
} catch (IllegalArgumentException e) {
RestValidationResult vr = new RestValidationResult();
vr.addError("validate.invalid", "dateTimeFormat");
throw new ValidationFailedRestException(vr);
}
}
if (timezone != null) {
try {
ZoneId.of(timezone);
} catch (Exception e) {
RestValidationResult vr = new RestValidationResult();
vr.addError("validate.invalidValue", "timezone");
throw new ValidationFailedRestException(vr);
}
}
Map<Integer, DataPointVO> pointIdMap = new HashMap<Integer, DataPointVO>(xids.length);
DataPointVO vo;
for (String xid : xids) {
vo = DataPointDao.instance.getByXid(xid);
if (vo != null) {
if (Permissions.hasDataPointReadPermission(user, vo))
pointIdMap.put(vo.getId(), vo);
else {
// Abort, invalid permissions
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
}
}
// Do we have any valid points?
if (pointIdMap.size() == 0) {
result.addRestMessage(getDoesNotExistMessage());
return result.createResponseEntity();
}
try {
IdPointValueTimeLatestPointValueFacadeStream pvtDatabaseStream = new IdPointValueTimeLatestPointValueFacadeStream(pointIdMap, useRendered, unitConversion, limit, useCache, dateTimeFormat, timezone);
return result.createResponseEntity(pvtDatabaseStream);
} catch (PermissionException e) {
LOG.error(e.getMessage(), e);
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
} else {
return result.createResponseEntity();
}
}
use of com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult in project ma-modules-public by infiniteautomation.
the class PointValueRestController method putPointValue.
/**
* Update a point value in the system
*
* @param pvt
* @param xid
* @param builder
* @return
* @throws RestValidationFailedException
*/
@ApiOperation(value = "Update an existing data point's value", notes = "Data point must exist and be enabled")
@RequestMapping(method = RequestMethod.PUT, value = "/{xid}", produces = { "application/json" }, consumes = { "application/json" })
public ResponseEntity<PointValueTimeModel> putPointValue(HttpServletRequest request, @RequestBody(required = true) PointValueTimeModel model, @PathVariable String xid, @ApiParam(value = "Return converted value using displayed unit", required = false, defaultValue = "false", allowMultiple = false) @RequestParam(required = false, defaultValue = "false") boolean unitConversion, UriComponentsBuilder builder) throws RestValidationFailedException {
RestProcessResult<PointValueTimeModel> result = new RestProcessResult<PointValueTimeModel>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
RestProcessResult<PointValueTimeModel> setResult = setPointValue(user, xid, model, unitConversion, builder);
if (setResult.getHighestStatus().value() == HttpStatus.CREATED.value())
return setResult.createResponseEntity(model);
else
return setResult.createResponseEntity();
} else {
return result.createResponseEntity();
}
}
Aggregations