Java Code Examples for org.springframework.validation.BindException#hasErrors()

The following examples show how to use org.springframework.validation.BindException#hasErrors() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BandwidthRestrictionsController.java    From webcurator with Apache License 2.0 6 votes vote down vote up
/**
 * process the delete restriction action.
 * 
 * @see AbstractFormController#processFormSubmission(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse, java.lang.Object,
 *      org.springframework.validation.BindException)
 */
private ModelAndView processDeleteRestriction(HttpServletRequest aReq, HttpServletResponse aResp,
		BandwidthRestrictionsCommand aCmd, BindException aErrors) throws Exception {
	if (aErrors.hasErrors()) {
		ModelAndView mav = new ModelAndView();
		mav.addObject(Constants.GBL_CMD_DATA, aErrors.getTarget());
		mav.addObject(Constants.GBL_ERRORS, aErrors);
		mav.addObject(BandwidthRestrictionsCommand.MDL_ACTION, Constants.CNTRL_MNG_BANDWIDTH);
		mav.setViewName(Constants.VIEW_EDIT_BANDWIDTH);

		return mav;
	}

	BandwidthRestriction br = harvestBandwidthManager.getBandwidthRestriction(aCmd.getOid());
	harvestBandwidthManager.delete(br);

	return createDefaultModelAndView();
}
 
Example 2
Source File: TargetInstanceResultHandler.java    From webcurator with Apache License 2.0 6 votes vote down vote up
public TabbedModelAndView buildResultsModel(TabbedController tc, TargetInstance ti, boolean editMode, BindException errors) { 
  	TabbedModelAndView tmav = tc.new TabbedModelAndView();
      List<HarvestResult> results = targetInstanceManager.getHarvestResults(ti.getOid());
User user = org.webcurator.core.util.AuthUtil.getRemoteUserObject();
Agency agency = user.getAgency();
      List<RejReason> rejectionReasons = agencyUserManager.getValidRejReasonsForTIs(agency.getOid());
      tmav.addObject("editMode", editMode);
      tmav.addObject(TargetInstanceCommand.MDL_INSTANCE, ti);
      tmav.addObject("results", results);
      tmav.addObject("reasons", rejectionReasons);
      if(errors.hasErrors())
      {
      	tmav.addObject(Constants.GBL_ERRORS, errors);
      }
      return tmav;     	
  }
 
Example 3
Source File: GeneralHandler.java    From webcurator with Apache License 2.0 5 votes vote down vote up
@Override
public ModelAndView processOther(TabbedController tc, Tab currentTab,
		HttpServletRequest req, HttpServletResponse res, Object comm,
		BindException errors) {
	
       TabbedModelAndView nextView = null;

       //Save the tab data before moving to parents screen
       processTab(tc, currentTab, req, res, comm, errors);      
   	nextView = preProcessNextTab(tc, currentTab, req, res, comm, errors);
       nextView.getTabStatus().setCurrentTab(currentTab);
       
	GeneralCommand command = (GeneralCommand) comm;
   	
	if(!errors.hasErrors() && command.getAction().equals(GeneralCommand.ACTION_ADD_PARENT))
	{
		// get value of page size cookie
		String currentPageSize = CookieUtils.getPageSize(req);
		
		AddParentsCommand cmd = new AddParentsCommand();
		
		cmd.setSearch("");
		cmd.setSelectedPageSize(currentPageSize);
		
		Pagination results = targetManager.getSubGroupParentDTOs(cmd.getSearch() + "%", 0, Integer.parseInt(cmd.getSelectedPageSize()));
		
		ModelAndView mav = new ModelAndView("group-add-parents");
		mav.addObject(Constants.GBL_CMD_DATA, cmd);
		mav.addObject("page", results);
		return mav;		
	}
	
	return nextView;				
}
 
Example 4
Source File: ResetPasswordController.java    From webcurator with Apache License 2.0 5 votes vote down vote up
/**
 * Process the change password command. 
 */
private ModelAndView processPasswordChange(HttpServletRequest aReq,HttpServletResponse aResp, ResetPasswordCommand aCmd, BindException aErrors) throws Exception {
    ModelAndView mav = new ModelAndView();
    if (aErrors.hasErrors()) {
        mav.addObject(Constants.GBL_CMD_DATA, aErrors.getTarget());
        mav.addObject(Constants.GBL_ERRORS, aErrors);
        mav.setViewName(Constants.VIEW_RESET_PWD);

        return mav;
    }

    try {
                    
        UsernamePasswordAuthenticationToken upat = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();

        
        User userAccount = (User) authDAO.getUserByName(upat.getName());
        
        String sysSalt = salt.getSystemWideSalt();
        String encodedPwd = encoder.encodePassword(aCmd.getNewPwd(),sysSalt);
        
        userAccount.setPassword(encodedPwd);
        //userAccount.setPwdFailedAttempts(0);
        userAccount.setForcePasswordChange(false);

        authDAO.saveOrUpdate(userAccount);
        
        upat.setDetails(userAccount);
        
        SecurityContextHolder.getContext().setAuthentication(upat);
        
        mav.addObject(Constants.MESSAGE_TEXT, "Your password has been changed.");
        mav.setViewName(Constants.VIEW_PASSWORD_RESET_SUCCESS);

        return mav;
    }
    catch (Exception e) {
        throw new Exception("Persistance Error occurred during password change", e);
    }
}
 
Example 5
Source File: TemplateController.java    From webcurator with Apache License 2.0 5 votes vote down vote up
@Override
protected ModelAndView processFormSubmission(HttpServletRequest aReq, HttpServletResponse aRes, Object aCmd, BindException aError) throws Exception {
    ModelAndView mav = null;
    TemplateCommand templateCmd = (TemplateCommand) aCmd;
    if (templateCmd != null) {
        if (aError.hasErrors()) {
            mav = getNewTemplateView(templateCmd);
            mav.addObject(Constants.GBL_CMD_DATA, aError.getTarget());
            mav.addObject(Constants.GBL_ERRORS, aError);
            
        } else if (TemplateCommand.ACTION_NEW.equals(templateCmd.getAction())) {
            log.debug("New Action on TemplateController");
            mav = getNewTemplateView(templateCmd);
        } else if (TemplateCommand.ACTION_SAVE.equals(templateCmd.getAction())) {
            log.debug("Save Action on TemplateController");
            mav = getSaveTemplateView(templateCmd);
        } else if (TemplateCommand.ACTION_VIEW.equals(templateCmd.getAction())) {
            log.debug("View Action on Template Controller");
            mav = getViewTemplateView(templateCmd);
        } else if (TemplateCommand.ACTION_EDIT.equals(templateCmd.getAction())) {
            log.debug("Edit Action on Template Controller");
            mav = getNewTemplateView(templateCmd);
        } else if (TemplateCommand.ACTION_DELETE.equals(templateCmd.getAction())) {
            log.debug("Delete Action on Template Controller");
            mav = getDeleteView(templateCmd);
        }
    }
    return mav;
}
 
Example 6
Source File: EditScheduleController.java    From webcurator with Apache License 2.0 5 votes vote down vote up
protected ModelAndView handleTest(HttpServletRequest request, HttpServletResponse response, Object comm, BindException errors) throws Exception {
	TargetSchedulesCommand command = (TargetSchedulesCommand) comm;
	
	if(errors.hasErrors()) {
		return getEditView(request, response, comm, errors);
	}
	else {			
	
		List<Date> testResults = new LinkedList<Date>();

		ModelAndView mav = getEditView(request, response, comm, errors);
		mav.addObject("testResults", testResults);
		
		try {
			CronExpression expr = new CronExpression(command.getCronExpression());
			Date d = DateUtils.latestDate(new Date(), command.getStartDate());
			Date nextDate = null;
			for(int i = 0; i<10; i++) {
				nextDate = expr.getNextValidTimeAfter(d);
				if(nextDate == null || command.getEndDate() != null && nextDate.after(command.getEndDate())) {
					break;
				}
				testResults.add(nextDate);
				d = nextDate;
			}
		}
		catch(ParseException ex) {
			ex.printStackTrace();
		}

		return mav;
	}
}
 
Example 7
Source File: TransferSeedsController.java    From webcurator with Apache License 2.0 5 votes vote down vote up
/**
 * Handle transfer.
 * @param req The servlet request.
 * @param res The servlet response.
 * @param command The TransferSeedsCommand object.
 * @param errors The bind errors.
 * @return The ModelAndView to be displayed.
 */	
protected ModelAndView handleTransfer(HttpServletRequest req, HttpServletResponse res, TransferSeedsCommand command, BindException errors) {
	
	if(errors.hasErrors()) {
		PermissionCriteria criteria = (PermissionCriteria) req.getSession().getAttribute("permSearchCriteria");
		ModelAndView mav = getSearchView(command, criteria);
		mav.addObject(Constants.GBL_ERRORS, errors);
		return mav;
	}
	else {
		Permission fromPermission = targetManager.loadPermission(command.getFromPermissionOid());
		Permission toPermission   = targetManager.loadPermission(command.getToPermissionOid());
		
		int seedsTransferred = 0;
		String message = null; 
		
		// Only perform the transfer if the user has the appropriate privileges.
		if(authorityManager.hasPrivilege(fromPermission, Privilege.TRANSFER_LINKED_TARGETS)) {
			seedsTransferred = targetManager.transferSeeds(fromPermission, toPermission);
			message = messageSource.getMessage("site.seeds_transferred", new Object[] { seedsTransferred }, Locale.getDefault());
		}
		else {
			message = messageSource.getMessage("site.seeds_transfer.denied", new Object[] {}, Locale.getDefault());
		}
		
		
		Tab currentTab = siteController.getTabConfig().getTabByID("PERMISSIONS");
		TabbedModelAndView tmav = currentTab.getTabHandler().preProcessNextTab(siteController, currentTab, req, res, command, errors);
		tmav.getTabStatus().setCurrentTab(currentTab);
			
		tmav.addObject(Constants.GBL_MESSAGES, message);
		
		return tmav;
	}
}
 
Example 8
Source File: AdministerNotificationRequestController.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * This method handles approval/disapproval/acknowledgement of the notification request
 * @param request the HttpServletRequest
 * @param response the HttpServletResponse
 * @param command the command object bound for this MultiActionController
 * @throws ServletException
 */
private void administerEventNotificationMessage(HttpServletRequest request, HttpServletResponse response, AdministerNotificationRequestCommand command, String action) throws ServletException {
    LOG.debug("remoteUser: " + request.getRemoteUser());

    BindException bindException = new BindException(command, "command");
    ValidationUtils.rejectIfEmpty(bindException, "docId", "Document id must be specified");
    if (bindException.hasErrors()) {
        throw new ServletRequestBindingException("Document id must be specified", bindException);
    }

    // obtain a workflow user object first
    //WorkflowIdDTO user = new WorkflowIdDTO(request.getRemoteUser());
    String userId = request.getRemoteUser();

    try {
        // now construct the workflow document, which will interact with workflow
        WorkflowDocument document = NotificationWorkflowDocument.loadNotificationDocument(userId, command.getDocId());

        NotificationBo notification = retrieveNotificationForWorkflowDocument(document);

        String initiatorPrincipalId = document.getInitiatorPrincipalId();
        Person initiator = KimApiServiceLocator.getPersonService().getPerson(initiatorPrincipalId);
        String notificationBlurb =  notification.getContentType().getName() + " notification submitted by " + initiator.getName() + " for channel " + notification.getChannel().getName();
        if ("disapprove".equals(action)) {
            document.disapprove("User " + userId + " disapproving " + notificationBlurb);
        } else if ("approve".equals(action)) {
            document.approve("User " + userId + " approving " + notificationBlurb);
        } else if ("acknowledge".equals(action)) {
            document.acknowledge("User " + userId + " acknowledging " + notificationBlurb);
        }
    } catch (Exception e) {
        LOG.error("Exception occurred taking action on notification request", e);
        throw new ServletException("Exception occurred taking action on notification request", e);
    }
}
 
Example 9
Source File: SiteAgencySearchController.java    From webcurator with Apache License 2.0 5 votes vote down vote up
private ModelAndView getSearchView(HttpServletRequest request, HttpServletResponse response, Object comm, BindException errors) {
	AgencySearchCommand command = (AgencySearchCommand) comm;
	Pagination results = siteManager.searchAuthAgents(command.getName(), command.getPageNumber());
	
	ModelAndView mav = new ModelAndView("site-auth-agency-search");
	mav.addObject("results", results);
	mav.addObject(Constants.GBL_CMD_DATA, command);
	
	if(errors.hasErrors()) {
		mav.addObject(Constants.GBL_ERRORS, errors);
	}
	
	return mav;
}
 
