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;
}
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;
}
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;
}
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());
}
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();
}
Aggregations