Skip to content

Commit

Permalink
Merge pull request #158 from catenax-ng/refactor_for-stable_code_2405
Browse files Browse the repository at this point in the history
feat | refactor code for stable release
  • Loading branch information
almadigabor authored May 13, 2024
2 parents 8a6dd54 + 27b0644 commit 3b3a640
Show file tree
Hide file tree
Showing 26 changed files with 303 additions and 130 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Refactor code for pcf, dt access API, EDC 7.
- Dt access api use in digital twin processing.
- Added test cases for PCF and policy controller.
- Refactor code to make stable release

### Fixed
- Remove garbage character from 'edc_request_template' path. Fixed [#147](https://github.com/eclipse-tractusx/managed-simple-data-exchanger-backend/issues/147).
- Dependabot bump version fix in pom.xml and DEPENDENCIES file update.
- Dockerfile image update. [#117](https://github.com/eclipse-tractusx/managed-simple-data-exchanger-backend/pull/117)

## [2.3.7] - 2024-05-09
### Fixed
- Rename edc_request_template directory.
- This is fixed for issue #147.

## [2.3.6] - 2024-03-06
### Fixed
Expand Down
4 changes: 3 additions & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ COPY ../pom.xml ./pom.xml
COPY ../modules ./modules

# build for release
RUN mvn clean install
#Commeting this because workflow job already building jar file
#As SDE its require some docker enviroment to run test cases so avoid it
#RUN mvn clean install

# our final base image

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public ObjectNode run(Integer rowNumber, ObjectNode objectNode, String processId
SubmoduleCommonColumnsConstant.SHELL_ID);
String subModelId = JsonObjectUtility.getValueFromJsonObjectAsString(objectNode,
SubmoduleCommonColumnsConstant.SUBMODULE_ID);
String uuid = JsonObjectUtility.getValueFromJsonObjectAsString(objectNode, getIdentifierOfModel());

String uuid = getDatabaseIdentifierValues(objectNode, getDatabaseIdentifierSpecsOfModel());

AssetEntryRequest assetEntryRequest = assetFactory.getAssetRequest(submodule,
getSubmodelShortDescriptionOfModel(), shellId, subModelId, getSubmoduleUriPathOfSubmodule(), uuid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public List<String> getTableColomnHeader(Submodel schemaObj) {
tableColomnHeader.add(SubmoduleCommonColumnsConstant.PROCESS_ID);
tableColomnHeader.add(SubmoduleCommonColumnsConstant.DELETED);
tableColomnHeader.add(SubmoduleCommonColumnsConstant.UPDATED);
tableColomnHeader.add(SubmoduleCommonColumnsConstant.SHELL_ACCESS_RULE_IDS);
return tableColomnHeader;
}

Expand Down
6 changes: 5 additions & 1 deletion modules/sde-core/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ logging.level.root=info
## Digital Twins
digital-twins.hostname=
digital-twins.authentication.url=
digital-twins.api=/api/v3.0
digital-twins.registry.uri=
digital-twins.registry.lookup.uri=
digital-twins.authentication.clientId=
digital-twins.authentication.clientSecret=
digital-twins.authentication.grantType=client_credentials
digital-twins.authentication.scope=

## EDC Provider
edc.hostname=
Expand All @@ -76,6 +78,8 @@ edc.apiKeyHeader=
edc.apiKey=
edc.dsp.endpointpath=/api/v1/dsp
edc.dataplane.endpointpath=/api/public
edc.managementpath.apiversion=/v2
edc.managementpath.apiversion.asset=/v3

## EDC Consumer
edc.consumer.hostname=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
{
"edc:operandLeft": "https://w3id.org/edc/v0.0.1/ns/type",
"edc:operator": "=",
"edc:operandRight": "data.core.digitalTwinRegistry"
"edc:operandRight": "${assetType}"
},
{
"edc:operandLeft": "https://w3id.org/edc/v0.0.1/ns/registry",
"edc:operandLeft": "https://w3id.org/edc/v0.0.1/ns/${registryType}",
"edc:operator": "=",
"edc:operandRight": "${digitalTwinRegistry}"
"edc:operandRight": "${baseUrl}"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"operandLeft": "https://w3id.org/edc/v0.0.1/ns/type",
"operator": "=",
"operandRight": "data.core.digitalTwinRegistry"
"operandRight": "${type}"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/********************************************************************************
* Copyright (c) 2022, 2024 T-Systems International GmbH
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation
* Copyright (c) 2022,2024 T-Systems International GmbH
* Copyright (c) 2022,2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -27,7 +27,9 @@
import static org.mockito.Mockito.when;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.eclipse.tractusx.sde.common.entities.Policies;
import org.eclipse.tractusx.sde.core.controller.ConsumerController;
Expand Down Expand Up @@ -66,7 +68,7 @@ class ConsumerControllerTest {
@Test
void testQueryOnDataOfferWithoutOfferModel() throws Exception {
when(consumerControlPanelService.queryOnDataOffers((String) any(), (String) any(), (String) any(), anyInt(),
anyInt())).thenReturn(new ArrayList<>());
anyInt())).thenReturn(new HashSet<>());
MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/query-data-offers")
.param("bpnNumber", "foo");

Expand All @@ -78,7 +80,7 @@ void testQueryOnDataOfferWithoutOfferModel() throws Exception {

@Test
void testQueryOnDataOffersWithOfferModel() throws Exception {
ArrayList<QueryDataOfferModel> queryDataOfferModelList = new ArrayList<>();
Set<QueryDataOfferModel> queryDataOfferModelList = new HashSet<>();
queryDataOfferModelList.add(QueryDataOfferModel.builder()
.assetId("foo")
.connectorId("test")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,73 +54,98 @@
@EnablePostgreSQL
class PolicyControllerTest {

@Autowired
private MockMvc mvc;

@Autowired
private PolicyRepository policyRepository;

@Autowired
private PolicyService policyService;

private final ObjectMapper objectMapper = new ObjectMapper();

@BeforeEach
public void init() {
policyRepository.deleteAll();
}

//@Test
void testSaveAndRetrievePolicy() throws Exception {
mvc.perform(MockMvcRequestBuilders.post("/policy").contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(getPolicy("new_policy")))).andExpect(status().isOk());

Assertions.assertEquals(1, policyRepository.findAll().size());
List<PolicyEntity> entities = policyRepository.findAll();
String uuid = entities.get(0).getUuid();

mvc.perform(MockMvcRequestBuilders.get("/policy/{uuid}", uuid).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());

}

//@Test
void testUniquePolicies() throws Exception {
mvc.perform(MockMvcRequestBuilders.post("/policy").contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(getPolicy("new_policy")))).andExpect(status().isOk());

Assertions.assertEquals(1, policyRepository.findAll().size());

mvc.perform(MockMvcRequestBuilders.post("/policy").contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(getPolicy("new_policy")))).andExpect(status().isBadRequest());

Assertions.assertEquals(1, policyRepository.findAll().size());

}

//@Test
void findMatchingPolicyBasedOnFileName() throws Exception {

String fileName = "Mysubmodel_new_policy.csv";
mvc.perform(MockMvcRequestBuilders.post("/policy").contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(getPolicy("new_policy")))).andExpect(status().isOk());

List<PolicyModel> findMatchingPolicyBasedOnFileName = policyService.findMatchingPolicyBasedOnFileName(fileName);
Assertions.assertEquals(1, findMatchingPolicyBasedOnFileName.size());
Assertions.assertEquals("new_policy", findMatchingPolicyBasedOnFileName.get(0).getPolicyName());

}

private PolicyModel getPolicy(String policyName) {

List<Policies> accessPolicies = List.of(
Policies.builder().technicalKey("BusinessPartnerNumber")
.value(List.of("BPNL00000005PROV", "BPNL00000005PROW", "BPNL00000005PROB")).build(),
Policies.builder().technicalKey("Membership").value(List.of("active")).build());

Policies usagePolicies = Policies.builder().technicalKey("Membership").value(List.of("active")).build();

return PolicyModel.builder().policyName(policyName).accessPolicies(accessPolicies)
.usagePolicies(List.of(usagePolicies)).build();
}
@Autowired
private MockMvc mvc;

@Autowired
private PolicyRepository policyRepository;

@Autowired
private PolicyService policyService;

private final ObjectMapper objectMapper = new ObjectMapper();

@BeforeEach
public void init() {
policyRepository.deleteAll();
}

@Test
void testSaveAndRetrievePolicy() throws Exception {
mvc.perform(MockMvcRequestBuilders
.post("/policy")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(getPolicy("new_policy"))))
.andExpect(status().isOk());

Assertions.assertEquals(1, policyRepository.findAll().size());
List<PolicyEntity> entities = policyRepository.findAll();
String uuid = entities.get(0).getUuid();

mvc.perform(MockMvcRequestBuilders
.get("/policy/{uuid}", uuid)
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());

}

@Test
void testUniquePolicies() throws Exception {
mvc.perform(MockMvcRequestBuilders
.post("/policy")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(getPolicy("new_policy"))))
.andExpect(status().isOk());

Assertions.assertEquals(1, policyRepository.findAll().size());

mvc.perform(MockMvcRequestBuilders
.post("/policy")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(getPolicy("new_policy"))))
.andExpect(status().isBadRequest());

Assertions.assertEquals(1, policyRepository.findAll().size());

}

@Test
void findMatchingPolicyBasedOnFileName() throws Exception {

String fileName = "Mysubmodel_new_policy.csv";
mvc.perform(MockMvcRequestBuilders
.post("/policy")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(getPolicy("new_policy"))))
.andExpect(status().isOk());

List<PolicyModel> findMatchingPolicyBasedOnFileName = policyService.findMatchingPolicyBasedOnFileName(fileName);
Assertions.assertEquals(1, findMatchingPolicyBasedOnFileName.size());
Assertions.assertEquals("new_policy", findMatchingPolicyBasedOnFileName.get(0).getPolicyName());

}


private PolicyModel getPolicy(String policyName) {

List<Policies> accessPolicies = List.of(Policies.builder()
.technicalKey("BusinessPartnerNumber")
.value(List.of("BPNL00000005PROV", "BPNL00000005PROW", "BPNL00000005PROB"))
.build(),Policies.builder()
.technicalKey("Membership")
.value(List.of("active"))
.build());

Policies usagePolicies = Policies.builder()
.technicalKey("Membership")
.value(List.of("active"))
.build();

return PolicyModel.builder()
.policyName(policyName)
.accessPolicies(accessPolicies)
.usagePolicies(List.of(usagePolicies))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

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

import org.eclipse.tractusx.sde.bpndiscovery.handler.BpnDiscoveryProxyService;
Expand Down Expand Up @@ -143,7 +144,7 @@ public void setup() {
void testQueryOnDataOfferEmpty() throws Exception {


List<QueryDataOfferModel> queryOnDataOffers = consumerControlPanelService.queryOnDataOffers("example", "", "",
Set<QueryDataOfferModel> queryOnDataOffers = consumerControlPanelService.queryOnDataOffers("example", "", "",
0, 0);
assertTrue(queryOnDataOffers.isEmpty());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ portal.backend.clientSecret=test
portal.backend.grantType=client_credentials

## bpn & discovery finder
bpndiscovery.hostname=http://test
bpndiscovery.hostname=test
discovery.authentication.url=test
discovery.clientId=test
discovery.clientSecret=test
Expand All @@ -115,6 +115,18 @@ discovery.grantType=client_credentials
springdoc.api-docs.path=/api-docs
springdoc.swagger-ui.oauth.client-id=test

## Notification Email server info
mail.smtp.username=test
mail.smtp.password=test
mail.smtp.host=test
mail.smtp.port=587
mail.from.address=test
mail.to.address=test
mail.cc.address=test
mail.replyto.address=test
mail.smtp.starttls.enable=true
mail.smtp.auth=true

# policy-hub config
policy.hub.hostname=test
policy.hub.authentication.url=test
Expand Down
3 changes: 1 addition & 2 deletions modules/sde-external-services/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ Currenlty SDE consume below Downstearm services API's to perform the Asset creat
- edc
- digital-twins
- portal
- bpn-discovery
- policy-nub
- bpn-discovery
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void delete(Integer rowIndex, JsonObject jsonObject, String delProcessId,

private Map<String, String> generateBPNDiscoveryIdentifiersIds(JsonNode jsonObject) {
return getBPNDiscoverySpecsOfModel().entrySet().stream().map(entry -> {
String value = JsonObjectUtility.getValueFromJsonObjectAsString(jsonObject, entry.getValue().getAsString());
String value = JsonObjectUtility.getValueFromJsonObjectAsString(jsonObject, extractExactFieldName(entry.getValue().getAsString()));
if (StringUtils.isBlank(value)) {
value = entry.getValue().getAsString();
}
Expand Down
Loading

0 comments on commit 3b3a640

Please sign in to comment.