use of com.infiniteautomation.mango.util.exception.ValidationException in project ma-core-public by MangoAutomation.
the class EventHandlerImporter method importImpl.
@Override
protected void importImpl() {
AbstractEventHandlerVO handler = null;
String xid = json.getString("xid");
if (StringUtils.isBlank(xid)) {
xid = service.generateUniqueXid();
} else {
try {
handler = service.get(xid);
} catch (NotFoundException e) {
// Nothing, done below
}
}
if (handler == null) {
String typeStr = json.getString("handlerType");
if (StringUtils.isBlank(typeStr))
addFailureMessage("emport.eventHandler.missingType", xid, ModuleRegistry.getEventHandlerDefinitionTypes());
else {
EventHandlerDefinition<?> def = ModuleRegistry.getEventHandlerDefinition(typeStr);
if (def == null)
addFailureMessage("emport.eventHandler.invalidType", xid, typeStr, ModuleRegistry.getEventHandlerDefinitionTypes());
else {
handler = def.baseCreateEventHandlerVO();
handler.setXid(xid);
}
}
}
JsonObject et = json.getJsonObject("eventType");
JsonArray ets = json.getJsonArray("eventTypes");
if (handler != null) {
try {
ctx.getReader().readInto(handler, json);
Set<EventTypeMatcher> eventTypes = new HashSet<>(handler.getEventTypes());
// Find the event type.
if (et != null) {
eventTypes.add(new EventTypeMatcher(ctx.getReader().read(EventType.class, et)));
} else if (ets != null) {
for (JsonValue jsonValue : ets) {
eventTypes.add(new EventTypeMatcher(ctx.getReader().read(EventType.class, jsonValue)));
}
}
handler.setEventTypes(new ArrayList<>(eventTypes));
boolean isnew = handler.getId() == Common.NEW_ID;
if (isnew) {
service.insert(handler);
addSuccessMessage(true, "emport.eventHandler.prefix", xid);
} else {
service.update(handler.getId(), handler);
addSuccessMessage(false, "emport.eventHandler.prefix", xid);
}
} catch (ValidationException e) {
setValidationMessages(e.getValidationResult(), "emport.eventHandler.prefix", xid);
} catch (TranslatableJsonException e) {
addFailureMessage("emport.eventHandler.prefix", xid, e.getMsg());
} catch (JsonException e) {
addFailureMessage("emport.eventHandler.prefix", xid, getJsonExceptionMessage(e));
}
}
}
use of com.infiniteautomation.mango.util.exception.ValidationException in project ma-core-public by MangoAutomation.
the class JsonDataImporter method importImpl.
@Override
protected void importImpl() {
String xid = json.getString("xid");
JsonDataVO vo = null;
boolean isNew = false;
if (StringUtils.isBlank(xid)) {
xid = service.generateUniqueXid();
} else {
try {
vo = service.get(xid);
} catch (NotFoundException e) {
}
}
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);
// Ensure we have a default permission since null is valid in Mango 3.x
if (vo.getReadPermission() == null) {
vo.setReadPermission(new MangoPermission());
}
if (vo.getEditPermission() == null) {
vo.setEditPermission(new MangoPermission());
}
if (isNew) {
service.insert(vo);
} else {
service.update(vo.getId(), vo);
}
addSuccessMessage(isNew, "emport.jsondata.prefix", xid);
} catch (ValidationException e) {
setValidationMessages(e.getValidationResult(), "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.infiniteautomation.mango.util.exception.ValidationException in project ma-core-public by MangoAutomation.
the class MailingListImporter method importImpl.
@Override
protected void importImpl() {
String xid = json.getString("xid");
MailingList vo = null;
if (StringUtils.isBlank(xid)) {
xid = service.generateUniqueXid();
} else {
try {
vo = service.get(xid);
} catch (NotFoundException e) {
}
}
if (vo == null) {
vo = new MailingList();
vo.setXid(xid);
}
try {
ctx.getReader().readInto(vo, json);
// Ensure we have a default permission since null is valid in Mango 3.x
if (vo.getReadPermission() == null) {
vo.setReadPermission(new MangoPermission());
}
if (vo.getEditPermission() == null) {
vo.setEditPermission(new MangoPermission());
}
boolean isnew = vo.getId() == Common.NEW_ID;
if (isnew) {
service.insert(vo);
} else {
service.update(vo.getId(), vo);
}
addSuccessMessage(isnew, "emport.mailingList.prefix", xid);
} catch (ValidationException e) {
setValidationMessages(e.getValidationResult(), "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.infiniteautomation.mango.util.exception.ValidationException in project ma-core-public by MangoAutomation.
the class PermissionImporter method importImpl.
@Override
protected void importImpl() {
Iterator<String> it = json.keySet().iterator();
if (it.hasNext()) {
String permissionType = it.next();
PermissionDefinition def = ModuleRegistry.getPermissionDefinition(permissionType);
if (def != null) {
try {
JsonValue v = json.get(permissionType);
if (v != null) {
MangoPermission permission = ctx.getReader().read(MangoPermission.class, v);
service.update(permission, def);
}
addSuccessMessage(false, "emport.permission.prefix", permissionType);
} catch (ValidationException e) {
setValidationMessages(e.getValidationResult(), "emport.permission.prefix", permissionType);
} catch (JsonException e) {
addFailureMessage("emport.permission.prefix", permissionType, getJsonExceptionMessage(e));
}
}
}
}
use of com.infiniteautomation.mango.util.exception.ValidationException 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));
}
}
}
Aggregations