MIFOSX-1674:The description field added to m_code_value can be edited/entered

This commit is contained in:
MithunKashyap
2014-12-02 16:18:29 +05:30
parent 06dfb9d732
commit d644fa9123
8 changed files with 123 additions and 76 deletions
@@ -15,7 +15,7 @@ public class CodeConstants {
* value
***/
public static enum CODEVALUE_JSON_INPUT_PARAMS {
CODEVALUE_ID("id"), NAME("name"), POSITION("position");
CODEVALUE_ID("id"), NAME("name"), POSITION("position"), DESCRIPTION("description");
private final String value;
@@ -19,32 +19,36 @@ public class CodeValueData implements Serializable {
@SuppressWarnings("unused")
private final Integer position;
@SuppressWarnings("unused")
private final String description;
public static CodeValueData instance(final Long id, final String name, final Integer position) {
String description = null;
return new CodeValueData(id, name, position, description);
}
return new CodeValueData(id, name, position, description);
}
public static CodeValueData instance(final Long id, final String name, final String description) {
Integer position = null;
return new CodeValueData(id, name, position, description);
}
Integer position = null;
return new CodeValueData(id, name, position, description);
}
public static CodeValueData instance(final Long id, final String name) {
String description = null;
Integer position=null;
Integer position = null;
return new CodeValueData(id, name, position, description);
}
}
private CodeValueData(final Long id, final String name, final Integer position, final String description) {
this.id = id;
this.name = name;
this.position = position;
this.description = description;
}
public static CodeValueData instance(final Long id, final String name, final Integer position, final String description) {
return new CodeValueData(id, name, position, description);
}
private CodeValueData(final Long id, final String name, final Integer position, final String description) {
this.id = id;
this.name = name;
this.position = position;
this.description = description;
}
public Long getId() {
return this.id;
@@ -31,22 +31,26 @@ public class CodeValue extends AbstractPersistable<Long> {
@Column(name = "order_position")
private int position;
@Column(name = "code_description")
private String description;
@ManyToOne
@JoinColumn(name = "code_id", nullable = false)
private Code code;
public static CodeValue createNew(final Code code, final String label, final int position) {
return new CodeValue(code, label, position);
public static CodeValue createNew(final Code code, final String label, final int position, final String description) {
return new CodeValue(code, label, position, description);
}
protected CodeValue() {
//
}
private CodeValue(final Code code, final String label, final int position) {
private CodeValue(final Code code, final String label, final int position, final String description) {
this.code = code;
this.label = StringUtils.defaultIfEmpty(label, null);
this.position = position;
this.description = description;
}
public String label() {
@@ -61,10 +65,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());
if (position == null) {
position = new Integer(0);
}
return new CodeValue(code, label, position.intValue());
return new CodeValue(code, label, position.intValue(),description);
}
public Map<String, Object> update(final JsonCommand command) {
@@ -77,6 +82,13 @@ public class CodeValue extends AbstractPersistable<Long> {
actualChanges.put(labelParamName, newValue);
this.label = StringUtils.defaultIfEmpty(newValue, null);
}
final String decriptionParamName = CODEVALUE_JSON_INPUT_PARAMS.DESCRIPTION.getValue();
if (command.isChangeInStringParameterNamed(decriptionParamName, this.description)) {
final String newValue = command.stringValueOfParameterNamed(decriptionParamName);
actualChanges.put(decriptionParamName, newValue);
this.description = StringUtils.defaultIfEmpty(newValue, null);
}
final String positionParamName = CODEVALUE_JSON_INPUT_PARAMS.POSITION.getValue();
if (command.isChangeInIntegerSansLocaleParameterNamed(positionParamName, this.position)) {
@@ -55,6 +55,13 @@ public final class CodeValueCommandFromApiJsonDeserializer {
final String name = this.fromApiJsonHelper.extractStringNamed(CODEVALUE_JSON_INPUT_PARAMS.NAME.getValue(), element);
baseDataValidator.reset().parameter(CODEVALUE_JSON_INPUT_PARAMS.NAME.getValue()).value(name).notBlank().notExceedingLengthOf(100);
if (this.fromApiJsonHelper.parameterExists(CODEVALUE_JSON_INPUT_PARAMS.DESCRIPTION.getValue(), element)) {
final String description = this.fromApiJsonHelper.extractStringNamed(CODEVALUE_JSON_INPUT_PARAMS.DESCRIPTION.getValue(),
element);
baseDataValidator.reset().parameter(CODEVALUE_JSON_INPUT_PARAMS.DESCRIPTION.getValue()).value(description)
.notExceedingLengthOf(500);
}
if (this.fromApiJsonHelper.parameterExists(CODEVALUE_JSON_INPUT_PARAMS.POSITION.getValue(), element)) {
// Validate input value is a valid Integer
this.fromApiJsonHelper.extractIntegerSansLocaleNamed(CODEVALUE_JSON_INPUT_PARAMS.POSITION.getValue(), element);
@@ -79,6 +86,12 @@ public final class CodeValueCommandFromApiJsonDeserializer {
baseDataValidator.reset().parameter(CODEVALUE_JSON_INPUT_PARAMS.NAME.getValue()).value(name).notBlank()
.notExceedingLengthOf(100);
}
if (this.fromApiJsonHelper.parameterExists(CODEVALUE_JSON_INPUT_PARAMS.DESCRIPTION.getValue(), element)) {
final String description = this.fromApiJsonHelper.extractStringNamed(CODEVALUE_JSON_INPUT_PARAMS.DESCRIPTION.getValue(),
element);
baseDataValidator.reset().parameter(CODEVALUE_JSON_INPUT_PARAMS.DESCRIPTION.getValue()).value(description)
.notExceedingLengthOf(500);
}
if (this.fromApiJsonHelper.parameterExists(CODEVALUE_JSON_INPUT_PARAMS.POSITION.getValue(), element)) {
// Validate input value is a valid Integer
@@ -35,7 +35,7 @@ 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.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"
+ " from m_code_value as cv join m_code c on cv.code_id = c.id ";
}
@@ -45,8 +45,8 @@ public class CodeValueReadPlatformServiceImpl implements CodeValueReadPlatformSe
final Long id = rs.getLong("id");
final String value = rs.getString("value");
final Integer position = rs.getInt("position");
return CodeValueData.instance(id, value, position);
final String description = rs.getString("description");
return CodeValueData.instance(id, value, position, description);
}
}
@@ -76,19 +76,16 @@ public class CodeValueReadPlatformServiceImpl implements CodeValueReadPlatformSe
@Override
public CodeValueData retrieveCodeValue(final Long codeValueId) {
try {
this.context.authenticatedUser();
try {
this.context.authenticatedUser();
final CodeValueDataMapper rm = new CodeValueDataMapper();
final String sql = "select " + rm.schema()
+ "where cv.id = ? order by position";
return this.jdbcTemplate.queryForObject(sql, rm,
new Object[] { codeValueId });
} catch (final EmptyResultDataAccessException e) {
throw new CodeValueNotFoundException(codeValueId);
}
final CodeValueDataMapper rm = new CodeValueDataMapper();
final String sql = "select " + rm.schema() + "where cv.id = ? order by position";
return this.jdbcTemplate.queryForObject(sql, rm, new Object[] { codeValueId });
} catch (final EmptyResultDataAccessException e) {
throw new CodeValueNotFoundException(codeValueId);
}
}
}