use of com.serotonin.m2m2.module.TemplateDefinition in project ma-core-public by infiniteautomation.
the class TemplateImporter method importImpl.
@Override
protected void importImpl() {
String xid = json.getString("xid");
if (StringUtils.isBlank(xid))
xid = TemplateDao.instance.generateUniqueXid();
BaseTemplateVO<?> vo = TemplateDao.instance.getByXid(xid);
if (vo == null) {
String typeStr = json.getString("templateType");
if (StringUtils.isBlank(typeStr))
addFailureMessage("emport.template.missingType", xid, ModuleRegistry.getTemplateDefinitionTypes());
else {
TemplateDefinition def = ModuleRegistry.getTemplateDefinition(typeStr);
if (def == null)
addFailureMessage("emport.template.invalidType", xid, typeStr, ModuleRegistry.getTemplateDefinitionTypes());
else {
vo = def.baseCreateTemplateVO();
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.template.prefix", xid);
else {
// Sweet. Save it.
boolean isnew = vo.isNew();
TemplateDao.instance.save(vo);
addSuccessMessage(isnew, "emport.template.prefix", xid);
}
} catch (TranslatableJsonException e) {
addFailureMessage("emport.template.prefix", xid, e.getMsg());
} catch (JsonException e) {
addFailureMessage("emport.template.prefix", xid, getJsonExceptionMessage(e));
}
}
}
use of com.serotonin.m2m2.module.TemplateDefinition in project ma-core-public by infiniteautomation.
the class TemplateRestorer method buildNewVO.
@Override
protected BaseTemplateVO<?> buildNewVO(JsonObject json) {
BaseTemplateVO<?> vo = null;
String xid = json.getString("xid");
String typeStr = json.getString("templateType");
if (StringUtils.isBlank(typeStr))
addFailureMessage("emport.template.missingType", xid, ModuleRegistry.getTemplateDefinitionTypes());
else {
TemplateDefinition def = ModuleRegistry.getTemplateDefinition(typeStr);
if (def == null)
addFailureMessage("emport.template.invalidType", xid, typeStr, ModuleRegistry.getTemplateDefinitionTypes());
else {
vo = def.baseCreateTemplateVO();
}
}
return vo;
}
use of com.serotonin.m2m2.module.TemplateDefinition in project ma-core-public by infiniteautomation.
the class ModuleRegistry method ensureTemplateDefinitions.
private static void ensureTemplateDefinitions() {
if (TEMPLATE_DEFINITIONS == null) {
synchronized (LOCK) {
if (TEMPLATE_DEFINITIONS == null) {
Map<String, TemplateDefinition> map = new HashMap<String, TemplateDefinition>();
for (TemplateDefinition def : Module.getDefinitions(preDefaults, TemplateDefinition.class)) {
map.put(def.getTemplateTypeName(), def);
}
for (Module module : MODULES.values()) {
for (TemplateDefinition def : module.getDefinitions(TemplateDefinition.class)) map.put(def.getTemplateTypeName(), def);
}
for (TemplateDefinition def : Module.getDefinitions(postDefaults, TemplateDefinition.class)) {
map.put(def.getTemplateTypeName(), def);
}
TEMPLATE_DEFINITIONS = map;
}
}
}
}
Aggregations