Search in sources :

Example 51 with UserContext

use of org.mifos.security.util.UserContext in project head by mifos.

the class RolesPermissionsAction method create.

@TransactionDemarcate(validateAndResetToken = true)
public ActionForward create(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    UserContext userContext = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
    List<ActivityEntity> activities = (List<ActivityEntity>) SessionUtils.getAttribute(RolesAndPermissionConstants.ACTIVITYLIST, request);
    RolesPermissionsActionForm rolesPermissionsActionForm = (RolesPermissionsActionForm) form;
    rolesPermissionServiceFacade.createRole(userContext.getId(), rolesPermissionsActionForm.getName(), getActivityIds(getActivities(activities, rolesPermissionsActionForm.getActivities())), rolesPermissionsActionForm.getActivityRestrictionDtoToPersistList());
    return mapping.findForward(ActionForwards.create_success.toString());
}
Also used : ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) UserContext(org.mifos.security.util.UserContext) RolesPermissionsActionForm(org.mifos.security.rolesandpermission.struts.actionforms.RolesPermissionsActionForm) ArrayList(java.util.ArrayList) List(java.util.List) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 52 with UserContext

use of org.mifos.security.util.UserContext in project head by mifos.

the class LoanUIHelperFnStrutsTest method testGetMeetingRecurrence.

@Test
public void testGetMeetingRecurrence() throws Exception {
    UserContext userContext = TestObjectFactory.getContext();
    MeetingBO meeting = TestObjectFactory.getNewMeeting(MONTHLY, EVERY_SECOND_MONTH, CUSTOMER_MEETING, MONDAY);
    Assert.assertEquals("2 month(s)", LoanUIHelperFn.getMeetingRecurrence(meeting, userContext));
}
Also used : UserContext(org.mifos.security.util.UserContext) MeetingBO(org.mifos.application.meeting.business.MeetingBO) Test(org.junit.Test)

Example 53 with UserContext

use of org.mifos.security.util.UserContext in project head by mifos.

the class BulkEntryActionStrutsTest method getUserLocale.

private Locale getUserLocale(final HttpServletRequest request) {
    Locale locale = null;
    HttpSession session = request.getSession();
    if (session != null) {
        UserContext userContext = (UserContext) session.getAttribute(LoginConstants.USERCONTEXT);
        if (null != userContext) {
            locale = userContext.getCurrentLocale();
        }
    }
    return locale;
}
Also used : Locale(java.util.Locale) HttpSession(javax.servlet.http.HttpSession) UserContext(org.mifos.security.util.UserContext)

Example 54 with UserContext

use of org.mifos.security.util.UserContext in project head by mifos.

the class NotesAction method create.

@CloseSession
@TransactionDemarcate(validateAndResetToken = true)
public ActionForward create(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    NotesActionForm notesActionForm = (NotesActionForm) form;
    UserContext uc = getUserContext(request);
    CreateAccountNote accountNote = (CreateAccountNote) SessionUtils.getAttribute("model.accountNote", request);
    AccountBO accountBO = new AccountBusinessService().getAccount(accountNote.getAccountId());
    if (accountBO.getPersonnel() != null) {
        checkPermissionForAddingNotes(accountBO.getType(), null, uc, accountBO.getOffice().getOfficeId(), accountBO.getPersonnel().getPersonnelId());
    } else {
        checkPermissionForAddingNotes(accountBO.getType(), null, uc, accountBO.getOffice().getOfficeId(), uc.getId());
    }
    if (accountBO.isSavingsAccount()) {
        this.savingsServiceFacade.addNote(accountNote);
    } else {
        this.loanAccountServiceFacade.addNote(accountNote);
    }
    return mapping.findForward(chooseForward(Short.valueOf(notesActionForm.getAccountTypeId())));
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) CreateAccountNote(org.mifos.dto.domain.CreateAccountNote) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) UserContext(org.mifos.security.util.UserContext) NotesActionForm(org.mifos.accounts.struts.actionforms.NotesActionForm) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 55 with UserContext

use of org.mifos.security.util.UserContext in project head by mifos.

