MIFOSX-132: tidy up of code and code values implementation so far.
This commit is contained in:
+1
-1
@@ -17,7 +17,6 @@ import org.mifosng.platform.client.domain.Note;
|
||||
import org.mifosng.platform.client.domain.NoteRepository;
|
||||
import org.mifosng.platform.exceptions.ClientIdentifierNotFoundException;
|
||||
import org.mifosng.platform.exceptions.ClientNotFoundException;
|
||||
import org.mifosng.platform.exceptions.CodeValueNotFoundException;
|
||||
import org.mifosng.platform.exceptions.DocumentManagementException;
|
||||
import org.mifosng.platform.exceptions.DuplicateClientIdentifierException;
|
||||
import org.mifosng.platform.exceptions.NoteNotFoundException;
|
||||
@@ -27,6 +26,7 @@ import org.mifosng.platform.infrastructure.Base64EncodedImage;
|
||||
import org.mifosng.platform.infrastructure.FileUtils;
|
||||
import org.mifosplatform.infrastructure.codes.domain.CodeValue;
|
||||
import org.mifosplatform.infrastructure.codes.domain.CodeValueRepository;
|
||||
import org.mifosplatform.infrastructure.codes.exception.CodeValueNotFoundException;
|
||||
import org.mifosplatform.infrastructure.office.domain.Office;
|
||||
import org.mifosplatform.infrastructure.office.domain.OfficeRepository;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
|
||||
+4
-1
@@ -9,9 +9,12 @@ public class CodeData {
|
||||
private final Long id;
|
||||
@SuppressWarnings("unused")
|
||||
private final String name;
|
||||
@SuppressWarnings("unused")
|
||||
private final boolean systemDefined;
|
||||
|
||||
public CodeData(final Long id, final String name) {
|
||||
public CodeData(final Long id, final String name, final boolean systemDefined) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.systemDefined = systemDefined;
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -22,7 +22,7 @@ public class Code extends AbstractPersistable<Long> {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Column(name = "code_name", length = 100)
|
||||
private String codeName;
|
||||
private String name;
|
||||
|
||||
@Column(name = "is_system_defined")
|
||||
private final boolean systemDefined;
|
||||
@@ -40,8 +40,8 @@ public class Code extends AbstractPersistable<Long> {
|
||||
this.systemDefined = false;
|
||||
}
|
||||
|
||||
private Code(final String codeName) {
|
||||
this.codeName = codeName;
|
||||
private Code(final String name) {
|
||||
this.name = name;
|
||||
this.systemDefined = false;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public class Code extends AbstractPersistable<Long> {
|
||||
}
|
||||
|
||||
if (command.isNameChanged()) {
|
||||
this.codeName = StringUtils.defaultIfEmpty(command.getName(), null);
|
||||
this.name = StringUtils.defaultIfEmpty(command.getName(), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -4,5 +4,6 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
|
||||
public interface CodeRepository extends JpaRepository<Code, Long>, JpaSpecificationExecutor<Code> {
|
||||
// no added behaviour
|
||||
}
|
||||
|
||||
Code findOneByName(String name);
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package org.mifosplatform.infrastructure.codes.exception;
|
||||
|
||||
import org.mifosng.platform.exceptions.AbstractPlatformResourceNotFoundException;
|
||||
|
||||
/**
|
||||
* A {@link RuntimeException} thrown when a code is not found.
|
||||
*/
|
||||
public class CodeNotFoundException extends AbstractPlatformResourceNotFoundException {
|
||||
|
||||
public CodeNotFoundException(final String name) {
|
||||
super("error.msg.code.not.found", "Code with name `" + name + "` does not exist", name);
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -1,11 +1,13 @@
|
||||
package org.mifosng.platform.exceptions;
|
||||
package org.mifosplatform.infrastructure.codes.exception;
|
||||
|
||||
import org.mifosng.platform.exceptions.AbstractPlatformResourceNotFoundException;
|
||||
|
||||
/**
|
||||
* A {@link RuntimeException} thrown when client resources are not found.
|
||||
*/
|
||||
public class CodeValueNotFoundException extends AbstractPlatformResourceNotFoundException {
|
||||
|
||||
public CodeValueNotFoundException(Long id) {
|
||||
public CodeValueNotFoundException(final Long id) {
|
||||
super("error.msg.codevalue.id.invalid", "Code value with identifier " + id + " does not exist", id);
|
||||
}
|
||||
}
|
||||
+4
-3
@@ -29,7 +29,7 @@ public class CodeReadPlatformServiceImpl implements CodeReadPlatformService {
|
||||
private static final class CodeMapper implements RowMapper<CodeData> {
|
||||
|
||||
public String schema() {
|
||||
return " c.id as id, c.code_name as code_name from m_code c ";
|
||||
return " c.id as id, c.code_name as code_name, c.is_system_defined as systemDefined from m_code c ";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -37,8 +37,9 @@ public class CodeReadPlatformServiceImpl implements CodeReadPlatformService {
|
||||
|
||||
final Long id = rs.getLong("id");
|
||||
final String code_name = rs.getString("code_name");
|
||||
|
||||
return new CodeData(id, code_name);
|
||||
final boolean systemDefined = rs.getBoolean("systemDefined");
|
||||
|
||||
return new CodeData(id, code_name, systemDefined);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -5,9 +5,9 @@ import org.mifosplatform.infrastructure.codes.command.CodeCommand;
|
||||
|
||||
public interface CodeWritePlatformService {
|
||||
|
||||
Long createCode(final CodeCommand command);
|
||||
Long createCode(CodeCommand command);
|
||||
|
||||
Long updateCode(final CodeCommand command);
|
||||
Long updateCode(CodeCommand command);
|
||||
|
||||
EntityIdentifier deleteCode(final CodeCommand command);
|
||||
EntityIdentifier deleteCode(CodeCommand command);
|
||||
}
|
||||
+8
-12
@@ -2,11 +2,11 @@ package org.mifosplatform.infrastructure.codes.service;
|
||||
|
||||
import org.mifosng.platform.api.data.EntityIdentifier;
|
||||
import org.mifosng.platform.client.service.RollbackTransactionAsCommandIsNotApprovedByCheckerException;
|
||||
import org.mifosng.platform.exceptions.CodeValueNotFoundException;
|
||||
import org.mifosng.platform.exceptions.PlatformDataIntegrityException;
|
||||
import org.mifosplatform.infrastructure.codes.command.CodeCommand;
|
||||
import org.mifosplatform.infrastructure.codes.domain.Code;
|
||||
import org.mifosplatform.infrastructure.codes.domain.CodeRepository;
|
||||
import org.mifosplatform.infrastructure.codes.exception.CodeNotFoundException;
|
||||
import org.mifosplatform.infrastructure.codes.exception.SystemDefinedCodeCannotBeChangedException;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.mifosplatform.infrastructure.user.domain.Permission;
|
||||
@@ -64,10 +64,7 @@ public class CodeWritePlatformServiceJpaRepositoryImpl implements CodeWritePlatf
|
||||
context.authenticatedUser();
|
||||
command.validateForUpdate();
|
||||
|
||||
final Long codeId = command.getId();
|
||||
final Code code = this.codeRepository.findOne(codeId);
|
||||
if (code == null) { throw new CodeValueNotFoundException(codeId); }
|
||||
|
||||
final Code code = retrieveCodeBy(command.getName());
|
||||
code.update(command);
|
||||
|
||||
this.codeRepository.save(code);
|
||||
@@ -102,23 +99,22 @@ public class CodeWritePlatformServiceJpaRepositoryImpl implements CodeWritePlatf
|
||||
|
||||
context.authenticatedUser();
|
||||
|
||||
final Long codeId = command.getId();
|
||||
Code code = retrieveCodeBy(codeId);
|
||||
final Code code = retrieveCodeBy(command.getName());
|
||||
if (code.isSystemDefined()) {
|
||||
throw new SystemDefinedCodeCannotBeChangedException();
|
||||
}
|
||||
|
||||
this.codeRepository.delete(codeId);
|
||||
this.codeRepository.delete(code);
|
||||
|
||||
final Permission thisTask = this.permissionRepository.findOneByCode("DELETE_CODE");
|
||||
if (thisTask.hasMakerCheckerEnabled() && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
|
||||
|
||||
return new EntityIdentifier(codeId);
|
||||
return new EntityIdentifier(code.getId());
|
||||
}
|
||||
|
||||
private Code retrieveCodeBy(final Long codeId) {
|
||||
final Code code = this.codeRepository.findOne(codeId);
|
||||
if (code == null) { throw new CodeValueNotFoundException(codeId); }
|
||||
private Code retrieveCodeBy(final String name) {
|
||||
final Code code = this.codeRepository.findOneByName(name);
|
||||
if (code == null) { throw new CodeNotFoundException(name); }
|
||||
return code;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user