Search in sources :

Example 26 with PublishedPointVO

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

the class PublishedPointServiceTest method newVO.

@Override
PublishedPointVO newVO(User owner) {
    IDataPoint dp = createMockDataPoints(1).get(0);
    MockPublisherVO publisher = createMockPublisher(false);
    MockPublishedPointVO pp = publisher.getDefinition().createPublishedPointVO(publisher, dp);
    pp.setName(dp.getName());
    pp.setEnabled(true);
    return pp;
}
Also used : IDataPoint(com.serotonin.m2m2.vo.IDataPoint) MockPublisherVO(com.serotonin.m2m2.vo.publish.mock.MockPublisherVO) MockPublishedPointVO(com.serotonin.m2m2.vo.publish.mock.MockPublishedPointVO)

Example 27 with PublishedPointVO

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

the class PublishedPointServiceTest method updateVO.

@Override
PublishedPointVO updateVO(PublishedPointVO existing) {
    MockPublishedPointVO vo = (MockPublishedPointVO) existing;
    vo.setTestField("Testing");
    return vo;
}
Also used : MockPublishedPointVO(com.serotonin.m2m2.vo.publish.mock.MockPublishedPointVO)

Example 28 with PublishedPointVO

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

the class PublishedPointServiceTest method testEmport.

@Test
public void testEmport() {
    // Create publisher and publishedPoints
    MockPublisherVO publisher = createMockPublisher(false);
    List<IDataPoint> dps = createMockDataPoints(5);
    List<PublishedPointVO> pps = new ArrayList<>();
    for (IDataPoint dp : dps) {
        MockPublishedPointVO pp = publisher.getDefinition().createPublishedPointVO(publisher, dp);
        pp.setName(dp.getName());
        pp.setEnabled(true);
        pps.add(service.insert(pp));
    }
    // Export publishedPoints
    String[] exportElements = new String[] { "publishedPoints" };
    Map<String, Object> data = ConfigurationExportData.createExportDataMap(exportElements);
    JsonObject json = null;
    try {
        json = JsonSerializableUtility.convertMapToJsonObject(data);
    } catch (JsonException e) {
        fail(e.getMessage());
    }
    // Ensure publishedPoints
    assertEquals(5, json.getJsonArray("publishedPoints").size());
    // Import publishedPoints for update
    loadConfiguration(json);
    assertEquals(5, service.count());
    // Remove publishedPoints
    pps.forEach(p -> service.delete(p));
    assertEquals(0, service.count());
    // Import publishedPoints for create
    loadConfiguration(json);
    assertEquals(5, service.count());
}
Also used : JsonException(com.serotonin.json.JsonException) MockPublisherVO(com.serotonin.m2m2.vo.publish.mock.MockPublisherVO) ArrayList(java.util.ArrayList) JsonObject(com.serotonin.json.type.JsonObject) IDataPoint(com.serotonin.m2m2.vo.IDataPoint) MockPublishedPointVO(com.serotonin.m2m2.vo.publish.mock.MockPublishedPointVO) JsonObject(com.serotonin.json.type.JsonObject) MockPublishedPointVO(com.serotonin.m2m2.vo.publish.mock.MockPublishedPointVO) PublishedPointVO(com.serotonin.m2m2.vo.publish.PublishedPointVO) Test(org.junit.Test)

Example 29 with PublishedPointVO

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

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)

Example 30 with PublishedPointVO

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

the class PublishedPointService method validate.

@Override
public ProcessResult validate(PublishedPointVO existing, PublishedPointVO vo) {
    // validate XID and name
    ProcessResult result = super.validate(vo);
    // Ensure the definition exists
    PublisherDefinition<? extends PublisherVO> definition = ModuleRegistry.getPublisherDefinition(vo.getPublisherTypeName());
    if (definition == null) {
        result.addContextualMessage("publisherTypeName", "validate.invalidValue");
    }
    // ensure the publisher type is not being changed
    if (!existing.getPublisherTypeName().equals(vo.getPublisherTypeName())) {
        result.addContextualMessage("publisherId", "validate.publishedPoints.cantChangeType");
    }
    // Check the publisher exists
    PublisherVO pub = publisherDao.get(vo.getPublisherId());
    if (pub == null) {
        result.addContextualMessage("publisherId", "validate.publisher.missingPublisher", vo.getPublisherId());
    } else {
        vo.setPublisherXid(pub.getXid());
        // don't allow moving to a different publisher
        if (existing.getPublisherId() != vo.getPublisherId()) {
            result.addContextualMessage("publisherId", "validate.publishedPoints.cantChangePublisher");
        }
    }
    // Ensure data point exists
    String dataPointXid = dataPointDao.getXidById(vo.getDataPointId());
    if (dataPointXid == null) {
        result.addContextualMessage("dataPointId", "validate.publisher.missingPoint", vo.getDataPointId());
    } else {
        vo.setDataPointXid(dataPointXid);
        // don't allow changing the point being published
        if (existing.getDataPointId() != vo.getDataPointId()) {
            result.addContextualMessage("dataPointId", "validate.publishedPoints.cantChangeDataPoint");
        }
    }
    if (definition != null && pub != null) {
        definition.validate(result, existing, vo, pub);
    }
    return result;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) PublisherVO(com.serotonin.m2m2.vo.publish.PublisherVO)

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