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