Search in sources :

Example 21 with BindException

use of org.springframework.validation.BindException in project opennms by OpenNMS.

the class DefaultDistributedPollerServiceTest method testPauseLocationMonitorSuccess.

public void testPauseLocationMonitorSuccess() {
    OnmsLocationMonitor locationMonitor = new OnmsLocationMonitor();
    locationMonitor.setId(LOCATION_MONITOR_ID);
    locationMonitor.setStatus(MonitorStatus.STARTED);
    expect(m_locationMonitorDao.load(locationMonitor.getId())).andReturn(locationMonitor);
    m_locationMonitorDao.update(locationMonitor);
    LocationMonitorIdCommand command = new LocationMonitorIdCommand();
    command.setMonitorId(LOCATION_MONITOR_ID);
    BindException errors = new BindException(command, "command");
    replayMocks();
    m_distributedPollerService.pauseLocationMonitor(command, errors);
    verifyMocks();
    assertEquals("error count", 0, errors.getErrorCount());
    assertEquals("new monitor status", MonitorStatus.PAUSED, locationMonitor.getStatus());
}
Also used : LocationMonitorIdCommand(org.opennms.web.svclayer.model.LocationMonitorIdCommand) BindException(org.springframework.validation.BindException) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor)

Example 22 with BindException

use of org.springframework.validation.BindException in project opennms by OpenNMS.

the class DefaultStatisticsReportServiceTest method testNullCommandObjectId.

@Test
public void testNullCommandObjectId() {
    StatisticsReportCommand command = new StatisticsReportCommand();
    BindException errors = new BindException(command, "");
    ThrowableAnticipator ta = new ThrowableAnticipator();
    ta.anticipate(new IllegalArgumentException("id property on command object cannot be null"));
    m_mocks.replayAll();
    try {
        m_service.getReport(command, errors);
    } catch (Throwable t) {
        ta.throwableReceived(t);
    }
    ta.verifyAnticipated();
}
Also used : BindException(org.springframework.validation.BindException) StatisticsReportCommand(org.opennms.web.svclayer.model.StatisticsReportCommand) ThrowableAnticipator(org.opennms.test.ThrowableAnticipator) Test(org.junit.Test)

Example 23 with BindException

use of org.springframework.validation.BindException in project opennms by OpenNMS.

the class DefaultStatisticsReportServiceTest method testDatumWithNonExistentResource.

@Test
public void testDatumWithNonExistentResource() {
    StatisticsReport report = new StatisticsReport();
    report.setId(1);
    StatisticsReportData datum = new StatisticsReportData();
    ResourceReference resourceRef = new ResourceReference();
    resourceRef.setId(1);
    resourceRef.setResourceId("node[1].interfaceSnmp[en0]");
    datum.setId(1);
    datum.setResource(resourceRef);
    datum.setReport(report);
    datum.setValue(0.1d);
    report.addData(datum);
    StatisticsReportCommand command = new StatisticsReportCommand();
    command.setId(report.getId());
    BindException errors = new BindException(command, "");
    expect(m_statisticsReportDao.load(report.getId())).andReturn(report);
    m_statisticsReportDao.initialize(report);
    m_statisticsReportDao.initialize(report.getData());
    expect(m_resourceDao.getResourceById(ResourceId.fromString(resourceRef.getResourceId()))).andReturn(null);
    m_mocks.replayAll();
    StatisticsReportModel model = m_service.getReport(command, errors);
    assertNotNull("model should not be null", model);
    assertNotNull("model.getData() should not be null", model.getData());
    SortedSet<Datum> data = model.getData();
    assertEquals("data size", 1, data.size());
    Datum d = data.first();
    assertNotNull("first datum should not be null", d);
    assertNull("first datum resource should be null", d.getResource());
}
Also used : Datum(org.opennms.web.svclayer.model.StatisticsReportModel.Datum) StatisticsReport(org.opennms.netmgt.model.StatisticsReport) StatisticsReportData(org.opennms.netmgt.model.StatisticsReportData) BindException(org.springframework.validation.BindException) ResourceReference(org.opennms.netmgt.model.ResourceReference) StatisticsReportCommand(org.opennms.web.svclayer.model.StatisticsReportCommand) StatisticsReportModel(org.opennms.web.svclayer.model.StatisticsReportModel) Test(org.junit.Test)

Example 24 with BindException

use of org.springframework.validation.BindException in project bigbluebutton by bigbluebutton.

the class CourseIndexingController method onSubmit.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax
	 * .servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse,
	 * java.lang.Object, org.springframework.validation.BindException)
	 */