Example 10
Source File: SiteAgencySearchController.java    From webcurator with Apache License 2.0 5 votes vote down vote up
@Override
protected ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object comm, BindException errors) throws Exception {
	AgencySearchCommand command = (AgencySearchCommand) comm;
	
	if(AgencySearchCommand.ACTION_ADD.equals(command.getActionCmd())) {
		
		if(errors.hasErrors()) {
			return getSearchView(request, response, comm, errors);
		}
		else {
			long[] newAuthAgents = command.getSelectedOids();

			if(newAuthAgents != null && newAuthAgents.length > 0 ) {
				// Perform some validation before allowing the members to be 
				// added.
				for(int i=0; i<newAuthAgents.length; i++) {
					AuthorisingAgent agent = siteManager.loadAuthorisingAgent(newAuthAgents[i]);
					SiteEditorContext ctx = getEditorContext(request);
					ctx.putObject(agent);
					ctx.getSite().getAuthorisingAgents().add(agent);
				}
				
				// Go back to the main view.
				return getAgencyTab(request, response, comm, errors);
			}
			else {
				// Shouldn't ever reach this code, as newAuthAgents being 
				// null or empty should cause a validation failure.
				return getSearchView(request, response, comm, errors);
			}
		}
	}
	else if(AgencySearchCommand.ACTION_CANCEL.equals(command.getActionCmd())) {
		// Go back to the main view.
		return getAgencyTab(request, response, comm, errors);
	}
	else {
		return getSearchView(request, response, comm, errors);
	}
}
 
Example 11
Source File: SiteController.java    From webcurator with Apache License 2.0 5 votes vote down vote up
@Override
protected ModelAndView processSave(Tab currentTab, HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) {
	
	log.debug("------------------------processSave-------------------------------");
	checkSave(req, errors);
	
	if(errors.hasErrors()) {
		return getErrorsView(currentTab, req, res, comm, errors);
	}
	
	// Save the object.
	try {
		siteManager.save(getEditorContext(req).getSite());

		// Go back to the search screen.
		ModelAndView mav = siteSearchController.showForm(req, res, errors);
		mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("site.saved", new Object[] { getEditorContext(req).getSite().getTitle() }, Locale.getDefault()));
		return mav;
	} 
	catch (Exception ex) {
		throw new WCTRuntimeException(ex.getMessage(), ex);
	}
	finally {
		// Take the editor context out of the session.
		unbindEditorContext(req);
	}
}
 
Example 12
Source File: SiteController.java    From webcurator with Apache License 2.0 5 votes vote down vote up
public void checkSave(HttpServletRequest req, BindException errors) { 
	if (!errors.hasErrors() && !siteManager.isSiteTitleUnique(getEditorContext(req).getSite())) {
		errors.reject("site.errors.duplicatename", new Object[] {getEditorContext(req).getSite().getTitle()} ,"");
	}
	
	checkAuthAgencyNamesUnique(req, errors);
}
 
Example 13
Source File: MoveTargetsController.java    From webcurator with Apache License 2.0 5 votes vote down vote up
/** 
 * Perform the search for Group members. 
 */
private ModelAndView doSearch(HttpServletRequest request, HttpServletResponse response, Object comm, BindException errors) throws Exception {
	
	// get value of page size cookie
	String currentPageSize = CookieUtils.getPageSize(request);

	MoveTargetsCommand command = (MoveTargetsCommand) comm;
	
	if(command.getSearch() == null) {
		command.setSearch("");
		command.setSelectedPageSize(currentPageSize);
	}
	
	Pagination results = null;
	if (command.getSelectedPageSize().equals(currentPageSize)) {
		// user has left the page size unchanged..
		results = targetManager.getGroupDTOs(command.getSearch() + "%", command.getPageNumber(), Integer.parseInt(command.getSelectedPageSize()));
	}
	else {
		// user has selected a new page size, so reset to first page..
		results = targetManager.getGroupDTOs(command.getSearch() + "%", 0, Integer.parseInt(command.getSelectedPageSize()));
		// ..then update the page size cookie
		CookieUtils.setPageSize(response, command.getSelectedPageSize());
	}
	
	ModelAndView mav = new ModelAndView("group-move-targets");
	mav.addObject("page", results);
	mav.addObject(Constants.GBL_CMD_DATA, command);
	if(errors.hasErrors()) { mav.addObject(Constants.GBL_ERRORS, errors); }
	return mav;		
}
 
