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 ( + <> +
+ + + + + + + + + + + + + {favaddressbook.map((addressBook, index) => ( + + + + + + + + + ))} + +
Address Book Name Address Book Contact Address Book Email Address Book function
+ + handleUnfavorite(addressBook.companyId)} + size={25} + /> + + + + {addressBook.companyId}}> + + {addressBook.name}{addressBook.contact}{addressBook.email}{addressBook.function}
+
+
+
+ +
+
+
+ + + Per Page: + + + setEventsPerPage(Number(e.target.value))} + /> + + +
+
+
+
+
+ + ); +}; + +export default FavoriteTableCompanies; + + + diff --git a/demand-capacity-mgmt-frontend/src/components/pages/FavoritesPage.tsx b/demand-capacity-mgmt-frontend/src/components/pages/FavoritesPage.tsx index 8dbb7d8f..f244c1a0 100644 --- a/demand-capacity-mgmt-frontend/src/components/pages/FavoritesPage.tsx +++ b/demand-capacity-mgmt-frontend/src/components/pages/FavoritesPage.tsx @@ -28,6 +28,7 @@ import FavoritesTableCapacityGroup from "../favorites/FavoritesTableCapacityGrou import FavoriteTableCompanies from "../favorites/FavoritesTableCompanies"; import FavoritesTableEvents from "../favorites/FavoritesTableEvents"; import FavoriteTableMaterialDemands from "../favorites/FavoritesTableMaterialDemands"; +import FavoritesTableAddressBook from "../favorites/FavoritesTableAddressBook"; const FavoritesPage: React.FC = () => { const { favorites } = useContext(FavoritesContext)!; @@ -66,6 +67,11 @@ const FavoritesPage: React.FC = () => { events={favorites?.events || []} /> + + + diff --git a/demand-capacity-mgmt-frontend/src/contexts/InfoMenuContextProvider.tsx b/demand-capacity-mgmt-frontend/src/contexts/InfoMenuContextProvider.tsx index 16ace9f9..2fdce657 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'; diff --git a/demand-capacity-mgmt-frontend/src/interfaces/favorite_interfaces.tsx b/demand-capacity-mgmt-frontend/src/interfaces/favorite_interfaces.tsx index 51a7c0e0..73a9ce52 100644 --- a/demand-capacity-mgmt-frontend/src/interfaces/favorite_interfaces.tsx +++ b/demand-capacity-mgmt-frontend/src/interfaces/favorite_interfaces.tsx @@ -35,18 +35,29 @@ export interface SingleCapacityGroupFavoriteResponse { capacityGroupName: string; } +export interface AddressBookFavoriteResponse{ + id:string + companyId:string + name:string + contact:string + email:string + function:string +} + export interface FavoriteResponse { capacityGroups: SingleCapacityGroupFavoriteResponse[]; materialDemands: MaterialDemandFavoriteResponse[]; companies: CompanyDtoFavoriteResponse[]; events: EventFavoriteResponse[]; + addressBooks: AddressBookFavoriteResponse[]; } export enum FavoriteType { CAPACITY_GROUP = 'CAPACITY_GROUP', COMPANY_BASE_DATA = 'COMPANY_BASE_DATA', MATERIAL_DEMAND = 'MATERIAL_DEMAND', - EVENT = 'EVENT' + EVENT = 'EVENT', + ADDRESS_BOOK = 'ADDRESS_BOOK' } export interface FavoritePayload { diff --git a/demand-capacity-mgmt-frontend/src/interfaces/InfoMenu_interfaces.tsx b/demand-capacity-mgmt-frontend/src/interfaces/infomenu_interfaces.tsx similarity index 100% rename from demand-capacity-mgmt-frontend/src/interfaces/InfoMenu_interfaces.tsx rename to demand-capacity-mgmt-frontend/src/interfaces/infomenu_interfaces.tsx diff --git a/demand-capacity-mgmt-specification/src/main/resources/openapi.yml b/demand-capacity-mgmt-specification/src/main/resources/openapi.yml index b2ddd7bf..c7c3eb7f 100644 --- a/demand-capacity-mgmt-specification/src/main/resources/openapi.yml +++ b/demand-capacity-mgmt-specification/src/main/resources/openapi.yml @@ -183,13 +183,31 @@ paths: content: application/json: schema: - type: string + $ref: '#/components/schemas/AddressBookResponse' requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/AddressBookRequest' + get: + tags: + - addressBook + summary: get companies + operationId: getAddressBook + responses: + 200: + description: General greeting + content: + application/json: + schema: + $ref: '#/components/schemas/AddressBookResponse' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/AddressBookRequest' /loggingHistory/filterLogs: @@ -1492,6 +1510,25 @@ components: directQuery: type: boolean + AddressBookResponse: + type: object + properties: + id: + type: string + companyId: + type: string + name: + type: string + contact: + type: string + email: + type: string + function: + type: string + picture: + type: string + format: byte + MaterialDemandFavoriteResponse: type: object properties: @@ -1534,6 +1571,22 @@ components: favorited_at: type: string + AddressBookFavoriteResponse: + type: object + properties: + id: + type: string + companyId: + type: string + name: + type: string + contact: + type: string + email: + type: string + function: + type: string + UnitMeasure: type: object properties: @@ -1810,4 +1863,8 @@ components: events: type: array items: - $ref: '#/components/schemas/EventFavoriteResponse' \ No newline at end of file + $ref: '#/components/schemas/EventFavoriteResponse' + addressBooks: + type: array + items: + $ref: '#/components/schemas/AddressBookFavoriteResponse' \ No newline at end of file From bad61e1288323c3929753e377b451c9847b2f609 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Wed, 8 Nov 2023 14:36:41 +0000 Subject: [PATCH 06/12] address book crud --- .../controllers/AddressBookController.java | 33 ++++++++- .../services/AddressBookService.java | 7 +- .../services/impl/AddressBookServiceImpl.java | 32 +++++++-- .../src/main/resources/openapi.yml | 71 ++++++++++++++----- 4 files changed, 113 insertions(+), 30 deletions(-) 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 index f3273598..241588c0 100644 --- 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 @@ -24,12 +24,41 @@ import eclipse.tractusx.demand_capacity_mgmt_specification.api.AddressBookApi; import eclipse.tractusx.demand_capacity_mgmt_specification.model.AddressBookRequest; +import eclipse.tractusx.demand_capacity_mgmt_specification.model.AddressBookResponse; +import jakarta.servlet.http.HttpServletRequest; +import lombok.AllArgsConstructor; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.AddressBookService; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.utils.UserUtil; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RestController; +import java.util.List; +@RestController +@AllArgsConstructor public class AddressBookController implements AddressBookApi { + private final AddressBookService service; + private HttpServletRequest request; + + @Override + public ResponseEntity deleteAddressBook(AddressBookRequest addressBookRequest) throws Exception { + String userID = UserUtil.getUserID(request); + service.deleteRecord(addressBookRequest); + return ResponseEntity.status(201).build(); + } + + @Override + public ResponseEntity getAddressBook(AddressBookRequest addressBookRequest) throws Exception { + return ResponseEntity.status(200).body(service.getRecord(addressBookRequest)); + } + + @Override + public ResponseEntity> getAllAddressBooks(AddressBookRequest addressBookRequest) throws Exception { + return ResponseEntity.status(200).body(service.getRecords(addressBookRequest)); + } + @Override - public ResponseEntity getAddressBook(AddressBookRequest addressBookRequest) throws Exception { - return null; + public ResponseEntity postAddressBook(AddressBookRequest addressBookRequest) throws Exception { + return ResponseEntity.status(200).body(service.postRecord(addressBookRequest)); } } 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 37855272..33146fda 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 @@ -23,16 +23,17 @@ package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services; import eclipse.tractusx.demand_capacity_mgmt_specification.model.AddressBookRequest; +import eclipse.tractusx.demand_capacity_mgmt_specification.model.AddressBookResponse; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.AddressBookRecordEntity; import java.util.List; public interface AddressBookService { - AddressBookRecordEntity getRecord(AddressBookRequest request); + AddressBookResponse getRecord(AddressBookRequest request); - List getRecords(AddressBookRequest request); + List getRecords(AddressBookRequest request); - AddressBookRecordEntity postRecord(AddressBookRequest request); + AddressBookResponse postRecord(AddressBookRequest request); void deleteRecord(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 index e267deb2..f2edd42a 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,6 +23,7 @@ package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.impl; import eclipse.tractusx.demand_capacity_mgmt_specification.model.AddressBookRequest; +import eclipse.tractusx.demand_capacity_mgmt_specification.model.AddressBookResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.AddressBookRecordEntity; @@ -31,6 +32,7 @@ import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.GoldenRecordManager; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.UUID; @@ -45,11 +47,11 @@ public class AddressBookServiceImpl implements AddressBookService { private final GoldenRecordManager goldenRecordManager; @Override - public AddressBookRecordEntity getRecord(AddressBookRequest request) { + public AddressBookResponse getRecord(AddressBookRequest request) { if(Boolean.FALSE.equals(request.getDirectQuery())){ Optional entity = repository.findById(UUID.fromString(request.getQuery())); if(entity.isPresent()){ - return entity.get(); + return convertEntityToDto(entity.get()); } } else { //TODO GOLDEN RECORD IMPL @@ -59,24 +61,40 @@ public AddressBookRecordEntity getRecord(AddressBookRequest request) { } @Override - public List getRecords(AddressBookRequest request) { + public List getRecords(AddressBookRequest request) { List records; if(Boolean.TRUE.equals(request.getDirectQuery())){ return null; } else { records = repository.findByNameOrCompanyId(request.getQuery(), UUID.fromString(request.getQuery())); - return records; + List response = new ArrayList<>(); + for(AddressBookRecordEntity ent : records){ + response.add(convertEntityToDto(ent)); + } + return response; } } @Override - public AddressBookRecordEntity postRecord(AddressBookRequest request) { - AddressBookRecordEntity entity = goldenRecordManager.createRecord(request.getQuery()); - return entity; + public AddressBookResponse postRecord(AddressBookRequest request) { + return convertEntityToDto(goldenRecordManager.createRecord(request.getQuery())); } @Override public void deleteRecord(AddressBookRequest request) { repository.deleteById(UUID.fromString(request.getQuery())); } + + + private AddressBookResponse convertEntityToDto(AddressBookRecordEntity entity){ + AddressBookResponse response = new AddressBookResponse(); + response.setId(entity.getId().toString()); + response.setContact(entity.getContact()); + response.setName(entity.getName()); + response.setEmail(entity.getEmail()); + response.setFunction(entity.getFunction()); + response.setCompanyId(entity.getCompanyId().toString()); + response.setPicture(entity.getPicture()); + return response; + } } diff --git a/demand-capacity-mgmt-specification/src/main/resources/openapi.yml b/demand-capacity-mgmt-specification/src/main/resources/openapi.yml index c7c3eb7f..e961d0c3 100644 --- a/demand-capacity-mgmt-specification/src/main/resources/openapi.yml +++ b/demand-capacity-mgmt-specification/src/main/resources/openapi.yml @@ -170,13 +170,32 @@ paths: type: array items: $ref: '#/components/schemas/LoggingHistoryResponse' - /addressBook: get: tags: - addressBook - summary: get companies - operationId: getAddressBook + summary: get all companies + operationId: getAllAddressBooks + responses: + 200: + description: General greeting + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/AddressBookResponse' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/AddressBookRequest' + post: + tags: + - addressBook + summary: post a record + operationId: postAddressBook responses: 200: description: General greeting @@ -190,24 +209,40 @@ paths: application/json: schema: $ref: '#/components/schemas/AddressBookRequest' - get: - tags: - - addressBook - summary: get companies - operationId: getAddressBook - responses: - 200: - description: General greeting + delete: + tags: + - addressBook + summary: delete a record + operationId: deleteAddressBook + responses: + 201: + description: General greeting + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/AddressBookRequest' + + /addressBook/query: + get: + tags: + - addressBook + summary: get companies + operationId: getAddressBook + responses: + 200: + description: General greeting + content: + application/json: + schema: + $ref: '#/components/schemas/AddressBookResponse' + requestBody: + required: true content: application/json: schema: - $ref: '#/components/schemas/AddressBookResponse' - requestBody: - required: true - content: - application/json: - schema: - $ref: '#/components/schemas/AddressBookRequest' + $ref: '#/components/schemas/AddressBookRequest' /loggingHistory/filterLogs: From 660ad2b072cd0e5d5217ee832ef3bb61f1ca41ff Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Wed, 8 Nov 2023 15:33:15 +0000 Subject: [PATCH 07/12] Role based access --- .../controllers/AddressBookController.java | 10 +++-- .../impl/SecurityTokenServiceImpl.java | 2 +- .../utils/UserUtil.java | 42 +++++++++++++++++-- 3 files changed, 47 insertions(+), 7 deletions(-) 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 index 241588c0..bf389efc 100644 --- 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 @@ -27,6 +27,7 @@ import eclipse.tractusx.demand_capacity_mgmt_specification.model.AddressBookResponse; import jakarta.servlet.http.HttpServletRequest; import lombok.AllArgsConstructor; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.Role; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.AddressBookService; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.utils.UserUtil; import org.springframework.http.ResponseEntity; @@ -42,9 +43,12 @@ public class AddressBookController implements AddressBookApi { @Override public ResponseEntity deleteAddressBook(AddressBookRequest addressBookRequest) throws Exception { - String userID = UserUtil.getUserID(request); - service.deleteRecord(addressBookRequest); - return ResponseEntity.status(201).build(); + if(UserUtil.getUserRole(request).equals(Role.ADMIN)){ + service.deleteRecord(addressBookRequest); + return ResponseEntity.status(201).build(); + } + return ResponseEntity.status(401).build(); + } @Override diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/SecurityTokenServiceImpl.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/SecurityTokenServiceImpl.java index 69616cd2..2b51c29b 100644 --- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/SecurityTokenServiceImpl.java +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/SecurityTokenServiceImpl.java @@ -243,7 +243,7 @@ private UserEntity generateUser(String userID, DecodedJWT decodedJWT) { newUserEntity.setRole(role); break; } catch (IllegalArgumentException e) { - Logger.logError("Incompatible role! User must have one of the 3 role types 'ADMIN','"); + Logger.logError("Incompatible role! User must have one of the 3 role types 'ADMIN','CUSTOMER','SUPPLIER'"); } } } diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/utils/UserUtil.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/utils/UserUtil.java index 7d4b3663..90ad8160 100644 --- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/utils/UserUtil.java +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/utils/UserUtil.java @@ -1,13 +1,17 @@ package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.utils; import com.auth0.jwt.JWT; +import com.auth0.jwt.interfaces.Claim; import com.auth0.jwt.interfaces.DecodedJWT; -import eclipse.tractusx.demand_capacity_mgmt_specification.model.User; +import com.fasterxml.uuid.Logger; import jakarta.servlet.http.HttpServletRequest; -import java.util.Objects; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.UserEntity; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.Role; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories.UserRepository; -public class UserUtil { +import java.util.*; +public class UserUtil { public static String getUserID(HttpServletRequest request) { try { DecodedJWT decodedJWT = JWT.decode(Objects.requireNonNull(getTokenFromHeader(request))); @@ -24,4 +28,36 @@ private static String getTokenFromHeader(HttpServletRequest request) { } return null; } + + public static Role getUserRole(HttpServletRequest request) { + try { + DecodedJWT decodedJWT = JWT.decode(Objects.requireNonNull(getTokenFromHeader(request))); + Claim rolesClaim = decodedJWT.getClaim("realm_access"); + Map realmAccessMap = Optional + .ofNullable(rolesClaim) + .map(Claim::asMap) + .orElse(Collections.emptyMap()); + + Object rolesObject = realmAccessMap.get("roles"); + + if (rolesObject instanceof List) { + List list = (List) rolesObject; + for (Object roleObj : list) { + if (roleObj instanceof String) { + String roleStr = (String) roleObj; + try { + return Role.valueOf( + roleStr + ); + } catch (IllegalArgumentException e) { + Logger.logError("Incompatible role! User must have one of the 3 role types 'ADMIN','CUSTOMER','SUPPLIER'"); + } + } + } + } + } catch (Exception e) { + return null; + } + return null; + } } From 971c56c08dbdbf404d03d817b0e845f91ece09c6 Mon Sep 17 00:00:00 2001 From: Sergio Figueiredo Date: Thu, 9 Nov 2023 16:32:07 +0000 Subject: [PATCH 08/12] Admin Help File --- .../components/demands/DemandManagement.tsx | 2 +- ...e.tsx => DemandManagementTableHeaders.tsx} | 0 .../src/components/menu/InfoMenu.tsx | 2 - .../src/components/pages/AdminPage.tsx | 42 ++++++++++++++++--- .../src/contexts/InfoMenuContextProvider.tsx | 2 +- 5 files changed, 38 insertions(+), 10 deletions(-) rename demand-capacity-mgmt-frontend/src/components/demands/{DemandManagementTable.tsx => DemandManagementTableHeaders.tsx} (100%) diff --git a/demand-capacity-mgmt-frontend/src/components/demands/DemandManagement.tsx b/demand-capacity-mgmt-frontend/src/components/demands/DemandManagement.tsx index 998537de..d8c0e38b 100644 --- a/demand-capacity-mgmt-frontend/src/components/demands/DemandManagement.tsx +++ b/demand-capacity-mgmt-frontend/src/components/demands/DemandManagement.tsx @@ -43,7 +43,7 @@ import { } from "../../interfaces/favorite_interfaces"; import DangerConfirmationModal, { ConfirmationAction } from '../common/DangerConfirmationModal'; import { LoadingMessage } from '../common/LoadingMessages'; -import DemandManagementTable from './DemandManagementTable'; +import DemandManagementTable from './DemandManagementTableHeaders'; const DemandManagement: React.FC = () => { const [showEditModal, setIsEditModalOpen] = useState(false); diff --git a/demand-capacity-mgmt-frontend/src/components/demands/DemandManagementTable.tsx b/demand-capacity-mgmt-frontend/src/components/demands/DemandManagementTableHeaders.tsx similarity index 100% rename from demand-capacity-mgmt-frontend/src/components/demands/DemandManagementTable.tsx rename to demand-capacity-mgmt-frontend/src/components/demands/DemandManagementTableHeaders.tsx diff --git a/demand-capacity-mgmt-frontend/src/components/menu/InfoMenu.tsx b/demand-capacity-mgmt-frontend/src/components/menu/InfoMenu.tsx index ead8788c..852ca81e 100644 --- a/demand-capacity-mgmt-frontend/src/components/menu/InfoMenu.tsx +++ b/demand-capacity-mgmt-frontend/src/components/menu/InfoMenu.tsx @@ -24,8 +24,6 @@ import Nav from "react-bootstrap/Nav"; import { FaArrowDown, FaArrowUp, FaHome, FaStar } from "react-icons/fa"; import { useNavigate } from "react-router-dom"; import { useInfoMenu } from "../../contexts/InfoMenuContextProvider"; -//Events, Capacitity groups, material demands - function InfoMenu() { diff --git a/demand-capacity-mgmt-frontend/src/components/pages/AdminPage.tsx b/demand-capacity-mgmt-frontend/src/components/pages/AdminPage.tsx index cbf68714..6dcedbe4 100644 --- a/demand-capacity-mgmt-frontend/src/components/pages/AdminPage.tsx +++ b/demand-capacity-mgmt-frontend/src/components/pages/AdminPage.tsx @@ -23,9 +23,9 @@ import { useEffect, useState } from 'react'; -import { Col, Nav, Row, Tab, TabContent } from 'react-bootstrap'; -import { FaBell, FaClock, FaCogs, FaFingerprint, FaHeartbeat, FaKey } from 'react-icons/fa'; -import { FcEngineering } from 'react-icons/fc'; +import { Button, Col, Modal, Nav, Row, Tab, TabContent } from 'react-bootstrap'; +import { FaBell, FaClock, FaCogs, FaFingerprint, FaHeartbeat, FaKey, FaQuestion } from 'react-icons/fa'; +import { FcEngineering, FcQuestions } from 'react-icons/fc'; import { useNavigate } from 'react-router-dom'; import { useUser } from '../../contexts/UserContext'; import { LoadingMessage } from '../common/LoadingMessages'; @@ -34,6 +34,7 @@ const AdminPage = () => { const { user } = useUser(); const [loading, setLoading] = useState(false); const [activeTab, setActiveTab] = useState('general'); + const [showHelpModal, setShowHelpModal] = useState(false); const navigate = useNavigate() @@ -47,11 +48,24 @@ const AdminPage = () => { return ; // Show loading spinner when data is loading } + const handleHelpModalClose = () => setShowHelpModal(false); + const handleQuestionButtonClick = () => setShowHelpModal(true); + return (<>
-
- -

