Skip to content
Snippets Groups Projects
Commit 01c05f25 authored by Morris Estepa's avatar Morris Estepa
Browse files

Refactor code to SonarQube standards

parent cfcaed75
No related branches found
No related tags found
1 merge request!252Refactor code to SonarQube standards
......@@ -28,8 +28,6 @@ import com.google.gson.Gson;
import javassist.NotFoundException;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
......@@ -55,7 +53,7 @@ public class GlobalExceptionMapper extends ResponseEntityExceptionHandler {
private static final Gson gson = new Gson();
@Autowired
private JaxRsDpsLog logger;
private JaxRsDpsLog jaxRsDpsLogger;
@ExceptionHandler(AppException.class)
protected ResponseEntity<Object> handleAppException(AppException e) {
......@@ -94,7 +92,7 @@ public class GlobalExceptionMapper extends ResponseEntityExceptionHandler {
@ExceptionHandler(ConstraintViolationException.class)
protected ResponseEntity<Object> handleConstraintValidationException(ConstraintViolationException e) {
logger.error("Validation exception", e);
jaxRsDpsLogger.error("Validation exception", e);
List<String> msgs = new ArrayList<>();
for (ConstraintViolation<?> violation : e.getConstraintViolations()) {
......@@ -134,9 +132,9 @@ public class GlobalExceptionMapper extends ResponseEntityExceptionHandler {
String exceptionMsg = e.getError().getMessage();
if (e.getError().getCode() > 499) {
this.logger.error(exceptionMsg, e);
this.jaxRsDpsLogger.error(exceptionMsg, e);
} else {
this.logger.warning(exceptionMsg, e);
this.jaxRsDpsLogger.warning(exceptionMsg, e);
}
return new ResponseEntity<>(gson.toJson(exceptionMsg), HttpStatus.resolve(e.getError().getCode()));
......
......@@ -82,6 +82,9 @@ public class PartitionApiTest {
public void should_return204_when_givenUpdatingValidPartitionId() {
String partitionId = "partition1";
this.sut.patch(partitionId, partitionInfo);
ResponseEntity<Map<String, Property>> result = this.sut.get(partitionId);
assertEquals(HttpStatus.OK, result.getStatusCode());
}
@Test
......
......@@ -79,19 +79,13 @@ public class AuthorizationService implements IAuthorizationService {
memberEmail = headers.getUserId();
if(memberEmail != null)
{
if(memberEmail.equals(spu_email)){
return true;
}
else{
throw AppException.createUnauthorized("Unauthorized. The user is not Service Principal");
}
}
if(memberEmail == null){
throw AppException.createUnauthorized("Unauthorized. The JWT token could not be validated");
} else if(memberEmail.equals(spu_email)){
return true;
} else{
throw AppException.createUnauthorized("Unauthorized. The user is not Service Principal");
}
}
catch (AppException appE) {
throw appE;
......@@ -99,11 +93,7 @@ public class AuthorizationService implements IAuthorizationService {
catch (Exception e) {
throw new AppException(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Authentication Failure", e.getMessage(), e);
}
return false;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment