Search in sources :

Example 21 with IntStringPair

use of com.serotonin.db.pair.IntStringPair in project ma-modules-public by infiniteautomation.

the class WatchListDao method getPropertiesMap.

/* (non-Javadoc)
	 * @see com.serotonin.m2m2.db.dao.AbstractBasicDao#getPropertiesMap()
	 */
@Override
protected Map<String, IntStringPair> getPropertiesMap() {
    Map<String, IntStringPair> map = new HashMap<String, IntStringPair>();
    // So we can filter/sort on username in the models
    map.put("username", new IntStringPair(Types.VARCHAR, "u.username"));
    return map;
}
Also used : IntStringPair(com.serotonin.db.pair.IntStringPair) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 22 with IntStringPair

use of com.serotonin.db.pair.IntStringPair in project ma-modules-public by infiniteautomation.

the class WatchListDwr method addNewWatchList.

@DwrPermission(user = true)
public IntStringPair addNewWatchList(int copyId) {
    User user = Common.getUser();
    WatchListVO watchList;
    if (copyId == Common.NEW_ID) {
        watchList = new WatchListVO();
        watchList.setName(translate("common.newName"));
    } else {
        watchList = WatchListDao.instance.get(getWatchList().getId());
        watchList.setId(Common.NEW_ID);
        watchList.setName(translate(new TranslatableMessage("common.copyPrefix", watchList.getName())));
    }
    watchList.setUserId(user.getId());
    watchList.setXid(WatchListDao.instance.generateUniqueXid());
    WatchListDao.instance.saveWatchList(watchList);
    setWatchList(user, watchList);
    WatchListDao.instance.saveSelectedWatchList(user.getId(), watchList.getId());
    return new IntStringPair(watchList.getId(), watchList.getName());
}
Also used : User(com.serotonin.m2m2.vo.User) IntStringPair(com.serotonin.db.pair.IntStringPair) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 23 with IntStringPair

use of com.serotonin.db.pair.IntStringPair in project ma-core-public by infiniteautomation.

the class EmailEventHandlerVO method readObject.

@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    int ver = in.readInt();
    if (ver == 1) {
        activeRecipients = (List<RecipientListEntryBean>) in.readObject();
        RecipientListEntryBean.cleanRecipientList(activeRecipients);
        sendEscalation = in.readBoolean();
        repeatEscalations = false;
        escalationDelayType = in.readInt();
        escalationDelay = in.readInt();
        escalationRecipients = (List<RecipientListEntryBean>) in.readObject();
        RecipientListEntryBean.cleanRecipientList(escalationRecipients);
        sendInactive = in.readBoolean();
        inactiveOverride = in.readBoolean();
        inactiveRecipients = (List<RecipientListEntryBean>) in.readObject();
        RecipientListEntryBean.cleanRecipientList(inactiveRecipients);
        includeSystemInfo = in.readBoolean();
        includePointValueCount = in.readInt();
        includeLogfile = in.readBoolean();
        customTemplate = null;
        additionalContext = new ArrayList<IntStringPair>();
        scriptPermissions = new ScriptPermissions();
        script = null;
    } else if (ver == 2) {
        activeRecipients = (List<RecipientListEntryBean>) in.readObject();
        RecipientListEntryBean.cleanRecipientList(activeRecipients);
        sendEscalation = in.readBoolean();
        repeatEscalations = false;
        escalationDelayType = in.readInt();
        escalationDelay = in.readInt();
        escalationRecipients = (List<RecipientListEntryBean>) in.readObject();
        RecipientListEntryBean.cleanRecipientList(escalationRecipients);
        sendInactive = in.readBoolean();
        inactiveOverride = in.readBoolean();
        inactiveRecipients = (List<RecipientListEntryBean>) in.readObject();
        RecipientListEntryBean.cleanRecipientList(inactiveRecipients);
        includeSystemInfo = in.readBoolean();
        includePointValueCount = in.readInt();
        includeLogfile = in.readBoolean();
        customTemplate = SerializationHelper.readSafeUTF(in);
        additionalContext = new ArrayList<IntStringPair>();
        scriptPermissions = new ScriptPermissions();
        script = null;
    } else if (ver == 3) {
        activeRecipients = (List<RecipientListEntryBean>) in.readObject();
        RecipientListEntryBean.cleanRecipientList(activeRecipients);
        sendEscalation = in.readBoolean();
        repeatEscalations = false;
        escalationDelayType = in.readInt();
        escalationDelay = in.readInt();
        escalationRecipients = (List<RecipientListEntryBean>) in.readObject();
        RecipientListEntryBean.cleanRecipientList(escalationRecipients);
        sendInactive = in.readBoolean();
        inactiveOverride = in.readBoolean();
        inactiveRecipients = (List<RecipientListEntryBean>) in.readObject();
        RecipientListEntryBean.cleanRecipientList(inactiveRecipients);
        includeSystemInfo = in.readBoolean();
        includePointValueCount = in.readInt();
        includeLogfile = in.readBoolean();
        customTemplate = SerializationHelper.readSafeUTF(in);
        additionalContext = (List<IntStringPair>) in.readObject();
        scriptPermissions = new ScriptPermissions();
        script = null;
    } else if (ver == 4) {
        activeRecipients = (List<RecipientListEntryBean>) in.readObject();
        RecipientListEntryBean.cleanRecipientList(activeRecipients);
        sendEscalation = in.readBoolean();
        repeatEscalations = false;
        escalationDelayType = in.readInt();
        escalationDelay = in.readInt();
        escalationRecipients = (List<RecipientListEntryBean>) in.readObject();
        RecipientListEntryBean.cleanRecipientList(escalationRecipients);
        sendInactive = in.readBoolean();
        inactiveOverride = in.readBoolean();
        inactiveRecipients = (List<RecipientListEntryBean>) in.readObject();
        RecipientListEntryBean.cleanRecipientList(inactiveRecipients);
        includeSystemInfo = in.readBoolean();
        includePointValueCount = in.readInt();
        includeLogfile = in.readBoolean();
        customTemplate = SerializationHelper.readSafeUTF(in);
        additionalContext = (List<IntStringPair>) in.readObject();
        scriptPermissions = (ScriptPermissions) in.readObject();
        script = SerializationHelper.readSafeUTF(in);
    } else if (ver == 5) {
        activeRecipients = (List<RecipientListEntryBean>) in.readObject();
        RecipientListEntryBean.cleanRecipientList(activeRecipients);
        sendEscalation = in.readBoolean();
        repeatEscalations = in.readBoolean();
        escalationDelayType = in.readInt();
        escalationDelay = in.readInt();
        escalationRecipients = (List<RecipientListEntryBean>) in.readObject();
        RecipientListEntryBean.cleanRecipientList(escalationRecipients);
        sendInactive = in.readBoolean();
        inactiveOverride = in.readBoolean();
        inactiveRecipients = (List<RecipientListEntryBean>) in.readObject();
        RecipientListEntryBean.cleanRecipientList(inactiveRecipients);
        includeSystemInfo = in.readBoolean();
        includePointValueCount = in.readInt();
        includeLogfile = in.readBoolean();
        customTemplate = SerializationHelper.readSafeUTF(in);
        additionalContext = (List<IntStringPair>) in.readObject();
        scriptPermissions = (ScriptPermissions) in.readObject();
        script = SerializationHelper.readSafeUTF(in);
    }
}
Also used : IntStringPair(com.serotonin.db.pair.IntStringPair) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) RecipientListEntryBean(com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean) ScriptPermissions(com.serotonin.m2m2.rt.script.ScriptPermissions)

Example 24 with IntStringPair

use of com.serotonin.db.pair.IntStringPair in project ma-core-public by infiniteautomation.

the class EmailEventHandlerVO method validate.

@Override
public void validate(ProcessResult response) {
    super.validate(response);
    if (activeRecipients.isEmpty())
        response.addGenericMessage("eventHandlers.noEmailRecips");
    if (sendEscalation) {
        if (escalationDelay <= 0)
            response.addContextualMessage("escalationDelay", "eventHandlers.escalDelayError");
        if (escalationRecipients.isEmpty())
            response.addGenericMessage("eventHandlers.noEscalRecips");
    } else if (repeatEscalations)
        repeatEscalations = false;
    if (sendInactive && inactiveOverride) {
        if (inactiveRecipients == null || inactiveRecipients.isEmpty())
            response.addGenericMessage("eventHandlers.noInactiveRecips");
    }
    List<String> varNameSpace = new ArrayList<String>();
    if (additionalContext != null) {
        for (IntStringPair cxt : additionalContext) {
            if (DataPointDao.instance.get(cxt.getKey()) == null)
                response.addGenericMessage("event.script.contextPointMissing", cxt.getKey(), cxt.getValue());
            String varName = cxt.getValue();
            if (StringUtils.isBlank(varName)) {
                response.addGenericMessage("validate.allVarNames");
                break;
            }
            if (!VarNames.validateVarName(varName)) {
                response.addGenericMessage("validate.invalidVarName", varName);
                break;
            }
            if (varNameSpace.contains(varName)) {
                response.addGenericMessage("validate.duplicateVarName", varName);
                break;
            }
            varNameSpace.add(varName);
        }
    } else {
        additionalContext = new ArrayList<>();
    }
    if (!StringUtils.isEmpty(script)) {
        try {
            CompiledScriptExecutor.compile(script);
        } catch (ScriptException e) {
            response.addGenericMessage("eventHandlers.invalidActiveScriptError", e.getMessage() == null ? e.getCause().getMessage() : e.getMessage());
        }
    }
}
Also used : ScriptException(javax.script.ScriptException) IntStringPair(com.serotonin.db.pair.IntStringPair) ArrayList(java.util.ArrayList)

Example 25 with IntStringPair

use of com.serotonin.db.pair.IntStringPair in project ma-core-public by infiniteautomation.

the class SetPointEventHandlerVO method validate.

