Search in sources :

Example 51 with NotFoundException

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

the class FileStoreService method deleteFileOrFolder.

public FileStorePath deleteFileOrFolder(String xid, String toDelete, boolean recursive) {
    FileStore fileStore = getWithoutPermissionCheck(xid);
    ensureEditPermission(Common.getUser(), fileStore);
    FileStorePath toDeletePath = getPathWithinFileStore(fileStore, toDelete);
    if (toDeletePath.absolutePath.equals(toDeletePath.getFileStoreRoot())) {
        throw new FileStoreException(new TranslatableMessage("filestore.deleteRootNotPermitted"));
    }
    if (!Files.exists(toDeletePath.absolutePath)) {
        throw new NotFoundException();
    }
    try {
        if (Files.isDirectory(toDeletePath.absolutePath) && recursive) {
            FileUtils.deleteDirectory(toDeletePath.absolutePath.toFile());
        } else {
            Files.delete(toDeletePath.absolutePath);
        }
        return toDeletePath;
    } catch (NoSuchFileException e) {
        throw new NotFoundException();
    } catch (Exception e) {
        throw new FileStoreException(new TranslatableMessage("filestore.errorDeletingFile"));
    }
}
Also used : FileStore(com.serotonin.m2m2.vo.FileStore) NoSuchFileException(java.nio.file.NoSuchFileException) 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 52 with NotFoundException

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

the class SystemPermissionService method update.

/**
 */
public void update(MangoPermission permission, PermissionDefinition def) throws ValidationException {
    Objects.requireNonNull(def, "Permission definition cannot be null");
    permissionService.ensureAdminRole(Common.getUser());
    ProcessResult validation = new ProcessResult();
    if (permission == null) {
        validation.addContextualMessage("permission", "validate.required");
        throw new ValidationException(validation);
    }
    permission.getRoles().stream().flatMap(Collection::stream).forEach(role -> {
        try {
            roleService.get(role.getXid());
        } catch (NotFoundException e) {
            validation.addGenericMessage("validate.role.notFound", role.getXid());
        }
    });
    if (validation.getHasMessages()) {
        throw new ValidationException(validation);
    }
    // Execute in transaction as def.setPermission may make database calls
    dao.doInTransaction(tx -> {
        dao.update(def.getPermissionTypeName(), def.getPermission(), permission);
        def.setPermission(permission);
    });
    this.eventPublisher.publishEvent(new SystemPermissionUpdated(def));
}
Also used : ValidationException(com.infiniteautomation.mango.util.exception.ValidationException) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException)

Example 53 with NotFoundException

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

the class UsersService method get.

/*
     * Nice little hack since Users don't have an XID.
     */
@Override
public User get(String username) throws NotFoundException, PermissionException {
    Assert.notNull(username, "Username required");
    if (this.userByUsername != null) {
        String usernameLower = username.toLowerCase(Locale.ROOT);
        User vo = userByUsername.get(usernameLower, dao::getByXid);
        if (vo == null) {
            throw new NotFoundException();
        }
        PermissionHolder currentUser = Common.getUser();
        ensureReadPermission(currentUser, vo);
        return vo;
    } else {
        return super.get(username);
    }
}
Also used : User(com.serotonin.m2m2.vo.User) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder)

Example 54 with NotFoundException

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

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 55 with NotFoundException

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

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)

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