Search in sources :

Example 6 with Role

use of com.serotonin.m2m2.vo.role.Role in project ma-modules-public by infiniteautomation.

the class EmailEventHandlerModel method fromVO.

@Override
public void fromVO(EmailEventHandlerVO vo) {
    super.fromVO(vo);
    this.sendEscalation = vo.isSendEscalation();
    this.escalationDelayType = Common.TIME_PERIOD_CODES.getCode(vo.getEscalationDelayType());
    this.repeatEscalations = vo.isRepeatEscalations();
    this.escalationDelay = vo.getEscalationDelay();
    this.sendInactive = vo.isSendInactive();
    this.inactiveOverride = vo.isInactiveOverride();
    this.includeSystemInfo = vo.isIncludeSystemInfo();
    this.includePointValueCount = vo.getIncludePointValueCount() == 0 ? null : vo.getIncludePointValueCount();
    this.includeLogfile = vo.isIncludeLogfile();
    this.customTemplate = vo.getCustomTemplate();
    this.script = vo.getScript();
    if (vo.getScriptRoles() != null) {
        this.scriptPermissions = new HashSet<>();
        for (Role role : vo.getScriptRoles().getRoles()) {
            this.scriptPermissions.add(role.getXid());
        }
    }
    if (vo.getAdditionalContext() != null) {
        this.scriptContext = new ArrayList<>();
        for (IntStringPair var : vo.getAdditionalContext()) {
            String xid = DataPointDao.getInstance().getXidById(var.getKey());
            if (xid != null) {
                this.scriptContext.add(new ScriptContextVariableModel(xid, var.getValue()));
            }
        }
    }
    this.subject = EmailEventHandlerVO.SUBJECT_INCLUDE_CODES.getCode(vo.getSubject());
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) IntStringPair(com.serotonin.db.pair.IntStringPair) ScriptContextVariableModel(com.infiniteautomation.mango.rest.latest.model.javascript.MangoJavaScriptModel.ScriptContextVariableModel)

Example 7 with Role

use of com.serotonin.m2m2.vo.role.Role in project ma-modules-public by infiniteautomation.

the class SetPointEventHandlerModel method fromVO.

@Override
public void fromVO(SetPointEventHandlerVO vo) {
    super.fromVO(vo);
    DataPointVO target = DataPointDao.getInstance().get(vo.getTargetPointId());
    this.activeAction = SetPointEventHandlerVO.SET_ACTION_CODES.getCode(vo.getActiveAction());
    if (target != null) {
        this.targetPointXid = target.getXid();
        if (vo.getActiveAction() == SetPointEventHandlerVO.SET_ACTION_STATIC_VALUE) {
            DataValue value = DataValue.stringToValue(vo.getActiveValueToSet(), target.getPointLocator().getDataType());
            this.activeValueToSet = value.getObjectValue();
        }
        if (vo.getInactiveAction() == SetPointEventHandlerVO.SET_ACTION_STATIC_VALUE) {
            DataValue value = DataValue.stringToValue(vo.getInactiveValueToSet(), target.getPointLocator().getDataType());
            this.inactiveValueToSet = value.getObjectValue();
        }
    }
    if (vo.getActiveAction() == SetPointEventHandlerVO.SET_ACTION_POINT_VALUE)
        this.activePointXid = DataPointDao.getInstance().getXidById(vo.getActivePointId());
    if (vo.getInactiveAction() == SetPointEventHandlerVO.SET_ACTION_POINT_VALUE)
        this.inactivePointXid = DataPointDao.getInstance().getXidById(vo.getInactivePointId());
    this.inactiveAction = SetPointEventHandlerVO.SET_ACTION_CODES.getCode(vo.getInactiveAction());
    this.activeScript = vo.getActiveScript();
    this.inactiveScript = vo.getInactiveScript();
    if (vo.getScriptRoles() != null) {
        this.scriptPermissions = new HashSet<>();
        for (Role role : vo.getScriptRoles().getRoles()) {
            this.scriptPermissions.add(role.getXid());
        }
    }
    if (vo.getAdditionalContext() != null) {
        this.scriptContext = new ArrayList<>();
        for (IntStringPair var : vo.getAdditionalContext()) {
            String xid = DataPointDao.getInstance().getXidById(var.getKey());
            if (xid != null) {
                this.scriptContext.add(new ScriptContextVariableModel(xid, var.getValue()));
            }
        }
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) Role(com.serotonin.m2m2.vo.role.Role) DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) IntStringPair(com.serotonin.db.pair.IntStringPair) ScriptContextVariableModel(com.infiniteautomation.mango.rest.latest.model.javascript.MangoJavaScriptModel.ScriptContextVariableModel)

