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

[fix]: SDE backend : PCF schema update with security issue fixed #74

Merged
merged 2 commits into from
Nov 28, 2023
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
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/),

## [2.2.1] - non-released
### Fix
- Update PCF schema fields for SDE

## [2.2.0] - 2023-09-20
### Added
- Pcf model schema and model registration.
Expand Down
2 changes: 1 addition & 1 deletion DEPENDENCIES
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ maven/mavencentral/jakarta.annotation/jakarta.annotation-api/2.1.1, EPL-2.0 OR G
maven/mavencentral/jakarta.inject/jakarta.inject-api/2.0.1, Apache-2.0, approved, clearlydefined
maven/mavencentral/jakarta.persistence/jakarta.persistence-api/3.1.0, EPL-2.0 OR BSD-3-Clause AND (EPL-2.0 OR BSD-3-Clause AND BSD-3-Clause), approved, #7696
maven/mavencentral/jakarta.transaction/jakarta.transaction-api/2.0.1, EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0, approved, #7697
maven/mavencentral/jakarta.validation/jakarta.validation-api/3.0.2, Apache-2.0, approved, clearlydefined
maven/mavencentral/jakarta.validation/jakarta.validation-api/3.0.2, Apache-2.0, approved, ee4j.validation
maven/mavencentral/jakarta.xml.bind/jakarta.xml.bind-api/4.0.0, BSD-3-Clause, approved, ee4j.jaxb
maven/mavencentral/net.bytebuddy/byte-buddy-agent/1.14.4, Apache-2.0, approved, #7164
maven/mavencentral/net.bytebuddy/byte-buddy/1.14.4, Apache-2.0 AND BSD-3-Clause, approved, #7163
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ public void setFieldValue(ObjectNode rowjObject, String ele, JsonObject jObject,

fieldValue = fieldValue.trim();

if (isNumberTypeField(jObject, fieldValue))
rowjObject.put(ele, Double.parseDouble(fieldValue));
else if (isDateFormatField(jObject)) {
if (isNumberTypeField(jObject)) {
if (fieldValue.isBlank()) {
rowjObject.putNull(ele);
} else {
rowjObject.put(ele, Double.parseDouble(fieldValue));
}
} else if (isDateFormatField(jObject)) {

if (fieldValue.isBlank())
fieldValue = null;
Expand All @@ -57,12 +61,10 @@ private boolean isDateFormatField(JsonObject jObject) {
return jObject.get("format") != null && "date-time".equals(jObject.get("format").getAsString());
}

private boolean isNumberTypeField(JsonObject jObject, String fieldValue) {

if (fieldValue != null && !fieldValue.isBlank() && jObject.get("type") != null
&& jObject.get("type").isJsonArray()) {
private boolean isNumberTypeField(JsonObject jObject) {
JsonElement jsonElement = JsonParser.parseString("number");
FaGru3n marked this conversation as resolved.
Show resolved Hide resolved
if (jObject.get("type") != null && jObject.get("type").isJsonArray()) {
JsonArray types = jObject.get("type").getAsJsonArray();
JsonElement jsonElement = JsonParser.parseString("number");
return types.contains(jsonElement);
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public ProcessReportPageResponse listAllProcessReports(int page, int size) {
.findAll(PageRequest.of(page, size, Sort.by(Sort.Direction.DESC, "startDate")));
List<ProcessReport> processReports = result.get().map(mapper::mapFrom).toList();
return ProcessReportPageResponse.builder().items(processReports).pageSize(result.getSize())
.pageNumber(result.getNumber()).totalItems(result.getTotalElements()).build();
.page(result.getNumber()).totalItems(result.getTotalElements()).build();
}

public ProcessReport getProcessReportById(String id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
@NoArgsConstructor
public class ProcessReportPageResponse {

private int pageNumber;
private int page;
private int pageSize;
private long totalItems;
private List<ProcessReport> items;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class AspectRelationship {
private String oldSubmodelIdforUpdateCase;

@JsonProperty(value = "row_number")
private int rowNumber;
private Integer rowNumber;

@JsonProperty(value = "process_id")
private String processId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class PartAsPlanned {
private String subModelId;

@JsonProperty(value ="row_number")
private int rowNumber;
private Integer rowNumber;

@JsonProperty(value ="uuid")
private String uuid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class PartSiteInformationAsPlanned {
private String subModelId;

@JsonProperty(value ="row_number")
private int rowNumber;
private Integer rowNumber;

@JsonProperty(value ="uuid")
private String uuid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class PcfSubmodel extends SubmodelExtension {

@Autowired
private PcfExecutor pcfWorkflow;

@PostConstruct
public void init() {

Expand All @@ -48,7 +48,7 @@ public void init() {
}

submodel = loadSubmodel(input);

submodel.setExecutor(pcfWorkflow);

submodel.addProperties("tableName", "pcf_aspect");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ public JsonObject mapToResponse(PcfEntity entity) {
.productMassPerDeclaredUnit(entity.getProductMassPerDeclaredUnit())
.productOrSectorSpecificRules(List.of(ProductOrSectorSpecificRules.builder()
.extWBCSDOperator(entity.getExtWBCSDOperator())
.productOrSectorSpecificRulesObj(ProductOrSectorSpecificRule.builder()
.productOrSectorSpecificRulesObj(List.of(ProductOrSectorSpecificRule.builder()
.ruleName(entity.getRuleName())
.build())
.build()))
.extWBCSDOtherOperatorName(entity.getExtWBCSDOtherOperatorName())
.build()))
.extTFSAllocationWasteIncineration(entity.getExtTFSAllocationWasteIncineration())
Expand Down Expand Up @@ -140,9 +140,9 @@ public JsonObject mapToResponse(PcfEntity entity) {

return new Gson().toJsonTree(PcfSubmodelResponse.builder()
.specVersion(entity.getSpecVersion())
.companyIds(CompanyIds.builder()
.companyIds(List.of(CompanyIds.builder()
.companyId(entity.getCompanyId())
.build())
.build()))
.extWBCSDProductCodeCpc(entity.getExtWBCSDProductCodeCpc())
.created(entity.getCreated())
.companyName(entity.getCompanyName())
Expand All @@ -151,9 +151,9 @@ public JsonObject mapToResponse(PcfEntity entity) {
.productName(entity.getProductName())
.pcf(pcfResponse)
.partialFullPcf(entity.getPartialFullPcf())
.productIds(ProductIds.builder()
.productIds(List.of(ProductIds.builder()
.productId(entity.getProductId())
.build())
.build()))

.validityPeriodStart(entity.getValidityPeriodStart())
.comment(entity.getComment())
Expand All @@ -162,9 +162,9 @@ public JsonObject mapToResponse(PcfEntity entity) {
.pcfLegalStatement(entity.getPcfLegalStatement())
.productDescription(entity.getProductDescription())

.precedingPfIds(PrecedingPfIds.builder()
.precedingPfIds(List.of(PrecedingPfIds.builder()
.id(entity.getPrecedingPfId())
.build())
.build()))
.build()).getAsJsonObject();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class PcfAspect {
private String subModelIdforPcf;

@JsonProperty(value = "row_number")
private int rowNumberforPcf;
private Integer rowNumberforPcf;

@JsonProperty(value = "bpn_numbers")
private List<String> bpnNumbersforPcf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
********************************************************************************/
package org.eclipse.tractusx.sde.submodels.pcf.model;

import java.util.List;

import com.google.gson.annotations.SerializedName;

import lombok.AllArgsConstructor;
Expand All @@ -31,7 +33,7 @@
public class PcfSubmodelResponse {

private String specVersion;
private CompanyIds companyIds;
private List<CompanyIds> companyIds;

@SerializedName(value = "extWBCSD_productCodeCpc")
private String extWBCSDProductCodeCpc;
Expand All @@ -44,13 +46,13 @@ public class PcfSubmodelResponse {
private double version;
private Pcf pcf;
private String partialFullPcf;
private ProductIds productIds;
private List<ProductIds> productIds;
private String validityPeriodStart;
private String comment;
private String id;
private String validityPeriodEnd;
private String pcfLegalStatement;
private String productDescription;
private PrecedingPfIds precedingPfIds;
private List<PrecedingPfIds> precedingPfIds;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
********************************************************************************/
package org.eclipse.tractusx.sde.submodels.pcf.model;

import java.util.List;

import com.google.gson.annotations.SerializedName;

import lombok.AllArgsConstructor;
Expand All @@ -34,7 +36,7 @@ public class ProductOrSectorSpecificRules {
private String extWBCSDOperator;

@SerializedName(value = "productOrSectorSpecificRules")
private ProductOrSectorSpecificRule productOrSectorSpecificRulesObj;
private List<ProductOrSectorSpecificRule> productOrSectorSpecificRulesObj;

@SerializedName(value = "extWBCSD_otherOperatorName")
private String extWBCSDOtherOperatorName;
Expand Down
Loading