use of com.serotonin.m2m2.i18n.TranslatableMessage in project ma-modules-public by infiniteautomation.
the class EventHandlerRestController method update.
@ApiOperation(value = "Update an existing event handler", notes = "")
@RequestMapping(method = RequestMethod.PUT, consumes = { "application/json" }, produces = { "application/json" }, value = "/{xid}")
public ResponseEntity<AbstractEventHandlerModel<?>> update(@PathVariable String xid, @ApiParam(value = "Updated model", required = true) @RequestBody(required = true) AbstractEventHandlerModel<?> model, UriComponentsBuilder builder, HttpServletRequest request) {
RestProcessResult<AbstractEventHandlerModel<?>> result = new RestProcessResult<AbstractEventHandlerModel<?>>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
AbstractEventHandlerVO<?> vo = model.getData();
AbstractEventHandlerVO<?> existing = EventHandlerDao.instance.getByXid(xid);
if (existing == null) {
result.addRestMessage(getDoesNotExistMessage());
return result.createResponseEntity();
}
// Check Event Type Permission
if (!Permissions.hasAdmin(user)) {
result.addRestMessage(HttpStatus.UNAUTHORIZED, new TranslatableMessage("permissions.accessDenied", user.getUsername(), SuperadminPermissionDefinition.GROUP_NAME));
return result.createResponseEntity();
}
// Ensure we keep the same ID
vo.setId(existing.getId());
if (!model.validate()) {
result.addRestMessage(this.getValidationFailedError());
return result.createResponseEntity(model);
} else {
String initiatorId = request.getHeader("initiatorId");
EventHandlerDao.instance.save(vo, initiatorId);
}
// Put a link to the updated data in the header?
URI location = builder.path("/v1/event-handlers/{xid}").buildAndExpand(vo.getXid()).toUri();
result.addRestMessage(getResourceUpdatedMessage(location));
return result.createResponseEntity(model);
}
// Not logged in
return result.createResponseEntity();
}
use of com.serotonin.m2m2.i18n.TranslatableMessage in project ma-modules-public by infiniteautomation.
the class JsonDataRestController method replaceNode.
JsonNode replaceNode(final JsonNode existingData, final String[] dataPath, final JsonNode newData) {
if (dataPath.length == 0) {
return newData;
}
String[] parentPath = Arrays.copyOfRange(dataPath, 0, dataPath.length - 1);
String fieldName = dataPath[dataPath.length - 1];
JsonNode parent = getNode(existingData, parentPath);
if (parent.isObject()) {
ObjectNode parentObject = (ObjectNode) parent;
parentObject.set(fieldName, newData);
} else if (parent.isArray()) {
ArrayNode parentArray = (ArrayNode) parent;
int index = toArrayIndex(fieldName);
parentArray.set(index, newData);
} else {
throw new BadRequestException(new TranslatableMessage("rest.error.cantSetFieldOfNodeType", parent.getNodeType()));
}
return existingData;
}
use of com.serotonin.m2m2.i18n.TranslatableMessage 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.serotonin.m2m2.i18n.TranslatableMessage in project ma-modules-public by infiniteautomation.
the class JsonDataRestController method deleteNode.
boolean deleteNode(final JsonNode existingData, final String[] dataPath) {
if (dataPath.length == 0)
throw new IllegalArgumentException();
String[] parentPath = Arrays.copyOfRange(dataPath, 0, dataPath.length - 1);
String fieldName = dataPath[dataPath.length - 1];
JsonNode parent = getNode(existingData, parentPath);
JsonNode deletedValue = null;
if (parent.isObject()) {
ObjectNode parentObject = (ObjectNode) parent;
deletedValue = parentObject.remove(fieldName);
} else if (parent.isArray()) {
ArrayNode parentArray = (ArrayNode) parent;
int index = toArrayIndex(fieldName);
deletedValue = parentArray.remove(index);
} else {
throw new BadRequestException(new TranslatableMessage("rest.error.cantDeleteFieldOfNodeType", parent.getNodeType()));
}
return deletedValue != null;
}
use of com.serotonin.m2m2.i18n.TranslatableMessage in project ma-modules-public by infiniteautomation.
the class ServerRestController method getSystemInfo.
@ApiOperation(value = "System Info", notes = "Provides disk use, db sizes and point, event counts", response = Map.class)
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" }, value = "/system-info")
public ResponseEntity<SystemInfoModel> getSystemInfo(HttpServletRequest request) {
RestProcessResult<SystemInfoModel> result = new RestProcessResult<SystemInfoModel>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
if (user.isAdmin()) {
SystemInfoModel model = new SystemInfoModel();
// Database size
model.setSqlDbSizeBytes(Common.databaseProxy.getDatabaseSizeInBytes());
// Do we have any NoSQL Data
if (Common.databaseProxy.getNoSQLProxy() != null) {
String pointValueStoreName = Common.envProps.getString("db.nosql.pointValueStoreName", "mangoTSDB");
model.setNoSqlDbSizeBytes(Common.databaseProxy.getNoSQLProxy().getDatabaseSizeInBytes(pointValueStoreName));
}
// Filedata data
DirectoryInfo fileDatainfo = DirectoryUtils.getSize(new File(Common.getFiledataPath()));
model.setFileDataSizeBytes(fileDatainfo.getSize());
// Point history counts.
model.setTopPoints(DataPointDao.instance.getTopPointHistoryCounts());
model.setEventCount(EventDao.instance.getEventCount());
// Disk Info
FileSystem fs = FileSystems.getDefault();
List<DiskInfoModel> disks = new ArrayList<DiskInfoModel>();
model.setDisks(disks);
for (Path root : fs.getRootDirectories()) {
try {
FileStore store = Files.getFileStore(root);
DiskInfoModel disk = new DiskInfoModel();
disk.setName(root.getRoot().toString());
disk.setTotalSpaceBytes(store.getTotalSpace());
disk.setUsableSpaceBytes(store.getUsableSpace());
disks.add(disk);
} catch (IOException e) {
}
}
// CPU Info
OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
model.setLoadAverage(osBean.getSystemLoadAverage());
// OS Info
model.setArchitecture(osBean.getArch());
model.setOperatingSystem(osBean.getName());
model.setOsVersion(osBean.getVersion());
return result.createResponseEntity(model);
} else {
result.addRestMessage(HttpStatus.UNAUTHORIZED, new TranslatableMessage("common.default", "User not admin"));
}
}
return result.createResponseEntity();
}
Aggregations