use of org.springframework.validation.ObjectError in project OpenClinica by OpenClinica.
the class StudyEventDefinitionEndpoint method mapFailConfirmation.
private Element mapFailConfirmation(String confirmation, Errors errors) throws Exception {
DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
Document document = docBuilder.newDocument();
Element responseElement = document.createElementNS(NAMESPACE_URI_V1, "listAllResponse");
Element resultElement = document.createElementNS(NAMESPACE_URI_V1, "result");
resultElement.setTextContent(confirmation);
responseElement.appendChild(resultElement);
for (ObjectError error : errors.getAllErrors()) {
Element errorElement = document.createElementNS(NAMESPACE_URI_V1, "error");
String theMessage = messages.getMessage(error.getCode(), error.getArguments(), locale);
errorElement.setTextContent(theMessage);
responseElement.appendChild(errorElement);
}
return responseElement;
}
use of org.springframework.validation.ObjectError in project OpenClinica by OpenClinica.
the class DataEndpoint method mapFailConfirmation.
/**
* Create Error Response
*
* @param confirmation
* @return
* @throws Exception
*/
private Element mapFailConfirmation(Errors errors, String message) throws Exception {
DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
Document document = docBuilder.newDocument();
Element responseElement = document.createElementNS(NAMESPACE_URI_V1, "importDataResponse");
Element resultElement = document.createElementNS(NAMESPACE_URI_V1, "result");
String confirmation = messages.getMessage("dataEndpoint.fail", null, "Fail", locale);
resultElement.setTextContent(confirmation);
responseElement.appendChild(resultElement);
if (errors != null) {
for (ObjectError error : errors.getAllErrors()) {
Element errorElement = document.createElementNS(NAMESPACE_URI_V1, "error");
String theMessage = messages.getMessage(error.getCode(), error.getArguments(), locale);
errorElement.setTextContent(theMessage);
responseElement.appendChild(errorElement);
}
}
if (message != null) {
Element msgElement = document.createElementNS(NAMESPACE_URI_V1, "error");
msgElement.setTextContent(message);
responseElement.appendChild(msgElement);
LOG.debug("sending fail message " + message);
}
return responseElement;
}
use of org.springframework.validation.ObjectError in project opennms by OpenNMS.
the class DefaultDistributedPollerServiceTest method testResumeLocationMonitorNotPaused.
public void testResumeLocationMonitorNotPaused() {
OnmsLocationMonitor locationMonitor = new OnmsLocationMonitor();
locationMonitor.setId(LOCATION_MONITOR_ID);
locationMonitor.setStatus(MonitorStatus.STARTED);
expect(m_locationMonitorDao.load(locationMonitor.getId())).andReturn(locationMonitor);
LocationMonitorIdCommand command = new LocationMonitorIdCommand();
command.setMonitorId(LOCATION_MONITOR_ID);
BindException errors = new BindException(command, "command");
replayMocks();
m_distributedPollerService.resumeLocationMonitor(command, errors);
verifyMocks();
assertEquals("error count", 1, errors.getErrorCount());
List<ObjectError> errorList = getErrorList(errors);
assertEquals("error list count", 1, errorList.size());
assertEquals("error 0 code", "distributed.locationMonitor.notPaused", errorList.get(0).getCode());
}
use of org.springframework.validation.ObjectError in project opennms by OpenNMS.
the class DefaultDistributedPollerServiceTest method testPauseLocationMonitorBindingErrors.
public void testPauseLocationMonitorBindingErrors() {
LocationMonitorIdCommand command = new LocationMonitorIdCommand();
BindException errors = new BindException(command, "command");
errors.addError(new ObjectError("foo", null, null, "foo"));
assertEquals("error count before pause", 1, errors.getErrorCount());
replayMocks();
m_distributedPollerService.pauseLocationMonitor(command, errors);
verifyMocks();
assertEquals("error count after pause", 1, errors.getErrorCount());
}
use of org.springframework.validation.ObjectError in project opennms by OpenNMS.
the class DefaultDistributedPollerService method resumeLocationMonitor.
/** {@inheritDoc} */
@Override
public void resumeLocationMonitor(LocationMonitorIdCommand command, BindingResult errors) {
if (command == null) {
throw new IllegalStateException("command argument cannot be null");
}
if (errors == null) {
throw new IllegalStateException("errors argument cannot be null");
}
if (errors.hasErrors()) {
return;
}
OnmsLocationMonitor monitor = m_locationMonitorDao.load(command.getMonitorId());
if (monitor.getStatus() != MonitorStatus.PAUSED) {
errors.addError(new ObjectError(MonitorStatus.class.getName(), new String[] { "distributed.locationMonitor.notPaused" }, new Object[] { command.getMonitorId() }, "Location monitor " + command.getMonitorId() + " is not paused."));
return;
}
monitor.setStatus(MonitorStatus.STARTED);
m_locationMonitorDao.update(monitor);
}
Aggregations