Search in sources :

Example 51 with ActionForward

use of org.apache.struts.action.ActionForward in project head by mifos.

the class GroupCustAction method search.

@Override
@TransactionDemarcate(joinToken = true)
public ActionForward search(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    GroupCustActionForm actionForm = (GroupCustActionForm) form;
    UserContext userContext = getUserContext(request);
    ActionForward actionForward = super.search(mapping, form, request, response);
    String searchString = actionForm.getSearchString();
    if (searchString == null) {
        if (actionForm.getInput() != null && actionForm.getInput().equals(GroupConstants.GROUP_SEARCH_CLIENT_TRANSFER)) {
            request.setAttribute(Constants.INPUT, CenterConstants.INPUT_SEARCH_TRANSFERGROUP);
        } else {
            request.setAttribute(Constants.INPUT, null);
        }
        throw new CustomerException(CenterConstants.NO_SEARCH_STRING);
    }
    addSeachValues(searchString, userContext.getBranchId().toString(), new OfficeBusinessService().getOffice(userContext.getBranchId()).getOfficeName(), request);
    final String normalizedSearchString = SearchUtils.normalizeSearchString(searchString);
    if (normalizedSearchString.equals("")) {
        if (actionForm.getInput() != null && actionForm.getInput().equals(GroupConstants.GROUP_SEARCH_CLIENT_TRANSFER)) {
            request.setAttribute(Constants.INPUT, CenterConstants.INPUT_SEARCH_TRANSFERGROUP);
        } else {
            request.setAttribute(Constants.INPUT, null);
        }
        throw new CustomerException(CenterConstants.NO_SEARCH_STRING);
    }
    boolean searchForAddingClientsToGroup = (actionForm.getInput() != null && actionForm.getInput().equals(GroupConstants.GROUP_SEARCH_ADD_CLIENTS_TO_GROUPS));
    GroupSearchResultsDto searchResult = this.customerServiceFacade.searchGroups(searchForAddingClientsToGroup, normalizedSearchString, userContext.getId());
    SessionUtils.setQueryResultAttribute(Constants.SEARCH_RESULTS, searchResult.getSearchResults(), request);
    if (actionForm.getInput() != null && actionForm.getInput().equals(GroupConstants.GROUP_SEARCH_CLIENT_TRANSFER)) {
        return mapping.findForward(ActionForwards.transferSearch_success.toString());
    } else if (searchForAddingClientsToGroup) {
        SessionUtils.setQueryResultAttribute(Constants.SEARCH_RESULTS, searchResult.getSearchForAddingClientToGroupResults(), request);
        return mapping.findForward(ActionForwards.addGroupSearch_success.toString());
    } else {
        return actionForward;
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) OfficeBusinessService(org.mifos.customers.office.business.service.OfficeBusinessService) UserContext(org.mifos.security.util.UserContext) GroupCustActionForm(org.mifos.customers.group.struts.actionforms.GroupCustActionForm) ActionForward(org.apache.struts.action.ActionForward) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 52 with ActionForward

use of org.apache.struts.action.ActionForward in project head by mifos.

the class CustomerNotesAction method create.

@CloseSession
@TransactionDemarcate(validateAndResetToken = true)
public ActionForward create(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    logger.debug("In CustomerNotesAction::create()");
    ActionForward forward = null;
    CustomerNotesActionForm notesActionForm = (CustomerNotesActionForm) form;
    Integer customerId = Integer.valueOf(((CustomerNotesActionForm) form).getCustomerId());
    CustomerBO customerBO = this.customerDao.findCustomerById(customerId);
    UserContext uc = getUserContext(request);
    if (customerBO.getPersonnel() != null) {
        checkPermissionForAddingNotes(AccountTypes.CUSTOMER_ACCOUNT, customerBO.getLevel(), uc, customerBO.getOffice().getOfficeId(), customerBO.getPersonnel().getPersonnelId());
    } else {
        checkPermissionForAddingNotes(AccountTypes.CUSTOMER_ACCOUNT, customerBO.getLevel(), uc, customerBO.getOffice().getOfficeId(), uc.getId());
    }
    CustomerNoteFormDto customerNoteForm = new CustomerNoteFormDto(customerBO.getGlobalCustNum(), customerBO.getDisplayName(), customerBO.getCustomerLevel().getId().intValue(), new LocalDate(), "", notesActionForm.getComment());
    this.centerServiceFacade.createCustomerNote(customerNoteForm);
    forward = mapping.findForward(getDetailCustomerPage(notesActionForm));
    return forward;
}
Also used : CustomerNotesActionForm(org.mifos.customers.struts.actionforms.CustomerNotesActionForm) UserContext(org.mifos.security.util.UserContext) CustomerBO(org.mifos.customers.business.CustomerBO) CustomerNoteFormDto(org.mifos.dto.screen.CustomerNoteFormDto) LocalDate(org.joda.time.LocalDate) ActionForward(org.apache.struts.action.ActionForward) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 53 with ActionForward

use of org.apache.struts.action.ActionForward in project head by mifos.

the class LoanAccountActionTest method shouldViewOriginalSchedule.

@SuppressWarnings("unchecked")
@Test
public void shouldViewOriginalSchedule() throws Exception {
    ActionForward viewOriginalScheduleForward = new ActionForward("viewOriginalSchedule");
    int loanId = 1;
    String loanAmount = "123";
    List<RepaymentScheduleInstallment> installments = Collections.EMPTY_LIST;
    java.sql.Date disbursementDate = new java.sql.Date(new DateTime().toDate().getTime());
    OriginalScheduleInfoDto dto = mock(OriginalScheduleInfoDto.class);
    when(dto.getOriginalLoanScheduleInstallment()).thenReturn(installments);
    when(dto.getLoanAmount()).thenReturn(loanAmount);
    when(dto.getDisbursementDate()).thenReturn(disbursementDate);
    when(request.getParameter(LoanAccountAction.ACCOUNT_ID)).thenReturn(String.valueOf(loanId));
    when(loanServiceFacade.retrieveOriginalLoanSchedule(loanId)).thenReturn(dto);
    when(mapping.findForward("viewOriginalSchedule")).thenReturn(viewOriginalScheduleForward);
    ActionForward forward = loanAccountAction.viewOriginalSchedule(mapping, form, request, response);
    assertThat(forward, is(viewOriginalScheduleForward));
    verify(request).getParameter(LoanAccountAction.ACCOUNT_ID);
    verify(loanServiceFacade).retrieveOriginalLoanSchedule(loanId);
    verify(dto).getOriginalLoanScheduleInstallment();
    verify(dto).getLoanAmount();
    verify(dto).getDisbursementDate();
    verify(mapping).findForward("viewOriginalSchedule");
}
Also used : RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) OriginalScheduleInfoDto(org.mifos.accounts.loan.business.service.OriginalScheduleInfoDto) ActionForward(org.apache.struts.action.ActionForward) Date(java.util.Date) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 54 with ActionForward

