Search in sources :

Example 1 with OffActionForm

use of org.mifos.customers.office.struts.actionforms.OffActionForm in project head by mifos.

the class OffAction method create.

@TransactionDemarcate(validateAndResetToken = true)
public ActionForward create(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    OffActionForm offActionForm = (OffActionForm) form;
    OfficeDto officeDto = new OfficeDto(getShortValue(offActionForm.getOfficeLevel()), getShortValue(offActionForm.getParentOfficeId()), offActionForm.getCustomFields(), offActionForm.getOfficeName(), offActionForm.getShortName(), Address.toDto(offActionForm.getAddress()));
    ListElement element = officeServiceFacade.createOffice(OperationMode.REMOTE_SERVER.getValue(), officeDto);
    offActionForm.setOfficeId(element.getId().toString());
    offActionForm.setGlobalOfficeNum(element.getName());
    createGroupQuestionnaire.saveResponses(request, offActionForm, element.getId());
    return mapping.findForward(ActionForwards.create_success.toString());
}
Also used : OfficeDto(org.mifos.dto.domain.OfficeDto) ListElement(org.mifos.dto.screen.ListElement) OffActionForm(org.mifos.customers.office.struts.actionforms.OffActionForm) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 2 with OffActionForm

use of org.mifos.customers.office.struts.actionforms.OffActionForm in project head by mifos.

the class OffAction method load.

@TransactionDemarcate(saveToken = true)
public ActionForward load(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    OffActionForm actionForm = (OffActionForm) form;
    actionForm.clear();
    String officeLevel = request.getParameter("officeLevel");
    Short officeLevelId = null;
    if (StringUtils.isNotBlank(officeLevel)) {
        officeLevelId = Short.valueOf(officeLevel);
    }
    OfficeFormDto officeFormDto = this.officeServiceFacade.retrieveOfficeFormInformation(officeLevelId);
    if (StringUtils.isNotBlank(officeLevel)) {
        actionForm.setOfficeLevel(officeLevel);
        OfficeDto office = (OfficeDto) SessionUtils.getAttribute(OfficeConstants.OFFICE_DTO, request);
        List<OfficeDto> validParentOffices = new ArrayList<OfficeDto>();
        if (actionForm.getInput() != null && actionForm.getInput().equals("edit") && office != null) {
            for (OfficeDto view : officeFormDto.getParents()) {
                if (!view.getId().equals(office.getOfficeId())) {
                    validParentOffices.add(view);
                }
            }
        } else {
            validParentOffices.addAll(officeFormDto.getParents());
        }
        SessionUtils.setCollectionAttribute(OfficeConstants.PARENTS, validParentOffices, request);
    }
    actionForm.setCustomFields(officeFormDto.getCustomFields());
    SessionUtils.setCollectionAttribute(CustomerConstants.CUSTOM_FIELDS_LIST, officeFormDto.getCustomFields(), request);
    SessionUtils.setCollectionAttribute(OfficeConstants.OFFICELEVELLIST, officeFormDto.getOfficeLevels(), request);
    SessionUtils.setAttribute(CustomerConstants.URL_MAP, null, request.getSession(false));
    return mapping.findForward(ActionForwards.load_success.toString());
}
Also used : OfficeDto(org.mifos.dto.domain.OfficeDto) OfficeFormDto(org.mifos.dto.screen.OfficeFormDto) ArrayList(java.util.ArrayList) OffActionForm(org.mifos.customers.office.struts.actionforms.OffActionForm) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 3 with OffActionForm

use of org.mifos.customers.office.struts.actionforms.OffActionForm in project head by mifos.

the class OffAction method update.

@TransactionDemarcate(validateAndResetToken = true)
@CloseSession
public ActionForward update(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    OffActionForm offActionForm = (OffActionForm) form;
    ActionForward forward = null;
    OfficeDto sessionOffice = (OfficeDto) SessionUtils.getAttribute(OfficeConstants.OFFICE_DTO, request);
    Short officeId = sessionOffice.getOfficeId();
    Integer versionNum = sessionOffice.getVersionNum();
    OfficeUpdateRequest officeUpdateRequest = officeUpdateRequestFrom(offActionForm);
    boolean isParentOfficeChanged = this.officeServiceFacade.updateOffice(officeId, versionNum, officeUpdateRequest);
    if (isParentOfficeChanged) {
        forward = mapping.findForward(ActionForwards.update_cache_success.toString());
    } else {
        forward = mapping.findForward(ActionForwards.update_success.toString());
    }
    return forward;
}
Also used : OfficeDto(org.mifos.dto.domain.OfficeDto) OffActionForm(org.mifos.customers.office.struts.actionforms.OffActionForm) ActionForward(org.apache.struts.action.ActionForward) OfficeUpdateRequest(org.mifos.dto.domain.OfficeUpdateRequest) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 4 with OffActionForm

