use of com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO in project ma-core-public by infiniteautomation.
the class DataSourceEditDwr method validatePoint.
protected ProcessResult validatePoint(int id, String xid, String name, PointLocatorVO<?> locator, DataPointDefaulter defaulter, boolean includePointList) {
ProcessResult response = new ProcessResult();
// This saving of the point into the User is a bad idea, need to rework to
// pass the point back and forth to page.
DataPointVO dp = getPoint(id, defaulter);
dp.setXid(xid);
dp.setName(name);
dp.setPointLocator(locator);
// Confirm that we are assinging a point to the correct data source
DataSourceVO<?> ds = DataSourceDao.instance.get(dp.getDataSourceId());
PointLocatorVO<?> plvo = ds.createPointLocator();
if (plvo.getClass() != locator.getClass()) {
response.addGenericMessage("validate.invalidType");
return response;
}
// If we are a new point then only validate the basics
if (id == Common.NEW_ID) {
if (StringUtils.isBlank(xid))
response.addContextualMessage("xid", "validate.required");
else if (StringValidation.isLengthGreaterThan(xid, 50))
response.addMessage("xid", new TranslatableMessage("validate.notLongerThan", 50));
else if (!DataPointDao.instance.isXidUnique(xid, id))
response.addContextualMessage("xid", "validate.xidUsed");
if (StringUtils.isBlank(name))
response.addContextualMessage("name", "validate.required");
// Load in the default Template
DataPointPropertiesTemplateVO template = TemplateDao.instance.getDefaultDataPointTemplate(locator.getDataTypeId());
if (template != null) {
template.updateDataPointVO(dp);
}
// Should really be done elsewhere
dp.setEventDetectors(new ArrayList<AbstractPointEventDetectorVO<?>>());
} else if (id == DataPointDwr.COPY_ID) {
dp.setId(Common.NEW_ID);
if (StringUtils.isBlank(xid))
response.addContextualMessage("xid", "validate.required");
else if (StringValidation.isLengthGreaterThan(xid, 50))
response.addMessage("xid", new TranslatableMessage("validate.notLongerThan", 50));
else if (!DataPointDao.instance.isXidUnique(xid, id))
response.addContextualMessage("xid", "validate.xidUsed");
if (StringUtils.isBlank(name))
response.addContextualMessage("name", "validate.required");
} else {
// New validation on save for all settings on existing points
dp.validate(response);
if (dp.getChartRenderer() != null)
dp.getChartRenderer().validate(response);
if (dp.getTextRenderer() != null)
dp.getTextRenderer().validate(response);
}
// Validate Locator
locator.validate(response, dp);
if (!response.getHasMessages()) {
try {
Common.runtimeManager.saveDataPoint(dp);
} catch (DuplicateKeyException e) {
response.addGenericMessage("pointEdit.detectors.duplicateXid");
return response;
} catch (LicenseViolatedException e) {
response.addMessage(e.getErrorMessage());
return response;
}
if (defaulter != null)
defaulter.postSave(dp);
response.addData("id", dp.getId());
response.addData("vo", dp);
if (includePointList)
response.addData("points", getPoints());
// Set the User Point
Common.getUser().setEditPoint(dp);
}
return response;
}
use of com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO in project ma-core-public by infiniteautomation.
the class TemplateDwr method getNewDataPointTemplate.
/**
* Get a new Data Point Template
* @return
*/
@DwrPermission(user = true)
public ProcessResult getNewDataPointTemplate() {
ProcessResult response = new ProcessResult();
DataPointPropertiesTemplateVO vo = new DataPointPropertiesTemplateVO();
vo.setDefinition(new DataPointPropertiesTemplateDefinition());
response.addData("vo", vo);
return response;
}
use of com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO in project ma-core-public by infiniteautomation.
the class TemplateDwr method saveDataPointTemplate.
/**
* Save a Data Point template
* @return
*/
@DwrPermission(user = true)
public ProcessResult saveDataPointTemplate(DataPointPropertiesTemplateVO vo) {
ProcessResult response = new ProcessResult();
if (vo.getXid() == null) {
vo.setXid(dao.generateUniqueXid());
}
// we need a name for validation so set XID and name to the same thing.
if (StringUtils.isEmpty(vo.getName())) {
vo.setName(vo.getXid());
}
vo.validate(response);
if (!response.getHasMessages()) {
try {
dao.save(vo);
updateDataPointsUsingTemplate(vo, response);
} catch (Exception e) {
// Handle the exceptions.
LOG.error(e);
String context = vo.getName();
if (context == null) {
context = vo.getXid();
}
if (context == null) {
context = vo.getXid();
}
if (context == null) {
context = Integer.toString(vo.getId());
}
if (e instanceof DuplicateKeyException)
response.addContextualMessage(context, "table.edit.alreadyExists");
else
response.addContextualMessage(context, "table.edit.unableToSave", e.getMessage());
}
}
response.addData("vo", vo);
// Add in case it fails
response.addData("id", vo.getId());
return response;
}
use of com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO in project ma-core-public by infiniteautomation.
the class TemplateDwr method getDataPointTemplates.
/**
* Save a template
* @return
*/
@DwrPermission(user = true)
public ProcessResult getDataPointTemplates(int dataTypeId) {
ProcessResult result = new ProcessResult();
List<DataPointPropertiesTemplateVO> templates = dao.getDataPointTemplatesByDataTypeId(dataTypeId);
result.addData(TemplateDao.instance.tableName, templates);
return result;
}
use of com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO in project ma-core-public by infiniteautomation.
the class DefaultDataPointPropertiesTemplateFactory method saveTemplate.
protected void saveTemplate(DataPointPropertiesTemplateVO template) {
ProcessResult response = new ProcessResult();
template.validate(response);
if (!response.getHasMessages()) {
TemplateDao.instance.save(template);
} else {
String output = new String();
List<ProcessMessage> messages = response.getMessages();
for (ProcessMessage message : messages) {
output += message.toString(Common.getTranslations());
output += "\n";
}
throw new ShouldNeverHappenException(output);
}
}
Aggregations