You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by GitBox <gi...@apache.org> on 2018/09/06 15:43:52 UTC

[GitHub] awasum closed pull request #7: Changes added to the Group Microservice [GSoC period]

awasum closed pull request #7: Changes added to the Group Microservice [GSoC period]
URL: https://github.com/apache/fineract-cn-group/pull/7
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/.gitignore b/.gitignore
index 95274b9..5f934cb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,7 @@
 .gradle
 .idea
+.project
+.settings
 **/build/
 **/target/
 
diff --git a/api/src/main/java/org/apache/fineract/cn/group/api/v1/EventConstants.java b/api/src/main/java/org/apache/fineract/cn/group/api/v1/EventConstants.java
index 435ac6d..99c5feb 100644
--- a/api/src/main/java/org/apache/fineract/cn/group/api/v1/EventConstants.java
+++ b/api/src/main/java/org/apache/fineract/cn/group/api/v1/EventConstants.java
@@ -29,6 +29,8 @@
 
   String POST_GROUP_DEFINITION = "post-group-definition";
   String SELECTOR_POST_GROUP_DEFINITION = SELECTOR_NAME + " = '" + POST_GROUP_DEFINITION + "'";
+  String PUT_GROUP_DEFINITION = "put-group-definition";
+  String SELECTOR_PUT_GROUP_DEFINITION = SELECTOR_NAME + " = '" + PUT_GROUP_DEFINITION + "'";
 
   String POST_GROUP = "post-group";
   String SELECTOR_POST_GROUP = SELECTOR_NAME + " = '" + POST_GROUP + "'";
diff --git a/api/src/main/java/org/apache/fineract/cn/group/api/v1/PermittableGroupIds.java b/api/src/main/java/org/apache/fineract/cn/group/api/v1/PermittableGroupIds.java
new file mode 100644
index 0000000..48738c8
--- /dev/null
+++ b/api/src/main/java/org/apache/fineract/cn/group/api/v1/PermittableGroupIds.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.apache.fineract.cn.group.api.v1;
+
+public interface PermittableGroupIds {
+
+    String GROUP = "group__v1__group";
+    String DEFINITION = "group__v1__definition";
+}
\ No newline at end of file
diff --git a/api/src/main/java/org/apache/fineract/cn/group/api/v1/client/GroupManager.java b/api/src/main/java/org/apache/fineract/cn/group/api/v1/client/GroupManager.java
index b64b390..12c563d 100644
--- a/api/src/main/java/org/apache/fineract/cn/group/api/v1/client/GroupManager.java
+++ b/api/src/main/java/org/apache/fineract/cn/group/api/v1/client/GroupManager.java
@@ -75,6 +75,18 @@
   @ResponseBody
   List<GroupDefinition> fetchGroupDefinitions();
 
+  @RequestMapping(
+          value = "/definitions/{identifier}",
+          method = RequestMethod.PUT,
+          produces = MediaType.APPLICATION_JSON_VALUE,
+          consumes = MediaType.APPLICATION_JSON_VALUE
+  )
+  @ThrowsExceptions({
+          @ThrowsException(status = HttpStatus.NOT_FOUND, exception = GroupDefinitionNotFound.class),
+          @ThrowsException(status = HttpStatus.BAD_REQUEST, exception = GroupDefinitionValidation.class)
+  })
+  void updateGroupDefinition(@PathVariable("identifier") final String identifier, @RequestBody final GroupDefinition groupDefinition);
+
   @RequestMapping(
       value = "/groups",
       method = RequestMethod.POST,
@@ -93,11 +105,11 @@
       produces = MediaType.ALL_VALUE,
       consumes = MediaType.APPLICATION_JSON_VALUE
   )
