From 737f490b22bf501893fd5975aab98089714fa820 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Fri, 20 Oct 2023 17:16:57 +0100 Subject: [PATCH] Global fixes and alignements --- .../controllers/DemandController.java | 10 ++- .../controllers/FavoriteController.java | 5 +- .../controllers/LoggingHistoryController.java | 13 +++- .../entities/DemandSeries.java | 7 ++- .../entities/DemandSeriesValues.java | 8 +-- .../entities/MaterialDemandEntity.java | 11 ++-- .../services/DemandService.java | 5 +- .../services/FavoriteService.java | 2 - .../services/LoggingHistoryService.java | 8 +-- .../impl/CapacityGroupServiceImpl.java | 52 +++++----------- .../services/impl/DemandServiceImpl.java | 61 ++++++------------- .../services/impl/FavoriteServiceImpl.java | 10 +-- .../impl/LoggingHistoryServiceImpl.java | 44 +++++-------- .../src/main/resources/openapi.yml | 9 ++- 14 files changed, 95 insertions(+), 150 deletions(-) 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 ad176d2d..413d6ca7 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 @@ -24,12 +24,7 @@ import eclipse.tractusx.demand_capacity_mgmt_specification.api.DemandApi; import eclipse.tractusx.demand_capacity_mgmt_specification.model.*; -import eclipse.tractusx.demand_capacity_mgmt_specification.model.MaterialDemandRequest; -import eclipse.tractusx.demand_capacity_mgmt_specification.model.MaterialDemandResponse; -import io.swagger.v3.oas.annotations.security.SecurityRequirement; import jakarta.servlet.http.HttpServletRequest; -import java.util.List; -import java.util.List; import lombok.AllArgsConstructor; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.DemandService; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.utils.UserUtil; @@ -37,6 +32,8 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RestController; +import java.util.List; + @RestController @AllArgsConstructor public class DemandController implements DemandApi { @@ -47,7 +44,8 @@ public class DemandController implements DemandApi { @Override public ResponseEntity deleteDemandsById(String demandId) { - demandService.deleteDemandById(demandId); + String userID = UserUtil.getUserID(request); + demandService.deleteDemandById(demandId,userID); return ResponseEntity.status(HttpStatus.OK).build(); } diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/FavoriteController.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/FavoriteController.java index 68bbde6e..dec53d45 100644 --- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/FavoriteController.java +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/FavoriteController.java @@ -64,8 +64,9 @@ public ResponseEntity getFavorite() throws Exception { @Override public ResponseEntity> getFavoriteByType(String type) { - List responseList = favoriteService.getAllFavoritesByType(type,UserUtil.getUserID(request)); - return ResponseEntity.status(200).body(responseList); + //FavoriteResponse responseList = favoriteService.getAllFavoritesByType(type,UserUtil.getUserID(request)); + //return ResponseEntity.status(200).body(responseList); + return null; } @Override diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/LoggingHistoryController.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/LoggingHistoryController.java index f0882768..705a7c74 100644 --- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/LoggingHistoryController.java +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/LoggingHistoryController.java @@ -26,19 +26,24 @@ import eclipse.tractusx.demand_capacity_mgmt_specification.model.ArchivedLoggingHistoryResponse; import eclipse.tractusx.demand_capacity_mgmt_specification.model.LoggingHistoryRequest; import eclipse.tractusx.demand_capacity_mgmt_specification.model.LoggingHistoryResponse; -import java.util.List; +import jakarta.servlet.http.HttpServletRequest; import lombok.AllArgsConstructor; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.LoggingHistoryService; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.utils.UserUtil; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RestController; +import java.util.List; + @RestController @AllArgsConstructor public class LoggingHistoryController implements LoggingHistoryApi { private final LoggingHistoryService loggingHistoryService; + private HttpServletRequest request; + @Override public ResponseEntity createArchivedLog(LoggingHistoryRequest loggingHistoryRequest) { loggingHistoryService.archiveLog(loggingHistoryRequest); @@ -94,12 +99,14 @@ public ResponseEntity> getLoggingHistory() { @Override public ResponseEntity> getLoggingHistoryForFavoriteCapacityGroups() { - return ResponseEntity.status(HttpStatus.OK).body(loggingHistoryService.filterByFavoriteCapacityGroup()); + String userID = UserUtil.getUserID(request); + return ResponseEntity.status(HttpStatus.OK).body(loggingHistoryService.filterByFavoriteCapacityGroup(userID)); } @Override public ResponseEntity> getLoggingHistoryForFavoriteMaterialDemands() { - return ResponseEntity.status(HttpStatus.OK).body(loggingHistoryService.filterByFavoriteMaterialDemand()); + String userID = UserUtil.getUserID(request); + return ResponseEntity.status(HttpStatus.OK).body(loggingHistoryService.filterByFavoriteMaterialDemand(userID)); } @Override 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 027e8894..cb5397bd 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 @@ -25,11 +25,12 @@ import com.fasterxml.jackson.annotation.JsonIdentityInfo; import com.fasterxml.jackson.annotation.ObjectIdGenerators; import jakarta.persistence.*; -import java.util.List; -import java.util.UUID; import lombok.*; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.converters.ListToStringConverter; +import java.util.List; +import java.util.UUID; + @Entity @Table(name = "demand_series") @Data @@ -61,6 +62,8 @@ public class DemandSeries { @OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY) @JoinColumn(name = "demand_series_id") + @ToString.Exclude + @EqualsAndHashCode.Exclude private List demandSeriesValues; @ToString.Exclude 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 a633eab8..0557ef2a 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 @@ -23,12 +23,10 @@ package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities; import jakarta.persistence.*; +import lombok.*; + import java.time.LocalDate; import java.util.UUID; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; @Entity @Table(name = "demand_series_values") @@ -44,6 +42,8 @@ public class DemandSeriesValues { private UUID id; @ManyToOne(fetch = FetchType.LAZY) + @ToString.Exclude + @EqualsAndHashCode.Exclude 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 4916f23f..2f7bfc10 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 @@ -25,17 +25,14 @@ import com.fasterxml.jackson.annotation.JsonIdentityInfo; import com.fasterxml.jackson.annotation.ObjectIdGenerators; import jakarta.persistence.*; -import java.time.LocalDateTime; -import java.util.List; -import java.util.UUID; import lombok.*; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.EventType; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.MaterialDemandStatus; +import java.time.LocalDateTime; +import java.util.List; +import java.util.UUID; + @Entity @Cacheable(false) @Table(name = "material_demand") 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 29a61868..c3fa703b 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 @@ -23,10 +23,11 @@ package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services; import eclipse.tractusx.demand_capacity_mgmt_specification.model.*; -import java.util.List; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.MaterialDemandEntity; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.MaterialDemandStatus; +import java.util.List; + public interface DemandService { MaterialDemandResponse createDemand(MaterialDemandRequest materialDemandRequest, String userID); @@ -37,7 +38,7 @@ public interface DemandService { MaterialDemandResponse updateDemand(String demandId, MaterialDemandRequest materialDemandRequest, String userID); - void deleteDemandById(String demandId); + void deleteDemandById(String demandId,String userID); List getAllByStatus(MaterialDemandStatus status); diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/FavoriteService.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/FavoriteService.java index d391cbaa..c864a2be 100644 --- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/FavoriteService.java +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/FavoriteService.java @@ -25,12 +25,10 @@ import eclipse.tractusx.demand_capacity_mgmt_specification.model.FavoriteRequest; import eclipse.tractusx.demand_capacity_mgmt_specification.model.FavoriteResponse; -import java.util.List; import java.util.UUID; public interface FavoriteService { FavoriteResponse getAllFavorites(String userID); - List getAllFavoritesByType(String type,String userID); FavoriteResponse createFavorite(FavoriteRequest favoriteRequest, String userID); FavoriteResponse updateFavorite(Integer id, FavoriteRequest favoriteRequest, String userID); void deleteFavorite(UUID id, String cookieUserID); diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/LoggingHistoryService.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/LoggingHistoryService.java index dc72c772..c5600da0 100644 --- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/LoggingHistoryService.java +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/LoggingHistoryService.java @@ -23,10 +23,8 @@ package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services; import eclipse.tractusx.demand_capacity_mgmt_specification.model.*; -import java.sql.Timestamp; + import java.util.List; -import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.EventStatus; -import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.EventType; public interface LoggingHistoryService { List getAllLoggingHistory(); @@ -37,8 +35,8 @@ public interface LoggingHistoryService { List getAllArchivedLogs(); void deleteAllArchivedLogs(); void deleteArchivedLogById(String logId); - List filterByFavoriteMaterialDemand(); - List filterByFavoriteCapacityGroup(); + List filterByFavoriteMaterialDemand(String userID); + List filterByFavoriteCapacityGroup(String userID); List filterLog( 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 cb5624cb..04ccea83 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 @@ -41,19 +41,7 @@ import java.util.List; import java.util.Optional; import java.util.UUID; - import java.util.concurrent.atomic.AtomicBoolean; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.*; -import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.EventObjectType; -import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.EventType; -import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.FavoriteType; -import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.exceptions.type.NotFoundException; -import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories.*; -import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.*; -import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.utils.UUIDUtil; -import org.springframework.stereotype.Service; @RequiredArgsConstructor @Service @@ -82,7 +70,7 @@ public CapacityGroupResponse createCapacityGroup(CapacityGroupRequest capacityGr capacityGroupEntity.setLinkStatus(eventType); capacityGroupEntity = capacityGroupRepository.save(capacityGroupEntity); String cgID = capacityGroupEntity.getId().toString(); - postLogs(cgID); + postLogs(cgID,userID); for (UUID uuid : capacityGroupRequest.getLinkMaterialDemandIds()) { LinkedCapacityGroupMaterialDemandEntity entity = new LinkedCapacityGroupMaterialDemandEntity(); entity.setCapacityGroupID(capacityGroupEntity.getId()); @@ -113,24 +101,15 @@ public EventType updateStatus(String userId,boolean isMaterialDemand) { return null; } - private void postLogs(String capacityGroupId) { - /*AtomicBoolean isFavorited = new AtomicBoolean(false); - favoriteService - .getAllFavoritesByType(FavoriteType.CAPACITY_GROUP.toString()) - .forEach( - favoriteResponse -> { - Optional found = Optional.empty(); - for (SingleCapacityGroup cg : favoriteResponse.getCapacityGroups()) { - if (cg.getCapacityGroupId().equals(capacityGroupId)) { - found = Optional.of(cg); - break; - } - } - if (found.isPresent()) { - isFavorited.set(true); - } - } - ); + private void postLogs(String capacityGroupId,String userID) { + AtomicBoolean isFavorited = new AtomicBoolean(false); + FavoriteResponse favoriteResponse = favoriteService.getAllFavorites(userID); + for(SingleCapacityGroupFavoriteResponse singleCapacityGroupFavoriteResponse : favoriteResponse.getCapacityGroups()){ + if(singleCapacityGroupFavoriteResponse.getId().equals(capacityGroupId)){ + isFavorited.set(true); + break; + } + } LoggingHistoryRequest loggingHistoryRequest = new LoggingHistoryRequest(); loggingHistoryRequest.setObjectType(EventObjectType.CAPACITY_GROUP.name()); loggingHistoryRequest.setMaterialDemandId(""); @@ -138,8 +117,7 @@ private void postLogs(String capacityGroupId) { loggingHistoryRequest.setEventDescription("Capacity Group created"); loggingHistoryRequest.setIsFavorited(isFavorited.get()); loggingHistoryRequest.setEventType(EventType.GENERAL_EVENT.toString()); - loggingHistoryService.createLog(loggingHistoryRequest); */ - //TODO FIX THIS + loggingHistoryService.createLog(loggingHistoryRequest); } @Override @@ -151,7 +129,7 @@ public void linkCapacityGroupToMaterialDemand(LinkCGDSRequest linkCGDSRequest, S List materialDemandEntities = new ArrayList<>(); - for (UUID uuid : linkCGDSRequest.getLinkedMaterialDemandID()) { + for (UUID uuid : linkCGDSRequest.getLinkMaterialDemandIds()) { Optional materialDemandEntity = materialDemandRepository.findById(uuid); if (materialDemandEntity.isPresent()) { MaterialDemandEntity materialDemand = materialDemandEntity.get(); @@ -189,7 +167,7 @@ public void linkCapacityGroupToMaterialDemand(LinkCGDSRequest linkCGDSRequest, S newCapacityGroups = capacityGroupRepository.findAll(); EventType eventType = updateStatus(userID,true); - for (UUID uuid : linkCGDSRequest.getLinkedMaterialDemandID()) { + for (UUID uuid : linkCGDSRequest.getLinkMaterialDemandIds()) { Optional materialDemandEntity = materialDemandRepository.findById(uuid); materialDemandEntity.ifPresent(demandEntity -> { demandEntity.setLinkStatus(eventType); @@ -319,7 +297,9 @@ private List convertCapacityGroupEntity( response.setNumberOfMaterials( linkedCapacityGroupMaterialDemandRepository.countByCapacityGroupID(entity.getId()) ); - response.setLinkStatus(entity.getLinkStatus().toString()); + if(entity.getLinkStatus()!=null) { + response.setLinkStatus(entity.getLinkStatus().toString()); + } capacityGroupList.add(response); } return capacityGroupList; 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 82104bf7..53965b70 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,28 +23,12 @@ package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.impl; import eclipse.tractusx.demand_capacity_mgmt_specification.model.*; - - -import jakarta.persistence.EntityManager; -import jakarta.persistence.EntityManagerFactory; -import jakarta.persistence.Persistence; -import java.math.BigDecimal; -import java.time.LocalDate; -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.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; - import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.*; -import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.EventType; -import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.MaterialDemandStatus; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.Role; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.*; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.exceptions.type.BadRequestException; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.exceptions.type.NotFoundException; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories.*; @@ -61,6 +45,7 @@ import java.util.List; import java.util.Optional; import java.util.UUID; +import java.util.concurrent.atomic.AtomicBoolean; @RequiredArgsConstructor @Service @@ -98,7 +83,7 @@ public MaterialDemandResponse createDemand(MaterialDemandRequest materialDemandR EventType eventType = updateStatus(oldMaterialDemands, oldMaterialDemands, userID); materialDemandEntity.setLinkStatus(eventType); materialDemandEntity = materialDemandRepository.save(materialDemandEntity); - postLogs(materialDemandEntity.getId().toString(), "Material Demand created", eventType); + postLogs(materialDemandEntity.getId().toString(), "Material Demand created", eventType,userID); return convertDemandResponseDto(materialDemandEntity); } @@ -126,36 +111,22 @@ public EventType updateStatus( return null; } - private void postLogs(String materialDemandId, String eventDescription, EventType eventType) { - /*AtomicBoolean isFavorited = new AtomicBoolean(false); - favoriteService - .getAllFavoritesByType(FavoriteType.MATERIAL_DEMAND.toString()) - .forEach( - favoriteResponse -> { - Optional found = Optional.empty(); - for (MaterialDemandResponse mt : favoriteResponse.getMaterialDemands()) { - if (mt.getId().equals(materialDemandId)) { - found = Optional.of(mt); - break; - } - } - if (found.isPresent()) { - isFavorited.set(true); - } - } - ); + private void postLogs(String materialDemandId, String eventDescription, EventType eventType,String userID) { + AtomicBoolean isFavorited = new AtomicBoolean(false); + FavoriteResponse favoriteResponse = favoriteService.getAllFavorites(userID); + for(MaterialDemandFavoriteResponse materialDemandFavoriteResponse : favoriteResponse.getMaterialDemands()){ + if(materialDemandFavoriteResponse.getId().equals(materialDemandId)){ + isFavorited.set(true); + break; + } + } LoggingHistoryRequest loggingHistoryRequest = new LoggingHistoryRequest(); loggingHistoryRequest.setObjectType(EventObjectType.MATERIAL_DEMAND.name()); loggingHistoryRequest.setMaterialDemandId(materialDemandId); loggingHistoryRequest.setIsFavorited(isFavorited.get()); loggingHistoryRequest.setEventDescription(eventDescription); - - // TODO : Add EventType loggingHistoryRequest.setEventType(eventType.toString()); - loggingHistoryService.createLog(loggingHistoryRequest); - */ - //TODO FIX THIS } @Override @@ -199,7 +170,7 @@ public MaterialDemandResponse updateDemand( EventType eventType = updateStatus(newMaterialDemands, oldMaterialDemands, userID); demand.setLinkStatus(eventType); demand = materialDemandRepository.save(demand); - postLogs(demandId, "MATERIAL DEMAND Updated", EventType.GENERAL_EVENT); + postLogs(demandId, "MATERIAL DEMAND Updated", EventType.GENERAL_EVENT,userID); return convertDemandResponseDto(demand); } @@ -208,9 +179,9 @@ private List getAllDemands() { } @Override - public void deleteDemandById(String demandId) { + public void deleteDemandById(String demandId,String userID) { MaterialDemandEntity demand = getDemandEntity(demandId); - postLogs(demandId, "Material Demand deleted", EventType.GENERAL_EVENT); + postLogs(demandId, "Material Demand deleted", EventType.GENERAL_EVENT,userID); materialDemandRepository.delete(demand); } @@ -327,6 +298,7 @@ private MaterialDemandResponse convertDemandResponseDto(MaterialDemandEntity mat responseDto.setCustomer(customer); responseDto.setSupplier(supplier); + if(materialDemandEntity.getLinkStatus() != null){ if((materialDemandEntity.getLinkStatus().equals(EventType.TODO) || (materialDemandEntity.getLinkStatus().equals(EventType.UN_LINKED)) && user.getRole().equals(Role.CUSTOMER))){ responseDto.setLinkStatus(String.valueOf(EventType.UN_LINKED)); @@ -336,6 +308,7 @@ private MaterialDemandResponse convertDemandResponseDto(MaterialDemandEntity mat }else { responseDto.setLinkStatus(String.valueOf(materialDemandEntity.getLinkStatus())); } + } responseDto.setChangedAt(materialDemandEntity.getChangedAt().toString()); responseDto.setId(materialDemandEntity.getId().toString()); diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/FavoriteServiceImpl.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/FavoriteServiceImpl.java index 2ed3f6cd..8de3eb9a 100644 --- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/FavoriteServiceImpl.java +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/FavoriteServiceImpl.java @@ -88,6 +88,7 @@ private SingleCapacityGroupFavoriteResponse convertToSingleCapacityGroup(Favorit if(cgEntity.isPresent()){ CapacityGroupEntity capacityGroup = cgEntity.get(); SingleCapacityGroupFavoriteResponse scgfv = new SingleCapacityGroupFavoriteResponse(); + scgfv.setId(capacityGroup.getId().toString()); scgfv.setCapacityGroupId(capacityGroup.getId().toString()); scgfv.setCapacityGroupName(capacityGroup.getCapacityGroupName()); scgfv.setCustomer(capacityGroup.getCustomer().getBpn()); @@ -102,6 +103,7 @@ private MaterialDemandFavoriteResponse convertToMaterialDemandResponse(FavoriteE MaterialDemandEntity materialDemand = materialDemandEntity.get(); MaterialDemandFavoriteResponse response = new MaterialDemandFavoriteResponse(); + response.setId(materialDemand.getId().toString()); response.setCustomer(materialDemand.getCustomerId().toString()); response.setSupplier(materialDemand.getSupplierId().toString()); response.setMaterialNumberCustomer(materialDemand.getMaterialNumberCustomer()); @@ -119,6 +121,7 @@ private CompanyDtoFavoriteResponse convertToCompanyDto(FavoriteEntity entity) { CompanyEntity companyEntity = cEntity.get(); CompanyDtoFavoriteResponse companyFavoriteResponse = new CompanyDtoFavoriteResponse(); + companyFavoriteResponse.setId(companyEntity.getId().toString()); companyFavoriteResponse.setBpn(companyEntity.getBpn()); companyFavoriteResponse.setMyCompany(companyEntity.getMyCompany()); companyFavoriteResponse.setCompanyName(companyEntity.getCompanyName()); @@ -129,13 +132,6 @@ private CompanyDtoFavoriteResponse convertToCompanyDto(FavoriteEntity entity) { } else return null; } - @Override - public List getAllFavoritesByType(String type, String userID) { - List favoriteEntities = favoriteRepository.findByType(FavoriteType.valueOf(type)); - //return favoriteEntities.stream().map(this::convertFavoriteResponse).toList(); - return null; - } - @Override public FavoriteResponse createFavorite(FavoriteRequest favoriteRequest, String cookieUserID) { FavoriteEntity entity = favoriteRepository.save(generateFavoriteEntity(favoriteRequest, cookieUserID)); diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/LoggingHistoryServiceImpl.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/LoggingHistoryServiceImpl.java index b06b7f7a..26acb57d 100644 --- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/LoggingHistoryServiceImpl.java +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/LoggingHistoryServiceImpl.java @@ -22,9 +22,7 @@ package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.impl; -import eclipse.tractusx.demand_capacity_mgmt_specification.model.ArchivedLoggingHistoryResponse; -import eclipse.tractusx.demand_capacity_mgmt_specification.model.LoggingHistoryRequest; -import eclipse.tractusx.demand_capacity_mgmt_specification.model.LoggingHistoryResponse; +import eclipse.tractusx.demand_capacity_mgmt_specification.model.*; import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -242,38 +240,28 @@ public List getLogsManagedByMe() { } @Override - public List filterByFavoriteMaterialDemand() { - /* + public List filterByFavoriteMaterialDemand(String userID) { List loggingHistoryResponses = new java.util.ArrayList<>(List.of()); - List favoriteResponses = favoriteService.getAllFavoritesByType( - FavoriteType.MATERIAL_DEMAND.toString() - ); + FavoriteResponse favoriteResponses = favoriteService.getAllFavorites(userID); + + for(MaterialDemandFavoriteResponse materialDemandFavoriteResponse : favoriteResponses.getMaterialDemands()){ + loggingHistoryResponses.addAll(getLoggingHistoryByMaterialDemandId(materialDemandFavoriteResponse.getId())); + } - favoriteResponses.forEach( - favoriteResponse -> { - loggingHistoryResponses.addAll(getLoggingHistoryByMaterialDemandId(favoriteResponse.getfTypeId())); - } - ); return loggingHistoryResponses; - */ - //TODO FIX THIS - return new ArrayList<>(); } @Override - public List filterByFavoriteCapacityGroup() { - /*List loggingHistoryResponses = new java.util.ArrayList<>(List.of()); - List favoriteResponses = favoriteService.getAllFavoritesByType( - FavoriteType.CAPACITY_GROUP.toString() - ); - - //or(SingleCapacityGroup scg : favoriteResponses) - //return loggingHistoryResponses; - //TODO FIX THIS - - */ - return new ArrayList<>(); + public List filterByFavoriteCapacityGroup(String userID) { + List loggingHistoryResponses = new java.util.ArrayList<>(List.of()); + FavoriteResponse favoriteResponses = favoriteService.getAllFavorites(userID); + + for(SingleCapacityGroupFavoriteResponse singleCapacityGroupFavoriteResponse : favoriteResponses.getCapacityGroups()){ + loggingHistoryResponses.addAll(getLoggingHistoryByCapacityId(singleCapacityGroupFavoriteResponse.getId())); + } + + return loggingHistoryResponses; } diff --git a/demand-capacity-mgmt-specification/src/main/resources/openapi.yml b/demand-capacity-mgmt-specification/src/main/resources/openapi.yml index 92e42524..6031fdaa 100644 --- a/demand-capacity-mgmt-specification/src/main/resources/openapi.yml +++ b/demand-capacity-mgmt-specification/src/main/resources/openapi.yml @@ -1460,6 +1460,8 @@ components: CompanyDtoFavoriteResponse: type: object properties: + id: + type: string bpn: type: string companyName: @@ -1474,6 +1476,8 @@ components: MaterialDemandFavoriteResponse: type: object properties: + id: + type: string materialDescriptionCustomer: type: string materialNumberCustomer: @@ -1492,6 +1496,8 @@ components: SingleCapacityGroupFavoriteResponse: type: object properties: + id: + type: string customer: type: string supplier: @@ -1686,8 +1692,7 @@ components: properties: capacityGroupID: type: string - - linkedMaterialDemandID: + linkMaterialDemandIds: type: array items: type: string