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

This commit is contained in:
Emmanuel Nnaa
2016-07-18 11:32:38 +02:00
parent 5ac0da03d3
commit 29b663b00b
6 changed files with 72 additions and 19 deletions
@@ -28,7 +28,8 @@ public class CodeConstants {
* value * value
***/ ***/
public static enum CODEVALUE_JSON_INPUT_PARAMS { 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; private final String value;
@@ -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.ApiRequestJsonSerializationSettings;
import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer; import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; 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.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@@ -58,7 +59,11 @@ public class CodeValuesApiResource {
/** /**
* The set of parameters that are supported in response for {@link CodeData} * 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 String resourceNameForPermissions = "CODEVALUE";
private final PlatformSecurityContext context; private final PlatformSecurityContext context;
@@ -34,35 +34,51 @@ public class CodeValueData implements Serializable {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final String description; 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; 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; 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) { public static CodeValueData instance(final Long id, final String name) {
String description = null; String description = null;
Integer position = null; Integer position = null;
boolean isActive = false; 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) { public static CodeValueData instance(final Long id, final String name, final Integer position,
return new CodeValueData(id, name, position, description,isActive); 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.id = id;
this.name = name; this.name = name;
this.position = position; this.position = position;
this.description = description; this.description = description;
this.isActive = isActive; this.active = active;
this.mandatory = mandatory;
} }
public Long getId() { public Long getId() {
@@ -72,4 +88,18 @@ public class CodeValueData implements Serializable {
public String getName() { public String getName() {
return this.name; return this.name;
} }
/**
* @return the mandatory
*/
public boolean isMandatory() {
return mandatory;
}
/**
* @return the active
*/
public boolean isActive() {
return active;
}
} }
@@ -54,21 +54,26 @@ public class CodeValue extends AbstractPersistable<Long> {
@Column(name = "is_active") @Column(name = "is_active")
private boolean isActive; 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, public static CodeValue createNew(final Code code, final String label, final int position, final String description,
final boolean isActive) { final boolean isActive, final boolean mandatory) {
return new CodeValue(code, label, position, description, isActive); return new CodeValue(code, label, position, description, isActive, mandatory);
} }
protected CodeValue() { 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.code = code;
this.label = StringUtils.defaultIfEmpty(label, null); this.label = StringUtils.defaultIfEmpty(label, null);
this.position = position; this.position = position;
this.description = description; this.description = description;
this.isActive = isActive; this.isActive = isActive;
this.mandatory = mandatory;
} }
public String label() { public String label() {
@@ -92,7 +97,16 @@ public class CodeValue extends AbstractPersistable<Long> {
if (position == null) { if (position == null) {
position = new Integer(0); 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) { public Map<String, Object> update(final JsonCommand command) {
@@ -131,6 +145,6 @@ public class CodeValue extends AbstractPersistable<Long> {
} }
public CodeValueData toData() { 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);
} }
} }
@@ -49,7 +49,7 @@ public class CodeValueReadPlatformServiceImpl implements CodeValueReadPlatformSe
public String schema() { 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," 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 @Override
@@ -60,7 +60,9 @@ public class CodeValueReadPlatformServiceImpl implements CodeValueReadPlatformSe
final Integer position = rs.getInt("position"); final Integer position = rs.getInt("position");
final String description = rs.getString("description"); final String description = rs.getString("description");
final boolean isActive = rs.getBoolean("isActive"); 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);
} }
} }
@@ -0,0 +1 @@
alter table `m_code_value` add `is_mandatory` tinyint(1) not null default '0';