use of com.serotonin.m2m2.i18n.ProcessResult in project ma-core-public by infiniteautomation.
the class AbstractDwr method get.
/* (non-Javadoc)
* @see com.deltamation.mango.downtime.web.AbstractBasicDwr#get(int)
*/
@DwrPermission(user = true)
@Override
public ProcessResult get(int id) {
VO vo;
if (id == Common.NEW_ID) {
vo = dao.getNewVo();
} else {
vo = dao.get(id);
}
ProcessResult response = new ProcessResult();
response.addData("vo", vo);
return response;
}
use of com.serotonin.m2m2.i18n.ProcessResult in project ma-core-public by infiniteautomation.
the class AbstractDwr method saveFull.
/**
* Save the VO AND FDAO Data
*
* Conversion for the VO must be added by extending DwrConversionDefinition
*
* @return
*/
@DwrPermission(admin = true)
public ProcessResult saveFull(VO vo) {
// TODO combine with save()
ProcessResult response = new ProcessResult();
if (vo.getXid() == null) {
vo.setXid(dao.generateUniqueXid());
}
vo.validate(response);
if (!response.getHasMessages()) {
try {
dao.saveFull(vo);
} 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.i18n.ProcessResult in project ma-core-public by infiniteautomation.
the class AbstractDwr method save.
/**
* Save the VO
*
* Conversion for the VO must be added by extending DwrConversionDefinition
*
* @return
*/
@DwrPermission(admin = true)
public ProcessResult save(VO vo) {
ProcessResult response = new ProcessResult();
if (vo.getXid() == null) {
vo.setXid(dao.generateUniqueXid());
}
vo.validate(response);
if (!response.getHasMessages()) {
try {
dao.save(vo);
} catch (Exception e) {
// Handle the exceptions.
LOG.error(e);
String context = vo.getName();
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.i18n.ProcessResult in project ma-core-public by infiniteautomation.
the class AbstractRTDwr method getCopy.
@SuppressWarnings("unchecked")
@DwrPermission(user = true)
@Override
public ProcessResult getCopy(int id) {
ProcessResult response = super.getCopy(id);
// Ensure he isn't running
((AbstractActionVO<?>) response.getData().get("vo")).setEnabled(false);
return response;
}
use of com.serotonin.m2m2.i18n.ProcessResult in project ma-core-public by infiniteautomation.
the class AbstractRTDwr method save.
/**
* Save the Process
* @return
*/
@DwrPermission(admin = true)
@Override
public ProcessResult save(VO vo) {
ProcessResult response = new ProcessResult();
vo.validate(response);
if (!response.getHasMessages()) {
// Save it
try {
runtimeManager.save(vo);
} catch (Exception e) {
// Handle the exceptions.
// TODO Clean up and generify these messages to some central place
LOG.error(e);
if (e instanceof DuplicateKeyException)
response.addMessage(this.keyName + "Errors", new TranslatableMessage("dsEdit.alreadyExists"));
else
response.addMessage(this.keyName + "Errors", new TranslatableMessage("dsEdit.unableToSave"));
}
}
response.addData("vo", vo);
// In case there are errors
response.addData("id", vo.getId());
return response;
}
Aggregations