Example 14
Source File: AddParentsController.java    From webcurator with Apache License 2.0 5 votes vote down vote up
/** 
 * Perform the search for Group members. 
 */
private ModelAndView doSearch(HttpServletRequest request, HttpServletResponse response, Object comm, BindException errors) throws Exception {
	
	// get value of page size cookie
	String currentPageSize = CookieUtils.getPageSize(request);

	AddParentsCommand command = (AddParentsCommand) comm;
	
	if(command.getSearch() == null) {
		command.setSearch("");
		command.setSelectedPageSize(currentPageSize);
	}
	
	Pagination results = null;
	if (command.getSelectedPageSize().equals(currentPageSize)) {
		// user has left the page size unchanged..
		results = targetManager.getSubGroupParentDTOs(command.getSearch() + "%", command.getPageNumber(), Integer.parseInt(command.getSelectedPageSize()));
	}
	else {
		// user has selected a new page size, so reset to first page..
		results = targetManager.getSubGroupParentDTOs(command.getSearch() + "%", 0, Integer.parseInt(command.getSelectedPageSize()));
		// ..then update the page size cookie
		CookieUtils.setPageSize(response, command.getSelectedPageSize());
	}
	
	ModelAndView mav = new ModelAndView("group-add-parents");
	mav.addObject("page", results);
	mav.addObject(Constants.GBL_CMD_DATA, command);
	if(errors.hasErrors()) { mav.addObject(Constants.GBL_ERRORS, errors); }
	return mav;		
}
 
Example 15
Source File: AddMembersController.java    From webcurator with Apache License 2.0 5 votes vote down vote up
/** 
 * Perform the search for Group members. 
 */
private ModelAndView doSearch(HttpServletRequest request, HttpServletResponse response, Object comm, BindException errors) throws Exception {
	
	AddMembersCommand command = (AddMembersCommand) comm;
	
	// get value of page size cookie
	String currentPageSize = CookieUtils.getPageSize(request);

	if(command.getSearch() == null) {
		command.setSearch("");
		command.setSelectedPageSize(currentPageSize);
	}
	
	Pagination results = null;
	if (command.getSelectedPageSize().equals(currentPageSize)) {
		// user has left the page size unchanged..
		results = targetManager.getNonSubGroupDTOs(command.getSearch() + "%", command.getPageNumber(), Integer.parseInt(command.getSelectedPageSize()));
	}
	else {
		// user has selected a new page size, so reset to first page..
		results = targetManager.getNonSubGroupDTOs(command.getSearch() + "%", 0, Integer.parseInt(command.getSelectedPageSize()));
		// ..then update the page size cookie
		CookieUtils.setPageSize(response, command.getSelectedPageSize());
	}
	
	ModelAndView mav = new ModelAndView("group-add-members");
	mav.addObject("page", results);
	mav.addObject(Constants.GBL_CMD_DATA, command);
	mav.addObject(AddMembersCommand.PARAM_SELECTIONS, getSelections(request));
	if(errors.hasErrors()) { mav.addObject(Constants.GBL_ERRORS, errors); }
	return mav;		
}
 
Example 16
Source File: ApiResponse.java    From j360-dubbo-app-all with Apache License 2.0 5 votes vote down vote up
/**
 * 参数绑定错误响应
 *
 * @param exception 异常
 * @return 响应
 */
public static ApiResponse createRestResponse(BindException exception, HttpServletRequest request) {
    Builder builder = newBuilder();
    if (null != exception && exception.hasErrors()) {
        StringBuilder error = new StringBuilder("");
        for (ObjectError objectError : exception.getAllErrors()) {
            error.append(objectError.getDefaultMessage() + ";");
        }
        log.error(error.toString());
        builder.status(BaseApiStatus.SYST_SERVICE_UNAVAILABLE);
        builder.error(getMessage(String.valueOf(builder.getThis().status),request));
    }
    return builder.data(null).build();
}
 