use of org.apache.struts.action.ActionForward in project zoj by licheng.

the class ShowUserRoleAction method execute.

/**
     * ShowRunsAction.
     * 
     * @param mapping
     *            action mapping
     * @param form
     *            action form
     * @param request
     *            http servlet request
     * @param response
     *            http servlet response
     * 
     * @return action forward instance
     * 
     * @throws Exception
     *             any errors happened
     */
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, ContextAdapter context) throws Exception {
    // check admin
    ActionForward forward = this.checkAdmin(mapping, context);
    if (forward != null) {
        return forward;
    }
    long userId = Utility.parseLong(String.valueOf(context.getRequest().getParameter("userId")));
    UserProfile user = UserManager.getInstance().getUserProfile(userId);
    if (user == null) {
        return this.handleSuccess(mapping, context, "failure");
    }
    context.getRequest().setAttribute("User", user);
    context.getRequest().setAttribute("Roles", PersistenceManager.getInstance().getAuthorizationPersistence().getAllRoles());
    context.getRequest().setAttribute("UserRoles", PersistenceManager.getInstance().getAuthorizationPersistence().getUserSecurity(userId).getRoles());
    return this.handleSuccess(mapping, context, "success");
}
Also used : UserProfile(cn.edu.zju.acm.onlinejudge.bean.UserProfile) ActionForward(org.apache.struts.action.ActionForward)

Example 55 with ActionForward

use of org.apache.struts.action.ActionForward in project zoj by licheng.

the class SubmitAction method execute.

