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