Search in sources :

Example 36 with NotFoundException

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

the class ModulesRestController method markForDeletion.

@ApiOperation(value = "Set Marked For Deletion state of Module", notes = "Marking a module for deletion will un-install it upon restart")
@RequestMapping(method = RequestMethod.PUT, value = "/deletion-state/{moduleName}")
public ResponseEntity<ModuleModel> markForDeletion(@PathVariable String moduleName, @ApiParam(value = "Deletion State", required = true, defaultValue = "false", allowMultiple = false) @RequestParam(name = "delete", required = true) boolean delete, @AuthenticationPrincipal PermissionHolder user, HttpServletRequest request) {
    Module module = ModuleRegistry.getModule(moduleName);
    if (module == null)
        throw new NotFoundException();
    module.setMarkedForDeletion(delete);
    if (module.isMarkedForDeletion() != delete)
        throw new ModuleRestException(HttpStatus.BAD_REQUEST, new TranslatableMessage("rest.modules.error.dependencyFailure"));
    return ResponseEntity.ok(new ModuleModel(module));
}
Also used : ModuleRestException(com.infiniteautomation.mango.rest.latest.exception.ModuleRestException) FileNotFoundException(java.io.FileNotFoundException) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) Module(com.serotonin.m2m2.module.Module) CoreModule(com.serotonin.m2m2.module.ModuleRegistry.CoreModule) InvalidModule(com.infiniteautomation.mango.rest.latest.model.modules.UpgradeUploadResult.InvalidModule) ModuleModel(com.infiniteautomation.mango.rest.latest.model.modules.ModuleModel) CoreModuleModel(com.infiniteautomation.mango.rest.latest.model.modules.CoreModuleModel) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 37 with NotFoundException

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

the class MaintenanceEventEmportDefinition method doImport.

@Override
public void doImport(JsonValue jsonValue, ImportContext importContext, PermissionHolder importer) throws JsonException {
    MaintenanceEventsService service = Common.getBean(MaintenanceEventsService.class);
    JsonObject maintenanceEvent = jsonValue.toJsonObject();
    String xid = maintenanceEvent.getString("xid");
    if (StringUtils.isBlank(xid))
        xid = service.generateUniqueXid();
    MaintenanceEventVO vo = null;
    if (StringUtils.isBlank(xid)) {
        xid = service.generateUniqueXid();
    } else {
        try {
            vo = service.get(xid);
        } catch (NotFoundException e) {
        }
    }
    if (vo == null) {
        vo = new MaintenanceEventVO();
        vo.setXid(xid);
    }
    try {
        importContext.getReader().readInto(vo, maintenanceEvent);
        // Ensure we have a default permission since null is valid in Mango 3.x
        if (vo.getTogglePermission() == null) {
            vo.setTogglePermission(new MangoPermission());
        }
        boolean isnew = vo.getId() == Common.NEW_ID;
        if (isnew) {
            service.insert(vo);
        } else {
            service.update(vo.getId(), vo);
        }
        importContext.addSuccessMessage(isnew, "emport.maintenanceEvent.prefix", xid);
    } catch (ValidationException e) {
        importContext.copyValidationMessages(e.getValidationResult(), "emport.maintenanceEvent.prefix", xid);
    } catch (TranslatableJsonException e) {
        importContext.getResult().addGenericMessage("emport.maintenanceEvent.prefix", xid, e.getMsg());
    } catch (JsonException e) {
        importContext.getResult().addGenericMessage("emport.maintenanceEvent.prefix", xid, importContext.getJsonExceptionMessage(e));
    }
}
Also used : MaintenanceEventsService(com.infiniteautomation.mango.spring.service.maintenanceEvents.MaintenanceEventsService) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonException(com.serotonin.json.JsonException) ValidationException(com.infiniteautomation.mango.util.exception.ValidationException) JsonObject(com.serotonin.json.type.JsonObject) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission)

Example 38 with NotFoundException

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

the class MaintenanceEventType method getEventPermission.

@Override
public MangoPermission getEventPermission(Map<String, Object> context, PermissionService service) {
    DataSourceService dataSourceService = Common.getBean(DataSourceService.class);
    DataPointService dataPointService = Common.getBean(DataPointService.class);
    MaintenanceEventsService maintenanceEventService = Common.getBean(MaintenanceEventsService.class);
    Set<Role> allRequired = new HashSet<>();
    try {
        MaintenanceEventVO vo = maintenanceEventService.get(maintenanceId);
        try {
            for (int dsId : vo.getDataSources()) {
                MangoPermission read = dataSourceService.getReadPermission(dsId);
                read.getRoles().forEach(allRequired::addAll);
            }
        } catch (NotFoundException e) {
        // Ignore this item
        }
        try {
            for (int dpId : vo.getDataPoints()) {
                MangoPermission read = dataPointService.getReadPermission(dpId);
                read.getRoles().forEach(allRequired::addAll);
            }
        } catch (NotFoundException e) {
        // Ignore this item
        }
    } catch (NotFoundException e) {
    // Ignore all of it
    }
    if (allRequired.size() == 0) {
        return MangoPermission.superadminOnly();
    } else {
        return MangoPermission.requireAllRoles(allRequired);
    }
}
Also used : DataPointService(com.infiniteautomation.mango.spring.service.DataPointService) MaintenanceEventsService(com.infiniteautomation.mango.spring.service.maintenanceEvents.MaintenanceEventsService) Role(com.serotonin.m2m2.vo.role.Role) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission) DataSourceService(com.infiniteautomation.mango.spring.service.DataSourceService) HashSet(java.util.HashSet)

Example 39 with NotFoundException

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

the class MaintenanceEventsService method getEventRT.

public MaintenanceEventRT getEventRT(String xid) throws NotFoundException, PermissionException, TranslatableIllegalStateException {
    PermissionHolder user = Common.getUser();
    MaintenanceEventVO existing = dao.getByXid(xid);
    if (existing == null)
        throw new NotFoundException();
    ensureTogglePermission(existing, user);
    MaintenanceEventRT rt = RTMDefinition.instance.getRunningMaintenanceEvent(existing.getId());
    if (rt == null)
        throw new TranslatableIllegalStateException(new TranslatableMessage("maintenanceEvents.toggle.disabled"));
    return rt;
}
Also used : MaintenanceEventVO(com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) MaintenanceEventRT(com.serotonin.m2m2.maintenanceEvents.MaintenanceEventRT) TranslatableIllegalStateException(com.infiniteautomation.mango.util.exception.TranslatableIllegalStateException) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder)

Example 40 with NotFoundException

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

the class SystemMetricsRestController method get.

@ApiOperation(value = "Get the current value for one System Metric by its ID", notes = "")
@RequestMapping(method = RequestMethod.GET, value = "/{id}")
public ValueMonitorModel get(@ApiParam(value = "Valid Monitor id", required = true, allowMultiple = false) @PathVariable String id, @AuthenticationPrincipal PermissionHolder user) {
    MangoPermission permission = definition.getPermission();
    service.ensurePermission(user, permission);
    List<ValueMonitor<?>> values = Common.MONITORED_VALUES.getMonitors();
    for (ValueMonitor<?> v : values) {
        if (v.getId().equals(id)) {
            return new ValueMonitorModel(v);
        }
    }
    throw new NotFoundException();
}
Also used : ValueMonitorModel(com.infiniteautomation.mango.rest.latest.model.ValueMonitorModel) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission) ValueMonitor(com.infiniteautomation.mango.monitor.ValueMonitor) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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