-  GroupPage fetchGroups(@RequestParam("employee") final String employee,
-                        @RequestParam("page") final Integer page,
-                        @RequestParam("size") final Integer size,
-                        @RequestParam("sortColumn") final String sortColumn,
-                        @RequestParam("sortDirection") final String sortDirection);
+  GroupPage fetchGroups(@RequestParam(value="employee", required=false) final String employee,
+                        @RequestParam(value="page", required=false) final Integer page,
+                        @RequestParam(value="size",required=false) final Integer size,
+                        @RequestParam(value="sortColumn", required=false) final String sortColumn,
+                        @RequestParam(value="sortDirection",required=false) final String sortDirection);
 
   @RequestMapping(
       value = "/groups/{identifier}",
@@ -108,6 +120,19 @@ GroupPage fetchGroups(@RequestParam("employee") final String employee,
   @ThrowsException(status = HttpStatus.NOT_FOUND, exception = GroupNotFoundException.class)
   Group findGroup(@PathVariable("identifier") final String identifier);
 
+  @RequestMapping(
+          value = "/groups/{identifier}",
+          method = RequestMethod.PUT,
+          produces = MediaType.APPLICATION_JSON_VALUE,
+          consumes = MediaType.APPLICATION_JSON_VALUE
+  )
+  @ThrowsExceptions({
+          @ThrowsException(status = HttpStatus.NOT_FOUND, exception = GroupNotFoundException.class),
+          @ThrowsException(status = HttpStatus.BAD_REQUEST, exception = GroupValidationException.class)
+  })
+  void updateGroup(@PathVariable("identifier") final String identifier, @RequestBody final Group group);
+
+
   @RequestMapping(
       value = "/groups/{identifier}/leaders",
       method = RequestMethod.PUT,
diff --git a/api/src/main/java/org/apache/fineract/cn/group/api/v1/domain/GroupCommand.java b/api/src/main/java/org/apache/fineract/cn/group/api/v1/domain/GroupCommand.java
index 526e5b7..3ca7996 100644
--- a/api/src/main/java/org/apache/fineract/cn/group/api/v1/domain/GroupCommand.java
+++ b/api/src/main/java/org/apache/fineract/cn/group/api/v1/domain/GroupCommand.java
@@ -18,7 +18,7 @@
  */
 package org.apache.fineract.cn.group.api.v1.domain;
 
-public class GroupCommand {
+public class    GroupCommand {
 
   private Action action;
   private String note;
diff --git a/component-test/src/main/java/org/apache/fineract/cn/group/TestGroup.java b/component-test/src/main/java/org/apache/fineract/cn/group/TestGroup.java
index 1307d66..1b485f9 100644
--- a/component-test/src/main/java/org/apache/fineract/cn/group/TestGroup.java
+++ b/component-test/src/main/java/org/apache/fineract/cn/group/TestGroup.java
@@ -262,6 +262,29 @@ public void shouldUpdateAssignedEmployee() throws Exception {
     Assert.assertEquals(anotherEmployee.getIdentifier(), fetchedGroup.getAssignedEmployee());
   }
 
+  @Test
+  public void shouldUpdateGroup() throws Exception{
+    final GroupDefinition randomGroupDefinition = GroupDefinitionGenerator.createRandomGroupDefinition();
+    this.testSubject.createGroupDefinition(randomGroupDefinition);
+    this.eventRecorder.wait(EventConstants.POST_GROUP_DEFINITION, randomGroupDefinition.getIdentifier());
+
+    final Group randomGroup = GroupGenerator.createRandomGroup(randomGroupDefinition.getIdentifier());
+    this.testSubject.createGroup(randomGroup);
+
+    this.eventRecorder.wait(EventConstants.POST_GROUP, randomGroup.getIdentifier());
+
+    randomGroup.setName(RandomStringUtils.randomAlphanumeric(256));
+
+    this.testSubject.updateGroup(randomGroup.getIdentifier(), randomGroup);
+
+    this.eventRecorder.wait(EventConstants.PUT_GROUP,randomGroup.getIdentifier());
+
+    final Group updatedGroup = this.testSubject.findGroup(randomGroup.getIdentifier());
+    Assert.assertEquals(randomGroup.getName(), updatedGroup.getName());
+
+
+  }
+
   @Configuration
   @EnableEventRecording
   @EnableFeignClients(basePackages = {"org.apache.fineract.cn.group.api.v1.client"})
diff --git a/component-test/src/main/java/org/apache/fineract/cn/group/TestGroupDefinition.java b/component-test/src/main/java/org/apache/fineract/cn/group/TestGroupDefinition.java
index 608cf64..e7a75f0 100644
--- a/component-test/src/main/java/org/apache/fineract/cn/group/TestGroupDefinition.java
+++ b/component-test/src/main/java/org/apache/fineract/cn/group/TestGroupDefinition.java
@@ -54,6 +54,7 @@
 
 @RunWith(SpringRunner.class)
 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
+
 public class TestGroupDefinition {
   private static final String APP_NAME = "group-v1";
   private static final String TEST_USER = "ranefer";
@@ -92,7 +93,7 @@ public void prepTest() {
 
   @After
   public void cleanTest() {
-    TenantContextHolder.clear();
+   //TenantContextHolder.clear();
     userContext.close();
   }
 
@@ -127,6 +128,34 @@ public void shouldCreateGroupDefinition() throws Exception {
     Assert.assertNull(fetchedGroupDefinition.getLastModifiedOn());
   }
 
+
+  @Test
+  public void shouldUpdateGroupDefinition() throws Exception{
+    final GroupDefinition randomGroupDefinition = GroupDefinitionGenerator.createRandomGroupDefinition();
+    this.testSubject.createGroupDefinition(randomGroupDefinition);
+
+    this.eventRecorder.wait(EventConstants.POST_GROUP_DEFINITION, randomGroupDefinition.getIdentifier());
+
+    final GroupDefinition updatedGroupDefinition = GroupDefinitionGenerator.createRandomGroupDefinition();
+    updatedGroupDefinition.setIdentifier(randomGroupDefinition.getIdentifier());
+
+    this.testSubject.updateGroupDefinition(updatedGroupDefinition.getIdentifier(),updatedGroupDefinition);
+
+    this.eventRecorder.wait(EventConstants.PUT_GROUP_DEFINITION, randomGroupDefinition.getIdentifier());
+
+    final GroupDefinition fetchedGroupDefinition = this.testSubject.findGroupDefinition(updatedGroupDefinition.getIdentifier());
+    Assert.assertNotNull(fetchedGroupDefinition);
+    Assert.assertEquals(updatedGroupDefinition.getIdentifier(), fetchedGroupDefinition.getIdentifier());
+    Assert.assertEquals(updatedGroupDefinition.getDescription(), fetchedGroupDefinition.getDescription());
+    Assert.assertEquals(updatedGroupDefinition.getMinimalSize(), fetchedGroupDefinition.getMinimalSize());
+    Assert.assertEquals(updatedGroupDefinition.getMaximalSize(), fetchedGroupDefinition.getMaximalSize());
+    Assert.assertNotNull(fetchedGroupDefinition.getCycle());
+    Assert.assertEquals(updatedGroupDefinition.getCycle().getNumberOfMeetings(), fetchedGroupDefinition.getCycle().getNumberOfMeetings());
+    Assert.assertEquals(updatedGroupDefinition.getCycle().getFrequency(), fetchedGroupDefinition.getCycle().getFrequency());
+  }
+
+
+
   @Configuration
   @EnableEventRecording
   @EnableFeignClients(basePackages = {"org.apache.fineract.cn.group.api.v1.client"})
diff --git a/component-test/src/main/java/org/apache/fineract/cn/group/listener/GroupDefinitionEventListener.java b/component-test/src/main/java/org/apache/fineract/cn/group/listener/GroupDefinitionEventListener.java
index 13dad62..42452a5 100644
--- a/component-test/src/main/java/org/apache/fineract/cn/group/listener/GroupDefinitionEventListener.java
+++ b/component-test/src/main/java/org/apache/fineract/cn/group/listener/GroupDefinitionEventListener.java
@@ -47,4 +47,15 @@ public void onGroupDefinitionCreated(@Header(TenantHeaderFilter.TENANT_HEADER) f
                                        final String payload) {
     this.eventRecorder.event(tenant, EventConstants.POST_GROUP_DEFINITION, payload, String.class);
   }
+
+  @JmsListener(
+          subscription = EventConstants.DESTINATION,
+          destination = EventConstants.DESTINATION,
+          selector = EventConstants.SELECTOR_PUT_GROUP_DEFINITION
+  )
+  public void onGroupDefinitionUpdated(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
+                                       final String payload) {
+    this.eventRecorder.event(tenant, EventConstants.PUT_GROUP_DEFINITION, payload, String.class);
+  }
+
 }
diff --git a/service/src/main/java/org/apache/fineract/cn/group/internal/command/UpdateGroupCommand.java b/service/src/main/java/org/apache/fineract/cn/group/internal/command/UpdateGroupCommand.java
new file mode 100644
index 0000000..c0a5ed9
--- /dev/null
+++ b/service/src/main/java/org/apache/fineract/cn/group/internal/command/UpdateGroupCommand.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.cn.group.internal.command;
+
+import org.apache.fineract.cn.group.api.v1.domain.Group;
+
+public class UpdateGroupCommand {
+
+    private final Group group;
+
+    public UpdateGroupCommand(final Group group) {
+        super();
+        this.group = group;
+    }
+
+    public Group group() {
+        return this.group;
+    }
+}
\ No newline at end of file
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
new file mode 100644
index 0000000..7254ba3
--- /dev/null
+++ b/service/src/main/java/org/apache/fineract/cn/group/internal/command/UpdateGroupDefinitionCommand.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.cn.group.internal.command;
+
+import org.apache.fineract.cn.group.api.v1.domain.GroupDefinition;
+
+public class UpdateGroupDefinitionCommand {
+
+
+    private final GroupDefinition groupDefinition;
+
+    public UpdateGroupDefinitionCommand( final GroupDefinition groupDefinition) {
+        super();
+        this.groupDefinition = groupDefinition;
+    }
+
+    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 2ddf42f..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
@@ -29,11 +29,13 @@
 import org.apache.fineract.cn.group.internal.command.CloseGroupCommand;
 import org.apache.fineract.cn.group.internal.command.CreateGroupCommand;
 import org.apache.fineract.cn.group.internal.command.CreateGroupDefinitionCommand;
+import org.apache.fineract.cn.group.internal.command.UpdateGroupDefinitionCommand;
 import org.apache.fineract.cn.group.internal.command.ReopenGroupCommand;
 import org.apache.fineract.cn.group.internal.command.SignOffMeetingCommand;
 import org.apache.fineract.cn.group.internal.command.UpdateAssignedEmployeeCommand;
 import org.apache.fineract.cn.group.internal.command.UpdateLeadersCommand;
 import org.apache.fineract.cn.group.internal.command.UpdateMembersCommand;
+import org.apache.fineract.cn.group.internal.command.UpdateGroupCommand;
 import org.apache.fineract.cn.group.internal.mapper.AddressMapper;
 import org.apache.fineract.cn.group.internal.mapper.GroupCommandMapper;
 import org.apache.fineract.cn.group.internal.repository.AddressEntity;
@@ -53,6 +55,7 @@
 import java.time.LocalDateTime;
 import java.time.temporal.ChronoField;
 import java.util.List;
+import java.util.Optional;
 import java.util.Set;
 import java.util.stream.Collectors;
 import org.apache.fineract.cn.api.util.UserContextHolder;
@@ -112,6 +115,45 @@ public String createDefinition(final CreateGroupDefinitionCommand createGroupDef
 
     return groupDefinition.getIdentifier();
   }
+//
+//    @Transactional
+//    @CommandHandler
+//    @EventEmitter(selectorName = EventConstants.SELECTOR_NAME, selectorValue = EventConstants.PUT_GROUP_DEFINITION)
+//    public String updateDefinition1(final UpdateGroupDefinitionCommand updateGroupDefinitionCommand) {
+//      final GroupDefinition updatedGroupDefinition = updateGroupDefinitionCommand.groupDefinition();
+//
+//        final Optional<GroupDefinitionEntity> groupDefinitionEntity = this.groupDefinitionRepository.findByIdentifier(updateGroupDefinitionCommand.identifier());
+//      groupDefinitionEntity.setDescription(updatedGroupDefinition.getDescription());
+//        groupDefinitionEntity.setMinimalSize(updatedGroupDefinition.getMinimalSize());
+//        groupDefinitionEntity.setMaximalSize(updatedGroupDefinition.getMaximalSize());
+//        final Cycle cycle = updatedGroupDefinition.getCycle();
+//        groupDefinitionEntity.setNumberOfMeetings(cycle.getNumberOfMeetings());
+//        groupDefinitionEntity.setFrequency(cycle.getFrequency());
+//        groupDefinitionEntity.setAdjustment(cycle.getAdjustment());
+//
+//        this.groupDefinitionRepository.save(groupDefinitionEntity);
+//
+//        return updatedGroupDefinition.getIdentifier();
+//    }
+
+  @Transactional
+  @CommandHandler
+  @EventEmitter(selectorName = EventConstants.SELECTOR_NAME, selectorValue = EventConstants.PUT_GROUP_DEFINITION)
+  public String updateDefinition(final UpdateGroupDefinitionCommand updateGroupDefinitionCommand) {
+      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 groupDefinition.getIdentifier();
+      }
 
   @Transactional
   @CommandHandler
@@ -143,6 +185,43 @@ public String createGroup(final CreateGroupCommand createGroupCommand) {
     return group.getIdentifier();
   }
 
+  // Updating Group
+  @Transactional
+  @CommandHandler
+  @EventEmitter(selectorName = EventConstants.SELECTOR_NAME, selectorValue = EventConstants.PUT_GROUP)
+  public String updateGroup(final UpdateGroupCommand updateGroupCommand) {
+      final Group group = updateGroupCommand.group();
+      final AddressEntity savedAddress = this.addressRepository.save(AddressMapper.map(group.getAddress()));
+      final GroupEntity groupEntity = findGroupEntityOrThrow(group.getIdentifier());
+
+     // groupEntity.setGroupDefinition(groupDefinitionEntity);
+     // groupEntity.setIdentifier(group.getIdentifier());
+      groupEntity.setName(group.getName());
+      groupEntity.setOffice(group.getOffice());
+      groupEntity.setWeekday(group.getWeekday());
+     // groupEntity.setGroupStatus(group.getStatus());
+      //groupEntity.setAddressEntity(group.getAddress());
+
+      if (group.getAssignedEmployee() != null) {
+          this.updateAssignedEmployee(new UpdateAssignedEmployeeCommand(group.getIdentifier(), group.getAssignedEmployee()));
+      }
+
+      if (group.getLeaders() != null) {
+          this.updateLeaders(new UpdateLeadersCommand(group.getIdentifier(), group.getLeaders()));
+      }
+
+      if (group.getMembers() != null) {
+          this.updateMembers(new UpdateMembersCommand(group.getIdentifier(), group.getMembers()));
+      }
+
+
+      groupEntity.setLastModifiedBy(UserContextHolder.checkedGetUser());
+      groupEntity.setLastModifiedOn(LocalDateTime.now(Clock.systemUTC()));
+
+      this.groupRepository.save(groupEntity);
+
+      return group.getIdentifier();
+  }
   @Transactional
   @CommandHandler
   @EventEmitter(selectorName = EventConstants.SELECTOR_NAME, selectorValue = EventConstants.ACTIVATE_GROUP)
@@ -227,7 +306,7 @@ public String updateAssignedEmployee(final UpdateAssignedEmployeeCommand updateA
 
   @Transactional
   @CommandHandler
-  @EventEmitter(selectorName = EventConstants.SELECTOR_NAME, selectorValue = EventConstants.PUT_GROUP)
+  @EventEmitter(selectorName = EventConstants.SELECTOR_NAME, selectorValue = EventConstants.PUT_MEETING)
   public String signOffMeeting(final SignOffMeetingCommand signOffMeetingCommand) {
     this.groupRepository.findByIdentifier(signOffMeetingCommand.groupIdentifier())
         .ifPresent(groupEntity -> {
@@ -336,4 +415,14 @@ private void saveGroupCommand(final GroupEntity groupEntity, final GroupCommand
     groupCommandEntity.setGroup(groupEntity);
     this.groupCommandRepository.save(groupCommandEntity);
   }
+
+    private GroupEntity findGroupEntityOrThrow(String identifier) {
+        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/internal/repository/GroupDefinitionRepository.java b/service/src/main/java/org/apache/fineract/cn/group/internal/repository/GroupDefinitionRepository.java
index 5bb130b..b70d029 100644
--- a/service/src/main/java/org/apache/fineract/cn/group/internal/repository/GroupDefinitionRepository.java
+++ b/service/src/main/java/org/apache/fineract/cn/group/internal/repository/GroupDefinitionRepository.java
@@ -19,12 +19,15 @@
 package org.apache.fineract.cn.group.internal.repository;
 
 import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
 import org.springframework.stereotype.Repository;
 
 import java.util.Optional;
 
 @Repository
 public interface GroupDefinitionRepository extends JpaRepository<GroupDefinitionEntity, Long> {
-
+  @Query("SELECT CASE WHEN COUNT(c) > 0 THEN 'true' ELSE 'false' END FROM GroupDefinitionEntity c WHERE c.identifier = :identifier")
+  Boolean existsByIdentifier(@Param("identifier") final String identifier);
   Optional<GroupDefinitionEntity> findByIdentifier(final String identifier);
 }
diff --git a/service/src/main/java/org/apache/fineract/cn/group/internal/service/GroupDefinitionService.java b/service/src/main/java/org/apache/fineract/cn/group/internal/service/GroupDefinitionService.java
index 6d34e81..19f1c9d 100644
--- a/service/src/main/java/org/apache/fineract/cn/group/internal/service/GroupDefinitionService.java
+++ b/service/src/main/java/org/apache/fineract/cn/group/internal/service/GroupDefinitionService.java
@@ -45,6 +45,10 @@ public GroupDefinitionService(@Qualifier(ServiceConstants.LOGGER_NAME) final Log
     this.groupDefinitionRepository = groupDefinitionRepository;
   }
 
+  public Boolean groupDefinitionExists(final String identifier) {
+    return this.groupDefinitionRepository.existsByIdentifier(identifier);
+  }
+
   public Optional<GroupDefinition> findByIdentifier(final String identifier) {
     return this.groupDefinitionRepository.findByIdentifier(identifier).map(GroupDefinitionMapper::map);
   }
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 a526450..5e6b92b 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
@@ -18,9 +18,11 @@
  */
 package org.apache.fineract.cn.group.rest;
 
+import org.apache.fineract.cn.group.api.v1.PermittableGroupIds;
 import org.apache.fineract.cn.group.api.v1.domain.GroupDefinition;
 import org.apache.fineract.cn.group.ServiceConstants;
 import org.apache.fineract.cn.group.internal.command.CreateGroupDefinitionCommand;
+import org.apache.fineract.cn.group.internal.command.UpdateGroupDefinitionCommand;
 import org.apache.fineract.cn.group.internal.service.GroupDefinitionService;
 import java.util.List;
 import javax.validation.Valid;
@@ -58,7 +60,7 @@ public GroupDefinitionRestController(@Qualifier(ServiceConstants.LOGGER_NAME) fi
     this.groupDefinitionService = groupDefinitionService;
   }
 
-  @Permittable(AcceptedTokenType.TENANT)
+  @Permittable(value= AcceptedTokenType.TENANT, groupId = PermittableGroupIds.DEFINITION)
   @RequestMapping(
       method = RequestMethod.POST,
       consumes = MediaType.APPLICATION_JSON_VALUE,
@@ -67,16 +69,22 @@ public GroupDefinitionRestController(@Qualifier(ServiceConstants.LOGGER_NAME) fi
   public
   @ResponseBody
   ResponseEntity<Void> createDefinition(@RequestBody @Valid final GroupDefinition groupDefinition) {
-    this.groupDefinitionService.findByIdentifier(groupDefinition.getIdentifier())
-        .ifPresent(gd -> {
-          throw ServiceException.conflict("Group definition {0} already exists.", gd.getIdentifier());
-        });
-
-    this.commandGateway.process(new CreateGroupDefinitionCommand(groupDefinition));
+    if (this.groupDefinitionService.groupDefinitionExists(groupDefinition.getIdentifier())) {
+      throw ServiceException.conflict("Group definition {0} already exists.", groupDefinition.getIdentifier());
+    }
+      this.commandGateway.process(new CreateGroupDefinitionCommand(groupDefinition));
     return ResponseEntity.accepted().build();
+
+//    this.groupDefinitionService.findByIdentifier(groupDefinition.getIdentifier())
+//        .ifPresent(gd -> {
+//          throw ServiceException.conflict("Group definition {0} already exists.", gd.getIdentifier());
+//        });
+//
+//    this.commandGateway.process(new CreateGroupDefinitionCommand(groupDefinition));
+//    return ResponseEntity.accepted().build();
   }
 
-  @Permittable(AcceptedTokenType.TENANT)
+  @Permittable(value= AcceptedTokenType.TENANT, groupId = PermittableGroupIds.DEFINITION)
   @RequestMapping(
       method = RequestMethod.GET,
       consumes = MediaType.ALL_VALUE,
@@ -88,7 +96,7 @@ public GroupDefinitionRestController(@Qualifier(ServiceConstants.LOGGER_NAME) fi
     return ResponseEntity.ok(this.groupDefinitionService.fetchAllGroupDefinitions());
   }
 
-  @Permittable(AcceptedTokenType.TENANT)
+  @Permittable(value= AcceptedTokenType.TENANT, groupId = PermittableGroupIds.DEFINITION)
   @RequestMapping(
       value = "/{identifier}",
       method = RequestMethod.GET,
@@ -103,4 +111,30 @@ public GroupDefinitionRestController(@Qualifier(ServiceConstants.LOGGER_NAME) fi
         .map(ResponseEntity::ok)
         .orElseThrow(() -> ServiceException.notFound("Group definition {0} not found.", identifier));
   }
+
+  @Permittable(value = AcceptedTokenType.TENANT, groupId = PermittableGroupIds.DEFINITION)
+  @RequestMapping(
+          value = "/{identifier}",
+          method = RequestMethod.PUT,
+          produces = MediaType.APPLICATION_JSON_VALUE,
+          consumes = MediaType.APPLICATION_JSON_VALUE
+  )
+  public
+  @ResponseBody
+  ResponseEntity<Void> updateGroupDefinition(@PathVariable("identifier") final String identifier, @RequestBody final GroupDefinition groupDefinition) {
+    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();
+ // }
 }
diff --git a/service/src/main/java/org/apache/fineract/cn/group/rest/GroupRestController.java b/service/src/main/java/org/apache/fineract/cn/group/rest/GroupRestController.java
index c9edae9..269f66c 100644
--- a/service/src/main/java/org/apache/fineract/cn/group/rest/GroupRestController.java
+++ b/service/src/main/java/org/apache/fineract/cn/group/rest/GroupRestController.java
@@ -25,6 +25,7 @@
 import org.apache.fineract.cn.group.api.v1.domain.Meeting;
 import org.apache.fineract.cn.group.api.v1.domain.SignOffMeeting;
 import org.apache.fineract.cn.group.ServiceConstants;
+import org.apache.fineract.cn.group.api.v1.PermittableGroupIds;
 import org.apache.fineract.cn.group.internal.command.ActivateGroupCommand;
 import org.apache.fineract.cn.group.internal.command.CloseGroupCommand;
 import org.apache.fineract.cn.group.internal.command.CreateGroupCommand;
@@ -33,6 +34,7 @@
 import org.apache.fineract.cn.group.internal.command.UpdateAssignedEmployeeCommand;
 import org.apache.fineract.cn.group.internal.command.UpdateLeadersCommand;
 import org.apache.fineract.cn.group.internal.command.UpdateMembersCommand;
+import org.apache.fineract.cn.group.internal.command.UpdateGroupCommand;
 import org.apache.fineract.cn.group.internal.service.GroupDefinitionService;
 import org.apache.fineract.cn.group.internal.service.GroupService;
 import java.util.List;
@@ -80,7 +82,7 @@ public GroupRestController(@Qualifier(ServiceConstants.LOGGER_NAME) final Logger
     this.groupDefinitionService = groupDefinitionService;
   }
 
-  @Permittable(AcceptedTokenType.TENANT)
+  @Permittable(value= AcceptedTokenType.TENANT, groupId = PermittableGroupIds.GROUP)
   @RequestMapping(
       method = RequestMethod.POST,
       consumes = MediaType.APPLICATION_JSON_VALUE,
@@ -102,7 +104,7 @@ public GroupRestController(@Qualifier(ServiceConstants.LOGGER_NAME) final Logger
     return ResponseEntity.accepted().build();
   }
 
-  @Permittable(AcceptedTokenType.TENANT)
+  @Permittable(value= AcceptedTokenType.TENANT, groupId = PermittableGroupIds.GROUP)
   @RequestMapping(
       method = RequestMethod.GET,
       consumes = MediaType.ALL_VALUE,
@@ -111,17 +113,17 @@ public GroupRestController(@Qualifier(ServiceConstants.LOGGER_NAME) final Logger
   public
   @ResponseBody
   ResponseEntity<GroupPage> fetchGroups(
-      @RequestParam("employee") final String employee,
-      @RequestParam("page") final Integer page,
-      @RequestParam("size") final Integer size,
-      @RequestParam("sortColumn") final String sortColumn,
-      @RequestParam("sortDirection") final String sortDirection) {
+      @RequestParam(value="employee",required=false) final String employee,
+      @RequestParam(value="page", required=false) final Integer page,
+      @RequestParam(value="size",required=false) final Integer size,
+      @RequestParam(value="sortColumn",required=false) final String sortColumn,
+      @RequestParam(value="sortDirection", required=false) final String sortDirection) {
     return ResponseEntity.ok(
         this.groupService.fetchGroups(employee, this.createPageRequest(page, size, sortColumn, sortDirection))
     );
   }
 
-  @Permittable(AcceptedTokenType.TENANT)
+  @Permittable(value= AcceptedTokenType.TENANT, groupId = PermittableGroupIds.GROUP)
   @RequestMapping(
       value = "/{identifier}",
       method = RequestMethod.GET,
@@ -136,6 +138,27 @@ public GroupRestController(@Qualifier(ServiceConstants.LOGGER_NAME) final Logger
         .orElseThrow(() -> ServiceException.notFound("Group {0} not found.", identifier));
   }
 
+  @Permittable(value= AcceptedTokenType.TENANT, groupId = PermittableGroupIds.GROUP)
+  @RequestMapping(
+          value = "/{identifier}",
+          method = RequestMethod.PUT,
+          consumes = MediaType.ALL_VALUE,
+          produces = MediaType.APPLICATION_JSON_VALUE
+  )
+
+  public
+  @ResponseBody
+  ResponseEntity<Void> updateGroup(@PathVariable("identifier") final String identifier,
+                                      @RequestBody final Group group) {
+    this.groupService.findByIdentifier(identifier)
+            .orElseThrow(() -> ServiceException.notFound("Group {0} not found.", identifier));
+
+    this.commandGateway.process(new UpdateGroupCommand(group));
+
+    return ResponseEntity.accepted().build();
+  }
+
+  @Permittable(value= AcceptedTokenType.TENANT, groupId = PermittableGroupIds.GROUP)
   @RequestMapping(
       value = "/{identifier}/commands",
       method = RequestMethod.POST,
@@ -163,6 +186,7 @@ public GroupRestController(@Qualifier(ServiceConstants.LOGGER_NAME) final Logger
     return ResponseEntity.accepted().build();
   }
 
+  @Permittable(value= AcceptedTokenType.TENANT, groupId = PermittableGroupIds.GROUP)
   @RequestMapping(
       value = "/{identifier}/commands",
       method = RequestMethod.GET,
@@ -175,6 +199,7 @@ public GroupRestController(@Qualifier(ServiceConstants.LOGGER_NAME) final Logger
     return ResponseEntity.ok(this.groupService.findCommandsByIdentifier(identifier));
   }
 
+  @Permittable(value= AcceptedTokenType.TENANT, groupId = PermittableGroupIds.GROUP)
   @RequestMapping(
       value = "/{identifier}/leaders",
       method = RequestMethod.PUT,
@@ -193,6 +218,7 @@ public GroupRestController(@Qualifier(ServiceConstants.LOGGER_NAME) final Logger
     return ResponseEntity.accepted().build();
   }
 
+  @Permittable(value= AcceptedTokenType.TENANT, groupId = PermittableGroupIds.GROUP)
   @RequestMapping(
       value = "/{identifier}/members",
       method = RequestMethod.PUT,
@@ -211,6 +237,7 @@ public GroupRestController(@Qualifier(ServiceConstants.LOGGER_NAME) final Logger
     return ResponseEntity.accepted().build();
   }
 
+  @Permittable(value= AcceptedTokenType.TENANT, groupId = PermittableGroupIds.GROUP)
   @RequestMapping(
       value = "/{identifier}/employee",
       method = RequestMethod.PUT,
@@ -230,6 +257,7 @@ public GroupRestController(@Qualifier(ServiceConstants.LOGGER_NAME) final Logger
     return ResponseEntity.accepted().build();
   }
 
+  @Permittable(value= AcceptedTokenType.TENANT, groupId = PermittableGroupIds.GROUP)
   @RequestMapping(
       value = "/{identifier}/meetings",
       method = RequestMethod.GET,
@@ -245,6 +273,7 @@ public GroupRestController(@Qualifier(ServiceConstants.LOGGER_NAME) final Logger
     return ResponseEntity.ok(this.groupService.findMeetings(groupIdentifier, upcoming));
   }
 
+  @Permittable(value= AcceptedTokenType.TENANT, groupId = PermittableGroupIds.GROUP)
   @RequestMapping(
       value = "/{identifier}/meetings",
       method = RequestMethod.PUT,
diff --git a/service/src/main/resources/bootstrap.yml b/service/src/main/resources/bootstrap.yml
index 93851b3..79e4528 100644
--- a/service/src/main/resources/bootstrap.yml
+++ b/service/src/main/resources/bootstrap.yml
@@ -19,4 +19,4 @@
 
 spring:
     application:
-        name: group-api
+        name: group-v1


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services