MIFOSX-97: move package structure movement and support for command approach.

This commit is contained in:
Keith Woodlock
2012-12-01 14:12:40 +00:00
parent 38ee5d130d
commit 9f65ff3cbd
397 changed files with 3300 additions and 3183 deletions
@@ -1,305 +0,0 @@
package org.mifosng.platform;
import java.math.BigDecimal;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.mifosng.platform.api.data.ApiParameterError;
import org.springframework.util.ObjectUtils;
public class DataValidatorBuilder {
private final List<ApiParameterError> dataValidationErrors;
private String resource;
private String parameter;
private Object value;
private boolean ignoreNullValue = false;
public DataValidatorBuilder(List<ApiParameterError> dataValidationErrors) {
this.dataValidationErrors = dataValidationErrors;
}
public DataValidatorBuilder reset() {
return new DataValidatorBuilder(dataValidationErrors).resource(resource);
}
public DataValidatorBuilder resource(final String resource) {
this.resource = resource;
return this;
}
public DataValidatorBuilder parameter(final String parameter) {
this.parameter = parameter;
return this;
}
public DataValidatorBuilder value(Object value) {
this.value = value;
return this;
}
public DataValidatorBuilder ignoreIfNull() {
this.ignoreNullValue = true;
return this;
}
public DataValidatorBuilder andNotBlank(String linkedParameterName, String linkedValue) {
if (value == null && linkedValue == null && ignoreNullValue) {
return this;
}
if (StringUtils.isBlank(linkedValue)) {
StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(resource).append(".").append(linkedParameterName).append(".cannot.be.empty.when.").append(parameter).append(".is.populated");
StringBuilder defaultEnglishMessage = new StringBuilder("The parameter ").append(linkedParameterName).append(" cannot be empty when ").append(parameter).append(" is populated.");
ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage.toString(), linkedParameterName, linkedValue, value);
dataValidationErrors.add(error);
}
return this;
}
public DataValidatorBuilder equalToParameter(String linkedParameterName, Object linkedValue) {
if (value == null && linkedValue == null && ignoreNullValue) {
return this;
}
if (value != null && !value.equals(linkedValue)) {
StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(resource).append(".").append(linkedParameterName).append(".not.equal.to.").append(parameter);
StringBuilder defaultEnglishMessage = new StringBuilder("The parameter ").append(linkedParameterName).append(" is not equal to ").append(parameter).append(".");
ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage.toString(), linkedParameterName, linkedValue, value);
dataValidationErrors.add(error);
}
return this;
}
public DataValidatorBuilder notSameAsParameter(String linkedParameterName, Object linkedValue) {
if (value == null && linkedValue == null && ignoreNullValue) {
return this;
}
if (value != null && value.equals(linkedValue)) {
StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(resource).append(".").append(linkedParameterName).append(".same.as.").append(parameter);
StringBuilder defaultEnglishMessage = new StringBuilder("The parameter ").append(linkedParameterName).append(" is same as ").append(parameter).append(".");
ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage.toString(), linkedParameterName, linkedValue, value);
dataValidationErrors.add(error);
}
return this;
}
public DataValidatorBuilder trueOrFalseRequired(boolean trueOfFalseFieldProvided) {
if (!trueOfFalseFieldProvided && !ignoreNullValue) {
StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(resource).append(".").append(parameter).append(".must.be.true.or.false");
StringBuilder defaultEnglishMessage = new StringBuilder("The parameter ").append(parameter).append(" must be set as true or false.");
ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage.toString(), parameter);
dataValidationErrors.add(error);
}
return this;
}
public DataValidatorBuilder notNull() {
if (value == null && !ignoreNullValue) {
StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(resource).append(".").append(parameter).append(".cannot.be.blank");
StringBuilder defaultEnglishMessage = new StringBuilder("The parameter ").append(parameter).append(" cannot be blank.");
ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage.toString(), parameter);
dataValidationErrors.add(error);
}
return this;
}
public DataValidatorBuilder notBlank() {
if (value == null && ignoreNullValue) {
return this;
}
if (value == null || StringUtils.isBlank(value.toString())) {
StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(resource).append(".").append(parameter).append(".cannot.be.blank");
StringBuilder defaultEnglishMessage = new StringBuilder("The parameter ").append(parameter).append(" cannot be blank.");
ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage.toString(), parameter);
dataValidationErrors.add(error);
}
return this;
}
public DataValidatorBuilder notExceedingLengthOf(Integer maxLength) {
if (value == null && ignoreNullValue) {
return this;
}
if (value != null && value.toString().trim().length() > maxLength) {
StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(resource).append(".").append(parameter).append(".exceeds.max.length");
StringBuilder defaultEnglishMessage = new StringBuilder("The parameter ").append(parameter).append(" exceeds max length of ").append(maxLength).append(".");
ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage.toString(), parameter, maxLength, value.toString());
dataValidationErrors.add(error);
}
return this;
}
public DataValidatorBuilder inMinMaxRange(Integer min, Integer max) {
if (value == null && ignoreNullValue) {
return this;
}
if (value != null) {
Integer number = Integer.valueOf(value.toString());
if (number < min || number > max) {
StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(resource).append(".").append(parameter).append(".is.not.within.expected.range");
StringBuilder defaultEnglishMessage = new StringBuilder("The parameter ").append(parameter).append(" must be between ").append(min).append(" and ").append(max).append(".");
ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage.toString(), parameter, number, min, max);
dataValidationErrors.add(error);
}
}
return this;
}
public DataValidatorBuilder positiveAmount() {
if (value == null && ignoreNullValue) {
return this;
}
if (value != null) {
BigDecimal number = BigDecimal.valueOf(Double.valueOf(value.toString()));
if (number.compareTo(BigDecimal.ZERO) <= 0) {
StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(resource).append(".").append(parameter).append(".not.greater.than.zero");
StringBuilder defaultEnglishMessage = new StringBuilder("The parameter ").append(parameter).append(" must be greater than 0.");
ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage.toString(), parameter, number, 0);
dataValidationErrors.add(error);
}
}
return this;
}
public DataValidatorBuilder zeroOrPositiveAmount() {
if (value == null && ignoreNullValue) {
return this;
}
if (value != null) {
BigDecimal number = BigDecimal.valueOf(Double.valueOf(value.toString()));
if (number.compareTo(BigDecimal.ZERO) < 0) {
StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(resource).append(".").append(parameter).append(".not.zero.or.greater");
StringBuilder defaultEnglishMessage = new StringBuilder("The parameter ").append(parameter).append(" must be greater than or equal to 0.");
ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage.toString(), parameter, number, 0);
dataValidationErrors.add(error);
}
}
return this;
}
public DataValidatorBuilder integerGreaterThanZero() {
if (value == null && ignoreNullValue) {
return this;
}
if (value != null) {
Integer number = Integer.valueOf(value.toString());
if (number < 1) {
StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(resource).append(".").append(parameter).append(".not.greater.than.zero");
StringBuilder defaultEnglishMessage = new StringBuilder("The parameter ").append(parameter).append(" must be greater than 0.");
ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage.toString(), parameter, number, 0);
dataValidationErrors.add(error);
}
}
return this;
}
public DataValidatorBuilder longGreaterThanZero() {
if (value == null && ignoreNullValue) {
return this;
}
if (value != null) {
Long number = Long.valueOf(value.toString());
if (number < 1) {
StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(resource).append(".").append(parameter).append(".not.greater.than.zero");
StringBuilder defaultEnglishMessage = new StringBuilder("The parameter ").append(parameter).append(" must be greater than 0.");
ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage.toString(), parameter, number, 0);
dataValidationErrors.add(error);
}
}
return this;
}
public DataValidatorBuilder arrayNotEmpty() {
if (value == null && ignoreNullValue) {
return this;
}
Object[] array = (Object[]) value;
if (ObjectUtils.isEmpty(array)) {
StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(resource).append(".").append(parameter).append(".cannot.be.empty");
StringBuilder defaultEnglishMessage = new StringBuilder("The parameter ").append(parameter).append(" cannot be empty. You must select at least one.");
ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage.toString(), parameter);
dataValidationErrors.add(error);
}
return this;
}
public DataValidatorBuilder anyOfNotNull(Object... object) {
boolean hasData = false;
for (Object obj : object) {
if (obj != null) {
hasData = true;
break;
}
}
if (!hasData) {
StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(resource).append(".no.parameters.for.update");
StringBuilder defaultEnglishMessage = new StringBuilder("No parameters passed for update.");
ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage.toString(), "id");
dataValidationErrors.add(error);
}
return this;
}
public DataValidatorBuilder inValidValue(String parameterValueCode, Object invalidValue) {
StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(resource).append(".").append(parameter).append(".invalid.").append(parameterValueCode);
StringBuilder defaultEnglishMessage = new StringBuilder("The parameter ").append(parameter).append(" has an invalid value.");
ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage.toString(), parameter, invalidValue);
dataValidationErrors.add(error);
return this;
}
public DataValidatorBuilder mustBeBlankWhenParameterProvided(String parameterName, Object parameterValue) {
if (value == null && ignoreNullValue) {
return this;
}
if (value == null && parameterValue != null) {
return this;
}
if (value != null && StringUtils.isBlank(value.toString()) && parameterValue != null && StringUtils.isNotBlank(parameterValue.toString())) {
return this;
}
StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(resource).append(".").append(parameter).append(".cannot.also.be.provided.when.").append(parameterName).append(".is.populated");
StringBuilder defaultEnglishMessage = new StringBuilder("The parameter ").append(parameter).append(" cannot also be provided when ").append(parameterName).append(" is populated.");
ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage.toString(), parameter, value, parameterName, parameterValue);
dataValidationErrors.add(error);
return this;
}
public DataValidatorBuilder comapareMinimumAndMaximumAmounts(BigDecimal minimumBalance,BigDecimal maximumBalance){
if(minimumBalance!=null&&maximumBalance!=null)
if(maximumBalance.compareTo(minimumBalance)==-1){
StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(resource).append(".").append(parameter).append(".is.not.within.expected.range");
StringBuilder defaultEnglishMessage = new StringBuilder("The parameter ").append(" minimum amount ").append(minimumBalance).append(" should less than maximum amount ").append(maximumBalance).append(".");
ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage.toString(), parameter, minimumBalance, maximumBalance);
dataValidationErrors.add(error);
return this;
}
return this;
}
public DataValidatorBuilder comapareMinAndMaxOfTwoBigDecmimalNos(BigDecimal min,BigDecimal max){
if(min!=null&&max!=null)
if(max.compareTo(min)==-1){
StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(resource).append(".").append(parameter).append(".is.not.within.expected.range");
StringBuilder defaultEnglishMessage = new StringBuilder("The ").append(" min number ").append(min).append(" should less than max number ").append(max).append(".");
ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage.toString(), parameter, min, max);
dataValidationErrors.add(error);
return this;
}
return this;
}
}
@@ -1,17 +0,0 @@
package org.mifosng.platform;
import java.sql.SQLException;
public class InvalidSqlException extends RuntimeException {
private final String sql;
public InvalidSqlException(SQLException e, String sql) {
super(e);
this.sql = sql;
}
public String getSql() {
return sql;
}
}
@@ -1,191 +0,0 @@
package org.mifosng.platform.api;
import java.util.Collection;
import java.util.Set;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import org.mifosng.platform.api.commands.ClientIdentifierCommand;
import org.mifosng.platform.api.data.ClientData;
import org.mifosng.platform.api.data.ClientIdentifierData;
import org.mifosng.platform.api.data.EntityIdentifier;
import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService;
import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService;
import org.mifosng.platform.client.service.ClientReadPlatformService;
import org.mifosng.platform.client.service.ClientWritePlatformService;
import org.mifosng.platform.exceptions.DuplicateClientIdentifierException;
import org.mifosng.platform.infrastructure.api.ApiParameterHelper;
import org.mifosplatform.infrastructure.codes.data.CodeValueData;
import org.mifosplatform.infrastructure.codes.service.CodeValueReadPlatformService;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
@Path("/clients/{clientId}/identifiers")
@Component
@Scope("singleton")
public class ClientIdentifiersApiResource {
@Autowired
private ClientReadPlatformService clientReadPlatformService;
@Autowired
private CodeValueReadPlatformService codeValueReadPlatformService;
@Autowired
private ClientWritePlatformService clientWritePlatformService;
@Autowired
private PortfolioApiDataConversionService apiDataConversionService;
@Autowired
private PortfolioApiJsonSerializerService apiJsonSerializerService;
@Autowired
private PlatformSecurityContext context;
private final String entityType = "CLIENTIDENTIFIER";
@GET
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveAllClientIdentifiers(
@Context final UriInfo uriInfo,
@PathParam("clientId") final Long clientId) {
context.authenticatedUser().validateHasReadPermission(entityType);
final Set<String> responseParameters = ApiParameterHelper
.extractFieldsForResponseIfProvided(uriInfo
.getQueryParameters());
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
final Collection<ClientIdentifierData> clientIdentifiers = this.clientReadPlatformService.retrieveClientIdentifiers(clientId);
return this.apiJsonSerializerService
.serializeClientIdentifierDataToJson(prettyPrint,
responseParameters, clientIdentifiers);
}
@GET
@Path("template")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String newClientDetails(@Context final UriInfo uriInfo) {
context.authenticatedUser().validateHasReadPermission(entityType);
final Set<String> responseParameters = ApiParameterHelper
.extractFieldsForResponseIfProvided(uriInfo
.getQueryParameters());
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
Collection<CodeValueData> codeValues = codeValueReadPlatformService.retrieveCustomIdentifierCodeValues();
ClientIdentifierData clientIdentifierData = ClientIdentifierData.template(codeValues);
return this.apiJsonSerializerService
.serializeClientIdentifierDataToJson(prettyPrint,
responseParameters, clientIdentifierData);
}
@POST
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public Response createClientIdentifier(
@PathParam("clientId") final Long clientId,
final String jsonRequestBody) {
try {
final ClientIdentifierCommand command = this.apiDataConversionService.convertJsonToClientIdentifierCommand(null, clientId, jsonRequestBody);
Long clientIdentifierId = this.clientWritePlatformService.addClientIdentifier(command);
return Response.ok().entity(new EntityIdentifier(clientIdentifierId)).build();
}
catch (DuplicateClientIdentifierException e) {
DuplicateClientIdentifierException rethrowas = e;
if (e.getDocumentTypeId() != null) {
// need to fetch client info
ClientData clientInfo = this.clientReadPlatformService.retrieveClientByIdentifier(e.getDocumentTypeId(), e.getIdentifierKey());
rethrowas = new DuplicateClientIdentifierException(clientInfo.displayName(), clientInfo.officeName(), e.getIdentifierType(), e.getIdentifierKey());
}
throw rethrowas;
}
}
@GET
@Path("{identifierId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String getClientIdentifier(
@PathParam("clientId") final Long clientId,
@PathParam("identifierId") final Long clientIdentifierId,
@Context final UriInfo uriInfo) {
context.authenticatedUser().validateHasReadPermission(entityType);
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
final boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters());
ClientIdentifierData clientIdentifierData = this.clientReadPlatformService.retrieveClientIdentifier(clientId, clientIdentifierId);
if (template) {
final Collection<CodeValueData> codeValues = codeValueReadPlatformService.retrieveCustomIdentifierCodeValues();
clientIdentifierData = ClientIdentifierData.template(clientIdentifierData, codeValues);
}
return this.apiJsonSerializerService
.serializeClientIdentifierDataToJson(prettyPrint,
responseParameters, clientIdentifierData);
}
@PUT
@Path("{identifierId}")
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
public Response updateClientIdentifer(
@PathParam("clientId") final Long clientId,
@PathParam("identifierId") final Long clientIdentifierId,
final String jsonRequestBody) {
try {
final ClientIdentifierCommand command = this.apiDataConversionService.convertJsonToClientIdentifierCommand(clientIdentifierId, clientId, jsonRequestBody);
final EntityIdentifier identifier = this.clientWritePlatformService.updateClientIdentifier(command);
return Response.ok().entity(identifier).build();
}
catch (DuplicateClientIdentifierException e) {
DuplicateClientIdentifierException reThrowAs = e;
if (e.getDocumentTypeId() != null) {
ClientData clientInfo = this.clientReadPlatformService.retrieveClientByIdentifier(e.getDocumentTypeId(), e.getIdentifierKey());
reThrowAs = new DuplicateClientIdentifierException(clientInfo.displayName(), clientInfo.officeName(), e.getIdentifierType(), e.getIdentifierKey());
}
throw reThrowAs;
}
}
@DELETE
@Path("{identifierId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public Response deleteClientIdentifier(
@PathParam("identifierId") final Long clientIdentifierId) {
this.clientWritePlatformService.deleteClientIdentifier(clientIdentifierId);
return Response.ok(new EntityIdentifier(clientIdentifierId)).build();
}
}
@@ -30,16 +30,16 @@ import org.mifosng.platform.api.commands.UndoStateTransitionCommand;
import org.mifosng.platform.api.data.DepositAccountData;
import org.mifosng.platform.api.data.DepositPermissionData;
import org.mifosng.platform.api.data.DepositProductLookup;
import org.mifosng.platform.api.data.EntityIdentifier;
import org.mifosng.platform.api.data.EnumOptionData;
import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService;
import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService;
import org.mifosng.platform.exceptions.UnrecognizedQueryParamException;
import org.mifosng.platform.infrastructure.api.ApiParameterHelper;
import org.mifosng.platform.saving.service.DepositAccountReadPlatformService;
import org.mifosng.platform.saving.service.DepositAccountWritePlatformService;
import org.mifosng.platform.savingproduct.service.DepositProductReadPlatformService;
import org.mifosng.platform.savingproduct.service.SavingsDepositEnumerations;
import org.mifosplatform.infrastructure.core.api.ApiParameterHelper;
import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService;
import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerService;
import org.mifosplatform.infrastructure.core.data.EntityIdentifier;
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
import org.mifosplatform.infrastructure.core.exception.UnrecognizedQueryParamException;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.portfolio.loanproduct.domain.PeriodFrequencyType;
import org.springframework.beans.factory.annotation.Autowired;
@@ -21,16 +21,16 @@ import javax.ws.rs.core.UriInfo;
import org.mifosng.platform.api.commands.DepositProductCommand;
import org.mifosng.platform.api.data.DepositProductData;
import org.mifosng.platform.api.data.EntityIdentifier;
import org.mifosng.platform.api.data.EnumOptionData;
import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService;
import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService;
import org.mifosng.platform.infrastructure.api.ApiParameterHelper;
import org.mifosng.platform.savingproduct.service.DepositProductReadPlatformService;
import org.mifosng.platform.savingproduct.service.DepositProductWritePlatformService;
import org.mifosng.platform.savingproduct.service.SavingsDepositEnumerations;
import org.mifosplatform.infrastructure.configuration.data.CurrencyData;
import org.mifosplatform.infrastructure.configuration.service.CurrencyReadPlatformService;
import org.mifosplatform.infrastructure.core.api.ApiParameterHelper;
import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService;
import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerService;
import org.mifosplatform.infrastructure.core.data.EntityIdentifier;
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.portfolio.loanproduct.domain.PeriodFrequencyType;
import org.springframework.beans.factory.annotation.Autowired;
@@ -24,13 +24,13 @@ import javax.ws.rs.core.UriInfo;
import org.mifosng.platform.api.commands.DocumentCommand;
import org.mifosng.platform.api.data.DocumentData;
import org.mifosng.platform.api.data.EntityIdentifier;
import org.mifosng.platform.api.infrastructure.ApiConstants;
import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService;
import org.mifosng.platform.documentmanagement.service.DocumentReadPlatformService;
import org.mifosng.platform.documentmanagement.service.DocumentWritePlatformService;
import org.mifosng.platform.infrastructure.FileUtils;
import org.mifosng.platform.infrastructure.api.ApiParameterHelper;
import org.mifosplatform.infrastructure.core.api.ApiConstants;
import org.mifosplatform.infrastructure.core.api.ApiParameterHelper;
import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerService;
import org.mifosplatform.infrastructure.core.data.EntityIdentifier;
import org.mifosplatform.infrastructure.core.service.FileUtils;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
@@ -21,19 +21,19 @@ import javax.ws.rs.core.UriInfo;
import org.apache.commons.lang.StringUtils;
import org.mifosng.platform.api.commands.GroupCommand;
import org.mifosng.platform.api.data.ClientLookup;
import org.mifosng.platform.api.data.EntityIdentifier;
import org.mifosng.platform.api.data.GroupAccountSummaryCollectionData;
import org.mifosng.platform.api.data.GroupData;
import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService;
import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService;
import org.mifosng.platform.client.service.ClientReadPlatformService;
import org.mifosng.platform.group.service.GroupReadPlatformService;
import org.mifosng.platform.group.service.GroupWritePlatformService;
import org.mifosng.platform.infrastructure.api.ApiParameterHelper;
import org.mifosplatform.infrastructure.core.api.ApiParameterHelper;
import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService;
import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerService;
import org.mifosplatform.infrastructure.core.data.EntityIdentifier;
import org.mifosplatform.infrastructure.office.data.OfficeLookup;
import org.mifosplatform.infrastructure.office.service.OfficeReadPlatformService;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.portfolio.client.data.ClientLookup;
import org.mifosplatform.portfolio.client.service.ClientReadPlatformService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -18,13 +18,13 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import org.mifosng.platform.api.commands.GuarantorCommand;
import org.mifosng.platform.api.data.EntityIdentifier;
import org.mifosng.platform.api.data.GuarantorData;
import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService;
import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService;
import org.mifosng.platform.guarantor.GuarantorReadPlatformService;
import org.mifosng.platform.guarantor.GuarantorWritePlatformService;
import org.mifosng.platform.infrastructure.api.ApiParameterHelper;
import org.mifosplatform.infrastructure.core.api.ApiParameterHelper;
import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService;
import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerService;
import org.mifosplatform.infrastructure.core.data.EntityIdentifier;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
@@ -28,8 +28,6 @@ import org.mifosng.platform.api.commands.LoanStateTransitionCommand;
import org.mifosng.platform.api.commands.LoanTransactionCommand;
import org.mifosng.platform.api.commands.UndoStateTransitionCommand;
import org.mifosng.platform.api.data.DisbursementData;
import org.mifosng.platform.api.data.EntityIdentifier;
import org.mifosng.platform.api.data.EnumOptionData;
import org.mifosng.platform.api.data.GuarantorData;
import org.mifosng.platform.api.data.LoanAccountData;
import org.mifosng.platform.api.data.LoanBasicDetailsData;
@@ -37,22 +35,24 @@ import org.mifosng.platform.api.data.LoanChargeData;
import org.mifosng.platform.api.data.LoanPermissionData;
import org.mifosng.platform.api.data.LoanScheduleData;
import org.mifosng.platform.api.data.LoanTransactionData;
import org.mifosng.platform.api.data.StaffAccountSummaryCollectionData;
import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService;
import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService;
import org.mifosng.platform.exceptions.UnrecognizedQueryParamException;
import org.mifosng.platform.guarantor.GuarantorReadPlatformService;
import org.mifosng.platform.infrastructure.api.ApiParameterHelper;
import org.mifosng.platform.loan.service.CalculationPlatformService;
import org.mifosng.platform.loan.service.LoanReadPlatformService;
import org.mifosng.platform.loan.service.LoanWritePlatformService;
import org.mifosplatform.infrastructure.configuration.domain.MonetaryCurrency;
import org.mifosplatform.infrastructure.configuration.domain.Money;
import org.mifosplatform.infrastructure.core.api.ApiParameterHelper;
import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService;
import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerService;
import org.mifosplatform.infrastructure.core.data.EntityIdentifier;
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
import org.mifosplatform.infrastructure.core.exception.UnrecognizedQueryParamException;
import org.mifosplatform.infrastructure.office.data.OfficeLookup;
import org.mifosplatform.infrastructure.office.service.OfficeReadPlatformService;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.infrastructure.staff.command.BulkTransferLoanOfficerCommand;
import org.mifosplatform.infrastructure.staff.data.BulkTransferLoanOfficerData;
import org.mifosplatform.infrastructure.staff.data.StaffAccountSummaryCollectionData;
import org.mifosplatform.infrastructure.staff.data.StaffData;
import org.mifosplatform.infrastructure.staff.service.StaffReadPlatformService;
import org.mifosplatform.portfolio.charge.data.ChargeData;
@@ -20,12 +20,7 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import org.mifosng.platform.api.commands.SavingProductCommand;
import org.mifosng.platform.api.data.EntityIdentifier;
import org.mifosng.platform.api.data.EnumOptionData;
import org.mifosng.platform.api.data.SavingProductData;
import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService;
import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService;
import org.mifosng.platform.infrastructure.api.ApiParameterHelper;
import org.mifosng.platform.savingproduct.domain.SavingFrequencyType;
import org.mifosng.platform.savingproduct.domain.SavingInterestCalculationMethod;
import org.mifosng.platform.savingproduct.domain.SavingProductType;
@@ -37,6 +32,11 @@ import org.mifosng.platform.savingproduct.service.SavingProductReadPlatformServi
import org.mifosng.platform.savingproduct.service.SavingProductWritePlatformService;
import org.mifosplatform.infrastructure.configuration.data.CurrencyData;
import org.mifosplatform.infrastructure.configuration.service.CurrencyReadPlatformService;
import org.mifosplatform.infrastructure.core.api.ApiParameterHelper;
import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService;
import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerService;
import org.mifosplatform.infrastructure.core.data.EntityIdentifier;
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
@@ -19,13 +19,13 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import org.mifosng.platform.api.commands.SavingAccountCommand;
import org.mifosng.platform.api.data.EntityIdentifier;
import org.mifosng.platform.api.data.SavingAccountData;
import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService;
import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService;
import org.mifosng.platform.infrastructure.api.ApiParameterHelper;
import org.mifosng.platform.saving.service.SavingAccountReadPlatformService;
import org.mifosng.platform.saving.service.SavingAccountWritePlatformService;
import org.mifosplatform.infrastructure.core.api.ApiParameterHelper;
import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService;
import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerService;
import org.mifosplatform.infrastructure.core.data.EntityIdentifier;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
@@ -1,66 +0,0 @@
package org.mifosng.platform.api.commands;
import java.util.Set;
/**
* Immutable command for creating or updating details of a client identifier.
*/
public class ClientIdentifierCommand {
private final Long id;
private final Long clientId;
private final Long documentTypeId;
private final String documentKey;
private final String description;
private final Set<String> modifiedParameters;
public ClientIdentifierCommand(final Set<String> modifiedParameters,
final Long id, final Long clientId, final Long documentTypeId,
final String documentKey, final String description) {
this.modifiedParameters = modifiedParameters;
this.id = id;
this.clientId = clientId;
this.documentTypeId = documentTypeId;
this.documentKey = documentKey;
this.description = description;
}
public Long getId() {
return id;
}
public Long getDocumentTypeId() {
return documentTypeId;
}
public String getDocumentKey() {
return documentKey;
}
public String getDescription() {
return description;
}
public Set<String> getModifiedParameters() {
return modifiedParameters;
}
public Long getClientId() {
return clientId;
}
public boolean isDocumentTypeChanged() {
return this.modifiedParameters.contains("documentTypeId");
}
public boolean isDocumentKeyChanged() {
return this.modifiedParameters.contains("documentKey");
}
public boolean isDescriptionChanged() {
return this.modifiedParameters.contains("description");
}
}
@@ -1,41 +0,0 @@
package org.mifosng.platform.api.commands;
/**
* Immutable command used for create or update of notes.
*/
public class NoteCommand {
private final Long id;
private final Long clientId;
private final Long loanId;
private final Long loanTransactionId;
private final String note;
public NoteCommand(final Long id, Long clientId, final String note) {
this.id = id;
this.clientId = clientId;
this.loanId = null;
this.loanTransactionId = null;
this.note = note;
}
public Long getId() {
return id;
}
public Long getClientId() {
return clientId;
}
public Long getLoanId() {
return loanId;
}
public Long getLoanTransactionId() {
return loanTransactionId;
}
public String getNote() {
return note;
}
}
@@ -1,46 +0,0 @@
package org.mifosng.platform.api.data;
/**
* Immutable data object for client loan accounts.
*/
public class ClientAccountSummaryData {
private final Long id;
private final String externalId;
private final Long productId;
private final String productName;
private final Integer accountStatusId;
public ClientAccountSummaryData(
final Long id,
final String externalId,
final Long productId,
final String loanProductName,
final Integer loanStatusId) {
this.id = id;
this.externalId = externalId;
this.productId = productId;
this.productName = loanProductName;
this.accountStatusId = loanStatusId;
}
public Long getId() {
return id;
}
public String getExternalId() {
return externalId;
}
public Long getProductId() {
return productId;
}
public String getProductName() {
return productName;
}
public Integer getAccountStatusId() {
return accountStatusId;
}
}
@@ -1,57 +0,0 @@
package org.mifosng.platform.api.data;
import java.util.Collection;
import org.mifosplatform.infrastructure.codes.data.CodeValueData;
/**
* Immutable data object represent client identity data.
*/
public class ClientIdentifierData {
private final Long id;
private final Long clientId;
private final Long documentTypeId;
private final String documentTypeName;
private final String documentKey;
private final String description;
@SuppressWarnings("unused")
private final Collection<CodeValueData> allowedDocumentTypes;
public static ClientIdentifierData singleItem(
final Long id,
final Long clientId,
final Long documentTypeId,
final String documentKey,
final String description,
final String documentTypeName) {
return new ClientIdentifierData(id, clientId, documentTypeId, documentKey, description, documentTypeName, null);
}
public static ClientIdentifierData template(final Collection<CodeValueData> codeValues) {
return new ClientIdentifierData(null, null, null, null, null, null, codeValues);
}
public static ClientIdentifierData template(
final ClientIdentifierData data,
final Collection<CodeValueData> codeValues) {
return new ClientIdentifierData(data.id, data.clientId, data.documentTypeId, data.documentKey, data.description, data.documentTypeName, codeValues);
}
public ClientIdentifierData(
final Long id,
final Long clientId,
final Long documentTypeId,
final String documentKey,
final String description,
final String documentTypeName,
final Collection<CodeValueData> allowedDocumentTypes) {
this.id = id;
this.clientId = clientId;
this.documentTypeId = documentTypeId;
this.documentKey = documentKey;
this.description = description;
this.documentTypeName = documentTypeName;
this.allowedDocumentTypes = allowedDocumentTypes;
}
}
@@ -11,6 +11,7 @@ import org.joda.time.Days;
import org.joda.time.LocalDate;
import org.joda.time.Months;
import org.mifosplatform.infrastructure.configuration.data.CurrencyData;
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
/**
* Immutable data object for deposit accounts.
@@ -3,6 +3,7 @@ package org.mifosng.platform.api.data;
import java.math.BigDecimal;
import org.joda.time.LocalDate;
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
/**
* Immutable data object to represent transactions on a deposit account.
@@ -6,6 +6,7 @@ import java.util.List;
import org.joda.time.DateTime;
import org.mifosplatform.infrastructure.configuration.data.CurrencyData;
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
/**
* Immutable data object representing details of a deposit product.
@@ -3,6 +3,7 @@ package org.mifosng.platform.api.data;
import java.util.Collection;
import org.mifosplatform.infrastructure.office.data.OfficeLookup;
import org.mifosplatform.portfolio.client.data.ClientLookup;
/**
* Immutable data object representing groups.
@@ -5,6 +5,7 @@ import java.util.Collection;
import org.joda.time.LocalDate;
import org.mifosplatform.infrastructure.configuration.data.CurrencyData;
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
import org.mifosplatform.infrastructure.staff.data.StaffData;
import org.mifosplatform.portfolio.charge.data.ChargeData;
import org.mifosplatform.portfolio.fund.data.FundData;
@@ -9,6 +9,7 @@ import org.joda.time.Days;
import org.joda.time.LocalDate;
import org.joda.time.Months;
import org.mifosplatform.infrastructure.configuration.data.CurrencyData;
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
import org.mifosplatform.portfolio.charge.data.ChargeData;
import org.mifosplatform.portfolio.loanproduct.data.LoanProductData;
@@ -5,6 +5,7 @@ import java.util.Collection;
import org.joda.time.LocalDate;
import org.mifosplatform.infrastructure.configuration.data.CurrencyData;
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
import org.mifosplatform.portfolio.charge.data.ChargeData;
/**
@@ -4,6 +4,7 @@ import java.math.BigDecimal;
import org.joda.time.LocalDate;
import org.mifosplatform.infrastructure.configuration.data.CurrencyData;
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
/**
* Immutable data object representing a loan transaction.
@@ -1,139 +0,0 @@
package org.mifosng.platform.api.data;
import org.joda.time.DateTime;
public class NoteData {
private Long id;
private Long clientId;
private Long loanId;
private Long loanTransactionId;
private EnumOptionData noteType;
private String note;
private Long createdById;
private String createdByUsername;
private DateTime createdOn;
private Long updatedById;
private String updatedByUsername;
private DateTime updatedOn;
public NoteData() {
//
}
public NoteData(Long id, Long clientId, Long loanId,
Long transactionId, EnumOptionData noteType, String note,
DateTime createdDate, Long createdById, String createdByUsername,
DateTime lastModifiedDate, Long lastModifiedById, String updatedByUsername) {
this.id = id;
this.clientId = clientId;
this.loanId = loanId;
this.loanTransactionId = transactionId;
this.noteType = noteType;
this.note = note;
this.createdOn = createdDate;
this.createdById = createdById;
this.createdByUsername = createdByUsername;
this.updatedOn = lastModifiedDate;
this.updatedById = lastModifiedById;
this.updatedByUsername = updatedByUsername;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getClientId() {
return clientId;
}
public void setClientId(Long clientId) {
this.clientId = clientId;
}
public Long getLoanId() {
return loanId;
}
public void setLoanId(Long loanId) {
this.loanId = loanId;
}
public Long getLoanTransactionId() {
return loanTransactionId;
}
public void setLoanTransactionId(Long loanTransactionId) {
this.loanTransactionId = loanTransactionId;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
public Long getCreatedById() {
return createdById;
}
public void setCreatedById(Long createdById) {
this.createdById = createdById;
}
public String getCreatedByUsername() {
return createdByUsername;
}
public void setCreatedByUsername(String createdByUsername) {
this.createdByUsername = createdByUsername;
}
public DateTime getCreatedOn() {
return createdOn;
}
public void setCreatedOn(DateTime createdOn) {
this.createdOn = createdOn;
}
public Long getUpdatedById() {
return updatedById;
}
public void setUpdatedById(Long updatedById) {
this.updatedById = updatedById;
}
public String getUpdatedByUsername() {
return updatedByUsername;
}
public void setUpdatedByUsername(String updatedByUsername) {
this.updatedByUsername = updatedByUsername;
}
public DateTime getUpdatedOn() {
return updatedOn;
}
public void setUpdatedOn(DateTime updatedOn) {
this.updatedOn = updatedOn;
}
public EnumOptionData getNoteType() {
return noteType;
}
public void setNoteType(EnumOptionData noteType) {
this.noteType = noteType;
}
}
@@ -4,6 +4,7 @@ import java.math.BigDecimal;
import org.joda.time.LocalDate;
import org.mifosplatform.infrastructure.configuration.data.CurrencyData;
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
/**
* Immutable data object reprsenting a savings account.
@@ -7,6 +7,7 @@ import java.util.List;
import org.joda.time.DateTime;
import org.mifosplatform.infrastructure.configuration.data.CurrencyData;
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
public class SavingProductData implements Serializable {
@@ -1,78 +0,0 @@
package org.mifosng.platform.api.data;
import java.util.Collection;
import java.util.List;
/**
*
*/
public class StaffAccountSummaryCollectionData {
@SuppressWarnings("unused")
private final List<ClientSummary> clients;
@SuppressWarnings("unused")
private final List<GroupSummary> groups;
public StaffAccountSummaryCollectionData(final List<ClientSummary> clients, final List<GroupSummary> groups) {
this.clients = clients;
this.groups = groups;
}
public static final class ClientSummary {
private final Long id;
private final String displayName;
private Collection<ClientAccountSummaryData> loans;
public ClientSummary(Long id, String displayName) {
this.id = id;
this.displayName = displayName;
}
public Long getId() {
return id;
}
public String getDisplayName() {
return displayName;
}
public Collection<ClientAccountSummaryData> getLoans() {
return loans;
}
public void setLoans(Collection<ClientAccountSummaryData> loans) {
this.loans = loans;
}
}
public static final class GroupSummary {
private final Long id;
private final String name;
private Collection<GroupAccountSummaryData> loans;
public GroupSummary(Long id, String name) {
this.id = id;
this.name = name;
}
public Long getId() {
return id;
}
public String getName() {
return name;
}
public Collection<GroupAccountSummaryData> getLoans() {
return loans;
}
public void setLoans(Collection<GroupAccountSummaryData> loans) {
this.loans = loans;
}
}
}
@@ -1,93 +0,0 @@
package org.mifosng.platform.client.domain;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import org.apache.commons.lang.StringUtils;
import org.mifosng.platform.api.commands.ClientIdentifierCommand;
import org.mifosng.platform.infrastructure.AbstractAuditableCustom;
import org.mifosplatform.infrastructure.codes.domain.CodeValue;
import org.mifosplatform.infrastructure.user.domain.AppUser;
@Entity
@Table(name = "m_client_identifier", uniqueConstraints = {
@UniqueConstraint(columnNames = { "document_type_id", "document_key" }, name = "unique_identifier_key"),
@UniqueConstraint(columnNames = { "client_id", "document_type_id" }, name = "unique_client_identifier") })
public class ClientIdentifier extends AbstractAuditableCustom<AppUser, Long> {
@ManyToOne
@JoinColumn(name = "client_id", nullable = false)
private Client client;
@ManyToOne
@JoinColumn(name = "document_type_id", nullable = false)
private CodeValue documentType;
@Column(name = "document_key", length = 1000)
private String documentKey;
@Column(name = "description", length = 1000)
private String description;
public ClientIdentifier() {
this.client = null;
this.documentType = null;
this.documentKey = null;
this.description = null;
}
public static ClientIdentifier createNew(final Client client,
final CodeValue documentType, final String documentKey,
final String description) {
return new ClientIdentifier(client, documentType, documentKey,
description);
}
private ClientIdentifier(final Client client, final CodeValue documentType,
final String documentKey, final String description) {
this.client = client;
this.documentType = documentType;
this.documentKey = StringUtils.defaultIfEmpty(documentKey, null);
this.description = StringUtils.defaultIfEmpty(description, null);
}
public void update(
final ClientIdentifierCommand command,
final CodeValue documentType) {
if (command.isDocumentTypeChanged()) {
this.documentType = documentType;
}
if (command.isDocumentKeyChanged()) {
this.documentKey = StringUtils.defaultIfEmpty(
command.getDocumentKey(), null);
}
if (command.isDescriptionChanged()) {
this.description = StringUtils.defaultIfEmpty(
command.getDescription(), null);
}
}
public Client getClient() {
return client;
}
public CodeValue getDocumentType() {
return documentType;
}
public String getDocumentKey() {
return documentKey;
}
public String getDescription() {
return description;
}
}
@@ -1,10 +0,0 @@
package org.mifosng.platform.client.domain;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
public interface ClientIdentifierRepository extends
JpaRepository<ClientIdentifier, Long>,
JpaSpecificationExecutor<ClientIdentifier> {
// no behaviour
}
@@ -1,65 +0,0 @@
package org.mifosng.platform.client.service;
import java.util.ArrayList;
import java.util.List;
import org.mifosng.platform.DataValidatorBuilder;
import org.mifosng.platform.api.commands.ClientIdentifierCommand;
import org.mifosng.platform.api.data.ApiParameterError;
import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
public class ClientIdentifierCommandValidator {
private final ClientIdentifierCommand command;
public ClientIdentifierCommandValidator(ClientIdentifierCommand command) {
this.command = command;
}
public void validateForUpdate() {
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(
dataValidationErrors).resource("clientIdentifier");
baseDataValidator.reset().parameter("documentKey")
.value(command.getDocumentKey()).ignoreIfNull().notBlank();
if (command.isDocumentTypeChanged()) {
baseDataValidator.reset().parameter("documentTypeId")
.value(command.getDocumentTypeId()).notNull()
.integerGreaterThanZero();
}
baseDataValidator.reset().anyOfNotNull(command.getDocumentTypeId(),
command.getDocumentKey());
if (!dataValidationErrors.isEmpty()) {
throw new PlatformApiDataValidationException(
"validation.msg.validation.errors.exist",
"Validation errors exist.", dataValidationErrors);
}
}
public void validateForCreate() {
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(
dataValidationErrors).resource("clientIdentifier");
baseDataValidator.reset().parameter("documentTypeId")
.value(command.getDocumentTypeId()).notNull()
.integerGreaterThanZero();
baseDataValidator.reset().parameter("clientId")
.value(command.getClientId()).notNull()
.integerGreaterThanZero();
baseDataValidator.reset().parameter("documentKey")
.value(command.getDocumentKey()).notBlank();
if (!dataValidationErrors.isEmpty()) {
throw new PlatformApiDataValidationException(
"validation.msg.validation.errors.exist",
"Validation errors exist.", dataValidationErrors);
}
}
}
@@ -1,34 +0,0 @@
package org.mifosng.platform.client.service;
public class LoanStatusMapper {
private final Integer statusId;
public LoanStatusMapper(Integer statusId) {
this.statusId = statusId;
}
public boolean isPendingApproval() {
return Integer.valueOf(100).equals(statusId);
}
public boolean isAwaitingDisbursal() {
return Integer.valueOf(200).equals(statusId);
}
public boolean isOpen() {
return Integer.valueOf(300).equals(statusId);
}
public boolean isWithdrawnByClient() {
return Integer.valueOf(400).equals(statusId);
}
public boolean isRejected() {
return Integer.valueOf(500).equals(statusId);
}
public boolean isClosed() {
return Integer.valueOf(600).equals(statusId) || isWithdrawnByClient() || isRejected();
}
}
@@ -6,7 +6,7 @@ import javax.persistence.Table;
import org.apache.commons.lang.StringUtils;
import org.mifosng.platform.api.commands.DocumentCommand;
import org.mifosng.platform.infrastructure.AbstractAuditableCustom;
import org.mifosplatform.infrastructure.core.domain.AbstractAuditableCustom;
import org.mifosplatform.infrastructure.user.domain.AppUser;
@Entity
@@ -3,10 +3,10 @@ package org.mifosng.platform.documentmanagement.service;
import java.util.ArrayList;
import java.util.List;
import org.mifosng.platform.DataValidatorBuilder;
import org.mifosng.platform.api.commands.DocumentCommand;
import org.mifosng.platform.api.data.ApiParameterError;
import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
public class DocumentCommandValidator {
@@ -6,8 +6,8 @@ import java.util.Collection;
import org.mifosng.platform.api.data.DocumentData;
import org.mifosng.platform.exceptions.DocumentNotFoundException;
import org.mifosng.platform.infrastructure.JdbcSupport;
import org.mifosng.platform.infrastructure.TenantAwareRoutingDataSource;
import org.mifosplatform.infrastructure.core.domain.JdbcSupport;
import org.mifosplatform.infrastructure.core.service.TenantAwareRoutingDataSource;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
@@ -3,7 +3,7 @@ package org.mifosng.platform.documentmanagement.service;
import java.io.InputStream;
import org.mifosng.platform.api.commands.DocumentCommand;
import org.mifosng.platform.api.data.EntityIdentifier;
import org.mifosplatform.infrastructure.core.data.EntityIdentifier;
import org.springframework.security.access.prepost.PreAuthorize;
public interface DocumentWritePlatformService {
@@ -5,14 +5,14 @@ import java.io.IOException;
import java.io.InputStream;
import org.mifosng.platform.api.commands.DocumentCommand;
import org.mifosng.platform.api.data.EntityIdentifier;
import org.mifosng.platform.documentmanagement.domain.Document;
import org.mifosng.platform.documentmanagement.domain.DocumentRepository;
import org.mifosng.platform.exceptions.DocumentManagementException;
import org.mifosng.platform.exceptions.DocumentNotFoundException;
import org.mifosng.platform.exceptions.InvalidEntityTypeForDocumentManagementException;
import org.mifosng.platform.exceptions.PlatformDataIntegrityException;
import org.mifosng.platform.infrastructure.FileUtils;
import org.mifosplatform.infrastructure.core.data.EntityIdentifier;
import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException;
import org.mifosplatform.infrastructure.core.service.FileUtils;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -2,6 +2,8 @@ package org.mifosng.platform.exceptions;
import java.math.BigDecimal;
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRuleException;
public class DepositAccounDataValidationtException extends
AbstractPlatformDomainRuleException {
@@ -1,5 +1,7 @@
package org.mifosng.platform.exceptions;
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
public class DepositAccountNotFoundException extends AbstractPlatformResourceNotFoundException {
public DepositAccountNotFoundException(final Long id) {
@@ -1,6 +1,7 @@
package org.mifosng.platform.exceptions;
import org.joda.time.LocalDate;
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRuleException;
public class DepositAccountReopenException extends AbstractPlatformDomainRuleException{
@@ -1,5 +1,7 @@
package org.mifosng.platform.exceptions;
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRuleException;
public class DepositAccountTransactionsException extends AbstractPlatformDomainRuleException {
@@ -1,5 +1,7 @@
package org.mifosng.platform.exceptions;
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
public class DepositProductNotFoundException extends
AbstractPlatformResourceNotFoundException {
@@ -0,0 +1,14 @@
package org.mifosng.platform.exceptions;
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRuleException;
/**
* Exception thrown when an attempt is made update the parent of a root office.
*/
public class DepositProductValueOutsideRangeException extends AbstractPlatformDomainRuleException {
public DepositProductValueOutsideRangeException(final String actualValue, final String rangeMin, final String rangeMax, final String fieldCode) {
super("error.msg." + fieldCode + ".outside.of.allowed.range", actualValue + " is outside of allowed range of [" + rangeMin + ", "
+ rangeMax + "].", actualValue, rangeMin, rangeMax);
}
}
@@ -1,5 +1,7 @@
package org.mifosng.platform.exceptions;
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRuleException;
public class DocumentManagementException extends
AbstractPlatformDomainRuleException {
@@ -1,5 +1,7 @@
package org.mifosng.platform.exceptions;
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
public class DocumentNotFoundException extends
AbstractPlatformResourceNotFoundException {
@@ -1,52 +0,0 @@
package org.mifosng.platform.exceptions;
/**
* A {@link RuntimeException} thrown when a client identifier of the particular type is already present
*/
public class DuplicateClientIdentifierException extends AbstractPlatformDomainRuleException {
private Long documentTypeId;
private String identifierKey;
private String identifierType;
public DuplicateClientIdentifierException(final String identifierType) {
super("error.msg.clientIdentifier.type.duplicate",
"Client identifier of type " + identifierType
+ " is already present for this client", identifierType);
this.identifierType = identifierType;
}
public DuplicateClientIdentifierException(final Long documentTypeId, final String identifierType, final String identifierKey) {
super("error.msg.clientIdentifier.identityKey.duplicate",
"Client identifier of type " + identifierType
+ " with value of " + identifierKey + " already exists.", identifierType, identifierKey);
this.documentTypeId = documentTypeId;
this.identifierType = identifierType;
this.identifierKey = identifierKey;
}
public DuplicateClientIdentifierException(
final String clientName,
final String officeName,
final String identifierType,
final String identifierKey) {
super("error.msg.clientIdentifier.identityKey.duplicate", "Client "
+ clientName + "under " + officeName + " Branch already has a "
+ identifierType + " with unique key " + identifierKey,
clientName, officeName, identifierType, identifierKey);
this.identifierType = identifierType;
this.identifierKey = identifierKey;
}
public Long getDocumentTypeId() {
return documentTypeId;
}
public String getIdentifierKey() {
return identifierKey;
}
public String getIdentifierType() {
return identifierType;
}
}
@@ -1,11 +0,0 @@
package org.mifosng.platform.exceptions;
/**
* A {@link RuntimeException} thrown when fund resources are not found.
*/
public class FundNotFoundException extends AbstractPlatformResourceNotFoundException {
public FundNotFoundException(final Long id) {
super("error.msg.fund.id.invalid", "Fund with identifier " + id + " does not exist", id);
}
}
@@ -1,5 +1,7 @@
package org.mifosng.platform.exceptions;
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
/**
* A {@link RuntimeException} thrown when group resources are not found.
*/
@@ -1,5 +1,7 @@
package org.mifosng.platform.exceptions;
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
/**
* A {@link RuntimeException} thrown when guarantor resources are not found.
*/
@@ -1,11 +0,0 @@
package org.mifosng.platform.exceptions;
public class ImageDataURLNotValidException extends
AbstractPlatformDomainRuleException {
public ImageDataURLNotValidException() {
super("error.msg.dataURL.save",
"Only GIF, PNG and JPEG Data URL's are allowed");
}
}
@@ -1,10 +0,0 @@
package org.mifosng.platform.exceptions;
public class ImageNotFoundException extends AbstractPlatformDomainRuleException {
public ImageNotFoundException(final String resource, final Long resourceId) {
super("error.msg.entity.image.invalid", "Image for resource "
+ resource + " with Identifier " + resourceId
+ " does not exist", resource, resourceId);
}
}
@@ -1,10 +0,0 @@
package org.mifosng.platform.exceptions;
public class ImageUploadException extends AbstractPlatformDomainRuleException {
public ImageUploadException() {
super("error.msg.image.type.upload",
"Only image files of type GIF,PNG and JPG are allowed ");
}
}
@@ -1,5 +1,7 @@
package org.mifosng.platform.exceptions;
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRuleException;
public class InvalidDepositStateTransitionException extends
AbstractPlatformDomainRuleException {
@@ -1,5 +1,7 @@
package org.mifosng.platform.exceptions;
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
/**
* A {@link RuntimeException} thrown when document management functionality is
* invoked for invalid Entity Types
@@ -1,5 +1,7 @@
package org.mifosng.platform.exceptions;
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRuleException;
/**
* {@link AbstractPlatformDomainRuleException} thrown when a Client is set as a
* guarantor for his/her own loans
@@ -1,5 +1,7 @@
package org.mifosng.platform.exceptions;
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRuleException;
/**
* {@link AbstractPlatformDomainRuleException} thrown an action to transition a loan from one state to another violates a domain rule.
*/
@@ -1,5 +1,7 @@
package org.mifosng.platform.exceptions;
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRuleException;
/**
* {@link AbstractPlatformDomainRuleException} thrown an action to transition a loan from one state to another violates a domain rule.
*/
@@ -1,5 +1,7 @@
package org.mifosng.platform.exceptions;
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
/**
* A {@link RuntimeException} thrown when loan resources are not found.
*/
@@ -1,5 +1,7 @@
package org.mifosng.platform.exceptions;
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRuleException;
/**
* {@link AbstractPlatformDomainRuleException} thrown when trying to delete a loan in an invalid state.
*/
@@ -1,18 +1,17 @@
package org.mifosng.platform.exceptions;
import org.joda.time.LocalDate;
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRuleException;
public class LoanOfficerAssignmentException extends
AbstractPlatformDomainRuleException {
public class LoanOfficerAssignmentException extends AbstractPlatformDomainRuleException {
public LoanOfficerAssignmentException(final Long loanId, final Long fromLoanOfficerId) {
super("error.msg.loan.not.assigned.to.loan.officer", "Loan with identifier " + loanId +
" is not assigned to Loan Officer with identifier " + fromLoanOfficerId + ".", loanId);
super("error.msg.loan.not.assigned.to.loan.officer", "Loan with identifier " + loanId
+ " is not assigned to Loan Officer with identifier " + fromLoanOfficerId + ".", loanId);
}
public LoanOfficerAssignmentException(final Long loanId, final LocalDate date){
super("error.msg.loan.assignment.date.is.before.last.assignment.date", "Loan with identifier " + loanId +
" was already assigned before date " + date.toString());
public LoanOfficerAssignmentException(final Long loanId, final LocalDate date) {
super("error.msg.loan.assignment.date.is.before.last.assignment.date", "Loan with identifier " + loanId
+ " was already assigned before date " + date.toString());
}
}
@@ -1,5 +1,7 @@
package org.mifosng.platform.exceptions;
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
/**
* A {@link RuntimeException} thrown when loan resources are not found.
*/
@@ -1,5 +1,7 @@
package org.mifosng.platform.exceptions;
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
/**
* A {@link RuntimeException} thrown when loan transactions processing strategy resources are not found.
*/
@@ -1,12 +0,0 @@
package org.mifosng.platform.exceptions;
/**
* A {@link RuntimeException} that is thrown in the case where a user does not have sufficient authorization to execute operation on platform.
*/
public class NoAuthorizationException extends RuntimeException {
public NoAuthorizationException(final String message) {
super(message);
}
}
@@ -1,15 +0,0 @@
package org.mifosng.platform.exceptions;
/**
* A {@link RuntimeException} thrown when note resources are not found.
*/
public class NoteNotFoundException extends AbstractPlatformResourceNotFoundException {
public NoteNotFoundException(Long id) {
super("error.msg.note.id.invalid", "Note with identifier " + id + " does not exist", id);
}
public NoteNotFoundException(Long id, Long clientId, final String resource) {
super("error.msg." + resource + ".note.id.invalid", "Note with identifier " + id + " does not exist for " + resource + " with identifier " + clientId, id, clientId);
}
}
@@ -1,30 +0,0 @@
package org.mifosng.platform.exceptions;
import java.util.List;
import org.mifosng.platform.api.data.ApiParameterError;
public class PlatformApiDataValidationException extends RuntimeException {
private final String globalisationMessageCode;
private final String defaultUserMessage;
private final List<ApiParameterError> errors;
public PlatformApiDataValidationException(final String globalisationMessageCode, final String defaultUserMessage, List<ApiParameterError> errors) {
this.globalisationMessageCode = globalisationMessageCode;
this.defaultUserMessage = defaultUserMessage;
this.errors = errors;
}
public String getGlobalisationMessageCode() {
return globalisationMessageCode;
}
public String getDefaultUserMessage() {
return defaultUserMessage;
}
public List<ApiParameterError> getErrors() {
return errors;
}
}
@@ -1,42 +0,0 @@
package org.mifosng.platform.exceptions;
/**
* A {@link RuntimeException} thrown when data integrity problems happen due to state modifying actions.
*/
public class PlatformDataIntegrityException extends RuntimeException {
private final String globalisationMessageCode;
private final String defaultUserMessage;
private final String parameterName;
private final Object[] defaultUserMessageArgs;
public PlatformDataIntegrityException(final String globalisationMessageCode, final String defaultUserMessage, final Object... defaultUserMessageArgs) {
this.globalisationMessageCode = globalisationMessageCode;
this.defaultUserMessage = defaultUserMessage;
this.parameterName = "";
this.defaultUserMessageArgs = defaultUserMessageArgs;
}
public PlatformDataIntegrityException(final String globalisationMessageCode, final String defaultUserMessage, final String parameterName, final Object... defaultUserMessageArgs) {
this.globalisationMessageCode = globalisationMessageCode;
this.defaultUserMessage = defaultUserMessage;
this.parameterName = parameterName;
this.defaultUserMessageArgs = defaultUserMessageArgs;
}
public String getGlobalisationMessageCode() {
return globalisationMessageCode;
}
public String getDefaultUserMessage() {
return defaultUserMessage;
}
public Object[] getDefaultUserMessageArgs() {
return defaultUserMessageArgs;
}
public String getParameterName() {
return parameterName;
}
}
@@ -1,29 +0,0 @@
package org.mifosng.platform.exceptions;
/**
* A {@link RuntimeException} thrown when unexpected server side errors happen.
*/
public class PlatformInternalServerException extends RuntimeException {
private final String globalisationMessageCode;
private final String defaultUserMessage;
private final Object[] defaultUserMessageArgs;
public PlatformInternalServerException(String globalisationMessageCode, String defaultUserMessage, Object... defaultUserMessageArgs) {
this.globalisationMessageCode = globalisationMessageCode;
this.defaultUserMessage = defaultUserMessage;
this.defaultUserMessageArgs = defaultUserMessageArgs;
}
public String getGlobalisationMessageCode() {
return globalisationMessageCode;
}
public String getDefaultUserMessage() {
return defaultUserMessage;
}
public Object[] getDefaultUserMessageArgs() {
return defaultUserMessageArgs;
}
}
@@ -1,9 +0,0 @@
package org.mifosng.platform.exceptions;
public class ProductNotFoundException extends AbstractPlatformResourceNotFoundException{
public ProductNotFoundException(Long id) {
super("error.msg.product.id.invalid", "Product with identifier " + id + " does not exist", id);
}
}
@@ -1,11 +0,0 @@
package org.mifosng.platform.exceptions;
/**
* A {@link RuntimeException} thrown when report resources are not found.
*/
public class ReportNotFoundException extends AbstractPlatformResourceNotFoundException {
public ReportNotFoundException(final String reportSql) {
super("error.msg.report.name.not.found", "Reporting Meta Data Entry Not Found", "Input Sql: " + reportSql);
}
}
@@ -1,5 +1,7 @@
package org.mifosng.platform.exceptions;
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
public class SavingAccountNotFoundException extends AbstractPlatformResourceNotFoundException {
public SavingAccountNotFoundException(final Long id) {
@@ -1,5 +1,7 @@
package org.mifosng.platform.exceptions;
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
public class SavingProductNotFoundException extends
AbstractPlatformResourceNotFoundException {
@@ -0,0 +1,11 @@
package org.mifosng.platform.exceptions;
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
public class SavingsProductNotFoundException extends AbstractPlatformResourceNotFoundException {
public SavingsProductNotFoundException(Long id) {
super("error.msg.product.id.invalid", "Product with identifier " + id + " does not exist", id);
}
}
@@ -1,20 +0,0 @@
package org.mifosng.platform.exceptions;
public class UnrecognizedQueryParamException extends RuntimeException {
private final String queryParamKey;
private final String queryParamValue;
public UnrecognizedQueryParamException(String queryParamKey, String queryParamValue) {
this.queryParamKey = queryParamKey;
this.queryParamValue = queryParamValue;
}
public String getQueryParamKey() {
return queryParamKey;
}
public String getQueryParamValue() {
return queryParamValue;
}
}
@@ -1,13 +0,0 @@
package org.mifosng.platform.exceptions;
/**
* Exception thrown when an attempt is made update the parent of a root office.
*/
public class ValueOutsideRangeException extends AbstractPlatformDomainRuleException {
public ValueOutsideRangeException(final String actualValue, final String rangeMin, final String rangeMax, final String fieldCode) {
super("error.msg." + fieldCode + ".outside.of.allowed.range", actualValue + " is outside of allowed range of ["
+ rangeMin + ", " + rangeMax + "].", actualValue, rangeMin, rangeMax);
}
}
@@ -1,34 +0,0 @@
package org.mifosng.platform.filters;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import com.sun.jersey.spi.container.ContainerRequest;
import com.sun.jersey.spi.container.ContainerResponse;
import com.sun.jersey.spi.container.ContainerResponseFilter;
/**
* Filter that returns a response with headers that allows for Cross-Origin Requests (CORs) to be performed against the platform API.
*/
public class ResponseCorsFilter implements ContainerResponseFilter {
@Override
public ContainerResponse filter(ContainerRequest request, ContainerResponse response) {
ResponseBuilder resp = Response.fromResponse(response.getResponse());
resp.header("Access-Control-Allow-Origin", "*")
// .header("Access-Control-Expose-Headers", "X-Mifos-Platform-TenantId")
.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
String reqHead = request.getHeaderValue("Access-Control-Request-Headers");
if (null != reqHead && !reqHead.equals(null)) {
resp.header("Access-Control-Allow-Headers", reqHead);
}
response.setResponse(resp.build());
return response;
}
}
@@ -13,10 +13,10 @@ import javax.persistence.Table;
import org.apache.commons.lang.StringUtils;
import org.mifosng.platform.api.commands.GroupCommand;
import org.mifosng.platform.client.domain.Client;
import org.mifosng.platform.infrastructure.AbstractAuditableCustom;
import org.mifosplatform.infrastructure.core.domain.AbstractAuditableCustom;
import org.mifosplatform.infrastructure.office.domain.Office;
import org.mifosplatform.infrastructure.user.domain.AppUser;
import org.mifosplatform.portfolio.client.domain.Client;
@Entity
@Table(name = "m_group")
@@ -3,10 +3,10 @@ package org.mifosng.platform.group.service;
import java.util.ArrayList;
import java.util.List;
import org.mifosng.platform.DataValidatorBuilder;
import org.mifosng.platform.api.commands.GroupCommand;
import org.mifosng.platform.api.data.ApiParameterError;
import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
public class GroupCommandValidator {
@@ -3,9 +3,9 @@ package org.mifosng.platform.group.service;
import java.util.Collection;
import org.mifosng.platform.api.data.GroupAccountSummaryCollectionData;
import org.mifosng.platform.api.data.ClientLookup;
import org.mifosng.platform.api.data.GroupAccountSummaryData;
import org.mifosng.platform.api.data.GroupData;
import org.mifosplatform.portfolio.client.data.ClientLookup;
public interface GroupReadPlatformService {
@@ -7,18 +7,18 @@ import java.util.Collection;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.mifosng.platform.api.data.ClientLookup;
import org.mifosng.platform.api.data.GroupAccountSummaryCollectionData;
import org.mifosng.platform.api.data.GroupAccountSummaryData;
import org.mifosng.platform.api.data.GroupData;
import org.mifosng.platform.client.service.ClientReadPlatformService;
import org.mifosng.platform.client.service.LoanStatusMapper;
import org.mifosng.platform.exceptions.GroupNotFoundException;
import org.mifosng.platform.infrastructure.JdbcSupport;
import org.mifosng.platform.infrastructure.TenantAwareRoutingDataSource;
import org.mifosplatform.infrastructure.core.domain.JdbcSupport;
import org.mifosplatform.infrastructure.core.service.TenantAwareRoutingDataSource;
import org.mifosplatform.infrastructure.office.data.OfficeLookup;
import org.mifosplatform.infrastructure.office.service.OfficeReadPlatformService;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.portfolio.client.data.ClientLookup;
import org.mifosplatform.portfolio.client.service.ClientReadPlatformService;
import org.mifosplatform.portfolio.client.service.LoanStatusMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -1,7 +1,7 @@
package org.mifosng.platform.group.service;
import org.mifosng.platform.api.commands.GroupCommand;
import org.mifosng.platform.api.data.EntityIdentifier;
import org.mifosplatform.infrastructure.core.data.EntityIdentifier;
import org.springframework.security.access.prepost.PreAuthorize;
public interface GroupWritePlatformService {
@@ -4,19 +4,19 @@ import java.util.HashSet;
import java.util.Set;
import org.mifosng.platform.api.commands.GroupCommand;
import org.mifosng.platform.api.data.EntityIdentifier;
import org.mifosng.platform.client.domain.Client;
import org.mifosng.platform.client.domain.ClientRepository;
import org.mifosng.platform.exceptions.ClientNotFoundException;
import org.mifosng.platform.exceptions.GroupNotFoundException;
import org.mifosng.platform.exceptions.InvalidOfficeException;
import org.mifosng.platform.exceptions.OfficeNotFoundException;
import org.mifosng.platform.exceptions.PlatformDataIntegrityException;
import org.mifosng.platform.group.domain.Group;
import org.mifosng.platform.group.domain.GroupRepository;
import org.mifosplatform.infrastructure.core.data.EntityIdentifier;
import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException;
import org.mifosplatform.infrastructure.office.domain.Office;
import org.mifosplatform.infrastructure.office.domain.OfficeRepository;
import org.mifosplatform.infrastructure.office.exception.InvalidOfficeException;
import org.mifosplatform.infrastructure.office.exception.OfficeNotFoundException;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.portfolio.client.domain.Client;
import org.mifosplatform.portfolio.client.domain.ClientRepository;
import org.mifosplatform.portfolio.client.exception.ClientNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -3,10 +3,10 @@ package org.mifosng.platform.guarantor;
import java.util.ArrayList;
import java.util.List;
import org.mifosng.platform.DataValidatorBuilder;
import org.mifosng.platform.api.commands.GuarantorCommand;
import org.mifosng.platform.api.data.ApiParameterError;
import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
public class GuarantorCommandValidator {
@@ -5,13 +5,13 @@ import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.joda.time.LocalDate;
import org.mifosng.platform.api.data.GuarantorData;
import org.mifosng.platform.client.domain.Client;
import org.mifosng.platform.exceptions.GuarantorNotFoundException;
import org.mifosng.platform.exceptions.LoanNotFoundException;
import org.mifosng.platform.loan.domain.Loan;
import org.mifosng.platform.loan.domain.LoanRepository;
import org.mifosplatform.infrastructure.dataqueries.data.GenericResultsetData;
import org.mifosplatform.infrastructure.dataqueries.service.ReadWriteNonCoreDataService;
import org.mifosplatform.portfolio.client.domain.Client;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -9,16 +9,16 @@ import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.mifosng.platform.api.commands.GuarantorCommand;
import org.mifosng.platform.api.data.ApiParameterError;
import org.mifosng.platform.client.domain.Client;
import org.mifosng.platform.client.domain.ClientRepository;
import org.mifosng.platform.exceptions.ClientNotFoundException;
import org.mifosng.platform.exceptions.InvalidGuarantorException;
import org.mifosng.platform.exceptions.LoanNotFoundException;
import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
import org.mifosng.platform.loan.domain.Loan;
import org.mifosng.platform.loan.domain.LoanRepository;
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
import org.mifosplatform.infrastructure.dataqueries.service.ReadWriteNonCoreDataService;
import org.mifosplatform.portfolio.client.domain.Client;
import org.mifosplatform.portfolio.client.domain.ClientRepository;
import org.mifosplatform.portfolio.client.exception.ClientNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -1,21 +0,0 @@
package org.mifosng.platform.infrastructure;
public class Base64EncodedImage {
private final String base64EncodedString;
private final String fileExtension;
public Base64EncodedImage(String base64EncodedString, String fileExtension) {
this.base64EncodedString = base64EncodedString;
this.fileExtension = fileExtension;
}
public String getBase64EncodedString() {
return base64EncodedString;
}
public String getFileExtension() {
return fileExtension;
}
}
@@ -1,209 +0,0 @@
package org.mifosng.platform.infrastructure;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import org.mifosng.platform.api.data.ApiParameterError;
import org.mifosng.platform.exceptions.DocumentManagementException;
import org.mifosng.platform.exceptions.ImageDataURLNotValidException;
import org.mifosng.platform.exceptions.ImageUploadException;
import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.lowagie.text.pdf.codec.Base64;
public class FileUtils {
private final static Logger logger = LoggerFactory
.getLogger(FileUtils.class);
public static final String MIFOSX_BASE_DIR = System
.getProperty("user.home") + File.separator + ".mifosx";
public static Random random = new Random();
/**
* Generate a random String
*
* @return
*/
public static String generateRandomString() {
String characters = "abcdefghijklmnopqrstuvwxyz123456789";
int length = generateRandomNumber();
char[] text = new char[length];
for (int i = 0; i < length; i++) {
text[i] = characters.charAt(random.nextInt(characters.length()));
}
return new String(text);
}
/**
* Generate a random number between 5 to 16
*
* @return
*/
public static int generateRandomNumber() {
Random randomGenerator = new Random();
return randomGenerator.nextInt(11) + 5;
}
/**
* Generate the directory path for storing the new document
*
* @param entityType
* @param entityId
* @return
*/
public static String generateFileParentDirectory(String entityType,
Long entityId) {
return FileUtils.MIFOSX_BASE_DIR
+ File.separator
+ ThreadLocalContextUtil.getTenant().getName()
.replaceAll(" ", "").trim() + File.separator
+ "documents" + File.separator + entityType + File.separator
+ entityId + File.separator + FileUtils.generateRandomString();
}
/**
* Generate directory path for storing new Image
*/
public static String generateClientImageParentDirectory(final Long resourceId) {
return FileUtils.MIFOSX_BASE_DIR
+ File.separator
+ ThreadLocalContextUtil.getTenant().getName()
.replaceAll(" ", "").trim() + File.separator + "images"
+ File.separator + "clients" + File.separator
+ resourceId;
}
/**
* @param uploadedInputStream
* @param uploadedFileLocation
* @return
* @throws IOException
*/
public static String saveToFileSystem(InputStream uploadedInputStream,
String uploadedFileLocation, String fileName) throws IOException {
String fileLocation = uploadedFileLocation + File.separator + fileName;
OutputStream out = new FileOutputStream(new File(fileLocation));
int read = 0;
byte[] bytes = new byte[1024];
while ((read = uploadedInputStream.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
out.flush();
out.close();
return fileLocation;
}
/**
* @param base64EncodedImage
* @param uploadedFileLocation
* @param fileName
* @return
* @throws IOException
*/
public static String saveToFileSystem(Base64EncodedImage base64EncodedImage,
String uploadedFileLocation, String fileName) throws IOException {
String fileLocation = uploadedFileLocation + File.separator + fileName + base64EncodedImage.getFileExtension();
OutputStream out = new FileOutputStream(new File(fileLocation));
byte[] imgBytes = Base64.decode(base64EncodedImage.getBase64EncodedString());
out.write(imgBytes);
out.flush();
out.close();
return fileLocation;
}
/**
* @param fileSize
* @param name
*/
public static void validateFileSizeWithinPermissibleRange(Long fileSize,
String name, int maxFileSize) {
/**
* Using Content-Length gives me size of the entire request, which is
* good enough for now for a fast fail as the length of the rest of the
* content i.e name and description while compared to the uploaded file
* size is negligible
**/
if (fileSize != null && ((fileSize / (1024 * 1024)) > maxFileSize)) {
throw new DocumentManagementException(name, fileSize, maxFileSize);
}
}
/**
* Validates that passed in Mime type maps to known image mime types
*
* @param mimeType
*/
public static void validateImageMimeType(String mimeType) {
if (!(mimeType.equalsIgnoreCase("image/gif")
|| mimeType.equalsIgnoreCase("image/jpeg") || mimeType
.equalsIgnoreCase("image/png"))) {
throw new ImageUploadException();
}
}
/**
* Extracts Image from a Data URL
*
* @param mimeType
*/
public static Base64EncodedImage extractImageFromDataURL(String dataURL) {
String fileExtension = "";
String base64EncodedString = null;
String gifDataURLSnippet = "data:image/gif;base64,";
String pngDataURLSnippet = "data:image/png;base64,";
String jpegDataURLSnippet = "data:image/jpeg;base64,";
if (dataURL.contains(gifDataURLSnippet)) {
base64EncodedString = dataURL.replaceAll(gifDataURLSnippet, "");
fileExtension = ".gif";
} else if (dataURL.contains(pngDataURLSnippet)) {
base64EncodedString = dataURL.replaceAll(pngDataURLSnippet, "");
fileExtension = ".png";
} else if (dataURL.contains(jpegDataURLSnippet)) {
base64EncodedString = dataURL.replaceAll(jpegDataURLSnippet, "");
fileExtension = ".jpeg";
} else {
throw new ImageDataURLNotValidException();
}
return new Base64EncodedImage(base64EncodedString, fileExtension);
}
public static void validateClientImageNotEmpty(String imageFileName) {
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
if (imageFileName == null) {
StringBuilder validationErrorCode = new StringBuilder(
"validation.msg.clientImage.cannot.be.blank");
StringBuilder defaultEnglishMessage = new StringBuilder(
"The parameter image cannot be blank.");
ApiParameterError error = ApiParameterError.parameterError(
validationErrorCode.toString(),
defaultEnglishMessage.toString(), "image");
dataValidationErrors.add(error);
throw new PlatformApiDataValidationException(
"validation.msg.validation.errors.exist",
"Validation errors exist.", dataValidationErrors);
}
}
public static void deleteClientImage(final Long resourceId, final String location) {
File fileToBeDeleted = new File(location);
boolean fileDeleted = fileToBeDeleted.delete();
if (!fileDeleted) {
// no need to throw an Error, simply log a warning
logger.warn("Unable to delete image associated with clients with Id " + resourceId);
}
}
}
@@ -1,14 +0,0 @@
package org.mifosng.platform.infrastructure;
/**
* {@link RuntimeException} thrown when an invalid tenant identifier is used in request to platform.
*
* @see CustomRequestHeaderAuthenticationFilter
*/
public class InvalidTenantIdentiferException extends RuntimeException {
public InvalidTenantIdentiferException(final String message) {
super(message);
}
}
@@ -1,92 +0,0 @@
package org.mifosng.platform.infrastructure;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.sql.DataSource;
import org.apache.tomcat.jdbc.pool.PoolConfiguration;
import org.apache.tomcat.jdbc.pool.PoolProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
/**
* Implementation that returns a new or existing tomcat 7 jdbc connection pool
* datasource based on the tenant details stored in a {@link ThreadLocal}
* variable for this request.
*
* {@link ThreadLocalContextUtil} is used to retrieve the {@link MifosPlatformTenant} for the request.
*/
@Service
public class TomcatJdbcDataSourcePerTenantService implements DataSourcePerTenantService {
private final Map<Long, DataSource> tenantToDataSourceMap = new ConcurrentHashMap<Long, DataSource>(1);
private final DataSource tenantDataSource;
@Autowired
public TomcatJdbcDataSourcePerTenantService(final @Qualifier("tenantDataSourceJndi") DataSource tenantDataSource) {
this.tenantDataSource = tenantDataSource;
}
@Override
public DataSource retrieveTenantAwareDataSource() {
// default to tenant database datasource
DataSource tenantDataSource = this.tenantDataSource;
MifosPlatformTenant tenant = ThreadLocalContextUtil.getTenant();
if (tenant != null) {
// if tenant information available switch to appropriate datasource for that tenant.
if (this.tenantToDataSourceMap.containsKey(tenant.getId())) {
tenantDataSource = this.tenantToDataSourceMap.get(tenant.getId());
} else {
tenantDataSource = createNewDataSourceFor(tenant);
this.tenantToDataSourceMap.put(tenant.getId(), tenantDataSource);
}
}
return tenantDataSource;
}
private DataSource createNewDataSourceFor(final MifosPlatformTenant tenant) {
// see http://www.tomcatexpert.com/blog/2010/04/01/configuring-jdbc-pool-high-concurrency
StringBuilder jdbcUrlBuilder = new StringBuilder("jdbc:mysql://")
.append(tenant.getSchemaServer())
.append(':')
.append(tenant.getSchemaServerPort())
.append('/')
.append(tenant.getSchemaName());
PoolConfiguration poolConfiguration = new PoolProperties();
poolConfiguration.setDriverClassName("com.mysql.jdbc.Driver");
poolConfiguration.setName(tenant.getSchemaName() + "_pool");
poolConfiguration.setUrl(jdbcUrlBuilder.toString());
poolConfiguration.setUsername(tenant.getSchemaUsername());
poolConfiguration.setPassword(tenant.getSchemaPassword());
poolConfiguration.setInitialSize(5);
poolConfiguration.setMaxActive(5);
poolConfiguration.setMinIdle(1);
poolConfiguration.setMaxIdle(4);
poolConfiguration.setSuspectTimeout(60);
poolConfiguration.setTimeBetweenEvictionRunsMillis(30000);
poolConfiguration.setMinEvictableIdleTimeMillis(60000);
poolConfiguration.setTestOnBorrow(true);
poolConfiguration.setValidationQuery("SELECT 1");
poolConfiguration.setValidationInterval(30000);
poolConfiguration.setRemoveAbandoned(true);
poolConfiguration.setRemoveAbandonedTimeout(60);
poolConfiguration.setLogAbandoned(true);
poolConfiguration.setAbandonWhenPercentageFull(50);
poolConfiguration.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;"
+ "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer;org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport");
return new org.apache.tomcat.jdbc.pool.DataSource(poolConfiguration);
}
}
@@ -1,7 +0,0 @@
package org.mifosng.platform.infrastructure;
public class UsernameAlreadyExistsException extends RuntimeException {
public UsernameAlreadyExistsException(final Throwable e) {
super(e);
}
}
@@ -1,30 +0,0 @@
package org.mifosng.platform.infrastructure.errorhandling;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import org.mifosng.platform.api.data.ApiGlobalErrorResponse;
import org.springframework.context.annotation.Scope;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.stereotype.Component;
/**
* An {@link ExceptionMapper} to map {@link AccessDeniedException} thrown by platform into a HTTP API friendly format.
*
* The {@link AccessDeniedException} is thrown by spring security on platform when an attempt is made to use functionality
* for which the user does have sufficient privileges.
*/
@Provider
@Component
@Scope("singleton")
public class AccessDeniedExceptionMapper implements ExceptionMapper<AccessDeniedException> {
@Override
public Response toResponse(@SuppressWarnings("unused") AccessDeniedException exception) {
// Status code 403 really reads as: "Authenticated - but not authorized":
return Response.status(Status.FORBIDDEN).entity(ApiGlobalErrorResponse.unAuthorized()).type(MediaType.APPLICATION_JSON).build();
}
}
@@ -1,31 +0,0 @@
package org.mifosng.platform.infrastructure.errorhandling;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import org.mifosng.platform.api.data.ApiParameterError;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
/**
* An {@link ExceptionMapper} to map {@link InvalidJsonException} thrown by platform into a HTTP API friendly format.
*/
@Provider
@Component
@Scope("singleton")
public class InvalidJsonExceptionMapper implements ExceptionMapper<InvalidJsonException> {
@Override
public Response toResponse(@SuppressWarnings("unused") final InvalidJsonException exception) {
String globalisationMessageCode = "error.msg.invalid.request.body";
String defaultUserMessage = "The JSON provided in the body of the request is invalid or missing.";
ApiParameterError error = ApiParameterError.generalError(globalisationMessageCode, defaultUserMessage);
return Response.status(Status.BAD_REQUEST).entity(error).type(MediaType.APPLICATION_JSON).build();
}
}
@@ -1,28 +0,0 @@
package org.mifosng.platform.infrastructure.errorhandling;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import org.mifosng.platform.api.data.ApiGlobalErrorResponse;
import org.mifosng.platform.infrastructure.InvalidTenantIdentiferException;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
/**
* An {@link ExceptionMapper} to map {@link InvalidTenantIdentiferException} thrown by platform during authentication into a HTTP API friendly format.
*
* The {@link InvalidTenantIdentiferException} is thrown by spring security on platform when a request contains an invalid tenant identifier.
*/
@Provider
@Component
@Scope("singleton")
public class InvalidTenantIdentifierExceptionMapper implements ExceptionMapper<InvalidTenantIdentiferException> {
@Override
public Response toResponse(@SuppressWarnings("unused") final InvalidTenantIdentiferException e) {
return Response.status(Status.UNAUTHORIZED).entity(ApiGlobalErrorResponse.invalidTenantIdentifier()).type(MediaType.APPLICATION_JSON).build();
}
}
@@ -1,33 +0,0 @@
package org.mifosng.platform.infrastructure.errorhandling;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import org.mifosng.platform.api.data.ApiParameterError;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import com.google.gson.JsonSyntaxException;
/**
* An {@link ExceptionMapper} to map {@link JsonSyntaxException} thrown by platform into a HTTP API friendly format.
*/
@Provider
@Component
@Scope("singleton")
public class JsonSyntaxExceptionMapper implements ExceptionMapper<JsonSyntaxException> {
@Override
public Response toResponse(final JsonSyntaxException exception) {
String globalisationMessageCode = "error.msg.invalid.request.body";
String defaultUserMessage = "The JSON syntax provided in the body of the request is invalid: " + exception.getMessage();
ApiParameterError error = ApiParameterError.generalError(globalisationMessageCode, defaultUserMessage);
return Response.status(Status.BAD_REQUEST).entity(error).type(MediaType.APPLICATION_JSON).build();
}
}
@@ -1,33 +0,0 @@
package org.mifosng.platform.infrastructure.errorhandling;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import org.mifosng.platform.api.data.ApiParameterError;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import com.google.gson.stream.MalformedJsonException;
/**
* An {@link ExceptionMapper} to map {@link MalformedJsonException} thrown by platform into a HTTP API friendly format.
*/
@Provider
@Component
@Scope("singleton")
public class MalformedJsonExceptionMapper implements ExceptionMapper<MalformedJsonException> {
@Override
public Response toResponse(@SuppressWarnings("unused") final MalformedJsonException exception) {
String globalisationMessageCode = "error.msg.invalid.request.body";
String defaultUserMessage = "The JSON provided in the body of the request is invalid or missing.";
ApiParameterError error = ApiParameterError.generalError(globalisationMessageCode, defaultUserMessage);
return Response.status(Status.BAD_REQUEST).entity(error).type(MediaType.APPLICATION_JSON).build();
}
}
@@ -1,30 +0,0 @@
package org.mifosng.platform.infrastructure.errorhandling;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import org.mifosng.platform.api.data.ApiGlobalErrorResponse;
import org.mifosng.platform.exceptions.NoAuthorizationException;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
/**
* An {@link ExceptionMapper} to map {@link NoAuthorizationException} thrown by platform into a HTTP API friendly format.
*
* The {@link NoAuthorizationException} is thrown on platform when an attempt is made to use functionality
* for which the user does have sufficient privileges.
*/
@Provider
@Component
@Scope("singleton")
public class NoAuthorizationExceptionMapper implements ExceptionMapper<NoAuthorizationException> {
@Override
public Response toResponse(@SuppressWarnings("unused") NoAuthorizationException exception) {
// Status code 403 really reads as: "Authenticated - but not authorized":
return Response.status(Status.FORBIDDEN).entity(ApiGlobalErrorResponse.unAuthorized()).type(MediaType.APPLICATION_JSON).build();
}
}
@@ -1,32 +0,0 @@
package org.mifosng.platform.infrastructure.errorhandling;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import org.mifosng.platform.api.data.ApiGlobalErrorResponse;
import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
/**
* An {@link ExceptionMapper} to map {@link PlatformApiDataValidationException} thrown by platform into a HTTP API friendly format.
*
* The {@link PlatformApiDataValidationException} is typically thrown in data validation of the parameters passed in with an api request.
*/
@Provider
@Component
@Scope("singleton")
public class PlatformApiDataValidationExceptionMapper implements ExceptionMapper<PlatformApiDataValidationException> {
@Override
public Response toResponse(PlatformApiDataValidationException exception) {
ApiGlobalErrorResponse dataIntegrityError = ApiGlobalErrorResponse.badClientRequest(exception.getGlobalisationMessageCode(),
exception.getDefaultUserMessage(), exception.getErrors());
return Response.status(Status.BAD_REQUEST).entity(dataIntegrityError).type(MediaType.APPLICATION_JSON).build();
}
}
@@ -1,32 +0,0 @@
package org.mifosng.platform.infrastructure.errorhandling;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import org.mifosng.platform.api.data.ApiGlobalErrorResponse;
import org.mifosng.platform.exceptions.PlatformDataIntegrityException;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
/**
* An {@link ExceptionMapper} to map {@link PlatformDataIntegrityException} thrown by platform into a HTTP API friendly format.
*
* The {@link PlatformDataIntegrityException} is thrown when modifying api call result in data integrity checks to be fired.
*/
@Provider
@Component
@Scope("singleton")
public class PlatformDataIntegrityExceptionMapper implements ExceptionMapper<PlatformDataIntegrityException> {
@Override
public Response toResponse(PlatformDataIntegrityException exception) {
ApiGlobalErrorResponse dataIntegrityError = ApiGlobalErrorResponse.dataIntegrityError(exception.getGlobalisationMessageCode(), exception.getDefaultUserMessage(),
exception.getParameterName(), exception.getDefaultUserMessageArgs());
return Response.status(Status.FORBIDDEN).entity(dataIntegrityError).type(MediaType.APPLICATION_JSON).build();
}
}
@@ -1,31 +0,0 @@
package org.mifosng.platform.infrastructure.errorhandling;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import org.mifosng.platform.api.data.ApiGlobalErrorResponse;
import org.mifosng.platform.exceptions.AbstractPlatformDomainRuleException;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
/**
* An {@link ExceptionMapper} to map {@link AbstractPlatformDomainRuleException} thrown by platform into a HTTP API friendly format.
*
* The {@link AbstractPlatformDomainRuleException} is thrown when an api call results is some internal business/domain logic been violated.
*/
@Provider
@Component
@Scope("singleton")
public class PlatformDomainRuleExceptionMapper implements ExceptionMapper<AbstractPlatformDomainRuleException> {
@Override
public Response toResponse(AbstractPlatformDomainRuleException exception) {
ApiGlobalErrorResponse notFoundErrorResponse = ApiGlobalErrorResponse.domainRuleViolation(exception.getGlobalisationMessageCode(), exception.getDefaultUserMessage(), exception.getDefaultUserMessageArgs());
// request understood but not carried out due to it violating some domain/business logic
return Response.status(Status.FORBIDDEN).entity(notFoundErrorResponse).type(MediaType.APPLICATION_JSON).build();
}
}
@@ -1,30 +0,0 @@
package org.mifosng.platform.infrastructure.errorhandling;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import org.mifosng.platform.api.data.ApiGlobalErrorResponse;
import org.mifosng.platform.exceptions.PlatformInternalServerException;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
/**
* An {@link ExceptionMapper} to map {@link PlatformInternalServerException} thrown by platform into a HTTP API friendly format.
*
* The {@link PlatformInternalServerException} is thrown when an api call results in unexpected server side exceptions.
*/
@Provider
@Component
@Scope("singleton")
public class PlatformInternalServerExceptionMapper implements ExceptionMapper<PlatformInternalServerException> {
@Override
public Response toResponse(PlatformInternalServerException exception) {
ApiGlobalErrorResponse notFoundErrorResponse = ApiGlobalErrorResponse.notFound(exception.getGlobalisationMessageCode(), exception.getDefaultUserMessage(), exception.getDefaultUserMessageArgs());
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(notFoundErrorResponse).type(MediaType.APPLICATION_JSON).build();
}
}
@@ -1,30 +0,0 @@
package org.mifosng.platform.infrastructure.errorhandling;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import org.mifosng.platform.api.data.ApiGlobalErrorResponse;
import org.mifosng.platform.exceptions.AbstractPlatformResourceNotFoundException;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
/**
* An {@link ExceptionMapper} to map {@link AbstractPlatformResourceNotFoundException} thrown by platform into a HTTP API friendly format.
*
* The {@link AbstractPlatformResourceNotFoundException} is thrown when an api call for a resource that is expected to exist does not.
*/
@Provider
@Component
@Scope("singleton")
public class PlatformResourceNotFoundExceptionMapper implements ExceptionMapper<AbstractPlatformResourceNotFoundException> {
@Override
public Response toResponse(AbstractPlatformResourceNotFoundException exception) {
ApiGlobalErrorResponse notFoundErrorResponse = ApiGlobalErrorResponse.notFound(exception.getGlobalisationMessageCode(), exception.getDefaultUserMessage(), exception.getDefaultUserMessageArgs());
return Response.status(Status.NOT_FOUND).entity(notFoundErrorResponse).type(MediaType.APPLICATION_JSON).build();
}
}
@@ -1,27 +0,0 @@
package org.mifosng.platform.infrastructure.errorhandling;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import org.mifosng.platform.api.data.ApiGlobalErrorResponse;
import org.mifosng.platform.exceptions.UnAuthenticatedUserException;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
/**
* An {@link ExceptionMapper} to map {@link UnAuthenticatedUserException} thrown by platform into a HTTP API friendly format.
*/
@Provider
@Component
@Scope("singleton")
public class UnAuthenticatedUserExceptionMapper implements ExceptionMapper<UnAuthenticatedUserException> {
@Override
public Response toResponse(@SuppressWarnings("unused") UnAuthenticatedUserException exception) {
// Status code 401 really reads as: "Unauthenticated":
return Response.status(Status.UNAUTHORIZED).entity(ApiGlobalErrorResponse.unAuthenticated()).type(MediaType.APPLICATION_JSON).build();
}
}

Some files were not shown because too many files have changed in this diff Show More