Commit 6a3a3c01 authored by Riabokon Stanislav(EPAM)[GCP]'s avatar Riabokon Stanislav(EPAM)[GCP]
Browse files

Merge branch 'update-with-latest-changes' into 'master'

Update with latest changes(GONRG-1610 & GONRG-1638 & GONRG-1734)

See merge request !2
parents 553888af 54d1920f
Pipeline #26888 passed with stages
in 11 minutes and 6 seconds
...@@ -25,8 +25,12 @@ The following software have components provided under the terms of this license: ...@@ -25,8 +25,12 @@ The following software have components provided under the terms of this license:
- Apache HttpCore NIO (from http://hc.apache.org/httpcomponents-core-ga) - Apache HttpCore NIO (from http://hc.apache.org/httpcomponents-core-ga)
- Apache Log4j API (from ) - Apache Log4j API (from )
- Apache Log4j to SLF4J Adapter (from ) - Apache Log4j to SLF4J Adapter (from )
- AssertJ fluent assertions (from )
- AutoValue Annotations (from ) - AutoValue Annotations (from )
- Bean Validation API (from http://beanvalidation.org) - Bean Validation API (from http://beanvalidation.org)
- Byte Buddy (without dependencies) (from )
- Byte Buddy Java agent (from )
- ClassMate (from http://github.com/cowtowncoder/java-classmate)
- Cloud Datastore API v1-rev20181207-1.26.0 (from https://repo1.maven.org/maven2/com/google/apis/google-api-services-datastore) - Cloud Datastore API v1-rev20181207-1.26.0 (from https://repo1.maven.org/maven2/com/google/apis/google-api-services-datastore)
- Cloud SQL Administration API v1beta4-rev25-1.22.0 (from ) - Cloud SQL Administration API v1beta4-rev25-1.22.0 (from )
- Cloud SQL MySQL Socket Factory (Core Library, don't depend on this directly) (from ) - Cloud SQL MySQL Socket Factory (Core Library, don't depend on this directly) (from )
...@@ -50,11 +54,15 @@ The following software have components provided under the terms of this license: ...@@ -50,11 +54,15 @@ The following software have components provided under the terms of this license:
- Guava ListenableFuture only (from ) - Guava ListenableFuture only (from )
- Guava: Google Core Libraries for Java (from https://github.com/google/guava.git) - Guava: Google Core Libraries for Java (from https://github.com/google/guava.git)
- HPPC Collections (from http://labs.carrotsearch.com) - HPPC Collections (from http://labs.carrotsearch.com)
- Hibernate Validator Engine (from )
- HikariCP (from https://github.com/brettwooldridge/HikariCP) - HikariCP (from https://github.com/brettwooldridge/HikariCP)
- Identity and Access Management (IAM) API v1-rev247-1.23.0 (from ) - Identity and Access Management (IAM) API v1-rev247-1.23.0 (from )
- J2ObjC Annotations (from https://github.com/google/j2objc/) - J2ObjC Annotations (from https://github.com/google/j2objc/)
- JBoss Logging 3 (from http://www.jboss.org)
- JSON Small and Fast Parser (from http://www.minidev.net/) - JSON Small and Fast Parser (from http://www.minidev.net/)
- JSON Web Token support for the JVM (from https://github.com/jwtk/jjwt.git) - JSON Web Token support for the JVM (from https://github.com/jwtk/jjwt.git)
- JSON library from Android SDK (from http://developer.android.com/sdk)
- JSONassert (from https://github.com/skyscreamer/JSONassert)
- Jackson (from http://jackson.codehaus.org) - Jackson (from http://jackson.codehaus.org)
- Jackson 2 extensions to the Google HTTP Client Library for Java. (from https://github.com/google/google-http-java-client.git/google-http-client-jackson2) - Jackson 2 extensions to the Google HTTP Client Library for Java. (from https://github.com/google/google-http-java-client.git/google-http-client-jackson2)
- Jackson dataformat: CBOR (from http://github.com/FasterXML/jackson-dataformats-binary) - Jackson dataformat: CBOR (from http://github.com/FasterXML/jackson-dataformats-binary)
...@@ -87,12 +95,14 @@ The following software have components provided under the terms of this license: ...@@ -87,12 +95,14 @@ The following software have components provided under the terms of this license:
- Lucene Suggest (from ) - Lucene Suggest (from )
- MapStruct Core (from ) - MapStruct Core (from )
- Mockito (from http://www.mockito.org) - Mockito (from http://www.mockito.org)
- Mockito (from http://mockito.org)
- Netty/Buffer (from http://netty.io/) - Netty/Buffer (from http://netty.io/)
- Netty/Codec (from ) - Netty/Codec (from )
- Netty/Common (from ) - Netty/Common (from )
- Netty/Handler (from ) - Netty/Handler (from )
- Netty/Resolver (from ) - Netty/Resolver (from )
- Netty/Transport (from http://netty.io/) - Netty/Transport (from http://netty.io/)
- Objenesis (from http://objenesis.org)
- OpenCensus (from https://github.com/census-instrumentation/opencensus-java) - OpenCensus (from https://github.com/census-instrumentation/opencensus-java)
- OpenCensus (from https://github.com/census-instrumentation/opencensus-java) - OpenCensus (from https://github.com/census-instrumentation/opencensus-java)
- OpenCensus (from https://github.com/census-instrumentation/opencensus-java) - OpenCensus (from https://github.com/census-instrumentation/opencensus-java)
...@@ -109,7 +119,11 @@ The following software have components provided under the terms of this license: ...@@ -109,7 +119,11 @@ The following software have components provided under the terms of this license:
- Spring Boot Logging Starter (from http://projects.spring.io/spring-boot/) - Spring Boot Logging Starter (from http://projects.spring.io/spring-boot/)
- Spring Boot Security Starter (from http://projects.spring.io/spring-boot/) - Spring Boot Security Starter (from http://projects.spring.io/spring-boot/)
- Spring Boot Starter (from http://projects.spring.io/spring-boot/) - Spring Boot Starter (from http://projects.spring.io/spring-boot/)
- Spring Boot Test (from http://projects.spring.io/spring-boot/)
- Spring Boot Test Auto-Configure (from http://projects.spring.io/spring-boot/)
- Spring Boot Test Starter (from http://projects.spring.io/spring-boot/)
- Spring Boot Tomcat Starter (from http://projects.spring.io/spring-boot/) - Spring Boot Tomcat Starter (from http://projects.spring.io/spring-boot/)
- Spring Boot Validation Starter (from http://projects.spring.io/spring-boot/)
- Spring Boot Web Starter (from http://projects.spring.io/spring-boot/) - Spring Boot Web Starter (from http://projects.spring.io/spring-boot/)
- Spring Cloud GCP Autoconfigure Module (from ) - Spring Cloud GCP Autoconfigure Module (from )
- Spring Cloud GCP Cloud SQL PostgreSQL Starter (from https://repo1.maven.org/maven2/org/springframework/cloud/spring-cloud-gcp-starter-sql-postgresql) - Spring Cloud GCP Cloud SQL PostgreSQL Starter (from https://repo1.maven.org/maven2/org/springframework/cloud/spring-cloud-gcp-starter-sql-postgresql)
...@@ -132,6 +146,7 @@ The following software have components provided under the terms of this license: ...@@ -132,6 +146,7 @@ The following software have components provided under the terms of this license:
- Spring Plugin - Core (from ) - Spring Plugin - Core (from )
- Spring Retry (from http://www.springsource.org) - Spring Retry (from http://www.springsource.org)
- Spring TestContext Framework (from https://github.com/spring-projects/spring-framework) - Spring TestContext Framework (from https://github.com/spring-projects/spring-framework)
- Spring TestContext Framework (from https://github.com/spring-projects/spring-framework)
- Spring Transaction (from https://github.com/spring-projects/spring-framework) - Spring Transaction (from https://github.com/spring-projects/spring-framework)
- Spring Web (from https://github.com/spring-projects/spring-framework) - Spring Web (from https://github.com/spring-projects/spring-framework)
- Spring Web MVC (from https://github.com/spring-projects/spring-framework) - Spring Web MVC (from https://github.com/spring-projects/spring-framework)
...@@ -161,6 +176,9 @@ The following software have components provided under the terms of this license: ...@@ -161,6 +176,9 @@ The following software have components provided under the terms of this license:
- lang-mustache (from https://github.com/elastic/elasticsearch) - lang-mustache (from https://github.com/elastic/elasticsearch)
- lettuce (from http://github.com/mp911de/lettuce/wiki) - lettuce (from http://github.com/mp911de/lettuce/wiki)
- mapper-extras (from https://github.com/elastic/elasticsearch) - mapper-extras (from https://github.com/elastic/elasticsearch)
- org.apiguardian:apiguardian-api (from https://github.com/apiguardian-team/apiguardian)
- org.opentest4j:opentest4j (from https://github.com/ota4j-team/opentest4j)
- org.xmlunit:xmlunit-core (from http://www.xmlunit.org/)
- parent-join (from https://github.com/elastic/elasticsearch) - parent-join (from https://github.com/elastic/elasticsearch)
- proto-google-cloud-datastore-v1 (from https://github.com/googleapis/api-client-staging) - proto-google-cloud-datastore-v1 (from https://github.com/googleapis/api-client-staging)
- rank-eval (from https://github.com/elastic/elasticsearch) - rank-eval (from https://github.com/elastic/elasticsearch)
...@@ -271,11 +289,18 @@ The following software have components provided under the terms of this license: ...@@ -271,11 +289,18 @@ The following software have components provided under the terms of this license:
- AspectJ weaver (from http://www.aspectj.org) - AspectJ weaver (from http://www.aspectj.org)
- Expression Language 3.0 (from https://projects.eclipse.org/projects/ee4j.el) - Expression Language 3.0 (from https://projects.eclipse.org/projects/ee4j.el)
- JUnit Jupiter (Aggregator) (from https://junit.org/junit5/)
- Logback Classic Module (from ) - Logback Classic Module (from )
- Logback Core Module (from ) - Logback Core Module (from )
- SnakeYAML (from http://www.snakeyaml.org) - SnakeYAML (from http://www.snakeyaml.org)
- jakarta.annotation-api (from https://projects.eclipse.org/projects/ee4j.ca) - jakarta.annotation-api (from https://projects.eclipse.org/projects/ee4j.ca)
- jnr-posix (from ) - jnr-posix (from )
- org.junit.jupiter:junit-jupiter-api (from http://junit.org/junit5/)
- org.junit.jupiter:junit-jupiter-engine (from http://junit.org/junit5/)
- org.junit.jupiter:junit-jupiter-params (from http://junit.org/junit5/)
- org.junit.platform:junit-platform-commons (from http://junit.org/junit5/)
- org.junit.platform:junit-platform-engine (from http://junit.org/junit5/)
- org.junit.vintage:junit-vintage-engine (from http://junit.org/junit5/)
======================================================================== ========================================================================
EPL-2.0 EPL-2.0
...@@ -283,7 +308,14 @@ EPL-2.0 ...@@ -283,7 +308,14 @@ EPL-2.0
The following software have components provided under the terms of this license: The following software have components provided under the terms of this license:
- Expression Language 3.0 (from https://projects.eclipse.org/projects/ee4j.el) - Expression Language 3.0 (from https://projects.eclipse.org/projects/ee4j.el)
- JUnit Jupiter (Aggregator) (from https://junit.org/junit5/)
- jakarta.annotation-api (from https://projects.eclipse.org/projects/ee4j.ca) - jakarta.annotation-api (from https://projects.eclipse.org/projects/ee4j.ca)
- org.junit.jupiter:junit-jupiter-api (from http://junit.org/junit5/)
- org.junit.jupiter:junit-jupiter-engine (from http://junit.org/junit5/)
- org.junit.jupiter:junit-jupiter-params (from http://junit.org/junit5/)
- org.junit.platform:junit-platform-commons (from http://junit.org/junit5/)
- org.junit.platform:junit-platform-engine (from http://junit.org/junit5/)
- org.junit.vintage:junit-vintage-engine (from http://junit.org/junit5/)
======================================================================== ========================================================================
GPL-2.0-only GPL-2.0-only
...@@ -372,10 +404,12 @@ The following software have components provided under the terms of this license: ...@@ -372,10 +404,12 @@ The following software have components provided under the terms of this license:
- Lucene Core (from ) - Lucene Core (from )
- Lucene Sandbox (from ) - Lucene Sandbox (from )
- Mockito (from http://www.mockito.org) - Mockito (from http://www.mockito.org)
- Mockito (from http://mockito.org)
- Netty/Common (from ) - Netty/Common (from )
- Project Lombok (from https://projectlombok.org) - Project Lombok (from https://projectlombok.org)
- SLF4J API Module (from http://www.slf4j.org) - SLF4J API Module (from http://www.slf4j.org)
- jnr-x86asm (from http://github.com/jnr/jnr-x86asm) - jnr-x86asm (from http://github.com/jnr/jnr-x86asm)
- mockito-junit-jupiter (from https://github.com/mockito/mockito)
- spring-security-core (from http://spring.io/spring-security) - spring-security-core (from http://spring.io/spring-security)
- webjars-locator-core (from http://webjars.org) - webjars-locator-core (from http://webjars.org)
...@@ -440,10 +474,18 @@ unknown ...@@ -440,10 +474,18 @@ unknown
======================================================================== ========================================================================
The following software have components provided under the terms of this license: The following software have components provided under the terms of this license:
- Byte Buddy (without dependencies) (from )
- Checker Qual (from https://checkerframework.org) - Checker Qual (from https://checkerframework.org)
- JUnit (from http://junit.org) - JUnit (from http://junit.org)
- JUnit Jupiter (Aggregator) (from https://junit.org/junit5/)
- JavaBeans Activation Framework API jar (from ) - JavaBeans Activation Framework API jar (from )
- PostgreSQL JDBC Driver - JDBC 4.1 (from ) - PostgreSQL JDBC Driver - JDBC 4.1 (from )
- jakarta.xml.bind-api (from ) - jakarta.xml.bind-api (from )
- org.junit.jupiter:junit-jupiter-api (from http://junit.org/junit5/)
- org.junit.jupiter:junit-jupiter-engine (from http://junit.org/junit5/)
- org.junit.jupiter:junit-jupiter-params (from http://junit.org/junit5/)
- org.junit.platform:junit-platform-commons (from http://junit.org/junit5/)
- org.junit.platform:junit-platform-engine (from http://junit.org/junit5/)
- org.junit.vintage:junit-vintage-engine (from http://junit.org/junit5/)
...@@ -5,13 +5,13 @@ ...@@ -5,13 +5,13 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>backup-core</artifactId> <artifactId>backup-core</artifactId>
<description>Backup service Core on GCP</description> <description>Backup service Core on GCP</description>
<version>0.0.1-SNAPSHOT</version> <version>0.0.2-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<parent> <parent>
<artifactId>backup-service</artifactId> <artifactId>backup-service</artifactId>
<groupId>org.opengroup.osdu</groupId> <groupId>org.opengroup.osdu</groupId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
...@@ -35,6 +35,10 @@ ...@@ -35,6 +35,10 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId> <artifactId>spring-boot-starter-security</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.retry</groupId> <groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId> <artifactId>spring-retry</artifactId>
...@@ -84,5 +88,10 @@ ...@@ -84,5 +88,10 @@
<artifactId>springdoc-openapi-data-rest</artifactId> <artifactId>springdoc-openapi-data-rest</artifactId>
<version>${openapi.version}</version> <version>${openapi.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-data-rest</artifactId>
<version>${openapi.version}</version>
</dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file
/*
* Copyright 2020 Google LLC
* Copyright 2020 EPAM Systems, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://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.
*/
package org.opengroup.osdu.backup.api;
import java.util.EnumMap;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.opengroup.osdu.backup.locator.Asset;
import org.opengroup.osdu.backup.model.BackupImportRequest;
import org.opengroup.osdu.backup.model.BackupRole;
import org.opengroup.osdu.backup.model.BackupSchedule;
import org.opengroup.osdu.backup.model.BackupStamp;
import org.opengroup.osdu.backup.service.BackupService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.annotation.RequestScope;
@Slf4j
@RestController
@RequestScope
@RequiredArgsConstructor
@PreAuthorize("@authorizationFilter.hasPermission('" + BackupRole.BACKUP + "')")
public class BackupApi {
private final BackupService backupService;
@PostMapping("/schedule")
public ResponseEntity<BackupSchedule> submitBackupSchedule(
@RequestBody BackupSchedule backupSchedule) {
BackupSchedule savedBackupSchedule = backupService.submitBackupSchedule(backupSchedule);
return new ResponseEntity<>(savedBackupSchedule, HttpStatus.CREATED);
}
@PutMapping("/schedule")
public ResponseEntity<BackupSchedule> updateBackupSchedule(
@RequestBody BackupSchedule backupSchedule) {
BackupSchedule savedBackupSchedule = backupService.updateBackupSchedule(backupSchedule);
return new ResponseEntity<>(savedBackupSchedule, HttpStatus.ACCEPTED);
}
@GetMapping("/schedule")
public ResponseEntity<BackupSchedule> getScheduleById(@RequestParam String id) {
return new ResponseEntity<>(backupService.getBackupSchedule(id), HttpStatus.OK);
}
@PostMapping("/backup_import")
public ResponseEntity<BackupStamp> submitImport(@RequestBody BackupImportRequest backupId) {
BackupStamp stamp = backupService.submitBackupImportRequest(backupId);
return new ResponseEntity<>(stamp, HttpStatus.OK);
}
@GetMapping("/list_schedules")
public ResponseEntity<List<BackupSchedule>> listSchedules() {
return new ResponseEntity<>(backupService.listSchedules(), HttpStatus.OK);
}
@GetMapping("/list_backups")
public ResponseEntity<EnumMap<Asset, List<BackupStamp>>> listBackups() {
return new ResponseEntity<>(backupService.listBackups(), HttpStatus.OK);
}
}
...@@ -17,56 +17,97 @@ ...@@ -17,56 +17,97 @@
package org.opengroup.osdu.backup.api; package org.opengroup.osdu.backup.api;
import java.util.Collections;
import java.util.List; import java.util.List;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.opengroup.osdu.backup.logging.AuditLogger;
import org.opengroup.osdu.backup.model.BackupCollection; import org.opengroup.osdu.backup.model.BackupCollection;
import org.opengroup.osdu.backup.model.BackupRole; import org.opengroup.osdu.backup.model.BackupRole;
import org.opengroup.osdu.backup.model.CollectionState; import org.opengroup.osdu.backup.model.CollectionState;
import org.opengroup.osdu.backup.service.BackupCollectionService; import org.opengroup.osdu.backup.service.BackupCollectionService;
import org.opengroup.osdu.backup.validation.CreateCollection;
import org.opengroup.osdu.backup.validation.UpdateCollection;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.annotation.RequestScope; import org.springframework.web.context.annotation.RequestScope;
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping(value = "/collection")
@RequestScope @RequestScope
@RequiredArgsConstructor @RequiredArgsConstructor
@PreAuthorize("@authorizationFilter.hasPermission('" + BackupRole.BACKUP + "')") @PreAuthorize("@authorizationFilter.hasPermission('" + BackupRole.ADMIN + "')")
@Validated
public class BackupCollectionApi { public class BackupCollectionApi {
private final BackupCollectionService collectionService; private final BackupCollectionService collectionService;
@PostMapping("/collection") private final AuditLogger auditLogger;
public ResponseEntity<BackupCollection> createCollection(@RequestBody BackupCollection collection) {
@PostMapping
public ResponseEntity<BackupCollection> createCollection(
@Validated(CreateCollection.class) @RequestBody BackupCollection collection) {
BackupCollection backupCollection = collectionService.saveCollection(collection); BackupCollection backupCollection = collectionService.saveCollection(collection);
this.auditLogger.createCollectionSuccess(Collections.singletonList(backupCollection.toString()));
return new ResponseEntity<>(backupCollection, HttpStatus.CREATED); return new ResponseEntity<>(backupCollection, HttpStatus.CREATED);
} }
@PutMapping("/collection/{name}") @PutMapping("/{collectionName}")
public ResponseEntity<BackupCollection> updateCollection(@PathVariable String name, public ResponseEntity<BackupCollection> updateCollection(
@RequestBody BackupCollection collection) { @PathVariable String collectionName,
BackupCollection backupCollection = collectionService.update(collection); @Validated(UpdateCollection.class) @RequestBody BackupCollection collection) {
return new ResponseEntity<>(backupCollection, HttpStatus.CREATED); BackupCollection backupCollection = collectionService.update(collection, collectionName);
this.auditLogger.updateCollectionSuccess(Collections.singletonList(backupCollection.toString()));
return new ResponseEntity<>(backupCollection, HttpStatus.ACCEPTED);
}
@GetMapping("/{collectionName}")
public ResponseEntity<BackupCollection> getCollectionConfig(@PathVariable String collectionName) {
BackupCollection collection = collectionService.getCollectionConfiguration(collectionName);
this.auditLogger.readCollectionConfigurationSuccess(Collections.singletonList(collection.toString()));
return new ResponseEntity<>(collection, HttpStatus.OK);
}
@DeleteMapping("/{collectionName}")
public ResponseEntity deleteCollection(@PathVariable String collectionName) {
collectionService.deleteCollectionConfiguration(collectionName);
this.auditLogger.deleteCollectionSuccess(Collections.singletonList(collectionName));
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@GetMapping("/list")
public ResponseEntity<List<BackupCollection>> listCollections() {
List<BackupCollection> collectionList = collectionService.listCollectionsConfigurations();
this.auditLogger.readListCollectionsSuccess(Collections.singletonList(collectionList.toString()));
return new ResponseEntity<>(collectionList, HttpStatus.OK);
} }
@GetMapping("/collection/{name}") @GetMapping("/states/{collectionName}")
public ResponseEntity<List<CollectionState>> getCollectionStates(@PathVariable String name) { public ResponseEntity<List<CollectionState>> getCollectionStates(@PathVariable String collectionName,
List<CollectionState> collectionStates = collectionService.getCollectionStates(name); @RequestParam(required = false) String success) {
List<CollectionState> collectionStates = collectionService.getCollectionStates(collectionName);
this.auditLogger.readCollectionStatesSuccess(Collections.singletonList(collectionStates.toString()));
return new ResponseEntity<>(collectionStates, HttpStatus.OK); return new ResponseEntity<>(collectionStates, HttpStatus.OK);
} }
@GetMapping("/collection/restore/{stateId}") @PatchMapping("/restore/{stateId}")
public ResponseEntity<CollectionState> restoreCollection(@PathVariable String stateId) { public ResponseEntity<CollectionState> restoreCollection(@PathVariable String stateId) {
CollectionState collectionState = collectionService.restoreCollection(stateId); CollectionState collectionState = collectionService.restoreCollection(stateId);
return new ResponseEntity<>(collectionState, HttpStatus.OK); this.auditLogger.restoreCollectionSuccess(Collections.singletonList(collectionState.toString()));
return new ResponseEntity<>(collectionState, HttpStatus.ACCEPTED);
} }
......
...@@ -16,13 +16,18 @@ ...@@ -16,13 +16,18 @@
*/ */
package org.opengroup.osdu.backup.exception; package org.opengroup.osdu.backup.exception;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.core.common.model.http.AppException;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
@ControllerAdvice @ControllerAdvice
@Slf4j @Slf4j
...@@ -33,6 +38,18 @@ public class AppExceptionHandler { ...@@ -33,6 +38,18 @@ public class AppExceptionHandler {
return this.getErrorResponse(e); return this.getErrorResponse(e);
} }
@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<Map<String, String>> handleValidationExceptions(
MethodArgumentNotValidException ex) {
Map<String, String> errors = new HashMap<>();
ex.getBindingResult().getAllErrors().forEach((error) -> {
String fieldName = ((FieldError) error).getField();
String errorMessage = error.getDefaultMessage();
errors.put(fieldName, errorMessage);
});
return new ResponseEntity<>(errors, HttpStatus.BAD_REQUEST);
}
private ResponseEntity<Object> getErrorResponse(AppException e) { private ResponseEntity<Object> getErrorResponse(AppException e) {
String exceptionMsg = Objects.nonNull(e.getOriginalException()) String exceptionMsg = Objects.nonNull(e.getOriginalException())
......
package org.opengroup.osdu.backup.logging;
import static java.lang.String.format;
import com.google.common.base.Strings;
import java.util.List;
import org.opengroup.osdu.core.common.logging.audit.AuditAction;
import org.opengroup.osdu.core.common.logging.audit.AuditPayload;
import org.opengroup.osdu.core.common.logging.audit.AuditStatus;
public class AuditEvents {
private static final String CREATE_COLLECTION_ACTION_ID = "BU001";
private static final String CREATE_COLLECTION_MESSAGE = "Create collection";
private static final String UPDATE_COLLECTION_ACTION_ID = "BU002";
private static final String UPDATE_COLLECTION_MESSAGE = "Update collection";
private static final String READ_COLLECTION_CONFIG_ACTION_ID = "BU003";
private static final String READ_COLLECTION_CONFIG_MESSAGE = "Read collection configuration";
private static final String DELETE_COLLECTION_ACTION_ID = "BU004";
private static final String DELETE_COLLECTION_MESSAGE = "Delete collection";
private static final String READ_LIST_COLLECTIONS_ACTION_ID = "BU005";
private static final String READ_LIST_COLLECTIONS_MESSAGE = "Read list collections";
private static final String READ_COLLECTION_STATES_ACTION_ID = "BU006";
private static final String READ_COLLECTION_STATES_MESSAGE = "Read collection states";
private static final String RESTORE_COLLECTION_ACTION_ID = "BU007";
private static final String RESTORE_COLLECTION_MESSAGE = "Restore collection";
private final String user;
public AuditEvents(String user) {
if (Strings.isNullOrEmpty(user)) {
throw new IllegalArgumentException("User not provided for audit events.");
}
this.user = user;
}
public AuditPayload getCreateCollectionEvent(AuditStatus status, List<String> resources) {
return AuditPayload.builder()
.action(AuditAction.CREATE)
.status(status)
.user(this.user)
.actionId(CREATE_COLLECTION_ACTION_ID)
.message(getStatusMessage(status, CREATE_COLLECTION_MESSAGE))
.resources(resources)
.build();
}