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

feature(chore):985 added filter mechanism to filter for notifiations … #1123

Merged
merged 2 commits into from
Jun 27, 2024
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ _**For better traceability add the corresponding GitHub issue number in each cha
- XXX updated local deployment documentation
- #1037 extended autocomplete api by contractAgreementId
- #985 Added function to save Contracts based on notification contractAgreementIds into the database
- #985 Added function to filter notifications for contractAgreementIds

### Added
- #832 added policymanagement list view, creator and editor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ public class ContractFieldMapper extends BaseRequestFieldMapper {
private static final Map<String, String> SUPPORTED_CONTRACT_FILTER_FIELDS = Map.ofEntries(
Map.entry("created", "created"),
Map.entry("id", "id"),
Map.entry("contractId", "contractAgreementId")
);
Map.entry("contractId", "contractAgreementId"),
Map.entry("contractType", "type")
);

@Override
protected Map<String, String> getSupportedFields() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
@PreAuthorize("hasAnyRole('ROLE_ADMIN', 'ROLE_SUPERVISOR')")
@Tag(name = "Contracts")
@RequestMapping(path = "/contracts", produces = "application/json", consumes = "application/json")
public class ContractController {
public class ContractsController {
private final ContractService contractService;

@Operation(operationId = "contracts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class NotificationFieldMapper extends BaseRequestFieldMapper {
Map.entry("sendToName", "messages_sendToName"),
Map.entry("targetDate", "targetDate"),
Map.entry("assetId", "assets_id"),
Map.entry("contractAgreementId", "messages_contractAgreementId"),
Map.entry("title", "title"),
Map.entry("type", "type")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,20 @@
package org.eclipse.tractusx.traceability.integration.common.support;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.restassured.common.mapper.TypeRef;
import io.restassured.http.ContentType;
import io.restassured.http.Header;
import io.restassured.response.Response;
import io.restassured.response.ResponseBody;
import lombok.RequiredArgsConstructor;
import notification.request.EditNotificationRequest;
import notification.request.StartNotificationRequest;
import notification.response.NotificationResponse;
import org.eclipse.tractusx.traceability.common.model.PageResult;
import org.eclipse.tractusx.traceability.common.request.OwnPageable;
import org.eclipse.tractusx.traceability.common.request.PageableFilterRequest;
import org.eclipse.tractusx.traceability.common.request.SearchCriteriaRequestParam;
import org.hamcrest.Matchers;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;

import static io.restassured.RestAssured.given;
import static org.eclipse.tractusx.traceability.common.security.JwtRole.SUPERVISOR;

@Component
@RequiredArgsConstructor
Expand Down Expand Up @@ -84,18 +75,19 @@ public void editNotificationRequest(Header authHeader, EditNotificationRequest e
.statusCode(expectedStatusCode);
}

public PageResult<NotificationResponse> getNotificationsRequest(Header authHeader){
public PageResult<NotificationResponse> getNotificationsRequest(Header authHeader, PageableFilterRequest pageableFilterRequest) {
Response response = given()
.header(authHeader)
.body(new PageableFilterRequest(new OwnPageable(0, 10, Collections.emptyList()), new SearchCriteriaRequestParam(List.of("channel,EQUAL,SENDER,AND"))))
.body(pageableFilterRequest)
.contentType(ContentType.JSON)
.when()
.post("/api/notifications/filter")
.then()
.statusCode(200)
.extract().response();

return response.as(new TypeRef<PageResult<NotificationResponse>>() {});
return response.as(new TypeRef<PageResult<NotificationResponse>>() {
});

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,22 @@
import io.restassured.common.mapper.TypeRef;
import io.restassured.http.ContentType;
import org.eclipse.tractusx.traceability.common.model.PageResult;
import org.eclipse.tractusx.traceability.common.request.OwnPageable;
import org.eclipse.tractusx.traceability.common.request.PageableFilterRequest;
import org.eclipse.tractusx.traceability.common.request.SearchCriteriaRequestParam;
import org.eclipse.tractusx.traceability.integration.IntegrationTestSpecification;
import org.eclipse.tractusx.traceability.integration.common.support.AssetsSupport;
import org.eclipse.tractusx.traceability.integration.common.support.EdcSupport;
import org.jose4j.lang.JoseException;
import org.junit.Ignore;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

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

import static io.restassured.RestAssured.given;
import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.tractusx.traceability.common.security.JwtRole.ADMIN;

class ContractControllerIT extends IntegrationTestSpecification {
class ContractsControllerIT extends IntegrationTestSpecification {

@Autowired
AssetsSupport assetsSupport;
Expand Down Expand Up @@ -98,6 +95,32 @@ void shouldReturnOnlyOneContract() throws JoseException {
assertThat(contractResponsePageResult.content().get(0).getCounterpartyAddress()).isNotEmpty();
}

@Test
void shouldReturnContractsWithNotificationType() throws JoseException {
//GIVEN
edcSupport.edcWillReturnOnlyOneContractAgreement();
edcSupport.edcWillReturnContractAgreementNegotiation();
assetsSupport.defaultAssetsStored();

//WHEN
PageResult<ContractResponse> contractResponsePageResult = given()
.header(oAuth2Support.jwtAuthorization(ADMIN))
.contentType(ContentType.JSON)
.log().all()
.when()
.body(PageableFilterRequest.builder().searchCriteriaRequestParam(SearchCriteriaRequestParam.builder().filter(List.of("contractType,EQUAL,ASSET_AS_BUILT,AND")).build()).build())
.post("/api/contracts")
.then()
.log().all()
.statusCode(200)
.extract().body().as(new TypeRef<>() {
});
//THEN
assertThat(contractResponsePageResult.content()).isNotEmpty();
assertThat(contractResponsePageResult.content().get(0).getCounterpartyAddress()).isNotEmpty();
}


@Test
void shouldReturnEmptyIfAssetIdIsUnknown() throws JoseException {
//GIVEN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.params.provider.Arguments.arguments;

public class EdcNotificationContractControllerIT extends IntegrationTestSpecification {
public class EdcNotificationContractsControllerIT extends IntegrationTestSpecification {

@Autowired
EdcSupport edcSupport;

// @Test
// @Test
void shouldCreateEdcContract() throws JoseException {
// given
edcSupport.edcWillCreateNotificationAsset();
Expand Down Expand Up @@ -81,7 +81,7 @@ void shouldCreateEdcContract() throws JoseException {
edcSupport.verifyDeleteContractDefinitionEndpointCalledTimes(0);
}

// @Test
// @Test
void shouldNotCreateEdcContractWhenNotificationAssetCreationFailed() throws JoseException {
// given
edcSupport.edcWillFailToCreateNotificationAsset();
Expand Down Expand Up @@ -114,7 +114,7 @@ void shouldNotCreateEdcContractWhenNotificationAssetCreationFailed() throws Jose

}

// @Test
// @Test
void shouldNotCreateEdcContractAndDoRollbackWhenPolicyDefinitionCreationFailed() throws JoseException {
// given
edcSupport.edcWillCreateNotificationAsset();
Expand Down Expand Up @@ -149,7 +149,7 @@ void shouldNotCreateEdcContractAndDoRollbackWhenPolicyDefinitionCreationFailed()
edcSupport.verifyDeleteContractDefinitionEndpointCalledTimes(0);
}

// @Test
// @Test
void shouldNotCreateEdcContractAndDoRollbackWhenContractDefinitionCreationFailed() throws JoseException {
// given
edcSupport.edcWillCreateNotificationAsset();
Expand Down Expand Up @@ -266,7 +266,7 @@ void shouldNotCreateEdcContractWithInvalidRequest(
.statusCode(400);
}

// @Test
// @Test
void shouldNotCreateEdcContractForQualityAlertBecauseItsNotYetImplemented() throws JoseException {
given()
.contentType(ContentType.JSON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,14 @@ void shouldUpdateInvestigationFields() throws JsonProcessingException, JoseExcep
// then
notificationMessageSupport.assertMessageSize(0);

PageableFilterRequest pageableFilterRequest =
new PageableFilterRequest(
new OwnPageable(0, 10, Collections.emptyList()),
new SearchCriteriaRequestParam(List.of("channel,EQUAL,SENDER,AND")));

PageResult<NotificationResponse> notificationResponsePageResult
= notificationAPISupport.getNotificationsRequest(authHeader);
= notificationAPISupport.getNotificationsRequest(authHeader, pageableFilterRequest);


NotificationResponse notificationResponse = notificationResponsePageResult.content().get(0);
assertThat(notificationResponse.getId()).isEqualTo(id);
Expand Down Expand Up @@ -239,9 +245,12 @@ void shouldNotUpdateInvestigationFields_whenBpnWrongFormatted() throws JoseExcep
notificationAPISupport.editNotificationRequest(authHeader, editNotificationRequest, id, 400);

// then

PageableFilterRequest pageableFilterRequest =
new PageableFilterRequest(
new OwnPageable(0, 10, Collections.emptyList()),
new SearchCriteriaRequestParam(List.of("channel,EQUAL,SENDER,AND")));
PageResult<NotificationResponse> notificationResponsePageResult
= notificationAPISupport.getNotificationsRequest(authHeader);
= notificationAPISupport.getNotificationsRequest(authHeader, pageableFilterRequest);

NotificationResponse notificationResponse = notificationResponsePageResult.content().get(0);
assertThat(notificationResponse.getSendTo()).isEqualTo("BPNL00000003CNKC");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
import notification.request.StartNotificationRequest;
import notification.request.UpdateNotificationStatusRequest;
import notification.request.UpdateNotificationStatusTransitionRequest;
import notification.response.NotificationResponse;
import org.apache.commons.lang3.RandomStringUtils;
import org.eclipse.tractusx.traceability.assets.domain.asbuilt.repository.AssetAsBuiltRepository;
import org.eclipse.tractusx.traceability.assets.domain.base.model.AssetBase;
import org.eclipse.tractusx.traceability.common.model.PageResult;
import org.eclipse.tractusx.traceability.common.request.OwnPageable;
import org.eclipse.tractusx.traceability.common.request.PageableFilterRequest;
import org.eclipse.tractusx.traceability.common.request.SearchCriteriaRequestParam;
Expand Down Expand Up @@ -137,7 +139,6 @@ void shouldReceiveNotification() {
@Test
void shouldStartInvestigation() throws JoseException, JsonProcessingException {


// given
List<String> partIds = List.of(
"urn:uuid:fe99da3d-b0de-4e80-81da-882aebcca978", // BPN: BPNL00000003AYRE
Expand Down Expand Up @@ -426,9 +427,19 @@ void shouldApproveInvestigationStatus() throws JoseException, JsonProcessingExce
.body("content", Matchers.hasSize(1))
.body("content[0].sendTo", Matchers.is(Matchers.not(Matchers.blankOrNullString())));

String contractAgreementId = "NmYxMjk2ZmUtYmRlZS00ZTViLTk0NzktOWU0YmQyYWYyNGQ3:ZDBjZGUzYjktOWEwMS00N2QzLTgwNTgtOTU2MjgyOGY2ZDBm:YjYxMjcxM2MtNjdkNC00N2JlLWI0NjMtNDdjNjk4YTk1Mjky";
PageableFilterRequest pageableFilterRequest =
new PageableFilterRequest(
new OwnPageable(0, 10, Collections.emptyList()),
new SearchCriteriaRequestParam(List.of("contractAgreementId,EQUAL," + contractAgreementId + ",AND")));

PageResult<NotificationResponse> notificationsRequest =
notificationApiSupport.getNotificationsRequest(oAuth2Support.jwtAuthorization(SUPERVISOR), pageableFilterRequest);
assertThat(notificationsRequest.content().get(0).getMessages().get(0).getContractAgreementId()).isEqualTo(contractAgreementId);
notificationMessageSupport.assertMessageSize(2);
}


@Test
void shouldCloseInvestigationStatus() throws JoseException, JsonProcessingException {
// given
Expand Down
Loading