Example 8 with Role

use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.

the class MangoPermissionConverter method jsonWrite.

@Override
public void jsonWrite(JsonWriter writer, Object value) throws IOException, JsonException {
    MangoPermission permission = (MangoPermission) value;
    JsonArray outerRolesArray = new JsonArray();
    for (Set<Role> roleSet : permission.getRoles()) {
        JsonArray roles = new JsonArray();
        for (Role role : roleSet) {
            roles.add(role.getXid());
        }
        outerRolesArray.add(roles);
    }
    writer.writeObject(outerRolesArray);
}
Also used : JsonArray(com.serotonin.json.type.JsonArray) Role(com.serotonin.m2m2.vo.role.Role) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission)

Example 9 with Role

use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.

the class MangoPermissionConverter method jsonRead.

@Override
public Object jsonRead(JsonReader reader, JsonValue jsonValue, Type type) throws JsonException {
    Set<Set<Role>> roles = new HashSet<>();
    PermissionService permissionService = Common.getBean(PermissionService.class);
    if (jsonValue instanceof JsonArray) {
        for (JsonValue val : (JsonArray) jsonValue) {
            if (val instanceof JsonArray) {
                Set<Role> inner = new HashSet<>();
                roles.add(inner);
                for (JsonValue v : (JsonArray) val) {
                    Role r = permissionService.getRole(v.toString());
                    if (r != null) {
                        inner.add(r);
                    } else {
                        inner.add(new Role(Common.NEW_ID, v.toString()));
                    }
                }
            } else {
                // Just a single string
                Role r = permissionService.getRole(val.toString());
                if (r != null) {
                    roles.add(Collections.singleton(r));
                } else {
                    roles.add(Collections.singleton(new Role(Common.NEW_ID, val.toString())));
                }
            }
        }
    } else {
        for (String role : PermissionService.explodeLegacyPermissionGroups(jsonValue.toString())) {
            Role r = permissionService.getRole(role);
            if (r != null) {
                roles.add(Collections.singleton(r));
            } else {
                roles.add(Collections.singleton(new Role(Common.NEW_ID, role)));
            }
        }
    }
    return new MangoPermission(roles);
}
Also used : PermissionService(com.infiniteautomation.mango.spring.service.PermissionService) JsonArray(com.serotonin.json.type.JsonArray) Role(com.serotonin.m2m2.vo.role.Role) Set(java.util.Set) HashSet(java.util.HashSet) JsonValue(com.serotonin.json.type.JsonValue) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission) HashSet(java.util.HashSet)

Example 10 with Role

use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.

the class ScriptPermissionConverter method jsonWrite.

@Override
public void jsonWrite(JsonWriter writer, Object value) throws IOException, JsonException {
    ScriptPermissions permission = (ScriptPermissions) value;
    JsonArray roles = new JsonArray();
    for (Role role : permission.getRoles()) {
        roles.add(role.getXid());
    }
    writer.writeObject(roles);
}
Also used : JsonArray(com.serotonin.json.type.JsonArray) Role(com.serotonin.m2m2.vo.role.Role) ScriptPermissions(com.infiniteautomation.mango.util.script.ScriptPermissions)

Aggregations

Role (com.serotonin.m2m2.vo.role.Role)102 Test (org.junit.Test)59 HashSet (java.util.HashSet)40 Set (java.util.Set)38 User (com.serotonin.m2m2.vo.User)33 MangoPermission (com.infiniteautomation.mango.permission.MangoPermission)23 RoleVO (com.serotonin.m2m2.vo.role.RoleVO)22 Collectors (java.util.stream.Collectors)18 Common (com.serotonin.m2m2.Common)17 MangoTestBase (com.serotonin.m2m2.MangoTestBase)15 RoleDao (com.serotonin.m2m2.db.dao.RoleDao)15 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)15 List (java.util.List)15 PermissionService (com.infiniteautomation.mango.spring.service.PermissionService)14 Assert.assertEquals (org.junit.Assert.assertEquals)14 Assert.assertTrue (org.junit.Assert.assertTrue)14 DataPointService (com.infiniteautomation.mango.spring.service.DataPointService)12 PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)12 IDataPoint (com.serotonin.m2m2.vo.IDataPoint)11 DSLContext (org.jooq.DSLContext)11