use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-core-public by infiniteautomation.
the class EventDetectorImporter method importImpl.
@Override
protected void importImpl() {
String dataPointXid = json.getString("dataPointXid");
DataPointVO dpvo;
// Everyone is in the same thread so no synchronization on dataPointMap required.
if (dataPointMap.containsKey(dataPointXid))
dpvo = dataPointMap.get(dataPointXid);
else if (StringUtils.isEmpty(dataPointXid) || (dpvo = DataPointDao.instance.getByXid(dataPointXid)) == null) {
addFailureMessage("emport.error.missingPoint", dataPointXid);
return;
} else {
dataPointMap.put(dataPointXid, dpvo);
// We're only going to use this to house event detectors imported in the eventDetectors object.
dpvo.setEventDetectors(new ArrayList<AbstractPointEventDetectorVO<?>>());
}
String typeStr = json.getString("type");
if (typeStr == null)
addFailureMessage("emport.error.ped.missingAttr", "type");
EventDetectorDefinition<?> def = ModuleRegistry.getEventDetectorDefinition(typeStr);
if (def == null) {
addFailureMessage("emport.error.ped.invalid", "type", typeStr, ModuleRegistry.getEventDetectorDefinitionTypes());
return;
}
JsonArray handlerXids = json.getJsonArray("handlers");
if (handlerXids != null)
for (int k = 0; k < handlerXids.size(); k += 1) {
AbstractEventHandlerVO<?> eh = EventHandlerDao.instance.getByXid(handlerXids.getString(k));
if (eh == null) {
addFailureMessage("emport.eventHandler.missing", handlerXids.getString(k));
return;
}
}
AbstractEventDetectorVO<?> importing = def.baseCreateEventDetectorVO();
importing.setDefinition(def);
String xid = json.getString("xid");
// Create a new one
importing.setId(Common.NEW_ID);
importing.setXid(xid);
AbstractPointEventDetectorVO<?> dped = (AbstractPointEventDetectorVO<?>) importing;
dped.njbSetDataPoint(dpvo);
dpvo.getEventDetectors().add(dped);
try {
ctx.getReader().readInto(importing, json);
// try {
// if(Common.runtimeManager.getState() == RuntimeManager.RUNNING){
// Common.runtimeManager.saveDataPoint(dpvo);
// addSuccessMessage(isNew, "emport.eventDetector.prefix", xid);
// }else{
// addFailureMessage(new ProcessMessage("Runtime Manager not running point with xid: " + xid + " not saved."));
// }
// } catch(LicenseViolatedException e) {
// addFailureMessage(new ProcessMessage(e.getErrorMessage()));
// }
} catch (TranslatableJsonException e) {
addFailureMessage("emport.eventDetector.prefix", xid, e.getMsg());
} catch (JsonException e) {
addFailureMessage("emport.eventDetector.prefix", xid, getJsonExceptionMessage(e));
}
}
use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-core-public by infiniteautomation.
the class JsonDataImporter method importImpl.
@Override
protected void importImpl() {
String xid = json.getString("xid");
boolean isNew = false;
if (StringUtils.isBlank(xid)) {
xid = JsonDataDao.instance.generateUniqueXid();
isNew = true;
}
JsonDataVO vo = JsonDataDao.instance.getByXid(xid);
if (vo == null) {
isNew = true;
vo = new JsonDataVO();
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.jsondata.prefix", xid);
else {
// Sweet. Save it.
JsonDataDao.instance.save(vo);
addSuccessMessage(isNew, "emport.jsondata.prefix", xid);
}
} catch (TranslatableJsonException e) {
addFailureMessage("emport.jsondata.prefix", xid, e.getMsg());
} catch (JsonException e) {
addFailureMessage("emport.jsondata.prefix", xid, getJsonExceptionMessage(e));
}
}
}
use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-core-public by infiniteautomation.
the class MailingListImporter method importImpl.
@Override
protected void importImpl() {
String xid = json.getString("xid");
if (StringUtils.isBlank(xid))
xid = ctx.getMailingListDao().generateUniqueXid();
MailingList vo = ctx.getMailingListDao().getMailingList(xid);
if (vo == null) {
vo = new MailingList();
vo.setXid(xid);
}
try {
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.mailingList.prefix", xid);
else {
// Sweet. Save it.
boolean isnew = vo.getId() == Common.NEW_ID;
ctx.getMailingListDao().saveMailingList(vo);
addSuccessMessage(isnew, "emport.mailingList.prefix", xid);
}
} catch (TranslatableJsonException e) {
addFailureMessage("emport.mailingList.prefix", xid, e.getMsg());
} catch (JsonException e) {
addFailureMessage("emport.mailingList.prefix", xid, getJsonExceptionMessage(e));
}
}
use of com.serotonin.m2m2.i18n.TranslatableJsonException 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.i18n.TranslatableJsonException 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