Pull request #556: RED-5293: 500 for invalid tenant
Merge in RED/persistence-service from RED-5293 to master * commit '92326e82f572c62f275c98fc47d1848e47f2c2ea': RED-5293: 500 for invalid tenant RED-5293: 500 for invalid tenant RED-5293: 500 for invalid tenant RED-5293: 500 for invalid tenant RED-5293: 500 for invalid tenant RED-5293: 500 for invalid tenant
This commit is contained in:
commit
17a6f53673
@ -56,16 +56,22 @@
|
||||
|
||||
<!-- spring -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- test -->
|
||||
<dependency>
|
||||
<groupId>com.iqser.red.commons</groupId>
|
||||
<artifactId>jackson-commons</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
package com.iqser.red.service.persistence.service.v1.api.model.multitenancy;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
@ -11,11 +14,15 @@ import lombok.NoArgsConstructor;
|
||||
@NoArgsConstructor
|
||||
public class TenantRequest {
|
||||
|
||||
@NotNull
|
||||
private String tenantId;
|
||||
@NotBlank
|
||||
private String displayName;
|
||||
private String guid;
|
||||
private String jdbcUrl;
|
||||
@NotBlank
|
||||
private String user;
|
||||
@NotBlank
|
||||
private String password;
|
||||
|
||||
}
|
||||
|
||||
@ -7,4 +7,11 @@ public class ConflictException extends RuntimeException {
|
||||
super(message);
|
||||
}
|
||||
|
||||
|
||||
public static ConflictException withObjectName(String objectName) {
|
||||
|
||||
return new ConflictException(String.format("An object of type %s already exists.", objectName));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -125,6 +125,10 @@
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.iqser.red.commons</groupId>
|
||||
<artifactId>spring-boot-starter-web-custom-commons</artifactId>
|
||||
|
||||
@ -5,6 +5,7 @@ import java.time.OffsetDateTime;
|
||||
import org.postgresql.util.PSQLException;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
@ -93,4 +94,13 @@ public class ControllerAdvice {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ResponseBody
|
||||
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
|
||||
@ExceptionHandler(value = MethodArgumentNotValidException.class)
|
||||
public ErrorMessage handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
|
||||
|
||||
return new ErrorMessage(OffsetDateTime.now(), e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -2,6 +2,8 @@ package com.iqser.red.service.peristence.v1.server.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@ -23,7 +25,7 @@ public class TenantsController implements TenantsResource {
|
||||
private final DeploymentKeyService deploymentKeyService;
|
||||
|
||||
|
||||
public void createTenant(@RequestBody TenantRequest tenantRequest) {
|
||||
public void createTenant(@Valid @RequestBody TenantRequest tenantRequest) {
|
||||
|
||||
tenantManagementService.createTenant(tenantRequest);
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.postgresql.util.PSQLException;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
@ -15,6 +16,8 @@ import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.jdbc.datasource.SingleConnectionDataSource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.iqser.red.service.persistence.management.v1.processor.exception.BadRequestException;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.exception.ConflictException;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.exception.NotFoundException;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.multitenancy.entity.TenantEntity;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.EncryptionDecryptionService;
|
||||
@ -71,6 +74,8 @@ public class TenantManagementService {
|
||||
.password(encryptedPassword)
|
||||
.build();
|
||||
tenantRepository.save(tenantEntity);
|
||||
} else {
|
||||
throw ConflictException.withObjectName("tenant");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -68,6 +68,7 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user