diff --git a/src/main/java/com/epam/reportportal/auth/AuthConfigService.java b/src/main/java/com/epam/reportportal/auth/AuthConfigService.java index 191ed59c..edfc004e 100644 --- a/src/main/java/com/epam/reportportal/auth/AuthConfigService.java +++ b/src/main/java/com/epam/reportportal/auth/AuthConfigService.java @@ -109,18 +109,18 @@ public OAuth2ProtectedResourceDetails loadResourceDetails(String name) { */ private static final Function RESOURCE_DETAILS_CONVERTER = d -> { - BaseOAuth2ProtectedResourceDetails details = getOauth2ProtectedResourceDetails(d); - details.setId(d.getId()); - details.setAccessTokenUri(d.getTokenUri()); - Arrays.stream(AuthenticationScheme.values()) - .filter(scheme -> scheme.name().equalsIgnoreCase(d.getClientAuthMethod())) - .findFirst() - .ifPresent(details::setClientAuthenticationScheme); - details.setClientId(d.getClientId()); - details.setClientSecret(d.getClientSecret()); - details.setScope(new ArrayList<>(d.getScopes())); - return details; - }; + BaseOAuth2ProtectedResourceDetails details = getOauth2ProtectedResourceDetails(d); + details.setId(d.getId()); + details.setAccessTokenUri(d.getTokenUri()); + Arrays.stream(AuthenticationScheme.values()) + .filter(scheme -> scheme.name().equalsIgnoreCase(d.getClientAuthMethod())) + .findFirst() + .ifPresent(details::setClientAuthenticationScheme); + details.setClientId(d.getClientId()); + details.setClientSecret(d.getClientSecret()); + details.setScope(new ArrayList<>(d.getScopes())); + return details; + }; private static BaseOAuth2ProtectedResourceDetails getOauth2ProtectedResourceDetails( OAuthRegistrationResource oAuthRegistrationResource) { diff --git a/src/main/java/com/epam/reportportal/auth/commons/ThumbnailatorImpl.java b/src/main/java/com/epam/reportportal/auth/commons/ThumbnailatorImpl.java index 8e4b7405..47aef468 100644 --- a/src/main/java/com/epam/reportportal/auth/commons/ThumbnailatorImpl.java +++ b/src/main/java/com/epam/reportportal/auth/commons/ThumbnailatorImpl.java @@ -28,8 +28,8 @@ import net.coobird.thumbnailator.Thumbnails; /** - * Thumbnailator implementation using Thumbnailator - * API + * Thumbnailator implementation. Using Thumbnailator API. * * @author Andrei Varabyeu */ diff --git a/src/main/java/com/epam/reportportal/auth/config/SecurityConfiguration.java b/src/main/java/com/epam/reportportal/auth/config/SecurityConfiguration.java index 30c7f9de..6838bf72 100644 --- a/src/main/java/com/epam/reportportal/auth/config/SecurityConfiguration.java +++ b/src/main/java/com/epam/reportportal/auth/config/SecurityConfiguration.java @@ -239,19 +239,19 @@ protected final void configure(HttpSecurity http) throws Exception { authCompositeFilter.setFilters(additionalFilters); http - .antMatcher("/**") - .authorizeRequests() - .antMatchers(SSO_LOGIN_PATH - + "/**", "/epam/**", "/info", "/health", "/api-docs/**", "/saml/**", "/templates/**") - .permitAll() - .anyRequest() - .authenticated() - .and() - .csrf().disable() - .formLogin().disable() - .sessionManagement() - .sessionCreationPolicy(SessionCreationPolicy.STATELESS) - .and() + .antMatcher("/**") + .authorizeRequests() + .antMatchers(SSO_LOGIN_PATH + + "/**", "/epam/**", "/info", "/health", "/api-docs/**", "/saml/**", "/templates/**") + .permitAll() + .anyRequest() + .authenticated() + .and() + .csrf().disable() + .formLogin().disable() + .sessionManagement() + .sessionCreationPolicy(SessionCreationPolicy.STATELESS) + .and() .addFilterAfter(authCompositeFilter, BasicAuthenticationFilter.class); } @@ -281,7 +281,6 @@ public AuthenticationEventPublisher authenticationEventPublisher( } - @Bean public AuthenticationProvider activeDirectoryAuthProvider() { return new ActiveDirectoryAuthProvider(authConfigRepository, eventPublisher, diff --git a/src/main/java/com/epam/reportportal/auth/config/SpringDocConfiguration.java b/src/main/java/com/epam/reportportal/auth/config/SpringDocConfiguration.java index cb343b1b..b6fa919f 100644 --- a/src/main/java/com/epam/reportportal/auth/config/SpringDocConfiguration.java +++ b/src/main/java/com/epam/reportportal/auth/config/SpringDocConfiguration.java @@ -113,6 +113,6 @@ public OpenApiCustomiser sortTagsAlphabetically() { } private String getPathValue() { - return StringUtils.isEmpty(pathValue) || pathValue.equals("/") ? "/uat" : pathValue; + return StringUtils.isEmpty(pathValue) || pathValue.equals("/") ? "/uat" : pathValue; } } diff --git a/src/main/java/com/epam/reportportal/auth/dao/ReportPortalRepository.java b/src/main/java/com/epam/reportportal/auth/dao/ReportPortalRepository.java index 38fb34a9..6fa57718 100644 --- a/src/main/java/com/epam/reportportal/auth/dao/ReportPortalRepository.java +++ b/src/main/java/com/epam/reportportal/auth/dao/ReportPortalRepository.java @@ -25,6 +25,7 @@ */ @NoRepositoryBean public interface ReportPortalRepository extends JpaRepository { + void refresh(T t); } diff --git a/src/main/java/com/epam/reportportal/auth/endpoint/AuthConfigurationEndpoint.java b/src/main/java/com/epam/reportportal/auth/endpoint/AuthConfigurationEndpoint.java index 05cfee91..9191560c 100644 --- a/src/main/java/com/epam/reportportal/auth/endpoint/AuthConfigurationEndpoint.java +++ b/src/main/java/com/epam/reportportal/auth/endpoint/AuthConfigurationEndpoint.java @@ -69,10 +69,10 @@ public AuthConfigurationEndpoint(CreateAuthIntegrationHandler createAuthIntegrat /** * Creates or updates auth integration settings. * - * @param request Update request + * @param request Update request * @param authType Type of Auth - * @param user User - * @return Successful message or an error + * @param user User + * @return Successful message or an error */ @Transactional @PostMapping(value = "/{authType}") @@ -87,9 +87,9 @@ public AbstractAuthResource createAuthIntegration(@RequestBody @Valid UpdateAuth /** * Creates or updates auth integration settings * - * @param request Update request - * @param authType Type of Auth - * @param user User + * @param request Update request + * @param authType Type of Auth + * @param user User * @param integrationId Integration ID * @return Successful message or an error */ diff --git a/src/main/java/com/epam/reportportal/auth/endpoint/OAuthConfigurationEndpoint.java b/src/main/java/com/epam/reportportal/auth/endpoint/OAuthConfigurationEndpoint.java index d37b59bd..d0f3fe61 100644 --- a/src/main/java/com/epam/reportportal/auth/endpoint/OAuthConfigurationEndpoint.java +++ b/src/main/java/com/epam/reportportal/auth/endpoint/OAuthConfigurationEndpoint.java @@ -71,7 +71,7 @@ public OAuthConfigurationEndpoint(CreateAuthIntegrationHandler createAuthIntegra * Updates oauth integration settings * * @param clientRegistrationResource OAuth configuration - * @param oauthProviderId Oauth settings Profile Id + * @param oauthProviderId Oauth settings Profile Id * @return All defined OAuth integration settings */ @Transactional diff --git a/src/main/java/com/epam/reportportal/auth/entity/attachment/BinaryData.java b/src/main/java/com/epam/reportportal/auth/entity/attachment/BinaryData.java index c1a0ecce..7d49818f 100644 --- a/src/main/java/com/epam/reportportal/auth/entity/attachment/BinaryData.java +++ b/src/main/java/com/epam/reportportal/auth/entity/attachment/BinaryData.java @@ -24,53 +24,54 @@ import org.springframework.web.multipart.MultipartFile; /** - * Binary data representation. Contains only input stream and data type. - * Introduced to simplify store/retrieve operations + * Binary data representation. Contains only input stream and data type. Introduced to simplify + * store/retrieve operations * * @author Andrei Varabyeu */ @Getter public class BinaryData { - private String fileName; + private String fileName; - /** - * MIME Type of Binary Data - */ - private final String contentType; + /** + * MIME Type of Binary Data + */ + private final String contentType; - /** - * Data Stream - */ - private final InputStream inputStream; + /** + * Data Stream + */ + private final InputStream inputStream; - /** - * Content length - */ - private final Long length; + /** + * Content length + */ + private final Long length; - public BinaryData(String contentType, Long length, InputStream inputStream) { - this.contentType = contentType; - this.inputStream = inputStream; - this.length = length; - } + public BinaryData(String contentType, Long length, InputStream inputStream) { + this.contentType = contentType; + this.inputStream = inputStream; + this.length = length; + } - public BinaryData(String fileName, String contentType, Long length, InputStream inputStream) { - this.fileName = fileName; - this.contentType = contentType; - this.length = length; - this.inputStream = inputStream; - } + public BinaryData(String fileName, String contentType, Long length, InputStream inputStream) { + this.fileName = fileName; + this.contentType = contentType; + this.length = length; + this.inputStream = inputStream; + } - public BinaryData(MultipartFile multipartFile) { - this.contentType = multipartFile.getContentType(); - this.length = multipartFile.getSize(); + public BinaryData(MultipartFile multipartFile) { + this.contentType = multipartFile.getContentType(); + this.length = multipartFile.getSize(); - try { - this.inputStream = multipartFile.getInputStream(); - } catch (IOException e) { - throw new ReportPortalException(ErrorType.INCORRECT_REQUEST, "Unable to create binary data from multipart file"); - } - } + try { + this.inputStream = multipartFile.getInputStream(); + } catch (IOException e) { + throw new ReportPortalException(ErrorType.INCORRECT_REQUEST, + "Unable to create binary data from multipart file"); + } + } } diff --git a/src/main/java/com/epam/reportportal/auth/entity/enums/ProjectAttributeEnum.java b/src/main/java/com/epam/reportportal/auth/entity/enums/ProjectAttributeEnum.java index f91fa18f..cbb4c498 100644 --- a/src/main/java/com/epam/reportportal/auth/entity/enums/ProjectAttributeEnum.java +++ b/src/main/java/com/epam/reportportal/auth/entity/enums/ProjectAttributeEnum.java @@ -48,7 +48,8 @@ public enum ProjectAttributeEnum { AUTO_PATTERN_ANALYZER_ENABLED(Prefix.ANALYZER + "isAutoPatternAnalyzerEnabled", String.valueOf(false)), AUTO_ANALYZER_ENABLED(Prefix.ANALYZER + "isAutoAnalyzerEnabled", String.valueOf(true)), - AUTO_ANALYZER_MODE(Prefix.ANALYZER + "autoAnalyzerMode", AnalyzeMode.CURRENT_AND_THE_SAME_NAME.getValue()), + AUTO_ANALYZER_MODE(Prefix.ANALYZER + "autoAnalyzerMode", + AnalyzeMode.CURRENT_AND_THE_SAME_NAME.getValue()), ALL_MESSAGES_SHOULD_MATCH(Prefix.ANALYZER + "allMessagesShouldMatch", String.valueOf(false)), SEARCH_LOGS_MIN_SHOULD_MATCH(Prefix.ANALYZER + "searchLogsMinShouldMatch", String.valueOf(ProjectAnalyzerConfig.MIN_SHOULD_MATCH)), diff --git a/src/main/java/com/epam/reportportal/auth/event/UiAuthenticationSuccessEventHandler.java b/src/main/java/com/epam/reportportal/auth/event/UiAuthenticationSuccessEventHandler.java index 10586918..7775cfdf 100644 --- a/src/main/java/com/epam/reportportal/auth/event/UiAuthenticationSuccessEventHandler.java +++ b/src/main/java/com/epam/reportportal/auth/event/UiAuthenticationSuccessEventHandler.java @@ -57,9 +57,9 @@ public UiAuthenticationSuccessEventHandler(UserRepository userRepository, } /** - * Handles the UI user signed-in event. Updates the last login date for the user - * and generates a personal project if the user has no projects. - * Also, if the user is inactive, it will be activated for SAML authentication. + * Handles the UI user signed-in event. Updates the last login date for the user and generates a + * personal project if the user has no projects. Also, if the user is inactive, it will be + * activated for SAML authentication. * * @param event the UI user signed-in event */ diff --git a/src/main/java/com/epam/reportportal/auth/integration/converter/SamlConverter.java b/src/main/java/com/epam/reportportal/auth/integration/converter/SamlConverter.java index c976b901..895170f9 100644 --- a/src/main/java/com/epam/reportportal/auth/integration/converter/SamlConverter.java +++ b/src/main/java/com/epam/reportportal/auth/integration/converter/SamlConverter.java @@ -67,21 +67,22 @@ public class SamlConverter { resource.setIdentityProviderName(integration.getName()); resource.setEnabled(integration.isEnabled()); - EMAIL_ATTRIBUTE.getParameter(integration).ifPresent(resource::setEmailAttribute); - FIRST_NAME_ATTRIBUTE.getParameter(integration).ifPresent(resource::setFirstNameAttribute); - LAST_NAME_ATTRIBUTE.getParameter(integration).ifPresent(resource::setLastNameAttribute); - FULL_NAME_ATTRIBUTE.getParameter(integration).ifPresent(resource::setFullNameAttribute); - IDP_ALIAS.getParameter(integration).ifPresent(resource::setIdentityProviderAlias); - IDP_METADATA_URL.getParameter(integration).ifPresent(resource::setIdentityProviderMetadataUrl); - IDP_URL.getParameter(integration).ifPresent(resource::setIdentityProviderUrl); - IDP_NAME_ID.getParameter(integration).ifPresent(resource::setIdentityProviderNameId); - ROLES_ATTRIBUTE.getParameter(integration).ifPresent(resource::setRolesAttribute); - final IntegrationType integrationType = integration.getType(); - ofNullable(integrationType.getDetails()).flatMap(typeDetails -> Optional.ofNullable(typeDetails.getDetails())) - .flatMap(BASE_PATH::getParameter) - .ifPresent(resource::setCallbackUrl); - return resource; - }; + EMAIL_ATTRIBUTE.getParameter(integration).ifPresent(resource::setEmailAttribute); + FIRST_NAME_ATTRIBUTE.getParameter(integration).ifPresent(resource::setFirstNameAttribute); + LAST_NAME_ATTRIBUTE.getParameter(integration).ifPresent(resource::setLastNameAttribute); + FULL_NAME_ATTRIBUTE.getParameter(integration).ifPresent(resource::setFullNameAttribute); + IDP_ALIAS.getParameter(integration).ifPresent(resource::setIdentityProviderAlias); + IDP_METADATA_URL.getParameter(integration).ifPresent(resource::setIdentityProviderMetadataUrl); + IDP_URL.getParameter(integration).ifPresent(resource::setIdentityProviderUrl); + IDP_NAME_ID.getParameter(integration).ifPresent(resource::setIdentityProviderNameId); + ROLES_ATTRIBUTE.getParameter(integration).ifPresent(resource::setRolesAttribute); + final IntegrationType integrationType = integration.getType(); + ofNullable(integrationType.getDetails()).flatMap( + typeDetails -> Optional.ofNullable(typeDetails.getDetails())) + .flatMap(BASE_PATH::getParameter) + .ifPresent(resource::setCallbackUrl); + return resource; + }; public static final Function, List> TO_EXTERNAL_PROVIDER_CONFIG = integrations -> { List externalProviders = integrations.stream() diff --git a/src/main/java/com/epam/reportportal/auth/integration/github/GitHubClient.java b/src/main/java/com/epam/reportportal/auth/integration/github/GitHubClient.java index 0f905ec6..01272ce8 100644 --- a/src/main/java/com/epam/reportportal/auth/integration/github/GitHubClient.java +++ b/src/main/java/com/epam/reportportal/auth/integration/github/GitHubClient.java @@ -82,7 +82,8 @@ public List getUserEmails() { public List getUserOrganizations(String user) { return getForObject(GITHUB_BASE_URL + "/user/orgs", - new ParameterizedTypeReference<>() {}, + new ParameterizedTypeReference<>() { + }, user); } diff --git a/src/main/java/com/epam/reportportal/auth/integration/handler/impl/GetAuthIntegrationHandlerImpl.java b/src/main/java/com/epam/reportportal/auth/integration/handler/impl/GetAuthIntegrationHandlerImpl.java index e69221c3..7fe8fb59 100644 --- a/src/main/java/com/epam/reportportal/auth/integration/handler/impl/GetAuthIntegrationHandlerImpl.java +++ b/src/main/java/com/epam/reportportal/auth/integration/handler/impl/GetAuthIntegrationHandlerImpl.java @@ -80,8 +80,9 @@ public ResponseEntity getOauthIntegrationById(String .orElseGet(() -> { ExtendedOAuthRegistrationResource body = new ExtendedOAuthRegistrationResource(); body.setErrorCode(ErrorType.AUTH_INTEGRATION_NOT_FOUND.getCode()); - body.setMessage(Suppliers.formattedSupplier("Oauth settings with id = {} have not been found.", - oauthProviderId).get() + body.setMessage( + Suppliers.formattedSupplier("Oauth settings with id = {} have not been found.", + oauthProviderId).get() ); return new ResponseEntity<>(body, HttpStatus.NOT_FOUND); }); diff --git a/src/main/java/com/epam/reportportal/auth/integration/parameter/ParameterUtils.java b/src/main/java/com/epam/reportportal/auth/integration/parameter/ParameterUtils.java index f2423c9f..cbb804a1 100644 --- a/src/main/java/com/epam/reportportal/auth/integration/parameter/ParameterUtils.java +++ b/src/main/java/com/epam/reportportal/auth/integration/parameter/ParameterUtils.java @@ -46,14 +46,14 @@ public static void setLdapParameters(UpdateAuthRQ request, Integration integrati Arrays.stream(LdapParameter.values()).forEach(it -> it.setParameter(request, integration)); } - public static void setSamlParameters(UpdateAuthRQ request, Integration integration) { - IDP_NAME.setParameter(request, integration); - IDP_METADATA_URL.setParameter(request, integration); - EMAIL_ATTRIBUTE.setParameter(request, integration); - IDP_NAME_ID.setParameter(request, integration); - IDP_ALIAS.setParameter(request, integration); - IDP_URL.setParameter(request, integration); - ROLES_ATTRIBUTE.setParameter(request, integration); + public static void setSamlParameters(UpdateAuthRQ request, Integration integration) { + IDP_NAME.setParameter(request, integration); + IDP_METADATA_URL.setParameter(request, integration); + EMAIL_ATTRIBUTE.setParameter(request, integration); + IDP_NAME_ID.setParameter(request, integration); + IDP_ALIAS.setParameter(request, integration); + IDP_URL.setParameter(request, integration); + ROLES_ATTRIBUTE.setParameter(request, integration); FULL_NAME_ATTRIBUTE.getParameter(request).ifPresentOrElse(fullName -> { FIRST_NAME_ATTRIBUTE.removeParameter(integration); diff --git a/src/main/java/com/epam/reportportal/auth/integration/parameter/SamlParameter.java b/src/main/java/com/epam/reportportal/auth/integration/parameter/SamlParameter.java index 40fb65b3..13cf9d04 100644 --- a/src/main/java/com/epam/reportportal/auth/integration/parameter/SamlParameter.java +++ b/src/main/java/com/epam/reportportal/auth/integration/parameter/SamlParameter.java @@ -35,17 +35,17 @@ */ public enum SamlParameter { - BASE_PATH("callbackUrl", false), - IDP_NAME("identityProviderName", true), - IDP_METADATA_URL("identityProviderMetadataUrl", true), - EMAIL_ATTRIBUTE("emailAttribute", true), - IDP_NAME_ID("identityProviderNameId", false), - IDP_ALIAS("identityProviderAlias", false), - IDP_URL("identityProviderUrl", false), - FULL_NAME_ATTRIBUTE("fullNameAttribute", false), - FIRST_NAME_ATTRIBUTE("firstNameAttribute", false), - LAST_NAME_ATTRIBUTE("lastNameAttribute", false), - ROLES_ATTRIBUTE("rolesAttribute", false); + BASE_PATH("callbackUrl", false), + IDP_NAME("identityProviderName", true), + IDP_METADATA_URL("identityProviderMetadataUrl", true), + EMAIL_ATTRIBUTE("emailAttribute", true), + IDP_NAME_ID("identityProviderNameId", false), + IDP_ALIAS("identityProviderAlias", false), + IDP_URL("identityProviderUrl", false), + FULL_NAME_ATTRIBUTE("fullNameAttribute", false), + FIRST_NAME_ATTRIBUTE("firstNameAttribute", false), + LAST_NAME_ATTRIBUTE("lastNameAttribute", false), + ROLES_ATTRIBUTE("rolesAttribute", false); private String parameterName; diff --git a/src/main/java/com/epam/reportportal/auth/model/SamlProvidersResource.java b/src/main/java/com/epam/reportportal/auth/model/SamlProvidersResource.java index df228496..0215f410 100644 --- a/src/main/java/com/epam/reportportal/auth/model/SamlProvidersResource.java +++ b/src/main/java/com/epam/reportportal/auth/model/SamlProvidersResource.java @@ -27,6 +27,7 @@ @Getter @JsonInclude(JsonInclude.Include.NON_NULL) public class SamlProvidersResource extends AbstractAuthResource { - @Valid - private List providers; + + @Valid + private List providers; } diff --git a/src/main/java/com/epam/reportportal/auth/model/SamlResource.java b/src/main/java/com/epam/reportportal/auth/model/SamlResource.java index 4bd8658e..3576e741 100644 --- a/src/main/java/com/epam/reportportal/auth/model/SamlResource.java +++ b/src/main/java/com/epam/reportportal/auth/model/SamlResource.java @@ -34,57 +34,57 @@ @JsonInclude(JsonInclude.Include.NON_NULL) public class SamlResource extends AbstractAuthResource { - private Long id; + private Long id; - @JsonProperty(value = "callbackUrl") - private String callbackUrl; + @JsonProperty(value = "callbackUrl") + private String callbackUrl; - /** - * Provider name associated with IDP - */ - @NotEmpty - private String identityProviderName; - /** - * Alias associated with IDP - */ - private String identityProviderAlias; - /** - * IDP metadata URL - */ - @NotEmpty - private String identityProviderMetadataUrl; - /** - * Attribute Name Format Id associated with IDP for user identification - */ - private String identityProviderNameId; - /** - * IDP URL - */ - private String identityProviderUrl; - /** - * Attribute name associated with full name of user in SAML response - */ - private String fullNameAttribute; - /** - * Attribute name associated with first name of user in SAML response - */ - private String firstNameAttribute; - /** - * Attribute name associated with last name of user in SAML response - */ - private String lastNameAttribute; - /** - * Attribute name associated with email of user in SAML response - */ - @NotEmpty - private String emailAttribute; - /** - * Attribute name associated with roles of user in SAML response - */ - private String rolesAttribute; - /** - * Indicates IDP availability for authentication - */ - private boolean enabled; + /** + * Provider name associated with IDP + */ + @NotEmpty + private String identityProviderName; + /** + * Alias associated with IDP + */ + private String identityProviderAlias; + /** + * IDP metadata URL + */ + @NotEmpty + private String identityProviderMetadataUrl; + /** + * Attribute Name Format Id associated with IDP for user identification + */ + private String identityProviderNameId; + /** + * IDP URL + */ + private String identityProviderUrl; + /** + * Attribute name associated with full name of user in SAML response + */ + private String fullNameAttribute; + /** + * Attribute name associated with first name of user in SAML response + */ + private String firstNameAttribute; + /** + * Attribute name associated with last name of user in SAML response + */ + private String lastNameAttribute; + /** + * Attribute name associated with email of user in SAML response + */ + @NotEmpty + private String emailAttribute; + /** + * Attribute name associated with roles of user in SAML response + */ + private String rolesAttribute; + /** + * Indicates IDP availability for authentication + */ + private boolean enabled; } diff --git a/src/main/java/com/epam/reportportal/auth/rules/exception/ErrorRS.java b/src/main/java/com/epam/reportportal/auth/rules/exception/ErrorRS.java index 2647f87a..ee65f80f 100644 --- a/src/main/java/com/epam/reportportal/auth/rules/exception/ErrorRS.java +++ b/src/main/java/com/epam/reportportal/auth/rules/exception/ErrorRS.java @@ -12,7 +12,7 @@ * 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 com.epam.reportportal.auth.rules.exception; @@ -37,89 +37,98 @@ /** * Base Error response body for all Report Portal exceptions - * + * * @author Andrei Varabyeu - * */ @Setter @Getter -@JsonPropertyOrder({ "errorCode", "message", "stackTrace" }) +@JsonPropertyOrder({"errorCode", "message", "stackTrace"}) @JsonInclude(Include.NON_NULL) public class ErrorRS implements Serializable { - /** - * Generated SVUID - */ - private static final long serialVersionUID = -3717290684860161862L; - @JsonSerialize(using = ErrorTypeSerializer.class) - @JsonDeserialize(using = ErrorTypeDeserializer.class) - @JsonProperty("errorCode") - private ErrorType errorType; + /** + * Generated SVUID + */ + private static final long serialVersionUID = -3717290684860161862L; + + @JsonSerialize(using = ErrorTypeSerializer.class) + @JsonDeserialize(using = ErrorTypeDeserializer.class) + @JsonProperty("errorCode") + private ErrorType errorType; + + @JsonProperty("stackTrace") + private String stackTrace; - @JsonProperty("stackTrace") - private String stackTrace; + @JsonProperty("message") + private String message; - @JsonProperty("message") - private String message; + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((errorType == null) ? 0 : errorType.hashCode()); + result = prime * result + ((message == null) ? 0 : message.hashCode()); + result = prime * result + ((stackTrace == null) ? 0 : stackTrace.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + ErrorRS other = (ErrorRS) obj; + if (errorType != other.errorType) { + return false; + } + if (message == null) { + if (other.message != null) { + return false; + } + } else if (!message.equals(other.message)) { + return false; + } + if (stackTrace == null) { + return other.stackTrace == null; + } else { + return stackTrace.equals(other.stackTrace); + } + } + + private static class ErrorTypeDeserializer extends JsonDeserializer { + + @Override + public ErrorType deserialize(JsonParser parser, DeserializationContext context) + throws IOException { + ObjectCodec oc = parser.getCodec(); + JsonNode node = oc.readTree(parser); + return ErrorType.getByCode(node.asInt()); + + } + + } + + private static class ErrorTypeSerializer extends JsonSerializer { + + @Override + public void serialize(ErrorType error, JsonGenerator jsonGenerator, + SerializerProvider serializerProvider) throws IOException { + jsonGenerator.writeNumber(error.getCode()); + } + + } @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((errorType == null) ? 0 : errorType.hashCode()); - result = prime * result + ((message == null) ? 0 : message.hashCode()); - result = prime * result + ((stackTrace == null) ? 0 : stackTrace.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - ErrorRS other = (ErrorRS) obj; - if (errorType != other.errorType) - return false; - if (message == null) { - if (other.message != null) - return false; - } else if (!message.equals(other.message)) - return false; - if (stackTrace == null) { - return other.stackTrace == null; - } else - return stackTrace.equals(other.stackTrace); - } - - private static class ErrorTypeDeserializer extends JsonDeserializer { - - @Override - public ErrorType deserialize(JsonParser parser, DeserializationContext context) throws IOException { - ObjectCodec oc = parser.getCodec(); - JsonNode node = oc.readTree(parser); - return ErrorType.getByCode(node.asInt()); - - } - - } - - private static class ErrorTypeSerializer extends JsonSerializer { - - @Override - public void serialize(ErrorType error, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { - jsonGenerator.writeNumber(error.getCode()); - } - - } - - @Override - public String toString() { - return "ErrorRS{" + "errorType=" + errorType - + ", stackTrace='" + stackTrace + '\'' - + ", message='" + message + '\'' - + '}'; - } + public String toString() { + return "ErrorRS{" + "errorType=" + errorType + + ", stackTrace='" + stackTrace + '\'' + + ", message='" + message + '\'' + + '}'; + } }