use of com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException in project ma-modules-public by infiniteautomation.
the class PointValueRestController method buildMap.
/**
* Build and validate the map of Requested Data Points
* @param user
* @param xids
* @return
*/
protected Map<Integer, DataPointVO> buildMap(User user, String[] xids, RollupEnum rollup) {
// Build the map, check permissions
Map<Integer, DataPointVO> voMap = new HashMap<Integer, DataPointVO>();
for (String xid : xids) {
DataPointVO vo = DataPointDao.instance.getByXid(xid);
if (vo == null) {
throw new NotFoundRestException();
} else {
if (!Permissions.hasDataPointReadPermission(user, vo))
throw new AccessDeniedException();
}
// TODO Add support for NONE Default Rollup
if (rollup == RollupEnum.POINT_DEFAULT && vo.getRollup() == RollupEnum.NONE.getId())
throw new BadRequestException(new TranslatableMessage("common.default", "Default point rollup of NONE is not yet supported for point with xid: " + xid));
;
// Validate the rollup
switch(vo.getPointLocator().getDataTypeId()) {
case DataTypes.ALPHANUMERIC:
case DataTypes.BINARY:
case DataTypes.IMAGE:
case DataTypes.MULTISTATE:
if (rollup.nonNumericSupport() == false)
throw new BadRequestException(new TranslatableMessage("rest.validate.rollup.incompatible", rollup.toString(), xid));
break;
case DataTypes.NUMERIC:
break;
}
voMap.put(vo.getId(), vo);
}
// Do we have any points
if (voMap.isEmpty())
throw new NotFoundRestException();
return voMap;
}
use of com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException in project ma-modules-public by infiniteautomation.
the class PointValueRestController method deletePointValues.
@ApiOperation(value = "Delete point values >= from and < to", notes = "The user must have set permission to the data point. If date is not supplied it defaults to now.")
@RequestMapping(method = RequestMethod.DELETE, value = "/{xid}", produces = { "application/json", "text/csv", "application/sero-json" })
public ResponseEntity<Long> deletePointValues(@ApiParam(value = "Point xids", required = true) @PathVariable String xid, @ApiParam(value = "From time", required = false, allowMultiple = false) @RequestParam(value = "from", required = false) @DateTimeFormat(iso = ISO.DATE_TIME) ZonedDateTime from, @ApiParam(value = "To time", required = false, allowMultiple = false) @RequestParam(value = "to", required = false) @DateTimeFormat(iso = ISO.DATE_TIME) ZonedDateTime to, @ApiParam(value = "Time zone", required = false, allowMultiple = false) @RequestParam(value = "timezone", required = false) String timezone, @AuthenticationPrincipal User user, UriComponentsBuilder builder, HttpServletRequest request) {
DataPointVO vo = DataPointDao.instance.getByXid(xid);
if (vo == null) {
throw new NotFoundRestException();
} else {
if (!Permissions.hasDataPointSetPermission(user, vo))
throw new AccessDeniedException();
}
ZoneId zoneId;
if (timezone == null) {
if (from != null) {
zoneId = from.getZone();
} else if (to != null)
zoneId = to.getZone();
else
zoneId = TimeZone.getDefault().toZoneId();
} else {
zoneId = ZoneId.of(timezone);
}
// Set the timezone on the from and to dates
long current = Common.timer.currentTimeMillis();
if (from != null)
from = from.withZoneSameInstant(zoneId);
else
from = ZonedDateTime.ofInstant(Instant.ofEpochMilli(current), zoneId);
if (to != null)
to = to.withZoneSameInstant(zoneId);
else
to = ZonedDateTime.ofInstant(Instant.ofEpochMilli(current), zoneId);
return ResponseEntity.ok(Common.runtimeManager.purgeDataPointValuesBetween(vo.getId(), from.toInstant().toEpochMilli(), to.toInstant().toEpochMilli()));
}
use of com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException in project ma-modules-public by infiniteautomation.
the class AuthenticationTokenRestController method createTokenForUser.
@ApiOperation(value = "Revoke all tokens for user", notes = "Revokes all tokens for a given user")
@RequestMapping(path = "/revoke/{username}", method = RequestMethod.POST)
@PreAuthorize("isAdmin() and isPasswordAuthenticated()")
public ResponseEntity<Void> createTokenForUser(@PathVariable String username, HttpServletRequest request) {
User user = UserDao.instance.getUser(username);
if (user == null) {
throw new NotFoundRestException();
}
tokenAuthService.revokeTokens(user);
sessionRegistry.userUpdated(request, user);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
use of com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException in project ma-modules-public by infiniteautomation.
the class DataPointTagsRestController method addTagsForDataPoint.
@ApiOperation(value = "Merge data point tags by data point XID", notes = "User must have edit permission for the data point's data source." + "Adds a tag or replaces the tag value for each tag key. Any other existing tags will be kept.")
@RequestMapping(method = RequestMethod.PUT, value = "/point/{xid}")
public Map<String, String> addTagsForDataPoint(@ApiParam(value = "Data point XID", required = true, allowMultiple = false) @PathVariable String xid, @RequestBody Map<String, String> tags, @AuthenticationPrincipal User user) {
return DataPointTagsDao.instance.doInTransaction(txStatus -> {
DataPointVO dataPoint = DataPointDao.instance.getByXid(xid);
if (dataPoint == null) {
throw new NotFoundRestException();
}
Permissions.ensureDataSourcePermission(user, dataPoint.getDataSourceId());
Map<String, String> existingTags = DataPointTagsDao.instance.getTagsForDataPointId(dataPoint.getId());
Map<String, String> newTags = new HashMap<>(existingTags);
for (Entry<String, String> entry : tags.entrySet()) {
String tagKey = entry.getKey();
String tagVal = entry.getValue();
if (tagVal == null) {
newTags.remove(tagKey);
} else {
newTags.put(tagKey, tagVal);
}
}
dataPoint.setTags(newTags);
DataPointTagsDao.instance.saveDataPointTags(dataPoint);
// we set the tags on the data point then retrieve them so that the device and name tags are removed
return dataPoint.getTags();
});
}
use of com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException in project ma-modules-public by infiniteautomation.
the class VirtualSerialPortRestV2Controller method update.
@PreAuthorize("isAdmin()")
@ApiOperation(value = "Update virtual serial port", notes = "")
@RequestMapping(method = RequestMethod.PUT, consumes = { "application/json", "application/sero-json" }, produces = { "application/json", "text/csv", "application/sero-json" }, value = { "/{xid}" })
public ResponseEntity<VirtualSerialPortConfig> update(@ApiParam(value = "Valid virtual serial port id", required = true, allowMultiple = false) @PathVariable String xid, @ApiParam(value = "Virtual Serial Port", required = true) @RequestBody(required = true) VirtualSerialPortConfig model, @AuthenticationPrincipal User user, UriComponentsBuilder builder, HttpServletRequest request) {
// Check to see if it already exists
VirtualSerialPortConfig existing = VirtualSerialPortConfigDao.instance.getByXid(model.getXid());
if (existing == null)
throw new NotFoundRestException();
// Validate
model.ensureValid();
// Save it
VirtualSerialPortConfigDao.instance.save(model);
// Put a link to the updated data in the header
URI location = builder.path("/v2/virtual-serial-ports/{xid}").buildAndExpand(model.getXid()).toUri();
return getResourceUpdated(model, location);
}
Aggregations