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

feat: Completed revision on terminal api #20

Merged
merged 8 commits into from
Aug 2, 2024
Merged
3 changes: 2 additions & 1 deletion .github/workflows/post-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ jobs:
--env-var "clientSecretPsp=${{ secrets.NEWMAN_IT_PA_TOKEN_CLIENT_SECRET }}" \
--env-var "clientIdPa=${{ secrets.NEWMAN_IT__PSP_TOKEN_CLIENT_ID }}" \
--env-var "clientSecretPa=${{ secrets.NEWMAN_IT_PSP_TOKEN_CLIENT_SECRET }}" \
--env-var "filePathBulkload=${{ secrets.MIL_PAPOS_BULKLOAD_FILE_PATH }}"
--env-var "clientIdAdm=${{ secrets.NEWMAN_IT__PAPOS_ADMIN_TOKEN_CLIENT_ID }}" \
--env-var "clientSecretAdm=${{ secrets.NEWMAN_IT_PAPOS_ADMIN_TOKEN_CLIENT_SECRET }}"

#
# STABLE - Update of pom.xml with the new version.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
public class BulkLoadStatusEntity extends PanacheMongoEntity {

private String bulkLoadingId;
private String pspId;
private int totalRecords;
private int successRecords;
private int failedRecords;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@ToString
public class BulkLoadStatus {
private String bulkLoadingId;
private String pspId;
private int totalRecords;
private int successRecords;
private int failedRecords;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,13 @@ public Uni<Response> createSolution(
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({ "mil_papos_admin" })
public Uni<Response> getSolutions(
@HeaderParam("RequestId") @NotNull(message = ErrorCodes.ERROR_REQUESTID_MUST_NOT_BE_NULL_MSG) @Pattern(regexp = RegexPatterns.REQUEST_ID_PATTERN) String requestId,
@HeaderParam("RequestId") @NotNull(message = ErrorCodes.ERROR_REQUESTID_MUST_NOT_BE_NULL_MSG)
@Pattern(regexp = RegexPatterns.REQUEST_ID_PATTERN) String requestId,
@QueryParam("page") int pageNumber,
@QueryParam("size") int pageSize) {

Log.debugf("SolutionResource -> getSolutions - Input requestId, pageNumber, pageSize: %s, %s, %s", requestId, pageNumber, pageSize);

return solutionService
.getSolutionsCount()
.onFailure()
Expand All @@ -91,7 +94,7 @@ public Uni<Response> getSolutions(
.transformToUni(numberOfSolutions -> {
Log.debugf("SolutionResource -> findAll: found a total count of [%s] solutions", numberOfSolutions);

return solutionService.findSolutions(requestId, pageNumber, pageSize)
return solutionService.findSolutions(pageNumber, pageSize)
.onFailure()
.transform(err -> {
Log.errorf(err,
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,20 @@ public Uni<SolutionEntity> createSolution(SolutionDto solutionDto) {
.onItem()
.transform(solutionSaved -> solutionSaved);
}
/**

/**
* Find all the solutions.
*
* @param requestId
* @param pageNumber 0-based page index
* @param pageSize page size
* @return Solutions found
*/
public Uni<List<SolutionEntity>> findSolutions(String requestId, int pageNumber, int pageSize) {
Log.debugf("SolutionService -> findSolutions - Input requestId: %s, pageNumber: %s, size: %s", requestId, pageNumber, pageSize);
return solutionRepository.findAll().page(pageNumber,pageSize).list();
public Uni<List<SolutionEntity>> findSolutions(int pageNumber, int pageSize) {
Log.debugf("SolutionService -> findSolutions - Input pageNumber: %s, size: %s", pageNumber, pageSize);

return solutionRepository.findAll()
.page(pageNumber, pageSize)
.list();
}

/**
Expand All @@ -62,8 +66,6 @@ public Uni<SolutionEntity> findById(String solutionId) {
return solutionRepository.findById(new ObjectId(solutionId));
}



/**
* Delete solution starting from a solutionEntity.
*
Expand All @@ -80,19 +82,17 @@ public Uni<Void> deleteSolution(SolutionEntity solution) {
.transform(solutionDeleted -> solutionDeleted);
}


/**
* Returns a number corresponding to the total number of solutions found.
*
* @return a number
*/
public Uni<Long> getSolutionsCount() {
Log.debugf("SolutionService -> getSolutionsCount");

return solutionRepository.count();
}


/**
* Returns a number corresponding to the total number of solutions found.
*
Expand All @@ -106,7 +106,7 @@ public Uni<Long> getSolutionCountByAttribute(String attributeName, String attrib
return solutionRepository.count(attributeName, attributeValue);
}

/**
/**
* Returns a list of solutions paginated. The query filters on attributeName.
*
* @param attributeName string representing the name of attribute to be filtered
Expand All @@ -124,4 +124,46 @@ public Uni<List<SolutionEntity>> getSolutionsListPagedByAttribute(String attribu
.list();
}

/**
* Returns a list of solutions. The query filters on locationCode.
*
* @param locationCode of the solution to be filtered
* @return a list of solutions
*/
public Uni<List<SolutionEntity>> getSolutionsListByLocationCode(String locationCode) {
Log.debugf("SolutionService -> getSolutionsListByLocationCode - Input parameters: %s", locationCode);

return solutionRepository
.find("locationCode = ?1", locationCode)
.list();
}

/**
* Find all solution equals to attributeValue given in input.
*
* @param attributeName string representing the name of attribute to be filtered
* @param attributeValue value of attribute
* @return list of Solution found
*/
public Uni<List<SolutionEntity>> findAllByLocationOrPsp(String attributeName, String attributeValue) {
Log.debugf("SolutionService -> findAllByLocationOrPsp - Input parameters: [%s, %s]", attributeName, attributeValue);

return solutionRepository.list(String.format("%s = ?1", attributeName), attributeValue);
}

/**
* Find all solution equals to pspId and solutionId given in input.
*
* @param pspId ID of the POS service provider
* @param solutionIds id of the solution
* @return list of Solution found
*/
public Uni<List<SolutionEntity>> findAllByPspAndSolutionId(String pspId, List<String> solutionIds) {
Log.debugf("SolutionService -> findAllByPspAndSolutionId - Input parameters: [%s, %s]", pspId, solutionIds);
List<ObjectId> solutionObjectIds = solutionIds.stream()
.map(ObjectId::new)
.toList();

return solutionRepository.list("pspId = ?1 and _id in ?2", pspId, solutionObjectIds);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ public Uni<TerminalEntity> createTerminal(TerminalDto terminalDto) {
* @param terminalRequests file json containing a set of terminals
* @return list of terminal created
*/
public Uni<BulkLoadStatusEntity> processBulkLoad(List<TerminalDto> terminalRequests) {
public Uni<BulkLoadStatusEntity> processBulkLoad(List<TerminalDto> terminalRequests, int totalRecords, String pspId) {
Log.debugf("TerminalService -> processBulkLoad - Input parameters: file content length: %d bytes", terminalRequests.size());

String bulkLoadingId = Utility.generateRandomUuid();
BulkLoadStatus bulkLoadStatus = new BulkLoadStatus(bulkLoadingId, 0);

bulkLoadStatus.setTotalRecords(terminalRequests.size());
BulkLoadStatus bulkLoadStatus = new BulkLoadStatus(bulkLoadingId, totalRecords);
bulkLoadStatus.setFailedRecords(totalRecords - terminalRequests.size());
bulkLoadStatus.setPspId(pspId);
List<Uni<Void>> terminalCreationUnis = new ArrayList<>();

for (TerminalDto terminal : terminalRequests) {
Expand Down Expand Up @@ -112,39 +112,28 @@ public Uni<BulkLoadStatusEntity> findBulkLoadStatus(String bulkLoadingId) {
/**
* Returns a number corresponding to the total number of terminal found.
*
* @param attributeName name of the attribute
* @param attributeValue value of the attribute
* @param workstation name of workstation
* @return a number
*/
public Uni<Long> getTerminalCountByAttribute(String attributeName, String attributeValue) {
Log.debugf("TerminalService -> getTerminalCountByAttribute - Input parameters: %s, %s", attributeName, attributeValue);
public Uni<Long> getTerminalCountByWorkstation(String workstation, List<String> solutionIds) {
Log.debugf("TerminalService -> getTerminalCountByWorkstation - Input parameter: %s", workstation);

if (attributeName.equals("workstation")) {
return terminalRepository.count("{ 'workstations': ?1 }", attributeValue);
}
return terminalRepository.count(attributeName, attributeValue);
return terminalRepository.count("workstations = ?1 and solutionId in ?2", workstation, solutionIds);
}

/**
* Returns a list of terminals paginated. The query filters on attributeName.
*
* @param attributeName string representing the name of attribute to be filtered
* @param attributeValue value of attribute
* @param pageIndex 0-based page index
* @param pageSize page size
* @param workstation name of workstation
* @param pageIndex 0-based page index
* @param pageSize page size
* @return a list of terminals
*/
public Uni<List<TerminalEntity>> getTerminalListPagedByAttribute(String attributeName, String attributeValue, int pageIndex, int pageSize) {
Log.debugf("TerminalService -> getTerminalListPagedByAttribute - Input parameters: %s, %s, %s, %s", attributeName, attributeValue, pageIndex, pageSize);

if (attributeName.equals("workstation")) {
return terminalRepository
.find("{ 'workstations': ?1 }", attributeValue)
.page(pageIndex, pageSize)
.list();
}
public Uni<List<TerminalEntity>> getTerminalListPagedByWorkstation(String workstation, int pageIndex, int pageSize, List<String> solutionIds) {
Log.debugf("TerminalService -> getTerminalListPagedByWorkstation - Input parameters: %s, %s, %s, %s", workstation, pageIndex, pageSize, solutionIds);

return terminalRepository
.find(String.format("%s = ?1", attributeName), attributeValue)
.find("workstations = ?1 and solutionId in ?2", workstation, solutionIds)
.page(pageIndex, pageSize)
.list();
}
Expand Down Expand Up @@ -219,6 +208,28 @@ public Uni<Void> deleteTerminal(TerminalEntity terminal) {
.transform(terminalDeleted -> terminalDeleted);
}

/**
* Returns a number corresponding to the total number of terminal found.
*
* @param solutionIds list of Solution
* @return a number
*/
public Uni<Long> countBySolutionIds(List<String> solutionIds) {
return terminalRepository.count("solutionId in (?1)", solutionIds);
}

/**
* Find all terminal equals to solutionIds given in input.
*
* @param solutionIds list of Solution
* @return Solutions found
*/
public Uni<List<TerminalEntity>> findBySolutionIds(List<String> solutionIds, int pageIndex, int pageSize) {
return terminalRepository.find("solutionId in ?1", solutionIds)
.page(pageIndex, pageSize)
.list();
}

private TerminalEntity createTerminalEntity(TerminalDto terminalDto, String terminalUuid) {
Log.debugf("TerminalService -> createTerminalEntity: storing terminal [%s] on DB", terminalDto);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ private ErrorCodes() {
public static final String ERROR_AMOUNT_MUST_NOT_BE_NULL = MODULE_ID + "000017";
public static final String ERROR_STATUS_MUST_NOT_BE_NULL = MODULE_ID + "000018";
public static final String ERROR_SOLUTIONID_MUST_NOT_BE_NULL = MODULE_ID + "000019";


/*
* Service errors code from 000200 to 000500
Expand All @@ -50,7 +49,7 @@ private ErrorCodes() {
public static final String ERROR_SOLUTION_NOT_FOUND = MODULE_ID + "000211";
public static final String ERROR_LIST_SOLUTIONS = MODULE_ID + "000212";
public static final String ERROR_COUNTING_SOLUTIONS = MODULE_ID + "000213";

public static final String ERROR_NO_SOLUTIONS_FOUND = MODULE_ID + "000214";

/*
* Error descriptions
Expand Down Expand Up @@ -89,8 +88,8 @@ private ErrorCodes() {
private static final String ERROR_SOLUTION_NOT_FOUND_DESCR = "solution not found on db";
private static final String ERROR_LIST_SOLUTIONS_DESCR = "error occurred while retrieving list of paginated solutions";
private static final String ERROR_COUNTING_SOLUTIONS_DESCR = "error occurred while counting solutions";


private static final String ERROR_NO_SOLUTIONS_FOUND_DESCR = "no solutions found with given pspId and solutionIds";
private static final String ERROR_NO_SOLUTIONS_FOUND_PAYEE_DESCR = "no solutions found with given payeeCode";

/*
* Error complete message
Expand Down Expand Up @@ -129,6 +128,7 @@ private ErrorCodes() {
public static final String ERROR_SOLUTION_NOT_FOUND_MSG = "[" + ERROR_SOLUTION_NOT_FOUND + "] " + ERROR_SOLUTION_NOT_FOUND_DESCR;
public static final String ERROR_LIST_SOLUTIONS_MSG = "[" + ERROR_LIST_SOLUTIONS + "] " + ERROR_LIST_SOLUTIONS_DESCR;
public static final String ERROR_COUNTING_SOLUTIONS_MSG = "[" + ERROR_COUNTING_SOLUTIONS + "] " + ERROR_COUNTING_SOLUTIONS_DESCR;

public static final String ERROR_NO_SOLUTIONS_FOUND_MSG = "[" + ERROR_NO_SOLUTIONS_FOUND + "] " + ERROR_NO_SOLUTIONS_FOUND_DESCR;
public static final String ERROR_NO_SOLUTIONS_FOUND_PAYEE_MSG = "[" + ERROR_NO_SOLUTIONS_FOUND + "] " + ERROR_NO_SOLUTIONS_FOUND_PAYEE_DESCR;

}
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void testFindAll_200() {
Mockito.when(solutionService.getSolutionsCount())
.thenReturn(Uni.createFrom().item(10L));

Mockito.when(solutionService.findSolutions(anyString(), anyInt(), anyInt()))
Mockito.when(solutionService.findSolutions(anyInt(), anyInt()))
.thenReturn(Uni.createFrom().item(new ArrayList<>()));

Response response = given()
Expand Down Expand Up @@ -189,7 +189,7 @@ void testFindSolutionsEndpoint_500TLP() {
Mockito.when(solutionService.getSolutionsCount())
.thenReturn(Uni.createFrom().item(10L));

Mockito.when(solutionService.findSolutions(anyString(), anyInt(), anyInt()))
Mockito.when(solutionService.findSolutions(anyInt(), anyInt()))
.thenReturn(Uni.createFrom().failure(new WebApplicationException()));

Response response = given()
Expand Down
Loading
Loading