use of com.serotonin.m2m2.i18n.TranslatableMessage in project ma-modules-public by infiniteautomation.
the class MBusDataSourceRT method setValue.
protected boolean setValue(DataBlock db, boolean pointError, long time, DataPointRT point, final MBusPointLocatorRT locatorRT, final MBusPointLocatorVO locatorVo) {
try {
if ((db instanceof BcdValue) && ((BcdValue) db).isBcdError()) {
pointError = true;
LOG.fatal("BCD Error : " + ((BcdValue) db).getBcdError());
raiseEvent(POINT_READ_EXCEPTION_EVENT, time, true, new TranslatableMessage("event.exception2", point.getVO().getExtendedName(), "BCD error value: " + ((BcdValue) db).getBcdError()));
pointError = true;
} else if (db instanceof ByteDataBlock) {
point.updatePointValue(new PointValueTime(locatorRT.calcCorrectedValue(((ByteDataBlock) db).getValue(), db.getCorrectionExponent(locatorVo.effectiveSiPrefix()), db.getCorrectionConstant()), time));
} else if (db instanceof ShortDataBlock) {
point.updatePointValue(new PointValueTime(locatorRT.calcCorrectedValue(((ShortDataBlock) db).getValue(), db.getCorrectionExponent(locatorVo.effectiveSiPrefix()), db.getCorrectionConstant()), time));
} else if (db instanceof IntegerDataBlock) {
point.updatePointValue(new PointValueTime(locatorRT.calcCorrectedValue(((IntegerDataBlock) db).getValue(), db.getCorrectionExponent(locatorVo.effectiveSiPrefix()), db.getCorrectionConstant()), time));
} else if (db instanceof LongDataBlock) {
point.updatePointValue(new PointValueTime(locatorRT.calcCorrectedValue(((LongDataBlock) db).getValue(), db.getCorrectionExponent(locatorVo.effectiveSiPrefix()), db.getCorrectionConstant()), time));
} else if (db instanceof RealDataBlock) {
point.updatePointValue(new PointValueTime(locatorRT.calcCorrectedValue(((RealDataBlock) db).getValue(), db.getCorrectionExponent(locatorVo.effectiveSiPrefix()), db.getCorrectionConstant()), time));
} else if (db instanceof BigDecimalDataBlock) {
point.updatePointValue(new PointValueTime(locatorRT.calcCorrectedValue(((BigDecimalDataBlock) db).getValue().doubleValue(), db.getCorrectionExponent(locatorVo.effectiveSiPrefix()), db.getCorrectionConstant()), time));
} else if (db instanceof StringDataBlock) {
point.updatePointValue(new PointValueTime(((StringDataBlock) db).getValue(), time));
} else {
LOG.fatal("Dont know how to save: " + point.getVO().getExtendedName());
raiseEvent(POINT_READ_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("event.exception2", point.getVO().getExtendedName(), "Dont know how to save"));
pointError = true;
}
} catch (Exception ex) {
LOG.fatal("Error during saving: " + vo.getName(), ex);
raiseEvent(POINT_READ_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("event.exception2", point.getVO().getExtendedName(), "Ex: " + ex));
pointError = true;
}
return pointError;
}
use of com.serotonin.m2m2.i18n.TranslatableMessage in project ma-modules-public by infiniteautomation.
the class PointValueImportResult method saveValue.
public void saveValue(XidPointValueTimeModel model) {
if (valid) {
// Validate the model against our point
long timestamp = model.getTimestamp();
if (timestamp == 0)
timestamp = Common.timer.currentTimeMillis();
int dataTypeId = DataTypeEnum.convertFrom(model.getType());
if (dataTypeId != vo.getPointLocator().getDataTypeId()) {
result.addContextualMessage("dataType", "event.ds.dataType");
return;
}
DataValue value;
switch(model.getType()) {
case ALPHANUMERIC:
value = new AlphanumericValue((String) model.getValue());
break;
case BINARY:
value = new BinaryValue((Boolean) model.getValue());
break;
case MULTISTATE:
if (model.getValue() instanceof String) {
try {
value = vo.getTextRenderer().parseText((String) model.getValue(), dataTypeId);
} catch (Exception e) {
// Lots can go wrong here so let the user know
result.addContextualMessage("value", "event.valueParse.textParse", e.getMessage());
return;
}
} else {
value = new MultistateValue(((Number) model.getValue()).intValue());
}
break;
case NUMERIC:
value = new NumericValue(((Number) model.getValue()).doubleValue());
break;
case IMAGE:
default:
result.addContextualMessage("dataType", "common.default", model.getType() + " data type not supported yet");
return;
}
PointValueTime pvt;
if (model.getAnnotation() == null) {
pvt = new PointValueTime(value, timestamp);
} else {
pvt = new AnnotatedPointValueTime(value, timestamp, new TranslatableMessage("common.default", model.getAnnotation()));
}
if (rt == null) {
dao.savePointValueAsync(vo.getId(), pvt, null);
} else {
rt.savePointValueDirectToCache(pvt, null, true, true);
}
total++;
}
}
use of com.serotonin.m2m2.i18n.TranslatableMessage in project ma-modules-public by infiniteautomation.
the class MaintenanceEventsDwr method toggleMaintenanceEvent.
@DwrPermission(admin = true)
public ProcessResult toggleMaintenanceEvent(int id) {
ProcessResult response = new ProcessResult();
MaintenanceEventRT rt = RTMDefinition.instance.getRunningMaintenanceEvent(id);
boolean activated = false;
if (rt == null)
response.addMessage(new TranslatableMessage("maintenanceEvents.toggle.disabled"));
else
activated = rt.toggle();
response.addData("activated", activated);
return response;
}
use of com.serotonin.m2m2.i18n.TranslatableMessage in project ma-modules-public by infiniteautomation.
the class GraphicalViewDwr method setViewPoint.
/**
* Allows the setting of a given data point. Overrides BaseDwr to resolve the point view id.
*
* @param pointId
* @param valueStr
* @return
*/
@DwrPermission(user = true)
public String setViewPoint(String viewComponentId, String valueStr) {
User user = Common.getUser();
GraphicalView view = GraphicalViewsCommon.getUserView(user);
DataPointVO point = view.findDataPoint(viewComponentId);
if (point != null) {
// Check that setting is allowed.
if (!view.isSetter(user))
throw new PermissionException(new TranslatableMessage("permission.exception.setDataPoint", user.getUsername()), user);
// Try setting the point.
setPointImpl(point, valueStr, user);
}
return viewComponentId;
}
use of com.serotonin.m2m2.i18n.TranslatableMessage in project ma-modules-public by infiniteautomation.
the class GraphicalView method validateUpdatedPermissions.
/**
* Validate permissions by:
*
* 1. Removed permissions must be in the user's groups
* 2. Added permissions must be in the user's groups
*
* @param existingPermissionsString - Previous permissions of object
* @param newPermissionsString - New permissions of object
* @param user - User who's permissions to compare to
* @param response - ProcessResult to add messages
* @param contextKey - context key for messages to be applied
* @return
*/
private boolean validateUpdatedPermissions(String existingPermissionsString, String newPermissionsString, User user, ProcessResult response, String contextKey) {
if (user == null) {
response.addContextualMessage(contextKey, "validate.invalidPermission", "No User Found");
return false;
}
// Track the result
boolean success = true;
// Explode the current permissions for comparison
Set<String> newPermissions = Permissions.explodePermissionGroups(newPermissionsString);
Set<String> existingPermissions = Permissions.explodePermissionGroups(existingPermissionsString);
// TODO add trim to the explode method?
for (String newPermission : newPermissions) {
newPermission = newPermission.trim();
if (StringUtils.isBlank(newPermission))
response.addMessage(contextKey, new TranslatableMessage("validate.cannotContainEmptyString"));
}
// Check that we are not removing a permission we do not have
for (String existingPermission : existingPermissions) {
if (!Permissions.hasPermission(user, existingPermission)) {
// Make sure it is in the new permissions
if (!newPermissions.contains(existingPermission)) {
success = false;
response.addMessage(contextKey, new TranslatableMessage("viewEdit.validate.ungrantedPermissionRemoved", existingPermission));
}
}
}
// they are assumed to be valid.
for (String newPermission : newPermissions) {
if (!existingPermissions.contains(newPermission)) {
// We didn't have this permission, validate it
if (!Permissions.hasPermission(user, newPermission)) {
success = false;
response.addContextualMessage(contextKey, "validate.invalidPermission", newPermission);
}
}
}
return success;
}
Aggregations