Search in sources :

Example 11 with GroupCustActionForm

use of org.mifos.customers.group.struts.actionforms.GroupCustActionForm in project head by mifos.

the class GroupCustAction method create.

@TransactionDemarcate(validateAndResetToken = true)
public ActionForward create(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    GroupCustActionForm actionForm = (GroupCustActionForm) form;
    MeetingBO meeting = (MeetingBO) SessionUtils.getAttribute(CustomerConstants.CUSTOMER_MEETING, request);
    UserContext userContext = getUserContext(request);
    String groupName = actionForm.getDisplayName();
    String externalId = actionForm.getExternalId();
    boolean trained = actionForm.isCustomerTrained();
    DateTime trainedOn = new DateTime(actionForm.getTrainedDateValue(userContext.getPreferredLocale()));
    AddressDto addressDto = null;
    if (actionForm.getAddress() != null) {
        addressDto = Address.toDto(actionForm.getAddress());
    }
    Short customerStatusId = actionForm.getStatusValue().getValue();
    String centerSystemId = "";
    boolean isCenterHierarchyExists = ClientRules.getCenterHierarchyExists();
    if (isCenterHierarchyExists) {
        centerSystemId = actionForm.getParentCustomer().getGlobalCustNum();
    }
    Short officeId = actionForm.getOfficeIdValue();
    MeetingDto meetingDto = null;
    if (meeting != null) {
        meetingDto = meeting.toDto();
    }
    DateTime mfiJoiningDate = new DateTime().toDateMidnight().toDateTime();
    DateTime activationDate = new DateTime().toDateMidnight().toDateTime();
    try {
        GroupCreationDetail groupCreationDetail = new GroupCreationDetail(groupName, externalId, addressDto, actionForm.getFormedByPersonnelValue(), actionForm.getFeesToApply(), customerStatusId, trained, trainedOn, centerSystemId, officeId, mfiJoiningDate, activationDate);
        CustomerDetailsDto centerDetails = this.groupServiceFacade.createNewGroup(groupCreationDetail, meetingDto);
        createGroupQuestionnaire.saveResponses(request, actionForm, centerDetails.getId());
        actionForm.setCustomerId(centerDetails.getId().toString());
        actionForm.setGlobalCustNum(centerDetails.getGlobalCustNum());
    } catch (BusinessRuleException e) {
        throw new ApplicationException(e.getMessageKey(), e);
    }
    SessionUtils.setAttribute(GroupConstants.IS_GROUP_LOAN_ALLOWED, ClientRules.getGroupCanApplyLoans(), request);
    return mapping.findForward(ActionForwards.create_success.toString());
}
Also used : MeetingBO(org.mifos.application.meeting.business.MeetingBO) UserContext(org.mifos.security.util.UserContext) AddressDto(org.mifos.dto.domain.AddressDto) GroupCreationDetail(org.mifos.dto.domain.GroupCreationDetail) DateTime(org.joda.time.DateTime) MeetingDto(org.mifos.dto.domain.MeetingDto) BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) CustomerDetailsDto(org.mifos.dto.domain.CustomerDetailsDto) GroupCustActionForm(org.mifos.customers.group.struts.actionforms.GroupCustActionForm) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 12 with GroupCustActionForm

use of org.mifos.customers.group.struts.actionforms.GroupCustActionForm in project head by mifos.

the class GroupActionStrutsTest method testSuccessfulCreate_UnderCenter.

@Test
public void testSuccessfulCreate_UnderCenter() throws Exception {
    createParentCustomer();
    StaticHibernateUtil.flushAndClearSession();
    setRequestPathInfo("/groupCustAction.do");
    addRequestParameter("method", "load");
    addRequestParameter("centerSystemId", center.getGlobalCustNum());
    actionPerform();
    List<CustomFieldDto> customFieldDefs = getCustomFieldsFromSession();
    setRequestPathInfo("/groupCustAction.do");
    addRequestParameter("method", "preview");
    addRequestParameter(Constants.CURRENTFLOWKEY, (String) request.getAttribute(Constants.CURRENTFLOWKEY));
    addRequestParameter("displayName", "groupUnderCenter");
    addRequestParameter("status", CustomerStatus.GROUP_PENDING.getValue().toString());
    addRequestParameter("formedByPersonnel", center.getPersonnel().getPersonnelId().toString());
    int i = 0;
    for (CustomFieldDto customFieldDef : customFieldDefs) {
        addRequestParameter("customField[" + i + "].fieldId", customFieldDef.getFieldId().toString());
        addRequestParameter("customField[" + i + "].fieldValue", "11");
        i++;
    }
    actionPerform();
    setRequestPathInfo("/groupCustAction.do");
    addRequestParameter("method", "create");
    addRequestParameter(Constants.CURRENTFLOWKEY, (String) request.getAttribute(Constants.CURRENTFLOWKEY));
    actionPerform();
    verifyNoActionErrors();
    verifyForward(ActionForwards.create_success.toString());
    GroupCustActionForm actionForm = (GroupCustActionForm) request.getSession().getAttribute("groupCustActionForm");
    group = TestObjectFactory.getGroup(actionForm.getCustomerIdAsInt());
    center = TestObjectFactory.getCenter(center.getCustomerId());
    actionForm.setParentCustomer(null);
}
Also used : CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) GroupCustActionForm(org.mifos.customers.group.struts.actionforms.GroupCustActionForm) Test(org.junit.Test)

