Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=Mastercard_promotions-digital-enablement-reference-app
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:3.2:sonar -Dsonar.projectKey=Mastercard_promotions-digital-enablement-reference-app
8 changes: 6 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<sonar.organization>mastercard</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>

<java.version>1.8</java.version>
<java.version>11</java.version>
<openapi-generator.version>5.4.0</openapi-generator.version>
<oauth1-signer.version>1.5.1</oauth1-signer.version>
<client-encryption.version>1.7.1</client-encryption.version>
Expand Down Expand Up @@ -140,6 +140,10 @@
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>

</dependencies>

Expand Down Expand Up @@ -181,4 +185,4 @@
</plugins>
</build>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import lombok.extern.slf4j.Slf4j;
import org.openapitools.client.ApiException;
import org.openapitools.client.model.AccountSearch;
import org.openapitools.client.model.PagedResponseOfAccountSearch;
import org.openapitools.client.model.PagedAccountSearchItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PostMapping;
Expand Down Expand Up @@ -68,12 +68,12 @@ public AccountController(AccountValidator accountValidator, AccountService accou
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Successfully Retrieved Account")
})
public PagedResponseOfAccountSearch searchAccount(@RequestParam(value = "offset", required = false, defaultValue = "0") int offset,
public PagedAccountSearchItem searchAccount(@RequestParam(value = "offset", required = false, defaultValue = "0") int offset,
@RequestParam(value = "limit", required = false, defaultValue = "25") int limit,
@RequestBody AccountSearch accountSearch) {
accountValidator.validateSearchAccount(accountSearch);
try {
PagedResponseOfAccountSearch response = accountService.searchAccount(offset, limit, accountSearch);
PagedAccountSearchItem response = accountService.searchAccount(offset, limit, accountSearch);
if (response != null && response.getItems() != null) {
log.debug("Method : searchAccount, Message :Successfully got the accounts" + response);
return response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.UUID;

@Slf4j
@RestController
Expand Down Expand Up @@ -74,7 +75,13 @@ public ResponseEntity<Void> promotionOptIn(@RequestBody List<OptIn> optInCreateV
* @throws InvalidRequest If fail to validate input values and serialize the request body object
*/
@GetMapping(value = "/promotions")
public Promotions getPromotions(@RequestParam(name = "rewardsCompanyId", required = false) String rewardsCompanyId, @RequestParam(name = "programId", required = false) String programId, @RequestParam(name = "promotionId", required = false) String promotionId, @RequestParam(name = "accountId", required = false) String accountId, @RequestParam(name = "promotion_state", required = false) String promotionState, @RequestParam(name = "offset", required = false, defaultValue = "0") Integer offset, @RequestParam(name = "limit", required = false, defaultValue = "25") Integer limit) {
public Promotions getPromotions(@RequestParam(name = "rewardsCompanyId", required = false) UUID rewardsCompanyId,
@RequestParam(name = "programId", required = false) UUID programId,
@RequestParam(name = "promotionId", required = false) UUID promotionId,
@RequestParam(name = "accountId", required = false) UUID accountId,
@RequestParam(name = "promotion_state", required = false) String promotionState,
@RequestParam(name = "offset", required = false, defaultValue = "0") Integer offset,
@RequestParam(name = "limit", required = false, defaultValue = "25") Integer limit) {
optInValidator.validateGetPromotions(rewardsCompanyId, programId, promotionId, accountId);
try {
log.info("Method : getActivePromotions, Message : Getting promotions");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@Slf4j
@RestController
@RequestMapping(value = "", produces = {"application/json"})
Expand All @@ -35,9 +37,9 @@ public ProgressController(ProgressValidator progressValidator, ProgressService p
* @return
*/
@GetMapping(value = "/promotion-progresses")
public PromotionProgressList getProgress(@RequestParam(value = "household_id", required = false) String householdId,
@RequestParam(value = "account_id", required = false) String accountId,
@RequestParam(value = "promotion_id", required = false) String promotionID,
public PromotionProgressList getProgress(@RequestParam(value = "household_id", required = false) UUID householdId,
@RequestParam(value = "account_id", required = false) UUID accountId,
@RequestParam(value = "promotion_id", required = false) UUID promotionID,
@RequestParam(value = "include_history", required = false, defaultValue = "false") boolean includeHistory) {
progressValidator.validateGetProgress(householdId, accountId);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@Slf4j
@RestController
@RequestMapping(value = "", produces = {"application/json"})
Expand All @@ -35,7 +37,7 @@ public PromotionDetailController(OptInService optInService) {
* @throws InvalidRequest If fail to validate input values and serialize the request body object
*/
@GetMapping(value = "/promotions/{id}/details")
public PromotionDetail getPromotionDetails(@PathVariable(value = "id") String promotionId) {
public PromotionDetail getPromotionDetails(@PathVariable(value = "id") UUID promotionId) {
try {
log.info("Method : getPromotionDetails, Message : Getting promotions");
PromotionDetail response = optInService.getPromotionDetail(promotionId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
import com.mastercard.developer.validator.TransactionValidator;
import lombok.extern.slf4j.Slf4j;
import org.openapitools.client.ApiException;
import org.openapitools.client.model.PagedResponseGetTransactionDto;
import org.openapitools.client.model.PagedTransaction;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.UUID;

@Slf4j
@RestController
@RequestMapping(value = "", produces = {"application/json"})
Expand All @@ -37,18 +40,18 @@ public TransactionController(TransactionValidator transactionValidator, Transact
* @return
*/
@GetMapping(value = "/transactions")
public PagedResponseGetTransactionDto getTransactions(@RequestParam(name = "account_id", required = false) String accountId,
@RequestParam(name = "from_date", required = false) String fromDate,
@RequestParam(name = "to_date", required = false) String toDate,
@RequestParam(name = "promotion_id", required = false) String promotionId,
public PagedTransaction getTransactions(@RequestParam(name = "account_id", required = false) UUID accountId,
@RequestParam(name = "from_date", required = false) LocalDate fromDate,
@RequestParam(name = "to_date", required = false) LocalDate toDate,
@RequestParam(name = "promotion_id", required = false) UUID promotionId,
@RequestParam(value = "offset", required = false, defaultValue = "0") int offset,
@RequestParam(value = "limit", required = false, defaultValue = "25") int limit) {
transactionValidator.validateTransactionRequest(accountId);
transactionValidator.validateTransactionDates(fromDate, toDate, 13);
transactionValidator.validatePaginationParams(offset, limit);
try {
log.info("Method : getTransactions, Message : Getting transactions");
PagedResponseGetTransactionDto response = transactionService.getTransactions(accountId, fromDate, toDate, promotionId, offset, limit);
PagedTransaction response = transactionService.getTransactions(accountId, fromDate, toDate, promotionId, offset, limit);
if (response != null) {
log.debug("Method : getTransactions, Message :Successfully got the transactions" + response);
return response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.openapitools.client.ApiException;
import org.openapitools.client.api.AccountManagementApi;
import org.openapitools.client.model.AccountSearch;
import org.openapitools.client.model.PagedResponseOfAccountSearch;
import org.openapitools.client.model.PagedAccountSearchItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

Expand All @@ -20,7 +20,7 @@ public AccountService(ApiClient cryptoApiClient) {
this.accountManagementApi = new AccountManagementApi(cryptoApiClient);
}

public PagedResponseOfAccountSearch searchAccount(Integer offset, Integer limit, AccountSearch accountSearch) throws ApiException {
return this.accountManagementApi.searchAccount(offset, limit, accountSearch);
public PagedAccountSearchItem searchAccount(Integer offset, Integer limit, AccountSearch accountSearch) throws ApiException {
return this.accountManagementApi.searchAccount(accountSearch, offset, limit);
}
}
11 changes: 6 additions & 5 deletions src/main/java/com/mastercard/developer/service/OptInService.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Slf4j
@Service
Expand All @@ -24,15 +25,15 @@ public OptInService(ApiClient apiClient) {
}

public void optIn(List<OptIn> optInCreateValueBeanList) throws ApiException {
promotionManagementApi.promotionOptInUsingPOST(optInCreateValueBeanList);
promotionManagementApi.postPromotionOptIn(optInCreateValueBeanList);
}

public Promotions getActivePromotions(String businessPartnerReferenceId, String programReferenceId, String promotionId, String accountId, String promotionState, Integer offset, Integer limit) throws ApiException {
return promotionManagementApi.getPromotionsUsingGET(businessPartnerReferenceId, programReferenceId, promotionId, accountId, promotionState, offset, limit);
public Promotions getActivePromotions(UUID businessPartnerReferenceId, UUID programReferenceId, UUID promotionId, UUID accountId, String promotionState, Integer offset, Integer limit) throws ApiException {
return promotionManagementApi.getPromotions(businessPartnerReferenceId, programReferenceId, promotionId, accountId, promotionState, offset, limit);
}

public PromotionDetail getPromotionDetail(String promotionId) throws ApiException {
return promotionManagementApi.getPromotionDetailsUsingGET(promotionId);
public PromotionDetail getPromotionDetail(UUID promotionId) throws ApiException {
return promotionManagementApi.getPromotionDetails(promotionId);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.openapitools.client.model.PromotionProgressList;
import org.springframework.stereotype.Service;

import java.util.UUID;

@Slf4j
@Service
public class ProgressService {
Expand All @@ -18,8 +20,8 @@ public ProgressService(ApiClient apiClient) {
this.promotionProgressApi = new PromotionProgressApi(apiClient);
}

public PromotionProgressList getProgress(String householdId, String accountId, String promotionId, Boolean includeHistory) throws ApiException {
return promotionProgressApi.retrieveUsingGET(householdId, accountId, promotionId, includeHistory);
public PromotionProgressList getProgress(UUID householdId, UUID accountId, UUID promotionId, Boolean includeHistory) throws ApiException {
return promotionProgressApi.getPromotionProgress(householdId, accountId, promotionId, includeHistory);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
import org.openapitools.client.ApiClient;
import org.openapitools.client.ApiException;
import org.openapitools.client.api.TransactionsApi;
import org.openapitools.client.model.PagedResponseGetTransactionDto;
import org.openapitools.client.model.PagedTransaction;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.UUID;

@Slf4j
@Service
public class TransactionService {
Expand All @@ -16,8 +19,8 @@ public TransactionService(ApiClient apiClient) {
this.transactionApi = new TransactionsApi(apiClient);
}

public PagedResponseGetTransactionDto getTransactions(String accountId, String fromDate, String toDate, String promotionId, Integer offset, Integer limit) throws ApiException {
return transactionApi.getTransactionsUsingGET(accountId, fromDate, toDate, promotionId, offset, limit);
public PagedTransaction getTransactions(UUID accountId, LocalDate fromDate, LocalDate toDate, UUID promotionId, Integer offset, Integer limit) throws ApiException {
return transactionApi.getTransactions(accountId, fromDate, toDate, promotionId, offset, limit);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@Component
public class OptInValidator {
Expand All @@ -17,7 +18,7 @@ public void validateCreate(List<OptIn> optIns) {
if (optIn.getActivation() == (null)) {
messages.add("activation cannot be null");
}
if (messages.isEmpty() && !StringUtils.hasText(optIn.getPromotionId())) {
if (messages.isEmpty() && null == optIn.getPromotionId()) {
messages.add("promotionId cannot be null");
}
}
Expand All @@ -26,10 +27,10 @@ public void validateCreate(List<OptIn> optIns) {
}
}

public void validateGetPromotions(String rewardsCompanyId, String programReferenceId, String promotionId, String userId) {
public void validateGetPromotions(UUID rewardsCompanyId, UUID programReferenceId, UUID promotionId, UUID userId) {
List<String> messages = new ArrayList<>();
if (!StringUtils.hasText(rewardsCompanyId) && !StringUtils.hasText(programReferenceId) && !StringUtils.hasText(promotionId)) {
if (!StringUtils.hasText(userId)) {
if (null == rewardsCompanyId && null == programReferenceId && null ==promotionId) {
if (null == userId) {
messages.add("Either the rewardsCompanyId or programId or promotionId or accountId must be provided");
} else {
messages.add("Either the rewardsCompanyId, programId or promotionId must be provided");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@Component
public class ProgressValidator {

public void validateGetProgress(String householdId, String accountId) {
public void validateGetProgress(UUID householdId, UUID accountId) {
List<String> messages = new ArrayList<>();
if (!StringUtils.hasText(householdId) && !StringUtils.hasText(accountId)) {
if (null == householdId && null == accountId) {
messages.add("household_id or account_id is missing");
}
if (!messages.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,35 @@
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@Component
public class TransactionValidator {

static Map<String, SimpleDateFormat> sdfMap = new HashMap();

public void validateTransactionRequest(String accountId) {
if (!StringUtils.hasText(accountId)) {
public void validateTransactionRequest(UUID accountId) {
if (null == accountId) {
throw new InvalidRequest(ErrorCodes.INVALID_INPUT.code, "account_id is missing");
}

}

public void validateTransactionDates(String fromDateAsString, String toDateAsString, int maxDuration) {
if (fromDateAsString == null && toDateAsString == null) {
public void validateTransactionDates(LocalDate fromDate, LocalDate toDate, int maxDuration) {
if (fromDate == null && toDate == null) {
return;
}
try {
Date fromDate = convertStringToDate("yyyy-MM-dd", fromDateAsString);
Date toDate = convertStringToDate("yyyy-MM-dd", toDateAsString);

if (fromDate == null) {
fromDate = getFromDate(fromDateAsString, maxDuration);
}

if (fromDate != null && toDate != null && toDate.compareTo(fromDate) < 0) {
throw new InvalidRequest(HttpStatus.BAD_REQUEST.toString(), "Invalid Date Range");
}
} catch (ParseException ex) {
throw new InvalidRequest(HttpStatus.BAD_REQUEST.toString(),
"Invalid Date Format. Acceptable Date format is YYYY-MM-DD");

if (fromDate == null) {
fromDate = getFromDate(fromDate, maxDuration);
}

if (fromDate != null && toDate != null && toDate.compareTo(fromDate) < 0) {
throw new InvalidRequest(HttpStatus.BAD_REQUEST.toString(), "Invalid Date Range");
}

if (fromDate != null && toDate != null && toDate.isBefore(fromDate)) {
throw new InvalidRequest(HttpStatus.BAD_REQUEST.toString(), "Invalid Date Range");
}
}

Expand All @@ -54,19 +52,11 @@ public void validatePaginationParams(int offset, int limit) {
}
}

public static Date getFromDate(String fromDateAsString, int maxDuration) {
Date fromDate = null;
public static LocalDate getFromDate(LocalDate fromDate, int maxDuration) {

try {
fromDate = convertStringToDate("yyyy-MM-dd", fromDateAsString);
if (fromDate == null || fromDate.compareTo(Date.from(LocalDate.now().minusMonths((long) maxDuration).atStartOfDay(ZoneId.systemDefault()).toInstant())) < 0) {
fromDate = Date.from(LocalDate.now().minusMonths((long) maxDuration).atStartOfDay(ZoneId.systemDefault()).toInstant());
}
fromDate = LocalDate.now().minusMonths(maxDuration);

return fromDate;
} catch (ParseException var4) {
return null;
}
return fromDate;
}

public static Date convertStringToDate(String dateFormat, String date) throws ParseException {
Expand Down
Loading