Search in sources :

Example 66 with DataPointVO

use of com.serotonin.m2m2.vo.DataPointVO in project ma-modules-public by infiniteautomation.

the class PointValueTimeStreamCsvMessageConverter method writeInternal.

@Override
protected void writeInternal(Object object, Type type, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
    MediaType contentType = outputMessage.getHeaders().getContentType();
    JsonEncoding encoding = getJsonEncoding(contentType);
    try {
        PointValueTimeStream<?, ?> stream = (PointValueTimeStream<?, ?>) object;
        stream.setContentType(StreamContentType.CSV);
        JsonGenerator generator = this.objectMapper.getFactory().createGenerator(outputMessage.getBody(), encoding);
        // Set the schema
        CsvSchema.Builder builder = CsvSchema.builder();
        builder.setUseHeader(true);
        // Setup our rendering parameters
        LatestQueryInfo info = stream.getQueryInfo();
        if (stream instanceof MultiPointTimeRangeDatabaseStream || stream instanceof MultiPointLatestDatabaseStream) {
            if (info.isSingleArray()) {
                if (info.isMultiplePointsPerArray()) {
                    Map<Integer, DataPointVO> voMap = stream.getVoMap();
                    Iterator<Integer> it = voMap.keySet().iterator();
                    boolean firstTimestamp = true;
                    while (it.hasNext()) {
                        String xid = voMap.get(it.next()).getXid();
                        for (PointValueField field : info.getFields()) {
                            if (field == PointValueField.TIMESTAMP) {
                                if (firstTimestamp)
                                    field.createColumn(builder, xid);
                                firstTimestamp = false;
                            } else
                                field.createColumn(builder, xid);
                        }
                    }
                } else {
                    for (PointValueField field : info.getFields()) field.createColumn(builder, null);
                }
            } else {
                for (PointValueField field : info.getFields()) field.createColumn(builder, null);
            }
        } else if (stream instanceof MultiDataPointStatisticsQuantizerStream) {
            if (stream.getQueryInfo().isSingleArray()) {
                if (stream.getQueryInfo().isMultiplePointsPerArray()) {
                    Map<Integer, DataPointVO> voMap = stream.getVoMap();
                    Iterator<Integer> it = voMap.keySet().iterator();
                    boolean firstTimestamp = true;
                    while (it.hasNext()) {
                        String xid = voMap.get(it.next()).getXid();
                        for (PointValueField field : info.getFields()) {
                            if (field == PointValueField.TIMESTAMP) {
                                if (firstTimestamp)
                                    field.createColumn(builder, xid);
                                firstTimestamp = false;
                            } else if (field == PointValueField.VALUE) {
                                if (info.getRollup() == RollupEnum.ALL) {
                                    for (RollupEnum rollup : getAllRollups()) {
                                        builder.addColumn(xid + PointValueTimeWriter.DOT + rollup.name(), ColumnType.NUMBER_OR_STRING);
                                    }
                                } else {
                                    field.createColumn(builder, xid);
                                }
                            } else {
                                field.createColumn(builder, xid);
                            }
                        }
                    }
                } else {
                    // Single array
                    if (info.getRollup() == RollupEnum.ALL) {
                        for (RollupEnum rollup : getAllRollups()) {
                            builder.addColumn(rollup.name(), ColumnType.NUMBER_OR_STRING);
                        }
                        for (PointValueField field : info.getFields()) {
                            if (field == PointValueField.VALUE)
                                continue;
                            field.createColumn(builder, null);
                        }
                    } else {
                        for (PointValueField field : info.getFields()) field.createColumn(builder, null);
                    }
                }
            } else {
                if (info.getRollup() == RollupEnum.ALL) {
                    for (RollupEnum rollup : getAllRollups()) {
                        builder.addColumn(rollup.name(), ColumnType.NUMBER_OR_STRING);
                    }
                    for (PointValueField field : info.getFields()) {
                        if (field == PointValueField.VALUE)
                            continue;
                        field.createColumn(builder, null);
                    }
                } else {
                    for (PointValueField field : info.getFields()) field.createColumn(builder, null);
                }
            }
        }
        generator.setSchema(builder.build());
        PointValueTimeWriter writer = new PointValueTimeCsvWriter(stream.getQueryInfo(), stream.getVoMap().size(), generator);
        stream.start(writer);
        stream.streamData(writer);
        stream.finish(writer);
        generator.flush();
    } catch (JsonProcessingException ex) {
        throw new HttpMessageNotWritableException("Could not write content: " + ex.getMessage(), ex);
    }
}
Also used : PointValueTimeStream(com.infiniteautomation.mango.rest.v2.model.pointValue.PointValueTimeStream) MultiDataPointStatisticsQuantizerStream(com.infiniteautomation.mango.rest.v2.model.pointValue.quantize.MultiDataPointStatisticsQuantizerStream) LatestQueryInfo(com.infiniteautomation.mango.rest.v2.model.pointValue.query.LatestQueryInfo) CsvSchema(com.fasterxml.jackson.dataformat.csv.CsvSchema) PointValueTimeCsvWriter(com.infiniteautomation.mango.rest.v2.model.pointValue.PointValueTimeCsvWriter) JsonEncoding(com.fasterxml.jackson.core.JsonEncoding) MultiPointTimeRangeDatabaseStream(com.infiniteautomation.mango.rest.v2.model.pointValue.query.MultiPointTimeRangeDatabaseStream) Iterator(java.util.Iterator) MediaType(org.springframework.http.MediaType) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) RollupEnum(com.serotonin.m2m2.web.mvc.rest.v1.model.time.RollupEnum) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) MultiPointLatestDatabaseStream(com.infiniteautomation.mango.rest.v2.model.pointValue.query.MultiPointLatestDatabaseStream) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) HttpMessageNotWritableException(org.springframework.http.converter.HttpMessageNotWritableException) PointValueTimeWriter(com.infiniteautomation.mango.rest.v2.model.pointValue.PointValueTimeWriter) Map(java.util.Map) PointValueField(com.infiniteautomation.mango.rest.v2.model.pointValue.PointValueField)

