-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #709 from folio-org/tmp-release-v4.0.2
Release v4.0.2, prepare v4.0.3 development iteration
- Loading branch information
Showing
56 changed files
with
1,425 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 72 additions & 4 deletions
76
...ava/org/folio/search/service/converter/preprocessor/extractor/ChildResourceExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,81 @@ | ||
package org.folio.search.service.converter.preprocessor.extractor; | ||
|
||
import static java.util.Collections.emptyList; | ||
import static java.util.Collections.emptySet; | ||
import static org.apache.commons.collections4.MapUtils.getObject; | ||
import static org.folio.search.utils.SearchConverterUtils.getNewAsMap; | ||
|
||
import java.util.HashSet; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
import lombok.RequiredArgsConstructor; | ||
import org.folio.search.domain.dto.ResourceEvent; | ||
import org.folio.search.domain.dto.ResourceEventType; | ||
import org.folio.search.service.reindex.jdbc.InstanceChildResourceRepository; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@RequiredArgsConstructor | ||
public abstract class ChildResourceExtractor { | ||
|
||
private final InstanceChildResourceRepository repository; | ||
|
||
public abstract List<ResourceEvent> prepareEvents(ResourceEvent resource); | ||
|
||
public abstract List<ResourceEvent> prepareEventsOnSharing(ResourceEvent resource); | ||
|
||
public abstract boolean hasChildResourceChanges(ResourceEvent event); | ||
|
||
protected abstract List<Map<String, Object>> constructRelations(boolean shared, ResourceEvent event, | ||
List<Map<String, Object>> entities); | ||
|
||
protected abstract Map<String, Object> constructEntity(Map<String, Object> entityProperties); | ||
|
||
protected abstract String childrenFieldName(); | ||
|
||
@Transactional | ||
public void persistChildren(boolean shared, List<ResourceEvent> events) { | ||
var instanceIdsForDeletion = events.stream() | ||
.filter(event -> event.getType() != ResourceEventType.CREATE && event.getType() != ResourceEventType.REINDEX) | ||
.map(ResourceEvent::getId) | ||
.toList(); | ||
if (!instanceIdsForDeletion.isEmpty()) { | ||
repository.deleteByInstanceIds(instanceIdsForDeletion); | ||
} | ||
|
||
public interface ChildResourceExtractor { | ||
var eventsForSaving = events.stream() | ||
.filter(event -> event.getType() != ResourceEventType.DELETE) | ||
.toList(); | ||
if (eventsForSaving.isEmpty()) { | ||
return; | ||
} | ||
|
||
List<ResourceEvent> prepareEvents(ResourceEvent resource); | ||
var entities = new HashSet<Map<String, Object>>(); | ||
var relations = new LinkedList<Map<String, Object>>(); | ||
eventsForSaving.forEach(event -> { | ||
var entitiesFromEvent = extractEntities(event); | ||
relations.addAll(constructRelations(shared, event, entitiesFromEvent)); | ||
entities.addAll(entitiesFromEvent); | ||
}); | ||
repository.saveAll(entities, relations); | ||
} | ||
|
||
List<ResourceEvent> prepareEventsOnSharing(ResourceEvent resource); | ||
private List<Map<String, Object>> extractEntities(ResourceEvent event) { | ||
var entities = getChildResources(getNewAsMap(event)); | ||
return entities.stream() | ||
.map(this::constructEntity) | ||
.filter(Objects::nonNull) | ||
.toList(); | ||
} | ||
|
||
boolean hasChildResourceChanges(ResourceEvent event); | ||
@SuppressWarnings("unchecked") | ||
protected Set<Map<String, Object>> getChildResources(Map<String, Object> event) { | ||
var object = getObject(event, childrenFieldName(), emptyList()); | ||
if (object == null) { | ||
return emptySet(); | ||
} | ||
return new HashSet<>((List<Map<String, Object>>) object); | ||
} | ||
} |
Oops, something went wrong.