Skip to content

Commit

Permalink
Merged dspace-cris-7 into DSC-820-introduce-new-metadata-in-submissio…
Browse files Browse the repository at this point in the history
…n-for-bitstreams-to-show-in-advanced-attachment
  • Loading branch information
Andrea Barbasso committed Dec 6, 2023
2 parents 1df6c0b + 7053dde commit ebdc752
Show file tree
Hide file tree
Showing 63 changed files with 4,179 additions and 2,212 deletions.
2 changes: 1 addition & 1 deletion dspace-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<parent>
<groupId>org.dspace</groupId>
<artifactId>dspace-parent</artifactId>
<version>cris-2023.02.00-SNAPSHOT</version>
<version>cris-2023.02.01-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,13 @@ public Bitstream getBitstreamByName(Item item, String bundleName, String bitstre
return null;
}

@Override
public List<Bitstream> getBitstreamByBundleName(Item item, String bundleName) throws SQLException {
return itemService.getBundles(item, bundleName).stream()
.flatMap(bundle -> bundle.getBitstreams().stream())
.collect(Collectors.toList());
}

@Override
public Bitstream getFirstBitstream(Item item, String bundleName) throws SQLException {
List<Bundle> bundles = itemService.getBundles(item, bundleName);
Expand Down Expand Up @@ -545,6 +552,10 @@ public List<Bitstream> findByItemAndBundleAndMetadata(Context context, Item item

}

public boolean exists(Context context, UUID id) throws SQLException {
return this.bitstreamDAO.exists(context, Bitstream.class, id);
}

private boolean isContainedInBundleNamed(Bitstream bitstream, String name) {

if (StringUtils.isEmpty(name)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,4 +579,8 @@ public Bundle findByLegacyId(Context context, int id) throws SQLException {
public int countTotal(Context context) throws SQLException {
return bundleDAO.countRows(context);
}

public boolean exists(Context context, UUID id) throws SQLException {
return this.bundleDAO.exists(context, Bundle.class, id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1250,4 +1250,10 @@ public List<Collection> findAllCollectionsByEntityType(Context context, String e
public int countArchivedItems(Collection collection) throws ItemCountException {
return ItemCounter.getInstance().getCount(collection);
}

@Override
public boolean exists(Context context, UUID id) throws SQLException {
return this.collectionDAO.exists(context, Collection.class, id);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -725,4 +725,10 @@ public int countTotal(Context context) throws SQLException {
public int countArchivedItems(Community community) throws ItemCountException {
return ItemCounter.getInstance().getCount(community);
}

@Override
public boolean exists(Context context, UUID id) throws SQLException {
return this.communityDAO.exists(context, Community.class, id);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2249,4 +2249,8 @@ public void addResourcePolicy(Context context, Item item, int actionID, EPerson
item.getResourcePolicies().add(resourcePolicy);
}

public boolean exists(Context context, UUID id) throws SQLException {
return this.itemDAO.exists(context, Item.class, id);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,8 @@ public void delete(Context context, Site dso) throws SQLException, AuthorizeExce
public int getSupportsTypeConstant() {
return Constants.SITE;
}

public boolean exists(Context context, UUID id) throws SQLException {
return this.siteDAO.exists(context, Site.class, id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class OrcidAuthority extends ItemAuthority {

private static final Logger LOGGER = LoggerFactory.getLogger(OrcidAuthority.class);

private static final String IS_LATIN_REGEX = "\\p{IsLatin}+";

public static final String DEFAULT_ORCID_KEY = "person_identifier_orcid";

public static final String DEFAULT_INSTITUTION_KEY = "institution-affiliation-name";
Expand Down Expand Up @@ -118,9 +120,13 @@ private String getTitle(ExpandedResult result) {
String givenName = result.getGivenNames();
String familyName = result.getFamilyNames();

String title = isNotBlank(givenName) ? capitalizeFully(givenName) : "";
title += isNotBlank(familyName) ? " " + capitalizeFully(familyName) : "";

String capitalizedFamilyName = capitalizeFully(familyName);
String capitalizedGivenName = capitalizeFully(givenName);
String title = capitalizedFamilyName + ", " + capitalizedGivenName;
if (!givenName.matches(IS_LATIN_REGEX) || !familyName.matches(IS_LATIN_REGEX)) {
title = isNotBlank(familyName) ? capitalizeFully(familyName) : "";
title += isNotBlank(givenName) ? " " + capitalizeFully(givenName) : "";
}
return title.trim();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@
import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.ItemService;
import org.dspace.core.Context;
import org.dspace.discovery.IndexingService;
import org.dspace.discovery.indexobject.IndexableItem;
import org.dspace.event.Consumer;
import org.dspace.event.Event;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.dspace.utils.DSpace;

/**
Expand All @@ -38,26 +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 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()));
}
}
private final IndexingService indexer = DSpaceServicesFactory.getInstance().getServiceManager()
.getServiceByName(IndexingService.class.getName(), IndexingService.class);

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

@Override
Expand All @@ -73,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 @@ -127,6 +122,34 @@ private void assureReciprocalLink(Context ctx, Item target, String mdString, Str

itemService.addMetadata(ctx, target, mdSplit[0], mdSplit[1], mdSplit.length > 2 ? mdSplit[2] : null, null,
name, sourceUuid, Choices.CF_ACCEPTED);
reindexItem(ctx, target);
}

private void reindexItem(Context ctx, Item target) throws SQLException {
IndexableItem item = new IndexableItem(target);
item.setIndexedObject(ctx.reloadEntity(item.getIndexedObject()));
String uniqueIndexID = item.getUniqueIndexID();
if (uniqueIndexID != null) {
try {
indexer.indexContent(ctx, item, true, false, false);
log.debug("Indexed "
+ item.getTypeText()
+ ", id=" + item.getID()
+ ", unique_id=" + uniqueIndexID);
} catch (Exception e) {
log.error("Failed while indexing object: ", e);
}
}
}

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ public class METSDisseminationCrosswalk
private static final String schemaLocation =
METS_NS.getURI() + " " + METS_XSD;

private String metsPackagerPlugin;

public METSDisseminationCrosswalk() {
this.metsPackagerPlugin = METS_PACKAGER_PLUGIN;
}

public METSDisseminationCrosswalk(String metsPackagerPlugin) {
this.metsPackagerPlugin = metsPackagerPlugin;
}

@Override
public Namespace[] getNamespaces() {
return (Namespace[]) ArrayUtils.clone(namespaces);
Expand Down Expand Up @@ -103,10 +113,10 @@ public Element disseminateElement(Context context, DSpaceObject dso)

PackageDisseminator dip = (PackageDisseminator)
CoreServiceFactory.getInstance().getPluginService()
.getNamedPlugin(PackageDisseminator.class, METS_PACKAGER_PLUGIN);
.getNamedPlugin(PackageDisseminator.class, metsPackagerPlugin);
if (dip == null) {
throw new CrosswalkInternalException(
"Cannot find a disseminate plugin for package=" + METS_PACKAGER_PLUGIN);
"Cannot find a disseminate plugin for package=" + metsPackagerPlugin);
}

try {
Expand All @@ -117,11 +127,16 @@ public Element disseminateElement(Context context, DSpaceObject dso)
// Create a temporary file to disseminate into
ConfigurationService configurationService
= DSpaceServicesFactory.getInstance().getConfigurationService();
String tempDirectory = (configurationService.hasProperty("upload.temp.dir"))
String tempDirectoryPath = (configurationService.hasProperty("upload.temp.dir"))
? configurationService.getProperty("upload.temp.dir")
: System.getProperty("java.io.tmpdir");

File tempFile = File.createTempFile("METSDissemination" + dso.hashCode(), null, new File(tempDirectory));
File tempDirectory = new File(tempDirectoryPath);
if (!tempDirectory.exists()) {
tempDirectory.mkdirs();
}

File tempFile = File.createTempFile("METSDissemination" + dso.hashCode(), null, tempDirectory);
tempFile.deleteOnExit();

// Disseminate METS to temp file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import org.dspace.content.crosswalk.CrosswalkMode;
import org.dspace.content.crosswalk.StreamDisseminationCrosswalk;
import org.dspace.core.Context;

/**
* Implementation of {@link StreamDisseminationCrosswalk} related to item
Expand Down Expand Up @@ -40,4 +41,8 @@ public default Optional<String> getEntityType() {
public default CrosswalkMode getCrosswalkMode() {
return CrosswalkMode.SINGLE;
}

public default boolean isAuthorized(Context context) {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* 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.content.integration.crosswalks;

import java.io.IOException;
import java.io.OutputStream;
import java.sql.SQLException;
import javax.annotation.PostConstruct;

import org.dspace.authorize.AuthorizeException;
import org.dspace.content.DSpaceObject;
import org.dspace.content.crosswalk.CrosswalkException;
import org.dspace.content.crosswalk.METSDisseminationCrosswalk;
import org.dspace.content.crosswalk.StreamDisseminationCrosswalk;
import org.dspace.core.Context;
import org.jdom2.Element;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;

/**
* Implementation of {@link StreamDisseminationCrosswalk} that produces a METS
* manifest for the DSpace item as a metadata description, using
* {@link METSDisseminationCrosswalk}.
*
* @author Luca Giamminonni (luca.giamminonni at 4science.it)
*
*/
public class METSStreamDisseminationCrosswalk implements StreamDisseminationCrosswalk {

private METSDisseminationCrosswalk metsDisseminationCrosswalk;

@PostConstruct
public void setup() {
metsDisseminationCrosswalk = new METSDisseminationCrosswalk("AIP");
}

@Override
public boolean canDisseminate(Context context, DSpaceObject dso) {
return metsDisseminationCrosswalk.canDisseminate(dso);
}

@Override
public void disseminate(Context context, DSpaceObject dso, OutputStream out)
throws CrosswalkException, IOException, SQLException, AuthorizeException {

Element element = metsDisseminationCrosswalk.disseminateElement(context, dso);

XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat());
xmlOutputter.output(element, out);

}

@Override
public String getMIMEType() {
return "application/xml";
}

}
Loading

0 comments on commit ebdc752

Please sign in to comment.