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;
}
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;
}
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());
}
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());
}
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;
}
Aggregations