Skip to content

Commit

Permalink
Merge pull request #1191 from eclipse-tractusx/feature/1105-contracta…
Browse files Browse the repository at this point in the history
…greement-persistent

chore(contracts):1105 provided tables for all types of contracts to save th…
  • Loading branch information
ds-mwesener authored Jul 18, 2024
2 parents 9ca88e0 + bc9e917 commit c1b5528
Show file tree
Hide file tree
Showing 64 changed files with 1,382 additions and 369 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/.trivyignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ref https://github.com/catenax-ng/product-traceability-foss-backend/security/code-scanning/1419
# ref https://github.com/eclipse-tractusx/traceability-foss-backend/security/code-scanning/1419
CVE-2022-25857
# ref https://github.com/catenax-ng/tx-traceability-foss/security/code-scanning/6879
# ref https://github.com/eclipse-tractusx/traceability-foss/security/code-scanning/6879
# this is acceptable due to custom environment variable injection script which is executed upon FE container startup
AVD-KSV-0014
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ _**For better traceability add the corresponding GitHub issue number in each cha
- #1173 Update IRS-Helm from 7.1.4 to 7.2.0 - updated Compatibility Matrix
- #1082 fix duplicate key errors when synchronizing assets with IRS
- #970 fixed bug where the right operand of policies was not showing up in table and detailed view
- #1191 Refactored contractAgreementId to be a list of elements.
- #1188 prevent retry requests for notification actions to prevent duplicate error messages in history
- #1025 fix overlapping table actions
- #1221 Updgrade EDC version to 0.7.3
- #1196 Update IRS to 7.3.1
- #941 made the naming for quality notifications consistent throughout the FE app
- #1190 store accepted policies in catalog offers on startup

Expand Down
4 changes: 2 additions & 2 deletions COMPATIBILITY_MATRIX.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
| Dependency | Name of Service | Version | Helm | Comments |
|------------------|------------------------------|----------------------|----------|-----------------------------------------------------|
| EDC | edc-postgresql | 15.4.0-debian-11-r45 | 12.12.10 | Enterprise Data Connector for PostgreSQL |
| IRS | item-relationship-service | 5.2.0 | 7.2.1 | Helm charts for Item Relationship Service |
| EDC | tractusx-connector | 0.7.0 | 0.7.0 | Connector for Data Transfer and Registration |
| IRS | item-relationship-service | 5.3.0 | 7.3.1 | Helm charts for Item Relationship Service |
| EDC | tractusx-connector | 0.7.3 | 0.7.3 | Connector for Data Transfer and Registration |
| Discovery Finder | discovery service | 0.2.5 | - | Service for discovering and registering artifacts |
| Portal | portal | 1.8.0 | - | Web portal for interacting with Trace-X |
| SD-Factory | SD-Factory | 2.1.7 | - | Service Discovery Factory for managing dependencies |
Expand Down
4 changes: 2 additions & 2 deletions charts/traceability-foss/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ dependencies:
condition: pgadmin4.enabled
- name: item-relationship-service
repository: https://eclipse-tractusx.github.io/item-relationship-service
version: 7.2.1
version: 7.3.1
condition: item-relationship-service.enabled
- name: tractusx-connector
repository: https://eclipse-tractusx.github.io/tractusx-edc
version: 0.7.1
version: 0.7.3
condition: tractusx-connector.enabled
- name: postgresql
alias: edc-postgresql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ public class AssetAsBuiltFieldMapper extends BaseRequestFieldMapper {
Map.entry("receivedQualityAlertIdsInStatusActive", "receivedActiveAlerts"),
Map.entry("receivedQualityInvestigationIdsInStatusActive", "receivedActiveInvestigations"),
Map.entry("importState", "importState"),
Map.entry("importNote", "importNote"),
Map.entry("contractAgreementId", "contractAgreementId")
);
Map.entry("importNote", "importNote"));

@Override
protected Map<String, String> getSupportedFields() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.tractusx.traceability.assets.application.base.mapper.AssetBaseResponseMapper;
import org.eclipse.tractusx.traceability.assets.domain.base.model.AssetBase;
import org.eclipse.tractusx.traceability.common.model.PageResult;
import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement;

import java.util.List;

