Skip to content

Commit

Permalink
EPMRPP-97288 fix sonar comments
Browse files Browse the repository at this point in the history
  • Loading branch information
grabsefx committed Jan 14, 2025
1 parent b5fff1a commit 65cbed9
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import lombok.Getter;

/**
* Enum with a list of basic required project parameters
* Enum with a list of basic required project parameters.
*
* @author Andrey Plisunov
*/
Expand Down Expand Up @@ -78,6 +78,9 @@ public static boolean isPresent(String name) {

public static class Prefix {

private Prefix() {
}

public static final String ANALYZER = "analyzer.";
public static final String JOB = "job.";
public static final String UNIQUE_ERROR = "uniqueError.";
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.epam.reportportal.auth.entity.user;

import com.google.common.base.Strings;
import java.util.Arrays;
import java.util.Optional;
import org.apache.commons.lang3.StringUtils;

/**
* UserRole representation<br> Role has more rights than the following one. So, Administrator is
Expand All @@ -37,15 +36,9 @@ public static Optional<UserRole> findByName(String name) {
return Arrays.stream(UserRole.values()).filter(role -> role.name().equals(name)).findAny();
}

public static Optional<UserRole> findByAuthority(String name) {
if (Strings.isNullOrEmpty(name)) {
return Optional.empty();
}
return findByName(StringUtils.substringAfter(name, ROLE_PREFIX));
}

public String getAuthority() {
return "ROLE_" + this.name();
return ROLE_PREFIX + this.name();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class S3DataStore implements DataStore {

private static final Logger LOGGER = LoggerFactory.getLogger(S3DataStore.class);
private static final Lock CREATE_BUCKET_LOCK = new ReentrantLock();
public static final String UNABLE_TO_FIND_FILE = "Unable to find file";

private final BlobStore blobStore;
private final String bucketPrefix;
Expand Down Expand Up @@ -107,8 +108,8 @@ public String save(String filePath, InputStream inputStream) {
@Override
public InputStream load(String filePath) {
if (filePath == null) {
LOGGER.error("Unable to find file");
throw new ReportPortalException(ErrorType.UNABLE_TO_LOAD_BINARY_DATA, "Unable to find file");
LOGGER.error(UNABLE_TO_FIND_FILE);
throw new ReportPortalException(ErrorType.UNABLE_TO_LOAD_BINARY_DATA, UNABLE_TO_FIND_FILE);
}
StoredFile storedFile = getStoredFile(filePath);
Blob fileBlob = blobStore.getBlob(storedFile.bucket(), storedFile.filePath());
Expand All @@ -120,7 +121,7 @@ public InputStream load(String filePath) {
}
}
LOGGER.error("Unable to find file '{}'", filePath);
throw new ReportPortalException(ErrorType.UNABLE_TO_LOAD_BINARY_DATA, "Unable to find file");
throw new ReportPortalException(ErrorType.UNABLE_TO_LOAD_BINARY_DATA, UNABLE_TO_FIND_FILE);
}

@Override
Expand Down Expand Up @@ -181,13 +182,15 @@ private StoredFile getStoredFile(String filePath) {
}

private Location getLocationFromString(String locationString) {
Location location = null;
Location loc = null;
if (locationString != null) {
location =
new LocationBuilder().scope(LocationScope.REGION).id(locationString).description("region")
.build();
loc = new LocationBuilder()
.scope(LocationScope.REGION)
.id(locationString)
.description("region")
.build();
}
return location;
return loc;
}

private String retrievePath(Path path, int beginIndex, int endIndex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package com.epam.reportportal.auth.integration.github;

import com.google.common.base.Charsets;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
Expand Down Expand Up @@ -51,7 +51,7 @@ private GitHubClient(String accessToken) {
@Override
public void handleError(ClientHttpResponse response) throws IOException {
String errorMessage =
"Unable to load Github Data:" + new String(getResponseBody(response), Charsets.UTF_8);
"Unable to load Github Data:" + new String(getResponseBody(response), StandardCharsets.UTF_8);
LOGGER.error(errorMessage);
throw new AuthenticationServiceException(errorMessage);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public ReportPortalExceptionResolver(ErrorResolver defaultErrorResolver) {
@Override
public RestError resolveError(Exception ex) {

LOGGER.error("ReportPortalExceptionResolver > " + ex.getMessage(), ex);
LOGGER.error("ReportPortalExceptionResolver > {}", ex.getMessage(), ex);

if (ReportPortalException.class.isAssignableFrom(ex.getClass())) {
ReportPortalException currentException = (ReportPortalException) ex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,11 @@
public class BusinessRule {

private BusinessRule() {
//should be create by factory-methods only
//should be created via factory-methods only
}

/**
* Create rule from object to be verified, predicate and error message in case of violation
*
* @param <T> Type of object being checked
* @param object Object to be validated
* @param predicate Validation predicate
* @param message Error message
* @return Validator
* @deprecated in favor of {@link #expect(Object, Predicate, Supplier)}<br> This approach would be
* better in case you need to concatenate some error string
*/
@Deprecated
public static <T> DefaultRuleValidator<T> expect(T object, Predicate<T> predicate,
String message) {
return new DefaultRuleValidator<>(object, predicate, Suppliers.stringSupplier(message));
}

/**
* Create rule from object to be verified, predicate and error message in case of violation
* Create rule from object to be verified, predicate and error message in case of violation.
*
* @param <T> Type of object being checked
* @param object Object to be validated
Expand All @@ -63,7 +46,7 @@ public static <T> DefaultRuleValidator<T> expect(T object, Predicate<T> predicat
}

/**
* Create rule from object to be verified, predicate
* Create rule from object to be verified, predicate.
*
* @param <T> Type of object being checked
* @param object Object to be validated
Expand All @@ -75,7 +58,7 @@ public static <T> ErrorTypeBasedRuleValidator<T> expect(T object, Predicate<T> p
}

/**
* For cases where we are going to fail something
* For cases where we are going to fail something.
*
* @return {@link AlwaysFailRuleValidator}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public abstract class RuleValidator<T> {
protected final Predicate<T> predicate;
protected final T target;

public RuleValidator(T target, Predicate<T> predicate) {
protected RuleValidator(T target, Predicate<T> predicate) {
this.target = target;
this.predicate = predicate;

Expand Down
6 changes: 4 additions & 2 deletions src/test/java/com/epam/auth/reportportal/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.epam.auth.reportportal.config.TestConfig;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -82,8 +83,9 @@ private static void applyMigrationScripts() {
try {
var file = new File(
DB_MIGRATION_PATH + "/V" + filename.replace(" ", "0"));
FileUtils.writeStringToFile(file,
"\n" + FileUtils.readFileToString(new File(MIGRATIONS_PATH + filename.trim())));
FileUtils.writeStringToFile(file, "\n"
+ FileUtils.readFileToString(new File(MIGRATIONS_PATH + filename.trim()),
StandardCharsets.UTF_8), StandardCharsets.UTF_8);

} catch (IOException e) {
throw new RuntimeException(e);
Expand Down

0 comments on commit 65cbed9

Please sign in to comment.