Search in sources :

Example 16 with PublishedPointVO

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

the class PublishedPointsRestController method exportPublishedPoint.

@ApiOperation(value = "Export formatted for Configuration Import")
@RequestMapping(method = RequestMethod.GET, value = "/export/{xid}", produces = MediaTypes.SEROTONIN_JSON_VALUE)
public Map<String, Object> exportPublishedPoint(@ApiParam(value = "Valid published point XID", required = true) @PathVariable String xid, @AuthenticationPrincipal PermissionHolder user) {
    PublishedPointVO vo = service.get(xid);
    Map<String, Object> export = new LinkedHashMap<>();
    export.put("publishedPoints", Collections.singletonList(vo));
    return export;
}
Also used : PublishedPointVO(com.serotonin.m2m2.vo.publish.PublishedPointVO) LinkedHashMap(java.util.LinkedHashMap) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with PublishedPointVO

use of com.serotonin.m2m2.vo.publish.PublishedPointVO in project ma-core-public by infiniteautomation.

the class PublishedPointDao method mapRecord.

@Override
@NonNull
public PublishedPointVO mapRecord(@NonNull Record record) {
    String publisherType = record.get(publishers.publisherType);
    PublisherDefinition<?> def = ModuleRegistry.getPublisherDefinition(publisherType);
    if (def == null) {
        throw new RuntimeException(new ModuleNotLoadedException(publisherType, "published point", new Exception("Publisher definition not found")));
    }
    PublishedPointVO vo = def.createPublishedPointVO(record.get(table.publisherId), record.get(table.dataPointId));
    vo.setId(record.get(table.id));
    vo.setXid(record.get(table.xid));
    vo.setName(record.get(table.name));
    vo.setEnabled(charToBool(record.get(table.enabled)));
    vo.setJsonData(extractData(record.get(table.jsonData)));
    // Publisher information from join
    vo.setPublisherXid(record.get(publishers.xid));
    vo.setPublisherTypeName(publisherType);
    // Data point information from join
    vo.setDataPointXid(record.get(dataPoints.xid));
    String data = record.get(table.data);
    if (data != null) {
        try {
            def.mapPublishedPointDbData(vo, data);
        } catch (JsonProcessingException e) {
            LOG.error("Failed to read published point JSON for point {}", vo.getXid(), e);
        }
    }
    return vo;
}
Also used : ModuleNotLoadedException(com.serotonin.ModuleNotLoadedException) PublishedPointVO(com.serotonin.m2m2.vo.publish.PublishedPointVO) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ModuleNotLoadedException(com.serotonin.ModuleNotLoadedException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) NonNull(org.checkerframework.checker.nullness.qual.NonNull)

Example 18 with PublishedPointVO

use of com.serotonin.m2m2.vo.publish.PublishedPointVO in project ma-core-public by infiniteautomation.

the class PublishedPointDao method saveEnabledColumn.

/**
 * Update the enabled column
 *
 * @param existing point for which to update the enabled column
 * @param enabled if the point should be enabled or disabled
 * @return updated publshed point
 */
public PublishedPointVO saveEnabledColumn(PublishedPointVO existing, boolean enabled) {
    create.update(table).set(table.enabled, boolToChar(enabled)).where(table.id.eq(existing.getId())).execute();
    PublishedPointVO result = existing.copy();
    result.setEnabled(enabled);
    this.publishEvent(new DaoEvent<>(this, DaoEventType.UPDATE, result, existing));
    this.publishAuditEvent(new ToggleAuditEvent<>(this.auditEventType, Common.getUser(), result));
    return result;
}
Also used : PublishedPointVO(com.serotonin.m2m2.vo.publish.PublishedPointVO)

Example 19 with PublishedPointVO

use of com.serotonin.m2m2.vo.publish.PublishedPointVO in project ma-core-public by infiniteautomation.

the class PublishedPointImporter method importImpl.

