Search in sources :

Example 66 with ServiceException

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

the class CenterServiceFacadeWebTier method waiveChargesOverDue.

@Override
public void waiveChargesOverDue(Integer accountId, Integer waiveType) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    try {
        AccountBO account = new AccountBusinessService().getAccount(accountId);
        account.updateDetails(userContext);
        WaiveEnum waiveEnum = WaiveEnum.fromInt(waiveType);
        if (account.getPersonnel() != null) {
            new AccountBusinessService().checkPermissionForWaiveDue(waiveEnum, account.getType(), account.getCustomer().getLevel(), userContext, account.getOffice().getOfficeId(), account.getPersonnel().getPersonnelId());
        } else {
            new AccountBusinessService().checkPermissionForWaiveDue(waiveEnum, account.getType(), account.getCustomer().getLevel(), userContext, account.getOffice().getOfficeId(), userContext.getId());
        }
        this.transactionHelper.startTransaction();
        account.waiveAmountOverDue(waiveEnum);
        this.customerDao.save(account);
        this.transactionHelper.commitTransaction();
    } catch (ServiceException e) {
        this.transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } catch (ApplicationException e) {
        this.transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    } finally {
        this.transactionHelper.closeSession();
    }
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) WaiveEnum(org.mifos.accounts.util.helpers.WaiveEnum) BusinessRuleException(org.mifos.service.BusinessRuleException) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) ApplicationException(org.mifos.framework.exceptions.ApplicationException) ServiceException(org.mifos.framework.exceptions.ServiceException) UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 67 with ServiceException

use of org.mifos.framework.exceptions.ServiceException 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 68 with ServiceException

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

the class AuditBusinessService method getAuditLogRecords.

public List<AuditLogView> getAuditLogRecords(Short entityType, Integer entityId) throws ServiceException {
    try {
        LegacyAuditDao auditPersistence = ApplicationContextProvider.getBean(LegacyAuditDao.class);
        PersonnelBusinessService personnelService = new PersonnelBusinessService();
        List<AuditLog> auditLogRecords = auditPersistence.getAuditLogRecords(entityType, entityId);
        List<AuditLogView> auditLogViewList = new ArrayList<AuditLogView>();
        for (AuditLog auditLog : auditLogRecords) {
            for (AuditLogRecord auditLogRecord : auditLog.getAuditLogRecords()) {
                AuditLogView auditLogView = new AuditLogView();
                auditLogView.setDate(auditLog.getUpdatedDate().toString());
                Short userId = auditLog.getUpdatedBy();
                PersonnelBO personnel = personnelService.getPersonnel(userId);
                auditLogView.setUser(personnel.getUserName());
                auditLogView.setField(auditLogRecord.getFieldName());
                String encryptedPasswordAuditFieldName = AuditConfiguration.getColumnNameForPropertyName(AuditConstants.PERSONNEL, AuditConstants.Audit_PASSWORD);
                if ((null != encryptedPasswordAuditFieldName) && (auditLogRecord.getFieldName().equals(encryptedPasswordAuditFieldName.trim()))) {
                    auditLogView.setOldValue(AuditConstants.HIDDEN_PASSWORD);
                    auditLogView.setNewValue(AuditConstants.HIDDEN_PASSWORD);
                } else {
                    auditLogView.setOldValue(auditLogRecord.getOldValue());
                    auditLogView.setNewValue(auditLogRecord.getNewValue());
                }
                auditLogViewList.add(auditLogView);
            }
        }
        return auditLogViewList;
    } catch (PersistenceException e) {
        throw new ServiceException(e);
    }
}
Also used : PersonnelBusinessService(org.mifos.customers.personnel.business.service.PersonnelBusinessService) ArrayList(java.util.ArrayList) AuditLogView(org.mifos.framework.components.audit.util.helpers.AuditLogView) AuditLog(org.mifos.framework.components.audit.business.AuditLog) LegacyAuditDao(org.mifos.framework.components.audit.persistence.LegacyAuditDao) AuditLogRecord(org.mifos.framework.components.audit.business.AuditLogRecord) ServiceException(org.mifos.framework.exceptions.ServiceException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) PersistenceException(org.mifos.framework.exceptions.PersistenceException)

Example 69 with ServiceException

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

the class AuditLogServiceImpl method addAuditLogRegistry.

