Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSA-681: added Monthly Metrics Reference App changes #9

Merged
merged 4 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 97 additions & 8 deletions src/main/java/com/mastercard/creditanalytics/api/ApiExamples.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ private ApiExamples() {

public static final String RSA_METRICS_QUERY_PARAM = "retail_sales_analytics";
public static final String BENCHMARKS_METRICS_QUERY_PARAM = "retail_sales_benchmarks";

private static final String MONTHLY = "Monthly";
Maithrie168505 marked this conversation as resolved.
Show resolved Hide resolved
private static final String WEEKLY = "Weekly";
/* ApiClient Configuration */

private static org.openapitools.client.ApiClient ApiClient;
Expand Down Expand Up @@ -231,34 +232,66 @@ public static List<Match> throwsInvalidCountryCodeApiException() throws Unrecove
* validation logic will trigger.
* */

public static MetricsPerLocation getFullyPopulatedMetrics() throws UnrecoverableKeyException, CertificateException, IOException, KeyStoreException, NoSuchAlgorithmException, ApiException {
public static MetricsPerLocation getFullyPopulatedWeeklyMetrics() throws UnrecoverableKeyException, CertificateException, IOException, KeyStoreException, NoSuchAlgorithmException, ApiException {
Maithrie168505 marked this conversation as resolved.
Show resolved Hide resolved
return new MetricsApi(getApiClient()).getMetrics(
UUID.fromString(FULLY_POPULATED_METRICS_LOCATION_ID),
true,
WEEKLY,
RSA_METRICS_QUERY_PARAM

);
}

public static MetricsPerLocation getMerchantWithLowTransactionVolumeMetrics() throws UnrecoverableKeyException, CertificateException, IOException, KeyStoreException, NoSuchAlgorithmException, ApiException {
public static MetricsPerLocation getMerchantWithLowTransactionVolumeWeeklyMetrics() throws UnrecoverableKeyException, CertificateException, IOException, KeyStoreException, NoSuchAlgorithmException, ApiException {
return new MetricsApi(getApiClient()).getMetrics(
UUID.fromString(MERCHANT_WITH_LOW_TRANSACTION_VOLUME_LOCATION_ID),
true,
WEEKLY,
RSA_METRICS_QUERY_PARAM

);
}
public static MetricsPerLocation getMerchantWithLowTransactionVolumeMonthlyMetrics() throws UnrecoverableKeyException, CertificateException, IOException, KeyStoreException, NoSuchAlgorithmException, ApiException {
return new MetricsApi(getApiClient()).getMetrics(
UUID.fromString(MERCHANT_WITH_LOW_TRANSACTION_VOLUME_LOCATION_ID),
true,
MONTHLY,
RSA_METRICS_QUERY_PARAM

);
}

public static MetricsPerLocation getMerchantWithNoDataFromCurrentOrPreviousYearYoyMetrics() throws UnrecoverableKeyException, CertificateException, IOException, KeyStoreException, NoSuchAlgorithmException, ApiException {
public static MetricsPerLocation getMerchantWithNoDataFromCurrentOrPreviousYearYoyWeeklyMetrics() throws UnrecoverableKeyException, CertificateException, IOException, KeyStoreException, NoSuchAlgorithmException, ApiException {
return new MetricsApi(getApiClient()).getMetrics(
UUID.fromString(MERCHANT_WITH_NO_DATA_FROM_CURRENT_OR_PREVIOUS_YEAR_YOY_LOCATION_ID),
true,
WEEKLY,
RSA_METRICS_QUERY_PARAM
);
}
public static MetricsPerLocation getMerchantWithNoDataFromCurrentOrPreviousYearYoyMonthlyMetrics() throws UnrecoverableKeyException, CertificateException, IOException, KeyStoreException, NoSuchAlgorithmException, ApiException {
Maithrie168505 marked this conversation as resolved.
Show resolved Hide resolved
return new MetricsApi(getApiClient()).getMetrics(
UUID.fromString(MERCHANT_WITH_NO_DATA_FROM_CURRENT_OR_PREVIOUS_YEAR_YOY_LOCATION_ID),
true,
WEEKLY,
RSA_METRICS_QUERY_PARAM
);
}


public static MetricsPerLocation getMerchantWithLessThan52WeeksMetrics() throws UnrecoverableKeyException, CertificateException, IOException, KeyStoreException, NoSuchAlgorithmException, ApiException {
return new MetricsApi(getApiClient()).getMetrics(
UUID.fromString(NEW_MERCHANT_WITH_LESS_THAN_52_WEEKS_LOCATION_ID),
true,
WEEKLY,
RSA_METRICS_QUERY_PARAM
);
}
public static MetricsPerLocation getMerchantWithLessThan52WeeksMonthlyMetrics() throws UnrecoverableKeyException, CertificateException, IOException, KeyStoreException, NoSuchAlgorithmException, ApiException {
Maithrie168505 marked this conversation as resolved.
Show resolved Hide resolved
return new MetricsApi(getApiClient()).getMetrics(
UUID.fromString(NEW_MERCHANT_WITH_LESS_THAN_52_WEEKS_LOCATION_ID),
true,
MONTHLY,
RSA_METRICS_QUERY_PARAM
);
}
Expand All @@ -267,32 +300,60 @@ public static MetricsPerLocation throwsMetricsNotFound() throws UnrecoverableKey
return new MetricsApi(getApiClient()).getMetrics(
UUID.fromString(MERCHANT_TOO_NEW_TO_HAVE_METRICS_LOCATION_ID),
true,
WEEKLY,
RSA_METRICS_QUERY_PARAM
);
}

public static MetricsPerLocation throwsLocationNotFound() throws UnrecoverableKeyException, CertificateException, IOException, KeyStoreException, NoSuchAlgorithmException, ApiException {
public static MetricsPerLocation throwsLocationNotFoundForWeekly() throws UnrecoverableKeyException, CertificateException, IOException, KeyStoreException, NoSuchAlgorithmException, ApiException {
return new MetricsApi(getApiClient()).getMetrics(
UUID.fromString(MERCHANT_NOT_FOUND_LOCATION_ID),
Maithrie168505 marked this conversation as resolved.
Show resolved Hide resolved
true,
WEEKLY,
RSA_METRICS_QUERY_PARAM
);
}
public static MetricsPerLocation throwsLocationNotFoundForMonthly() throws UnrecoverableKeyException, CertificateException, IOException, KeyStoreException, NoSuchAlgorithmException, ApiException {
return new MetricsApi(getApiClient()).getMetrics(
UUID.fromString(MERCHANT_NOT_FOUND_LOCATION_ID),
true,
MONTHLY,
RSA_METRICS_QUERY_PARAM
);
}

public static MetricsPerLocation throwsConsentNotProvided() throws UnrecoverableKeyException, CertificateException, IOException, KeyStoreException, NoSuchAlgorithmException, ApiException {
public static MetricsPerLocation throwsWeeklyConsentNotProvided() throws UnrecoverableKeyException, CertificateException, IOException, KeyStoreException, NoSuchAlgorithmException, ApiException {
return new MetricsApi(getApiClient()).getMetrics(
UUID.fromString(CONSENT_NOT_PROVIDED_LOCATION_ID),
false,
WEEKLY,
RSA_METRICS_QUERY_PARAM
);
}
public static MetricsPerLocation throwsMonthlyConsentNotProvided() throws UnrecoverableKeyException, CertificateException, IOException, KeyStoreException, NoSuchAlgorithmException, ApiException {
return new MetricsApi(getApiClient()).getMetrics(
UUID.fromString(CONSENT_NOT_PROVIDED_LOCATION_ID),
false,
Maithrie168505 marked this conversation as resolved.
Show resolved Hide resolved
MONTHLY,
RSA_METRICS_QUERY_PARAM
);
}

/* Full business flow use case: Matches + Metrics */

public static MetricsPerLocation getMetricsUsingMatchResults() throws UnrecoverableKeyException, CertificateException, IOException, KeyStoreException, NoSuchAlgorithmException, ApiException {
public static MetricsPerLocation getMetricsWeeklyUsingMatchResults() throws UnrecoverableKeyException, CertificateException, IOException, KeyStoreException, NoSuchAlgorithmException, ApiException {
return new MetricsApi(getApiClient()).getMetrics(
getSingleMatchByNameAndAddress().get(0).getLocationId(),
true,
WEEKLY,
RSA_METRICS_QUERY_PARAM
);
}
public static MetricsPerLocation getMetricsMonthlyUsingMatchResults() throws UnrecoverableKeyException, CertificateException, IOException, KeyStoreException, NoSuchAlgorithmException, ApiException {
return new MetricsApi(getApiClient()).getMetrics(
getSingleMatchByNameAndAddress().get(0).getLocationId(),
true,
MONTHLY,
RSA_METRICS_QUERY_PARAM
);
}
Expand All @@ -301,47 +362,75 @@ public static MetricsPerLocation getFullyPopulatedBenchmarksMetrics() throws Unr
return new MetricsApi(getApiClient()).getMetrics(
UUID.fromString(FULLY_POPULATED_BENCHMARKS_METRICS_LOCATION_ID),
true,
MONTHLY,
BENCHMARKS_METRICS_QUERY_PARAM

);
}

public static MetricsPerLocation getMerchantWithLowTransactionVolumeBenchmarksMetrics() throws UnrecoverableKeyException, CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, ApiException {
return new MetricsApi(getApiClient()).getMetrics(
UUID.fromString(MERCHANT_WITH_LOW_TRANSACTION_VOLUME_BENCHMARKS_METRICS_LOCATION_ID),
true,
MONTHLY,
BENCHMARKS_METRICS_QUERY_PARAM

);
}

public static MetricsPerLocation throwsBenchmarksMetricsNotFound() throws UnrecoverableKeyException, CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, ApiException {
return new MetricsApi(getApiClient()).getMetrics(
UUID.fromString(MERCHANT_TOO_NEW_TO_HAVE_BENCHMARKS_METRICS_LOCATION_ID),
true,
MONTHLY,
BENCHMARKS_METRICS_QUERY_PARAM

);
}

public static MetricsPerLocation throwsBenchmarksMetricsConsentNotProvided() throws UnrecoverableKeyException, CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, ApiException {
return new MetricsApi(getApiClient()).getMetrics(
UUID.fromString(CONSENT_NOT_PROVIDED_BENCHMARKS_METRICS_LOCATION_ID),
false,
MONTHLY,
BENCHMARKS_METRICS_QUERY_PARAM

);
}

public static MetricsPerLocation throwsBenchmarksMetricsLocationNotFound() throws UnrecoverableKeyException, CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, ApiException {
return new MetricsApi(getApiClient()).getMetrics(
UUID.fromString(MERCHANT_NOT_FOUND_BENCHMARKS_METRICS_LOCATION_ID),
true,
MONTHLY,
BENCHMARKS_METRICS_QUERY_PARAM

);
}

public static MetricsPerLocation getBenchmarksMetricsUsingMatchResults() throws UnrecoverableKeyException, CertificateException, IOException, KeyStoreException, NoSuchAlgorithmException, ApiException {
return new MetricsApi(getApiClient()).getMetrics(
getSingleMatchByNameAndAddress().get(0).getLocationId(),
true,
MONTHLY,
BENCHMARKS_METRICS_QUERY_PARAM

);
}
public static MetricsPerLocation getFullyPopulateMonthlyMetrics() throws UnrecoverableKeyException, CertificateException, IOException, KeyStoreException, NoSuchAlgorithmException, ApiException {
Maithrie168505 marked this conversation as resolved.
Show resolved Hide resolved
return new MetricsApi(getApiClient()).getMetrics(
UUID.fromString(FULLY_POPULATED_METRICS_LOCATION_ID),
true,
MONTHLY,
RSA_METRICS_QUERY_PARAM

);
}
public static MetricsPerLocation throwsMetricFrequencyNotFound() throws UnrecoverableKeyException, CertificateException, IOException, KeyStoreException, NoSuchAlgorithmException, ApiException {
return new MetricsApi(getApiClient()).getMetrics(
UUID.fromString(FULLY_POPULATED_METRICS_LOCATION_ID),
true,
null,
RSA_METRICS_QUERY_PARAM
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,29 @@ public static void main(String[] args) throws UnrecoverableKeyException, Certifi
try { ApiExamples.throwsInvalidCountryCodeApiException(); } catch (Exception e) { log.info(e.getMessage()); }

// Metrics examples
log.log(Level.INFO, "FullyPopulatedMetrics: {0}", ApiExamples.getFullyPopulatedMetrics());
log.log(Level.INFO, "LowTransactionVolumeMetrics: {0}", ApiExamples.getMerchantWithLowTransactionVolumeMetrics());
log.log(Level.INFO, "NoDataFromCurrentOrPreviousYearYoyMetrics: {0}", ApiExamples.getMerchantWithNoDataFromCurrentOrPreviousYearYoyMetrics());
log.log(Level.INFO, "LessThan52WeeksMetrics: {0}", ApiExamples.getMerchantWithLessThan52WeeksMetrics());
log.log(Level.INFO, "FullyPopulatedWeeklyMetrics: {0}", ApiExamples.getFullyPopulatedWeeklyMetrics());
log.log(Level.INFO, "LowTransactionVolumeWeeklyMetrics: {0}", ApiExamples.getMerchantWithLowTransactionVolumeWeeklyMetrics());
log.log(Level.INFO, "NoDataFromCurrentOrPreviousYearYoyWeeklyMetrics: {0}", ApiExamples.getMerchantWithNoDataFromCurrentOrPreviousYearYoyWeeklyMetrics());
log.log(Level.INFO, "LessThan52WeeksWeeklyMetrics: {0}", ApiExamples.getMerchantWithLessThan52WeeksMetrics());

//Monthly
log.log(Level.INFO, "LowTransactionVolumeMonthlyMetrics: {0}", ApiExamples.getMerchantWithLowTransactionVolumeMonthlyMetrics());
log.log(Level.INFO, "NoDataFromCurrentOrPreviousYearYoyMonthlyMetrics: {0}", ApiExamples.getMerchantWithNoDataFromCurrentOrPreviousYearYoyMonthlyMetrics());
log.log(Level.INFO, "LessThan52WeeksMonthlyMetrics: {0}", ApiExamples.getMerchantWithLessThan52WeeksMonthlyMetrics());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be LessThan12Months

log.log(Level.INFO, "FullyPopulatedMetrics for monthly: {0}", ApiExamples.getFullyPopulateMonthlyMetrics());


// Metrics error examples
try { ApiExamples.throwsMetricsNotFound(); } catch (Exception e) { log.info(e.getMessage()); }
try { ApiExamples.throwsLocationNotFound(); } catch (Exception e) { log.info(e.getMessage()); }
try { ApiExamples.throwsConsentNotProvided(); } catch (Exception e) { log.info(e.getMessage()); }

try { ApiExamples.throwsLocationNotFoundForWeekly(); } catch (Exception e) { log.info(e.getMessage()); }
try { ApiExamples.throwsLocationNotFoundForMonthly(); } catch (Exception e) { log.info(e.getMessage()); }
try { ApiExamples.throwsWeeklyConsentNotProvided(); } catch (Exception e) { log.info(e.getMessage()); }
try { ApiExamples.throwsMonthlyConsentNotProvided(); } catch (Exception e) { log.info(e.getMessage()); }
try { ApiExamples.throwsMetricFrequencyNotFound(); } catch (Exception e) { log.info(e.getMessage()); }
// Example business use case calling matches, then metrics
// This will return the same metrics as ApiExamples.GetFullyPopulatedMetrics()
log.log(Level.INFO, "MetricsFromMatch: {0}", ApiExamples.getMetricsUsingMatchResults());
log.log(Level.INFO, "MetricsFromMatch for Monthly : {0}", ApiExamples.getMetricsMonthlyUsingMatchResults());
log.log(Level.INFO, "MetricsFromMatch for Weekly: {0}", ApiExamples.getMetricsWeeklyUsingMatchResults());

//Benchmarks metrics examples
log.log(Level.INFO, "FullyPopulatedBenchmarksMetrics: {0}", ApiExamples.getFullyPopulatedBenchmarksMetrics());
Expand Down
17 changes: 17 additions & 0 deletions src/main/resources/small-business-credit-analytics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ paths:
- $ref: '#/components/parameters/locationIdParameter'
- $ref: '#/components/parameters/hasConsentParameter'
- $ref: '#/components/parameters/metricsTypeParameter'
- $ref: '#/components/parameters/metricsFrequencyParameter'
responses:
'200':
$ref: '#/components/responses/MetricsResponse'
Expand Down Expand Up @@ -265,6 +266,16 @@ components:
example: RSA
schema:
type: string
metricsFrequencyParameter:
name: metrics_frequency
in: query
description: >-
Metrics Frequency parameter indicates frequency of metrics to be returned.
Mandatory parameter with allowed values 'weekly' and 'monthly' case-insensitive.
example: weekly
required: true
schema:
type: string
responses:
MatchesResponse:
description: Operation was successful.
Expand Down Expand Up @@ -426,6 +437,12 @@ components:
The date of the last Mastercard transaction processed for this
merchant.
example: '2022-01-13'
metricsFrequency:
type: string
description: >-
Metrics Frequency parameter indicates frequency of metrics to be returned.
Mandatory parameter with allowed values 'weekly' and 'monthly' case-insensitive.
example: weekly
metricsLists:
type: array
description: >-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
public class MatchesAndMetricsApiTest {
@Test
public void getMetricsFromMatchesTest() throws ApiException, UnrecoverableKeyException, CertificateException, IOException, KeyStoreException, NoSuchAlgorithmException {
Assert.assertNotNull(ApiExamples.getMetricsUsingMatchResults());
Assert.assertNotNull(ApiExamples.getMetricsMonthlyUsingMatchResults());
Assert.assertNotNull(ApiExamples.getMetricsWeeklyUsingMatchResults());
Assert.assertNotNull(ApiExamples.getBenchmarksMetricsUsingMatchResults());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,21 @@
public class MetricsApiTest {
@Test
public void getMetricsTest() throws ApiException, UnrecoverableKeyException, CertificateException, IOException, KeyStoreException, NoSuchAlgorithmException {
Assert.assertNotNull(ApiExamples.getFullyPopulatedMetrics());
Assert.assertNotNull(ApiExamples.getMerchantWithLowTransactionVolumeMetrics());
Assert.assertNotNull(ApiExamples.getMerchantWithNoDataFromCurrentOrPreviousYearYoyMetrics());
Assert.assertNotNull(ApiExamples.getMerchantWithLessThan52WeeksMetrics());
Assert.assertNotNull(ApiExamples.getFullyPopulatedWeeklyMetrics());

Assert.assertNotNull(ApiExamples.getFullyPopulateMonthlyMetrics());
Assert.assertNotNull(ApiExamples.getMerchantWithLowTransactionVolumeMonthlyMetrics());
Assert.assertNotNull(ApiExamples.getMerchantWithLowTransactionVolumeWeeklyMetrics());
Assert.assertNotNull(ApiExamples.getMerchantWithNoDataFromCurrentOrPreviousYearYoyMonthlyMetrics());
Assert.assertNotNull(ApiExamples.getMerchantWithNoDataFromCurrentOrPreviousYearYoyWeeklyMetrics());
Assert.assertNotNull(ApiExamples.getMerchantWithLessThan52WeeksMetrics());
Assert.assertNotNull(ApiExamples.getMerchantWithLessThan52WeeksMonthlyMetrics());
Assert.assertThrows(ApiException.class, ApiExamples::throwsMetricsNotFound);
Assert.assertThrows(ApiException.class, ApiExamples::throwsLocationNotFound);
Assert.assertThrows(ApiException.class, ApiExamples::throwsConsentNotProvided);

Assert.assertThrows(ApiException.class, ApiExamples::throwsLocationNotFoundForMonthly);
Assert.assertThrows(ApiException.class, ApiExamples::throwsLocationNotFoundForWeekly);
Assert.assertThrows(ApiException.class, ApiExamples::throwsMonthlyConsentNotProvided);
Assert.assertThrows(ApiException.class, ApiExamples::throwsWeeklyConsentNotProvided);
Assert.assertThrows(ApiException.class, ApiExamples::throwsMetricFrequencyNotFound);
//Benchmarks metrics test cases
Assert.assertNotNull(ApiExamples.getFullyPopulatedBenchmarksMetrics());
Assert.assertNotNull(ApiExamples.getMerchantWithLowTransactionVolumeBenchmarksMetrics());
Expand Down