documentation stub for entity documents and code values

This commit is contained in:
Vishwas Babu AJ
2013-03-19 20:09:01 +05:30
parent cb8b8e72d1
commit 5145b242ae
12 changed files with 793 additions and 167 deletions
@@ -52,7 +52,7 @@ import com.sun.jersey.multipart.FormDataParam;
public class DocumentManagementApiResource {
private final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(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<DocumentData> 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<String> modifiedParams = new HashSet<String>();
final Set<String> modifiedParams = new HashSet<String>();
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);
@@ -26,7 +26,7 @@ public class DocumentCommand {
private final Set<String> modifiedParameters;
public DocumentCommand(final Set<String> 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<String> 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;
}
@@ -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<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
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<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
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); }
@@ -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;
}
}
@@ -43,13 +43,13 @@ public class Document extends AbstractPersistable<Long> {
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<Long> {
}
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;
}
@@ -35,13 +35,13 @@ public class DocumentReadPlatformServiceImpl implements DocumentReadPlatformServ
@Override
public Collection<DocumentData> 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<DocumentData> {
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);
}
@@ -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;
@@ -49,12 +49,12 @@ public final class ClientIdentifierCommandFromApiJsonDeserializer extends Abstra
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.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);
}
@@ -37,11 +37,11 @@ public class ClientIdentifierReadPlatformServiceImpl implements ClientIdentifier
@Override
public Collection<ClientIdentifierData> 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);
}
@@ -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));
}