Skip to content

Commit

Permalink
Merge branch 'master' into MODEXPW-529
Browse files Browse the repository at this point in the history
  • Loading branch information
Saba-Zedginidze-EPAM authored Dec 17, 2024
2 parents c1d4a97 + ee9b9f1 commit 7ad2c9f
Show file tree
Hide file tree
Showing 24 changed files with 575 additions and 514 deletions.
29 changes: 15 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -292,21 +292,22 @@
<version>${spring-cloud-starter-bootstrap.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>3.4.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
Expand Down
33 changes: 18 additions & 15 deletions src/main/java/org/folio/dew/domain/dto/InstanceFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import lombok.NoArgsConstructor;
import lombok.With;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.folio.dew.domain.dto.IdentifierType;

import java.lang.reflect.Field;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -59,60 +58,64 @@ public class InstanceFormat implements Formatable<org.folio.dew.domain.dto.Insta
@CsvBindByPosition(position = 8)
private String modeOfIssuanceId;

@CsvBindByName(column = "Administrative note")
@CsvBindByName(column = "Statistical code")
@CsvBindByPosition(position = 9)
private String statisticalCode;

@CsvBindByName(column = "Administrative note")
@CsvBindByPosition(position = 10)
private String administrativeNotes;

@CsvBindByName(column = "Resource title")
@CsvBindByPosition(position = 10)
@CsvBindByPosition(position = 11)
private String title;

@CsvBindByName(column = "Index title")
@CsvBindByPosition(position = 11)
@CsvBindByPosition(position = 12)
private String indexTitle;

@CsvBindByName(column = "Series statements")
@CsvBindByPosition(position = 12)
@CsvBindByPosition(position = 13)
private String series;

@CsvBindByName(column = "Contributors")
@CsvBindByPosition(position = 13)
@CsvBindByPosition(position = 14)
private String contributors;

@CsvBindByName(column = "Edition")
@CsvBindByPosition(position = 14)
@CsvBindByPosition(position = 15)
private String editions;

@CsvBindByName(column = "Physical description")
@CsvBindByPosition(position = 15)
@CsvBindByPosition(position = 16)
private String physicalDescriptions;

@CsvBindByName(column = "Resource type")
@CsvBindByPosition(position = 16)
@CsvBindByPosition(position = 17)
private String instanceTypeId;

@CsvBindByName(column = "Nature of content")
@CsvBindByPosition(position = 17)
@CsvBindByPosition(position = 18)
private String natureOfContentTermIds;

@CsvBindByName(column = "Formats")
@CsvBindByPosition(position = 18)
@CsvBindByPosition(position = 19)
private String instanceFormatIds;

@CsvBindByName(column = "Languages")
@CsvBindByPosition(position = 19)
@CsvBindByPosition(position = 20)
private String languages;

@CsvBindByName(column = "Publication frequency")
@CsvBindByPosition(position = 20)
@CsvBindByPosition(position = 21)
private String publicationFrequency;

@CsvBindByName(column = "Publication range")
@CsvBindByPosition(position = 21)
@CsvBindByPosition(position = 22)
private String publicationRange;

@CsvBindByName(column = "Notes")
@CsvBindByPosition(position = 22)
@CsvBindByPosition(position = 23)
private String notes;

private String isbn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ private String getPathToStorage(String jobId) {
return format(STORAGE_TEMPLATE, jobId);
}

private String getPathToCsvFile(String jobId, String csvFileName) {
public String getPathToCsvFile(String jobId, String csvFileName) {
return format(CSV_FILE_TEMPLATE, jobId, csvFileName);
}

private String getCsvFileName(String jobId, String fileName) {
public String getCsvFileName(String jobId, String fileName) {
var pathToStorage = getPathToStorage(jobId);
List<String> names = new ArrayList<>();

Expand Down
58 changes: 2 additions & 56 deletions src/main/java/org/folio/dew/service/ElectronicAccessService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,18 @@

import static org.apache.commons.lang3.ObjectUtils.isEmpty;
import static org.apache.commons.lang3.StringUtils.EMPTY;
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
import static org.folio.dew.utils.Constants.ARRAY_DELIMITER;
import static org.folio.dew.utils.Constants.ENTITY_TYPE_TO_ELECTRONIC_ACCESS_DATA_DELIMITER;
import static org.folio.dew.utils.Constants.ENTITY_TYPE_TO_ELECTRONIC_ACCESS_DELIMITER;
import static org.folio.dew.utils.Constants.ITEM_DELIMITER_PATTERN;

import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.folio.dew.client.ElectronicAccessRelationshipClient;
import org.folio.dew.domain.dto.ElectronicAccess;
import org.folio.dew.domain.dto.EntityType;
import org.folio.dew.domain.dto.ErrorServiceArgs;
import org.folio.dew.error.BulkEditException;
import org.folio.dew.error.NotFoundException;
import org.folio.spring.FolioExecutionContext;
import org.folio.spring.scope.FolioExecutionContextSetter;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
Expand All @@ -32,16 +22,8 @@
@RequiredArgsConstructor
@Log4j2
public class ElectronicAccessService extends FolioExecutionContextManager {
private final ElectronicAccessRelationshipClient relationshipClient;
private final BulkEditProcessingErrorsService errorsService;
private final FolioExecutionContext folioExecutionContext;

private static final int NUMBER_OF_ELECTRONIC_ACCESS_COMPONENTS = 6;
private static final int ELECTRONIC_ACCESS_URI_INDEX = 0;
private static final int ELECTRONIC_ACCESS_LINK_TEXT_INDEX = 1;
private static final int ELECTRONIC_ACCESS_MATERIAL_SPECIFICATION_INDEX = 2;
private static final int ELECTRONIC_ACCESS_PUBLIC_NOTE_INDEX = 3;

private final ElectronicAccessServiceCache electronicAccessServiceCache;

public String getElectronicAccessesToString(List<ElectronicAccess> electronicAccesses, ErrorServiceArgs errorServiceArgs, EntityType entityType, String tenantId) {
return isEmpty(electronicAccesses) ?
Expand All @@ -63,50 +45,14 @@ private String electronicAccessToString(ElectronicAccess access, ErrorServiceArg
isEmpty(access.getPublicNote()) ? EMPTY : access.getPublicNote());
}

@Cacheable(cacheNames = "relationships")
public String getRelationshipNameById(String id, ErrorServiceArgs errorServiceArgs, String tenantId) {
try {
try (var context = new FolioExecutionContextSetter(refreshAndGetFolioExecutionContext(tenantId, folioExecutionContext))) {
return relationshipClient.getById(id).getName();
}
return electronicAccessServiceCache.getRelationshipNameById(id, tenantId);
} catch (NotFoundException e) {
var errorMessage = String.format("Electronic access relationship not found by id=%s", id);
log.error(errorMessage);
errorsService.saveErrorInCSV(errorServiceArgs.getJobId(), errorServiceArgs.getIdentifier(), new BulkEditException(errorMessage), errorServiceArgs.getFileName());
return id;
}
}

@Cacheable(cacheNames = "relationships")
public String getElectronicAccessRelationshipIdByName(String name) {
var relationships = relationshipClient.getByQuery(String.format("name==\"%s\"", name));
if (relationships.getElectronicAccessRelationships().isEmpty()) {
return EMPTY;
}
return relationships.getElectronicAccessRelationships().get(0).getId();
}

public List<ElectronicAccess> restoreElectronicAccess(String s) {
return StringUtils.isEmpty(s) ? Collections.emptyList() :
Arrays.stream(s.split(ITEM_DELIMITER_PATTERN))
.map(this::restoreElectronicAccessItem)
.filter(Objects::nonNull)
.toList();
}

private ElectronicAccess restoreElectronicAccessItem(String s) {
if (isNotEmpty(s)) {
var tokens = s.split(ARRAY_DELIMITER, -1);
if (NUMBER_OF_ELECTRONIC_ACCESS_COMPONENTS == tokens.length) {
return new ElectronicAccess()
.uri(tokens[ELECTRONIC_ACCESS_URI_INDEX])
.linkText(tokens[ELECTRONIC_ACCESS_LINK_TEXT_INDEX])
.materialsSpecification(tokens[ELECTRONIC_ACCESS_MATERIAL_SPECIFICATION_INDEX])
.publicNote(tokens[ELECTRONIC_ACCESS_PUBLIC_NOTE_INDEX])
.relationshipId(tokens[tokens.length - 1]);
}
throw new BulkEditException(String.format("Illegal number of electronic access elements: %d, expected: %d", tokens.length, NUMBER_OF_ELECTRONIC_ACCESS_COMPONENTS));
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.folio.dew.service;

import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.folio.dew.client.ElectronicAccessRelationshipClient;
import org.folio.spring.FolioExecutionContext;
import org.folio.spring.scope.FolioExecutionContextSetter;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
@Log4j2
public class ElectronicAccessServiceCache extends FolioExecutionContextManager {

private final ElectronicAccessRelationshipClient relationshipClient;
private final FolioExecutionContext folioExecutionContext;

@Cacheable(cacheNames = "relationships")
public String getRelationshipNameById(String id, String tenantId) {
try (var context = new FolioExecutionContextSetter(refreshAndGetFolioExecutionContext(tenantId, folioExecutionContext))) {
return relationshipClient.getById(id).getName();
}
}
}
Loading

0 comments on commit 7ad2c9f

Please sign in to comment.