Skip to content

Commit

Permalink
Merge pull request #87 from catenax-ng/CX_R24.03_Policy_hub_02
Browse files Browse the repository at this point in the history
[feat|sde-backend] : First draft new policies changes
  • Loading branch information
almadigabor authored Feb 19, 2024
2 parents 0f7b838 + ed2e64c commit a14135b
Show file tree
Hide file tree
Showing 45 changed files with 423 additions and 914 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased] - 2023-02-10
## [Unreleased] - 2023-02-13

### Added

- Policy-Hub service api integration.
- Added New Policy Entities and pojo classes.
- Draft code of Policies changes.

### Fixed

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/********************************************************************************
* Copyright (c) 2022, 2023 T-Systems International GmbH
* Copyright (c) 2022, 2023 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 @@ -22,30 +22,27 @@

import java.util.List;

import org.eclipse.tractusx.sde.common.validators.UsagePolicyValidation;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.node.ObjectNode;

import jakarta.validation.constraints.NotEmpty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class SubmodelJsonRequest<T> {

@EqualsAndHashCode(callSuper = true)
public class SubmodelJsonRequest extends PolicyTemplateRequest {

@NotEmpty
@JsonProperty(value = "row_data")
private List<T> rowData;
private List<ObjectNode> rowData;

@JsonProperty(value = "type_of_access")
private String typeOfAccess;

@JsonProperty(value = "bpn_numbers")
private List<String> bpnNumbers;

@JsonProperty(value = "usage_policies")
@UsagePolicyValidation
private List<UsagePolicies> usagePolicies;

}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/********************************************************************************
* Copyright (c) 2022, 2023 T-Systems International GmbH
* Copyright (c) 2022, 2023 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 @@ -22,10 +22,12 @@

import java.util.Map;

import org.eclipse.tractusx.sde.common.entities.SubmodelFileRequest;
import org.eclipse.tractusx.sde.common.entities.PolicyModel;
import org.mapstruct.Mapper;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
Expand All @@ -35,16 +37,22 @@
@Mapper(componentModel = "spring")
public abstract class JsonObjectMapper {

Gson gson = new Gson();
ObjectMapper mapper = new ObjectMapper();

Gson gson=new Gson();

@SneakyThrows
public JsonObject submodelFileRequestToJsonPojo(SubmodelFileRequest submodelFileRequest) {
return gson.toJsonTree(submodelFileRequest).getAsJsonObject();
public JsonNode gsonObjectToJsonNode(JsonObject json) {
String jsonStr = "{}";
if(json != null) {
jsonStr = gson.toJson(json);
}
return mapper.readTree(jsonStr);
}

@SneakyThrows
public ObjectNode submodelFileRequestToJsonNodePojo(SubmodelFileRequest submodelFileRequest) {
public ObjectNode submodelFileRequestToJsonNodePojo(PolicyModel submodelFileRequest) {
mapper.findAndRegisterModules();
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
return mapper.convertValue(submodelFileRequest, ObjectNode.class);
}

Expand All @@ -54,5 +62,11 @@ public ObjectNode submodelJsonRequestToJsonPojo(ObjectNode jobj, Map<String, Obj
jobj.putAll(mapper.convertValue(mps, ObjectNode.class));
return jobj;
}

@SneakyThrows
public JsonNode objectToJsonNode(Object jobj) {
return mapper.convertValue(jobj, JsonNode.class);
}


}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/********************************************************************************
* Copyright (c) 2022, 2023 T-Systems International GmbH
* Copyright (c) 2022, 2023 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 @@ -20,12 +20,12 @@

package org.eclipse.tractusx.sde.common.submodel.executor.create.steps;

import org.eclipse.tractusx.sde.common.entities.SubmodelFileRequest;
import org.eclipse.tractusx.sde.common.entities.PolicyModel;
import org.eclipse.tractusx.sde.common.entities.csv.RowData;

import com.google.gson.JsonObject;

public interface ICsvParseStep {

JsonObject execute(RowData rowData, String processId, SubmodelFileRequest submodelFileRequest);
JsonObject execute(RowData rowData, String processId, PolicyModel submodelFileRequest);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/********************************************************************************
* Copyright (c) 2022, 2023 T-Systems International GmbH
* Copyright (c) 2022, 2023 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 Down Expand Up @@ -29,7 +29,9 @@
import org.springframework.stereotype.Component;

import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
Expand All @@ -44,7 +46,8 @@ public class CsvParse extends Step {
public ObjectNode run(RowData rowData, ObjectNode rowjObject, String processId) {

JsonObject submodelProperties = getSubmodelProperties();

JsonArray submodelRequiredFields = getSubmodelRequiredFields();
JsonObject submodelDependentRequiredFields = getSubmodelDependentRequiredFields();
Set<String> fields = submodelProperties.keySet();

String[] rowDataFields = rowData.content().split(CommonConstants.SEPARATOR, -1);
Expand All @@ -61,7 +64,11 @@ public ObjectNode run(RowData rowData, ObjectNode rowjObject, String processId)

fieldValue = rowDataFields[colomnIndex];

recordProcessUtils.setFieldValue(rowjObject, ele, jObject, fieldValue);
boolean isNotNeedToRemoveFromFields = recordProcessUtils.isFieldEnumDataExpect(jObject)
&& (submodelRequiredFields.contains(JsonParser.parseString(ele))
|| recordProcessUtils.isDependentField(ele, submodelDependentRequiredFields));

recordProcessUtils.setFieldValue(rowjObject, ele, jObject, fieldValue, isNotNeedToRemoveFromFields);

colomnIndex++;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/********************************************************************************
* Copyright (c) 2022, 2023 T-Systems International GmbH
* Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2023, 2024 T-Systems International GmbH
* Copyright (c) 2022, 2023, 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down Expand Up @@ -28,7 +28,9 @@

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
Expand All @@ -43,6 +45,8 @@ public class JsonRecordFormating extends Step {
public ObjectNode run(Integer rowIndex, ObjectNode rowjObject, String processId) {

JsonObject submodelProperties = getSubmodelProperties();
JsonArray submodelRequiredFields = getSubmodelRequiredFields();
JsonObject submodelDependentRequiredFields = getSubmodelDependentRequiredFields();
Set<String> fields = submodelProperties.keySet();

int colomnIndex = 0;
Expand All @@ -52,10 +56,14 @@ public ObjectNode run(Integer rowIndex, ObjectNode rowjObject, String processId)
JsonObject jObject = submodelProperties.get(ele).getAsJsonObject();

JsonNode jsonValuenode = rowjObject.get(ele);
if (!jsonValuenode.isNull())
if (jsonValuenode!=null && !jsonValuenode.isNull())
fieldValue = jsonValuenode.asText();

recordProcessUtils.setFieldValue(rowjObject, ele, jObject, fieldValue);
boolean isNotNeedToRemoveFromFields = recordProcessUtils.isFieldEnumDataExpect(jObject)
&& (submodelRequiredFields.contains(JsonParser.parseString(ele))
|| recordProcessUtils.isDependentField(ele, submodelDependentRequiredFields));

recordProcessUtils.setFieldValue(rowjObject, ele, jObject, fieldValue, isNotNeedToRemoveFromFields);

colomnIndex++;

Expand Down
Loading

0 comments on commit a14135b

Please sign in to comment.