Example 67 with DataPointVO

use of com.serotonin.m2m2.vo.DataPointVO in project ma-modules-public by infiniteautomation.

the class MBusEditDwr method changeMBusAddress.

@DwrPermission(user = true)
public Map<String, Object> changeMBusAddress(int deviceIndex, String newAddress) {
    Map<String, Object> result = new HashMap<>();
    result.put("deviceIndex", deviceIndex);
    MBusDiscovery test = Common.getUser().getTestingUtility(MBusDiscovery.class);
    if (test == null) {
        return null;
    }
    try {
        final byte oldAddress = test.getDevice(deviceIndex).getAddress();
        byte address;
        if (newAddress.startsWith("0x")) {
            address = (byte) Short.parseShort(newAddress.substring(2), 16);
        } else {
            address = (byte) Short.parseShort(newAddress);
        }
        if (test.changeAddress(deviceIndex, address, result)) {
            // if address was changed, then change existing datapoints enabled disabled
            final DataSourceVO<?> ds = Common.getUser().getEditDataSource();
            List<DataPointVO> dpVos = DataPointDao.instance.getDataPoints(ds.getId(), null);
            for (DataPointVO dpVo : dpVos) {
                final MBusPointLocatorVO pl = dpVo.getPointLocator();
                if (pl.getAddress() == oldAddress) {
                    pl.setAddress(address);
                    Common.runtimeManager.saveDataPoint(dpVo);
                }
            }
        }
        result.put("points", getPoints());
    } catch (IOException | InterruptedException e) {
        return null;
    }
    return result;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) HashMap(java.util.HashMap) IOException(java.io.IOException) MBusPointLocatorVO(com.serotonin.m2m2.mbus.MBusPointLocatorVO) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 68 with DataPointVO

use of com.serotonin.m2m2.vo.DataPointVO 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 69 with DataPointVO

