Search in sources :

Example 41 with PublishedPointVO

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

the class PublisherRT method initializePoints.

/**
 * The {@link PublishedPointGroupInitializer} calls
 * {@link RuntimeManager#startPublishedPoint(PublishedPointVO) startPublishedPoint()}
 * which adds the points to the cache in the RTM and initializes them.
 */
private void initializePoints() {
    ExecutorService executorService = Common.getBean(ExecutorService.class);
    // Add the enabled points to the data source.
    List<PublishedPointVO> points = publishedPointDao.getEnabledPublishedPoints(getId());
    // Startup multi threaded
    int pointsPerThread = Common.envProps.getInt("runtime.publishedPoint.startupThreads.pointsPerThread", 1000);
    int startupThreads = Common.envProps.getInt("runtime.publishedPoint.startupThreads", Runtime.getRuntime().availableProcessors());
    PublishedPointGroupInitializer pointInitializer = new PublishedPointGroupInitializer(executorService, startupThreads);
    pointInitializer.initialize(points, pointsPerThread);
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) PublishedPointGroupInitializer(com.serotonin.m2m2.rt.PublishedPointGroupInitializer) PublishedPointVO(com.serotonin.m2m2.vo.publish.PublishedPointVO)

Example 42 with PublishedPointVO

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

the class PublisherImporter method importImpl.