the class SavingsApplyAdjustmentAction method load.

@TransactionDemarcate(joinToken = true)
public ActionForward load(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    clearActionForm(form);
    doCleanUp(request);
    UserContext uc = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
    SavingsBO savings = (SavingsBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
    SessionUtils.removeAttribute(Constants.BUSINESS_KEY, request);
    Long savingsId = Long.valueOf(savings.getAccountId());
    savings = this.savingsDao.findById(savingsId);
    savings.setUserContext(uc);
    String paymentIdParam = request.getParameter("paymentId");
    Integer paymentId;
    if (paymentIdParam == null) {
        AccountPaymentEntity payment = savings.getLastPmnt();
        paymentId = (payment == null) ? null : payment.getPaymentId();
    } else {
        paymentId = Integer.valueOf(paymentIdParam);
    }
    SavingsAdjustmentReferenceDto savingsAdjustmentDto = this.savingsServiceFacade.retrieveAdjustmentReferenceData(savingsId, paymentId);
    if (savingsAdjustmentDto.isDepositOrWithdrawal()) {
        AccountPaymentEntity payment = (paymentId == null) ? savings.findMostRecentPaymentByPaymentDate() : savings.findPaymentById(paymentId);
        AccountActionEntity accountAction = legacyMasterDao.getPersistentObject(AccountActionEntity.class, new SavingsHelper().getPaymentActionType(payment));
        Hibernate.initialize(savings.findMostRecentPaymentByPaymentDate().getAccountTrxns());
        SessionUtils.setAttribute(SavingsConstants.ACCOUNT_ACTION, accountAction, request);
        SessionUtils.setAttribute(SavingsConstants.CLIENT_NAME, savingsAdjustmentDto.getClientName(), request);
        SessionUtils.setAttribute(SavingsConstants.IS_LAST_PAYMENT_VALID, Constants.YES, request);
        SessionUtils.setAttribute(SavingsConstants.ADJUSTMENT_AMOUNT, payment.getAmount().getAmount(), request);
        SavingsApplyAdjustmentActionForm actionForm = (SavingsApplyAdjustmentActionForm) form;
        actionForm.setPaymentId(paymentId);
        actionForm.setTrxnDate(new LocalDate(payment.getPaymentDate()));
    } else {
        SessionUtils.setAttribute(SavingsConstants.IS_LAST_PAYMENT_VALID, Constants.NO, request);
    }
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, savings, request);
    return mapping.findForward("load_success");
}
Also used : SavingsAdjustmentReferenceDto(org.mifos.dto.screen.SavingsAdjustmentReferenceDto) UserContext(org.mifos.security.util.UserContext) SavingsHelper(org.mifos.accounts.savings.util.helpers.SavingsHelper) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) SavingsApplyAdjustmentActionForm(org.mifos.accounts.savings.struts.actionforms.SavingsApplyAdjustmentActionForm) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) LocalDate(org.joda.time.LocalDate) AccountActionEntity(org.mifos.accounts.business.AccountActionEntity) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Aggregations

UserContext (org.mifos.security.util.UserContext)369 MifosUser (org.mifos.security.MifosUser)134 MifosRuntimeException (org.mifos.core.MifosRuntimeException)102 ArrayList (java.util.ArrayList)97 Test (org.junit.Test)81 BusinessRuleException (org.mifos.service.BusinessRuleException)75 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)72 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)65 AccountException (org.mifos.accounts.exceptions.AccountException)55 UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)49 Money (org.mifos.framework.util.helpers.Money)46 LoanBO (org.mifos.accounts.loan.business.LoanBO)45 LocalDate (org.joda.time.LocalDate)44 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)43 ServiceException (org.mifos.framework.exceptions.ServiceException)43 PersistenceException (org.mifos.framework.exceptions.PersistenceException)38 CustomerBO (org.mifos.customers.business.CustomerBO)37 MeetingBO (org.mifos.application.meeting.business.MeetingBO)34 Date (java.util.Date)31 CustomerException (org.mifos.customers.exceptions.CustomerException)31