Skip to content

Commit

Permalink
Merged in DSC-1307 (pull request DSpace#1213)
Browse files Browse the repository at this point in the history
[DSC-1307] Fix integration tests (REST)

Approved-by: Francesco Pio Scognamiglio
  • Loading branch information
NikitaKr1vonosov authored and francescopioscognamiglio committed Dec 4, 2023
2 parents f893f60 + 136b54e commit 32a9312
Show file tree
Hide file tree
Showing 8 changed files with 837 additions and 673 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,18 @@
public class ReciprocalItemAuthorityConsumer implements Consumer {
private static final Logger log = LogManager.getLogger(ReciprocalItemAuthorityConsumer.class);

private final Map<String, String> reciprocalMetadata = new ConcurrentHashMap<>();
private final ConfigurationService configurationService = new DSpace().getConfigurationService();
private final ItemService itemService = ContentServiceFactory.getInstance().getItemService();

private final Map<String, String> reciprocalMetadataMap = new ConcurrentHashMap<>();
private final transient Set<UUID> processedHandles = new HashSet<>();

private final IndexingService indexer = DSpaceServicesFactory.getInstance().getServiceManager()
.getServiceByName(IndexingService.class.getName(), IndexingService.class);

private final ItemService itemService;

public ReciprocalItemAuthorityConsumer() {
ConfigurationService confService = new DSpace().getConfigurationService();
itemService = ContentServiceFactory.getInstance().getItemService();
for (String conf : confService.getPropertyKeys("ItemAuthority.reciprocalMetadata")) {
reciprocalMetadata.put(conf.substring("ItemAuthority.reciprocalMetadata.".length()),
confService.getProperty(conf));
reciprocalMetadata.put(confService.getProperty(conf),
conf.substring("ItemAuthority.reciprocalMetadata.".length()));
}
}

@Override
public void initialize() throws Exception {
// nothing
iniReciprocalMetadata();
}

@Override
Expand All @@ -79,11 +68,11 @@ public void consume(Context ctx, Event event) throws Exception {
} else {
processedHandles.add(item.getID());
}
if (!reciprocalMetadata.isEmpty()) {
for (String k : reciprocalMetadata.keySet()) {
if (!reciprocalMetadataMap.isEmpty()) {
for (String k : reciprocalMetadataMap.keySet()) {
String entityType = k.split("\\.", 2)[0];
String metadata = k.split("\\.", 2)[1];
checkItemRefs(ctx, item, entityType, metadata, reciprocalMetadata.get(k));
checkItemRefs(ctx, item, entityType, metadata, reciprocalMetadataMap.get(k));
}
}
} finally {
Expand Down Expand Up @@ -153,6 +142,16 @@ private void reindexItem(Context ctx, Item target) throws SQLException {
}
}

private void iniReciprocalMetadata() {
List<String> properties = configurationService.getPropertyKeys("ItemAuthority.reciprocalMetadata");
for (String conf : properties) {
reciprocalMetadataMap.put(conf.substring("ItemAuthority.reciprocalMetadata.".length()),
configurationService.getProperty(conf));
reciprocalMetadataMap.put(configurationService.getProperty(conf),
conf.substring("ItemAuthority.reciprocalMetadata.".length()));
}
}

@Override
public void end(Context ctx) throws Exception {
processedHandles.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ public void testWorkbookBuildingFromItemDtos() throws Exception {

String authorId = author.getID().toString();

Item testUser = ItemBuilder.createItem(context, persons)
.withTitle("Test User")
.build();

Item jesse = ItemBuilder.createItem(context, persons)
.withTitle("Jesse Pinkman")
.build();

context.restoreAuthSystemState();

List<MetadataValueDTO> metadata = new ArrayList<>();
Expand All @@ -153,9 +161,11 @@ public void testWorkbookBuildingFromItemDtos() throws Exception {
metadata.add(new MetadataValueDTO("dc", "date", "issued", "2022/02/15"));
metadata.add(new MetadataValueDTO("dc", "type", null, "Book"));
metadata.add(new MetadataValueDTO("dc", "language", "iso", "it"));
metadata.add(new MetadataValueDTO("dc", "contributor", "author", "Jesse Pinkman"));
metadata.add(new MetadataValueDTO("dc", "contributor", "author", null, "Jesse Pinkman",
jesse.getID().toString(), 600));
metadata.add(new MetadataValueDTO("oairecerif", "author", "affiliation", PLACEHOLDER_PARENT_METADATA_VALUE));
metadata.add(new MetadataValueDTO("dc", "contributor", "author", "Test User"));
metadata.add(new MetadataValueDTO("dc", "contributor", "author", null, "Test User",
testUser.getID().toString(), 600));
metadata.add(new MetadataValueDTO("oairecerif", "author", "affiliation", "Company"));

bitstreams = new ArrayList<BitstreamDTO>();
Expand Down Expand Up @@ -224,10 +234,11 @@ public void testWorkbookBuildingFromItemDtos() throws Exception {
with("dspace.entity.type", "Publication"),
with("dc.type", "Book"),
with("dc.language.iso", "it"),
with("dc.contributor.author", "Jesse Pinkman"),
with("dc.contributor.author", "Test User", 1),
with("dc.contributor.author", "Jesse Pinkman", jesse.getID().toString(), 600),
with("dc.contributor.author", "Test User", testUser.getID().toString(), 1, 600),
with("oairecerif.author.affiliation", PLACEHOLDER_PARENT_METADATA_VALUE),
with("oairecerif.author.affiliation", "Company", 1)));
with("oairecerif.author.affiliation", "Company", 1)
));

assertThat(getItemBitstreamsByBundle(secondItem, "ORIGINAL"), contains(
bitstreamWith("Bitstream 3", "Third bitstream content")));
Expand Down
Loading

0 comments on commit 32a9312

Please sign in to comment.