This repository has been archived by the owner on Jan 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Merge pull request #18 from catenax-ng/feature/DCMFOSS-70
implemented alert service
- Loading branch information
Showing
18 changed files
with
900 additions
and
69 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
...se/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/AlertController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<AlertResponse> configureAlert(AlertRequest alertRequest) throws Exception { | ||
AlertResponse responseDto = alertService.configureAlert(alertRequest); | ||
return ResponseEntity.status(HttpStatus.CREATED).body(responseDto); | ||
} | ||
|
||
@Override | ||
public ResponseEntity<TriggeredAlertResponse> configureTriggeredAlert(TriggeredAlertRequest triggeredAlertRequest) | ||
throws Exception { | ||
TriggeredAlertResponse responseDto = alertService.postTriggeredAlerts(triggeredAlertRequest); | ||
return ResponseEntity.status(HttpStatus.CREATED).body(responseDto); | ||
} | ||
|
||
@Override | ||
public ResponseEntity<List<AlertResponse>> getAlerts() throws Exception { | ||
String userID = UserUtil.getUserID(request); | ||
return ResponseEntity.status(HttpStatus.OK).body(alertService.getAlerts(userID)); | ||
} | ||
|
||
@Override | ||
public ResponseEntity<List<TriggeredAlertResponse>> getTriggeredAlerts() throws Exception { | ||
String userID = UserUtil.getUserID(request); | ||
return ResponseEntity.status(HttpStatus.OK).body(alertService.getTriggeredAlerts(userID)); // | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...g/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/AlertEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<DedicatedAlertEntity> dedicatedAlerts; | ||
} |
33 changes: 33 additions & 0 deletions
33
.../tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/DedicatedAlertEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
.../tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/TriggeredAlertEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
6 changes: 6 additions & 0 deletions
6
...ctusx/demandcapacitymgmt/demandcapacitymgmtbackend/entities/enums/AlertThresholdType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums; | ||
|
||
public enum AlertThresholdType { | ||
ABSOLUTE, | ||
RELATIVE, | ||
} |
8 changes: 8 additions & 0 deletions
8
...x/demandcapacitymgmt/demandcapacitymgmtbackend/entities/enums/AlertsMonitoredObjects.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums; | ||
|
||
public enum AlertsMonitoredObjects { | ||
ALL_DEMANDS, | ||
ALL_CAPACITIES, | ||
ALL_OBJECTS, | ||
DEDICATED, | ||
} |
36 changes: 36 additions & 0 deletions
36
.../tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/repositories/AlertsRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<AlertEntity, Integer> { | ||
Optional<AlertEntity> findByUserID(UUID userID); | ||
List<AlertEntity> findAllByUserID(UUID userID); | ||
void deleteByUserID(UUID userID); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
.../demandcapacitymgmt/demandcapacitymgmtbackend/repositories/TriggeredAlertsRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TriggeredAlertEntity, Integer> {} |
41 changes: 41 additions & 0 deletions
41
.../eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/AlertService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<AlertResponse> getAlerts(String userID); | ||
List<TriggeredAlertResponse> getTriggeredAlerts(String userID); | ||
TriggeredAlertResponse postTriggeredAlerts(TriggeredAlertRequest triggeredAlertRequest); | ||
} |
Oops, something went wrong.