added unique number generation for account transaction id
This commit is contained in:
+15
-6
@@ -40,10 +40,12 @@ import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
|||||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder;
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder;
|
||||||
import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException;
|
import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException;
|
||||||
|
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||||
import org.mifosplatform.organisation.office.domain.Office;
|
import org.mifosplatform.organisation.office.domain.Office;
|
||||||
import org.mifosplatform.organisation.office.domain.OfficeRepository;
|
import org.mifosplatform.organisation.office.domain.OfficeRepository;
|
||||||
import org.mifosplatform.organisation.office.domain.OrganisationCurrencyRepositoryWrapper;
|
import org.mifosplatform.organisation.office.domain.OrganisationCurrencyRepositoryWrapper;
|
||||||
import org.mifosplatform.organisation.office.exception.OfficeNotFoundException;
|
import org.mifosplatform.organisation.office.exception.OfficeNotFoundException;
|
||||||
|
import org.mifosplatform.useradministration.domain.AppUser;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -67,6 +69,7 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa
|
|||||||
private final AccountingRuleRepository accountingRuleRepository;
|
private final AccountingRuleRepository accountingRuleRepository;
|
||||||
private final GLAccountReadPlatformService glAccountReadPlatformService;
|
private final GLAccountReadPlatformService glAccountReadPlatformService;
|
||||||
private final OrganisationCurrencyRepositoryWrapper organisationCurrencyRepository;
|
private final OrganisationCurrencyRepositoryWrapper organisationCurrencyRepository;
|
||||||
|
private final PlatformSecurityContext context;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public JournalEntryWritePlatformServiceJpaRepositoryImpl(final GLClosureRepository glClosureRepository,
|
public JournalEntryWritePlatformServiceJpaRepositoryImpl(final GLClosureRepository glClosureRepository,
|
||||||
@@ -76,7 +79,8 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa
|
|||||||
final AccountingProcessorForLoanFactory accountingProcessorForLoanFactory,
|
final AccountingProcessorForLoanFactory accountingProcessorForLoanFactory,
|
||||||
final AccountingProcessorForSavingsFactory accountingProcessorForSavingsFactory,
|
final AccountingProcessorForSavingsFactory accountingProcessorForSavingsFactory,
|
||||||
final GLAccountReadPlatformService glAccountReadPlatformService,
|
final GLAccountReadPlatformService glAccountReadPlatformService,
|
||||||
final OrganisationCurrencyRepositoryWrapper organisationCurrencyRepository) {
|
final OrganisationCurrencyRepositoryWrapper organisationCurrencyRepository,
|
||||||
|
final PlatformSecurityContext context) {
|
||||||
this.glClosureRepository = glClosureRepository;
|
this.glClosureRepository = glClosureRepository;
|
||||||
this.officeRepository = officeRepository;
|
this.officeRepository = officeRepository;
|
||||||
this.glJournalEntryRepository = glJournalEntryRepository;
|
this.glJournalEntryRepository = glJournalEntryRepository;
|
||||||
@@ -88,6 +92,7 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa
|
|||||||
this.accountingRuleRepository = accountingRuleRepository;
|
this.accountingRuleRepository = accountingRuleRepository;
|
||||||
this.glAccountReadPlatformService = glAccountReadPlatformService;
|
this.glAccountReadPlatformService = glAccountReadPlatformService;
|
||||||
this.organisationCurrencyRepository = organisationCurrencyRepository;
|
this.organisationCurrencyRepository = organisationCurrencyRepository;
|
||||||
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@@ -109,7 +114,7 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa
|
|||||||
|
|
||||||
/** Set a transaction Id and save these Journal entries **/
|
/** Set a transaction Id and save these Journal entries **/
|
||||||
final Date transactionDate = command.DateValueOfParameterNamed(JournalEntryJsonInputParams.TRANSACTION_DATE.getValue());
|
final Date transactionDate = command.DateValueOfParameterNamed(JournalEntryJsonInputParams.TRANSACTION_DATE.getValue());
|
||||||
final String transactionId = generateTransactionId();
|
final String transactionId = generateTransactionId(officeId);
|
||||||
final String referenceNumber = command.stringValueOfParameterNamed(JournalEntryJsonInputParams.REFERENCE_NUMBER.getValue());
|
final String referenceNumber = command.stringValueOfParameterNamed(JournalEntryJsonInputParams.REFERENCE_NUMBER.getValue());
|
||||||
|
|
||||||
if (accountRuleId != null) {
|
if (accountRuleId != null) {
|
||||||
@@ -263,8 +268,8 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa
|
|||||||
.getTransactionId());
|
.getTransactionId());
|
||||||
|
|
||||||
if (journalEntries.size() <= 1) { throw new JournalEntriesNotFoundException(command.getTransactionId()); }
|
if (journalEntries.size() <= 1) { throw new JournalEntriesNotFoundException(command.getTransactionId()); }
|
||||||
|
Long officeId = journalEntries.get(0).getOffice().getId();
|
||||||
final String reversalTransactionId = generateTransactionId();
|
final String reversalTransactionId = generateTransactionId(officeId);
|
||||||
final boolean manualEntry = true;
|
final boolean manualEntry = true;
|
||||||
|
|
||||||
for (final JournalEntry journalEntry : journalEntries) {
|
for (final JournalEntry journalEntry : journalEntries) {
|
||||||
@@ -377,8 +382,12 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa
|
|||||||
* TODO: Need a better implementation with guaranteed uniqueness (but not a
|
* TODO: Need a better implementation with guaranteed uniqueness (but not a
|
||||||
* long UUID)...maybe something tied to system clock..
|
* long UUID)...maybe something tied to system clock..
|
||||||
*/
|
*/
|
||||||
private String generateTransactionId() {
|
private String generateTransactionId(Long officeId) {
|
||||||
return RandomStringUtils.random(15, "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890");
|
AppUser user = this.context.authenticatedUser();
|
||||||
|
Long time = System.currentTimeMillis();
|
||||||
|
String uniqueVal = String.valueOf(time) + user.getId() + officeId;
|
||||||
|
String transactionId = Long.toHexString(Long.parseLong(uniqueVal));
|
||||||
|
return transactionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleJournalEntryDataIntegrityIssues(final DataIntegrityViolationException dve) {
|
private void handleJournalEntryDataIntegrityIssues(final DataIntegrityViolationException dve) {
|
||||||
|
|||||||
Reference in New Issue
Block a user