Expand Down Expand Up @@ -59,7 +60,6 @@ public static AssetAsBuiltResponse from(final AssetBase asset) {
.importState(toImportStateResponse(asset.getImportState()))
.importNote(asset.getImportNote())
.tombstone(asset.getTombstone())
.contractAgreementId(asset.getContractAgreementId())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ public class AssetAsPlannedFieldMapper extends BaseRequestFieldMapper {
Map.entry("businessPartner", "manufacturerId"),
Map.entry("van", "van"),
Map.entry("importState", "importState"),
Map.entry("importNote", "importNote"),
Map.entry("contractAgreementId", "contractAgreementId")
Map.entry("importNote", "importNote")

);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.tractusx.traceability.assets.application.base.mapper.AssetBaseResponseMapper;
import org.eclipse.tractusx.traceability.assets.domain.base.model.AssetBase;
import org.eclipse.tractusx.traceability.common.model.PageResult;
import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement;

import java.util.List;

Expand Down Expand Up @@ -60,7 +61,6 @@ public static AssetAsPlannedResponse from(final AssetBase asset) {
.importState(toImportStateResponse(asset.getImportState()))
.importNote(asset.getImportNote())
.tombstone(asset.getTombstone())
.contractAgreementId(asset.getContractAgreementId())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import lombok.extern.slf4j.Slf4j;
import org.eclipse.tractusx.irs.component.enums.BomLifecycle;
import org.eclipse.tractusx.traceability.assets.domain.base.model.aspect.DetailAspectModel;
import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement;
import org.eclipse.tractusx.traceability.notification.domain.base.model.Notification;

import java.util.List;
Expand Down Expand Up @@ -62,7 +63,8 @@ public class AssetBase {
private String importNote;
private String policyId;
private String tombstone;
private String contractAgreementId;
private List<ContractAgreement> contractAgreements;
private String latestContractAgreementId;


public BomLifecycle getBomLifecycle() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@ public Map<AssetBase, Boolean> importAssets(MultipartFile file, ImportJob import
}
});

List<AssetBase> persistedAsBuilt = assetAsBuiltRepository.saveAllIfNotInIRSSyncAndUpdateImportStateAndNote(assetToUploadByBomLifecycle.get(BomLifecycle.AS_BUILT));
List<AssetBase> persistedAsPlanned = assetAsPlannedRepository.saveAllIfNotInIRSSyncAndUpdateImportStateAndNote(assetToUploadByBomLifecycle.get(BomLifecycle.AS_PLANNED));
List<AssetBase> assetAsBuilt = assetToUploadByBomLifecycle.get(BomLifecycle.AS_BUILT);
List<AssetBase> assetAsPlanned = assetToUploadByBomLifecycle.get(BomLifecycle.AS_PLANNED);

List<AssetBase> persistedAsBuilt = assetAsBuiltRepository.saveAllIfNotInIRSSyncAndUpdateImportStateAndNote(assetAsBuilt);
List<AssetBase> persistedAsPlanned = assetAsPlannedRepository.saveAllIfNotInIRSSyncAndUpdateImportStateAndNote(assetAsPlanned);

importJob.setAssetAsBuilt(persistedAsBuilt);
importJob.setAssetAsPlanned(persistedAsPlanned);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

package org.eclipse.tractusx.traceability.assets.infrastructure.asbuilt.model;

import jakarta.persistence.CascadeType;
import jakarta.persistence.CollectionTable;
import jakarta.persistence.Column;
import jakarta.persistence.ElementCollection;
Expand All @@ -43,6 +44,8 @@
import org.eclipse.tractusx.traceability.assets.domain.base.model.aspect.DetailAspectModel;
import org.eclipse.tractusx.traceability.assets.infrastructure.base.model.AssetBaseEntity;
import org.eclipse.tractusx.traceability.assets.infrastructure.base.model.SemanticDataModelEntity;
import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement;
import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsBuiltEntity;
import org.eclipse.tractusx.traceability.notification.infrastructure.notification.model.NotificationEntity;
import org.eclipse.tractusx.traceability.notification.infrastructure.notification.model.NotificationSideBaseEntity;
import org.eclipse.tractusx.traceability.notification.infrastructure.notification.model.NotificationTypeEntity;
Expand Down Expand Up @@ -89,6 +92,8 @@ public class AssetAsBuiltEntity extends AssetBaseEntity {
@OneToMany(mappedBy = "assetAsBuilt", fetch = FetchType.EAGER)
private List<SubmodelPayloadEntity> submodels;

@OneToMany(mappedBy = "assetAsBuilt", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private List<ContractAgreementAsBuiltEntity> contractAgreements;

public static AssetAsBuiltEntity from(AssetBase asset) {
ManufacturingInfo manufacturingInfo = ManufacturingInfo.from(asset.getDetailAspectModels());
Expand Down Expand Up @@ -123,7 +128,7 @@ public static AssetAsBuiltEntity from(AssetBase asset) {
.importNote(asset.getImportNote())
.policyId(asset.getPolicyId())
.tombstone(asset.getTombstone())
.contractAgreementId(asset.getContractAgreementId())
.contractAgreements(ContractAgreementAsBuiltEntity.fromDomainToEntityList(asset.getContractAgreements()))
.build();
}

Expand Down Expand Up @@ -180,7 +185,7 @@ public AssetBase toDomain() {
.importNote(this.getImportNote())
.policyId(this.getPolicyId())
.tombstone(this.getTombstone())
.contractAgreementId(this.getContractAgreementId())
.contractAgreements(ContractAgreement.fromAsBuiltEntityToContractAgreements(emptyIfNull(this.getContractAgreements())))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@

package org.eclipse.tractusx.traceability.assets.infrastructure.asbuilt.model;

import jakarta.persistence.CascadeType;
import jakarta.persistence.CollectionTable;
import jakarta.persistence.Column;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.Embeddable;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.JoinTable;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -40,6 +43,8 @@
import org.eclipse.tractusx.traceability.assets.domain.base.model.aspect.DetailAspectModel;
import org.eclipse.tractusx.traceability.assets.infrastructure.base.model.AssetBaseEntity;
import org.eclipse.tractusx.traceability.assets.infrastructure.base.model.SemanticDataModelEntity;
import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement;
import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsBuiltEntity;
import org.eclipse.tractusx.traceability.notification.infrastructure.notification.model.NotificationEntity;
import org.eclipse.tractusx.traceability.notification.infrastructure.notification.model.NotificationSideBaseEntity;
import org.eclipse.tractusx.traceability.notification.infrastructure.notification.model.NotificationTypeEntity;
Expand Down Expand Up @@ -90,6 +95,9 @@ public class AssetAsBuiltViewEntity extends AssetBaseEntity {
inverseJoinColumns = @JoinColumn(name = "notification_id"))
private List<NotificationEntity> notifications = new ArrayList<>();

@OneToMany(mappedBy = "assetAsBuiltView", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private List<ContractAgreementAsBuiltEntity> contractAgreements;

public AssetBase toDomain() {
return AssetBase.builder()
.id(this.getId())
Expand Down Expand Up @@ -143,7 +151,7 @@ public AssetBase toDomain() {
.toList()
)
.tombstone(this.getTombstone())
.contractAgreementId(this.getContractAgreementId())
.contractAgreements(ContractAgreement.fromAsBuiltEntityToContractAgreements(this.getContractAgreements()))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@
import org.eclipse.tractusx.traceability.assets.domain.base.model.ImportState;
import org.eclipse.tractusx.traceability.assets.domain.base.model.Owner;
import org.eclipse.tractusx.traceability.assets.infrastructure.asbuilt.model.AssetAsBuiltEntity;
import org.eclipse.tractusx.traceability.assets.infrastructure.asplanned.model.AssetAsPlannedEntity;
import org.eclipse.tractusx.traceability.assets.infrastructure.base.irs.AssetCallbackRepository;
import org.eclipse.tractusx.traceability.assets.infrastructure.base.model.AssetBaseEntity;
import org.eclipse.tractusx.traceability.common.repository.CriteriaUtility;
import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement;
import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -92,11 +96,25 @@ public List<AssetBase> getAssets() {

@Override
public AssetBase save(AssetBase asset) {
enrichContractAgreementsAsBuilt(List.of(asset));
return jpaAssetAsBuiltRepository.save(AssetAsBuiltEntity.from(asset)).toDomain();
}

private void enrichContractAgreementsAsBuilt(List<AssetBase> assets) {


assets.forEach(assetBase -> {
List<ContractAgreement> contractAgreements = new ArrayList<>();
contractAgreements.add(ContractAgreement.toDomain(assetBase.getLatestContractAgreementId(), assetBase.getId(), ContractType.ASSET_AS_BUILT));
Optional<AssetAsBuiltEntity> byId = jpaAssetAsBuiltRepository.findById(assetBase.getId());
byId.ifPresent(assetAsBuiltEntity -> contractAgreements.addAll(ContractAgreement.fromAsBuiltEntityToContractAgreements(assetAsBuiltEntity.getContractAgreements())));
assetBase.setContractAgreements(contractAgreements);
});
}

@Override
public List<AssetBase> saveAll(List<AssetBase> assets) {
enrichContractAgreementsAsBuilt(assets);
return jpaAssetAsBuiltRepository.saveAll(AssetAsBuiltEntity.fromList(assets)).stream()
.map(AssetAsBuiltEntity::toDomain)
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
********************************************************************************/
package org.eclipse.tractusx.traceability.assets.infrastructure.asplanned.model;

import jakarta.persistence.CascadeType;
import jakarta.persistence.CollectionTable;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.Embeddable;
Expand All @@ -37,6 +38,9 @@
import org.eclipse.tractusx.traceability.assets.domain.base.model.aspect.DetailAspectModel;
import org.eclipse.tractusx.traceability.assets.infrastructure.base.model.AssetBaseEntity;
import org.eclipse.tractusx.traceability.assets.infrastructure.base.model.SemanticDataModelEntity;
import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement;
import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType;
import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsPlannedEntity;
import org.eclipse.tractusx.traceability.submodel.infrastructure.model.SubmodelPayloadEntity;

import java.time.Instant;
Expand All @@ -63,6 +67,9 @@ public class AssetAsPlannedEntity extends AssetBaseEntity {
@CollectionTable(name = "assets_as_planned_childs", joinColumns = {@JoinColumn(name = "asset_as_planned_id")})
private List<AssetAsPlannedEntity.ChildDescription> childDescriptors;

@OneToMany(mappedBy = "assetAsPlanned", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private List<ContractAgreementAsPlannedEntity> contractAgreements;

@Builder
@NoArgsConstructor
@AllArgsConstructor
Expand Down Expand Up @@ -107,7 +114,7 @@ public static AssetAsPlannedEntity from(AssetBase asset) {
.importNote(asset.getImportNote())
.policyId(asset.getPolicyId())
.tombstone(asset.getTombstone())
.contractAgreementId(asset.getContractAgreementId())
.contractAgreements(ContractAgreementAsPlannedEntity.fromDomainToEntityList(asset.getContractAgreements()))
.build();
}

Expand All @@ -133,7 +140,7 @@ public static AssetBase toDomain(AssetAsPlannedEntity entity) {
.importNote(entity.getImportNote())
.policyId(entity.getPolicyId())
.tombstone(entity.getTombstone())
.contractAgreementId(entity.getContractAgreementId())
.contractAgreements(ContractAgreement.fromAsPlannedEntityToContractAgreements(entity.getContractAgreements()))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@
import org.eclipse.tractusx.traceability.common.model.PageResult;
import org.eclipse.tractusx.traceability.common.model.SearchCriteria;
import org.eclipse.tractusx.traceability.common.repository.CriteriaUtility;
import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement;
import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -100,11 +103,13 @@ public List<AssetBase> getAssets() {

@Override
public AssetBase save(AssetBase asset) {
enrichContractAgreementsAsPlanned(List.of(asset));
return AssetAsPlannedEntity.toDomain(jpaAssetAsPlannedRepository.save(AssetAsPlannedEntity.from(asset)));
}

@Override
public List<AssetBase> saveAll(List<AssetBase> assets) {
enrichContractAgreementsAsPlanned(assets);
return AssetAsPlannedEntity.toDomainList(jpaAssetAsPlannedRepository.saveAll(AssetAsPlannedEntity.fromList(assets)));
}

Expand All @@ -124,7 +129,10 @@ public List<AssetBase> saveAllIfNotInIRSSyncAndUpdateImportStateAndNote(List<Ass
}
return entry.getKey();
})
.map(AssetAsPlannedEntity::from).toList();
.map(assetBase -> {
enrichContractAgreementsAsPlanned(List.of(assetBase));
return AssetAsPlannedEntity.from(assetBase);
}).toList();

return jpaAssetAsPlannedRepository.saveAll(toPersist).stream().map(AssetAsPlannedEntity::toDomain).toList();

Expand Down Expand Up @@ -173,4 +181,17 @@ public void updateImportStateAndNoteForAssets(ImportState importState, String im
});
jpaAssetAsPlannedRepository.saveAll(foundAssets);
}


private void enrichContractAgreementsAsPlanned(List<AssetBase> assets) {

assets.forEach(assetBase -> {
Optional<AssetAsPlannedEntity> byId = jpaAssetAsPlannedRepository.findById(assetBase.getId());
if (byId.isPresent()) {
List<ContractAgreement> contractAgreements = new ArrayList<>(ContractAgreement.fromAsPlannedEntityToContractAgreements(byId.get().getContractAgreements()));
contractAgreements.add(ContractAgreement.toDomain(assetBase.getLatestContractAgreementId(), assetBase.getId(), ContractType.ASSET_AS_PLANNED));
assetBase.setContractAgreements(contractAgreements);
}
});
}
}
Loading

0 comments on commit c1b5528

Please sign in to comment.