Search in sources :

Example 91 with PermissionHolder

use of com.serotonin.m2m2.vo.permission.PermissionHolder in project ma-core-public by infiniteautomation.

the class DataPointService method validate.

@Override
public ProcessResult validate(DataPointVO vo) {
    ProcessResult result = commonValidation(vo);
    DataSourceVO dsvo = dataSourceDao.get(vo.getDataSourceId());
    if (dsvo == null) {
        result.addContextualMessage("dataSourceId", "validate.invalidValue");
        return result;
    }
    // Validate pl if there is one
    if (vo.getPointLocator() != null) {
        DataSourceDefinition<? extends DataSourceVO> def = ModuleRegistry.getDataSourceDefinition(vo.getPointLocator().getDataSourceType());
        if (def == null) {
            throw new ShouldNeverHappenException("No data source definition for type " + vo.getPointLocator().getDataSourceType());
        } else {
            // Validate the point locator
            def.validate(result, vo, dsvo);
            if (vo.getPointLocator().getDataType() == null && !result.hasContextualMessage("dataType")) {
                result.addContextualMessage("dataType", "validate.invalidValueWithAcceptable", DataType.formatNames());
            }
        }
    }
    PermissionHolder user = Common.getUser();
    permissionService.validatePermission(result, "readPermission", user, vo.getReadPermission());
    permissionService.validatePermission(result, "editPermission", user, vo.getEditPermission());
    permissionService.validatePermission(result, "setPermission", user, vo.getSetPermission(), false);
    return result;
}
Also used : DataSourceVO(com.serotonin.m2m2.vo.dataSource.DataSourceVO) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder)

Example 92 with PermissionHolder

use of com.serotonin.m2m2.vo.permission.PermissionHolder in project ma-core-public by infiniteautomation.

the class AbstractVOService method insert.

/**
 */
@Override
public T insert(T vo) throws PermissionException, ValidationException {
    PermissionHolder user = Common.getUser();
    // Ensure they can create
    ensureCreatePermission(user, vo);
    // Ensure id is not set
    if (vo.getId() != Common.NEW_ID) {
        ProcessResult result = new ProcessResult();
        result.addContextualMessage("id", "validate.invalidValue");
        throw new ValidationException(result, vo.getClass());
    }
    // Generate an Xid if necessary
    if (StringUtils.isEmpty(vo.getXid()))
        vo.setXid(dao.generateUniqueXid());
    ensureValid(vo);
    dao.insert(vo);
    return vo;
}
Also used : ValidationException(com.infiniteautomation.mango.util.exception.ValidationException) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder)

Example 93 with PermissionHolder

use of com.serotonin.m2m2.vo.permission.PermissionHolder in project ma-core-public by infiniteautomation.

the class EventDetectorsService method validate.

@Override
public ProcessResult validate(AbstractEventDetectorVO existing, AbstractEventDetectorVO vo) {
    ProcessResult response = commonValidation(vo);
    PermissionHolder user = Common.getUser();
    permissionService.validatePermission(response, "readPermission", user, existing.getReadPermission(), vo.getReadPermission());
    permissionService.validatePermission(response, "editPermission", user, existing.getEditPermission(), vo.getEditPermission());
    vo.getDefinition().validate(response, existing, vo);
    return response;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder)

Example 94 with PermissionHolder

use of com.serotonin.m2m2.vo.permission.PermissionHolder in project ma-core-public by infiniteautomation.

the class EventInstanceService method getActiveSummary.

/**
 * Get the active summary of events for a user
 */
public List<UserEventLevelSummary> getActiveSummary() throws PermissionException {
    PermissionHolder user = Common.getUser();
    this.permissionService.ensurePermission(user, eventsViewPermission.getPermission());
    Map<AlarmLevels, UserEventLevelSummary> summaries = new EnumMap<>(AlarmLevels.class);
    for (AlarmLevels level : AlarmLevels.values()) {
        if (level == AlarmLevels.IGNORE) {
            continue;
        }
        summaries.put(level, new UserEventLevelSummary(level));
    }
    for (EventInstance event : this.getAllActiveUserEvents()) {
        UserEventLevelSummary summary = summaries.get(event.getAlarmLevel());
        summary.increment(event);
    }
    return new ArrayList<>(summaries.values());
}
Also used : EventInstance(com.serotonin.m2m2.rt.event.EventInstance) ArrayList(java.util.ArrayList) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) UserEventLevelSummary(com.serotonin.m2m2.rt.event.UserEventLevelSummary) EnumMap(java.util.EnumMap) AlarmLevels(com.serotonin.m2m2.rt.event.AlarmLevels)

Example 95 with PermissionHolder

use of com.serotonin.m2m2.vo.permission.PermissionHolder in project ma-core-public by infiniteautomation.

the class EventInstanceService method getDataPointEventSummaries.

/**
 * Get a summary of data point events for a list of data points
 */
public Collection<DataPointEventLevelSummary> getDataPointEventSummaries(String[] dataPointXids) throws NotFoundException, PermissionException {
    PermissionHolder user = Common.getUser();
    this.permissionService.ensurePermission(user, eventsViewPermission.getPermission());
    Map<Integer, DataPointEventLevelSummary> map = new LinkedHashMap<>();
    for (String xid : dataPointXids) {
        Integer point = dataPointDao.getIdByXid(xid);
        if (point != null) {
            map.put(point, new DataPointEventLevelSummary(xid));
        }
    }
    for (EventInstance event : this.getAllActiveUserEvents()) {
        if (EventType.EventTypeNames.DATA_POINT.equals(event.getEventType().getEventType())) {
            DataPointEventLevelSummary model = map.get(event.getEventType().getReferenceId1());
            if (model != null) {
                model.update(event);
            }
        }
    }
    return map.values();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DataPointEventLevelSummary(com.serotonin.m2m2.rt.event.DataPointEventLevelSummary) EventInstance(com.serotonin.m2m2.rt.event.EventInstance) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)120 ApiOperation (io.swagger.annotations.ApiOperation)97 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)97 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)64 ResponseEntity (org.springframework.http.ResponseEntity)53 HttpHeaders (org.springframework.http.HttpHeaders)50 URI (java.net.URI)48 ArrayList (java.util.ArrayList)37 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)34 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)29 List (java.util.List)27 User (com.serotonin.m2m2.vo.User)25 NotFoundException (com.infiniteautomation.mango.util.exception.NotFoundException)24 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)24 BadRequestException (com.infiniteautomation.mango.rest.latest.exception.BadRequestException)19 HashMap (java.util.HashMap)19 ValidationException (com.infiniteautomation.mango.util.exception.ValidationException)18 Common (com.serotonin.m2m2.Common)18 Collectors (java.util.stream.Collectors)17 Role (com.serotonin.m2m2.vo.role.Role)16