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

chore(contracts):1105 provided tables for all types of contracts to save th… #1191

Merged
merged 47 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
f478634
chore(irs):1105 provided tables for all types of contracts to save th…
ds-mwesener Jul 9, 2024
fdd1898
Merge branch 'refs/heads/main' into feature/1105-contractagreement-pe…
ds-mwesener Jul 10, 2024
fe0663a
Merge branch 'refs/heads/main' into feature/1105-contractagreement-pe…
ds-mwesener Jul 10, 2024
8f99ddb
chore(irs):1105 Added contractAgreementIds to asset domain.
ds-mwesener Jul 11, 2024
ee5a4cf
Merge branch 'refs/heads/main' into feature/1105-contractagreement-pe…
ds-mwesener Jul 11, 2024
fd2fb69
chore(irs):1105 Added contractAgreementIds to asset domain.
ds-mwesener Jul 11, 2024
361019c
chore(irs):1105 Added contractAgreementIds to asset domain.
ds-mwesener Jul 11, 2024
f1fd134
chore(irs):1105 Added contractAgreementIds to asset domain.
ds-mwesener Jul 12, 2024
924db25
Merge branch 'refs/heads/main' into feature/1105-contractagreement-pe…
ds-mwesener Jul 12, 2024
be3731f
chore(irs):1105 Added contractAgreementIds to asset domain.
ds-mwesener Jul 12, 2024
fa639ca
chore(irs):1105 Added contractAgreementIds to asset domain.
ds-mwesener Jul 12, 2024
9a03a7a
chore(irs):1105 Added contractAgreementIds to asset domain.
ds-mwesener Jul 12, 2024
3732990
chore(irs):1105 Added logging.
ds-mwesener Jul 12, 2024
21714a6
chore(irs):1105 Added logging.
ds-mwesener Jul 12, 2024
a8aec7c
chore(irs):1105 Renamed bean.
ds-mwesener Jul 12, 2024
20bb037
Merge branch 'refs/heads/main' into feature/1105-contractagreement-pe…
ds-mwesener Jul 12, 2024
64989d8
Merge branch 'refs/heads/main' into feature/1105-contractagreement-pe…
ds-mwesener Jul 17, 2024
cfc603b
chore(irs):1105 Fixed issues.
ds-mwesener Jul 17, 2024
6fc2472
feature: #1221 #1196 update IRS to 7.3.1 and EDC to 0.7.3
ds-lcapellino Jul 17, 2024
68844e0
feature: #1221 #1193 update CHANGELOG.md
ds-lcapellino Jul 17, 2024
c2e526c
chore(irs):1105 Added globalAssetId to contract response.
ds-mwesener Jul 17, 2024
cb9768c
Merge remote-tracking branch 'eclipse/feature/1105-contractagreement-…
ds-mwesener Jul 17, 2024
e64ce83
chore(irs):1105 Fixed policy of testdata.
ds-mwesener Jul 17, 2024
b439aea
chore(irs):1105 Fixed mapper.
ds-mwesener Jul 17, 2024
bb48d77
chore(irs):1105 Fixed mapper.
ds-mwesener Jul 17, 2024
9c2de5e
chore(irs):1105 Fixed mapper.
ds-mwesener Jul 17, 2024
6c1a46b
chore(irs):1105 Fixed mapper.
ds-mwesener Jul 17, 2024
8ba7fab
chore(irs):1105 Fixed mapper.
ds-mwesener Jul 17, 2024
75ed077
chore(irs):1105 Fixed mapper.
ds-mwesener Jul 17, 2024
39613a7
chore(irs):1105 Fixed mapper.
ds-mwesener Jul 17, 2024
835ac9e
chore(irs):1105 Refactored.
ds-mwesener Jul 17, 2024
33e07f6
Merge branch 'refs/heads/main' into feature/1105-contractagreement-pe…
ds-mwesener Jul 17, 2024
47efd8d
chore(irs):1105 Refactored.
ds-mwesener Jul 17, 2024
89e0474
chore(irs):1105 Refactored.
ds-mwesener Jul 18, 2024
560cd33
chore(irs):1105 Refactored.
ds-mwesener Jul 18, 2024
4816269
chore(contracts):1105 Refactored.
ds-mwesener Jul 18, 2024
6ab83f1
chore(contracts):1105 Refactored.
ds-mwesener Jul 18, 2024
2312262
chore(contracts):1105 Refactored.
ds-mwesener Jul 18, 2024
8b01314
chore(contracts):1105 Refactored.
ds-mwesener Jul 18, 2024
7fd8f0e
chore(contracts):1105 Refactored.
ds-mwesener Jul 18, 2024
87ef392
chore(contracts):1105 Refactored.
ds-mwesener Jul 18, 2024
876148b
Merge branch 'refs/heads/main' into feature/1105-contractagreement-pe…
ds-mwesener Jul 18, 2024
bc149b9
chore(contracts):1105 Merged main.
ds-mwesener Jul 18, 2024
dd92f33
Update tx-backend/src/main/java/org/eclipse/tractusx/traceability/con…
ds-mwesener Jul 18, 2024
55bfde9
Apply suggestions from code review
ds-mwesener Jul 18, 2024
13520dd
Merge branch 'refs/heads/main' into feature/1105-contractagreement-pe…
ds-mwesener Jul 18, 2024
bc9e917
chore(contracts):1105 Code Review
ds-mwesener Jul 18, 2024
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: 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 @@ -16,8 +16,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

## [12.0.0 - 05.07.2024]
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
Loading