Skip to content

Commit

Permalink
MODLD-575: Authority lookup: not already in data graph (#39)
Browse files Browse the repository at this point in the history
Covers specific case in Authority lookup when authority resource exists in SRS but not in the Data Graph
  • Loading branch information
AndreiBordak authored Nov 11, 2024
1 parent f12c41f commit e074dc3
Show file tree
Hide file tree
Showing 32 changed files with 455 additions and 91 deletions.
8 changes: 5 additions & 3 deletions descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"inventory-storage.preceding-succeeding-titles.item.put",
"inventory-storage.preceding-succeeding-titles.item.delete",
"source-storage.snapshots.post",
"source-storage.records.formatted.item.get",
"source-storage.records.post",
"source-storage.records.put"
]
Expand Down Expand Up @@ -56,6 +57,7 @@
"inventory-storage.preceding-succeeding-titles.item.put",
"inventory-storage.preceding-succeeding-titles.item.delete",
"source-storage.snapshots.post",
"source-storage.records.formatted.item.get",
"source-storage.records.post",
"source-storage.records.put"
]
Expand All @@ -76,20 +78,20 @@
"methods": [ "GET" ],
"pathPattern": "/resource/check/{inventoryId}/supported",
"permissionsRequired": [ "linked-data.resources.support-check.get" ],
"modulePermissions": ["source-storage.records.get"]
"modulePermissions": ["source-storage.records.formatted.item.get"]
},
{
"methods": [ "GET" ],
"pathPattern": "/resource/preview/{inventoryId}",
"permissionsRequired": [ "linked-data.resources.preview.get" ],
"modulePermissions": ["source-storage.records.get"]
"modulePermissions": ["source-storage.records.formatted.item.get"]
},
{
"methods": [ "POST" ],
"pathPattern": "/resource/import/{inventoryId}",
"permissionsRequired": [ "linked-data.resources.import.post" ],
"modulePermissions": [
"source-storage.records.get",
"source-storage.records.formatted.item.get",
"mapping-metadata.get",
"mapping-metadata.type.item.get",
"inventory-storage.instances.item.post",
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/folio/linked/data/client/SrsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
public interface SrsClient {

@GetMapping(value = "/records/{inventoryId}/formatted?idType=INSTANCE")
ResponseEntity<Record> getFormattedSourceStorageInstanceRecordById(@PathVariable("inventoryId") String inventoryId);
ResponseEntity<Record> getSourceStorageInstanceRecordById(@PathVariable("inventoryId") String inventoryId);

@GetMapping(value = "/records/{srsId}/formatted?idType=SRS_RECORD")
ResponseEntity<Record> getSourceStorageRecordBySrsId(@PathVariable("srsId") String srsId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@

import static java.util.Optional.ofNullable;
import static org.folio.linked.data.util.ResourceUtils.ensureLatestReplaced;
import static org.folio.linked.data.util.ResourceUtils.fetchResource;

import java.util.function.BiConsumer;
import lombok.RequiredArgsConstructor;
import org.folio.ld.dictionary.PredicateDictionary;
import org.folio.linked.data.domain.dto.Agent;
import org.folio.linked.data.model.entity.Resource;
import org.folio.linked.data.model.entity.ResourceEdge;
import org.folio.linked.data.repo.ResourceRepository;
import org.folio.linked.data.service.resource.ResourceMarcAuthorityService;

@RequiredArgsConstructor
public abstract class AgentMapperUnit implements WorkSubResourceMapperUnit {

private final BiConsumer<Object, Agent> agentConsumer;
private final AgentRoleAssigner agentRoleAssigner;
private final ResourceRepository resourceRepository;
private final ResourceMarcAuthorityService resourceMarcAuthorityService;

@Override
public <P> P toDto(Resource source, P parentDto, Resource parentResource) {
Expand All @@ -34,7 +33,7 @@ public <P> P toDto(Resource source, P parentDto, Resource parentResource) {
@Override
public Resource toEntity(Object dto, Resource parentEntity) {
var agent = (Agent) dto;
var resource = fetchResource(agent, resourceRepository);
var resource = resourceMarcAuthorityService.fetchResourceOrCreateFromSrsRecord(agent);
ofNullable(agent.getRoles())
.ifPresent(roles -> roles.forEach(role -> PredicateDictionary.fromUri(role)
.ifPresent(p -> parentEntity.addOutgoingEdge(new ResourceEdge(parentEntity, resource, p)))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.folio.linked.data.domain.dto.ClassificationResponse;
import org.folio.linked.data.domain.dto.Reference;
import org.folio.linked.data.mapper.dto.common.MapperUnit;
import org.folio.linked.data.repo.ResourceRepository;
import org.folio.linked.data.service.resource.ResourceMarcAuthorityService;
import org.springframework.stereotype.Component;

@Component
Expand All @@ -20,12 +20,12 @@ public class AssigningSourceMapperUnit extends ReferenceMapperUnit {
ClassificationResponse.class
);

public AssigningSourceMapperUnit(ResourceRepository resourceRepository) {
public AssigningSourceMapperUnit(ResourceMarcAuthorityService resourceMarcAuthorityService) {
super((assigningSource, destination) -> {
if (destination instanceof ClassificationResponse classification) {
classification.addAssigningSourceReferenceItem(assigningSource);
}
}, resourceRepository);
}, resourceMarcAuthorityService);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
import org.folio.linked.data.domain.dto.Reference;
import org.folio.linked.data.domain.dto.WorkResponse;
import org.folio.linked.data.mapper.dto.common.MapperUnit;
import org.folio.linked.data.repo.ResourceRepository;
import org.folio.linked.data.service.resource.ResourceMarcAuthorityService;
import org.springframework.stereotype.Component;

@Component
@MapperUnit(type = FORM, predicate = GENRE, requestDto = Reference.class)
public class GenreMapperUnit extends ReferenceMapperUnit {

public GenreMapperUnit(ResourceRepository resourceRepository) {
public GenreMapperUnit(ResourceMarcAuthorityService resourceMarcAuthorityService) {
super((genre, destination) -> {
if (destination instanceof WorkResponse work) {
work.addGenreReferenceItem(genre);
}
}, resourceRepository);
}, resourceMarcAuthorityService);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
import org.folio.linked.data.domain.dto.Reference;
import org.folio.linked.data.domain.dto.WorkResponse;
import org.folio.linked.data.mapper.dto.common.MapperUnit;
import org.folio.linked.data.repo.ResourceRepository;
import org.folio.linked.data.service.resource.ResourceMarcAuthorityService;
import org.springframework.stereotype.Component;

@Component
@MapperUnit(type = PLACE, predicate = GEOGRAPHIC_COVERAGE, requestDto = Reference.class)
public class GeographicCoverageMapperUnit extends ReferenceMapperUnit {

public GeographicCoverageMapperUnit(ResourceRepository resourceRepository) {
public GeographicCoverageMapperUnit(ResourceMarcAuthorityService resourceMarcAuthorityService) {
super((geographicCoverage, destination) -> {
if (destination instanceof WorkResponse work) {
work.addGeographicCoverageReferenceItem(geographicCoverage);
}
}, resourceRepository);
}, resourceMarcAuthorityService);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.folio.linked.data.domain.dto.DissertationResponse;
import org.folio.linked.data.domain.dto.Reference;
import org.folio.linked.data.mapper.dto.common.MapperUnit;
import org.folio.linked.data.repo.ResourceRepository;
import org.folio.linked.data.service.resource.ResourceMarcAuthorityService;
import org.springframework.stereotype.Component;

@Component
Expand All @@ -20,12 +20,12 @@ public class GrantingInstitutionMapperUnit extends ReferenceMapperUnit {
DissertationResponse.class
);

public GrantingInstitutionMapperUnit(ResourceRepository resourceRepository) {
public GrantingInstitutionMapperUnit(ResourceMarcAuthorityService resourceMarcAuthorityService) {
super((grantingInstitution, destination) -> {
if (destination instanceof DissertationResponse dissertation) {
dissertation.addGrantingInstitutionReferenceItem(grantingInstitution);
}
}, resourceRepository);
}, resourceMarcAuthorityService);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package org.folio.linked.data.mapper.dto.monograph.work.sub;

import static org.folio.linked.data.util.ResourceUtils.ensureLatestReplaced;
import static org.folio.linked.data.util.ResourceUtils.fetchResource;

import java.util.function.BiConsumer;
import lombok.RequiredArgsConstructor;
import org.folio.linked.data.domain.dto.Reference;
import org.folio.linked.data.model.entity.Resource;
import org.folio.linked.data.repo.ResourceRepository;
import org.folio.linked.data.service.resource.ResourceMarcAuthorityService;

@RequiredArgsConstructor
public class ReferenceMapperUnit implements WorkSubResourceMapperUnit {

private final BiConsumer<Reference, Object> referenceConsumer;
private final ResourceRepository resourceRepository;
private final ResourceMarcAuthorityService resourceMarcAuthorityService;

@Override
public <P> P toDto(Resource source, P parentDto, Resource parentResource) {
Expand All @@ -28,7 +27,7 @@ public <P> P toDto(Resource source, P parentDto, Resource parentResource) {
@Override
public Resource toEntity(Object dto, Resource parentEntity) {
var reference = (Reference) dto;
return fetchResource(reference, resourceRepository);
return resourceMarcAuthorityService.fetchResourceOrCreateFromSrsRecord(reference);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
import org.folio.linked.data.domain.dto.Reference;
import org.folio.linked.data.domain.dto.WorkResponse;
import org.folio.linked.data.mapper.dto.common.MapperUnit;
import org.folio.linked.data.repo.ResourceRepository;
import org.folio.linked.data.service.resource.ResourceMarcAuthorityService;
import org.springframework.stereotype.Component;

@Component
@MapperUnit(type = CONCEPT, predicate = SUBJECT, requestDto = Reference.class)
public class SubjectMapperUnit extends ReferenceMapperUnit {

public SubjectMapperUnit(ResourceRepository resourceRepository) {
public SubjectMapperUnit(ResourceMarcAuthorityService resourceMarcAuthorityService) {
super((subject, destination) -> {
if (destination instanceof WorkResponse work) {
work.addSubjectsItem(subject);
}
}, resourceRepository);
}, resourceMarcAuthorityService);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
import org.folio.linked.data.domain.dto.WorkResponse;
import org.folio.linked.data.mapper.dto.monograph.work.sub.AgentMapperUnit;
import org.folio.linked.data.mapper.dto.monograph.work.sub.AgentRoleAssigner;
import org.folio.linked.data.repo.ResourceRepository;
import org.folio.linked.data.service.resource.ResourceMarcAuthorityService;

public class ContributorMapperUnit extends AgentMapperUnit {

ContributorMapperUnit(AgentRoleAssigner agentRoleAssigner, ResourceRepository resourceRepository) {
ContributorMapperUnit(AgentRoleAssigner agentRoleAssigner,
ResourceMarcAuthorityService resourceMarcAuthorityService) {
super((dto, creator) -> {
if (dto instanceof WorkResponse work) {
work.addContributorReferenceItem(creator);
}
}, agentRoleAssigner, resourceRepository);
}, agentRoleAssigner, resourceMarcAuthorityService);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
import org.folio.linked.data.domain.dto.Agent;
import org.folio.linked.data.mapper.dto.common.MapperUnit;
import org.folio.linked.data.mapper.dto.monograph.work.sub.AgentRoleAssigner;
import org.folio.linked.data.repo.ResourceRepository;
import org.folio.linked.data.service.resource.ResourceMarcAuthorityService;
import org.springframework.stereotype.Component;

@Component("contributorFamilyMapperUnit")
@MapperUnit(type = FAMILY, requestDto = Agent.class, predicate = CONTRIBUTOR)
public class FamilyMapperUnit extends ContributorMapperUnit {

public FamilyMapperUnit(AgentRoleAssigner agentRoleAssigner, ResourceRepository resourceRepository) {
super(agentRoleAssigner, resourceRepository);
public FamilyMapperUnit(AgentRoleAssigner agentRoleAssigner,
ResourceMarcAuthorityService resourceMarcAuthorityService) {
super(agentRoleAssigner, resourceMarcAuthorityService);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
import org.folio.linked.data.domain.dto.Agent;
import org.folio.linked.data.mapper.dto.common.MapperUnit;
import org.folio.linked.data.mapper.dto.monograph.work.sub.AgentRoleAssigner;
import org.folio.linked.data.repo.ResourceRepository;
import org.folio.linked.data.service.resource.ResourceMarcAuthorityService;
import org.springframework.stereotype.Component;

@Component("contributorMeetingMapperUnit")
@MapperUnit(type = MEETING, requestDto = Agent.class, predicate = CONTRIBUTOR)
public class MeetingMapperUnit extends ContributorMapperUnit {

public MeetingMapperUnit(AgentRoleAssigner agentRoleAssigner, ResourceRepository resourceRepository) {
super(agentRoleAssigner, resourceRepository);
public MeetingMapperUnit(AgentRoleAssigner agentRoleAssigner,
ResourceMarcAuthorityService resourceMarcAuthorityService) {
super(agentRoleAssigner, resourceMarcAuthorityService);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
import org.folio.linked.data.domain.dto.Agent;
import org.folio.linked.data.mapper.dto.common.MapperUnit;
import org.folio.linked.data.mapper.dto.monograph.work.sub.AgentRoleAssigner;
import org.folio.linked.data.repo.ResourceRepository;
import org.folio.linked.data.service.resource.ResourceMarcAuthorityService;
import org.springframework.stereotype.Component;

@Component("contributorOrganizationMapperUnit")
@MapperUnit(type = ORGANIZATION, requestDto = Agent.class, predicate = CONTRIBUTOR)
public class OrganizationMapperUnit extends ContributorMapperUnit {

public OrganizationMapperUnit(AgentRoleAssigner agentRoleAssigner, ResourceRepository resourceRepository) {
super(agentRoleAssigner, resourceRepository);
public OrganizationMapperUnit(AgentRoleAssigner agentRoleAssigner,
ResourceMarcAuthorityService resourceMarcAuthorityService) {
super(agentRoleAssigner, resourceMarcAuthorityService);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
import org.folio.linked.data.domain.dto.Agent;
import org.folio.linked.data.mapper.dto.common.MapperUnit;
import org.folio.linked.data.mapper.dto.monograph.work.sub.AgentRoleAssigner;
import org.folio.linked.data.repo.ResourceRepository;
import org.folio.linked.data.service.resource.ResourceMarcAuthorityService;
import org.springframework.stereotype.Component;

@Component("contributorPersonMapperUnit")
@MapperUnit(type = PERSON, requestDto = Agent.class, predicate = CONTRIBUTOR)
public class PersonMapperUnit extends ContributorMapperUnit {

public PersonMapperUnit(AgentRoleAssigner agentRoleAssigner, ResourceRepository resourceRepository) {
super(agentRoleAssigner, resourceRepository);
public PersonMapperUnit(AgentRoleAssigner agentRoleAssigner,
ResourceMarcAuthorityService resourceMarcAuthorityService) {
super(agentRoleAssigner, resourceMarcAuthorityService);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
import org.folio.linked.data.domain.dto.WorkResponse;
import org.folio.linked.data.mapper.dto.monograph.work.sub.AgentMapperUnit;
import org.folio.linked.data.mapper.dto.monograph.work.sub.AgentRoleAssigner;
import org.folio.linked.data.repo.ResourceRepository;
import org.folio.linked.data.service.resource.ResourceMarcAuthorityService;

public abstract class CreatorMapperUnit extends AgentMapperUnit {

CreatorMapperUnit(AgentRoleAssigner agentRoleAssigner, ResourceRepository resourceRepository) {
CreatorMapperUnit(AgentRoleAssigner agentRoleAssigner,
ResourceMarcAuthorityService resourceMarcAuthorityService) {
super((dto, creator) -> {
if (dto instanceof WorkResponse work) {
work.addCreatorReferenceItem(creator);
}
}, agentRoleAssigner, resourceRepository);
}, agentRoleAssigner, resourceMarcAuthorityService);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
import org.folio.linked.data.domain.dto.Agent;
import org.folio.linked.data.mapper.dto.common.MapperUnit;
import org.folio.linked.data.mapper.dto.monograph.work.sub.AgentRoleAssigner;
import org.folio.linked.data.repo.ResourceRepository;
import org.folio.linked.data.service.resource.ResourceMarcAuthorityService;
import org.springframework.stereotype.Component;

@Component("creatorFamilyMapperUnit")
@MapperUnit(type = FAMILY, requestDto = Agent.class, predicate = CREATOR)
public class FamilyMapperUnit extends CreatorMapperUnit {

public FamilyMapperUnit(AgentRoleAssigner agentRoleAssigner, ResourceRepository resourceRepository) {
super(agentRoleAssigner, resourceRepository);
public FamilyMapperUnit(AgentRoleAssigner agentRoleAssigner,
ResourceMarcAuthorityService resourceMarcAuthorityService) {
super(agentRoleAssigner, resourceMarcAuthorityService);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
import org.folio.linked.data.domain.dto.Agent;
import org.folio.linked.data.mapper.dto.common.MapperUnit;
import org.folio.linked.data.mapper.dto.monograph.work.sub.AgentRoleAssigner;
import org.folio.linked.data.repo.ResourceRepository;
import org.folio.linked.data.service.resource.ResourceMarcAuthorityService;
import org.springframework.stereotype.Component;

@Component("creatorMeetingMapperUnit")
@MapperUnit(type = MEETING, requestDto = Agent.class, predicate = CREATOR)
public class MeetingMapperUnit extends CreatorMapperUnit {

public MeetingMapperUnit(AgentRoleAssigner agentRoleAssigner, ResourceRepository resourceRepository) {
super(agentRoleAssigner, resourceRepository);
public MeetingMapperUnit(AgentRoleAssigner agentRoleAssigner,
ResourceMarcAuthorityService resourceMarcAuthorityService) {
super(agentRoleAssigner, resourceMarcAuthorityService);
}
}
Loading

0 comments on commit e074dc3

Please sign in to comment.