diff --git a/api-docs/apiLive.htm b/api-docs/apiLive.htm index 15a554d15..e072939d0 100644 --- a/api-docs/apiLive.htm +++ b/api-docs/apiLive.htm @@ -660,7 +660,7 @@ savingproducts/{prodcutId} - Retrieve a Saving procduct + Retrieve a Saving product Update a Saving product Delete a Saving product @@ -742,6 +742,22 @@ Update a Code Delete a Code + + CODE VALUES + codes/{codeId}/codevalues + Create a Code Value + List Code Values + + + + + + codes/{codeId}/codevalues/{codevalueId} + + Retrieve a Code Value + Update a Code Value + Delete a Code Value + @@ -841,7 +857,7 @@ Data Table (One to Many) - NOTE + NOTES {resource}/{resourceId}/notes Add a Resource Note Retrieve a Resource's Notes @@ -852,10 +868,38 @@ {resource}/{resourceId}/notes/{noteId} - Retrieve a Resource Note + List All + Notes for a Resource Update a Resource Note Delete a Resource Note + + Documents + {entityType}/{entityId}/documents + Create a Document + List All Document Details + + + + + + {entityType}/{entityId}/documents/{documentId} + + Retrieve a Documents Details + Update a Document + Delete a Document + + + + {entityType}/{entityId}/documents/{documentId}/attachment + + Retrieve + binary file associated with a + Document + + + + @@ -7018,7 +7062,7 @@ Request Body: { } data, their code values are a specific instance of that category.

Codes are mostly system defined which means the code itself - comes out of the box and cannot be modifed however its code values + comes out of the box and cannot be modified however its code values can be. e.g. 'Customer Identifier', it defaults to a code value of 'Passport' but could be 'Drivers License, National Id' etc

@@ -7164,6 +7208,174 @@ Content-Type: application/json + +   +

+
+

Code Values

+

Code and code values: Codes represent a specific category of + data, their code values are a specific instance of that category.

+

+ Codes are mostly system defined which means the code itself + comes out of the box and cannot be modified however its code values + can be. e.g. 'Customer Identifier', it defaults to a code value of + 'Passport' but could be 'Drivers License, National Id' etc +

+

+
+ +   +
+
+

Create a Code Value

+
+
+ +POST https://DomainName/api/v1/codes/1/codevalues + + +POST codes/1/codevalues +Content-Type: application/json +Request Body: +{ + "name":"Ration Card", + "position":"1" +} + + +{ + "resourceId": 4 +} + +
+
+ +   +
+
+

List Code Values

+

Returns the list of Code Values for a given Code

+

Example Requests:

+
codes/1/codevalues
+
+
+ +GET https://DomainName/api/v1/codes/{codeId}/codevalues + + +[ + { + "id": 1, + "name": "Passport", + "position": 0 + }, + { + "id": 2, + "name": "Id", + "position": 0 + }, + { + "id": 3, + "name": "Drivers License", + "position": 0 + }, + { + "id": 4, + "name": "Any Other Id Type", + "position": 0 + }, + { + "id": 5, + "name": "Ration Card", + "position": 1 + } +] + +
+
+ +   +
+
+

Retrieve a Code Value

+

Returns the details of a Code Value

+

Example Requests:

+
codes/1/codevalues/1
+
+
+ +GET https://DomainName/api/v1/codes/{codeId}/codevalues/{codevalueId} + + +{ + "id": 1, + "name": "Passport", + "position": 0 +} + +
+
+ +   +
+
+

Update a Code Value

+

Updates the details of a code value.

+
+
+ +PUT https://DomainName/api/v1/codes/{codeId}/codevalues/{codevalueId} + + +PUT codes/1/codevalues/1 +Content-Type: application/json +Request Body: +{ + "name": "Indian Passport", + "position":2 +} + + +{ + "resourceId": 1, + "changes": { + "name": "Indian Passport", + "position": 2 + } +} + +
+
+ +   +
+
+

Delete a Code Value

+

Deletes a code value

+
+
+ +DELETE https://DomainName/api/v1/codes/{codeId}/codevalues/{codevalueId} + + +DELETE codes/1/codevalues/5 +Content-Type: application/json + + +{ + "resourceId": 5 +} + +
+
+ + +  
@@ -9229,6 +9441,336 @@ No Request Body:
+ + +   +
+
+

Documents

+

Multiple Documents (a combination of a name, description + and a file) may be attached to different Entities + like Clients, Staff, Loans, Savings and Client + Identifiers in the system +

+

Note: The currently allowed Entities are +

    +
  • Clients: URL Pattern as clients
  • +
  • Staff: URL Pattern as staff
  • +
  • Loans: URL Pattern as loans
  • +
  • Savings: URL Pattern as savings
  • +
  • Client Identifiers: URL Pattern as client_identifiers
  • +
+

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Field Descriptions
parentEntityType
The type of the Entity + with which this document is associated +
parentEntityId
The ID of the entity (client, + loan etc) with which this document is + associated
name
User Defined name for the + document, need not be the same as the name + of the file associated with the document +
fileName
The name of the file associated + with this document
size
The size (in bytes) of the file + associated with this document
type
Mime Type of the file + associated with this document +
description
A description of this document +
+
+
+ +   +
+
+

List documents

+

Example Requests:

+
clients/1/documents
+
+
client_identifiers/1/documents
+
+
loans/1/documents?fields=name,description
+
+
+ +GET https://DomainName/api/v1/{entityType}/{entityId}/documents + + +[ + { + "id": 1, + "parentEntityType": "clients", + "parentEntityId": 1, + "name": "Client Details Form ", + "fileName": "CGAP.pdf", + "size": 5246719, + "type": "application/pdf", + "description": "A signed form signed by new member" + } +] + +
+
+ +   +
+
+

