Search in sources :

Example 26 with NotFoundException

use of com.infiniteautomation.mango.util.exception.NotFoundException in project ma-core-public by infiniteautomation.

the class DataSourceService method getDefinition.

/**
 * Get a definition for a data source
 */
public DataSourceDefinition<DataSourceVO> getDefinition(String dataSourceType, PermissionHolder user) throws NotFoundException, PermissionException {
    permissionService.ensurePermission(user, createPermission.getPermission());
    DataSourceDefinition<DataSourceVO> def = ModuleRegistry.getDataSourceDefinition(dataSourceType);
    if (def == null)
        throw new NotFoundException();
    return def;
}
Also used : DataSourceVO(com.serotonin.m2m2.vo.dataSource.DataSourceVO) PollingDataSourceVO(com.serotonin.m2m2.vo.dataSource.PollingDataSourceVO) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException)

Example 27 with NotFoundException

use of com.infiniteautomation.mango.util.exception.NotFoundException in project ma-core-public by infiniteautomation.

the class TokenAuthenticationService method verifyClaims.

@Override
protected User verifyClaims(Jws<Claims> token) {
    Claims claims = token.getBody();
    String username = claims.getSubject();
    if (username == null) {
        throw new NotFoundException();
    }
    User user = this.runAs.runAs(runAs.systemSuperadmin(), () -> this.usersService.get(username));
    Integer userId = user.getId();
    this.verifyClaim(token, USER_ID_CLAIM, userId);
    Integer tokenVersion = user.getTokenVersion();
    this.verifyClaim(token, USER_TOKEN_VERSION_CLAIM, tokenVersion);
    return user;
}
Also used : Claims(io.jsonwebtoken.Claims) User(com.serotonin.m2m2.vo.User) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException)

Example 28 with NotFoundException

use of com.infiniteautomation.mango.util.exception.NotFoundException in project ma-core-public by infiniteautomation.

the class DataSourceService method getReadPermission.

/**
 * Get the read permission for this data source
 */
public MangoPermission getReadPermission(int dataPointId) throws NotFoundException, PermissionException {
    PermissionHolder user = Common.getUser();
    Integer permissionId = dao.getReadPermissionId(dataPointId);
    if (permissionId == null) {
        throw new NotFoundException();
    }
    MangoPermission read = permissionService.get(permissionId);
    permissionService.ensurePermission(user, read);
    return read;
}
Also used : NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission)

Example 29 with NotFoundException

use of com.infiniteautomation.mango.util.exception.NotFoundException in project ma-core-public by infiniteautomation.

the class DataSourceImporter method importImpl.

@Override
protected void importImpl() {
    String xid = json.getString("xid");
    DataSourceVO vo = null;
    if (StringUtils.isBlank(xid)) {
        xid = service.generateUniqueXid();
    } else {
        try {
            vo = service.get(xid);
        } catch (NotFoundException e) {
        }
    }
    if (vo == null) {
        String typeStr = json.getString("type");
        if (StringUtils.isBlank(typeStr))
            addFailureMessage("emport.dataSource.missingType", xid, ModuleRegistry.getDataSourceDefinitionTypes());
        else {
            DataSourceDefinition<?> def = ModuleRegistry.getDataSourceDefinition(typeStr);
            if (def == null)
                addFailureMessage("emport.dataSource.invalidType", xid, typeStr, ModuleRegistry.getDataSourceDefinitionTypes());
            else {
                vo = def.baseCreateDataSourceVO();
                vo.setXid(xid);
            }
        }
    }
    if (vo != null) {
        try {
            // The VO was found or successfully created. Finish reading it in.
            ctx.getReader().readInto(vo, json);
            // Ensure we have a default permission since null is valid in Mango 3.x
            if (vo.getReadPermission() == null) {
                vo.setReadPermission(new MangoPermission());
            }
            if (vo.getEditPermission() == null) {
                vo.setEditPermission(new MangoPermission());
            }
            boolean isnew = vo.isNew();
            if (Common.runtimeManager.getLifecycleState() == ILifecycleState.RUNNING) {
                if (isnew) {
                    service.insert(vo);
                } else {
                    service.update(vo.getId(), vo);
                }
                addSuccessMessage(isnew, "emport.dataSource.prefix", xid);
            } else {
                addFailureMessage("emport.dataSource.runtimeManagerNotRunning", xid);
            }
        } catch (ValidationException e) {
            setValidationMessages(e.getValidationResult(), "emport.dataSource.prefix", xid);
        } catch (TranslatableJsonException e) {
            addFailureMessage("emport.dataSource.prefix", xid, e.getMsg());
        } catch (JsonException e) {
            addFailureMessage("emport.dataSource.prefix", xid, getJsonExceptionMessage(e));
        }
    }
}
Also used : DataSourceVO(com.serotonin.m2m2.vo.dataSource.DataSourceVO) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonException(com.serotonin.json.JsonException) ValidationException(com.infiniteautomation.mango.util.exception.ValidationException) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission)