Example 17
Source File: MembersHandler.java    From webcurator with Apache License 2.0 4 votes vote down vote up
@Override
public ModelAndView processOther(TabbedController tc, Tab currentTab,
		HttpServletRequest req, HttpServletResponse res, Object comm,
		BindException errors) {

	MembersCommand command = (MembersCommand) comm;

	// get value of page size cookie
	String currentPageSize = CookieUtils.getPageSize(req);

	if( MembersCommand.ACTION_UNLINK_MEMBER.equals(command.getActionCmd())) {
		getEditorContext(req).getTargetGroup().getRemovedChildren().add(command.getChildOid());
	}

	if(!errors.hasErrors() && MembersCommand.ACTION_MOVE_TARGETS.equals(command.getActionCmd())) {
		
		long[] targetOids = command.getTargetOids();
		List<Long> targetsToMove = new ArrayList<Long>();
		if(targetOids != null)
		{
			for(int i=0; i < targetOids.length; i++)
			{
				targetsToMove.add(targetOids[i]);
			}
		}
		
		getEditorContext(req).setTargetsToMove(targetsToMove);
		
		MoveTargetsCommand cmd = new MoveTargetsCommand();
		
		cmd.setSearch("");
		cmd.setSelectedPageSize(currentPageSize);
		
		Pagination results = targetManager.getGroupDTOs(cmd.getSearch() + "%", 0, Integer.parseInt(cmd.getSelectedPageSize()));
		
		ModelAndView mav = new ModelAndView("group-move-targets");
		mav.addObject(Constants.GBL_CMD_DATA, cmd);
		mav.addObject("page", results);
		return mav;
	}

	// Paging command
	TabbedModelAndView tmav = tc.new TabbedModelAndView();
	tmav.getTabStatus().setCurrentTab(currentTab);
	TargetGroup targetGroup = getEditorContext(req).getTargetGroup();
	
	Pagination members = null;
	if (command.getSelectedPageSize().equals(currentPageSize)) {
		// user has left the page size unchanged..
		members = targetManager.getMembers(targetGroup, command.getPageNumber(), Integer.parseInt(command.getSelectedPageSize()));
	}
	else {
		// user has selected a new page size, so reset to first page..
		members = targetManager.getMembers(targetGroup, 0, Integer.parseInt(command.getSelectedPageSize()));
		// ..then update the page size cookie
		CookieUtils.setPageSize(res, command.getSelectedPageSize());
	}
	
	tmav.addObject("members", members);
	// Add the pagination to the "page" attribute for standard pagination footer.
	tmav.addObject("page", members);
	tmav.addObject("subGroupSeparator", subGroupSeparator);
	tmav.addObject(Constants.GBL_CMD_DATA, command);
	return tmav;
}
 
Example 18
Source File: ReportController.java    From webcurator with Apache License 2.0 4 votes vote down vote up
@Override
protected ModelAndView processFormSubmission(HttpServletRequest request,
		HttpServletResponse response, Object comm, BindException errors)
		throws Exception {
		
	ReportCommand com = (ReportCommand) comm;
	
	// Build parameters
	long start = System.currentTimeMillis();
	ArrayList<Parameter> parameters = parseParameters(com);		
	log.debug("Parsing parameters took " + (System.currentTimeMillis()-start) + "ms");
			
	request.getSession().setAttribute("selectedRunReport", com.getSelectedReport());
	ModelAndView mav = new ModelAndView();
	if (errors.hasErrors()) {
		
		mav.addObject(Constants.GBL_ERRORS, errors);
		mav.addObject("reports", getReportMngr().getReports());
		mav.setViewName("reporting");
		
	} else {
				
		// Retreive reportGenerator & info  
		String info = "";
		ReportGenerator reportGenerator = null;
		for(Report rep : reportMngr.getReports()){
			if(rep.getName().equals(com.getSelectedReport())){
				info = rep.getInfo();
				reportGenerator = rep.getReportGenerator();
			}
		}
		
		// Build an AbstractReport
		OperationalReport operationalReport = new OperationalReport(
				com.getSelectedReport(), info, parameters, reportGenerator);
		
		// Store in session
		request.getSession().setAttribute("operationalReport", operationalReport);
		
		mav.setViewName("reporting-preview");

	}
	
	return mav;
}
 
