From e61454792fd851ef0a0e00eaca15de66c2dbec8f Mon Sep 17 00:00:00 2001 From: Keith Woodlock Date: Fri, 16 Nov 2012 10:13:06 +0000 Subject: [PATCH] refactor ApplicationConstants usage, refactor usage of code and code values for customer identifiers. --- .../api/ClientIdentifiersApiResource.java | 52 +++++------ .../platform/api/ClientsApiResource.java | 57 ++++-------- .../api/DocumentManagementApiResource.java | 8 +- .../api/data/ClientIdentifierData.java | 86 ++++++++----------- .../mifosng/platform/api/data/CodeData.java | 38 +++----- .../api/infrastructure/ApiConstants.java | 10 +++ .../service/ClientReadPlatformService.java | 2 - .../ClientReadPlatformServiceImpl.java | 55 ++++-------- .../service/ClientWritePlatformService.java | 2 +- ...WritePlatformServiceJpaRepositoryImpl.java | 52 +++-------- .../platform/common/ApplicationConstants.java | 43 ---------- ...WritePlatformServiceJpaRepositoryImpl.java | 32 +++---- .../exceptions/ImageNotFoundException.java | 15 ++-- .../Base64EncodedImage.java | 2 +- .../{common => infrastructure}/FileUtils.java | 29 ++----- .../service/CodeValueReadPlatformService.java | 17 +++- .../CodeValueReadPlatformServiceImpl.java | 29 +++---- 17 files changed, 178 insertions(+), 351 deletions(-) create mode 100644 mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/ApiConstants.java delete mode 100755 mifosng-provider/src/main/java/org/mifosng/platform/common/ApplicationConstants.java rename mifosng-provider/src/main/java/org/mifosng/platform/{common => infrastructure}/Base64EncodedImage.java (90%) mode change 100755 => 100644 rename mifosng-provider/src/main/java/org/mifosng/platform/{common => infrastructure}/FileUtils.java (90%) mode change 100755 => 100644 diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/ClientIdentifiersApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/ClientIdentifiersApiResource.java index afb70b1f3..19ae91972 100755 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/ClientIdentifiersApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/ClientIdentifiersApiResource.java @@ -1,8 +1,6 @@ package org.mifosng.platform.api; -import java.util.Arrays; import java.util.Collection; -import java.util.HashSet; import java.util.Set; import javax.ws.rs.Consumes; @@ -21,6 +19,7 @@ import javax.ws.rs.core.UriInfo; import org.mifosng.platform.api.commands.ClientIdentifierCommand; import org.mifosng.platform.api.data.ClientData; import org.mifosng.platform.api.data.ClientIdentifierData; +import org.mifosng.platform.api.data.CodeValueData; import org.mifosng.platform.api.data.EntityIdentifier; import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService; import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService; @@ -28,6 +27,7 @@ import org.mifosng.platform.client.service.ClientReadPlatformService; import org.mifosng.platform.client.service.ClientWritePlatformService; import org.mifosng.platform.exceptions.DuplicateClientIdentifierException; import org.mifosng.platform.infrastructure.api.ApiParameterHelper; +import org.mifosng.platform.organisation.service.CodeValueReadPlatformService; import org.mifosng.platform.security.PlatformSecurityContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; @@ -40,6 +40,9 @@ public class ClientIdentifiersApiResource { @Autowired private ClientReadPlatformService clientReadPlatformService; + + @Autowired + private CodeValueReadPlatformService codeValueReadPlatformService; @Autowired private ClientWritePlatformService clientWritePlatformService; @@ -50,33 +53,26 @@ public class ClientIdentifiersApiResource { @Autowired private PortfolioApiJsonSerializerService apiJsonSerializerService; - private static final Set typicalResponseParameters = new HashSet( - Arrays.asList("id", "clientId", "documentTypeId", "description", - "documentKey", "documentTypeName")); + @Autowired + private PlatformSecurityContext context; private final String entityType = "CLIENTIDENTIFIER"; - @Autowired - private PlatformSecurityContext context; @GET @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) - public String retrieveAllClientIdentifiers(@Context final UriInfo uriInfo, + public String retrieveAllClientIdentifiers( + @Context final UriInfo uriInfo, @PathParam("clientId") final Long clientId) { context.authenticatedUser().validateHasReadPermission(entityType); - Set responseParameters = ApiParameterHelper + final Set responseParameters = ApiParameterHelper .extractFieldsForResponseIfProvided(uriInfo .getQueryParameters()); - if (responseParameters.isEmpty()) { - responseParameters.addAll(typicalResponseParameters); - } - boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo - .getQueryParameters()); + final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); - Collection clientIdentifiers = this.clientReadPlatformService - .retrieveClientIdentifiers(clientId); + final Collection clientIdentifiers = this.clientReadPlatformService.retrieveClientIdentifiers(clientId); return this.apiJsonSerializerService .serializeClientIdentifierDataToJson(prettyPrint, @@ -91,16 +87,13 @@ public class ClientIdentifiersApiResource { context.authenticatedUser().validateHasReadPermission(entityType); - Set responseParameters = ApiParameterHelper + final Set responseParameters = ApiParameterHelper .extractFieldsForResponseIfProvided(uriInfo .getQueryParameters()); - responseParameters.addAll(typicalResponseParameters); - responseParameters.add("allowedDocumentTypes"); - boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo - .getQueryParameters()); + final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); - ClientIdentifierData clientIdentifierData = this.clientReadPlatformService - .retrieveNewClientIdentifierDetails(); + Collection codeValues = codeValueReadPlatformService.retrieveCustomIdentifierCodeValues(); + ClientIdentifierData clientIdentifierData = ClientIdentifierData.template(codeValues); return this.apiJsonSerializerService .serializeClientIdentifierDataToJson(prettyPrint, @@ -144,18 +137,15 @@ public class ClientIdentifiersApiResource { context.authenticatedUser().validateHasReadPermission(entityType); final Set responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); - if (responseParameters.isEmpty()) { - responseParameters.addAll(typicalResponseParameters); - } + final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); + final boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters()); - boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); - boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters()); + ClientIdentifierData clientIdentifierData = this.clientReadPlatformService.retrieveClientIdentifier(clientId, clientIdentifierId); if (template) { - responseParameters.add("allowedDocumentTypes"); + final Collection codeValues = codeValueReadPlatformService.retrieveCustomIdentifierCodeValues(); + clientIdentifierData = ClientIdentifierData.template(clientIdentifierData, codeValues); } - final ClientIdentifierData clientIdentifierData = this.clientReadPlatformService.retrieveClientIdentifier(clientId, clientIdentifierId); - return this.apiJsonSerializerService .serializeClientIdentifierDataToJson(prettyPrint, responseParameters, clientIdentifierData); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/ClientsApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/ClientsApiResource.java index c22bdf69a..424213312 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/ClientsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/ClientsApiResource.java @@ -32,15 +32,14 @@ import org.mifosng.platform.api.data.CommandSourceData; import org.mifosng.platform.api.data.EntityIdentifier; import org.mifosng.platform.api.data.NoteData; import org.mifosng.platform.api.data.OfficeLookup; +import org.mifosng.platform.api.infrastructure.ApiConstants; import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService; import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService; import org.mifosng.platform.client.service.ClientReadPlatformService; import org.mifosng.platform.client.service.ClientWritePlatformService; -import org.mifosng.platform.common.ApplicationConstants; -import org.mifosng.platform.common.Base64EncodedImage; -import org.mifosng.platform.common.FileUtils; -import org.mifosng.platform.exceptions.ClientNotFoundException; import org.mifosng.platform.exceptions.ImageNotFoundException; +import org.mifosng.platform.infrastructure.Base64EncodedImage; +import org.mifosng.platform.infrastructure.FileUtils; import org.mifosng.platform.infrastructure.api.ApiParameterHelper; import org.mifosng.platform.makerchecker.service.PortfolioCommandSourceWritePlatformService; import org.mifosng.platform.makerchecker.service.PortfolioCommandsReadPlatformService; @@ -348,13 +347,8 @@ public class ClientsApiResource { return Response.ok().entity(identifier).build(); } - /** Upload images through multi-part form upload - * @param clientId - * @param fileSize - * @param inputStream - * @param fileDetails - * @param bodyPart - * @return + /** + * Upload images through multi-part form upload */ @POST @Path("{clientId}/image") @@ -374,7 +368,7 @@ public class ClientsApiResource { FileUtils.validateImageMimeType(bodyPart.getMediaType().toString()); FileUtils.validateFileSizeWithinPermissibleRange(fileSize, fileDetails.getFileName(), - ApplicationConstants.MAX_FILE_UPLOAD_SIZE_IN_MB); + ApiConstants.MAX_FILE_UPLOAD_SIZE_IN_MB); logger.debug(bodyPart.getMediaType().toString()); @@ -382,16 +376,12 @@ public class ClientsApiResource { .saveOrUpdateClientImage(clientId, fileDetails.getFileName(), inputStream); - // return identifier of the client whose image was updated return Response.ok().entity(entityIdentifier).build(); - } - /** Upload image as a Data URL (essentially a base64 encoded stream) - * @param clientId - * @param jsonRequestBody - * @return + /** + * Upload image as a Data URL (essentially a base64 encoded stream) */ @POST @Path("{clientId}/image") @@ -407,14 +397,11 @@ public class ClientsApiResource { EntityIdentifier entityIdentifier = this.clientWritePlatformService .saveOrUpdateClientImage(clientId, base64EncodedImage); - // return identifier of the client whose image was updated return Response.ok().entity(entityIdentifier).build(); } /** * Returns a base 64 encoded client image - * @param clientId - * @return */ @GET @Path("{clientId}/image") @@ -426,28 +413,17 @@ public class ClientsApiResource { context.authenticatedUser().validateHasReadPermission("CLIENTIMAGE"); final ClientData clientData = this.clientReadPlatformService.retrieveIndividualClient(clientId); - //validate if client does not exist or image key is null - if(clientData == null){ - throw new ClientNotFoundException(clientId); - } - else if(clientData.imageKeyDoesNotExist()){ - throw new ImageNotFoundException(ApplicationConstants.IMAGE_MANAGEMENT_ENTITY.CLIENTS, clientId); + + if (clientData.imageKeyDoesNotExist()) { + throw new ImageNotFoundException("clients", clientId); } return Response.ok().entity(Base64.encodeFromFile(clientData.imageKey())).build(); } - - - /** This method is added only for consistency with other URL patterns - * and for maintaining consistency of usage of the HTTP "verb" - * at the client side - * - * @param clientId - * @param fileSize - * @param inputStream - * @param fileDetails - * @param bodyPart - * @return + /** + * This method is added only for consistency with other URL patterns + * and for maintaining consistency of usage of the HTTP "verb" + * at the client side */ @PUT @Path("{clientId}/image") @@ -479,9 +455,6 @@ public class ClientsApiResource { * at the client side * * Upload image as a Data URL (essentially a base64 encoded stream) - * @param clientId - * @param jsonRequestBody - * @return */ @PUT @Path("{clientId}/image") diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/DocumentManagementApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/DocumentManagementApiResource.java index c0b275192..ba42af91c 100755 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/DocumentManagementApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/DocumentManagementApiResource.java @@ -25,11 +25,11 @@ import javax.ws.rs.core.UriInfo; import org.mifosng.platform.api.commands.DocumentCommand; import org.mifosng.platform.api.data.DocumentData; import org.mifosng.platform.api.data.EntityIdentifier; +import org.mifosng.platform.api.infrastructure.ApiConstants; import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService; -import org.mifosng.platform.common.ApplicationConstants; -import org.mifosng.platform.common.FileUtils; import org.mifosng.platform.documentmanagement.service.DocumentReadPlatformService; import org.mifosng.platform.documentmanagement.service.DocumentWritePlatformService; +import org.mifosng.platform.infrastructure.FileUtils; import org.mifosng.platform.infrastructure.api.ApiParameterHelper; import org.mifosng.platform.security.PlatformSecurityContext; import org.springframework.beans.factory.annotation.Autowired; @@ -116,7 +116,7 @@ public class DocumentManagementApiResource { @FormDataParam("name") String name, @FormDataParam("description") String description) { - FileUtils.validateFileSizeWithinPermissibleRange(fileSize, name, ApplicationConstants.MAX_FILE_UPLOAD_SIZE_IN_MB); + FileUtils.validateFileSizeWithinPermissibleRange(fileSize, name, ApiConstants.MAX_FILE_UPLOAD_SIZE_IN_MB); /** * TODO: also need to have a backup and stop reading from stream after @@ -163,7 +163,7 @@ public class DocumentManagementApiResource { @FormDataParam("name") String name, @FormDataParam("description") String description) { - FileUtils.validateFileSizeWithinPermissibleRange(fileSize, name, ApplicationConstants.MAX_FILE_UPLOAD_SIZE_IN_MB); + FileUtils.validateFileSizeWithinPermissibleRange(fileSize, name, ApiConstants.MAX_FILE_UPLOAD_SIZE_IN_MB); Set modifiedParams = new HashSet(); modifiedParams.add("name"); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/ClientIdentifierData.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/ClientIdentifierData.java index 83e67bc12..c8a4cae41 100755 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/ClientIdentifierData.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/ClientIdentifierData.java @@ -1,73 +1,55 @@ package org.mifosng.platform.api.data; -import java.util.ArrayList; -import java.util.List; +import java.util.Collection; +/** + * Immutable data object represent client identity data. + */ public class ClientIdentifierData { private final Long id; private final Long clientId; private final Long documentTypeId; private final String documentTypeName; - private final String documentKey; private final String description; - private List allowedDocumentTypes = new ArrayList(); + @SuppressWarnings("unused") + private final Collection allowedDocumentTypes; + + public static ClientIdentifierData singleItem( + final Long id, + final Long clientId, + final Long documentTypeId, + final String documentKey, + final String description, + final String documentTypeName) { + return new ClientIdentifierData(id, clientId, documentTypeId, documentKey, description, documentTypeName, null); + } + + public static ClientIdentifierData template(final Collection codeValues) { + return new ClientIdentifierData(null, null, null, null, null, null, codeValues); + } + + public static ClientIdentifierData template( + final ClientIdentifierData data, + final Collection codeValues) { + return new ClientIdentifierData(data.id, data.clientId, data.documentTypeId, data.documentKey, data.description, data.documentTypeName, codeValues); + } - public ClientIdentifierData(final Long id, final Long clientId, - final Long documentTypeId, final String documentKey, - final String description, final String documentTypeName) { + public ClientIdentifierData( + final Long id, + final Long clientId, + final Long documentTypeId, + final String documentKey, + final String description, + final String documentTypeName, + final Collection allowedDocumentTypes) { this.id = id; this.clientId = clientId; this.documentTypeId = documentTypeId; this.documentKey = documentKey; this.description = description; this.documentTypeName = documentTypeName; - } - - public ClientIdentifierData(final Long clientId, final Long documentTypeId, - final String documentKey, final String description, - final String documentTypeName, - List allowedDocumentTypes) { - this.id = null; - this.clientId = clientId; - this.documentTypeId = documentTypeId; - this.documentKey = documentKey; - this.description = description; - this.documentTypeName = documentTypeName; this.allowedDocumentTypes = allowedDocumentTypes; } - - public Long getId() { - return id; - } - - public Long getClientId() { - return clientId; - } - - public Long getDocumentTypeId() { - return documentTypeId; - } - - public String getDocumentKey() { - return documentKey; - } - - public String getDescription() { - return description; - } - - public List getAllowedDocumentTypes() { - return allowedDocumentTypes; - } - - public void setAllowedDocumentTypes(List allowedDocumentTypes) { - this.allowedDocumentTypes = allowedDocumentTypes; - } - - public String getDocumentTypeName() { - return documentTypeName; - } - } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/CodeData.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/CodeData.java index cff3209eb..7a39fe853 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/CodeData.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/CodeData.java @@ -1,35 +1,17 @@ package org.mifosng.platform.api.data; -import java.io.Serializable; +/** + * Immutable data object representing a code. + */ +public class CodeData { -public class CodeData implements Serializable { + @SuppressWarnings("unused") + private final Long id; + @SuppressWarnings("unused") + private final String name; - private Long id; - private String codeName; - - public CodeData() { - // - } - - public CodeData(final Long id, final String codeName) { + public CodeData(final Long id, final String name) { this.id = id; - this.codeName = codeName; + this.name = name; } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getCodeName() { - return codeName; - } - - public void setName(String codeName) { - this.codeName = codeName; - } - } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/ApiConstants.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/ApiConstants.java new file mode 100644 index 000000000..e13f2b0a8 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/ApiConstants.java @@ -0,0 +1,10 @@ +package org.mifosng.platform.api.infrastructure; + +public class ApiConstants { + + // TODO:Vishwas Need to move these settings to the Database + public static final Integer MAX_FILE_UPLOAD_SIZE_IN_MB = 5; + + // TODO:Vishwas Need to move these settings to the Database + public static final Integer MAX_IMAGE_UPLOAD_SIZE_IN_MB = 1; +} diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientReadPlatformService.java b/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientReadPlatformService.java index f0340a499..af98be5de 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientReadPlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientReadPlatformService.java @@ -33,7 +33,5 @@ public interface ClientReadPlatformService { ClientIdentifierData retrieveClientIdentifier(Long clientId,Long clientIdentifierId); - ClientIdentifierData retrieveNewClientIdentifierDetails(); - ClientData retrieveClientByIdentifier(Long identifierTypeId, String identifierKey); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientReadPlatformServiceImpl.java index 1315aac1f..6c8a6b0be 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientReadPlatformServiceImpl.java @@ -15,18 +15,15 @@ import org.mifosng.platform.api.data.ClientAccountSummaryData; import org.mifosng.platform.api.data.ClientData; import org.mifosng.platform.api.data.ClientIdentifierData; import org.mifosng.platform.api.data.ClientLookup; -import org.mifosng.platform.api.data.CodeValueData; import org.mifosng.platform.api.data.EnumOptionData; import org.mifosng.platform.api.data.NoteData; import org.mifosng.platform.api.data.OfficeLookup; import org.mifosng.platform.client.domain.NoteEnumerations; -import org.mifosng.platform.common.ApplicationConstants; import org.mifosng.platform.exceptions.ClientIdentifierNotFoundException; import org.mifosng.platform.exceptions.ClientNotFoundException; import org.mifosng.platform.exceptions.NoteNotFoundException; import org.mifosng.platform.infrastructure.JdbcSupport; import org.mifosng.platform.infrastructure.TenantAwareRoutingDataSource; -import org.mifosng.platform.organisation.service.CodeValueReadPlatformService; import org.mifosng.platform.organisation.service.OfficeReadPlatformService; import org.mifosng.platform.security.PlatformSecurityContext; import org.mifosng.platform.user.domain.AppUser; @@ -44,22 +41,18 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService private final PlatformSecurityContext context; private final OfficeReadPlatformService officeReadPlatformService; private final AppUserReadPlatformService appUserReadPlatformService; - private final CodeValueReadPlatformService codeValuePlatformService; @Autowired public ClientReadPlatformServiceImpl(final PlatformSecurityContext context, final TenantAwareRoutingDataSource dataSource, final OfficeReadPlatformService officeReadPlatformService, - final AppUserReadPlatformService appUserReadPlatformService, - final CodeValueReadPlatformService codeValuePlatformService) { + final AppUserReadPlatformService appUserReadPlatformService) { this.context = context; this.officeReadPlatformService = officeReadPlatformService; this.appUserReadPlatformService = appUserReadPlatformService; this.jdbcTemplate = new JdbcTemplate(dataSource); - this.codeValuePlatformService = codeValuePlatformService; } - @Override public Collection retrieveAllIndividualClients(final String extraCriteria) { @@ -445,8 +438,7 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService } @Override - public Collection retrieveClientIdentifiers( - Long clientId) { + public Collection retrieveClientIdentifiers(final Long clientId) { AppUser currentUser = context.authenticatedUser(); String hierarchy = currentUser.getOffice().getHierarchy(); @@ -458,13 +450,13 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService sql += " order by ci.id"; - return this.jdbcTemplate.query(sql, rm, new Object[] { clientId, - hierarchySearchString }); + return this.jdbcTemplate.query(sql, rm, new Object[] { clientId, hierarchySearchString }); } @Override - public ClientIdentifierData retrieveClientIdentifier(Long clientId, - Long clientIdentifierId) { + public ClientIdentifierData retrieveClientIdentifier( + final Long clientId, + final Long clientIdentifierId) { try { AppUser currentUser = context.authenticatedUser(); String hierarchy = currentUser.getOffice().getHierarchy(); @@ -476,14 +468,10 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService sql += " and ci.id = ?"; - ClientIdentifierData clientIdentifierData = this.jdbcTemplate + final ClientIdentifierData clientIdentifierData = this.jdbcTemplate .queryForObject(sql, rm, new Object[] { clientId, hierarchySearchString, clientIdentifierId }); - clientIdentifierData - .setAllowedDocumentTypes(new ArrayList( - codeValuePlatformService - .retrieveAllCodeValues(ApplicationConstants.CLIENT_IDENTITY_CODE_ID))); return clientIdentifierData; } catch (EmptyResultDataAccessException e) { throw new ClientIdentifierNotFoundException(clientIdentifierId); @@ -491,19 +479,7 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService } - @Override - public ClientIdentifierData retrieveNewClientIdentifierDetails() { - - context.authenticatedUser(); - - List codeValueDatas = new ArrayList( - codeValuePlatformService.retrieveAllCodeValues(ApplicationConstants.CLIENT_IDENTITY_CODE_ID)); - - return new ClientIdentifierData(null,null,null,null,null,codeValueDatas); - } - - private static final class ClientIdentityMapper implements - RowMapper { + private static final class ClientIdentityMapper implements RowMapper { public ClientIdentityMapper() { } @@ -522,15 +498,14 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService @SuppressWarnings("unused") final int rowNum) throws SQLException { - Long id = JdbcSupport.getLong(rs, "id"); - Long clientId = JdbcSupport.getLong(rs, "clientId"); - Long documentTypeId = JdbcSupport.getLong(rs, "documentTypeId"); - String documentKey = rs.getString("documentKey"); - String description = rs.getString("description"); - String documentTypeName = rs.getString("documentType"); + final Long id = JdbcSupport.getLong(rs, "id"); + final Long clientId = JdbcSupport.getLong(rs, "clientId"); + final Long documentTypeId = JdbcSupport.getLong(rs, "documentTypeId"); + final String documentKey = rs.getString("documentKey"); + final String description = rs.getString("description"); + final String documentTypeName = rs.getString("documentType"); - return new ClientIdentifierData(id, clientId, documentTypeId, - documentKey, description,documentTypeName); + return ClientIdentifierData.singleItem(id, clientId, documentTypeId,documentKey, description,documentTypeName); } } diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientWritePlatformService.java index 85153cfcf..7716d00b9 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientWritePlatformService.java @@ -6,7 +6,7 @@ import org.mifosng.platform.api.commands.ClientCommand; import org.mifosng.platform.api.commands.ClientIdentifierCommand; import org.mifosng.platform.api.commands.NoteCommand; import org.mifosng.platform.api.data.EntityIdentifier; -import org.mifosng.platform.common.Base64EncodedImage; +import org.mifosng.platform.infrastructure.Base64EncodedImage; import org.springframework.security.access.prepost.PreAuthorize; public interface ClientWritePlatformService { diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java index 512963f79..5106d3c4b 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java @@ -15,9 +15,6 @@ import org.mifosng.platform.client.domain.ClientIdentifierRepository; import org.mifosng.platform.client.domain.ClientRepository; import org.mifosng.platform.client.domain.Note; import org.mifosng.platform.client.domain.NoteRepository; -import org.mifosng.platform.common.ApplicationConstants; -import org.mifosng.platform.common.Base64EncodedImage; -import org.mifosng.platform.common.FileUtils; import org.mifosng.platform.exceptions.ClientIdentifierNotFoundException; import org.mifosng.platform.exceptions.ClientNotFoundException; import org.mifosng.platform.exceptions.CodeValueNotFoundException; @@ -26,6 +23,8 @@ import org.mifosng.platform.exceptions.DuplicateClientIdentifierException; import org.mifosng.platform.exceptions.NoteNotFoundException; import org.mifosng.platform.exceptions.OfficeNotFoundException; import org.mifosng.platform.exceptions.PlatformDataIntegrityException; +import org.mifosng.platform.infrastructure.Base64EncodedImage; +import org.mifosng.platform.infrastructure.FileUtils; import org.mifosng.platform.organisation.domain.CodeValue; import org.mifosng.platform.organisation.domain.CodeValueRepository; import org.mifosng.platform.organisation.domain.Office; @@ -50,7 +49,7 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP private final NoteRepository noteRepository; private final CodeValueRepository codeValueRepository; - // FIXME - kw - this value is hardcoded for now but will be retrieved from coinfiguration + // FIXME - kw - this value is hardcoded for now but will be retrieved from configuration private boolean makerCheckerEnabledForTask = false; @Autowired @@ -366,29 +365,27 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP @Transactional @Override - public EntityIdentifier deleteClientImage(Long clientId) { + public EntityIdentifier deleteClientImage(final Long clientId) { + final Client client = this.clientRepository.findOne(clientId); if (client == null || client.isDeleted()) { throw new ClientNotFoundException(clientId); } + // delete image from the file system if (StringUtils.isNotEmpty(client.getImageKey())) { - FileUtils.deleteImage( - ApplicationConstants.IMAGE_MANAGEMENT_ENTITY.CLIENTS, - clientId, client.getImageKey()); + FileUtils.deleteClientImage(clientId, client.getImageKey()); } return updateClientImage(clientId, client, null); } @Override - public EntityIdentifier saveOrUpdateClientImage(Long clientId, - Base64EncodedImage encodedImage) { + public EntityIdentifier saveOrUpdateClientImage(final Long clientId, final Base64EncodedImage encodedImage) { try { final Client client = this.clientRepository.findOne(clientId); - String imageUploadLocation = setupForClientImageUpdate(clientId, - client); + final String imageUploadLocation = setupForClientImageUpdate(clientId, client); - String imageLocation = FileUtils.saveToFileSystem(encodedImage, imageUploadLocation, "image"); + final String imageLocation = FileUtils.saveToFileSystem(encodedImage, imageUploadLocation, "image"); return updateClientImage(clientId, client, imageLocation); } catch (IOException ioe) { @@ -397,25 +394,15 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP } } - /** - * @param clientId - * @param client - * @return - */ - private String setupForClientImageUpdate(Long clientId, final Client client) { + private String setupForClientImageUpdate(final Long clientId, final Client client) { if (client == null || client.isDeleted()) { throw new ClientNotFoundException(clientId); } - String imageUploadLocation = FileUtils - .generateImageParentDirectory( - ApplicationConstants.IMAGE_MANAGEMENT_ENTITY.CLIENTS, - clientId); + final String imageUploadLocation = FileUtils.generateClientImageParentDirectory(clientId); // delete previous image from the file system if (StringUtils.isNotEmpty(client.getImageKey())) { - FileUtils.deleteImage( - ApplicationConstants.IMAGE_MANAGEMENT_ENTITY.CLIENTS, - clientId, client.getImageKey()); + FileUtils.deleteClientImage(clientId, client.getImageKey()); } /** Recursively create the directory if it does not exist **/ @@ -425,21 +412,10 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP return imageUploadLocation; } - - /** - * @param clientId - * @param client - * @param imageLocation - * @return - */ - private EntityIdentifier updateClientImage(Long clientId, - final Client client, String imageLocation) { + private EntityIdentifier updateClientImage(final Long clientId, final Client client, final String imageLocation) { client.setImageKey(imageLocation); this.clientRepository.save(client); return new EntityIdentifier(clientId); } - - - } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/common/ApplicationConstants.java b/mifosng-provider/src/main/java/org/mifosng/platform/common/ApplicationConstants.java deleted file mode 100755 index b1f4a0151..000000000 --- a/mifosng-provider/src/main/java/org/mifosng/platform/common/ApplicationConstants.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.mifosng.platform.common; - -/** - * @deprecated - KW - in general would like to avoid the whole throw it in common approach and dont want to see - * - this file attract more application constants. - */ -@Deprecated -public class ApplicationConstants { - - /** - * The intention of m_code table usage is not to use the id but the unique name of the code. - * - * This will stop reserved magic numbers spreading through application for one and it - * more natural to use the code name like you would use a table name in a query. - */ - @Deprecated - public static final Long CLIENT_IDENTITY_CODE_ID = 9L; - - // TODO:Vishwas Need to move these settings to the Database - public static final Integer MAX_FILE_UPLOAD_SIZE_IN_MB = 5; - - // TODO:Vishwas Need to move these settings to the Database - public static final Integer MAX_IMAGE_UPLOAD_SIZE_IN_MB = 1; - - /*** Entities for document Management **/ - public static enum DOCUMENT_MANAGEMENT_ENTITY { - CLIENTS, CLIENT_IDENTIFIERS, STAFF, LOANS, SAVINGS; - @Override - public String toString() { - return name().toString().toLowerCase(); - } - } - - /*** Entities for image Management **/ - public static enum IMAGE_MANAGEMENT_ENTITY { - CLIENTS, STAFF; - @Override - public String toString() { - return name().toString().toLowerCase(); - } - } - -} diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/documentmanagement/service/DocumentWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/documentmanagement/service/DocumentWritePlatformServiceJpaRepositoryImpl.java index cc2eedeee..89204d893 100755 --- a/mifosng-provider/src/main/java/org/mifosng/platform/documentmanagement/service/DocumentWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/documentmanagement/service/DocumentWritePlatformServiceJpaRepositoryImpl.java @@ -6,14 +6,13 @@ import java.io.InputStream; import org.mifosng.platform.api.commands.DocumentCommand; import org.mifosng.platform.api.data.EntityIdentifier; -import org.mifosng.platform.common.ApplicationConstants; -import org.mifosng.platform.common.FileUtils; import org.mifosng.platform.documentmanagement.domain.Document; import org.mifosng.platform.documentmanagement.domain.DocumentRepository; import org.mifosng.platform.exceptions.DocumentManagementException; import org.mifosng.platform.exceptions.DocumentNotFoundException; import org.mifosng.platform.exceptions.InvalidEntityTypeForDocumentManagementException; import org.mifosng.platform.exceptions.PlatformDataIntegrityException; +import org.mifosng.platform.infrastructure.FileUtils; import org.mifosng.platform.security.PlatformSecurityContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,28 +27,14 @@ public class DocumentWritePlatformServiceJpaRepositoryImpl implements private final static Logger logger = LoggerFactory.getLogger(DocumentWritePlatformServiceJpaRepositoryImpl.class); - // TODO: Use these services to ensure that the appropriate entities exist, - // are active, check data scope for user etc private final PlatformSecurityContext context; -// private final ClientRepository clientRepository; -// private final OfficeRepository officeRepository; -// private final LoanRepository loanRepository; -// private final StaffRepository staffRepository; private final DocumentRepository documentRepository; @Autowired public DocumentWritePlatformServiceJpaRepositoryImpl( final PlatformSecurityContext context, -// final ClientRepository clientRepository, -// final OfficeRepository officeRepository, -// final LoanRepository loanRepository, -// final StaffRepository staffRepository, final DocumentRepository documentRepository) { this.context = context; -// this.clientRepository = clientRepository; -// this.officeRepository = officeRepository; -// this.loanRepository = loanRepository; -// this.staffRepository = staffRepository; this.documentRepository = documentRepository; } @@ -192,13 +177,22 @@ public class DocumentWritePlatformServiceJpaRepositoryImpl implements } } - private static boolean checkValidEntityType(String entityType) { - for (ApplicationConstants.DOCUMENT_MANAGEMENT_ENTITY entities : ApplicationConstants.DOCUMENT_MANAGEMENT_ENTITY - .values()) { + private static boolean checkValidEntityType(final String entityType) { + + for (DOCUMENT_MANAGEMENT_ENTITY entities : DOCUMENT_MANAGEMENT_ENTITY.values()) { if (entities.name().equalsIgnoreCase(entityType)) { return true; } } return false; } + + /*** Entities for document Management **/ + public static enum DOCUMENT_MANAGEMENT_ENTITY { + CLIENTS, CLIENT_IDENTIFIERS, STAFF, LOANS, SAVINGS; + @Override + public String toString() { + return name().toString().toLowerCase(); + } + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/exceptions/ImageNotFoundException.java b/mifosng-provider/src/main/java/org/mifosng/platform/exceptions/ImageNotFoundException.java index 6cfad41c6..3377c0ce3 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/exceptions/ImageNotFoundException.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/exceptions/ImageNotFoundException.java @@ -1,15 +1,10 @@ package org.mifosng.platform.exceptions; -import org.mifosng.platform.common.ApplicationConstants; - public class ImageNotFoundException extends AbstractPlatformDomainRuleException { - public ImageNotFoundException( - ApplicationConstants.IMAGE_MANAGEMENT_ENTITY entityType, - Long entityId) { - super("error.msg.entity.image.invalid", "Image for entity " - + entityType.toString() + " with Identifier " + entityId - + " does not exist", entityType.toString(), entityId); + public ImageNotFoundException(final String resource, final Long resourceId) { + super("error.msg.entity.image.invalid", "Image for resource " + + resource + " with Identifier " + resourceId + + " does not exist", resource, resourceId); } - -} +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/common/Base64EncodedImage.java b/mifosng-provider/src/main/java/org/mifosng/platform/infrastructure/Base64EncodedImage.java old mode 100755 new mode 100644 similarity index 90% rename from mifosng-provider/src/main/java/org/mifosng/platform/common/Base64EncodedImage.java rename to mifosng-provider/src/main/java/org/mifosng/platform/infrastructure/Base64EncodedImage.java index 908cf6497..f42ffa636 --- a/mifosng-provider/src/main/java/org/mifosng/platform/common/Base64EncodedImage.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/infrastructure/Base64EncodedImage.java @@ -1,4 +1,4 @@ -package org.mifosng.platform.common; +package org.mifosng.platform.infrastructure; public class Base64EncodedImage { diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/common/FileUtils.java b/mifosng-provider/src/main/java/org/mifosng/platform/infrastructure/FileUtils.java old mode 100755 new mode 100644 similarity index 90% rename from mifosng-provider/src/main/java/org/mifosng/platform/common/FileUtils.java rename to mifosng-provider/src/main/java/org/mifosng/platform/infrastructure/FileUtils.java index 6e7027128..c87431b6b --- a/mifosng-provider/src/main/java/org/mifosng/platform/common/FileUtils.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/infrastructure/FileUtils.java @@ -1,4 +1,4 @@ -package org.mifosng.platform.common; +package org.mifosng.platform.infrastructure; import java.io.File; import java.io.FileOutputStream; @@ -14,7 +14,6 @@ import org.mifosng.platform.exceptions.DocumentManagementException; import org.mifosng.platform.exceptions.ImageDataURLNotValidException; import org.mifosng.platform.exceptions.ImageUploadException; import org.mifosng.platform.exceptions.PlatformApiDataValidationException; -import org.mifosng.platform.infrastructure.ThreadLocalContextUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -74,20 +73,14 @@ public class FileUtils { /** * Generate directory path for storing new Image - * - * @param entityType - * @param entityId - * @return */ - public static String generateImageParentDirectory( - ApplicationConstants.IMAGE_MANAGEMENT_ENTITY entityType, - Long entityId) { + public static String generateClientImageParentDirectory(final Long resourceId) { return FileUtils.MIFOSX_BASE_DIR + File.separator + ThreadLocalContextUtil.getTenant().getName() .replaceAll(" ", "").trim() + File.separator + "images" - + File.separator + entityType.toString() + File.separator - + entityId; + + File.separator + "clients" + File.separator + + resourceId; } /** @@ -205,20 +198,12 @@ public class FileUtils { } } - /** - * @param entityType - * @param entityId - * @param location - */ - public static void deleteImage( - ApplicationConstants.IMAGE_MANAGEMENT_ENTITY entityType, - Long entityId, String location) { + public static void deleteClientImage(final Long resourceId, final String location) { File fileToBeDeleted = new File(location); boolean fileDeleted = fileToBeDeleted.delete(); if (!fileDeleted) { // no need to throw an Error, simply log a warning - logger.warn("Unable to delete image associated with " - + entityType.toString() + " with Id " + entityId); + logger.warn("Unable to delete image associated with clients with Id " + resourceId); } } -} +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/CodeValueReadPlatformService.java b/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/CodeValueReadPlatformService.java index ce15dd38a..576d890b7 100755 --- a/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/CodeValueReadPlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/CodeValueReadPlatformService.java @@ -4,8 +4,21 @@ import java.util.Collection; import org.mifosng.platform.api.data.CodeValueData; +/** + * A service for retrieving code value information based on the code itself. + * + * There are two types of code information in the platform: + *
    + *
  1. System defined codes
  2. + *
  3. User defined codes
  4. + *
+ * + *

System defined codes cannot be altered or removed but their code values may be allowed to be added to or removed.

+ * + *

User defined codes can be changed in any way by application users with system permissions.

+ */ public interface CodeValueReadPlatformService { - Collection retrieveAllCodeValues(Long codeId); - + // system defined code value data + Collection retrieveCustomIdentifierCodeValues(); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/CodeValueReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/CodeValueReadPlatformServiceImpl.java index 0e8d2aec4..7dfd7425a 100755 --- a/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/CodeValueReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/CodeValueReadPlatformServiceImpl.java @@ -19,41 +19,38 @@ public class CodeValueReadPlatformServiceImpl implements CodeValueReadPlatformSe private final PlatformSecurityContext context; @Autowired - public CodeValueReadPlatformServiceImpl(final PlatformSecurityContext context, - final TenantAwareRoutingDataSource dataSource) { + public CodeValueReadPlatformServiceImpl(final PlatformSecurityContext context, final TenantAwareRoutingDataSource dataSource) { this.context = context; this.jdbcTemplate = new JdbcTemplate(dataSource); } - private static final class CodeValueDataMapper implements - RowMapper { + private static final class CodeValueDataMapper implements RowMapper { public String schema() { - return " cv.id as id,cv.code_value as value,cv.code_id as codeId, cv.order_position as position" - + " from m_code_value as cv "; + return " cv.id as id, cv.code_value as value, cv.code_id as codeId, cv.order_position as position" + + " from m_code_value as cv join m_code c on cv.code_id = c.id "; } @Override public CodeValueData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { - Long id = rs.getLong("id"); - String value = rs.getString("value"); - Integer position = rs.getInt("position"); + final Long id = rs.getLong("id"); + final String value = rs.getString("value"); + final Integer position = rs.getInt("position"); return new CodeValueData(id, value, position); } } - + @Override - public Collection retrieveAllCodeValues(final Long codeId) { + public Collection retrieveCustomIdentifierCodeValues() { + context.authenticatedUser(); - CodeValueDataMapper rm = new CodeValueDataMapper(); - String sql = "select " + rm.schema() - + "where cv.code_id = ? order by position"; + final CodeValueDataMapper rm = new CodeValueDataMapper(); + final String sql = "select " + rm.schema() + "where c.code_name like ? order by position"; - return this.jdbcTemplate.query(sql, rm, new Object[] { codeId }); + return this.jdbcTemplate.query(sql, rm, new Object[] {"Customer Identifier"}); } - } \ No newline at end of file