fineract-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nazeer1100...@apache.org
Subject [1/2] incubator-fineract git commit: commit for FINERACT-50 (Add 'mandatory' property to code value entity)
Date Fri, 29 Jul 2016 09:03:28 GMT
Repository: incubator-fineract
Updated Branches:
  refs/heads/develop 4232d6c6a -> a232d1b1a


commit for FINERACT-50 (Add 'mandatory' property to code value entity)


Project: http://git-wip-us.apache.org/repos/asf/incubator-fineract/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-fineract/commit/29b663b0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-fineract/tree/29b663b0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-fineract/diff/29b663b0

Branch: refs/heads/develop
Commit: 29b663b00b9de1fdb27d5b988e87e5c076b3e954
Parents: 5ac0da0
Author: Emmanuel Nnaa <emmanuelnnaa@musoni.eu>
Authored: Mon Jul 18 11:29:12 2016 +0200
Committer: Emmanuel Nnaa <emmanuelnnaa@musoni.eu>
Committed: Mon Jul 18 11:32:38 2016 +0200

----------------------------------------------------------------------
 .../infrastructure/codes/CodeConstants.java     |  3 +-
 .../codes/api/CodeValuesApiResource.java        |  7 ++-
 .../codes/data/CodeValueData.java               | 50 ++++++++++++++++----
 .../infrastructure/codes/domain/CodeValue.java  | 24 ++++++++--
 .../CodeValueReadPlatformServiceImpl.java       |  6 ++-
 .../V312__add_is_mandatory_to_code_value.sql    |  1 +
 6 files changed, 72 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/29b663b0/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/CodeConstants.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/CodeConstants.java
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/CodeConstants.java
index 90f71a8..182c4d8 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/CodeConstants.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/CodeConstants.java
@@ -28,7 +28,8 @@ public class CodeConstants {
      * value
      ***/
     public static enum CODEVALUE_JSON_INPUT_PARAMS {
-        CODEVALUE_ID("id"), NAME("name"), POSITION("position"), DESCRIPTION("description"),
IS_ACTIVE("isActive");
+        CODEVALUE_ID("id"), NAME("name"), POSITION("position"), DESCRIPTION("description"),
IS_ACTIVE("isActive"), 
+        IS_MANDATORY("isMandatory");
 
         private final String value;
 

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/29b663b0/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/api/CodeValuesApiResource.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/api/CodeValuesApiResource.java
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/api/CodeValuesApiResource.java
index 77f74f7..4c9faa3 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/api/CodeValuesApiResource.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/api/CodeValuesApiResource.java
@@ -46,6 +46,7 @@ import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
 import org.apache.fineract.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
 import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
 import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
+import org.apache.fineract.infrastructure.codes.CodeConstants.CODEVALUE_JSON_INPUT_PARAMS;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Scope;
 import org.springframework.stereotype.Component;
@@ -58,7 +59,11 @@ public class CodeValuesApiResource {
     /**
      * The set of parameters that are supported in response for {@link CodeData}
      */
-    private final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<>(Arrays.asList("id",
"name", "position", "description"));
+    private final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<>(
+            Arrays.asList(CODEVALUE_JSON_INPUT_PARAMS.CODEVALUE_ID.getValue(), 
+                    CODEVALUE_JSON_INPUT_PARAMS.NAME.getValue(), CODEVALUE_JSON_INPUT_PARAMS.POSITION.getValue(),

+                    CODEVALUE_JSON_INPUT_PARAMS.IS_MANDATORY.getValue(), 
+                    CODEVALUE_JSON_INPUT_PARAMS.DESCRIPTION.getValue()));
     private final String resourceNameForPermissions = "CODEVALUE";
 
     private final PlatformSecurityContext context;

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/29b663b0/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/data/CodeValueData.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/data/CodeValueData.java
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/data/CodeValueData.java
index 2eeb1b0..8b3a819 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/data/CodeValueData.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/data/CodeValueData.java
@@ -34,35 +34,51 @@ public class CodeValueData implements Serializable {
 
     @SuppressWarnings("unused")
     private final String description;
-    private final boolean isActive;
+    private final boolean active;
+    private final boolean mandatory;
 
-    public static CodeValueData instance(final Long id, final String name, final Integer
position, final boolean isActive) {
+    public static CodeValueData instance(final Long id, final String name, final Integer
position, 
+            final boolean isActive, final boolean mandatory) {
         String description = null;
-        return new CodeValueData(id, name, position, description,isActive);
+        return new CodeValueData(id, name, position, description, isActive, mandatory);
     }
 
-    public static CodeValueData instance(final Long id, final String name, final String description,
final boolean isActive) {
+    public static CodeValueData instance(final Long id, final String name, final String description,

+            final boolean isActive, final boolean mandatory) {
         Integer position = null;
-        return new CodeValueData(id, name, position, description,isActive);
+        return new CodeValueData(id, name, position, description, isActive, mandatory);
+    }
+    
+    public static CodeValueData instance(final Long id, final String name, final String description,

+            final boolean isActive) {
+        Integer position = null;
+        boolean mandatory = false;
+        
+        return new CodeValueData(id, name, position, description, isActive, mandatory);
     }
 
     public static CodeValueData instance(final Long id, final String name) {
         String description = null;
         Integer position = null;
         boolean isActive = false;
-        return new CodeValueData(id, name, position, description, isActive);
+        boolean mandatory = false;
+        
+        return new CodeValueData(id, name, position, description, isActive, mandatory);
     }
 
-    public static CodeValueData instance(final Long id, final String name, final Integer
position, final String description, final boolean isActive) {
-        return new CodeValueData(id, name, position, description,isActive);
+    public static CodeValueData instance(final Long id, final String name, final Integer
position, 
+            final String description, final boolean isActive, final boolean mandatory) {
+        return new CodeValueData(id, name, position, description, isActive, mandatory);
     }
 
-    private CodeValueData(final Long id, final String name, final Integer position, final
String description, final boolean isActive) {
+    private CodeValueData(final Long id, final String name, final Integer position, final
String description, 
+            final boolean active, final boolean mandatory) {
         this.id = id;
         this.name = name;
         this.position = position;
         this.description = description;
-        this.isActive = isActive;
+        this.active = active;
+        this.mandatory = mandatory;
     }
 
     public Long getId() {
@@ -72,4 +88,18 @@ public class CodeValueData implements Serializable {
     public String getName() {
         return this.name;
     }
+    
+    /**
+     * @return the mandatory
+     */
+    public boolean isMandatory() {
+        return mandatory;
+    }
+
+    /**
+     * @return the active
+     */
+    public boolean isActive() {
+        return active;
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/29b663b0/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/domain/CodeValue.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/domain/CodeValue.java
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/domain/CodeValue.java
index a9029f6..5045c67 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/domain/CodeValue.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/domain/CodeValue.java
@@ -53,22 +53,27 @@ public class CodeValue extends AbstractPersistable<Long> {
 
     @Column(name = "is_active")
     private boolean isActive;
+    
+    @Column(name = "is_mandatory")
+    private boolean mandatory;
 
     public static CodeValue createNew(final Code code, final String label, final int position,
final String description,
-            final boolean isActive) {
-        return new CodeValue(code, label, position, description, isActive);
+            final boolean isActive, final boolean mandatory) {
+        return new CodeValue(code, label, position, description, isActive, mandatory);
     }
 
     protected CodeValue() {
         //
     }
 
-    private CodeValue(final Code code, final String label, final int position, final String
description, final boolean isActive) {
+    private CodeValue(final Code code, final String label, final int position, final String
description, 
+            final boolean isActive, final boolean mandatory) {
         this.code = code;
         this.label = StringUtils.defaultIfEmpty(label, null);
         this.position = position;
         this.description = description;
         this.isActive = isActive;
+        this.mandatory = mandatory;
     }
 
     public String label() {
@@ -92,7 +97,16 @@ public class CodeValue extends AbstractPersistable<Long> {
         if (position == null) {
             position = new Integer(0);
         }
-        return new CodeValue(code, label, position.intValue(), description, isActive);
+        
+        Boolean mandatory = command.booleanPrimitiveValueOfParameterNamed(
+                CODEVALUE_JSON_INPUT_PARAMS.IS_MANDATORY.getValue());
+        
+        // if the "mandatory" Boolean object is null, then set it to false by default
+        if (mandatory == null) {
+            mandatory = false;
+        }
+        
+        return new CodeValue(code, label, position.intValue(), description, isActive, mandatory);
     }
 
     public Map<String, Object> update(final JsonCommand command) {
@@ -131,6 +145,6 @@ public class CodeValue extends AbstractPersistable<Long> {
     }
 
     public CodeValueData toData() {
-        return CodeValueData.instance(getId(), this.label, this.position, this.isActive);
+        return CodeValueData.instance(getId(), this.label, this.position, this.isActive,
this.mandatory);
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/29b663b0/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/service/CodeValueReadPlatformServiceImpl.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/service/CodeValueReadPlatformServiceImpl.java
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/service/CodeValueReadPlatformServiceImpl.java
index de13981..a33c427 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/service/CodeValueReadPlatformServiceImpl.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/service/CodeValueReadPlatformServiceImpl.java
@@ -49,7 +49,7 @@ public class CodeValueReadPlatformServiceImpl implements CodeValueReadPlatformSe
 
         public String schema() {
             return " cv.id as id, cv.code_value as value, cv.code_id as codeId, cv.code_description
as description, cv.order_position as position,"
-                    + " cv.is_active isActive from m_code_value as cv join m_code c on cv.code_id
= c.id ";
+                    + " cv.is_active isActive, cv.is_mandatory as mandatory from m_code_value
as cv join m_code c on cv.code_id = c.id ";
         }
 
         @Override
@@ -60,7 +60,9 @@ public class CodeValueReadPlatformServiceImpl implements CodeValueReadPlatformSe
             final Integer position = rs.getInt("position");
             final String description = rs.getString("description");
             final boolean isActive = rs.getBoolean("isActive");
-            return CodeValueData.instance(id, value, position, description, isActive);
+            final boolean mandatory = rs.getBoolean("mandatory");
+            
+            return CodeValueData.instance(id, value, position, description, isActive, mandatory);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/29b663b0/fineract-provider/src/main/resources/sql/migrations/core_db/V312__add_is_mandatory_to_code_value.sql
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/resources/sql/migrations/core_db/V312__add_is_mandatory_to_code_value.sql
b/fineract-provider/src/main/resources/sql/migrations/core_db/V312__add_is_mandatory_to_code_value.sql
new file mode 100644
index 0000000..21a992d
--- /dev/null
+++ b/fineract-provider/src/main/resources/sql/migrations/core_db/V312__add_is_mandatory_to_code_value.sql
@@ -0,0 +1 @@
+alter table `m_code_value` add `is_mandatory` tinyint(1) not null default '0'; 


Mime
View raw message