Admin Dashboard

+ +
+
+
+ +

Admin Dashboard

+
+
+
+ +

@@ -128,6 +142,22 @@ const AdminPage = () => {
+ + + + Help + + +

Cat-X Portal Core

+

Cat-X CX-0010 Business Partner Number Standards

+
+ + + +
+ ); }; diff --git a/demand-capacity-mgmt-frontend/src/contexts/InfoMenuContextProvider.tsx b/demand-capacity-mgmt-frontend/src/contexts/InfoMenuContextProvider.tsx index 594a6505..16ace9f9 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 333fe2673d3e3242b194d492be44d66563532756 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Fri, 10 Nov 2023 12:56:37 +0000 Subject: [PATCH 09/12] addressBook fixes --- .../controllers/AddressBookController.java | 4 ++-- .../services/AddressBookService.java | 3 +-- .../services/impl/AddressBookServiceImpl.java | 8 ++------ .../src/main/resources/openapi.yml | 6 ------ 4 files changed, 5 insertions(+), 16 deletions(-) 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 index bf389efc..778eb4b9 100644 --- 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 @@ -57,8 +57,8 @@ public ResponseEntity getAddressBook(AddressBookRequest add } @Override - public ResponseEntity> getAllAddressBooks(AddressBookRequest addressBookRequest) throws Exception { - return ResponseEntity.status(200).body(service.getRecords(addressBookRequest)); + public ResponseEntity> getAllAddressBooks() throws Exception { + return ResponseEntity.status(200).body(service.getRecords()); } @Override 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 33146fda..76424d60 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 @@ -24,14 +24,13 @@ import eclipse.tractusx.demand_capacity_mgmt_specification.model.AddressBookRequest; import eclipse.tractusx.demand_capacity_mgmt_specification.model.AddressBookResponse; -import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.AddressBookRecordEntity; import java.util.List; public interface AddressBookService { AddressBookResponse getRecord(AddressBookRequest request); - List getRecords(AddressBookRequest request); + List getRecords(); AddressBookResponse 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 index f2edd42a..99795ce8 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 @@ -61,18 +61,14 @@ public AddressBookResponse getRecord(AddressBookRequest request) { } @Override - public List getRecords(AddressBookRequest request) { + public List getRecords() { List records; - if(Boolean.TRUE.equals(request.getDirectQuery())){ - return null; - } else { - records = repository.findByNameOrCompanyId(request.getQuery(), UUID.fromString(request.getQuery())); + records = repository.findAll(); List response = new ArrayList<>(); for(AddressBookRecordEntity ent : records){ response.add(convertEntityToDto(ent)); } return response; - } } @Override diff --git a/demand-capacity-mgmt-specification/src/main/resources/openapi.yml b/demand-capacity-mgmt-specification/src/main/resources/openapi.yml index e961d0c3..e97af332 100644 --- a/demand-capacity-mgmt-specification/src/main/resources/openapi.yml +++ b/demand-capacity-mgmt-specification/src/main/resources/openapi.yml @@ -185,12 +185,6 @@ paths: type: array items: $ref: '#/components/schemas/AddressBookResponse' - requestBody: - required: true - content: - application/json: - schema: - $ref: '#/components/schemas/AddressBookRequest' post: tags: - addressBook From 0c8c71ff1c420e57dccaa08c6be418d04288f189 Mon Sep 17 00:00:00 2001 From: Sergio Figueiredo Date: Tue, 14 Nov 2023 12:33:26 +0000 Subject: [PATCH 10/12] -UserRoles an rights --- .../src/components/common/TopMenu.tsx | 4 +- .../components/demands/DemandManagement.tsx | 15 ++++--- .../components/demands/DemandsOverview.tsx | 41 ++++++++++--------- .../src/components/events/EventsTable.tsx | 7 ++-- .../src/components/pages/EventsPage.tsx | 9 ++-- .../src/components/pages/TodoListPage.tsx | 31 ++++++++------ 6 files changed, 60 insertions(+), 47 deletions(-) diff --git a/demand-capacity-mgmt-frontend/src/components/common/TopMenu.tsx b/demand-capacity-mgmt-frontend/src/components/common/TopMenu.tsx index 15e23493..144f1974 100644 --- a/demand-capacity-mgmt-frontend/src/components/common/TopMenu.tsx +++ b/demand-capacity-mgmt-frontend/src/components/common/TopMenu.tsx @@ -37,10 +37,8 @@ import { logout } from "../../util/Auth"; import InfoMenu from "../menu/InfoMenu"; function TopMenuLinks() { - const { refresh_token } = useUser(); - const { user } = useUser(); + const { user, refresh_token, setUser } = useUser(); const navigate = useNavigate(); - const { setUser } = useUser(); const [collapsed, setCollapsed] = useState(() => { // Load the state from local storage, defaulting to false if it doesn't exist return localStorage.getItem('navbarCollapsed') === 'true'; diff --git a/demand-capacity-mgmt-frontend/src/components/demands/DemandManagement.tsx b/demand-capacity-mgmt-frontend/src/components/demands/DemandManagement.tsx index d8c0e38b..4e712345 100644 --- a/demand-capacity-mgmt-frontend/src/components/demands/DemandManagement.tsx +++ b/demand-capacity-mgmt-frontend/src/components/demands/DemandManagement.tsx @@ -36,6 +36,7 @@ import EditForm from './DemandEditForm'; import { LuStar } from 'react-icons/lu'; import { FavoritesContext } from "../../contexts/FavoritesContextProvider"; +import { useUser } from '../../contexts/UserContext'; import { EventType } from '../../interfaces/event_interfaces'; import { FavoriteType, @@ -46,6 +47,7 @@ import { LoadingMessage } from '../common/LoadingMessages'; import DemandManagementTable from './DemandManagementTableHeaders'; const DemandManagement: React.FC = () => { + const { user } = useUser(); const [showEditModal, setIsEditModalOpen] = useState(false); const [showAddModal, setShowAddModal] = useState(false); const [showDetailsModal, setShowDetailsModal] = useState(false); @@ -309,8 +311,8 @@ const DemandManagement: React.FC = () => { N/A )} - - + {user?.role === 'CUSTOMER' && ( + )} @@ -341,10 +343,11 @@ const DemandManagement: React.FC = () => {
- + {user?.role === 'CUSTOMER' && ( + )} diff --git a/demand-capacity-mgmt-frontend/src/components/demands/DemandsOverview.tsx b/demand-capacity-mgmt-frontend/src/components/demands/DemandsOverview.tsx index 34b60174..ffcbe173 100644 --- a/demand-capacity-mgmt-frontend/src/components/demands/DemandsOverview.tsx +++ b/demand-capacity-mgmt-frontend/src/components/demands/DemandsOverview.tsx @@ -32,6 +32,7 @@ import { Demand, DemandCategory, DemandProp, DemandSeriesValue, MaterialDemandSe import { format, getISOWeek, } from 'date-fns'; import { useNavigate } from 'react-router-dom'; +import { useUser } from '../../contexts/UserContext'; import { LoadingGatheringDataMessage } from '../common/LoadingMessages'; interface WeeklyViewProps { @@ -88,6 +89,7 @@ const WeeklyView: React.FC = ({ demandId }) => { const currentYear = new Date().getFullYear(); const [editMode, setEditMode] = useState(false); const [isLoading, setIsLoading] = useState(true); + const { user } = useUser(); const { getDemandbyId } = useContext(DemandContext)!; const [demandData, setDemandData] = useState(); @@ -356,26 +358,27 @@ const WeeklyView: React.FC = ({ demandId }) => {
{demandData?.id} - {demandData?.materialDescriptionCustomer}
+
-
- - setEditMode(!editMode)} - >Edit - - - - +
{user?.role === 'CUSTOMER' && ( + + setEditMode(!editMode)} + >Edit + + + + )}

diff --git a/demand-capacity-mgmt-frontend/src/components/events/EventsTable.tsx b/demand-capacity-mgmt-frontend/src/components/events/EventsTable.tsx index c8ca3cb5..12552502 100644 --- a/demand-capacity-mgmt-frontend/src/components/events/EventsTable.tsx +++ b/demand-capacity-mgmt-frontend/src/components/events/EventsTable.tsx @@ -34,6 +34,7 @@ import { import { LuStar } from 'react-icons/lu'; import { EventsContext } from '../../contexts/EventsContextProvider'; import { FavoritesContext } from "../../contexts/FavoritesContextProvider"; +import { useUser } from '../../contexts/UserContext'; import { EventProp, eventTypeIcons } from '../../interfaces/event_interfaces'; import { EventFavoriteResponse, FavoriteType } from "../../interfaces/favorite_interfaces"; import DangerConfirmationModal, { ConfirmationAction } from '../common/DangerConfirmationModal'; @@ -45,6 +46,7 @@ interface EventsTableProps { } const EventsTable: React.FC = ({ events, isArchive }) => { + const { user } = useUser(); const eventsContext = useContext(EventsContext)!; const [sortField, setSortField] = useState('timestamp'); const [sortOrder, setSortOrder] = useState<'asc' | 'desc'>('asc'); @@ -286,9 +288,8 @@ const EventsTable: React.FC = ({ events, isArchive }) => { { navigator.clipboard.writeText(event.id.toString()) }}> Copy ID - {isArchive ? null : ( - handleDeleteButtonClick(event.id.toString())}> + {isArchive !== null && user?.role === 'ADMIN' && ( + handleDeleteButtonClick(event.id.toString())}> Delete )} diff --git a/demand-capacity-mgmt-frontend/src/components/pages/EventsPage.tsx b/demand-capacity-mgmt-frontend/src/components/pages/EventsPage.tsx index f5705287..47fdc5dc 100644 --- a/demand-capacity-mgmt-frontend/src/components/pages/EventsPage.tsx +++ b/demand-capacity-mgmt-frontend/src/components/pages/EventsPage.tsx @@ -27,6 +27,7 @@ import { LuStar } from "react-icons/lu"; import Creatable from 'react-select/creatable'; import { EventsContext } from "../../contexts/EventsContextProvider"; import { FavoritesContext } from "../../contexts/FavoritesContextProvider"; +import { useUser } from "../../contexts/UserContext"; import CustomOption from "../../interfaces/customoption_interface"; import { EventProp } from "../../interfaces/event_interfaces"; import { FavoriteType } from "../../interfaces/favorite_interfaces"; @@ -35,6 +36,7 @@ import { LoadingMessage } from "../common/LoadingMessages"; import EventsTable from "../events/EventsTable"; function EventsPage() { + const { user } = useUser(); const [activeTab, setActiveTab] = useState("Events"); const [userInput, setUserInput] = useState(''); const { events, archiveEvents, fetchEvents, fetchFilteredEvents, deleteAllEvents } = useContext(EventsContext)!; @@ -200,9 +202,10 @@ function EventsPage() { - + {user?.role === 'ADMIN' && ( + )} diff --git a/demand-capacity-mgmt-frontend/src/components/pages/TodoListPage.tsx b/demand-capacity-mgmt-frontend/src/components/pages/TodoListPage.tsx index c0703fcd..84dc67ac 100644 --- a/demand-capacity-mgmt-frontend/src/components/pages/TodoListPage.tsx +++ b/demand-capacity-mgmt-frontend/src/components/pages/TodoListPage.tsx @@ -26,6 +26,7 @@ import { FaMagic, FaRedo } from "react-icons/fa"; import { FcTodoList } from "react-icons/fc"; import { DemandContext } from "../../contexts/DemandContextProvider"; import { EventsContext } from "../../contexts/EventsContextProvider"; +import { useUser } from "../../contexts/UserContext"; import { EventProp, EventType } from "../../interfaces/event_interfaces"; import { LoadingMessage } from "../common/LoadingMessages"; import DemandsSearch from "../common/Search"; @@ -41,6 +42,7 @@ function TodoListPage() { const { fetchFilteredEvents } = useContext(EventsContext)!; const [filteredEvents, setFilteredEvents] = useState([]); const [loading, setLoading] = useState(false); + const { user } = useUser(); useEffect(() => { const fetchData = async () => { @@ -110,19 +112,22 @@ function TodoListPage() { - - - + {user?.role === 'SUPPLIER' && ( + <> + + + + )} From c9e6fb814765389c85688a7dfb4a600fccd59629 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Tue, 14 Nov 2023 17:32:51 +0000 Subject: [PATCH 11/12] user edit + keycloak fix --- .../controllers/UserController.java | 24 +++++++++++++ .../entities/UserEntity.java | 3 ++ .../services/UserOperationsService.java | 7 ++++ .../impl/SecurityTokenServiceImpl.java | 7 ++-- .../impl/UserOperationsServiceImpl.java | 36 +++++++++++++++++++ .../src/main/resources/application.yml | 4 +-- .../db/migration/V7__Create_User_Table.sql | 1 + .../src/main/resources/openapi.yml | 36 +++++++++++++++++++ 8 files changed, 113 insertions(+), 5 deletions(-) create mode 100644 demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/UserController.java create mode 100644 demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/UserOperationsService.java create mode 100644 demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/UserOperationsServiceImpl.java diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/UserController.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/UserController.java new file mode 100644 index 00000000..26f69f86 --- /dev/null +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/UserController.java @@ -0,0 +1,24 @@ +package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.controllers; + +import eclipse.tractusx.demand_capacity_mgmt_specification.api.UserOperationsApi; +import eclipse.tractusx.demand_capacity_mgmt_specification.model.UserRequest; +import jakarta.servlet.http.HttpServletRequest; +import lombok.AllArgsConstructor; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.UserOperationsService; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.utils.UserUtil; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@AllArgsConstructor +public class UserController implements UserOperationsApi { + + private final UserOperationsService service; + private HttpServletRequest request; + + @Override + public ResponseEntity updateAnUser(UserRequest userRequest) throws Exception { + service.updateUser(userRequest); + return ResponseEntity.status(201).build(); + } +} diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/UserEntity.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/UserEntity.java index 11fc1617..f99547ff 100644 --- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/UserEntity.java +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/UserEntity.java @@ -54,6 +54,9 @@ public class UserEntity { @Column(name = "username") private String username; + @Column(name = "company_id") + private UUID companyID; + @Column(name = "role", columnDefinition = "varchar") @Enumerated(EnumType.STRING) private Role role; diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/UserOperationsService.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/UserOperationsService.java new file mode 100644 index 00000000..f893d865 --- /dev/null +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/UserOperationsService.java @@ -0,0 +1,7 @@ +package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services; + +import eclipse.tractusx.demand_capacity_mgmt_specification.model.UserRequest; + +public interface UserOperationsService { + void updateUser(UserRequest request); +} diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/SecurityTokenServiceImpl.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/SecurityTokenServiceImpl.java index 69616cd2..254ddac8 100644 --- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/SecurityTokenServiceImpl.java +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/SecurityTokenServiceImpl.java @@ -262,20 +262,21 @@ private User convertUserEntity(UserEntity userEntity, String accessToken, String user.setAccessToken(accessToken); user.setRefreshToken(refreshToken); user.setExpiresIn(expiresIn); + user.setCompanyID(user.getCompanyID()); statusManager.calculateBottleneck(user.getUserID(), false); statusManager.calculateTodos(user.getUserID()); return user; } private String tokenUrl() { - return String.format("%s/auth/realms/%s/protocol/openid-connect/token", keycloakBaseUrl, realm); + return String.format("%s/realms/%s/protocol/openid-connect/token", keycloakBaseUrl, realm); } private String introspectTokenUrl() { - return String.format("%s/auth/realms/%s/protocol/openid-connect/token/introspect", keycloakBaseUrl, realm); + return String.format("%s/realms/%s/protocol/openid-connect/token/introspect", keycloakBaseUrl, realm); } private String logoutTokenUrl() { - return String.format("%s/auth/realms/%s/protocol/openid-connect/logout", keycloakBaseUrl, realm); + return String.format("%s/realms/%s/protocol/openid-connect/logout", keycloakBaseUrl, realm); } } diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/UserOperationsServiceImpl.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/UserOperationsServiceImpl.java new file mode 100644 index 00000000..37a929ed --- /dev/null +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/UserOperationsServiceImpl.java @@ -0,0 +1,36 @@ +package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.impl; + +import eclipse.tractusx.demand_capacity_mgmt_specification.model.UserRequest; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.UserEntity; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.Role; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories.UserRepository; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.UserOperationsService; +import org.springframework.stereotype.Service; + +import java.util.Optional; +import java.util.UUID; + +@RequiredArgsConstructor +@Service +@Slf4j +public class UserOperationsServiceImpl implements UserOperationsService { + + private final UserRepository repository; + + @Override + public void updateUser(UserRequest request) { + Optional userEntity = repository.findById(UUID.fromString(request.getUserID())); + if(userEntity.isPresent()){ + UserEntity user = userEntity.get(); + user.setRole(Role.valueOf(request.getRole().name())); + user.setUsername(request.getUsername()); + user.setName(request.getName()); + user.setLastName(request.getLastName()); + user.setEmail(request.getEmail()); + user.setCompanyID(UUID.fromString(request.getCompanyID())); + repository.save(user); + } + } +} diff --git a/demand-capacity-mgmt-backend/src/main/resources/application.yml b/demand-capacity-mgmt-backend/src/main/resources/application.yml index c0f4a716..c3d89da6 100644 --- a/demand-capacity-mgmt-backend/src/main/resources/application.yml +++ b/demand-capacity-mgmt-backend/src/main/resources/application.yml @@ -21,9 +21,9 @@ spring: security: oauth2: - resourceserver: + resource-server: jwt: - issuer-uri: http://localhost:8888/auth/realms/dcm + issuer-uri: http://localhost:8888/realms/dcm datasource: url: jdbc:postgresql://${DCM_DATASOURCE_HOST:localhost:5432}/${DCM_DATASOURCE_NAME:dcm} diff --git a/demand-capacity-mgmt-backend/src/main/resources/db/migration/V7__Create_User_Table.sql b/demand-capacity-mgmt-backend/src/main/resources/db/migration/V7__Create_User_Table.sql index 5d48e43c..7ff95ef3 100644 --- a/demand-capacity-mgmt-backend/src/main/resources/db/migration/V7__Create_User_Table.sql +++ b/demand-capacity-mgmt-backend/src/main/resources/db/migration/V7__Create_User_Table.sql @@ -28,5 +28,6 @@ create table if not exists dcm_users last_name varchar(150), email varchar(150), username varchar(50), + companyID uuid, role varchar(50) ) \ No newline at end of file diff --git a/demand-capacity-mgmt-specification/src/main/resources/openapi.yml b/demand-capacity-mgmt-specification/src/main/resources/openapi.yml index c34f15bb..1d5da270 100644 --- a/demand-capacity-mgmt-specification/src/main/resources/openapi.yml +++ b/demand-capacity-mgmt-specification/src/main/resources/openapi.yml @@ -126,6 +126,22 @@ paths: schema: $ref: '#/components/schemas/IntrospectTokenResponse' + /user: + put: + tags: + - userOperations + summary: edit a user + operationId: update an user + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/UserRequest' + responses: + 201: + description: General Greeting + /loggingHistory: post: tags: @@ -892,6 +908,24 @@ paths: components: schemas: + UserRequest: + type: object + properties: + userID: + type: string + name: + type: string + lastName: + type: string + email: + type: string + username: + type: string + companyID: + type: string + role: + $ref: '#/components/schemas/Role' + User: type: object properties: @@ -905,6 +939,8 @@ components: type: string username: type: string + companyID: + type: string role: $ref: '#/components/schemas/Role' access_token: From 115ea41ed0955107918df3807dd6b884e4d97f52 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Wed, 15 Nov 2023 11:43:56 +0000 Subject: [PATCH 12/12] fetch by company ID on customer side. --- .../controllers/CapacityGroupsController.java | 7 ++- .../services/CapacityGroupService.java | 4 +- .../impl/CapacityGroupServiceImpl.java | 46 ++++++++++++------- 3 files changed, 37 insertions(+), 20 deletions(-) diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/CapacityGroupsController.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/CapacityGroupsController.java index 17b98d0c..f9fe44c2 100644 --- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/CapacityGroupsController.java +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/CapacityGroupsController.java @@ -25,14 +25,16 @@ import eclipse.tractusx.demand_capacity_mgmt_specification.api.CapacityGroupApi; import eclipse.tractusx.demand_capacity_mgmt_specification.model.*; import jakarta.servlet.http.HttpServletRequest; -import java.util.List; import lombok.AllArgsConstructor; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.Role; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.CapacityGroupService; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.utils.UserUtil; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RestController; +import java.util.List; + @RestController @AllArgsConstructor public class CapacityGroupsController implements CapacityGroupApi { @@ -43,7 +45,8 @@ public class CapacityGroupsController implements CapacityGroupApi { @Override public ResponseEntity> getCapacityGroups() { String userID = UserUtil.getUserID(request); - List capacityGroupDefaultViewResponses = service.getAll(userID); + Role userRole = UserUtil.getUserRole(request); + List capacityGroupDefaultViewResponses = service.getAll(userID,userRole); return ResponseEntity.status(HttpStatus.OK).body(capacityGroupDefaultViewResponses); } diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/CapacityGroupService.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/CapacityGroupService.java index c316f1b4..8ee8d1b1 100644 --- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/CapacityGroupService.java +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/CapacityGroupService.java @@ -23,6 +23,8 @@ package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services; import eclipse.tractusx.demand_capacity_mgmt_specification.model.*; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.Role; + import java.util.List; public interface CapacityGroupService { @@ -31,5 +33,5 @@ public interface CapacityGroupService { void linkCapacityGroupToMaterialDemand(LinkCGDSRequest linkCGDSRequest, String userID); SingleCapacityGroup getCapacityGroupById(String CapacityGroupId); - List getAll(String userID); + List getAll(String userID, Role role); } diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/CapacityGroupServiceImpl.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/CapacityGroupServiceImpl.java index 99370f39..b38c09c3 100644 --- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/CapacityGroupServiceImpl.java +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/CapacityGroupServiceImpl.java @@ -23,28 +23,27 @@ package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.impl; import eclipse.tractusx.demand_capacity_mgmt_specification.model.*; -import java.math.BigDecimal; -import java.time.LocalDate; -import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.UUID; -import java.util.concurrent.atomic.AtomicBoolean; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.*; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.EventObjectType; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.EventType; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.Role; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.exceptions.type.NotFoundException; -import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories.CapacityGroupRepository; -import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories.DemandSeriesRepository; -import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories.LinkedCapacityGroupMaterialDemandRepository; -import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories.MaterialDemandRepository; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories.*; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.*; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.utils.UUIDUtil; import org.springframework.stereotype.Service; +import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.UUID; +import java.util.concurrent.atomic.AtomicBoolean; + @RequiredArgsConstructor @Service @Slf4j @@ -61,6 +60,8 @@ public class CapacityGroupServiceImpl implements CapacityGroupService { private final FavoriteService favoriteService; private final StatusManagerImpl statusManager; + private final UserRepository userRepository; + @Override public CapacityGroupResponse createCapacityGroup(CapacityGroupRequest capacityGroupRequest, String userID) { CapacityGroupEntity capacityGroupEntity = enrichCapacityGroup(capacityGroupRequest); @@ -222,11 +223,22 @@ public SingleCapacityGroup getCapacityGroupById(String capacityGroupId) { } @Override - public List getAll(String userID) { - List capacityGroupEntityList = capacityGroupRepository.findByUserID( - UUID.fromString(userID) - ); - return convertCapacityGroupEntity(capacityGroupEntityList); + public List getAll(String userID, Role role) { + if(role.equals(Role.SUPPLIER)){ + List capacityGroupEntityList = capacityGroupRepository.findByUserID( + UUID.fromString(userID) + ); + return convertCapacityGroupEntity(capacityGroupEntityList); + } + else if(role.equals(Role.CUSTOMER)) { + String companyID = String.valueOf(userRepository.findById(UUID.fromString(userID)).get().getCompanyID()); + List capacityGroupEntityList = capacityGroupRepository.findByCustomer_Id(UUID.fromString(companyID)); + return convertCapacityGroupEntity(capacityGroupEntityList); + } + else { + List capacityGroupEntityList = capacityGroupRepository.findAll(); + return convertCapacityGroupEntity(capacityGroupEntityList); + } } private CapacityGroupEntity getCapacityGroupEntity(String capacityGroupId) {