Search in sources :

Example 46 with PublishedPointVO

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

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 47 with PublishedPointVO

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

the class PublisherRTQueueMonitorTest method testQueueMonitor.

@Test(timeout = 1 * 60 * 1000)
public void testQueueMonitor() {
    // create DS and DP and enable them (need to be running)
    MockDataSourceVO dataSource = this.createMockDataSource(true);
    DataPointVO dataPoint = this.createMockDataPoint(dataSource, new MockPointLocatorVO(DataType.NUMERIC, true), true);
    // create publisher with a published point (this is a listener) for the DP
    TestPublisherVO publisherVO = (TestPublisherVO) createMockPublisher(true);
    List<PublishedPointVO> points = createMockPublishedPoints(publisherVO, Collections.singletonList(dataPoint), true);
    // get the running data point RT from the Common.runtimeManager
    DataPointRT rt = Common.runtimeManager.getDataPoint(dataPoint.getId());
    // MockBackgroundProcessing
    // set PV(s) to the RT
    // Note: the publish point will be notified by DataPointEventNotifyWorkItem
    PointValueTime newValue = new PointValueTime(1.0, this.timer.currentTimeMillis());
    rt.setPointValue(newValue, null);
    try {
        /* Waiting for the PublishQueue.add to happen...
             * because I know that PublishQueue.lastSizeCheck is 0,
             * the fist time the PublishQueue.sizeCheck() will happen
             */
        publisherVO.getAddedFuture().get();
    } catch (InterruptedException | ExecutionException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    // confirm publish queue is of certain size
    String monitor = QUEUE_SIZE_MONITOR_ID + publisherVO.getXid();
    Assert.assertNotNull(Common.MONITORED_VALUES.getMonitor(monitor).getName());
    Assert.assertEquals(1, Common.MONITORED_VALUES.getMonitor(monitor).getValue());
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) MockDataSourceVO(com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) MockPublishedPointVO(com.serotonin.m2m2.vo.publish.mock.MockPublishedPointVO) PublishedPointVO(com.serotonin.m2m2.vo.publish.PublishedPointVO) ExecutionException(java.util.concurrent.ExecutionException) MockPointLocatorVO(com.serotonin.m2m2.vo.dataPoint.MockPointLocatorVO) Test(org.junit.Test)

Example 48 with PublishedPointVO

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

the class PublishedPointServiceTest method testSetPublishedPointState.

@Test
public void testSetPublishedPointState() {
    // Start out with a running publisher and an enabled point
    IDataPoint dp = createMockDataPoints(1).get(0);
    MockPublisherVO publisher = createMockPublisher(true);
    MockPublishedPointVO pp = publisher.getDefinition().createPublishedPointVO(publisher, dp);
    pp.setName(dp.getName());
    pp.setEnabled(true);
    PublishedPointVO vo = service.insert(pp);
    assertTrue(service.setPublishedPointState(vo.getXid(), false, false));
    // Ensure it is not running
    assertNull(getRuntimeManager().getPublishedPoint(vo.getId()));
    assertTrue(service.setPublishedPointState(vo.getXid(), true, false));
    // Ensure it is running
    assertNotNull(getRuntimeManager().getPublishedPoint(vo.getId()));
}
Also used : IDataPoint(com.serotonin.m2m2.vo.IDataPoint) MockPublisherVO(com.serotonin.m2m2.vo.publish.mock.MockPublisherVO) MockPublishedPointVO(com.serotonin.m2m2.vo.publish.mock.MockPublishedPointVO) MockPublishedPointVO(com.serotonin.m2m2.vo.publish.mock.MockPublishedPointVO) PublishedPointVO(com.serotonin.m2m2.vo.publish.PublishedPointVO) Test(org.junit.Test)

Example 49 with PublishedPointVO

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

the class PublishedPointServiceTest method testNonAdminUpdate.

@Test(expected = PermissionException.class)
public void testNonAdminUpdate() {
    PublishedPointVO vo = insertNewVO(readUser);
    PublishedPointVO fromDb = service.get(vo.getId());
    assertVoEqual(vo, fromDb);
    PublishedPointVO updated = updateVO(vo);
    runAs.runAs(readUser, () -> {
        service.update(vo.getId(), updated);
    });
}
Also used : MockPublishedPointVO(com.serotonin.m2m2.vo.publish.mock.MockPublishedPointVO) PublishedPointVO(com.serotonin.m2m2.vo.publish.PublishedPointVO) Test(org.junit.Test)

Example 50 with PublishedPointVO

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

the class PublishedPointServiceTest method testDeletePoint.

@Test(expected = NotFoundException.class)
public void testDeletePoint() {
    IDataPoint dp = createMockDataPoints(1).get(0);
    MockPublisherVO publisher = createMockPublisher(true);
    MockPublishedPointVO pp = publisher.getDefinition().createPublishedPointVO(publisher, dp);
    pp.setName(dp.getName());
    pp.setEnabled(true);
    PublishedPointVO vo = service.insert(pp);
    // Ensure it is running
    assertNotNull(getRuntimeManager().getPublishedPoint(vo.getId()));
    DataPointVO point = dataPointService.get(dp.getId());
    // Delete datapoint
    dataPointService.delete(point);
    // Ensure published point deleted
    service.get(pp.getId());
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) IDataPoint(com.serotonin.m2m2.vo.IDataPoint) MockPublisherVO(com.serotonin.m2m2.vo.publish.mock.MockPublisherVO) MockPublishedPointVO(com.serotonin.m2m2.vo.publish.mock.MockPublishedPointVO) MockPublishedPointVO(com.serotonin.m2m2.vo.publish.mock.MockPublishedPointVO) PublishedPointVO(com.serotonin.m2m2.vo.publish.PublishedPointVO) Test(org.junit.Test)

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