Search in sources :

Example 56 with TranslatableMessage

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;
}
Also used : ShortDataBlock(net.sf.mbus4j.dataframes.datablocks.ShortDataBlock) IntegerDataBlock(net.sf.mbus4j.dataframes.datablocks.IntegerDataBlock) BigDecimalDataBlock(net.sf.mbus4j.dataframes.datablocks.BigDecimalDataBlock) StringDataBlock(net.sf.mbus4j.dataframes.datablocks.StringDataBlock) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) BcdValue(net.sf.mbus4j.dataframes.datablocks.BcdValue) RealDataBlock(net.sf.mbus4j.dataframes.datablocks.RealDataBlock) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) LongDataBlock(net.sf.mbus4j.dataframes.datablocks.LongDataBlock) ByteDataBlock(net.sf.mbus4j.dataframes.datablocks.ByteDataBlock) IOException(java.io.IOException)

Example 57 with TranslatableMessage

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++;
    }
}
Also used : DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) BinaryValue(com.serotonin.m2m2.rt.dataImage.types.BinaryValue) MultistateValue(com.serotonin.m2m2.rt.dataImage.types.MultistateValue) AlphanumericValue(com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue)

Example 58 with TranslatableMessage

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;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 59 with TranslatableMessage

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;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) PermissionException(com.serotonin.m2m2.vo.permission.PermissionException) ShareUser(com.serotonin.m2m2.view.ShareUser) AnonymousUser(com.serotonin.m2m2.vo.AnonymousUser) User(com.serotonin.m2m2.vo.User) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 60 with TranslatableMessage

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;
}
Also used : TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage)

Aggregations

TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)180 User (com.serotonin.m2m2.vo.User)53 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)52 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)52 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)33 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)33 IOException (java.io.IOException)28 HashMap (java.util.HashMap)27 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)24 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)22 ArrayList (java.util.ArrayList)22 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)20 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)20 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)19 BadRequestException (com.infiniteautomation.mango.rest.v2.exception.BadRequestException)18 NotFoundRestException (com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException)17 File (java.io.File)16 URI (java.net.URI)16 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)12 ResponseEntity (org.springframework.http.ResponseEntity)11