use of org.mifos.customers.office.struts.actionforms.OffActionForm in project head by mifos.

the class OfficeActionStrutsTest method testCreate.

@Test
public void testCreate() throws Exception {
    setRequestPathInfo("/offAction.do");
    addRequestParameter("method", Methods.create.toString());
    addRequestParameter("officeName", "abcd");
    addRequestParameter("shortName", "abcd");
    addRequestParameter("officeLevel", "5");
    addRequestParameter("parentOfficeId", "1");
    addRequestParameter("address.line1", "123");
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    actionPerform();
    verifyForward(ActionForwards.create_success.toString());
    OffActionForm offActionForm = (OffActionForm) request.getSession().getAttribute("offActionForm");
    Assert.assertEquals("abcd", offActionForm.getOfficeName());
    Assert.assertEquals("abcd", offActionForm.getShortName());
    Assert.assertEquals("123", offActionForm.getAddress().getLine1());
}
Also used : OffActionForm(org.mifos.customers.office.struts.actionforms.OffActionForm) Test(org.junit.Test)

Example 5 with OffActionForm

use of org.mifos.customers.office.struts.actionforms.OffActionForm in project head by mifos.

the class OffAction method get.

@TransactionDemarcate(saveToken = true)
public ActionForward get(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    OffActionForm actionForm = (OffActionForm) form;
    if (StringUtils.isBlank(actionForm.getOfficeId())) {
        throw new OfficeException(OfficeConstants.KEYGETFAILED);
    }
    OfficeDto officeDto = this.officeServiceFacade.retrieveOfficeById(Short.valueOf(actionForm.getOfficeId()));
    actionForm.clear();
    List<CustomFieldDefinitionEntity> customFieldDefs = new ArrayList<CustomFieldDefinitionEntity>();
    SessionUtils.setCollectionAttribute(CustomerConstants.CUSTOM_FIELDS_LIST, customFieldDefs, request);
    actionForm.populate(officeDto);
    SessionUtils.setAttribute(OfficeConstants.OFFICE_DTO, officeDto, request);
    setCurrentPageUrl(request, officeDto);
    return mapping.findForward(ActionForwards.get_success.toString());
}
Also used : OfficeException(org.mifos.customers.office.exceptions.OfficeException) OfficeDto(org.mifos.dto.domain.OfficeDto) ArrayList(java.util.ArrayList) OffActionForm(org.mifos.customers.office.struts.actionforms.OffActionForm) CustomFieldDefinitionEntity(org.mifos.application.master.business.CustomFieldDefinitionEntity) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Aggregations

OffActionForm (org.mifos.customers.office.struts.actionforms.OffActionForm)8 OfficeDto (org.mifos.dto.domain.OfficeDto)6 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)6 ArrayList (java.util.ArrayList)3 OfficeDetailsDto (org.mifos.dto.domain.OfficeDetailsDto)3 Test (org.junit.Test)2 CustomFieldDefinitionEntity (org.mifos.application.master.business.CustomFieldDefinitionEntity)2 List (java.util.List)1 ActionForward (org.apache.struts.action.ActionForward)1 OfficeBO (org.mifos.customers.office.business.OfficeBO)1 OfficeException (org.mifos.customers.office.exceptions.OfficeException)1 CustomFieldDto (org.mifos.dto.domain.CustomFieldDto)1 OfficeUpdateRequest (org.mifos.dto.domain.OfficeUpdateRequest)1 ListElement (org.mifos.dto.screen.ListElement)1 OfficeDetailsForEdit (org.mifos.dto.screen.OfficeDetailsForEdit)1 OfficeFormDto (org.mifos.dto.screen.OfficeFormDto)1 CloseSession (org.mifos.framework.util.helpers.CloseSession)1