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