Skip to content

Commit

Permalink
Merge pull request #30 from catenax-ng/feature/DCMFOSS-62-copy
Browse files Browse the repository at this point in the history
Logging History service - 62
  • Loading branch information
carslen authored Oct 16, 2023
2 parents dbb9d8e + 9950fce commit 9a563d3
Show file tree
Hide file tree
Showing 27 changed files with 1,603 additions and 368 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,4 @@ target/

demand-capacity-mgmt-backend/.mvn/wrapper/maven-wrapper.jar
.env
keycloak/generate-secret.sh
keycloak/init-db.sql
keycloak/realm-export.json
keycloak/
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* *******************************************************************************
* 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.LoggingHistoryApi;
import eclipse.tractusx.demand_capacity_mgmt_specification.model.*;
import java.sql.Timestamp;
import java.util.List;
import lombok.AllArgsConstructor;
import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.LoggingHistoryService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;

@RestController
@AllArgsConstructor
public class LoggingHistoryController implements LoggingHistoryApi {

private final LoggingHistoryService loggingHistoryService;

@Override
public ResponseEntity<Void> createArchivedLog(LoggingHistoryRequest loggingHistoryRequest) {
loggingHistoryService.archiveLog(loggingHistoryRequest);
return ResponseEntity.status(HttpStatus.OK).build();
}

@Override
public ResponseEntity<Void> deleteAllArchivedLogs() {
loggingHistoryService.deleteAllArchivedLogs();
return ResponseEntity.status(HttpStatus.OK).build();
}

@Override
public ResponseEntity<Void> deleteAllLogs() {
loggingHistoryService.deleteAllLogs();
return ResponseEntity.status(HttpStatus.OK).build();
}

@Override
public ResponseEntity<Void> deleteArchivedLogById(String logId) throws Exception {
loggingHistoryService.deleteArchivedLogById(logId);
return ResponseEntity.status(HttpStatus.OK).build();
}

@Override
public ResponseEntity<Void> deleteLogById(String logId) throws Exception {
loggingHistoryService.deleteLogById(logId);
return ResponseEntity.status(HttpStatus.OK).build();
}

@Override
public ResponseEntity<List<ArchivedLoggingHistoryResponse>> getArchivedLogs() throws Exception {
return ResponseEntity.status(HttpStatus.OK).body(loggingHistoryService.getAllArchivedLogs());
}

@Override
public ResponseEntity<List<LoggingHistoryResponse>> filterLogs(
String startTime,
String endTime,
String event,
String materialDemandId,
String capacityGroupId
) throws Exception {
return ResponseEntity
.status(HttpStatus.OK)
.body(loggingHistoryService.filterLog(capacityGroupId, materialDemandId, event, startTime, endTime));
}

@Override
public ResponseEntity<List<LoggingHistoryResponse>> getLoggingHistory() {
return ResponseEntity.status(HttpStatus.OK).body(loggingHistoryService.getAllLoggingHistory());
}

@Override
public ResponseEntity<List<LoggingHistoryResponse>> getLoggingHistoryForFavoriteCapacityGroups() {
return ResponseEntity.status(HttpStatus.OK).body(loggingHistoryService.filterByFavoriteCapacityGroup());
}

@Override
public ResponseEntity<List<LoggingHistoryResponse>> getLoggingHistoryForFavoriteMaterialDemands() {
return ResponseEntity.status(HttpStatus.OK).body(loggingHistoryService.filterByFavoriteMaterialDemand());
}

@Override
public ResponseEntity<LoggingHistoryResponse> postLogs(LoggingHistoryRequest loggingHistoryRequest) {
LoggingHistoryResponse responseDto = loggingHistoryService.createLog(loggingHistoryRequest);
return ResponseEntity.status(HttpStatus.CREATED).body(responseDto);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* *******************************************************************************
* 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.entities;

import io.micrometer.core.lang.Nullable;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import java.sql.Timestamp;
import java.util.UUID;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.EventObjectType;
import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.EventType;
import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name = "archived_log")
@Data
@Builder
public class ArchivedLogEntity {

@Id
@GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(columnDefinition = "uuid", updatable = false, name = "id")
private UUID id;

@Column(name = "USER_ACCOUNT")
private String userAccount;

@Column(name = "TIME_CREATED")
private Timestamp time_created;

@Column(name = "EVENT_TYPE")
private EventType eventType;

@Column(columnDefinition = "uuid", updatable = false, name = "CAPACITY_GP_ID")
@Nullable
private UUID capacityGroupId;

@Column(columnDefinition = "uuid", updatable = false, name = "MATERIAL_DEMAND_ID")
@Nullable
private UUID materialDemandId;

@Column(name = "DESCRIPTION")
private String description;

@Column(name = "OBJECT_TYPE")
private EventObjectType objectType;

@Column(name = "IS_FAVORITED")
private Boolean isFavorited;

public ArchivedLogEntity(
UUID id,
String userAccount,
Timestamp time_created,
EventType eventType,
UUID capacityGroupId,
UUID materialDemandId,
String description,
EventObjectType objectType,
Boolean isFavorited
) {
this.id = id;
this.userAccount = userAccount;
this.time_created = time_created;
this.eventType = eventType;
this.capacityGroupId = capacityGroupId;
this.materialDemandId = materialDemandId;
this.description = description;
this.objectType = objectType;
this.isFavorited = isFavorited;
}

public ArchivedLogEntity() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public class FavoriteEntity {
@Column(columnDefinition = "uuid", name = "favorite_id")
private UUID favoriteId;

@Column(columnDefinition = "uuid", name = "favorite_type_id")
private UUID favoriteTypeId;

@Column(name = "f_type", columnDefinition = "varchar")
@Enumerated(EnumType.STRING)
private FavoriteType type;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* *******************************************************************************
* 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.entities;

import io.micrometer.core.lang.Nullable;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import java.sql.Timestamp;
import java.util.UUID;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.EventObjectType;
import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.EventStatus;
import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.EventType;
import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.UserSpecificEventStatus;
import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name = "logging_history")
@Data
@Builder
public class LoggingHistoryEntity {

@Id
@GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(columnDefinition = "uuid", updatable = false, name = "id")
private UUID id;

@Column(name = "USER_ACCOUNT")
@Nullable
private String userAccount;

@Column(name = "TIME_CREATED")
@Nullable
private Timestamp time_created;

@Column(name = "EVENT_TYPE")
@Nullable
private EventType eventType;

@Column(columnDefinition = "uuid", updatable = false, name = "CAPACITY_GP_ID")
@Nullable
private UUID capacityGroupId;

@Column(columnDefinition = "uuid", updatable = false, name = "MATERIAL_DEMAND_ID")
@Nullable
private UUID materialDemandId;

@Nullable
@Column(name = "DESCRIPTION")
private String description;

@Nullable
@Column(name = "OBJECT_TYPE")
private EventObjectType objectType;

@Column(name = "IS_FAVORITED")
@Nullable
private Boolean isFavorited;

public LoggingHistoryEntity(
UUID id,
String userAccount,
Timestamp time_created,
EventType eventType,
UUID capacityGroupId,
UUID materialDemandId,
String description,
EventObjectType objectType,
Boolean isFavorited
) {
this.id = id;
this.userAccount = userAccount;
this.time_created = time_created;
this.eventType = eventType;
this.capacityGroupId = capacityGroupId;
this.materialDemandId = materialDemandId;
this.description = description;
this.objectType = objectType;
this.isFavorited = isFavorited;
}

public LoggingHistoryEntity() {}
}
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.entities.enums;

public enum EventObjectType {
MATERIAL_DEMAND,
CAPACITY_GROUP,
DEMAND_CATEGORY,
COMPANY,
WEEKLY_MATERIAL_DEMAND,
WEEKLY_BASED_CAPACITY_GROUP,
LINK_DEMAND_SERVICE,
}
Loading

0 comments on commit 9a563d3

Please sign in to comment.