Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
aacitelli authored and aacitelli committed Oct 14, 2022
1 parent 0dbb37a commit 437db43
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 116 deletions.
82 changes: 41 additions & 41 deletions load-test/src/create_spontaneous_payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { SharedArray } from 'k6/data';

import { generateFakeFiscalCode, randomString } from './modules/helpers.js';

import { createCreditorInstitutionEnrollment, getCiCode} from "./modules/gps_client.js";
import { createCreditorInstitutionEnrollment } from "./modules/gps_client.js";

export let options = JSON.parse(open(__ENV.TEST_TYPE));

Expand All @@ -22,48 +22,48 @@ const gpdUrlBasePath = `${vars.gpdBaseUrl}`;

const creditor_institution_code = `organizationNew`;

//export function setup() {
// // 2. setup code (once)
// // The setup code runs, setting up the test environment (optional) and generating data
// // used to reuse code for the same VU
// const params = {
// headers: {
// 'Content-Type': 'application/json'
// },
// };
// const response = createCreditorInstitutionEnrollment(rootUrl, params, creditor_institution_code);
//
// console.log(`setup ... ${response.status}`);
//
//// check(response, {
//// "status is 201 or 409": (response) => (response.status === 201 || response.status === 409),
//// });
//
// // precondition is moved to default fn because in this stage
// // __VU is always 0 and cannot be used to create env properly
//}
export function setup() {
// 2. setup code (once)
// The setup code runs, setting up the test environment (optional) and generating data
// used to reuse code for the same VU
const params = {
headers: {
'Content-Type': 'application/json'
},
};
const response = createCreditorInstitutionEnrollment(rootUrl, params, creditor_institution_code);

console.log(`setup ... ${response.status}`);

check(response, {
"status is 201 or 409": (res) => (res.status === 201 || res.status === 409),
});

// precondition is moved to default fn because in this stage
// __VU is always 0 and cannot be used to create env properly
}

function precondition() {
// no pre conditions
}

//function postcondition(iupd, params) {
//
// // Delete the newly created debt position.
// let tag = {
// gpdMethod: "DeleteDebtPosition",
// };
//
// let url = `${gpdUrlBasePath}/organizations/${creditor_institution_code}/debtpositions/${iupd}`;
//
// let r = http.del(url, params);
//
// console.log("DeleteDebtPosition call - creditor_institution_code " + creditor_institution_code + ", iupd " + iupd + ", Status " + r.status);
//
// check(r, {
// "DeleteDebtPosition status is 200": (_r) => r.status === 200,
// }, tag);
//}
function postcondition(iupd, params) {

// Delete the newly created debt position.
let tag = {
gpdMethod: "DeleteDebtPosition",
};

let url = `${gpdUrlBasePath}/organizations/${creditor_institution_code}/debtpositions/${iupd}`;

let r = http.del(url, params);

console.log("DeleteDebtPosition call - creditor_institution_code " + creditor_institution_code + ", iupd " + iupd + ", Status " + r.status);

check(r, {
"DeleteDebtPosition status is 200": (_r) => r.status === 200,
}, tag);
}

export default function() {

Expand Down Expand Up @@ -125,9 +125,9 @@ export default function() {
}, tag);

