From 828b6701830e2f28197a54a35aa3b5c0bbacc378 Mon Sep 17 00:00:00 2001
From: Martin Maul <martin.maul@doubleslash.de>
Date: Fri, 12 Jul 2024 12:39:58 +0200
Subject: [PATCH 1/2] chore(contracts): 1105 adjust part reference in contracts

---
 CHANGELOG.md                                  |  1 +
 .../mocks/services/admin-mock/admin.model.ts  | 24 ++++++++++++-------
 .../core/user/table-settings.service.spec.ts  |  4 ++--
 .../modules/page/admin/core/admin.model.ts    |  9 ++++---
 .../contracts/contracts.component.spec.ts     | 19 ++-------------
 .../contracts/contracts.component.ts          |  8 +------
 .../modules/page/parts/model/parts.model.ts   |  2 --
 .../shared/assembler/parts.assembler.ts       |  1 -
 .../parts-as-built-configuration.model.ts     |  1 -
 .../parts-as-planned-configuration.model.ts   |  1 -
 .../parts-table/parts-table.component.spec.ts |  2 --
 11 files changed, 28 insertions(+), 44 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index c3657c3817..1ad9e3a9b0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -17,6 +17,7 @@ _**For better traceability add the corresponding GitHub issue number in each cha
 - #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
 - #1188 prevent retry requests for notification actions to prevent duplicate error messages in history
+- #
 
 ## [12.0.0 - 05.07.2024]
 
