use of com.infiniteautomation.mango.util.exception.NotFoundException in project ma-core-public by MangoAutomation.
the class FileStoreService method moveFileOrFolder.
public FileStorePath moveFileOrFolder(String xid, String src, String dst) {
FileStore fileStore = getWithoutPermissionCheck(xid);
ensureEditPermission(Common.getUser(), fileStore);
FileStorePath srcPath = getPathWithinFileStore(fileStore, src);
if (!Files.exists(srcPath.absolutePath)) {
throw new NotFoundException();
}
FileStorePath dstPath = srcPath.getParent().resolve(Paths.get(dst));
if (Files.isDirectory(dstPath.absolutePath)) {
Path pathWithFileName = dstPath.absolutePath.resolve(srcPath.absolutePath.getFileName());
dstPath = new FileStorePath(fileStore, pathWithFileName);
}
try {
Files.move(srcPath.absolutePath, dstPath.absolutePath);
return dstPath;
} catch (FileAlreadyExistsException e) {
throw new FileStoreException(new TranslatableMessage("filestore.fileExists", dstPath.standardizedPath()));
} catch (Exception e) {
throw new FileStoreException(new TranslatableMessage("filestore.errorMovingFile"));
}
}
use of com.infiniteautomation.mango.util.exception.NotFoundException in project ma-core-public by MangoAutomation.
the class AbstractBasicVOService method get.
/**
*/
public T get(int id) throws NotFoundException, PermissionException {
T vo = dao.get(id);
if (vo == null)
throw new NotFoundException();
PermissionHolder user = Common.getUser();
ensureReadPermission(user, vo);
return vo;
}
use of com.infiniteautomation.mango.util.exception.NotFoundException in project ma-core-public by MangoAutomation.
the class AbstractVOService method get.
/**
*/
public T get(String xid) throws NotFoundException, PermissionException {
T vo = dao.getByXid(xid);
if (vo == null)
throw new NotFoundException();
PermissionHolder user = Common.getUser();
ensureReadPermission(user, vo);
return vo;
}
use of com.infiniteautomation.mango.util.exception.NotFoundException in project ma-core-public by MangoAutomation.
the class EventDetectorImporter method importImpl.
@Override
protected void importImpl() {
String dataPointXid = json.getString("dataPointXid");
DataPointWithEventDetectors dp;
// Everyone is in the same thread so no synchronization on dataPointMap required.
if (dataPointMap.containsKey(dataPointXid))
dp = dataPointMap.get(dataPointXid);
else {
try {
dp = dataPointService.getWithEventDetectors(dataPointXid);
dataPointMap.put(dataPointXid, dp);
} catch (NotFoundException e) {
addFailureMessage("emport.error.missingPoint", dataPointXid);
return;
}
}
String typeStr = json.getString("type");
if (typeStr == null)
addFailureMessage("emport.error.ped.missingAttr", "type");
PointEventDetectorDefinition<?> def = ModuleRegistry.getEventDetectorDefinition(typeStr);
if (def == null) {
addFailureMessage("emport.error.ped.invalid", "type", typeStr, ModuleRegistry.getEventDetectorDefinitionTypes());
return;
}
String xid = json.getString("xid");
AbstractEventDetectorVO importing;
importing = EventDetectorDao.getInstance().getByXid(xid);
if (importing == null) {
importing = def.baseCreateEventDetectorVO(dp.getDataPoint());
importing.setDefinition(def);
// Create a new one
importing.setId(Common.NEW_ID);
importing.setXid(xid);
}
JsonArray handlerXids = json.getJsonArray("handlers");
if (handlerXids != null)
for (int k = 0; k < handlerXids.size(); k += 1) {
AbstractEventHandlerVO eh = EventHandlerDao.getInstance().getByXid(handlerXids.getString(k));
if (eh == null) {
addFailureMessage("emport.eventHandler.missing", handlerXids.getString(k));
return;
} else {
importing.addAddedEventHandler(eh);
}
}
AbstractPointEventDetectorVO dped = (AbstractPointEventDetectorVO) importing;
dp.addOrReplaceDetector(dped);
try {
ctx.getReader().readInto(importing, json);
} catch (TranslatableJsonException e) {
addFailureMessage("emport.eventDetector.prefix", xid, e.getMsg());
} catch (JsonException e) {
addFailureMessage("emport.eventDetector.prefix", xid, getJsonExceptionMessage(e));
}
}
use of com.infiniteautomation.mango.util.exception.NotFoundException in project ma-modules-public by infiniteautomation.
the class PointValueWebSocketHandler method handleTextMessage.
@Override
public void handleTextMessage(WebSocketSession session, TextMessage message) {
try {
PermissionHolder user = getUser(session);
PointValueRegistrationModel model = this.jacksonMapper.readValue(message.getPayload(), PointValueRegistrationModel.class);
DataPointVO vo;
try {
// This will check for not found and permissions
vo = datapointService.get(model.getDataPointXid());
} catch (NotFoundException e) {
// send not found message back
this.sendErrorMessage(session, MangoWebSocketErrorType.SERVER_ERROR, new TranslatableMessage("rest.error.pointNotFound", model.getDataPointXid()));
return;
} catch (PermissionException e) {
// Send permission denied message here
this.sendErrorMessage(session, MangoWebSocketErrorType.PERMISSION_DENIED, new TranslatableMessage("permission.exception.readDataPoint", user.getPermissionHolderName()));
return;
}
Set<PointValueEventType> eventsTypes = model.getEventTypes();
int dataPointId = vo.getId();
synchronized (pointIdToListenerMap) {
if (this.connectionClosed) {
return;
}
PointValueWebSocketListener publisher = pointIdToListenerMap.get(dataPointId);
if (publisher != null) {
if (eventsTypes.isEmpty()) {
publisher.terminate();
pointIdToListenerMap.remove(dataPointId);
} else {
publisher.setEventTypes(eventsTypes);
}
} else if (!eventsTypes.isEmpty()) {
publisher = new PointValueWebSocketListener(vo, eventsTypes);
publisher.initialize();
// Immediately send the most recent Point Value and the status of the data point
publisher.sendPointStatus();
pointIdToListenerMap.put(dataPointId, publisher);
}
}
} catch (WebSocketSendException e) {
log.warn("Error sending websocket message", e);
} catch (Exception e) {
try {
this.sendErrorMessage(session, MangoWebSocketErrorType.SERVER_ERROR, new TranslatableMessage("rest.error.serverError", e.getMessage()));
} catch (Exception e1) {
log.error("An error occurred", e);
}
}
if (log.isDebugEnabled()) {
log.debug(message.getPayload());
}
}
Aggregations