Search in sources :

Example 1 with ImportedFilesEntity

use of org.mifos.application.importexport.business.ImportedFilesEntity in project head by mifos.

the class ImportTransactionsServiceFacadeWebTier method undoFullImport.

@Override
public void undoFullImport(String importTransactionsFileName) {
    MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(mifosUser);
    TreeSet<String> accountsWithAdjustedPayments = new TreeSet<String>();
    try {
        ImportedFilesEntity filesEntity = this.importedFilesService.getImportedFileByName(importTransactionsFileName);
        List<AccountTrxnEntity> trxUndo = new ArrayList<AccountTrxnEntity>(filesEntity.getImportedTrxn());
        List<ImportedAccPaymentDto> accPaymentList = new ArrayList<ImportedAccPaymentDto>();
        for (AccountTrxnEntity trxn : trxUndo) {
            try {
                validateForAdjustedPayments(trxn, accountsWithAdjustedPayments);
                accPaymentList.add(new ImportedAccPaymentDto(trxn.getAccount().getGlobalAccountNum(), trxn.getAccountPayment().getPaymentId()));
            } catch (BusinessRuleException e) {
            //nothing to do   
            }
        }
        for (ImportedAccPaymentDto accDto : accPaymentList) {
            try {
                this.accountServiceFacade.applyHistoricalAdjustment(accDto.getGlobalNum(), accDto.getPaymentId(), IMPORT_UNDONE, userContext.getId(), null);
            } catch (MifosRuntimeException e) {
            // TODO: validation will be added with MIFOS-5779
            }
        }
        this.importedFilesService.saveImportedFileName(filesEntity.getFileName(), filesEntity.getSubmittedBy(), null, Boolean.TRUE, filesEntity.getUndoable());
    } catch (Exception e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) ImportedFilesEntity(org.mifos.application.importexport.business.ImportedFilesEntity) BusinessRuleException(org.mifos.service.BusinessRuleException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) BusinessRuleException(org.mifos.service.BusinessRuleException) TreeSet(java.util.TreeSet) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 2 with ImportedFilesEntity

use of org.mifos.application.importexport.business.ImportedFilesEntity in project head by mifos.

the class ImportTransactionsServiceFacadeWebTier method isAlreadyImported.

@Override
public boolean isAlreadyImported(String importTransactionsFileName) {
    ImportedFilesEntity importedFile = importedFilesService.getImportedFileByName(importTransactionsFileName);
    if (importedFile != null) {
        logger.debug(importTransactionsFileName + " has already been submitted");
        logger.debug("Submitted by" + importedFile.getSubmittedBy());
        logger.debug("Submitted on" + importedFile.getSubmittedOn());
        return true;
    }
    return false;
}
Also used : ImportedFilesEntity(org.mifos.application.importexport.business.ImportedFilesEntity)

Example 3 with ImportedFilesEntity

use of org.mifos.application.importexport.business.ImportedFilesEntity in project head by mifos.

the class ImportedFilesDaoHibernateIntegrationTest method testSaveConstraintVoilation.

/**
     * ignoring as can't get first
     */
@Test(expected = MifosRuntimeException.class)
public void testSaveConstraintVoilation() throws Exception {
    Short personnelId = new Short("1");
    PersonnelBO personnelBO = TestObjectFactory.getPersonnel(personnelId);
    Timestamp timeStamp = new Timestamp(123134554L);
    String fileName = "testFile.xls";
    ImportedFilesEntity expected = new ImportedFilesEntity(fileName, timeStamp, personnelBO, null, false, false);
    StaticHibernateUtil.startTransaction();
    importedFilesDao.saveImportedFile(expected);
    StaticHibernateUtil.flushSession();
    ImportedFilesEntity shouldViolateConstraint = new ImportedFilesEntity(fileName, timeStamp, personnelBO, null, false, false);
    importedFilesDao.saveImportedFile(shouldViolateConstraint);
    StaticHibernateUtil.flushSession();
}
Also used : PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) Timestamp(java.sql.Timestamp) ImportedFilesEntity(org.mifos.application.importexport.business.ImportedFilesEntity) Test(org.junit.Test)

Example 4 with ImportedFilesEntity

use of org.mifos.application.importexport.business.ImportedFilesEntity in project head by mifos.

the class ImportedFilesDaoHibernateIntegrationTest method testSaveAndFind.

@Test
public void testSaveAndFind() throws Exception {
    Short personnelId = new Short("1");
    PersonnelBO personnelBO = TestObjectFactory.getPersonnel(personnelId);
    Timestamp timeStamp = new Timestamp(123134554L);
    String fileName = "testFile.xls";
    ImportedFilesEntity expected = new ImportedFilesEntity(fileName, timeStamp, personnelBO, null, false, false);
    StaticHibernateUtil.startTransaction();
    importedFilesDao.saveImportedFile(expected);
    StaticHibernateUtil.flushSession();
    ImportedFilesEntity actual = importedFilesDao.findImportedFileByName(fileName);
    Assert.assertEquals(fileName, actual.getFileName());
    Assert.assertEquals(personnelId, actual.getSubmittedBy().getPersonnelId());
    Assert.assertEquals(timeStamp, actual.getSubmittedOn());
}
Also used : PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) Timestamp(java.sql.Timestamp) ImportedFilesEntity(org.mifos.application.importexport.business.ImportedFilesEntity) Test(org.junit.Test)

Example 5 with ImportedFilesEntity

use of org.mifos.application.importexport.business.ImportedFilesEntity in project head by mifos.

the class ImportTransactionsServiceFacadeWebTier method getImportedFiles.

@Override
public List<ImportedFileDto> getImportedFiles() {
    List<ImportedFileDto> importedFilesDto = new ArrayList<ImportedFileDto>();
    List<ImportedFilesEntity> importedFiles = this.importedFilesService.getImportedFiles();
    DateTime date;
    for (ImportedFilesEntity fileEntity : importedFiles) {
        date = new DateTime(fileEntity.getSubmittedOn().getTime());
        importedFilesDto.add(new ImportedFileDto(fileEntity.getFileName(), date, fileEntity.getPhaseOut(), fileEntity.getUndoable()));
    }
    return importedFilesDto;
}
Also used : ImportedFileDto(org.mifos.dto.screen.ImportedFileDto) ArrayList(java.util.ArrayList) ImportedFilesEntity(org.mifos.application.importexport.business.ImportedFilesEntity) DateTime(org.joda.time.DateTime)

Aggregations

ImportedFilesEntity (org.mifos.application.importexport.business.ImportedFilesEntity)6 Timestamp (java.sql.Timestamp)3 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 AccountTrxnEntity (org.mifos.accounts.business.AccountTrxnEntity)2 MifosRuntimeException (org.mifos.core.MifosRuntimeException)2 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)2 HashSet (java.util.HashSet)1 TreeSet (java.util.TreeSet)1 DateTime (org.joda.time.DateTime)1 UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)1 AccountTrxDto (org.mifos.dto.domain.AccountTrxDto)1 ImportedFileDto (org.mifos.dto.screen.ImportedFileDto)1 DateTimeService (org.mifos.framework.util.DateTimeService)1 MifosUser (org.mifos.security.MifosUser)1 UserContext (org.mifos.security.util.UserContext)1 BusinessRuleException (org.mifos.service.BusinessRuleException)1