Retrieve a Document

+

Example Requests:

+
clients/1/documents/1
+
+
+
loans/1/documents/1
+
+
+
client_identifiers/1/documents/1?fields=name,description
+
+
+ +GET https://DomainName/api/v1/documents/{clientId} + + +{ + "id": 1, + "parentEntityType": "clients", + "parentEntityId": 1, + "name": "Client Details Form ", + "fileName": "CGAP.pdf", + "size": 5246719, + "type": "application/pdf", + "description": "A signed form signed by new member" +} + +
+
+ +   +
+
+

Create a Document

+

+ Note: A document is created using a Multi-part form upload +
+ + + + + + + + + + + + + + + + + + + + + + +
Body Parts
name
Name or summary of the document +
description
Description of the document +
file
The file to be uploaded +
+

+ + + + + + + +
Mandatory Fields
file and description
+
+
+ +POST https://DomainName/api/v1/{entityType}/{entityId}/documents + + +POST clients/1/documents +Content-Type: multipart/form-data +Request Body: +Not Shown (multi-part form data) + + +{ + "resourceId":3, + "resourceIdentifier":"3" +} + +
+
+ +   +
+
+

Update a Document

+

+ Note: A document is updated using a Multi-part form upload +
+ + + + + + + + + + + + + + + + + + + + + + +
Body Parts
name
Name or summary of the document +
description
Description of the document +
file
The file to be uploaded +
+

+
+
+ +PUT https://DomainName/api/v1/{entityType}/{entityId}/documents/{documentId} + + +PUT clients/1/documents/1 +Content-Type: multipart/form-data +Request Body: +Not Shown (multi-part form data) + + +{ + "resourceId":3, + "changes":{}, + "resourceIdentifier":"3" +} + +
+
+ +   +
+
+

Retrieve Binary File associated with Document

+

Request used to download the file associated with the document

+

Example Requests:

+
clients/1/documents/1/attachment
+
+
+
loans/1/documents/1/attachment
+
+
+ +GET https://DomainName/api/v1/{entityType}/{entityId}/documents/{documentId}/attachment + + +Not Shown: The corresponding Binary file + +
+
+ +   +
+
+

Remove a Document

