-
Notifications
You must be signed in to change notification settings - Fork 1
Chore/project service #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
2a626d1
Add project service module with key generation and existence checks
angelmp01 77a4dd8
Bump version to 0.0.3 in pom.xml for all modules
angelmp01 e6fd774
Rename external service project files and update artifactId in pom.xml
angelmp01 059a5d3
Add API module for project management with create and retrieve functi…
angelmp01 bd6f019
Update API base path to /api/pub/v0 and refactor ProjectServiceImpl c…
angelmp01 ef84f80
Add database module with Liquibase integration and JPA Repository
jorge-romero e53a810
Add API module for project management with create and retrieve functi…
angelmp01 8760581
Refactor project service integration tests and enhance response handling
angelmp01 54dd88f
Update API base path in integration tests to /api/pub/v0 and add new …
angelmp01 6fd0367
Add Spring Boot DevTools dependency for improved development experience
angelmp01 fbd572d
Add project service implementation with create and retrieve functiona…
angelmp01 2099073
Refactor MapStruct versioning in pom.xml and update ProjectServiceImp…
angelmp01 82279e1
Remove unused test for external service calls in ProjectServiceImplTest
angelmp01 8ffa571
Add JPA configuration to DevstackApiServiceApplication and remove fro…
angelmp01 1d81b0f
Refactor project request and response models, update mappings, and ad…
angelmp01 40af2da
Add projectFlavor field to response models, update error handling, an…
angelmp01 1f4441c
Refactor project response handling to include location header and imp…
angelmp01 632c387
Add ErrorKey enum for standardized error handling in project responses
angelmp01 5473269
Refactor ErrorKey enum to use ErrorMessage constants for improved err…
angelmp01 b3f6406
Prevent instantiation of ErrorMessage class by making the constructor…
angelmp01 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
40 changes: 26 additions & 14 deletions
40
.../src/main/java/org/opendevstack/apiservice/project/controller/ProjectResponseFactory.java
This file contains hidden or 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 |
|---|---|---|
| @@ -1,38 +1,50 @@ | ||
| package org.opendevstack.apiservice.project.controller; | ||
|
|
||
| import org.opendevstack.apiservice.project.exception.ErrorKey; | ||
| import org.opendevstack.apiservice.project.model.CreateProjectResponse; | ||
|
|
||
| public final class ProjectResponseFactory { | ||
|
|
||
| private static final String INTERNAL_ERROR = "INTERNAL_ERROR"; | ||
|
|
||
| private ProjectResponseFactory() { | ||
| } | ||
|
|
||
| public static CreateProjectResponse conflict(String message) { | ||
| return error("CONFLICT", "PROJECT_ALREADY_EXISTS", message); | ||
| public static CreateProjectResponse conflict(String message, String location) { | ||
| return error( | ||
| ErrorKey.PROJECT_ALREADY_EXISTS.getMessage(), | ||
| ErrorKey.PROJECT_ALREADY_EXISTS.getKey(), | ||
| message, location); | ||
| } | ||
|
|
||
| public static CreateProjectResponse projectKeyGenerationFailed() { | ||
| return error(INTERNAL_ERROR, "PROJECT_KEY_GENERATION_FAILED", | ||
| "Failed to generate a unique project key."); | ||
| public static CreateProjectResponse projectKeyGenerationFailed(String location) { | ||
| return error(ErrorKey.INTERNAL_ERROR.getMessage(), | ||
| "PROJECT_KEY_GENERATION_FAILED", | ||
| "Failed to generate a unique project key.", | ||
| location); | ||
| } | ||
|
|
||
| public static CreateProjectResponse notFound(String projectKey) { | ||
| return error("NOT_FOUND", "PROJECT_NOT_FOUND", | ||
| String.format("Project with key '%s' not found", projectKey)); | ||
| public static CreateProjectResponse notFound(String projectKey, String location) { | ||
| return error( | ||
| ErrorKey.PROJECT_NOT_FOUND.getMessage(), | ||
| ErrorKey.PROJECT_NOT_FOUND.getKey(), | ||
| String.format("Project with key '%s' not found", projectKey), | ||
| location | ||
| ); | ||
| } | ||
|
|
||
| public static CreateProjectResponse internalError() { | ||
| return error(INTERNAL_ERROR, INTERNAL_ERROR, | ||
| "An error occurred while processing the request."); | ||
| public static CreateProjectResponse internalError(String location) { | ||
| return error( | ||
| ErrorKey.INTERNAL_ERROR.getMessage(), | ||
| ErrorKey.INTERNAL_ERROR.getKey(), | ||
| "An error occurred while processing the request.", | ||
| location); | ||
| } | ||
|
|
||
| private static CreateProjectResponse error(String error, String errorKey, String message) { | ||
| private static CreateProjectResponse error(String error, String errorKey, String message, String location) { | ||
| CreateProjectResponse response = new CreateProjectResponse(); | ||
| response.setError(error); | ||
| response.setErrorKey(errorKey); | ||
| response.setMessage(message); | ||
| response.setLocation(location); | ||
| return response; | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
api-project/src/main/java/org/opendevstack/apiservice/project/exception/ErrorKey.java
This file contains hidden or 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,48 @@ | ||
| package org.opendevstack.apiservice.project.exception; | ||
|
|
||
| public enum ErrorKey { | ||
|
|
||
| OK("000", "Success"), | ||
| PRODUCT_NOT_FOUND("001", ErrorMessage.NOT_FOUND), | ||
| ACCESS_DENIED("002", ErrorMessage.FORBIDDEN), | ||
| INTERNAL_ERROR("003", "Internal error"), | ||
| INVALID_AUTH_HEADER("004", ErrorMessage.BAD_REQUEST), | ||
| MISSING_AUTH_HEADER("005", ErrorMessage.BAD_REQUEST), | ||
| INVALID_PARAMETERS("006", ErrorMessage.BAD_REQUEST), | ||
| X2_ACCOUNT_MISSING_GROUPS("007", ErrorMessage.NOT_FOUND), | ||
| ONLY_INVITED_PROJECT("008", ErrorMessage.FORBIDDEN), | ||
| ONCE_PER_PROJECT("009", ErrorMessage.FORBIDDEN), | ||
| COMPONENT_PARAM_NOT_MEET_REGEX("010", ErrorMessage.BAD_REQUEST), | ||
| INVALID_LOCATION("011", ErrorMessage.BAD_REQUEST), | ||
| PROJECT_NOT_FOUND("012", ErrorMessage.NOT_FOUND), | ||
| COMPONENT_NOT_FOUND("013", ErrorMessage.NOT_FOUND), | ||
| BAD_REQUEST_BODY("014", ErrorMessage.BAD_REQUEST), | ||
| FORBIDDEN("015", ErrorMessage.FORBIDDEN), | ||
| DUPLICATE_RECORD("016", "Record already exists"), | ||
| COMPONENT_PARAM_INVALID_FORMAT("017", ErrorMessage.BAD_REQUEST), | ||
| PROJECT_KEY_INVALID_FORMAT("018", "projectKey not met the pattern ^[A-Z] {2}[A-Z0-9] {1,8}$"), | ||
| PROJECT_NAME_INVALID_FORMAT("019", "projectName not met the pattern ^[A-Za-z0-9 ] {0,80}$"), | ||
| PROJECT_DESCRIPTION_INVALID_FORMAT("020", "projectDescription not met the pattern ^.{0,255}$"), | ||
| PROJECT_OWNER_INVALID_FORMAT("021", "projectOwner not met the pattern ^[a-z]{1,10}$"), | ||
| PROJECT_X2ACCOUNT_INVALID_FORMAT("022", "projectX2Account not met the pattern ^x2[a-zA-Z0-9]{0,13}$"), | ||
| BAD_REQUEST_FLAVOR_CONFIG_ITEM("023", "Project flavour and config item cannot be both null"), | ||
| MANDATORY_OWNER("024", "Owner must be present if the X2 account is present"), | ||
| PROJECT_ALREADY_EXISTS("025", "Project already exists"), | ||
| PROJECT_SAME_PROJECT_NAME_ALREADY_EXISTS("026", "Project with same project name already exists"); | ||
|
|
||
| private String key; | ||
| private String message; | ||
|
|
||
| ErrorKey(String key, String message) { | ||
| this.key = key; | ||
| this.message = message; | ||
| } | ||
|
|
||
| public String getKey() { | ||
| return this.key; | ||
| } | ||
|
|
||
| public String getMessage() { | ||
| return this.message; | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
api-project/src/main/java/org/opendevstack/apiservice/project/exception/ErrorMessage.java
This file contains hidden or 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,12 @@ | ||
| package org.opendevstack.apiservice.project.exception; | ||
|
|
||
| public class ErrorMessage { | ||
|
|
||
| public static final String NOT_FOUND = "Not Found"; | ||
| public static final String FORBIDDEN = "Forbidden"; | ||
| public static final String BAD_REQUEST = "Bad Request"; | ||
|
|
||
| private ErrorMessage() { | ||
| // prevent instantiation | ||
| } | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
46 changes: 40 additions & 6 deletions
46
api-project/src/main/java/org/opendevstack/apiservice/project/mapper/ProjectMapper.java
This file contains hidden or 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 |
|---|---|---|
| @@ -1,15 +1,49 @@ | ||
| package org.opendevstack.apiservice.project.mapper; | ||
|
|
||
| import org.mapstruct.Mapper; | ||
| import org.mapstruct.Mapping; | ||
| import org.mapstruct.Named; | ||
| import org.opendevstack.apiservice.project.model.CreateProjectRequest; | ||
| import org.opendevstack.apiservice.project.model.CreateProjectResponse; | ||
| import org.opendevstack.apiservice.serviceproject.model.ProjectRequest; | ||
| import org.opendevstack.apiservice.serviceproject.model.ProjectResponse; | ||
| import org.opendevstack.apiservice.serviceproject.model.Status; | ||
|
|
||
| import java.text.MessageFormat; | ||
|
|
||
| @Mapper(componentModel = "spring") | ||
| public interface ProjectMapper { | ||
|
|
||
| org.opendevstack.apiservice.serviceproject.model.CreateProjectRequest toServiceRequest( | ||
| CreateProjectRequest apiRequest); | ||
|
|
||
| CreateProjectResponse toApiResponse( | ||
| org.opendevstack.apiservice.serviceproject.model.CreateProjectResponse serviceResponse); | ||
|
|
||
| ProjectRequest toServiceRequest(CreateProjectRequest apiRequest); | ||
|
|
||
| @Mapping(source = "status", target = "status", qualifiedByName = "mapStatus") | ||
| @Mapping(source = "projectKey", target = "location", qualifiedByName = "mapLocation") | ||
| @Mapping(source = ".", target = "errorDescription", qualifiedByName = "mapErrorDescription") | ||
| CreateProjectResponse toApiResponse(ProjectResponse serviceResponse); | ||
|
|
||
| @Named("mapStatus") | ||
| default String mapStatus(Status status) { | ||
| if (status == null) { | ||
| return null; | ||
| } | ||
| return status.getDbValue(); | ||
| } | ||
|
|
||
| @Named("mapErrorDescription") | ||
| default String mapErrorDescription(ProjectResponse serviceResponse) { | ||
| return (serviceResponse.getStatus() == Status.FAILED) | ||
| ? MessageFormat.format( | ||
| "There was an error when creating the project {0}.\n\n " + | ||
| "The error has been reported to our Support team as an incident. " + | ||
| "You will be informed about the incident via email.", serviceResponse.getProjectKey()) | ||
|
Check warning on line 38 in api-project/src/main/java/org/opendevstack/apiservice/project/mapper/ProjectMapper.java
|
||
| : null; | ||
| } | ||
|
|
||
| @Named("mapLocation") | ||
| default String mapLocation(String projectKey) { | ||
| if (projectKey == null || projectKey.isEmpty()) { | ||
| return null; | ||
| } | ||
| return "/api/pub/v0/projects/" + projectKey; | ||
| } | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like this is more close to the use of MapStuct
package org.opendevstack.apiservice.project.mapper;
import org.apache.commons.lang3.StringUtils;
import org.mapstruct.*;
import org.opendevstack.apiservice.project.model.CreateProjectRequest;
import org.opendevstack.apiservice.project.model.CreateProjectResponse;
import org.opendevstack.apiservice.serviceproject.model.ProjectRequest;
import org.opendevstack.apiservice.serviceproject.model.ProjectResponse;
@Mapper(
componentModel = "spring",
unmappedTargetPolicy = ReportingPolicy.ERROR,
nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS
)
public interface ProjectMapper {
}