@Override
protected void importImpl() {
    String xid = json.getString("xid");
    PublishedPointVO vo = null;
    PublisherVO publisherVO = null;
    DataPointVO dataPointVO = null;
    if (StringUtils.isBlank(xid)) {
        xid = service.generateUniqueXid();
    } else {
        try {
            vo = service.get(xid);
        } catch (NotFoundException e) {
        }
    }
    if (vo == null) {
        String pubXid = json.getString("publisherXid");
        try {
            publisherVO = publisherService.get(pubXid);
        } catch (NotFoundException e) {
            addFailureMessage("emport.publishedPoint.badPublisherReference", xid);
            return;
        }
        String dpXid = json.getString("dataPointXid");
        try {
            dataPointVO = dataPointService.get(dpXid);
        } catch (NotFoundException e) {
            addFailureMessage("emport.publishedPoint.badDataPointReference", xid);
            return;
        }
        vo = publisherVO.getDefinition().createPublishedPointVO(publisherVO, dataPointVO);
        vo.setXid(xid);
    }
    if (vo != null) {
        try {
            // The VO was found or successfully created. Finish reading it in.
            ctx.getReader().readInto(vo, json);
            boolean isnew = vo.isNew();
            if (Common.runtimeManager.getLifecycleState() == ILifecycleState.RUNNING) {
                if (isnew) {
                    service.insert(vo);
                } else {
                    service.update(vo.getId(), vo);
                }
                addSuccessMessage(isnew, "emport.publishedPoint.prefix", xid);
            } else {
                addFailureMessage("emport.publishedPoint.runtimeManagerNotRunning", xid);
            }
        } catch (ValidationException e) {
            setValidationMessages(e.getValidationResult(), "emport.publishedPoint.prefix", xid);
        } catch (TranslatableJsonException e) {
            addFailureMessage("emport.publishedPoint.prefix", xid, e.getMsg());
        } catch (JsonException e) {
            addFailureMessage("emport.publishedPoint.prefix", xid, getJsonExceptionMessage(e));
        }
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonException(com.serotonin.json.JsonException) ValidationException(com.infiniteautomation.mango.util.exception.ValidationException) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) PublisherVO(com.serotonin.m2m2.vo.publish.PublisherVO) PublishedPointVO(com.serotonin.m2m2.vo.publish.PublishedPointVO)

Example 20 with PublishedPointVO

use of com.serotonin.m2m2.vo.publish.PublishedPointVO in project ma-core-public by infiniteautomation.

the class RuntimeManagerImpl method startPublishedPoint.

@Override
public void startPublishedPoint(PublishedPointVO vo) {
    // Ensure that the published point is saved and enabled.
    Assert.isTrue(vo.getId() > 0, "Published point must be saved");
    Assert.isTrue(vo.isEnabled(), "Published point not enabled");
    ensureState(ILifecycleState.INITIALIZING, ILifecycleState.RUNNING);
    // Only add the published point if its publisher is enabled.
    PublisherRT<? extends PublisherVO, ? extends PublishedPointVO, ? extends SendThread> pub = runningPublishers.get(vo.getPublisherId());
    if (pub != null) {
        PublishedPointRT point = publishedPointCache.computeIfAbsent(vo.getId(), k -> new PublishedPointRT(vo, pub));
        // Initialize it, will fail if published point is already initializing or running
        point.initialize(false);
    }
}
Also used : PublishedPointRT(com.serotonin.m2m2.rt.publish.PublishedPointRT)

Aggregations

PublishedPointVO (com.serotonin.m2m2.vo.publish.PublishedPointVO)34 MockPublishedPointVO (com.serotonin.m2m2.vo.publish.mock.MockPublishedPointVO)16 Test (org.junit.Test)12 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)9 IDataPoint (com.serotonin.m2m2.vo.IDataPoint)8 MockPublisherVO (com.serotonin.m2m2.vo.publish.mock.MockPublisherVO)8 JsonException (com.serotonin.json.JsonException)6 PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)6 PublisherVO (com.serotonin.m2m2.vo.publish.PublisherVO)6 NonNull (org.checkerframework.checker.nullness.qual.NonNull)6 NotFoundException (com.infiniteautomation.mango.util.exception.NotFoundException)4 ValidationException (com.infiniteautomation.mango.util.exception.ValidationException)4 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)4 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)4 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)4 PublisherRT (com.serotonin.m2m2.rt.publish.PublisherRT)4 ApiOperation (io.swagger.annotations.ApiOperation)4 ArrayList (java.util.ArrayList)4 URI (java.net.URI)3 HttpHeaders (org.springframework.http.HttpHeaders)3