From 145318c2600a83a73787a4caf0fa25ea491970e5 Mon Sep 17 00:00:00 2001 From: Madhukar Date: Thu, 10 Apr 2014 09:57:37 +0530 Subject: [PATCH] MIFOSX-1027 Adding missed subresources --- ...eWritePlatformServiceJpaRepositoryImpl.java | 9 +++++++-- .../core/data/CommandProcessingResult.java | 18 ++++++++++++------ .../data/CommandProcessingResultBuilder.java | 9 ++++++++- ...eWritePlatformServiceJpaRepositoryImpl.java | 16 +++++----------- 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/codes/service/CodeValueWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/codes/service/CodeValueWritePlatformServiceJpaRepositoryImpl.java index a702cf894..cefecebf3 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/codes/service/CodeValueWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/codes/service/CodeValueWritePlatformServiceJpaRepositoryImpl.java @@ -61,12 +61,16 @@ public class CodeValueWritePlatformServiceJpaRepositoryImpl implements CodeValue final Long codeId = command.entityId(); final Code code = this.codeRepository.findOne(codeId); + if (code == null) { + throw new CodeNotFoundException(codeId); + } final CodeValue codeValue = CodeValue.fromJson(code, command); this.codeValueRepository.save(codeValue); return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // - .withEntityId(codeValue.getId()) // + .withEntityId(code.getId()) // + .withSubEntityId(codeValue.getId())// .build(); } catch (final DataIntegrityViolationException dve) { handleCodeValueDataIntegrityIssues(command, dve); @@ -143,7 +147,8 @@ public class CodeValueWritePlatformServiceJpaRepositoryImpl implements CodeValue } return new CommandProcessingResultBuilder() // - .withEntityId(codeValueId) // + .withEntityId(codeId) // + .withSubEntityId(codeValueId)// .build(); } catch (final DataIntegrityViolationException dve) { logger.error(dve.getMessage(), dve); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/data/CommandProcessingResult.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/data/CommandProcessingResult.java index a1e1330f5..c394c0de8 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/data/CommandProcessingResult.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/data/CommandProcessingResult.java @@ -21,6 +21,7 @@ public class CommandProcessingResult { private final Long loanId; private final Long savingsId; private final Long resourceId; + private final Long subResourceId; private final String transactionId; private final Map changes; @SuppressWarnings("unused") @@ -30,9 +31,9 @@ public class CommandProcessingResult { public static CommandProcessingResult fromDetails(final Long commandId, final Long officeId, final Long groupId, final Long clientId, final Long loanId, final Long savingsId, final String resourceIdentifier, final Long entityId, final String transactionId, - final Map changes, final Long productId,final Boolean rollbackTransaction) { + final Map changes, final Long productId, final Boolean rollbackTransaction, final Long subResourceId) { return new CommandProcessingResult(commandId, officeId, groupId, clientId, loanId, savingsId, resourceIdentifier, entityId, - transactionId, changes, productId,rollbackTransaction); + transactionId, changes, productId, rollbackTransaction, subResourceId); } public static CommandProcessingResult commandOnlyResult(final Long commandId) { @@ -82,11 +83,12 @@ public class CommandProcessingResult { this.transactionId = null; this.changes = new HashMap(); this.productId = null; + this.subResourceId = null; } private CommandProcessingResult(final Long commandId, final Long officeId, final Long groupId, final Long clientId, final Long loanId, final Long savingsId, final String resourceIdentifier, final Long resourceId, final String transactionId, - final Map changesOnly, final Long productId, Boolean rollbackTransaction) { + final Map changesOnly, final Long productId, Boolean rollbackTransaction, final Long subResourceId) { this.commandId = commandId; this.officeId = officeId; this.groupId = groupId; @@ -99,6 +101,7 @@ public class CommandProcessingResult { this.transactionId = transactionId; this.productId = productId; this.rollbackTransaction = rollbackTransaction; + this.subResourceId = subResourceId; } private CommandProcessingResult(final Long resourceId, final Long officeId, final Long commandId, final Map changesOnly) { @@ -117,6 +120,7 @@ public class CommandProcessingResult { this.commandId = commandId; this.changes = changesOnly; this.productId = null; + this.subResourceId = null; } public Long commandId() { @@ -172,13 +176,15 @@ public class CommandProcessingResult { return this.productId; } - public boolean isRollbackTransaction() { - return this.rollbackTransaction!=null && this.rollbackTransaction; + return this.rollbackTransaction != null && this.rollbackTransaction; } - public void setRollbackTransaction(Boolean rollbackTransaction) { this.rollbackTransaction = rollbackTransaction; } + + public Long getSubResourceId() { + return subResourceId; + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/data/CommandProcessingResultBuilder.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/data/CommandProcessingResultBuilder.java index aa7c6a7f5..81b6b6829 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/data/CommandProcessingResultBuilder.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/data/CommandProcessingResultBuilder.java @@ -21,6 +21,7 @@ public class CommandProcessingResultBuilder { private Long savingsId; private String resourceIdentifier; private Long entityId; + private Long subEntityId; private String transactionId; private Map changes; private Long productId; @@ -28,7 +29,8 @@ public class CommandProcessingResultBuilder { public CommandProcessingResult build() { return CommandProcessingResult.fromDetails(this.commandId, this.officeId, this.groupId, this.clientId, this.loanId, this.savingsId, - this.resourceIdentifier, this.entityId, this.transactionId, this.changes, this.productId,this.rollbackTransaction); + this.resourceIdentifier, this.entityId, this.transactionId, this.changes, this.productId, this.rollbackTransaction, + this.subEntityId); } public CommandProcessingResultBuilder withCommandId(final Long withCommandId) { @@ -50,6 +52,11 @@ public class CommandProcessingResultBuilder { this.entityId = withEntityId; return this; } + + public CommandProcessingResultBuilder withSubEntityId(final Long withSubEntityId) { + this.subEntityId = withSubEntityId; + return this; + } public CommandProcessingResultBuilder withOfficeId(final Long withOfficeId) { this.officeId = withOfficeId; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/note/service/NoteWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/note/service/NoteWritePlatformServiceJpaRepositoryImpl.java index ceaae75e8..8fc120bf0 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/note/service/NoteWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/note/service/NoteWritePlatformServiceJpaRepositoryImpl.java @@ -96,7 +96,7 @@ public class NoteWritePlatformServiceJpaRepositoryImpl implements NoteWritePlatf return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // .withEntityId(newNote.getId()) // - .withClientId(group.getId()) // + .withGroupId(group.getId()) // .withOfficeId(group.officeId()) // .build(); } @@ -116,10 +116,8 @@ public class NoteWritePlatformServiceJpaRepositoryImpl implements NoteWritePlatf return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // .withEntityId(newNote.getId()) // - .withClientId(loan.getClientId()) // .withOfficeId(loan.getOfficeId()) // .withLoanId(loan.getId()) // - .withGroupId(loan.getGroupId()) // .build(); } @@ -140,10 +138,8 @@ public class NoteWritePlatformServiceJpaRepositoryImpl implements NoteWritePlatf return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // .withEntityId(newNote.getId()) // - .withClientId(loan.getClientId()).withOfficeId(loan.getOfficeId()).withLoanId(loan.getId()).withGroupId(loan.getGroupId())// Loan - // can - // be - // associated + .withOfficeId(loan.getOfficeId())// + .withLoanId(loan.getId())// Loan can be associated .build(); } @@ -295,8 +291,7 @@ public class NoteWritePlatformServiceJpaRepositoryImpl implements NoteWritePlatf } return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(noteForUpdate.getId()) - .withClientId(loan.getClientId()).withLoanId(loan.getId()).withGroupId(loan.getGroupId()).withOfficeId(loan.getOfficeId()) - .with(changes).build(); + .withLoanId(loan.getId()).withOfficeId(loan.getOfficeId()).with(changes).build(); } private CommandProcessingResult updateLoanTransactionNote(final JsonCommand command) { @@ -321,8 +316,7 @@ public class NoteWritePlatformServiceJpaRepositoryImpl implements NoteWritePlatf } return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(noteForUpdate.getId()) - .withClientId(loan.getClientId()).withLoanId(loan.getId()).withGroupId(loan.getGroupId()).withOfficeId(loan.getOfficeId()) - .with(changes).build(); + .withLoanId(loan.getId()).withOfficeId(loan.getOfficeId()).with(changes).build(); } // private CommandProcessingResult updateSavingAccountNote(final JsonCommand