mifosx-45: removed usused imports.
This commit is contained in:
@@ -4,6 +4,7 @@ import java.util.Collection;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.DELETE;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.POST;
|
import javax.ws.rs.POST;
|
||||||
import javax.ws.rs.PUT;
|
import javax.ws.rs.PUT;
|
||||||
@@ -46,8 +47,12 @@ public class CodesApiResource {
|
|||||||
private PortfolioApiJsonSerializerService apiJsonSerializerService;
|
private PortfolioApiJsonSerializerService apiJsonSerializerService;
|
||||||
|
|
||||||
private final String entityType = "CODE";
|
private final String entityType = "CODE";
|
||||||
@Autowired
|
private final PlatformSecurityContext context;
|
||||||
private PlatformSecurityContext context;
|
|
||||||
|
@Autowired
|
||||||
|
public CodesApiResource(final PlatformSecurityContext context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Consumes({MediaType.APPLICATION_JSON})
|
@Consumes({MediaType.APPLICATION_JSON})
|
||||||
@@ -76,13 +81,41 @@ public class CodesApiResource {
|
|||||||
return Response.ok().entity(new EntityIdentifier(id)).build();
|
return Response.ok().entity(new EntityIdentifier(id)).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("{codeId}")
|
||||||
|
@Consumes({MediaType.APPLICATION_JSON})
|
||||||
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
|
public String retreiveOffice(@PathParam("codeId") final Long codeId, @Context final UriInfo uriInfo) {
|
||||||
|
|
||||||
|
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||||
|
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||||
|
|
||||||
|
final CodeData code = this.readPlatformService.retrieveCode(codeId);
|
||||||
|
|
||||||
|
return this.apiJsonSerializerService.serializeCodeDataToJson(prettyPrint, responseParameters, code);
|
||||||
|
}
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Path("{Id}")
|
@Path("{Id}")
|
||||||
@Consumes({MediaType.APPLICATION_JSON})
|
@Consumes({MediaType.APPLICATION_JSON})
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public Response updateCode(@PathParam("Id") final Long Id, final String jsonRequestBody) {
|
public Response updateCode(@PathParam("Id") final Long codeId, final String jsonRequestBody) {
|
||||||
|
|
||||||
|
final CodeCommand command = this.apiDataConversionService.convertJsonToCodeCommand(codeId, jsonRequestBody);
|
||||||
|
final Long entityId = this.writePlatformService.updateCode(command);
|
||||||
|
return Response.ok().entity(new EntityIdentifier(entityId)).build();
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DELETE
|
||||||
|
@Path("{codeId}")
|
||||||
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
|
public Response deleteCodeApplication(@PathParam("codeId") final Long Id) {
|
||||||
|
|
||||||
|
EntityIdentifier identifier = this.writePlatformService.deleteCode(Id);
|
||||||
|
|
||||||
|
return Response.ok().entity(identifier).build();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -27,7 +27,7 @@ public class CodeCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isNameChanged() {
|
public boolean isNameChanged() {
|
||||||
return this.modifiedParameters.contains("codename");
|
return this.modifiedParameters.contains("name");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -5,8 +5,12 @@ import javax.persistence.Entity;
|
|||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
import javax.persistence.UniqueConstraint;
|
import javax.persistence.UniqueConstraint;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.mifosng.platform.api.commands.CodeCommand;
|
||||||
|
|
||||||
import org.springframework.data.jpa.domain.AbstractPersistable;
|
import org.springframework.data.jpa.domain.AbstractPersistable;
|
||||||
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "m_code", uniqueConstraints = { @UniqueConstraint(columnNames = { "code_name" }, name = "code_name") })
|
@Table(name = "m_code", uniqueConstraints = { @UniqueConstraint(columnNames = { "code_name" }, name = "code_name") })
|
||||||
public class Code extends AbstractPersistable<Long> {
|
public class Code extends AbstractPersistable<Long> {
|
||||||
@@ -27,4 +31,11 @@ public class Code extends AbstractPersistable<Long> {
|
|||||||
this.codeName = codeName;
|
this.codeName = codeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void update(final CodeCommand command)
|
||||||
|
{
|
||||||
|
if (command.isNameChanged()) {
|
||||||
|
this.codeName = StringUtils.defaultIfEmpty(command.getCodeName(), null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+42
@@ -0,0 +1,42 @@
|
|||||||
|
package org.mifosng.platform.organisation.service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.mifosng.platform.DataValidatorBuilder;
|
||||||
|
import org.mifosng.platform.api.commands.CodeCommand;
|
||||||
|
import org.mifosng.platform.api.data.ApiParameterError;
|
||||||
|
import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
|
||||||
|
|
||||||
|
|
||||||
|
public class CodeCommandValidator
|
||||||
|
{
|
||||||
|
private final CodeCommand command;
|
||||||
|
|
||||||
|
public CodeCommandValidator(CodeCommand command)
|
||||||
|
{
|
||||||
|
this.command = command;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void validateForCreate()
|
||||||
|
{
|
||||||
|
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||||
|
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("code");
|
||||||
|
baseDataValidator.reset().parameter("codeName").value(command.getCodeName()).notBlank();
|
||||||
|
if (!dataValidationErrors.isEmpty()) {
|
||||||
|
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void validateForUpdate()
|
||||||
|
{
|
||||||
|
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||||
|
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("code");
|
||||||
|
baseDataValidator.reset().parameter("id").value(command.getId()).notNull();
|
||||||
|
baseDataValidator.reset().parameter("codeName").value(command.getCodeName()).ignoreIfNull().notBlank();
|
||||||
|
if (!dataValidationErrors.isEmpty()) {
|
||||||
|
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+4
@@ -1,6 +1,7 @@
|
|||||||
package org.mifosng.platform.organisation.service;
|
package org.mifosng.platform.organisation.service;
|
||||||
|
|
||||||
import org.mifosng.platform.api.commands.CodeCommand;
|
import org.mifosng.platform.api.commands.CodeCommand;
|
||||||
|
import org.mifosng.platform.api.data.EntityIdentifier;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
|
||||||
public interface CodeWritePlatformService {
|
public interface CodeWritePlatformService {
|
||||||
@@ -10,4 +11,7 @@ public interface CodeWritePlatformService {
|
|||||||
|
|
||||||
@PreAuthorize(value = "hasRole('ALL_FUNCTIONS', 'ORGANISATION_ADMINISTRATION_SUPER_USER', 'UPDATE_CODE)")
|
@PreAuthorize(value = "hasRole('ALL_FUNCTIONS', 'ORGANISATION_ADMINISTRATION_SUPER_USER', 'UPDATE_CODE)")
|
||||||
Long updateCode(final CodeCommand command);
|
Long updateCode(final CodeCommand command);
|
||||||
|
|
||||||
|
@PreAuthorize(value = "hasRole('ORGANISATION_ADMINISTRATION_SUPER_USER_ROLE')")
|
||||||
|
EntityIdentifier deleteCode(Long codeId);
|
||||||
}
|
}
|
||||||
+57
-7
@@ -1,10 +1,14 @@
|
|||||||
package org.mifosng.platform.organisation.service;
|
package org.mifosng.platform.organisation.service;
|
||||||
|
|
||||||
import org.mifosng.platform.api.commands.CodeCommand;
|
import org.mifosng.platform.api.commands.CodeCommand;
|
||||||
import org.mifosng.platform.api.commands.FundCommand;
|
import org.mifosng.platform.api.data.EntityIdentifier;
|
||||||
|
import org.mifosng.platform.exceptions.CodeValueNotFoundException;
|
||||||
|
import org.mifosng.platform.exceptions.PlatformDataIntegrityException;
|
||||||
import org.mifosng.platform.organisation.domain.Code;
|
import org.mifosng.platform.organisation.domain.Code;
|
||||||
import org.mifosng.platform.organisation.domain.CodeRepository;
|
import org.mifosng.platform.organisation.domain.CodeRepository;
|
||||||
import org.mifosng.platform.security.PlatformSecurityContext;
|
import org.mifosng.platform.security.PlatformSecurityContext;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.dao.DataIntegrityViolationException;
|
import org.springframework.dao.DataIntegrityViolationException;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -13,6 +17,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
@Service
|
@Service
|
||||||
public class CodeWritePlatformServiceJpaRepositoryImpl implements CodeWritePlatformService {
|
public class CodeWritePlatformServiceJpaRepositoryImpl implements CodeWritePlatformService {
|
||||||
|
|
||||||
|
private final static Logger logger = LoggerFactory.getLogger(CodeWritePlatformServiceJpaRepositoryImpl.class);
|
||||||
|
|
||||||
private final PlatformSecurityContext context;
|
private final PlatformSecurityContext context;
|
||||||
private final CodeRepository codeRepository;
|
private final CodeRepository codeRepository;
|
||||||
|
|
||||||
@@ -22,7 +28,6 @@ public class CodeWritePlatformServiceJpaRepositoryImpl implements CodeWritePlatf
|
|||||||
this.codeRepository = codeRepository;
|
this.codeRepository = codeRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public Long createCode(final CodeCommand command) {
|
public Long createCode(final CodeCommand command) {
|
||||||
@@ -30,6 +35,8 @@ public class CodeWritePlatformServiceJpaRepositoryImpl implements CodeWritePlatf
|
|||||||
try {
|
try {
|
||||||
context.authenticatedUser();
|
context.authenticatedUser();
|
||||||
|
|
||||||
|
CodeCommandValidator validator = new CodeCommandValidator(command);
|
||||||
|
validator.validateForCreate();
|
||||||
|
|
||||||
Code code = Code.createNew(command.getCodeName());
|
Code code = Code.createNew(command.getCodeName());
|
||||||
|
|
||||||
@@ -45,18 +52,61 @@ public class CodeWritePlatformServiceJpaRepositoryImpl implements CodeWritePlatf
|
|||||||
@Override
|
@Override
|
||||||
public Long updateCode(final CodeCommand command) {
|
public Long updateCode(final CodeCommand command) {
|
||||||
|
|
||||||
/**
|
try
|
||||||
* TODO - NATU -
|
{
|
||||||
**/
|
context.authenticatedUser();
|
||||||
|
|
||||||
|
CodeCommandValidator validator = new CodeCommandValidator(command);
|
||||||
|
validator.validateForUpdate();
|
||||||
|
|
||||||
|
final Long codeId = command.getId();
|
||||||
|
Code code = this.codeRepository.findOne(codeId);
|
||||||
|
if (code == null) {
|
||||||
|
throw new CodeValueNotFoundException(codeId);
|
||||||
|
}
|
||||||
|
code.update(command);
|
||||||
|
|
||||||
|
this.codeRepository.saveAndFlush(code);
|
||||||
|
|
||||||
|
return code.getId();
|
||||||
|
}
|
||||||
|
catch (DataIntegrityViolationException dve) {
|
||||||
|
handleCodeDataIntegrityIssues(command, dve);
|
||||||
|
return Long.valueOf(-1);
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Guaranteed to throw an exception no matter what the data integrity issue is.
|
* Guaranteed to throw an exception no matter what the data integrity issue is.
|
||||||
*/
|
*/
|
||||||
private void handleCodeDataIntegrityIssues(final FundCommand command, DataIntegrityViolationException dve) {
|
private void handleCodeDataIntegrityIssues(final CodeCommand command, final DataIntegrityViolationException dve) {
|
||||||
|
Throwable realCause = dve.getMostSpecificCause();
|
||||||
|
if (realCause.getMessage().contains("code_name_org")) {
|
||||||
|
throw new PlatformDataIntegrityException("error.msg.code.duplicate.name", "A code with name '" + command.getCodeName() + "' already exists");
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.error(dve.getMessage(), dve);
|
||||||
|
throw new PlatformDataIntegrityException("error.msg.cund.unknown.data.integrity.issue", "Unknown data integrity issue with resource: " + realCause.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
@Override
|
||||||
|
public EntityIdentifier deleteCode(final Long codeId) {
|
||||||
|
|
||||||
|
context.authenticatedUser();
|
||||||
|
|
||||||
|
retrieveCodeBy(codeId);
|
||||||
|
this.codeRepository.delete(codeId);
|
||||||
|
|
||||||
|
return new EntityIdentifier(codeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Code retrieveCodeBy(final Long codeId) {
|
||||||
|
final Code code = this.codeRepository.findOne(codeId);
|
||||||
|
if (code == null) {
|
||||||
|
throw new CodeValueNotFoundException(codeId);
|
||||||
|
}
|
||||||
|
return code;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
MSYS-1.0.12 Build:2011-07-20 17:52
|
||||||
|
Exception: STATUS_ACCESS_VIOLATION at eip=68085E34
|
||||||
|
eax=68560000 ebx=00005D7C ecx=0000175F edx=00000000 esi=00000000 edi=68560000
|
||||||
|
ebp=0023FE80 esp=0023FE74 program=us
|
||||||
|
cs=001B ds=0023 es=0023 fs=003B gs=0000 ss=0023
|
||||||
|
Stack trace:
|
||||||
|
Frame Function Args
|
||||||
|
0023FE80 68085E34 (68560000, 00000000, 00005D7C, 00000004)
|
||||||
|
0023FED0 68001CB0 (00020C58, 00000001, 0023FF20, 680044EA)
|
||||||
|
0023FF20 680045C7 (8600D670, FFDFF538, 0023FF60, 00405F80)
|
||||||
|
0023FF40 68004C5F (00402318, 00000000, 804FA14C, 0000D670)
|
||||||
|
0023FF60 68004C98 (00000000, 00000000, A78A3C6C, 00000000)
|
||||||
|
0023FF90 00405E90 (00402318, 00000000, 00000001, 00000006)
|
||||||
|
0023FFC0 0040103D (00000000, 00000000, 7FFDE000, 8054A6ED)
|
||||||
|
0023FFF0 7C816FE7 (00401000, 00000000, 78746341, 00000020)
|
||||||
|
End of stack trace
|
||||||
Reference in New Issue
Block a user