diff --git a/frontend/src/app/mocks/services/admin-mock/admin.model.ts b/frontend/src/app/mocks/services/admin-mock/admin.model.ts
index 3165c962d6..70abbdb5f1 100644
--- a/frontend/src/app/mocks/services/admin-mock/admin.model.ts
+++ b/frontend/src/app/mocks/services/admin-mock/admin.model.ts
@@ -226,7 +226,8 @@ export const getContracts = (): PaginationResponse<ContractResponse> => {
         "creationDate": "2024-02-26T13:38:07+01:00",
         "endDate": null,
         "state": ContractState.FINALIZED,
-        "policy": "jsontextaspolicy"
+        'policy': 'jsontextaspolicy',
+        'globalAssetId': 'uuid-1',
       },
       {
         "contractId": "abc2",
@@ -235,7 +236,8 @@ export const getContracts = (): PaginationResponse<ContractResponse> => {
         "creationDate": "2022-05-01T12:34:12",
         "endDate": null,
         "state": ContractState.FINALIZED,
-        "policy": "jsontextaspolicy"
+        'policy': 'jsontextaspolicy',
+        'globalAssetId': 'uuid-2',
       },
       {
         "contractId": "abc3",
@@ -244,7 +246,8 @@ export const getContracts = (): PaginationResponse<ContractResponse> => {
         "creationDate": "2022-05-01T12:34:12",
         "endDate": null,
         "state": ContractState.FINALIZED,
-        "policy": "jsontextaspolicy"
+        'policy': 'jsontextaspolicy',
+        'globalAssetId': 'uuid-3',
       },
       {
         "contractId": "abc4",
@@ -253,7 +256,8 @@ export const getContracts = (): PaginationResponse<ContractResponse> => {
         "creationDate": "2022-05-01T12:34:12",
         "endDate": null,
         "state": ContractState.FINALIZED,
-        "policy": "jsontextaspolicy"
+        'policy': 'jsontextaspolicy',
+        'globalAssetId': 'uuid-4',
       },
       {
         "contractId": "abc5",
@@ -262,7 +266,8 @@ export const getContracts = (): PaginationResponse<ContractResponse> => {
         "creationDate": "2022-05-01T12:34:12",
         "endDate": null,
         "state": ContractState.FINALIZED,
-        "policy": "jsontextaspolicy"
+        'policy': 'jsontextaspolicy',
+        'globalAssetId': 'uuid-5',
       },
       {
         "contractId": "abc6",
@@ -271,7 +276,8 @@ export const getContracts = (): PaginationResponse<ContractResponse> => {
         "creationDate": "2022-05-01T12:34:12",
         "endDate": null,
         "state": ContractState.FINALIZED,
-        "policy": "jsontextaspolicy"
+        'policy': 'jsontextaspolicy',
+        'globalAssetId': 'uuid-6',
       },
       {
         "contractId": "abc7",
@@ -280,7 +286,8 @@ export const getContracts = (): PaginationResponse<ContractResponse> => {
         "creationDate": "2022-05-01T12:34:12",
         "endDate": null,
         "state": ContractState.FINALIZED,
-        "policy": "jsontextaspolicy"
+        'policy': 'jsontextaspolicy',
+        'globalAssetId': 'uuid-7',
       },
       {
         "contractId": "abc8",
@@ -289,7 +296,8 @@ export const getContracts = (): PaginationResponse<ContractResponse> => {
         "creationDate": "2022-05-01T12:34:12",
         "endDate": null,
         "state": ContractState.FINALIZED,
-        "policy": "jsontextaspolicy"
+        'policy': 'jsontextaspolicy',
+        'globalAssetId': 'uuid-8',
       },
       {
         "contractId": "abc9",
diff --git a/frontend/src/app/modules/core/user/table-settings.service.spec.ts b/frontend/src/app/modules/core/user/table-settings.service.spec.ts
index e7021fe92d..754887ecde 100644
--- a/frontend/src/app/modules/core/user/table-settings.service.spec.ts
+++ b/frontend/src/app/modules/core/user/table-settings.service.spec.ts
@@ -46,12 +46,12 @@ describe('TableSettingsService', () => {
 
     it('should return PartsAsPlannedConfigurationModel for AS_PLANNED_OWN', () => {
       const result: TableViewConfig = service.initializeTableViewSettings(TableType.AS_PLANNED_OWN);
-      expect(result.displayedColumns.length).toBe(21);
+      expect(result.displayedColumns.length).toBe(20);
     });
 
     it('should return PartsAsBuiltConfigurationModel for AS_BUILT_OWN', () => {
       const result: TableViewConfig = service.initializeTableViewSettings(TableType.AS_BUILT_OWN);
-      expect(result.displayedColumns.length).toBe(23);
+      expect(result.displayedColumns.length).toBe(22);
     });
 
     it('should return NotificationsSentConfigurationModel for SENT_NOTIFICATION', () => {
diff --git a/frontend/src/app/modules/page/admin/core/admin.model.ts b/frontend/src/app/modules/page/admin/core/admin.model.ts
index 4d857cd960..03800752b4 100644
--- a/frontend/src/app/modules/page/admin/core/admin.model.ts
+++ b/frontend/src/app/modules/page/admin/core/admin.model.ts
@@ -59,7 +59,8 @@ export interface Contract {
   creationDate: CalendarDateModel,
   endDate: CalendarDateModel,
   state: ContractState,
-  policy: string
+  policy: string,
+  globalAssetId?: string,
 }
 
 export interface ContractResponse {
@@ -69,7 +70,8 @@ export interface ContractResponse {
   creationDate: string,
   endDate: string,
   state: ContractState,
-  policy: string
+  policy: string,
+  globalAssetId?: string,
 }
 
 export enum ContractType {
@@ -90,7 +92,8 @@ export function assembleContract(contractResponse: ContractResponse): Contract {
     creationDate: new CalendarDateModel(contractResponse.creationDate),
     endDate: new CalendarDateModel(contractResponse.endDate),
     state: contractResponse.state,
-    policy: contractResponse.policy
+    policy: contractResponse.policy,
+    globalAssetId: contractResponse.globalAssetId,
   };
 }
 
diff --git a/frontend/src/app/modules/page/admin/presentation/contracts/contracts.component.spec.ts b/frontend/src/app/modules/page/admin/presentation/contracts/contracts.component.spec.ts
index dbe7b8cc0a..375e842fdc 100644
--- a/frontend/src/app/modules/page/admin/presentation/contracts/contracts.component.spec.ts
+++ b/frontend/src/app/modules/page/admin/presentation/contracts/contracts.component.spec.ts
@@ -133,8 +133,8 @@ describe('ContractTableComponent', () => {
 
     let result = componentInstance.convertArrayOfObjectsToCSV([ getContracts().content[0] ]);
 
-    expect(result).toEqual('contractId,contractType,counterpartyAddress,creationDate,endDate,state,policy\n' +
-      'abc1,ASSET_AS_BUILT,https://trace-x-edc-e2e-a.dev.demo.catena-x.net/api/v1/dsp,2024-02-26T13:38:07+01:00,,Finalized,jsontextaspolicy');
+    expect(result).toEqual('contractId,contractType,counterpartyAddress,creationDate,endDate,state,policy,globalAssetId\n' +
+      'abc1,ASSET_AS_BUILT,https://trace-x-edc-e2e-a.dev.demo.catena-x.net/api/v1/dsp,2024-02-26T13:38:07+01:00,,Finalized,jsontextaspolicy,uuid-1');
 
   });
   it('should download CSV file', async () => {
@@ -186,21 +186,6 @@ describe('ContractTableComponent', () => {
     expect(toastServiceMock.error).toHaveBeenCalledWith('pageAdmin.contracts.noItemsFoundError');
   });
 
-
-  it('should show error when contractType is not NOTIFICATION and no parts are found', async () => {
-    partsServiceMock.getPartsByFilter.and.returnValue(of({ content: [] }));
-
-    const { fixture } = await renderContractTableComponent();
-    const { componentInstance } = fixture;
-    const data = { contractId: 'contract-id', contractType: ContractType.ASSET_AS_BUILT };
-
-    componentInstance.viewItemsClicked.emit(data);
-    fixture.detectChanges();
-
-    expect(partsServiceMock.getPartsByFilter).toHaveBeenCalledWith({ contractAgreementId: 'contract-id' }, true);
-    expect(toastServiceMock.error).toHaveBeenCalledWith('pageAdmin.contracts.noItemsFoundError');
-  });
-
   it('should filter contract type', async () => {
     const { fixture } = await renderContractTableComponent();
     const { componentInstance } = fixture;
diff --git a/frontend/src/app/modules/page/admin/presentation/contracts/contracts.component.ts b/frontend/src/app/modules/page/admin/presentation/contracts/contracts.component.ts
index fb24d8e7ed..6c275b0578 100644
--- a/frontend/src/app/modules/page/admin/presentation/contracts/contracts.component.ts
+++ b/frontend/src/app/modules/page/admin/presentation/contracts/contracts.component.ts
@@ -52,13 +52,7 @@ export class ContractsComponent {
           },
         );
       } else {
-        this.partsService.getPartsByFilter({ contractAgreementId: contractId }, data?.contractType === ContractType.ASSET_AS_BUILT).subscribe({
-          next: data => {
-            data?.content?.length > 0 ? this.router.navigate([ 'parts', data?.content[0]?.id ], { queryParams: { isAsBuilt: data?.content[0]?.partId !== undefined } }) : this.toastService.error('pageAdmin.contracts.noItemsFoundError');
-          },
-          error: error => this.toastService.error(error),
-
-        });
+        this.router.navigate([ 'parts', data?.globalAssetId ], { queryParams: { isAsBuilt: data?.contractType === ContractType.ASSET_AS_BUILT } });
       }
     });
 
diff --git a/frontend/src/app/modules/page/parts/model/parts.model.ts b/frontend/src/app/modules/page/parts/model/parts.model.ts
index 2e942e1a1f..f454ecfd97 100644
--- a/frontend/src/app/modules/page/parts/model/parts.model.ts
+++ b/frontend/src/app/modules/page/parts/model/parts.model.ts
@@ -42,7 +42,6 @@ export interface Part {
   owner: Owner;
   semanticDataModel: SemanticDataModel;
   classification: string;
-  contractAgreementId?: string;
 
   mainAspectType: MainAspectType;
 
@@ -101,7 +100,6 @@ export interface PartResponse {
   receivedQualityInvestigationIdsInStatusActive: string[]
   importNote?: string,
   importState?: ImportState,
-  contractAgreementId?: string,
   tombstone?: string,
 }
 
diff --git a/frontend/src/app/modules/shared/assembler/parts.assembler.ts b/frontend/src/app/modules/shared/assembler/parts.assembler.ts
index 61404c9f1b..feb6f77693 100644
--- a/frontend/src/app/modules/shared/assembler/parts.assembler.ts
+++ b/frontend/src/app/modules/shared/assembler/parts.assembler.ts
@@ -89,7 +89,6 @@ export class PartsAssembler {
       semanticDataModel: partResponse.semanticDataModel,
       classification: partResponse.classification,
       semanticModel: createdSemanticModel,
-      contractAgreementId: partResponse.contractAgreementId,
 
       mainAspectType: mainAspectType,
 
diff --git a/frontend/src/app/modules/shared/components/parts-table/parts-as-built-configuration.model.ts b/frontend/src/app/modules/shared/components/parts-table/parts-as-built-configuration.model.ts
index e8448f6b4b..d997f3245e 100644
--- a/frontend/src/app/modules/shared/components/parts-table/parts-as-built-configuration.model.ts
+++ b/frontend/src/app/modules/shared/components/parts-table/parts-as-built-configuration.model.ts
@@ -42,7 +42,6 @@ export class PartsAsBuiltConfigurationModel extends TableFilterConfiguration {
       sentActiveInvestigations: true,
       importState: true,
       importNote: true,
-      contractAgreementId: true,
       menu: false,
     };
 
diff --git a/frontend/src/app/modules/shared/components/parts-table/parts-as-planned-configuration.model.ts b/frontend/src/app/modules/shared/components/parts-table/parts-as-planned-configuration.model.ts
index 3c7bc22542..011068b42f 100644
--- a/frontend/src/app/modules/shared/components/parts-table/parts-as-planned-configuration.model.ts
+++ b/frontend/src/app/modules/shared/components/parts-table/parts-as-planned-configuration.model.ts
@@ -41,7 +41,6 @@ export class PartsAsPlannedConfigurationModel extends TableFilterConfiguration {
       functionValidUntil: true,
       importState: true,
       importNote: true,
-      contractAgreementId: true,
       menu: false,
     };
 
diff --git a/frontend/src/app/modules/shared/components/parts-table/parts-table.component.spec.ts b/frontend/src/app/modules/shared/components/parts-table/parts-table.component.spec.ts
index e3b88d9a08..f5494bf5ba 100644
--- a/frontend/src/app/modules/shared/components/parts-table/parts-table.component.spec.ts
+++ b/frontend/src/app/modules/shared/components/parts-table/parts-table.component.spec.ts
@@ -142,7 +142,6 @@ describe('PartsTableComponent', () => {
       'filtersentActiveInvestigations',
       'filterimportState',
       'filterimportNote',
-      'filtercontractAgreementId',
       'Menu',
     ]);
   });
@@ -173,7 +172,6 @@ describe('PartsTableComponent', () => {
       'filterfunctionValidUntil',
       'filterimportState',
       'filterimportNote',
-      'filtercontractAgreementId',
       'Menu',
     ]);
   });

From 073b1ab3f6232f8cbb738aae60fa86088d737149 Mon Sep 17 00:00:00 2001
From: Martin Maul <117836305+ds-mmaul@users.noreply.github.com>
Date: Mon, 15 Jul 2024 12:40:48 +0200
Subject: [PATCH 2/2] Update CHANGELOG.md

---
 CHANGELOG.md | 1 -
 1 file changed, 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1ad9e3a9b0..c3657c3817 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -17,7 +17,6 @@ _**For better traceability add the corresponding GitHub issue number in each cha
 - #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
 - #1188 prevent retry requests for notification actions to prevent duplicate error messages in history
-- #
 
 ## [12.0.0 - 05.07.2024]