Example 13 with GroupCustActionForm

use of org.mifos.customers.group.struts.actionforms.GroupCustActionForm in project head by mifos.

the class GroupActionStrutsTest method testSuccessfulCreate_UnderBranch.

@Test
public void testSuccessfulCreate_UnderBranch() throws Exception {
    createParentCustomer();
    StaticHibernateUtil.flushAndClearSession();
    setRequestPathInfo("/groupCustAction.do");
    addRequestParameter("method", "load");
    addRequestParameter("branchId", officeId.toString());
    addRequestParameter("centerSystemId", center.getGlobalCustNum());
    actionPerform();
    List<CustomFieldDto> customFieldDefs = getCustomFieldsFromSession();
    setRequestPathInfo("/groupCustAction.do");
    addRequestParameter("method", "preview");
    addRequestParameter(Constants.CURRENTFLOWKEY, (String) request.getAttribute(Constants.CURRENTFLOWKEY));
    addRequestParameter("displayName", "groupUnderBranch");
    addRequestParameter("status", CustomerStatus.GROUP_PENDING.getValue().toString());
    addRequestParameter("formedByPersonnel", center.getPersonnel().getPersonnelId().toString());
    int i = 0;
    for (CustomFieldDto customFieldDef : customFieldDefs) {
        addRequestParameter("customField[" + i + "].fieldId", customFieldDef.getFieldId().toString());
        addRequestParameter("customField[" + i + "].fieldValue", "11");
        i++;
    }
    actionPerform();
    SessionUtils.setAttribute(GroupConstants.CENTER_HIERARCHY_EXIST, Boolean.FALSE, request);
    setRequestPathInfo("/groupCustAction.do");
    addRequestParameter("method", "create");
    addRequestParameter(Constants.CURRENTFLOWKEY, (String) request.getAttribute(Constants.CURRENTFLOWKEY));
    actionPerform();
    verifyNoActionErrors();
    verifyForward(ActionForwards.create_success.toString());
    GroupCustActionForm actionForm = (GroupCustActionForm) request.getSession().getAttribute("groupCustActionForm");
    group = TestObjectFactory.getGroup(actionForm.getCustomerIdAsInt());
    center = TestObjectFactory.getCenter(center.getCustomerId());
    actionForm.setParentCustomer(null);
}
Also used : CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) GroupCustActionForm(org.mifos.customers.group.struts.actionforms.GroupCustActionForm) Test(org.junit.Test)

Aggregations

GroupCustActionForm (org.mifos.customers.group.struts.actionforms.GroupCustActionForm)13 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)9 CustomFieldDto (org.mifos.dto.domain.CustomFieldDto)6 Test (org.junit.Test)4 GroupBO (org.mifos.customers.group.business.GroupBO)3 ApplicationException (org.mifos.framework.exceptions.ApplicationException)3 AddressDto (org.mifos.dto.domain.AddressDto)2 UserContext (org.mifos.security.util.UserContext)2 BusinessRuleException (org.mifos.service.BusinessRuleException)2 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 ActionForward (org.apache.struts.action.ActionForward)1 DateTime (org.joda.time.DateTime)1 MeetingBO (org.mifos.application.meeting.business.MeetingBO)1 ActionForwards (org.mifos.application.util.helpers.ActionForwards)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 CenterBO (org.mifos.customers.center.business.CenterBO)1 CustomerException (org.mifos.customers.exceptions.CustomerException)1 OfficeBusinessService (org.mifos.customers.office.business.service.OfficeBusinessService)1 CenterDto (org.mifos.dto.domain.CenterDto)1