@Override
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) {
    // Get url of lecture.xml
    IndexingContentSource contentSourceCommand = (IndexingContentSource) command;
    String lectureXMLURL = contentSourceCommand.getLectureURL();
    System.out.println("in indexing");
    // location.
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder parser = factory.newDocumentBuilder();
        org.w3c.dom.Document document = parser.parse(lectureXMLURL);
        String slideBaseURL = contentSourceCommand.getSlideBaseURL();
        List slideListResult = slideExpression.evaluateAsNodeList(document);
        List playTimeNodeList = slidePlayTimeExpression.evaluateAsNodeList(document);
        Map<String, String> slideTimeMap = new HashMap<String, String>();
        for (int i = 0; i < playTimeNodeList.size(); i++) {
            Node slideNode = (Node) playTimeNodeList.get(i);
            String slideTime = slideNode.getAttributes().getNamedItem("time").getNodeValue();
            String slideIndex = slideNode.getTextContent();
            if (slideTimeMap.get(slideIndex) != null) {
                // if a slide has been played multiple times, appending all
                // times or only record the first play time
                String value = slideTimeMap.get(slideIndex) + "||" + slideTime;
                slideTimeMap.put(slideIndex, value);
            } else {
                slideTimeMap.put(slideIndex, slideTime);
            }
            if (logger.isInfoEnabled()) {
                logger.info("slide index = " + slideIndex + " " + slideTime);
                logger.info("---Slide play time ---" + (String) slideTimeMap.get(slideIndex));
            }
        }
        // Map <String, String> slideTimeMap = new HashMap<String,
        // String>();
        ArrayList<String> fileURLs = new ArrayList();
        String fileLocation = null;
        synchronized (Index.getInstance()) {
            Index.getInstance().startIndex(lectureXMLURL);
            for (int i = 0; i < slideListResult.size(); i++) {
                Node node = (Node) slideListResult.get(i);
                String swfName = node.getNodeValue();
                fileLocation = slideBaseURL + swfName;
                fileURLs.add(i, fileLocation);
                Map attrs = new HashMap();
                // attrs.put("title", swfName);
                attrs.put("fileName", swfName);
                attrs.put("uid", lectureXMLURL);
                String idxToKey = (new Integer(i + 1)).toString();
                if (logger.isDebugEnabled()) {
                    logger.debug("idxToKey" + idxToKey + " resultsize=" + slideListResult.size() + "---Slide play time ---" + (String) slideTimeMap.get(idxToKey) + " summary = " + contentSourceCommand.getSummary());
                }
                // show the slide time
                if (slideTimeMap.get(idxToKey) != null) {
                    attrs.put("slideTime", "Slide " + idxToKey + ": played at " + (String) slideTimeMap.get(idxToKey));
                }
                attrs.put("summary", contentSourceCommand.getSummary());
                Index.getInstance().addIndex(fileLocation, attrs);
            }
            Index.getInstance().finishIndex();
        }
    } catch (Exception e) {
        System.out.println("-----------------exception -----------------------");
        Map<String, Object> model = new HashMap<String, Object>();
        model.put("generalError", "Please check the URL of files required by indexing");
        model.put("sourceContentURL", contentSourceCommand);
        return new ModelAndView(this.getFormView(), model);
    }
    return new ModelAndView(this.getSuccessView(), errors.getModel());
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) HashMap(java.util.HashMap) IndexingContentSource(org.bigbluebutton.webminer.web.model.IndexingContentSource) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) BindException(org.springframework.validation.BindException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 25 with BindException

use of org.springframework.validation.BindException in project grails-core by grails.

the class ScaleConstraintTests method proceedValidation.

private Object proceedValidation(Constraint constraint, Object value) {
    BeanWrapper constrainedBean = new BeanWrapperImpl(new TestClass());
    constrainedBean.setPropertyValue(constraint.getPropertyName(), value);
    Errors errors = new BindException(constrainedBean.getWrappedInstance(), constrainedBean.getWrappedClass().getName());
    assertFalse(errors.hasErrors());
    constraint.validate(constrainedBean.getWrappedInstance(), value, errors);
    return constrainedBean.getPropertyValue(constraint.getPropertyName());
}
Also used : Errors(org.springframework.validation.Errors) BeanWrapper(org.springframework.beans.BeanWrapper) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) BindException(org.springframework.validation.BindException) TestClass(grails.validation.TestClass)

Aggregations

BindException (org.springframework.validation.BindException)40 Errors (org.springframework.validation.Errors)15 LocationMonitorIdCommand (org.opennms.web.svclayer.model.LocationMonitorIdCommand)11 Test (org.junit.Test)9 ObjectError (org.springframework.validation.ObjectError)9 ThrowableAnticipator (org.opennms.test.ThrowableAnticipator)8 DistributedStatusDetailsCommand (org.opennms.web.svclayer.model.DistributedStatusDetailsCommand)8 OnmsLocationMonitor (org.opennms.netmgt.model.OnmsLocationMonitor)6 Map (java.util.Map)3 SimpleWebTable (org.opennms.web.svclayer.model.SimpleWebTable)3 BindingResult (org.springframework.validation.BindingResult)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3 HashMap (java.util.HashMap)2 List (java.util.List)2 OnmsLocationSpecificStatus (org.opennms.netmgt.model.OnmsLocationSpecificStatus)2 StatisticsReportCommand (org.opennms.web.svclayer.model.StatisticsReportCommand)2 BeanWrapper (org.springframework.beans.BeanWrapper)2 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)2 TypeMismatchException (org.springframework.beans.TypeMismatchException)2 FieldError (org.springframework.validation.FieldError)2