Example 19
Source File: ShowHopPathController.java    From webcurator with Apache License 2.0 4 votes vote down vote up
@Override
protected ModelAndView handle(HttpServletRequest aReq, HttpServletResponse aResp, Object aCommand, BindException aErrors) throws Exception {
	
	ShowHopPathCommand cmd = (ShowHopPathCommand) aCommand;
	String messageText = "";
	int firstLine = 0;
	String[] lines = {"", ""};		
	
	if(aErrors.hasErrors())
	{
		Iterator it = aErrors.getAllErrors().iterator();
		while(it.hasNext())
		{
			org.springframework.validation.ObjectError err = (org.springframework.validation.ObjectError)it.next();
			if(messageText.length()>0) messageText += "; ";
			messageText += err.getDefaultMessage();
		}
	}
	else if(cmd.getTargetInstanceOid() != null)
	{
		TargetInstance ti = targetInstanceManager.getTargetInstance(cmd.getTargetInstanceOid());
		
		cmd.setTargetName(ti.getTarget().getName());
		
		lines = harvestLogManager.getHopPath(ti, cmd.getLogFileName(), cmd.getUrl());
	}
	else
	{
		messageText = "Context has been lost. Please close the Log Viewer and re-open.";
		cmd = new ShowHopPathCommand();
	}
	
	if (lines.length == 0) {
		
	}
	ModelAndView mav = new ModelAndView();
	mav.setViewName(Constants.HOP_PATH__READER);
	mav.addObject(Constants.GBL_CMD_DATA, cmd);
	if (lines.length == 0) {
		String [] problem = { "Could not determine Hop Path for Url: " + cmd.getUrl() };
		mav.addObject(ShowHopPathCommand.MDL_LINES, parseLines(problem, cmd.getShowLineNumbers(), firstLine, cmd.getNumLines()));
	} else {
		mav.addObject(ShowHopPathCommand.MDL_LINES, parseLines(lines, cmd.getShowLineNumbers(), firstLine, cmd.getNumLines()));
	}
	mav.addObject(Constants.MESSAGE_TEXT, messageText);
	
	return mav;
}
 
Example 20
Source File: AQAReaderController.java    From webcurator with Apache License 2.0 4 votes vote down vote up
@Override
protected ModelAndView handle(HttpServletRequest aReq, HttpServletResponse aResp, Object aCommand, BindException aErrors) throws Exception {
	LogReaderCommand cmd = (LogReaderCommand) aCommand;
	String messageText = "";
	int firstLine = 0;
	List<AQAElement> missingElements = new ArrayList<AQAElement>();
	
	if(aErrors.hasErrors())
	{
		Iterator it = aErrors.getAllErrors().iterator();
		while(it.hasNext())
		{
			org.springframework.validation.ObjectError err = (org.springframework.validation.ObjectError)it.next();
			if(messageText.length()>0) messageText += "; ";
			messageText += err.getDefaultMessage();
		}
	}
	else if(cmd.getTargetInstanceOid() != null)
	{
		TargetInstance ti = targetInstanceManager.getTargetInstance(cmd.getTargetInstanceOid());
		
		cmd.setTargetName(ti.getTarget().getName());
		
		File f = harvestCoordinator.getLogfile(ti, cmd.getLogFileName());
		Document aqaResult = readXMLDocument(f);
		NodeList missingElementsNodes = aqaResult.getElementsByTagName("missingElements");
		if(missingElementsNodes.getLength() > 0)
		{
			NodeList missingElementNodes = ((Element)missingElementsNodes.item(0)).getElementsByTagName("element");
			for(int i = 0; i < missingElementNodes.getLength(); i++)
			{
				Element elementNode = (Element)missingElementNodes.item(i);
				if (elementNode.getAttribute("statuscode").equals("200")) {
					missingElements.add(new AQAElement(elementNode.getAttribute("url"),
													   elementNode.getAttribute("contentfile"),
													   elementNode.getAttribute("contentType"),
													   Long.parseLong(elementNode.getAttribute("contentLength"))));
				}

			}
		}
	}
	
	ModelAndView mav = new ModelAndView();
	mav.setViewName(Constants.VIEW_AQA_READER);
	mav.addObject(Constants.GBL_CMD_DATA, cmd);
	mav.addObject(Constants.MESSAGE_TEXT, messageText);
	mav.addObject(LogReaderCommand.MDL_MISSINGELEMENTS, missingElements);
	
	return mav;
}