Search in sources :

Example 11 with NotFoundException

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"));
    }
}
Also used : Path(java.nio.file.Path) FileStore(com.serotonin.m2m2.vo.FileStore) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) NoSuchFileException(java.nio.file.NoSuchFileException) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) TranslatableRuntimeException(com.infiniteautomation.mango.util.exception.TranslatableRuntimeException) TranslatableIllegalArgumentException(com.infiniteautomation.mango.util.exception.TranslatableIllegalArgumentException) IOException(java.io.IOException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) ValidationException(com.infiniteautomation.mango.util.exception.ValidationException) PermissionException(com.serotonin.m2m2.vo.permission.PermissionException)

Example 12 with NotFoundException

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;
}
Also used : NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder)

Example 13 with NotFoundException

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;
}
Also used : NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder)

Example 14 with NotFoundException

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));
    }
}
Also used : JsonArray(com.serotonin.json.type.JsonArray) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonException(com.serotonin.json.JsonException) AbstractPointEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO) AbstractEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractEventDetectorVO) DataPointWithEventDetectors(com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) AbstractEventHandlerVO(com.serotonin.m2m2.vo.event.AbstractEventHandlerVO)

Example 15 with NotFoundException

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());
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) PermissionException(com.serotonin.m2m2.vo.permission.PermissionException) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) WebSocketSendException(com.infiniteautomation.mango.rest.latest.websocket.WebSocketSendException) PermissionException(com.serotonin.m2m2.vo.permission.PermissionException) WebSocketSendException(com.infiniteautomation.mango.rest.latest.websocket.WebSocketSendException)

Aggregations

NotFoundException (com.infiniteautomation.mango.util.exception.NotFoundException)74 ValidationException (com.infiniteautomation.mango.util.exception.ValidationException)26 JsonException (com.serotonin.json.JsonException)20 MangoPermission (com.infiniteautomation.mango.permission.MangoPermission)18 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)18 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)15 User (com.serotonin.m2m2.vo.User)15 PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)15 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)12 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)10 DataSourceVO (com.serotonin.m2m2.vo.dataSource.DataSourceVO)9 JsonArray (com.serotonin.json.type.JsonArray)8 TranslatableIllegalArgumentException (com.infiniteautomation.mango.util.exception.TranslatableIllegalArgumentException)6 TranslatableRuntimeException (com.infiniteautomation.mango.util.exception.TranslatableRuntimeException)6 FileStore (com.serotonin.m2m2.vo.FileStore)6 AbstractEventHandlerVO (com.serotonin.m2m2.vo.event.AbstractEventHandlerVO)6 AbstractPointEventDetectorVO (com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO)6 PublisherVO (com.serotonin.m2m2.vo.publish.PublisherVO)6 ApiOperation (io.swagger.annotations.ApiOperation)6 IOException (java.io.IOException)6