Skip to content

Commit

Permalink
Global fixes and alignements
Browse files Browse the repository at this point in the history
  • Loading branch information
OSousa117 committed Oct 20, 2023
1 parent 50e53a4 commit 737f490
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,16 @@

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;
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 DemandController implements DemandApi {
Expand All @@ -47,7 +44,8 @@ public class DemandController implements DemandApi {

@Override
public ResponseEntity<Void> deleteDemandsById(String demandId) {
demandService.deleteDemandById(demandId);
String userID = UserUtil.getUserID(request);
demandService.deleteDemandById(demandId,userID);
return ResponseEntity.status(HttpStatus.OK).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ public ResponseEntity<FavoriteResponse> getFavorite() throws Exception {

@Override
public ResponseEntity<List<FavoriteResponse>> getFavoriteByType(String type) {
List<FavoriteResponse> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Void> createArchivedLog(LoggingHistoryRequest loggingHistoryRequest) {
loggingHistoryService.archiveLog(loggingHistoryRequest);
Expand Down Expand Up @@ -94,12 +99,14 @@ public ResponseEntity<List<LoggingHistoryResponse>> getLoggingHistory() {

@Override
public ResponseEntity<List<LoggingHistoryResponse>> 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<List<LoggingHistoryResponse>> getLoggingHistoryForFavoriteMaterialDemands() {
return ResponseEntity.status(HttpStatus.OK).body(loggingHistoryService.filterByFavoriteMaterialDemand());
String userID = UserUtil.getUserID(request);
return ResponseEntity.status(HttpStatus.OK).body(loggingHistoryService.filterByFavoriteMaterialDemand(userID));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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> demandSeriesValues;

@ToString.Exclude
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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<MaterialDemandEntity> getAllByStatus(MaterialDemandStatus status);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<FavoriteResponse> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<LoggingHistoryResponse> getAllLoggingHistory();
Expand All @@ -37,8 +35,8 @@ public interface LoggingHistoryService {
List<ArchivedLoggingHistoryResponse> getAllArchivedLogs();
void deleteAllArchivedLogs();
void deleteArchivedLogById(String logId);
List<LoggingHistoryResponse> filterByFavoriteMaterialDemand();
List<LoggingHistoryResponse> filterByFavoriteCapacityGroup();
List<LoggingHistoryResponse> filterByFavoriteMaterialDemand(String userID);
List<LoggingHistoryResponse> filterByFavoriteCapacityGroup(String userID);

List<LoggingHistoryResponse> filterLog(
String capacityGroupId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -113,33 +101,23 @@ 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<SingleCapacityGroup> 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("");
loggingHistoryRequest.setCapacityGroupId(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
Expand All @@ -151,7 +129,7 @@ public void linkCapacityGroupToMaterialDemand(LinkCGDSRequest linkCGDSRequest, S

List<MaterialDemandEntity> materialDemandEntities = new ArrayList<>();

for (UUID uuid : linkCGDSRequest.getLinkedMaterialDemandID()) {
for (UUID uuid : linkCGDSRequest.getLinkMaterialDemandIds()) {
Optional<MaterialDemandEntity> materialDemandEntity = materialDemandRepository.findById(uuid);
if (materialDemandEntity.isPresent()) {
MaterialDemandEntity materialDemand = materialDemandEntity.get();
Expand Down Expand Up @@ -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> materialDemandEntity = materialDemandRepository.findById(uuid);
materialDemandEntity.ifPresent(demandEntity -> {
demandEntity.setLinkStatus(eventType);
Expand Down Expand Up @@ -319,7 +297,9 @@ private List<CapacityGroupDefaultViewResponse> 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;
Expand Down
Loading

0 comments on commit 737f490

Please sign in to comment.