This is an automated email from the ASF dual-hosted git repository. ofuks pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git
The following commit(s) were added to refs/heads/develop by this push: new 626b9c7 Sonar code smell changes 626b9c7 is described below commit 626b9c7b5176b009d260b5fdad218dcfb7f650b3 Author: Oleh Fuks <olegfuk...@gmail.com> AuthorDate: Fri Sep 11 15:22:04 2020 +0300 Sonar code smell changes --- .../java/com/epam/dlab/backendapi/dao/BaseDAO.java | 49 +++++---- .../com/epam/dlab/backendapi/dao/IndexCreator.java | 1 - .../backendapi/resources/EndpointResource.java | 69 +++++-------- .../dlab/backendapi/resources/ProjectResource.java | 115 +++++++++------------ 4 files changed, 98 insertions(+), 136 deletions(-) diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/BaseDAO.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/BaseDAO.java index 96532a5..253fc7b 100644 --- a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/BaseDAO.java +++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/BaseDAO.java @@ -66,27 +66,27 @@ import static com.mongodb.client.model.Filters.ne; * Implements the base API for Mongo database. */ public class BaseDAO { - private static final Logger LOGGER = LoggerFactory.getLogger(BaseDAO.class); - - private static final ObjectMapper MAPPER = new ObjectMapper() - .configure(JsonParser.Feature.AUTO_CLOSE_SOURCE, true) - .configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false) - .registerModule(new IsoDateModule()) - .registerModule(new JavaPrimitiveModule()) - .registerModule(new MongoModule()); - static final String FIELD_SET_DELIMETER = ".$."; public static final String ID = "_id"; - static final String SET = "$set"; public static final String USER = "user"; - protected static final String INSTANCE_ID = "instance_id"; - protected static final String EDGE_STATUS = "edge_status"; public static final String STATUS = "status"; public static final String ERROR_MESSAGE = "error_message"; - static final String TIMESTAMP = "timestamp"; - static final String REUPLOAD_KEY_REQUIRED = "reupload_key_required"; + protected static final String INSTANCE_ID = "instance_id"; + protected static final String EDGE_STATUS = "edge_status"; protected static final String ADD_TO_SET = "$addToSet"; protected static final String UNSET_OPERATOR = "$unset"; + static final String FIELD_SET_DELIMETER = ".$."; + static final String SET = "$set"; + static final String TIMESTAMP = "timestamp"; + static final String REUPLOAD_KEY_REQUIRED = "reupload_key_required"; + private static final Logger LOGGER = LoggerFactory.getLogger(BaseDAO.class); + private static final String INSERT_ERROR_MESSAGE = "Insert to Mongo DB fails: "; + private static final ObjectMapper MAPPER = new ObjectMapper() + .configure(JsonParser.Feature.AUTO_CLOSE_SOURCE, true) + .configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false) + .registerModule(new IsoDateModule()) + .registerModule(new JavaPrimitiveModule()) + .registerModule(new MongoModule()); private static final String PULL = "$pull"; private static final String PULL_ALL = "$pullAll"; private static final String EACH = "$each"; @@ -137,7 +137,7 @@ public class BaseDAO { .append(ID, uuid) .append(TIMESTAMP, new Date())); } catch (MongoException e) { - LOGGER.warn("Insert to Mongo DB fails: {}", e.getLocalizedMessage(), e); + LOGGER.warn(INSERT_ERROR_MESSAGE + "{}", e.getLocalizedMessage(), e); throw new DlabException("Insert to Mongo DB failed: " + e.getLocalizedMessage(), e); } } @@ -166,8 +166,8 @@ public class BaseDAO { .append(ID, uuid) .append(TIMESTAMP, new Date())); } catch (MongoException e) { - LOGGER.warn("Insert to Mongo DB fails: {}", e.getLocalizedMessage(), e); - throw new DlabException("Insert to Mongo DB fails: " + e.getLocalizedMessage(), e); + LOGGER.warn(INSERT_ERROR_MESSAGE + "{}", e.getLocalizedMessage(), e); + throw new DlabException(INSERT_ERROR_MESSAGE + e.getLocalizedMessage(), e); } } @@ -189,8 +189,8 @@ public class BaseDAO { .collect(Collectors.toList()) ); } catch (MongoException e) { - LOGGER.warn("Insert to Mongo DB fails: {}", e.getLocalizedMessage(), e); - throw new DlabException("Insert to Mongo DB fails: " + e.getLocalizedMessage(), e); + LOGGER.warn(INSERT_ERROR_MESSAGE + "{}", e.getLocalizedMessage(), e); + throw new DlabException(INSERT_ERROR_MESSAGE + e.getLocalizedMessage(), e); } } @@ -246,7 +246,7 @@ public class BaseDAO { .updateMany(condition, document); } catch (MongoException e) { LOGGER.warn("Update Mongo DB fails: {}", e.getLocalizedMessage(), e); - throw new DlabException("Insert to Mongo DB fails: " + e.getLocalizedMessage(), e); + throw new DlabException("Update to Mongo DB fails: " + e.getLocalizedMessage(), e); } } @@ -351,8 +351,7 @@ public class BaseDAO { * @param collection collection name. * @param pipeline the aggregate pipeline. */ - public AggregateIterable<Document> aggregate(String collection, - List<? extends Bson> pipeline) { + public AggregateIterable<Document> aggregate(String collection, List<? extends Bson> pipeline) { return mongoService.getCollection(collection) .aggregate(pipeline); } @@ -395,11 +394,9 @@ public class BaseDAO { * @param projection document describing the fields in the collection to return. * @throws DlabException if documents iterator have more than one document. */ - protected Optional<Document> findOne(String collection, - Bson condition, - Bson projection) { + protected Optional<Document> findOne(String collection, Bson condition, Bson projection) { FindIterable<Document> found = find(collection, condition, projection); - return limitOne(found); + return limitOne(found); } /** diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/IndexCreator.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/IndexCreator.java index f6e8bb6..4145d70 100644 --- a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/IndexCreator.java +++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/IndexCreator.java @@ -33,7 +33,6 @@ public class IndexCreator extends BaseDAO implements Managed { public void start() { mongoService.getCollection(USER_INSTANCES) .createIndex(Indexes.ascending(USER, EXPLORATORY_NAME, PROJECT_FIELD), new IndexOptions().unique(true)); - // TODO: Make refactoring and append indexes for other mongo collections } @Override diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/EndpointResource.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/EndpointResource.java index dcb4594..7665831 100644 --- a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/EndpointResource.java +++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/EndpointResource.java @@ -32,7 +32,6 @@ import io.swagger.v3.oas.annotations.headers.Header; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.responses.ApiResponses; import javax.annotation.security.RolesAllowed; import javax.validation.Valid; @@ -63,18 +62,16 @@ public class EndpointResource { } @Operation(summary = "Create endpoint", tags = "endpoint") - @ApiResponses({ - @ApiResponse(responseCode = "201", description = "Endpoint is successfully created", - headers = - @Header(required = true, name = "Location", description = "URI of created endpoint resource", - schema = @Schema(type = "string"))), - @ApiResponse(responseCode = "400", description = "Validation error", content = @Content(mediaType = - MediaType.APPLICATION_JSON, - schema = @Schema(implementation = ErrorDTO.class))), - @ApiResponse(responseCode = "409", description = "Endpoint with passed name already exist in system", - content = @Content(mediaType = MediaType.APPLICATION_JSON, - schema = @Schema(implementation = ErrorDTO.class))) - }) + @ApiResponse(responseCode = "201", description = "Endpoint is successfully created", + headers = + @Header(required = true, name = "Location", description = "URI of created endpoint resource", + schema = @Schema(type = "string"))) + @ApiResponse(responseCode = "400", description = "Validation error", content = @Content(mediaType = + MediaType.APPLICATION_JSON, + schema = @Schema(implementation = ErrorDTO.class))) + @ApiResponse(responseCode = "409", description = "Endpoint with passed name already exist in system", + content = @Content(mediaType = MediaType.APPLICATION_JSON, + schema = @Schema(implementation = ErrorDTO.class))) @Consumes(MediaType.APPLICATION_JSON) @POST public Response createEndpoint(@Parameter(hidden = true) @Auth UserInfo userInfo, @Valid EndpointDTO endpointDTO) { @@ -87,14 +84,12 @@ public class EndpointResource { } @Operation(summary = "Get endpoint info", tags = "endpoint") - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "Return information about endpoint", - content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = - @Schema(implementation = EndpointDTO.class))), - @ApiResponse(responseCode = "404", description = "Endpoint with passed name not found", - content = @Content(mediaType = MediaType.APPLICATION_JSON, - schema = @Schema(implementation = ErrorDTO.class))) - }) + @ApiResponse(responseCode = "200", description = "Return information about endpoint", + content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = + @Schema(implementation = EndpointDTO.class))) + @ApiResponse(responseCode = "404", description = "Endpoint with passed name not found", + content = @Content(mediaType = MediaType.APPLICATION_JSON, + schema = @Schema(implementation = ErrorDTO.class))) @GET @Path("{name}") @Produces(MediaType.APPLICATION_JSON) @@ -105,11 +100,9 @@ public class EndpointResource { } @Operation(summary = "Get endpoints available in system", tags = "endpoint") - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "Return information about endpoints", - content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = - @Schema(implementation = EndpointDTO.class))) - }) + @ApiResponse(responseCode = "200", description = "Return information about endpoints", + content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = + @Schema(implementation = EndpointDTO.class))) @GET @Produces(MediaType.APPLICATION_JSON) public Response getEndpoints(@Parameter(hidden = true) @Auth UserInfo userInfo) { @@ -117,11 +110,9 @@ public class EndpointResource { } @Operation(summary = "Get resources related to the endpoint", tags = "endpoint") - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "Return information about resources of endpoint", - content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = - @Schema(implementation = EndpointResourcesDTO.class))) - }) + @ApiResponse(responseCode = "200", description = "Return information about resources of endpoint", + content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = + @Schema(implementation = EndpointResourcesDTO.class))) @GET @Path("{name}/resources") @Produces(MediaType.APPLICATION_JSON) @@ -132,12 +123,10 @@ public class EndpointResource { } @Operation(summary = "Remove endpoint", tags = "endpoint") - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "Endpoint is successfully removed"), - @ApiResponse(responseCode = "404", description = "Endpoint with passed name not found", - content = @Content(mediaType = MediaType.APPLICATION_JSON, - schema = @Schema(implementation = ErrorDTO.class))) - }) + @ApiResponse(responseCode = "200", description = "Endpoint is successfully removed") + @ApiResponse(responseCode = "404", description = "Endpoint with passed name not found", + content = @Content(mediaType = MediaType.APPLICATION_JSON, + schema = @Schema(implementation = ErrorDTO.class))) @DELETE @Path("{name}") public Response removeEndpoint(@Parameter(hidden = true) @Auth UserInfo userInfo, @@ -148,10 +137,8 @@ public class EndpointResource { } @Operation(summary = "Check whether endpoint url is valid", tags = "endpoint") - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "Valid endpoint url"), - @ApiResponse(responseCode = "404", description = "Endpoint url is not valid"), - }) + @ApiResponse(responseCode = "200", description = "Valid endpoint url") + @ApiResponse(responseCode = "404", description = "Endpoint url is not valid") @GET @Path("url/{url}") @Produces(MediaType.APPLICATION_JSON) diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/ProjectResource.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/ProjectResource.java index 5b6a241..f1bca5f 100644 --- a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/ProjectResource.java +++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/ProjectResource.java @@ -39,7 +39,6 @@ import io.swagger.v3.oas.annotations.headers.Header; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.responses.ApiResponses; import javax.annotation.security.RolesAllowed; import javax.validation.Valid; @@ -76,18 +75,16 @@ public class ProjectResource { @Operation(summary = "Create project", tags = "project") - @ApiResponses({ - @ApiResponse(responseCode = "201", description = "Project is successfully created", - headers = - @Header(required = true, name = "Location", description = "URI of created project resource", - schema = @Schema(type = "string"))), - @ApiResponse(responseCode = "400", description = "Validation error", content = @Content(mediaType = - MediaType.APPLICATION_JSON, - schema = @Schema(implementation = ErrorDTO.class))), - @ApiResponse(responseCode = "409", description = "Project with passed name already exist in system", - content = @Content(mediaType = MediaType.APPLICATION_JSON, - schema = @Schema(implementation = ErrorDTO.class))) - }) + @ApiResponse(responseCode = "201", description = "Project is successfully created", + headers = + @Header(required = true, name = "Location", description = "URI of created project resource", + schema = @Schema(type = "string"))) + @ApiResponse(responseCode = "400", description = "Validation error", content = @Content(mediaType = + MediaType.APPLICATION_JSON, + schema = @Schema(implementation = ErrorDTO.class))) + @ApiResponse(responseCode = "409", description = "Project with passed name already exist in system", + content = @Content(mediaType = MediaType.APPLICATION_JSON, + schema = @Schema(implementation = ErrorDTO.class))) @POST @Consumes(MediaType.APPLICATION_JSON) @RolesAllowed("/api/project/create") @@ -108,12 +105,10 @@ public class ProjectResource { } @Operation(summary = "Start project", tags = "project") - @ApiResponses({ - @ApiResponse(responseCode = "202", description = "Project is starting"), - @ApiResponse(responseCode = "400", description = "Validation error", content = @Content(mediaType = - MediaType.APPLICATION_JSON, - schema = @Schema(implementation = ErrorDTO.class))) - }) + @ApiResponse(responseCode = "202", description = "Project is starting") + @ApiResponse(responseCode = "400", description = "Validation error", content = @Content(mediaType = + MediaType.APPLICATION_JSON, + schema = @Schema(implementation = ErrorDTO.class))) @Path("start") @POST @Consumes(MediaType.APPLICATION_JSON) @@ -127,12 +122,10 @@ public class ProjectResource { } @Operation(summary = "Stop project", tags = "project") - @ApiResponses({ - @ApiResponse(responseCode = "202", description = "Project is stopping"), - @ApiResponse(responseCode = "400", description = "Validation error", content = @Content(mediaType = - MediaType.APPLICATION_JSON, - schema = @Schema(implementation = ErrorDTO.class))) - }) + @ApiResponse(responseCode = "202", description = "Project is stopping") + @ApiResponse(responseCode = "400", description = "Validation error", content = @Content(mediaType = + MediaType.APPLICATION_JSON, + schema = @Schema(implementation = ErrorDTO.class))) @Path("stop") @POST @Consumes(MediaType.APPLICATION_JSON) @@ -146,14 +139,12 @@ public class ProjectResource { } @Operation(summary = "Get project info", tags = "project") - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "Return information about project", - content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = - @Schema(implementation = ProjectDTO.class))), - @ApiResponse(responseCode = "404", description = "Project with passed name not found", - content = @Content(mediaType = MediaType.APPLICATION_JSON, - schema = @Schema(implementation = ErrorDTO.class))) - }) + @ApiResponse(responseCode = "200", description = "Return information about project", + content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = + @Schema(implementation = ProjectDTO.class))) + @ApiResponse(responseCode = "404", description = "Project with passed name not found", + content = @Content(mediaType = MediaType.APPLICATION_JSON, + schema = @Schema(implementation = ErrorDTO.class))) @GET @Path("{name}") @Produces(MediaType.APPLICATION_JSON) @@ -167,11 +158,9 @@ public class ProjectResource { } @Operation(summary = "Get available projects", tags = "project") - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "Return information about projects", - content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = - @Schema(implementation = ProjectDTO.class))), - }) + @ApiResponse(responseCode = "200", description = "Return information about projects", + content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = + @Schema(implementation = ProjectDTO.class))) @GET @Produces(MediaType.APPLICATION_JSON) @RolesAllowed("/api/project") @@ -182,11 +171,9 @@ public class ProjectResource { } @Operation(summary = "Get projects assigned to user", tags = "project") - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "Return information about projects", - content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = - @Schema(implementation = ProjectDTO.class))), - }) + @ApiResponse(responseCode = "200", description = "Return information about projects", + content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = + @Schema(implementation = ProjectDTO.class))) @GET @Path("/me") @Produces(MediaType.APPLICATION_JSON) @@ -198,15 +185,13 @@ public class ProjectResource { } @Operation(summary = "Update project", tags = "project") - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "Project is successfully updated"), - @ApiResponse(responseCode = "400", description = "Validation error", content = @Content(mediaType = - MediaType.APPLICATION_JSON, - schema = @Schema(implementation = ErrorDTO.class))), - @ApiResponse(responseCode = "404", description = "Project with passed name not found", - content = @Content(mediaType = MediaType.APPLICATION_JSON, - schema = @Schema(implementation = ErrorDTO.class))) - }) + @ApiResponse(responseCode = "200", description = "Project is successfully updated") + @ApiResponse(responseCode = "400", description = "Validation error", content = @Content(mediaType = + MediaType.APPLICATION_JSON, + schema = @Schema(implementation = ErrorDTO.class))) + @ApiResponse(responseCode = "404", description = "Project with passed name not found", + content = @Content(mediaType = MediaType.APPLICATION_JSON, + schema = @Schema(implementation = ErrorDTO.class))) @PUT @RolesAllowed("/api/project") public Response updateProject(@Parameter(hidden = true) @Auth UserInfo userInfo, UpdateProjectDTO projectDTO) { @@ -215,12 +200,10 @@ public class ProjectResource { } @Operation(summary = "Remove project", tags = "project") - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "Project is successfully removed"), - @ApiResponse(responseCode = "404", description = "Project with passed name not found", - content = @Content(mediaType = MediaType.APPLICATION_JSON, - schema = @Schema(implementation = ErrorDTO.class))) - }) + @ApiResponse(responseCode = "200", description = "Project is successfully removed") + @ApiResponse(responseCode = "404", description = "Project with passed name not found", + content = @Content(mediaType = MediaType.APPLICATION_JSON, + schema = @Schema(implementation = ErrorDTO.class))) @POST @Path("terminate") @RolesAllowed("/api/project") @@ -231,13 +214,11 @@ public class ProjectResource { } @Operation(summary = "Updates project budget", tags = "project") - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "Project budget is successfully updated"), - @ApiResponse(responseCode = "404", description = "Project with specified name not found"), - @ApiResponse(responseCode = "400", description = "Validation error", - content = @Content(mediaType = MediaType.APPLICATION_JSON, - schema = @Schema(implementation = ErrorDTO.class))) - }) + @ApiResponse(responseCode = "200", description = "Project budget is successfully updated") + @ApiResponse(responseCode = "404", description = "Project with specified name not found") + @ApiResponse(responseCode = "400", description = "Validation error", + content = @Content(mediaType = MediaType.APPLICATION_JSON, + schema = @Schema(implementation = ErrorDTO.class))) @PUT @Path("/budget") @RolesAllowed("/api/project") @@ -249,9 +230,7 @@ public class ProjectResource { } @Operation(summary = "Generate keys for project", tags = "project") - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "Keys are successfully generated") - }) + @ApiResponse(responseCode = "200", description = "Keys are successfully generated") @POST @Path("/keys") @Consumes(MediaType.APPLICATION_JSON) --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@dlab.apache.org For additional commands, e-mail: commits-h...@dlab.apache.org