// If flag delete_debt_position is set to true the debit position is deleted after being created
// if (r.status === 201 && delete_debt_position === "true") {
// postcondition(r.json().iupd, params);
// }
if (r.status === 201 && delete_debt_position === "true") {
postcondition(r.json().iupd, params);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.azure.core.credential.AzureKeyCredential;
import com.azure.cosmos.CosmosClientBuilder;
import com.azure.cosmos.DirectConnectionConfig;
import com.azure.cosmos.GatewayConnectionConfig;
import com.azure.spring.data.cosmos.config.AbstractCosmosConfiguration;
import com.azure.spring.data.cosmos.config.CosmosConfig;
import com.azure.spring.data.cosmos.core.ResponseDiagnostics;
Expand Down Expand Up @@ -42,9 +41,6 @@ public class CosmosDBConfiguration extends AbstractCosmosConfiguration {
CosmosClientBuilder getCosmosClientBuilder() {
AzureKeyCredential azureKeyCredential = new AzureKeyCredential(key);
DirectConnectionConfig directConnectionConfig = new DirectConnectionConfig();
directConnectionConfig.setMaxConnectionsPerEndpoint(300);
directConnectionConfig.setMaxRequestsPerConnection(60);
//GatewayConnectionConfig gatewayConnectionConfig = new GatewayConnectionConfig();
return new CosmosClientBuilder()
.endpoint(uri)
.credential(azureKeyCredential)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package it.gov.pagopa.spontaneouspayment.service;

import java.net.URI;
import java.rmi.server.UID;
import java.time.Year;
import java.util.Collections;
import java.util.Optional;
Expand All @@ -11,7 +10,6 @@
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.math.NumberUtils;
import org.json.JSONObject;
import org.modelmapper.ModelMapper;
Expand All @@ -29,6 +27,7 @@
import it.gov.pagopa.spontaneouspayment.model.ServicePropertyModel;
import it.gov.pagopa.spontaneouspayment.model.SpontaneousPaymentModel;
import it.gov.pagopa.spontaneouspayment.model.enumeration.PropertyType;
import it.gov.pagopa.spontaneouspayment.model.enumeration.Status;
import it.gov.pagopa.spontaneouspayment.model.response.PaymentOptionModel;
import it.gov.pagopa.spontaneouspayment.model.response.PaymentPositionModel;
import it.gov.pagopa.spontaneouspayment.model.response.TransferModel;
Expand All @@ -37,14 +36,12 @@
import it.gov.pagopa.spontaneouspayment.service.client.ExternalServiceClient;
import it.gov.pagopa.spontaneouspayment.service.client.GpdClient;
import it.gov.pagopa.spontaneouspayment.service.client.IuvGeneratorClient;
import it.gov.pagopa.spontaneouspayment.model.enumeration.Status;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

@Service
@AllArgsConstructor
@NoArgsConstructor
@Slf4j
public class PaymentsService {

@Autowired
Expand Down Expand Up @@ -82,7 +79,7 @@ public PaymentPositionModel createSpontaneousPayment(@NotBlank String organizati
var serviceConfiguration = getServiceDetails(spontaneousPayment.getService());

// check if the relationship between organization and enrollment to service exists
checkServiceOrganization(organizationFiscalCode, serviceConfiguration);
checkServiceOrganization(orgConfiguration, serviceConfiguration);

// checks if the service is in suitable state and the request contains the properties required by the configured service
checkServiceConfiguration(spontaneousPayment, serviceConfiguration);
Expand Down Expand Up @@ -142,41 +139,35 @@ private Predicate<ServicePropertyModel> getCheckPropertyType(ServiceProperty con
private PaymentPositionModel createDebtPosition(String organizationFiscalCode,
Organization orgConfiguration, it.gov.pagopa.spontaneouspayment.entity.Service serviceConfiguration, SpontaneousPaymentModel spontaneousPayment) {

//String sUuid = new UID().toString();
// get the enrollment for the service
//log.info("[PaymentPositionModel]step-1-{}",sUuid);
ServiceRef enrollment = Optional.ofNullable(orgConfiguration.getEnrollments()).orElseGet(Collections::emptyList)
.parallelStream()
.filter(e -> e.getServiceId().equals(serviceConfiguration.getId()))
.findAny()
.orElseThrow(() -> new AppException(AppError.ENROLLMENT_TO_SERVICE_NOT_FOUND, serviceConfiguration.getId(), organizationFiscalCode));
//log.info("[PaymentPositionModel]step-2-{}",sUuid);

// call the external service to get the PO
PaymentOptionModel po = this.callExternalService(spontaneousPayment, serviceConfiguration);
//log.info("[PaymentPositionModel]step-3-{}",sUuid);

// generate IUV
String iuv = this.callIuvGeneratorService(organizationFiscalCode, enrollment);

// integration the information for the PO
//String iuv = sUuid;
po.setIuv(iuv);
TransferModel transfer = po.getTransfer().get(0);
transfer.setIdTransfer("1");
transfer.setRemittanceInformation(enrollment.getRemittanceInformation());
transfer.setCategory(serviceConfiguration.getTransferCategory());
transfer.setIban(enrollment.getIban());
transfer.setPostalIban(enrollment.getPostalIban());
//log.info("[PaymentPositionModel]step-4-{}",sUuid);

// Payment Position to create
PaymentPositionModel pp = modelMapper.map(spontaneousPayment.getDebtor(), PaymentPositionModel.class);
pp.setIupd(iupdPrefix + iuv);
pp.setCompanyName(orgConfiguration.getCompanyName());
pp.addPaymentOptions(po);
//log.info("[PaymentPositionModel]step-5-{}",sUuid);

PaymentPositionModel p = gpdClient.createDebtPosition(organizationFiscalCode, pp);
//log.info("[PaymentPositionModel]step-6-{}",sUuid);
return p;

return gpdClient.createDebtPosition(organizationFiscalCode, pp);
}


Expand Down Expand Up @@ -209,12 +200,13 @@ private String callIuvGeneratorService(String organizationFiscalCode, ServiceRef
return Optional.ofNullable(iuvObj).orElseThrow(() -> new AppException(AppError.IUV_ACQUISITION_ERROR, organizationFiscalCode, auxDigit, segregationCode)).getIuv();
}

public void checkServiceOrganization(@NotBlank String organizationFiscalCode,
@NotNull it.gov.pagopa.spontaneouspayment.entity.Service service) {
var org = orgRepository.getCreditInstitutionByOrgFiscCodeAndServiceId(organizationFiscalCode, service.getId());
if (org.isEmpty()) {
throw new AppException(AppError.ORGANIZATION_SERVICE_NOT_FOUND, organizationFiscalCode, service.getId());
}

private void checkServiceOrganization(@NotNull Organization organization,
@NotNull it.gov.pagopa.spontaneouspayment.entity.Service service) {
Optional<ServiceRef> enrollment = organization.getEnrollments().stream().filter(e -> e.getServiceId().equals(service.getId())).findAny();
if (enrollment.isEmpty()) {
throw new AppException(AppError.ORGANIZATION_SERVICE_NOT_FOUND, organization.getFiscalCode(), service.getId());
}
}

private it.gov.pagopa.spontaneouspayment.entity.Service getServiceDetails(@NotNull ServiceModel service) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Retryable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import feign.FeignException;
Expand All @@ -18,7 +18,7 @@ public interface IuvGeneratorClient {

@Retryable(exclude = FeignException.FeignClientException.class, maxAttemptsExpression = "${retry.iuv-generator.maxAttempts}",
backoff = @Backoff(delayExpression = "${retry.iuv-generator.maxDelay}"))
@GetMapping(value = "/organizations/{organizationfiscalcode}/iuv")
@PostMapping(value = "/organizations/{organizationfiscalcode}/iuv")
IuvGenerationModelResponse generateIUV(@PathVariable("organizationfiscalcode") String organizationFiscalCode,
@RequestBody IuvGenerationModel paymentPositionModel);

Expand Down

0 comments on commit 437db43

Please sign in to comment.