@Override
public void addAuditLogRegistry(QuestionGroupDetail questionGroupDetail, QuestionGroupDetail oldQuestionGroupDetail, int creatorId, int entityId, String source, String event) {
    PersonnelBusinessService pbs = new PersonnelBusinessService();
    String modifierName;
    if (oldQuestionGroupDetail != null && event.toLowerCase().equals(CREATE)) {
        String questionGroupName;
        String sectionName;
        String fieldName;
        String fieldValue;
        try {
            modifierName = pbs.getPersonnel((short) creatorId).getDisplayName();
        } catch (ServiceException e) {
            modifierName = "";
        }
        questionGroupName = questionGroupDetail.getTitle();
        AuditLog auditLog = new AuditLog(entityId, EntityType.getEntityValue(source.toUpperCase()), modifierName, new DateTimeService().getCurrentJavaSqlDate(), (short) creatorId);
        Set<AuditLogRecord> auditLogRecords = new HashSet<AuditLogRecord>();
        for (int sectionPosition = 0; sectionPosition < questionGroupDetail.getSectionDetails().size(); sectionPosition++) {
            SectionDetail sectionDetail = questionGroupDetail.getSectionDetails().get(sectionPosition);
            sectionName = sectionDetail.getName();
            for (int questionPosition = 0; questionPosition < sectionDetail.getQuestions().size(); questionPosition++) {
                SectionQuestionDetail sectionQuestionDetail = sectionDetail.getQuestions().get(questionPosition);
                fieldName = sectionQuestionDetail.getText();
                fieldValue = sectionQuestionDetail.getAnswer();
                String oldFieldValue = null;
                for (SectionDetail oldSectionDetail : oldQuestionGroupDetail.getSectionDetails()) {
                    if (oldSectionDetail.getName().equals(sectionName)) {
                        for (SectionQuestionDetail oldSectionQuestionDetail : oldSectionDetail.getQuestions()) {
                            if (oldSectionQuestionDetail.getText().equals(fieldName)) {
                                oldFieldValue = oldSectionQuestionDetail.getAnswer();
                                break;
                            }
                        }
                        break;
                    }
                }
                if (!fieldValue.equals("")) {
                    if (oldFieldValue != null && !oldFieldValue.equals("")) {
                        if (!oldFieldValue.equals(fieldValue)) {
                            auditLogRecords.add(new AuditLogRecord(trimField(questionGroupName + "/" + sectionName + "/" + fieldName, 100), trimField(oldFieldValue, 200), trimField(fieldValue, 200), auditLog));
                        }
                    } else {
                        auditLogRecords.add(new AuditLogRecord(trimField(questionGroupName + "/" + sectionName + "/" + fieldName, 100), "-", trimField(fieldValue, 200), auditLog));
                    }
                }
            }
        }
        if (!auditLogRecords.isEmpty()) {
            auditLog.addAuditLogRecords(auditLogRecords);
            legacyAuditDao.save(auditLog);
        }
    }
}
Also used : AuditLogRecord(org.mifos.framework.components.audit.business.AuditLogRecord) PersonnelBusinessService(org.mifos.customers.personnel.business.service.PersonnelBusinessService) ServiceException(org.mifos.framework.exceptions.ServiceException) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) DateTimeService(org.mifos.framework.util.DateTimeService) AuditLog(org.mifos.framework.components.audit.business.AuditLog) HashSet(java.util.HashSet)

Example 70 with ServiceException

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

the class PersonnelBusinessServiceTest method testInvalidConnectionInGetOffice.

@Test
@ExpectedException(value = CustomerException.class)
public void testInvalidConnectionInGetOffice() throws PersistenceException {
    try {
        when(officePersistence.getOffice(id)).thenThrow(new PersistenceException("some exception"));
        service.getOffice(id);
        junit.framework.Assert.fail("should fail because of invalid session");
    } catch (ServiceException e) {
    }
}
Also used : ServiceException(org.mifos.framework.exceptions.ServiceException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) Test(org.junit.Test) ExpectedException(org.springframework.test.annotation.ExpectedException)

Aggregations

ServiceException (org.mifos.framework.exceptions.ServiceException)93 PersistenceException (org.mifos.framework.exceptions.PersistenceException)46 MifosRuntimeException (org.mifos.core.MifosRuntimeException)39 Test (org.junit.Test)34 ExpectedException (org.springframework.test.annotation.ExpectedException)29 ArrayList (java.util.ArrayList)24 UserContext (org.mifos.security.util.UserContext)19 AccountBO (org.mifos.accounts.business.AccountBO)17 MifosUser (org.mifos.security.MifosUser)16 LoanBO (org.mifos.accounts.loan.business.LoanBO)15 AccountBusinessService (org.mifos.accounts.business.service.AccountBusinessService)14 AccountException (org.mifos.accounts.exceptions.AccountException)13 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)13 BusinessRuleException (org.mifos.service.BusinessRuleException)11 Date (java.util.Date)8 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)7 BigDecimal (java.math.BigDecimal)6 ProductCategoryBusinessService (org.mifos.accounts.productdefinition.business.service.ProductCategoryBusinessService)6 DateTimeService (org.mifos.framework.util.DateTimeService)6 LocalDate (org.joda.time.LocalDate)5