/**
     * SubmitAction.
     * 
     * @param mapping
     *            action mapping
     * @param form
     *            action form
     * @param request
     *            http servlet request
     * @param response
     *            http servlet response
     * 
     * @return action forward instance
     * 
     * @throws Exception
     *             any errors happened
     */
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, ContextAdapter context) throws Exception {
    if (!this.isLogin(context, true)) {
        return this.handleSuccess(mapping, context, "login");
    }
    boolean isProblemset = context.getRequest().getRequestURI().endsWith("submit.do");
    ActionForward forward = this.checkProblemParticipatePermission(mapping, context, isProblemset);
    if (forward != null) {
        return forward;
    }
    AbstractContest contest = context.getContest();
    Problem problem = context.getProblem();
    long languageId = Utility.parseLong(context.getRequest().getParameter("languageId"));
    Language language = PersistenceManager.getInstance().getLanguagePersistence().getLanguage(languageId);
    if (language == null) {
        return this.handleSuccess(mapping, context, "submit");
    }
    String source = context.getRequest().getParameter("source");
    if (source == null || source.length() == 0) {
        return this.handleSuccess(mapping, context, "submit");
    }
    List refrance = PersistenceManager.getInstance().getReferencePersistence().getProblemReferences(problem.getId(), ReferenceType.HEADER);
    if (refrance.size() != 0) {
        Reference r = (Reference) refrance.get(0);
        String percode = new String(r.getContent());
        source = percode + "\n" + source;
    }
    UserProfile user = context.getUserProfile();
    if (submitCache != null && submitCache.contains(user.getId())) {
        ActionMessages messages = new ActionMessages();
        messages.add("message", new ActionMessage("onlinejudge.submit.interval"));
        this.saveErrors(context.getRequest(), messages);
        context.setAttribute("source", source);
        return handleSuccess(mapping, context, "submit");
    }
    if (contest.isCheckIp()) {
        forward = this.checkLastLoginIP(mapping, context, isProblemset);
        if (forward != null) {
            return forward;
        }
    }
    Submission submission = new Submission();
    submission.setContestId(contest.getId());
    submission.setLanguage(language);
    submission.setProblemId(problem.getId());
    submission.setUserProfileId(user.getId());
    submission.setContent(source);
    submission.setMemoryConsumption(0);
    submission.setTimeConsumption(0);
    submission.setSubmitDate(new Date());
    SubmissionPersistence submissionPersistence = PersistenceManager.getInstance().getSubmissionPersistence();
    if (contest.getEndTime() != null && new Date().after(contest.getEndTime())) {
        submission.setJudgeReply(JudgeReply.OUT_OF_CONTEST_TIME);
        submissionPersistence.createSubmission(submission, user.getId());
    } else if (source.getBytes().length > problem.getLimit().getSubmissionLimit() * 1024) {
        submission.setContent(source.substring(0, problem.getLimit().getSubmissionLimit() * 1024));
        submission.setJudgeReply(JudgeReply.SUBMISSION_LIMIT_EXCEEDED);
        submissionPersistence.createSubmission(submission, user.getId());
    } else {
        submission.setJudgeReply(JudgeReply.QUEUING);
        submissionPersistence.createSubmission(submission, user.getId());
        JudgeService.getInstance().judge(submission, Priority.NORMAL);
    }
    context.setAttribute("contestOrder", submission.getContestOrder());
    if (submitCache != null) {
        submitCache.put(user.getId(), user.getId());
    }
    return this.handleSuccess(mapping, context, "success");
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) UserProfile(cn.edu.zju.acm.onlinejudge.bean.UserProfile) Submission(cn.edu.zju.acm.onlinejudge.bean.Submission) Reference(cn.edu.zju.acm.onlinejudge.bean.Reference) SubmissionPersistence(cn.edu.zju.acm.onlinejudge.persistence.SubmissionPersistence) ActionForward(org.apache.struts.action.ActionForward) Date(java.util.Date) Language(cn.edu.zju.acm.onlinejudge.bean.enumeration.Language) ActionMessages(org.apache.struts.action.ActionMessages) ActionMessage(org.apache.struts.action.ActionMessage) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) List(java.util.List)

Aggregations

ActionForward (org.apache.struts.action.ActionForward)62 AbstractContest (cn.edu.zju.acm.onlinejudge.bean.AbstractContest)16 ActionMessages (org.apache.struts.action.ActionMessages)14 Problem (cn.edu.zju.acm.onlinejudge.bean.Problem)11 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)11 UserProfile (cn.edu.zju.acm.onlinejudge.bean.UserProfile)9 ActionMessage (org.apache.struts.action.ActionMessage)9 UserContext (org.mifos.security.util.UserContext)7 Date (java.util.Date)6 AuthorizationPersistence (cn.edu.zju.acm.onlinejudge.persistence.AuthorizationPersistence)5 CloseSession (org.mifos.framework.util.helpers.CloseSession)5 Submission (cn.edu.zju.acm.onlinejudge.bean.Submission)4 RoleSecurity (cn.edu.zju.acm.onlinejudge.security.RoleSecurity)4 Language (cn.edu.zju.acm.onlinejudge.bean.enumeration.Language)3 ContestPersistence (cn.edu.zju.acm.onlinejudge.persistence.ContestPersistence)3 ProblemPersistence (cn.edu.zju.acm.onlinejudge.persistence.ProblemPersistence)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 ActionMapping (org.apache.struts.action.ActionMapping)3 Test (org.junit.Test)3