Skip to content

Commit

Permalink
EPMRPP-90612 || Error in UAT logs when there is no GitHub integration (
Browse files Browse the repository at this point in the history
  • Loading branch information
APiankouski committed Jul 15, 2024
1 parent 7477c9d commit 0a9bb27
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
Expand Down Expand Up @@ -122,7 +123,7 @@ public Map<String, OAuthRegistrationResource> getOAuthSettings() {
@ResponseBody
@ResponseStatus(HttpStatus.OK)
@Operation(summary = "Returns OAuth Server Settings")
public OAuthRegistrationResource getOAuthSettings(
public ResponseEntity<OAuthRegistrationResource> getOAuthSettings(
@PathVariable("authId") String oauthProviderId) {
return getAuthIntegrationHandler.getOauthIntegrationById(oauthProviderId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.epam.reportportal.model.integration.auth.AbstractAuthResource;
import com.epam.reportportal.model.settings.OAuthRegistrationResource;
import java.util.Map;
import org.springframework.http.ResponseEntity;

/**
* @author <a href="mailto:ivan_budayeu@epam.com">Ivan Budayeu</a>
Expand All @@ -30,5 +31,5 @@ public interface GetAuthIntegrationHandler {

Map<String, OAuthRegistrationResource> getAllOauthIntegrations();

OAuthRegistrationResource getOauthIntegrationById(String oauthProviderId);
ResponseEntity<OAuthRegistrationResource> getOauthIntegrationById(String oauthProviderId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.epam.reportportal.auth.integration.converter.OAuthRegistrationConverters;
import com.epam.reportportal.auth.integration.handler.GetAuthIntegrationHandler;
import com.epam.reportportal.auth.integration.handler.GetAuthIntegrationStrategy;
import com.epam.reportportal.auth.model.ExtendedOAuthRegistrationResource;
import com.epam.reportportal.auth.store.MutableClientRegistrationRepository;
import com.epam.reportportal.rules.commons.validation.Suppliers;
import com.epam.reportportal.rules.exception.ReportPortalException;
Expand All @@ -33,6 +34,8 @@
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

/**
Expand Down Expand Up @@ -70,12 +73,17 @@ public Map<String, OAuthRegistrationResource> getAllOauthIntegrations() {
}

@Override
public OAuthRegistrationResource getOauthIntegrationById(String oauthProviderId) {
public ResponseEntity<OAuthRegistrationResource> getOauthIntegrationById(String oauthProviderId) {
return clientRegistrationRepository.findOAuthRegistrationById(oauthProviderId)
.map(OAuthRegistrationConverters.TO_RESOURCE)
.orElseThrow(() -> new ReportPortalException(ErrorType.AUTH_INTEGRATION_NOT_FOUND,
Suppliers.formattedSupplier("Oauth settings with id = {} have not been found.",
oauthProviderId).get()
));
.map(ResponseEntity::ok)
.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()
);
return new ResponseEntity<>(body, HttpStatus.NOT_FOUND);
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2024 EPAM Systems
*
* 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 com.epam.reportportal.auth.model;

import com.epam.reportportal.model.settings.OAuthRegistrationResource;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
* @author <a href="mailto:andrei_piankouski@epam.com">Andrei Piankouski</a>
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class ExtendedOAuthRegistrationResource extends OAuthRegistrationResource {

private int errorCode;

private String message;
}

0 comments on commit 0a9bb27

Please sign in to comment.