Example 30 with NotFoundException

use of com.infiniteautomation.mango.util.exception.NotFoundException in project ma-core-public by infiniteautomation.

the class EventHandlerImporter method importImpl.

@Override
protected void importImpl() {
    AbstractEventHandlerVO handler = null;
    String xid = json.getString("xid");
    if (StringUtils.isBlank(xid)) {
        xid = service.generateUniqueXid();
    } else {
        try {
            handler = service.get(xid);
        } catch (NotFoundException e) {
        // Nothing, done below
        }
    }
    if (handler == null) {
        String typeStr = json.getString("handlerType");
        if (StringUtils.isBlank(typeStr))
            addFailureMessage("emport.eventHandler.missingType", xid, ModuleRegistry.getEventHandlerDefinitionTypes());
        else {
            EventHandlerDefinition<?> def = ModuleRegistry.getEventHandlerDefinition(typeStr);
            if (def == null)
                addFailureMessage("emport.eventHandler.invalidType", xid, typeStr, ModuleRegistry.getEventHandlerDefinitionTypes());
            else {
                handler = def.baseCreateEventHandlerVO();
                handler.setXid(xid);
            }
        }
    }
    JsonObject et = json.getJsonObject("eventType");
    JsonArray ets = json.getJsonArray("eventTypes");
    if (handler != null) {
        try {
            ctx.getReader().readInto(handler, json);
            Set<EventTypeMatcher> eventTypes = new HashSet<>(handler.getEventTypes());
            // Find the event type.
            if (et != null) {
                eventTypes.add(new EventTypeMatcher(ctx.getReader().read(EventType.class, et)));
            } else if (ets != null) {
                for (JsonValue jsonValue : ets) {
                    eventTypes.add(new EventTypeMatcher(ctx.getReader().read(EventType.class, jsonValue)));
                }
            }
            handler.setEventTypes(new ArrayList<>(eventTypes));
            boolean isnew = handler.getId() == Common.NEW_ID;
            if (isnew) {
                service.insert(handler);
                addSuccessMessage(true, "emport.eventHandler.prefix", xid);
            } else {
                service.update(handler.getId(), handler);
                addSuccessMessage(false, "emport.eventHandler.prefix", xid);
            }
        } catch (ValidationException e) {
            setValidationMessages(e.getValidationResult(), "emport.eventHandler.prefix", xid);
        } catch (TranslatableJsonException e) {
            addFailureMessage("emport.eventHandler.prefix", xid, e.getMsg());
        } catch (JsonException e) {
            addFailureMessage("emport.eventHandler.prefix", xid, getJsonExceptionMessage(e));
        }
    }
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonException(com.serotonin.json.JsonException) EventTypeMatcher(com.serotonin.m2m2.rt.event.type.EventTypeMatcher) ValidationException(com.infiniteautomation.mango.util.exception.ValidationException) EventType(com.serotonin.m2m2.rt.event.type.EventType) JsonValue(com.serotonin.json.type.JsonValue) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) JsonObject(com.serotonin.json.type.JsonObject) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) AbstractEventHandlerVO(com.serotonin.m2m2.vo.event.AbstractEventHandlerVO) JsonArray(com.serotonin.json.type.JsonArray) HashSet(java.util.HashSet)

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