From 7da4931862f9c7a5a832f086740a3182cff32f50 Mon Sep 17 00:00:00 2001
From: Diogo Sousa
Date: Fri, 3 Nov 2023 13:25:35 +0000
Subject: [PATCH 01/12] Address book table script
---
.../migration/V11__Create_BP_Adressbook.sql | 34 +++++++++++++++++++
1 file changed, 34 insertions(+)
create mode 100644 demand-capacity-mgmt-backend/src/main/resources/db/migration/V11__Create_BP_Adressbook.sql
diff --git a/demand-capacity-mgmt-backend/src/main/resources/db/migration/V11__Create_BP_Adressbook.sql b/demand-capacity-mgmt-backend/src/main/resources/db/migration/V11__Create_BP_Adressbook.sql
new file mode 100644
index 00000000..f2f182b1
--- /dev/null
+++ b/demand-capacity-mgmt-backend/src/main/resources/db/migration/V11__Create_BP_Adressbook.sql
@@ -0,0 +1,34 @@
+/*
+ * ******************************************************************************
+ * Copyright (c) 2023 BMW AG
+ * Copyright (c) 2023 Contributors to the Eclipse Foundation
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Apache License, Version 2.0 which is available at
+ * https://www.apache.org/licenses/LICENSE-2.0.
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * *******************************************************************************
+ */
+
+SET search_path TO public;
+
+CREATE TABLE IF NOT EXISTS address_book
+(
+ id uuid DEFAULT uuid_generate_v4() primary key,
+ company_id uuid,
+ name varchar(100),
+ contact varchar(50),
+ email varchar(150),
+ function varchar(100),
+ picture bytea
+);
\ No newline at end of file
From 0a552085547b6ee19bf7f4620da2768bd987ba1c Mon Sep 17 00:00:00 2001
From: Diogo Sousa
Date: Mon, 6 Nov 2023 11:23:52 +0000
Subject: [PATCH 02/12] Classes
---
.../entities/AddressBookRecordEntity.java | 65 +++++++++++++++++++
.../repositories/AddressBookRepository.java | 32 +++++++++
.../services/AddressBookService.java | 36 ++++++++++
.../services/impl/AddressBookServiceImpl.java | 46 +++++++++++++
.../src/main/resources/openapi.yml | 29 ++++++++-
5 files changed, 207 insertions(+), 1 deletion(-)
create mode 100644 demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/AddressBookRecordEntity.java
create mode 100644 demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/repositories/AddressBookRepository.java
create mode 100644 demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/AddressBookService.java
create mode 100644 demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/AddressBookServiceImpl.java
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/AddressBookRecordEntity.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/AddressBookRecordEntity.java
new file mode 100644
index 00000000..22b0c4c8
--- /dev/null
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/AddressBookRecordEntity.java
@@ -0,0 +1,65 @@
+/*
+ * ******************************************************************************
+ * Copyright (c) 2023 BMW AG
+ * Copyright (c) 2023 Contributors to the Eclipse Foundation
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Apache License, Version 2.0 which is available at
+ * https://www.apache.org/licenses/LICENSE-2.0.
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * *******************************************************************************
+ */
+
+package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities;
+
+
+import jakarta.persistence.*;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.UUID;
+
+@Entity
+@Table(name = "address_book")
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class AddressBookRecordEntity {
+
+ @Id
+ @GeneratedValue
+ @Column(columnDefinition = "uuid", updatable = false, name = "id")
+ private UUID id;
+
+ @Column(name = "company_id")
+ private UUID companyId;
+
+ @Column(name = "name")
+ private String name;
+
+ @Column(name = "contact")
+ private String contact;
+
+ @Column(name = "email")
+ private String email;
+
+ @Column(name = "function")
+ private String function;
+
+ @Column(name = "picture")
+ private byte[] picture;
+
+}
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/repositories/AddressBookRepository.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/repositories/AddressBookRepository.java
new file mode 100644
index 00000000..8d88e5eb
--- /dev/null
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/repositories/AddressBookRepository.java
@@ -0,0 +1,32 @@
+/*
+ * *******************************************************************************
+ * Copyright (c) 2023 BMW AG
+ * Copyright (c) 2023 Contributors to the Eclipse Foundation
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Apache License, Version 2.0 which is available at
+ * https://www.apache.org/licenses/LICENSE-2.0.
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ********************************************************************************
+ */
+
+package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories;
+
+import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.AddressBookRecordEntity;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+import java.util.UUID;
+
+@Repository
+public interface AddressBookRepository extends JpaRepository {}
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/AddressBookService.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/AddressBookService.java
new file mode 100644
index 00000000..c37391ad
--- /dev/null
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/AddressBookService.java
@@ -0,0 +1,36 @@
+/*
+ * ******************************************************************************
+ * Copyright (c) 2023 BMW AG
+ * Copyright (c) 2023 Contributors to the Eclipse Foundation
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Apache License, Version 2.0 which is available at
+ * https://www.apache.org/licenses/LICENSE-2.0.
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * *******************************************************************************
+ */
+
+package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services;
+
+import eclipse.tractusx.demand_capacity_mgmt_specification.model.AddressBookRequest;
+import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.AddressBookRecordEntity;
+
+import java.util.List;
+
+public interface AddressBookService {
+ AddressBookRecordEntity getRecord(AddressBookRequest request);
+
+ List getRecords(AddressBookRequest request);
+
+ AddressBookRecordEntity postRecord(AddressBookRequest request);
+}
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/AddressBookServiceImpl.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/AddressBookServiceImpl.java
new file mode 100644
index 00000000..fd08c5fb
--- /dev/null
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/AddressBookServiceImpl.java
@@ -0,0 +1,46 @@
+/*
+ * ******************************************************************************
+ * Copyright (c) 2023 BMW AG
+ * Copyright (c) 2023 Contributors to the Eclipse Foundation
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Apache License, Version 2.0 which is available at
+ * https://www.apache.org/licenses/LICENSE-2.0.
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * *******************************************************************************
+ */
+
+package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.impl;
+
+import eclipse.tractusx.demand_capacity_mgmt_specification.model.AddressBookRequest;
+import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.AddressBookRecordEntity;
+import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.AddressBookService;
+
+import java.util.List;
+
+public class AddressBookServiceImpl implements AddressBookService {
+ @Override
+ public AddressBookRecordEntity getRecord(AddressBookRequest request) {
+ return null;
+ }
+
+ @Override
+ public List getRecords(AddressBookRequest request) {
+ return null;
+ }
+
+ @Override
+ public AddressBookRecordEntity postRecord(AddressBookRequest request) {
+ return null;
+ }
+}
diff --git a/demand-capacity-mgmt-specification/src/main/resources/openapi.yml b/demand-capacity-mgmt-specification/src/main/resources/openapi.yml
index c34f15bb..b2ddd7bf 100644
--- a/demand-capacity-mgmt-specification/src/main/resources/openapi.yml
+++ b/demand-capacity-mgmt-specification/src/main/resources/openapi.yml
@@ -145,7 +145,6 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/LoggingHistoryResponse'
-
delete:
tags:
- loggingHistory
@@ -172,6 +171,26 @@ paths:
items:
$ref: '#/components/schemas/LoggingHistoryResponse'
+ /addressBook:
+ get:
+ tags:
+ - addressBook
+ summary: get companies
+ operationId: getAddressBook
+ responses:
+ 200:
+ description: General greeting
+ content:
+ application/json:
+ schema:
+ type: string
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/AddressBookRequest'
+
/loggingHistory/filterLogs:
get:
@@ -1465,6 +1484,14 @@ components:
favorited_at:
type: string
+ AddressBookRequest:
+ type: object
+ properties:
+ query:
+ type: string
+ directQuery:
+ type: boolean
+
MaterialDemandFavoriteResponse:
type: object
properties:
From e79a4c70f8865a4dd898090f9278c1ff59859f8e Mon Sep 17 00:00:00 2001
From: Sergio Figueiredo
Date: Mon, 6 Nov 2023 23:33:46 +0000
Subject: [PATCH 03/12] Console Log cleanup
---
.../CapacityGroupAddToExisting.tsx | 1 -
.../CapacityGroupWizardModal.tsx | 20 +++++++++++++------
.../capacitygroup/CapacityGroupsList.tsx | 1 -
.../src/components/demands/DemandList.tsx | 1 -
.../components/demands/DemandManagement.tsx | 1 -
.../src/components/events/EventsTable.tsx | 1 -
.../src/contexts/DemandContextProvider.tsx | 1 -
.../src/contexts/EventsContextProvider.tsx | 1 -
8 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/demand-capacity-mgmt-frontend/src/components/capacitygroup/CapacityGroupAddToExisting.tsx b/demand-capacity-mgmt-frontend/src/components/capacitygroup/CapacityGroupAddToExisting.tsx
index a0d41ef8..d1978dea 100644
--- a/demand-capacity-mgmt-frontend/src/components/capacitygroup/CapacityGroupAddToExisting.tsx
+++ b/demand-capacity-mgmt-frontend/src/components/capacitygroup/CapacityGroupAddToExisting.tsx
@@ -51,7 +51,6 @@ const CapacityGroupAddToExisting: React.FC = ({
const handleLinkToCapacityGroup = () => {
if (selectedCapacityGroup?.value && checkedDemands && checkedDemands.length > 0) {
const demandIds = checkedDemands.map((demand) => {
- console.log(demand.id , "ssssssssss");
return demand.id
});
diff --git a/demand-capacity-mgmt-frontend/src/components/capacitygroup/CapacityGroupWizardModal.tsx b/demand-capacity-mgmt-frontend/src/components/capacitygroup/CapacityGroupWizardModal.tsx
index 4505ea07..0204f2fc 100644
--- a/demand-capacity-mgmt-frontend/src/components/capacitygroup/CapacityGroupWizardModal.tsx
+++ b/demand-capacity-mgmt-frontend/src/components/capacitygroup/CapacityGroupWizardModal.tsx
@@ -64,6 +64,7 @@ function CapacityGroupWizardModal({ show, onHide, checkedDemands, demands }: Cap
// Function to get the unit measure description based on id
const getUnitMeasureDescription = (unitMeasureId: string) => {
+ console.log(unitMeasureId)
const unitMeasure = unitsofmeasureContext?.unitsofmeasure.find(unit => unit.id === unitMeasureId);
return unitMeasure ? `${unitMeasure.dimension} - ${unitMeasure.description} (${unitMeasure.unSymbol})` : 'N/A';
};
@@ -130,16 +131,19 @@ function CapacityGroupWizardModal({ show, onHide, checkedDemands, demands }: Cap
return { earliestDate, latestDate };
};
+
function areUnitMeasureIdsEqual(demands: DemandProp[]): boolean {
if (demands.length <= 1) {
return true; // If there's only one or zero demands, they are equal.
}
- const firstUnitMeasureId = demands[0].unitMeasureId;
- return demands.every((demand) => demand.unitMeasureId.id === firstUnitMeasureId.id);
+ const firstUnitMeasureId = demands[0].unitMeasureId?.id ?? demands[0].unitMeasureId;
+ return demands.every((demand) => {
+ const demandId = demand.unitMeasureId?.id ?? demand.unitMeasureId;
+ return demandId === firstUnitMeasureId;
+ });
}
-
const handleSubmit = async () => {
setIsLoading(true);
@@ -235,7 +239,11 @@ function CapacityGroupWizardModal({ show, onHide, checkedDemands, demands }: Cap
if (favoriteIdsSet.has(md.id)) {
return false;
}
- // Include demand if its ID is not in favorites
+ // Exclude demand if its linkStatus is neither 'TODO' nor 'UNLINKED'
+ if (md.linkStatus !== 'TODO' && md.linkStatus !== 'UNLINKED') {
+ return false;
+ }
+ // else
return true;
});
@@ -396,7 +404,7 @@ function CapacityGroupWizardModal({ show, onHide, checkedDemands, demands }: Cap
Material Number Customer: {demand ? demand.materialNumberCustomer : 'Not selected'}
- Unit of Measure:{getUnitMeasureDescription(demand.unitMeasureId?.id ?? demand.unitMeasureId)}
+ Unit of Measure:{getUnitMeasureDescription(demand.unitMeasureId?.id ?? demand.unitOfMeasure)}
@@ -452,7 +460,7 @@ function CapacityGroupWizardModal({ show, onHide, checkedDemands, demands }: Cap
Material Number Customer: {demand ? demand.materialNumberCustomer : 'Not selected'}
- Unit of Measure: {getUnitMeasureDescription(demand.unitMeasureId?.id ?? demand.unitMeasureId)}
+ Unit of Measure: {getUnitMeasureDescription(demand.unitMeasureId?.id ?? demand.unitOfMeasure)}
diff --git a/demand-capacity-mgmt-frontend/src/components/capacitygroup/CapacityGroupsList.tsx b/demand-capacity-mgmt-frontend/src/components/capacitygroup/CapacityGroupsList.tsx
index d27e73d5..8bd25f72 100644
--- a/demand-capacity-mgmt-frontend/src/components/capacitygroup/CapacityGroupsList.tsx
+++ b/demand-capacity-mgmt-frontend/src/components/capacitygroup/CapacityGroupsList.tsx
@@ -67,7 +67,6 @@ const CapacityGroupsList: React.FC = () => {
const fetchFavorites = async () => {
try {
const favorites = await fetchFavoritesByType(FavoriteType.CAPACITY_GROUP);
- console.log(favorites)
if (favorites && favorites.capacityGroups) {
setFavoriteCapacityGroups(favorites.capacityGroups.map((fav: SingleCapacityGroupFavoriteResponse) => fav.id));
}
diff --git a/demand-capacity-mgmt-frontend/src/components/demands/DemandList.tsx b/demand-capacity-mgmt-frontend/src/components/demands/DemandList.tsx
index def97c2a..9a434395 100644
--- a/demand-capacity-mgmt-frontend/src/components/demands/DemandList.tsx
+++ b/demand-capacity-mgmt-frontend/src/components/demands/DemandList.tsx
@@ -82,7 +82,6 @@ const DemandList: React.FC<{
const fetchFavorites = async () => {
try {
const favorites = await fetchFavoritesByType(FavoriteType.MATERIAL_DEMAND);
- console.log(favorites)
if (favorites && favorites.materialDemands) {
setFavoriteDemands(favorites.materialDemands.map((fav: MaterialDemandFavoriteResponse) => fav.id));
}
diff --git a/demand-capacity-mgmt-frontend/src/components/demands/DemandManagement.tsx b/demand-capacity-mgmt-frontend/src/components/demands/DemandManagement.tsx
index 67021c3e..998537de 100644
--- a/demand-capacity-mgmt-frontend/src/components/demands/DemandManagement.tsx
+++ b/demand-capacity-mgmt-frontend/src/components/demands/DemandManagement.tsx
@@ -76,7 +76,6 @@ const DemandManagement: React.FC = () => {
const fetchFavorites = async () => {
try {
const favorites = await fetchFavoritesByType(FavoriteType.MATERIAL_DEMAND);
- console.log(favorites)
if (favorites && favorites.materialDemands) {
setFavoriteDemands(favorites.materialDemands.map((fav: MaterialDemandFavoriteResponse) => fav.id));
}
diff --git a/demand-capacity-mgmt-frontend/src/components/events/EventsTable.tsx b/demand-capacity-mgmt-frontend/src/components/events/EventsTable.tsx
index 3e0078db..c8ca3cb5 100644
--- a/demand-capacity-mgmt-frontend/src/components/events/EventsTable.tsx
+++ b/demand-capacity-mgmt-frontend/src/components/events/EventsTable.tsx
@@ -62,7 +62,6 @@ const EventsTable: React.FC = ({ events, isArchive }) => {
const fetchFavorites = async () => {
try {
const favorites = await fetchFavoritesByType(FavoriteType.EVENT);
- console.log(favorites)
if (favorites && favorites.events) {
setFavoriteEvents(favorites.events.map((fav: EventFavoriteResponse) => fav.logID));
}
diff --git a/demand-capacity-mgmt-frontend/src/contexts/DemandContextProvider.tsx b/demand-capacity-mgmt-frontend/src/contexts/DemandContextProvider.tsx
index f568967e..46a6bb15 100644
--- a/demand-capacity-mgmt-frontend/src/contexts/DemandContextProvider.tsx
+++ b/demand-capacity-mgmt-frontend/src/contexts/DemandContextProvider.tsx
@@ -108,7 +108,6 @@ const DemandContextProvider: React.FC> = (props) =>
const updateDemand = async (updatedDemand: Demand) => {
try {
- console.log(updatedDemand)
await api.put(`/demand/${updatedDemand.id}`, updatedDemand);
fetchDemandProps();
} catch (error) {
diff --git a/demand-capacity-mgmt-frontend/src/contexts/EventsContextProvider.tsx b/demand-capacity-mgmt-frontend/src/contexts/EventsContextProvider.tsx
index fc2981a6..ae6018a2 100644
--- a/demand-capacity-mgmt-frontend/src/contexts/EventsContextProvider.tsx
+++ b/demand-capacity-mgmt-frontend/src/contexts/EventsContextProvider.tsx
@@ -113,7 +113,6 @@ const EventsContextProvider: React.FC> = (props) =>
const archiveLog = async (event: EventProp) => {
try {
const api = createAPIInstance(access_token);
- console.log(event)
await api.post('/loggingHistory/archivedLog', event);
} catch (error) {
console.error('Error archiving event:', error);
From 8d019a765a2deb6acf4b4fe207100fc86124dbdc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pedro=20Bail=C3=A3o?=
Date: Tue, 7 Nov 2023 15:49:32 +0000
Subject: [PATCH 04/12] fix: resolved typo in InfoMenuContextProvider
---
.../src/contexts/InfoMenuContextProvider.tsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/demand-capacity-mgmt-frontend/src/contexts/InfoMenuContextProvider.tsx b/demand-capacity-mgmt-frontend/src/contexts/InfoMenuContextProvider.tsx
index 16ace9f9..594a6505 100644
--- a/demand-capacity-mgmt-frontend/src/contexts/InfoMenuContextProvider.tsx
+++ b/demand-capacity-mgmt-frontend/src/contexts/InfoMenuContextProvider.tsx
@@ -23,7 +23,7 @@
import React, { FunctionComponent, createContext, useCallback, useContext, useEffect, useState } from 'react';
-import { InfoMenuData } from '../interfaces/infomenu_interfaces';
+import { InfoMenuData } from '../interfaces/InfoMenu_interfaces';
import createAPIInstance from "../util/Api";
import { CapacityGroupContext } from './CapacityGroupsContextProvider';
import { DemandContext } from './DemandContextProvider';
From 0e6cd6ca9db3415588ce75d9e4a7be00fc82d128 Mon Sep 17 00:00:00 2001
From: Diogo Sousa
Date: Wed, 8 Nov 2023 13:55:53 +0000
Subject: [PATCH 05/12] v0.9
feature almost complete
---
.../controllers/AddressBookController.java | 35 ++++
.../entities/enums/FavoriteType.java | 1 +
.../repositories/AddressBookRepository.java | 5 +-
.../services/AddressBookService.java | 2 +
.../services/GoldenRecordManager.java | 31 ++++
.../services/impl/AddressBookServiceImpl.java | 40 +++-
.../services/impl/FavoriteServiceImpl.java | 29 +++
.../impl/GoldenRecordManagerImpl.java | 59 ++++++
.../favorites/FavoritesTableAddressBook.tsx | 174 ++++++++++++++++++
.../src/components/pages/FavoritesPage.tsx | 6 +
.../src/contexts/InfoMenuContextProvider.tsx | 2 +-
.../src/interfaces/favorite_interfaces.tsx | 13 +-
...interfaces.tsx => infomenu_interfaces.tsx} | 0
.../src/main/resources/openapi.yml | 61 +++++-
14 files changed, 451 insertions(+), 7 deletions(-)
create mode 100644 demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/AddressBookController.java
create mode 100644 demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/GoldenRecordManager.java
create mode 100644 demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/GoldenRecordManagerImpl.java
create mode 100644 demand-capacity-mgmt-frontend/src/components/favorites/FavoritesTableAddressBook.tsx
rename demand-capacity-mgmt-frontend/src/interfaces/{InfoMenu_interfaces.tsx => infomenu_interfaces.tsx} (100%)
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/AddressBookController.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/AddressBookController.java
new file mode 100644
index 00000000..f3273598
--- /dev/null
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/AddressBookController.java
@@ -0,0 +1,35 @@
+/*
+ * ******************************************************************************
+ * Copyright (c) 2023 BMW AG
+ * Copyright (c) 2023 Contributors to the Eclipse Foundation
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Apache License, Version 2.0 which is available at
+ * https://www.apache.org/licenses/LICENSE-2.0.
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * *******************************************************************************
+ */
+
+package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.controllers;
+
+import eclipse.tractusx.demand_capacity_mgmt_specification.api.AddressBookApi;
+import eclipse.tractusx.demand_capacity_mgmt_specification.model.AddressBookRequest;
+import org.springframework.http.ResponseEntity;
+
+public class AddressBookController implements AddressBookApi {
+
+ @Override
+ public ResponseEntity getAddressBook(AddressBookRequest addressBookRequest) throws Exception {
+ return null;
+ }
+}
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/enums/FavoriteType.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/enums/FavoriteType.java
index 206e4588..08099b9c 100644
--- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/enums/FavoriteType.java
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/enums/FavoriteType.java
@@ -27,4 +27,5 @@ public enum FavoriteType {
COMPANY_BASE_DATA,
MATERIAL_DEMAND,
EVENT,
+ ADDRESS_BOOK
}
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/repositories/AddressBookRepository.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/repositories/AddressBookRepository.java
index 8d88e5eb..395b90fd 100644
--- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/repositories/AddressBookRepository.java
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/repositories/AddressBookRepository.java
@@ -24,9 +24,12 @@
import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.AddressBookRecordEntity;
import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.lang.NonNull;
import org.springframework.stereotype.Repository;
+import java.util.List;
import java.util.UUID;
@Repository
-public interface AddressBookRepository extends JpaRepository {}
+public interface AddressBookRepository extends JpaRepository {
+ List findByNameOrCompanyId(@NonNull String name, @NonNull UUID companyId);}
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/AddressBookService.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/AddressBookService.java
index c37391ad..37855272 100644
--- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/AddressBookService.java
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/AddressBookService.java
@@ -33,4 +33,6 @@ public interface AddressBookService {
List getRecords(AddressBookRequest request);
AddressBookRecordEntity postRecord(AddressBookRequest request);
+
+ void deleteRecord(AddressBookRequest request);
}
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/GoldenRecordManager.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/GoldenRecordManager.java
new file mode 100644
index 00000000..42af1d10
--- /dev/null
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/GoldenRecordManager.java
@@ -0,0 +1,31 @@
+/*
+ * ******************************************************************************
+ * Copyright (c) 2023 BMW AG
+ * Copyright (c) 2023 Contributors to the Eclipse Foundation
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Apache License, Version 2.0 which is available at
+ * https://www.apache.org/licenses/LICENSE-2.0.
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * *******************************************************************************
+ */
+
+package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services;
+
+import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.AddressBookRecordEntity;
+
+public interface GoldenRecordManager {
+ AddressBookRecordEntity queryGoldenRecord(String recordQuery);
+
+ AddressBookRecordEntity createRecord(String query);
+}
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/AddressBookServiceImpl.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/AddressBookServiceImpl.java
index fd08c5fb..e267deb2 100644
--- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/AddressBookServiceImpl.java
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/AddressBookServiceImpl.java
@@ -23,24 +23,60 @@
package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.impl;
import eclipse.tractusx.demand_capacity_mgmt_specification.model.AddressBookRequest;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.AddressBookRecordEntity;
+import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories.AddressBookRepository;
import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.AddressBookService;
+import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.GoldenRecordManager;
+import org.springframework.stereotype.Service;
import java.util.List;
+import java.util.Optional;
+import java.util.UUID;
+@RequiredArgsConstructor
+@Service
+@Slf4j
public class AddressBookServiceImpl implements AddressBookService {
+
+ private final AddressBookRepository repository;
+
+ private final GoldenRecordManager goldenRecordManager;
+
@Override
public AddressBookRecordEntity getRecord(AddressBookRequest request) {
+ if(Boolean.FALSE.equals(request.getDirectQuery())){
+ Optional entity = repository.findById(UUID.fromString(request.getQuery()));
+ if(entity.isPresent()){
+ return entity.get();
+ }
+ } else {
+ //TODO GOLDEN RECORD IMPL
+ return null;
+ }
return null;
}
@Override
public List getRecords(AddressBookRequest request) {
- return null;
+ List records;
+ if(Boolean.TRUE.equals(request.getDirectQuery())){
+ return null;
+ } else {
+ records = repository.findByNameOrCompanyId(request.getQuery(), UUID.fromString(request.getQuery()));
+ return records;
+ }
}
@Override
public AddressBookRecordEntity postRecord(AddressBookRequest request) {
- return null;
+ AddressBookRecordEntity entity = goldenRecordManager.createRecord(request.getQuery());
+ return entity;
+ }
+
+ @Override
+ public void deleteRecord(AddressBookRequest request) {
+ repository.deleteById(UUID.fromString(request.getQuery()));
}
}
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/FavoriteServiceImpl.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/FavoriteServiceImpl.java
index 7b505dfd..9044f84c 100644
--- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/FavoriteServiceImpl.java
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/FavoriteServiceImpl.java
@@ -54,6 +54,8 @@ public class FavoriteServiceImpl implements FavoriteService {
private final LoggingHistoryRepository eventRepository;
+ private final AddressBookRepository addressBookRepository;
+
@Override
public FavoriteResponse getAllFavorites(String userID) {
List favoriteEntities = favoriteRepository.findByUserID(UUID.fromString(userID));
@@ -103,6 +105,15 @@ public FavoriteResponse getAllFavoritesByType(String userID, FavoriteType type)
response.setEvents(favoriteResponses);
return response;
}
+ case ADDRESS_BOOK -> {
+ List favoriteResponses = new ArrayList<>();
+ for(FavoriteEntity fav : favoriteResponseList){
+ favoriteResponses.add(convertToAddressBookDto(fav));
+ }
+ FavoriteResponse response = new FavoriteResponse();
+ response.setAddressBooks(favoriteResponses);
+ return response;
+ }
}
return new FavoriteResponse();
}
@@ -114,6 +125,7 @@ private FavoriteResponse filterFavorites(List favoriteEntities)
List materialDemandList = new ArrayList<>();
List companyList = new ArrayList<>();
List eventsList = new ArrayList<>();
+ List addressBookList = new ArrayList<>();
for (FavoriteEntity entity : favoriteEntities) {
switch (entity.getType()) {
@@ -121,6 +133,7 @@ private FavoriteResponse filterFavorites(List favoriteEntities)
case MATERIAL_DEMAND -> materialDemandList.add(convertToMaterialDemandResponse(entity));
case COMPANY_BASE_DATA -> companyList.add(convertToCompanyDto(entity));
case EVENT -> eventsList.add(convertToEventDto(entity));
+ case ADDRESS_BOOK -> addressBookList.add(convertToAddressBookDto(entity));
}
}
@@ -129,10 +142,26 @@ private FavoriteResponse filterFavorites(List favoriteEntities)
response.setMaterialDemands(materialDemandList);
response.setCompanies(companyList);
response.setEvents(eventsList);
+ response.setAddressBooks(addressBookList);
return response;
}
+ private AddressBookFavoriteResponse convertToAddressBookDto(FavoriteEntity entity){
+ Optional recordEntity = addressBookRepository.findById(entity.getFavoriteId());
+ if(recordEntity.isPresent()){
+ AddressBookRecordEntity record = recordEntity.get();
+ AddressBookFavoriteResponse response = new AddressBookFavoriteResponse();
+ response.setName(record.getName());
+ response.setId(record.getId().toString());
+ response.setContact(record.getContact());
+ response.setEmail(record.getEmail());
+ response.setCompanyId(response.getCompanyId());
+ response.setFunction(record.getFunction());
+ return response;
+ } else return null;
+ }
+
private SingleCapacityGroupFavoriteResponse convertToSingleCapacityGroup(FavoriteEntity entity) {
Optional cgEntity = capacityGroupRepository.findById(entity.getFavoriteId());
if (cgEntity.isPresent()) {
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/GoldenRecordManagerImpl.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/GoldenRecordManagerImpl.java
new file mode 100644
index 00000000..f716585a
--- /dev/null
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/GoldenRecordManagerImpl.java
@@ -0,0 +1,59 @@
+/*
+ * ******************************************************************************
+ * Copyright (c) 2023 BMW AG
+ * Copyright (c) 2023 Contributors to the Eclipse Foundation
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Apache License, Version 2.0 which is available at
+ * https://www.apache.org/licenses/LICENSE-2.0.
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * *******************************************************************************
+ */
+
+package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.impl;
+
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.AddressBookRecordEntity;
+import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories.AddressBookRepository;
+import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.GoldenRecordManager;
+import org.springframework.stereotype.Service;
+
+import java.util.UUID;
+
+@Slf4j
+@Service
+@RequiredArgsConstructor
+public class GoldenRecordManagerImpl implements GoldenRecordManager {
+
+ private final AddressBookRepository repository;
+
+ //TODO ACTUAL PROPER IMPLEMENTATION
+ @Override
+ public AddressBookRecordEntity queryGoldenRecord(String recordQuery) {
+ return null;
+ }
+
+ @Override
+ public AddressBookRecordEntity createRecord(String query) {
+ AddressBookRecordEntity recordEntity = new AddressBookRecordEntity();
+ recordEntity.setCompanyId(UUID.fromString(query));
+ recordEntity.setName("TEST NAME");
+ recordEntity.setContact("TEST CONTACT");
+ recordEntity.setEmail("TEST EMAIL");
+ recordEntity.setPicture("yeetus".getBytes());
+ repository.save(recordEntity);
+ return recordEntity;
+ }
+
+}
diff --git a/demand-capacity-mgmt-frontend/src/components/favorites/FavoritesTableAddressBook.tsx b/demand-capacity-mgmt-frontend/src/components/favorites/FavoritesTableAddressBook.tsx
new file mode 100644
index 00000000..b8af0551
--- /dev/null
+++ b/demand-capacity-mgmt-frontend/src/components/favorites/FavoritesTableAddressBook.tsx
@@ -0,0 +1,174 @@
+/*
+ * ******************************************************************************
+ * Copyright (c) 2023 BMW AG
+ * Copyright (c) 2023 Contributors to the Eclipse Foundation
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Apache License, Version 2.0 which is available at
+ * https://www.apache.org/licenses/LICENSE-2.0.
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * *******************************************************************************
+ */
+
+import React, { useCallback, useContext, useMemo, useState } from 'react';
+import { Button, Col, Form, OverlayTrigger, Row, Tooltip } from 'react-bootstrap';
+import {
+ FaCopy
+} from 'react-icons/fa';
+import { LuStarOff } from "react-icons/lu";
+import { FavoritesContext } from "../../contexts/FavoritesContextProvider";
+import {AddressBookFavoriteResponse, CompanyDtoFavoriteResponse} from '../../interfaces/favorite_interfaces';
+import Pagination from '../common/Pagination';
+interface FavoriteTableCompaniesProps {
+ favaddressbook: AddressBookFavoriteResponse[];
+}
+
+const FavoriteTableCompanies: React.FC = ({ favaddressbook }) => {
+ const [sortField, setSortField] = useState('changedAt');
+ const [sortOrder, setSortOrder] = useState<'asc' | 'desc'>('asc');
+ const [currentPage, setCurrentPage] = useState(1);
+ const [eventsPerPage, setEventsPerPage] = useState(5);
+
+ const { deleteFavorite, fetchFavorites } = useContext(FavoritesContext)!;
+
+ const handleSort = useCallback((field: string) => {
+ setSortField(field);
+ setSortOrder(prevOrder => (prevOrder === 'asc' ? 'desc' : 'asc') as 'asc' | 'desc');
+ }, []);
+
+
+ const sortedData = useMemo(() => {
+ const sortedArray = [...favaddressbook].sort((a, b) => {
+ let comparison = 0;
+ // if (sortField === 'changedAt' && a.changedAt && b.changedAt) {
+ // const dateA = new Date(a.changedAt).getTime();
+ // const dateB = new Date(b.changedAt).getTime();
+ // comparison = dateB - dateA; // Most recent first
+ // }
+ if (sortField !== 'changedAt' && a[sortField as keyof AddressBookFavoriteResponse] && b[sortField as keyof AddressBookFavoriteResponse]) {
+ const fieldA = a[sortField as keyof AddressBookFavoriteResponse];
+ const fieldB = b[sortField as keyof AddressBookFavoriteResponse];
+ comparison = fieldA.localeCompare(fieldB);
+ }
+ return sortOrder === 'asc' ? comparison : -comparison;
+ });
+ return sortedArray;
+ }, [favaddressbook, sortField, sortOrder]);
+
+ const indexOfLastEvent = currentPage * eventsPerPage;
+ const indexOfFirstEvent = indexOfLastEvent - eventsPerPage;
+ const currentEvents = sortedData.slice(indexOfFirstEvent, indexOfLastEvent);
+ const totalPagesNum = Math.ceil(sortedData.length / eventsPerPage);
+
+ const handleUnfavorite = useCallback(
+ async (id: string) => {
+ try {
+ await deleteFavorite(id)
+ fetchFavorites();
+ } catch (error) {
+ console.error('Error Unfavoriting:', error);
+ }
+ },
+ [favaddressbook]
+ );
+
+ return (
+ <>
+