public void validate(ProcessResult response) {
    super.validate(response);
    DataPointVO dp = DataPointDao.instance.getDataPoint(targetPointId, false);
    if (dp == null)
        response.addGenericMessage("eventHandlers.noTargetPoint");
    else {
        int dataType = dp.getPointLocator().getDataTypeId();
        if (activeAction == SET_ACTION_NONE && inactiveAction == SET_ACTION_NONE)
            response.addGenericMessage("eventHandlers.noSetPointAction");
        // Active
        if (activeAction == SET_ACTION_STATIC_VALUE && dataType == DataTypes.MULTISTATE) {
            try {
                Integer.parseInt(activeValueToSet);
            } catch (NumberFormatException e) {
                response.addGenericMessage("eventHandlers.invalidActiveValue");
            }
        } else if (activeAction == SET_ACTION_STATIC_VALUE && dataType == DataTypes.NUMERIC) {
            try {
                Double.parseDouble(activeValueToSet);
            } catch (NumberFormatException e) {
                response.addGenericMessage("eventHandlers.invalidActiveValue");
            }
        } else if (activeAction == SET_ACTION_POINT_VALUE) {
            DataPointVO dpActive = DataPointDao.instance.getDataPoint(activePointId, false);
            if (dpActive == null)
                response.addGenericMessage("eventHandlers.invalidActiveSource");
            else if (dataType != dpActive.getPointLocator().getDataTypeId())
                response.addGenericMessage("eventHandlers.invalidActiveSourceType");
        } else if (activeAction == SET_ACTION_SCRIPT_VALUE) {
            if (StringUtils.isEmpty(activeScript))
                response.addGenericMessage("eventHandlers.invalidActiveScript");
            try {
                CompiledScriptExecutor.compile(activeScript);
            } catch (ScriptException e) {
                response.addGenericMessage("eventHandlers.invalidActiveScriptError", e.getMessage() == null ? e.getCause().getMessage() : e.getMessage());
            }
        }
        // Inactive
        if (inactiveAction == SET_ACTION_STATIC_VALUE && dataType == DataTypes.MULTISTATE) {
            try {
                Integer.parseInt(inactiveValueToSet);
            } catch (NumberFormatException e) {
                response.addGenericMessage("eventHandlers.invalidInactiveValue");
            }
        } else if (inactiveAction == SET_ACTION_STATIC_VALUE && dataType == DataTypes.NUMERIC) {
            try {
                Double.parseDouble(inactiveValueToSet);
            } catch (NumberFormatException e) {
                response.addGenericMessage("eventHandlers.invalidInactiveValue");
            }
        } else if (inactiveAction == SET_ACTION_POINT_VALUE) {
            DataPointVO dpInactive = DataPointDao.instance.getDataPoint(inactivePointId, false);
            if (dpInactive == null)
                response.addGenericMessage("eventHandlers.invalidInactiveSource");
            else if (dataType != dpInactive.getPointLocator().getDataTypeId())
                response.addGenericMessage("eventHandlers.invalidInactiveSourceType");
        } else if (inactiveAction == SET_ACTION_SCRIPT_VALUE) {
            if (StringUtils.isEmpty(inactiveScript))
                response.addGenericMessage("eventHandlers.invalidInactiveScript");
            try {
                CompiledScriptExecutor.compile(inactiveScript);
            } catch (ScriptException e) {
                response.addGenericMessage("eventHandlers.invalidInactiveScriptError", e.getMessage() == null ? e.getCause().getMessage() : e.getMessage());
            }
        }
        List<String> varNameSpace = new ArrayList<String>();
        varNameSpace.add(TARGET_CONTEXT_KEY);
        for (IntStringPair cxt : additionalContext) {
            if (DataPointDao.instance.getDataPoint(cxt.getKey(), false) == null)
                response.addGenericMessage("event.script.contextPointMissing", cxt.getKey(), cxt.getValue());
            String varName = cxt.getValue();
            if (StringUtils.isBlank(varName)) {
                response.addGenericMessage("validate.allVarNames");
                break;
            }
            if (!VarNames.validateVarName(varName)) {
                response.addGenericMessage("validate.invalidVarName", varName);
                break;
            }
            if (varNameSpace.contains(varName)) {
                response.addGenericMessage("validate.duplicateVarName", varName);
                break;
            }
            varNameSpace.add(varName);
        }
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) ScriptException(javax.script.ScriptException) IntStringPair(com.serotonin.db.pair.IntStringPair) ArrayList(java.util.ArrayList)

Aggregations

IntStringPair (com.serotonin.db.pair.IntStringPair)31 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)10 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)9 JsonArray (com.serotonin.json.type.JsonArray)6 JsonObject (com.serotonin.json.type.JsonObject)6 LinkedHashMap (java.util.LinkedHashMap)6 ScriptException (javax.script.ScriptException)5 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)4 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)4 ScriptPermissions (com.serotonin.m2m2.rt.script.ScriptPermissions)4 User (com.serotonin.m2m2.vo.User)4 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)4 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)3 JsonValue (com.serotonin.json.type.JsonValue)3 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)3 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)3 IDataPointValueSource (com.serotonin.m2m2.rt.dataImage.IDataPointValueSource)3 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)3 ResultTypeException (com.serotonin.m2m2.rt.script.ResultTypeException)3