You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by aw...@apache.org on 2019/09/03 07:25:51 UTC

[fineract-cn-group] 25/46: Implementing PUT request on Group definition

This is an automated email from the ASF dual-hosted git repository.

awasum pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-group.git

commit f2297c2ed23a99c2a8740967bbeba0f0881c6762
Author: kengneruphine <ru...@gmail.com>
AuthorDate: Sun Jun 24 15:59:05 2018 +0100

    Implementing PUT request on Group definition
---
 .../cn/group/api/v1/client/GroupManager.java       | 12 +++++++
 .../command/UpdateGroupDefinitionCommand.java      | 41 ++++++++++++++++++++++
 .../group/rest/GroupDefinitionRestController.java  | 19 ++++++++++
 3 files changed, 72 insertions(+)

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 e146987..dac2955 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
@@ -76,6 +76,18 @@ public interface GroupManager {
   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,
       produces = MediaType.APPLICATION_JSON_VALUE,
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..cb9c481
--- /dev/null
+++ b/service/src/main/java/org/apache/fineract/cn/group/internal/command/UpdateGroupDefinitionCommand.java
@@ -0,0 +1,41 @@
+/*
+ * 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 String identifier;
+    private final GroupDefinition groupDefinition;
+
+    public UpdateGroupDefinitionCommand(final String identifier, 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/rest/GroupDefinitionRestController.java b/service/src/main/java/org/apache/fineract/cn/group/rest/GroupDefinitionRestController.java
index 8874e76..6bd9ecb 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
@@ -22,6 +22,7 @@ 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;
@@ -110,4 +111,22 @@ public class GroupDefinitionRestController {
         .map(ResponseEntity::ok)
         .orElseThrow(() -> ServiceException.notFound("Group definition {0} not found.", identifier));
   }
+
+  @Permittable(value = AcceptedTokenType.TENANT, groupId = PermittableGroupIds.DEFINITION)
+  @RequestMapping(
+          value = "/definitions/{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) {
+    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();
+  }
 }