Search in sources :

Example 1 with ScriptContextVariableModel

use of com.infiniteautomation.mango.rest.latest.model.javascript.MangoJavaScriptModel.ScriptContextVariableModel 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 2 with ScriptContextVariableModel

use of com.infiniteautomation.mango.rest.latest.model.javascript.MangoJavaScriptModel.ScriptContextVariableModel 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 3 with ScriptContextVariableModel

use of com.infiniteautomation.mango.rest.latest.model.javascript.MangoJavaScriptModel.ScriptContextVariableModel in project ma-modules-public by infiniteautomation.

the class SetPointEventHandlerModel method readInto.

@Override
public void readInto(SetPointEventHandlerVO vo) {
    super.readInto(vo);
    Integer targetId = DataPointDao.getInstance().getIdByXid(targetPointXid);
    if (targetId != null)
        vo.setTargetPointId(targetId);
    vo.setActiveAction(SetPointEventHandlerVO.SET_ACTION_CODES.getId(activeAction));
    if (activeValueToSet != null)
        vo.setActiveValueToSet(activeValueToSet.toString());
    if (activePointXid != null) {
        Integer activePointId = DataPointDao.getInstance().getIdByXid(activePointXid);
        if (activePointId != null)
            vo.setActivePointId(activePointId);
    }
    vo.setActiveScript(activeScript);
    vo.setInactiveAction(SetPointEventHandlerVO.SET_ACTION_CODES.getId(inactiveAction));
    if (inactiveValueToSet != null)
        vo.setInactiveValueToSet(inactiveValueToSet.toString());
    if (inactivePointXid != null) {
        Integer inactivePointId = DataPointDao.getInstance().getIdByXid(inactivePointXid);
        if (inactivePointId != null)
            vo.setInactivePointId(inactivePointId);
    }
    vo.setInactiveScript(inactiveScript);
    PermissionService service = Common.getBean(PermissionService.class);
    vo.setScriptRoles(new ScriptPermissions(service.explodeLegacyPermissionGroupsToRoles(scriptPermissions)));
    if (scriptContext != null) {
        List<IntStringPair> additionalContext = new ArrayList<>();
        for (ScriptContextVariableModel var : scriptContext) {
            Integer id = DataPointDao.getInstance().getIdByXid(var.getXid());
            if (id != null) {
                additionalContext.add(new IntStringPair(id, var.getVariableName()));
            } else {
                additionalContext.add(new IntStringPair(Common.NEW_ID, var.getVariableName()));
            }
        }
        vo.setAdditionalContext(additionalContext);
    }
}
Also used : PermissionService(com.infiniteautomation.mango.spring.service.PermissionService) IntStringPair(com.serotonin.db.pair.IntStringPair) ScriptContextVariableModel(com.infiniteautomation.mango.rest.latest.model.javascript.MangoJavaScriptModel.ScriptContextVariableModel) ArrayList(java.util.ArrayList) ScriptPermissions(com.infiniteautomation.mango.util.script.ScriptPermissions)

Example 4 with ScriptContextVariableModel

use of com.infiniteautomation.mango.rest.latest.model.javascript.MangoJavaScriptModel.ScriptContextVariableModel in project ma-modules-public by infiniteautomation.

the class EmailEventHandlerModel method readInto.

@Override
public void readInto(EmailEventHandlerVO vo) {
    super.readInto(vo);
    if (activeRecipients != null) {
        List<MailingListRecipient> beans = new ArrayList<>();
        for (EmailRecipientModel model : activeRecipients) beans.add(model.fromModel());
        vo.setActiveRecipients(beans);
    }
    vo.setSendEscalation(sendEscalation);
    vo.setRepeatEscalations(repeatEscalations);
    vo.setEscalationDelayType(Common.TIME_PERIOD_CODES.getId(escalationDelayType));
    vo.setEscalationDelay(escalationDelay);
    if (escalationRecipients != null) {
        List<MailingListRecipient> beans = new ArrayList<>();
        for (EmailRecipientModel model : escalationRecipients) beans.add(model.fromModel());
        vo.setEscalationRecipients(beans);
    }
    vo.setSendInactive(sendInactive);
    vo.setInactiveOverride(inactiveOverride);
    if (inactiveRecipients != null) {
        List<MailingListRecipient> beans = new ArrayList<>();
        for (EmailRecipientModel model : inactiveRecipients) beans.add(model.fromModel());
        vo.setInactiveRecipients(beans);
    }
    vo.setIncludeSystemInfo(includeSystemInfo);
    if (includePointValueCount != null)
        vo.setIncludePointValueCount(includePointValueCount);
    vo.setIncludeLogfile(includeLogfile);
    vo.setCustomTemplate(customTemplate);
    vo.setScript(script);
    PermissionService service = Common.getBean(PermissionService.class);
    vo.setScriptRoles(new ScriptPermissions(service.explodeLegacyPermissionGroupsToRoles(scriptPermissions)));
    if (scriptContext != null) {
        List<IntStringPair> additionalContext = new ArrayList<>();
        for (ScriptContextVariableModel var : scriptContext) {
            Integer id = DataPointDao.getInstance().getIdByXid(var.getXid());
            if (id != null) {
                additionalContext.add(new IntStringPair(id, var.getVariableName()));
            } else {
                additionalContext.add(new IntStringPair(Common.NEW_ID, var.getVariableName()));
            }
        }
        vo.setAdditionalContext(additionalContext);
    }
    vo.setSubject(EmailEventHandlerVO.SUBJECT_INCLUDE_CODES.getId(subject));
}
Also used : PermissionService(com.infiniteautomation.mango.spring.service.PermissionService) IntStringPair(com.serotonin.db.pair.IntStringPair) ScriptContextVariableModel(com.infiniteautomation.mango.rest.latest.model.javascript.MangoJavaScriptModel.ScriptContextVariableModel) ArrayList(java.util.ArrayList) MailingListRecipient(com.serotonin.m2m2.vo.mailingList.MailingListRecipient) EmailRecipientModel(com.infiniteautomation.mango.rest.latest.model.mailingList.EmailRecipientModel) ScriptPermissions(com.infiniteautomation.mango.util.script.ScriptPermissions)

Aggregations

ScriptContextVariableModel (com.infiniteautomation.mango.rest.latest.model.javascript.MangoJavaScriptModel.ScriptContextVariableModel)4 IntStringPair (com.serotonin.db.pair.IntStringPair)4 PermissionService (com.infiniteautomation.mango.spring.service.PermissionService)2 ScriptPermissions (com.infiniteautomation.mango.util.script.ScriptPermissions)2 Role (com.serotonin.m2m2.vo.role.Role)2 ArrayList (java.util.ArrayList)2 EmailRecipientModel (com.infiniteautomation.mango.rest.latest.model.mailingList.EmailRecipientModel)1 DataValue (com.serotonin.m2m2.rt.dataImage.types.DataValue)1 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)1 MailingListRecipient (com.serotonin.m2m2.vo.mailingList.MailingListRecipient)1