CC-48:enabling code values based on active or inactive status
This commit is contained in:
+1
-1
@@ -15,7 +15,7 @@ public class CodeConstants {
|
||||
* value
|
||||
***/
|
||||
public static enum CODEVALUE_JSON_INPUT_PARAMS {
|
||||
CODEVALUE_ID("id"), NAME("name"), POSITION("position"), DESCRIPTION("description");
|
||||
CODEVALUE_ID("id"), NAME("name"), POSITION("position"), DESCRIPTION("description"), IS_ACTIVE("isActive");
|
||||
|
||||
private final String value;
|
||||
|
||||
|
||||
+11
-8
@@ -21,32 +21,35 @@ public class CodeValueData implements Serializable {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final String description;
|
||||
private final boolean isActive;
|
||||
|
||||
public static CodeValueData instance(final Long id, final String name, final Integer position) {
|
||||
public static CodeValueData instance(final Long id, final String name, final Integer position, final boolean isActive) {
|
||||
String description = null;
|
||||
return new CodeValueData(id, name, position, description);
|
||||
return new CodeValueData(id, name, position, description,isActive);
|
||||
}
|
||||
|
||||
public static CodeValueData instance(final Long id, final String name, final String description) {
|
||||
public static CodeValueData instance(final Long id, final String name, final String description, final boolean isActive) {
|
||||
Integer position = null;
|
||||
return new CodeValueData(id, name, position, description);
|
||||
return new CodeValueData(id, name, position, description,isActive);
|
||||
}
|
||||
|
||||
public static CodeValueData instance(final Long id, final String name) {
|
||||
String description = null;
|
||||
Integer position = null;
|
||||
return new CodeValueData(id, name, position, description);
|
||||
boolean isActive = false;
|
||||
return new CodeValueData(id, name, position, description, isActive);
|
||||
}
|
||||
|
||||
public static CodeValueData instance(final Long id, final String name, final Integer position, final String description) {
|
||||
return new CodeValueData(id, name, position, description);
|
||||
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);
|
||||
}
|
||||
|
||||
private CodeValueData(final Long id, final String name, final Integer position, final String description) {
|
||||
private CodeValueData(final Long id, final String name, final Integer position, final String description, final boolean isActive) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.position = position;
|
||||
this.description = description;
|
||||
this.isActive = isActive;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
|
||||
+17
-5
@@ -38,19 +38,23 @@ public class CodeValue extends AbstractPersistable<Long> {
|
||||
@JoinColumn(name = "code_id", nullable = false)
|
||||
private Code code;
|
||||
|
||||
public static CodeValue createNew(final Code code, final String label, final int position, final String description) {
|
||||
return new CodeValue(code, label, position, description);
|
||||
@Column(name = "is_active")
|
||||
private boolean isActive;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
protected CodeValue() {
|
||||
//
|
||||
}
|
||||
|
||||
private CodeValue(final Code code, final String label, final int position, final String description) {
|
||||
private CodeValue(final Code code, final String label, final int position, final String description, final boolean isActive) {
|
||||
this.code = code;
|
||||
this.label = StringUtils.defaultIfEmpty(label, null);
|
||||
this.position = position;
|
||||
this.description = description;
|
||||
this.isActive = isActive;
|
||||
}
|
||||
|
||||
public String label() {
|
||||
@@ -66,10 +70,11 @@ public class CodeValue extends AbstractPersistable<Long> {
|
||||
final String label = command.stringValueOfParameterNamed(CODEVALUE_JSON_INPUT_PARAMS.NAME.getValue());
|
||||
Integer position = command.integerValueSansLocaleOfParameterNamed(CODEVALUE_JSON_INPUT_PARAMS.POSITION.getValue());
|
||||
String description = command.stringValueOfParameterNamed(CODEVALUE_JSON_INPUT_PARAMS.DESCRIPTION.getValue());
|
||||
boolean isActive = command.booleanPrimitiveValueOfParameterNamed(CODEVALUE_JSON_INPUT_PARAMS.IS_ACTIVE.getValue());
|
||||
if (position == null) {
|
||||
position = new Integer(0);
|
||||
}
|
||||
return new CodeValue(code, label, position.intValue(),description);
|
||||
return new CodeValue(code, label, position.intValue(), description, isActive);
|
||||
}
|
||||
|
||||
public Map<String, Object> update(final JsonCommand command) {
|
||||
@@ -96,11 +101,18 @@ public class CodeValue extends AbstractPersistable<Long> {
|
||||
actualChanges.put(positionParamName, newValue);
|
||||
this.position = newValue.intValue();
|
||||
}
|
||||
|
||||
final String isActiveParamName = CODEVALUE_JSON_INPUT_PARAMS.IS_ACTIVE.getValue();
|
||||
if (command.isChangeInBooleanParameterNamed(isActiveParamName, this.isActive)) {
|
||||
final Boolean newValue = command.booleanPrimitiveValueOfParameterNamed(isActiveParamName);
|
||||
actualChanges.put(isActiveParamName, newValue);
|
||||
this.isActive = newValue.booleanValue();
|
||||
}
|
||||
|
||||
return actualChanges;
|
||||
}
|
||||
|
||||
public CodeValueData toData() {
|
||||
return CodeValueData.instance(getId(), this.label, this.position);
|
||||
return CodeValueData.instance(getId(), this.label, this.position, this.isActive);
|
||||
}
|
||||
}
|
||||
+8
@@ -66,6 +66,9 @@ public final class CodeValueCommandFromApiJsonDeserializer {
|
||||
// Validate input value is a valid Integer
|
||||
this.fromApiJsonHelper.extractIntegerSansLocaleNamed(CODEVALUE_JSON_INPUT_PARAMS.POSITION.getValue(), element);
|
||||
}
|
||||
|
||||
final Boolean isActive = this.fromApiJsonHelper.extractBooleanNamed(CODEVALUE_JSON_INPUT_PARAMS.IS_ACTIVE.getValue(), element);
|
||||
baseDataValidator.reset().parameter(CODEVALUE_JSON_INPUT_PARAMS.IS_ACTIVE.getValue()).value(isActive).validateForBooleanValue();
|
||||
|
||||
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||
}
|
||||
@@ -97,6 +100,11 @@ public final class CodeValueCommandFromApiJsonDeserializer {
|
||||
// Validate input value is a valid Integer
|
||||
this.fromApiJsonHelper.extractIntegerSansLocaleNamed(CODEVALUE_JSON_INPUT_PARAMS.POSITION.getValue(), element);
|
||||
}
|
||||
|
||||
if (this.fromApiJsonHelper.parameterExists(CODEVALUE_JSON_INPUT_PARAMS.IS_ACTIVE.getValue(), element)) {
|
||||
final Boolean isActive = this.fromApiJsonHelper.extractBooleanNamed(CODEVALUE_JSON_INPUT_PARAMS.IS_ACTIVE.getValue(), element);
|
||||
baseDataValidator.reset().parameter(CODEVALUE_JSON_INPUT_PARAMS.IS_ACTIVE.getValue()).value(isActive).validateForBooleanValue();
|
||||
}
|
||||
|
||||
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||
}
|
||||
|
||||
+5
-4
@@ -35,8 +35,8 @@ public class CodeValueReadPlatformServiceImpl implements CodeValueReadPlatformSe
|
||||
private static final class CodeValueDataMapper implements RowMapper<CodeValueData> {
|
||||
|
||||
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"
|
||||
+ " from m_code_value as cv join m_code c on cv.code_id = c.id ";
|
||||
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 ";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -46,7 +46,8 @@ public class CodeValueReadPlatformServiceImpl implements CodeValueReadPlatformSe
|
||||
final String value = rs.getString("value");
|
||||
final Integer position = rs.getInt("position");
|
||||
final String description = rs.getString("description");
|
||||
return CodeValueData.instance(id, value, position, description);
|
||||
final boolean isActive = rs.getBoolean("isActive");
|
||||
return CodeValueData.instance(id, value, position, description, isActive);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +57,7 @@ public class CodeValueReadPlatformServiceImpl implements CodeValueReadPlatformSe
|
||||
this.context.authenticatedUser();
|
||||
|
||||
final CodeValueDataMapper rm = new CodeValueDataMapper();
|
||||
final String sql = "select " + rm.schema() + "where c.code_name like ? order by position";
|
||||
final String sql = "select " + rm.schema() + "where c.code_name like ? and cv.is_active = 1 order by position";
|
||||
|
||||
return this.jdbcTemplate.query(sql, rm, new Object[] { code });
|
||||
}
|
||||
|
||||
+6
-3
@@ -183,7 +183,8 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
|
||||
}
|
||||
|
||||
if (displayName != null) {
|
||||
extraCriteria += " and concat(ifnull(c.firstname, ''), if(c.firstname > '',' ', '') , ifnull(c.lastname, '')) like "
|
||||
//extraCriteria += " and concat(ifnull(c.firstname, ''), if(c.firstname > '',' ', '') , ifnull(c.lastname, '')) like "
|
||||
extraCriteria += " and c.display_name like "
|
||||
+ ApiParameterHelper.sqlEncodeString("%" + displayName + "%");
|
||||
}
|
||||
|
||||
@@ -353,7 +354,8 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
|
||||
final Long subStatusId = JdbcSupport.getLong(rs, "subStatus");
|
||||
final String subStatusValue = rs.getString("subStatusValue");
|
||||
final String subStatusDesc = rs.getString("subStatusDesc");
|
||||
final CodeValueData subStatus = CodeValueData.instance(subStatusId, subStatusValue, subStatusDesc);
|
||||
final boolean isActive = false;
|
||||
final CodeValueData subStatus = CodeValueData.instance(subStatusId, subStatusValue, subStatusDesc, isActive);
|
||||
|
||||
final Long officeId = JdbcSupport.getLong(rs, "officeId");
|
||||
final String officeName = rs.getString("officeName");
|
||||
@@ -504,7 +506,8 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
|
||||
final Long subStatusId = JdbcSupport.getLong(rs, "subStatus");
|
||||
final String subStatusValue = rs.getString("subStatusValue");
|
||||
final String subStatusDesc = rs.getString("subStatusDesc");
|
||||
final CodeValueData subStatus = CodeValueData.instance(subStatusId, subStatusValue, subStatusDesc);
|
||||
final boolean isActive = false;
|
||||
final CodeValueData subStatus = CodeValueData.instance(subStatusId, subStatusValue, subStatusDesc, isActive);
|
||||
|
||||
final Long officeId = JdbcSupport.getLong(rs, "officeId");
|
||||
final String officeName = rs.getString("officeName");
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE `m_code_value`
|
||||
ADD COLUMN `is_active` TINYINT(1) NOT NULL DEFAULT '1' AFTER `code_score`;
|
||||
Reference in New Issue
Block a user