use of com.serotonin.m2m2.vo.DataPointVO in project ma-modules-public by infiniteautomation.

the class GraphicalViewDwr method saveCompoundPoints.

private void saveCompoundPoints(CompoundComponent c, List<StringStringPair> childPointIds) {
    User user = Common.getUser();
    for (StringStringPair kvp : childPointIds) {
        int dataPointId = -1;
        try {
            dataPointId = Integer.parseInt(kvp.getValue());
        } catch (NumberFormatException e) {
        // no op
        }
        DataPointVO dp = DataPointDao.instance.getDataPoint(dataPointId);
        if (dp == null || !Permissions.hasDataPointReadPermission(user, dp))
            c.setDataPoint(kvp.getKey(), null);
        else
            c.setDataPoint(kvp.getKey(), dp);
        c.getChildComponent(kvp.getKey()).validateDataPoint(user, false);
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) StringStringPair(com.serotonin.db.pair.StringStringPair) ShareUser(com.serotonin.m2m2.view.ShareUser) AnonymousUser(com.serotonin.m2m2.vo.AnonymousUser) User(com.serotonin.m2m2.vo.User)

Example 70 with DataPointVO

use of com.serotonin.m2m2.vo.DataPointVO in project ma-modules-public by infiniteautomation.

the class GraphicalViewDwr method setPointComponentSettings.

@DwrPermission(user = true)
public ProcessResult setPointComponentSettings(String pointComponentId, int dataPointId, String name, boolean settable, String bkgdColorOverride, int updatePeriodType, int updatePeriods, boolean displayControls, int x, int y) {
    ProcessResult response = new ProcessResult();
    PointComponent pc = (PointComponent) getViewComponent(pointComponentId);
    User user = Common.getUser();
    DataPointVO dp = DataPointDao.instance.getDataPoint(dataPointId);
    if (dp == null || !Permissions.hasDataPointReadPermission(user, dp))
        response.addContextualMessage("settingsPointInfo", "validate.required");
    if (!Common.TIME_PERIOD_CODES.isValidId(updatePeriodType))
        response.addContextualMessage("settingsUpdatePeriodType", "validate.invalidValue");
    if (updatePeriods < 0)
        response.addContextualMessage("settingsUpdatePeriods", "validate.cannotBeNegative");
    if (x < 0)
        response.addContextualMessage("settingsX", "validate.cannotBeNegative");
    if (y < 0)
        response.addContextualMessage("settingsY", "validate.cannotBeNegative");
    if (!response.getHasMessages()) {
        pc.tsetDataPoint(dp);
        pc.setNameOverride(name);
        pc.setSettableOverride(settable && Permissions.hasDataPointSetPermission(user, dp));
        pc.setBkgdColorOverride(bkgdColorOverride);
        pc.setUpdatePeriodType(updatePeriodType);
        pc.setUpdatePeriods(updatePeriods);
        pc.setDisplayControls(displayControls);
        pc.setLocation(x, y);
        pc.validateDataPoint(user, false);
        response.addData("x", x);
        response.addData("y", y);
    }
    return response;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) ShareUser(com.serotonin.m2m2.view.ShareUser) AnonymousUser(com.serotonin.m2m2.vo.AnonymousUser) User(com.serotonin.m2m2.vo.User) PointComponent(com.serotonin.m2m2.gviews.component.PointComponent) SimplePointComponent(com.serotonin.m2m2.gviews.component.SimplePointComponent) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Aggregations

DataPointVO (com.serotonin.m2m2.vo.DataPointVO)196 User (com.serotonin.m2m2.vo.User)62 ArrayList (java.util.ArrayList)53 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)48 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)40 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)40 HashMap (java.util.HashMap)35 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)33 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)32 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)30 NotFoundRestException (com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException)29 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)28 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)26 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)21 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)21 AnnotatedPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime)16 AbstractPointEventDetectorVO (com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO)15 List (java.util.List)15 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)14 IOException (java.io.IOException)12