diff --git a/.github/workflows/veracode-pipeline.yml b/.github/workflows/veracode-pipeline.yml index f605ee91..73dbfea8 100644 --- a/.github/workflows/veracode-pipeline.yml +++ b/.github/workflows/veracode-pipeline.yml @@ -18,7 +18,6 @@ # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************** - name: Veracode Static Analysis Pipeline Scan on: diff --git a/DEPENDENCIES_FRONTEND b/DEPENDENCIES_FRONTEND index 0ec0408e..0f8c586c 100644 --- a/DEPENDENCIES_FRONTEND +++ b/DEPENDENCIES_FRONTEND @@ -300,7 +300,7 @@ npm/npmjs/-/escape-string-regexp/2.0.0, MIT, approved, clearlydefined npm/npmjs/-/escape-string-regexp/4.0.0, MIT, approved, clearlydefined npm/npmjs/-/escodegen/2.1.0, BSD-2-Clause AND (BSD-2-Clause AND BSD-3-Clause), approved, #9306 npm/npmjs/-/eslint-config-react-app/7.0.1, MIT, approved, clearlydefined -npm/npmjs/-/eslint-import-resolver-node/0.3.7, MIT, approved, clearlydefined +npm/npmjs/-/eslint-import-resolver-node/0.3.7, MIT, approved, #9923 npm/npmjs/-/eslint-module-utils/2.8.0, MIT, approved, #8209 npm/npmjs/-/eslint-plugin-flowtype/8.0.3, BSD-3-Clause, approved, #2958 npm/npmjs/-/eslint-plugin-import/2.27.5, MIT, approved, #6937 @@ -310,7 +310,7 @@ npm/npmjs/-/eslint-plugin-react-hooks/4.6.0, MIT, approved, clearlydefined npm/npmjs/-/eslint-plugin-react/7.32.2, MIT, approved, #7035 npm/npmjs/-/eslint-plugin-testing-library/5.11.0, MIT, approved, clearlydefined npm/npmjs/-/eslint-scope/5.1.1, BSD-2-Clause, approved, clearlydefined -npm/npmjs/-/eslint-scope/7.2.1, BSD-2-Clause, approved, clearlydefined +npm/npmjs/-/eslint-scope/7.2.1, BSD-2-Clause, approved, #9916 npm/npmjs/-/eslint-utils/2.1.0, MIT, approved, #2498 npm/npmjs/-/eslint-visitor-keys/1.3.0, Apache-2.0, approved, #2501 npm/npmjs/-/eslint-visitor-keys/2.1.0, Apache-2.0, approved, #2433 @@ -1350,7 +1350,7 @@ npm/npmjs/@babel/plugin-transform-unicode-regex/7.22.5, MIT, approved, #8929 npm/npmjs/@babel/plugin-transform-unicode-sets-regex/7.22.5, MIT AND (BSD-2-Clause AND ISC AND MIT) AND BSD-2-Clause AND BSD-3-Clause, approved, #8755 npm/npmjs/@babel/preset-env/7.22.5, MIT AND (BSD-2-Clause AND ISC AND MIT) AND BSD-2-Clause AND BSD-3-Clause, approved, #8748 npm/npmjs/@babel/preset-flow/7.22.5, MIT, approved, #8974 -npm/npmjs/@babel/preset-modules/0.1.5, MIT, approved, clearlydefined +npm/npmjs/@babel/preset-modules/0.1.5, MIT, approved, #9932 npm/npmjs/@babel/preset-react/7.22.5, MIT, approved, #8987 npm/npmjs/@babel/preset-typescript/7.22.5, MIT, approved, #9074 npm/npmjs/@babel/register/7.22.5, MIT, approved, #8959 @@ -1379,7 +1379,7 @@ npm/npmjs/@csstools/selector-specificity/2.2.0, CC0-1.0, approved, clearlydefine npm/npmjs/@eslint-community/eslint-utils/4.4.0, MIT, approved, #8032 npm/npmjs/@eslint-community/regexpp/4.5.1, MIT, approved, clearlydefined npm/npmjs/@eslint/eslintrc/0.4.3, MIT, approved, clearlydefined -npm/npmjs/@eslint/eslintrc/2.1.0, MIT, approved, clearlydefined +npm/npmjs/@eslint/eslintrc/2.1.0, MIT, approved, #9908 npm/npmjs/@eslint/js/8.44.0, MIT, approved, clearlydefined npm/npmjs/@hapi/hoek/9.3.0, BSD-3-Clause AND MIT, approved, #6651 npm/npmjs/@hapi/topo/5.1.0, BSD-3-Clause, approved, clearlydefined @@ -1417,7 +1417,7 @@ npm/npmjs/@jridgewell/set-array/1.1.2, MIT, approved, clearlydefined npm/npmjs/@jridgewell/source-map/0.3.5, MIT, approved, #9304 npm/npmjs/@jridgewell/sourcemap-codec/1.4.14, MIT, approved, clearlydefined npm/npmjs/@jridgewell/sourcemap-codec/1.4.15, MIT, approved, clearlydefined -npm/npmjs/@jridgewell/trace-mapping/0.3.18, MIT, approved, clearlydefined +npm/npmjs/@jridgewell/trace-mapping/0.3.18, MIT, approved, #9904 npm/npmjs/@leichtgewicht/ip-codec/2.0.4, MIT, approved, clearlydefined npm/npmjs/@nicolo-ribaudo/eslint-scope-5-internals/5.1.1-v1, MIT, approved, clearlydefined npm/npmjs/@nicolo-ribaudo/semver-v6/6.3.3, ISC, approved, #9315 diff --git a/LICENSE.txt b/LICENSE.txt deleted file mode 100644 index 12b495f7..00000000 --- a/LICENSE.txt +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright 2022 Catena-X - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://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. \ No newline at end of file diff --git a/NOTICE.md b/NOTICE.md index f7ae12c7..73a3febf 100644 --- a/NOTICE.md +++ b/NOTICE.md @@ -36,7 +36,9 @@ The project maintains the following source code repositories: This project leverages the following third party content. -See DEPENDENCIES_FRONTEND, DEPENDENCIES_BACKEND and DEPENDENCIES_SPECIFICATION files. + +See DEPENDENCIES_BACKEND, DEPENDENCIES_FRONTEND and DEPENDENCIES_SPECIFICATION file. + ## Cryptography diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/CapacityGroupController.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/CapacityGroupController.java index 3261c5ba..975cf19a 100644 --- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/CapacityGroupController.java +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/CapacityGroupController.java @@ -26,10 +26,10 @@ import eclipse.tractusx.demand_capacity_mgmt_specification.model.CapacityGroupDefaultViewResponse; import eclipse.tractusx.demand_capacity_mgmt_specification.model.CapacityGroupRequest; import eclipse.tractusx.demand_capacity_mgmt_specification.model.CapacityGroupResponse; -import eclipse.tractusx.demand_capacity_mgmt_specification.model.MaterialDemandResponse; import java.util.List; import lombok.AllArgsConstructor; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.CapacityGroupService; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RestController; @@ -40,14 +40,20 @@ public class CapacityGroupController implements CapacityGroupApi { private final CapacityGroupService capacityGroupService; @Override - public ResponseEntity> getCapacityGroup() throws Exception { - return null; + public ResponseEntity> getCapacityGroup() { + List capacityGroupDefaultViewResponseList = capacityGroupService.getAll(); + return ResponseEntity.status(HttpStatus.OK).body(capacityGroupDefaultViewResponseList); } @Override - public ResponseEntity postCapacityGroup(CapacityGroupRequest capacityGroupRequest) - throws Exception { - capacityGroupService.createCapacityGroup(capacityGroupRequest); - return null; + public ResponseEntity getCapacityGroupById(String capacityGroupId) { + CapacityGroupResponse responseDto = capacityGroupService.getCapacityGroupById(capacityGroupId); + return ResponseEntity.status(HttpStatus.OK).body(responseDto); + } + + @Override + public ResponseEntity postCapacityGroup(CapacityGroupRequest capacityGroupRequest) { + CapacityGroupResponse capacityGroupResponse = capacityGroupService.createCapacityGroup(capacityGroupRequest); + return ResponseEntity.status(HttpStatus.OK).body(capacityGroupResponse); } } diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/DemandController.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/DemandController.java index 200f4a5f..b8b1c3b7 100644 --- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/DemandController.java +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/DemandController.java @@ -23,9 +23,6 @@ package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.controllers; import eclipse.tractusx.demand_capacity_mgmt_specification.api.DemandApi; -import eclipse.tractusx.demand_capacity_mgmt_specification.model.DemandRequestDto; -import eclipse.tractusx.demand_capacity_mgmt_specification.model.DemandRequestUpdateDto; -import eclipse.tractusx.demand_capacity_mgmt_specification.model.DemandResponseDto; import eclipse.tractusx.demand_capacity_mgmt_specification.model.MaterialDemandRequest; import eclipse.tractusx.demand_capacity_mgmt_specification.model.MaterialDemandResponse; import java.util.List; @@ -68,9 +65,9 @@ public ResponseEntity postDemand(MaterialDemandRequest m @Override public ResponseEntity updateDemandsById( String demandId, - DemandRequestUpdateDto demandRequestUpdateDto + MaterialDemandRequest materialDemandRequest ) { - MaterialDemandResponse responseDto = demandService.updateDemand(demandId, demandRequestUpdateDto); + MaterialDemandResponse responseDto = demandService.updateDemand(demandId, materialDemandRequest); return ResponseEntity.status(HttpStatus.OK).body(responseDto); } } diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/WeekBasedCapacityGroupController.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/WeekBasedCapacityGroupController.java index d26d1519..221fef90 100644 --- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/WeekBasedCapacityGroupController.java +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/WeekBasedCapacityGroupController.java @@ -37,25 +37,11 @@ public class WeekBasedCapacityGroupController implements WeekBasedCapacityGroupA private final WeekBasedCapacityGroupService weekBasedCapacityGroupService; - /* @Override + @Override public ResponseEntity postWeekBasedCapacityGroup( List weekBasedCapacityGroupRequest ) { weekBasedCapacityGroupService.createWeekBasedCapacityGroup(weekBasedCapacityGroupRequest); return ResponseEntity.status(HttpStatus.OK).build(); - }*/ - - /*public ResponseEntity postWeekBasedCapacityGroup( - List weekBasedCapacityGroupRequest - ) throws Exception { - weekBasedCapacityGroupService.createWeekBasedCapacityGroup(weekBasedCapacityGroupRequest); - return ResponseEntity.status(HttpStatus.OK).build(); - }*/ - - @Override - public ResponseEntity postWeekBasedCapacityGroup( - List weekBasedCapacityGroupRequest - ) throws Exception { - return null; } } diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/CapacityGroupEntity.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/CapacityGroupEntity.java index 4e26d2f4..6e358d86 100644 --- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/CapacityGroupEntity.java +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/CapacityGroupEntity.java @@ -29,6 +29,8 @@ import javax.persistence.Column; import javax.persistence.Convert; import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; @@ -40,6 +42,7 @@ import lombok.Data; import lombok.NoArgsConstructor; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.converters.ListToStringConverter; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.CapacityGroupStatus; @Entity @Table(name = "capacity_group") @@ -93,4 +96,8 @@ public class CapacityGroupEntity { @Column(name = "name") private String name; + + @Column(name = "status") + @Enumerated(EnumType.STRING) + private CapacityGroupStatus status; } diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/DemandSeries.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/DemandSeries.java index b829240d..2f7de53b 100644 --- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/DemandSeries.java +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/DemandSeries.java @@ -55,6 +55,9 @@ public class DemandSeries { @Column(columnDefinition = "uuid", updatable = false, name = "id") private UUID id; + @Column(name = "capacity_group_id") + private String capacityGroupId; + @OneToOne @JoinColumn(name = "customer_location_id", referencedColumnName = "ID") private CompanyEntity customerLocation; @@ -63,14 +66,14 @@ public class DemandSeries { @Convert(converter = ListToStringConverter.class) private List expectedSupplierLocation; - @ManyToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY) - @JoinColumn(name = "material_demand_id", referencedColumnName = "ID") - private MaterialDemandEntity materialDemandEntity; - @OneToOne @JoinColumn(name = "demand_category_code_id", referencedColumnName = "ID") private DemandCategoryEntity demandCategory; - @OneToMany(mappedBy = "demandSeries", cascade = { CascadeType.ALL }, fetch = FetchType.LAZY) + @OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY) + @JoinColumn(name = "demand_series_id") private List demandSeriesValues; + + @ManyToOne(fetch = FetchType.LAZY) + private MaterialDemandEntity materialDemand; } diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/DemandSeriesValues.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/DemandSeriesValues.java index 04367b69..9cb025ab 100644 --- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/DemandSeriesValues.java +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/DemandSeriesValues.java @@ -51,7 +51,6 @@ public class DemandSeriesValues { private UUID id; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "demand_series_id", referencedColumnName = "ID") private DemandSeries demandSeries; @Column(name = "calendar_week", nullable = false) diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/MaterialDemandEntity.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/MaterialDemandEntity.java index 26d5f29f..51ff1a18 100644 --- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/MaterialDemandEntity.java +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/MaterialDemandEntity.java @@ -23,20 +23,25 @@ package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities; import java.time.LocalDateTime; +import java.util.List; import java.util.UUID; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; +import javax.persistence.OneToMany; import javax.persistence.OneToOne; import javax.persistence.Table; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.MaterialDemandStatus; @Entity @Table(name = "material_demand") @@ -75,7 +80,11 @@ public class MaterialDemandEntity { @JoinColumn(name = "unity_of_measure_id", referencedColumnName = "ID") private UnitMeasureEntity unitMeasure; - @OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY) - @JoinColumn(name = "id", referencedColumnName = "id") - private DemandSeries demandSeries; + @OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY) + @JoinColumn(name = "material_demand_id") + private List demandSeries; + + @Column(name = "status") + @Enumerated(EnumType.STRING) + private MaterialDemandStatus status; } diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/WeekBasedCapacityGroupEntity.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/WeekBasedCapacityGroupEntity.java index 19c54185..06cb0da7 100644 --- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/WeekBasedCapacityGroupEntity.java +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/WeekBasedCapacityGroupEntity.java @@ -22,6 +22,7 @@ package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities; +import eclipse.tractusx.demand_capacity_mgmt_specification.model.WeekBasedCapacityGroupRequest; import javax.persistence.Column; import javax.persistence.Convert; import javax.persistence.Entity; @@ -40,7 +41,7 @@ import org.hibernate.annotations.ColumnTransformer; @Entity -@Table(name = "week_based_material_demand") +@Table(name = "week_based_capacity") @Data @Builder @NoArgsConstructor @@ -55,7 +56,7 @@ public class WeekBasedCapacityGroupEntity { @Convert(converter = WeekBasedCapacityGroupConverter.class) @Column(name = "data", columnDefinition = "jsonb") @ColumnTransformer(write = "?::jsonb") - private WeekBasedCapacityGroup weekBasedCapacityGroup; + private WeekBasedCapacityGroupRequest weekBasedCapacityGroup; @Column(name = "viewed") private Boolean viewed; diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/converters/WeekBasedCapacityGroupConverter.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/converters/WeekBasedCapacityGroupConverter.java index 5a0d22e5..721a8f4f 100644 --- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/converters/WeekBasedCapacityGroupConverter.java +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/converters/WeekBasedCapacityGroupConverter.java @@ -23,22 +23,23 @@ package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.converters; import com.google.gson.Gson; +import eclipse.tractusx.demand_capacity_mgmt_specification.model.WeekBasedCapacityGroupRequest; import javax.persistence.AttributeConverter; import javax.persistence.Converter; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.jsonEntities.WeekBasedCapacityGroup; @Converter(autoApply = true) -public class WeekBasedCapacityGroupConverter implements AttributeConverter { +public class WeekBasedCapacityGroupConverter implements AttributeConverter { private static final Gson GSON = new Gson(); @Override - public String convertToDatabaseColumn(WeekBasedCapacityGroup attribute) { + public String convertToDatabaseColumn(WeekBasedCapacityGroupRequest attribute) { return GSON.toJson(attribute); } @Override - public WeekBasedCapacityGroup convertToEntityAttribute(String dbData) { - return GSON.fromJson(dbData, WeekBasedCapacityGroup.class); + public WeekBasedCapacityGroupRequest convertToEntityAttribute(String dbData) { + return GSON.fromJson(dbData, WeekBasedCapacityGroupRequest.class); } } diff --git a/demand-capacity-mgmt-frontend/src/hooks/ToggleModal.tsx b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/enums/CapacityGroupStatus.java similarity index 82% rename from demand-capacity-mgmt-frontend/src/hooks/ToggleModal.tsx rename to demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/enums/CapacityGroupStatus.java index 8efd6349..6a35536c 100644 --- a/demand-capacity-mgmt-frontend/src/hooks/ToggleModal.tsx +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/enums/CapacityGroupStatus.java @@ -1,4 +1,3 @@ - /* * ******************************************************************************* * Copyright (c) 2023 BMW AG @@ -21,17 +20,11 @@ * ******************************************************************************** */ -import { useState } from "react"; - -export default function useModal() { - const [isOpen, setisOpen] = useState(false); - - const toggle = () => { - setisOpen(!isOpen); - }; +package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums; - return { - isOpen, - toggle - }; +public enum CapacityGroupStatus { + DRAFT, + READY_SYNCHRONIZE, + SYNCHRONIZED, + DELETED, } diff --git a/demand-capacity-mgmt-frontend/src/App.test.tsx b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/enums/MaterialDemandStatus.java similarity index 80% rename from demand-capacity-mgmt-frontend/src/App.test.tsx rename to demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/enums/MaterialDemandStatus.java index a1f31231..a1f60982 100644 --- a/demand-capacity-mgmt-frontend/src/App.test.tsx +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/enums/MaterialDemandStatus.java @@ -20,11 +20,11 @@ * ******************************************************************************** */ -import { render, screen } from '@testing-library/react'; -import App from './App'; +package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums; -test('renders learn react link', () => { - render(); - const linkElement = screen.getByText(/learn react/i); - expect(linkElement).toBeInTheDocument(); -}); +public enum MaterialDemandStatus { + DRAFT, + READY_SYNCHRONIZE, + SYNCHRONIZED, + DELETED, +} diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/jsonEntities/LikedDemandSeries.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/jsonEntities/LikedDemandSeries.java index e811fc82..6ffc34f3 100644 --- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/jsonEntities/LikedDemandSeries.java +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/jsonEntities/LikedDemandSeries.java @@ -32,5 +32,5 @@ public class LikedDemandSeries { private String materialNumberCustomer; private String materialNumberSupplier; private String customerLocation; - private DemandCategory demandCategory; + private DemandCategory demandCategory; // } diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/repositories/CapacityGroupRepository.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/repositories/CapacityGroupRepository.java index 3c2a04e1..5dac0a1b 100644 --- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/repositories/CapacityGroupRepository.java +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/repositories/CapacityGroupRepository.java @@ -22,10 +22,16 @@ package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories; +import java.util.List; import java.util.UUID; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.CapacityGroupEntity; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.CapacityGroupStatus; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @Repository -public interface CapacityGroupRepository extends JpaRepository {} +public interface CapacityGroupRepository extends JpaRepository { + List findAllByStatus(CapacityGroupStatus status); + + List findAll(); +} diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/repositories/MaterialDemandRepository.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/repositories/MaterialDemandRepository.java index f169aede..790c12a7 100644 --- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/repositories/MaterialDemandRepository.java +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/repositories/MaterialDemandRepository.java @@ -22,10 +22,28 @@ package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories; +import java.util.List; import java.util.UUID; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.MaterialDemandEntity; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.MaterialDemandStatus; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; @Repository -public interface MaterialDemandRepository extends JpaRepository {} +public interface MaterialDemandRepository extends JpaRepository { + List findAllByStatus(MaterialDemandStatus status); + + @Query( + "SELECT DISTINCT md FROM MaterialDemandEntity md " + + "JOIN FETCH md.demandSeries ds JOIN FETCH ds.demandCategory dc " + + "WHERE md.materialNumberCustomer = :materialNumberCustomer " + + "AND ds.customerLocation.bpn = :customerLocationBpn " + + "AND dc.demandCategoryCode = :demandCategoryCode" + ) + List findAllByMaterialNumberCustomerAndDemandSeriesCustomerLocationAndDemandCategory( + String materialNumberCustomer, + String customerLocationBpn, + String demandCategoryCode + ); +} 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 bc62bcd9..8c92f6ef 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 @@ -22,8 +22,20 @@ package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services; +import eclipse.tractusx.demand_capacity_mgmt_specification.model.CapacityGroupDefaultViewResponse; import eclipse.tractusx.demand_capacity_mgmt_specification.model.CapacityGroupRequest; +import eclipse.tractusx.demand_capacity_mgmt_specification.model.CapacityGroupResponse; +import eclipse.tractusx.demand_capacity_mgmt_specification.model.MaterialDemandResponse; +import java.util.List; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.CapacityGroupEntity; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.CapacityGroupStatus; public interface CapacityGroupService { - void createCapacityGroup(CapacityGroupRequest capacityGroupRequest); + CapacityGroupResponse createCapacityGroup(CapacityGroupRequest capacityGroupRequest); + + CapacityGroupResponse getCapacityGroupById(String CapacityGroupId); + + List getAllByStatus(CapacityGroupStatus status); + + List getAll(); } diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/DemandService.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/DemandService.java index ef5ce9c5..77c45ddc 100644 --- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/DemandService.java +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/DemandService.java @@ -28,6 +28,8 @@ import eclipse.tractusx.demand_capacity_mgmt_specification.model.MaterialDemandRequest; import eclipse.tractusx.demand_capacity_mgmt_specification.model.MaterialDemandResponse; import java.util.List; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.MaterialDemandEntity; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.MaterialDemandStatus; public interface DemandService { MaterialDemandResponse createDemand(MaterialDemandRequest materialDemandRequest); @@ -36,7 +38,9 @@ public interface DemandService { MaterialDemandResponse getDemandById(String demandId); - MaterialDemandResponse updateDemand(String demandId, DemandRequestUpdateDto demandRequestUpdateDto); + MaterialDemandResponse updateDemand(String demandId, MaterialDemandRequest materialDemandRequest); void deleteDemandById(String demandId); + + List getAllByStatus(MaterialDemandStatus status); } diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/WeekBasedCapacityGroupService.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/WeekBasedCapacityGroupService.java index e1436cd1..2a98fc1f 100644 --- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/WeekBasedCapacityGroupService.java +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/WeekBasedCapacityGroupService.java @@ -24,6 +24,8 @@ import eclipse.tractusx.demand_capacity_mgmt_specification.model.WeekBasedCapacityGroupRequest; import java.util.List; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.CapacityGroupEntity; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.WeekBasedCapacityGroupEntity; public interface WeekBasedCapacityGroupService { void createWeekBasedCapacityGroup(List weekBasedCapacityGroupRequest); @@ -31,4 +33,8 @@ public interface WeekBasedCapacityGroupService { void receiveWeekBasedCapacityGroup(); void sendWeekBasedCapacityGroup(); + + void createWeekBasedCapacityGroupRequestFromEntity(CapacityGroupEntity capacityGroupEntity); + + WeekBasedCapacityGroupEntity findById(String capacityGroupId); } 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 06ad048d..a9dd955d 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 @@ -22,25 +22,24 @@ package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.impl; -import eclipse.tractusx.demand_capacity_mgmt_specification.model.CapacityGroupRequest; +import eclipse.tractusx.demand_capacity_mgmt_specification.model.*; +import java.math.BigDecimal; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.UUID; import java.util.concurrent.atomic.AtomicReference; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.CapacityGroupEntity; -import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.CapacityTimeSeries; -import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.CompanyEntity; -import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.LinkDemandEntity; -import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.LinkedDemandSeries; -import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.UnitMeasureEntity; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.*; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.CapacityGroupStatus; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.exceptions.BadRequestException; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.exceptions.NotFoundException; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories.CapacityGroupRepository; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories.LinkDemandRepository; -import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.CapacityGroupService; -import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.CompanyService; -import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.UnityOfMeasureService; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories.WeekBasedCapacityGroupRepository; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.*; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.utils.DataConverterUtil; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.utils.UUIDUtil; import org.springframework.stereotype.Service; @@ -58,13 +57,46 @@ public class CapacityGroupServiceImpl implements CapacityGroupService { private final LinkDemandRepository linkDemandRepository; + private final DemandCategoryService demandCategoryService; + @Override - public void createCapacityGroup(CapacityGroupRequest capacityGroupRequest) { + public CapacityGroupResponse createCapacityGroup(CapacityGroupRequest capacityGroupRequest) { validateRequestFields(capacityGroupRequest); CapacityGroupEntity capacityGroupEntity = enrichCapacityGroup(capacityGroupRequest); - saveAll(capacityGroupEntity); + capacityGroupEntity = capacityGroupRepository.save(capacityGroupEntity); + + return convertCapacityGroupDto(capacityGroupEntity); + } + + @Override + public CapacityGroupResponse getCapacityGroupById(String capacityGroupId) { + CapacityGroupEntity capacityGroupEntity = getCapacityGroupEntity(capacityGroupId); + return convertCapacityGroupDto(capacityGroupEntity); + } + + @Override + public List getAllByStatus(CapacityGroupStatus status) { + return capacityGroupRepository.findAllByStatus(status); + } + + @Override + public List getAll() { + List capacityGroupEntityList = capacityGroupRepository.findAll(); + return convertCapacityGroupEntity(capacityGroupEntityList); + } + + private CapacityGroupEntity getCapacityGroupEntity(String capacityGroupId) { + UUIDUtil.checkValidUUID(capacityGroupId); + UUID uuid = UUIDUtil.generateUUIDFromString(capacityGroupId); + Optional capacityGroup = capacityGroupRepository.findById(uuid); + + if (capacityGroup.isEmpty()) { + throw new NotFoundException(""); + } + + return capacityGroup.get(); } private void validateRequestFields(CapacityGroupRequest capacityGroupRequest) { @@ -144,10 +176,21 @@ private CapacityGroupEntity enrichCapacityGroup(CapacityGroupRequest capacityGro .findById(UUIDUtil.generateUUIDFromString(s)) .orElseThrow(); + WeekBasedMaterialDemandEntity weekBasedMaterialDemandEntity = linkDemandEntity.getWeekBasedMaterialDemand(); + WeekBasedMaterialDemandRequestDto weekBasedMaterialDemandRequestDto = weekBasedMaterialDemandEntity.getWeekBasedMaterialDemand(); + CompanyEntity customerId = companyService.getCompanyById( + UUID.fromString(weekBasedMaterialDemandRequestDto.getCustomer()) + ); + materialNumberCustomer.set(linkDemandEntity.getMaterialNumberCustomer()); materialDescriptionCustomer.set(linkDemandEntity.getMaterialNumberCustomer()); + String demandCategoryId = linkDemandEntity.getDemandCategoryId(); + DemandCategoryEntity demandCategoryEntity = demandCategoryService.findById( + UUID.fromString(demandCategoryId) + ); + linkDemandEntity.setLinked(true); linkDemandRepository.save(linkDemandEntity); @@ -155,6 +198,8 @@ private CapacityGroupEntity enrichCapacityGroup(CapacityGroupRequest capacityGro .builder() .materialNumberSupplier(linkDemandEntity.getMaterialNumberSupplier()) .materialNumberCustomer(linkDemandEntity.getMaterialNumberCustomer()) + .customerId(customerId) + .demandCategory(demandCategoryEntity) .build(); } ) @@ -174,6 +219,7 @@ private CapacityGroupEntity enrichCapacityGroup(CapacityGroupRequest capacityGro .name(capacityGroupRequest.getName()) .materialNumberCustomer(materialNumberCustomer.get()) .materialDescriptionCustomer(materialDescriptionCustomer.get()) + .status(CapacityGroupStatus.DRAFT) .build(); } @@ -191,7 +237,118 @@ private CapacityTimeSeries enrichCapacityTimeSeries( .build(); } - private void saveAll(CapacityGroupEntity capacityGroupEntity) { - capacityGroupRepository.save(capacityGroupEntity); + private CapacityGroupResponse convertCapacityGroupDto(CapacityGroupEntity capacityGroupEntity) { + CapacityGroupResponse responseDto = new CapacityGroupResponse(); + + CompanyDto customer = companyService.convertEntityToDto(capacityGroupEntity.getCustomerId()); + CompanyDto supplier = companyService.convertEntityToDto(capacityGroupEntity.getSupplierId()); + UnitMeasure unitMeasure = enrichUnitMeasure(capacityGroupEntity.getUnitMeasure()); + + responseDto.setCustomer(customer); + responseDto.setSupplier(supplier); + responseDto.setUnitOfMeasure(unitMeasure); + responseDto.setChangeAt(capacityGroupEntity.getChangedAt().toString()); + responseDto.setName(capacityGroupEntity.getName()); + responseDto.setCapacityGroupId(capacityGroupEntity.getCapacityGroupId().toString()); + + List capacityRequests = capacityGroupEntity + .getCapacityTimeSeries() + .stream() + .map(this::convertCapacityTimeSeries) + .toList(); + + responseDto.setCapacities(capacityRequests); + + List linkedDemandSeriesResponses = capacityGroupEntity + .getLinkedDemandSeries() + .stream() + .map(this::convertLinkedDemandSeries) + .toList(); + responseDto.setLinkedDemandSeries(linkedDemandSeriesResponses); + + List companyDtoList = capacityGroupEntity + .getSupplierLocation() + .stream() + .map(this::convertString) + .toList(); + + responseDto.setSupplierLocations(companyDtoList); + + return responseDto; + } + + private UnitMeasure enrichUnitMeasure(UnitMeasureEntity unitMeasureEntity) { + UnitMeasure unitMeasure = new UnitMeasure(); + + unitMeasure.setId(unitMeasureEntity.getId().toString()); + unitMeasure.setCodeValue(unitMeasureEntity.getCodeValue()); + unitMeasure.setDisplayValue(unitMeasureEntity.getDisplayValue()); + + return unitMeasure; + } + + private CapacityRequest convertCapacityTimeSeries(CapacityTimeSeries capacityTimeSeries) { + CapacityRequest capacityRequest = new CapacityRequest(); + + capacityRequest.setActualCapacity(new BigDecimal(capacityTimeSeries.getActualCapacity())); + capacityRequest.setMaximumCapacity(new BigDecimal(capacityTimeSeries.getMaximumCapacity())); + capacityRequest.setCalendarWeek(capacityRequest.getCalendarWeek()); + + return capacityRequest; + } + + private LinkedDemandSeriesResponse convertLinkedDemandSeries(LinkedDemandSeries linkedDemandSeries) { + LinkedDemandSeriesResponse linkedDemandSeriesResponse = new LinkedDemandSeriesResponse(); + + linkedDemandSeriesResponse.setMaterialNumberCustomer(linkedDemandSeries.getMaterialNumberCustomer()); + linkedDemandSeriesResponse.setMaterialNumberSupplier(linkedDemandSeries.getMaterialNumberSupplier()); + + CompanyDto customer = companyService.convertEntityToDto(linkedDemandSeries.getCustomerId()); + linkedDemandSeriesResponse.setCustomerLocation(customer); + + DemandCategoryResponse demand = convertDemandCategoryEntity(linkedDemandSeries.getDemandCategory()); + linkedDemandSeriesResponse.setDemandCategory(demand); + + return linkedDemandSeriesResponse; + } + + private DemandCategoryResponse convertDemandCategoryEntity(DemandCategoryEntity demandCategoryEntity) { + DemandCategoryResponse response = new DemandCategoryResponse(); + + response.setId(demandCategoryEntity.getId().toString()); + response.setDemandCategoryCode(demandCategoryEntity.getDemandCategoryCode()); + response.setDemandCategoryName(demandCategoryEntity.getDemandCategoryName()); + + return response; + } + + private CompanyDto convertString(String supplier) { + CompanyEntity entity = companyService.getCompanyById(UUID.fromString(supplier)); + + return companyService.convertEntityToDto(entity); + } + + private List convertCapacityGroupEntity( + List capacityGroupEntityList + ) { + List capacityGroupList = new ArrayList<>(); + + for (CapacityGroupEntity entity : capacityGroupEntityList) { + CapacityGroupDefaultViewResponse response = new CapacityGroupDefaultViewResponse(); + + response.setName(entity.getName()); + response.setStatus(entity.getStatus().toString()); + response.setSupplierBNPL(entity.getSupplierId().getBpn()); + response.setCustomerName(entity.getCustomerId().getCompanyName()); + response.setCustomerBPNL(entity.getCustomerId().getBpn()); + response.setInternalId(entity.getId().toString()); + response.setNumberOfMaterials(new BigDecimal(entity.getCapacityTimeSeries().size())); + //response.setFavoritedBy(); + //response.setCatXUuid(); + + capacityGroupList.add(response); + } + + return capacityGroupList; } } diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/CompanyServiceImpl.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/CompanyServiceImpl.java index cd5eddae..793f69a2 100644 --- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/CompanyServiceImpl.java +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/CompanyServiceImpl.java @@ -64,7 +64,7 @@ public List getCompanyIn(List uuidList) { @Override public CompanyDto convertEntityToDto(CompanyEntity companyEntity) { CompanyDto companyDto = new CompanyDto(); - + companyDto.setId(String.valueOf(companyEntity.getId())); companyDto.setBpn(companyEntity.getBpn()); companyDto.setMyCompany(companyEntity.getMyCompany()); companyDto.setCompanyName(companyEntity.getCompanyName()); diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/DemandServiceImpl.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/DemandServiceImpl.java index 7960b39f..082d29a6 100644 --- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/DemandServiceImpl.java +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/DemandServiceImpl.java @@ -23,12 +23,13 @@ package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.impl; import eclipse.tractusx.demand_capacity_mgmt_specification.model.CompanyDto; -import eclipse.tractusx.demand_capacity_mgmt_specification.model.DemandRequestUpdateDto; +import eclipse.tractusx.demand_capacity_mgmt_specification.model.DemandCategoryResponse; import eclipse.tractusx.demand_capacity_mgmt_specification.model.MaterialDemandRequest; import eclipse.tractusx.demand_capacity_mgmt_specification.model.MaterialDemandResponse; import eclipse.tractusx.demand_capacity_mgmt_specification.model.MaterialDemandSeries; import eclipse.tractusx.demand_capacity_mgmt_specification.model.MaterialDemandSeriesResponse; import eclipse.tractusx.demand_capacity_mgmt_specification.model.MaterialDemandSeriesValue; +import eclipse.tractusx.demand_capacity_mgmt_specification.model.UnitMeasure; import java.math.BigDecimal; import java.time.LocalDateTime; import java.util.List; @@ -42,6 +43,7 @@ import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.DemandSeriesValues; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.MaterialDemandEntity; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.UnitMeasureEntity; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.MaterialDemandStatus; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.exceptions.BadRequestException; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.exceptions.NotFoundException; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories.MaterialDemandRepository; @@ -91,8 +93,9 @@ public MaterialDemandResponse getDemandById(String demandId) { } @Override - public MaterialDemandResponse updateDemand(String demandId, DemandRequestUpdateDto demandRequestUpdateDto) { - MaterialDemandEntity demand = getDemandEntity(demandId); + public MaterialDemandResponse updateDemand(String demandId, MaterialDemandRequest materialDemandRequest) { + MaterialDemandEntity demand = convertDtoToEntity(materialDemandRequest); + demand.setId(UUID.fromString(demandId)); demand = materialDemandRepository.save(demand); return convertDemandResponseDto(demand); @@ -105,6 +108,11 @@ public void deleteDemandById(String demandId) { materialDemandRepository.delete(demand); } + @Override + public List getAllByStatus(MaterialDemandStatus status) { + return materialDemandRepository.findAllByStatus(status); + } + private MaterialDemandEntity getDemandEntity(String demandId) { UUIDUtil.checkValidUUID(demandId); UUID uuid = UUIDUtil.generateUUIDFromString(demandId); @@ -129,10 +137,18 @@ private MaterialDemandResponse convertDemandResponseDto(MaterialDemandEntity mat responseDto.setCustomer(customer); responseDto.setSupplier(supplier); responseDto.setChangedAt(materialDemandEntity.getChangedAt().toString()); + responseDto.setId(materialDemandEntity.getId().toString()); + + UnitMeasure unitMeasure = enrichUnitMeasure(materialDemandEntity.getUnitMeasure()); + + List materialDemandSeriesResponse = materialDemandEntity + .getDemandSeries() + .stream() + .map(this::enrichMaterialDemandSeriesResponse) + .toList(); + + responseDto.setUnitMeasureId(unitMeasure); - MaterialDemandSeriesResponse materialDemandSeriesResponse = enrichMaterialDemandSeriesResponse( - materialDemandEntity.getDemandSeries() - ); responseDto.setDemandSeries(materialDemandSeriesResponse); return responseDto; @@ -147,50 +163,51 @@ private void validateMaterialDemandRequestFields(MaterialDemandRequest materialD throw new BadRequestException("not a valid ID"); } - if (!UUIDUtil.checkValidUUID(materialDemandRequest.getMaterialDemandSeries().getCustomerLocationId())) { - throw new BadRequestException("not a valid ID"); - } - - if (!UUIDUtil.checkValidUUID(materialDemandRequest.getMaterialDemandSeries().getDemandCategoryId())) { - throw new BadRequestException("not a valid category"); - } - - List dates = materialDemandRequest + materialDemandRequest .getMaterialDemandSeries() - .getDemandSeriesValues() - .stream() - .map( - materialDemandSeriesValue -> - DataConverterUtil.convertFromString(materialDemandSeriesValue.getCalendarWeek()) - ) - .toList(); + .forEach( + materialDemandSeries -> { + if (!UUIDUtil.checkValidUUID(materialDemandSeries.getCustomerLocationId())) { + throw new BadRequestException("not a valid ID"); + } + + if (!UUIDUtil.checkValidUUID(materialDemandSeries.getDemandCategoryId())) { + throw new BadRequestException("not a valid category"); + } + + List dates = materialDemandSeries + .getDemandSeriesValues() + .stream() + .map( + materialDemandSeriesValue -> + DataConverterUtil.convertFromString(materialDemandSeriesValue.getCalendarWeek()) + ) + .toList(); - if (!DataConverterUtil.checkListAllMonday(dates) || !DataConverterUtil.checkDatesSequence(dates)) { - throw new BadRequestException("not a valid dates"); - } + if (!DataConverterUtil.checkListAllMonday(dates) || !DataConverterUtil.checkDatesSequence(dates)) { + throw new BadRequestException("not a valid dates"); + } - materialDemandRequest - .getMaterialDemandSeries() - .getExpectedSupplierLocationId() - .forEach(UUIDUtil::checkValidUUID); + materialDemandSeries.getExpectedSupplierLocationId().forEach(UUIDUtil::checkValidUUID); - List expectedSuppliersLocation = materialDemandRequest - .getMaterialDemandSeries() - .getExpectedSupplierLocationId() - .stream() - .map(UUIDUtil::generateUUIDFromString) - .toList(); + List expectedSuppliersLocation = materialDemandSeries + .getExpectedSupplierLocationId() + .stream() + .map(UUIDUtil::generateUUIDFromString) + .toList(); - List companyEntities = companyService.getCompanyIn(expectedSuppliersLocation); + List companyEntities = companyService.getCompanyIn(expectedSuppliersLocation); - boolean hasAllCompanies = companyEntities - .stream() - .map(CompanyEntity::getId) - .allMatch(expectedSuppliersLocation::contains); + boolean hasAllCompanies = companyEntities + .stream() + .map(CompanyEntity::getId) + .allMatch(expectedSuppliersLocation::contains); - if (!hasAllCompanies) { - throw new BadRequestException("Some Invalid Company"); - } + if (!hasAllCompanies) { + throw new BadRequestException("Some Invalid Company"); + } + } + ); } private MaterialDemandEntity convertDtoToEntity(MaterialDemandRequest materialDemandRequest) { @@ -209,25 +226,28 @@ private MaterialDemandEntity convertDtoToEntity(MaterialDemandRequest materialDe UUID.fromString(materialDemandRequest.getUnitMeasureId()) ); - DemandCategoryEntity demandCategory = demandCategoryService.findById( - UUIDUtil.generateUUIDFromString(materialDemandRequest.getMaterialDemandSeries().getDemandCategoryId()) - ); - - DemandSeries demandSeries = enrichDemandSeries( - materialDemandRequest.getMaterialDemandSeries(), - customerEntity, - demandCategory - ); + List demandSeriesList = materialDemandRequest + .getMaterialDemandSeries() + .stream() + .map( + materialDemandSeries -> { + DemandCategoryEntity demandCategory = demandCategoryService.findById( + UUIDUtil.generateUUIDFromString(materialDemandSeries.getDemandCategoryId()) + ); + return enrichDemandSeries(materialDemandSeries, customerEntity, demandCategory); + } + ) + .toList(); return MaterialDemandEntity .builder() .materialDescriptionCustomer(materialDemandRequest.getMaterialDescriptionCustomer()) .materialNumberCustomer(materialDemandRequest.getMaterialNumberCustomer()) - .materialNumberSupplier("") + .materialNumberSupplier(materialDemandRequest.getMaterialNumberSupplier()) .customerId(customerEntity) .supplierId(supplierEntity) .unitMeasure(unitMeasure) - .demandSeries(demandSeries) + .demandSeries(demandSeriesList) .changedAt(LocalDateTime.now()) .build(); } @@ -291,6 +311,10 @@ private MaterialDemandSeriesResponse enrichMaterialDemandSeriesResponse(DemandSe .map(this::enrichMaterialDemandSeriesValue) .toList(); + DemandCategoryResponse demandCategory = enrichDemandCategory(demandSeries.getDemandCategory()); + + materialDemandSeriesResponse.setDemandCategory(demandCategory); + materialDemandSeriesResponse.setDemandSeriesValues(materialDemandSeriesValues); return materialDemandSeriesResponse; @@ -303,4 +327,22 @@ private MaterialDemandSeriesValue enrichMaterialDemandSeriesValue(DemandSeriesVa return materialDemandSeriesValue; } + + private UnitMeasure enrichUnitMeasure(UnitMeasureEntity unitMeasureEntity) { + UnitMeasure unitMeasure = new UnitMeasure(); + + unitMeasure.setId(unitMeasureEntity.getId().toString()); + unitMeasure.setCodeValue(unitMeasureEntity.getCodeValue()); + unitMeasure.setDisplayValue(unitMeasureEntity.getDisplayValue()); + + return unitMeasure; + } + + private DemandCategoryResponse enrichDemandCategory(DemandCategoryEntity demandCategoryEntity) { + DemandCategoryResponse demandCategory = new DemandCategoryResponse(); + demandCategory.setId(demandCategoryEntity.getId().toString()); + demandCategory.setDemandCategoryName(demandCategoryEntity.getDemandCategoryName()); + demandCategory.setDemandCategoryCode(demandCategoryEntity.getDemandCategoryCode()); + return demandCategory; + } } diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/LinkDemandServiceImpl.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/LinkDemandServiceImpl.java index cd82db8e..c189cda4 100644 --- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/LinkDemandServiceImpl.java +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/LinkDemandServiceImpl.java @@ -63,8 +63,8 @@ private List convertFromWeekBasedMaterial(WeekBasedMaterialDem demandWeekSeriesDto -> LinkDemandEntity .builder() - .linked(false) - .demandCategoryId(demandWeekSeriesDto.getDemandCategory().getDemandCategoryCode()) + .linked(false) //Id =id + .demandCategoryId(demandWeekSeriesDto.getDemandCategory().getId()) .weekBasedMaterialDemand(weekBasedMaterialDemand) .materialNumberSupplier( weekBasedMaterialDemand.getWeekBasedMaterialDemand().getMaterialNumberSupplier() diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/WeekBasedCapacityGroupServiceImpl.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/WeekBasedCapacityGroupServiceImpl.java index e6eba98e..48732eec 100644 --- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/WeekBasedCapacityGroupServiceImpl.java +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/WeekBasedCapacityGroupServiceImpl.java @@ -22,22 +22,22 @@ package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.impl; +import eclipse.tractusx.demand_capacity_mgmt_specification.model.CapacitiesDto; +import eclipse.tractusx.demand_capacity_mgmt_specification.model.DemandCategoryDto; +import eclipse.tractusx.demand_capacity_mgmt_specification.model.LinkedDemandSeriesRequest; import eclipse.tractusx.demand_capacity_mgmt_specification.model.WeekBasedCapacityGroupRequest; -import java.util.LinkedList; import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; -import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.CustomerEntity; -import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.SupplierEntity; -import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.WeekBasedCapacityGroupEntity; -import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.jsonEntities.Capacity; -import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.jsonEntities.DemandCategory; -import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.jsonEntities.LikedDemandSeries; -import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.jsonEntities.WeekBasedCapacityGroup; +import lombok.extern.slf4j.Slf4j; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.*; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.CapacityGroupStatus; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.exceptions.BadRequestException; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.exceptions.NotFoundException; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories.CustomerRepository; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories.MaterialDemandRepository; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories.WeekBasedCapacityGroupRepository; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.CapacityGroupService; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.WeekBasedCapacityGroupService; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.utils.UUIDUtil; import org.springframework.http.ResponseEntity; @@ -46,12 +46,17 @@ @RequiredArgsConstructor @Service +@Slf4j public class WeekBasedCapacityGroupServiceImpl implements WeekBasedCapacityGroupService { private final WeekBasedCapacityGroupRepository weekBasedCapacityGroupRepository; private final CustomerRepository customerRepository; + private final CapacityGroupService capacityGroupService; + + private final MaterialDemandRepository materialDemandRepository; + @Override public void createWeekBasedCapacityGroup(List weekBasedCapacityGroupRequestList) { weekBasedCapacityGroupRequestList.forEach( @@ -70,7 +75,45 @@ public void receiveWeekBasedCapacityGroup() { false ); - weekBasedCapacityGroupRepository.saveAll(weekBasedCapacityGroupEntities); + weekBasedCapacityGroupEntities.forEach( + weekBasedCapacityGroupEntity -> { + WeekBasedCapacityGroupRequest weekBasedCapacityGroup = weekBasedCapacityGroupEntity.getWeekBasedCapacityGroup(); + + if (weekBasedCapacityGroup != null) { + List likedDemandSeriesList = weekBasedCapacityGroup.getLinkedDemandSeries(); + + if (likedDemandSeriesList != null) { + for (LinkedDemandSeriesRequest likedDemandSeries : likedDemandSeriesList) { + String materialNumberCustomer = likedDemandSeries.getMaterialNumberCustomer(); + String customerLocation = likedDemandSeries.getCustomerLocation(); + String demandCategoryCode = likedDemandSeries.getDemandCategory().getDemandCategory(); + + List matchingDemands = materialDemandRepository.findAllByMaterialNumberCustomerAndDemandSeriesCustomerLocationAndDemandCategory( + materialNumberCustomer, + customerLocation, + demandCategoryCode + ); + + matchingDemands.forEach( + materialDemandEntity -> { + materialDemandEntity + .getDemandSeries() + .forEach( + demandSeries -> { + demandSeries.setCapacityGroupId( + weekBasedCapacityGroup.getCapacityGroupId() + ); + } + ); + } + ); + + materialDemandRepository.saveAll(matchingDemands); + } + } + } + } + ); } @Override @@ -88,52 +131,89 @@ public void sendWeekBasedCapacityGroup() { //TODO create the Actual Demand and send to the supplier ResponseEntity response = restTemplate.getForEntity(fooResourceUrl, String.class); } - } - private void validateFields(WeekBasedCapacityGroupRequest weekBasedCapacityGroupRequest) { - if (!UUIDUtil.checkValidUUID(weekBasedCapacityGroupRequest.getCapacityGroupId())) { - throw new BadRequestException("not a valid ID"); - } + List capacityGroupEntityList = capacityGroupService.getAllByStatus( + CapacityGroupStatus.READY_SYNCHRONIZE + ); + + capacityGroupEntityList.forEach(this::createWeekBasedCapacityGroupRequestFromEntity); } - private WeekBasedCapacityGroupEntity convertEntity(WeekBasedCapacityGroupRequest weekBasedCapacityGroupRequest) { - List capacities = weekBasedCapacityGroupRequest - .getCapacities() + @Override + public void createWeekBasedCapacityGroupRequestFromEntity(CapacityGroupEntity capacityGroupEntity) { + WeekBasedCapacityGroupRequest basedCapacityGroupRequest = new WeekBasedCapacityGroupRequest(); + + basedCapacityGroupRequest.setCapacityGroupId(capacityGroupEntity.getCapacityGroupId().toString()); + basedCapacityGroupRequest.setUnityOfMeasure(capacityGroupEntity.getUnitMeasure().getCodeValue()); + basedCapacityGroupRequest.setCustomer(capacityGroupEntity.getCustomerId().getBpn()); + basedCapacityGroupRequest.setSupplier(capacityGroupEntity.getSupplierId().getBpn()); + basedCapacityGroupRequest.setName(capacityGroupEntity.getName()); + basedCapacityGroupRequest.setChangedAt(capacityGroupEntity.getChangedAt().toString()); + basedCapacityGroupRequest.setSupplierLocations(capacityGroupEntity.getSupplierLocation()); + + List linkedDemandSeries = capacityGroupEntity + .getLinkedDemandSeries() .stream() - .map( - capacitiesDto -> - Capacity - .builder() - .actualCapacity(Double.valueOf(capacitiesDto.getActualCapacity())) - .maximumCapacity(Double.valueOf(capacitiesDto.getMaximumCapacity())) - .calendarWeek(capacitiesDto.getCalendarWeek()) - .build() - ) + .map(WeekBasedCapacityGroupServiceImpl::getLinkedDemandSeries) .toList(); + basedCapacityGroupRequest.setLinkedDemandSeries(linkedDemandSeries); - List likedDemandSeries = weekBasedCapacityGroupRequest - .getCapacities() + List capacitiesDtos = capacityGroupEntity + .getCapacityTimeSeries() .stream() - .map( - capacitiesDto -> { - DemandCategory demandCategory = DemandCategory.builder().build(); - return LikedDemandSeries.builder().demandCategory(demandCategory).build(); - } - ) + .map(WeekBasedCapacityGroupServiceImpl::getCapacitiesDto) .toList(); - WeekBasedCapacityGroup weekBasedCapacityGroup = WeekBasedCapacityGroup + basedCapacityGroupRequest.setCapacities(capacitiesDtos); + } + + @Override + public WeekBasedCapacityGroupEntity findById(String capacityGroupId) { + Optional weekBasedCapacityGroupEntityOptional = weekBasedCapacityGroupRepository.findById( + Integer.getInteger(capacityGroupId) + ); + + if (weekBasedCapacityGroupEntityOptional.isEmpty()) { + throw new NotFoundException("WeekBasedCapacity not found"); + } + + return weekBasedCapacityGroupEntityOptional.get(); + } + + private static CapacitiesDto getCapacitiesDto(CapacityTimeSeries capacityTimeSeries) { + CapacitiesDto capacitiesDto = new CapacitiesDto(); + + capacitiesDto.setActualCapacity(capacityTimeSeries.getActualCapacity().toString()); + capacitiesDto.setMaximumCapacity(capacitiesDto.getMaximumCapacity()); + capacitiesDto.setCalendarWeek(capacitiesDto.getCalendarWeek()); + + return capacitiesDto; + } + + private static LinkedDemandSeriesRequest getLinkedDemandSeries(LinkedDemandSeries linkedDemandSeries1) { + LinkedDemandSeriesRequest linkedDemandSeriesRequest = new LinkedDemandSeriesRequest(); + DemandCategoryDto demandCategoryDto = new DemandCategoryDto(); + demandCategoryDto.setDemandCategory(linkedDemandSeries1.getDemandCategory().getDemandCategoryCode()); + + linkedDemandSeriesRequest.setDemandCategory(demandCategoryDto); + linkedDemandSeriesRequest.setCustomerLocation(linkedDemandSeries1.getCustomerId().getBpn()); + linkedDemandSeriesRequest.setMaterialNumberCustomer(linkedDemandSeries1.getMaterialNumberCustomer()); + linkedDemandSeriesRequest.setMaterialNumberSupplier(linkedDemandSeries1.getMaterialNumberSupplier()); + + return linkedDemandSeriesRequest; + } + + private void validateFields(WeekBasedCapacityGroupRequest weekBasedCapacityGroupRequest) { + if (!UUIDUtil.checkValidUUID(weekBasedCapacityGroupRequest.getCapacityGroupId())) { + throw new BadRequestException("not a valid ID"); + } + } + + private WeekBasedCapacityGroupEntity convertEntity(WeekBasedCapacityGroupRequest weekBasedCapacityGroupRequest) { + return WeekBasedCapacityGroupEntity .builder() - .name(weekBasedCapacityGroupRequest.getName()) - .unityOfMeasure(weekBasedCapacityGroupRequest.getUnityOfMeasure()) - .supplier(weekBasedCapacityGroupRequest.getSupplier()) - .changedAt(weekBasedCapacityGroupRequest.getChangedAt()) - .capacityGroupId(weekBasedCapacityGroupRequest.getCapacityGroupId()) - .customer(weekBasedCapacityGroupRequest.getCustomer()) - .capacities(capacities) - .likedDemandSeries(likedDemandSeries) + .weekBasedCapacityGroup(weekBasedCapacityGroupRequest) + .viewed(false) .build(); - - return WeekBasedCapacityGroupEntity.builder().weekBasedCapacityGroup(weekBasedCapacityGroup).build(); } } diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/WeekBasedMaterialServiceImpl.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/WeekBasedMaterialServiceImpl.java index 386e47d0..359c2bb5 100644 --- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/WeekBasedMaterialServiceImpl.java +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/WeekBasedMaterialServiceImpl.java @@ -22,7 +22,11 @@ package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.impl; +import eclipse.tractusx.demand_capacity_mgmt_specification.model.DemandSeriesCategoryDto; +import eclipse.tractusx.demand_capacity_mgmt_specification.model.DemandSeriesDto; +import eclipse.tractusx.demand_capacity_mgmt_specification.model.DemandWeekSeriesDto; import eclipse.tractusx.demand_capacity_mgmt_specification.model.WeekBasedMaterialDemandRequestDto; +import java.util.LinkedList; import java.util.List; import java.util.Optional; import lombok.RequiredArgsConstructor; @@ -30,9 +34,11 @@ import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.MaterialDemandEntity; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.SupplierEntity; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.WeekBasedMaterialDemandEntity; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.MaterialDemandStatus; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.exceptions.BadRequestException; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories.SupplierRepository; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories.WeekBasedMaterialDemandRepository; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.DemandService; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.LinkDemandService; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.WeekBasedMaterialService; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.utils.DataConverterUtil; @@ -52,6 +58,8 @@ public class WeekBasedMaterialServiceImpl implements WeekBasedMaterialService { private final LinkDemandService linkDemandService; + private final DemandService demandService; + @Override public void createWeekBasedMaterial(List weekBasedMaterialDemandRequestDtoList) { weekBasedMaterialDemandRequestDtoList.forEach( @@ -74,10 +82,15 @@ public void sendWeekBasedMaterial() { SupplierEntity supplierEntity = supplierEntityOpt.get(); RestTemplate restTemplate = new RestTemplate(); String fooResourceUrl = supplierEntity.getEdcUrl(); - //TODO create the Actual Demand and send to the supplier - ResponseEntity response = restTemplate.getForEntity(fooResourceUrl, String.class); + // ResponseEntity response = restTemplate.getForEntity(fooResourceUrl, String.class); } + + List demandEntityList = demandService.getAllByStatus( + MaterialDemandStatus.READY_SYNCHRONIZE + ); + + demandEntityList.forEach(this::createWeekBasedMaterialRequestFromEntity); } @Override @@ -90,7 +103,57 @@ public void receiveWeekBasedMaterial() { } @Override - public void createWeekBasedMaterialRequestFromEntity(MaterialDemandEntity materialDemandEntity) {} + public void createWeekBasedMaterialRequestFromEntity(MaterialDemandEntity materialDemandEntity) { + WeekBasedMaterialDemandRequestDto basedMaterialDemandRequestDto = new WeekBasedMaterialDemandRequestDto(); + + basedMaterialDemandRequestDto.setMaterialDemandId(materialDemandEntity.getId().toString()); + basedMaterialDemandRequestDto.setMaterialNumberCustomer(materialDemandEntity.getMaterialNumberCustomer()); + basedMaterialDemandRequestDto.setMaterialDescriptionCustomer( + materialDemandEntity.getMaterialDescriptionCustomer() + ); + basedMaterialDemandRequestDto.setCustomer(materialDemandEntity.getCustomerId().getBpn()); + basedMaterialDemandRequestDto.setSupplier(materialDemandEntity.getSupplierId().getBpn()); + basedMaterialDemandRequestDto.setUnityOfMeasure(materialDemandEntity.getUnitMeasure().getCodeValue()); + + List demandWeekSeriesDtoList = new LinkedList<>(); + + materialDemandEntity + .getDemandSeries() + .forEach( + demandSeries -> { + DemandWeekSeriesDto demandWeekSeriesDto = new DemandWeekSeriesDto(); + + demandWeekSeriesDto.setCustomerLocation(demandSeries.getCustomerLocation().getBpn()); + demandWeekSeriesDto.setExpectedSupplierLocation( + demandSeries.getExpectedSupplierLocation().toString() + ); + + DemandSeriesCategoryDto demandSeriesCategoryDto = new DemandSeriesCategoryDto(); + demandSeriesCategoryDto.setId(demandSeries.getDemandCategory().getId().toString()); + + demandWeekSeriesDto.setDemandCategory(demandSeriesCategoryDto); + + List demandSeriesDtos = demandSeries + .getDemandSeriesValues() + .stream() + .map( + demandSeriesValues -> { + DemandSeriesDto demandSeriesDto = new DemandSeriesDto(); + + demandSeriesDto.setCalendarWeek(demandSeriesValues.getCalendarWeek().toString()); + demandSeriesValues.setDemand(demandSeriesValues.getDemand()); + + return demandSeriesDto; + } + ) + .toList(); + + demandWeekSeriesDto.setDemands(demandSeriesDtos); + + demandWeekSeriesDtoList.add(demandWeekSeriesDto); + } + ); + } private void validateFields(WeekBasedMaterialDemandRequestDto weekBasedMaterialDemandRequestDto) { if (!UUIDUtil.checkValidUUID(weekBasedMaterialDemandRequestDto.getMaterialDemandId())) { diff --git a/demand-capacity-mgmt-backend/src/main/resources/application.yml b/demand-capacity-mgmt-backend/src/main/resources/application.yml index 93db5966..15647e30 100644 --- a/demand-capacity-mgmt-backend/src/main/resources/application.yml +++ b/demand-capacity-mgmt-backend/src/main/resources/application.yml @@ -24,9 +24,9 @@ spring: database: POSTGRESQL show-sql: true datasource: - url: jdbc:postgresql://${DCM_DATASOURCE_HOST:localhost:5432}/${DCM_DATASOURCE_NAME:dmc} - username: ${DCM_DATASOURCE_USER:dcm} - password: ${DCM_DATASOURCE_PASS:dcm} + url: jdbc:postgresql://${DCM_DATASOURCE_HOST:localhost:5432}/${DCM_DATASOURCE_NAME:dcm} + username: ${DCM_DATASOURCE_USER:postgres} + password: ${DCM_DATASOURCE_PASS:postgres} driverClassName: org.postgresql.Driver sql: init: diff --git a/demand-capacity-mgmt-backend/src/main/resources/db/migration/V202307221430__6_create_demand_status_and_capacity_status.sql b/demand-capacity-mgmt-backend/src/main/resources/db/migration/V202307221430__6_create_demand_status_and_capacity_status.sql new file mode 100644 index 00000000..359654d0 --- /dev/null +++ b/demand-capacity-mgmt-backend/src/main/resources/db/migration/V202307221430__6_create_demand_status_and_capacity_status.sql @@ -0,0 +1,28 @@ +/* + * ******************************************************************************* + * 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 + * ******************************************************************************** + * + */ + +ALTER TABLE material_demand +ADD COLUMN status varchar(40); + +ALTER TABLE capacity_group +ADD COLUMN status varchar(40); diff --git a/demand-capacity-mgmt-backend/src/main/resources/db/migration/V202308041430__7_create_capacity_group_id_in_demand_series.sql b/demand-capacity-mgmt-backend/src/main/resources/db/migration/V202308041430__7_create_capacity_group_id_in_demand_series.sql new file mode 100644 index 00000000..85014fc9 --- /dev/null +++ b/demand-capacity-mgmt-backend/src/main/resources/db/migration/V202308041430__7_create_capacity_group_id_in_demand_series.sql @@ -0,0 +1,25 @@ +/* + * ******************************************************************************* + * 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 + * ******************************************************************************** + * + */ + +ALTER TABLE demand_series +ADD COLUMN capacity_group_id varchar(200); diff --git a/demand-capacity-mgmt-backend/src/test/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/DemandCapacityMgmtBackendApplicationTests.java b/demand-capacity-mgmt-backend/src/test/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/DemandCapacityMgmtBackendApplicationTests.java index b6a56147..e726d674 100644 --- a/demand-capacity-mgmt-backend/src/test/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/DemandCapacityMgmtBackendApplicationTests.java +++ b/demand-capacity-mgmt-backend/src/test/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/DemandCapacityMgmtBackendApplicationTests.java @@ -22,9 +22,6 @@ package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend; -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - //@SpringBootTest class DemandCapacityMgmtBackendApplicationTests { diff --git a/demand-capacity-mgmt-backend/src/test/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/CapacityGroupServiceTest.java b/demand-capacity-mgmt-backend/src/test/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/CapacityGroupServiceTest.java index 46d46e9c..9ee053fa 100644 --- a/demand-capacity-mgmt-backend/src/test/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/CapacityGroupServiceTest.java +++ b/demand-capacity-mgmt-backend/src/test/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/CapacityGroupServiceTest.java @@ -29,13 +29,17 @@ import eclipse.tractusx.demand_capacity_mgmt_specification.model.CapacityGroupRequest; import eclipse.tractusx.demand_capacity_mgmt_specification.model.CapacityRequest; +import eclipse.tractusx.demand_capacity_mgmt_specification.model.WeekBasedMaterialDemandRequestDto; import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.UUID; -import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.CompanyEntity; -import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.LinkDemandEntity; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.*; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.CapacityGroupStatus; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories.CapacityGroupRepository; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories.DemandCategoryRepository; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories.LinkDemandRepository; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.impl.CapacityGroupServiceImpl; import org.junit.jupiter.api.Test; @@ -62,18 +66,31 @@ public class CapacityGroupServiceTest { @Mock private LinkDemandRepository linkDemandRepository; + @Mock + private DemandCategoryService demandCategoryService; + private static CapacityGroupRequest capacityGroupRequest = createCapacityGroupRequest(); private static CompanyEntity company = createCompanyEntity(); private LinkDemandEntity linkDemandEntity = createLinkDemandEntity(); + private static UnitMeasureEntity unitMeasure = createUnitMeasureEntity(); + + private static WeekBasedMaterialDemandEntity weekBasedMaterialDemandEntity = createWeekBasedMaterialDemandEntity(); + + private static DemandCategoryEntity demandCategoryEntity = createDemandCategoryEntity(); + private CapacityGroupEntity capacityGroupEntity = createCapacityGroupEntity(); + @Test void shouldCreateCapacityGroup() { when(companyService.getCompanyIn(any())).thenReturn(List.of(company)); when(unityOfMeasureService.findById(any())).thenReturn(null); when(companyService.getCompanyById(any())).thenReturn(company); + when(demandCategoryService.findById(any())).thenReturn(demandCategoryEntity); when(linkDemandRepository.findById(any())).thenReturn(Optional.of(linkDemandEntity)); + // when(demandCategoryService.save(any())).thenReturn(demandCategoryEntity); + when(capacityGroupRepository.save(any())).thenReturn(capacityGroupEntity); capacityGroupService.createCapacityGroup(capacityGroupRequest); @@ -113,9 +130,93 @@ private static LinkDemandEntity createLinkDemandEntity() { return LinkDemandEntity .builder() .linked(false) - .demandCategoryId("") - .materialNumberSupplier("") - .materialNumberCustomer("") + .demandCategoryId("08b95a75-11a7-4bea-a958-821b9cb01642") + .materialNumberSupplier("08b95a75-11a7-4bea-a958-821b9cb01642") + .materialNumberCustomer("08b95a75-11a7-4bea-a958-821b9cb01642") + .weekBasedMaterialDemand(weekBasedMaterialDemandEntity) + .build(); + } + + private static UnitMeasureEntity createUnitMeasureEntity() { + return UnitMeasureEntity + .builder() + .id(UUID.fromString("08b95a75-11a7-4bea-a958-821b9cb01643")) + .codeValue("Kilogram") + .displayValue("Kg") + .build(); + } + + private static CapacityGroupEntity createCapacityGroupEntity() { + CapacityGroupEntity capacityGroup = CapacityGroupEntity + .builder() + .id(UUID.fromString("08b95a75-11a7-4bea-a958-821b9cb01642")) + .capacityGroupId(UUID.fromString("08b95a75-11a7-4bea-a958-821b9cb01642")) + .materialDescriptionCustomer("08b95a75-11a7-4bea-a958-821b9cb01641") + .materialNumberCustomer("08b95a75-11a7-4bea-a958-821b9cb01641") + .changedAt(LocalDateTime.now()) + .customerId(company) + .supplierId(company) + .unitMeasure(unitMeasure) + .linkedDemandSeries(new ArrayList<>()) + .supplierLocation(new ArrayList<>()) + .name("08b95a75-11a7-4bea-a958-821b9cb01642") + .status(CapacityGroupStatus.READY_SYNCHRONIZE) + .build(); + + List timeSeriesList = createCapacityTimeSeries(capacityGroup); + + capacityGroup.setCapacityTimeSeries(timeSeriesList); + + return capacityGroup; + } + + private static List createCapacityTimeSeries(CapacityGroupEntity capacityGroup) { + CapacityTimeSeries capacityTimeSeries1 = new CapacityTimeSeries(); + capacityTimeSeries1.setId(UUID.randomUUID()); + capacityTimeSeries1.setCalendarWeek(LocalDateTime.now()); + capacityTimeSeries1.setActualCapacity(100.0); + capacityTimeSeries1.setMaximumCapacity(150.0); + capacityTimeSeries1.setCapacityGroupEntity(capacityGroup); + + CapacityTimeSeries capacityTimeSeries2 = new CapacityTimeSeries(); + capacityTimeSeries2.setId(UUID.randomUUID()); + capacityTimeSeries2.setCalendarWeek(LocalDateTime.now()); + capacityTimeSeries2.setActualCapacity(120.0); + capacityTimeSeries2.setMaximumCapacity(160.0); + capacityTimeSeries2.setCapacityGroupEntity(capacityGroup); + + List timeSeriesList = new ArrayList<>(); + timeSeriesList.add(capacityTimeSeries1); + timeSeriesList.add(capacityTimeSeries2); + + return timeSeriesList; + } + + private static WeekBasedMaterialDemandEntity createWeekBasedMaterialDemandEntity() { + WeekBasedMaterialDemandRequestDto dto = new WeekBasedMaterialDemandRequestDto(); + dto.setUnityOfMeasure("kg"); + dto.setCustomer("08b95a75-11a7-4bea-a958-821b9cb01643"); + dto.setMaterialDemandId("ID"); + dto.setMaterialNumberCustomer("IDD"); + dto.setMaterialDescriptionCustomer("08b95a75-11a7-4bea-a958-821b9cb01643"); + dto.setChangedAt("now"); + + WeekBasedMaterialDemandEntity entity = WeekBasedMaterialDemandEntity + .builder() + .id(Long.valueOf("4")) + .viewed(false) + .weekBasedMaterialDemand(dto) + .build(); + return entity; + } + + private static DemandCategoryEntity createDemandCategoryEntity() { + DemandCategoryEntity demandCategoryEntity = DemandCategoryEntity + .builder() + .id(UUID.fromString("08b95a75-11a7-4bea-a958-821b9cb01642")) + .demandCategoryCode("Test") + .demandCategoryName("test2") .build(); + return demandCategoryEntity; } } diff --git a/demand-capacity-mgmt-backend/src/test/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/WeekBasedCapacityGroupServiceTest.java b/demand-capacity-mgmt-backend/src/test/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/WeekBasedCapacityGroupServiceTest.java new file mode 100644 index 00000000..61ee5fa0 --- /dev/null +++ b/demand-capacity-mgmt-backend/src/test/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/WeekBasedCapacityGroupServiceTest.java @@ -0,0 +1,154 @@ +/* + * ******************************************************************************* + * 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 static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import eclipse.tractusx.demand_capacity_mgmt_specification.model.CapacitiesDto; +import eclipse.tractusx.demand_capacity_mgmt_specification.model.DemandCategoryDto; +import eclipse.tractusx.demand_capacity_mgmt_specification.model.LinkedDemandSeriesRequest; +import eclipse.tractusx.demand_capacity_mgmt_specification.model.WeekBasedCapacityGroupRequest; +import java.util.List; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.DemandSeries; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.MaterialDemandEntity; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.WeekBasedCapacityGroupEntity; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories.CustomerRepository; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories.MaterialDemandRepository; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories.WeekBasedCapacityGroupRepository; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.impl.WeekBasedCapacityGroupServiceImpl; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ExtendWith(SpringExtension.class) +public class WeekBasedCapacityGroupServiceTest { + + @InjectMocks + private WeekBasedCapacityGroupServiceImpl weekBasedCapacityGroupService; + + @Mock + private WeekBasedCapacityGroupRepository weekBasedCapacityGroupRepository; + + @Mock + private CustomerRepository customerRepository; + + @Mock + private CapacityGroupService capacityGroupService; + + @Mock + private MaterialDemandRepository materialDemandRepository; + + private static DemandCategoryDto demandCategoryDto = createDemandCategoryDto(); + private static CapacitiesDto capacitiesDto = createCapacitiesDto(); + private static LinkedDemandSeriesRequest linkedDemandSeriesRequest = createLinkedDemandSeriesRequest(); + private static WeekBasedCapacityGroupRequest weekBasedCapacityGroupRequest = createWeekBasedCapacityGroupRequest(); + private static WeekBasedCapacityGroupEntity weekBasedCapacityGroup = createWeekBasedCapacityGroupEntity(); + private static MaterialDemandEntity materialDemandEntity = createMaterialDemandEntity(); + + @Test + void shouldCreateWeekBasedCapacityGroup() { + weekBasedCapacityGroupService.createWeekBasedCapacityGroup(List.of(weekBasedCapacityGroupRequest)); + + verify(weekBasedCapacityGroupRepository, times(1)).save(any()); + } + + @Test + void shouldReceiveWeekBasedCapacityGroup() { + when(weekBasedCapacityGroupRepository.getAllByViewed(false)).thenReturn(List.of(weekBasedCapacityGroup)); + when( + materialDemandRepository.findAllByMaterialNumberCustomerAndDemandSeriesCustomerLocationAndDemandCategory( + any(), + any(), + any() + ) + ) + .thenReturn(List.of(materialDemandEntity)); + + weekBasedCapacityGroupService.receiveWeekBasedCapacityGroup(); + + verify(materialDemandRepository, times(1)).saveAll(any()); + } + + private static WeekBasedCapacityGroupRequest createWeekBasedCapacityGroupRequest() { + WeekBasedCapacityGroupRequest weekBasedCapacityGroupRequest = new WeekBasedCapacityGroupRequest(); + + weekBasedCapacityGroupRequest.setName("test"); + weekBasedCapacityGroupRequest.setCustomer("test"); + weekBasedCapacityGroupRequest.setCapacityGroupId("2c478e29-3909-481a-99b9-df3d0db97a4c"); + weekBasedCapacityGroupRequest.setUnityOfMeasure("un"); + + weekBasedCapacityGroupRequest.setCapacities(List.of(capacitiesDto)); + weekBasedCapacityGroupRequest.setLinkedDemandSeries(List.of(linkedDemandSeriesRequest)); + weekBasedCapacityGroupRequest.setSupplierLocations(List.of("")); + + return weekBasedCapacityGroupRequest; + } + + private static CapacitiesDto createCapacitiesDto() { + CapacitiesDto capacitiesDto = new CapacitiesDto(); + capacitiesDto.setActualCapacity("1"); + capacitiesDto.setMaximumCapacity("10"); + capacitiesDto.setCalendarWeek("2023-06-19"); + + return capacitiesDto; + } + + private static LinkedDemandSeriesRequest createLinkedDemandSeriesRequest() { + LinkedDemandSeriesRequest linkedDemandSeriesRequest = new LinkedDemandSeriesRequest(); + + linkedDemandSeriesRequest.setDemandCategory(demandCategoryDto); + linkedDemandSeriesRequest.setCustomerLocation(""); + linkedDemandSeriesRequest.setMaterialNumberCustomer("test"); + linkedDemandSeriesRequest.setMaterialNumberSupplier(""); + + return linkedDemandSeriesRequest; + } + + private static DemandCategoryDto createDemandCategoryDto() { + DemandCategoryDto demandCategoryDto = new DemandCategoryDto(); + demandCategoryDto.setDemandCategory("default"); + + return demandCategoryDto; + } + + private static WeekBasedCapacityGroupEntity createWeekBasedCapacityGroupEntity() { + return WeekBasedCapacityGroupEntity + .builder() + .viewed(false) + .id(1l) + .weekBasedCapacityGroup(weekBasedCapacityGroupRequest) + .build(); + } + + private static MaterialDemandEntity createMaterialDemandEntity() { + DemandSeries demandSeries = DemandSeries.builder().build(); + + return MaterialDemandEntity.builder().demandSeries(List.of(demandSeries)).build(); + } +} diff --git a/demand-capacity-mgmt-backend/src/test/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/WeekBasedMaterialServiceTest.java b/demand-capacity-mgmt-backend/src/test/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/WeekBasedMaterialServiceTest.java new file mode 100644 index 00000000..c7d5283c --- /dev/null +++ b/demand-capacity-mgmt-backend/src/test/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/WeekBasedMaterialServiceTest.java @@ -0,0 +1,86 @@ +package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import eclipse.tractusx.demand_capacity_mgmt_specification.model.DemandSeriesCategoryDto; +import eclipse.tractusx.demand_capacity_mgmt_specification.model.DemandSeriesDto; +import eclipse.tractusx.demand_capacity_mgmt_specification.model.DemandWeekSeriesDto; +import eclipse.tractusx.demand_capacity_mgmt_specification.model.WeekBasedMaterialDemandRequestDto; +import java.util.List; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories.SupplierRepository; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories.WeekBasedMaterialDemandRepository; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.impl.WeekBasedMaterialServiceImpl; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ExtendWith(SpringExtension.class) +public class WeekBasedMaterialServiceTest { + + @InjectMocks + private WeekBasedMaterialServiceImpl weekBasedMaterialService; + + @Mock + private WeekBasedMaterialDemandRepository weekBasedMaterialDemandRepository; + + @Mock + private SupplierRepository supplierRepository; + + @Mock + private LinkDemandService linkDemandService; + + @Mock + private DemandService demandService; + + private static DemandSeriesDto demandSeriesDto = createDemandSeriesDto(); + private static DemandWeekSeriesDto demandWeekSeriesDto = createDemandWeekSeriesDto(); + + private static WeekBasedMaterialDemandRequestDto weekBasedMaterialDemandRequestDto = createWeekBasedMaterialDemandRequestDto(); + + @Test + void shouldCreateWeekBasedMaterial() { + weekBasedMaterialService.createWeekBasedMaterial(List.of(weekBasedMaterialDemandRequestDto)); + + verify(weekBasedMaterialDemandRepository, times(1)).save(any()); + } + + private static DemandSeriesDto createDemandSeriesDto() { + DemandSeriesDto demandSeriesDto = new DemandSeriesDto(); + demandSeriesDto.setCalendarWeek("2023-06-19"); + demandSeriesDto.setDemand("1"); + + return demandSeriesDto; + } + + private static DemandWeekSeriesDto createDemandWeekSeriesDto() { + DemandWeekSeriesDto demandWeekSeriesDto = new DemandWeekSeriesDto(); + + DemandSeriesCategoryDto demandSeriesCategoryDto = new DemandSeriesCategoryDto(); + demandSeriesCategoryDto.setId("f50c3e71-a1a7-44c9-9de6-2e7aaaf65ac4"); + + demandWeekSeriesDto.setCustomerLocation(""); + demandWeekSeriesDto.setDemands(List.of(demandSeriesDto)); + demandWeekSeriesDto.setDemandCategory(demandSeriesCategoryDto); + demandWeekSeriesDto.setExpectedSupplierLocation(""); + + return demandWeekSeriesDto; + } + + private static WeekBasedMaterialDemandRequestDto createWeekBasedMaterialDemandRequestDto() { + WeekBasedMaterialDemandRequestDto basedMaterialDemandRequestDto = new WeekBasedMaterialDemandRequestDto(); + basedMaterialDemandRequestDto.setMaterialNumberCustomer("test"); + basedMaterialDemandRequestDto.setMaterialDemandId("f50c3e71-a1a7-44c9-9de6-2e7aaaf65ac4"); + basedMaterialDemandRequestDto.setSupplier("f50c3e71-a1a7-44c9-9de6-2e7aaaf65ac4"); + basedMaterialDemandRequestDto.setCustomer("f50c3e71-a1a7-44c9-9de6-2e7aaaf65ac4"); + basedMaterialDemandRequestDto.setMaterialDescriptionCustomer(""); + basedMaterialDemandRequestDto.setUnityOfMeasure("un"); + + basedMaterialDemandRequestDto.setDemandSeries(List.of(demandWeekSeriesDto)); + + return basedMaterialDemandRequestDto; + } +} diff --git a/demand-capacity-mgmt-frontend/package.json b/demand-capacity-mgmt-frontend/package.json index 16e7f079..f4846cdf 100644 --- a/demand-capacity-mgmt-frontend/package.json +++ b/demand-capacity-mgmt-frontend/package.json @@ -2,6 +2,7 @@ "name": "tx-demand-capacity-mgmt", "version": "0.1.0", "private": true, + "proxy": "http://localhost:8080", "dependencies": { "@popperjs/core": "^2.11.8", "@react-icons/all-files": "^4.1.0", @@ -14,11 +15,12 @@ "@types/react-dom": "^18.2.6", "axios": "^1.4.0", "bootstrap": "^5.3.0", + "http-proxy-middleware": "^2.0.6", "prop-types": "^15.8.1", "react": "^18.2.0", "react-dom": "^18.2.0", "react-icons": "^4.10.1", - "react-router-dom": "^6.14.1", + "react-router-dom": "^6.14.2", "react-scripts": "^5.0.1", "typescript": "^5.1.3", "web-vitals": "^2.1.4" diff --git a/demand-capacity-mgmt-frontend/public/favicon.ico b/demand-capacity-mgmt-frontend/public/favicon.ico index a11777cc..9a363c90 100644 Binary files a/demand-capacity-mgmt-frontend/public/favicon.ico and b/demand-capacity-mgmt-frontend/public/favicon.ico differ diff --git a/demand-capacity-mgmt-frontend/src/App.css b/demand-capacity-mgmt-frontend/src/App.css index 4065397d..648dbe97 100644 --- a/demand-capacity-mgmt-frontend/src/App.css +++ b/demand-capacity-mgmt-frontend/src/App.css @@ -71,6 +71,8 @@ button { text-decoration: underline; } -.quickAcessBody{ - z-index: 1020; +.required-field-label::after { + content: "*"; + color: red; + margin-left: 4px; /* Add some spacing between the label text and the asterisk */ } \ No newline at end of file diff --git a/demand-capacity-mgmt-frontend/src/components/AddForm.tsx b/demand-capacity-mgmt-frontend/src/components/AddForm.tsx deleted file mode 100644 index 2fda8b8b..00000000 --- a/demand-capacity-mgmt-frontend/src/components/AddForm.tsx +++ /dev/null @@ -1,203 +0,0 @@ -/* - * ******************************************************************************* - * 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, { useContext, useState, ChangeEvent, FormEvent } from 'react'; -import { Form, Button } from 'react-bootstrap'; -import { DemandContext } from '../contexts/DemandContextProvider'; - -const AddForm: React.FC = () => { - const { createDemand } = useContext(DemandContext)!; - - const [description, setDescription] = useState(''); - const [startDate, setStartDate] = useState(''); - const [endDate, setEndDate] = useState(''); - const [requiredValue, setRequiredValue] = useState(''); - const [deliveredValue, setDeliveredValue] = useState(''); - const [maximumValue, setMaximumValue] = useState(''); - const [demandCategory, setDemandCategory] = useState(''); - - - const handleSubmit = (e: FormEvent) => { - e.preventDefault(); - - const newDemand = { - id: 0, // Assign an appropriate ID here - product: '', // Assign the product name here - startDate, - endDate, - requiredValue: parseInt(requiredValue), - deliveredValue: parseInt(deliveredValue), - maximumValue: parseInt(maximumValue), - productId: '1', - projectId: '1', - demandCategory, - companyId: '1', - description, - }; - - createDemand(newDemand); - resetForm(); - }; - - const resetForm = () => { - setDescription(''); - setStartDate(''); - setEndDate(''); - setRequiredValue(''); - setDeliveredValue(''); - setMaximumValue(''); - setDemandCategory(''); - }; - - const onInputChange = (e: ChangeEvent) => { - const { name, value } = e.target; - switch (name) { - case 'description': - setDescription(value); - break; - case 'startDate': - setStartDate(value); - break; - case 'endDate': - setEndDate(value); - break; - case 'requiredValue': - if (value >= '0') { - setRequiredValue(value); - } - break; - case 'deliveredValue': - if (value >= '0') { - setDeliveredValue(value); - } - break; - case 'maximumValue': - if (value >= '0') { - setMaximumValue(value); - } - break; - case 'demandCategory': - setDemandCategory(value); - break; - default: - break; - } - }; - - return ( -
-

