You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by ju...@apache.org on 2019/10/09 07:40:33 UTC
[fineract-cn-group] 31/50: modifying the implementation of
updateGroupDefinition in the GroupAggregate.java file
This is an automated email from the ASF dual-hosted git repository.
juhan pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-group.git
commit 7df8dc5acc9e33806ee633c3ba429f164e5cfc88
Author: kengneruphine <ru...@gmail.com>
AuthorDate: Sat Jul 7 15:10:08 2018 +0100
modifying the implementation of updateGroupDefinition in the GroupAggregate.java file
---
.../command/UpdateGroupDefinitionCommand.java | 9 ++-----
.../internal/command/handler/GroupAggregate.java | 29 +++++++++++-----------
.../group/rest/GroupDefinitionRestController.java | 18 ++++++++++----
3 files changed, 29 insertions(+), 27 deletions(-)
diff --git a/service/src/main/java/org/apache/fineract/cn/group/internal/command/UpdateGroupDefinitionCommand.java b/service/src/main/java/org/apache/fineract/cn/group/internal/command/UpdateGroupDefinitionCommand.java
index cb9c481..7254ba3 100644
--- a/service/src/main/java/org/apache/fineract/cn/group/internal/command/UpdateGroupDefinitionCommand.java
+++ b/service/src/main/java/org/apache/fineract/cn/group/internal/command/UpdateGroupDefinitionCommand.java
@@ -22,19 +22,14 @@ import org.apache.fineract.cn.group.api.v1.domain.GroupDefinition;
public class UpdateGroupDefinitionCommand {
- private final String identifier;
+
private final GroupDefinition groupDefinition;
- public UpdateGroupDefinitionCommand(final String identifier, final GroupDefinition groupDefinition) {
+ public UpdateGroupDefinitionCommand( final GroupDefinition groupDefinition) {
super();
- this.identifier = identifier;
this.groupDefinition = groupDefinition;
}
- public String identifier() {
- return this.identifier;
- }
-
public GroupDefinition groupDefinition() {
return this.groupDefinition;
}
diff --git a/service/src/main/java/org/apache/fineract/cn/group/internal/command/handler/GroupAggregate.java b/service/src/main/java/org/apache/fineract/cn/group/internal/command/handler/GroupAggregate.java
index b4a93d6..bc631b5 100644
--- a/service/src/main/java/org/apache/fineract/cn/group/internal/command/handler/GroupAggregate.java
+++ b/service/src/main/java/org/apache/fineract/cn/group/internal/command/handler/GroupAggregate.java
@@ -140,19 +140,19 @@ public class GroupAggregate {
@CommandHandler
@EventEmitter(selectorName = EventConstants.SELECTOR_NAME, selectorValue = EventConstants.PUT_GROUP_DEFINITION)
public String updateDefinition(final UpdateGroupDefinitionCommand updateGroupDefinitionCommand) {
- final GroupDefinition updatedGroupDefinition = updateGroupDefinitionCommand.groupDefinition();
- final Cycle cycle = updatedGroupDefinition.getCycle();
- this.groupDefinitionRepository.findByIdentifier(updateGroupDefinitionCommand.identifier())
- .ifPresent(groupDefinitionEntity -> {
- groupDefinitionEntity.setDescription(updatedGroupDefinition.getDescription());
- groupDefinitionEntity.setMinimalSize(updatedGroupDefinition.getMinimalSize());
- groupDefinitionEntity.setMaximalSize(updatedGroupDefinition.getMaximalSize());
+ final GroupDefinition groupDefinition = updateGroupDefinitionCommand.groupDefinition();
+ final Cycle cycle = groupDefinition.getCycle();
+ final GroupDefinitionEntity groupDefinitionEntity = findGroupDefinitionEntityOrThrow(groupDefinition.getIdentifier());
+
+ groupDefinitionEntity.setDescription(groupDefinition.getDescription());
+ groupDefinitionEntity.setMinimalSize(groupDefinition.getMinimalSize());
+ groupDefinitionEntity.setMaximalSize(groupDefinition.getMaximalSize());
groupDefinitionEntity.setNumberOfMeetings(cycle.getNumberOfMeetings());
groupDefinitionEntity.setFrequency(cycle.getFrequency());
groupDefinitionEntity.setAdjustment(cycle.getAdjustment());
this.groupDefinitionRepository.save(groupDefinitionEntity);
- });
- return updatedGroupDefinition.getIdentifier();
+
+ return groupDefinition.getIdentifier();
}
@Transactional
@@ -191,12 +191,6 @@ public class GroupAggregate {
@EventEmitter(selectorName = EventConstants.SELECTOR_NAME, selectorValue = EventConstants.PUT_GROUP)
public String updateGroup(final UpdateGroupCommand updateGroupCommand) {
final Group group = updateGroupCommand.group();
- //final GroupDefinitionEntity groupDefinitionEntity =
- // this.groupDefinitionRepository.findByIdentifier(group.getGroupDefinitionIdentifier())
- // .orElseThrow(
- // () -> ServiceException.notFound("Group definition {0} not found.", group.getGroupDefinitionIdentifier())
- // );
-
final AddressEntity savedAddress = this.addressRepository.save(AddressMapper.map(group.getAddress()));
final GroupEntity groupEntity = findGroupEntityOrThrow(group.getIdentifier());
@@ -426,4 +420,9 @@ public class GroupAggregate {
return this.groupRepository.findByIdentifier(identifier)
.orElseThrow(() -> ServiceException.notFound("Group ''{0}'' not found", identifier));
}
+
+ private GroupDefinitionEntity findGroupDefinitionEntityOrThrow(String identifier) {
+ return this.groupDefinitionRepository.findByIdentifier(identifier)
+ .orElseThrow(() -> ServiceException.notFound("GroupDefinition ''{0}'' not found", identifier));
+ }
}
diff --git a/service/src/main/java/org/apache/fineract/cn/group/rest/GroupDefinitionRestController.java b/service/src/main/java/org/apache/fineract/cn/group/rest/GroupDefinitionRestController.java
index 6bd9ecb..d878938 100644
--- a/service/src/main/java/org/apache/fineract/cn/group/rest/GroupDefinitionRestController.java
+++ b/service/src/main/java/org/apache/fineract/cn/group/rest/GroupDefinitionRestController.java
@@ -122,11 +122,19 @@ public class GroupDefinitionRestController {
public
@ResponseBody
ResponseEntity<Void> updateGroupDefinition(@PathVariable("identifier") final String identifier, @RequestBody final GroupDefinition groupDefinition) {
- if (this.groupDefinitionService.groupDefinitionExists(identifier)) {
- this.commandGateway.process(new UpdateGroupDefinitionCommand(identifier, groupDefinition));
- } else {
- throw ServiceException.notFound("Group Definition {0} not found.", identifier);
- }
+ this.groupDefinitionService.findByIdentifier(identifier)
+ .orElseThrow(() -> ServiceException.notFound("Group Definition {0} not found.", identifier));
+
+ this.commandGateway.process(new UpdateGroupDefinitionCommand(groupDefinition));
+
return ResponseEntity.accepted().build();
}
+
+ // if (this.groupDefinitionService.groupDefinitionExists(identifier)) {
+ // this.commandGateway.process(new UpdateGroupDefinitionCommand(identifier, groupDefinition));
+ //} else {
+ //throw ServiceException.notFound("Group Definition {0} not found.", identifier);
+ //}
+ //return ResponseEntity.accepted().build();
+ // }
}