refactor ApplicationConstants usage, refactor usage of code and code values for customer identifiers.
This commit is contained in:
+21
-31
@@ -1,8 +1,6 @@
|
|||||||
package org.mifosng.platform.api;
|
package org.mifosng.platform.api;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
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.commands.ClientIdentifierCommand;
|
||||||
import org.mifosng.platform.api.data.ClientData;
|
import org.mifosng.platform.api.data.ClientData;
|
||||||
import org.mifosng.platform.api.data.ClientIdentifierData;
|
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.data.EntityIdentifier;
|
||||||
import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService;
|
import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService;
|
||||||
import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService;
|
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.client.service.ClientWritePlatformService;
|
||||||
import org.mifosng.platform.exceptions.DuplicateClientIdentifierException;
|
import org.mifosng.platform.exceptions.DuplicateClientIdentifierException;
|
||||||
import org.mifosng.platform.infrastructure.api.ApiParameterHelper;
|
import org.mifosng.platform.infrastructure.api.ApiParameterHelper;
|
||||||
|
import org.mifosng.platform.organisation.service.CodeValueReadPlatformService;
|
||||||
import org.mifosng.platform.security.PlatformSecurityContext;
|
import org.mifosng.platform.security.PlatformSecurityContext;
|
||||||
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;
|
||||||
@@ -40,6 +40,9 @@ public class ClientIdentifiersApiResource {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ClientReadPlatformService clientReadPlatformService;
|
private ClientReadPlatformService clientReadPlatformService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CodeValueReadPlatformService codeValueReadPlatformService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ClientWritePlatformService clientWritePlatformService;
|
private ClientWritePlatformService clientWritePlatformService;
|
||||||
@@ -50,33 +53,26 @@ public class ClientIdentifiersApiResource {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private PortfolioApiJsonSerializerService apiJsonSerializerService;
|
private PortfolioApiJsonSerializerService apiJsonSerializerService;
|
||||||
|
|
||||||
private static final Set<String> typicalResponseParameters = new HashSet<String>(
|
@Autowired
|
||||||
Arrays.asList("id", "clientId", "documentTypeId", "description",
|
private PlatformSecurityContext context;
|
||||||
"documentKey", "documentTypeName"));
|
|
||||||
|
|
||||||
private final String entityType = "CLIENTIDENTIFIER";
|
private final String entityType = "CLIENTIDENTIFIER";
|
||||||
@Autowired
|
|
||||||
private PlatformSecurityContext context;
|
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ 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) {
|
@PathParam("clientId") final Long clientId) {
|
||||||
|
|
||||||
context.authenticatedUser().validateHasReadPermission(entityType);
|
context.authenticatedUser().validateHasReadPermission(entityType);
|
||||||
|
|
||||||
Set<String> responseParameters = ApiParameterHelper
|
final Set<String> responseParameters = ApiParameterHelper
|
||||||
.extractFieldsForResponseIfProvided(uriInfo
|
.extractFieldsForResponseIfProvided(uriInfo
|
||||||
.getQueryParameters());
|
.getQueryParameters());
|
||||||
if (responseParameters.isEmpty()) {
|
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||||
responseParameters.addAll(typicalResponseParameters);
|
|
||||||
}
|
|
||||||
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo
|
|
||||||
.getQueryParameters());
|
|
||||||
|
|
||||||
Collection<ClientIdentifierData> clientIdentifiers = this.clientReadPlatformService
|
final Collection<ClientIdentifierData> clientIdentifiers = this.clientReadPlatformService.retrieveClientIdentifiers(clientId);
|
||||||
.retrieveClientIdentifiers(clientId);
|
|
||||||
|
|
||||||
return this.apiJsonSerializerService
|
return this.apiJsonSerializerService
|
||||||
.serializeClientIdentifierDataToJson(prettyPrint,
|
.serializeClientIdentifierDataToJson(prettyPrint,
|
||||||
@@ -91,16 +87,13 @@ public class ClientIdentifiersApiResource {
|
|||||||
|
|
||||||
context.authenticatedUser().validateHasReadPermission(entityType);
|
context.authenticatedUser().validateHasReadPermission(entityType);
|
||||||
|
|
||||||
Set<String> responseParameters = ApiParameterHelper
|
final Set<String> responseParameters = ApiParameterHelper
|
||||||
.extractFieldsForResponseIfProvided(uriInfo
|
.extractFieldsForResponseIfProvided(uriInfo
|
||||||
.getQueryParameters());
|
.getQueryParameters());
|
||||||
responseParameters.addAll(typicalResponseParameters);
|
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||||
responseParameters.add("allowedDocumentTypes");
|
|
||||||
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo
|
|
||||||
.getQueryParameters());
|
|
||||||
|
|
||||||
ClientIdentifierData clientIdentifierData = this.clientReadPlatformService
|
Collection<CodeValueData> codeValues = codeValueReadPlatformService.retrieveCustomIdentifierCodeValues();
|
||||||
.retrieveNewClientIdentifierDetails();
|
ClientIdentifierData clientIdentifierData = ClientIdentifierData.template(codeValues);
|
||||||
|
|
||||||
return this.apiJsonSerializerService
|
return this.apiJsonSerializerService
|
||||||
.serializeClientIdentifierDataToJson(prettyPrint,
|
.serializeClientIdentifierDataToJson(prettyPrint,
|
||||||
@@ -144,18 +137,15 @@ public class ClientIdentifiersApiResource {
|
|||||||
context.authenticatedUser().validateHasReadPermission(entityType);
|
context.authenticatedUser().validateHasReadPermission(entityType);
|
||||||
|
|
||||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||||
if (responseParameters.isEmpty()) {
|
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||||
responseParameters.addAll(typicalResponseParameters);
|
final boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters());
|
||||||
}
|
|
||||||
|
|
||||||
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
ClientIdentifierData clientIdentifierData = this.clientReadPlatformService.retrieveClientIdentifier(clientId, clientIdentifierId);
|
||||||
boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters());
|
|
||||||
if (template) {
|
if (template) {
|
||||||
responseParameters.add("allowedDocumentTypes");
|
final Collection<CodeValueData> codeValues = codeValueReadPlatformService.retrieveCustomIdentifierCodeValues();
|
||||||
|
clientIdentifierData = ClientIdentifierData.template(clientIdentifierData, codeValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
final ClientIdentifierData clientIdentifierData = this.clientReadPlatformService.retrieveClientIdentifier(clientId, clientIdentifierId);
|
|
||||||
|
|
||||||
return this.apiJsonSerializerService
|
return this.apiJsonSerializerService
|
||||||
.serializeClientIdentifierDataToJson(prettyPrint,
|
.serializeClientIdentifierDataToJson(prettyPrint,
|
||||||
responseParameters, clientIdentifierData);
|
responseParameters, clientIdentifierData);
|
||||||
|
|||||||
@@ -32,15 +32,14 @@ import org.mifosng.platform.api.data.CommandSourceData;
|
|||||||
import org.mifosng.platform.api.data.EntityIdentifier;
|
import org.mifosng.platform.api.data.EntityIdentifier;
|
||||||
import org.mifosng.platform.api.data.NoteData;
|
import org.mifosng.platform.api.data.NoteData;
|
||||||
import org.mifosng.platform.api.data.OfficeLookup;
|
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.PortfolioApiDataConversionService;
|
||||||
import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService;
|
import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService;
|
||||||
import org.mifosng.platform.client.service.ClientReadPlatformService;
|
import org.mifosng.platform.client.service.ClientReadPlatformService;
|
||||||
import org.mifosng.platform.client.service.ClientWritePlatformService;
|
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.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.infrastructure.api.ApiParameterHelper;
|
||||||
import org.mifosng.platform.makerchecker.service.PortfolioCommandSourceWritePlatformService;
|
import org.mifosng.platform.makerchecker.service.PortfolioCommandSourceWritePlatformService;
|
||||||
import org.mifosng.platform.makerchecker.service.PortfolioCommandsReadPlatformService;
|
import org.mifosng.platform.makerchecker.service.PortfolioCommandsReadPlatformService;
|
||||||
@@ -348,13 +347,8 @@ public class ClientsApiResource {
|
|||||||
return Response.ok().entity(identifier).build();
|
return Response.ok().entity(identifier).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Upload images through multi-part form upload
|
/**
|
||||||
* @param clientId
|
* Upload images through multi-part form upload
|
||||||
* @param fileSize
|
|
||||||
* @param inputStream
|
|
||||||
* @param fileDetails
|
|
||||||
* @param bodyPart
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Path("{clientId}/image")
|
@Path("{clientId}/image")
|
||||||
@@ -374,7 +368,7 @@ public class ClientsApiResource {
|
|||||||
FileUtils.validateImageMimeType(bodyPart.getMediaType().toString());
|
FileUtils.validateImageMimeType(bodyPart.getMediaType().toString());
|
||||||
FileUtils.validateFileSizeWithinPermissibleRange(fileSize,
|
FileUtils.validateFileSizeWithinPermissibleRange(fileSize,
|
||||||
fileDetails.getFileName(),
|
fileDetails.getFileName(),
|
||||||
ApplicationConstants.MAX_FILE_UPLOAD_SIZE_IN_MB);
|
ApiConstants.MAX_FILE_UPLOAD_SIZE_IN_MB);
|
||||||
|
|
||||||
logger.debug(bodyPart.getMediaType().toString());
|
logger.debug(bodyPart.getMediaType().toString());
|
||||||
|
|
||||||
@@ -382,16 +376,12 @@ public class ClientsApiResource {
|
|||||||
.saveOrUpdateClientImage(clientId, fileDetails.getFileName(),
|
.saveOrUpdateClientImage(clientId, fileDetails.getFileName(),
|
||||||
inputStream);
|
inputStream);
|
||||||
|
|
||||||
// return identifier of the client whose image was updated
|
|
||||||
return Response.ok().entity(entityIdentifier).build();
|
return Response.ok().entity(entityIdentifier).build();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Upload image as a Data URL (essentially a base64 encoded stream)
|
/**
|
||||||
* @param clientId
|
* Upload image as a Data URL (essentially a base64 encoded stream)
|
||||||
* @param jsonRequestBody
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Path("{clientId}/image")
|
@Path("{clientId}/image")
|
||||||
@@ -407,14 +397,11 @@ public class ClientsApiResource {
|
|||||||
EntityIdentifier entityIdentifier = this.clientWritePlatformService
|
EntityIdentifier entityIdentifier = this.clientWritePlatformService
|
||||||
.saveOrUpdateClientImage(clientId, base64EncodedImage);
|
.saveOrUpdateClientImage(clientId, base64EncodedImage);
|
||||||
|
|
||||||
// return identifier of the client whose image was updated
|
|
||||||
return Response.ok().entity(entityIdentifier).build();
|
return Response.ok().entity(entityIdentifier).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a base 64 encoded client image
|
* Returns a base 64 encoded client image
|
||||||
* @param clientId
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("{clientId}/image")
|
@Path("{clientId}/image")
|
||||||
@@ -426,28 +413,17 @@ public class ClientsApiResource {
|
|||||||
context.authenticatedUser().validateHasReadPermission("CLIENTIMAGE");
|
context.authenticatedUser().validateHasReadPermission("CLIENTIMAGE");
|
||||||
|
|
||||||
final ClientData clientData = this.clientReadPlatformService.retrieveIndividualClient(clientId);
|
final ClientData clientData = this.clientReadPlatformService.retrieveIndividualClient(clientId);
|
||||||
//validate if client does not exist or image key is null
|
|
||||||
if(clientData == null){
|
if (clientData.imageKeyDoesNotExist()) {
|
||||||
throw new ClientNotFoundException(clientId);
|
throw new ImageNotFoundException("clients", clientId);
|
||||||
}
|
|
||||||
else if(clientData.imageKeyDoesNotExist()){
|
|
||||||
throw new ImageNotFoundException(ApplicationConstants.IMAGE_MANAGEMENT_ENTITY.CLIENTS, clientId);
|
|
||||||
}
|
}
|
||||||
return Response.ok().entity(Base64.encodeFromFile(clientData.imageKey())).build();
|
return Response.ok().entity(Base64.encodeFromFile(clientData.imageKey())).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
/** This method is added only for consistency with other URL patterns
|
* This method is added only for consistency with other URL patterns
|
||||||
* and for maintaining consistency of usage of the HTTP "verb"
|
* and for maintaining consistency of usage of the HTTP "verb"
|
||||||
* at the client side
|
* at the client side
|
||||||
*
|
|
||||||
* @param clientId
|
|
||||||
* @param fileSize
|
|
||||||
* @param inputStream
|
|
||||||
* @param fileDetails
|
|
||||||
* @param bodyPart
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
@PUT
|
@PUT
|
||||||
@Path("{clientId}/image")
|
@Path("{clientId}/image")
|
||||||
@@ -479,9 +455,6 @@ public class ClientsApiResource {
|
|||||||
* at the client side
|
* at the client side
|
||||||
*
|
*
|
||||||
* Upload image as a Data URL (essentially a base64 encoded stream)
|
* Upload image as a Data URL (essentially a base64 encoded stream)
|
||||||
* @param clientId
|
|
||||||
* @param jsonRequestBody
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
@PUT
|
@PUT
|
||||||
@Path("{clientId}/image")
|
@Path("{clientId}/image")
|
||||||
|
|||||||
+4
-4
@@ -25,11 +25,11 @@ import javax.ws.rs.core.UriInfo;
|
|||||||
import org.mifosng.platform.api.commands.DocumentCommand;
|
import org.mifosng.platform.api.commands.DocumentCommand;
|
||||||
import org.mifosng.platform.api.data.DocumentData;
|
import org.mifosng.platform.api.data.DocumentData;
|
||||||
import org.mifosng.platform.api.data.EntityIdentifier;
|
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.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.DocumentReadPlatformService;
|
||||||
import org.mifosng.platform.documentmanagement.service.DocumentWritePlatformService;
|
import org.mifosng.platform.documentmanagement.service.DocumentWritePlatformService;
|
||||||
|
import org.mifosng.platform.infrastructure.FileUtils;
|
||||||
import org.mifosng.platform.infrastructure.api.ApiParameterHelper;
|
import org.mifosng.platform.infrastructure.api.ApiParameterHelper;
|
||||||
import org.mifosng.platform.security.PlatformSecurityContext;
|
import org.mifosng.platform.security.PlatformSecurityContext;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -116,7 +116,7 @@ public class DocumentManagementApiResource {
|
|||||||
@FormDataParam("name") String name,
|
@FormDataParam("name") String name,
|
||||||
@FormDataParam("description") String description) {
|
@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
|
* 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("name") String name,
|
||||||
@FormDataParam("description") String description) {
|
@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<String> modifiedParams = new HashSet<String>();
|
Set<String> modifiedParams = new HashSet<String>();
|
||||||
modifiedParams.add("name");
|
modifiedParams.add("name");
|
||||||
|
|||||||
+34
-52
@@ -1,73 +1,55 @@
|
|||||||
package org.mifosng.platform.api.data;
|
package org.mifosng.platform.api.data;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Immutable data object represent client identity data.
|
||||||
|
*/
|
||||||
public class ClientIdentifierData {
|
public class ClientIdentifierData {
|
||||||
|
|
||||||
private final Long id;
|
private final Long id;
|
||||||
private final Long clientId;
|
private final Long clientId;
|
||||||
private final Long documentTypeId;
|
private final Long documentTypeId;
|
||||||
private final String documentTypeName;
|
private final String documentTypeName;
|
||||||
|
|
||||||
private final String documentKey;
|
private final String documentKey;
|
||||||
private final String description;
|
private final String description;
|
||||||
private List<CodeValueData> allowedDocumentTypes = new ArrayList<CodeValueData>();
|
@SuppressWarnings("unused")
|
||||||
|
private final Collection<CodeValueData> 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<CodeValueData> codeValues) {
|
||||||
|
return new ClientIdentifierData(null, null, null, null, null, null, codeValues);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ClientIdentifierData template(
|
||||||
|
final ClientIdentifierData data,
|
||||||
|
final Collection<CodeValueData> 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,
|
public ClientIdentifierData(
|
||||||
final Long documentTypeId, final String documentKey,
|
final Long id,
|
||||||
final String description, final String documentTypeName) {
|
final Long clientId,
|
||||||
|
final Long documentTypeId,
|
||||||
|
final String documentKey,
|
||||||
|
final String description,
|
||||||
|
final String documentTypeName,
|
||||||
|
final Collection<CodeValueData> allowedDocumentTypes) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.clientId = clientId;
|
this.clientId = clientId;
|
||||||
this.documentTypeId = documentTypeId;
|
this.documentTypeId = documentTypeId;
|
||||||
this.documentKey = documentKey;
|
this.documentKey = documentKey;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.documentTypeName = documentTypeName;
|
this.documentTypeName = documentTypeName;
|
||||||
}
|
|
||||||
|
|
||||||
public ClientIdentifierData(final Long clientId, final Long documentTypeId,
|
|
||||||
final String documentKey, final String description,
|
|
||||||
final String documentTypeName,
|
|
||||||
List<CodeValueData> allowedDocumentTypes) {
|
|
||||||
this.id = null;
|
|
||||||
this.clientId = clientId;
|
|
||||||
this.documentTypeId = documentTypeId;
|
|
||||||
this.documentKey = documentKey;
|
|
||||||
this.description = description;
|
|
||||||
this.documentTypeName = documentTypeName;
|
|
||||||
this.allowedDocumentTypes = allowedDocumentTypes;
|
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<CodeValueData> getAllowedDocumentTypes() {
|
|
||||||
return allowedDocumentTypes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAllowedDocumentTypes(List<CodeValueData> allowedDocumentTypes) {
|
|
||||||
this.allowedDocumentTypes = allowedDocumentTypes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDocumentTypeName() {
|
|
||||||
return documentTypeName;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,35 +1,17 @@
|
|||||||
package org.mifosng.platform.api.data;
|
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;
|
public CodeData(final Long id, final String name) {
|
||||||
private String codeName;
|
|
||||||
|
|
||||||
public CodeData() {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
public CodeData(final Long id, final String codeName) {
|
|
||||||
this.id = id;
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
+10
@@ -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;
|
||||||
|
}
|
||||||
-2
@@ -33,7 +33,5 @@ public interface ClientReadPlatformService {
|
|||||||
|
|
||||||
ClientIdentifierData retrieveClientIdentifier(Long clientId,Long clientIdentifierId);
|
ClientIdentifierData retrieveClientIdentifier(Long clientId,Long clientIdentifierId);
|
||||||
|
|
||||||
ClientIdentifierData retrieveNewClientIdentifierDetails();
|
|
||||||
|
|
||||||
ClientData retrieveClientByIdentifier(Long identifierTypeId, String identifierKey);
|
ClientData retrieveClientByIdentifier(Long identifierTypeId, String identifierKey);
|
||||||
}
|
}
|
||||||
+15
-40
@@ -15,18 +15,15 @@ import org.mifosng.platform.api.data.ClientAccountSummaryData;
|
|||||||
import org.mifosng.platform.api.data.ClientData;
|
import org.mifosng.platform.api.data.ClientData;
|
||||||
import org.mifosng.platform.api.data.ClientIdentifierData;
|
import org.mifosng.platform.api.data.ClientIdentifierData;
|
||||||
import org.mifosng.platform.api.data.ClientLookup;
|
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.EnumOptionData;
|
||||||
import org.mifosng.platform.api.data.NoteData;
|
import org.mifosng.platform.api.data.NoteData;
|
||||||
import org.mifosng.platform.api.data.OfficeLookup;
|
import org.mifosng.platform.api.data.OfficeLookup;
|
||||||
import org.mifosng.platform.client.domain.NoteEnumerations;
|
import org.mifosng.platform.client.domain.NoteEnumerations;
|
||||||
import org.mifosng.platform.common.ApplicationConstants;
|
|
||||||
import org.mifosng.platform.exceptions.ClientIdentifierNotFoundException;
|
import org.mifosng.platform.exceptions.ClientIdentifierNotFoundException;
|
||||||
import org.mifosng.platform.exceptions.ClientNotFoundException;
|
import org.mifosng.platform.exceptions.ClientNotFoundException;
|
||||||
import org.mifosng.platform.exceptions.NoteNotFoundException;
|
import org.mifosng.platform.exceptions.NoteNotFoundException;
|
||||||
import org.mifosng.platform.infrastructure.JdbcSupport;
|
import org.mifosng.platform.infrastructure.JdbcSupport;
|
||||||
import org.mifosng.platform.infrastructure.TenantAwareRoutingDataSource;
|
import org.mifosng.platform.infrastructure.TenantAwareRoutingDataSource;
|
||||||
import org.mifosng.platform.organisation.service.CodeValueReadPlatformService;
|
|
||||||
import org.mifosng.platform.organisation.service.OfficeReadPlatformService;
|
import org.mifosng.platform.organisation.service.OfficeReadPlatformService;
|
||||||
import org.mifosng.platform.security.PlatformSecurityContext;
|
import org.mifosng.platform.security.PlatformSecurityContext;
|
||||||
import org.mifosng.platform.user.domain.AppUser;
|
import org.mifosng.platform.user.domain.AppUser;
|
||||||
@@ -44,22 +41,18 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
|
|||||||
private final PlatformSecurityContext context;
|
private final PlatformSecurityContext context;
|
||||||
private final OfficeReadPlatformService officeReadPlatformService;
|
private final OfficeReadPlatformService officeReadPlatformService;
|
||||||
private final AppUserReadPlatformService appUserReadPlatformService;
|
private final AppUserReadPlatformService appUserReadPlatformService;
|
||||||
private final CodeValueReadPlatformService codeValuePlatformService;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public ClientReadPlatformServiceImpl(final PlatformSecurityContext context,
|
public ClientReadPlatformServiceImpl(final PlatformSecurityContext context,
|
||||||
final TenantAwareRoutingDataSource dataSource,
|
final TenantAwareRoutingDataSource dataSource,
|
||||||
final OfficeReadPlatformService officeReadPlatformService,
|
final OfficeReadPlatformService officeReadPlatformService,
|
||||||
final AppUserReadPlatformService appUserReadPlatformService,
|
final AppUserReadPlatformService appUserReadPlatformService) {
|
||||||
final CodeValueReadPlatformService codeValuePlatformService) {
|
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.officeReadPlatformService = officeReadPlatformService;
|
this.officeReadPlatformService = officeReadPlatformService;
|
||||||
this.appUserReadPlatformService = appUserReadPlatformService;
|
this.appUserReadPlatformService = appUserReadPlatformService;
|
||||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||||
this.codeValuePlatformService = codeValuePlatformService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<ClientData> retrieveAllIndividualClients(final String extraCriteria) {
|
public Collection<ClientData> retrieveAllIndividualClients(final String extraCriteria) {
|
||||||
|
|
||||||
@@ -445,8 +438,7 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<ClientIdentifierData> retrieveClientIdentifiers(
|
public Collection<ClientIdentifierData> retrieveClientIdentifiers(final Long clientId) {
|
||||||
Long clientId) {
|
|
||||||
|
|
||||||
AppUser currentUser = context.authenticatedUser();
|
AppUser currentUser = context.authenticatedUser();
|
||||||
String hierarchy = currentUser.getOffice().getHierarchy();
|
String hierarchy = currentUser.getOffice().getHierarchy();
|
||||||
@@ -458,13 +450,13 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
|
|||||||
|
|
||||||
sql += " order by ci.id";
|
sql += " order by ci.id";
|
||||||
|
|
||||||
return this.jdbcTemplate.query(sql, rm, new Object[] { clientId,
|
return this.jdbcTemplate.query(sql, rm, new Object[] { clientId, hierarchySearchString });
|
||||||
hierarchySearchString });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClientIdentifierData retrieveClientIdentifier(Long clientId,
|
public ClientIdentifierData retrieveClientIdentifier(
|
||||||
Long clientIdentifierId) {
|
final Long clientId,
|
||||||
|
final Long clientIdentifierId) {
|
||||||
try {
|
try {
|
||||||
AppUser currentUser = context.authenticatedUser();
|
AppUser currentUser = context.authenticatedUser();
|
||||||
String hierarchy = currentUser.getOffice().getHierarchy();
|
String hierarchy = currentUser.getOffice().getHierarchy();
|
||||||
@@ -476,14 +468,10 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
|
|||||||
|
|
||||||
sql += " and ci.id = ?";
|
sql += " and ci.id = ?";
|
||||||
|
|
||||||
ClientIdentifierData clientIdentifierData = this.jdbcTemplate
|
final ClientIdentifierData clientIdentifierData = this.jdbcTemplate
|
||||||
.queryForObject(sql, rm, new Object[] { clientId,
|
.queryForObject(sql, rm, new Object[] { clientId,
|
||||||
hierarchySearchString, clientIdentifierId });
|
hierarchySearchString, clientIdentifierId });
|
||||||
|
|
||||||
clientIdentifierData
|
|
||||||
.setAllowedDocumentTypes(new ArrayList<CodeValueData>(
|
|
||||||
codeValuePlatformService
|
|
||||||
.retrieveAllCodeValues(ApplicationConstants.CLIENT_IDENTITY_CODE_ID)));
|
|
||||||
return clientIdentifierData;
|
return clientIdentifierData;
|
||||||
} catch (EmptyResultDataAccessException e) {
|
} catch (EmptyResultDataAccessException e) {
|
||||||
throw new ClientIdentifierNotFoundException(clientIdentifierId);
|
throw new ClientIdentifierNotFoundException(clientIdentifierId);
|
||||||
@@ -491,19 +479,7 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private static final class ClientIdentityMapper implements RowMapper<ClientIdentifierData> {
|
||||||
public ClientIdentifierData retrieveNewClientIdentifierDetails() {
|
|
||||||
|
|
||||||
context.authenticatedUser();
|
|
||||||
|
|
||||||
List<CodeValueData> codeValueDatas = new ArrayList<CodeValueData>(
|
|
||||||
codeValuePlatformService.retrieveAllCodeValues(ApplicationConstants.CLIENT_IDENTITY_CODE_ID));
|
|
||||||
|
|
||||||
return new ClientIdentifierData(null,null,null,null,null,codeValueDatas);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final class ClientIdentityMapper implements
|
|
||||||
RowMapper<ClientIdentifierData> {
|
|
||||||
|
|
||||||
public ClientIdentityMapper() {
|
public ClientIdentityMapper() {
|
||||||
}
|
}
|
||||||
@@ -522,15 +498,14 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
|
|||||||
@SuppressWarnings("unused") final int rowNum)
|
@SuppressWarnings("unused") final int rowNum)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
|
|
||||||
Long id = JdbcSupport.getLong(rs, "id");
|
final Long id = JdbcSupport.getLong(rs, "id");
|
||||||
Long clientId = JdbcSupport.getLong(rs, "clientId");
|
final Long clientId = JdbcSupport.getLong(rs, "clientId");
|
||||||
Long documentTypeId = JdbcSupport.getLong(rs, "documentTypeId");
|
final Long documentTypeId = JdbcSupport.getLong(rs, "documentTypeId");
|
||||||
String documentKey = rs.getString("documentKey");
|
final String documentKey = rs.getString("documentKey");
|
||||||
String description = rs.getString("description");
|
final String description = rs.getString("description");
|
||||||
String documentTypeName = rs.getString("documentType");
|
final String documentTypeName = rs.getString("documentType");
|
||||||
|
|
||||||
return new ClientIdentifierData(id, clientId, documentTypeId,
|
return ClientIdentifierData.singleItem(id, clientId, documentTypeId,documentKey, description,documentTypeName);
|
||||||
documentKey, description,documentTypeName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@ import org.mifosng.platform.api.commands.ClientCommand;
|
|||||||
import org.mifosng.platform.api.commands.ClientIdentifierCommand;
|
import org.mifosng.platform.api.commands.ClientIdentifierCommand;
|
||||||
import org.mifosng.platform.api.commands.NoteCommand;
|
import org.mifosng.platform.api.commands.NoteCommand;
|
||||||
import org.mifosng.platform.api.data.EntityIdentifier;
|
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;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
|
||||||
public interface ClientWritePlatformService {
|
public interface ClientWritePlatformService {
|
||||||
|
|||||||
+14
-38
@@ -15,9 +15,6 @@ import org.mifosng.platform.client.domain.ClientIdentifierRepository;
|
|||||||
import org.mifosng.platform.client.domain.ClientRepository;
|
import org.mifosng.platform.client.domain.ClientRepository;
|
||||||
import org.mifosng.platform.client.domain.Note;
|
import org.mifosng.platform.client.domain.Note;
|
||||||
import org.mifosng.platform.client.domain.NoteRepository;
|
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.ClientIdentifierNotFoundException;
|
||||||
import org.mifosng.platform.exceptions.ClientNotFoundException;
|
import org.mifosng.platform.exceptions.ClientNotFoundException;
|
||||||
import org.mifosng.platform.exceptions.CodeValueNotFoundException;
|
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.NoteNotFoundException;
|
||||||
import org.mifosng.platform.exceptions.OfficeNotFoundException;
|
import org.mifosng.platform.exceptions.OfficeNotFoundException;
|
||||||
import org.mifosng.platform.exceptions.PlatformDataIntegrityException;
|
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.CodeValue;
|
||||||
import org.mifosng.platform.organisation.domain.CodeValueRepository;
|
import org.mifosng.platform.organisation.domain.CodeValueRepository;
|
||||||
import org.mifosng.platform.organisation.domain.Office;
|
import org.mifosng.platform.organisation.domain.Office;
|
||||||
@@ -50,7 +49,7 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
|
|||||||
private final NoteRepository noteRepository;
|
private final NoteRepository noteRepository;
|
||||||
private final CodeValueRepository codeValueRepository;
|
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;
|
private boolean makerCheckerEnabledForTask = false;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -366,29 +365,27 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public EntityIdentifier deleteClientImage(Long clientId) {
|
public EntityIdentifier deleteClientImage(final Long clientId) {
|
||||||
|
|
||||||
final Client client = this.clientRepository.findOne(clientId);
|
final Client client = this.clientRepository.findOne(clientId);
|
||||||
if (client == null || client.isDeleted()) {
|
if (client == null || client.isDeleted()) {
|
||||||
throw new ClientNotFoundException(clientId);
|
throw new ClientNotFoundException(clientId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete image from the file system
|
// delete image from the file system
|
||||||
if (StringUtils.isNotEmpty(client.getImageKey())) {
|
if (StringUtils.isNotEmpty(client.getImageKey())) {
|
||||||
FileUtils.deleteImage(
|
FileUtils.deleteClientImage(clientId, client.getImageKey());
|
||||||
ApplicationConstants.IMAGE_MANAGEMENT_ENTITY.CLIENTS,
|
|
||||||
clientId, client.getImageKey());
|
|
||||||
}
|
}
|
||||||
return updateClientImage(clientId, client, null);
|
return updateClientImage(clientId, client, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntityIdentifier saveOrUpdateClientImage(Long clientId,
|
public EntityIdentifier saveOrUpdateClientImage(final Long clientId, final Base64EncodedImage encodedImage) {
|
||||||
Base64EncodedImage encodedImage) {
|
|
||||||
try {
|
try {
|
||||||
final Client client = this.clientRepository.findOne(clientId);
|
final Client client = this.clientRepository.findOne(clientId);
|
||||||
String imageUploadLocation = setupForClientImageUpdate(clientId,
|
final String imageUploadLocation = setupForClientImageUpdate(clientId, client);
|
||||||
client);
|
|
||||||
|
|
||||||
String imageLocation = FileUtils.saveToFileSystem(encodedImage, imageUploadLocation, "image");
|
final String imageLocation = FileUtils.saveToFileSystem(encodedImage, imageUploadLocation, "image");
|
||||||
|
|
||||||
return updateClientImage(clientId, client, imageLocation);
|
return updateClientImage(clientId, client, imageLocation);
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
@@ -397,25 +394,15 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private String setupForClientImageUpdate(final Long clientId, final Client client) {
|
||||||
* @param clientId
|
|
||||||
* @param client
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private String setupForClientImageUpdate(Long clientId, final Client client) {
|
|
||||||
if (client == null || client.isDeleted()) {
|
if (client == null || client.isDeleted()) {
|
||||||
throw new ClientNotFoundException(clientId);
|
throw new ClientNotFoundException(clientId);
|
||||||
}
|
}
|
||||||
|
|
||||||
String imageUploadLocation = FileUtils
|
final String imageUploadLocation = FileUtils.generateClientImageParentDirectory(clientId);
|
||||||
.generateImageParentDirectory(
|
|
||||||
ApplicationConstants.IMAGE_MANAGEMENT_ENTITY.CLIENTS,
|
|
||||||
clientId);
|
|
||||||
// delete previous image from the file system
|
// delete previous image from the file system
|
||||||
if (StringUtils.isNotEmpty(client.getImageKey())) {
|
if (StringUtils.isNotEmpty(client.getImageKey())) {
|
||||||
FileUtils.deleteImage(
|
FileUtils.deleteClientImage(clientId, client.getImageKey());
|
||||||
ApplicationConstants.IMAGE_MANAGEMENT_ENTITY.CLIENTS,
|
|
||||||
clientId, client.getImageKey());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Recursively create the directory if it does not exist **/
|
/** Recursively create the directory if it does not exist **/
|
||||||
@@ -425,21 +412,10 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
|
|||||||
return imageUploadLocation;
|
return imageUploadLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private EntityIdentifier updateClientImage(final Long clientId, final Client client, final String imageLocation) {
|
||||||
/**
|
|
||||||
* @param clientId
|
|
||||||
* @param client
|
|
||||||
* @param imageLocation
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private EntityIdentifier updateClientImage(Long clientId,
|
|
||||||
final Client client, String imageLocation) {
|
|
||||||
client.setImageKey(imageLocation);
|
client.setImageKey(imageLocation);
|
||||||
this.clientRepository.save(client);
|
this.clientRepository.save(client);
|
||||||
|
|
||||||
return new EntityIdentifier(clientId);
|
return new EntityIdentifier(clientId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
+13
-19
@@ -6,14 +6,13 @@ import java.io.InputStream;
|
|||||||
|
|
||||||
import org.mifosng.platform.api.commands.DocumentCommand;
|
import org.mifosng.platform.api.commands.DocumentCommand;
|
||||||
import org.mifosng.platform.api.data.EntityIdentifier;
|
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.Document;
|
||||||
import org.mifosng.platform.documentmanagement.domain.DocumentRepository;
|
import org.mifosng.platform.documentmanagement.domain.DocumentRepository;
|
||||||
import org.mifosng.platform.exceptions.DocumentManagementException;
|
import org.mifosng.platform.exceptions.DocumentManagementException;
|
||||||
import org.mifosng.platform.exceptions.DocumentNotFoundException;
|
import org.mifosng.platform.exceptions.DocumentNotFoundException;
|
||||||
import org.mifosng.platform.exceptions.InvalidEntityTypeForDocumentManagementException;
|
import org.mifosng.platform.exceptions.InvalidEntityTypeForDocumentManagementException;
|
||||||
import org.mifosng.platform.exceptions.PlatformDataIntegrityException;
|
import org.mifosng.platform.exceptions.PlatformDataIntegrityException;
|
||||||
|
import org.mifosng.platform.infrastructure.FileUtils;
|
||||||
import org.mifosng.platform.security.PlatformSecurityContext;
|
import org.mifosng.platform.security.PlatformSecurityContext;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -28,28 +27,14 @@ public class DocumentWritePlatformServiceJpaRepositoryImpl implements
|
|||||||
|
|
||||||
private final static Logger logger = LoggerFactory.getLogger(DocumentWritePlatformServiceJpaRepositoryImpl.class);
|
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 PlatformSecurityContext context;
|
||||||
// private final ClientRepository clientRepository;
|
|
||||||
// private final OfficeRepository officeRepository;
|
|
||||||
// private final LoanRepository loanRepository;
|
|
||||||
// private final StaffRepository staffRepository;
|
|
||||||
private final DocumentRepository documentRepository;
|
private final DocumentRepository documentRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public DocumentWritePlatformServiceJpaRepositoryImpl(
|
public DocumentWritePlatformServiceJpaRepositoryImpl(
|
||||||
final PlatformSecurityContext context,
|
final PlatformSecurityContext context,
|
||||||
// final ClientRepository clientRepository,
|
|
||||||
// final OfficeRepository officeRepository,
|
|
||||||
// final LoanRepository loanRepository,
|
|
||||||
// final StaffRepository staffRepository,
|
|
||||||
final DocumentRepository documentRepository) {
|
final DocumentRepository documentRepository) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
// this.clientRepository = clientRepository;
|
|
||||||
// this.officeRepository = officeRepository;
|
|
||||||
// this.loanRepository = loanRepository;
|
|
||||||
// this.staffRepository = staffRepository;
|
|
||||||
this.documentRepository = documentRepository;
|
this.documentRepository = documentRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,13 +177,22 @@ public class DocumentWritePlatformServiceJpaRepositoryImpl implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean checkValidEntityType(String entityType) {
|
private static boolean checkValidEntityType(final String entityType) {
|
||||||
for (ApplicationConstants.DOCUMENT_MANAGEMENT_ENTITY entities : ApplicationConstants.DOCUMENT_MANAGEMENT_ENTITY
|
|
||||||
.values()) {
|
for (DOCUMENT_MANAGEMENT_ENTITY entities : DOCUMENT_MANAGEMENT_ENTITY.values()) {
|
||||||
if (entities.name().equalsIgnoreCase(entityType)) {
|
if (entities.name().equalsIgnoreCase(entityType)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+5
-10
@@ -1,15 +1,10 @@
|
|||||||
package org.mifosng.platform.exceptions;
|
package org.mifosng.platform.exceptions;
|
||||||
|
|
||||||
import org.mifosng.platform.common.ApplicationConstants;
|
|
||||||
|
|
||||||
public class ImageNotFoundException extends AbstractPlatformDomainRuleException {
|
public class ImageNotFoundException extends AbstractPlatformDomainRuleException {
|
||||||
|
|
||||||
public ImageNotFoundException(
|
public ImageNotFoundException(final String resource, final Long resourceId) {
|
||||||
ApplicationConstants.IMAGE_MANAGEMENT_ENTITY entityType,
|
super("error.msg.entity.image.invalid", "Image for resource "
|
||||||
Long entityId) {
|
+ resource + " with Identifier " + resourceId
|
||||||
super("error.msg.entity.image.invalid", "Image for entity "
|
+ " does not exist", resource, resourceId);
|
||||||
+ entityType.toString() + " with Identifier " + entityId
|
|
||||||
+ " does not exist", entityType.toString(), entityId);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
Executable → Regular
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package org.mifosng.platform.common;
|
package org.mifosng.platform.infrastructure;
|
||||||
|
|
||||||
public class Base64EncodedImage {
|
public class Base64EncodedImage {
|
||||||
|
|
||||||
Executable → Regular
+7
-22
@@ -1,4 +1,4 @@
|
|||||||
package org.mifosng.platform.common;
|
package org.mifosng.platform.infrastructure;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
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.ImageDataURLNotValidException;
|
||||||
import org.mifosng.platform.exceptions.ImageUploadException;
|
import org.mifosng.platform.exceptions.ImageUploadException;
|
||||||
import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
|
import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
|
||||||
import org.mifosng.platform.infrastructure.ThreadLocalContextUtil;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -74,20 +73,14 @@ public class FileUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate directory path for storing new Image
|
* Generate directory path for storing new Image
|
||||||
*
|
|
||||||
* @param entityType
|
|
||||||
* @param entityId
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public static String generateImageParentDirectory(
|
public static String generateClientImageParentDirectory(final Long resourceId) {
|
||||||
ApplicationConstants.IMAGE_MANAGEMENT_ENTITY entityType,
|
|
||||||
Long entityId) {
|
|
||||||
return FileUtils.MIFOSX_BASE_DIR
|
return FileUtils.MIFOSX_BASE_DIR
|
||||||
+ File.separator
|
+ File.separator
|
||||||
+ ThreadLocalContextUtil.getTenant().getName()
|
+ ThreadLocalContextUtil.getTenant().getName()
|
||||||
.replaceAll(" ", "").trim() + File.separator + "images"
|
.replaceAll(" ", "").trim() + File.separator + "images"
|
||||||
+ File.separator + entityType.toString() + File.separator
|
+ File.separator + "clients" + File.separator
|
||||||
+ entityId;
|
+ resourceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -205,20 +198,12 @@ public class FileUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static void deleteClientImage(final Long resourceId, final String location) {
|
||||||
* @param entityType
|
|
||||||
* @param entityId
|
|
||||||
* @param location
|
|
||||||
*/
|
|
||||||
public static void deleteImage(
|
|
||||||
ApplicationConstants.IMAGE_MANAGEMENT_ENTITY entityType,
|
|
||||||
Long entityId, String location) {
|
|
||||||
File fileToBeDeleted = new File(location);
|
File fileToBeDeleted = new File(location);
|
||||||
boolean fileDeleted = fileToBeDeleted.delete();
|
boolean fileDeleted = fileToBeDeleted.delete();
|
||||||
if (!fileDeleted) {
|
if (!fileDeleted) {
|
||||||
// no need to throw an Error, simply log a warning
|
// no need to throw an Error, simply log a warning
|
||||||
logger.warn("Unable to delete image associated with "
|
logger.warn("Unable to delete image associated with clients with Id " + resourceId);
|
||||||
+ entityType.toString() + " with Id " + entityId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+15
-2
@@ -4,8 +4,21 @@ import java.util.Collection;
|
|||||||
|
|
||||||
import org.mifosng.platform.api.data.CodeValueData;
|
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:
|
||||||
|
* <ol>
|
||||||
|
* <li>System defined codes</li>
|
||||||
|
* <li>User defined codes</li>
|
||||||
|
* </ol>
|
||||||
|
*
|
||||||
|
* <p>System defined codes cannot be altered or removed but their code values may be allowed to be added to or removed.</p>
|
||||||
|
*
|
||||||
|
* <p>User defined codes can be changed in any way by application users with system permissions.</p>
|
||||||
|
*/
|
||||||
public interface CodeValueReadPlatformService {
|
public interface CodeValueReadPlatformService {
|
||||||
|
|
||||||
Collection<CodeValueData> retrieveAllCodeValues(Long codeId);
|
// system defined code value data
|
||||||
|
Collection<CodeValueData> retrieveCustomIdentifierCodeValues();
|
||||||
}
|
}
|
||||||
+13
-16
@@ -19,41 +19,38 @@ public class CodeValueReadPlatformServiceImpl implements CodeValueReadPlatformSe
|
|||||||
private final PlatformSecurityContext context;
|
private final PlatformSecurityContext context;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public CodeValueReadPlatformServiceImpl(final PlatformSecurityContext context,
|
public CodeValueReadPlatformServiceImpl(final PlatformSecurityContext context, final TenantAwareRoutingDataSource dataSource) {
|
||||||
final TenantAwareRoutingDataSource dataSource) {
|
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class CodeValueDataMapper implements
|
private static final class CodeValueDataMapper implements RowMapper<CodeValueData> {
|
||||||
RowMapper<CodeValueData> {
|
|
||||||
|
|
||||||
public String schema() {
|
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.order_position as position"
|
||||||
+ " from m_code_value as cv ";
|
+ " from m_code_value as cv join m_code c on cv.code_id = c.id ";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CodeValueData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum)
|
public CodeValueData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
|
|
||||||
Long id = rs.getLong("id");
|
final Long id = rs.getLong("id");
|
||||||
String value = rs.getString("value");
|
final String value = rs.getString("value");
|
||||||
Integer position = rs.getInt("position");
|
final Integer position = rs.getInt("position");
|
||||||
|
|
||||||
return new CodeValueData(id, value, position);
|
return new CodeValueData(id, value, position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<CodeValueData> retrieveAllCodeValues(final Long codeId) {
|
public Collection<CodeValueData> retrieveCustomIdentifierCodeValues() {
|
||||||
|
|
||||||
context.authenticatedUser();
|
context.authenticatedUser();
|
||||||
|
|
||||||
CodeValueDataMapper rm = new CodeValueDataMapper();
|
final CodeValueDataMapper rm = new CodeValueDataMapper();
|
||||||
String sql = "select " + rm.schema()
|
final String sql = "select " + rm.schema() + "where c.code_name like ? order by position";
|
||||||
+ "where cv.code_id = ? order by position";
|
|
||||||
|
|
||||||
return this.jdbcTemplate.query(sql, rm, new Object[] { codeId });
|
return this.jdbcTemplate.query(sql, rm, new Object[] {"Customer Identifier"});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user