@Override
protected void importImpl() {
    String xid = json.getString("xid");
    PublisherVO vo = null;
    if (StringUtils.isBlank(xid)) {
        xid = service.generateUniqueXid();
    } else {
        try {
            vo = service.get(xid);
        } catch (NotFoundException e) {
        }
    }
    if (vo == null) {
        String typeStr = json.getString("type");
        if (StringUtils.isBlank(typeStr))
            addFailureMessage("emport.publisher.missingType", xid, ModuleRegistry.getPublisherDefinitionTypes());
        else {
            PublisherDefinition<?> def = ModuleRegistry.getPublisherDefinition(typeStr);
            if (def == null)
                addFailureMessage("emport.publisher.invalidType", xid, typeStr, ModuleRegistry.getPublisherDefinitionTypes());
            else {
                vo = def.baseCreatePublisherVO();
                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.publisher.prefix", xid);
                // Handle embedded points (pre Mango 4.3 this was the case)
                JsonArray arr = json.getJsonArray("points");
                if (arr != null) {
                    for (JsonValue jv : arr) {
                        String dataPointXid = jv.getJsonValue("dataPointId").toString();
                        try {
                            DataPointVO dataPointVO = dataPointService.get(dataPointXid);
                            PublishedPointVO point = vo.getDefinition().createPublishedPointVO(vo, dataPointVO);
                            point.setName(dataPointVO.getName());
                            ctx.getReader().readInto(point, jv.toJsonObject());
                            point.setXid(publishedPointService.generateUniqueXid());
                            publishedPointService.insert(point);
                            addSuccessMessage(isnew, "emport.publishedPoint.prefix", point.getXid());
                        } catch (NotFoundException e) {
                            addFailureMessage("emport.publisher.prefix", xid, new TranslatableMessage("emport.error.missingPoint", dataPointXid));
                        } catch (ValidationException e) {
                            for (ProcessMessage m : e.getValidationResult().getMessages()) {
                                addFailureMessage(new ProcessMessage("emport.publisher.prefix", new TranslatableMessage("literal", xid), m));
                            }
                        }
                    }
                }
            } else {
                addFailureMessage("emport.publisher.runtimeManagerNotRunning", xid);
            }
        } catch (ValidationException e) {
            setValidationMessages(e.getValidationResult(), "emport.publisher.prefix", xid);
        } catch (TranslatableJsonException e) {
            addFailureMessage("emport.publisher.prefix", xid, e.getMsg());
        } catch (JsonException e) {
            addFailureMessage("emport.publisher.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) JsonValue(com.serotonin.json.type.JsonValue) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonArray(com.serotonin.json.type.JsonArray) ProcessMessage(com.serotonin.m2m2.i18n.ProcessMessage) PublisherVO(com.serotonin.m2m2.vo.publish.PublisherVO) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) PublishedPointVO(com.serotonin.m2m2.vo.publish.PublishedPointVO)

Example 43 with PublishedPointVO

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

the class MockRuntimeManager method stopPublishedPoint.

@Override
public void stopPublishedPoint(int id) {
    if (useDatabase) {
        PublishedPointVO vo = PublishedPointDao.getInstance().get(id);
        vo.setEnabled(false);
        PublishedPointDao.getInstance().saveEnabledColumn(vo);
    }
}
Also used : PublishedPointVO(com.serotonin.m2m2.vo.publish.PublishedPointVO)

Example 44 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 pp point for which to update the enabled column
 */
public void saveEnabledColumn(PublishedPointVO pp) {
    PublishedPointVO existing = get(pp.getId());
    saveEnabledColumn(existing, pp.isEnabled());
}
Also used : PublishedPointVO(com.serotonin.m2m2.vo.publish.PublishedPointVO)

Example 45 with PublishedPointVO

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

the class PublisherImporter method importImpl.

@Override
protected void importImpl() {
    String xid = json.getString("xid");
    PublisherVO vo = null;
    if (StringUtils.isBlank(xid)) {
        xid = service.generateUniqueXid();
    } else {
        try {
            vo = service.get(xid);
        } catch (NotFoundException e) {
        }
    }
    if (vo == null) {
        String typeStr = json.getString("type");
        if (StringUtils.isBlank(typeStr))
            addFailureMessage("emport.publisher.missingType", xid, ModuleRegistry.getPublisherDefinitionTypes());
        else {
            PublisherDefinition<?> def = ModuleRegistry.getPublisherDefinition(typeStr);
            if (def == null)
                addFailureMessage("emport.publisher.invalidType", xid, typeStr, ModuleRegistry.getPublisherDefinitionTypes());
            else {
                vo = def.baseCreatePublisherVO();
                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.publisher.prefix", xid);
                // Handle embedded points (pre Mango 4.3 this was the case)
                JsonArray arr = json.getJsonArray("points");
                if (arr != null) {
                    for (JsonValue jv : arr) {
                        String dataPointXid = jv.getJsonValue("dataPointId").toString();
                        try {
                            DataPointVO dataPointVO = dataPointService.get(dataPointXid);
                            PublishedPointVO point = vo.getDefinition().createPublishedPointVO(vo, dataPointVO);
                            point.setName(dataPointVO.getName());
                            ctx.getReader().readInto(point, jv.toJsonObject());
                            point.setXid(publishedPointService.generateUniqueXid());
                            publishedPointService.insert(point);
                            addSuccessMessage(isnew, "emport.publishedPoint.prefix", point.getXid());
                        } catch (NotFoundException e) {
                            addFailureMessage("emport.publisher.prefix", xid, new TranslatableMessage("emport.error.missingPoint", dataPointXid));
                        } catch (ValidationException e) {
                            for (ProcessMessage m : e.getValidationResult().getMessages()) {
                                addFailureMessage(new ProcessMessage("emport.publisher.prefix", new TranslatableMessage("literal", xid), m));
                            }
                        }
                    }
                }
            } else {
                addFailureMessage("emport.publisher.runtimeManagerNotRunning", xid);
            }
        } catch (ValidationException e) {
            setValidationMessages(e.getValidationResult(), "emport.publisher.prefix", xid);
        } catch (TranslatableJsonException e) {
            addFailureMessage("emport.publisher.prefix", xid, e.getMsg());
        } catch (JsonException e) {
            addFailureMessage("emport.publisher.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) JsonValue(com.serotonin.json.type.JsonValue) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonArray(com.serotonin.json.type.JsonArray) ProcessMessage(com.serotonin.m2m2.i18n.ProcessMessage) PublisherVO(com.serotonin.m2m2.vo.publish.PublisherVO) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) PublishedPointVO(com.serotonin.m2m2.vo.publish.PublishedPointVO)

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