Skip to content

Commit

Permalink
MODLD-582: Review/Sonar fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiBordak committed Nov 22, 2024
1 parent d20feb7 commit 90387f9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
17 changes: 17 additions & 0 deletions src/main/java/org/folio/linked/data/util/LccnUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.folio.linked.data.util;

import static org.apache.commons.collections4.CollectionUtils.isEmpty;

import lombok.experimental.UtilityClass;
import org.folio.linked.data.domain.dto.LccnRequest;

@UtilityClass
public class LccnUtils {

public static boolean isCurrent(LccnRequest lccnRequest) {
return isEmpty(lccnRequest.getStatus()) || lccnRequest.getStatus()
.stream()
.flatMap(status -> status.getLink().stream())
.anyMatch(link -> link.endsWith("current"));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.folio.linked.data.validation.dto;

import static org.folio.linked.data.util.LccnUtils.isCurrent;

import jakarta.validation.ConstraintValidatorContext;
import java.util.regex.Pattern;
import org.folio.linked.data.domain.dto.LccnRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.folio.linked.data.exception.RequestProcessingExceptionBuilder;
import org.folio.linked.data.repo.FolioMetadataRepository;
import org.folio.linked.data.service.search.InstanceSearchService;
import org.folio.linked.data.util.LccnUtils;
import org.folio.linked.data.validation.LccnUniqueConstraint;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -62,7 +63,7 @@ private SearchResponseTotalOnly findInstanceWithLccn(List<String> lccn, String i
}

private boolean hasCurrentLccn(InstanceField instance) {
return getLccnRequest(instance).anyMatch(this::isCurrent);
return getLccnRequest(instance).anyMatch(LccnUtils::isCurrent);
}

private List<String> getLccnValues(InstanceField instance) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
package org.folio.linked.data.validation.dto;

import static org.apache.commons.collections4.CollectionUtils.isEmpty;

import jakarta.validation.ConstraintValidator;
import java.lang.annotation.Annotation;
import org.folio.linked.data.domain.dto.LccnRequest;

public abstract class LccnValidator<A extends Annotation, T> implements ConstraintValidator<A, T> {

protected boolean isCurrent(LccnRequest lccnRequest) {
return isEmpty(lccnRequest.getStatus()) || lccnRequest.getStatus()
.stream()
.flatMap(status -> status.getLink().stream())
.anyMatch(link -> link.endsWith("current"));
}
}

0 comments on commit 90387f9

Please sign in to comment.