use of com.serotonin.m2m2.vo.publish.PublisherVO in project ma-core-public by infiniteautomation.
the class PublisherImporter method importImpl.
@Override
protected void importImpl() {
String xid = json.getString("xid");
if (StringUtils.isBlank(xid))
xid = ctx.getPublisherDao().generateUniqueXid();
PublisherVO<?> vo = ctx.getPublisherDao().getPublisher(xid);
if (vo == null) {
String typeStr = json.getString("type");
if (StringUtils.isBlank(typeStr))
addFailureMessage("emport.publisher.missingType", xid, ModuleRegistry.getPublisherDefinitionTypes());
else {
PublisherDefinition def = ModuleRegistry.getPublisherDefinition(typeStr);
if (def == null)
addFailureMessage("emport.publisher.invalidType", xid, typeStr, ModuleRegistry.getPublisherDefinitionTypes());
else {
vo = def.baseCreatePublisherVO();
vo.setXid(xid);
}
}
}
if (vo != null) {
try {
// The VO was found or successfully created. Finish reading it in.
ctx.getReader().readInto(vo, json);
// Now validate it. Use a new response object so we can distinguish errors in this vo from
// other errors.
ProcessResult voResponse = new ProcessResult();
vo.validate(voResponse);
if (voResponse.getHasMessages())
setValidationMessages(voResponse, "emport.publisher.prefix", xid);
else {
// Sweet. Save it.
boolean isnew = vo.isNew();
if (Common.runtimeManager.getState() == RuntimeManager.RUNNING) {
Common.runtimeManager.savePublisher(vo);
addSuccessMessage(isnew, "emport.publisher.prefix", xid);
} else {
addFailureMessage(new ProcessMessage("Runtime manager not running publisher with xid : " + vo.getXid() + " not saved."));
}
}
} catch (TranslatableJsonException e) {
addFailureMessage("emport.publisher.prefix", xid, e.getMsg());
} catch (JsonException e) {
addFailureMessage("emport.publisher.prefix", xid, getJsonExceptionMessage(e));
}
}
}
use of com.serotonin.m2m2.vo.publish.PublisherVO in project ma-core-public by infiniteautomation.
the class EventType method getPublisher.
protected PublisherVO<?> getPublisher(JsonObject json, String name) throws JsonException {
String xid = json.getString(name);
if (xid == null)
throw new TranslatableJsonException("emport.error.eventType.missing.reference", name);
PublisherVO<?> pb = PublisherDao.instance.getPublisher(xid);
if (pb == null)
throw new TranslatableJsonException("emport.error.eventType.invalid.reference", name, xid);
return pb;
}
Aggregations