Search in sources :

Example 36 with SystemException

use of org.mifos.framework.exceptions.SystemException in project head by mifos.

the class AdminServiceFacadeWebTier method retrieveSavingsProductFormReferenceData.

@Override
public SavingsProductFormDto retrieveSavingsProductFormReferenceData() {
    try {
        SavingsPrdBusinessService service = new SavingsPrdBusinessService();
        List<ListElement> statusOptions = new ArrayList<ListElement>();
        List<PrdStatusEntity> applicableStatuses = service.getApplicablePrdStatus(Short.valueOf("1"));
        for (PrdStatusEntity entity : applicableStatuses) {
            statusOptions.add(new ListElement(entity.getOfferingStatusId().intValue(), entity.getPrdState().getName()));
        }
        List<ListElement> penaltiesOptions = new ArrayList<ListElement>();
        List<PenaltyBO> applicablePenalties = this.penaltyDao.findAllSavingPenalties();
        for (PenaltyBO entity : applicablePenalties) {
            penaltiesOptions.add(new ListElement(entity.getPenaltyId().intValue(), entity.getPenaltyName()));
        }
        List<ListElement> productCategoryOptions = new ArrayList<ListElement>();
        List<ProductCategoryBO> productCategories = service.getActiveSavingsProductCategories();
        for (ProductCategoryBO category : productCategories) {
            productCategoryOptions.add(new ListElement(category.getProductCategoryID().intValue(), category.getProductCategoryName()));
        }
        List<ListElement> applicableForOptions = new ArrayList<ListElement>();
        List<PrdApplicableMasterEntity> applicableCustomerTypes = this.loanProductDao.retrieveSavingsApplicableProductCategories();
        for (PrdApplicableMasterEntity entity : applicableCustomerTypes) {
            applicableForOptions.add(new ListElement(entity.getId().intValue(), entity.getName()));
        }
        List<ListElement> savingsTypeOptions = new ArrayList<ListElement>();
        List<SavingsTypeEntity> savingsTypes = this.loanProductDao.retrieveSavingsTypes();
        for (SavingsTypeEntity entity : savingsTypes) {
            savingsTypeOptions.add(new ListElement(entity.getId().intValue(), entity.getName()));
        }
        List<ListElement> recommendedAmountTypeOptions = new ArrayList<ListElement>();
        List<RecommendedAmntUnitEntity> recommendedAmountTypes = this.loanProductDao.retrieveRecommendedAmountTypes();
        for (RecommendedAmntUnitEntity entity : recommendedAmountTypes) {
            recommendedAmountTypeOptions.add(new ListElement(entity.getId().intValue(), entity.getName()));
        }
        List<ListElement> interestCalcTypeOptions = new ArrayList<ListElement>();
        List<InterestCalcTypeEntity> interestCalcTypes = this.savingsProductDao.retrieveInterestCalculationTypes();
        for (InterestCalcTypeEntity entity : interestCalcTypes) {
            interestCalcTypeOptions.add(new ListElement(entity.getId().intValue(), entity.getName()));
        }
        List<ListElement> timePeriodOptions = new ArrayList<ListElement>();
        List<RecurrenceTypeEntity> applicableRecurrences = savingsProductDao.getSavingsApplicableRecurrenceTypes();
        for (RecurrenceTypeEntity entity : applicableRecurrences) {
            timePeriodOptions.add(new ListElement(entity.getRecurrenceId().intValue(), entity.getRecurrenceName()));
        }
        List<GLCodeEntity> depositGlCodeList = new ArrayList<GLCodeEntity>();
        depositGlCodeList.addAll(new FinancialBusinessService().getGLCodes(FinancialActionConstants.MANDATORYDEPOSIT, FinancialConstants.CREDIT));
        depositGlCodeList.addAll(new FinancialBusinessService().getGLCodes(FinancialActionConstants.VOLUNTARYDEPOSIT, FinancialConstants.CREDIT));
        List<ListElement> depositGlCodeOptions = new ArrayList<ListElement>();
        for (GLCodeEntity glCode : depositGlCodeList) {
            depositGlCodeOptions.add(new ListElement(glCode.getGlcodeId().intValue(), glCode.getGlcode(), glCode.getAssociatedCOA().getAccountName()));
        }
        List<GLCodeEntity> interestGlCodeList = new FinancialBusinessService().getGLCodes(FinancialActionConstants.SAVINGS_INTERESTPOSTING, FinancialConstants.DEBIT);
        List<ListElement> interestGlCodes = new ArrayList<ListElement>();
        for (GLCodeEntity glCode : interestGlCodeList) {
            interestGlCodes.add(new ListElement(glCode.getGlcodeId().intValue(), glCode.getGlcode(), glCode.getAssociatedCOA().getAccountName()));
        }
        return new SavingsProductFormDto(productCategoryOptions, applicableForOptions, savingsTypeOptions, recommendedAmountTypeOptions, interestCalcTypeOptions, timePeriodOptions, depositGlCodeOptions, interestGlCodes, statusOptions);
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    } catch (SystemException e) {
        throw new MifosRuntimeException(e);
    } catch (ApplicationException e) {
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : ArrayList(java.util.ArrayList) FinancialBusinessService(org.mifos.accounts.financial.business.service.FinancialBusinessService) BusinessRuleException(org.mifos.service.BusinessRuleException) SystemException(org.mifos.framework.exceptions.SystemException) SavingsPrdBusinessService(org.mifos.accounts.productdefinition.business.service.SavingsPrdBusinessService) PenaltyBO(org.mifos.accounts.penalties.business.PenaltyBO) RecurrenceTypeEntity(org.mifos.application.meeting.business.RecurrenceTypeEntity) ProductCategoryBO(org.mifos.accounts.productdefinition.business.ProductCategoryBO) InterestCalcTypeEntity(org.mifos.accounts.productdefinition.business.InterestCalcTypeEntity) GLCodeEntity(org.mifos.accounts.financial.business.GLCodeEntity) RecommendedAmntUnitEntity(org.mifos.accounts.productdefinition.business.RecommendedAmntUnitEntity) ApplicationException(org.mifos.framework.exceptions.ApplicationException) SavingsTypeEntity(org.mifos.accounts.productdefinition.business.SavingsTypeEntity) SavingsProductFormDto(org.mifos.dto.screen.SavingsProductFormDto) ListElement(org.mifos.dto.screen.ListElement) PersistenceException(org.mifos.framework.exceptions.PersistenceException) PrdStatusEntity(org.mifos.accounts.productdefinition.business.PrdStatusEntity) PrdApplicableMasterEntity(org.mifos.accounts.productdefinition.business.PrdApplicableMasterEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 37 with SystemException

use of org.mifos.framework.exceptions.SystemException in project head by mifos.

the class CenterServiceFacadeWebTier method revertLastChargesPayment.

@Override
public void revertLastChargesPayment(String globalCustNum, String adjustmentNote) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    PersonnelBO loggedInUser = this.personnelDao.findPersonnelById(userContext.getId());
    CustomerBO customerBO = this.customerDao.findCustomerBySystemId(globalCustNum);
    customerBO.updateDetails(userContext);
    if (customerBO.getCustomerAccount().findMostRecentNonzeroPaymentByPaymentDate() != null) {
        customerBO.getCustomerAccount().updateDetails(userContext);
        try {
            if (customerBO.getPersonnel() != null) {
                new AccountBusinessService().checkPermissionForAdjustment(AccountTypes.CUSTOMER_ACCOUNT, customerBO.getLevel(), userContext, customerBO.getOffice().getOfficeId(), customerBO.getPersonnel().getPersonnelId());
            } else {
                new AccountBusinessService().checkPermissionForAdjustment(AccountTypes.CUSTOMER_ACCOUNT, customerBO.getLevel(), userContext, customerBO.getOffice().getOfficeId(), userContext.getId());
            }
            this.transactionHelper.startTransaction();
            customerBO.adjustPmnt(adjustmentNote, loggedInUser);
            this.customerDao.save(customerBO);
            this.transactionHelper.commitTransaction();
        } catch (SystemException e) {
            this.transactionHelper.rollbackTransaction();
            throw new MifosRuntimeException(e);
        } catch (ApplicationException e) {
            this.transactionHelper.rollbackTransaction();
            throw new BusinessRuleException(e.getKey(), e);
        }
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) ApplicationException(org.mifos.framework.exceptions.ApplicationException) SystemException(org.mifos.framework.exceptions.SystemException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) UserContext(org.mifos.security.util.UserContext) CustomerBO(org.mifos.customers.business.CustomerBO) MifosUser(org.mifos.security.MifosUser) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 38 with SystemException

use of org.mifos.framework.exceptions.SystemException in project head by mifos.

the class QGFlowsServiceImpl method applyToAllLoanProducts.

@Override
public void applyToAllLoanProducts(Integer questionGroupId) throws SystemException {
    LoanPrdBusinessService loanPrdBusinessService = new LoanPrdBusinessService();
    try {
        List<LoanOfferingBO> offerings = loanPrdBusinessService.getAllLoanOfferings((short) 1);
        if (offerings.size() > 0) {
            QuestionGroupReference questionGroupReference = new QuestionGroupReference();
            questionGroupReference.setQuestionGroupId(questionGroupId);
            for (LoanOfferingBO offering : offerings) {
                offering.getQuestionGroups().add(questionGroupReference);
                offering.save();
            }
            StaticHibernateUtil.commitTransaction();
        }
    } catch (ServiceException e) {
        throw new SystemException(e);
    } catch (ProductDefinitionException e) {
        throw new SystemException(e);
    }
}
Also used : QuestionGroupReference(org.mifos.accounts.productdefinition.business.QuestionGroupReference) ServiceException(org.mifos.framework.exceptions.ServiceException) SystemException(org.mifos.framework.exceptions.SystemException) ProductDefinitionException(org.mifos.accounts.productdefinition.exceptions.ProductDefinitionException) LoanPrdBusinessService(org.mifos.accounts.productdefinition.business.service.LoanPrdBusinessService) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO)

Example 39 with SystemException

use of org.mifos.framework.exceptions.SystemException in project head by mifos.

the class QuestionGroupController method defineQuestionGroup.

@SuppressWarnings({ "ThrowableInstanceNeverThrown" })
public String defineQuestionGroup(QuestionGroupForm questionGroupForm, RequestContext requestContext, boolean createMode) {
    String result = "success";
    if (!questionGroupHasErrors(questionGroupForm, requestContext)) {
        QuestionGroupDetail questionGroupDetail = null;
        try {
            if (createMode) {
                questionGroupForm.setActive(true);
            }
            if (questionGroupForm.isActive()) {
                questionGroupDetail = questionnaireServiceFacade.createActiveQuestionGroup(questionGroupForm.getQuestionGroupDetail());
            } else {
                questionGroupDetail = questionnaireServiceFacade.createQuestionGroup(questionGroupForm.getQuestionGroupDetail());
            }
            if (containsCreateLoanEventSource(questionGroupForm.getEventSources()) && questionGroupForm.getApplyToAllLoanProducts()) {
                questionnaireServiceFacade.applyToAllLoanProducts(questionGroupDetail.getId());
            }
            List<QuestionLinkDetail> questionLinkDetails = setFilledQuestionDetailForQuestionLinks(questionGroupForm.getQuestionLinks(), questionGroupDetail);
            List<SectionLinkDetail> sectionLinkDetails = setFilledSectionDetailForQuestionLinks(questionGroupForm.getSectionLinks(), questionGroupDetail);
            questionnaireServiceFacade.createQuestionLinks(questionLinkDetails);
            questionnaireServiceFacade.createSectionLinks(sectionLinkDetails);
        } catch (AccessDeniedException e) {
            constructAndLogSystemError(requestContext.getMessageContext(), new SystemException(QuestionnaireConstants.MISSING_PERMISSION_TO_ACTIVATE_QG, e));
            result = "failure";
        } catch (SystemException e) {
            constructAndLogSystemError(requestContext.getMessageContext(), e);
            result = "failure";
        }
    } else {
        result = "failure";
    }
    return result;
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) SystemException(org.mifos.framework.exceptions.SystemException) QuestionLinkDetail(org.mifos.platform.questionnaire.service.QuestionLinkDetail) SectionLinkDetail(org.mifos.platform.questionnaire.service.SectionLinkDetail)

Example 40 with SystemException

use of org.mifos.framework.exceptions.SystemException in project head by mifos.

the class Upgrade method largestLookupId.

@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = { "OBL_UNSATISFIED_OBLIGATION" }, justification = "The statement and results are closed.")
@SuppressWarnings("PMD.CloseResource")
protected int largestLookupId(Connection connection) throws SQLException {
    Statement statement = connection.createStatement();
    ResultSet results = statement.executeQuery("select max(lookup_id) from lookup_value");
    if (!results.next()) {
        throw new SystemException(SystemException.DEFAULT_KEY, "Did not find an existing lookup_id in lookup_value table");
    }
    int largestLookupId = results.getInt(1);
    results.close();
    statement.close();
    return largestLookupId;
}
Also used : SystemException(org.mifos.framework.exceptions.SystemException) Statement(java.sql.Statement) PreparedStatement(java.sql.PreparedStatement) ResultSet(java.sql.ResultSet)

Aggregations

SystemException (org.mifos.framework.exceptions.SystemException)53 Test (org.junit.Test)21 ApplicationException (org.mifos.framework.exceptions.ApplicationException)13 QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)11 PersistenceException (org.mifos.framework.exceptions.PersistenceException)10 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)10 HibernateException (org.hibernate.HibernateException)7 Session (org.hibernate.Session)7 MifosRuntimeException (org.mifos.core.MifosRuntimeException)7 HibernateProcessException (org.mifos.framework.exceptions.HibernateProcessException)7 ReportException (org.mifos.reports.exceptions.ReportException)7 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)4 BusinessRuleException (org.mifos.service.BusinessRuleException)4 IOException (java.io.IOException)3 ResultSet (java.sql.ResultSet)3 Statement (java.sql.Statement)3 ArrayList (java.util.ArrayList)3 MessageMatcher (org.mifos.platform.matchers.MessageMatcher)3 EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)3 PreparedStatement (java.sql.PreparedStatement)2