Search in sources :

Example 96 with PermissionHolder

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

the class AuditEventService method raiseSystemSettingAuditEvent.

private void raiseSystemSettingAuditEvent(int changeType, String auditEventType, PermissionHolder permissionHolder, String systemSettingKey, String key, Map<String, Object> context) {
    User raisingUser = permissionHolder.getUser();
    Object username = permissionHolder.getPermissionHolderName();
    if (raisingUser != null) {
        username = raisingUser.getUsername() + " (" + raisingUser.getId() + ")";
    }
    TranslatableMessage message = new TranslatableMessage(key, username, systemSettingKey);
    AuditEventType type = new AuditEventType(auditEventType, changeType, Common.NEW_ID);
    type.setRaisingUser(raisingUser);
    Common.eventManager.raiseEvent(type, Common.timer.currentTimeMillis(), false, AuditEventType.getEventType(type.getAuditEventType()).getAlarmLevel(), message, context);
}
Also used : User(com.serotonin.m2m2.vo.User) AuditEventType(com.serotonin.m2m2.rt.event.type.AuditEventType) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage)

Example 97 with PermissionHolder

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

the class AuditEventService method raiseVoAuditEvent.

/**
 * Common raise event logic
 */
private void raiseVoAuditEvent(int changeType, String auditEventType, PermissionHolder permissionHolder, AbstractVO to, String key, Map<String, Object> context) {
    User raisingUser = permissionHolder.getUser();
    Object username = permissionHolder.getPermissionHolderName();
    if (raisingUser != null) {
        username = raisingUser.getUsername() + " (" + raisingUser.getId() + ")";
    }
    TranslatableMessage message = new TranslatableMessage(key, username, new TranslatableMessage(to.getTypeKey()), to.getName(), to.getXid());
    AuditEventType type = new AuditEventType(auditEventType, changeType, to.getId());
    type.setRaisingUser(raisingUser);
    Common.eventManager.raiseEvent(type, Common.timer.currentTimeMillis(), false, AuditEventType.getEventType(type.getAuditEventType()).getAlarmLevel(), message, context);
}
Also used : User(com.serotonin.m2m2.vo.User) AuditEventType(com.serotonin.m2m2.rt.event.type.AuditEventType) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage)

Example 98 with PermissionHolder

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

the class DataPointService method setValue.

/**
 * Set the value of a data point
 * @throws PermissionException - if the setting permission holder does not have set permission
 * @throws RTException - if the point is not enabled and settable
 */
public void setValue(int id, PointValueTime valueTime, SetPointSource source) throws NotFoundException, PermissionException, RTException {
    DataPointVO vo = get(id);
    PermissionHolder user = Common.getUser();
    ensureSetPermission(user, vo);
    getRuntimeManager().setDataPointValue(vo.getId(), valueTime, source);
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder)

Example 99 with PermissionHolder

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

the class DataPointService method getDataPoints.

/**
 */
public List<DataPointVO> getDataPoints(int dataSourceId) {
    List<DataPointVO> points = dao.getDataPoints(dataSourceId);
    PermissionHolder user = Common.getUser();
    for (DataPointVO point : points) {
        ensureReadPermission(user, point);
    }
    return points;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder)

Example 100 with PermissionHolder

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

the class DataPointService method update.

@Override
protected DataPointVO update(DataPointVO existing, DataPointVO vo) throws PermissionException, ValidationException {
    PermissionHolder user = Common.getUser();
    ensureEditPermission(user, existing);
    vo.setId(existing.getId());
    for (DataPointChangeDefinition def : changeDefinitions) {
        def.preUpdate(vo);
    }
    ensureValid(existing, vo);
    getRuntimeManager().stopDataPoint(vo.getId());
    dao.update(existing, vo);
    for (DataPointChangeDefinition def : changeDefinitions) {
        def.postUpdate(vo);
    }
    if (vo.isEnabled()) {
        List<AbstractPointEventDetectorVO> detectors = eventDetectorDao.getWithSource(vo.getId(), vo);
        getRuntimeManager().startDataPoint(new DataPointWithEventDetectors(vo, detectors));
    }
    return vo;
}
Also used : DataPointChangeDefinition(com.serotonin.m2m2.module.definitions.dataPoint.DataPointChangeDefinition) AbstractPointEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO) DataPointWithEventDetectors(com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder)

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