Skip to content

Commit

Permalink
Merge branch 'DSpace:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
msevigny authored Feb 22, 2024
2 parents d34330a + 42e3699 commit d1a0538
Show file tree
Hide file tree
Showing 268 changed files with 1,514 additions and 486 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,15 @@ public List<AuthorityValue> getAuthorityValues(Context context, Item item, Map<S
throws SQLException, AuthorizeException {
List<AuthorityValue> values = new ArrayList<>();
for (String metadataField : metadataFields) {
List<MetadataValue> metadataValues = itemService.getMetadataByMetadataString(item, metadataField);

String[] fieldParts = metadataField.split("\\.");
String schema = (fieldParts.length > 0 ? fieldParts[0] : null);
String element = (fieldParts.length > 1 ? fieldParts[1] : null);
String qualifier = (fieldParts.length > 2 ? fieldParts[2] : null);

// Get metadata values without virtual metadata
List<MetadataValue> metadataValues = itemService.getMetadata(item, schema, element, qualifier, Item.ANY,
false);
for (MetadataValue metadataValue : metadataValues) {
String content = metadataValue.getValue();
String authorityKey = metadataValue.getAuthority();
Expand Down
8 changes: 8 additions & 0 deletions dspace-api/src/main/java/org/dspace/content/Bitstream.java
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,18 @@ public Collection getCollection() {
return collection;
}

public void setCollection(Collection collection) {
this.collection = collection;
}

public Community getCommunity() {
return community;
}

public void setCommunity(Community community) {
this.community = community;
}

/**
* Get the asset store number where this bitstream is stored
*
Expand Down
3 changes: 3 additions & 0 deletions dspace-api/src/main/java/org/dspace/content/Collection.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ public Bitstream getLogo() {

protected void setLogo(Bitstream logo) {
this.logo = logo;
if (logo != null) {
logo.setCollection(this);
}
setModified();
}

Expand Down
3 changes: 3 additions & 0 deletions dspace-api/src/main/java/org/dspace/content/Community.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ public Bitstream getLogo() {

void setLogo(Bitstream logo) {
this.logo = logo;
if (logo != null) {
logo.setCommunity(this);
}
setModified();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,37 @@ public Choices getMatches(String text, int start, int limit, String locale) {

@Override
public Choices getBestMatch(String text, String locale) {
return getMatches(text, 0, 1, locale);
// punt if there is no query text
if (text == null || text.trim().length() == 0) {
return new Choices(true);
}
int limit = 10;
SHERPAService sherpaService = new DSpace().getSingletonService(SHERPAService.class);
SHERPAResponse sherpaResponse = sherpaService.performRequest("publication", "title",
"equals", text, 0, limit);
Choices result;
if (CollectionUtils.isNotEmpty(sherpaResponse.getJournals())) {
List<Choice> list = sherpaResponse
.getJournals().stream()
.map(sherpaJournal -> new Choice(sherpaJournal.getIssns().get(0),
sherpaJournal.getTitles().get(0), sherpaJournal.getTitles().get(0)))
.collect(Collectors.toList());
int total = sherpaResponse.getJournals().size();

int confidence;
if (list.isEmpty()) {
confidence = Choices.CF_NOTFOUND;
} else if (list.size() == 1) {
confidence = Choices.CF_UNCERTAIN;
} else {
confidence = Choices.CF_AMBIGUOUS;
}
result = new Choices(list.toArray(new Choice[list.size()]), 0, total, confidence,
total > limit);
} else {
result = new Choices(false);
}
return result;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,38 @@ public Choices getMatches(String text, int start, int limit, String locale) {

@Override
public Choices getBestMatch(String text, String locale) {
return getMatches(text, 0, 1, locale);
// punt if there is no query text
if (text == null || text.trim().length() == 0) {
return new Choices(true);
}
int limit = 10;
SHERPAService sherpaService = new DSpace().getSingletonService(SHERPAService.class);
SHERPAPublisherResponse sherpaResponse = sherpaService.performPublisherRequest("publisher", "name",
"equals", text, 0, limit);
Choices result;
if (CollectionUtils.isNotEmpty(sherpaResponse.getPublishers())) {
List<Choice> list = sherpaResponse
.getPublishers().stream()
.map(sherpaPublisher ->
new Choice(sherpaPublisher.getIdentifier(),
sherpaPublisher.getName(), sherpaPublisher.getName()))
.collect(Collectors.toList());
int total = sherpaResponse.getPublishers().size();

int confidence;
if (list.isEmpty()) {
confidence = Choices.CF_NOTFOUND;
} else if (list.size() == 1) {
confidence = Choices.CF_UNCERTAIN;
} else {
confidence = Choices.CF_AMBIGUOUS;
}
result = new Choices(list.toArray(new Choice[list.size()]), 0, total, confidence,
total > limit);
} else {
result = new Choices(false);
}
return result;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.importer.external;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import javax.el.MethodNotFoundException;

import org.dspace.content.Item;
import org.dspace.importer.external.datamodel.ImportRecord;
import org.dspace.importer.external.datamodel.Query;
import org.dspace.importer.external.exception.MetadataSourceException;
import org.dspace.importer.external.service.components.QuerySource;

/**
* Implements a data source for querying multiple external data sources in parallel
*
* optional Affiliation informations are not part of the API request.
*
* @author Johanna Staudinger ([email protected])
*
*/
public class MultipleParallelImportMetadataSourceServiceImpl implements QuerySource {
private final List<QuerySource> innerProviders;
private final ExecutorService executorService;

private final String sourceName;
public MultipleParallelImportMetadataSourceServiceImpl(List<QuerySource> innerProviders, String sourceName) {
super();
this.innerProviders = innerProviders;
this.executorService = Executors.newFixedThreadPool(innerProviders.size());
this.sourceName = sourceName;
}

@Override
public String getImportSource() {
return sourceName;
}

@Override
public ImportRecord getRecord(String recordId) throws MetadataSourceException {
List<Future<ImportRecord>> futureList = new ArrayList<>();
ImportRecord result = null;
for (QuerySource innerProvider : innerProviders) {
futureList.add(executorService.submit(() -> innerProvider.getRecord(recordId)));
}
for (Future<ImportRecord> future: futureList) {
try {
ImportRecord importRecord = future.get();
if (!Objects.isNull(importRecord)) {
result = importRecord;
}
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}
return result;
}

@Override
public int getRecordsCount(String query) throws MetadataSourceException {
List<Future<Integer>> futureList = new ArrayList<>();
int result = 0;
for (QuerySource innerProvider : innerProviders) {
futureList.add(executorService.submit(() -> innerProvider.getRecordsCount(query)));
}
for (Future<Integer> future: futureList) {
try {
Integer count = future.get();
result += Objects.isNull(count) ? 0 : count;
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}
return result;
}

@Override
public int getRecordsCount(Query query) throws MetadataSourceException {
List<Future<Integer>> futureList = new ArrayList<>();
int result = 0;
for (QuerySource innerProvider : innerProviders) {
futureList.add(executorService.submit(() -> innerProvider.getRecordsCount(query)));
}
for (Future<Integer> future: futureList) {
try {
Integer count = future.get();
result += Objects.isNull(count) ? 0 : count;
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}
return result;
}


@Override
public Collection<ImportRecord> getRecords(String query, int start, int count) throws MetadataSourceException {
List<Future<Collection<ImportRecord>>> futureList = new ArrayList<>();
List<ImportRecord> result = new ArrayList<>();
for (QuerySource innerProvider : innerProviders) {
futureList.add(executorService.submit(() -> innerProvider.getRecords(query, start, count)));
}
for (Future<Collection<ImportRecord>> future: futureList) {
try {
Collection<ImportRecord> importRecords = future.get();
result.addAll(Objects.isNull(importRecords) ? Collections.emptyList() : importRecords);
} catch (InterruptedException | ExecutionException e) {
//
}
}
return result;
}

@Override
public Collection<ImportRecord> getRecords(Query query) throws MetadataSourceException {
List<Future<Collection<ImportRecord>>> futureList = new ArrayList<>();
List<ImportRecord> result = new ArrayList<>();
for (QuerySource innerProvider : innerProviders) {
futureList.add(executorService.submit(() -> innerProvider.getRecords(query)));
}
for (Future<Collection<ImportRecord>> future: futureList) {
try {
Collection<ImportRecord> importRecords = future.get();
result.addAll(Objects.isNull(importRecords) ? Collections.emptyList() : importRecords);
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}
return result;
}

@Override
public ImportRecord getRecord(Query query) throws MetadataSourceException {
throw new MethodNotFoundException("This method is not implemented for multiple external data sources");
}

@Override
public Collection<ImportRecord> findMatchingRecords(Query query) throws MetadataSourceException {
List<Future<Collection<ImportRecord>>> futureList = new ArrayList<>();
List<ImportRecord> result = new ArrayList<>();
for (QuerySource innerProvider : innerProviders) {
futureList.add(executorService.submit(() -> innerProvider.findMatchingRecords(query)));
}
for (Future<Collection<ImportRecord>> future: futureList) {
try {
Collection<ImportRecord> importRecords = future.get();
result.addAll(Objects.isNull(importRecords) ? Collections.emptyList() : importRecords);
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}
return result;
}


@Override
public Collection<ImportRecord> findMatchingRecords(Item item) throws MetadataSourceException {
List<Future<Collection<ImportRecord>>> futureList = new ArrayList<>();
List<ImportRecord> result = new ArrayList<>();
for (QuerySource innerProvider : innerProviders) {
futureList.add(executorService.submit(() -> innerProvider.findMatchingRecords(item)));
}
for (Future<Collection<ImportRecord>> future: futureList) {
try {
Collection<ImportRecord> importRecords = future.get();
result.addAll(Objects.isNull(importRecords) ? Collections.emptyList() : importRecords);
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,24 @@
<ref bean="csvImportService" />
<ref bean="tsvImportService" />
<ref bean="endnoteImportService" />
<ref bean="DoiImportService" />
</list>
</property>
</bean>

<bean id="DoiImportService"
class="org.dspace.importer.external.MultipleParallelImportMetadataSourceServiceImpl" scope="singleton">
<constructor-arg name="innerProviders">
<list>
<ref bean="CrossRefImportService"/>
<ref bean="DataCiteImportService"/>
</list>
</constructor-arg>
<constructor-arg name="sourceName">
<value>doi</value>
</constructor-arg>
</bean>

<bean id="DataCiteImportService"
class="org.dspace.importer.external.datacite.DataCiteImportMetadataSourceServiceImpl" scope="singleton">
<property name="metadataFieldMapping" ref="DataCiteMetadataFieldMapping"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/
package org.dspace.app.rest;

import static org.dspace.app.rest.utils.RegexUtils.REGEX_REQUESTMAPPING_IDENTIFIER_AS_UUID;

import java.io.IOException;
import java.sql.SQLException;
import java.util.UUID;
Expand Down Expand Up @@ -44,15 +46,9 @@
*/
@RestController
@RequestMapping("/api/" + CollectionRest.CATEGORY + "/" + CollectionRest.PLURAL_NAME
+ CollectionLogoController.REGEX_REQUESTMAPPING_IDENTIFIER_AS_UUID + "/logo")
+ REGEX_REQUESTMAPPING_IDENTIFIER_AS_UUID + "/logo")
public class CollectionLogoController {

/**
* Regular expression in the request mapping to accept UUID as identifier
*/
protected static final String REGEX_REQUESTMAPPING_IDENTIFIER_AS_UUID =
"/{uuid:[0-9a-fxA-FX]{8}-[0-9a-fxA-FX]{4}-[0-9a-fxA-FX]{4}-[0-9a-fxA-FX]{4}-[0-9a-fxA-FX]{12}}";

@Autowired
protected Utils utils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/
package org.dspace.app.rest;

import static org.dspace.app.rest.utils.RegexUtils.REGEX_REQUESTMAPPING_IDENTIFIER_AS_UUID;

import java.io.IOException;
import java.sql.SQLException;
import java.util.UUID;
Expand Down Expand Up @@ -44,15 +46,9 @@
*/
@RestController
@RequestMapping("/api/" + CommunityRest.CATEGORY + "/" + CommunityRest.PLURAL_NAME
+ CommunityLogoController.REGEX_REQUESTMAPPING_IDENTIFIER_AS_UUID + "/logo")
+ REGEX_REQUESTMAPPING_IDENTIFIER_AS_UUID + "/" + CommunityRest.LOGO)
public class CommunityLogoController {

/**
* Regular expression in the request mapping to accept UUID as identifier
*/
protected static final String REGEX_REQUESTMAPPING_IDENTIFIER_AS_UUID =
"/{uuid:[0-9a-fxA-FX]{8}-[0-9a-fxA-FX]{4}-[0-9a-fxA-FX]{4}-[0-9a-fxA-FX]{4}-[0-9a-fxA-FX]{12}}";

@Autowired
protected Utils utils;

Expand Down
Loading

0 comments on commit d1a0538

Please sign in to comment.