+
+
+ +DELETE https://DomainName/api/v1/{entityType}/{entityId}/documents/{documentId} + + +DELETE clients/1/documents/1 +Content-Type: application/json +No Request Body: + + +{ + "resourceId":1, + "changes":{}, + "resourceIdentifier":"1" +} + +
+
+ +DELETE https://DomainName/api/v1/{entityType}/{entityId}/documents/{documentId} + + +DELETE loans/1/documents/1 +Content-Type: application/json +No Request Body: + + +{ + "resourceId":1, + "changes":{}, + "resourceIdentifier":"1" +} + +
+ +
+ +  
@@ -12086,6 +12628,22 @@ Content-Type: application/json Update a Code Delete a Code + + CODE VALUES + codes/{codeId}/codevalues + Create a Code Value + List Code Values + + + + + + codes/{codeId}/codevalues/{codevalueId} + + Retrieve a Code Value + Update a Code Value + Delete a Code Value + FUNDS funds @@ -12181,6 +12739,50 @@ Content-Type: application/json Table (One to Many) + Documents + {entityType}/{entityId}/documents + Create a Document + List All Document Details + + + + + + {entityType}/{entityId}/documents/{documentId} + + Retrieve a Documents Details + Update a Document + Delete a Document + + + + {entityType}/{entityId}/documents/{documentId}/attachment + + Retrieve + binary file associated with a + Document + + + + + + NOTES + {resource}/{resourceId}/notes + Add a Resource Note + Retrieve a Resource's Notes + + + + + + {resource}/{resourceId}/notes/{noteId} + + List All + Notes for a Resource + Update a Resource Note + Delete a Resource Note + + General Ledger Account glaccounts Create a New Ledger Account @@ -12188,7 +12790,7 @@ Content-Type: application/json - + glaccounts/{glaccountId} @@ -12196,7 +12798,7 @@ Content-Type: application/json Update a Ledger Account Delete a Ledger Account - + Accounting Closure glclosures Create an Accounting Closure @@ -12204,7 +12806,7 @@ Content-Type: application/json - + glclosures/{glclosureId} @@ -12212,7 +12814,7 @@ Content-Type: application/json Update an Accounting Closure Delete an Accounting Closure - + Journal Entries journalentries Create Journal Entries @@ -12220,7 +12822,7 @@ Content-Type: application/json - + journalentries/{entryId} @@ -12228,7 +12830,7 @@ Content-Type: application/json - + journalentries/{transactionId}/reversal Reverse Journal Entries @@ -12236,7 +12838,7 @@ Content-Type: application/json - + REPORT reports @@ -12244,7 +12846,7 @@ Content-Type: application/json - + reports/{reportName} @@ -12252,7 +12854,7 @@ Content-Type: application/json - + AUTHENTICATION authentication Verify Authentication @@ -12260,7 +12862,7 @@ Content-Type: application/json - + USER users Create a User @@ -12268,7 +12870,7 @@ Content-Type: application/json - + users/{userId} @@ -12276,7 +12878,7 @@ Content-Type: application/json Update a User Delete a User - + ROLE roles Create a New Role @@ -12284,7 +12886,7 @@ Content-Type: application/json - + roles/{roleId} @@ -12292,7 +12894,7 @@ Content-Type: application/json Update a Role - + roles/{roleId}/permissions @@ -12302,7 +12904,7 @@ Content-Type: application/json Permissions - + PERMISSION permissions @@ -12311,7 +12913,7 @@ Content-Type: application/json - + DEPOSIT PRODUCT depositproducts Create a Deposit product @@ -12319,7 +12921,7 @@ Content-Type: application/json - + depositproducts/{prodcutId} @@ -12327,7 +12929,7 @@ Content-Type: application/json Update a Deposit product Delete a Deposit product - + SAVING PRODUCT savingproducts Create a Saving product @@ -12335,7 +12937,7 @@ Content-Type: application/json - + savingproducts/{prodcutId} @@ -12344,7 +12946,7 @@ Content-Type: application/json Delete a Saving product - + FIXED DEPOSITS depositaccounts Create a New Deposit @@ -12353,7 +12955,7 @@ Content-Type: application/json - + depositaccounts/{accountId} Approve, Undo Approve, @@ -12366,7 +12968,7 @@ Content-Type: application/json Application - + SAVING ACCOUNTS savingaccounts Create a New Saving @@ -12375,7 +12977,7 @@ Content-Type: application/json - + savingaccounts/{accountId} Approve, Undo Approve, diff --git a/api-docs/apidocs.css b/api-docs/apidocs.css index ed56acfe6..e98f6f696 100644 --- a/api-docs/apidocs.css +++ b/api-docs/apidocs.css @@ -172,7 +172,7 @@ body { text-align: center; text-transform: uppercase; font-size: 12px; - padding: 0 1em; + padding: 0 0.5em; line-height: 40px; border-right: 1px solid transparent; border-left: 1px solid transparent; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/api/DocumentManagementApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/api/DocumentManagementApiResource.java index e92e2a210..b12ae5054 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/api/DocumentManagementApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/api/DocumentManagementApiResource.java @@ -52,7 +52,7 @@ import com.sun.jersey.multipart.FormDataParam; public class DocumentManagementApiResource { private final Set RESPONSE_DATA_PARAMETERS = new HashSet(Arrays.asList("id", "parentEntityType", "parentEntityId", - "name", "fileName", "type", "size", "description")); + "name", "fileName", "size", "type", "description")); private final String SystemEntityType = "DOCUMENT"; @@ -76,24 +76,24 @@ public class DocumentManagementApiResource { @GET @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) - public String retreiveAllDocuments(@Context final UriInfo uriInfo, @PathParam("entityType") String entityType, - @PathParam("entityId") Long entityId) { + public String retreiveAllDocuments(@Context final UriInfo uriInfo, @PathParam("entityType") final String entityType, + @PathParam("entityId") final Long entityId) { - context.authenticatedUser().validateHasReadPermission(SystemEntityType); + this.context.authenticatedUser().validateHasReadPermission(this.SystemEntityType); final Collection documentDatas = this.documentReadPlatformService.retrieveAllDocuments(entityType, entityId); - final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters()); - return this.toApiJsonSerializer.serialize(settings, documentDatas, RESPONSE_DATA_PARAMETERS); + final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); + return this.toApiJsonSerializer.serialize(settings, documentDatas, this.RESPONSE_DATA_PARAMETERS); } @POST @Consumes({ MediaType.MULTIPART_FORM_DATA }) @Produces({ MediaType.APPLICATION_JSON }) - public String createDocument(@PathParam("entityType") String entityType, @PathParam("entityId") Long entityId, - @HeaderParam("Content-Length") Long fileSize, @FormDataParam("file") InputStream inputStream, - @FormDataParam("file") FormDataContentDisposition fileDetails, @FormDataParam("file") FormDataBodyPart bodyPart, - @FormDataParam("name") String name, @FormDataParam("description") String description) { + public String createDocument(@PathParam("entityType") final String entityType, @PathParam("entityId") final Long entityId, + @HeaderParam("Content-Length") final Long fileSize, @FormDataParam("file") final InputStream inputStream, + @FormDataParam("file") final FormDataContentDisposition fileDetails, @FormDataParam("file") final FormDataBodyPart bodyPart, + @FormDataParam("name") final String name, @FormDataParam("description") final String description) { FileUtils.validateFileSizeWithinPermissibleRange(fileSize, name, ApiConstants.MAX_FILE_UPLOAD_SIZE_IN_MB); @@ -106,10 +106,10 @@ public class DocumentManagementApiResource { * TODO: need to extract the actual file type and determine if they are * permissable **/ - DocumentCommand documentCommand = new DocumentCommand(null, null, entityType, entityId, name, fileDetails.getFileName(), fileSize, - bodyPart.getMediaType().toString(), description, null); + final DocumentCommand documentCommand = new DocumentCommand(null, null, entityType, entityId, name, fileDetails.getFileName(), + fileSize, bodyPart.getMediaType().toString(), description, null); - Long documentId = this.documentWritePlatformService.createDocument(documentCommand, inputStream); + final Long documentId = this.documentWritePlatformService.createDocument(documentCommand, inputStream); return this.toApiJsonSerializer.serialize(CommandProcessingResult.resourceResult(documentId, null)); } @@ -118,15 +118,15 @@ public class DocumentManagementApiResource { @Path("{documentId}") @Consumes({ MediaType.MULTIPART_FORM_DATA }) @Produces({ MediaType.APPLICATION_JSON }) - public String updateDocument(@PathParam("entityType") String entityType, @PathParam("entityId") Long entityId, - @PathParam("documentId") Long documentId, @HeaderParam("Content-Length") Long fileSize, - @FormDataParam("file") InputStream inputStream, @FormDataParam("file") FormDataContentDisposition fileDetails, - @FormDataParam("file") FormDataBodyPart bodyPart, @FormDataParam("name") String name, - @FormDataParam("description") String description) { + public String updateDocument(@PathParam("entityType") final String entityType, @PathParam("entityId") final Long entityId, + @PathParam("documentId") final Long documentId, @HeaderParam("Content-Length") final Long fileSize, + @FormDataParam("file") final InputStream inputStream, @FormDataParam("file") final FormDataContentDisposition fileDetails, + @FormDataParam("file") final FormDataBodyPart bodyPart, @FormDataParam("name") final String name, + @FormDataParam("description") final String description) { FileUtils.validateFileSizeWithinPermissibleRange(fileSize, name, ApiConstants.MAX_FILE_UPLOAD_SIZE_IN_MB); - Set modifiedParams = new HashSet(); + final Set modifiedParams = new HashSet(); modifiedParams.add("name"); modifiedParams.add("description"); @@ -146,7 +146,11 @@ public class DocumentManagementApiResource { documentCommand = new DocumentCommand(modifiedParams, documentId, entityType, entityId, name, null, null, null, description, null); } - CommandProcessingResult identifier = this.documentWritePlatformService.updateDocument(documentCommand, inputStream); + /*** + * TODO: does not return list of changes, should be done for consistency + * with rest of API + **/ + final CommandProcessingResult identifier = this.documentWritePlatformService.updateDocument(documentCommand, inputStream); return this.toApiJsonSerializer.serialize(identifier); } @@ -155,32 +159,35 @@ public class DocumentManagementApiResource { @Path("{documentId}") @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) - public String getDocument(@PathParam("entityType") String entityType, @PathParam("entityId") Long entityId, - @PathParam("documentId") Long documentId, @Context final UriInfo uriInfo) { + public String getDocument(@PathParam("entityType") final String entityType, @PathParam("entityId") final Long entityId, + @PathParam("documentId") final Long documentId, @Context final UriInfo uriInfo) { - context.authenticatedUser().validateHasReadPermission(SystemEntityType); + this.context.authenticatedUser().validateHasReadPermission(this.SystemEntityType); final DocumentData documentData = this.documentReadPlatformService.retrieveDocument(entityType, entityId, documentId); - final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters()); - return this.toApiJsonSerializer.serialize(settings, documentData, RESPONSE_DATA_PARAMETERS); + // we do not want to send document location as a part of the response + documentData.setLocation(null); + + final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); + return this.toApiJsonSerializer.serialize(settings, documentData, this.RESPONSE_DATA_PARAMETERS); } @GET @Path("{documentId}/attachment") @Consumes({ MediaType.APPLICATION_JSON }) - @Produces({ MediaType.APPLICATION_JSON }) - public Response downloadFile(@PathParam("entityType") String entityType, @PathParam("entityId") Long entityId, - @PathParam("documentId") Long documentId) { + @Produces({ MediaType.APPLICATION_OCTET_STREAM }) + public Response downloadFile(@PathParam("entityType") final String entityType, @PathParam("entityId") final Long entityId, + @PathParam("documentId") final Long documentId) { - context.authenticatedUser().validateHasReadPermission(SystemEntityType); + this.context.authenticatedUser().validateHasReadPermission(this.SystemEntityType); - DocumentData documentData = this.documentReadPlatformService.retrieveDocument(entityType, entityId, documentId); - File file = new File(documentData.fileLocation()); - ResponseBuilder response = Response.ok(file); + final DocumentData documentData = this.documentReadPlatformService.retrieveDocument(entityType, entityId, documentId); + final File file = new File(documentData.fileLocation()); + final ResponseBuilder response = Response.ok(file); response.header("Content-Disposition", "attachment; filename=\"" + documentData.fileName() + "\""); response.header("Content-Type", documentData.contentType()); - + return response.build(); } @@ -188,8 +195,8 @@ public class DocumentManagementApiResource { @Path("{documentId}") @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) - public String deleteDocument(@PathParam("entityType") String entityType, @PathParam("entityId") Long entityId, - @PathParam("documentId") Long documentId) { + public String deleteDocument(@PathParam("entityType") final String entityType, @PathParam("entityId") final Long entityId, + @PathParam("documentId") final Long documentId) { final DocumentCommand documentCommand = new DocumentCommand(null, documentId, entityType, entityId, null, null, null, null, null, null); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/command/DocumentCommand.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/command/DocumentCommand.java index 0955c02da..d138ad51f 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/command/DocumentCommand.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/command/DocumentCommand.java @@ -26,7 +26,7 @@ public class DocumentCommand { private final Set modifiedParameters; public DocumentCommand(final Set modifiedParameters, final Long id, final String parentEntityType, final Long parentEntityId, - final String name, final String fileName, Long size, String type, final String description, String location) { + final String name, final String fileName, final Long size, final String type, final String description, final String location) { this.modifiedParameters = modifiedParameters; this.id = id; this.parentEntityType = parentEntityType; @@ -40,58 +40,58 @@ public class DocumentCommand { } public Long getId() { - return id; + return this.id; } public String getParentEntityType() { - return parentEntityType; + return this.parentEntityType; } public Long getParentEntityId() { - return parentEntityId; + return this.parentEntityId; } public String getName() { - return name; + return this.name; } public String getFileName() { - return fileName; + return this.fileName; } public Long getSize() { - return size; + return this.size; } public String getType() { - return type; + return this.type; } public String getDescription() { - return description; + return this.description; } public String getLocation() { - return location; + return this.location; } public Set getModifiedParameters() { - return modifiedParameters; + return this.modifiedParameters; } - public void setFileName(String fileName) { + public void setFileName(final String fileName) { this.fileName = fileName; } - public void setSize(Long size) { + public void setSize(final Long size) { this.size = size; } - public void setType(String type) { + public void setType(final String type) { this.type = type; } - public void setLocation(String location) { + public void setLocation(final String location) { this.location = location; } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/command/DocumentCommandValidator.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/command/DocumentCommandValidator.java index 91143fa75..ab93dc3cf 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/command/DocumentCommandValidator.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/command/DocumentCommandValidator.java @@ -16,38 +16,40 @@ public class DocumentCommandValidator { private final DocumentCommand command; - public DocumentCommandValidator(DocumentCommand command) { + public DocumentCommandValidator(final DocumentCommand command) { this.command = command; } public void validateForUpdate() { - List dataValidationErrors = new ArrayList(); + final List dataValidationErrors = new ArrayList(); - DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("document"); + final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("document"); - baseDataValidator.reset().parameter("name").value(command.getName()).ignoreIfNull().notBlank(); - baseDataValidator.reset().parameter("size").value(command.getSize()).ignoreIfNull().integerGreaterThanZero(); - baseDataValidator.reset().parameter("fileName").value(command.getFileName()).ignoreIfNull().notBlank().notExceedingLengthOf(250); - baseDataValidator.reset().parameter("location").value(command.getLocation()).ignoreIfNull().notBlank(); - baseDataValidator.reset().parameter("description").value(command.getName()).ignoreIfNull().notExceedingLengthOf(250); + baseDataValidator.reset().parameter("name").value(this.command.getName()).ignoreIfNull().notBlank(); + baseDataValidator.reset().parameter("size").value(this.command.getSize()).ignoreIfNull().integerGreaterThanZero(); + baseDataValidator.reset().parameter("fileName").value(this.command.getFileName()).ignoreIfNull().notBlank() + .notExceedingLengthOf(250); + baseDataValidator.reset().parameter("location").value(this.command.getLocation()).ignoreIfNull().notBlank(); + baseDataValidator.reset().parameter("description").value(this.command.getName()).ignoreIfNull().notExceedingLengthOf(250); - baseDataValidator.reset().anyOfNotNull(command.getName(), command.getFileName(), command.getDescription(), command.getLocation(), - command.getSize()); + baseDataValidator.reset().anyOfNotNull(this.command.getName(), this.command.getFileName(), this.command.getDescription(), + this.command.getLocation(), this.command.getSize()); if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); } } public void validateForCreate() { - List dataValidationErrors = new ArrayList(); + final List dataValidationErrors = new ArrayList(); - DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("document"); - baseDataValidator.reset().parameter("parentEntityType").value(command.getParentEntityType()).notBlank().notExceedingLengthOf(50); - baseDataValidator.reset().parameter("parentEntityId").value(command.getParentEntityId()).integerGreaterThanZero(); - baseDataValidator.reset().parameter("name").value(command.getName()).notBlank().notExceedingLengthOf(250); - baseDataValidator.reset().parameter("size").value(command.getSize()).integerGreaterThanZero(); - baseDataValidator.reset().parameter("fileName").value(command.getFileName()).notBlank().notExceedingLengthOf(250); - baseDataValidator.reset().parameter("description").value(command.getName()).notExceedingLengthOf(250); + final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("document"); + baseDataValidator.reset().parameter("parentEntityType").value(this.command.getParentEntityType()).notBlank() + .notExceedingLengthOf(50); + baseDataValidator.reset().parameter("parentEntityId").value(this.command.getParentEntityId()).integerGreaterThanZero(); + baseDataValidator.reset().parameter("name").value(this.command.getName()).notBlank().notExceedingLengthOf(250); + baseDataValidator.reset().parameter("size").value(this.command.getSize()).integerGreaterThanZero(); + baseDataValidator.reset().parameter("fileName").value(this.command.getFileName()).notBlank().notExceedingLengthOf(250); + baseDataValidator.reset().parameter("description").value(this.command.getName()).notExceedingLengthOf(250); if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/data/DocumentData.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/data/DocumentData.java index e5a93620f..25cdcb931 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/data/DocumentData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/data/DocumentData.java @@ -24,7 +24,7 @@ public class DocumentData { private final String type; @SuppressWarnings("unused") private final String description; - private final String location; + private String location; public DocumentData(final Long id, final String parentEntityType, final Long parentEntityId, final String name, final String fileName, final Long size, final String type, final String description, final String location) { @@ -50,4 +50,9 @@ public class DocumentData { public String fileLocation() { return this.location; } + + public void setLocation(final String location) { + this.location = location; + } + } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/domain/Document.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/domain/Document.java index b138452f4..467503668 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/domain/Document.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/domain/Document.java @@ -43,13 +43,13 @@ public class Document extends AbstractPersistable { public Document() {} - public static Document createNew(String parentEntityType, Long parentEntityId, String name, String fileName, Long size, String type, - String description, String location) { + public static Document createNew(final String parentEntityType, final Long parentEntityId, final String name, final String fileName, + final Long size, final String type, final String description, final String location) { return new Document(parentEntityType, parentEntityId, name, fileName, size, type, description, location); } - private Document(String parentEntityType, Long parentEntityId, String name, String fileName, Long size, String type, - String description, String location) { + private Document(final String parentEntityType, final Long parentEntityId, final String name, final String fileName, final Long size, + final String type, final String description, final String location) { this.parentEntityType = StringUtils.defaultIfEmpty(parentEntityType, null); this.parentEntityId = parentEntityId; this.name = StringUtils.defaultIfEmpty(name, null); @@ -83,66 +83,66 @@ public class Document extends AbstractPersistable { } public String getParentEntityType() { - return parentEntityType; + return this.parentEntityType; } - public void setParentEntityType(String parentEntityType) { + public void setParentEntityType(final String parentEntityType) { this.parentEntityType = parentEntityType; } public Long getParentEntityId() { - return parentEntityId; + return this.parentEntityId; } - public void setParentEntityId(Long parentEntityId) { + public void setParentEntityId(final Long parentEntityId) { this.parentEntityId = parentEntityId; } public String getName() { - return name; + return this.name; } - public void setName(String name) { + public void setName(final String name) { this.name = name; } public String getFileName() { - return fileName; + return this.fileName; } - public void setFileName(String fileName) { + public void setFileName(final String fileName) { this.fileName = fileName; } public Long getSize() { - return size; + return this.size; } - public void setSize(Long size) { + public void setSize(final Long size) { this.size = size; } public String getType() { - return type; + return this.type; } - public void setType(String type) { + public void setType(final String type) { this.type = type; } public String getDescription() { - return description; + return this.description; } - public void setDescription(String description) { + public void setDescription(final String description) { this.description = description; } public String getLocation() { - return location; + return this.location; } - public void setLocation(String location) { + public void setLocation(final String location) { this.location = location; } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/service/DocumentReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/service/DocumentReadPlatformServiceImpl.java index de84d08a8..15fd7dcf9 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/service/DocumentReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/service/DocumentReadPlatformServiceImpl.java @@ -35,13 +35,13 @@ public class DocumentReadPlatformServiceImpl implements DocumentReadPlatformServ @Override public Collection retrieveAllDocuments(final String entityType, final Long entityId) { - context.authenticatedUser(); + this.context.authenticatedUser(); // TODO verify if the entities are valid and a user // has data // scope for the particular entities - DocumentMapper mapper = new DocumentMapper(); - String sql = "select " + mapper.schema() + " order by d.id"; + final DocumentMapper mapper = new DocumentMapper(true); + final String sql = "select " + mapper.schema() + " order by d.id"; return this.jdbcTemplate.query(sql, mapper, new Object[] { entityType, entityId }); } @@ -49,21 +49,27 @@ public class DocumentReadPlatformServiceImpl implements DocumentReadPlatformServ public DocumentData retrieveDocument(final String entityType, final Long entityId, final Long documentId) { try { - context.authenticatedUser(); + this.context.authenticatedUser(); // TODO verify if the entities are valid and a // user has data // scope for the particular entities - DocumentMapper mapper = new DocumentMapper(); - String sql = "select " + mapper.schema() + " and d.id=? "; + final DocumentMapper mapper = new DocumentMapper(false); + final String sql = "select " + mapper.schema() + " and d.id=? "; return this.jdbcTemplate.queryForObject(sql, mapper, new Object[] { entityType, entityId, documentId }); - } catch (EmptyResultDataAccessException e) { + } catch (final EmptyResultDataAccessException e) { throw new DocumentNotFoundException(entityType, entityId, documentId); } } private static final class DocumentMapper implements RowMapper { + private final boolean hideLocation; + + public DocumentMapper(final boolean hideLocation) { + this.hideLocation = hideLocation; + } + public String schema() { return "d.id as id, d.parent_entity_type as parentEntityType, d.parent_entity_id as parentEntityId, d.name as name, " + " d.file_name as fileName, d.size as fileSize, d.type as fileType, " @@ -82,7 +88,10 @@ public class DocumentReadPlatformServiceImpl implements DocumentReadPlatformServ final String fileName = rs.getString("fileName"); final String fileType = rs.getString("fileType"); final String description = rs.getString("description"); - final String location = rs.getString("location"); + String location = null; + if (!this.hideLocation) { + location = rs.getString("location"); + } return new DocumentData(id, parentEntityType, parentEntityId, name, fileName, fileSize, fileType, description, location); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/service/DocumentWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/service/DocumentWritePlatformServiceJpaRepositoryImpl.java index af4a80451..7c5e6cb16 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/service/DocumentWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/service/DocumentWritePlatformServiceJpaRepositoryImpl.java @@ -45,15 +45,15 @@ public class DocumentWritePlatformServiceJpaRepositoryImpl implements DocumentWr @Override public Long createDocument(final DocumentCommand documentCommand, final InputStream inputStream) { try { - context.authenticatedUser(); + this.context.authenticatedUser(); - DocumentCommandValidator validator = new DocumentCommandValidator(documentCommand); + final DocumentCommandValidator validator = new DocumentCommandValidator(documentCommand); validateParentEntityType(documentCommand); validator.validateForCreate(); - String fileUploadLocation = FileUtils.generateFileParentDirectory(documentCommand.getParentEntityType(), + final String fileUploadLocation = FileUtils.generateFileParentDirectory(documentCommand.getParentEntityType(), documentCommand.getParentEntityId()); /** Recursively create the directory if it does not exist **/ @@ -61,20 +61,20 @@ public class DocumentWritePlatformServiceJpaRepositoryImpl implements DocumentWr new File(fileUploadLocation).mkdirs(); } - String fileLocation = FileUtils.saveToFileSystem(inputStream, fileUploadLocation, documentCommand.getFileName()); + final String fileLocation = FileUtils.saveToFileSystem(inputStream, fileUploadLocation, documentCommand.getFileName()); - Document document = Document.createNew(documentCommand.getParentEntityType(), documentCommand.getParentEntityId(), + final Document document = Document.createNew(documentCommand.getParentEntityType(), documentCommand.getParentEntityId(), documentCommand.getName(), documentCommand.getFileName(), documentCommand.getSize(), documentCommand.getType(), documentCommand.getDescription(), fileLocation); this.documentRepository.save(document); return document.getId(); - } catch (DataIntegrityViolationException dve) { + } catch (final DataIntegrityViolationException dve) { logger.error(dve.getMessage(), dve); throw new PlatformDataIntegrityException("error.msg.document.unknown.data.integrity.issue", "Unknown data integrity issue with resource."); - } catch (IOException ioe) { + } catch (final IOException ioe) { logger.error(ioe.getMessage(), ioe); throw new DocumentManagementException(documentCommand.getName()); } @@ -84,20 +84,20 @@ public class DocumentWritePlatformServiceJpaRepositoryImpl implements DocumentWr @Override public CommandProcessingResult updateDocument(final DocumentCommand documentCommand, final InputStream inputStream) { try { - context.authenticatedUser(); + this.context.authenticatedUser(); String oldLocation = null; - DocumentCommandValidator validator = new DocumentCommandValidator(documentCommand); + final DocumentCommandValidator validator = new DocumentCommandValidator(documentCommand); validator.validateForUpdate(); // TODO check if entity id is valid and within data scope for the // user - Document documentForUpdate = this.documentRepository.findOne(documentCommand.getId()); + final Document documentForUpdate = this.documentRepository.findOne(documentCommand.getId()); if (documentForUpdate == null) { throw new DocumentNotFoundException(documentCommand.getParentEntityType(), documentCommand.getParentEntityId(), documentCommand.getId()); } oldLocation = documentForUpdate.getLocation(); // if a new file is also passed in if (inputStream != null && documentCommand.isFileNameChanged()) { - String fileUploadLocation = FileUtils.generateFileParentDirectory(documentCommand.getParentEntityType(), + final String fileUploadLocation = FileUtils.generateFileParentDirectory(documentCommand.getParentEntityType(), documentCommand.getParentEntityId()); /** Recursively create the directory if it does not exist **/ @@ -105,8 +105,9 @@ public class DocumentWritePlatformServiceJpaRepositoryImpl implements DocumentWr new File(fileUploadLocation).mkdirs(); } - // TODO replace file system appender with an Amazon S3 appender - String fileLocation = FileUtils.saveToFileSystem(inputStream, fileUploadLocation, documentCommand.getFileName()); + // TODO provide switch to toggle between file system appender + // and Amazon S3 appender + final String fileLocation = FileUtils.saveToFileSystem(inputStream, fileUploadLocation, documentCommand.getFileName()); documentCommand.setLocation(fileLocation); } @@ -120,11 +121,11 @@ public class DocumentWritePlatformServiceJpaRepositoryImpl implements DocumentWr this.documentRepository.saveAndFlush(documentForUpdate); return new CommandProcessingResult(documentForUpdate.getId()); - } catch (DataIntegrityViolationException dve) { + } catch (final DataIntegrityViolationException dve) { logger.error(dve.getMessage(), dve); throw new PlatformDataIntegrityException("error.msg.document.unknown.data.integrity.issue", "Unknown data integrity issue with resource."); - } catch (IOException ioe) { + } catch (final IOException ioe) { logger.error(ioe.getMessage(), ioe); throw new DocumentManagementException(documentCommand.getName()); } @@ -133,11 +134,11 @@ public class DocumentWritePlatformServiceJpaRepositoryImpl implements DocumentWr @Transactional @Override public CommandProcessingResult deleteDocument(final DocumentCommand documentCommand) { - context.authenticatedUser(); + this.context.authenticatedUser(); validateParentEntityType(documentCommand); // TODO: Check document is present under this entity Id - Document document = this.documentRepository.findOne(documentCommand.getId()); + final Document document = this.documentRepository.findOne(documentCommand.getId()); if (document == null) { throw new DocumentNotFoundException(documentCommand.getParentEntityType(), documentCommand.getParentEntityId(), documentCommand.getId()); } @@ -146,20 +147,20 @@ public class DocumentWritePlatformServiceJpaRepositoryImpl implements DocumentWr return new CommandProcessingResult(document.getId()); } - private void deleteFile(String documentName, String location) { - File fileToBeDeleted = new File(location); - boolean fileDeleted = fileToBeDeleted.delete(); + private void deleteFile(final String documentName, final String location) { + final File fileToBeDeleted = new File(location); + final boolean fileDeleted = fileToBeDeleted.delete(); if (!fileDeleted) { throw new DocumentManagementException(documentName); } } - private void validateParentEntityType(DocumentCommand documentCommand) { + private void validateParentEntityType(final DocumentCommand documentCommand) { if (!checkValidEntityType(documentCommand.getParentEntityType())) { throw new InvalidEntityTypeForDocumentManagementException( documentCommand.getParentEntityType()); } } private static boolean checkValidEntityType(final String entityType) { - for (DOCUMENT_MANAGEMENT_ENTITY entities : DOCUMENT_MANAGEMENT_ENTITY.values()) { + for (final DOCUMENT_MANAGEMENT_ENTITY entities : DOCUMENT_MANAGEMENT_ENTITY.values()) { if (entities.name().equalsIgnoreCase(entityType)) { return true; } } return false; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/serialization/ClientIdentifierCommandFromApiJsonDeserializer.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/serialization/ClientIdentifierCommandFromApiJsonDeserializer.java index 4aa67f445..872bdcb63 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/serialization/ClientIdentifierCommandFromApiJsonDeserializer.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/serialization/ClientIdentifierCommandFromApiJsonDeserializer.java @@ -49,12 +49,12 @@ public final class ClientIdentifierCommandFromApiJsonDeserializer extends Abstra if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } final Type typeOfMap = new TypeToken>() {}.getType(); - fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParameters); + this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, this.supportedParameters); - final JsonElement element = fromApiJsonHelper.parse(json); - final Long documentTypeId = fromApiJsonHelper.extractLongNamed("documentTypeId", element); - final String documentKey = fromApiJsonHelper.extractStringNamed("documentKey", element); - final String documentDescription = fromApiJsonHelper.extractStringNamed("documentDescription", element); + final JsonElement element = this.fromApiJsonHelper.parse(json); + final Long documentTypeId = this.fromApiJsonHelper.extractLongNamed("documentTypeId", element); + final String documentKey = this.fromApiJsonHelper.extractStringNamed("documentKey", element); + final String documentDescription = this.fromApiJsonHelper.extractStringNamed("documentDescription", element); return new ClientIdentifierCommand(documentTypeId, documentKey, documentDescription); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientIdentifierReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientIdentifierReadPlatformServiceImpl.java index 56f0c3787..1e2121180 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientIdentifierReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientIdentifierReadPlatformServiceImpl.java @@ -37,11 +37,11 @@ public class ClientIdentifierReadPlatformServiceImpl implements ClientIdentifier @Override public Collection retrieveClientIdentifiers(final Long clientId) { - AppUser currentUser = context.authenticatedUser(); - String hierarchy = currentUser.getOffice().getHierarchy(); - String hierarchySearchString = hierarchy + "%"; + final AppUser currentUser = this.context.authenticatedUser(); + final String hierarchy = currentUser.getOffice().getHierarchy(); + final String hierarchySearchString = hierarchy + "%"; - ClientIdentityMapper rm = new ClientIdentityMapper(); + final ClientIdentityMapper rm = new ClientIdentityMapper(); String sql = "select " + rm.schema(); @@ -53,11 +53,11 @@ public class ClientIdentifierReadPlatformServiceImpl implements ClientIdentifier @Override public ClientIdentifierData retrieveClientIdentifier(final Long clientId, final Long clientIdentifierId) { try { - AppUser currentUser = context.authenticatedUser(); - String hierarchy = currentUser.getOffice().getHierarchy(); - String hierarchySearchString = hierarchy + "%"; + final AppUser currentUser = this.context.authenticatedUser(); + final String hierarchy = currentUser.getOffice().getHierarchy(); + final String hierarchySearchString = hierarchy + "%"; - ClientIdentityMapper rm = new ClientIdentityMapper(); + final ClientIdentityMapper rm = new ClientIdentityMapper(); String sql = "select " + rm.schema(); @@ -67,7 +67,7 @@ public class ClientIdentifierReadPlatformServiceImpl implements ClientIdentifier hierarchySearchString, clientIdentifierId }); return clientIdentifierData; - } catch (EmptyResultDataAccessException e) { + } catch (final EmptyResultDataAccessException e) { throw new ClientIdentifierNotFoundException(clientIdentifierId); } @@ -95,7 +95,7 @@ public class ClientIdentifierReadPlatformServiceImpl implements ClientIdentifier final String description = rs.getString("description"); final String documentTypeName = rs.getString("documentType"); - CodeValueData documentType = CodeValueData.instance(documentTypeId, documentTypeName); + final CodeValueData documentType = CodeValueData.instance(documentTypeId, documentTypeName); return ClientIdentifierData.singleItem(id, clientId, documentType, documentKey, description); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientIdentifierWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientIdentifierWritePlatformServiceJpaRepositoryImpl.java index 0b4a6d5c0..c4b69ddd2 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientIdentifierWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientIdentifierWritePlatformServiceJpaRepositoryImpl.java @@ -58,12 +58,12 @@ public class ClientIdentifierWritePlatformServiceJpaRepositoryImpl implements Cl @Override public CommandProcessingResult addClientIdentifier(final Long clientId, final JsonCommand command) { - context.authenticatedUser(); + this.context.authenticatedUser(); final ClientIdentifierCommand clientIdentifierCommand = this.clientIdentifierCommandFromApiJsonDeserializer .commandFromApiJson(command.json()); clientIdentifierCommand.validateForCreate(); - String documentKey = clientIdentifierCommand.getDocumentKey(); + final String documentKey = clientIdentifierCommand.getDocumentKey(); String documentTypeLabel = null; Long documentTypeId = null; try { @@ -85,7 +85,7 @@ public class ClientIdentifierWritePlatformServiceJpaRepositoryImpl implements Cl .withClientId(clientId) // .withEntityId(clientIdentifier.getId()) // .build(); - } catch (DataIntegrityViolationException dve) { + } catch (final DataIntegrityViolationException dve) { handleClientIdentifierDataIntegrityViolation(documentTypeLabel, documentTypeId, documentKey, dve); return CommandProcessingResult.empty(); } @@ -95,7 +95,7 @@ public class ClientIdentifierWritePlatformServiceJpaRepositoryImpl implements Cl @Override public CommandProcessingResult updateClientIdentifier(final Long clientId, final Long identifierId, final JsonCommand command) { - context.authenticatedUser(); + this.context.authenticatedUser(); final ClientIdentifierCommand clientIdentifierCommand = this.clientIdentifierCommandFromApiJsonDeserializer .commandFromApiJson(command.json()); clientIdentifierCommand.validateForUpdate(); @@ -143,7 +143,7 @@ public class ClientIdentifierWritePlatformServiceJpaRepositoryImpl implements Cl .withEntityId(identifierId) // .with(changes) // .build(); - } catch (DataIntegrityViolationException dve) { + } catch (final DataIntegrityViolationException dve) { handleClientIdentifierDataIntegrityViolation(documentTypeLabel, documentTypeId, documentKey, dve); return new CommandProcessingResult(Long.valueOf(-1)); }