diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/AlertController.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/AlertController.java new file mode 100644 index 00000000..3080c226 --- /dev/null +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/AlertController.java @@ -0,0 +1,67 @@ +/* + * ****************************************************************************** + * Copyright (c) 2023 BMW AG + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ******************************************************************************* + */ +package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.controllers; + +import eclipse.tractusx.demand_capacity_mgmt_specification.api.AlertsApi; +import eclipse.tractusx.demand_capacity_mgmt_specification.model.*; +import jakarta.servlet.http.HttpServletRequest; +import java.util.List; +import lombok.AllArgsConstructor; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.AlertService; +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; + +@RestController +@AllArgsConstructor +//@RequestMapping("/alerts") +public class AlertController implements AlertsApi { + + private HttpServletRequest request; + private final AlertService alertService; + + @Override + public ResponseEntity configureAlert(AlertRequest alertRequest) throws Exception { + AlertResponse responseDto = alertService.configureAlert(alertRequest); + return ResponseEntity.status(HttpStatus.CREATED).body(responseDto); + } + + @Override + public ResponseEntity configureTriggeredAlert(TriggeredAlertRequest triggeredAlertRequest) + throws Exception { + TriggeredAlertResponse responseDto = alertService.postTriggeredAlerts(triggeredAlertRequest); + return ResponseEntity.status(HttpStatus.CREATED).body(responseDto); + } + + @Override + public ResponseEntity> getAlerts() throws Exception { + String userID = UserUtil.getUserID(request); + return ResponseEntity.status(HttpStatus.OK).body(alertService.getAlerts(userID)); + } + + @Override + public ResponseEntity> getTriggeredAlerts() throws Exception { + String userID = UserUtil.getUserID(request); + return ResponseEntity.status(HttpStatus.OK).body(alertService.getTriggeredAlerts(userID)); // + } +} diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/AlertEntity.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/AlertEntity.java new file mode 100644 index 00000000..6af4f346 --- /dev/null +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/AlertEntity.java @@ -0,0 +1,51 @@ +package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities; + +import jakarta.persistence.*; +import java.util.List; +import java.util.UUID; +import lombok.*; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.AlertThresholdType; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.AlertsMonitoredObjects; + +@Entity +@Table(name = "alerts") +@Builder +@Data +@NoArgsConstructor +@AllArgsConstructor +public class AlertEntity { + + @Id + @GeneratedValue + @Column(columnDefinition = "uuid", updatable = false, name = "id") + private UUID id; + + @Column(name = "user_id") + private UUID userID; + + @Column(name = "alert_name") + private String alertName; + + @Column(name = "monitored_objects") + @Enumerated(EnumType.STRING) + private AlertsMonitoredObjects monitoredObjects; + + @Column(name = "created") + private String created; + + @Column(name = "type") + @Enumerated(EnumType.STRING) + private AlertThresholdType type; + + @Column(name = "threshold") + private double threshold; + + @Column(name = "description") + private String description; + + @ToString.Exclude + @EqualsAndHashCode.Exclude + @OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY) + @JoinColumn(name = "alert_id") + private List dedicatedAlerts; +} diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/DedicatedAlertEntity.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/DedicatedAlertEntity.java new file mode 100644 index 00000000..98f933fd --- /dev/null +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/DedicatedAlertEntity.java @@ -0,0 +1,33 @@ +package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities; + +import jakarta.persistence.*; +import java.util.List; +import java.util.UUID; +import lombok.*; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.EventObjectType; + +@Entity +@Table(name = "dedicated_alerts") +@Builder +@Data +@NoArgsConstructor +@AllArgsConstructor +public class DedicatedAlertEntity { + + @Id + @GeneratedValue + @Column(columnDefinition = "uuid", updatable = false, name = "id") + private UUID id; + + @Column(name = "object_id") + private UUID objectId; + + @Column(name = "type") + @Enumerated(EnumType.STRING) + private EventObjectType type; + + @ManyToOne(fetch = FetchType.LAZY) + @ToString.Exclude + @EqualsAndHashCode.Exclude + private AlertEntity alertEntity; +} 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 2f7bfc10..a54cb04f 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,13 +25,12 @@ import com.fasterxml.jackson.annotation.JsonIdentityInfo; import com.fasterxml.jackson.annotation.ObjectIdGenerators; import jakarta.persistence.*; -import lombok.*; -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; +import lombok.*; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.EventType; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.MaterialDemandStatus; @Entity @Cacheable(false) diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/TriggeredAlertEntity.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/TriggeredAlertEntity.java new file mode 100644 index 00000000..ccbfafca --- /dev/null +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/TriggeredAlertEntity.java @@ -0,0 +1,52 @@ +package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities; + +import jakarta.persistence.*; +import java.util.UUID; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.AlertThresholdType; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.AlertsMonitoredObjects; + +@Entity +@Table(name = "triggered_alerts") +@Builder +@Data +@NoArgsConstructor +@AllArgsConstructor +public class TriggeredAlertEntity { + + @Id + @Column(name = "id") + private UUID id; + + @Column(name = "user_id") + private UUID userID; + + @Column(name = "alert_name") + private String alertName; + + @Column(name = "monitored_objects") + @Enumerated(EnumType.STRING) + private AlertsMonitoredObjects monitoredObjects; + + @Column(name = "created") + private String created; + + @Column(name = "trigger_times") + private int triggerTimes; + + @Column(name = "trigger_times_in_three_months") + private int triggerTimesInThreeMonths; + + @Column(name = "type") + @Enumerated(EnumType.STRING) + private AlertThresholdType type; + + @Column(name = "threshold") + private double threshold; + + @Column(name = "description") + private String description; +} diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/enums/AlertThresholdType.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/enums/AlertThresholdType.java new file mode 100644 index 00000000..2fa6d896 --- /dev/null +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/enums/AlertThresholdType.java @@ -0,0 +1,6 @@ +package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums; + +public enum AlertThresholdType { + ABSOLUTE, + RELATIVE, +} diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/enums/AlertsMonitoredObjects.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/enums/AlertsMonitoredObjects.java new file mode 100644 index 00000000..ccc83fa0 --- /dev/null +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/enums/AlertsMonitoredObjects.java @@ -0,0 +1,8 @@ +package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums; + +public enum AlertsMonitoredObjects { + ALL_DEMANDS, + ALL_CAPACITIES, + ALL_OBJECTS, + DEDICATED, +} diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/repositories/AlertsRepository.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/repositories/AlertsRepository.java new file mode 100644 index 00000000..066b46ac --- /dev/null +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/repositories/AlertsRepository.java @@ -0,0 +1,36 @@ +/* + * ******************************************************************************* + * Copyright (c) 2023 BMW AG + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ******************************************************************************** + */ + +package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories; + +import java.util.List; +import java.util.Optional; +import java.util.UUID; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.AlertEntity; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.StatusesEntity; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface AlertsRepository extends JpaRepository { + Optional findByUserID(UUID userID); + List findAllByUserID(UUID userID); + void deleteByUserID(UUID userID); +} 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 437dc8db..375a7b3a 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 @@ -23,19 +23,19 @@ package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories; import jakarta.persistence.Cacheable; +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; -import java.util.List; -import java.util.UUID; - @Repository @Cacheable(false) public interface MaterialDemandRepository extends JpaRepository { List findBySupplierId_Id(UUID id); + @Query("select m from MaterialDemandEntity m where m.customerId.id = ?1") List findByCustomerId_Id(UUID id); diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/repositories/TriggeredAlertsRepository.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/repositories/TriggeredAlertsRepository.java new file mode 100644 index 00000000..2172f097 --- /dev/null +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/repositories/TriggeredAlertsRepository.java @@ -0,0 +1,33 @@ +/* + * ******************************************************************************* + * Copyright (c) 2023 BMW AG + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ******************************************************************************** + */ + +package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories; + +import java.util.List; +import java.util.Optional; +import java.util.UUID; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.AlertEntity; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.StatusesEntity; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.TriggeredAlertEntity; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface TriggeredAlertsRepository extends JpaRepository {} diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/AlertService.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/AlertService.java new file mode 100644 index 00000000..40cf9395 --- /dev/null +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/AlertService.java @@ -0,0 +1,41 @@ +/* + * ******************************************************************************* + * Copyright (c) 2023 BMW AG + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ******************************************************************************** + */ + +package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services; + +import eclipse.tractusx.demand_capacity_mgmt_specification.model.*; +import java.util.List; +import java.util.concurrent.atomic.AtomicReference; + +public interface AlertService { + AlertResponse configureAlert(AlertRequest alertRequest); + void triggerDemandAlertsIfNeeded( + String userID, + boolean isMaterialDemandChange, + double oldDemandValue, + double newDemandValue, + String materialDemandId + ); + List getAlerts(String userID); + List getTriggeredAlerts(String userID); + TriggeredAlertResponse postTriggeredAlerts(TriggeredAlertRequest triggeredAlertRequest); +} diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/AlertServiceImpl.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/AlertServiceImpl.java new file mode 100644 index 00000000..bb3903bb --- /dev/null +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/AlertServiceImpl.java @@ -0,0 +1,259 @@ +/* + * ****************************************************************************** + * Copyright (c) 2023 BMW AG + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ******************************************************************************* + */ +package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.impl; + +import eclipse.tractusx.demand_capacity_mgmt_specification.model.*; +import java.sql.Timestamp; +import java.time.LocalDateTime; +import java.util.List; +import java.util.Objects; +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.*; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.AlertThresholdType; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.AlertsMonitoredObjects; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.EventObjectType; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories.AlertsRepository; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.repositories.TriggeredAlertsRepository; +import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.AlertService; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Service; + +@Lazy +@RequiredArgsConstructor +@Service +@Slf4j +public class AlertServiceImpl implements AlertService { + + private final AlertsRepository alertsRepository; + private final TriggeredAlertsRepository triggeredAlertsRepository; + + @Override + public AlertResponse configureAlert(AlertRequest alertRequest) { + AlertEntity alertEntity = convertDtoToEntity(alertRequest); + alertsRepository.save(alertEntity); + return convertAlertsResponseDto(alertEntity); + } + + @Override + public void triggerDemandAlertsIfNeeded( + String userID, + boolean isMaterialDemandChange, + double oldValue, + double newValue, + String materialDemandId + ) { + List alerts = alertsRepository.findAll(); // TODO : only bring my alerts + alerts.forEach( + alertEntity -> { + TriggeredAlertEntity triggeredAlertEntity = new TriggeredAlertEntity(); + triggeredAlertEntity.setId(UUID.randomUUID()); + triggeredAlertEntity.setAlertName(alertEntity.getAlertName()); + triggeredAlertEntity.setDescription(alertEntity.getDescription()); + triggeredAlertEntity.setType(alertEntity.getType()); + triggeredAlertEntity.setUserID(alertEntity.getUserID()); + triggeredAlertEntity.setMonitoredObjects(alertEntity.getMonitoredObjects()); + triggeredAlertEntity.setThreshold(alertEntity.getThreshold()); + LocalDateTime currentLocalDateTime = LocalDateTime.now(); + triggeredAlertEntity.setCreated(Timestamp.valueOf(currentLocalDateTime).toString()); + // TODO : Adjust trigger times + if (isGlobalAlert(isMaterialDemandChange, alertEntity)) { + if (alertEntity.getType().equals(AlertThresholdType.RELATIVE)) { + double threshold = alertEntity.getThreshold(); + double demandDelta = threshold * oldValue; + if ( + threshold >= 0 && + (newValue - oldValue >= demandDelta) || + (threshold < 0 && (newValue - oldValue <= demandDelta)) + ) { + // TODO : adjust the demand description , trigger times here + triggeredAlertsRepository.save(triggeredAlertEntity); + } + } + } else if (alertEntity.getMonitoredObjects().equals(AlertsMonitoredObjects.DEDICATED)) { + alertEntity + .getDedicatedAlerts() + .forEach( + dedicatedAlert -> { + if (Objects.equals(materialDemandId, dedicatedAlert.getObjectId().toString())) { + if (alertEntity.getType().equals(AlertThresholdType.ABSOLUTE)) { + double threshold = alertEntity.getThreshold(); + if ( + threshold >= 0 && + (newValue - oldValue >= threshold) || + (threshold < 0 && (newValue - oldValue <= threshold)) + ) { + // TODO : adjust the demand description , trigger times here + triggeredAlertsRepository.save(triggeredAlertEntity); + } + } else { + double threshold = alertEntity.getThreshold(); + double demandDelta = alertEntity.getThreshold() * oldValue; + if ( + threshold >= 0 && + (newValue - oldValue >= demandDelta) || + (threshold < 0 && (newValue - oldValue <= demandDelta)) + ) { + // TODO : adjust the demand description , trigger times here + triggeredAlertsRepository.save(triggeredAlertEntity); + } + } + } + } + ); + } + } + ); + } + + private static boolean isGlobalAlert(boolean isMaterialDemandChange, AlertEntity alertEntity) { + return ( + alertEntity.getMonitoredObjects().equals(AlertsMonitoredObjects.ALL_DEMANDS) || + ( + alertEntity.getMonitoredObjects().equals(AlertsMonitoredObjects.ALL_CAPACITIES) && + !isMaterialDemandChange + ) || + alertEntity.getMonitoredObjects().equals(AlertsMonitoredObjects.ALL_OBJECTS) + ); + } + + @Override + public List getAlerts(String userID) { + List alerts = alertsRepository.findAll(); + + getAlertByUserId(userID, alerts); + return alerts.stream().map(this::convertAlertsResponseDto).toList(); + } + + private static void getTriggeredAlertByUserId(String userID, List alerts) { + alerts + .stream() + .filter( + alertEntity -> { + if (alertEntity.getUserID().toString().equals(userID)) { + alerts.add(alertEntity); + } + return false; + } + ); + } + + private static void getAlertByUserId(String userID, List alerts) { + alerts + .stream() + .filter( + alertEntity -> { + if (alertEntity.getUserID().toString().equals(userID)) { + alerts.add(alertEntity); + } + return false; + } + ); + } + + @Override + public List getTriggeredAlerts(String userID) { + List alerts = triggeredAlertsRepository.findAll(); + + getTriggeredAlertByUserId(userID, alerts); + return alerts.stream().map(this::convertTriggeredAlertsResponseDto).toList(); + } + + @Override + public TriggeredAlertResponse postTriggeredAlerts(TriggeredAlertRequest triggeredAlertRequest) { + return null; + } + + private AlertResponse convertAlertsResponseDto(AlertEntity alertEntity) { + List dedicatedAlerts = alertEntity + .getDedicatedAlerts() + .stream() + .map(this::enrichDedicateAlertResponse) + .toList(); + + AlertResponse responseDto = new AlertResponse(); + responseDto.setType(alertEntity.getType().name()); + responseDto.setAlertId("" + alertEntity.getId()); + responseDto.setAlertName(alertEntity.getAlertName()); + responseDto.setCreated(alertEntity.getCreated()); + responseDto.setDescription(alertEntity.getDescription()); + responseDto.setMonitoredObjects(alertEntity.getMonitoredObjects().name()); + responseDto.setThreshold(String.valueOf(alertEntity.getThreshold())); + responseDto.setUser(alertEntity.getUserID().toString()); + responseDto.setDedicatedAlerts(dedicatedAlerts); + return responseDto; + } + + DedicatedAlert enrichDedicateAlertResponse(DedicatedAlertEntity alertEntity) { + DedicatedAlert dedicatedAlert = new DedicatedAlert(); + dedicatedAlert.setId(alertEntity.getId().toString()); + dedicatedAlert.setType(alertEntity.getType().toString()); + dedicatedAlert.setObjectId(alertEntity.getObjectId().toString()); + return dedicatedAlert; + } + + private TriggeredAlertResponse convertTriggeredAlertsResponseDto(TriggeredAlertEntity alertEntity) { + //TODO: Set triggerTimes + TriggeredAlertResponse responseDto = new TriggeredAlertResponse(); + responseDto.setType(alertEntity.getType().name()); + responseDto.setAlertId("" + alertEntity.getId()); + responseDto.setAlertName(alertEntity.getAlertName()); + responseDto.setCreated(alertEntity.getCreated()); + responseDto.setDescription(alertEntity.getDescription()); + responseDto.setMonitoredObjects(alertEntity.getMonitoredObjects().name()); + responseDto.setThreshold(String.valueOf(alertEntity.getThreshold())); + responseDto.setUser(alertEntity.getUserID().toString()); + return responseDto; + } + + DedicatedAlertEntity convertDedicatedAlertsDtoToEntity(DedicatedAlert dedicatedAlert) { + return DedicatedAlertEntity + .builder() + .id(UUID.fromString(dedicatedAlert.getId())) + .type(EventObjectType.valueOf(dedicatedAlert.getType())) + .objectId(UUID.fromString(dedicatedAlert.getObjectId())) + .build(); + } + + private AlertEntity convertDtoToEntity(AlertRequest alertRequest) { + List dedicatedAlertEntities = alertRequest + .getDedicatedAlerts() + .stream() + .map(this::convertDedicatedAlertsDtoToEntity) + .toList(); + + return AlertEntity + .builder() + .id(UUID.randomUUID()) + .alertName(alertRequest.getAlertName()) + .created(alertRequest.getCreated()) + .description(alertRequest.getDescription()) + .monitoredObjects(AlertsMonitoredObjects.valueOf(alertRequest.getMonitoredObjects())) + .threshold(Double.parseDouble(alertRequest.getThreshold().toString())) + .userID(UUID.fromString(alertRequest.getUser())) + .type(AlertThresholdType.valueOf(alertRequest.getType())) + .dedicatedAlerts(dedicatedAlertEntities) + .build(); + } +} 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 b38c09c3..e004f137 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 @@ -59,6 +59,7 @@ public class CapacityGroupServiceImpl implements CapacityGroupService { private final LoggingHistoryService loggingHistoryService; private final FavoriteService favoriteService; private final StatusManagerImpl statusManager; + private final AlertService alertService; private final UserRepository userRepository; @@ -89,6 +90,7 @@ public CapacityGroupResponse createCapacityGroup(CapacityGroupRequest capacityGr capacityGroupRepository.save(capacityGroupEntity); } statusManager.calculateTodos(userID); + return convertCapacityGroupDto(capacityGroupEntity); } 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 4c1598a0..337c65b0 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 @@ -27,11 +27,9 @@ 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.*; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.*; @@ -67,6 +65,8 @@ public class DemandServiceImpl implements DemandService { private final DemandSeriesRepository demandSeriesRepository; + private final AlertService alertService; + private final CapacityGroupRepository capacityGroupRepository; private final LinkedCapacityGroupMaterialDemandRepository linkedCapacityGroupMaterialDemandRepository; private final HttpServletRequest request; @@ -165,6 +165,9 @@ public MaterialDemandResponse updateDemand( } } ); + + triggerDemandAlertsIfNeeded(demandId, userID, demand); + demand = materialDemandRepository.save(demand); postLogs(demandId, "MATERIAL DEMAND Updated", EventType.GENERAL_EVENT, userID); statusManager.calculateBottleneck(userID, true); @@ -172,6 +175,53 @@ public MaterialDemandResponse updateDemand( return convertDemandResponseDto(demand); } + private void triggerDemandAlertsIfNeeded(String demandId, String userID, MaterialDemandEntity demand) { + List oldDemandValues = new ArrayList<>(List.of()); + List newDemandValues = new ArrayList<>(List.of()); + + demand + .getDemandSeries() + .forEach( + demandSeries -> { + demandSeries + .getDemandSeriesValues() + .forEach( + demandSeriesValues -> { + newDemandValues.add(demandSeriesValues.getDemand()); + } + ); + } + ); + + materialDemandRepository + .findById(UUID.fromString(demandId)) + .get() + .getDemandSeries() + .forEach( + demandSeries1 -> { + demandSeries1 + .getDemandSeriesValues() + .forEach( + demandSeriesValues -> { + oldDemandValues.add(demandSeriesValues.getDemand()); + } + ); + } + ); + + for (int i = 0; i < newDemandValues.size(); i++) { + if (!Objects.equals(oldDemandValues.get(i), newDemandValues.get(i))) { + alertService.triggerDemandAlertsIfNeeded( + userID, + true, + oldDemandValues.get(i), + newDemandValues.get(i), + demandId + ); + } + } + } + private List getAllDemands() { return materialDemandRepository.findAll(); } 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 9044f84c..30b7459b 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 @@ -23,6 +23,12 @@ package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.impl; import eclipse.tractusx.demand_capacity_mgmt_specification.model.*; +import java.sql.Timestamp; +import java.time.Instant; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.UUID; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.*; @@ -32,13 +38,6 @@ import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.FavoriteService; import org.springframework.stereotype.Service; -import java.sql.Timestamp; -import java.time.Instant; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.UUID; - @RequiredArgsConstructor @Service @Slf4j diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/SecurityTokenServiceImpl.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/SecurityTokenServiceImpl.java index 54cb0077..2a3efb4f 100644 --- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/SecurityTokenServiceImpl.java +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/SecurityTokenServiceImpl.java @@ -30,6 +30,7 @@ import eclipse.tractusx.demand_capacity_mgmt_specification.model.Role; import eclipse.tractusx.demand_capacity_mgmt_specification.model.TokenResponse; import eclipse.tractusx.demand_capacity_mgmt_specification.model.User; +import java.util.*; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.UserEntity; @@ -46,8 +47,6 @@ import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Mono; -import java.util.*; - @RequiredArgsConstructor @Service @Slf4j @@ -217,17 +216,17 @@ private UserEntity generateUser(String userID, DecodedJWT decodedJWT) { newUserEntity.setEmail(Optional.ofNullable(decodedJWT.getClaim("email")).map(Claim::asString).orElse("")); newUserEntity.setName(Optional.ofNullable(decodedJWT.getClaim("given_name")).map(Claim::asString).orElse("")); newUserEntity.setLastName( - Optional.ofNullable(decodedJWT.getClaim("family_name")).map(Claim::asString).orElse("") + Optional.ofNullable(decodedJWT.getClaim("family_name")).map(Claim::asString).orElse("") ); newUserEntity.setUsername( - Optional.ofNullable(decodedJWT.getClaim("preferred_username")).map(Claim::asString).orElse("") + Optional.ofNullable(decodedJWT.getClaim("preferred_username")).map(Claim::asString).orElse("") ); Claim rolesClaim = decodedJWT.getClaim("realm_access"); Map realmAccessMap = Optional - .ofNullable(rolesClaim) - .map(Claim::asMap) - .orElse(Collections.emptyMap()); + .ofNullable(rolesClaim) + .map(Claim::asMap) + .orElse(Collections.emptyMap()); Object rolesObject = realmAccessMap.get("roles"); @@ -238,7 +237,7 @@ private UserEntity generateUser(String userID, DecodedJWT decodedJWT) { String roleStr = (String) roleObj; try { org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.Role role = org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.Role.valueOf( - roleStr + roleStr ); newUserEntity.setRole(role); break; diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/StatusManagerImpl.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/StatusManagerImpl.java index 91695b0b..b241b72f 100644 --- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/StatusManagerImpl.java +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/StatusManagerImpl.java @@ -22,6 +22,11 @@ package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.impl; +import java.sql.Timestamp; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.*; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.tuple.Pair; @@ -33,12 +38,6 @@ import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.StatusManager; import org.springframework.stereotype.Service; -import java.sql.Timestamp; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.util.*; -import java.util.stream.Collectors; - @RequiredArgsConstructor @Service @Slf4j @@ -55,19 +54,19 @@ public class StatusManagerImpl implements StatusManager { @Override public void calculateTodos(String userID) { userRepository - .findById(UUID.fromString(userID)) - .ifPresent( - user -> { - List demands = fetchDemandsBasedOnRole(user, userID); + .findById(UUID.fromString(userID)) + .ifPresent( + user -> { + List demands = fetchDemandsBasedOnRole(user, userID); - StatusesEntity statusesEntity = statusesRepository - .findByUserID(UUID.fromString(userID)) - .orElseGet(() -> generateNewEntity(userID)); + StatusesEntity statusesEntity = statusesRepository + .findByUserID(UUID.fromString(userID)) + .orElseGet(() -> generateNewEntity(userID)); - statusesEntity.setTodosCount(demands.size()); - statusesRepository.save(statusesEntity); - } - ); + statusesEntity.setTodosCount(demands.size()); + statusesRepository.save(statusesEntity); + } + ); } private StatusesEntity generateNewEntity(String userID) { @@ -78,12 +77,28 @@ private List fetchDemandsBasedOnRole(UserEntity user, Stri List demands = new ArrayList<>(); if (user.getRole().equals(Role.CUSTOMER)) { - demands = materialDemandRepository.findAll() //TODO SUPPLIER AQUI findbysupplierID + demands = + materialDemandRepository + .findAll() //TODO SUPPLIER AQUI findbysupplierID .stream() - .filter(d -> d.getDemandSeries().stream().allMatch(series -> series.getDemandSeriesValues().stream().allMatch(value -> value.getDemand() == 0))) + .filter( + d -> + d + .getDemandSeries() + .stream() + .allMatch( + series -> + series + .getDemandSeriesValues() + .stream() + .allMatch(value -> value.getDemand() == 0) + ) + ) .collect(Collectors.toList()); } else if (user.getRole().equals(Role.SUPPLIER)) { - demands = materialDemandRepository.findAll() //TODO CUSTOMER AQUI findbycustomerID + demands = + materialDemandRepository + .findAll() //TODO CUSTOMER AQUI findbycustomerID .stream() .filter(d -> d.getLinkStatus() == EventType.UN_LINKED) .collect(Collectors.toList()); @@ -91,7 +106,6 @@ private List fetchDemandsBasedOnRole(UserEntity user, Stri return demands; } - @Override public void calculateBottleneck(String userID, boolean postLog) { UserEntity user = getUser(userID).orElseThrow(() -> new IllegalArgumentException("User not found")); @@ -122,20 +136,20 @@ private void updateAndLogStatus(String userID, boolean postLog, int improvements if (improvements > 0) { logEvent( - EventType.STATUS_IMPROVEMENT, - userID, - postLog, - "Status improved for " + improvements + " weeks", - cgID + EventType.STATUS_IMPROVEMENT, + userID, + postLog, + "Status improved for " + improvements + " weeks", + cgID ); } if (degradations > 0) { logEvent( - EventType.STATUS_REDUCTION, - userID, - postLog, - "Status degraded for " + degradations + " weeks", - cgID + EventType.STATUS_REDUCTION, + userID, + postLog, + "Status degraded for " + degradations + " weeks", + cgID ); } @@ -155,7 +169,7 @@ private StatusesEntity createInitialStatus(String userID) { private Pair processCapacityGroup(String userID, CapacityGroupEntity cgs, boolean postLog) { List matchedEntities = matchedDemandsRepository.findByCapacityGroupID( - cgs.getId() + cgs.getId() ); int weeklyImprovements = 0; @@ -165,7 +179,7 @@ private Pair processCapacityGroup(String userID, CapacityGroup for (LinkedCapacityGroupMaterialDemandEntity entity : matchedEntities) { Optional materialDemand = materialDemandRepository.findById( - entity.getMaterialDemandID() + entity.getMaterialDemandID() ); if (materialDemand.isPresent()) { Map weeklyDemands = getWeeklyDemands(materialDemand.get().getDemandSeries()); @@ -197,15 +211,15 @@ private Pair processCapacityGroup(String userID, CapacityGroup private Map getWeeklyDemands(List matchedDemandSeries) { return matchedDemandSeries - .stream() - .flatMap(demand -> demand.getDemandSeriesValues().stream()) - .filter(value -> !value.getCalendarWeek().isBefore(TWO_WEEKS_FROM_NOW)) - .collect( - Collectors.groupingBy( - DemandSeriesValues::getCalendarWeek, - Collectors.summingDouble(DemandSeriesValues::getDemand) - ) - ); + .stream() + .flatMap(demand -> demand.getDemandSeriesValues().stream()) + .filter(value -> !value.getCalendarWeek().isBefore(TWO_WEEKS_FROM_NOW)) + .collect( + Collectors.groupingBy( + DemandSeriesValues::getCalendarWeek, + Collectors.summingDouble(DemandSeriesValues::getDemand) + ) + ); } private void logEvent(EventType eventType, String userID, boolean postLog, String descriptionOverride, UUID cgID) { @@ -220,7 +234,7 @@ private void logEvent(EventType eventType, String userID, boolean postLog, Strin logEntity.setLogID(UUID.randomUUID()); logEntity.setDescription( - Optional.ofNullable(descriptionOverride).orElseGet(() -> getEventDescription(eventType)) + Optional.ofNullable(descriptionOverride).orElseGet(() -> getEventDescription(eventType)) ); if (logEntity.getDescription() != null) { loggingRepository.save(logEntity); diff --git a/demand-capacity-mgmt-specification/src/main/resources/openapi.yml b/demand-capacity-mgmt-specification/src/main/resources/openapi.yml index 7e3cb43b..7640f533 100644 --- a/demand-capacity-mgmt-specification/src/main/resources/openapi.yml +++ b/demand-capacity-mgmt-specification/src/main/resources/openapi.yml @@ -427,6 +427,77 @@ paths: $ref: '#/components/schemas/LoggingHistoryResponse' 404: description: loggingHistory not found + + /alerts: + post: + tags: + - alerts + summary: configureAlert + operationId: configureAlert + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/AlertRequest' + responses: + 200: + description: General greeting + content: + application/json: + schema: + $ref: '#/components/schemas/AlertResponse' + + get: + tags: + - alerts + summary: get alerts + operationId: getAlerts + responses: + 200: + description: General greeting + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/AlertResponse' + + /triggeredAlerts: + post: + tags: + - alerts + summary: configureTriggeredAlert + operationId: configureTriggeredAlert + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/TriggeredAlertRequest' + responses: + 200: + description: General greeting + content: + application/json: + schema: + $ref: '#/components/schemas/TriggeredAlertResponse' + + get: + tags: + - alerts + summary: get triggered alerts + operationId: getTriggeredAlerts + responses: + 200: + description: General greeting + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/TriggeredAlertResponse' + /statuses: post: tags: @@ -1093,6 +1164,117 @@ components: statusDegradation: type: integer + AlertRequest: + type: object + properties: + alertId: + type: string + alertName: + type: string + monitoredObjects: + type: string + created: + type: string + type: + type: string + threshold: + type: number + description: + type: string + user: + type: string + dedicatedAlerts: + type: array + items: + $ref: '#/components/schemas/DedicatedAlert' + + + TriggeredAlertRequest: + type: object + properties: + alertId: + type: string + alertName: + type: string + monitoredObjects: + type: string + created: + type: string + triggerTimes: + type: number + triggerTimesInThreeMonths: + type: number + type: + type: string + threshold: + type: number + description: + type: string + user: + type: string + + + AlertResponse: + type: object + properties: + alertId: + type: string + alertName: + type: string + monitoredObjects: + type: string + created: + type: string + type: + type: string + threshold: + type: string + description: + type: string + user: + type: string + dedicatedAlerts: + type: array + items: + $ref: '#/components/schemas/DedicatedAlert' + + DedicatedAlert: + type: object + properties: + id: + type: string + objectId: + type: string + type: + type: string + + + + TriggeredAlertResponse: + type: object + properties: + alertId: + type: string + alertName: + type: string + monitoredObjects: + type: string + created: + type: string + triggerTimes: + type: integer + triggerTimesInThreeMonths: + type: integer + type: + type: string + threshold: + type: string + description: + type: string + user: + type: string + + DemandRequestDto: type: object properties: