use of com.serotonin.m2m2.vo.publish.PublishedPointVO in project ma-modules-public by infiniteautomation.
the class PublishedPointsRestController method exportPublishedPoint.
@ApiOperation(value = "Export formatted for Configuration Import")
@RequestMapping(method = RequestMethod.GET, value = "/export/{xid}", produces = MediaTypes.SEROTONIN_JSON_VALUE)
public Map<String, Object> exportPublishedPoint(@ApiParam(value = "Valid published point XID", required = true) @PathVariable String xid, @AuthenticationPrincipal PermissionHolder user) {
PublishedPointVO vo = service.get(xid);
Map<String, Object> export = new LinkedHashMap<>();
export.put("publishedPoints", Collections.singletonList(vo));
return export;
}
use of com.serotonin.m2m2.vo.publish.PublishedPointVO in project ma-core-public by infiniteautomation.
the class PublishedPointDao method mapRecord.
@Override
@NonNull
public PublishedPointVO mapRecord(@NonNull Record record) {
String publisherType = record.get(publishers.publisherType);
PublisherDefinition<?> def = ModuleRegistry.getPublisherDefinition(publisherType);
if (def == null) {
throw new RuntimeException(new ModuleNotLoadedException(publisherType, "published point", new Exception("Publisher definition not found")));
}
PublishedPointVO vo = def.createPublishedPointVO(record.get(table.publisherId), record.get(table.dataPointId));
vo.setId(record.get(table.id));
vo.setXid(record.get(table.xid));
vo.setName(record.get(table.name));
vo.setEnabled(charToBool(record.get(table.enabled)));
vo.setJsonData(extractData(record.get(table.jsonData)));
// Publisher information from join
vo.setPublisherXid(record.get(publishers.xid));
vo.setPublisherTypeName(publisherType);
// Data point information from join
vo.setDataPointXid(record.get(dataPoints.xid));
String data = record.get(table.data);
if (data != null) {
try {
def.mapPublishedPointDbData(vo, data);
} catch (JsonProcessingException e) {
LOG.error("Failed to read published point JSON for point {}", vo.getXid(), e);
}
}
return vo;
}
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 existing point for which to update the enabled column
* @param enabled if the point should be enabled or disabled
* @return updated publshed point
*/
public PublishedPointVO saveEnabledColumn(PublishedPointVO existing, boolean enabled) {
create.update(table).set(table.enabled, boolToChar(enabled)).where(table.id.eq(existing.getId())).execute();
PublishedPointVO result = existing.copy();
result.setEnabled(enabled);
this.publishEvent(new DaoEvent<>(this, DaoEventType.UPDATE, result, existing));
this.publishAuditEvent(new ToggleAuditEvent<>(this.auditEventType, Common.getUser(), result));
return result;
}
use of com.serotonin.m2m2.vo.publish.PublishedPointVO in project ma-core-public by infiniteautomation.
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 infiniteautomation.
the class RuntimeManagerImpl method startPublishedPoint.
@Override
public void startPublishedPoint(PublishedPointVO vo) {
// Ensure that the published point is saved and enabled.
Assert.isTrue(vo.getId() > 0, "Published point must be saved");
Assert.isTrue(vo.isEnabled(), "Published point not enabled");
ensureState(ILifecycleState.INITIALIZING, ILifecycleState.RUNNING);
// Only add the published point if its publisher is enabled.
PublisherRT<? extends PublisherVO, ? extends PublishedPointVO, ? extends SendThread> pub = runningPublishers.get(vo.getPublisherId());
if (pub != null) {
PublishedPointRT point = publishedPointCache.computeIfAbsent(vo.getId(), k -> new PublishedPointRT(vo, pub));
// Initialize it, will fail if published point is already initializing or running
point.initialize(false);
}
}
Aggregations