resolving merge issues with api-docs

This commit is contained in:
Vishwas Babu A J
2015-04-06 10:00:15 -07:00
9 changed files with 1466 additions and 40 deletions
+1195
View File
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,80 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.integrationtests;
import java.util.HashMap;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mifosplatform.integrationtests.common.PaymentTypeDomain;
import org.mifosplatform.integrationtests.common.PaymentTypeHelper;
import org.mifosplatform.integrationtests.common.Utils;
import com.jayway.restassured.builder.RequestSpecBuilder;
import com.jayway.restassured.builder.ResponseSpecBuilder;
import com.jayway.restassured.http.ContentType;
import com.jayway.restassured.specification.RequestSpecification;
import com.jayway.restassured.specification.ResponseSpecification;
public class PaymentTypeIntegrationTest {
private ResponseSpecification responseSpec;
private RequestSpecification requestSpec;
@Before
public void setup() {
Utils.initializeRESTAssured();
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testPaymentType() {
String name = PaymentTypeHelper.randomNameGenerator("P_T", 5);
String description = PaymentTypeHelper.randomNameGenerator("PT_Desc", 15);
Boolean isCashPayment = true;
Integer position = 1;
Integer paymentTypeId = PaymentTypeHelper.createPaymentType(requestSpec, responseSpec, name, description, isCashPayment, position);
Assert.assertNotNull(paymentTypeId);
PaymentTypeHelper.verifyPaymentTypeCreatedOnServer(requestSpec, responseSpec, paymentTypeId);
PaymentTypeDomain paymentTypeResponse = PaymentTypeHelper.retrieveById(requestSpec, responseSpec, paymentTypeId);
Assert.assertEquals(name, paymentTypeResponse.getName());
Assert.assertEquals(description, paymentTypeResponse.getDescription());
Assert.assertEquals(isCashPayment, paymentTypeResponse.getIsCashPayment());
Assert.assertEquals(position, paymentTypeResponse.getPosition());
// Update Payment Type
String newName = PaymentTypeHelper.randomNameGenerator("P_TU", 5);
String newDescription = PaymentTypeHelper.randomNameGenerator("PTU_Desc", 15);
Boolean isCashPaymentUpdatedValue = false;
Integer newPosition = 2;
HashMap request = new HashMap();
request.put("name", newName);
request.put("description", newDescription);
request.put("isCashPayment", isCashPaymentUpdatedValue);
request.put("position", newPosition);
PaymentTypeHelper.updatePaymentType(paymentTypeId, request, requestSpec, responseSpec);
PaymentTypeDomain paymentTypeUpdatedResponse = PaymentTypeHelper.retrieveById(requestSpec, responseSpec, paymentTypeId);
Assert.assertEquals(newName, paymentTypeUpdatedResponse.getName());
Assert.assertEquals(newDescription, paymentTypeUpdatedResponse.getDescription());
Assert.assertEquals(isCashPaymentUpdatedValue, paymentTypeUpdatedResponse.getIsCashPayment());
Assert.assertEquals(newPosition, paymentTypeUpdatedResponse.getPosition());
// Delete
Integer deletedPaymentTypeId = PaymentTypeHelper.deletePaymentType(paymentTypeId, requestSpec, responseSpec);
Assert.assertEquals(paymentTypeId, deletedPaymentTypeId);
ResponseSpecification responseSpecification = new ResponseSpecBuilder().expectStatusCode(403).build();
PaymentTypeHelper.retrieveById(requestSpec, responseSpecification, paymentTypeId);
}
}
@@ -0,0 +1,66 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.integrationtests.common;
public class PaymentTypeDomain {
private Integer id;
private String name;
private String description;
private Boolean isCashPayment;
private Integer position;
private PaymentTypeDomain(final Integer id, final String name, final String description, final Boolean isCashPayment,
final Integer position) {
this.id = id;
this.name = name;
this.description = description;
this.isCashPayment = isCashPayment;
this.position = position;
}
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return this.description;
}
public void setDescription(String description) {
this.description = description;
}
public Boolean getIsCashPayment() {
return this.isCashPayment;
}
public void setIsCashPayment(Boolean isCashPayment) {
this.isCashPayment = isCashPayment;
}
public Integer getPosition() {
return this.position;
}
public void setPosition(Integer position) {
this.position = position;
}
}
@@ -0,0 +1,78 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.integrationtests.common;
import static org.junit.Assert.assertEquals;
import java.util.HashMap;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.jayway.restassured.specification.RequestSpecification;
import com.jayway.restassured.specification.ResponseSpecification;
@SuppressWarnings({ "rawtypes", "unchecked" })
public class PaymentTypeHelper {
private static final String CREATE_PAYMENTTYPE_URL = "/mifosng-provider/api/v1/paymenttype?" + Utils.TENANT_IDENTIFIER;
private static final String PAYMENTTYPE_URL = "/mifosng-provider/api/v1/paymenttype";
public static Integer createPaymentType(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final String name, final String description, final Boolean isCashPayment, final Integer position) {
System.out.println("---------------------------------CREATING A PAYMENT TYPE---------------------------------------------");
return Utils.performServerPost(requestSpec, responseSpec, CREATE_PAYMENTTYPE_URL,
getJsonToCreatePaymentType(name, description, isCashPayment, position), "resourceId");
}
public static String getJsonToCreatePaymentType(final String name, final String description, final Boolean isCashPayment,
final Integer position) {
HashMap hm = new HashMap();
hm.put("name", name);
if (description != null) hm.put("description", description);
hm.put("isCashPayment", isCashPayment);
if (position != null) hm.put("position", position);
System.out.println("------------------------CREATING PAYMENT TYPE-------------------------" + hm);
return new Gson().toJson(hm);
}
public static void verifyPaymentTypeCreatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final Integer generatedPaymentTypeID) {
System.out.println("------------------------------CHECK PAYMENT DETAILS------------------------------------\n");
final String PAYMENTTYPE_URL = "/mifosng-provider/api/v1/paymenttype/" + generatedPaymentTypeID + "?" + Utils.TENANT_IDENTIFIER;
final Integer responsePaymentTypeID = Utils.performServerGet(requestSpec, responseSpec, PAYMENTTYPE_URL, "id");
assertEquals("ERROR IN CREATING THE PAYMENT TYPE", generatedPaymentTypeID, responsePaymentTypeID);
}
public static PaymentTypeDomain retrieveById(RequestSpecification requestSpec, ResponseSpecification responseSpec,
final Integer paymentTypeId) {
final String GET_PAYMENTTYPE_URL = "/mifosng-provider/api/v1/paymenttype/" + paymentTypeId + "?" + Utils.TENANT_IDENTIFIER;
System.out.println("---------------------------------GET PAYMENT TYPE---------------------------------------------");
final String jsonData = new Gson().toJson(Utils.performServerGet(requestSpec, responseSpec, GET_PAYMENTTYPE_URL, ""));
return new Gson().fromJson(jsonData, new TypeToken<PaymentTypeDomain>() {}.getType());
}
public static HashMap<String, String> updatePaymentType(final int id, HashMap request, final RequestSpecification requestSpec,
final ResponseSpecification responseSpec) {
final String UPDATE_PAYMENTTYPE_URL = PAYMENTTYPE_URL + "/" + id + "?" + Utils.TENANT_IDENTIFIER;
System.out.println("---------------------------------UPDATE PAYMENT TYPE " + id + "---------------------------------------------");
HashMap<String, String> hash = Utils.performServerPut(requestSpec, responseSpec, UPDATE_PAYMENTTYPE_URL,
new Gson().toJson(request), "changes");
return hash;
}
public static Integer deletePaymentType(final int id, final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
final String DELETE_PAYMENTTYPE_URL = PAYMENTTYPE_URL + "/" + id + "?" + Utils.TENANT_IDENTIFIER;
System.out.println("---------------------------------DELETING PAYMENT TYPE " + id + "--------------------------------------------");
return Utils.performServerDelete(requestSpec, responseSpec, DELETE_PAYMENTTYPE_URL, "resourceId");
}
public static String randomNameGenerator(final String prefix, final int lenOfRandomSuffix) {
return Utils.randomStringGenerator(prefix, lenOfRandomSuffix);
}
}
@@ -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.");
}
}