Description *

- - - -

-

Start Date *

- - - -

-

End Date *

- - - -

-

Required Value *

- - - -

-

Delivered Value *

- - - -

-

Maximum Value *

- - - -

- -

Demand Category *

- - - -

- - -

- ); -}; - -export default AddForm; diff --git a/demand-capacity-mgmt-frontend/src/components/Home.tsx b/demand-capacity-mgmt-frontend/src/components/CapacityGroupDetails.tsx similarity index 78% rename from demand-capacity-mgmt-frontend/src/components/Home.tsx rename to demand-capacity-mgmt-frontend/src/components/CapacityGroupDetails.tsx index 3d0dcc8e..7320dc88 100644 --- a/demand-capacity-mgmt-frontend/src/components/Home.tsx +++ b/demand-capacity-mgmt-frontend/src/components/CapacityGroupDetails.tsx @@ -20,16 +20,13 @@ * ******************************************************************************** */ -import CapacityGroupsList from "./defaultview/DefaultviewPage"; +import CapacityGroupsList from "./capacitygroup/CapacityGroupsView"; import CapacityGroupContext from "../contexts/CapacityGroupsContextProvider"; -import TopMenu from "./TopMenu"; -import QuickAcessItems from "./QuickAcessItems"; -import DemandContextProvider from "../contexts/DemandContextProvider"; +function CapacityGroupDetails() { -function Home() { return ( - <> + <>

@@ -40,13 +37,9 @@ function Home() {
- - - - ); } -export default Home; \ No newline at end of file +export default CapacityGroupDetails; \ No newline at end of file diff --git a/demand-capacity-mgmt-frontend/src/components/CompanyOptions.tsx b/demand-capacity-mgmt-frontend/src/components/CompanyOptions.tsx new file mode 100644 index 00000000..7ab7c7cf --- /dev/null +++ b/demand-capacity-mgmt-frontend/src/components/CompanyOptions.tsx @@ -0,0 +1,50 @@ +/* + * ******************************************************************************* + * 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, { useContext } from 'react'; +import { CompanyContext } from '../contexts/CompanyContextProvider'; + +interface CompanyOptionsProps { + selectedCompanyName: string; +} + +const CompanyOptions: React.FC = ({ selectedCompanyName }) => { + const companiesContextData = useContext(CompanyContext); + const { companies } = companiesContextData || {}; + + // Use the companies array to fill the options + return ( + <> + + {unitsofmeasure && + unitsofmeasure.map((unit) => ( + + ))} + + ); +}; + +export default UnitsOfMeasureOptions; + diff --git a/demand-capacity-mgmt-frontend/src/components/capacitygroup/CapacityGroupDetailsPage.tsx b/demand-capacity-mgmt-frontend/src/components/capacitygroup/CapacityGroupDetailsPage.tsx new file mode 100644 index 00000000..149a65d2 --- /dev/null +++ b/demand-capacity-mgmt-frontend/src/components/capacitygroup/CapacityGroupDetailsPage.tsx @@ -0,0 +1,105 @@ +/* + * ******************************************************************************* + * 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 { useState } from 'react'; +import { Tab, Tabs, ButtonGroup, Button, ToggleButton } from 'react-bootstrap'; + +function CapacityGroupDetailsPage() { + const [editMode, setEditMode] = useState(false); + const [savedChanges, setSavedChanges] = useState(false); + const [activeTab, setActiveTab] = useState('overview'); + + const handleSave = () => { + // Perform save operation here + setEditMode(false); + setSavedChanges(true); + console.log(savedChanges);// todo clean + }; + + const handleRevert = () => { + // Revert changes here + setEditMode(false); + setSavedChanges(false); + }; + + + return ( + <> +
+
+
+
+
+ UUID - CapacityGroupName +
+
+
+ {activeTab === 'overview' && ( + + setEditMode(!editMode)} + > + Edit + + + + + )} +
+
+ { + if (typeof tabKey === 'string') { + setActiveTab(tabKey); + } + }} + > + + Element for Overview and chronogram here + + + Materials Table here + + + Pre filtered event list here + + +
+ + ); +} + +export default CapacityGroupDetailsPage; diff --git a/demand-capacity-mgmt-frontend/src/components/capacitygroup/CapacityGroupPage.tsx b/demand-capacity-mgmt-frontend/src/components/capacitygroup/CapacityGroupPage.tsx new file mode 100644 index 00000000..6d6dc662 --- /dev/null +++ b/demand-capacity-mgmt-frontend/src/components/capacitygroup/CapacityGroupPage.tsx @@ -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 + * ******************************************************************************** + */ + +import CapacityGroupsProvider from "../../contexts/CapacityGroupsContextProvider"; +import CapacityGroupsList from "./CapacityGroupsView"; + + +function CapacityGroupPage() { + + return ( + <> +
+
+
+
+ + + +
+
+
+ + + ); +} + +export default CapacityGroupPage; \ No newline at end of file diff --git a/demand-capacity-mgmt-frontend/src/components/defaultview/CapacityGroupsModal.tsx b/demand-capacity-mgmt-frontend/src/components/capacitygroup/CapacityGroupsModal.tsx similarity index 100% rename from demand-capacity-mgmt-frontend/src/components/defaultview/CapacityGroupsModal.tsx rename to demand-capacity-mgmt-frontend/src/components/capacitygroup/CapacityGroupsModal.tsx diff --git a/demand-capacity-mgmt-frontend/src/components/capacitygroup/CapacityGroupsTable.tsx b/demand-capacity-mgmt-frontend/src/components/capacitygroup/CapacityGroupsTable.tsx new file mode 100644 index 00000000..f44c15e7 --- /dev/null +++ b/demand-capacity-mgmt-frontend/src/components/capacitygroup/CapacityGroupsTable.tsx @@ -0,0 +1,86 @@ +/* + * ******************************************************************************* + * 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 from 'react'; +import { BiCaretDown, BiCaretUp } from 'react-icons/bi'; + +type CapacityGroupsTableProps = { + sortColumn: string; + sortOrder: string; + handleSort: (column: string) => void; + capacitygroupsItems: React.ReactNode; +}; + +const CapacityGroupsTable: React.FC = ({ sortColumn, sortOrder, handleSort, capacitygroupsItems }) => { + return ( + + + + + + + + + + + + + + + {capacitygroupsItems} +
handleSort('internalId')}> + Internal ID + {sortColumn === 'internalId' && sortOrder === 'asc' && } + {sortColumn === 'internalId' && sortOrder === 'desc' && } + handleSort('name')}> + Name + {sortColumn === 'name' && sortOrder === 'asc' && } + {sortColumn === 'name' && sortOrder === 'desc' && } + handleSort('customerBPNL')}> + Customber BPNL + {sortColumn === 'customerBPNL' && sortOrder === 'asc' && } + {sortColumn === 'customerBPNL' && sortOrder === 'desc' && } + handleSort('customerName')}> + Customer Name + {sortColumn === 'customerName' && sortOrder === 'asc' && } + {sortColumn === 'customerName' && sortOrder === 'desc' && } + handleSort('supplierBNPL')}> + Supplier BPNL + {sortColumn === 'supplierBNPL' && sortOrder === 'asc' && } + {sortColumn === 'supplierBNPL' && sortOrder === 'desc' && } + handleSort('numberOfMaterials')}> + # of Materials + {sortColumn === 'numberOfMaterials' && sortOrder === 'asc' && } + {sortColumn === 'numberOfMaterials' && sortOrder === 'desc' && } + handleSort('favoritedBy')}> + Favorited by + {sortColumn === 'favoritedBy' && sortOrder === 'asc' && } + {sortColumn === 'favoritedBy' && sortOrder === 'desc' && } + handleSort('status')}> + Status + {sortColumn === 'status' && sortOrder === 'asc' && } + {sortColumn === 'status' && sortOrder === 'desc' && } +
+ ); +}; + +export default CapacityGroupsTable; diff --git a/demand-capacity-mgmt-frontend/src/components/defaultview/DefaultviewPage.tsx b/demand-capacity-mgmt-frontend/src/components/capacitygroup/CapacityGroupsView.tsx similarity index 68% rename from demand-capacity-mgmt-frontend/src/components/defaultview/DefaultviewPage.tsx rename to demand-capacity-mgmt-frontend/src/components/capacitygroup/CapacityGroupsView.tsx index 0987db86..81bd259e 100644 --- a/demand-capacity-mgmt-frontend/src/components/defaultview/DefaultviewPage.tsx +++ b/demand-capacity-mgmt-frontend/src/components/capacitygroup/CapacityGroupsView.tsx @@ -20,36 +20,27 @@ * ******************************************************************************** */ -import React, { useContext, useState, useMemo } from 'react'; -import { Modal, Button,Form,Col,Row } from 'react-bootstrap'; -import { CapacityGroupContext } from '../../contexts/CapacityGroupsContextProvider'; -import AddForm from '../AddForm'; +import React, { useContext, useState, useMemo} from 'react'; +import { Form,Col,Row } from 'react-bootstrap'; +import { CapacityGroupContext } from '../../contexts/CapacityGroupsContextProvider'; +//import { CapacityGroup } from '../../interfaces/capacitygroup_interfaces'; import Pagination from '../Pagination'; import CapacityGroupsTable from './CapacityGroupsTable'; import Search from '../Search'; -import CapacityGroupsModal from './CapacityGroupsModal'; +import '../../index.css'; const CapacityGroupsList: React.FC = () => { - // const [, setShowEditModal] = useState(false); - // const [, setSelectedCapacityGroup] = useState(null); + // to do clean /const [selectedCapacityGroup, setSelectedCapacityGroup] = useState(null); const { capacitygroups } = useContext(CapacityGroupContext)!; const [searchQuery, setSearchQuery] = useState(''); - const [show, setShow] = useState(false); // Add setShow to manage modal visibility const [currentPage, setCurrentPage] = useState(1); const [sortColumn, setSortColumn] = useState(''); const [sortOrder, setSortOrder] = useState(''); const [capacitygroupsPerPage, setcapacitygroupsPerPage] = useState(20); // Set the default value here - /*const handleShow = () => { - setShow(true); - };*/ - - const handleClose = () => { - setShow(false); - }; - const handleSort = (column: string) => { + console.log('Sorting column:', column); if (sortColumn === column) { // If the same column is clicked again, toggle the sort order setSortOrder(sortOrder === 'asc' ? 'desc' : 'asc'); @@ -60,40 +51,28 @@ const CapacityGroupsList: React.FC = () => { } }; - /* const handleEdit = (capacitygroup: CapacityGroup) => { - setSelectedCapacityGroup(capacitygroup); - setShowEditModal(true); - };*/ - - /* const handleCloseEditModal = () => { - setShowEditModal(false); - };*/ - const filteredcapacitygroups = useMemo(() => { let sortedcapacitygroups = [...capacitygroups]; if (searchQuery !== '') { sortedcapacitygroups = sortedcapacitygroups.filter((capacitygroup) => - capacitygroup.description.toLowerCase().includes(searchQuery.toLowerCase()) || - capacitygroup.id.toString().includes(searchQuery.toLowerCase()) || - capacitygroup.companyId.toString().includes(searchQuery.toLowerCase()) + capacitygroup.internalId.toString().includes(searchQuery.toLowerCase()) || + capacitygroup.name.toLowerCase().includes(searchQuery.toLowerCase()) || + capacitygroup.customerBPNL.toString().includes(searchQuery.toLowerCase()) || + capacitygroup.customerName.toString().includes(searchQuery.toLowerCase()) || + capacitygroup.supplierBNPL.toString().includes(searchQuery.toLowerCase()) || + capacitygroup.numberOfMaterials.toString().includes(searchQuery.toLowerCase()) || + capacitygroup.favoritedBy.toString().includes(searchQuery.toLowerCase()) || + capacitygroup.status.toString().includes(searchQuery.toLowerCase()) ); } if (sortColumn !== '') { sortedcapacitygroups.sort((a, b) => { - const aValue = a[sortColumn]; - const bValue = b[sortColumn]; - - if (typeof aValue === 'string') { - // Sort strings alphabetically - return aValue.localeCompare(bValue, undefined, { sensitivity: 'base' }); - } else if (typeof aValue === 'number') { - // Sort numbers numerically - return aValue - bValue; - } - - return 0; + const aValue = String(a[sortColumn]); // Convert to string + const bValue = String(b[sortColumn]); // Convert to string + + return aValue.localeCompare(bValue, undefined, { sensitivity: 'base' }); }); if (sortOrder === 'desc') { @@ -119,15 +98,14 @@ const CapacityGroupsList: React.FC = () => { const capacitygroupsItems = useMemo( () => slicedcapacitygroups.map((capacitygroup) => ( - - {capacitygroup.id} - {capacitygroup.companyId} - {capacitygroup.requiredValue} - {capacitygroup.deliveredValue} - {capacitygroup.maximumValue} - {capacitygroup.description} - {capacitygroup.startDate.split('T')[0]} - {capacitygroup.endDate.split('T')[0]} + + {capacitygroup.internalId} + {capacitygroup.name} + {capacitygroup.customerBPNL} + {capacitygroup.customerName} + {capacitygroup.supplierBNPL} + {capacitygroup.numberOfMaterials} + {capacitygroup.favoritedBy} {/* TODO Depending on status, this should be a different span*/} OK @@ -193,23 +171,6 @@ const CapacityGroupsList: React.FC = () => { - - - - Add Demand - - - - - - - - ); }; diff --git a/demand-capacity-mgmt-frontend/src/components/defaultview/CapacityGroupsTable.tsx b/demand-capacity-mgmt-frontend/src/components/defaultview/CapacityGroupsTable.tsx deleted file mode 100644 index 3f7e3736..00000000 --- a/demand-capacity-mgmt-frontend/src/components/defaultview/CapacityGroupsTable.tsx +++ /dev/null @@ -1,72 +0,0 @@ -/* - * ******************************************************************************* - * 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 from 'react'; - - -type CapacityGroupsTableProps = { - sortColumn: string; - sortOrder: string; - handleSort: (column: string) => void; - capacitygroupsItems: React.ReactNode; -}; - -const CapacityGroupsTable: React.FC = ({ sortColumn, sortOrder, handleSort, capacitygroupsItems }) => { - return ( - - - - - - - - - - - - - - - {capacitygroupsItems} -
handleSort('id')}> - Internal ID {sortColumn === 'id' && } - handleSort('name')}> - Name {sortColumn === 'name' && } - handleSort('customberbpnl')}> - Customber BPNL {sortColumn === 'customberbpnl' && } - handleSort('customername')}> - Customer Name {sortColumn === 'customername' && } - handleSort('supplierbpnl')}> - Supplier BPNL {sortColumn === 'supplierbpnl' && } - handleSort('suppliername')}> - Supplier Name {sortColumn === 'suppliername' && } - handleSort('nmaterials')}> - # of Materials {sortColumn === 'nmaterials' && } - handleSort('favoritedby')}> - Favorited by {sortColumn === 'favoritedby' && } - handleSort('status')}> - Status {sortColumn === 'status' && } -
- ); -}; - -export default CapacityGroupsTable; diff --git a/demand-capacity-mgmt-frontend/src/components/demands/DemandAddForm.tsx b/demand-capacity-mgmt-frontend/src/components/demands/DemandAddForm.tsx new file mode 100644 index 00000000..91d031b3 --- /dev/null +++ b/demand-capacity-mgmt-frontend/src/components/demands/DemandAddForm.tsx @@ -0,0 +1,356 @@ +/* + * ******************************************************************************* + * 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, { useContext, useState, ChangeEvent, FormEvent, useCallback } from 'react'; +import { Form, Button, Row, Col } from 'react-bootstrap'; +import { DemandContext } from '../../contexts/DemandContextProvider'; +import DemandCategoryContextProvider from '../../contexts/DemandCategoryProvider'; +import DemandCategoryOptions from './DemandCategoryOptions'; +import CompanyContextProvider from '../../contexts/CompanyContextProvider'; +import CompanyOptions from '../CompanyOptions'; +import UnitsofMeasureContextContextProvider from '../../contexts/UnitsOfMeasureContextProvider'; +import UnitsOfMeasureOptions from '../UnitsofMeasureOptions'; +import { Demand } from '../../interfaces/demand_interfaces'; +import '../../App.css'; + +type AddFormProps = { + fetchDemandProps: () => void; // Function to fetch demands +}; + +const getMondaysBetweenDates = (startDate: Date, endDate: Date): string[] => { + const mondays: string[] = []; + const current = new Date(startDate); + + while (current <= endDate) { + if (current.getDay() === 1) { + // Monday has index 1 in JS (0 is Sunday, 1 is Monday, etc.) + const formattedDate = current.toISOString().slice(0, 10); + mondays.push(formattedDate); + } + + current.setDate(current.getDate() + 1); + } + + return mondays; +}; + +const useHandleSubmit = (initialFormState: Demand) => { + const { createDemand } = useContext(DemandContext)!; + const [submissionStatus, setSubmissionStatus] = useState<'idle' | 'submitting' | 'submitted'>('idle'); + + const handleSubmit = useCallback(async (formState: Demand) => { + + // Utility function to calculate the Mondays between the start and end dates + const calculateDemandSeriesValues = (startDate: Date, endDate: Date) => { + const mondays = getMondaysBetweenDates(startDate, endDate); + const values = mondays.map((monday) => ({ + calendarWeek: monday, + demand: 0, + })); + return values; + }; + + const startDateInput = document.querySelector('#startDate'); + const endDateInput = document.querySelector('#endDate'); + + if (startDateInput && endDateInput) { + const startDateObj = new Date(startDateInput.value); + const endDateObj = new Date(endDateInput.value); + + const calculatedValues = calculateDemandSeriesValues(startDateObj, endDateObj); + + // Build the materialDemandSeries object + const materialDemandSeries = { + customerLocationId: formState.customerId, + expectedSupplierLocationId: [formState.supplierId], + demandCategoryId: formState.materialDemandSeries[0].demandCategoryId, + demandSeriesValues: calculatedValues, + }; + + // Build the final demand object + const demand = { + id: formState.id, + materialDescriptionCustomer: formState.materialDescriptionCustomer, + materialNumberCustomer: formState.materialNumberCustomer, + materialNumberSupplier: formState.materialNumberSupplier, + customerId: formState.customerId, + supplierId: formState.supplierId, + unitMeasureId: formState.unitMeasureId, + materialDemandSeries: [materialDemandSeries], // Wrap materialDemandSeries in an array + }; + + try { + setSubmissionStatus('submitting'); // Set the submission status to 'submitting' while the API call is in progress + + await createDemand(demand); + setSubmissionStatus('submitted'); // Set the submission status to 'submitted' if the API call is successful + } catch (error) { + console.error('Error creating demand:', error); + setSubmissionStatus('idle'); // Set the submission status back to 'idle' if the API call fails + // Handle error if needed + } + } + }, [createDemand]); + + return { submissionStatus, handleSubmit }; +}; + +const AddForm: React.FC = ({ fetchDemandProps }) => { + const initialFormState: Demand = { + id: '', + materialDescriptionCustomer: '', + materialNumberCustomer: '', + materialNumberSupplier: '', + customerId: 'e1abe001-4e24-471f-9b66-a4b3408e3bf6', //This is my current login ID + supplierId: '', + unitMeasureId: '', + materialDemandSeries: [ + { + customerLocationId: 'e1abe001-4e24-471f-9b66-a4b3408e3bf6', //This is my current login ID + expectedSupplierLocationId: [], + demandCategoryId: '', + demandSeriesValues: [], + }, + ], + }; + + const [formState, setFormState] = useState(initialFormState); + const [showSuccessMessage, setShowSuccessMessage] = useState(false); // New state to handle the success message + const { submissionStatus, handleSubmit } = useHandleSubmit(initialFormState); + + const handleFormSubmit = async (e: FormEvent) => { + e.preventDefault(); + await handleSubmit(formState); + setShowSuccessMessage(true); + fetchDemandProps(); + }; + + const onInputChange = (e: ChangeEvent) => { + const { name, value } = e.target; + setFormState((prevFormState) => ({ + ...prevFormState, + [name]: value, + })); + }; + + const onInputChangeSelect = (e: ChangeEvent) => { + const { name, value } = e.target; + + setFormState((prevFormState) => { + if (name === 'supplierId') { + return { + ...prevFormState, + supplierId: value, + materialDemandSeries: [ + { + ...prevFormState.materialDemandSeries[0], + expectedSupplierLocationId: [value], + }, + ], + }; + } else if (name === 'demandCategoryId') { + return { + ...prevFormState, + materialDemandSeries: [ + { + ...prevFormState.materialDemandSeries[0], + demandCategoryId: value, + }, + ], + }; + } else { + return { + ...prevFormState, + [name]: value, + }; + } + }); + }; + + const getNextMonday = () => { + const today = new Date(); + const nextMonday = new Date(today); + nextMonday.setDate(today.getDate() + ((1 + 7 - today.getDay()) % 7)); + return nextMonday; + }; + + const [startDateValid, setStartDateValid] = useState(true); + const [endDateValid, setEndDateValid] = useState(true); + + const onStartDateChange = (e: ChangeEvent) => { + const selectedStartDate = new Date(e.target.value); + setStartDateValid(selectedStartDate.getDay() === 1); + setEndDateValid(true); + setFormState((prevFormState) => ({ + ...prevFormState, + [e.target.name]: e.target.value, + })); + }; + + const onEndDateChange = (e: ChangeEvent) => { + const selectedEndDate = new Date(e.target.value); + setEndDateValid(selectedEndDate.getDay() === 1 && selectedEndDate >= new Date(e.target.value)); + setFormState((prevFormState) => ({ + ...prevFormState, + [e.target.name]: e.target.value, + })); + }; + + return ( + <> + {showSuccessMessage && submissionStatus === 'submitted' ? ( +
+ Material demand has been created! + Please reach to the Overview to adjust the demand. +
+ ) : ( +
+ + + Start Date + + Please select a Monday for the Start Date. + + + End Date + + End Date has to be a Monday after Start Date. + + + + + + Unit of Measure + + + + + + + + + Supplier + + + + + + + + + Demand Category + + + + + + + + + Material Number Customer + + + + + Material Number Supplier + + + + + Description + + + + +
+ )} + + ); +}; + +export default AddForm; diff --git a/demand-capacity-mgmt-frontend/src/components/demands/DemandCategoryOptions.tsx b/demand-capacity-mgmt-frontend/src/components/demands/DemandCategoryOptions.tsx new file mode 100644 index 00000000..14f8c9e8 --- /dev/null +++ b/demand-capacity-mgmt-frontend/src/components/demands/DemandCategoryOptions.tsx @@ -0,0 +1,50 @@ +/* + * ******************************************************************************* + * 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, { useContext } from 'react'; +import { DemandCategoryContext } from '../../contexts/DemandCategoryProvider'; + +interface DemandCategoryOptionsProps { + selectedDemandCategoryId: string; +} + +const DemandCategoryOptions: React.FC = ({ selectedDemandCategoryId }) => { + const demandCategoryContextData = useContext(DemandCategoryContext); + const { demandcategories } = demandCategoryContextData || {}; + + // Use the demandcategories array to fill the