Search in sources :

Example 51 with ObjectError

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;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) ObjectError(org.springframework.validation.ObjectError) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Example 52 with ObjectError

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;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) ObjectError(org.springframework.validation.ObjectError) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Example 53 with ObjectError

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());
}
Also used : LocationMonitorIdCommand(org.opennms.web.svclayer.model.LocationMonitorIdCommand) ObjectError(org.springframework.validation.ObjectError) BindException(org.springframework.validation.BindException) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor)

Example 54 with ObjectError

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());
}
Also used : LocationMonitorIdCommand(org.opennms.web.svclayer.model.LocationMonitorIdCommand) ObjectError(org.springframework.validation.ObjectError) BindException(org.springframework.validation.BindException)

Example 55 with ObjectError

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);
}
Also used : ObjectError(org.springframework.validation.ObjectError) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor)

Aggregations

ObjectError (org.springframework.validation.ObjectError)55 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 BindException (org.springframework.validation.BindException)10 FieldError (org.springframework.validation.FieldError)8 BusinessRuleException (org.mifos.service.BusinessRuleException)7 ModelAndView (org.springframework.web.servlet.ModelAndView)7 BindingResult (org.springframework.validation.BindingResult)6 DocumentBuilder (javax.xml.parsers.DocumentBuilder)5 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)5 Test (org.junit.Test)5 OnmsLocationMonitor (org.opennms.netmgt.model.OnmsLocationMonitor)5 LocationMonitorIdCommand (org.opennms.web.svclayer.model.LocationMonitorIdCommand)5 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)5 MapBindingResult (org.springframework.validation.MapBindingResult)5 Document (org.w3c.dom.Document)5 Element (org.w3c.dom.Element)5 Errors (org.springframework.validation.Errors)3 MethodArgumentNotValidException (org.springframework.web.bind.MethodArgumentNotValidException)3 ArrayList (java.util.ArrayList)2 ServletException (javax.servlet.ServletException)2