MIFOSX : Api docs for Teller cash mgmt and paymenttypes

This commit is contained in:
MithunKashyap
2015-03-30 10:56:22 +05:30
parent ecaa78f6b5
commit ea8080f32c
9 changed files with 1467 additions and 268 deletions
@@ -7,6 +7,7 @@ package org.mifosplatform.commands.service;
import org.mifosplatform.commands.domain.CommandWrapper;
import org.mifosplatform.infrastructure.accountnumberformat.service.AccountNumberFormatConstants;
import org.mifosplatform.portfolio.paymenttype.api.PaymentTypeApiResourceConstants;
import org.mifosplatform.portfolio.savings.DepositsApiConstants;
import org.mifosplatform.useradministration.api.PasswordPreferencesApiConstants;
@@ -2371,17 +2372,17 @@ public class CommandWrapperBuilder {
public CommandWrapperBuilder createPaymentType() {
this.actionName = "CREATE";
this.entityName = "PAYMENTTYPE";
this.entityName = PaymentTypeApiResourceConstants.ENTITY_NAME;
this.entityId = null;
this.href = "/paymenttype";
this.href = "/" + PaymentTypeApiResourceConstants.RESOURCE_NAME;
return this;
}
public CommandWrapperBuilder updatePaymentType(final Long paymentTypeId) {
this.actionName = "UPDATE";
this.entityName = "PAYMENTTYPE";
this.entityName = PaymentTypeApiResourceConstants.ENTITY_NAME;
this.entityId = paymentTypeId;
this.href = "/paymenttype/" + paymentTypeId;
this.href = "/" + PaymentTypeApiResourceConstants.RESOURCE_NAME + paymentTypeId;
return this;
}
@@ -2389,7 +2390,7 @@ public class CommandWrapperBuilder {
this.actionName = "DELETE";
this.entityName = "PAYMENTTYPE";
this.entityId = paymentTypeId;
this.href = "/paymenttype/" + paymentTypeId;
this.href = "/" + PaymentTypeApiResourceConstants.RESOURCE_NAME + paymentTypeId;
return this;
}
@@ -31,11 +31,12 @@ import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSeriali
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.portfolio.paymenttype.data.PaymentTypeData;
import org.mifosplatform.portfolio.paymenttype.domain.PaymentTypeRepositoryWrapper;
import org.mifosplatform.portfolio.paymenttype.service.PaymentTypeReadPlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Path("/paymenttype")
@Path("/paymenttypes")
@Component
public class PaymentTypeApiResource {
@@ -44,17 +45,21 @@ public class PaymentTypeApiResource {
private final PaymentTypeReadPlatformService readPlatformService;
private final PortfolioCommandSourceWritePlatformService commandWritePlatformService;
private final ApiRequestParameterHelper apiRequestParameterHelper;
private final String resourceNameForPermissions = "PAYMENT_TYPE";
private final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<>(Arrays.asList("id", "value", "description", "isCashPayment"));
// private final String resourceNameForPermissions = "PAYMENT_TYPE";
private final PaymentTypeRepositoryWrapper paymentTypeRepositoryWrapper;
// private final Set<String> RESPONSE_DATA_PARAMETERS = new
// HashSet<>(Arrays.asList("id", "value", "description", "isCashPayment"));
@Autowired
public PaymentTypeApiResource(PlatformSecurityContext securityContext, DefaultToApiJsonSerializer<PaymentTypeData> jsonSerializer,
PaymentTypeReadPlatformService readPlatformService, ApiRequestParameterHelper apiRequestParameterHelper,
PortfolioCommandSourceWritePlatformService commandWritePlatformService) {
PaymentTypeReadPlatformService readPlatformService, PaymentTypeRepositoryWrapper paymentTypeRepositoryWrapper,
ApiRequestParameterHelper apiRequestParameterHelper, PortfolioCommandSourceWritePlatformService commandWritePlatformService) {
super();
this.securityContext = securityContext;
this.jsonSerializer = jsonSerializer;
this.readPlatformService = readPlatformService;
this.paymentTypeRepositoryWrapper = paymentTypeRepositoryWrapper;
this.apiRequestParameterHelper = apiRequestParameterHelper;
this.commandWritePlatformService = commandWritePlatformService;
}
@@ -63,22 +68,22 @@ public class PaymentTypeApiResource {
@Consumes({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON })
@Produces(MediaType.APPLICATION_JSON)
public String getAllPaymentTypes(@Context final UriInfo uriInfo) {
this.securityContext.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions);
this.securityContext.authenticatedUser().validateHasReadPermission(PaymentTypeApiResourceConstants.resourceNameForPermissions);
final Collection<PaymentTypeData> paymentTypes = this.readPlatformService.retrieveAllPaymentTypes();
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.jsonSerializer.serialize(settings, paymentTypes, this.RESPONSE_DATA_PARAMETERS);
return this.jsonSerializer.serialize(settings, paymentTypes, PaymentTypeApiResourceConstants.RESPONSE_DATA_PARAMETERS);
}
@GET
@Path("{paymentTypeId}")
@Consumes({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON })
@Produces(MediaType.APPLICATION_JSON)
public String retrieveOnePaymentType(@PathParam("paymentTypeId") final Long paymentTypeId,@Context final UriInfo uriInfo) {
this.securityContext.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions);
public String retrieveOnePaymentType(@PathParam("paymentTypeId") final Long paymentTypeId, @Context final UriInfo uriInfo) {
this.securityContext.authenticatedUser().validateHasReadPermission(PaymentTypeApiResourceConstants.resourceNameForPermissions);
this.paymentTypeRepositoryWrapper.findOneWithNotFoundDetection(paymentTypeId);
final PaymentTypeData paymentTypes = this.readPlatformService.retrieveOne(paymentTypeId);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.jsonSerializer.serialize(settings, paymentTypes, this.RESPONSE_DATA_PARAMETERS);
return this.jsonSerializer.serialize(settings, paymentTypes, PaymentTypeApiResourceConstants.RESPONSE_DATA_PARAMETERS);
}
@POST
@@ -11,14 +11,17 @@ import java.util.Set;
public class PaymentTypeApiResourceConstants {
public static final String resourceNameForPermissions = "PAYMENTTYPE";
public static final String RESOURCE_NAME = "paymenttype";
public static final String ENTITY_NAME = "PAYMENTTYPE";
public static final String resourceNameForPermissions = "PAYMENT_TYPE";
public static final String ID = "id";
public static final String NAME = "name";
public static final String DESCRIPTION = "description";
public static final String ISCASHPAYMENT = "isCashPayment";
public static final String POSITION = "position";
public final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<>(Arrays.asList(ID, NAME, DESCRIPTION, ISCASHPAYMENT));
public static final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<>(Arrays.asList(ID, NAME, DESCRIPTION, ISCASHPAYMENT));
public static final Set<String> CREATE_PAYMENT_TYPE_REQUEST_DATA_PARAMETERS = new HashSet<>(Arrays.asList(NAME, DESCRIPTION,
ISCASHPAYMENT, POSITION));
@@ -54,13 +54,13 @@ public class PaymentTypeDataValidator {
if (this.fromApiJsonHelper.parameterExists(PaymentTypeApiResourceConstants.DESCRIPTION, element)) {
final String description = this.fromApiJsonHelper.extractStringNamed(PaymentTypeApiResourceConstants.DESCRIPTION, element);
baseDataValidator.reset().parameter(PaymentTypeApiResourceConstants.DESCRIPTION).value(description).notExceedingLengthOf(500);
baseDataValidator.reset().parameter(PaymentTypeApiResourceConstants.DESCRIPTION).value(description).ignoreIfNull().notExceedingLengthOf(500);
}
if (this.fromApiJsonHelper.parameterExists(PaymentTypeApiResourceConstants.ISCASHPAYMENT, element)) {
final Boolean isCashPayment = this.fromApiJsonHelper
.extractBooleanNamed(PaymentTypeApiResourceConstants.ISCASHPAYMENT, element);
baseDataValidator.reset().parameter(PaymentTypeApiResourceConstants.ISCASHPAYMENT).value(isCashPayment);
baseDataValidator.reset().parameter(PaymentTypeApiResourceConstants.ISCASHPAYMENT).value(isCashPayment).validateForBooleanValue();
}
if (this.fromApiJsonHelper.parameterExists(PaymentTypeApiResourceConstants.POSITION, element)) {
@@ -100,13 +100,13 @@ public class PaymentTypeDataValidator {
if (this.fromApiJsonHelper.parameterExists(PaymentTypeApiResourceConstants.DESCRIPTION, element)) {
final String description = this.fromApiJsonHelper.extractStringNamed(PaymentTypeApiResourceConstants.DESCRIPTION, element);
baseDataValidator.reset().parameter(PaymentTypeApiResourceConstants.DESCRIPTION).value(description).notExceedingLengthOf(500);
baseDataValidator.reset().parameter(PaymentTypeApiResourceConstants.DESCRIPTION).value(description).ignoreIfNull().notExceedingLengthOf(500);
}
if (this.fromApiJsonHelper.parameterExists(PaymentTypeApiResourceConstants.ISCASHPAYMENT, element)) {
final Boolean isCashPayment = this.fromApiJsonHelper
.extractBooleanNamed(PaymentTypeApiResourceConstants.ISCASHPAYMENT, element);
baseDataValidator.reset().parameter(PaymentTypeApiResourceConstants.ISCASHPAYMENT).value(isCashPayment);
baseDataValidator.reset().parameter(PaymentTypeApiResourceConstants.ISCASHPAYMENT).value(isCashPayment).validateForBooleanValue();
}
if (this.fromApiJsonHelper.parameterExists(PaymentTypeApiResourceConstants.POSITION, element)) {
@@ -23,21 +23,8 @@ import org.springframework.stereotype.Service;
@Service
public class PaymentTypeWriteServiceImpl implements PaymentTypeWriteService {
// private final static Logger logger =
// LoggerFactory.getLogger(MifosEntityAccessWriteServiceImpl.class);
private final PaymentTypeRepository repository;
private final PaymentTypeRepositoryWrapper repositoryWrapper;
/*
* private final CodeValueRepositoryWrapper codeValueRepositoryWrapper;
* private final MifosEntityAccessRepository entityAccessRepository; private
* final MifosEntityRelationRepositoryWrapper
* mifosEntityRelationRepositoryWrapper; private final
* MifosEntityToEntityMappingRepository
* mifosEntityToEntityMappingRepository; private final
* MifosEntityToEntityMappingRepositoryWrapper
* mifosEntityToEntityMappingRepositoryWrapper;
*/
private final PaymentTypeDataValidator fromApiJsonDeserializer;
@Autowired
@@ -64,7 +51,7 @@ public class PaymentTypeWriteServiceImpl implements PaymentTypeWriteService {
@Override
public CommandProcessingResult updatePaymentType(Long paymentTypeId, JsonCommand command) {
// TODO Auto-generated method stub
this.fromApiJsonDeserializer.validateForUpdate(command.json());
final PaymentType paymentType = this.repositoryWrapper.findOneWithNotFoundDetection(paymentTypeId);
final Map<String, Object> changes = paymentType.update(command);
@@ -78,15 +65,26 @@ public class PaymentTypeWriteServiceImpl implements PaymentTypeWriteService {
@Override
public CommandProcessingResult deletePaymentType(Long paymentTypeId) {
// TODO Auto-generated method stub
final PaymentType paymentType = this.repositoryWrapper.findOneWithNotFoundDetection(paymentTypeId);
try {
this.repository.delete(paymentType);
this.repository.flush();
} catch (final DataIntegrityViolationException e) {
throw new PlatformDataIntegrityException("error.msg.cund.unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + e.getMostSpecificCause());
handleDataIntegrityIssues(e);
}
return new CommandProcessingResultBuilder().withEntityId(paymentType.getId()).build();
}
private void handleDataIntegrityIssues(final DataIntegrityViolationException dve) {
final Throwable realCause = dve.getMostSpecificCause();
if (realCause.getMessage().contains("acc_product_mapping")) {
throw new PlatformDataIntegrityException("error.msg.payment.type.association.exist",
"cannot.delete.payment.type.with.association");
} else if (realCause.getMessage().contains("payment_type_id")) { throw new PlatformDataIntegrityException(
"error.msg.payment.type.association.exist", "cannot.delete.payment.type.with.association"); }
throw new PlatformDataIntegrityException("error.msg.paymenttypes.unknown.data.integrity.issue",
"Unknown data integrity issue with resource.");
}
}