Merge branch 'main' into DS-2670

This commit is contained in:
Mark H. Wood
2020-08-04 15:17:11 -04:00
2841 changed files with 239240 additions and 123372 deletions

11
.dockerignore Normal file
View File

@@ -0,0 +1,11 @@
.git/
.idea/
.settings/
*/target/
dspace/modules/*/target/
Dockerfile.*
dspace/src/main/docker/dspace-postgres-pgcrypto
dspace/src/main/docker/dspace-postgres-pgcrypto-curl
dspace/src/main/docker/solr
dspace/src/main/docker/README.md
dspace/src/main/docker-compose/

6
.gitattributes vendored
View File

@@ -1,6 +1,12 @@
# Auto detect text files and perform LF normalization
* text=auto
# Ensure Unix files always keep Unix line endings
*.sh text eol=lf
# Ensure Windows files always keep Windows line endings
*.bat text eol=crlf
# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain

22
.github/ISSUE_TEMPLATE/bug_report.md vendored Normal file
View File

@@ -0,0 +1,22 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug, needs triage
assignees: ''
---
**Describe the bug**
A clear and concise description of what the bug is. Include the version(s) of DSpace where you've seen this problem. Link to examples if they are public.
**To Reproduce**
Steps to reproduce the behavior:
1. Do this
2. Then this...
**Expected behavior**
A clear and concise description of what you expected to happen.
**Related work**
Link to any related tickets or PRs here.

View File

@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest a new feature for this project
title: ''
labels: new feature, needs triage
assignees: ''
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe alternatives or workarounds you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.

View File

@@ -0,0 +1,26 @@
# This workflow runs whenever a new pull request is created
# TEMPORARILY DISABLED. Unfortunately this doesn't work for PRs created from forked repositories (which is how we tend to create PRs).
# There is no known workaround yet. See https://github.community/t/how-to-use-github-token-for-prs-from-forks/16818
name: Pull Request opened
# Only run for newly opened PRs against the "main" branch
on:
pull_request:
types: [opened]
branches:
- main
jobs:
automation:
runs-on: ubuntu-latest
steps:
# Assign the PR to whomever created it. This is useful for visualizing assignments on project boards
# See https://github.com/marketplace/actions/pull-request-assigner
- name: Assign PR to creator
uses: thomaseizinger/assign-pr-creator-action@v1.0.0
# Note, this authentication token is created automatically
# See: https://docs.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
# Ignore errors. It is possible the PR was created by someone who cannot be assigned
continue-on-error: true

26
.github/pull_request_template.md vendored Normal file
View File

@@ -0,0 +1,26 @@
## References
_Add references/links to any related issues or PRs. These may include:_
* Related to [REST Contract](https://github.com/DSpace/Rest7Contract) or an open REST Contract PR, if any
* Fixes [GitHub issue](https://github.com/DSpace/DSpace/issues), if any
## Description
Short summary of changes (1-2 sentences).
## Instructions for Reviewers
Please add a more detailed description of the changes made by your PR. At a minimum, providing a bulleted list of changes in your PR is helpful to reviewers.
List of changes in this PR:
* First, ...
* Second, ...
**Include guidance for how to test or review your PR.** This may include: steps to reproduce a bug, screenshots or description of a new feature, or reasons behind specific changes.
## Checklist
_This checklist provides a reminder of what we are going to look for when reviewing your PR. You need not complete this checklist prior to creating your PR (draft PRs are always welcome). If you are unsure about an item in the checklist, don't hesitate to ask. We're here to help!_
- [ ] My PR is small in size (e.g. less than 1,000 lines of code, not including comments & integration tests). Exceptions may be made if previously agreed upon.
- [ ] My PR passes Checkstyle validation based on the [Code Style Guide](https://wiki.lyrasis.org/display/DSPACE/Code+Style+Guide).
- [ ] My PR includes Javadoc for _all new (or modified) public methods and classes_. It also includes Javadoc for large or complex private methods.
- [ ] My PR passes all tests and includes new/updated Unit or Integration Tests based on the [Code Testing Guide](https://wiki.lyrasis.org/display/DSPACE/Code+Testing+Guide).
- [ ] If my PR includes new, third-party dependencies (in any `pom.xml`), I've made sure their licenses align with the [DSpace BSD License](https://github.com/DSpace/DSpace/blob/main/LICENSE) based on the [Licensing of Contributions](https://wiki.lyrasis.org/display/DSPACE/Code+Contribution+Guidelines#CodeContributionGuidelines-LicensingofContributions) documentation.
- [ ] If my PR modifies the REST API, I've linked to the REST Contract page (or open PR) related to this change.

29
.github/workflows/issue_opened.yml vendored Normal file
View File

@@ -0,0 +1,29 @@
# This workflow runs whenever a new issue is created
name: Issue opened
on:
issues:
types: [opened]
jobs:
automation:
runs-on: ubuntu-latest
steps:
# Add the new issue to a project board, if it needs triage
# See https://github.com/marketplace/actions/create-project-card-action
- name: Add issue to project board
# Only add to project board if issue is flagged as "needs triage" or has no labels
# NOTE: By default we flag new issues as "needs triage" in our issue template
if: (contains(github.event.issue.labels.*.name, 'needs triage') || join(github.event.issue.labels.*.name) == '')
uses: technote-space/create-project-card-action@v1
# Note, the authentication token below is an ORG level Secret.
# It must be created/recreated manually via a personal access token with "public_repo" and "admin:org" permissions
# See: https://docs.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token#permissions-for-the-github_token
# This is necessary because the "DSpace Backlog" project is an org level project (i.e. not repo specific)
with:
GITHUB_TOKEN: ${{ secrets.ORG_PROJECT_TOKEN }}
PROJECT: DSpace Backlog
COLUMN: Triage
CHECK_ORG_PROJECT: true
# Ignore errors.
continue-on-error: true

5
.gitignore vendored
View File

@@ -9,6 +9,7 @@ tags
/bin/
.project
.classpath
.checkstyle
## Ignore project files created by IntelliJ IDEA
*.iml
@@ -25,7 +26,6 @@ dist/
nbdist/
nbactions.xml
nb-configuration.xml
META-INF/
## Ignore all *.properties file in root folder, EXCEPT build.properties (the default)
## KEPT FOR BACKWARDS COMPATIBILITY WITH 5.x (build.properties is now replaced with local.cfg)
@@ -39,3 +39,6 @@ META-INF/
##Mac noise
.DS_Store
##Ignore JRebel project configuration
rebel.xml

9
.lgtm.yml Normal file
View File

@@ -0,0 +1,9 @@
# LGTM Settings (https://lgtm.com/)
# For reference, see https://lgtm.com/help/lgtm/lgtm.yml-configuration-file
# or template at https://lgtm.com/static/downloads/lgtm.template.yml
extraction:
java:
index:
# Specify the Java version required to build the project
java_version: 11

View File

@@ -1,14 +1,15 @@
language: java
sudo: false
dist: trusty
env:
# Give Maven 1GB of memory to work with
- MAVEN_OPTS=-Xmx1024M
jdk:
# DS-3384 Oracle JDK 8 has DocLint enabled by default.
# DS-3384 Oracle JDK has DocLint enabled by default.
# Let's use this to catch any newly introduced DocLint issues.
- oraclejdk8
- oraclejdk11
## Should we run into any problems with oraclejdk8 on Travis, we may try the following workaround.
## https://docs.travis-ci.com/user/languages/java#Testing-Against-Multiple-JDKs
@@ -18,7 +19,6 @@ jdk:
# packages:
# - oracle-java8-installer
# Install prerequisites for building Mirage2 more rapidly
before_install:
# Remove outdated settings.xml from Travis builds. Workaround for https://github.com/travis-ci/travis-ci/issues/4629
- rm ~/.m2/settings.xml
@@ -26,19 +26,21 @@ before_install:
# Skip install stage, as we'll do it below
install: "echo 'Skipping install stage, dependencies will be downloaded during build and test stages.'"
# Two stage Build and Test
# 1. Install & Unit Test APIs
# 2. Assemble DSpace
# Build DSpace and run both Unit and Integration Tests
script:
# 1. [Install & Unit Test] Check source code licenses and run source code Unit Tests
# Summary of flags used (below):
# license:check => Validate all source code license headers
# -Dmaven.test.skip=false => Enable DSpace Unit Tests
# -DskipTests=false => Enable DSpace Unit Tests
# -DskipITs=false => Enable DSpace Integration Tests
# -P !assembly => Skip normal assembly (as it can be memory intensive)
# -Pdspace-rest => Enable optional dspace-rest module as part of build
# -P !assembly => Skip assembly of "dspace-installer" directory (as it can be memory intensive)
# -B => Maven batch/non-interactive mode (recommended for CI)
# -V => Display Maven version info before build
# -Dsurefire.rerunFailingTestsCount=2 => try again for flakey tests, and keep track of/report on number of retries
- "mvn clean install license:check -Dmaven.test.skip=false -DskipITs=false -P !assembly -B -V -Dsurefire.rerunFailingTestsCount=2"
# 2. [Assemble DSpace] Ensure overlay & assembly process works (from [src]/dspace/)
# -P !assembly => SKIP the actual building of [src]/dspace/dspace-installer (as it can be memory intensive)
- "cd dspace && mvn package -P !assembly -B -V -Dsurefire.rerunFailingTestsCount=2"
- "mvn clean install license:check -DskipTests=false -DskipITs=false -Pdspace-rest -P !assembly -B -V -Dsurefire.rerunFailingTestsCount=2"
# After a successful build and test (see 'script'), send code coverage reports to coveralls.io
# These code coverage reports are generated by jacoco-maven-plugin (during test process above).
after_success:
# Run "verify", enabling the "coveralls" profile. This sends our reports to coveralls.io (see coveralls-maven-plugin)
- "cd dspace && mvn verify -P coveralls"

63
Dockerfile Normal file
View File

@@ -0,0 +1,63 @@
# This image will be published as dspace/dspace
# See https://github.com/DSpace/DSpace/tree/main/dspace/src/main/docker for usage details
#
# This version is JDK11 compatible
# - tomcat:8-jdk11
# - ANT 1.10.7
# - maven:3-jdk-11 (see dspace-dependencies)
# - note: default tag for branch: dspace/dspace: dspace/dspace:dspace-7_x
# Step 1 - Run Maven Build
FROM dspace/dspace-dependencies:dspace-7_x as build
ARG TARGET_DIR=dspace-installer
WORKDIR /app
# The dspace-install directory will be written to /install
RUN mkdir /install \
&& chown -Rv dspace: /install \
&& chown -Rv dspace: /app
USER dspace
# Copy the DSpace source code into the workdir (excluding .dockerignore contents)
ADD --chown=dspace . /app/
COPY dspace/src/main/docker/local.cfg /app/local.cfg
# Build DSpace (note: this build doesn't include the optional, deprecated "dspace-rest" webapp)
# Copy the dspace-install directory to /install. Clean up the build to keep the docker image small
RUN mvn package && \
mv /app/dspace/target/${TARGET_DIR}/* /install && \
mvn clean
# Step 2 - Run Ant Deploy
FROM tomcat:8-jdk11 as ant_build
ARG TARGET_DIR=dspace-installer
COPY --from=build /install /dspace-src
WORKDIR /dspace-src
# Create the initial install deployment using ANT
ENV ANT_VERSION 1.10.7
ENV ANT_HOME /tmp/ant-$ANT_VERSION
ENV PATH $ANT_HOME/bin:$PATH
RUN mkdir $ANT_HOME && \
wget -qO- "https://archive.apache.org/dist/ant/binaries/apache-ant-$ANT_VERSION-bin.tar.gz" | tar -zx --strip-components=1 -C $ANT_HOME
RUN ant init_installation update_configs update_code update_webapps
# Step 3 - Run tomcat
# Create a new tomcat image that does not retain the the build directory contents
FROM tomcat:8-jdk11
ENV DSPACE_INSTALL=/dspace
COPY --from=ant_build /dspace $DSPACE_INSTALL
EXPOSE 8080 8009
ENV JAVA_OPTS=-Xmx2000m
# Run the "server" webapp off the /server path (e.g. http://localhost:8080/server/)
RUN ln -s $DSPACE_INSTALL/webapps/server /usr/local/tomcat/webapps/server
# If you wish to run "server" webapp off the ROOT path, then comment out the above RUN, and uncomment the below RUN.
# You also MUST update the URL in dspace/src/main/docker/local.cfg
# Please note that server webapp should only run on one path at a time.
#RUN mv /usr/local/tomcat/webapps/ROOT /usr/local/tomcat/webapps/ROOT.bk && \
# ln -s $DSPACE_INSTALL/webapps/server /usr/local/tomcat/webapps/ROOT

53
Dockerfile.cli Normal file
View File

@@ -0,0 +1,53 @@
# This image will be published as dspace/dspace-cli
# See https://github.com/DSpace/DSpace/tree/main/dspace/src/main/docker for usage details
#
# This version is JDK11 compatible
# - openjdk:11
# - ANT 1.10.7
# - maven:3-jdk-11 (see dspace-dependencies)
# - note: default tag for branch: dspace/dspace-cli: dspace/dspace-cli:dspace-7_x
# Step 1 - Run Maven Build
FROM dspace/dspace-dependencies:dspace-7_x as build
ARG TARGET_DIR=dspace-installer
WORKDIR /app
# The dspace-install directory will be written to /install
RUN mkdir /install \
&& chown -Rv dspace: /install \
&& chown -Rv dspace: /app
USER dspace
# Copy the DSpace source code into the workdir (excluding .dockerignore contents)
ADD --chown=dspace . /app/
COPY dspace/src/main/docker/local.cfg /app/local.cfg
# Build DSpace. Copy the dspace-install directory to /install. Clean up the build to keep the docker image small
RUN mvn package && \
mv /app/dspace/target/${TARGET_DIR}/* /install && \
mvn clean
# Step 2 - Run Ant Deploy
FROM openjdk:11 as ant_build
ARG TARGET_DIR=dspace-installer
COPY --from=build /install /dspace-src
WORKDIR /dspace-src
# Create the initial install deployment using ANT
ENV ANT_VERSION 1.10.7
ENV ANT_HOME /tmp/ant-$ANT_VERSION
ENV PATH $ANT_HOME/bin:$PATH
RUN mkdir $ANT_HOME && \
wget -qO- "https://archive.apache.org/dist/ant/binaries/apache-ant-$ANT_VERSION-bin.tar.gz" | tar -zx --strip-components=1 -C $ANT_HOME
RUN ant init_installation update_configs update_code
# Step 3 - Run jdk
# Create a new tomcat image that does not retain the the build directory contents
FROM openjdk:11
ENV DSPACE_INSTALL=/dspace
COPY --from=ant_build /dspace $DSPACE_INSTALL
ENV JAVA_OPTS=-Xmx1000m

27
Dockerfile.dependencies Normal file
View File

@@ -0,0 +1,27 @@
# This image will be published as dspace/dspace-dependencies
# The purpose of this image is to make the build for dspace/dspace run faster
#
# This version is JDK11 compatible
# - maven:3-jdk-11
# Step 1 - Run Maven Build
FROM maven:3-jdk-11 as build
ARG TARGET_DIR=dspace-installer
WORKDIR /app
RUN useradd dspace \
&& mkdir /home/dspace \
&& chown -Rv dspace: /home/dspace
USER dspace
# Copy the DSpace source code into the workdir (excluding .dockerignore contents)
ADD --chown=dspace . /app/
COPY dspace/src/main/docker/local.cfg /app/local.cfg
# Trigger the installation of all maven dependencies
RUN mvn package
# Clear the contents of the /app directory (including all maven builds), so no artifacts remain.
# This ensures when dspace:dspace is built, it will just the Maven local cache (.m2) for dependencies
USER root
RUN rm -rf /app/*

72
Dockerfile.test Normal file
View File

@@ -0,0 +1,72 @@
# This image will be published as dspace/dspace
# See https://github.com/DSpace/DSpace/tree/main/dspace/src/main/docker for usage details
#
# This version is JDK11 compatible
# - tomcat:8-jdk11
# - ANT 1.10.7
# - maven:3-jdk-11 (see dspace-dependencies)
# - note: default tag for branch: dspace/dspace: dspace/dspace:dspace-7_x-test
#
# This image is meant for TESTING/DEVELOPMENT ONLY as it deploys the old v6 REST API under HTTP (not HTTPS)
# Step 1 - Run Maven Build
FROM dspace/dspace-dependencies:dspace-7_x as build
ARG TARGET_DIR=dspace-installer
WORKDIR /app
# The dspace-install directory will be written to /install
RUN mkdir /install \
&& chown -Rv dspace: /install \
&& chown -Rv dspace: /app
USER dspace
# Copy the DSpace source code into the workdir (excluding .dockerignore contents)
ADD --chown=dspace . /app/
COPY dspace/src/main/docker/local.cfg /app/local.cfg
# Build DSpace (including the optional, deprecated "dspace-rest" webapp)
# Copy the dspace-install directory to /install. Clean up the build to keep the docker image small
RUN mvn package -Pdspace-rest && \
mv /app/dspace/target/${TARGET_DIR}/* /install && \
mvn clean
# Step 2 - Run Ant Deploy
FROM tomcat:8-jdk11 as ant_build
ARG TARGET_DIR=dspace-installer
COPY --from=build /install /dspace-src
WORKDIR /dspace-src
# Create the initial install deployment using ANT
ENV ANT_VERSION 1.10.7
ENV ANT_HOME /tmp/ant-$ANT_VERSION
ENV PATH $ANT_HOME/bin:$PATH
RUN mkdir $ANT_HOME && \
wget -qO- "https://archive.apache.org/dist/ant/binaries/apache-ant-$ANT_VERSION-bin.tar.gz" | tar -zx --strip-components=1 -C $ANT_HOME
RUN ant init_installation update_configs update_code update_webapps
# Step 3 - Run tomcat
# Create a new tomcat image that does not retain the the build directory contents
FROM tomcat:8-jdk11
ENV DSPACE_INSTALL=/dspace
COPY --from=ant_build /dspace $DSPACE_INSTALL
EXPOSE 8080 8009
ENV JAVA_OPTS=-Xmx2000m
# Run the "server" webapp off the /server path (e.g. http://localhost:8080/server/)
# and the v6.x (deprecated) REST API off the "/rest" path
RUN ln -s $DSPACE_INSTALL/webapps/server /usr/local/tomcat/webapps/server && \
ln -s $DSPACE_INSTALL/webapps/rest /usr/local/tomcat/webapps/rest
# If you wish to run "server" webapp off the ROOT path, then comment out the above RUN, and uncomment the below RUN.
# You also MUST update the URL in dspace/src/main/docker/local.cfg
# Please note that server webapp should only run on one path at a time.
#RUN mv /usr/local/tomcat/webapps/ROOT /usr/local/tomcat/webapps/ROOT.bk && \
# ln -s $DSPACE_INSTALL/webapps/server /usr/local/tomcat/webapps/ROOT && \
# ln -s $DSPACE_INSTALL/webapps/rest /usr/local/tomcat/webapps/rest
# Overwrite the v6.x (deprecated) REST API's web.xml, so that we can run it on HTTP (defaults to requiring HTTPS)
COPY dspace/src/main/docker/test/rest_web.xml $DSPACE_INSTALL/webapps/rest/WEB-INF/web.xml
RUN sed -i -e "s|\${dspace.dir}|$DSPACE_INSTALL|" $DSPACE_INSTALL/webapps/rest/WEB-INF/web.xml

View File

@@ -1,7 +1,6 @@
DSpace source code license:
DSpace source code BSD License:
Copyright (c) 2002-2016, DuraSpace. All rights reserved.
Copyright (c) 2002-2020, LYRASIS. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are

View File

@@ -199,8 +199,6 @@ https://wiki.duraspace.org/display/DSPACE/Code+Contribution+Guidelines
* Woodstox (org.codehaus.woodstox:woodstox-core-asl:4.1.4 - http://woodstox.codehaus.org)
* Woodstox (org.codehaus.woodstox:wstx-asl:3.2.0 - http://woodstox.codehaus.org)
* Woodstox (org.codehaus.woodstox:wstx-asl:3.2.7 - http://woodstox.codehaus.org)
* databene ContiPerf (org.databene:contiperf:2.3.4 - http://databene.org/contiperf)
* elasticsearch (org.elasticsearch:elasticsearch:1.4.0 - http://nexus.sonatype.org/oss-repository-hosting.html/elasticsearch)
* flyway-core (org.flywaydb:flyway-core:4.0.3 - https://flywaydb.org/flyway-core)
* Ogg and Vorbis for Java, Core (org.gagravarr:vorbis-java-core:0.1 - https://github.com/Gagravarr/VorbisJava)
* Apache Tika plugin for Ogg, Vorbis and FLAC (org.gagravarr:vorbis-java-tika:0.1 - https://github.com/Gagravarr/VorbisJava)
@@ -300,7 +298,7 @@ https://wiki.duraspace.org/display/DSPACE/Code+Contribution+Guidelines
* Repackaged Cocoon Servlet Service Implementation (org.dspace.dependencies.cocoon:dspace-cocoon-servlet-service-impl:1.0.3 - http://projects.dspace.org/dspace-pom/dspace-cocoon-servlet-service-impl)
* DSpace Kernel :: Additions and Local Customizations (org.dspace.modules:additions:6.0-rc4-SNAPSHOT - https://github.com/dspace/DSpace/modules/additions)
* Hamcrest All (org.hamcrest:hamcrest-all:1.3 - https://github.com/hamcrest/JavaHamcrest/hamcrest-all)
* Hamcrest Core (org.hamcrest:hamcrest-core:1.3 - https://github.com/hamcrest/JavaHamcrest/hamcrest-core)
* Hamcrest Core (org.hamcrest:hamcrest-all:1.3 - https://github.com/hamcrest/JavaHamcrest/hamcrest-all)
* JBibTeX (org.jbibtex:jbibtex:1.0.10 - http://www.jbibtex.org)
* ASM Core (org.ow2.asm:asm:4.1 - http://asm.objectweb.org/asm/)
* ASM Analysis (org.ow2.asm:asm-analysis:4.1 - http://asm.objectweb.org/asm-analysis/)
@@ -368,7 +366,6 @@ https://wiki.duraspace.org/display/DSPACE/Code+Contribution+Guidelines
* FindBugs-Annotations (com.google.code.findbugs:annotations:3.0.1u2 - http://findbugs.sourceforge.net/)
* MaxMind GeoIP Legacy API (com.maxmind.geoip:geoip-api:1.3.0 - https://github.com/maxmind/geoip-api-java)
* JHighlight (com.uwyn:jhighlight:1.0 - https://jhighlight.dev.java.net/)
* DSpace TM-Extractors Dependency (org.dspace.dependencies:dspace-tm-extractors:1.0.1 - http://projects.dspace.org/dspace-pom/dspace-tm-extractors)
* A Hibernate O/RM Module (org.hibernate:hibernate-core:4.2.21.Final - http://hibernate.org)
* A Hibernate O/RM Module (org.hibernate:hibernate-ehcache:4.2.21.Final - http://hibernate.org)
* Hibernate Commons Annotations (org.hibernate.common:hibernate-commons-annotations:4.0.2.Final - http://hibernate.org)

9
NOTICE
View File

@@ -1,11 +1,14 @@
Licensing Notices
=================
Licensing Notice
[July 2019] DuraSpace joined with LYRASIS (another 501(c)3 organization) in July 2019.
LYRASIS holds the copyrights of DuraSpace.
Fedora Commons joined with the DSpace Foundation and began operating under
[July 2009] Fedora Commons joined with the DSpace Foundation and began operating under
the new name DuraSpace in July 2009. DuraSpace holds the copyrights of
the DSpace Foundation, Inc.
The DSpace Foundation, Inc. is a 501(c)3 corporation established in July 2007
[July 2007] The DSpace Foundation, Inc. is a 501(c)3 corporation established in July 2007
with a mission to promote and advance the dspace platform enabling management,
access and preservation of digital works. The Foundation was able to transfer
the legal copyright from Hewlett-Packard Company (HP) and Massachusetts

View File

@@ -1,24 +1,24 @@
# DSpace
[![Build Status](https://travis-ci.org/DSpace/DSpace.png?branch=master)](https://travis-ci.org/DSpace/DSpace)
[![Build Status](https://travis-ci.com/DSpace/DSpace.png?branch=main)](https://travis-ci.com/DSpace/DSpace)
[DSpace Documentation](https://wiki.duraspace.org/display/DSDOC/) |
[DSpace Documentation](https://wiki.lyrasis.org/display/DSDOC/) |
[DSpace Releases](https://github.com/DSpace/DSpace/releases) |
[DSpace Wiki](https://wiki.duraspace.org/display/DSPACE/Home) |
[Support](https://wiki.duraspace.org/display/DSPACE/Support)
[DSpace Wiki](https://wiki.lyrasis.org/display/DSPACE/Home) |
[Support](https://wiki.lyrasis.org/display/DSPACE/Support)
DSpace open source software is a turnkey repository application used by more than
2,000 organizations and institutions worldwide to provide durable access to digital resources.
For more information, visit http://www.dspace.org/
***
:warning: **Work on DSpace 7 has begun on our `master` branch.** This means that there is temporarily NO user interface on this `master` branch. DSpace 7 will feature a new, unified [Angular](https://angular.io/) user interface, along with an enhanced, rebuilt REST API. The latest status of this work can be found on the [DSpace 7 UI Working Group](https://wiki.duraspace.org/display/DSPACE/DSpace+7+UI+Working+Group) page. Additionally, the codebases can be found in the following places:
* DSpace 7 REST API work is occurring on the [`master` branch](https://github.com/DSpace/DSpace/tree/master/dspace-spring-rest) of this repository.
* The REST Contract is being documented at https://github.com/DSpace/Rest7Contract
:warning: **Work on DSpace 7 has begun on our `main` branch.** This means that there is NO user interface on this `main` branch. DSpace 7 will feature a new, unified [Angular](https://angular.io/) user interface, along with an enhanced, rebuilt REST API. The latest status of this work can be found on the [DSpace 7 Working Group](https://wiki.lyrasis.org/display/DSPACE/DSpace+7+Working+Group) page. Additionally, the codebases can be found in the following places:
* DSpace 7 REST API work is occurring on the [`main` branch](https://github.com/DSpace/DSpace/tree/main/dspace-server-webapp) of this repository.
* The REST Contract is at https://github.com/DSpace/Rest7Contract
* DSpace 7 Angular UI work is occurring at https://github.com/DSpace/dspace-angular
**If you would like to get involved in our DSpace 7 development effort, we welcome new contributors.** Just join one of our meetings or get in touch via Slack. See the [DSpace 7 UI Working Group](https://wiki.duraspace.org/display/DSPACE/DSpace+7+UI+Working+Group) wiki page for more info.
**If you would like to get involved in our DSpace 7 development effort, we welcome new contributors.** Just join one of our meetings or get in touch via Slack. See the [DSpace 7 Working Group](https://wiki.lyrasis.org/display/DSPACE/DSpace+7+Working+Group) wiki page for more info.
**If you are looking for the ongoing maintenance work for DSpace 6 (or prior releases)**, you can find that work on the corresponding maintenance branch (e.g. [`dspace-6_x`](https://github.com/DSpace/DSpace/tree/dspace-6_x)) in this repository.
***
@@ -31,29 +31,32 @@ Past releases are all available via GitHub at https://github.com/DSpace/DSpace/r
## Documentation / Installation
Documentation for each release may be viewed online or downloaded via our [Documentation Wiki](https://wiki.duraspace.org/display/DSDOC/).
Documentation for each release may be viewed online or downloaded via our [Documentation Wiki](https://wiki.lyrasis.org/display/DSDOC/).
The latest DSpace Installation instructions are available at:
https://wiki.duraspace.org/display/DSDOC6x/Installing+DSpace
https://wiki.lyrasis.org/display/DSDOC6x/Installing+DSpace
Please be aware that, as a Java web application, DSpace requires a database (PostgreSQL or Oracle)
and a servlet container (usually Tomcat) in order to function.
More information about these and all other prerequisites can be found in the Installation instructions above.
## Running DSpace 7 in Docker
See [Running DSpace 7 with Docker Compose](dspace/src/main/docker-compose/README.md)
## Contributing
DSpace is a community built and supported project. We do not have a centralized development or support team,
but have a dedicated group of volunteers who help us improve the software, documentation, resources, etc.
We welcome contributions of any type. Here's a few basic guides that provide suggestions for contributing to DSpace:
* [How to Contribute to DSpace](https://wiki.duraspace.org/display/DSPACE/How+to+Contribute+to+DSpace): How to contribute in general (via code, documentation, bug reports, expertise, etc)
* [Code Contribution Guidelines](https://wiki.duraspace.org/display/DSPACE/Code+Contribution+Guidelines): How to give back code or contribute features, bug fixes, etc.
* [DSpace Community Advisory Team (DCAT)](https://wiki.duraspace.org/display/cmtygp/DSpace+Community+Advisory+Team): If you are not a developer, we also have an interest group specifically for repository managers. The DCAT group meets virtually, once a month, and sends open invitations to join their meetings via the [DCAT mailing list](https://groups.google.com/d/forum/DSpaceCommunityAdvisoryTeam).
* [How to Contribute to DSpace](https://wiki.lyrasis.org/display/DSPACE/How+to+Contribute+to+DSpace): How to contribute in general (via code, documentation, bug reports, expertise, etc)
* [Code Contribution Guidelines](https://wiki.lyrasis.org/display/DSPACE/Code+Contribution+Guidelines): How to give back code or contribute features, bug fixes, etc.
* [DSpace Community Advisory Team (DCAT)](https://wiki.lyrasis.org/display/cmtygp/DSpace+Community+Advisory+Team): If you are not a developer, we also have an interest group specifically for repository managers. The DCAT group meets virtually, once a month, and sends open invitations to join their meetings via the [DCAT mailing list](https://groups.google.com/d/forum/DSpaceCommunityAdvisoryTeam).
We also encourage GitHub Pull Requests (PRs) at any time. Please see our [Development with Git](https://wiki.duraspace.org/display/DSPACE/Development+with+Git) guide for more info.
We also encourage GitHub Pull Requests (PRs) at any time. Please see our [Development with Git](https://wiki.lyrasis.org/display/DSPACE/Development+with+Git) guide for more info.
In addition, a listing of all known contributors to DSpace software can be
found online at: https://wiki.duraspace.org/display/DSPACE/DSpaceContributors
found online at: https://wiki.lyrasis.org/display/DSPACE/DSpaceContributors
## Getting Help
@@ -61,12 +64,12 @@ DSpace provides public mailing lists where you can post questions or raise topic
We welcome everyone to participate in these lists:
* [dspace-community@googlegroups.com](https://groups.google.com/d/forum/dspace-community) : General discussion about DSpace platform, announcements, sharing of best practices
* [dspace-tech@googlegroups.com](https://groups.google.com/d/forum/dspace-tech) : Technical support mailing list. See also our guide for [How to troubleshoot an error](https://wiki.duraspace.org/display/DSPACE/Troubleshoot+an+error).
* [dspace-tech@googlegroups.com](https://groups.google.com/d/forum/dspace-tech) : Technical support mailing list. See also our guide for [How to troubleshoot an error](https://wiki.lyrasis.org/display/DSPACE/Troubleshoot+an+error).
* [dspace-devel@googlegroups.com](https://groups.google.com/d/forum/dspace-devel) : Developers / Development mailing list
Great Q&A is also available under the [DSpace tag on Stackoverflow](http://stackoverflow.com/questions/tagged/dspace)
Additional support options are listed at https://wiki.duraspace.org/display/DSPACE/Support
Additional support options are at https://wiki.lyrasis.org/display/DSPACE/Support
DSpace also has an active service provider network. If you'd rather hire a service provider to
install, upgrade, customize or host DSpace, then we recommend getting in touch with one of our
@@ -74,9 +77,59 @@ install, upgrade, customize or host DSpace, then we recommend getting in touch w
## Issue Tracker
The DSpace Issue Tracker can be found at: https://jira.duraspace.org/projects/DS/summary
DSpace uses GitHub to track issues:
* Backend (REST API) issues: https://github.com/DSpace/DSpace/issues
* Frontend (User Interface) issues: https://github.com/DSpace/dspace-angular/issues
## Testing
### Running Tests
By default, in DSpace, Unit Tests and Integration Tests are disabled. However, they are
run automatically by [Travis CI](https://travis-ci.com/DSpace/DSpace/) for all Pull Requests and code commits.
* How to run both Unit Tests (via `maven-surefire-plugin`) and Integration Tests (via `maven-failsafe-plugin`):
```
mvn clean test -DskipTests=false -DskipITs=false
```
* How to run just Unit Tests:
```
mvn test -DskipTests=false
```
* How to run a *single* Unit Test
```
# Run all tests in a specific test class
# NOTE: failIfNoTests=false is required to skip tests in other modules
mvn test -DskipTests=false -Dtest=[full.package.testClassName] -DfailIfNoTests=false
# Run one test method in a specific test class
mvn test -DskipTests=false -Dtest=[full.package.testClassName]#[testMethodName] -DfailIfNoTests=false
```
* How to run Integration Tests (requires enabling Unit tests too)
```
mvn verify -DskipTests=false -DskipITs=false
```
* How to run a *single* Integration Test (requires enabling Unit tests too)
```
# Run all integration tests in a specific test class
# NOTE: failIfNoTests=false is required to skip tests in other modules
mvn test -DskipTests=false -DskipITs=false -Dtest=[full.package.testClassName] -DfailIfNoTests=false
# Run one test method in a specific test class
mvn test -DskipTests=false -DskipITs=false -Dtest=[full.package.testClassName]#[testMethodName] -DfailIfNoTests=false
```
* How to run only tests of a specific DSpace module
```
# Before you can run only one module's tests, other modules may need installing into your ~/.m2
cd [dspace-src]
mvn clean install
# Then, move into a module subdirectory, and run the test command
cd [dspace-src]/dspace-server-webapp
# Choose your test command from the lists above
```
## License
DSpace source code is freely available under a standard [BSD 3-Clause license](https://opensource.org/licenses/BSD-3-Clause).
The full license is available at http://www.dspace.org/license/
The full license is available in the [LICENSE](LICENSE) file or online at http://www.dspace.org/license/

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suppressions PUBLIC
"-//Puppy Crawl//DTD Suppressions 1.2//EN"
"http://checkstyle.sourceforge.net/dtds/suppressions_1_2.dtd">
<suppressions>
<!-- Temporarily suppress indentation checks for all Tests -->
<!-- TODO: We should have these turned on. But, currently there's a known bug with indentation checks
on JMockIt Expectations blocks and similar. See https://github.com/checkstyle/checkstyle/issues/3739 -->
<suppress checks="Indentation" files="src[/\\]test[/\\]java"/>
</suppressions>

142
checkstyle.xml Normal file
View File

@@ -0,0 +1,142 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://checkstyle.sourceforge.net/dtds/configuration_1_3.dtd">
<!--
DSpace CodeStyle Requirements
1. 4-space indents for Java, and 2-space indents for XML. NO TABS ALLOWED.
2. K&R style braces required. Braces required on all blocks.
3. Do not use wildcard imports (e.g. import java.util.*). Duplicated or unused imports also not allowed.
4. Javadocs should exist for all public classes and methods. (Methods rule is unenforced at this time.) Keep it short and to the point
5. Maximum line length is 120 characters (except for long URLs, packages or imports)
6. No trailing spaces allowed (except in comments)
7. Tokens should be surrounded by whitespace (see http://checkstyle.sourceforge.net/config_whitespace.html#WhitespaceAround)
8. Each source file must include our license header (validated separately by license-maven-plugin, see pom.xml)
For more information on CheckStyle configurations below, see: http://checkstyle.sourceforge.net/checks.html
-->
<module name="Checker">
<!-- Configure checker to use UTF-8 encoding -->
<property name="charset" value="UTF-8"/>
<!-- Configure checker to run on files with these extensions -->
<property name="fileExtensions" value="java, properties, cfg, xml"/>
<!-- Suppression configurations in checkstyle-suppressions.xml in same directory -->
<module name="SuppressionFilter">
<property name="file" value="${checkstyle.suppressions.file}" default="checkstyle-suppressions.xml"/>
</module>
<!-- No tab characters ('\t') allowed in the source code -->
<module name="FileTabCharacter">
<property name="eachLine" value="true"/>
<property name="fileExtensions" value="java, properties, cfg, css, js, xml"/>
</module>
<!-- No Trailing Whitespace, except on lines that only have an asterisk (e.g. Javadoc comments) -->
<module name="RegexpSingleline">
<property name="format" value="(?&lt;!\*)\s+$|\*\s\s+$"/>
<property name="message" value="Line has trailing whitespace"/>
<property name="fileExtensions" value="java, properties, cfg, css, js, xml"/>
</module>
<!-- Allow individual lines of code to be excluded from these rules, if they are annotated
with @SuppressWarnings. See also SuppressWarningsHolder below -->
<module name="SuppressWarningsFilter" />
<!-- Maximum line length is 120 characters -->
<module name="LineLength">
<property name="fileExtensions" value="java"/>
<property name="max" value="120"/>
<!-- Only exceptions for packages, imports, URLs, and JavaDoc {@link} tags -->
<property name="ignorePattern" value="^package.*|^import.*|http://|https://|@link"/>
</module>
<!-- Check individual Java source files for specific rules -->
<module name="TreeWalker">
<!-- Highlight any TODO or FIXME comments in info messages -->
<module name="TodoComment">
<property name="severity" value="info"/>
<property name="format" value="(TODO)|(FIXME)"/>
</module>
<!-- Do not report errors on any lines annotated with @SuppressWarnings -->
<module name="SuppressWarningsHolder"/>
<!-- ##### Import statement requirements ##### -->
<!-- Star imports (e.g. import java.util.*) are NOT ALLOWED -->
<module name="AvoidStarImport"/>
<!-- Redundant import statements are NOT ALLOWED -->
<module name="RedundantImport"/>
<!-- Unused import statements are NOT ALLOWED -->
<module name="UnusedImports"/>
<!-- Ensure imports appear alphabetically and grouped -->
<module name="CustomImportOrder">
<property name="sortImportsInGroupAlphabetically" value="true"/>
<property name="separateLineBetweenGroups" value="true"/>
<property name="customImportOrderRules" value="STATIC###STANDARD_JAVA_PACKAGE###THIRD_PARTY_PACKAGE"/>
</module>
<!-- ##### Javadocs requirements ##### -->
<!-- Requirements for Javadocs for classes/interfaces -->
<module name="JavadocType">
<!-- All public classes/interfaces MUST HAVE Javadocs -->
<property name="scope" value="public"/>
<!-- Add an exception for anonymous inner classes -->
<property name="excludeScope" value="anoninner"/>
<!-- Ignore errors related to unknown tags -->
<property name="allowUnknownTags" value="true"/>
<!-- Allow params tags to be optional -->
<property name="allowMissingParamTags" value="false"/>
</module>
<!-- Requirements for Javadocs for methods -->
<module name="JavadocMethod">
<!-- All public methods MUST HAVE Javadocs -->
<!-- <property name="scope" value="public"/> -->
<!-- TODO: Above rule has been disabled because of large amount of missing public method Javadocs -->
<property name="scope" value="nothing"/>
<!-- Allow params, throws and return tags to be optional -->
<property name="allowMissingParamTags" value="true"/>
<property name="allowMissingReturnTag" value="true"/>
</module>
<!-- ##### Requirements for K&R Style braces ##### -->
<!-- Code blocks MUST HAVE braces, even single line statements (if, while, etc) -->
<module name="NeedBraces"/>
<!-- Left braces should be at the end of current line (default value)-->
<module name="LeftCurly"/>
<!-- Right braces should be on start of a new line (default value) -->
<module name="RightCurly"/>
<!-- ##### Indentation / Whitespace requirements ##### -->
<!-- Require 4-space indentation (default value) -->
<module name="Indentation"/>
<!-- Whitespace should exist around all major tokens -->
<module name="WhitespaceAround">
<!-- However, make an exception for empty constructors, methods, types, etc. -->
<property name="allowEmptyConstructors" value="true"/>
<property name="allowEmptyMethods" value="true"/>
<property name="allowEmptyTypes" value="true"/>
<property name="allowEmptyLoops" value="true"/>
</module>
<!-- Validate whitespace around Generics (angle brackets) per typical conventions
http://checkstyle.sourceforge.net/config_whitespace.html#GenericWhitespace -->
<module name="GenericWhitespace"/>
<!-- ##### Requirements for "switch" statements ##### -->
<!-- "switch" statements MUST have a "default" clause -->
<module name="MissingSwitchDefault"/>
<!-- "case" clauses in switch statements MUST include break, return, throw or continue -->
<module name="FallThrough"/>
<!-- ##### Other / Miscellaneous requirements ##### -->
<!-- Require utility classes do not have a public constructor -->
<module name="HideUtilityClassConstructor"/>
<!-- Require each variable declaration is its own statement on its own line -->
<module name="MultipleVariableDeclarations"/>
<!-- Each line of code can only include one statement -->
<module name="OneStatementPerLine"/>
<!-- Require that "catch" statements are not empty (must at least contain a comment) -->
<module name="EmptyCatchBlock"/>
</module>
</module>

25
docker-compose-cli.yml Normal file
View File

@@ -0,0 +1,25 @@
version: "3.7"
services:
dspace-cli:
image: "${DOCKER_OWNER:-dspace}/dspace-cli:${DSPACE_VER:-dspace-7_x}"
container_name: dspace-cli
build:
context: .
dockerfile: Dockerfile.cli
#environment:
volumes:
- ./dspace/src/main/docker-compose/local.cfg:/dspace/config/local.cfg
- assetstore:/dspace/assetstore
entrypoint: /dspace/bin/dspace
command: help
networks:
- dspacenet
tty: true
stdin_open: true
volumes:
assetstore:
networks:
dspacenet:

69
docker-compose.yml Normal file
View File

@@ -0,0 +1,69 @@
version: '3.7'
networks:
dspacenet:
services:
dspace:
container_name: dspace
image: "${DOCKER_OWNER:-dspace}/dspace:${DSPACE_VER:-dspace-7_x-test}"
build:
context: .
dockerfile: Dockerfile.test
depends_on:
- dspacedb
networks:
dspacenet:
ports:
- published: 8080
target: 8080
stdin_open: true
tty: true
volumes:
- assetstore:/dspace/assetstore
- ./dspace/src/main/docker-compose/local.cfg:/dspace/config/local.cfg
# Ensure that the database is ready BEFORE starting tomcat
# 1. While a TCP connection to dspacedb port 5432 is not available, continue to sleep
# 2. Then, run database migration to init database tables
# 3. Finally, start Tomcat
entrypoint:
- /bin/bash
- '-c'
- |
while (!</dev/tcp/dspacedb/5432) > /dev/null 2>&1; do sleep 1; done;
/dspace/bin/dspace database migrate
catalina.sh run
dspacedb:
container_name: dspacedb
environment:
PGDATA: /pgdata
image: dspace/dspace-postgres-pgcrypto
networks:
dspacenet:
ports:
- published: 5432
target: 5432
stdin_open: true
tty: true
volumes:
- pgdata:/pgdata
dspacesolr:
container_name: dspacesolr
image: dspace/dspace-solr
networks:
dspacenet:
ports:
- published: 8983
target: 8983
stdin_open: true
tty: true
volumes:
- solr_authority:/opt/solr/server/solr/authority/data
- solr_oai:/opt/solr/server/solr/oai/data
- solr_search:/opt/solr/server/solr/search/data
- solr_statistics:/opt/solr/server/solr/statistics/data
volumes:
assetstore:
pgdata:
solr_authority:
solr_oai:
solr_search:
solr_statistics:

View File

@@ -12,7 +12,7 @@
<parent>
<groupId>org.dspace</groupId>
<artifactId>dspace-parent</artifactId>
<version>7.0-SNAPSHOT</version>
<version>7.0-beta4-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
@@ -50,6 +50,33 @@
<configuration>
<debug>true</debug>
<showDeprecation>true</showDeprecation>
<annotationProcessorPaths>
<!-- Enable Hibernate's Metamodel Generator to generate metadata model classes
(ending in _ suffix) for more type-safe Criteria queries -->
<path>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>${hibernate.version}</version>
</path>
<!-- Enable JAXB -->
<path>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>${jaxb-api.version}</version>
</path>
<!-- Enable Commons Annotations -->
<path>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>${javax-annotation.version}</version>
</path>
<!-- Enable http://errorprone.info -->
<path>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>${errorprone.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
@@ -71,25 +98,11 @@
</execution>
</executions>
</plugin>
<!-- Verify OS license headers for all source code files -->
<plugin>
<groupId>com.mycila</groupId>
<artifactId>license-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/src/test/resources/**</exclude>
<exclude>**/src/test/data/**</exclude>
<exclude>**/.gitignore</exclude>
<exclude>src/test/data/dspaceFolder/config/spiders/**</exclude>
<exclude>src/main/java/org/apache/solr/handler/extraction/ExtractingParams.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
<version>3.0.0</version>
<executions>
<execution>
<phase>validate</phase>
@@ -124,7 +137,7 @@
<activation>
<activeByDefault>false</activeByDefault>
<!-- property>
<name>maven.test.skip</name>
<name>skipTests</name>
<value>false</value>
</property -->
</activation>
@@ -145,7 +158,7 @@
<activation>
<activeByDefault>false</activeByDefault>
<property>
<name>maven.test.skip</name>
<name>skipTests</name>
<value>false</value>
</property>
</activation>
@@ -157,7 +170,6 @@
install of DSpace, against which Tests can be run. -->
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<configuration>
<outputDirectory>${project.build.directory}/testing</outputDirectory>
<artifactItems>
@@ -192,7 +204,7 @@
(see: http://gmaven.codehaus.org/Executing+Groovy+Code )
We are generating a OS-agnostic version (agnostic.build.dir) of
the ${project.build.directory} property (full path of target dir).
This is needed by the FileWeaver & Surefire plugins (see below)
This is needed by the Surefire & Failsafe plugins (see below)
to initialize the Unit Test environment's dspace.cfg file.
Otherwise, the Unit Test Framework will not work on Windows OS.
This Groovy code was mostly borrowed from:
@@ -201,18 +213,17 @@
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>groovy-maven-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<id>setproperty</id>
<phase>generate-test-resources</phase> <!-- XXX I think this should be 'initialize' - MHW -->
<phase>initialize</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
project.properties['agnostic.build.dir'] = project.build.directory.replace(File.separator, '/');
println("Initializing Maven property 'agnostic.build.dir' to: " + project.properties['agnostic.build.dir']);
log.info("Initializing Maven property 'agnostic.build.dir' to: {}", project.properties['agnostic.build.dir']);
</source>
</configuration>
</execution>
@@ -225,63 +236,27 @@
<configuration>
<systemPropertyVariables>
<!-- Specify the dspace.dir to use for test environment -->
<!-- ${agnostic.build.dir} is set dynamically by groovy-maven-plugin above -->
<!-- This system property is loaded by AbstractDSpaceTest to initialize the test environment -->
<dspace.dir>${agnostic.build.dir}/testing/dspace/</dspace.dir>
<!-- Turn off any DSpace logging -->
<dspace.log.init.disable>true</dspace.log.init.disable>
<solr.install.dir>${agnostic.build.dir}/testing/dspace/solr/</solr.install.dir>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xml-maven-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution>
<id>validate-ALL-xml-and-xsl</id>
<phase>process-test-resources</phase>
<goals>
<goal>validate</goal>
</goals>
</execution>
</executions>
<configuration>
<validationSets>
<!-- validate ALL XML and XSL config files in the testing folder -->
<validationSet>
<dir>${agnostic.build.dir}/testing</dir>
<includes>
<include>**/*.xml</include>
<include>**/*.xsl</include>
<include>**/*.xconf</include>
</includes>
</validationSet>
<!-- validate ALL XML and XSL files throughout the project -->
<validationSet>
<dir>${root.basedir}</dir>
<includes>
<include>**/*.xml</include>
<include>**/*.xsl</include>
<include>**/*.xmap</include>
</includes>
</validationSet>
</validationSets>
</configuration>
</plugin>
<!-- Run Integration Testing! This plugin just kicks off the tests (when enabled). -->
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<!-- Specify the dspace.dir to use for test environment -->
<!-- ${agnostic.build.dir} is set dynamically by groovy-maven-plugin above -->
<dspace.dir>${agnostic.build.dir}/testing/dspace/</dspace.dir>
<!-- Turn off any DSpace logging -->
<dspace.log.init.disable>true</dspace.log.init.disable>
<solr.install.dir>${agnostic.build.dir}/testing/dspace/solr/</solr.install.dir>
</systemPropertyVariables>
</configuration>
</plugin>
@@ -291,30 +266,52 @@
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<exclusions>
<exclusion>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator-cdi</artifactId>
<version>${hibernate-validator.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
</dependency>
<dependency>
<groupId>org.dspace</groupId>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
<version>3.0.1-b10</version>
</dependency>
<dependency>
<groupId>net.handle</groupId>
<artifactId>handle</artifactId>
</dependency>
<dependency>
<groupId>net.cnri</groupId>
<artifactId>cnri-servlet-container</artifactId>
<exclusions>
<!-- Newer versions provided in our parent POM -->
<exclusion>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-commons</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Jetty is needed to run Handle Server -->
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
</dependency>
<dependency>
<groupId>org.dspace</groupId>
<artifactId>jargon</artifactId>
@@ -323,24 +320,10 @@
<groupId>org.dspace</groupId>
<artifactId>mets</artifactId>
</dependency>
<dependency>
<groupId>org.dspace.dependencies</groupId>
<artifactId>dspace-tm-extractors</artifactId>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>apache-jena-libs</artifactId>
<type>pom</type>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
@@ -351,8 +334,8 @@
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
@@ -368,8 +351,8 @@
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
@@ -385,7 +368,7 @@
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
@@ -402,10 +385,6 @@
<groupId>org.jdom</groupId>
<artifactId>jdom</artifactId>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
<dependency>
<groupId>oro</groupId>
<artifactId>oro</artifactId>
@@ -418,18 +397,6 @@
<groupId>org.apache.pdfbox</groupId>
<artifactId>fontbox</artifactId>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15</artifactId>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcmail-jdk15</artifactId>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
@@ -449,12 +416,6 @@
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
@@ -476,11 +437,6 @@
<groupId>org.dspace</groupId>
<artifactId>dspace-services</artifactId>
</dependency>
<dependency> <!-- Keep jmockit before junit -->
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@@ -497,13 +453,13 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.databene</groupId>
<artifactId>contiperf</artifactId>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
@@ -511,67 +467,187 @@
<artifactId>rome-modules</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>gr.ekt.bte</groupId>
<artifactId>bte-core</artifactId>
<version>0.9.3.5</version>
<exclusions>
<!-- A more recent version is retrieved from another dependency -->
<exclusion>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>gr.ekt.bte</groupId>
<artifactId>bte-io</artifactId>
<version>0.9.3.5</version>
<exclusions>
<!-- A more recent version is retrieved from another dependency -->
<exclusion>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</exclusion>
<!-- A more recent version is retrieved from another dependency -->
<exclusion>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>${solr.version}</version>
<version>${solr.client.version}</version>
</dependency>
<!-- Solr Core is needed for Integration Tests (to run a MockSolrServer) -->
<!-- The following Solr / Lucene dependencies also support integration tests -->
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-core</artifactId>
<scope>test</scope>
<version>${solr.client.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-continuation</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-deploy</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-http</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-io</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jmx</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-rewrite</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-security</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlets</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-xml</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<groupId>org.apache.solr</groupId>
<artifactId>solr-cell</artifactId>
<exclusions>
<!-- Newer versions provided in our parent POM -->
<exclusion>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
</exclusion>
<exclusion>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-commons</artifactId>
</exclusion>
<exclusion>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
</exclusion>
<exclusion>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-xml</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-http</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-deploy</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-continuation</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlets</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-io</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-security</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.maxmind.geoip</groupId>
<artifactId>geoip-api</artifactId>
<version>1.3.0</version>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
</dependency>
<!-- Reminder: Keep icu4j (in Parent POM) synced with version used by lucene-analyzers-icu below,
otherwise ICUFoldingFilterFactory may throw errors in tests. -->
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers-icu</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers-smartcn</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers-stempel</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>com.maxmind.geoip2</groupId>
<artifactId>geoip2</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
@@ -583,12 +659,6 @@
<version>2.1.7</version>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>com.coverity.security</groupId>
<artifactId>coverity-escapers</artifactId>
@@ -605,7 +675,6 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
@@ -614,11 +683,6 @@
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>jdbm</groupId>
<artifactId>jdbm</artifactId>
@@ -672,7 +736,6 @@
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
@@ -681,56 +744,102 @@
<type>jar</type>
</dependency>
<!-- JAXB API and implementation (no longer bundled as of Java 11) -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
</dependency>
<!-- Apache Axiom -->
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-impl</artifactId>
<!-- NOTE: SWORDv2 needs 1.2.14, required by Abdera: https://abdera.apache.org/ -->
<version>1.2.14</version>
<version>${axiom.version}</version>
<exclusions>
<!-- Exclude Geronimo as it is NOT necessary when using javax.activation (which we use)
See: https://ws.apache.org/axiom/userguide/ch04.html#d0e732 -->
<exclusion>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-api</artifactId>
<!-- NOTE: SWORDv2 needs 1.2.14, required by Abdera: https://abdera.apache.org/ -->
<version>1.2.14</version>
<version>${axiom.version}</version>
<exclusions>
<!-- Exclude Geronimo as it is NOT necessary when using javax.activation (which we use)
See: https://ws.apache.org/axiom/userguide/ch04.html#d0e732 -->
<exclusion>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.22.1</version>
<version>${jersey.version}</version>
</dependency>
<!-- S3 -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.10.50</version>
<exclusions>
<exclusion>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- S3 also wanted jackson... -->
<!-- For ORCID v2 integration -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.7.0</version>
<groupId>org.dspace</groupId>
<artifactId>orcid-jaxb-api</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.0</version>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180130</version>
</dependency>
<!-- Used for Solr core export/import -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.7.0</version>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>4.5</version>
</dependency>
<!-- Email templating -->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<version>2.0</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-core</artifactId>
<version>2.6.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.apache.bcel</groupId>
<artifactId>bcel</artifactId>
<version>6.4.0</version>
</dependency>
</dependencies>
</project>

View File

@@ -1,165 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.solr.handler.extraction;
/**
* The various Solr Parameters names to use when extracting content.
*
**/
public interface ExtractingParams {
/**
* Map all generated attribute names to field names with lowercase and underscores.
*/
public static final String LOWERNAMES = "lowernames";
/**
* if true, ignore TikaException (give up to extract text but index meta data)
*/
public static final String IGNORE_TIKA_EXCEPTION = "ignoreTikaException";
/**
* The param prefix for mapping Tika metadata to Solr fields.
* <p>
* To map a field, add a name like:
* <pre>fmap.title=solr.title</pre>
*
* In this example, the tika "title" metadata value will be added to a Solr field named "solr.title"
*
*
*/
public static final String MAP_PREFIX = "fmap.";
/**
* The boost value for the name of the field. The boost can be specified by a name mapping.
* <p>
* For example
* <pre>
* map.title=solr.title
* boost.solr.title=2.5
* </pre>
* will boost the solr.title field for this document by 2.5
*
*/
public static final String BOOST_PREFIX = "boost.";
/**
* Pass in literal values to be added to the document, as in
* <pre>
* literal.myField=Foo
* </pre>
*
*/
public static final String LITERALS_PREFIX = "literal.";
/**
* Restrict the extracted parts of a document to be indexed
* by passing in an XPath expression. All content that satisfies the XPath expr.
* will be passed to the {@link org.apache.solr.handler.extraction.SolrContentHandler}.
* <p>
* See Tika's docs for what the extracted document looks like.
*
* @see #CAPTURE_ELEMENTS
*/
public static final String XPATH_EXPRESSION = "xpath";
/**
* Only extract and return the content, do not index it.
*/
public static final String EXTRACT_ONLY = "extractOnly";
/**
* Content output format if extractOnly is true. Default is "xml", alternative is "text".
*/
public static final String EXTRACT_FORMAT = "extractFormat";
/**
* Capture attributes separately according to the name of the element, instead of just adding them to the string buffer
*/
public static final String CAPTURE_ATTRIBUTES = "captureAttr";
/**
* Literal field values will by default override other values such as metadata and content. Set this to false to revert to pre-4.0 behaviour
*/
public static final String LITERALS_OVERRIDE = "literalsOverride";
/**
* Capture the specified fields (and everything included below it that isn't capture by some other capture field) separately from the default. This is different
* then the case of passing in an XPath expression.
* <p>
* The Capture field is based on the localName returned to the {@link org.apache.solr.handler.extraction.SolrContentHandler}
* by Tika, not to be confused by the mapped field. The field name can then
* be mapped into the index schema.
* <p>
* For instance, a Tika document may look like:
* <pre>
* &lt;html&gt;
* ...
* &lt;body&gt;
* &lt;p&gt;some text here. &lt;div&gt;more text&lt;/div&gt;&lt;/p&gt;
* Some more text
* &lt;/body&gt;
* </pre>
* By passing in the p tag, you could capture all P tags separately from the rest of the t
* Thus, in the example, the capture of the P tag would be: "some text here. more text"
*
*/
public static final String CAPTURE_ELEMENTS = "capture";
/**
* The type of the stream. If not specified, Tika will use mime type detection.
*/
public static final String STREAM_TYPE = "stream.type";
/**
* Optional. The file name. If specified, Tika can take this into account while
* guessing the MIME type.
*/
public static final String RESOURCE_NAME = "resource.name";
/**
* Optional. The password for this resource. Will be used instead of the rule based password lookup mechanisms
*/
public static final String RESOURCE_PASSWORD = "resource.password";
/**
* Optional. If specified, the prefix will be prepended to all Metadata, such that it would be possible
* to setup a dynamic field to automatically capture it
*/
public static final String UNKNOWN_FIELD_PREFIX = "uprefix";
/**
* Optional. If specified and the name of a potential field cannot be determined, the default Field specified
* will be used instead.
*/
public static final String DEFAULT_FIELD = "defaultField";
/**
* Optional. If specified, loads the file as a source for password lookups for Tika encrypted documents.
* <p>
* File format is Java properties format with one key=value per line.
* The key is evaluated as a regex against the file name, and the value is the password
* The rules are evaluated top-bottom, i.e. the first match will be used
* If you want a fallback password to be always used, supply a .*=&lt;defaultmypassword&gt; at the end
*/
public static final String PASSWORD_MAP_FILE = "passwordsFile";
}

View File

@@ -17,7 +17,7 @@ import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.PosixParser;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Community;
import org.dspace.content.factory.ContentServiceFactory;
@@ -35,8 +35,7 @@ import org.dspace.handle.service.HandleService;
* @version $Revision$
*/
public class CommunityFiliator
{
public class CommunityFiliator {
protected CommunityService communityService;
protected HandleService handleService;
@@ -47,12 +46,10 @@ public class CommunityFiliator
}
/**
*
* @param argv the command line arguments given
* @throws Exception if error
*/
public static void main(String[] argv) throws Exception
{
public static void main(String[] argv) throws Exception {
// create an options object and populate it
CommandLineParser parser = new PosixParser();
@@ -73,8 +70,7 @@ public class CommunityFiliator
String parentID = null;
String childID = null;
if (line.hasOption('h'))
{
if (line.hasOption('h')) {
HelpFormatter myhelp = new HelpFormatter();
myhelp.printHelp("CommunityFiliator\n", options);
System.out
@@ -85,45 +81,37 @@ public class CommunityFiliator
System.exit(0);
}
if (line.hasOption('s'))
{
if (line.hasOption('s')) {
command = "set";
}
if (line.hasOption('r'))
{
if (line.hasOption('r')) {
command = "remove";
}
if (line.hasOption('p')) // parent
{
if (line.hasOption('p')) { // parent
parentID = line.getOptionValue('p');
}
if (line.hasOption('c')) // child
{
if (line.hasOption('c')) { // child
childID = line.getOptionValue('c');
}
// now validate
// must have a command set
if (command == null)
{
if (command == null) {
System.out
.println("Error - must run with either set or remove (run with -h flag for details)");
System.exit(1);
}
if ("set".equals(command) || "remove".equals(command))
{
if (parentID == null)
{
if ("set".equals(command) || "remove".equals(command)) {
if (parentID == null) {
System.out.println("Error - a parentID must be specified (run with -h flag for details)");
System.exit(1);
}
if (childID == null)
{
if (childID == null) {
System.out.println("Error - a childID must be specified (run with -h flag for details)");
System.exit(1);
}
@@ -135,52 +123,39 @@ public class CommunityFiliator
// we are superuser!
c.turnOffAuthorisationSystem();
try
{
try {
// validate and resolve the parent and child IDs into commmunities
Community parent = filiator.resolveCommunity(c, parentID);
Community child = filiator.resolveCommunity(c, childID);
if (parent == null)
{
if (parent == null) {
System.out.println("Error, parent community cannot be found: "
+ parentID);
System.exit(1);
}
if (child == null)
{
if (child == null) {
System.out.println("Error, child community cannot be found: "
+ childID);
System.exit(1);
}
if ("set".equals(command))
{
if ("set".equals(command)) {
filiator.filiate(c, parent, child);
}
else
{
} else {
filiator.defiliate(c, parent, child);
}
}
catch (SQLException sqlE)
{
} catch (SQLException sqlE) {
System.out.println("Error - SQL exception: " + sqlE.toString());
}
catch (AuthorizeException authE)
{
} catch (AuthorizeException authE) {
System.out.println("Error - Authorize exception: "
+ authE.toString());
}
catch (IOException ioE)
{
} catch (IOException ioE) {
System.out.println("Error - IO exception: " + ioE.toString());
}
}
/**
*
* @param c context
* @param parent parent Community
* @param child child community
@@ -189,15 +164,14 @@ public class CommunityFiliator
* @throws IOException if IO error
*/
public void filiate(Context c, Community parent, Community child)
throws SQLException, AuthorizeException, IOException
{
throws SQLException, AuthorizeException, IOException {
// check that a valid filiation would be established
// first test - proposed child must currently be an orphan (i.e.
// top-level)
Community childDad = CollectionUtils.isNotEmpty(child.getParentCommunities()) ? child.getParentCommunities().iterator().next() : null;
Community childDad = CollectionUtils.isNotEmpty(child.getParentCommunities()) ? child.getParentCommunities()
.iterator().next() : null;
if (childDad != null)
{
if (childDad != null) {
System.out.println("Error, child community: " + child.getID()
+ " already a child of: " + childDad.getID());
System.exit(1);
@@ -206,16 +180,10 @@ public class CommunityFiliator
// second test - circularity: parent's parents can't include proposed
// child
List<Community> parentDads = parent.getParentCommunities();
for (int i = 0; i < parentDads.size(); i++)
{
if (parentDads.get(i).getID().equals(child.getID()))
{
System.out
.println("Error, circular parentage - child is parent of parent");
if (parentDads.contains(child)) {
System.out.println("Error, circular parentage - child is parent of parent");
System.exit(1);
}
}
// everthing's OK
communityService.addSubcommunity(c, parent, child);
@@ -227,7 +195,6 @@ public class CommunityFiliator
}
/**
*
* @param c context
* @param parent parent Community
* @param child child community
@@ -236,33 +203,18 @@ public class CommunityFiliator
* @throws IOException if IO error
*/
public void defiliate(Context c, Community parent, Community child)
throws SQLException, AuthorizeException, IOException
{
throws SQLException, AuthorizeException, IOException {
// verify that child is indeed a child of parent
List<Community> parentKids = parent.getSubcommunities();
boolean isChild = false;
for (int i = 0; i < parentKids.size(); i++)
{
if (parentKids.get(i).getID().equals(child.getID()))
{
isChild = true;
break;
}
}
if (!isChild)
{
System.out
.println("Error, child community not a child of parent community");
if (!parentKids.contains(child)) {
System.out.println("Error, child community not a child of parent community");
System.exit(1);
}
// OK remove the mappings - but leave the community, which will become
// top-level
child.getParentCommunities().remove(parent);
parent.getSubcommunities().remove(child);
child.removeParentCommunity(parent);
parent.removeSubCommunity(child);
communityService.update(c, child);
communityService.update(c, parent);
@@ -275,31 +227,27 @@ public class CommunityFiliator
/**
* Find a community by ID
*
* @param c context
* @param communityID community ID
* @return Community object
* @throws SQLException if database error
*/
protected Community resolveCommunity(Context c, String communityID)
throws SQLException
{
throws SQLException {
Community community = null;
if (communityID.indexOf('/') != -1)
{
if (communityID.indexOf('/') != -1) {
// has a / must be a handle
community = (Community) handleService.resolveToObject(c,
communityID);
// ensure it's a community
if ((community == null)
|| (community.getType() != Constants.COMMUNITY))
{
|| (community.getType() != Constants.COMMUNITY)) {
community = null;
}
}
else
{
} else {
community = communityService.find(c, UUID.fromString(communityID));
}

View File

@@ -15,8 +15,7 @@ import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.PosixParser;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.dspace.core.ConfigurationManager;
import org.dspace.core.Context;
import org.dspace.core.I18nUtil;
@@ -42,12 +41,12 @@ import org.dspace.eperson.service.GroupService;
*
* @author Robert Tansley
* @author Richard Jones
*
* @version $Revision$
*/
public final class CreateAdministrator
{
/** DSpace Context object */
public final class CreateAdministrator {
/**
* DSpace Context object
*/
private final Context context;
protected EPersonService ePersonService;
@@ -61,8 +60,7 @@ public final class CreateAdministrator
* @throws Exception if error
*/
public static void main(String[] argv)
throws Exception
{
throws Exception {
CommandLineParser parser = new PosixParser();
Options options = new Options();
@@ -77,14 +75,11 @@ public final class CreateAdministrator
CommandLine line = parser.parse(options, argv);
if (line.hasOption("e") && line.hasOption("f") && line.hasOption("l") &&
line.hasOption("c") && line.hasOption("p"))
{
line.hasOption("c") && line.hasOption("p")) {
ca.createAdministrator(line.getOptionValue("e"),
line.getOptionValue("f"), line.getOptionValue("l"),
line.getOptionValue("c"), line.getOptionValue("p"));
}
else
{
} else {
ca.negotiateAdministratorDetails();
}
}
@@ -95,8 +90,7 @@ public final class CreateAdministrator
* @throws Exception if error
*/
protected CreateAdministrator()
throws Exception
{
throws Exception {
context = new Context();
groupService = EPersonServiceFactory.getInstance().getGroupService();
ePersonService = EPersonServiceFactory.getInstance().getEPersonService();
@@ -109,8 +103,7 @@ public final class CreateAdministrator
* @throws Exception if error
*/
protected void negotiateAdministratorDetails()
throws Exception
{
throws Exception {
Console console = System.console();
System.out.println("Creating an initial administrator account");
@@ -122,20 +115,16 @@ public final class CreateAdministrator
String lastName = null;
char[] password1 = null;
char[] password2 = null;
String language = I18nUtil.DEFAULTLOCALE.getLanguage();
String language = I18nUtil.getDefaultLocale().getLanguage();
while (!dataOK)
{
while (!dataOK) {
System.out.print("E-mail address: ");
System.out.flush();
email = console.readLine();
if (!StringUtils.isBlank(email))
{
if (!StringUtils.isBlank(email)) {
email = email.trim();
}
else
{
} else {
System.out.println("Please provide an email address.");
continue;
}
@@ -145,8 +134,7 @@ public final class CreateAdministrator
firstName = console.readLine();
if (firstName != null)
{
if (firstName != null) {
firstName = firstName.trim();
}
@@ -155,21 +143,19 @@ public final class CreateAdministrator
lastName = console.readLine();
if (lastName != null)
{
if (lastName != null) {
lastName = lastName.trim();
}
if (ConfigurationManager.getProperty("webui.supported.locales") != null)
{
System.out.println("Select one of the following languages: " + ConfigurationManager.getProperty("webui.supported.locales"));
if (ConfigurationManager.getProperty("webui.supported.locales") != null) {
System.out.println("Select one of the following languages: " + ConfigurationManager
.getProperty("webui.supported.locales"));
System.out.print("Language: ");
System.out.flush();
language = console.readLine();
if (language != null)
{
if (language != null) {
language = language.trim();
language = I18nUtil.getSupportedLocale(new Locale(language)).getLanguage();
}
@@ -187,25 +173,20 @@ public final class CreateAdministrator
password2 = console.readPassword();
//TODO real password validation
if (password1.length > 1 && Arrays.equals(password1, password2))
{
if (password1.length > 1 && Arrays.equals(password1, password2)) {
// password OK
System.out.print("Is the above data correct? (y or n): ");
System.out.flush();
String s = console.readLine();
if (s != null)
{
if (s != null) {
s = s.trim();
if (s.toLowerCase().startsWith("y"))
{
if (s.toLowerCase().startsWith("y")) {
dataOK = true;
}
}
}
else
{
} else {
System.out.println("Passwords don't match");
}
}
@@ -227,13 +208,11 @@ public final class CreateAdministrator
* @param last user's last name
* @param language preferred language
* @param pw desired password
*
* @throws Exception if error
*/
protected void createAdministrator(String email, String first, String last,
String language, String pw)
throws Exception
{
throws Exception {
// Of course we aren't an administrator yet so we need to
// circumvent authorisation
context.turnOffAuthorisationSystem();
@@ -241,8 +220,7 @@ public final class CreateAdministrator
// Find administrator group
Group admins = groupService.findByName(context, Group.ADMIN);
if (admins == null)
{
if (admins == null) {
throw new IllegalStateException("Error, no admin group (group 1) found");
}
@@ -251,8 +229,7 @@ public final class CreateAdministrator
// check if the email belongs to a registered user,
// if not create a new user with this email
if (eperson == null)
{
if (eperson == null) {
eperson = ePersonService.create(context);
eperson.setEmail(email);
eperson.setCanLogIn(true);

View File

@@ -7,7 +7,19 @@
*/
package org.dspace.administer;
import org.apache.commons.cli.*;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
import org.apache.xml.serialize.Method;
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.XMLSerializer;
@@ -19,14 +31,6 @@ import org.dspace.content.service.MetadataSchemaService;
import org.dspace.core.Context;
import org.xml.sax.SAXException;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author Graham Triggs
@@ -44,11 +48,17 @@ import java.util.Map;
* </metadata-schemas>
* }
*/
public class MetadataExporter
{
public class MetadataExporter {
protected static MetadataSchemaService metadataSchemaService = ContentServiceFactory.getInstance().getMetadataSchemaService();
protected static MetadataFieldService metadataFieldService = ContentServiceFactory.getInstance().getMetadataFieldService();
protected static MetadataSchemaService metadataSchemaService = ContentServiceFactory.getInstance()
.getMetadataSchemaService();
protected static MetadataFieldService metadataFieldService = ContentServiceFactory.getInstance()
.getMetadataFieldService();
/**
* Default constructor
*/
private MetadataExporter() { }
/**
* @param args commandline arguments
@@ -58,8 +68,8 @@ public class MetadataExporter
* @throws SQLException if database error
* @throws RegistryExportException if export error
*/
public static void main(String[] args) throws ParseException, SQLException, IOException, SAXException, RegistryExportException
{
public static void main(String[] args)
throws ParseException, SQLException, IOException, SAXException, RegistryExportException {
// create an options object and populate it
CommandLineParser parser = new PosixParser();
Options options = new Options();
@@ -70,18 +80,14 @@ public class MetadataExporter
String file = null;
String schema = null;
if (line.hasOption('f'))
{
if (line.hasOption('f')) {
file = line.getOptionValue('f');
}
else
{
} else {
usage();
System.exit(0);
}
if (line.hasOption('s'))
{
if (line.hasOption('s')) {
schema = line.getOptionValue('s');
}
@@ -90,6 +96,7 @@ public class MetadataExporter
/**
* Save a registry to a filepath
*
* @param file filepath
* @param schema schema definition to save
* @throws SQLException if database error
@@ -97,8 +104,8 @@ public class MetadataExporter
* @throws SAXException if XML error
* @throws RegistryExportException if export error
*/
public static void saveRegistry(String file, String schema) throws SQLException, IOException, SAXException, RegistryExportException
{
public static void saveRegistry(String file, String schema)
throws SQLException, IOException, SAXException, RegistryExportException {
// create a context
Context context = new Context();
context.turnOffAuthorisationSystem();
@@ -118,27 +125,22 @@ public class MetadataExporter
List<MetadataField> mdFields = null;
// If a single schema has been specified
if (schema != null && !"".equals(schema))
{
if (schema != null && !"".equals(schema)) {
// Get the id of that schema
MetadataSchema mdSchema = metadataSchemaService.find(context, schema);
if (mdSchema == null)
{
if (mdSchema == null) {
throw new RegistryExportException("no schema to export");
}
// Get the metadata fields only for the specified schema
mdFields = metadataFieldService.findAllInSchema(context, mdSchema);
}
else
{
} else {
// Get the metadata fields for all the schemas
mdFields = metadataFieldService.findAll(context);
}
// Output the metadata fields
for (MetadataField mdField : mdFields)
{
for (MetadataField mdField : mdFields) {
saveType(context, xmlSerializer, mdField);
}
@@ -151,6 +153,7 @@ public class MetadataExporter
/**
* Serialize the schema registry. If the parameter 'schema' is null or empty, save all schemas
*
* @param context DSpace Context
* @param xmlSerializer XML serializer
* @param schema schema (may be null to save all)
@@ -158,22 +161,18 @@ public class MetadataExporter
* @throws SAXException if XML error
* @throws RegistryExportException if export error
*/
public static void saveSchema(Context context, XMLSerializer xmlSerializer, String schema) throws SQLException, SAXException, RegistryExportException
{
if (schema != null && !"".equals(schema))
{
public static void saveSchema(Context context, XMLSerializer xmlSerializer, String schema)
throws SQLException, SAXException, RegistryExportException {
if (schema != null && !"".equals(schema)) {
// Find a single named schema
MetadataSchema mdSchema = metadataSchemaService.find(context, schema);
saveSchema(xmlSerializer, mdSchema);
}
else
{
} else {
// Find all schemas
List<MetadataSchema> mdSchemas = metadataSchemaService.findAll(context);
for (MetadataSchema mdSchema : mdSchemas)
{
for (MetadataSchema mdSchema : mdSchemas) {
saveSchema(xmlSerializer, mdSchema);
}
}
@@ -187,25 +186,22 @@ public class MetadataExporter
* @throws SAXException if XML error
* @throws RegistryExportException if export error
*/
private static void saveSchema(XMLSerializer xmlSerializer, MetadataSchema mdSchema) throws SAXException, RegistryExportException
{
private static void saveSchema(XMLSerializer xmlSerializer, MetadataSchema mdSchema)
throws SAXException, RegistryExportException {
// If we haven't got a schema, it's an error
if (mdSchema == null)
{
if (mdSchema == null) {
throw new RegistryExportException("no schema to export");
}
String name = mdSchema.getName();
String namespace = mdSchema.getNamespace();
if (name == null || "".equals(name))
{
if (name == null || "".equals(name)) {
System.out.println("name is null, skipping");
return;
}
if (namespace == null || "".equals(namespace))
{
if (namespace == null || "".equals(namespace)) {
System.out.println("namespace is null, skipping");
return;
}
@@ -237,11 +233,10 @@ public class MetadataExporter
* @throws SQLException if database error
* @throws IOException if IO error
*/
private static void saveType(Context context, XMLSerializer xmlSerializer, MetadataField mdField) throws SAXException, RegistryExportException, SQLException, IOException
{
private static void saveType(Context context, XMLSerializer xmlSerializer, MetadataField mdField)
throws SAXException, RegistryExportException, SQLException, IOException {
// If we haven't been given a field, it's an error
if (mdField == null)
{
if (mdField == null) {
throw new RegistryExportException("no field to export");
}
@@ -252,8 +247,7 @@ public class MetadataExporter
String scopeNote = mdField.getScopeNote();
// We must have a schema and element
if (schemaName == null || element == null)
{
if (schemaName == null || element == null) {
throw new RegistryExportException("incomplete field information");
}
@@ -271,26 +265,20 @@ public class MetadataExporter
xmlSerializer.endElement("element");
// Output the qualifier, if present
if (qualifier != null)
{
if (qualifier != null) {
xmlSerializer.startElement("qualifier", null);
xmlSerializer.characters(qualifier.toCharArray(), 0, qualifier.length());
xmlSerializer.endElement("qualifier");
}
else
{
} else {
xmlSerializer.comment("unqualified");
}
// Output the scope note, if present
if (scopeNote != null)
{
if (scopeNote != null) {
xmlSerializer.startElement("scope_note", null);
xmlSerializer.characters(scopeNote.toCharArray(), 0, scopeNote.length());
xmlSerializer.endElement("scope_note");
}
else
{
} else {
xmlSerializer.comment("no scope note");
}
@@ -298,31 +286,29 @@ public class MetadataExporter
}
static Map<Integer, String> schemaMap = new HashMap<Integer, String>();
/**
* Helper method to retrieve a schema name for the field.
* Caches the name after looking up the id.
*
* @param context DSpace Context
* @param mdField DSpace metadata field
* @return name of schema
* @throws SQLException if database error
* @throws RegistryExportException if export error
*/
private static String getSchemaName(Context context, MetadataField mdField) throws SQLException, RegistryExportException
{
private static String getSchemaName(Context context, MetadataField mdField)
throws SQLException, RegistryExportException {
// Get name from cache
String name = schemaMap.get(mdField.getMetadataSchema().getID());
if (name == null)
{
if (name == null) {
// Name not retrieved before, so get the schema now
MetadataSchema mdSchema = metadataSchemaService.find(context, mdField.getMetadataSchema().getID());
if (mdSchema != null)
{
if (mdSchema != null) {
name = mdSchema.getName();
schemaMap.put(mdSchema.getID(), name);
}
else
{
} else {
// Can't find the schema
throw new RegistryExportException("Can't get schema name for field");
}
@@ -333,8 +319,7 @@ public class MetadataExporter
/**
* Print the usage message to stdout
*/
public static void usage()
{
public static void usage() {
String usage = "Use this class with the following options:\n" +
" -f <xml output file> : specify the output file for the schemas\n" +
" -s <schema> : name of the schema to export\n";

View File

@@ -9,7 +9,6 @@ package org.dspace.administer;
import java.io.IOException;
import java.sql.SQLException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
@@ -18,12 +17,11 @@ import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
import org.apache.xpath.XPathAPI;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.MetadataField;
import org.dspace.content.MetadataSchema;
import org.dspace.content.MetadataSchemaEnum;
import org.dspace.content.NonUniqueMetadataException;
import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.MetadataFieldService;
@@ -31,11 +29,9 @@ import org.dspace.content.service.MetadataSchemaService;
import org.dspace.core.Context;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
/**
@@ -61,14 +57,22 @@ import org.xml.sax.SAXException;
* </dspace-dc-types>
* }
*/
public class MetadataImporter
{
protected static MetadataSchemaService metadataSchemaService = ContentServiceFactory.getInstance().getMetadataSchemaService();
protected static MetadataFieldService metadataFieldService = ContentServiceFactory.getInstance().getMetadataFieldService();
public class MetadataImporter {
protected static MetadataSchemaService metadataSchemaService = ContentServiceFactory.getInstance()
.getMetadataSchemaService();
protected static MetadataFieldService metadataFieldService = ContentServiceFactory.getInstance()
.getMetadataFieldService();
/** logging category */
/**
* logging category
*/
private static final Logger log = LoggerFactory.getLogger(MetadataImporter.class);
/**
* Default constructor
*/
private MetadataImporter() { }
/**
* main method for reading user input from the command line
*
@@ -86,8 +90,7 @@ public class MetadataImporter
public static void main(String[] args)
throws ParseException, SQLException, IOException, TransformerException,
ParserConfigurationException, AuthorizeException, SAXException,
NonUniqueMetadataException, RegistryImportException
{
NonUniqueMetadataException, RegistryImportException {
boolean forceUpdate = false;
// create an options object and populate it
@@ -98,12 +101,9 @@ public class MetadataImporter
CommandLine line = parser.parse(options, args);
String file = null;
if (line.hasOption('f'))
{
if (line.hasOption('f')) {
file = line.getOptionValue('f');
}
else
{
} else {
usage();
System.exit(0);
}
@@ -128,12 +128,10 @@ public class MetadataImporter
*/
public static void loadRegistry(String file, boolean forceUpdate)
throws SQLException, IOException, TransformerException, ParserConfigurationException,
AuthorizeException, SAXException, NonUniqueMetadataException, RegistryImportException
{
AuthorizeException, SAXException, NonUniqueMetadataException, RegistryImportException {
Context context = null;
try
{
try {
// create a context
context = new Context();
context.turnOffAuthorisationSystem();
@@ -145,8 +143,7 @@ public class MetadataImporter
NodeList schemaNodes = XPathAPI.selectNodeList(document, "/dspace-dc-types/dc-schema");
// Add each one as a new format to the registry
for (int i = 0; i < schemaNodes.getLength(); i++)
{
for (int i = 0; i < schemaNodes.getLength(); i++) {
Node n = schemaNodes.item(i);
loadSchema(context, n, forceUpdate);
}
@@ -155,31 +152,27 @@ public class MetadataImporter
NodeList typeNodes = XPathAPI.selectNodeList(document, "/dspace-dc-types/dc-type");
// Add each one as a new format to the registry
for (int i = 0; i < typeNodes.getLength(); i++)
{
for (int i = 0; i < typeNodes.getLength(); i++) {
Node n = typeNodes.item(i);
loadType(context, n);
}
context.restoreAuthSystemState();
context.complete();
}
finally
{
} finally {
// Clean up our context, if it still exists & it was never completed
if(context!=null && context.isValid())
if (context != null && context.isValid()) {
context.abort();
}
}
}
/**
* Process a node in the metadata registry XML file. If the
* schema already exists, it will not be recreated
*
* @param context
* DSpace context object
* @param node
* the node in the DOM tree
* @param context DSpace context object
* @param node the node in the DOM tree
* @throws SQLException if database error
* @throws IOException if IO error
* @throws TransformerException if transformer error
@@ -189,51 +182,43 @@ public class MetadataImporter
*/
private static void loadSchema(Context context, Node node, boolean updateExisting)
throws SQLException, IOException, TransformerException,
AuthorizeException, NonUniqueMetadataException, RegistryImportException
{
AuthorizeException, NonUniqueMetadataException, RegistryImportException {
// Get the values
String name = RegistryImporter.getElementData(node, "name");
String namespace = RegistryImporter.getElementData(node, "namespace");
if (name == null || "".equals(name))
{
if (name == null || "".equals(name)) {
throw new RegistryImportException("Name of schema must be supplied");
}
if (namespace == null || "".equals(namespace))
{
if (namespace == null || "".equals(namespace)) {
throw new RegistryImportException("Namespace of schema must be supplied");
}
// check to see if the schema already exists
MetadataSchema s = metadataSchemaService.find(context, name);
if (s == null)
{
if (s == null) {
// Schema does not exist - create
log.info("Registering Schema " + name + " (" + namespace + ")");
metadataSchemaService.create(context, name, namespace);
}
else
{
} else {
// Schema exists - if it's the same namespace, allow the type imports to continue
if (s.getNamespace().equals(namespace))
{
if (s.getNamespace().equals(namespace)) {
// This schema already exists with this namespace, skipping it
return;
}
// It's a different namespace - have we been told to update?
if (updateExisting)
{
if (updateExisting) {
// Update the existing schema namespace and continue to type import
log.info("Updating Schema " + name + ": New namespace " + namespace);
s.setNamespace(namespace);
metadataSchemaService.update(context, s);
}
else
{
throw new RegistryImportException("Schema " + name + " already registered with different namespace " + namespace + ". Rerun with 'update' option enabled if you wish to update this schema.");
} else {
throw new RegistryImportException(
"Schema " + name + " already registered with different namespace " + namespace + ". Rerun with " +
"'update' option enabled if you wish to update this schema.");
}
}
@@ -244,10 +229,8 @@ public class MetadataImporter
* be a "dc-type" node. If the type already exists, then it
* will not be reimported
*
* @param context
* DSpace context object
* @param node
* the node in the DOM tree
* @param context DSpace context object
* @param node the node in the DOM tree
* @throws SQLException if database error
* @throws IOException if IO error
* @throws TransformerException if transformer error
@@ -257,8 +240,7 @@ public class MetadataImporter
*/
private static void loadType(Context context, Node node)
throws SQLException, IOException, TransformerException,
AuthorizeException, NonUniqueMetadataException, RegistryImportException
{
AuthorizeException, NonUniqueMetadataException, RegistryImportException {
// Get the values
String schema = RegistryImporter.getElementData(node, "schema");
String element = RegistryImporter.getElementData(node, "element");
@@ -266,31 +248,29 @@ public class MetadataImporter
String scopeNote = RegistryImporter.getElementData(node, "scope_note");
// If the schema is not provided default to DC
if (schema == null)
{
schema = MetadataSchema.DC_SCHEMA;
if (schema == null) {
schema = MetadataSchemaEnum.DC.getName();
}
// Find the matching schema object
MetadataSchema schemaObj = metadataSchemaService.find(context, schema);
if (schemaObj == null)
{
if (schemaObj == null) {
throw new RegistryImportException("Schema '" + schema + "' is not registered and does not exist.");
}
MetadataField mf = metadataFieldService.findByElement(context, schemaObj, element, qualifier);
if (mf != null)
{
if (mf != null) {
// Metadata field already exists, skipping it
return;
}
// Actually create this metadata field as it doesn't yet exist
String fieldName = schema + "." + element + "." + qualifier;
if(qualifier==null)
if (qualifier == null) {
fieldName = schema + "." + element;
}
log.info("Registering metadata field " + fieldName);
MetadataField field = metadataFieldService.create(context, schemaObj, element, qualifier, scopeNote);
metadataFieldService.update(context, field);
@@ -299,8 +279,7 @@ public class MetadataImporter
/**
* Print the usage message to stdout
*/
public static void usage()
{
public static void usage() {
String usage = "Use this class with the following option:\n" +
" -f <xml source file> : specify which xml source file " +
"contains the DC fields to import.\n";

View File

@@ -12,13 +12,11 @@ package org.dspace.administer;
*
* An exception to report any problems with registry exports
*/
public class RegistryExportException extends Exception
{
public class RegistryExportException extends Exception {
/**
* Create an empty authorize exception
*/
public RegistryExportException()
{
public RegistryExportException() {
super();
}
@@ -27,8 +25,7 @@ public class RegistryExportException extends Exception
*
* @param message exception message
*/
public RegistryExportException(String message)
{
public RegistryExportException(String message) {
super(message);
}
@@ -38,8 +35,7 @@ public class RegistryExportException extends Exception
* @param message exception message
* @param e reference to Throwable
*/
public RegistryExportException(String message, Throwable e)
{
public RegistryExportException(String message, Throwable e) {
super(message, e);
}
@@ -48,8 +44,7 @@ public class RegistryExportException extends Exception
*
* @param e reference to Throwable
*/
public RegistryExportException(Throwable e)
{
public RegistryExportException(Throwable e) {
super(e);
}

View File

@@ -12,13 +12,11 @@ package org.dspace.administer;
*
* An exception to report any problems with registry imports
*/
public class RegistryImportException extends Exception
{
public class RegistryImportException extends Exception {
/**
* Create an empty authorize exception
*/
public RegistryImportException()
{
public RegistryImportException() {
super();
}
@@ -27,8 +25,7 @@ public class RegistryImportException extends Exception
*
* @param message error message
*/
public RegistryImportException(String message)
{
public RegistryImportException(String message) {
super(message);
}
@@ -38,8 +35,7 @@ public class RegistryImportException extends Exception
* @param message error message
* @param e throwable
*/
public RegistryImportException(String message, Throwable e)
{
public RegistryImportException(String message, Throwable e) {
super(message, e);
}
@@ -48,8 +44,7 @@ public class RegistryImportException extends Exception
*
* @param e throwable
*/
public RegistryImportException(Throwable e)
{
public RegistryImportException(Throwable e) {
super(e);
}

View File

@@ -9,18 +9,15 @@ package org.dspace.administer;
import java.io.File;
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import org.apache.xpath.XPathAPI;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
/**
@@ -31,22 +28,24 @@ import org.xml.sax.SAXException;
* I am the author, really I ripped these methods off from other
* classes
*/
public class RegistryImporter
{
public class RegistryImporter {
/**
* Default constructor
*/
private RegistryImporter() { }
/**
* Load in the XML from file.
*
* @param filename
* the filename to load from
*
* @param filename the filename to load from
* @return the DOM representation of the XML file
* @throws IOException if IO error
* @throws ParserConfigurationException if configuration parse error
* @throws SAXException if XML parse error
*/
public static Document loadXML(String filename)
throws IOException, ParserConfigurationException, SAXException
{
throws IOException, ParserConfigurationException, SAXException {
DocumentBuilder builder = DocumentBuilderFactory.newInstance()
.newDocumentBuilder();
@@ -67,21 +66,17 @@ public class RegistryImporter
* </P>
* Why this isn't a core part of the XML API I do not know...
*
* @param parentElement
* the element, whose child element you want the CDATA from
* @param childName
* the name of the element you want the CDATA from
* @throws TransformerException if error
* @param parentElement the element, whose child element you want the CDATA from
* @param childName the name of the element you want the CDATA from
* @return the CDATA as a <code>String</code>
* @throws TransformerException if error
*/
public static String getElementData(Node parentElement, String childName)
throws TransformerException
{
throws TransformerException {
// Grab the child node
Node childNode = XPathAPI.selectSingleNode(parentElement, childName);
if (childNode == null)
{
if (childNode == null) {
// No child node, so no values
return null;
}
@@ -89,8 +84,7 @@ public class RegistryImporter
// Get the #text
Node dataNode = childNode.getFirstChild();
if (dataNode == null)
{
if (dataNode == null) {
return null;
}
@@ -115,23 +109,19 @@ public class RegistryImporter
* </P>
* Why this also isn't a core part of the XML API I do not know...
*
* @param parentElement
* the element, whose child element you want the CDATA from
* @param childName
* the name of the element you want the CDATA from
* @throws TransformerException if error
* @param parentElement the element, whose child element you want the CDATA from
* @param childName the name of the element you want the CDATA from
* @return the CDATA as a <code>String</code>
* @throws TransformerException if error
*/
public static String[] getRepeatedElementData(Node parentElement,
String childName) throws TransformerException
{
String childName) throws TransformerException {
// Grab the child node
NodeList childNodes = XPathAPI.selectNodeList(parentElement, childName);
String[] data = new String[childNodes.getLength()];
for (int i = 0; i < childNodes.getLength(); i++)
{
for (int i = 0; i < childNodes.getLength(); i++) {
// Get the #text node
Node dataNode = childNodes.item(i).getFirstChild();

View File

@@ -12,13 +12,12 @@ import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import org.apache.log4j.Logger;
import org.apache.logging.log4j.Logger;
import org.apache.xpath.XPathAPI;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.BitstreamFormat;
@@ -44,12 +43,19 @@ import org.xml.sax.SAXException;
* @author Robert Tansley
* @version $Revision$
*/
public class RegistryLoader
{
/** log4j category */
private static Logger log = Logger.getLogger(RegistryLoader.class);
public class RegistryLoader {
/**
* log4j category
*/
private static Logger log = org.apache.logging.log4j.LogManager.getLogger(RegistryLoader.class);
protected static BitstreamFormatService bitstreamFormatService = ContentServiceFactory.getInstance().getBitstreamFormatService();
protected static BitstreamFormatService bitstreamFormatService = ContentServiceFactory.getInstance()
.getBitstreamFormatService();
/**
* Default constructor
*/
private RegistryLoader() { }
/**
* For invoking via the command line
@@ -57,15 +63,13 @@ public class RegistryLoader
* @param argv the command line arguments given
* @throws Exception if error
*/
public static void main(String[] argv) throws Exception
{
public static void main(String[] argv) throws Exception {
String usage = "Usage: " + RegistryLoader.class.getName()
+ " (-bitstream | -metadata) registry-file.xml";
Context context = null;
try
{
try {
context = new Context();
// Can't update registries anonymously, so we need to turn off
@@ -73,17 +77,12 @@ public class RegistryLoader
context.turnOffAuthorisationSystem();
// Work out what we're loading
if (argv[0].equalsIgnoreCase("-bitstream"))
{
if (argv[0].equalsIgnoreCase("-bitstream")) {
RegistryLoader.loadBitstreamFormats(context, argv[1]);
}
else if (argv[0].equalsIgnoreCase("-metadata"))
{
} else if (argv[0].equalsIgnoreCase("-metadata")) {
// Call MetadataImporter, as it handles Metadata schema updates
MetadataImporter.loadRegistry(argv[1], true);
}
else
{
} else {
System.err.println(usage);
}
@@ -91,36 +90,29 @@ public class RegistryLoader
context.complete();
System.exit(0);
}
catch (ArrayIndexOutOfBoundsException ae)
{
} catch (ArrayIndexOutOfBoundsException ae) {
System.err.println(usage);
System.exit(1);
}
catch (Exception e)
{
} catch (Exception e) {
log.fatal(LogManager.getHeader(context, "error_loading_registries",
""), e);
System.err.println("Error: \n - " + e.getMessage());
System.exit(1);
}
finally
{
} finally {
// Clean up our context, if it still exists & it was never completed
if(context!=null && context.isValid())
if (context != null && context.isValid()) {
context.abort();
}
}
}
/**
* Load Bitstream Format metadata
*
* @param context
* DSpace context object
* @param filename
* the filename of the XML file to load
* @param context DSpace context object
* @param filename the filename of the XML file to load
* @throws SQLException if database error
* @throws IOException if IO error
* @throws TransformerException if transformer error
@@ -130,8 +122,7 @@ public class RegistryLoader
*/
public static void loadBitstreamFormats(Context context, String filename)
throws SQLException, IOException, ParserConfigurationException,
SAXException, TransformerException, AuthorizeException
{
SAXException, TransformerException, AuthorizeException {
Document document = loadXML(filename);
// Get the nodes corresponding to formats
@@ -139,8 +130,7 @@ public class RegistryLoader
"dspace-bitstream-types/bitstream-type");
// Add each one as a new format to the registry
for (int i = 0; i < typeNodes.getLength(); i++)
{
for (int i = 0; i < typeNodes.getLength(); i++) {
Node n = typeNodes.item(i);
loadFormat(context, n);
}
@@ -153,10 +143,8 @@ public class RegistryLoader
* Process a node in the bitstream format registry XML file. The node must
* be a "bitstream-type" node
*
* @param context
* DSpace context object
* @param node
* the node in the DOM tree
* @param context DSpace context object
* @param node the node in the DOM tree
* @throws SQLException if database error
* @throws IOException if IO error
* @throws TransformerException if transformer error
@@ -164,8 +152,7 @@ public class RegistryLoader
*/
private static void loadFormat(Context context, Node node)
throws SQLException, IOException, TransformerException,
AuthorizeException
{
AuthorizeException {
// Get the values
String mimeType = getElementData(node, "mimetype");
String shortDesc = getElementData(node, "short_description");
@@ -183,14 +170,12 @@ public class RegistryLoader
BitstreamFormat exists = bitstreamFormatService.findByMIMEType(context, mimeType);
// If not found by mimeType, check by short description (since this must also be unique)
if(exists==null)
{
if (exists == null) {
exists = bitstreamFormatService.findByShortDescription(context, shortDesc);
}
// If it doesn't exist, create it..otherwise skip it.
if(exists==null)
{
if (exists == null) {
// Create the format object
BitstreamFormat format = bitstreamFormatService.create(context);
@@ -214,16 +199,14 @@ public class RegistryLoader
/**
* Load in the XML from file.
*
* @param filename
* the filename to load from
* @param filename the filename to load from
* @return the DOM representation of the XML file
* @throws IOException if IO error
* @throws ParserConfigurationException if config error
* @throws SAXException if parser error
* @return the DOM representation of the XML file
*/
private static Document loadXML(String filename) throws IOException,
ParserConfigurationException, SAXException
{
ParserConfigurationException, SAXException {
DocumentBuilder builder = DocumentBuilderFactory.newInstance()
.newDocumentBuilder();
@@ -242,21 +225,17 @@ public class RegistryLoader
* </P>
* Why this isn't a core part of the XML API I do not know...
*
* @param parentElement
* the element, whose child element you want the CDATA from
* @param childName
* the name of the element you want the CDATA from
* @throws TransformerException if transformer error
* @param parentElement the element, whose child element you want the CDATA from
* @param childName the name of the element you want the CDATA from
* @return the CDATA as a <code>String</code>
* @throws TransformerException if transformer error
*/
private static String getElementData(Node parentElement, String childName)
throws TransformerException
{
throws TransformerException {
// Grab the child node
Node childNode = XPathAPI.selectSingleNode(parentElement, childName);
if (childNode == null)
{
if (childNode == null) {
// No child node, so no values
return null;
}
@@ -264,8 +243,7 @@ public class RegistryLoader
// Get the #text
Node dataNode = childNode.getFirstChild();
if (dataNode == null)
{
if (dataNode == null) {
return null;
}
@@ -290,23 +268,19 @@ public class RegistryLoader
* </P>
* Why this also isn't a core part of the XML API I do not know...
*
* @param parentElement
* the element, whose child element you want the CDATA from
* @param childName
* the name of the element you want the CDATA from
* @throws TransformerException if transformer error
* @param parentElement the element, whose child element you want the CDATA from
* @param childName the name of the element you want the CDATA from
* @return the CDATA as a <code>String</code>
* @throws TransformerException if transformer error
*/
private static String[] getRepeatedElementData(Node parentElement,
String childName) throws TransformerException
{
String childName) throws TransformerException {
// Grab the child node
NodeList childNodes = XPathAPI.selectNodeList(parentElement, childName);
String[] data = new String[childNodes.getLength()];
for (int i = 0; i < childNodes.getLength(); i++)
{
for (int i = 0; i < childNodes.getLength(); i++) {
// Get the #text node
Node dataNode = childNodes.item(i).getFirstChild();

View File

@@ -7,14 +7,17 @@
*/
package org.dspace.administer;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
@@ -22,12 +25,18 @@ import javax.xml.transform.TransformerException;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.PosixParser;
import org.apache.commons.cli.ParseException;
import org.apache.xpath.XPathAPI;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Collection;
import org.dspace.content.Community;
import org.dspace.content.Item;
import org.dspace.content.MetadataSchemaEnum;
import org.dspace.content.MetadataValue;
import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.CollectionService;
import org.dspace.content.service.CommunityService;
@@ -35,6 +44,7 @@ import org.dspace.core.Context;
import org.dspace.eperson.factory.EPersonServiceFactory;
import org.dspace.eperson.service.EPersonService;
import org.jdom.Element;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
@@ -46,7 +56,7 @@ import org.xml.sax.SAXException;
* an XML file.
*
* The XML file structure needs to be:
* {@code
* <pre>{@code
* <import_structure>
* <community>
* <name>....</name>
@@ -56,96 +66,199 @@ import org.xml.sax.SAXException;
* </collection>
* </community>
* </import_structure>
* }
* it can be arbitrarily deep, and supports all the metadata elements
* }</pre>
* <p>
* It can be arbitrarily deep, and supports all the metadata elements
* that make up the community and collection metadata. See the system
* documentation for more details
* documentation for more details.
*
* @author Richard Jones
*
*/
public class StructBuilder
{
/** the output xml document which will contain updated information about the
* imported structure
public class StructBuilder {
/** Name of the root element for the document to be imported. */
static final String INPUT_ROOT = "import_structure";
/*
* Name of the root element for the document produced by importing.
* Community and collection elements are annotated with their identifiers.
*/
private static org.jdom.Document xmlOutput = new org.jdom.Document(new Element("imported_structure"));
static final String RESULT_ROOT = "imported_structure";
/** a hashtable to hold metadata for the collection being worked on */
private static Map<String, String> collectionMap = new HashMap<String, String>();
/**
* A table to hold metadata for the collection being worked on.
*/
private static final Map<String, String> collectionMap = new HashMap<>();
/** a hashtable to hold metadata for the community being worked on */
private static Map<String, String> communityMap = new HashMap<String, String>();
/**
* A table to hold metadata for the community being worked on.
*/
private static final Map<String, String> communityMap = new HashMap<>();
protected static CommunityService communityService = ContentServiceFactory.getInstance().getCommunityService();
protected static CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
protected static EPersonService ePersonService = EPersonServiceFactory.getInstance().getEPersonService();
protected static CommunityService communityService
= ContentServiceFactory.getInstance().getCommunityService();
protected static CollectionService collectionService
= ContentServiceFactory.getInstance().getCollectionService();
protected static EPersonService ePersonService
= EPersonServiceFactory.getInstance().getEPersonService();
/**
* Default constructor
*/
private StructBuilder() { }
/**
* Main method to be run from the command line to import a structure into
* DSpace
* DSpacee or export existing structure to a file.The command is of the form:
*
* This is of the form:
* <p>{@code StructBuilder -f [XML source] -e [administrator email] -o [output file]}
*
* {@code StructBuilder -f [xml source] -e [administrator email] -o [output file]}
* <p>to import, or
*
* The output file will contain exactly the same as the source xml document, but
* with the handle for each imported item added as an attribute.
* <p>{@code StructBuilder -x -e [administrator email] -o [output file]}</p>
*
* @param argv the command line arguments given
* @throws Exception if an error occurs
* <p>to export. The output will contain exactly the same as the source XML
* document, but with the Handle for each imported item added as an attribute.
*
*
* @param argv command line arguments.
* @throws ParserConfigurationException passed through.
* @throws SQLException passed through.
* @throws FileNotFoundException if input or output could not be opened.
* @throws TransformerException if the input document is invalid.
*/
public static void main(String[] argv)
throws Exception
{
CommandLineParser parser = new PosixParser();
throws ParserConfigurationException, SQLException,
FileNotFoundException, IOException, TransformerException {
// Define command line options.
Options options = new Options();
options.addOption( "f", "file", true, "file");
options.addOption( "e", "eperson", true, "eperson");
options.addOption("o", "output", true, "output");
options.addOption("h", "help", false, "Print this help message.");
options.addOption("?", "help");
options.addOption("x", "export", false, "Export the current structure as XML.");
CommandLine line = parser.parse( options, argv );
options.addOption(Option.builder("e").longOpt("eperson")
.desc("User who is manipulating the repository's structure.")
.hasArg().argName("eperson").required().build());
String file = null;
String eperson = null;
String output = null;
options.addOption(Option.builder("f").longOpt("file")
.desc("File of new structure information.")
.hasArg().argName("input").build());
if (line.hasOption('f'))
{
file = line.getOptionValue('f');
options.addOption(Option.builder("o").longOpt("output")
.desc("File to receive the structure map ('-' for standard out).")
.hasArg().argName("output").required().build());
// Parse the command line.
CommandLineParser parser = new DefaultParser();
CommandLine line = null;
try {
line = parser.parse(options, argv);
} catch (ParseException ex) {
System.err.println(ex.getMessage());
usage(options);
System.exit(1);
}
if (line.hasOption('e'))
{
eperson = line.getOptionValue('e');
}
if (line.hasOption('o'))
{
output = line.getOptionValue('o');
}
if (output == null || eperson == null || file == null)
{
usage();
// If the user asked for help, give it and exit.
if (line.hasOption('h') || line.hasOption('?')) {
giveHelp(options);
System.exit(0);
}
// Otherwise, analyze the command.
// Must be import or export.
if (!(line.hasOption('f') || line.hasOption('x'))) {
giveHelp(options);
System.exit(1);
}
// Open the output stream.
String output = line.getOptionValue('o');
OutputStream outputStream;
if ("-".equals(output)) {
outputStream = System.out;
} else {
outputStream = new FileOutputStream(output);
}
// create a context
Context context = new Context();
// set the context
// set the context.
String eperson = line.getOptionValue('e');
try {
context.setCurrentUser(ePersonService.findByEmail(context, eperson));
} catch (SQLException ex) {
System.err.format("That user could not be found: %s%n", ex.getMessage());
System.exit(1);
}
// Export? Import?
if (line.hasOption('x')) { // export
exportStructure(context, outputStream);
} else { // Must be import
String input = line.getOptionValue('f');
if (null == input) {
usage(options);
System.exit(1);
}
InputStream inputStream;
if ("-".equals(input)) {
inputStream = System.in;
} else {
inputStream = new FileInputStream(input);
}
importStructure(context, inputStream, outputStream);
// save changes from import
context.complete();
}
System.exit(0);
}
/**
* Import new Community/Collection structure.
*
* @param context
* @param input XML which describes the new communities and collections.
* @param output input, annotated with the new objects' identifiers.
* @throws IOException
* @throws ParserConfigurationException
* @throws SAXException
* @throws TransformerException
* @throws SQLException
*/
static void importStructure(Context context, InputStream input, OutputStream output)
throws IOException, ParserConfigurationException, SQLException, TransformerException {
// load the XML
Document document = loadXML(file);
Document document = null;
try {
document = loadXML(input);
} catch (IOException ex) {
System.err.format("The input document could not be read: %s%n", ex.getMessage());
System.exit(1);
} catch (SAXException ex) {
System.err.format("The input document could not be parsed: %s%n", ex.getMessage());
System.exit(1);
}
// run the preliminary validation, to be sure that the the XML document
// is properly structured
// is properly structured.
try {
validate(document);
} catch (TransformerException ex) {
System.err.format("The input document is invalid: %s%n", ex.getMessage());
System.exit(1);
}
// Check for 'identifier' attributes -- possibly output by this class.
NodeList identifierNodes = XPathAPI.selectNodeList(document, "//*[@identifier]");
if (identifierNodes.getLength() > 0) {
System.err.println("The input document has 'identifier' attributes, which will be ignored.");
}
// load the mappings into the member variable hashmaps
communityMap.put("name", "name");
@@ -162,119 +275,235 @@ public class StructBuilder
collectionMap.put("license", "license");
collectionMap.put("provenance", "provenance_description");
Element[] elements = new Element[]{};
try {
// get the top level community list
NodeList first = XPathAPI.selectNodeList(document, "/import_structure/community");
// run the import starting with the top level communities
Element[] elements = handleCommunities(context, first, null);
elements = handleCommunities(context, first, null);
} catch (TransformerException ex) {
System.err.format("Input content not understood: %s%n", ex.getMessage());
System.exit(1);
} catch (AuthorizeException ex) {
System.err.format("Not authorized: %s%n", ex.getMessage());
System.exit(1);
}
// generate the output
Element root = xmlOutput.getRootElement();
for (int i = 0; i < elements.length; i++)
{
root.addContent(elements[i]);
final Element root = new Element(RESULT_ROOT);
for (Element element : elements) {
root.addContent(element);
}
// finally write the string into the output file
try
{
BufferedWriter out = new BufferedWriter(new FileWriter(output));
out.write(new XMLOutputter().outputString(xmlOutput));
out.close();
// finally write the string into the output file.
final org.jdom.Document xmlOutput = new org.jdom.Document(root);
try {
new XMLOutputter().output(xmlOutput, output);
} catch (IOException e) {
System.out.printf("Unable to write to output file %s: %s%n",
output, e.getMessage());
System.exit(1);
}
catch (IOException e)
{
System.out.println("Unable to write to output file " + output);
System.exit(0);
}
context.complete();
}
/**
* Output the usage information
* Add a single community, and its children, to the Document.
*
* @param community
* @return a fragment representing this Community.
*/
private static void usage()
{
System.out.println("Usage: java StructBuilder -f <source XML file> -o <output file> -e <eperson email>");
System.out.println("Communities will be created from the top level, and a map of communities to handles will be returned in the output file");
return;
private static Element exportACommunity(Community community) {
// Export this Community.
Element element = new Element("community");
element.setAttribute("identifier", community.getHandle());
element.addContent(new Element("name").setText(community.getName()));
element.addContent(new Element("description")
.setText(communityService.getMetadataFirstValue(community,
MetadataSchemaEnum.DC.getName(), "description", "abstract", Item.ANY)));
element.addContent(new Element("intro")
.setText(communityService.getMetadataFirstValue(community,
MetadataSchemaEnum.DC.getName(), "description", null, Item.ANY)));
element.addContent(new Element("copyright")
.setText(communityService.getMetadataFirstValue(community,
MetadataSchemaEnum.DC.getName(), "rights", null, Item.ANY)));
element.addContent(new Element("sidebar")
.setText(communityService.getMetadataFirstValue(community,
MetadataSchemaEnum.DC.getName(), "description", "tableofcontents", Item.ANY)));
// Export this Community's Community children.
for (Community subCommunity : community.getSubcommunities()) {
element.addContent(exportACommunity(subCommunity));
}
// Export this Community's Collection children.
for (Collection collection : community.getCollections()) {
element.addContent(exportACollection(collection));
}
return element;
}
/**
* Validate the XML document. This method does not return, but if validation
* fails it generates an error and ceases execution
* Add a single Collection to the Document.
*
* @param collection
* @return a fragment representing this Collection.
*/
private static Element exportACollection(Collection collection) {
// Export this Collection.
Element element = new Element("collection");
element.setAttribute("identifier", collection.getHandle());
element.addContent(new Element("name").setText(collection.getName()));
element.addContent(new Element("description")
.setText(collectionService.getMetadataFirstValue(collection,
MetadataSchemaEnum.DC.getName(), "description", "abstract", Item.ANY)));
element.addContent(new Element("intro")
.setText(collectionService.getMetadataFirstValue(collection,
MetadataSchemaEnum.DC.getName(), "description", null, Item.ANY)));
element.addContent(new Element("copyright")
.setText(collectionService.getMetadataFirstValue(collection,
MetadataSchemaEnum.DC.getName(), "rights", null, Item.ANY)));
element.addContent(new Element("sidebar")
.setText(collectionService.getMetadataFirstValue(collection,
MetadataSchemaEnum.DC.getName(), "description", "tableofcontents", Item.ANY)));
element.addContent(new Element("license")
.setText(collectionService.getMetadataFirstValue(collection,
MetadataSchemaEnum.DC.getName(), "rights", "license", Item.ANY)));
// Provenance is special: multivalued
for (MetadataValue value : collectionService.getMetadata(collection,
MetadataSchemaEnum.DC.getName(), "provenance", null, Item.ANY)) {
element.addContent(new Element("provenance")
.setText(value.getValue()));
}
return element;
}
/**
* Write out the existing Community/Collection structure.
*/
static void exportStructure(Context context, OutputStream output) {
// Build a document from the Community/Collection hierarchy.
Element rootElement = new Element(INPUT_ROOT); // To be read by importStructure, perhaps
List<Community> communities = null;
try {
communities = communityService.findAllTop(context);
} catch (SQLException ex) {
System.out.printf("Unable to get the list of top-level communities: %s%n",
ex.getMessage());
System.exit(1);
}
for (Community community : communities) {
rootElement.addContent(exportACommunity(community));
}
// Now write the structure out.
org.jdom.Document xmlOutput = new org.jdom.Document(rootElement);
try {
XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
outputter.output(xmlOutput, output);
} catch (IOException e) {
System.out.printf("Unable to write to output file %s: %s%n",
output, e.getMessage());
System.exit(1);
}
}
/**
* Output the usage information.
*/
private static void usage(Options options) {
HelpFormatter helper = new HelpFormatter();
try (PrintWriter writer = new PrintWriter(System.out);) {
helper.printUsage(writer, 80/* FIXME Magic */,
"structure-builder", options);
}
}
/**
* Help the user more.
*/
private static void giveHelp(Options options) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("struct-builder",
"Import or export Community/Collection structure.",
options,
"When importing (-f), communities will be created from the "
+ "top level, and a map of communities to handles will "
+ "be returned in the output file. When exporting (-x),"
+ "the current structure will be written to the map file.",
true);
}
/**
* Validate the XML document. This method returns if the document is valid.
* If validation fails it generates an error and ceases execution.
*
* @param document the XML document object
* @throws TransformerException if transformer error
*
*/
private static void validate(org.w3c.dom.Document document)
throws TransformerException
{
StringBuffer err = new StringBuffer();
throws TransformerException {
StringBuilder err = new StringBuilder();
boolean trip = false;
err.append("The following errors were encountered parsing the source XML\n");
err.append("No changes have been made to the DSpace instance\n\n");
err.append("The following errors were encountered parsing the source XML.\n");
err.append("No changes have been made to the DSpace instance.\n\n");
NodeList first = XPathAPI.selectNodeList(document, "/import_structure/community");
if (first.getLength() == 0)
{
err.append("-There are no top level communities in the source document");
if (first.getLength() == 0) {
err.append("-There are no top level communities in the source document.");
System.out.println(err.toString());
System.exit(0);
System.exit(1);
}
String errs = validateCommunities(first, 1);
if (errs != null)
{
if (errs != null) {
err.append(errs);
trip = true;
}
if (trip)
{
if (trip) {
System.out.println(err.toString());
System.exit(0);
System.exit(1);
}
}
/**
* Validate the communities section of the XML document. This returns a string
* containing any errors encountered, or null if there were no errors
* containing any errors encountered, or null if there were no errors.
*
* @param communities the NodeList of communities to validate
* @param level the level in the XML document that we are at, for the purposes
* of error reporting
*
* @return the errors that need to be generated by the calling method, or null if
* no errors.
*/
private static String validateCommunities(NodeList communities, int level)
throws TransformerException
{
StringBuffer err = new StringBuffer();
throws TransformerException {
StringBuilder err = new StringBuilder();
boolean trip = false;
String errs = null;
for (int i = 0; i < communities.getLength(); i++)
{
for (int i = 0; i < communities.getLength(); i++) {
Node n = communities.item(i);
NodeList name = XPathAPI.selectNodeList(n, "name");
if (name.getLength() != 1)
{
if (name.getLength() != 1) {
String pos = Integer.toString(i + 1);
err.append("-The level " + level + " community in position " + pos);
err.append(" does not contain exactly one name field\n");
err.append("-The level ").append(level)
.append(" community in position ").append(pos)
.append(" does not contain exactly one name field.\n");
trip = true;
}
// validate sub communities
NodeList subCommunities = XPathAPI.selectNodeList(n, "community");
String comErrs = validateCommunities(subCommunities, level + 1);
if (comErrs != null)
{
if (comErrs != null) {
err.append(comErrs);
trip = true;
}
@@ -282,15 +511,13 @@ public class StructBuilder
// validate collections
NodeList collections = XPathAPI.selectNodeList(n, "collection");
String colErrs = validateCollections(collections, level + 1);
if (colErrs != null)
{
if (colErrs != null) {
err.append(colErrs);
trip = true;
}
}
if (trip)
{
if (trip) {
errs = err.toString();
}
@@ -299,35 +526,31 @@ public class StructBuilder
/**
* validate the collection section of the XML document. This generates a
* string containing any errors encountered, or returns null if no errors
* string containing any errors encountered, or returns null if no errors.
*
* @param collections a NodeList of collections to validate
* @param level the level in the XML document for the purposes of error reporting
*
* @return the errors to be generated by the calling method, or null if none
*/
private static String validateCollections(NodeList collections, int level)
throws TransformerException
{
StringBuffer err = new StringBuffer();
throws TransformerException {
StringBuilder err = new StringBuilder();
boolean trip = false;
String errs = null;
for (int i = 0; i < collections.getLength(); i++)
{
for (int i = 0; i < collections.getLength(); i++) {
Node n = collections.item(i);
NodeList name = XPathAPI.selectNodeList(n, "name");
if (name.getLength() != 1)
{
if (name.getLength() != 1) {
String pos = Integer.toString(i + 1);
err.append("-The level " + level + " collection in position " + pos);
err.append(" does not contain exactly one name field\n");
err.append("-The level ").append(level)
.append(" collection in position ").append(pos)
.append(" does not contain exactly one name field.\n");
trip = true;
}
}
if (trip)
{
if (trip) {
errs = err.toString();
}
@@ -335,20 +558,17 @@ public class StructBuilder
}
/**
* Load in the XML from file.
* Load the XML document from input.
*
* @param filename
* the filename to load from
*
* @return the DOM representation of the XML file
* @param input the filename to load from.
* @return the DOM representation of the XML input.
*/
private static org.w3c.dom.Document loadXML(String filename)
throws IOException, ParserConfigurationException, SAXException
{
private static org.w3c.dom.Document loadXML(InputStream input)
throws IOException, ParserConfigurationException, SAXException {
DocumentBuilder builder = DocumentBuilderFactory.newInstance()
.newDocumentBuilder();
org.w3c.dom.Document document = builder.parse(new File(filename));
org.w3c.dom.Document document = builder.parse(input);
return document;
}
@@ -357,19 +577,15 @@ public class StructBuilder
* Return the String value of a Node
*
* @param node the node from which we want to extract the string value
*
* @return the string value of the node
*/
public static String getStringValue(Node node)
{
private static String getStringValue(Node node) {
String value = node.getNodeValue();
if (node.hasChildNodes())
{
if (node.hasChildNodes()) {
Node first = node.getFirstChild();
if (first.getNodeType() == Node.TEXT_NODE)
{
if (first.getNodeType() == Node.TEXT_NODE) {
return first.getNodeValue().trim();
}
}
@@ -384,27 +600,21 @@ public class StructBuilder
* @param context the context of the request
* @param communities a nodelist of communities to create along with their sub-structures
* @param parent the parent community of the nodelist of communities to create
*
* @return an element array containing additional information regarding the
* created communities (e.g. the handles they have been assigned)
*/
private static Element[] handleCommunities(Context context, NodeList communities, Community parent)
throws TransformerException, SQLException, Exception
{
throws TransformerException, SQLException, AuthorizeException {
Element[] elements = new Element[communities.getLength()];
for (int i = 0; i < communities.getLength(); i++)
{
for (int i = 0; i < communities.getLength(); i++) {
Community community;
Element element = new Element("community");
// create the community or sub community
if (parent != null)
{
if (parent != null) {
community = communityService.create(parent, context);
}
else
{
} else {
community = communityService.create(null, context);
}
@@ -413,22 +623,18 @@ public class StructBuilder
// now update the metadata
Node tn = communities.item(i);
for (Map.Entry<String, String> entry : communityMap.entrySet())
{
for (Map.Entry<String, String> entry : communityMap.entrySet()) {
NodeList nl = XPathAPI.selectNodeList(tn, entry.getKey());
if (nl.getLength() == 1)
{
if (nl.getLength() == 1) {
communityService.setMetadata(context, community, entry.getValue(), getStringValue(nl.item(0)));
}
}
// FIXME: at the moment, if the community already exists by name
// then this will throw a PSQLException on a duplicate key
// violation
// Ideally we'd skip this row and continue to create sub
// communities
// and so forth where they don't exist, but it's proving
// difficult
// then this will throw an SQLException on a duplicate key
// violation.
// Ideally we'd skip this row and continue to create sub communities
// and so forth where they don't exist, but it's proving difficult
// to isolate the community that already exists without hitting
// the database directly.
communityService.update(context, community);
@@ -447,29 +653,25 @@ public class StructBuilder
nameElement.setText(communityService.getMetadata(community, "name"));
element.addContent(nameElement);
if (communityService.getMetadata(community, "short_description") != null)
{
if (communityService.getMetadata(community, "short_description") != null) {
Element descriptionElement = new Element("description");
descriptionElement.setText(communityService.getMetadata(community, "short_description"));
element.addContent(descriptionElement);
}
if (communityService.getMetadata(community, "introductory_text") != null)
{
if (communityService.getMetadata(community, "introductory_text") != null) {
Element introElement = new Element("intro");
introElement.setText(communityService.getMetadata(community, "introductory_text"));
element.addContent(introElement);
}
if (communityService.getMetadata(community, "copyright_text") != null)
{
if (communityService.getMetadata(community, "copyright_text") != null) {
Element copyrightElement = new Element("copyright");
copyrightElement.setText(communityService.getMetadata(community, "copyright_text"));
element.addContent(copyrightElement);
}
if (communityService.getMetadata(community, "side_bar_text") != null)
{
if (communityService.getMetadata(community, "side_bar_text") != null) {
Element sidebarElement = new Element("sidebar");
sidebarElement.setText(communityService.getMetadata(community, "side_bar_text"));
element.addContent(sidebarElement);
@@ -484,12 +686,10 @@ public class StructBuilder
Element[] collectionElements = handleCollections(context, collections, community);
int j;
for (j = 0; j < subCommunityElements.length; j++)
{
for (j = 0; j < subCommunityElements.length; j++) {
element.addContent(subCommunityElements[j]);
}
for (j = 0; j < collectionElements.length; j++)
{
for (j = 0; j < collectionElements.length; j++) {
element.addContent(collectionElements[j]);
}
@@ -505,17 +705,14 @@ public class StructBuilder
* @param context the context of the request
* @param collections the node list of collections to be created
* @param parent the parent community to whom the collections belong
*
* @return an Element array containing additional information about the
* created collections (e.g. the handle)
*/
private static Element[] handleCollections(Context context, NodeList collections, Community parent)
throws TransformerException, SQLException, AuthorizeException, IOException, Exception
{
throws TransformerException, SQLException, AuthorizeException {
Element[] elements = new Element[collections.getLength()];
for (int i = 0; i < collections.getLength(); i++)
{
for (int i = 0; i < collections.getLength(); i++) {
Element element = new Element("collection");
Collection collection = collectionService.create(context, parent);
@@ -524,11 +721,9 @@ public class StructBuilder
// import the rest of the metadata
Node tn = collections.item(i);
for (Map.Entry<String, String> entry : collectionMap.entrySet())
{
for (Map.Entry<String, String> entry : collectionMap.entrySet()) {
NodeList nl = XPathAPI.selectNodeList(tn, entry.getKey());
if (nl.getLength() == 1)
{
if (nl.getLength() == 1) {
collectionService.setMetadata(context, collection, entry.getValue(), getStringValue(nl.item(0)));
}
}
@@ -541,43 +736,37 @@ public class StructBuilder
nameElement.setText(collectionService.getMetadata(collection, "name"));
element.addContent(nameElement);
if (collectionService.getMetadata(collection, "short_description") != null)
{
if (collectionService.getMetadata(collection, "short_description") != null) {
Element descriptionElement = new Element("description");
descriptionElement.setText(collectionService.getMetadata(collection, "short_description"));
element.addContent(descriptionElement);
}
if (collectionService.getMetadata(collection, "introductory_text") != null)
{
if (collectionService.getMetadata(collection, "introductory_text") != null) {
Element introElement = new Element("intro");
introElement.setText(collectionService.getMetadata(collection, "introductory_text"));
element.addContent(introElement);
}
if (collectionService.getMetadata(collection, "copyright_text") != null)
{
if (collectionService.getMetadata(collection, "copyright_text") != null) {
Element copyrightElement = new Element("copyright");
copyrightElement.setText(collectionService.getMetadata(collection, "copyright_text"));
element.addContent(copyrightElement);
}
if (collectionService.getMetadata(collection, "side_bar_text") != null)
{
if (collectionService.getMetadata(collection, "side_bar_text") != null) {
Element sidebarElement = new Element("sidebar");
sidebarElement.setText(collectionService.getMetadata(collection, "side_bar_text"));
element.addContent(sidebarElement);
}
if (collectionService.getMetadata(collection, "license") != null)
{
if (collectionService.getMetadata(collection, "license") != null) {
Element sidebarElement = new Element("license");
sidebarElement.setText(collectionService.getMetadata(collection, "license"));
element.addContent(sidebarElement);
}
if (collectionService.getMetadata(collection, "provenance_description") != null)
{
if (collectionService.getMetadata(collection, "provenance_description") != null) {
Element sidebarElement = new Element("provenance");
sidebarElement.setText(collectionService.getMetadata(collection, "provenance_description"));
element.addContent(sidebarElement);

View File

@@ -7,67 +7,94 @@
*/
package org.dspace.app.bulkedit;
import org.dspace.content.Item;
import org.dspace.content.Collection;
import java.util.ArrayList;
import java.util.List;
import org.dspace.content.Collection;
import org.dspace.content.Item;
/**
* Utility class to store changes to item that may occur during a batch edit.
*
* @author Stuart Lewis
*/
public class BulkEditChange
{
/** The item these changes relate to */
public class BulkEditChange {
/**
* The item these changes relate to
*/
private Item item;
/** The List of hashtables with the new elements */
/**
* The List of hashtables with the new elements
*/
private List<BulkEditMetadataValue> adds;
/** The List of hashtables with the removed elements */
/**
* The List of hashtables with the removed elements
*/
private List<BulkEditMetadataValue> removes;
/** The List of hashtables with the unchanged elements */
/**
* The List of hashtables with the unchanged elements
*/
private List<BulkEditMetadataValue> constant;
/** The List of the complete set of new values (constant + adds) */
/**
* The List of the complete set of new values (constant + adds)
*/
private List<BulkEditMetadataValue> complete;
/** The list of old collections the item used to be mapped to */
/**
* The list of old collections the item used to be mapped to
*/
private List<Collection> oldMappedCollections;
/** The list of new collections the item has been mapped into */
/**
* The list of new collections the item has been mapped into
*/
private List<Collection> newMappedCollections;
/** The old owning collection */
/**
* The old owning collection
*/
private Collection oldOwningCollection;
/** The new owning collection */
/**
* The new owning collection
*/
private Collection newOwningCollection;
/** Is this a new item */
/**
* Is this a new item
*/
private boolean newItem;
/** Has this item been deleted? */
/**
* Has this item been deleted?
*/
private boolean deleted;
/** Has this item been withdrawn? */
/**
* Has this item been withdrawn?
*/
private boolean withdrawn;
/** Has this item been reinstated? */
/**
* Has this item been reinstated?
*/
private boolean reinstated;
/** Have any changes actually been made? */
/**
* Have any changes actually been made?
*/
private boolean empty;
/**
* Initialise a change holder for a new item
*/
public BulkEditChange()
{
public BulkEditChange() {
// Set the item to be null
item = null;
newItem = true;
@@ -89,8 +116,7 @@ public class BulkEditChange
*
* @param i The Item to store
*/
public BulkEditChange(Item i)
{
public BulkEditChange(Item i) {
// Store the item
item = i;
newItem = false;
@@ -110,8 +136,7 @@ public class BulkEditChange
*
* @param i The item
*/
public void setItem(Item i)
{
public void setItem(Item i) {
// Store the item
item = i;
}
@@ -121,8 +146,7 @@ public class BulkEditChange
*
* @param dcv The value to add
*/
public void registerAdd(BulkEditMetadataValue dcv)
{
public void registerAdd(BulkEditMetadataValue dcv) {
// Add the added value
adds.add(dcv);
complete.add(dcv);
@@ -134,8 +158,7 @@ public class BulkEditChange
*
* @param dcv The value to remove
*/
public void registerRemove(BulkEditMetadataValue dcv)
{
public void registerRemove(BulkEditMetadataValue dcv) {
// Add the removed value
removes.add(dcv);
empty = false;
@@ -146,8 +169,7 @@ public class BulkEditChange
*
* @param dcv The value to keep unchanged
*/
public void registerConstant(BulkEditMetadataValue dcv)
{
public void registerConstant(BulkEditMetadataValue dcv) {
// Add the removed value
constant.add(dcv);
complete.add(dcv);
@@ -158,8 +180,7 @@ public class BulkEditChange
*
* @param c The new mapped Collection
*/
public void registerNewMappedCollection(Collection c)
{
public void registerNewMappedCollection(Collection c) {
// Add the new owning Collection
newMappedCollections.add(c);
empty = false;
@@ -170,27 +191,22 @@ public class BulkEditChange
*
* @param c The old mapped Collection
*/
public void registerOldMappedCollection(Collection c)
{
public void registerOldMappedCollection(Collection c) {
// Add the old owning Collection (if it isn't there already, or is an old collection)
boolean found = false;
if ((this.getOldOwningCollection() != null) &&
(this.getOldOwningCollection().getHandle().equals(c.getHandle())))
{
(this.getOldOwningCollection().getHandle().equals(c.getHandle()))) {
found = true;
}
for (Collection collection : oldMappedCollections)
{
if (collection.getHandle().equals(c.getHandle()))
{
for (Collection collection : oldMappedCollections) {
if (collection.getHandle().equals(c.getHandle())) {
found = true;
}
}
if (!found)
{
if (!found) {
oldMappedCollections.add(c);
empty = false;
}
@@ -202,8 +218,7 @@ public class BulkEditChange
* @param oldC The old owning collection
* @param newC The new owning collection
*/
public void changeOwningCollection(Collection oldC, Collection newC)
{
public void changeOwningCollection(Collection oldC, Collection newC) {
// Store the old owning collection
oldOwningCollection = oldC;
@@ -217,8 +232,7 @@ public class BulkEditChange
*
* @param newC The new owning collection
*/
public void setOwningCollection(Collection newC)
{
public void setOwningCollection(Collection newC) {
// Store the new owning collection
newOwningCollection = newC;
//empty = false;
@@ -229,8 +243,7 @@ public class BulkEditChange
*
* @return The item
*/
public Item getItem()
{
public Item getItem() {
// Return the item
return item;
}
@@ -240,8 +253,7 @@ public class BulkEditChange
*
* @return the list of elements and their values that have been added.
*/
public List<BulkEditMetadataValue> getAdds()
{
public List<BulkEditMetadataValue> getAdds() {
// Return the array
return adds;
}
@@ -251,8 +263,7 @@ public class BulkEditChange
*
* @return the list of elements and their values that have been removed.
*/
public List<BulkEditMetadataValue> getRemoves()
{
public List<BulkEditMetadataValue> getRemoves() {
// Return the array
return removes;
}
@@ -262,8 +273,7 @@ public class BulkEditChange
*
* @return the list of unchanged values
*/
public List<BulkEditMetadataValue> getConstant()
{
public List<BulkEditMetadataValue> getConstant() {
// Return the array
return constant;
}
@@ -273,8 +283,7 @@ public class BulkEditChange
*
* @return the list of all values
*/
public List<BulkEditMetadataValue> getComplete()
{
public List<BulkEditMetadataValue> getComplete() {
// Return the array
return complete;
}
@@ -284,8 +293,7 @@ public class BulkEditChange
*
* @return the list of new mapped collections
*/
public List<Collection> getNewMappedCollections()
{
public List<Collection> getNewMappedCollections() {
// Return the array
return newMappedCollections;
}
@@ -295,8 +303,7 @@ public class BulkEditChange
*
* @return the list of old mapped collections
*/
public List<Collection> getOldMappedCollections()
{
public List<Collection> getOldMappedCollections() {
// Return the array
return oldMappedCollections;
}
@@ -306,8 +313,7 @@ public class BulkEditChange
*
* @return the old owning collection
*/
public Collection getOldOwningCollection()
{
public Collection getOldOwningCollection() {
// Return the old owning collection
return oldOwningCollection;
}
@@ -317,8 +323,7 @@ public class BulkEditChange
*
* @return the new owning collection
*/
public Collection getNewOwningCollection()
{
public Collection getNewOwningCollection() {
// Return the new owning collection
return newOwningCollection;
}
@@ -328,8 +333,7 @@ public class BulkEditChange
*
* @return Whether or not this is for a new item
*/
public boolean isNewItem()
{
public boolean isNewItem() {
// Return the new item status
return newItem;
}
@@ -339,8 +343,7 @@ public class BulkEditChange
*
* @return Whether or not this is for a deleted item
*/
public boolean isDeleted()
{
public boolean isDeleted() {
// Return the new item status
return deleted;
}
@@ -359,8 +362,7 @@ public class BulkEditChange
*
* @return Whether or not this is for a withdrawn item
*/
public boolean isWithdrawn()
{
public boolean isWithdrawn() {
// Return the new item status
return withdrawn;
}
@@ -379,8 +381,7 @@ public class BulkEditChange
*
* @return Whether or not this is for a reinstated item
*/
public boolean isReinstated()
{
public boolean isReinstated() {
// Return the new item status
return reinstated;
}
@@ -399,8 +400,7 @@ public class BulkEditChange
*
* @return Whether or not changes have been made
*/
public boolean hasChanges()
{
public boolean hasChanges() {
return !empty;
}
}

View File

@@ -7,6 +7,23 @@
*/
package org.dspace.app.bulkedit;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.dspace.authority.AuthorityValue;
import org.dspace.authority.factory.AuthorityServiceFactory;
@@ -15,20 +32,16 @@ import org.dspace.content.Collection;
import org.dspace.content.Item;
import org.dspace.content.MetadataField;
import org.dspace.content.MetadataSchema;
import org.dspace.content.MetadataSchemaEnum;
import org.dspace.content.MetadataValue;
import org.dspace.content.authority.Choices;
import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.ItemService;
import org.dspace.content.service.MetadataFieldService;
import org.dspace.content.service.MetadataSchemaService;
import org.dspace.content.authority.Choices;
import org.dspace.core.Context;
import org.dspace.services.factory.DSpaceServicesFactory;
import java.util.*;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.io.*;
/**
* Utility class to read and write CSV files
*
@@ -43,45 +56,69 @@ import java.io.*;
*
* @author Stuart Lewis
*/
public class DSpaceCSV implements Serializable
{
/** The headings of the CSV file */
public class DSpaceCSV implements Serializable {
/**
* The headings of the CSV file
*/
protected List<String> headings;
/** An array list of CSV lines */
/**
* An array list of CSV lines
*/
protected List<DSpaceCSVLine> lines;
/** A counter of how many CSV lines this object holds */
/**
* A counter of how many CSV lines this object holds
*/
protected int counter;
/** The value separator (defaults to double pipe '||') */
/**
* The value separator (defaults to double pipe '||')
*/
protected String valueSeparator;
/** The value separator in an escaped form for using in regexes */
/**
* The value separator in an escaped form for using in regexes
*/
protected String escapedValueSeparator;
/** The field separator (defaults to comma) */
/**
* The field separator (defaults to comma)
*/
protected String fieldSeparator;
/** The field separator in an escaped form for using in regexes */
/**
* The field separator in an escaped form for using in regexes
*/
protected String escapedFieldSeparator;
/** The authority separator (defaults to double colon '::') */
/**
* The authority separator (defaults to double colon '::')
*/
protected String authoritySeparator;
/** The authority separator in an escaped form for using in regexes */
/**
* The authority separator in an escaped form for using in regexes
*/
protected String escapedAuthoritySeparator;
protected transient final ItemService itemService = ContentServiceFactory.getInstance().getItemService();
protected transient final MetadataSchemaService metadataSchemaService = ContentServiceFactory.getInstance().getMetadataSchemaService();
protected transient final MetadataFieldService metadataFieldService = ContentServiceFactory.getInstance().getMetadataFieldService();
protected transient final AuthorityValueService authorityValueService = AuthorityServiceFactory.getInstance().getAuthorityValueService();
protected transient final MetadataSchemaService metadataSchemaService =
ContentServiceFactory.getInstance().getMetadataSchemaService();
protected transient final MetadataFieldService metadataFieldService =
ContentServiceFactory.getInstance().getMetadataFieldService();
protected transient final AuthorityValueService authorityValueService =
AuthorityServiceFactory.getInstance().getAuthorityValueService();
/** Whether to export all metadata such as handles and provenance information */
/**
* Whether to export all metadata such as handles and provenance information
*/
protected boolean exportAll;
/** A list of metadata elements to ignore */
/**
* A list of metadata elements to ignore
*/
protected Map<String, String> ignore;
@@ -90,8 +127,7 @@ public class DSpaceCSV implements Serializable
*
* @param exportAll Whether to export all metadata such as handles and provenance information
*/
public DSpaceCSV(boolean exportAll)
{
public DSpaceCSV(boolean exportAll) {
// Initialise the class
init();
@@ -102,50 +138,42 @@ public class DSpaceCSV implements Serializable
/**
* Create a new instance, reading the lines in from file
*
* @param f The file to read from
* @param inputStream the inputstream to read from
* @param c The DSpace Context
*
* @throws Exception thrown if there is an error reading or processing the file
*/
public DSpaceCSV(File f, Context c) throws Exception
{
public DSpaceCSV(InputStream inputStream, Context c) throws Exception {
// Initialise the class
init();
// Open the CSV file
BufferedReader input = null;
try
{
input = new BufferedReader(new InputStreamReader(new FileInputStream(f),"UTF-8"));
try {
input = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
// Read the heading line
String head = input.readLine();
String[] headingElements = head.split(escapedFieldSeparator);
int columnCounter = 0;
for (String element : headingElements)
{
for (String element : headingElements) {
columnCounter++;
// Remove surrounding quotes if there are any
if ((element.startsWith("\"")) && (element.endsWith("\"")))
{
if ((element.startsWith("\"")) && (element.endsWith("\""))) {
element = element.substring(1, element.length() - 1);
}
// Store the heading
if ("collection".equals(element))
{
if ("collection".equals(element)) {
// Store the heading
headings.add(element);
}
// Store the action
else if ("action".equals(element))
{
} else if ("rowName".equals(element)) {
// Store the heading
headings.add(element);
}
else if (!"id".equals(element))
{
} else if ("action".equals(element)) { // Store the action
// Store the heading
headings.add(element);
} else if (!"id".equals(element)) {
String authorityPrefix = "";
AuthorityValue authorityValueType = authorityValueService.getAuthorityValueType(element);
if (authorityValueType != null) {
@@ -172,20 +200,25 @@ public class DSpaceCSV implements Serializable
}
// Check that the scheme exists
if (!StringUtils.equals(metadataSchema, MetadataSchemaEnum.RELATION.getName())) {
MetadataSchema foundSchema = metadataSchemaService.find(c, metadataSchema);
if (foundSchema == null) {
throw new MetadataImportInvalidHeadingException(clean[0],
MetadataImportInvalidHeadingException.SCHEMA,
MetadataImportInvalidHeadingException
.SCHEMA,
columnCounter);
}
// Check that the metadata element exists in the schema
MetadataField foundField = metadataFieldService.findByElement(c, foundSchema, metadataElement, metadataQualifier);
MetadataField foundField = metadataFieldService
.findByElement(c, foundSchema, metadataElement, metadataQualifier);
if (foundField == null) {
throw new MetadataImportInvalidHeadingException(clean[0],
MetadataImportInvalidHeadingException.ELEMENT,
MetadataImportInvalidHeadingException
.ELEMENT,
columnCounter);
}
}
// Store the heading
headings.add(authorityPrefix + element);
@@ -196,8 +229,7 @@ public class DSpaceCSV implements Serializable
StringBuilder lineBuilder = new StringBuilder();
String lineRead;
while ((lineRead = input.readLine()) != null)
{
while ((lineRead = input.readLine()) != null) {
if (lineBuilder.length() > 0) {
// Already have a previously read value - add this line
lineBuilder.append("\n").append(lineRead);
@@ -236,11 +268,8 @@ public class DSpaceCSV implements Serializable
addItem(lineRead);
}
}
}
finally
{
if (input != null)
{
} finally {
if (input != null) {
input.close();
}
}
@@ -249,8 +278,7 @@ public class DSpaceCSV implements Serializable
/**
* Initialise this class with values from dspace.cfg
*/
protected void init()
{
protected void init() {
// Set the value separator
setValueSeparator();
@@ -273,13 +301,16 @@ public class DSpaceCSV implements Serializable
ignore = new HashMap<>();
// Specify default values
String[] defaultValues = new String[]{"dc.date.accessioned, dc.date.available, " +
"dc.date.updated, dc.description.provenance"};
String[] toIgnoreArray = DSpaceServicesFactory.getInstance().getConfigurationService().getArrayProperty("bulkedit.ignore-on-export", defaultValues);
for (String toIgnoreString : toIgnoreArray)
{
if (!"".equals(toIgnoreString.trim()))
{
String[] defaultValues =
new String[] {
"dc.date.accessioned, dc.date.available, dc.date.updated, dc.description.provenance"
};
String[] toIgnoreArray =
DSpaceServicesFactory.getInstance()
.getConfigurationService()
.getArrayProperty("bulkedit.ignore-on-export", defaultValues);
for (String toIgnoreString : toIgnoreArray) {
if (!"".equals(toIgnoreString.trim())) {
ignore.put(toIgnoreString.trim(), toIgnoreString.trim());
}
}
@@ -307,16 +338,13 @@ public class DSpaceCSV implements Serializable
*
* If not set, defaults to double pipe '||'
*/
private void setValueSeparator()
{
private void setValueSeparator() {
// Get the value separator
valueSeparator = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("bulkedit.valueseparator");
if ((valueSeparator != null) && (!"".equals(valueSeparator.trim())))
{
valueSeparator = DSpaceServicesFactory.getInstance().getConfigurationService()
.getProperty("bulkedit.valueseparator");
if ((valueSeparator != null) && (!"".equals(valueSeparator.trim()))) {
valueSeparator = valueSeparator.trim();
}
else
{
} else {
valueSeparator = "||";
}
@@ -336,32 +364,22 @@ public class DSpaceCSV implements Serializable
* Special values are 'tab', 'hash' and 'semicolon' which will
* get substituted from the text to the value.
*/
private void setFieldSeparator()
{
private void setFieldSeparator() {
// Get the value separator
fieldSeparator =DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("bulkedit.fieldseparator");
if ((fieldSeparator != null) && (!"".equals(fieldSeparator.trim())))
{
fieldSeparator = DSpaceServicesFactory.getInstance().getConfigurationService()
.getProperty("bulkedit.fieldseparator");
if ((fieldSeparator != null) && (!"".equals(fieldSeparator.trim()))) {
fieldSeparator = fieldSeparator.trim();
if ("tab".equals(fieldSeparator))
{
if ("tab".equals(fieldSeparator)) {
fieldSeparator = "\t";
}
else if ("semicolon".equals(fieldSeparator))
{
} else if ("semicolon".equals(fieldSeparator)) {
fieldSeparator = ";";
}
else if ("hash".equals(fieldSeparator))
{
} else if ("hash".equals(fieldSeparator)) {
fieldSeparator = "#";
}
else
{
} else {
fieldSeparator = fieldSeparator.trim();
}
}
else
{
} else {
fieldSeparator = ",";
}
@@ -378,16 +396,13 @@ public class DSpaceCSV implements Serializable
*
* If not set, defaults to double colon '::'
*/
private void setAuthoritySeparator()
{
private void setAuthoritySeparator() {
// Get the value separator
authoritySeparator = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("bulkedit.authorityseparator");
if ((authoritySeparator != null) && (!"".equals(authoritySeparator.trim())))
{
authoritySeparator = DSpaceServicesFactory.getInstance().getConfigurationService()
.getProperty("bulkedit.authorityseparator");
if ((authoritySeparator != null) && (!"".equals(authoritySeparator.trim()))) {
authoritySeparator = authoritySeparator.trim();
}
else
{
} else {
authoritySeparator = "::";
}
@@ -401,11 +416,9 @@ public class DSpaceCSV implements Serializable
* Add a DSpace item to the CSV file
*
* @param i The DSpace item
*
* @throws Exception if something goes wrong with adding the Item
*/
public final void addItem(Item i) throws Exception
{
public final void addItem(Item i) throws Exception {
// If the item does not have an "owningCollection" the the below "getHandle()" call will fail
// This should not happen but is here for safety.
if (i.getOwningCollection() == null) {
@@ -421,49 +434,42 @@ public class DSpaceCSV implements Serializable
// Add in any mapped collections
List<Collection> collections = i.getCollections();
for (Collection c : collections)
{
for (Collection c : collections) {
// Only add if it is not the owning collection
if (!c.getHandle().equals(owningCollectionHandle))
{
if (!c.getHandle().equals(owningCollectionHandle)) {
line.add("collection", c.getHandle());
}
}
// Populate it
List<MetadataValue> md = itemService.getMetadata(i, Item.ANY, Item.ANY, Item.ANY, Item.ANY);
for (MetadataValue value : md)
{
for (MetadataValue value : md) {
MetadataField metadataField = value.getMetadataField();
MetadataSchema metadataSchema = metadataField.getMetadataSchema();
// Get the key (schema.element)
String key = metadataSchema.getName() + "." + metadataField.getElement();
// Add the qualifier if there is one (schema.element.qualifier)
if (metadataField.getQualifier() != null)
{
if (metadataField.getQualifier() != null) {
key = key + "." + metadataField.getQualifier();
}
// Add the language if there is one (schema.element.qualifier[langauge])
//if ((value.language != null) && (!"".equals(value.language)))
if (value.getLanguage() != null)
{
if (value.getLanguage() != null) {
key = key + "[" + value.getLanguage() + "]";
}
// Store the item
if (exportAll || okToExport(metadataField))
{
if (exportAll || okToExport(metadataField)) {
// Add authority and confidence if authority is not null
String mdValue = value.getValue();
if (value.getAuthority() != null && !"".equals(value.getAuthority()))
{
mdValue += authoritySeparator + value.getAuthority() + authoritySeparator + (value.getConfidence() != -1 ? value.getConfidence() : Choices.CF_ACCEPTED);
if (value.getAuthority() != null && !"".equals(value.getAuthority())) {
mdValue += authoritySeparator + value.getAuthority() + authoritySeparator + (value
.getConfidence() != -1 ? value.getConfidence() : Choices.CF_ACCEPTED);
}
line.add(key, mdValue);
if (!headings.contains(key))
{
if (!headings.contains(key)) {
headings.add(key);
}
}
@@ -478,12 +484,10 @@ public class DSpaceCSV implements Serializable
* @param line The line of elements
* @throws Exception Thrown if an error occurs when adding the item
*/
public final void addItem(String line) throws Exception
{
public final void addItem(String line) throws Exception {
// Check to see if the last character is a field separator, which hides the last empty column
boolean last = false;
if (line.endsWith(fieldSeparator))
{
if (line.endsWith(fieldSeparator)) {
// Add a space to the end, then remove it later
last = true;
line += " ";
@@ -496,15 +500,12 @@ public class DSpaceCSV implements Serializable
// Merge parts with embedded separators
boolean alldone = false;
while (!alldone)
{
while (!alldone) {
boolean found = false;
int i = 0;
for (String part : bits)
{
for (String part : bits) {
int bitcounter = part.length() - part.replaceAll("\"", "").length();
if ((part.startsWith("\"")) && ((!part.endsWith("\"")) || ((bitcounter & 1) == 1)))
{
if ((part.startsWith("\"")) && ((!part.endsWith("\"")) || ((bitcounter & 1) == 1))) {
found = true;
String add = bits.get(i) + fieldSeparator + bits.get(i + 1);
bits.remove(i);
@@ -519,10 +520,8 @@ public class DSpaceCSV implements Serializable
// Deal with quotes around the elements
int i = 0;
for (String part : bits)
{
if ((part.startsWith("\"")) && (part.endsWith("\"")))
{
for (String part : bits) {
if ((part.startsWith("\"")) && (part.endsWith("\""))) {
part = part.substring(1, part.length() - 1);
bits.set(i, part);
}
@@ -531,10 +530,8 @@ public class DSpaceCSV implements Serializable
// Remove embedded quotes
i = 0;
for (String part : bits)
{
if (part.contains("\"\""))
{
for (String part : bits) {
if (part.contains("\"\"")) {
part = part.replaceAll("\"\"", "\"");
bits.set(i, part);
}
@@ -546,18 +543,12 @@ public class DSpaceCSV implements Serializable
DSpaceCSVLine csvLine;
// Is this an existing item, or a new item (where id = '+')
if ("+".equals(id))
{
if ("+".equals(id)) {
csvLine = new DSpaceCSVLine();
}
else
{
try
{
} else {
try {
csvLine = new DSpaceCSVLine(UUID.fromString(id));
}
catch (NumberFormatException nfe)
{
} catch (NumberFormatException nfe) {
System.err.println("Invalid item identifier: " + id);
System.err.println("Please check your CSV file for information. " +
"Item id must be numeric, or a '+' to add a new item");
@@ -567,13 +558,10 @@ public class DSpaceCSV implements Serializable
// Add the rest of the parts
i = 0;
for (String part : bits)
{
if (i > 0)
{
for (String part : bits) {
if (i > 0) {
// Is this a last empty item?
if ((last) && (i == headings.size()))
{
if ((last) && (i == headings.size())) {
part = "";
}
@@ -585,10 +573,8 @@ public class DSpaceCSV implements Serializable
}
csvLine.add(headings.get(i - 1), null);
String[] elements = part.split(escapedValueSeparator);
for (String element : elements)
{
if ((element != null) && (!"".equals(element)))
{
for (String element : elements) {
if ((element != null) && (!"".equals(element))) {
csvLine.add(headings.get(i - 1), element);
}
}
@@ -604,8 +590,7 @@ public class DSpaceCSV implements Serializable
*
* @return The lines
*/
public final List<DSpaceCSVLine> getCSVLines()
{
public final List<DSpaceCSVLine> getCSVLines() {
// Return the lines
return lines;
}
@@ -615,22 +600,19 @@ public class DSpaceCSV implements Serializable
*
* @return the array of CSV formatted Strings
*/
public final String[] getCSVLinesAsStringArray()
{
public final String[] getCSVLinesAsStringArray() {
// Create the headings line
String[] csvLines = new String[counter + 1];
csvLines[0] = "id" + fieldSeparator + "collection";
List<String> headingsCopy = new ArrayList<>(headings);
Collections.sort(headingsCopy);
for (String value : headingsCopy)
{
for (String value : headingsCopy) {
csvLines[0] = csvLines[0] + fieldSeparator + value;
}
Iterator<DSpaceCSVLine> i = lines.iterator();
int c = 1;
while (i.hasNext())
{
while (i.hasNext()) {
csvLines[c++] = i.next().toCSV(headingsCopy, fieldSeparator, valueSeparator);
}
@@ -638,23 +620,15 @@ public class DSpaceCSV implements Serializable
}
/**
* Save the CSV file to the given filename
*
* @param filename The filename to save the CSV file to
*
* @throws IOException Thrown if an error occurs when writing the file
* Creates and returns an InputStream from the CSV Lines in this DSpaceCSV
* @return The InputStream created from the CSVLines in this DSpaceCSV
*/
public final void save(String filename) throws IOException
{
// Save the file
BufferedWriter out = new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(filename), "UTF-8"));
public InputStream getInputStream() {
StringBuilder stringBuilder = new StringBuilder();
for (String csvLine : getCSVLinesAsStringArray()) {
out.write(csvLine + "\n");
stringBuilder.append(csvLine + "\n");
}
out.flush();
out.close();
return IOUtils.toInputStream(stringBuilder.toString(), StandardCharsets.UTF_8);
}
/**
@@ -666,12 +640,10 @@ public class DSpaceCSV implements Serializable
* @param md The Metadatum to examine
* @return Whether or not it is OK to export this element
*/
protected boolean okToExport(MetadataField md)
{
protected boolean okToExport(MetadataField md) {
// Now compare with the list to ignore
String key = md.getMetadataSchema().getName() + "." + md.getElement();
if (md.getQualifier() != null)
{
if (md.getQualifier() != null) {
key += "." + md.getQualifier();
}
if (ignore.get(key) != null) {
@@ -687,8 +659,7 @@ public class DSpaceCSV implements Serializable
*
* @return The headings
*/
public List<String> getHeadings()
{
public List<String> getHeadings() {
return headings;
}
@@ -698,13 +669,11 @@ public class DSpaceCSV implements Serializable
* @return The formatted String as a csv
*/
@Override
public final String toString()
{
public final String toString() {
// Return the csv as one long string
StringBuilder csvLines = new StringBuilder();
String[] lines = this.getCSVLinesAsStringArray();
for (String line : lines)
{
for (String line : lines) {
csvLines.append(line).append("\n");
}
return csvLines.toString();

View File

@@ -7,30 +7,41 @@
*/
package org.dspace.app.bulkedit;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.UUID;
import org.dspace.authority.AuthorityValue;
import org.dspace.authority.factory.AuthorityServiceFactory;
import org.dspace.authority.service.AuthorityValueService;
import java.io.Serializable;
import java.util.*;
/**
* Utility class to store a line from a CSV file
*
* @author Stuart Lewis
*/
public class DSpaceCSVLine implements Serializable
{
/** The item id of the item represented by this line. -1 is for a new item */
public class DSpaceCSVLine implements Serializable {
/**
* The item id of the item represented by this line. -1 is for a new item
*/
private final UUID id;
/** The elements in this line in a hashtable, keyed by the metadata type */
/**
* The elements in this line in a hashtable, keyed by the metadata type
*/
private final Map<String, ArrayList> items;
protected transient final AuthorityValueService authorityValueService
= AuthorityServiceFactory.getInstance().getAuthorityValueService();
/** ensuring that the order-sensible columns of the csv are processed in the correct order */
/**
* ensuring that the order-sensible columns of the csv are processed in the correct order
*/
private transient final Comparator<? super String> headerComparator = new Comparator<String>() {
@Override
public int compare(String md1, String md2) {
@@ -41,8 +52,7 @@ public class DSpaceCSVLine implements Serializable
int compare;
if (source1 == null && source2 != null) {
compare = -1;
}
else if (source1 != null && source2 == null) {
} else if (source1 != null && source2 == null) {
compare = 1;
} else {
// the order of the rest does not matter
@@ -57,8 +67,7 @@ public class DSpaceCSVLine implements Serializable
*
* @param itemId The item ID of the line
*/
public DSpaceCSVLine(UUID itemId)
{
public DSpaceCSVLine(UUID itemId) {
// Store the ID + separator, and initialise the hashtable
this.id = itemId;
items = new TreeMap<>(headerComparator);
@@ -68,8 +77,7 @@ public class DSpaceCSVLine implements Serializable
/**
* Create a new CSV line for a new item
*/
public DSpaceCSVLine()
{
public DSpaceCSVLine() {
// Set the ID to be null, and initialise the hashtable
this.id = null;
this.items = new TreeMap<>(headerComparator);
@@ -80,8 +88,7 @@ public class DSpaceCSVLine implements Serializable
*
* @return The item ID
*/
public UUID getID()
{
public UUID getID() {
// Return the ID
return id;
}
@@ -92,17 +99,14 @@ public class DSpaceCSVLine implements Serializable
* @param key The metadata key (e.g. dc.contributor.author)
* @param value The metadata value
*/
public void add(String key, String value)
{
public void add(String key, String value) {
// Create the array list if we need to
if (items.get(key) == null)
{
if (items.get(key) == null) {
items.put(key, new ArrayList<String>());
}
// Store the item if it is not null
if (value != null)
{
if (value != null) {
items.get(key).add(value);
}
}
@@ -113,8 +117,7 @@ public class DSpaceCSVLine implements Serializable
* @param key The metadata key
* @return All the elements that match
*/
public List<String> get(String key)
{
public List<String> get(String key) {
// Return any relevant values
return items.get(key);
}
@@ -124,8 +127,7 @@ public class DSpaceCSVLine implements Serializable
*
* @return The action (may be blank, 'withdraw', 'reinstate' or 'delete')
*/
public String getAction()
{
public String getAction() {
if (items.containsKey("action")) {
ArrayList actions = items.get("action");
if (actions.size() > 0) {
@@ -140,8 +142,7 @@ public class DSpaceCSVLine implements Serializable
*
* @return An enumeration of all the keys
*/
public Set<String> keys()
{
public Set<String> keys() {
// Return the keys
return items.keySet();
}
@@ -154,8 +155,7 @@ public class DSpaceCSVLine implements Serializable
* @param valueSeparator separator between metadata values (within a field)
* @return The CSV formatted String
*/
protected String toCSV(List<String> headings, String fieldSeparator, String valueSeparator)
{
protected String toCSV(List<String> headings, String fieldSeparator, String valueSeparator) {
StringBuilder bits = new StringBuilder();
// Add the id
@@ -163,12 +163,10 @@ public class DSpaceCSVLine implements Serializable
bits.append(valueToCSV(items.get("collection"), valueSeparator));
// Add the rest of the elements
for (String heading : headings)
{
for (String heading : headings) {
bits.append(fieldSeparator);
List<String> values = items.get(heading);
if (values != null && !"collection".equals(heading))
{
if (values != null && !"collection".equals(heading)) {
bits.append(valueToCSV(values, valueSeparator));
}
}
@@ -183,29 +181,22 @@ public class DSpaceCSVLine implements Serializable
* @param valueSeparator value separator
* @return The line as a CSV formatted String
*/
protected String valueToCSV(List<String> values, String valueSeparator)
{
protected String valueToCSV(List<String> values, String valueSeparator) {
// Check there is some content
if (values == null)
{
if (values == null) {
return "";
}
// Get on with the work
String s;
if (values.size() == 1)
{
if (values.size() == 1) {
s = values.get(0);
}
else
{
} else {
// Concatenate any fields together
StringBuilder str = new StringBuilder();
for (String value : values)
{
if (str.length() > 0)
{
for (String value : values) {
if (str.length() > 0) {
str.append(valueSeparator);
}

View File

@@ -7,295 +7,85 @@
*/
package org.dspace.app.bulkedit;
import com.google.common.collect.Iterators;
import org.apache.commons.cli.*;
import org.dspace.content.*;
import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.ItemService;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.handle.factory.HandleServiceFactory;
import java.util.ArrayList;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.cli.ParseException;
import org.dspace.content.service.MetadataDSpaceCsvExportService;
import org.dspace.core.Context;
import org.dspace.eperson.factory.EPersonServiceFactory;
import org.dspace.eperson.service.EPersonService;
import org.dspace.scripts.DSpaceRunnable;
import org.dspace.utils.DSpace;
/**
* Metadata exporter to allow the batch export of metadata into a file
*
* @author Stuart Lewis
*/
public class MetadataExport
{
/** The items to export */
protected Iterator<Item> toExport;
public class MetadataExport extends DSpaceRunnable<MetadataExportScriptConfiguration> {
protected ItemService itemService;
private boolean help = false;
private String filename = null;
private String handle = null;
private boolean exportAllMetadata = false;
private boolean exportAllItems = false;
protected Context context;
private static final String EXPORT_CSV = "exportCSV";
/** Whether to export all metadata, or just normally edited metadata */
protected boolean exportAll;
private MetadataDSpaceCsvExportService metadataDSpaceCsvExportService = new DSpace().getServiceManager()
.getServicesByType(MetadataDSpaceCsvExportService.class).get(0);
protected MetadataExport() {
itemService = ContentServiceFactory.getInstance().getItemService();
private EPersonService ePersonService = EPersonServiceFactory.getInstance().getEPersonService();
@Override
public void internalRun() throws Exception {
if (help) {
handler.logInfo("\nfull export: metadata-export -f filename");
handler.logInfo("partial export: metadata-export -i handle -f filename");
printHelp();
return;
}
Context context = new Context();
context.turnOffAuthorisationSystem();
try {
context.setCurrentUser(ePersonService.find(context, this.getEpersonIdentifier()));
} catch (SQLException e) {
handler.handleException(e);
}
DSpaceCSV dSpaceCSV = metadataDSpaceCsvExportService
.handleExport(context, exportAllItems, exportAllMetadata, handle,
handler);
handler.writeFilestream(context, filename, dSpaceCSV.getInputStream(), EXPORT_CSV);
context.restoreAuthSystemState();
context.complete();
}
/**
* Set up a new metadata export
*
* @param c The Context
* @param toExport The ItemIterator of items to export
* @param exportAll whether to export all metadata or not (include handle, provenance etc)
*/
public MetadataExport(Context c, Iterator<Item> toExport, boolean exportAll)
{
itemService = ContentServiceFactory.getInstance().getItemService();
// Store the export settings
this.toExport = toExport;
this.exportAll = exportAll;
this.context = c;
@Override
public MetadataExportScriptConfiguration getScriptConfiguration() {
return new DSpace().getServiceManager().getServiceByName("metadata-export",
MetadataExportScriptConfiguration.class);
}
/**
* Method to export a community (and sub-communities and collections)
*
* @param c The Context
* @param toExport The Community to export
* @param exportAll whether to export all metadata or not (include handle, provenance etc)
*/
public MetadataExport(Context c, Community toExport, boolean exportAll)
{
itemService = ContentServiceFactory.getInstance().getItemService();
@Override
public void setup() throws ParseException {
try
{
// Try to export the community
this.toExport = buildFromCommunity(c, toExport, 0);
this.exportAll = exportAll;
this.context = c;
}
catch (SQLException sqle)
{
// Something went wrong...
System.err.println("Error running exporter:");
sqle.printStackTrace(System.err);
System.exit(1);
}
}
/**
* Build an array list of item ids that are in a community (include sub-communities and collections)
*
* @param context DSpace context
* @param community The community to build from
* @param indent How many spaces to use when writing out the names of items added
* @return The list of item ids
* @throws SQLException if database error
*/
protected Iterator<Item> buildFromCommunity(Context context, Community community, int indent)
throws SQLException
{
// Add all the collections
List<Collection> collections = community.getCollections();
Iterator<Item> result = null;
for (Collection collection : collections)
{
for (int i = 0; i < indent; i++)
{
System.out.print(" ");
}
Iterator<Item> items = itemService.findByCollection(context, collection);
result = addItemsToResult(result,items);
}
// Add all the sub-communities
List<Community> communities = community.getSubcommunities();
for (Community subCommunity : communities)
{
for (int i = 0; i < indent; i++)
{
System.out.print(" ");
}
Iterator<Item> items = buildFromCommunity(context, subCommunity, indent + 1);
result = addItemsToResult(result,items);
}
return result;
}
private Iterator<Item> addItemsToResult(Iterator<Item> result, Iterator<Item> items) {
if(result == null)
{
result = items;
}else{
result = Iterators.concat(result, items);
}
return result;
}
/**
* Run the export
*
* @return the exported CSV lines
*/
public DSpaceCSV export()
{
try
{
Context.Mode originalMode = context.getCurrentMode();
context.setMode(Context.Mode.READ_ONLY);
// Process each item
DSpaceCSV csv = new DSpaceCSV(exportAll);
while (toExport.hasNext())
{
Item item = toExport.next();
csv.addItem(item);
context.uncacheEntity(item);
}
context.setMode(originalMode);
// Return the results
return csv;
}
catch (Exception e)
{
// Something went wrong...
System.err.println("Error exporting to CSV:");
e.printStackTrace();
return null;
}
}
/**
* Print the help message
*
* @param options The command line options the user gave
* @param exitCode the system exit code to use
*/
private static void printHelp(Options options, int exitCode)
{
// print the help message
HelpFormatter myhelp = new HelpFormatter();
myhelp.printHelp("MetadataExport\n", options);
System.out.println("\nfull export: metadataexport -f filename");
System.out.println("partial export: metadataexport -i handle -f filename");
System.exit(exitCode);
}
/**
* main method to run the metadata exporter
*
* @param argv the command line arguments given
* @throws Exception if error occurs
*/
public static void main(String[] argv) throws Exception
{
// Create an options object and populate it
CommandLineParser parser = new PosixParser();
Options options = new Options();
options.addOption("i", "id", true, "ID or handle of thing to export (item, collection, or community)");
options.addOption("f", "file", true, "destination where you want file written");
options.addOption("a", "all", false, "include all metadata fields that are not normally changed (e.g. provenance)");
options.addOption("h", "help", false, "help");
CommandLine line = null;
try
{
line = parser.parse(options, argv);
}
catch (ParseException pe)
{
System.err.println("Error with commands.");
printHelp(options, 1);
System.exit(0);
}
if (line.hasOption('h'))
{
printHelp(options, 0);
if (commandLine.hasOption('h')) {
help = true;
return;
}
// Check a filename is given
if (!line.hasOption('f'))
{
System.err.println("Required parameter -f missing!");
printHelp(options, 1);
if (!commandLine.hasOption('f')) {
throw new ParseException("Required parameter -f missing!");
}
String filename = line.getOptionValue('f');
filename = commandLine.getOptionValue('f');
// Create a context
Context c = new Context(Context.Mode.READ_ONLY);
c.turnOffAuthorisationSystem();
exportAllMetadata = commandLine.hasOption('a');
// The things we'll export
Iterator<Item> toExport = null;
MetadataExport exporter = null;
// Export everything?
boolean exportAll = line.hasOption('a');
ContentServiceFactory contentServiceFactory = ContentServiceFactory.getInstance();
// Check we have an item OK
ItemService itemService = contentServiceFactory.getItemService();
if (!line.hasOption('i'))
{
System.out.println("Exporting whole repository WARNING: May take some time!");
exporter = new MetadataExport(c, itemService.findAll(c), exportAll);
if (!commandLine.hasOption('i')) {
exportAllItems = true;
}
else
{
String handle = line.getOptionValue('i');
DSpaceObject dso = HandleServiceFactory.getInstance().getHandleService().resolveToObject(c, handle);
if (dso == null)
{
System.err.println("Item '" + handle + "' does not resolve to an item in your repository!");
printHelp(options, 1);
}
if (dso.getType() == Constants.ITEM)
{
System.out.println("Exporting item '" + dso.getName() + "' (" + handle + ")");
List<Item> item = new ArrayList<>();
item.add((Item) dso);
exporter = new MetadataExport(c, item.iterator(), exportAll);
}
else if (dso.getType() == Constants.COLLECTION)
{
System.out.println("Exporting collection '" + dso.getName() + "' (" + handle + ")");
Collection collection = (Collection)dso;
toExport = itemService.findByCollection(c, collection);
exporter = new MetadataExport(c, toExport, exportAll);
}
else if (dso.getType() == Constants.COMMUNITY)
{
System.out.println("Exporting community '" + dso.getName() + "' (" + handle + ")");
exporter = new MetadataExport(c, (Community)dso, exportAll);
}
else
{
System.err.println("Error identifying '" + handle + "'");
System.exit(1);
}
}
// Perform the export
DSpaceCSV csv = exporter.export();
// Save the files to the file
csv.save(filename);
// Finish off and tidy up
c.restoreAuthSystemState();
c.complete();
handle = commandLine.getOptionValue('i');
}
}

View File

@@ -0,0 +1,74 @@
/**
* 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.app.bulkedit;
import java.io.OutputStream;
import java.sql.SQLException;
import org.apache.commons.cli.Options;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.core.Context;
import org.dspace.scripts.configuration.ScriptConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
/**
* The {@link ScriptConfiguration} for the {@link MetadataExport} script
*/
public class MetadataExportScriptConfiguration<T extends MetadataExport> extends ScriptConfiguration<T> {
@Autowired
private AuthorizeService authorizeService;
private Class<T> dspaceRunnableClass;
@Override
public Class<T> getDspaceRunnableClass() {
return dspaceRunnableClass;
}
/**
* Generic setter for the dspaceRunnableClass
* @param dspaceRunnableClass The dspaceRunnableClass to be set on this MetadataExportScriptConfiguration
*/
@Override
public void setDspaceRunnableClass(Class<T> dspaceRunnableClass) {
this.dspaceRunnableClass = dspaceRunnableClass;
}
@Override
public boolean isAllowedToExecute(Context context) {
try {
return authorizeService.isAdmin(context);
} catch (SQLException e) {
throw new RuntimeException("SQLException occurred when checking if the current user is an admin", e);
}
}
@Override
public Options getOptions() {
if (options == null) {
Options options = new Options();
options.addOption("i", "id", true, "ID or handle of thing to export (item, collection, or community)");
options.getOption("i").setType(String.class);
options.addOption("f", "file", true, "destination where you want file written");
options.getOption("f").setType(OutputStream.class);
options.getOption("f").setRequired(true);
options.addOption("a", "all", false,
"include all metadata fields that are not normally changed (e.g. provenance)");
options.getOption("a").setType(boolean.class);
options.addOption("h", "help", false, "help");
options.getOption("h").setType(boolean.class);
super.options = options;
}
return options;
}
}

View File

@@ -0,0 +1,33 @@
/**
* 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.app.bulkedit;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.dspace.scripts.handler.DSpaceRunnableHandler;
/**
* CLI variant for the {@link MetadataImport} class
* This has been made so that we can specify the behaviour of the determineChanges method to be specific for the CLI
*/
public class MetadataImportCLI extends MetadataImport {
@Override
protected boolean determineChange(DSpaceRunnableHandler handler) throws IOException {
handler.logInfo("Do you want to make these changes? [y/n] ");
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in))) {
String yn = bufferedReader.readLine();
if ("y".equalsIgnoreCase(yn)) {
return true;
}
return false;
}
}
}

View File

@@ -0,0 +1,16 @@
/**
* 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.app.bulkedit;
import org.dspace.scripts.configuration.ScriptConfiguration;
/**
* The {@link ScriptConfiguration} for the {@link org.dspace.app.bulkedit.MetadataImportCLI} CLI script
*/
public class MetadataImportCliScriptConfiguration extends MetadataImportScriptConfiguration<MetadataImportCLI> {
}

View File

@@ -12,15 +12,13 @@ package org.dspace.app.bulkedit;
*
* @author Stuart Lewis
*/
public class MetadataImportException extends Exception
{
public class MetadataImportException extends Exception {
/**
* Instantiate a new MetadataImportException
*
* @param message the error message
*/
public MetadataImportException(String message)
{
public MetadataImportException(String message) {
super(message);
}
@@ -30,8 +28,7 @@ public class MetadataImportException extends Exception
* @param message the error message
* @param exception the root cause
*/
public MetadataImportException(String message, Exception exception)
{
public MetadataImportException(String message, Exception exception) {
super(message, exception);
}
}

View File

@@ -12,27 +12,40 @@ package org.dspace.app.bulkedit;
*
* @author Stuart Lewis
*/
public class MetadataImportInvalidHeadingException extends Exception
{
/** The type of error (schema or element) */
public class MetadataImportInvalidHeadingException extends Exception {
/**
* The type of error (schema or element)
*/
private int type;
/** The bad heading */
/**
* The bad heading
*/
private String badHeading;
/** The column number */
/**
* The column number
*/
private int column;
/** Error with the schema */
/**
* Error with the schema
*/
public static final int SCHEMA = 0;
/** Error with the element */
/**
* Error with the element
*/
public static final int ELEMENT = 1;
/** Error with a missing header */
/**
* Error with a missing header
*/
public static final int MISSING = 98;
/** Error with the whole entry */
/**
* Error with the whole entry
*/
public static final int ENTRY = 99;
@@ -43,8 +56,7 @@ public class MetadataImportInvalidHeadingException extends Exception
* @param theType the type of the error
* @param theColumn column number
*/
public MetadataImportInvalidHeadingException(String message, int theType, int theColumn)
{
public MetadataImportInvalidHeadingException(String message, int theType, int theColumn) {
super(message);
badHeading = message;
type = theType;
@@ -56,8 +68,7 @@ public class MetadataImportInvalidHeadingException extends Exception
*
* @return the type of the exception
*/
public String getType()
{
public String getType() {
return "" + type;
}
@@ -66,8 +77,7 @@ public class MetadataImportInvalidHeadingException extends Exception
*
* @return the invalid heading
*/
public String getBadHeader()
{
public String getBadHeader() {
return badHeading;
}
@@ -76,8 +86,7 @@ public class MetadataImportInvalidHeadingException extends Exception
*
* @return the invalid column number
*/
public int getColumn()
{
public int getColumn() {
return column;
}
@@ -87,19 +96,14 @@ public class MetadataImportInvalidHeadingException extends Exception
* @return The exception message
*/
@Override
public String getMessage()
{
if (type == SCHEMA)
{
public String getMessage() {
if (type == SCHEMA) {
return "Unknown metadata schema in column " + column + ": " + badHeading;
} else if (type == ELEMENT)
{
} else if (type == ELEMENT) {
return "Unknown metadata element in column " + column + ": " + badHeading;
} else if (type == MISSING)
{
} else if (type == MISSING) {
return "Row with missing header: column " + column;
} else
{
} else {
return "Bad metadata declaration in column" + column + ": " + badHeading;
}
}

View File

@@ -0,0 +1,84 @@
/**
* 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.app.bulkedit;
import java.io.InputStream;
import java.sql.SQLException;
import org.apache.commons.cli.Options;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.core.Context;
import org.dspace.scripts.configuration.ScriptConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
/**
* The {@link ScriptConfiguration} for the {@link MetadataImport} script
*/
public class MetadataImportScriptConfiguration<T extends MetadataImport> extends ScriptConfiguration<T> {
@Autowired
private AuthorizeService authorizeService;
private Class<T> dspaceRunnableClass;
@Override
public Class<T> getDspaceRunnableClass() {
return dspaceRunnableClass;
}
/**
* Generic setter for the dspaceRunnableClass
* @param dspaceRunnableClass The dspaceRunnableClass to be set on this MetadataImportScriptConfiguration
*/
@Override
public void setDspaceRunnableClass(Class<T> dspaceRunnableClass) {
this.dspaceRunnableClass = dspaceRunnableClass;
}
@Override
public boolean isAllowedToExecute(Context context) {
try {
return authorizeService.isAdmin(context);
} catch (SQLException e) {
throw new RuntimeException("SQLException occurred when checking if the current user is an admin", e);
}
}
@Override
public Options getOptions() {
if (options == null) {
Options options = new Options();
options.addOption("f", "file", true, "source file");
options.getOption("f").setType(InputStream.class);
options.getOption("f").setRequired(true);
options.addOption("e", "email", true, "email address or user id of user (required if adding new items)");
options.getOption("e").setType(String.class);
options.getOption("e").setRequired(true);
options.addOption("s", "silent", false,
"silent operation - doesn't request confirmation of changes USE WITH CAUTION");
options.getOption("s").setType(boolean.class);
options.addOption("w", "workflow", false, "workflow - when adding new items, use collection workflow");
options.getOption("w").setType(boolean.class);
options.addOption("n", "notify", false,
"notify - when adding new items using a workflow, send notification emails");
options.getOption("n").setType(boolean.class);
options.addOption("v", "validate-only", false,
"validate - just validate the csv, don't run the import");
options.getOption("v").setType(boolean.class);
options.addOption("t", "template", false,
"template - when adding new items, use the collection template (if it exists)");
options.getOption("t").setType(boolean.class);
options.addOption("h", "help", false, "help");
options.getOption("h").setType(boolean.class);
super.options = options;
}
return options;
}
}

View File

@@ -9,7 +9,11 @@ package org.dspace.app.checker;
import java.io.FileNotFoundException;
import java.sql.SQLException;
import java.util.*;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
@@ -19,8 +23,17 @@ import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
import org.apache.log4j.Logger;
import org.dspace.checker.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dspace.checker.BitstreamDispatcher;
import org.dspace.checker.CheckerCommand;
import org.dspace.checker.HandleDispatcher;
import org.dspace.checker.IteratorDispatcher;
import org.dspace.checker.LimitedCountDispatcher;
import org.dspace.checker.LimitedDurationDispatcher;
import org.dspace.checker.ResultsLogger;
import org.dspace.checker.ResultsPruner;
import org.dspace.checker.SimpleDispatcher;
import org.dspace.content.Bitstream;
import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.BitstreamService;
@@ -35,19 +48,16 @@ import org.dspace.core.Utils;
* @author Grace Carpenter
* @author Nathan Sarr
*/
public final class ChecksumChecker
{
private static final Logger LOG = Logger.getLogger(ChecksumChecker.class);
public final class ChecksumChecker {
private static final Logger LOG = LogManager.getLogger(ChecksumChecker.class);
private static final BitstreamService bitstreamService = ContentServiceFactory.getInstance().getBitstreamService();
/**
* Blanked off constructor, this class should be used as a command line
* tool.
*
*/
private ChecksumChecker()
{
private ChecksumChecker() {
}
/**
@@ -71,6 +81,7 @@ public final class ChecksumChecker
* <dt>-p</dt>
* <dd>Don't prune results before running checker</dd>
* </dl>
*
* @param args the command line arguments given
* @throws SQLException if error
*/
@@ -105,19 +116,15 @@ public final class ChecksumChecker
"Prune old results (optionally using specified properties file for configuration)")
.create('p'));
try
{
try {
line = parser.parse(options, args);
}
catch (ParseException e)
{
} catch (ParseException e) {
LOG.fatal(e);
System.exit(1);
}
// user asks for help
if (line.hasOption('h'))
{
if (line.hasOption('h')) {
printHelp(options);
}
Context context = null;
@@ -126,17 +133,13 @@ public final class ChecksumChecker
// Prune stage
if (line.hasOption('p'))
{
if (line.hasOption('p')) {
ResultsPruner rp = null;
try
{
try {
rp = (line.getOptionValue('p') != null) ? ResultsPruner
.getPruner(context, line.getOptionValue('p')) : ResultsPruner
.getDefaultPruner(context);
}
catch (FileNotFoundException e)
{
} catch (FileNotFoundException e) {
LOG.error("File not found", e);
System.exit(1);
}
@@ -151,68 +154,47 @@ public final class ChecksumChecker
// process should loop infinitely through
// most_recent_checksum table
if (line.hasOption('l'))
{
if (line.hasOption('l')) {
dispatcher = new SimpleDispatcher(context, processStart, false);
}
else if (line.hasOption('L'))
{
} else if (line.hasOption('L')) {
dispatcher = new SimpleDispatcher(context, processStart, true);
}
else if (line.hasOption('b'))
{
} else if (line.hasOption('b')) {
// check only specified bitstream(s)
String[] ids = line.getOptionValues('b');
List<Bitstream> bitstreams = new ArrayList<>(ids.length);
for (int i = 0; i < ids.length; i++)
{
try
{
for (int i = 0; i < ids.length; i++) {
try {
bitstreams.add(bitstreamService.find(context, UUID.fromString(ids[i])));
}
catch (NumberFormatException nfe)
{
} catch (NumberFormatException nfe) {
System.err.println("The following argument: " + ids[i]
+ " is not an integer");
System.exit(0);
}
}
dispatcher = new IteratorDispatcher(bitstreams.iterator());
}
else if (line.hasOption('a'))
{
} else if (line.hasOption('a')) {
dispatcher = new HandleDispatcher(context, line.getOptionValue('a'));
}
else if (line.hasOption('d'))
{
} else if (line.hasOption('d')) {
// run checker process for specified duration
try
{
try {
dispatcher = new LimitedDurationDispatcher(
new SimpleDispatcher(context, processStart, true), new Date(
System.currentTimeMillis()
+ Utils.parseDuration(line
.getOptionValue('d'))));
}
catch (Exception e)
{
} catch (Exception e) {
LOG.fatal("Couldn't parse " + line.getOptionValue('d')
+ " as a duration: ", e);
System.exit(0);
}
}
else if (line.hasOption('c'))
{
} else if (line.hasOption('c')) {
int count = Integer.valueOf(line.getOptionValue('c'));
// run checker process for specified number of bitstreams
dispatcher = new LimitedCountDispatcher(new SimpleDispatcher(
context, processStart, false), count);
}
else
{
} else {
dispatcher = new LimitedCountDispatcher(new SimpleDispatcher(
context, processStart, false), 1);
}
@@ -220,8 +202,7 @@ public final class ChecksumChecker
ResultsLogger logger = new ResultsLogger(processStart);
CheckerCommand checker = new CheckerCommand(context);
// verbose reporting
if (line.hasOption('v'))
{
if (line.hasOption('v')) {
checker.setReportVerbose(true);
}
@@ -243,8 +224,7 @@ public final class ChecksumChecker
*
* @param options that are available for the user
*/
private static void printHelp(Options options)
{
private static void printHelp(Options options) {
HelpFormatter myhelp = new HelpFormatter();
myhelp.printHelp("Checksum Checker\n", options);

View File

@@ -7,12 +7,12 @@
*/
package org.dspace.app.configuration;
import org.dspace.kernel.config.SpringLoader;
import org.dspace.services.ConfigurationService;
import java.io.File;
import java.net.MalformedURLException;
import org.dspace.kernel.config.SpringLoader;
import org.dspace.services.ConfigurationService;
/**
* @author Kevin Van de Velde (kevin at atmire dot com)
*/

View File

@@ -7,7 +7,17 @@
*/
package org.dspace.app.harvest;
import org.apache.commons.cli.*;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.PosixParser;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Collection;
import org.dspace.content.DSpaceObject;
@@ -27,27 +37,21 @@ import org.dspace.harvest.OAIHarvester;
import org.dspace.harvest.factory.HarvestServiceFactory;
import org.dspace.harvest.service.HarvestedCollectionService;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
/**
* Test class for harvested collections.
*
* @author Alexey Maslov
*/
public class Harvest
{
public class Harvest {
private static Context context;
private static final HarvestedCollectionService harvestedCollectionService = HarvestServiceFactory.getInstance().getHarvestedCollectionService();
private static final HarvestedCollectionService harvestedCollectionService =
HarvestServiceFactory.getInstance().getHarvestedCollectionService();
private static final EPersonService ePersonService = EPersonServiceFactory.getInstance().getEPersonService();
private static final CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
private static final CollectionService collectionService =
ContentServiceFactory.getInstance().getCollectionService();
public static void main(String[] argv) throws Exception
{
public static void main(String[] argv) throws Exception {
// create an options object and populate it
CommandLineParser parser = new PosixParser();
@@ -74,7 +78,8 @@ public class Harvest
options.addOption("i", "oai_set_id", true,
"id of the PMH set representing the harvested collection");
options.addOption("m", "metadata_format", true,
"the name of the desired metadata format for harvesting, resolved to namespace and crosswalk in dspace.cfg");
"the name of the desired metadata format for harvesting, resolved to namespace and " +
"crosswalk in dspace.cfg");
options.addOption("h", "help", false, "help");
@@ -88,13 +93,16 @@ public class Harvest
String metadataKey = null;
int harvestType = 0;
if (line.hasOption('h'))
{
if (line.hasOption('h')) {
HelpFormatter myhelp = new HelpFormatter();
myhelp.printHelp("Harvest\n", options);
System.out.println("\nPING OAI server: Harvest -g -a oai_source -i oai_set_id");
System.out.println("RUNONCE harvest with arbitrary options: Harvest -o -e eperson -c collection -t harvest_type -a oai_source -i oai_set_id -m metadata_format");
System.out.println("SETUP a collection for harvesting: Harvest -s -c collection -t harvest_type -a oai_source -i oai_set_id -m metadata_format");
System.out.println(
"RUNONCE harvest with arbitrary options: Harvest -o -e eperson -c collection -t harvest_type -a " +
"oai_source -i oai_set_id -m metadata_format");
System.out.println(
"SETUP a collection for harvesting: Harvest -s -c collection -t harvest_type -a oai_source -i " +
"oai_set_id -m metadata_format");
System.out.println("RUN harvest once: Harvest -r -e eperson -c collection");
System.out.println("START harvest scheduler: Harvest -S");
System.out.println("RESET all harvest status: Harvest -R");
@@ -102,7 +110,6 @@ public class Harvest
System.out.println("PURGE all harvestable collections: Harvest -P -e eperson");
System.exit(0);
}
@@ -160,17 +167,13 @@ public class Harvest
// Check our options
if (command == null)
{
if (command == null) {
System.out
.println("Error - no parameters specified (run with -h flag for details)");
System.exit(1);
}
} else if ("run".equals(command)) {
// Run a single harvest cycle on a collection using saved settings.
else if ("run".equals(command))
{
if (collection == null || eperson == null)
{
if (collection == null || eperson == null) {
System.out
.println("Error - a target collection and eperson must be provided");
System.out.println(" (run with -h flag for details)");
@@ -178,22 +181,15 @@ public class Harvest
}
harvester.runHarvest(collection, eperson);
}
} else if ("start".equals(command)) {
// start the harvest loop
else if ("start".equals(command))
{
startHarvester();
}
} else if ("reset".equals(command)) {
// reset harvesting status
else if ("reset".equals(command))
{
resetHarvesting();
}
} else if ("purgeAll".equals(command)) {
// purge all collections that are set up for harvesting (obviously for testing purposes only)
else if ("purgeAll".equals(command))
{
if (eperson == null)
{
if (eperson == null) {
System.out
.println("Error - an eperson must be provided");
System.out.println(" (run with -h flag for details)");
@@ -201,18 +197,17 @@ public class Harvest
}
List<HarvestedCollection> harvestedCollections = harvestedCollectionService.findAll(context);
for (HarvestedCollection harvestedCollection : harvestedCollections)
{
System.out.println("Purging the following collections (deleting items and resetting harvest status): " + harvestedCollection.getCollection().getID().toString());
for (HarvestedCollection harvestedCollection : harvestedCollections) {
System.out.println(
"Purging the following collections (deleting items and resetting harvest status): " +
harvestedCollection
.getCollection().getID().toString());
harvester.purgeCollection(harvestedCollection.getCollection().getID().toString(), eperson);
}
context.complete();
}
} else if ("purge".equals(command)) {
// Delete all items in a collection. Useful for testing fresh harvests.
else if ("purge".equals(command))
{
if (collection == null || eperson == null)
{
if (collection == null || eperson == null) {
System.out
.println("Error - a target collection and eperson must be provided");
System.out.println(" (run with -h flag for details)");
@@ -223,35 +218,28 @@ public class Harvest
context.complete();
//TODO: implement this... remove all items and remember to unset "last-harvested" settings
}
} else if ("config".equals(command)) {
// Configure a collection with the three main settings
else if ("config".equals(command))
{
if (collection == null)
{
if (collection == null) {
System.out.println("Error - a target collection must be provided");
System.out.println(" (run with -h flag for details)");
System.exit(1);
}
if (oaiSource == null || oaiSetID == null)
{
if (oaiSource == null || oaiSetID == null) {
System.out.println("Error - both the OAI server address and OAI set id must be specified");
System.out.println(" (run with -h flag for details)");
System.exit(1);
}
if (metadataKey == null)
{
System.out.println("Error - a metadata key (commonly the prefix) must be specified for this collection");
if (metadataKey == null) {
System.out
.println("Error - a metadata key (commonly the prefix) must be specified for this collection");
System.out.println(" (run with -h flag for details)");
System.exit(1);
}
harvester.configureCollection(collection, harvestType, oaiSource, oaiSetID, metadataKey);
}
else if ("ping".equals(command))
{
if (oaiSource == null || oaiSetID == null)
{
} else if ("ping".equals(command)) {
if (oaiSource == null || oaiSetID == null) {
System.out.println("Error - both the OAI server address and OAI set id must be specified");
System.out.println(" (run with -h flag for details)");
System.exit(1);
@@ -272,39 +260,29 @@ public class Harvest
try {
// is the ID a handle?
if (collectionID != null)
{
if (collectionID.indexOf('/') != -1)
{
if (collectionID != null) {
if (collectionID.indexOf('/') != -1) {
// string has a / so it must be a handle - try and resolve it
dso = HandleServiceFactory.getInstance().getHandleService().resolveToObject(context, collectionID);
// resolved, now make sure it's a collection
if (dso == null || dso.getType() != Constants.COLLECTION)
{
if (dso == null || dso.getType() != Constants.COLLECTION) {
targetCollection = null;
}
else
{
} else {
targetCollection = (Collection) dso;
}
}
// not a handle, try and treat it as an integer collection
// database ID
else
{
System.out.println("Looking up by id: " + collectionID + ", parsed as '" + Integer.parseInt(collectionID) + "', " + "in context: " + context);
} else {
// not a handle, try and treat it as an collection database UUID
System.out.println("Looking up by UUID: " + collectionID + ", " + "in context: " + context);
targetCollection = collectionService.find(context, UUID.fromString(collectionID));
}
}
// was the collection valid?
if (targetCollection == null)
{
if (targetCollection == null) {
System.out.println("Cannot resolve " + collectionID + " to collection");
System.exit(1);
}
}
catch (SQLException se) {
} catch (SQLException se) {
se.printStackTrace();
}
@@ -312,7 +290,8 @@ public class Harvest
}
private void configureCollection(String collectionID, int type, String oaiSource, String oaiSetId, String mdConfigId) {
private void configureCollection(String collectionID, int type, String oaiSource, String oaiSetId,
String mdConfigId) {
System.out.println("Running: configure collection");
Collection collection = resolveCollection(collectionID);
@@ -330,15 +309,12 @@ public class Harvest
harvestedCollectionService.update(context, hc);
context.restoreAuthSystemState();
context.complete();
}
catch (Exception e) {
} catch (Exception e) {
System.out.println("Changes could not be committed");
e.printStackTrace();
System.exit(1);
}
finally {
if (context != null)
{
} finally {
if (context != null) {
context.restoreAuthSystemState();
}
}
@@ -352,11 +328,11 @@ public class Harvest
* @param email
*/
private void purgeCollection(String collectionID, String email) {
System.out.println("Purging collection of all items and resetting last_harvested and harvest_message: " + collectionID);
System.out.println(
"Purging collection of all items and resetting last_harvested and harvest_message: " + collectionID);
Collection collection = resolveCollection(collectionID);
try
{
try {
EPerson eperson = ePersonService.findByEmail(context, email);
context.setCurrentUser(eperson);
context.turnOffAuthorisationSystem();
@@ -386,13 +362,11 @@ public class Harvest
}
context.restoreAuthSystemState();
context.dispatchEvents();
}
catch (Exception e) {
} catch (Exception e) {
System.out.println("Changes could not be committed");
e.printStackTrace();
System.exit(1);
}
finally {
} finally {
context.restoreAuthSystemState();
}
}
@@ -411,8 +385,7 @@ public class Harvest
HarvestedCollection hc = harvestedCollectionService.find(context, collection);
harvester = new OAIHarvester(context, collection, hc);
System.out.println("success. ");
}
catch (HarvestingException hex) {
} catch (HarvestingException hex) {
System.out.print("failed. ");
System.out.println(hex.getMessage());
throw new IllegalStateException("Unable to harvest", hex);
@@ -429,14 +402,11 @@ public class Harvest
context.setCurrentUser(eperson);
harvester.runHarvest();
context.complete();
}
catch (SQLException e) {
} catch (SQLException e) {
throw new IllegalStateException("Failed to run harvester", e);
}
catch (AuthorizeException e) {
} catch (AuthorizeException e) {
throw new IllegalStateException("Failed to run harvester", e);
}
catch (IOException e) {
} catch (IOException e) {
throw new IllegalStateException("Failed to run harvester", e);
}
@@ -444,24 +414,22 @@ public class Harvest
}
/**
* Resets harvest_status and harvest_start_time flags for all collections that have a row in the harvested_collections table
* Resets harvest_status and harvest_start_time flags for all collections that have a row in the
* harvested_collections table
*/
private static void resetHarvesting() {
System.out.print("Resetting harvest status flag on all collections... ");
try
{
try {
List<HarvestedCollection> harvestedCollections = harvestedCollectionService.findAll(context);
for (HarvestedCollection harvestedCollection : harvestedCollections)
{
for (HarvestedCollection harvestedCollection : harvestedCollections) {
//hc.setHarvestResult(null,"");
harvestedCollection.setHarvestStartTime(null);
harvestedCollection.setHarvestStatus(HarvestedCollection.STATUS_READY);
harvestedCollectionService.update(context, harvestedCollection);
}
System.out.println("success. ");
}
catch (Exception ex) {
} catch (Exception ex) {
System.out.println("failed. ");
ex.printStackTrace();
}
@@ -470,15 +438,12 @@ public class Harvest
/**
* Starts up the harvest scheduler. Terminating this process will stop the scheduler.
*/
private static void startHarvester()
{
try
{
private static void startHarvester() {
try {
System.out.print("Starting harvest loop... ");
HarvestServiceFactory.getInstance().getHarvestSchedulingService().startNewScheduler();
System.out.println("running. ");
}
catch (Exception ex) {
} catch (Exception ex) {
ex.printStackTrace();
}
}
@@ -490,30 +455,29 @@ public class Harvest
* @param set name of an item set.
* @param metadataFormat local prefix name, or null for "dc".
*/
private static void pingResponder(String server, String set, String metadataFormat)
{
private static void pingResponder(String server, String set, String metadataFormat) {
List<String> errors;
System.out.print("Testing basic PMH access: ");
errors = OAIHarvester.verifyOAIharvester(server, set,
errors = harvestedCollectionService.verifyOAIharvester(server, set,
(null != metadataFormat) ? metadataFormat : "dc", false);
if (errors.isEmpty())
if (errors.isEmpty()) {
System.out.println("OK");
else
{
for (String error : errors)
} else {
for (String error : errors) {
System.err.println(error);
}
}
System.out.print("Testing ORE support: ");
errors = OAIHarvester.verifyOAIharvester(server, set,
errors = harvestedCollectionService.verifyOAIharvester(server, set,
(null != metadataFormat) ? metadataFormat : "dc", true);
if (errors.isEmpty())
if (errors.isEmpty()) {
System.out.println("OK");
else
{
for (String error : errors)
} else {
for (String error : errors) {
System.err.println(error);
}
}
}
}

View File

@@ -7,7 +7,17 @@
*/
package org.dspace.app.itemexport;
import org.apache.commons.cli.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.PosixParser;
import org.dspace.app.itemexport.factory.ItemExportServiceFactory;
import org.dspace.app.itemexport.service.ItemExportService;
import org.dspace.content.Collection;
@@ -20,8 +30,6 @@ import org.dspace.core.Context;
import org.dspace.handle.factory.HandleServiceFactory;
import org.dspace.handle.service.HandleService;
import java.util.*;
/**
* Item exporter to create simple AIPs for DSpace content. Currently exports
* individual items, or entire collections. For instructions on use, see
@@ -45,17 +53,21 @@ import java.util.*;
*/
public class ItemExportCLITool {
protected static ItemExportService itemExportService = ItemExportServiceFactory.getInstance().getItemExportService();
protected static ItemExportService itemExportService = ItemExportServiceFactory.getInstance()
.getItemExportService();
protected static HandleService handleService = HandleServiceFactory.getInstance().getHandleService();
protected static ItemService itemService = ContentServiceFactory.getInstance().getItemService();
protected static CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
/**
* Default constructor
*/
private ItemExportCLITool() { }
/*
*
*/
public static void main(String[] argv) throws Exception
{
public static void main(String[] argv) throws Exception {
// create an options object and populate it
CommandLineParser parser = new PosixParser();
@@ -65,7 +77,8 @@ public class ItemExportCLITool {
options.addOption("i", "id", true, "ID or handle of thing to export");
options.addOption("d", "dest", true,
"destination where you want items to go");
options.addOption("m", "migrate", false, "export for migration (remove handle and metadata that will be re-created in new system)");
options.addOption("m", "migrate", false,
"export for migration (remove handle and metadata that will be re-created in new system)");
options.addOption("n", "number", true,
"sequence number to begin exporting items with");
options.addOption("z", "zip", true, "export as zip file (specify filename e.g. export.zip)");
@@ -86,8 +99,7 @@ public class ItemExportCLITool {
Item myItem = null;
Collection mycollection = null;
if (line.hasOption('h'))
{
if (line.hasOption('h')) {
HelpFormatter myhelp = new HelpFormatter();
myhelp.printHelp("ItemExport\n", options);
System.out
@@ -98,79 +110,65 @@ public class ItemExportCLITool {
System.exit(0);
}
if (line.hasOption('t')) // type
{
if (line.hasOption('t')) { // type
typeString = line.getOptionValue('t');
if ("ITEM".equals(typeString))
{
if ("ITEM".equals(typeString)) {
myType = Constants.ITEM;
}
else if ("COLLECTION".equals(typeString))
{
} else if ("COLLECTION".equals(typeString)) {
myType = Constants.COLLECTION;
}
}
if (line.hasOption('i')) // id
{
if (line.hasOption('i')) { // id
myIDString = line.getOptionValue('i');
}
if (line.hasOption('d')) // dest
{
if (line.hasOption('d')) { // dest
destDirName = line.getOptionValue('d');
}
if (line.hasOption('n')) // number
{
if (line.hasOption('n')) { // number
seqStart = Integer.parseInt(line.getOptionValue('n'));
}
boolean migrate = false;
if (line.hasOption('m')) // number
{
if (line.hasOption('m')) { // number
migrate = true;
}
boolean zip = false;
String zipFileName = "";
if (line.hasOption('z'))
{
if (line.hasOption('z')) {
zip = true;
zipFileName = line.getOptionValue('z');
}
boolean excludeBitstreams = false;
if (line.hasOption('x'))
{
if (line.hasOption('x')) {
excludeBitstreams = true;
}
// now validate the args
if (myType == -1)
{
if (myType == -1) {
System.out
.println("type must be either COLLECTION or ITEM (-h for help)");
System.exit(1);
}
if (destDirName == null)
{
if (destDirName == null) {
System.out
.println("destination directory must be set (-h for help)");
System.exit(1);
}
if (seqStart == -1)
{
if (seqStart == -1) {
System.out
.println("sequence start number must be set (-h for help)");
System.exit(1);
}
if (myIDString == null)
{
if (myIDString == null) {
System.out
.println("ID must be set to either a database ID or a handle (-h for help)");
System.exit(1);
@@ -179,82 +177,62 @@ public class ItemExportCLITool {
Context c = new Context(Context.Mode.READ_ONLY);
c.turnOffAuthorisationSystem();
if (myType == Constants.ITEM)
{
if (myType == Constants.ITEM) {
// first, is myIDString a handle?
if (myIDString.indexOf('/') != -1)
{
if (myIDString.indexOf('/') != -1) {
myItem = (Item) handleService.resolveToObject(c, myIDString);
if ((myItem == null) || (myItem.getType() != Constants.ITEM))
{
if ((myItem == null) || (myItem.getType() != Constants.ITEM)) {
myItem = null;
}
}
else
{
} else {
myItem = itemService.find(c, UUID.fromString(myIDString));
}
if (myItem == null)
{
if (myItem == null) {
System.out
.println("Error, item cannot be found: " + myIDString);
}
}
else
{
if (myIDString.indexOf('/') != -1)
{
} else {
if (myIDString.indexOf('/') != -1) {
// has a / must be a handle
mycollection = (Collection) handleService.resolveToObject(c,
myIDString);
// ensure it's a collection
if ((mycollection == null)
|| (mycollection.getType() != Constants.COLLECTION))
{
|| (mycollection.getType() != Constants.COLLECTION)) {
mycollection = null;
}
}
else if (myIDString != null)
{
} else if (myIDString != null) {
mycollection = collectionService.find(c, UUID.fromString(myIDString));
}
if (mycollection == null)
{
if (mycollection == null) {
System.out.println("Error, collection cannot be found: "
+ myIDString);
System.exit(1);
}
}
if (zip)
{
if (zip) {
Iterator<Item> items;
if (myItem != null)
{
if (myItem != null) {
List<Item> myItems = new ArrayList<>();
myItems.add(myItem);
items = myItems.iterator();
}
else
{
} else {
System.out.println("Exporting from collection: " + myIDString);
items = itemService.findByCollection(c, mycollection);
}
itemExportService.exportAsZip(c, items, destDirName, zipFileName, seqStart, migrate, excludeBitstreams);
}
else
{
if (myItem != null)
{
} else {
if (myItem != null) {
// it's only a single item
itemExportService.exportItem(c, Collections.singletonList(myItem).iterator(), destDirName, seqStart, migrate, excludeBitstreams);
}
else
{
itemExportService
.exportItem(c, Collections.singletonList(myItem).iterator(), destDirName, seqStart, migrate,
excludeBitstreams);
} else {
System.out.println("Exporting from collection: " + myIDString);
// it's a collection, so do a bunch of items

View File

@@ -10,20 +10,17 @@ package org.dspace.app.itemexport;
/**
* An exception that can be thrown when error occur during item export
*/
public class ItemExportException extends Exception
{
public class ItemExportException extends Exception {
public static final int EXPORT_TOO_LARGE = 0;
private int reason;
public ItemExportException(int r, String message)
{
public ItemExportException(int r, String message) {
super(message);
reason = r;
}
public int getReason()
{
public int getReason() {
return reason;
}
}

View File

@@ -11,7 +11,8 @@ import org.dspace.app.itemexport.service.ItemExportService;
import org.dspace.services.factory.DSpaceServicesFactory;
/**
* Abstract factory to get services for the itemexport package, use ItemExportServiceFactory.getInstance() to retrieve an implementation
* Abstract factory to get services for the itemexport package, use ItemExportServiceFactory.getInstance() to
* retrieve an implementation
*
* @author kevinvandevelde at atmire.com
*/
@@ -20,6 +21,7 @@ public abstract class ItemExportServiceFactory {
public abstract ItemExportService getItemExportService();
public static ItemExportServiceFactory getInstance() {
return DSpaceServicesFactory.getInstance().getServiceManager().getServiceByName("itemExportServiceFactory", ItemExportServiceFactory.class);
return DSpaceServicesFactory.getInstance().getServiceManager()
.getServiceByName("itemExportServiceFactory", ItemExportServiceFactory.class);
}
}

View File

@@ -11,7 +11,8 @@ import org.dspace.app.itemexport.service.ItemExportService;
import org.springframework.beans.factory.annotation.Autowired;
/**
* Factory implementation to get services for the itemexport package, use ItemExportServiceFactory.getInstance() to retrieve an implementation
* Factory implementation to get services for the itemexport package, use ItemExportServiceFactory.getInstance() to
* retrieve an implementation
*
* @author kevinvandevelde at atmire.com
*/

View File

@@ -7,16 +7,16 @@
*/
package org.dspace.app.itemexport.service;
import org.dspace.content.DSpaceObject;
import org.dspace.content.Item;
import org.dspace.core.Context;
import org.dspace.eperson.EPerson;
import javax.mail.MessagingException;
import java.io.InputStream;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import javax.mail.MessagingException;
import org.dspace.content.DSpaceObject;
import org.dspace.content.Item;
import org.dspace.core.Context;
import org.dspace.eperson.EPerson;
/**
* Item exporter to create simple AIPs for DSpace content. Currently exports
@@ -71,10 +71,8 @@ public interface ItemExportService {
* Convenience methot to create export a single Community, Collection, or
* Item
*
* @param dso
* - the dspace object to export
* @param context
* - the dspace context
* @param dso - the dspace object to export
* @param context - the dspace context
* @param migrate Whether to use the migrate option or not
* @throws Exception if error
*/
@@ -85,10 +83,8 @@ public interface ItemExportService {
* Convenience method to export a List of dspace objects (Community,
* Collection or Item)
*
* @param dsObjects
* - List containing dspace objects
* @param context
* - the dspace context
* @param dsObjects - List containing dspace objects
* @param context - the dspace context
* @param migrate Whether to use the migrate option or not
* @throws Exception if error
*/
@@ -99,12 +95,9 @@ public interface ItemExportService {
* Convenience methot to create export a single Community, Collection, or
* Item
*
* @param dso
* - the dspace object to export
* @param context
* - the dspace context
* @param additionalEmail
* - cc email to use
* @param dso - the dspace object to export
* @param context - the dspace context
* @param additionalEmail - cc email to use
* @param migrate Whether to use the migrate option or not
* @throws Exception if error
*/
@@ -115,12 +108,9 @@ public interface ItemExportService {
* Convenience method to export a List of dspace objects (Community,
* Collection or Item)
*
* @param dsObjects
* - List containing dspace objects
* @param context
* - the dspace context
* @param additionalEmail
* - cc email to use
* @param dsObjects - List containing dspace objects
* @param context - the dspace context
* @param additionalEmail - cc email to use
* @param migrate Whether to use the migrate option or not
* @throws Exception if error
*/
@@ -132,10 +122,8 @@ public interface ItemExportService {
* Create a file name based on the date and eperson
*
* @param type Type of object (as string)
* @param eperson
* - eperson who requested export and will be able to download it
* @param date
* - the date the export process was created
* @param eperson - eperson who requested export and will be able to download it
* @param date - the date the export process was created
* @return String representing the file name in the form of
* 'export_yyy_MMM_dd_count_epersonID'
* @throws Exception if error
@@ -148,8 +136,7 @@ public interface ItemExportService {
* Use config file entry for org.dspace.app.itemexport.download.dir and id
* of the eperson to create a download directory name
*
* @param ePerson
* - the eperson who requested export archive
* @param ePerson - the eperson who requested export archive
* @return String representing a directory in the form of
* org.dspace.app.itemexport.download.dir/epersonID
* @throws Exception if error
@@ -170,10 +157,8 @@ public interface ItemExportService {
/**
* Used to read the export archived. Inteded for download.
*
* @param fileName
* the name of the file to download
* @param eperson
* the eperson requesting the download
* @param fileName the name of the file to download
* @param eperson the eperson requesting the download
* @return an input stream of the file to be downloaded
* @throws Exception if error
*/
@@ -184,10 +169,9 @@ public interface ItemExportService {
* Get the file size of the export archive represented by the file name.
*
* @param context DSpace context
* @param fileName
* name of the file to get the size.
* @throws Exception if error
* @param fileName name of the file to get the size.
* @return size as long
* @throws Exception if error
*/
public long getExportFileSize(Context context, String fileName) throws Exception;
@@ -195,11 +179,10 @@ public interface ItemExportService {
* Get the last modified date of the export archive represented by the file name.
*
* @param context DSpace context
* @param fileName
* name of the file to get the size.
* @param fileName name of the file to get the size.
* @return date as long
* @see java.io.File#lastModified()
* @throws Exception if error
* @see java.io.File#lastModified()
*/
public long getExportFileLastModified(Context context, String fileName)
throws Exception;
@@ -209,10 +192,8 @@ public interface ItemExportService {
* who created it When requested for download this method can check if the
* person requesting it is the same one that created it
*
* @param context
* dspace context
* @param fileName
* the file name to check auths for
* @param context dspace context
* @param fileName the file name to check auths for
* @return true if it is the same person false otherwise
*/
public boolean canDownload(Context context, String fileName);
@@ -234,8 +215,7 @@ public interface ItemExportService {
* uses the config file entry 'org.dspace.app.itemexport.life.span.hours' to
* determine if the current exports are too old and need pruging
*
* @param eperson
* - the eperson to clean up
* @param eperson - the eperson to clean up
* @throws Exception if error
*/
public void deleteOldExportArchives(EPerson eperson) throws Exception;
@@ -256,12 +236,9 @@ public interface ItemExportService {
* communication with email instead. Send a success email once the export
* archive is complete and ready for download
*
* @param context
* - the current Context
* @param eperson
* - eperson to send the email to
* @param fileName
* - the file name to be downloaded. It is added to the url in
* @param context - the current Context
* @param eperson - eperson to send the email to
* @param fileName - the file name to be downloaded. It is added to the url in
* the email
* @throws MessagingException if error
*/
@@ -274,10 +251,8 @@ public interface ItemExportService {
* communication with email instead. Send an error email if the export
* archive fails
*
* @param eperson
* - EPerson to send the error message to
* @param error
* - the error message
* @param eperson - EPerson to send the error message to
* @param error - the error message
* @throws MessagingException if error
*/
public void emailErrorMessage(EPerson eperson, String error)
@@ -285,6 +260,7 @@ public interface ItemExportService {
/**
* Zip source to target
*
* @param strSource source file
* @param target target file
* @throws Exception if error

View File

@@ -7,23 +7,20 @@
*/
package org.dspace.app.itemimport;
import gr.ekt.bte.core.DataLoader;
import gr.ekt.bte.core.TransformationEngine;
import gr.ekt.bte.dataloader.FileDataLoader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import gr.ekt.bte.core.DataLoader;
import gr.ekt.bte.core.TransformationEngine;
import gr.ekt.bte.dataloader.FileDataLoader;
/**
* This class acts as a Service in the procedure to batch import using the Biblio-Transformation-Engine
*/
public class BTEBatchImportService
{
public class BTEBatchImportService {
TransformationEngine transformationEngine;
Map<String, DataLoader> dataLoaders = new HashMap<String, DataLoader>();
@@ -32,31 +29,31 @@ public class BTEBatchImportService
/**
* Default constructor
*/
public BTEBatchImportService()
{
public BTEBatchImportService() {
super();
}
/**
* Setter method for dataLoaders parameter
*
* @param dataLoaders map of data loaders
*/
public void setDataLoaders(Map<String, DataLoader> dataLoaders)
{
public void setDataLoaders(Map<String, DataLoader> dataLoaders) {
this.dataLoaders = dataLoaders;
}
/**
* Get data loaders
*
* @return the map of DataLoaders
*/
public Map<String, DataLoader> getDataLoaders()
{
public Map<String, DataLoader> getDataLoaders() {
return dataLoaders;
}
/**
* Get output map
*
* @return the outputMapping
*/
public Map<String, String> getOutputMap() {
@@ -65,6 +62,7 @@ public class BTEBatchImportService
/**
* Setter method for the outputMapping
*
* @param outputMap the output mapping
*/
public void setOutputMap(Map<String, String> outputMap) {
@@ -73,6 +71,7 @@ public class BTEBatchImportService
/**
* Get transformation engine
*
* @return transformation engine
*/
public TransformationEngine getTransformationEngine() {
@@ -81,6 +80,7 @@ public class BTEBatchImportService
/**
* set transformation engine
*
* @param transformationEngine transformation engine
*/
public void setTransformationEngine(TransformationEngine transformationEngine) {
@@ -89,6 +89,7 @@ public class BTEBatchImportService
/**
* Getter of file data loaders
*
* @return List of file data loaders
*/
public List<String> getFileDataLoaders() {

View File

@@ -20,7 +20,6 @@ import java.util.List;
/**
* @author kstamatis
*
*/
public class BatchUpload {
@@ -35,6 +34,7 @@ public class BatchUpload {
/**
* Initialize with directory
*
* @param dirPath directory path
*/
public BatchUpload(String dirPath) {
@@ -45,6 +45,7 @@ public class BatchUpload {
/**
* Initialize with directory
*
* @param dir directory path
*/
public BatchUpload(File dir) {
@@ -55,6 +56,7 @@ public class BatchUpload {
/**
* Initialize with directory
*
* @param dir directory path
*/
private void initializeWithFile(File dir) {
@@ -96,6 +98,7 @@ public class BatchUpload {
/**
* Count lines in file
*
* @param filename file name
* @return lines in file
* @throws IOException if IO error
@@ -106,11 +109,12 @@ public class BatchUpload {
String lineRead = "";
while ((lineRead = reader.readLine()) != null) {
String[] parts = lineRead.split(" ");
if (parts.length > 1)
if (parts.length > 1) {
handlesImported.add(parts[1].trim());
else
} else {
handlesImported.add(lineRead);
}
}
cnt = reader.getLineNumber();
reader.close();
@@ -119,6 +123,7 @@ public class BatchUpload {
/**
* Read a file
*
* @param filename file name
* @throws IOException if IO error
*/
@@ -130,11 +135,9 @@ public class BatchUpload {
if (lineRead.startsWith("\tat ")) {
this.errorMsgHTML += "<span class=\"batchimport-error-tab\">" + lineRead + "</span><br/>";
}
else if (lineRead.startsWith("Caused by")){
} else if (lineRead.startsWith("Caused by")) {
this.errorMsgHTML += "<span class=\"batchimport-error-caused\">" + lineRead + "</span><br/>";
}
else {
} else {
this.errorMsgHTML += lineRead + "<br/>";
}
}
@@ -143,6 +146,7 @@ public class BatchUpload {
/**
* Get date
*
* @return Date
*/
public Date getDate() {
@@ -151,6 +155,7 @@ public class BatchUpload {
/**
* Get path to directory
*
* @return directory
*/
public File getDir() {
@@ -159,6 +164,7 @@ public class BatchUpload {
/**
* Whether successulf
*
* @return true or false
*/
public boolean isSuccessful() {
@@ -167,6 +173,7 @@ public class BatchUpload {
/**
* Get items imported
*
* @return number of items
*/
public int getItemsImported() {
@@ -175,6 +182,7 @@ public class BatchUpload {
/**
* Get total items
*
* @return total
*/
public int getTotalItems() {
@@ -183,6 +191,7 @@ public class BatchUpload {
/**
* Get formatted date (DD/MM/YY)
*
* @return date as string
*/
public String getDateFormatted() {
@@ -193,6 +202,7 @@ public class BatchUpload {
/**
* Get handles of imported files
*
* @return list of handles
*/
public List<String> getHandlesImported() {
@@ -201,6 +211,7 @@ public class BatchUpload {
/**
* Get error message
*
* @return error message
*/
public String getErrorMsg() {
@@ -209,6 +220,7 @@ public class BatchUpload {
/**
* Get error message as HTML
*
* @return error message string as HTML
*/
public String getErrorMsgHTML() {

View File

@@ -7,7 +7,17 @@
*/
package org.dspace.app.itemimport;
import org.apache.commons.cli.*;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.PosixParser;
import org.dspace.app.itemimport.factory.ItemImportServiceFactory;
import org.dspace.app.itemimport.service.ItemImportService;
import org.dspace.content.Collection;
@@ -21,12 +31,6 @@ import org.dspace.eperson.service.EPersonService;
import org.dspace.handle.factory.HandleServiceFactory;
import org.dspace.handle.service.HandleService;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
/**
* Import items into DSpace. The conventional use is upload files by copying
* them. DSpace writes the item's bitstreams into its assetstore. Metadata is
@@ -47,12 +51,17 @@ public class ItemImportCLITool {
private static boolean template = false;
private static final CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
private static final CollectionService collectionService = ContentServiceFactory.getInstance()
.getCollectionService();
private static final EPersonService epersonService = EPersonServiceFactory.getInstance().getEPersonService();
private static final HandleService handleService = HandleServiceFactory.getInstance().getHandleService();
public static void main(String[] argv) throws Exception
{
/**
* Default constructor
*/
private ItemImportCLITool() { }
public static void main(String[] argv) throws Exception {
Date startTime = new Date();
int status = 0;
@@ -108,13 +117,17 @@ public class ItemImportCLITool {
System.out
.println("\nadding items: ItemImport -a -e eperson -c collection -s sourcedir -m mapfile");
System.out
.println("\nadding items from zip file: ItemImport -a -e eperson -c collection -s sourcedir -z filename.zip -m mapfile");
.println(
"\nadding items from zip file: ItemImport -a -e eperson -c collection -s sourcedir -z " +
"filename.zip -m mapfile");
System.out
.println("replacing items: ItemImport -r -e eperson -c collection -s sourcedir -m mapfile");
System.out
.println("deleting items: ItemImport -d -e eperson -m mapfile");
System.out
.println("If multiple collections are specified, the first collection will be the one that owns the item.");
.println(
"If multiple collections are specified, the first collection will be the one that owns the " +
"item.");
System.exit(0);
}
@@ -155,23 +168,19 @@ public class ItemImportCLITool {
template = true;
}
if (line.hasOption('s')) // source
{
if (line.hasOption('s')) { // source
sourcedir = line.getOptionValue('s');
}
if (line.hasOption('m')) // mapfile
{
if (line.hasOption('m')) { // mapfile
mapfile = line.getOptionValue('m');
}
if (line.hasOption('e')) // eperson
{
if (line.hasOption('e')) { // eperson
eperson = line.getOptionValue('e');
}
if (line.hasOption('c')) // collections
{
if (line.hasOption('c')) { // collections
collections = line.getOptionValues('c');
}
@@ -227,7 +236,8 @@ public class ItemImportCLITool {
commandLineCollections = false;
}
} else if ("add-bte".equals(command)) {
//Source dir can be null, the user can specify the parameters for his loader in the Spring XML configuration file
//Source dir can be null, the user can specify the parameters for his loader in the Spring XML
// configuration file
if (mapfile == null) {
System.out
@@ -250,7 +260,9 @@ public class ItemImportCLITool {
if (bteInputType == null) {
System.out
.println("Error - an input type (tsv, csv, ris, endnote, bibtex or any other type you have specified in BTE Spring XML configuration file) must be specified");
.println(
"Error - an input type (tsv, csv, ris, endnote, bibtex or any other type you have " +
"specified in BTE Spring XML configuration file) must be specified");
System.out.println(" (run with -h flag for details)");
System.exit(1);
}
@@ -337,10 +349,8 @@ public class ItemImportCLITool {
|| (mycollections.get(i).getType() != Constants.COLLECTION)) {
mycollections.set(i, null);
}
}
// not a handle, try and treat it as an integer collection
// database ID
else if (collections[i] != null) {
} else if (collections[i] != null) {
// not a handle, try and treat it as an integer collection database ID
mycollections.set(i, collectionService.find(c, UUID.fromString(collections[i])));
}
@@ -394,11 +404,13 @@ public class ItemImportCLITool {
try {
if (zip) {
System.gc();
System.out.println("Deleting temporary zip directory: " + myloader.getTempWorkDirFile().getAbsolutePath());
System.out.println(
"Deleting temporary zip directory: " + myloader.getTempWorkDirFile().getAbsolutePath());
myloader.cleanupZipTemp();
}
} catch (Exception ex) {
System.out.println("Unable to delete temporary zip archive location: " + myloader.getTempWorkDirFile().getAbsolutePath());
System.out.println("Unable to delete temporary zip archive location: " + myloader.getTempWorkDirFile()
.getAbsolutePath());
}
@@ -409,7 +421,9 @@ public class ItemImportCLITool {
Date endTime = new Date();
System.out.println("Started: " + startTime.getTime());
System.out.println("Ended: " + endTime.getTime());
System.out.println("Elapsed time: " + ((endTime.getTime() - startTime.getTime()) / 1000) + " secs (" + (endTime.getTime() - startTime.getTime()) + " msecs)");
System.out.println(
"Elapsed time: " + ((endTime.getTime() - startTime.getTime()) / 1000) + " secs (" + (endTime
.getTime() - startTime.getTime()) + " msecs)");
}
System.exit(status);

View File

@@ -11,7 +11,8 @@ import org.dspace.app.itemimport.service.ItemImportService;
import org.dspace.services.factory.DSpaceServicesFactory;
/**
* Abstract factory to get services for the itemimport package, use ItemImportService.getInstance() to retrieve an implementation
* Abstract factory to get services for the itemimport package, use ItemImportService.getInstance() to retrieve an
* implementation
*
* @author kevinvandevelde at atmire.com
*/
@@ -20,6 +21,7 @@ public abstract class ItemImportServiceFactory {
public abstract ItemImportService getItemImportService();
public static ItemImportServiceFactory getInstance() {
return DSpaceServicesFactory.getInstance().getServiceManager().getServiceByName("itemImportServiceFactory", ItemImportServiceFactory.class);
return DSpaceServicesFactory.getInstance().getServiceManager()
.getServiceByName("itemImportServiceFactory", ItemImportServiceFactory.class);
}
}

View File

@@ -11,7 +11,8 @@ import org.dspace.app.itemimport.service.ItemImportService;
import org.springframework.beans.factory.annotation.Autowired;
/**
* Factory implementation to get services for the itemimport package, use ItemImportService.getInstance() to retrieve an implementation
* Factory implementation to get services for the itemimport package, use ItemImportService.getInstance() to retrieve
* an implementation
*
* @author kevinvandevelde at atmire.com
*/

View File

@@ -7,16 +7,16 @@
*/
package org.dspace.app.itemimport.service;
import java.io.File;
import java.io.IOException;
import java.util.List;
import javax.mail.MessagingException;
import org.dspace.app.itemimport.BatchUpload;
import org.dspace.content.Collection;
import org.dspace.core.Context;
import org.dspace.eperson.EPerson;
import javax.mail.MessagingException;
import java.io.File;
import java.io.IOException;
import java.util.List;
/**
* Import items into DSpace. The conventional use is upload files by copying
* them. DSpace writes the item's bitstreams into its assetstore. Metadata is
@@ -37,7 +37,6 @@ public interface ItemImportService {
/**
*
* @param c DSpace Context
* @param mycollections List of Collections
* @param sourceDir source location
@@ -45,10 +44,12 @@ public interface ItemImportService {
* @param template whether to use template item
* @throws Exception if error
*/
public void addItemsAtomic(Context c, List<Collection> mycollections, String sourceDir, String mapFile, boolean template) throws Exception;
public void addItemsAtomic(Context c, List<Collection> mycollections, String sourceDir, String mapFile,
boolean template) throws Exception;
/**
* Add items
*
* @param c DSpace Context
* @param mycollections List of Collections
* @param sourceDir source location
@@ -61,6 +62,7 @@ public interface ItemImportService {
/**
* Unzip a file
*
* @param zipfile file
* @return unzip location
* @throws IOException if error
@@ -69,6 +71,7 @@ public interface ItemImportService {
/**
* Unzip a file to a destination
*
* @param zipfile file
* @param destDir destination directory
* @return unzip location
@@ -78,6 +81,7 @@ public interface ItemImportService {
/**
* Unzip a file in a specific source directory
*
* @param sourcedir source directory
* @param zipfilename file name
* @return unzip location
@@ -86,8 +90,8 @@ public interface ItemImportService {
public String unzip(String sourcedir, String zipfilename) throws IOException;
/**
*
* Given a public URL to a zip file that has the Simple Archive Format, this method imports the contents to DSpace
*
* @param url The public URL of the zip file
* @param owningCollection The owning collection the items will belong to
* @param collections The collections the created items will be inserted to, apart from the owning one
@@ -97,7 +101,8 @@ public interface ItemImportService {
* @param template whether to use template item
* @throws Exception if error
*/
public void processUIImport(String url, Collection owningCollection, String[] collections, String resumeDir, String inputType, Context context, boolean template) throws Exception;
public void processUIImport(String url, Collection owningCollection, String[] collections, String resumeDir,
String inputType, Context context, boolean template) throws Exception;
/**
* Since the BTE batch import is done in a new thread we are unable to communicate
@@ -105,12 +110,9 @@ public interface ItemImportService {
* communication with email instead. Send a success email once the batch
* import is complete
*
* @param context
* - the current Context
* @param eperson
* - eperson to send the email to
* @param fileName
* - the filepath to the mapfile created by the batch import
* @param context - the current Context
* @param eperson - eperson to send the email to
* @param fileName - the filepath to the mapfile created by the batch import
* @throws MessagingException if error
*/
public void emailSuccessMessage(Context context, EPerson eperson,
@@ -122,10 +124,8 @@ public interface ItemImportService {
* communication with email instead. Send an error email if the batch
* import fails
*
* @param eperson
* - EPerson to send the error message to
* @param error
* - the error message
* @param eperson - EPerson to send the error message to
* @param error - the error message
* @throws MessagingException if error
*/
public void emailErrorMessage(EPerson eperson, String error)
@@ -134,6 +134,7 @@ public interface ItemImportService {
/**
* Get imports available for a person
*
* @param eperson EPerson object
* @return List of batch uploads
* @throws Exception if error
@@ -143,6 +144,7 @@ public interface ItemImportService {
/**
* Get import upload directory
*
* @param ePerson EPerson object
* @return directory
* @throws Exception if error
@@ -152,6 +154,7 @@ public interface ItemImportService {
/**
* Delete a batch by ID
*
* @param c DSpace Context
* @param uploadId identifier
* @throws Exception if error
@@ -160,6 +163,7 @@ public interface ItemImportService {
/**
* Replace items
*
* @param c DSpace Context
* @param mycollections List of Collections
* @param sourcedir source directory
@@ -167,10 +171,12 @@ public interface ItemImportService {
* @param template whether to use template item
* @throws Exception if error
*/
public void replaceItems(Context c, List<Collection> mycollections, String sourcedir, String mapfile, boolean template) throws Exception;
public void replaceItems(Context c, List<Collection> mycollections, String sourcedir, String mapfile,
boolean template) throws Exception;
/**
* Delete items via mapfile
*
* @param c DSpace Context
* @param mapfile map file
* @throws Exception if error
@@ -179,6 +185,7 @@ public interface ItemImportService {
/**
* Add items
*
* @param c DSpace Context
* @param mycollections List of Collections
* @param sourcedir source directory
@@ -188,16 +195,19 @@ public interface ItemImportService {
* @param workingDir working directory
* @throws Exception if error
*/
public void addBTEItems(Context c, List<Collection> mycollections, String sourcedir, String mapfile, boolean template, String bteInputType, String workingDir) throws Exception;
public void addBTEItems(Context c, List<Collection> mycollections, String sourcedir, String mapfile,
boolean template, String bteInputType, String workingDir) throws Exception;
/**
* Get temporary work directory
*
* @return directory as string
*/
public String getTempWorkDir();
/**
* Get temporary work directory (as File)
*
* @return directory as File
* @throws java.io.IOException if the directory cannot be created.
*/
@@ -210,18 +220,21 @@ public interface ItemImportService {
/**
* Set test flag
*
* @param isTest true or false
*/
public void setTest(boolean isTest);
/**
* Set resume flag
*
* @param isResume true or false
*/
public void setResume(boolean isResume);
/**
* Set use workflow
*
* @param useWorkflow whether to enable workflow
*/
public void setUseWorkflow(boolean useWorkflow);
@@ -233,6 +246,7 @@ public interface ItemImportService {
/**
* Set quiet flag
*
* @param isQuiet true or false
*/
public void setQuiet(boolean isQuiet);

View File

@@ -25,7 +25,6 @@ import org.springframework.beans.factory.annotation.Autowired;
* based on the existence of bitstreams within the ORIGINAL bundle.
*
* @author Kostas Stamatis
*
*/
public class ItemMarkingAvailabilityBitstreamStrategy implements ItemMarkingExtractor {
@@ -49,16 +48,14 @@ public class ItemMarkingAvailabilityBitstreamStrategy implements ItemMarkingExtr
markInfo.setImageName(nonAvailableImageName);
return markInfo;
}
else {
} else {
Bundle originalBundle = bundles.iterator().next();
if (originalBundle.getBitstreams().size() == 0) {
ItemMarkingInfo markInfo = new ItemMarkingInfo();
markInfo.setImageName(nonAvailableImageName);
return markInfo;
}
else {
} else {
Bitstream bitstream = originalBundle.getBitstreams().get(0);
ItemMarkingInfo signInfo = new ItemMarkingInfo();
@@ -66,7 +63,6 @@ public class ItemMarkingAvailabilityBitstreamStrategy implements ItemMarkingExtr
signInfo.setTooltip(bitstream.getName());
String bsLink = "";
bsLink = bsLink + "bitstream/"

View File

@@ -20,7 +20,6 @@ import org.dspace.core.Context;
* based on the collection the items belong to
*
* @author Kostas Stamatis
*
*/
public class ItemMarkingCollectionStrategy implements ItemMarkingExtractor {

View File

@@ -16,7 +16,6 @@ import org.dspace.core.Context;
* Interface to abstract the strategy for item signing
*
* @author Kostas Stamatis
*
*/
public interface ItemMarkingExtractor {
public ItemMarkingInfo getItemMarkingInfo(Context context, Item item)

View File

@@ -11,7 +11,6 @@ package org.dspace.app.itemmarking;
* Simple DTO to transfer data about the marking info for an item
*
* @author Kostas Stamatis
*
*/
public class ItemMarkingInfo {
private String imageName;

View File

@@ -24,7 +24,6 @@ import org.springframework.beans.factory.annotation.Autowired;
* metadata field
*
* @author Kostas Stamatis
*
*/
public class ItemMarkingMetadataStrategy implements ItemMarkingExtractor {
@@ -41,11 +40,9 @@ public class ItemMarkingMetadataStrategy implements ItemMarkingExtractor {
public ItemMarkingInfo getItemMarkingInfo(Context context, Item item)
throws SQLException {
if (metadataField != null && mapping!=null)
{
if (metadataField != null && mapping != null) {
List<MetadataValue> vals = itemService.getMetadataByMetadataString(item, metadataField);
if (vals.size() > 0)
{
if (vals.size() > 0) {
for (MetadataValue value : vals) {
String type = value.getValue();
if (mapping.containsKey(type)) {

View File

@@ -16,8 +16,6 @@ import java.util.Map;
* Order of actions is very import for correct processing. This implementation
* supports an iterator that returns the actions in the order in which they are
* put in. Adding the same action a second time has no effect on this order.
*
*
*/
public class ActionManager implements Iterable<UpdateAction> {
@@ -26,18 +24,17 @@ public class ActionManager implements Iterable<UpdateAction> {
/**
* Get update action
*
* @param actionClass UpdateAction class
* @return instantiation of UpdateAction class
* @throws InstantiationException if instantiation error
* @throws IllegalAccessException if illegal access error
*/
public UpdateAction getUpdateAction(Class<? extends UpdateAction> actionClass)
throws InstantiationException, IllegalAccessException
{
throws InstantiationException, IllegalAccessException {
UpdateAction action = registry.get(actionClass);
if (action == null)
{
if (action == null) {
action = actionClass.newInstance();
registry.put(actionClass, action);
}
@@ -46,11 +43,9 @@ public class ActionManager implements Iterable<UpdateAction> {
}
/**
*
* @return whether any actions have been registered with this manager
*/
public boolean hasActions()
{
public boolean hasActions() {
return !registry.isEmpty();
}
@@ -61,28 +56,23 @@ public class ActionManager implements Iterable<UpdateAction> {
* @return iterator for UpdateActions
*/
@Override
public Iterator<UpdateAction> iterator()
{
return new Iterator<UpdateAction>()
{
public Iterator<UpdateAction> iterator() {
return new Iterator<UpdateAction>() {
private Iterator<Class<? extends UpdateAction>> itr = registry.keySet().iterator();
@Override
public boolean hasNext()
{
public boolean hasNext() {
return itr.hasNext();
}
@Override
public UpdateAction next()
{
public UpdateAction next() {
return registry.get(itr.next());
}
//not supported
@Override
public void remove()
{
public void remove() {
throw new UnsupportedOperationException();
}
};

View File

@@ -19,7 +19,11 @@ import java.util.List;
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.factory.AuthorizeServiceFactory;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.content.*;
import org.dspace.content.Bitstream;
import org.dspace.content.BitstreamFormat;
import org.dspace.content.Bundle;
import org.dspace.content.DCDate;
import org.dspace.content.Item;
import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.BitstreamFormatService;
import org.dspace.content.service.InstallItemService;
@@ -30,18 +34,16 @@ import org.dspace.eperson.service.GroupService;
/**
* Action to add bitstreams listed in item contents file to the item in DSpace
*
*
*/
public class AddBitstreamsAction extends UpdateBitstreamsAction {
protected AuthorizeService authorizeService = AuthorizeServiceFactory.getInstance().getAuthorizeService();
protected BitstreamFormatService bitstreamFormatService = ContentServiceFactory.getInstance().getBitstreamFormatService();
protected BitstreamFormatService bitstreamFormatService = ContentServiceFactory.getInstance()
.getBitstreamFormatService();
protected GroupService groupService = EPersonServiceFactory.getInstance().getGroupService();
protected InstallItemService installItemService = ContentServiceFactory.getInstance().getInstallItemService();
public AddBitstreamsAction()
{
public AddBitstreamsAction() {
//empty
}
@@ -61,15 +63,13 @@ public class AddBitstreamsAction extends UpdateBitstreamsAction {
@Override
public void execute(Context context, ItemArchive itarch, boolean isTest,
boolean suppressUndo) throws IllegalArgumentException,
ParseException, IOException, AuthorizeException, SQLException
{
ParseException, IOException, AuthorizeException, SQLException {
Item item = itarch.getItem();
File dir = itarch.getDirectory();
List<ContentsEntry> contents = MetadataUtilities.readContentsFile(new File(dir, ItemUpdate.CONTENTS_FILE));
if (contents.isEmpty())
{
if (contents.isEmpty()) {
ItemUpdate.pr("Contents is empty - no bitstreams to add");
return;
}
@@ -78,36 +78,30 @@ public class AddBitstreamsAction extends UpdateBitstreamsAction {
String[] files = dir.list(ItemUpdate.fileFilter);
List<String> fileList = new ArrayList<String>();
for (String filename : files)
{
for (String filename : files) {
fileList.add(filename);
ItemUpdate.pr("file: " + filename);
}
for (ContentsEntry ce : contents)
{
for (ContentsEntry ce : contents) {
//validate match to existing file in archive
if (!fileList.contains(ce.filename))
{
if (!fileList.contains(ce.filename)) {
throw new IllegalArgumentException("File listed in contents is missing: " + ce.filename);
}
}
int bitstream_bundles_updated = 0;
//now okay to add
for (ContentsEntry ce : contents)
{
for (ContentsEntry ce : contents) {
String targetBundleName = addBitstream(context, itarch, item, dir, ce, suppressUndo, isTest);
if (!targetBundleName.equals("")
&& !targetBundleName.equals("THUMBNAIL")
&& !targetBundleName.equals("TEXT"))
{
&& !targetBundleName.equals("TEXT")) {
bitstream_bundles_updated++;
}
}
if (alterProvenance && bitstream_bundles_updated > 0)
{
if (alterProvenance && bitstream_bundles_updated > 0) {
DtoMetadata dtom = DtoMetadata.create("dc.description.provenance", "en", "");
String append = ". Added " + Integer.toString(bitstream_bundles_updated)
@@ -119,6 +113,7 @@ public class AddBitstreamsAction extends UpdateBitstreamsAction {
/**
* Add bitstream
*
* @param context DSpace Context
* @param itarch Item Archive
* @param item DSpace Item
@@ -135,8 +130,7 @@ public class AddBitstreamsAction extends UpdateBitstreamsAction {
*/
protected String addBitstream(Context context, ItemArchive itarch, Item item, File dir,
ContentsEntry ce, boolean suppressUndo, boolean isTest)
throws IOException, IllegalArgumentException, SQLException, AuthorizeException, ParseException
{
throws IOException, IllegalArgumentException, SQLException, AuthorizeException, ParseException {
ItemUpdate.pr("contents entry for bitstream: " + ce.toString());
File f = new File(dir, ce.filename);
@@ -146,40 +140,29 @@ public class AddBitstreamsAction extends UpdateBitstreamsAction {
Bitstream bs = null;
String newBundleName = ce.bundlename;
if (ce.bundlename == null) // should be required but default convention established
{
if (ce.filename.equals("license.txt"))
{
if (ce.bundlename == null) { // should be required but default convention established
if (ce.filename.equals("license.txt")) {
newBundleName = "LICENSE";
}
else
{
} else {
newBundleName = "ORIGINAL";
}
}
ItemUpdate.pr(" Bitstream " + ce.filename + " to be added to bundle: " + newBundleName);
if (!isTest)
{
if (!isTest) {
// find the bundle
List<Bundle> bundles = itemService.getBundles(item, newBundleName);
Bundle targetBundle = null;
if (bundles.size() < 1)
{
if (bundles.size() < 1) {
// not found, create a new one
targetBundle = bundleService.create(context, item, newBundleName);
}
else
{
} else {
//verify bundle + name are not duplicates
for (Bundle b : bundles)
{
for (Bundle b : bundles) {
List<Bitstream> bitstreams = b.getBitstreams();
for (Bitstream bsm : bitstreams)
{
if (bsm.getName().equals(ce.filename))
{
for (Bitstream bsm : bitstreams) {
if (bsm.getName().equals(ce.filename)) {
throw new IllegalArgumentException("Duplicate bundle + filename cannot be added: "
+ b.getName() + " + " + bsm.getName());
}
@@ -198,17 +181,14 @@ public class AddBitstreamsAction extends UpdateBitstreamsAction {
BitstreamFormat fmt = bitstreamFormatService.guessFormat(context, bs);
bitstreamService.setFormat(context, bs, fmt);
if (ce.description != null)
{
if (ce.description != null) {
bs.setDescription(context, ce.description);
}
if ((ce.permissionsActionId != -1) && (ce.permissionsGroupName != null))
{
if ((ce.permissionsActionId != -1) && (ce.permissionsGroupName != null)) {
Group group = groupService.findByName(context, ce.permissionsGroupName);
if (group != null)
{
if (group != null) {
authorizeService.removeAllPolicies(context, bs); // remove the default policy
authorizeService.createResourcePolicy(context, bs, group, null, ce.permissionsActionId, null);
}
@@ -217,8 +197,7 @@ public class AddBitstreamsAction extends UpdateBitstreamsAction {
//update after all changes are applied
bitstreamService.update(context, bs);
if (!suppressUndo)
{
if (!suppressUndo) {
itarch.addUndoDeleteContents(bs.getID());
}
return targetBundle.getName();

View File

@@ -11,11 +11,10 @@ import java.sql.SQLException;
import java.util.List;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.MetadataValue;
import org.dspace.content.Item;
import org.dspace.content.MetadataField;
import org.dspace.content.MetadataSchema;
import org.dspace.content.MetadataValue;
import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.MetadataFieldService;
import org.dspace.content.service.MetadataSchemaService;
@@ -23,11 +22,11 @@ import org.dspace.core.Context;
/**
* Action to add metadata to item
*
*/
public class AddMetadataAction extends UpdateMetadataAction {
protected MetadataSchemaService metadataSchemaService = ContentServiceFactory.getInstance().getMetadataSchemaService();
protected MetadataSchemaService metadataSchemaService = ContentServiceFactory.getInstance()
.getMetadataSchemaService();
protected MetadataFieldService metadataFieldService = ContentServiceFactory.getInstance().getMetadataFieldService();
/**
@@ -42,79 +41,68 @@ public class AddMetadataAction extends UpdateMetadataAction {
*/
@Override
public void execute(Context context, ItemArchive itarch, boolean isTest,
boolean suppressUndo) throws AuthorizeException, SQLException
{
boolean suppressUndo) throws AuthorizeException, SQLException {
Item item = itarch.getItem();
String dirname = itarch.getDirectoryName();
for (DtoMetadata dtom : itarch.getMetadataFields())
{
for (String f : targetFields)
{
if (dtom.matches(f, false))
{
for (DtoMetadata dtom : itarch.getMetadataFields()) {
for (String f : targetFields) {
if (dtom.matches(f, false)) {
// match against metadata for this field/value in repository
// qualifier must be strictly matched, possibly null
List<MetadataValue> ardcv = null;
ardcv = itemService.getMetadata(item, dtom.schema, dtom.element, dtom.qualifier, Item.ANY);
boolean found = false;
for (MetadataValue dcv : ardcv)
{
if (dcv.getValue().equals(dtom.value))
{
for (MetadataValue dcv : ardcv) {
if (dcv.getValue().equals(dtom.value)) {
found = true;
break;
}
}
if (found)
{
if (found) {
ItemUpdate.pr("Warning: No new metadata found to add to item " + dirname
+ " for element " + f);
}
else
{
if (isTest)
{
} else {
if (isTest) {
ItemUpdate.pr("Metadata to add: " + dtom.toString());
//validity tests that would occur in actual processing
// If we're just test the import, let's check that the actual metadata field exists.
MetadataSchema foundSchema = metadataSchemaService.find(context, dtom.schema);
if (foundSchema == null)
{
if (foundSchema == null) {
ItemUpdate.pr("ERROR: schema '"
+ dtom.schema + "' was not found in the registry; found on item " + dirname);
}
else
{
MetadataField foundField = metadataFieldService.findByElement(context, foundSchema, dtom.element, dtom.qualifier);
+ dtom.schema + "' was not found in the registry; found on item " +
dirname);
} else {
MetadataField foundField = metadataFieldService
.findByElement(context, foundSchema, dtom.element, dtom.qualifier);
if (foundField == null)
{
if (foundField == null) {
ItemUpdate.pr("ERROR: Metadata field: '" + dtom.schema + "." + dtom.element + "."
+ dtom.qualifier + "' not found in registry; found on item " + dirname);
+ dtom.qualifier + "' not found in registry; found on item " +
dirname);
}
}
}
else
{
itemService.addMetadata(context, item, dtom.schema, dtom.element, dtom.qualifier, dtom.language, dtom.value);
} else {
itemService
.addMetadata(context, item, dtom.schema, dtom.element, dtom.qualifier, dtom.language,
dtom.value);
ItemUpdate.pr("Metadata added: " + dtom.toString());
if (!suppressUndo)
{
if (!suppressUndo) {
//itarch.addUndoDtom(dtom);
//ItemUpdate.pr("Undo metadata: " + dtom);
// add all as a replace record to be preceded by delete
for (MetadataValue dcval : ardcv)
{
for (MetadataValue dcval : ardcv) {
MetadataField metadataField = dcval.getMetadataField();
MetadataSchema metadataSchema = metadataField.getMetadataSchema();
itarch.addUndoMetadataField(DtoMetadata.create(metadataSchema.getName(), metadataField.getElement(),
metadataField.getQualifier(), dcval.getLanguage(), dcval.getValue()));
itarch.addUndoMetadataField(
DtoMetadata.create(metadataSchema.getName(), metadataField.getElement(),
metadataField.getQualifier(), dcval.getLanguage(),
dcval.getValue()));
}
}

View File

@@ -7,17 +7,17 @@
*/
package org.dspace.app.itemupdate;
import java.io.IOException;
import java.util.Properties;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.dspace.content.Bitstream;
/**
* Filter interface to be used by ItemUpdate
* to determine which bitstreams in an Item
* acceptable for removal.
*
*/
public abstract class BitstreamFilter {
@@ -33,26 +33,20 @@ public abstract class BitstreamFilter {
public abstract boolean accept(Bitstream bitstream) throws BitstreamFilterException;
/**
*
* @param filepath - The complete path for the properties file
* @throws IOException if IO error
*/
public void initProperties(String filepath)
throws IOException
{
throws IOException {
props = new Properties();
InputStream in = null;
try
{
try {
in = new FileInputStream(filepath);
props.load(in);
}
finally
{
if (in != null)
{
} finally {
if (in != null) {
in.close();
}
}

View File

@@ -15,14 +15,12 @@ import org.dspace.content.Bundle;
/**
* BitstreamFilter implementation to filter by bundle name
*
*/
public class BitstreamFilterByBundleName extends BitstreamFilter {
protected String bundleName;
public BitstreamFilterByBundleName()
{
public BitstreamFilterByBundleName() {
//empty
}
@@ -30,36 +28,27 @@ public class BitstreamFilterByBundleName extends BitstreamFilter {
* Filter bitstream based on bundle name found in properties file
*
* @param bitstream Bitstream
* @throws BitstreamFilterException if filter error
* @return whether bitstream is in bundle
*
* @throws BitstreamFilterException if filter error
*/
@Override
public boolean accept(Bitstream bitstream)
throws BitstreamFilterException
{
if (bundleName == null)
{
throws BitstreamFilterException {
if (bundleName == null) {
bundleName = props.getProperty("bundle");
if (bundleName == null)
{
if (bundleName == null) {
throw new BitstreamFilterException("Property 'bundle' not found.");
}
}
try
{
try {
List<Bundle> bundles = bitstream.getBundles();
for (Bundle b : bundles)
{
if (b.getName().equals(bundleName))
{
for (Bundle b : bundles) {
if (b.getName().equals(bundleName)) {
return true;
}
}
}
catch(SQLException e)
{
} catch (SQLException e) {
throw new BitstreamFilterException(e);
}
return false;

View File

@@ -7,21 +7,20 @@
*/
package org.dspace.app.itemupdate;
import java.util.regex.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.dspace.content.Bitstream;
/**
* BitstreamFilter implementation to filter by filename pattern
*
*/
public class BitstreamFilterByFilename extends BitstreamFilter {
protected Pattern pattern;
protected String filenameRegex;
public BitstreamFilterByFilename()
{
public BitstreamFilterByFilename() {
//empty
}
@@ -34,13 +33,10 @@ public class BitstreamFilterByFilename extends BitstreamFilter {
* @throws BitstreamFilterException if filter error
*/
@Override
public boolean accept(Bitstream bitstream) throws BitstreamFilterException
{
if (filenameRegex == null)
{
public boolean accept(Bitstream bitstream) throws BitstreamFilterException {
if (filenameRegex == null) {
filenameRegex = props.getProperty("filename");
if (filenameRegex == null)
{
if (filenameRegex == null) {
throw new BitstreamFilterException("BitstreamFilter property 'filename' not found.");
}
pattern = Pattern.compile(filenameRegex);

View File

@@ -9,28 +9,25 @@ package org.dspace.app.itemupdate;
/**
* Exception class for BitstreamFilters
*
*/
public class BitstreamFilterException extends Exception
{
public class BitstreamFilterException extends Exception {
private static final long serialVersionUID = 1L;
public BitstreamFilterException() {}
public BitstreamFilterException() {
}
/**
*
* @param msg exception message
*/
public BitstreamFilterException(String msg)
{
public BitstreamFilterException(String msg) {
super(msg);
}
/**
*
* @param e exception
*/
public BitstreamFilterException(Exception e)
{
public BitstreamFilterException(Exception e) {
super(e);
}

View File

@@ -8,7 +8,8 @@
package org.dspace.app.itemupdate;
import java.text.ParseException;
import java.util.regex.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.dspace.core.Constants;
@@ -26,11 +27,8 @@ import org.dspace.core.Constants;
* permissions: -[r|w] ['group name']
* description: <the description of the file>
* }
*
*
*/
public class ContentsEntry
{
public class ContentsEntry {
public static final String HDR_BUNDLE = "bundle:";
public static final String HDR_PERMISSIONS = "permissions:";
public static final String HDR_DESCRIPTION = "description:";
@@ -47,8 +45,7 @@ public class ContentsEntry
String bundlename,
int permissionsActionId,
String permissionsGroupName,
String description)
{
String description) {
this.filename = filename;
this.bundlename = bundlename;
this.permissionsActionId = permissionsActionId;
@@ -64,8 +61,7 @@ public class ContentsEntry
* @throws ParseException if parse error
*/
public static ContentsEntry parse(String line)
throws ParseException
{
throws ParseException {
String[] ar = line.split("\t");
ItemUpdate.pr("ce line split: " + ar.length);
@@ -75,46 +71,33 @@ public class ContentsEntry
String groupName = null;
int actionId = -1;
if (ar.length > 1)
{
for (int i=1; i < ar.length; i++)
{
if (ar.length > 1) {
for (int i = 1; i < ar.length; i++) {
ItemUpdate.pr("ce " + i + " : " + ar[i]);
if (ar[i].startsWith(HDR_BUNDLE))
{
if (ar[i].startsWith(HDR_BUNDLE)) {
arp[1] = ar[i].substring(HDR_BUNDLE.length()).trim();
}
else if (ar[i].startsWith(HDR_PERMISSIONS))
{
} else if (ar[i].startsWith(HDR_PERMISSIONS)) {
arp[2] = ar[i].substring(HDR_PERMISSIONS.length()).trim();
// parse into actionId and group name
Matcher m = permissionsPattern.matcher(arp[2]);
if (m.matches())
{
if (m.matches()) {
String action = m.group(1); //
if (action.equals("r"))
{
if (action.equals("r")) {
actionId = Constants.READ;
}
else if (action.equals("w"))
{
} else if (action.equals("w")) {
actionId = Constants.WRITE;
}
groupName = m.group(2).trim();
}
}
else if (ar[i].startsWith(HDR_DESCRIPTION))
{
} else if (ar[i].startsWith(HDR_DESCRIPTION)) {
arp[3] = ar[i].substring(HDR_DESCRIPTION.length()).trim();
}
else
{
} else {
throw new ParseException("Unknown text in contents file: " + ar[i], 0);
}
}
@@ -122,30 +105,23 @@ public class ContentsEntry
return new ContentsEntry(arp[0], arp[1], actionId, groupName, arp[3]);
}
public String toString()
{
public String toString() {
StringBuilder sb = new StringBuilder(filename);
if (bundlename != null)
{
if (bundlename != null) {
sb.append(HDR_BUNDLE).append(" ").append(bundlename);
}
if (permissionsGroupName != null)
{
if (permissionsGroupName != null) {
sb.append(HDR_PERMISSIONS);
if (permissionsActionId == Constants.READ)
{
if (permissionsActionId == Constants.READ) {
sb.append(" -r ");
}
else if (permissionsActionId == Constants.WRITE)
{
} else if (permissionsActionId == Constants.WRITE) {
sb.append(" -w ");
}
sb.append(permissionsGroupName);
}
if (description != null)
{
if (description != null) {
sb.append(HDR_DESCRIPTION).append(" ").append(description);
}

View File

@@ -14,7 +14,10 @@ import java.text.ParseException;
import java.util.List;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.*;
import org.dspace.content.Bitstream;
import org.dspace.content.Bundle;
import org.dspace.content.DCDate;
import org.dspace.content.Item;
import org.dspace.core.Context;
/**
@@ -23,10 +26,8 @@ import org.dspace.core.Context;
* Undo not supported for this UpdateAction
*
* Derivatives of the bitstream to be deleted are not also deleted
*
*/
public class DeleteBitstreamsAction extends UpdateBitstreamsAction
{
public class DeleteBitstreamsAction extends UpdateBitstreamsAction {
/**
* Delete bitstream from item
*
@@ -43,65 +44,46 @@ public class DeleteBitstreamsAction extends UpdateBitstreamsAction
@Override
public void execute(Context context, ItemArchive itarch, boolean isTest,
boolean suppressUndo) throws IllegalArgumentException, IOException,
SQLException, AuthorizeException, ParseException
{
SQLException, AuthorizeException, ParseException {
File f = new File(itarch.getDirectory(), ItemUpdate.DELETE_CONTENTS_FILE);
if (!f.exists())
{
if (!f.exists()) {
ItemUpdate.pr("Warning: Delete_contents file for item " + itarch.getDirectoryName() + " not found.");
}
else
{
} else {
List<String> list = MetadataUtilities.readDeleteContentsFile(f);
if (list.isEmpty())
{
if (list.isEmpty()) {
ItemUpdate.pr("Warning: empty delete_contents file for item " + itarch.getDirectoryName());
}
else
{
for (String id : list)
{
try
{
} else {
for (String id : list) {
try {
Bitstream bs = bitstreamService.findByIdOrLegacyId(context, id);
if (bs == null)
{
if (bs == null) {
ItemUpdate.pr("Bitstream not found by id: " + id);
}
else
{
} else {
List<Bundle> bundles = bs.getBundles();
for (Bundle b : bundles)
{
if (isTest)
{
for (Bundle b : bundles) {
if (isTest) {
ItemUpdate.pr("Delete bitstream with id = " + id);
}
else
{
} else {
bundleService.removeBitstream(context, b, bs);
ItemUpdate.pr("Deleted bitstream with id = " + id);
}
}
if (alterProvenance)
{
if (alterProvenance) {
DtoMetadata dtom = DtoMetadata.create("dc.description.provenance", "en", "");
String append = "Bitstream " + bs.getName() + " deleted on " + DCDate.getCurrent() + "; ";
String append = "Bitstream " + bs.getName() + " deleted on " + DCDate
.getCurrent() + "; ";
Item item = bundles.iterator().next().getItems().iterator().next();
ItemUpdate.pr("Append provenance with: " + append);
if (!isTest)
{
if (!isTest) {
MetadataUtilities.appendMetadata(context, item, dtom, false, append);
}
}
}
}
catch(SQLException e)
{
} catch (SQLException e) {
ItemUpdate.pr("Error finding bitstream from id: " + id + " : " + e.toString());
}
}

View File

@@ -14,7 +14,10 @@ import java.util.ArrayList;
import java.util.List;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.*;
import org.dspace.content.Bitstream;
import org.dspace.content.Bundle;
import org.dspace.content.DCDate;
import org.dspace.content.Item;
import org.dspace.core.Context;
/**
@@ -25,8 +28,6 @@ import org.dspace.core.Context;
*
* Note: Multiple filters are impractical if trying to manage multiple properties files
* in a commandline environment
*
*
*/
public class DeleteBitstreamsByFilterAction extends UpdateBitstreamsAction {
@@ -37,17 +38,16 @@ public class DeleteBitstreamsByFilterAction extends UpdateBitstreamsAction {
*
* @param filter BitstreamFilter
*/
public void setBitstreamFilter(BitstreamFilter filter)
{
public void setBitstreamFilter(BitstreamFilter filter) {
this.filter = filter;
}
/**
* Get filter
*
* @return filter
*/
public BitstreamFilter getBitstreamFilter()
{
public BitstreamFilter getBitstreamFilter() {
return filter;
}
@@ -67,33 +67,25 @@ public class DeleteBitstreamsByFilterAction extends UpdateBitstreamsAction {
@Override
public void execute(Context context, ItemArchive itarch, boolean isTest,
boolean suppressUndo) throws AuthorizeException,
BitstreamFilterException, IOException, ParseException, SQLException
{
BitstreamFilterException, IOException, ParseException, SQLException {
List<String> deleted = new ArrayList<String>();
Item item = itarch.getItem();
List<Bundle> bundles = item.getBundles();
for (Bundle b : bundles)
{
for (Bundle b : bundles) {
List<Bitstream> bitstreams = b.getBitstreams();
String bundleName = b.getName();
for (Bitstream bs : bitstreams)
{
if (filter.accept(bs))
{
if (isTest)
{
for (Bitstream bs : bitstreams) {
if (filter.accept(bs)) {
if (isTest) {
ItemUpdate.pr("Delete from bundle " + bundleName + " bitstream " + bs.getName()
+ " with id = " + bs.getID());
}
else
{
} else {
//provenance is not maintained for derivative bitstreams
if (!bundleName.equals("THUMBNAIL") && !bundleName.equals("TEXT"))
{
if (!bundleName.equals("THUMBNAIL") && !bundleName.equals("TEXT")) {
deleted.add(bs.getName());
}
bundleService.removeBitstream(context, b, bs);
@@ -104,13 +96,11 @@ public class DeleteBitstreamsByFilterAction extends UpdateBitstreamsAction {
}
}
if (alterProvenance && !deleted.isEmpty())
{
if (alterProvenance && !deleted.isEmpty()) {
StringBuilder sb = new StringBuilder(" Bitstreams deleted on ");
sb.append(DCDate.getCurrent()).append(": ");
for (String s : deleted)
{
for (String s : deleted) {
sb.append(s).append(", ");
}
@@ -118,8 +108,7 @@ public class DeleteBitstreamsByFilterAction extends UpdateBitstreamsAction {
ItemUpdate.pr("Append provenance with: " + sb.toString());
if (!isTest)
{
if (!isTest) {
MetadataUtilities.appendMetadata(context, item, dtom, false, sb.toString());
}
}

View File

@@ -12,16 +12,14 @@ import java.text.ParseException;
import java.util.List;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Item;
import org.dspace.content.MetadataField;
import org.dspace.content.MetadataSchema;
import org.dspace.content.MetadataValue;
import org.dspace.content.Item;
import org.dspace.core.Context;
/**
* Action to delete metadata
*
*
*/
public class DeleteMetadataAction extends UpdateMetadataAction {
@@ -40,26 +38,22 @@ public class DeleteMetadataAction extends UpdateMetadataAction {
public void execute(Context context, ItemArchive itarch, boolean isTest,
boolean suppressUndo) throws AuthorizeException, ParseException, SQLException {
Item item = itarch.getItem();
for (String f : targetFields)
{
for (String f : targetFields) {
DtoMetadata dummy = DtoMetadata.create(f, Item.ANY, "");
List<MetadataValue> ardcv = itemService.getMetadataByMetadataString(item, f);
ItemUpdate.pr("Metadata to be deleted: ");
for (MetadataValue dcv : ardcv)
{
for (MetadataValue dcv : ardcv) {
ItemUpdate.pr(" " + MetadataUtilities.getDCValueString(dcv));
}
if (!isTest)
{
if (!suppressUndo)
{
for (MetadataValue dcv : ardcv)
{
if (!isTest) {
if (!suppressUndo) {
for (MetadataValue dcv : ardcv) {
MetadataField metadataField = dcv.getMetadataField();
MetadataSchema metadataSchema = metadataField.getMetadataSchema();
itarch.addUndoMetadataField(DtoMetadata.create(metadataSchema.getName(), metadataField.getElement(),
itarch.addUndoMetadataField(
DtoMetadata.create(metadataSchema.getName(), metadataField.getElement(),
metadataField.getQualifier(), dcv.getLanguage(), dcv.getValue()));
}
}

View File

@@ -11,12 +11,10 @@ import java.util.Properties;
/**
* Bitstream filter to delete from TEXT bundle
*
*/
public class DerivativeTextBitstreamFilter extends BitstreamFilterByBundleName {
public DerivativeTextBitstreamFilter()
{
public DerivativeTextBitstreamFilter() {
props = new Properties();
props.setProperty("bundle", "TEXT");
}

View File

@@ -8,6 +8,7 @@
package org.dspace.app.itemupdate;
import java.text.ParseException;
import org.dspace.content.Item;
/**
@@ -16,22 +17,19 @@ import org.dspace.content.Item;
*
* Adds some utility methods
*
* Really not at all general enough but supports Dublin Core and the compound form notation {@code <schema>.<element>[.<qualifier>]}
* Really not at all general enough but supports Dublin Core and the compound form notation {@code <schema>
* .<element>[.<qualifier>]}
*
* Does not support wildcard for qualifier
*
*
*/
class DtoMetadata
{
class DtoMetadata {
final String schema;
final String element;
final String qualifier;
final String language;
final String value;
protected DtoMetadata(String schema, String element, String qualifier, String language, String value)
{
protected DtoMetadata(String schema, String element, String qualifier, String language, String value) {
this.schema = schema;
this.element = element;
this.qualifier = qualifier;
@@ -42,7 +40,6 @@ class DtoMetadata
/**
* Factory method
*
*
* @param schema not null, not empty - 'dc' is the standard case
* @param element not null, not empty
* @param qualifier null; don't allow empty string or * indicating 'any'
@@ -56,10 +53,8 @@ class DtoMetadata
String qualifier,
String language,
String value)
throws IllegalArgumentException
{
if ((qualifier != null) && (qualifier.equals(Item.ANY) || qualifier.equals("")))
{
throws IllegalArgumentException {
if ((qualifier != null) && (qualifier.equals(Item.ANY) || qualifier.equals(""))) {
throw new IllegalArgumentException("Invalid qualifier: " + qualifier);
}
return new DtoMetadata(schema, element, qualifier, language, value);
@@ -68,7 +63,6 @@ class DtoMetadata
/**
* Factory method to create metadata object
*
*
* @param compoundForm of the form <schema>.<element>[.<qualifier>]
* @param language null or empty
* @param value value
@@ -76,13 +70,11 @@ class DtoMetadata
* @throws IllegalArgumentException if arg error
*/
public static DtoMetadata create(String compoundForm, String language, String value)
throws ParseException, IllegalArgumentException
{
throws ParseException, IllegalArgumentException {
String[] ar = MetadataUtilities.parseCompoundForm(compoundForm);
String qual = null;
if (ar.length > 2)
{
if (ar.length > 2) {
qual = ar[2];
}
@@ -93,56 +85,44 @@ class DtoMetadata
* Determine if this metadata field matches the specified type:
* schema.element or schema.element.qualifier
*
*
* @param compoundForm of the form <schema>.<element>[.<qualifier>|.*]
* @param wildcard allow wildcards in compoundForm param
* @return whether matches
*/
public boolean matches(String compoundForm, boolean wildcard)
{
public boolean matches(String compoundForm, boolean wildcard) {
String[] ar = compoundForm.split("\\s*\\.\\s*"); //MetadataUtilities.parseCompoundForm(compoundForm);
if ((ar.length < 2) || (ar.length > 3))
{
if ((ar.length < 2) || (ar.length > 3)) {
return false;
}
if (!this.schema.equals(ar[0]) || !this.element.equals(ar[1]))
{
if (!this.schema.equals(ar[0]) || !this.element.equals(ar[1])) {
return false;
}
if (ar.length == 2)
{
if (this.qualifier != null)
{
if (ar.length == 2) {
if (this.qualifier != null) {
return false;
}
}
if (ar.length == 3)
{
if (this.qualifier == null)
{
if (ar.length == 3) {
if (this.qualifier == null) {
return false;
}
if (wildcard && ar[2].equals(Item.ANY))
{
if (wildcard && ar[2].equals(Item.ANY)) {
return true;
}
if (!this.qualifier.equals(ar[2]))
{
if (!this.qualifier.equals(ar[2])) {
return false;
}
}
return true;
}
public String toString()
{
public String toString() {
String s = "\tSchema: " + schema + " Element: " + element;
if (qualifier != null)
{
if (qualifier != null) {
s += " Qualifier: " + qualifier;
}
s += " Language: " + ((language == null) ? "[null]" : language);
@@ -151,8 +131,7 @@ class DtoMetadata
return s;
}
public String getValue()
{
public String getValue() {
return value;
}

View File

@@ -10,12 +10,11 @@ package org.dspace.app.itemupdate;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.FilenameFilter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.sql.SQLException;
@@ -23,16 +22,15 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerConfigurationException;
import org.apache.log4j.Logger;
import org.apache.logging.log4j.Logger;
import org.dspace.app.util.LocalSchemaFilenameFilter;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.DSpaceObject;
@@ -40,7 +38,6 @@ import org.dspace.content.Item;
import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.ItemService;
import org.dspace.core.Context;
import org.dspace.handle.factory.HandleServiceFactory;
import org.dspace.handle.service.HandleService;
import org.w3c.dom.Document;
@@ -48,10 +45,9 @@ import org.w3c.dom.Document;
/**
* Encapsulates the Item in the context of the DSpace Archive Format
*
*/
public class ItemArchive {
private static final Logger log = Logger.getLogger(ItemArchive.class);
private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(ItemArchive.class);
public static final String DUBLIN_CORE_XML = "dublin_core.xml";
@@ -71,13 +67,13 @@ public class ItemArchive {
protected ItemService itemService;
//constructors
protected ItemArchive()
{
protected ItemArchive() {
handleService = HandleServiceFactory.getInstance().getHandleService();
itemService = ContentServiceFactory.getInstance().getItemService();
}
/** factory method
/**
* factory method
*
* Minimal requirements for dublin_core.xml for this application
* is the presence of dc.identifier.uri
@@ -89,48 +85,38 @@ public class ItemArchive {
* if null, the default is the handle in the dc.identifier.uri field
* @return ItemArchive object
* @throws Exception if error
*
*/
public static ItemArchive create(Context context, File dir, String itemField)
throws Exception
{
throws Exception {
ItemArchive itarch = new ItemArchive();
itarch.dir = dir;
itarch.dirname = dir.getName();
InputStream is = null;
try
{
try {
is = new FileInputStream(new File(dir, DUBLIN_CORE_XML));
itarch.dtomList = MetadataUtilities.loadDublinCore(getDocumentBuilder(), is);
//The code to search for local schema files was copied from org.dspace.app.itemimport.ItemImportServiceImpl.java
//The code to search for local schema files was copied from org.dspace.app.itemimport
// .ItemImportServiceImpl.java
File file[] = dir.listFiles(new LocalSchemaFilenameFilter());
for (int i = 0; i < file.length; i++)
{
for (int i = 0; i < file.length; i++) {
is = new FileInputStream(file[i]);
itarch.dtomList.addAll(MetadataUtilities.loadDublinCore(getDocumentBuilder(), is));
}
}
finally
{
if (is != null)
{
} finally {
if (is != null) {
is.close();
}
}
ItemUpdate.pr("Loaded metadata with " + itarch.dtomList.size() + " fields");
if (itemField == null)
{
if (itemField == null) {
itarch.item = itarch.itemFromHandleInput(context); // sets the item instance var and seeds the undo list
}
else
{
} else {
itarch.item = itarch.itemFromMetadataField(context, itemField);
}
if (itarch.item == null)
{
if (itarch.item == null) {
throw new Exception("Item not instantiated: " + itarch.dirname);
}
@@ -140,10 +126,8 @@ public class ItemArchive {
}
protected static DocumentBuilder getDocumentBuilder()
throws ParserConfigurationException
{
if (builder == null)
{
throws ParserConfigurationException {
if (builder == null) {
builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
}
return builder;
@@ -151,14 +135,13 @@ public class ItemArchive {
/**
* Getter for Transformer
*
* @return Transformer
* @throws TransformerConfigurationException if config error
*/
protected Transformer getTransformer()
throws TransformerConfigurationException
{
if (transformer == null)
{
throws TransformerConfigurationException {
if (transformer == null) {
transformer = TransformerFactory.newInstance().newTransformer();
}
return transformer;
@@ -166,55 +149,55 @@ public class ItemArchive {
/**
* Getter for the DSpace item referenced in the archive
*
* @return DSpace item
*/
public Item getItem()
{
public Item getItem() {
return item;
}
/**
* Getter for directory in archive on disk
*
* @return directory in archive
*/
public File getDirectory()
{
public File getDirectory() {
return dir;
}
/**
* Getter for directory name in archive
*
* @return directory name in archive
*/
public String getDirectoryName()
{
public String getDirectoryName() {
return dirname;
}
/**
* Add metadata field to undo list
*
* @param dtom DtoMetadata (represents metadata field)
*/
public void addUndoMetadataField(DtoMetadata dtom)
{
public void addUndoMetadataField(DtoMetadata dtom) {
this.undoDtomList.add(dtom);
}
/**
* Getter for list of metadata fields
*
* @return list of metadata fields
*/
public List<DtoMetadata> getMetadataFields()
{
public List<DtoMetadata> getMetadataFields() {
return dtomList;
}
/**
* Add bitstream id to delete contents file
*
* @param bitstreamId bitstream ID
*/
public void addUndoDeleteContents(UUID bitstreamId)
{
public void addUndoDeleteContents(UUID bitstreamId) {
this.undoAddContents.add(bitstreamId);
}
@@ -224,16 +207,15 @@ public class ItemArchive {
* This is the default implementation
* that uses the dc.identifier.uri metadatafield
* that contains the item handle as its value
*
* @param context DSpace Context
* @throws SQLException if database error
* @throws Exception if error
*/
private Item itemFromHandleInput(Context context)
throws SQLException, Exception
{
throws SQLException, Exception {
DtoMetadata dtom = getMetadataField("dc.identifier.uri");
if (dtom == null)
{
if (dtom == null) {
throw new Exception("No dc.identier.uri field found for handle");
}
@@ -241,8 +223,7 @@ public class ItemArchive {
String uri = dtom.value;
if (!uri.startsWith(ItemUpdate.HANDLE_PREFIX))
{
if (!uri.startsWith(ItemUpdate.HANDLE_PREFIX)) {
throw new Exception("dc.identifier.uri for item " + uri
+ " does not begin with prefix: " + ItemUpdate.HANDLE_PREFIX);
}
@@ -250,12 +231,9 @@ public class ItemArchive {
String handle = uri.substring(ItemUpdate.HANDLE_PREFIX.length());
DSpaceObject dso = handleService.resolveToObject(context, handle);
if (dso instanceof Item)
{
if (dso instanceof Item) {
item = (Item) dso;
}
else
{
} else {
ItemUpdate.pr("Warning: item not instantiated");
throw new IllegalArgumentException("Item " + handle + " not instantiated.");
}
@@ -266,55 +244,50 @@ public class ItemArchive {
* Find and instantiate Item from the dublin_core.xml based
* on the specified itemField for the item identifier,
*
*
* @param context - the DSpace context
* @param itemField - the compound form of the metadata element <schema>.<element>.<qualifier>
* @throws SQLException if database error
* @throws Exception if error
*/
private Item itemFromMetadataField(Context context, String itemField)
throws SQLException, AuthorizeException, Exception
{
throws SQLException, AuthorizeException, Exception {
DtoMetadata dtom = getMetadataField(itemField);
Item item = null;
if (dtom == null)
{
if (dtom == null) {
throw new IllegalArgumentException("No field found for item identifier field: " + itemField);
}
ItemUpdate.prv("Metadata field to match for item: " + dtom.toString());
this.addUndoMetadataField(dtom); //seed the undo list with the identifier field
Iterator<Item> itr = itemService.findByMetadataField(context, dtom.schema, dtom.element, dtom.qualifier, dtom.value);
Iterator<Item> itr = itemService
.findByMetadataField(context, dtom.schema, dtom.element, dtom.qualifier, dtom.value);
int count = 0;
while (itr.hasNext())
{
while (itr.hasNext()) {
item = itr.next();
count++;
}
ItemUpdate.prv("items matching = " + count);
if (count != 1)
{
if (count != 1) {
throw new Exception("" + count + " items matching item identifier: " + dtom.value);
}
return item;
}
/**
* Get DtoMetadata field
*
* @param compoundForm compound form
* @return DtoMetadata field
*/
private DtoMetadata getMetadataField(String compoundForm)
{
for (DtoMetadata dtom : dtomList)
{
if (dtom.matches(compoundForm, false))
{
private DtoMetadata getMetadataField(String compoundForm) {
for (DtoMetadata dtom : dtomList) {
if (dtom.matches(compoundForm, false)) {
return dtom;
}
}
@@ -333,46 +306,35 @@ public class ItemArchive {
*/
public void writeUndo(File undoDir)
throws IOException, ParserConfigurationException, TransformerConfigurationException,
TransformerException, FileNotFoundException
{
TransformerException, FileNotFoundException {
// create directory for item
File dir = new File(undoDir, dirname);
if (!dir.exists() && !dir.mkdir())
{
if (!dir.exists() && !dir.mkdir()) {
log.error("Unable to create undo directory");
}
OutputStream out = null;
try
{
try {
out = new FileOutputStream(new File(dir, "dublin_core.xml"));
Document doc = MetadataUtilities.writeDublinCore(getDocumentBuilder(), undoDtomList);
MetadataUtilities.writeDocument(doc, getTransformer(), out);
// if undo has delete bitstream
if (undoAddContents.size() > 0)
{
if (undoAddContents.size() > 0) {
PrintWriter pw = null;
try
{
try {
File f = new File(dir, ItemUpdate.DELETE_CONTENTS_FILE);
pw = new PrintWriter(new BufferedWriter(new FileWriter(f)));
for (UUID i : undoAddContents)
{
for (UUID i : undoAddContents) {
pw.println(i);
}
}
finally
{
} finally {
pw.close();
}
}
}
finally
{
if (out != null)
{
} finally {
if (out != null) {
out.close();
}
}

View File

@@ -7,21 +7,38 @@
*/
package org.dspace.app.itemupdate;
import org.apache.commons.cli.*;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.PosixParser;
import org.dspace.content.Item;
import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.ItemService;
import org.dspace.core.ConfigurationManager;
import org.dspace.core.Context;
import org.dspace.eperson.EPerson;
import org.dspace.eperson.factory.EPersonServiceFactory;
import org.dspace.eperson.service.EPersonService;
import java.io.*;
import java.util.*;
import org.dspace.handle.factory.HandleServiceFactory;
import org.dspace.handle.service.HandleService;
/**
*
* Provides some batch editing capabilities for items in DSpace:
* Metadata fields - Add, Delete
* Bitstreams - Add, Delete
@@ -46,9 +63,7 @@ import java.util.*;
* Some of this has been placed into the MetadataUtilities class
* for possible reuse elsewhere.
*
*
* @author W. Hays based on a conceptual design by R. Rodgers
*
*/
public class ItemUpdate {
@@ -64,32 +79,29 @@ public class ItemUpdate {
protected static final EPersonService epersonService = EPersonServiceFactory.getInstance().getEPersonService();
protected static final ItemService itemService = ContentServiceFactory.getInstance().getItemService();
protected static final HandleService handleService = HandleServiceFactory.getInstance().getHandleService();
static
{
static {
filterAliases.put("ORIGINAL", "org.dspace.app.itemupdate.OriginalBitstreamFilter");
filterAliases.put("ORIGINAL_AND_DERIVATIVES", "org.dspace.app.itemupdate.OriginalWithDerivativesBitstreamFilter");
filterAliases
.put("ORIGINAL_AND_DERIVATIVES", "org.dspace.app.itemupdate.OriginalWithDerivativesBitstreamFilter");
filterAliases.put("TEXT", "org.dspace.app.itemupdate.DerivativeTextBitstreamFilter");
filterAliases.put("THUMBNAIL", "org.dspace.app.itemupdate.ThumbnailBitstreamFilter");
}
// File listing filter to check for folders
static FilenameFilter directoryFilter = new FilenameFilter()
{
static FilenameFilter directoryFilter = new FilenameFilter() {
@Override
public boolean accept(File dir, String n)
{
public boolean accept(File dir, String n) {
File f = new File(dir.getAbsolutePath() + File.separatorChar + n);
return f.isDirectory();
}
};
// File listing filter to check for files (not directories)
static FilenameFilter fileFilter = new FilenameFilter()
{
static FilenameFilter fileFilter = new FilenameFilter() {
@Override
public boolean accept(File dir, String n)
{
public boolean accept(File dir, String n) {
File f = new File(dir.getAbsolutePath() + File.separatorChar + n);
return (f.isFile());
}
@@ -101,11 +113,9 @@ public class ItemUpdate {
protected String eperson;
/**
*
* @param argv the command line arguments given
*/
public static void main(String[] argv)
{
public static void main(String[] argv) {
// create an options object and populate it
CommandLineParser parser = new PosixParser();
@@ -116,20 +126,23 @@ public class ItemUpdate {
options.addOption("s", "source", true, "root directory of source dspace archive ");
//actions on items
options.addOption("a", "addmetadata", true, "add metadata specified for each item; multiples separated by semicolon ';'");
options.addOption("a", "addmetadata", true,
"add metadata specified for each item; multiples separated by semicolon ';'");
options.addOption("d", "deletemetadata", true, "delete metadata specified for each item");
options.addOption("A", "addbitstreams", false, "add bitstreams as specified for each item");
// extra work to get optional argument
Option delBitstreamOption = new Option("D", "deletebitstreams", true, "delete bitstreams as specified for each item");
Option delBitstreamOption = new Option("D", "deletebitstreams", true,
"delete bitstreams as specified for each item");
delBitstreamOption.setOptionalArg(true);
delBitstreamOption.setArgName("BitstreamFilter");
options.addOption(delBitstreamOption);
//other params
options.addOption("e", "eperson", true, "email of eperson doing the update");
options.addOption("i", "itemfield", true, "optional metadata field that containing item identifier; default is dc.identifier.uri");
options.addOption("i", "itemfield", true,
"optional metadata field that containing item identifier; default is dc.identifier.uri");
options.addOption("F", "filter-properties", true, "filter class name; only for deleting bitstream");
options.addOption("v", "verbose", false, "verbose logging");
@@ -147,12 +160,10 @@ public class ItemUpdate {
Context context = null;
ItemUpdate iu = new ItemUpdate();
try
{
try {
CommandLine line = parser.parse(options, argv);
if (line.hasOption('h'))
{
if (line.hasOption('h')) {
HelpFormatter myhelp = new HelpFormatter();
myhelp.printHelp("ItemUpdate", options);
pr("");
@@ -166,91 +177,79 @@ public class ItemUpdate {
System.exit(0);
}
if (line.hasOption('v'))
{
if (line.hasOption('v')) {
verbose = true;
}
if (line.hasOption('P'))
{
if (line.hasOption('P')) {
alterProvenance = false;
pr("Suppressing changes to Provenance field option");
}
iu.eperson = line.getOptionValue('e'); // db ID or email
if (!line.hasOption('s')) // item specific changes from archive dir
{
if (!line.hasOption('s')) { // item specific changes from archive dir
pr("Missing source archive option");
System.exit(1);
}
String sourcedir = line.getOptionValue('s');
if (line.hasOption('t')) //test
{
if (line.hasOption('t')) { //test
isTest = true;
pr("**Test Run** - not actually updating items.");
}
if (line.hasOption('i'))
{
if (line.hasOption('i')) {
itemField = line.getOptionValue('i');
}
if (line.hasOption('d'))
{
if (line.hasOption('d')) {
String[] targetFields = line.getOptionValues('d');
DeleteMetadataAction delMetadataAction = (DeleteMetadataAction) iu.actionMgr.getUpdateAction(DeleteMetadataAction.class);
DeleteMetadataAction delMetadataAction = (DeleteMetadataAction) iu.actionMgr
.getUpdateAction(DeleteMetadataAction.class);
delMetadataAction.addTargetFields(targetFields);
//undo is an add
for (String field : targetFields)
{
for (String field : targetFields) {
iu.undoActionList.add(" -a " + field + " ");
}
pr("Delete metadata for fields: ");
for (String s : targetFields)
{
for (String s : targetFields) {
pr(" " + s);
}
}
if (line.hasOption('a'))
{
if (line.hasOption('a')) {
String[] targetFields = line.getOptionValues('a');
AddMetadataAction addMetadataAction = (AddMetadataAction) iu.actionMgr.getUpdateAction(AddMetadataAction.class);
AddMetadataAction addMetadataAction = (AddMetadataAction) iu.actionMgr
.getUpdateAction(AddMetadataAction.class);
addMetadataAction.addTargetFields(targetFields);
//undo is a delete followed by an add of a replace record for target fields
for (String field : targetFields)
{
for (String field : targetFields) {
iu.undoActionList.add(" -d " + field + " ");
}
for (String field : targetFields)
{
for (String field : targetFields) {
iu.undoActionList.add(" -a " + field + " ");
}
pr("Add metadata for fields: ");
for (String s : targetFields)
{
for (String s : targetFields) {
pr(" " + s);
}
}
if (line.hasOption('D')) // undo not supported
{
if (line.hasOption('D')) { // undo not supported
pr("Delete bitstreams ");
String[] filterNames = line.getOptionValues('D');
if ((filterNames != null) && (filterNames.length > 1))
{
if ((filterNames != null) && (filterNames.length > 1)) {
pr("Error: Only one filter can be a used at a time.");
System.exit(1);
}
@@ -258,84 +257,71 @@ public class ItemUpdate {
String filterName = line.getOptionValue('D');
pr("Filter argument: " + filterName);
if (filterName == null) // indicates using delete_contents files
{
DeleteBitstreamsAction delAction = (DeleteBitstreamsAction) iu.actionMgr.getUpdateAction(DeleteBitstreamsAction.class);
if (filterName == null) { // indicates using delete_contents files
DeleteBitstreamsAction delAction = (DeleteBitstreamsAction) iu.actionMgr
.getUpdateAction(DeleteBitstreamsAction.class);
delAction.setAlterProvenance(alterProvenance);
}
else
{
} else {
// check if param is on ALIAS list
String filterClassname = filterAliases.get(filterName);
if (filterClassname == null)
{
if (filterClassname == null) {
filterClassname = filterName;
}
BitstreamFilter filter = null;
try
{
try {
Class<?> cfilter = Class.forName(filterClassname);
pr("BitstreamFilter class to instantiate: " + cfilter.toString());
filter = (BitstreamFilter) cfilter.newInstance(); //unfortunate cast, an erasure consequence
}
catch(Exception e)
{
} catch (Exception e) {
pr("Error: Failure instantiating bitstream filter class: " + filterClassname);
System.exit(1);
}
String filterPropertiesName = line.getOptionValue('F');
if (filterPropertiesName != null) //not always required
{
try
{
if (filterPropertiesName != null) { //not always required
try {
// TODO try multiple relative locations, e.g. source dir
if (!filterPropertiesName.startsWith("/"))
{
if (!filterPropertiesName.startsWith("/")) {
filterPropertiesName = sourcedir + File.separator + filterPropertiesName;
}
filter.initProperties(filterPropertiesName);
}
catch(Exception e)
{
pr("Error: Failure finding properties file for bitstream filter class: " + filterPropertiesName);
} catch (Exception e) {
pr("Error: Failure finding properties file for bitstream filter class: " +
filterPropertiesName);
System.exit(1);
}
}
DeleteBitstreamsByFilterAction delAction =
(DeleteBitstreamsByFilterAction) iu.actionMgr.getUpdateAction(DeleteBitstreamsByFilterAction.class);
(DeleteBitstreamsByFilterAction) iu.actionMgr
.getUpdateAction(DeleteBitstreamsByFilterAction.class);
delAction.setAlterProvenance(alterProvenance);
delAction.setBitstreamFilter(filter);
//undo not supported
}
}
if (line.hasOption('A'))
{
if (line.hasOption('A')) {
pr("Add bitstreams ");
AddBitstreamsAction addAction = (AddBitstreamsAction) iu.actionMgr.getUpdateAction(AddBitstreamsAction.class);
AddBitstreamsAction addAction = (AddBitstreamsAction) iu.actionMgr
.getUpdateAction(AddBitstreamsAction.class);
addAction.setAlterProvenance(alterProvenance);
iu.undoActionList.add(" -D "); // delete_contents file will be written, no arg required
}
if (!iu.actionMgr.hasActions())
{
if (!iu.actionMgr.hasActions()) {
pr("Error - an action must be specified");
System.exit(1);
}
else
{
} else {
pr("Actions to be performed: ");
for (UpdateAction ua : iu.actionMgr)
{
for (UpdateAction ua : iu.actionMgr) {
pr(" " + ua.getClass().getName());
}
}
@@ -346,36 +332,25 @@ public class ItemUpdate {
iu.setEPerson(context, iu.eperson);
context.turnOffAuthorisationSystem();
HANDLE_PREFIX = ConfigurationManager.getProperty("handle.canonical.prefix");
if (HANDLE_PREFIX == null || HANDLE_PREFIX.length() == 0)
{
HANDLE_PREFIX = "http://hdl.handle.net/";
}
HANDLE_PREFIX = handleService.getCanonicalPrefix();
iu.processArchive(context, sourcedir, itemField, metadataIndexName, alterProvenance, isTest);
context.complete(); // complete all transactions
}
catch (Exception e)
{
if (context != null && context.isValid())
{
} catch (Exception e) {
if (context != null && context.isValid()) {
context.abort();
}
e.printStackTrace();
pr(e.toString());
status = 1;
}
finally {
} finally {
context.restoreAuthSystemState();
}
if (isTest)
{
if (isTest) {
pr("***End of Test Run***");
}
else
{
} else {
pr("End.");
}
@@ -395,13 +370,11 @@ public class ItemUpdate {
*/
protected void processArchive(Context context, String sourceDirPath, String itemField,
String metadataIndexName, boolean alterProvenance, boolean isTest)
throws Exception
{
throws Exception {
// open and process the source directory
File sourceDir = new File(sourceDirPath);
if ((sourceDir == null) || !sourceDir.exists() || !sourceDir.isDirectory())
{
if ((sourceDir == null) || !sourceDir.exists() || !sourceDir.isDirectory()) {
pr("Error, cannot open archive source directory " + sourceDirPath);
throw new Exception("error with archive source directory " + sourceDirPath);
}
@@ -412,89 +385,73 @@ public class ItemUpdate {
//Undo is suppressed to prevent undo of undo
boolean suppressUndo = false;
File fSuppressUndo = new File(sourceDir, SUPPRESS_UNDO_FILENAME);
if (fSuppressUndo.exists())
{
if (fSuppressUndo.exists()) {
suppressUndo = true;
}
File undoDir = null; //sibling directory of source archive
if (!suppressUndo && !isTest)
{
if (!suppressUndo && !isTest) {
undoDir = initUndoArchive(sourceDir);
}
int itemCount = 0;
int successItemCount = 0;
for (String dirname : dircontents)
{
for (String dirname : dircontents) {
itemCount++;
pr("");
pr("processing item " + dirname);
try
{
try {
ItemArchive itarch = ItemArchive.create(context, new File(sourceDir, dirname), itemField);
for (UpdateAction action : actionMgr)
{
for (UpdateAction action : actionMgr) {
pr("action: " + action.getClass().getName());
action.execute(context, itarch, isTest, suppressUndo);
if (!isTest && !suppressUndo)
{
if (!isTest && !suppressUndo) {
itarch.writeUndo(undoDir);
}
}
if (!isTest)
{
if (!isTest) {
Item item = itarch.getItem();
itemService.update(context, item); //need to update before commit
context.uncacheEntity(item);}
context.uncacheEntity(item);
}
ItemUpdate.pr("Item " + dirname + " completed");
successItemCount++;
}
catch(Exception e)
{
} catch (Exception e) {
pr("Exception processing item " + dirname + ": " + e.toString());
e.printStackTrace();
}
}
if (!suppressUndo && !isTest)
{
if (!suppressUndo && !isTest) {
StringBuilder sb = new StringBuilder("dsrun org.dspace.app.itemupdate.ItemUpdate ");
sb.append(" -e ").append(this.eperson);
sb.append(" -s ").append(undoDir);
if (itemField != null)
{
if (itemField != null) {
sb.append(" -i ").append(itemField);
}
if (!alterProvenance)
{
if (!alterProvenance) {
sb.append(" -P ");
}
if (isTest)
{
if (isTest) {
sb.append(" -t ");
}
for (String actionOption : undoActionList)
{
for (String actionOption : undoActionList) {
sb.append(actionOption);
}
PrintWriter pw = null;
try
{
try {
File cmdFile = new File(undoDir.getParent(), undoDir.getName() + "_command.sh");
pw = new PrintWriter(new BufferedWriter(new FileWriter(cmdFile)));
pw.println(sb.toString());
}
finally
{
} finally {
pw.close();
}
}
@@ -515,38 +472,33 @@ public class ItemUpdate {
* @throws IOException if IO error
*/
protected File initUndoArchive(File sourceDir)
throws FileNotFoundException, IOException
{
throws FileNotFoundException, IOException {
File parentDir = sourceDir.getCanonicalFile().getParentFile();
if (parentDir == null)
{
throw new FileNotFoundException("Parent directory of archive directory not found; unable to write UndoArchive; no processing performed");
if (parentDir == null) {
throw new FileNotFoundException(
"Parent directory of archive directory not found; unable to write UndoArchive; no processing " +
"performed");
}
String sourceDirName = sourceDir.getName();
int seqNo = 1;
File undoDir = new File(parentDir, "undo_" + sourceDirName + "_" + seqNo);
while (undoDir.exists())
{
while (undoDir.exists()) {
undoDir = new File(parentDir, "undo_" + sourceDirName + "_" + ++seqNo); //increment
}
// create root directory
if (!undoDir.mkdir())
{
if (!undoDir.mkdir()) {
pr("ERROR creating Undo Archive directory " + undoDir.getCanonicalPath());
throw new IOException("ERROR creating Undo Archive directory " + undoDir.getCanonicalPath());
}
//Undo is suppressed to prevent undo of undo
File fSuppressUndo = new File(undoDir, ItemUpdate.SUPPRESS_UNDO_FILENAME);
try
{
try {
fSuppressUndo.createNewFile();
}
catch(IOException e)
{
} catch (IOException e) {
pr("ERROR creating Suppress Undo File " + e.toString());
throw e;
}
@@ -557,33 +509,29 @@ public class ItemUpdate {
/**
* Set EPerson doing import
*
* @param context DSpace Context
* @param eperson EPerson obj
* @throws Exception if error
*/
protected void setEPerson(Context context, String eperson)
throws Exception
{
if (eperson == null)
{
throws Exception {
if (eperson == null) {
pr("Error - an eperson to do the importing must be specified");
pr(" (run with -h flag for details)");
throw new Exception("EPerson not specified."); }
throw new Exception("EPerson not specified.");
}
EPerson myEPerson = null;
if (eperson.indexOf('@') != -1)
{
if (eperson.indexOf('@') != -1) {
// @ sign, must be an email
myEPerson = epersonService.findByEmail(context, eperson);
}
else
{
} else {
myEPerson = epersonService.find(context, UUID.fromString(eperson));
}
if (myEPerson == null)
{
if (myEPerson == null) {
pr("Error, eperson cannot be found: " + eperson);
throw new Exception("Invalid EPerson");
}
@@ -598,19 +546,17 @@ public class ItemUpdate {
*
* @param s String
*/
static void pr(String s)
{
static void pr(String s) {
System.out.println(s);
}
/**
* print if verbose flag is set
*
* @param s String
*/
static void prv(String s)
{
if (verbose)
{
static void prv(String s) {
if (verbose) {
System.out.println(s);
}
}

View File

@@ -11,14 +11,13 @@ import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.InputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Result;
@@ -29,12 +28,17 @@ import javax.xml.transform.TransformerException;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.xpath.XPathAPI;
import org.dspace.content.*;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Item;
import org.dspace.content.MetadataField;
import org.dspace.content.MetadataSchema;
import org.dspace.content.MetadataSchemaEnum;
import org.dspace.content.MetadataValue;
import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.ItemService;
import org.dspace.core.ConfigurationManager;
import org.dspace.core.Context;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -43,9 +47,6 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import org.dspace.authorize.AuthorizeException;
import org.dspace.core.ConfigurationManager;
/**
* Miscellaneous methods for metadata handling that build on the API
@@ -53,37 +54,37 @@ import org.dspace.core.ConfigurationManager;
* in context in ItemUpdate.
*
* The XML methods were based on those in ItemImport
*
*
*/
public class MetadataUtilities {
protected static final ItemService itemService = ContentServiceFactory.getInstance().getItemService();
/**
*
* Default constructor
*/
private MetadataUtilities() { }
/**
* Working around Item API to delete a value-specific Metadatum
For a given element/qualifier/lang:
get all DCValues
clear (i.e. delete) all of these DCValues
* For a given element/qualifier/lang:
* get all DCValues
* clear (i.e. delete) all of these DCValues
* add them back, minus the one to actually delete
*
* @param context DSpace Context
* @param item Item Object
* @param dtom metadata field
* @param isLanguageStrict whether strict or not
* @throws SQLException if database error
* @return true if metadata field is found with matching value and was deleted
* @throws SQLException if database error
*/
public static boolean deleteMetadataByValue(Context context, Item item, DtoMetadata dtom, boolean isLanguageStrict) throws SQLException {
public static boolean deleteMetadataByValue(Context context, Item item, DtoMetadata dtom, boolean isLanguageStrict)
throws SQLException {
List<MetadataValue> ar = null;
if (isLanguageStrict)
{ // get all for given type
if (isLanguageStrict) { // get all for given type
ar = itemService.getMetadata(item, dtom.schema, dtom.element, dtom.qualifier, dtom.language);
}
else
{
} else {
ar = itemService.getMetadata(item, dtom.schema, dtom.element, dtom.qualifier, Item.ANY);
}
@@ -91,26 +92,18 @@ public class MetadataUtilities {
//build new set minus the one to delete
List<String> vals = new ArrayList<String>();
for (MetadataValue dcv : ar)
{
if (dcv.getValue().equals(dtom.value))
{
for (MetadataValue dcv : ar) {
if (dcv.getValue().equals(dtom.value)) {
found = true;
}
else
{
} else {
vals.add(dcv.getValue());
}
}
if (found) //remove all for given type ??synchronize this block??
{
if (isLanguageStrict)
{
if (found) { //remove all for given type ??synchronize this block??
if (isLanguageStrict) {
itemService.clearMetadata(context, item, dtom.schema, dtom.element, dtom.qualifier, dtom.language);
}
else
{
} else {
itemService.clearMetadata(context, item, dtom.schema, dtom.element, dtom.qualifier, Item.ANY);
}
@@ -136,46 +129,34 @@ public class MetadataUtilities {
List<MetadataValue> ar = null;
// get all values for given element/qualifier
if (isLanguageStrict) // get all for given element/qualifier
{
if (isLanguageStrict) { // get all for given element/qualifier
ar = itemService.getMetadata(item, dtom.schema, dtom.element, dtom.qualifier, dtom.language);
}
else
{
} else {
ar = itemService.getMetadata(item, dtom.schema, dtom.element, dtom.qualifier, Item.ANY);
}
if (ar.size() == 0)
{
if (ar.size() == 0) {
throw new IllegalArgumentException("Metadata to append to not found");
}
int idx = 0; //index of field to change
if (ar.size() > 1) //need to pick one, can't be sure it's the last one
{
if (ar.size() > 1) { //need to pick one, can't be sure it's the last one
// TODO maybe get highest id ?
}
//build new set minus the one to delete
List<String> vals = new ArrayList<String>();
for (int i=0; i < ar.size(); i++)
{
if (i == idx)
{
for (int i = 0; i < ar.size(); i++) {
if (i == idx) {
vals.add(ar.get(i).getValue() + textToAppend);
}
else
{
} else {
vals.add(ar.get(i).getValue());
}
}
if (isLanguageStrict)
{
if (isLanguageStrict) {
itemService.clearMetadata(context, item, dtom.schema, dtom.element, dtom.qualifier, dtom.language);
}
else
{
} else {
itemService.clearMetadata(context, item, dtom.schema, dtom.element, dtom.qualifier, Item.ANY);
}
@@ -198,8 +179,7 @@ public class MetadataUtilities {
*/
public static List<DtoMetadata> loadDublinCore(DocumentBuilder docBuilder, InputStream is)
throws SQLException, IOException, ParserConfigurationException,
SAXException, TransformerException, AuthorizeException
{
SAXException, TransformerException, AuthorizeException {
Document document = docBuilder.parse(is);
List<DtoMetadata> dtomList = new ArrayList<DtoMetadata>();
@@ -209,55 +189,43 @@ public class MetadataUtilities {
String schema = null;
NodeList metadata = XPathAPI.selectNodeList(document, "/dublin_core");
Node schemaAttr = metadata.item(0).getAttributes().getNamedItem("schema");
if (schemaAttr == null)
{
schema = MetadataSchema.DC_SCHEMA;
}
else
{
if (schemaAttr == null) {
schema = MetadataSchemaEnum.DC.getName();
} else {
schema = schemaAttr.getNodeValue();
}
// Get the nodes corresponding to formats
NodeList dcNodes = XPathAPI.selectNodeList(document, "/dublin_core/dcvalue");
for (int i = 0; i < dcNodes.getLength(); i++)
{
for (int i = 0; i < dcNodes.getLength(); i++) {
Node n = dcNodes.item(i);
String value = getStringValue(n).trim();
// compensate for empty value getting read as "null", which won't display
if (value == null)
{
if (value == null) {
value = "";
}
String element = getAttributeValue(n, "element");
if (element != null)
{
if (element != null) {
element = element.trim();
}
String qualifier = getAttributeValue(n, "qualifier");
if (qualifier != null)
{
if (qualifier != null) {
qualifier = qualifier.trim();
}
String language = getAttributeValue(n, "language");
if (language != null)
{
if (language != null) {
language = language.trim();
}
if ("none".equals(qualifier) || "".equals(qualifier))
{
if ("none".equals(qualifier) || "".equals(qualifier)) {
qualifier = null;
}
// a goofy default, but consistent with DSpace treatment elsewhere
if (language == null)
{
if (language == null) {
language = "en";
}
else if ("".equals(language))
{
} else if ("".equals(language)) {
language = ConfigurationManager.getProperty("default.language");
}
@@ -279,31 +247,23 @@ public class MetadataUtilities {
* @throws TransformerException if transformer error
*/
public static Document writeDublinCore(DocumentBuilder docBuilder, List<DtoMetadata> dtomList)
throws ParserConfigurationException, TransformerConfigurationException, TransformerException
{
throws ParserConfigurationException, TransformerConfigurationException, TransformerException {
Document doc = docBuilder.newDocument();
Element root = doc.createElement("dublin_core");
doc.appendChild(root);
for (DtoMetadata dtom : dtomList)
{
for (DtoMetadata dtom : dtomList) {
Element mel = doc.createElement("dcvalue");
mel.setAttribute("element", dtom.element);
if (dtom.qualifier == null)
{
if (dtom.qualifier == null) {
mel.setAttribute("qualifier", "none");
}
else
{
} else {
mel.setAttribute("qualifier", dtom.qualifier);
}
if (StringUtils.isEmpty(dtom.language))
{
if (StringUtils.isEmpty(dtom.language)) {
mel.setAttribute("language", "en");
}
else
{
} else {
mel.setAttribute("language", dtom.language);
}
mel.setTextContent(dtom.value);
@@ -315,6 +275,7 @@ public class MetadataUtilities {
/**
* write xml document to output stream
*
* @param doc XML Document
* @param transformer XML Transformer
* @param out OutputStream
@@ -322,32 +283,29 @@ public class MetadataUtilities {
* @throws TransformerException if Transformer error
*/
public static void writeDocument(Document doc, Transformer transformer, OutputStream out)
throws IOException, TransformerException
{
throws IOException, TransformerException {
Source src = new DOMSource(doc);
Result dest = new StreamResult(out);
transformer.transform(src, dest);
}
// XML utility methods
/**
* Lookup an attribute from a DOM node.
*
* @param n Node
* @param name name
* @return attribute value
*/
private static String getAttributeValue(Node n, String name)
{
private static String getAttributeValue(Node n, String name) {
NamedNodeMap nm = n.getAttributes();
for (int i = 0; i < nm.getLength(); i++)
{
for (int i = 0; i < nm.getLength(); i++) {
Node node = nm.item(i);
if (name.equals(node.getNodeName()))
{
if (name.equals(node.getNodeName())) {
return node.getNodeValue();
}
}
@@ -357,19 +315,17 @@ public class MetadataUtilities {
/**
* Return the String value of a Node.
*
* @param node node
* @return string value
*/
private static String getStringValue(Node node)
{
private static String getStringValue(Node node) {
String value = node.getNodeValue();
if (node.hasChildNodes())
{
if (node.hasChildNodes()) {
Node first = node.getFirstChild();
if (first.getNodeType() == Node.TEXT_NODE)
{
if (first.getNodeType() == Node.TEXT_NODE) {
return first.getNodeValue();
}
}
@@ -388,36 +344,27 @@ public class MetadataUtilities {
* @throws ParseException if parse error
*/
public static List<ContentsEntry> readContentsFile(File f)
throws FileNotFoundException, IOException, ParseException
{
throws FileNotFoundException, IOException, ParseException {
List<ContentsEntry> list = new ArrayList<ContentsEntry>();
BufferedReader in = null;
try
{
try {
in = new BufferedReader(new FileReader(f));
String line = null;
while ((line = in.readLine()) != null)
{
while ((line = in.readLine()) != null) {
line = line.trim();
if ("".equals(line))
{
if ("".equals(line)) {
continue;
}
ItemUpdate.pr("Contents entry: " + line);
list.add(ContentsEntry.parse(line));
}
}
finally
{
try
{
} finally {
try {
in.close();
}
catch(IOException e)
{
} catch (IOException e) {
//skip
}
}
@@ -426,43 +373,33 @@ public class MetadataUtilities {
}
/**
*
* @param f file
* @return list of lines as strings
* @throws FileNotFoundException if file doesn't exist
* @throws IOException if IO Error
*/
public static List<String> readDeleteContentsFile(File f)
throws FileNotFoundException, IOException
{
throws FileNotFoundException, IOException {
List<String> list = new ArrayList<>();
BufferedReader in = null;
try
{
try {
in = new BufferedReader(new FileReader(f));
String line = null;
while ((line = in.readLine()) != null)
{
while ((line = in.readLine()) != null) {
line = line.trim();
if ("".equals(line))
{
if ("".equals(line)) {
continue;
}
list.add(line);
}
}
finally
{
try
{
} finally {
try {
in.close();
}
catch(IOException e)
{
} catch (IOException e) {
//skip
}
}
@@ -476,29 +413,28 @@ public class MetadataUtilities {
* @param dcv MetadataValue
* @return string displaying elements of the Metadatum
*/
public static String getDCValueString(MetadataValue dcv)
{
public static String getDCValueString(MetadataValue dcv) {
MetadataField metadataField = dcv.getMetadataField();
MetadataSchema metadataSchema = metadataField.getMetadataSchema();
return "schema: " + metadataSchema.getName() + "; element: " + metadataField.getElement() + "; qualifier: " + metadataField.getQualifier() +
return "schema: " + metadataSchema.getName() + "; element: " + metadataField
.getElement() + "; qualifier: " + metadataField.getQualifier() +
"; language: " + dcv.getLanguage() + "; value: " + dcv.getValue();
}
/**
* Return compound form of a metadata field (i.e. schema.element.qualifier)
*
* @param schema schema
* @param element element
* @param qualifier qualifier
* @return a String representation of the two- or three-part form of a metadata element
* e.g. dc.identifier.uri
*/
public static String getCompoundForm(String schema, String element, String qualifier)
{
public static String getCompoundForm(String schema, String element, String qualifier) {
StringBuilder sb = new StringBuilder();
sb.append(schema).append(".").append(element);
if (qualifier != null)
{
if (qualifier != null) {
sb.append(".").append(qualifier);
}
return sb.toString();
@@ -511,20 +447,16 @@ public class MetadataUtilities {
* @param compoundForm compound form of metadata field
* @return String Array
* @throws ParseException if validity checks fail
*
*/
public static String[] parseCompoundForm(String compoundForm)
throws ParseException
{
throws ParseException {
String[] ar = compoundForm.split("\\s*\\.\\s*"); //trim ends
if ("".equals(ar[0]))
{
if ("".equals(ar[0])) {
throw new ParseException("schema is empty string: " + compoundForm, 0);
}
if ((ar.length < 2) || (ar.length > 3) || "".equals(ar[1]))
{
if ((ar.length < 2) || (ar.length > 3) || "".equals(ar[1])) {
throw new ParseException("element is malformed or empty string: " + compoundForm, 0);
}

View File

@@ -18,37 +18,29 @@ import org.dspace.content.Bundle;
* Also delete all derivative bitstreams, i.e.
* all bitstreams in the TEXT and THUMBNAIL bundles
*/
public class OriginalBitstreamFilter extends BitstreamFilterByBundleName
{
public OriginalBitstreamFilter()
{
public class OriginalBitstreamFilter extends BitstreamFilterByBundleName {
public OriginalBitstreamFilter() {
//empty
}
/**
* Tests bitstreams for containment in an ORIGINAL bundle
*
* @param bitstream Bitstream
* @return true if the bitstream is in the ORIGINAL bundle
*
* @throws BitstreamFilterException if filter error
*/
@Override
public boolean accept(Bitstream bitstream)
throws BitstreamFilterException
{
try
{
throws BitstreamFilterException {
try {
List<Bundle> bundles = bitstream.getBundles();
for (Bundle bundle : bundles)
{
if (bundle.getName().equals("ORIGINAL"))
{
for (Bundle bundle : bundles) {
if (bundle.getName().equals("ORIGINAL")) {
return true;
}
}
}
catch(SQLException e)
{
} catch (SQLException e) {
throw new BitstreamFilterException(e);
}
return false;

View File

@@ -18,12 +18,10 @@ import org.dspace.content.Bundle;
* Also delete all derivative bitstreams, i.e.
* all bitstreams in the TEXT and THUMBNAIL bundles
*/
public class OriginalWithDerivativesBitstreamFilter extends BitstreamFilter
{
public class OriginalWithDerivativesBitstreamFilter extends BitstreamFilter {
protected String[] bundlesToEmpty = {"ORIGINAL", "TEXT", "THUMBNAIL"};
public OriginalWithDerivativesBitstreamFilter()
{
public OriginalWithDerivativesBitstreamFilter() {
//empty
}
@@ -31,29 +29,22 @@ public class OriginalWithDerivativesBitstreamFilter extends BitstreamFilter
* Tests bitstream for membership in specified bundles (ORIGINAL, TEXT, THUMBNAIL)
*
* @param bitstream Bitstream
* @throws BitstreamFilterException if error
* @return true if bitstream is in specified bundles
* @throws BitstreamFilterException if error
*/
@Override
public boolean accept(Bitstream bitstream)
throws BitstreamFilterException
{
try
{
throws BitstreamFilterException {
try {
List<Bundle> bundles = bitstream.getBundles();
for (Bundle b : bundles)
{
for (String bn : bundlesToEmpty)
{
if (b.getName().equals(bn))
{
for (Bundle b : bundles) {
for (String bn : bundlesToEmpty) {
if (b.getName().equals(bn)) {
return true;
}
}
}
}
catch(SQLException e)
{
} catch (SQLException e) {
throw new BitstreamFilterException(e);
}
return false;

View File

@@ -11,12 +11,10 @@ import java.util.Properties;
/**
* Bitstream filter targetting the THUMBNAIL bundle
*
*/
public class ThumbnailBitstreamFilter extends BitstreamFilterByBundleName {
public ThumbnailBitstreamFilter()
{
public ThumbnailBitstreamFilter() {
props = new Properties();
props.setProperty("bundle", "THUMBNAIL");
}

View File

@@ -13,10 +13,8 @@ import org.dspace.core.Context;
/**
* Interface for actions to update an item
*
*/
public interface UpdateAction
{
public interface UpdateAction {
public ItemService itemService = ContentServiceFactory.getInstance().getItemService();

View File

@@ -13,8 +13,6 @@ import org.dspace.content.service.BundleService;
/**
* Base class for Bitstream actions
*
*
*/
public abstract class UpdateBitstreamsAction implements UpdateAction {
@@ -27,20 +25,18 @@ public abstract class UpdateBitstreamsAction implements UpdateAction {
/**
* Set variable to indicate that the dc.description.provenance field may
* be changed as a result of Bitstream changes by ItemUpdate
*
* @param alterProvenance whether to alter provenance
*/
public void setAlterProvenance(boolean alterProvenance)
{
public void setAlterProvenance(boolean alterProvenance) {
this.alterProvenance = alterProvenance;
}
/**
*
* @return boolean value to indicate whether the dc.description.provenance field may
* be changed as a result of Bitstream changes by ItemUpdate
*/
public boolean getAlterProvenance()
{
public boolean getAlterProvenance() {
return alterProvenance;
}

View File

@@ -17,8 +17,6 @@ import java.util.Set;
* on which to apply the action when the method execute is called.
*
* Implemented as a Set to avoid problems with duplicates
*
*
*/
public abstract class UpdateMetadataAction implements UpdateAction {
@@ -39,8 +37,7 @@ public abstract class UpdateMetadataAction implements UpdateAction {
* @param targetFields Set of target fields to update
*/
public void addTargetFields(Set<String> targetFields) {
for (String tf : targetFields)
{
for (String tf : targetFields) {
this.targetFields.add(tf);
}
@@ -48,11 +45,11 @@ public abstract class UpdateMetadataAction implements UpdateAction {
/**
* Add array of target fields to update
*
* @param targetFields array of target fields to update
*/
public void addTargetFields(String[] targetFields) {
for (String tf : targetFields)
{
for (String tf : targetFields) {
this.targetFields.add(tf);
}

View File

@@ -15,29 +15,29 @@ import java.io.Reader;
import java.io.StreamTokenizer;
import java.util.ArrayList;
import java.util.List;
import org.jdom.Document;
/**
*
* @author mwood
*/
public class CommandRunner
{
public class CommandRunner {
/**
* Default constructor
*/
private CommandRunner() { }
/**
*
* @param args the command line arguments given
* @throws IOException if IO error
* @throws FileNotFoundException if file doesn't exist
*/
public static void main(String[] args)
throws FileNotFoundException, IOException
{
if (args.length > 0)
{
throws FileNotFoundException, IOException {
if (args.length > 0) {
runManyCommands(args[0]);
}
else
{
} else {
runManyCommands("-");
}
// There is no sensible way to use the status returned by runManyCommands().
@@ -58,15 +58,11 @@ public class CommandRunner
* @throws FileNotFoundException if file doesn't exist
*/
static int runManyCommands(String script)
throws FileNotFoundException, IOException
{
throws FileNotFoundException, IOException {
Reader input;
if ("-".equals(script))
{
if ("-".equals(script)) {
input = new InputStreamReader(System.in);
}
else
{
} else {
input = new FileReader(script);
}
@@ -89,22 +85,16 @@ public class CommandRunner
int status = 0;
List<String> tokens = new ArrayList<String>();
Document commandConfigs = ScriptLauncher.getConfig();
while (StreamTokenizer.TT_EOF != tokenizer.nextToken())
{
if (StreamTokenizer.TT_EOL == tokenizer.ttype)
{
if (tokens.size() > 0)
{
while (StreamTokenizer.TT_EOF != tokenizer.nextToken()) {
if (StreamTokenizer.TT_EOL == tokenizer.ttype) {
if (tokens.size() > 0) {
status = ScriptLauncher.runOneCommand(commandConfigs, tokens.toArray(new String[tokens.size()]));
if (status > 0)
{
if (status > 0) {
break;
}
tokens.clear();
}
}
else
{
} else {
tokens.add(tokenizer.sval);
}
}

View File

@@ -12,6 +12,15 @@ import java.io.IOException;
import java.lang.reflect.Method;
import java.util.List;
import java.util.TreeMap;
import org.apache.commons.cli.ParseException;
import org.apache.log4j.Logger;
import org.dspace.scripts.DSpaceRunnable;
import org.dspace.scripts.configuration.ScriptConfiguration;
import org.dspace.scripts.factory.ScriptServiceFactory;
import org.dspace.scripts.handler.DSpaceRunnableHandler;
import org.dspace.scripts.handler.impl.CommandLineDSpaceRunnableHandler;
import org.dspace.scripts.service.ScriptService;
import org.dspace.servicemanager.DSpaceKernelImpl;
import org.dspace.servicemanager.DSpaceKernelInit;
import org.dspace.services.RequestService;
@@ -25,11 +34,21 @@ import org.jdom.input.SAXBuilder;
* @author Stuart Lewis
* @author Mark Diggory
*/
public class ScriptLauncher
{
/** The service manager kernel */
public class ScriptLauncher {
private static final Logger log = Logger.getLogger(ScriptLauncher.class);
/**
* The service manager kernel
*/
private static transient DSpaceKernelImpl kernelImpl;
/**
* Default constructor
*/
private ScriptLauncher() {
}
/**
* Execute the DSpace script launcher
*
@@ -38,25 +57,18 @@ public class ScriptLauncher
* @throws FileNotFoundException if file doesn't exist
*/
public static void main(String[] args)
throws FileNotFoundException, IOException
{
throws FileNotFoundException, IOException, IllegalAccessException, InstantiationException {
// Initialise the service manager kernel
try
{
try {
kernelImpl = DSpaceKernelInit.getKernel(null);
if (!kernelImpl.isRunning())
{
if (!kernelImpl.isRunning()) {
kernelImpl.start();
}
} catch (Exception e)
{
} catch (Exception e) {
// Failed to start so destroy it and log and throw an exception
try
{
try {
kernelImpl.destroy();
}
catch (Exception e1)
{
} catch (Exception e1) {
// Nothing to do
}
String message = "Failure during kernel init: " + e.getMessage();
@@ -69,50 +81,98 @@ public class ScriptLauncher
Document commandConfigs = getConfig();
// Check that there is at least one argument (if not display command options)
if (args.length < 1)
{
if (args.length < 1) {
System.err.println("You must provide at least one command argument");
display(commandConfigs);
System.exit(1);
}
// Look up command in the configuration, and execute.
int status;
status = runOneCommand(commandConfigs, args);
CommandLineDSpaceRunnableHandler commandLineDSpaceRunnableHandler = new CommandLineDSpaceRunnableHandler();
int status = handleScript(args, commandConfigs, commandLineDSpaceRunnableHandler, kernelImpl);
// Destroy the service kernel if it is still alive
if (kernelImpl != null)
{
if (kernelImpl != null) {
kernelImpl.destroy();
kernelImpl = null;
}
System.exit(status);
}
/**
* This method will take the arguments from a commandline input and it'll find the script that the first argument
* refers to and it'll execute this script.
* It can return a 1 or a 0 depending on whether the script failed or passed respectively
* @param args The arguments for the script and the script as first one in the array
* @param commandConfigs The Document
* @param dSpaceRunnableHandler The DSpaceRunnableHandler for this execution
* @param kernelImpl The relevant DSpaceKernelImpl
* @return A 1 or 0 depending on whether the script failed or passed respectively
*/
public static int handleScript(String[] args, Document commandConfigs,
DSpaceRunnableHandler dSpaceRunnableHandler,
DSpaceKernelImpl kernelImpl) throws InstantiationException, IllegalAccessException {
int status;
ScriptService scriptService = ScriptServiceFactory.getInstance().getScriptService();
ScriptConfiguration scriptConfiguration = scriptService.getScriptConfiguration(args[0]);
DSpaceRunnable script = null;
if (scriptConfiguration != null) {
script = scriptService.createDSpaceRunnableForScriptConfiguration(scriptConfiguration);
}
if (script != null) {
status = executeScript(args, dSpaceRunnableHandler, script);
} else {
status = runOneCommand(commandConfigs, args, kernelImpl);
}
return status;
}
/**
* This method will simply execute the script
* @param args The arguments of the script with the script name as first place in the array
* @param dSpaceRunnableHandler The relevant DSpaceRunnableHandler
* @param script The script to be executed
* @return A 1 or 0 depending on whether the script failed or passed respectively
*/
private static int executeScript(String[] args, DSpaceRunnableHandler dSpaceRunnableHandler,
DSpaceRunnable script) {
try {
script.initialize(args, dSpaceRunnableHandler, null);
script.run();
return 0;
} catch (ParseException e) {
script.printHelp();
e.printStackTrace();
return 1;
}
}
protected static int runOneCommand(Document commandConfigs, String[] args) {
return runOneCommand(commandConfigs, args, kernelImpl);
}
/**
* Recognize and execute a single command.
*
* @param doc Document
* @param commandConfigs Document
* @param args the command line arguments given
*/
static int runOneCommand(Document commandConfigs, String[] args)
{
protected static int runOneCommand(Document commandConfigs, String[] args, DSpaceKernelImpl kernelImpl) {
String request = args[0];
Element root = commandConfigs.getRootElement();
List<Element> commands = root.getChildren("command");
Element command = null;
for (Element candidate : commands)
{
if (request.equalsIgnoreCase(candidate.getChild("name").getValue()))
{
for (Element candidate : commands) {
if (request.equalsIgnoreCase(candidate.getChild("name").getValue())) {
command = candidate;
break;
}
}
if (null == command)
{
if (null == command) {
// The command wasn't found
System.err.println("Command not found: " + args[0]);
display(commandConfigs);
@@ -121,33 +181,26 @@ public class ScriptLauncher
// Run each step
List<Element> steps = command.getChildren("step");
for (Element step : steps)
{
for (Element step : steps) {
// Instantiate the class
Class target = null;
// Is it the special case 'dsrun' where the user provides the class name?
String className;
if ("dsrun".equals(request))
{
if (args.length < 2)
{
if ("dsrun".equals(request)) {
if (args.length < 2) {
System.err.println("Error in launcher.xml: Missing class name");
return 1;
}
className = args[1];
}
else {
} else {
className = step.getChild("class").getValue();
}
try
{
try {
target = Class.forName(className,
true,
Thread.currentThread().getContextClassLoader());
}
catch (ClassNotFoundException e)
{
} catch (ClassNotFoundException e) {
System.err.println("Error in launcher.xml: Invalid class name: " + className);
return 1;
}
@@ -158,26 +211,20 @@ public class ScriptLauncher
Class[] argTypes = {useargs.getClass()};
boolean passargs = true;
if ((step.getAttribute("passuserargs") != null) &&
("false".equalsIgnoreCase(step.getAttribute("passuserargs").getValue())))
{
("false".equalsIgnoreCase(step.getAttribute("passuserargs").getValue()))) {
passargs = false;
}
if ((args.length == 1) || (("dsrun".equals(request)) && (args.length == 2)) || (!passargs))
{
if ((args.length == 1) || (("dsrun".equals(request)) && (args.length == 2)) || (!passargs)) {
useargs = new String[0];
}
else
{
} else {
// The number of arguments to ignore
// If dsrun is the command, ignore the next, as it is the class name not an arg
int x = 1;
if ("dsrun".equals(request))
{
if ("dsrun".equals(request)) {
x = 2;
}
String[] argsnew = new String[useargs.length - x];
for (int i = x; i < useargs.length; i++)
{
for (int i = x; i < useargs.length; i++) {
argsnew[i - x] = useargs[i];
}
useargs = argsnew;
@@ -185,16 +232,13 @@ public class ScriptLauncher
// Add any extra properties
List<Element> bits = step.getChildren("argument");
if (step.getChild("argument") != null)
{
if (step.getChild("argument") != null) {
String[] argsnew = new String[useargs.length + bits.size()];
int i = 0;
for (Element arg : bits)
{
for (Element arg : bits) {
argsnew[i++] = arg.getValue();
}
for (; i < bits.size() + useargs.length; i++)
{
for (; i < bits.size() + useargs.length; i++) {
argsnew[i] = useargs[i - bits.size()];
}
useargs = argsnew;
@@ -203,8 +247,7 @@ public class ScriptLauncher
// Establish the request service startup
RequestService requestService = kernelImpl.getServiceManager().getServiceByName(
RequestService.class.getName(), RequestService.class);
if (requestService == null)
{
if (requestService == null) {
throw new IllegalStateException(
"Could not get the DSpace RequestService to start the request transaction");
}
@@ -214,8 +257,7 @@ public class ScriptLauncher
requestService.startRequest();
// Run the main() method
try
{
try {
Object[] arguments = {useargs};
// Useful for debugging, so left in the code...
@@ -231,9 +273,7 @@ public class ScriptLauncher
// ensure we close out the request (happy request)
requestService.endRequest(null);
}
catch (Exception e)
{
} catch (Exception e) {
// Failure occurred in the request so we destroy it
requestService.endRequest(e);
@@ -254,20 +294,20 @@ public class ScriptLauncher
*
* @return The XML configuration file Document
*/
protected static Document getConfig()
{
protected static Document getConfig() {
return getConfig(kernelImpl);
}
public static Document getConfig(DSpaceKernelImpl kernelImpl) {
// Load the launcher configuration file
String config = kernelImpl.getConfigurationService().getProperty("dspace.dir") +
System.getProperty("file.separator") + "config" +
System.getProperty("file.separator") + "launcher.xml";
SAXBuilder saxBuilder = new SAXBuilder();
Document doc = null;
try
{
try {
doc = saxBuilder.build(config);
}
catch (Exception e)
{
} catch (Exception e) {
System.err.println("Unable to load the launcher configuration file: [dspace]/config/launcher.xml");
System.err.println(e.getMessage());
e.printStackTrace();
@@ -278,10 +318,10 @@ public class ScriptLauncher
/**
* Display the commands that the current launcher config file knows about
*
* @param commandConfigs configs as Document
*/
private static void display(Document commandConfigs)
{
private static void display(Document commandConfigs) {
// List all command elements
List<Element> commands = commandConfigs.getRootElement().getChildren("command");
@@ -289,15 +329,13 @@ public class ScriptLauncher
// We cannot just use commands.sort() because it tries to remove and
// reinsert Elements within other Elements, and that doesn't work.
TreeMap<String, Element> sortedCommands = new TreeMap<>();
for (Element command : commands)
{
for (Element command : commands) {
sortedCommands.put(command.getChild("name").getValue(), command);
}
// Display the sorted list
System.out.println("Usage: dspace [command-name] {parameters}");
for (Element command : sortedCommands.values())
{
for (Element command : sortedCommands.values()) {
System.out.println(" - " + command.getChild("name").getValue() +
": " + command.getChild("description").getValue());
}

View File

@@ -7,12 +7,12 @@
*/
package org.dspace.app.mediafilter;
import java.awt.image.BufferedImage;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
/**
* Class to attach a footer to an image using ImageMagick.
@@ -20,8 +20,7 @@ import java.awt.Rectangle;
* This version of the code is basically Ninh's but reorganised a little. Used with permission.
*/
public class Brand
{
public class Brand {
private int brandWidth;
private int brandHeight;
private Font font;
@@ -34,13 +33,11 @@ public class Brand
* @param brandHeight height of the footer in pixels
* @param font font to use for text on the footer
* @param xOffset number of pixels text should be indented from left-hand side of footer
*
*/
public Brand(int brandWidth,
int brandHeight,
Font font,
int xOffset)
{
int xOffset) {
this.brandWidth = brandWidth;
this.brandHeight = brandHeight;
this.font = font;
@@ -55,46 +52,34 @@ public class Brand
* the image is resized such that brandLeftText will not fit. <code>null</code> if not
* required
* @param brandRightText text that should appear in the bottom right of the image
*
* @return BufferedImage a BufferedImage object describing the brand image file
*/
public BufferedImage create(String brandLeftText,
String shortLeftText,
String brandRightText)
{
String brandRightText) {
BrandText[] allBrandText = null;
BufferedImage brandImage =
new BufferedImage(brandWidth, brandHeight, BufferedImage.TYPE_INT_RGB);
if (brandWidth >= 350)
{
allBrandText = new BrandText[]
{
if (brandWidth >= 350) {
allBrandText = new BrandText[] {
new BrandText(BrandText.BL, brandLeftText),
new BrandText(BrandText.BR, brandRightText)
};
}
else if (brandWidth >= 190)
{
allBrandText = new BrandText[]
{
} else if (brandWidth >= 190) {
allBrandText = new BrandText[] {
new BrandText(BrandText.BL, shortLeftText),
new BrandText(BrandText.BR, brandRightText)
};
}
else
{
allBrandText = new BrandText[]
{
} else {
allBrandText = new BrandText[] {
new BrandText(BrandText.BR, brandRightText)
};
}
if (allBrandText != null && allBrandText.length > 0)
{
for (int i = 0; i < allBrandText.length; ++i)
{
if (allBrandText != null && allBrandText.length > 0) {
for (int i = 0; i < allBrandText.length; ++i) {
drawImage(brandImage, allBrandText[i]);
}
}
@@ -111,48 +96,37 @@ public class Brand
* position within the brand
*/
private void drawImage(BufferedImage brandImage,
BrandText brandText)
{
BrandText brandText) {
int imgWidth = brandImage.getWidth();
int imgHeight = brandImage.getHeight();
int bx, by, tx, ty, bWidth, bHeight;
Graphics2D g2 = brandImage.createGraphics();
g2.setFont(font);
FontMetrics fm = g2.getFontMetrics();
int bWidth = fm.stringWidth(brandText.getText()) + xOffset * 2 + 1;
int bHeight = fm.getHeight();
bWidth = fm.stringWidth(brandText.getText()) + xOffset * 2 + 1;
bHeight = fm.getHeight();
int bx = 0;
int by = 0;
if (brandText.getLocation().equals(BrandText.TL)) {
bx = 0;
by = 0;
if (brandText.getLocation().equals(BrandText.TL))
{
bx = 0;
by = 0;
}
else if (brandText.getLocation().equals(BrandText.TR))
{
} else if (brandText.getLocation().equals(BrandText.TR)) {
bx = imgWidth - bWidth;
by = 0;
}
else if (brandText.getLocation().equals(BrandText.BL))
{
} else if (brandText.getLocation().equals(BrandText.BL)) {
bx = 0;
by = imgHeight - bHeight;
}
else if (brandText.getLocation().equals(BrandText.BR))
{
} else if (brandText.getLocation().equals(BrandText.BR)) {
bx = imgWidth - bWidth;
by = imgHeight - bHeight;
}
Rectangle box = new Rectangle(bx, by, bWidth, bHeight);
tx = bx + xOffset;
ty = by + fm.getAscent();
int tx = bx + xOffset;
int ty = by + fm.getAscent();
g2.setColor(Color.black);
g2.fill(box);

View File

@@ -13,15 +13,22 @@ package org.dspace.app.mediafilter;
* This is a copy of Picture Australia's PiObj class re-organised with methods.
* Thanks to Ninh Nguyen at the National Library for providing the original source.
*/
class BrandText
{
/** Bottom Left */
class BrandText {
/**
* Bottom Left
*/
public static final String BL = "bl";
/** Bottom Right */
/**
* Bottom Right
*/
public static final String BR = "br";
/** Top Left */
/**
* Top Left
*/
public static final String TL = "tl";
/** Top Right */
/**
* Top Right
*/
public static final String TR = "tr";
private String location;
@@ -34,8 +41,7 @@ class BrandText
* @param location one of the class location constants e.g. <code>Identifier.BL</code>
* @param the text associated with the location
*/
public BrandText(String location, String text)
{
public BrandText(String location, String text) {
this.location = location;
this.text = text;
}
@@ -45,8 +51,7 @@ class BrandText
*
* @return String one the class location constants e.g. <code>Identifier.BL</code>
*/
public String getLocation()
{
public String getLocation() {
return location;
}
@@ -56,8 +61,7 @@ class BrandText
*
* @return String the text associated with the Identifier object
*/
public String getText()
{
public String getText() {
return text;
}
@@ -67,8 +71,7 @@ class BrandText
*
* @param location one of the class location constants
*/
public void setLocation(String location)
{
public void setLocation(String location) {
this.location = location;
}
@@ -78,8 +81,7 @@ class BrandText
*
* @param text any text string (typically a branding or identifier)
*/
public void setText(String text)
{
public void setText(String text) {
this.text = text;
}
}

View File

@@ -7,16 +7,13 @@
*/
package org.dspace.app.mediafilter;
import java.awt.image.*;
import java.awt.image.BufferedImage;
import java.io.InputStream;
import javax.imageio.ImageIO;
import org.dspace.content.Item;
import org.dspace.core.ConfigurationManager;
import org.dspace.app.mediafilter.JPEGFilter;
/**
* Filter image bitstreams, scaling the image to be within the bounds of
* thumbnail.maxwidth, thumbnail.maxheight, the size we want our thumbnail to be
@@ -24,21 +21,17 @@ import org.dspace.app.mediafilter.JPEGFilter;
*
* @author Jason Sherman jsherman@usao.edu
*/
public class BrandedPreviewJPEGFilter extends MediaFilter
{
public class BrandedPreviewJPEGFilter extends MediaFilter {
@Override
public String getFilteredName(String oldFilename)
{
public String getFilteredName(String oldFilename) {
return oldFilename + ".preview.jpg";
}
/**
* @return String bundle name
*
*/
@Override
public String getBundleName()
{
public String getBundleName() {
return "BRANDED_PREVIEW";
}
@@ -46,8 +39,7 @@ public class BrandedPreviewJPEGFilter extends MediaFilter
* @return String bitstreamformat
*/
@Override
public String getFormatString()
{
public String getFormatString() {
return "JPEG";
}
@@ -55,25 +47,21 @@ public class BrandedPreviewJPEGFilter extends MediaFilter
* @return String description
*/
@Override
public String getDescription()
{
public String getDescription() {
return "Generated Branded Preview";
}
/**
* @param currentItem item
* @param source
* source input stream
* @param source source input stream
* @param verbose verbose mode
*
* @return InputStream the resulting input stream
* @throws Exception if error
*/
@Override
public InputStream getDestinationStream(Item currentItem, InputStream source, boolean verbose)
throws Exception
{
throws Exception {
// read in bitstream's image
BufferedImage buf = ImageIO.read(source);
@@ -91,6 +79,8 @@ public class BrandedPreviewJPEGFilter extends MediaFilter
int brandFontPoint = ConfigurationManager.getIntProperty("webui.preview.brand.fontpoint");
JPEGFilter jpegFilter = new JPEGFilter();
return jpegFilter.getThumbDim(currentItem, buf, verbose, xmax, ymax, blurring, hqscaling, brandHeight, brandFontPoint, brandFont);
return jpegFilter
.getThumbDim(currentItem, buf, verbose, xmax, ymax, blurring, hqscaling, brandHeight, brandFontPoint,
brandFont);
}
}

View File

@@ -11,12 +11,11 @@ import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.Logger;
import org.apache.poi.POITextExtractor;
import org.apache.poi.extractor.ExtractorFactory;
import org.apache.poi.hssf.extractor.ExcelExtractor;
import org.apache.poi.xssf.extractor.XSSFExcelExtractor;
import org.apache.log4j.Logger;
import org.dspace.content.Item;
/*
@@ -35,40 +34,32 @@ import org.dspace.content.Item;
* filter.org.dspace.app.mediafilter.ExcelFilter.inputFormats = Microsoft Excel, Microsoft Excel XML
*
*/
public class ExcelFilter extends MediaFilter
{
public class ExcelFilter extends MediaFilter {
private static Logger log = Logger.getLogger(ExcelFilter.class);
private static Logger log = org.apache.logging.log4j.LogManager.getLogger(ExcelFilter.class);
public String getFilteredName(String oldFilename)
{
public String getFilteredName(String oldFilename) {
return oldFilename + ".txt";
}
/**
* @return String bundle name
*
*/
public String getBundleName()
{
public String getBundleName() {
return "TEXT";
}
/**
* @return String bitstream format
*
*
*/
public String getFormatString()
{
public String getFormatString() {
return "Text";
}
/**
* @return String description
*/
public String getDescription()
{
public String getDescription() {
return "Extracted text";
}
@@ -76,38 +67,29 @@ public class ExcelFilter extends MediaFilter
* @param item item
* @param source source input stream
* @param verbose verbose mode
*
* @return InputStream the resulting input stream
* @throws Exception if error
*/
@Override
public InputStream getDestinationStream(Item item, InputStream source, boolean verbose)
throws Exception
{
throws Exception {
String extractedText = null;
try
{
try {
POITextExtractor theExtractor = ExtractorFactory.createExtractor(source);
if (theExtractor instanceof ExcelExtractor)
{
if (theExtractor instanceof ExcelExtractor) {
// for xls file
extractedText = (theExtractor).getText();
}
else if (theExtractor instanceof XSSFExcelExtractor)
{
} else if (theExtractor instanceof XSSFExcelExtractor) {
// for xlsx file
extractedText = (theExtractor).getText();
}
}
catch (Exception e)
{
} catch (Exception e) {
log.error("Error filtering bitstream: " + e.getMessage(), e);
throw e;
}
if (extractedText != null)
{
if (extractedText != null) {
// generate an input stream with the extracted text
return IOUtils.toInputStream(extractedText, StandardCharsets.UTF_8);
}

View File

@@ -18,13 +18,11 @@ import org.dspace.core.Context;
* from one format to another. This interface should be implemented by any class
* which defines a "filter" to be run by the MediaFilterManager.
*/
public interface FormatFilter
{
public interface FormatFilter {
/**
* Get a filename for a newly created filtered bitstream
*
* @param sourceName
* name of source bitstream
* @param sourceName name of source bitstream
* @return filename generated by the filter - for example, document.pdf
* becomes document.pdf.txt
*/
@@ -53,10 +51,8 @@ public interface FormatFilter
* Read the source stream and produce the filtered content.
*
* @param item Item
* @param source
* input stream
* @param source input stream
* @param verbose verbosity flag
*
* @return result of filter's transformation as a byte stream.
* @throws Exception if error
*/
@@ -71,12 +67,10 @@ public interface FormatFilter
* is necessary). Return false if bitstream should be skipped
* for any reason.
*
*
* @param c context
* @param item item containing bitstream to process
* @param source source bitstream to be processed
* @param verbose verbose mode
*
* @return true if bitstream processing should continue,
* false if this bitstream should be skipped
* @throws Exception if error
@@ -92,13 +86,9 @@ public interface FormatFilter
* is necessary). Return false if bitstream should be skipped
* for some reason.
*
*
* @param c
* context
* @param item
* item containing bitstream to process
* @param generatedBitstream
* the bitstream which was generated by
* @param c context
* @param item item containing bitstream to process
* @param generatedBitstream the bitstream which was generated by
* this filter.
* @throws Exception if error
*/

View File

@@ -7,36 +7,31 @@
*/
package org.dspace.app.mediafilter;
import org.dspace.content.Item;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import javax.swing.text.Document;
import javax.swing.text.html.HTMLEditorKit;
import org.dspace.content.Item;
/*
*
* to do: helpful error messages - can't find mediafilter.cfg - can't
* instantiate filter - bitstream format doesn't exist
*
*/
public class HTMLFilter extends MediaFilter
{
public class HTMLFilter extends MediaFilter {
@Override
public String getFilteredName(String oldFilename)
{
public String getFilteredName(String oldFilename) {
return oldFilename + ".txt";
}
/**
* @return String bundle name
*
*/
@Override
public String getBundleName()
{
public String getBundleName() {
return "TEXT";
}
@@ -44,8 +39,7 @@ public class HTMLFilter extends MediaFilter
* @return String bitstreamformat
*/
@Override
public String getFormatString()
{
public String getFormatString() {
return "Text";
}
@@ -53,8 +47,7 @@ public class HTMLFilter extends MediaFilter
* @return String description
*/
@Override
public String getDescription()
{
public String getDescription() {
return "Extracted text";
}
@@ -62,14 +55,12 @@ public class HTMLFilter extends MediaFilter
* @param currentItem item
* @param source source input stream
* @param verbose verbose mode
*
* @return InputStream the resulting input stream
* @throws Exception if error
*/
@Override
public InputStream getDestinationStream(Item currentItem, InputStream source, boolean verbose)
throws Exception
{
throws Exception {
// try and read the document - set to ignore character set directive,
// assuming that the input stream is already set properly (I hope)
HTMLEditorKit kit = new HTMLEditorKit();

View File

@@ -7,48 +7,41 @@
*/
package org.dspace.app.mediafilter;
import org.dspace.content.Item;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.nio.file.Files;
import org.dspace.content.Item;
/**
* Filter image bitstreams, scaling the image to be within the bounds of
* thumbnail.maxwidth, thumbnail.maxheight, the size we want our thumbnail to be
* no bigger than. Creates only JPEGs.
*/
public class ImageMagickImageThumbnailFilter extends ImageMagickThumbnailFilter
{
public class ImageMagickImageThumbnailFilter extends ImageMagickThumbnailFilter {
/**
* @param currentItem item
* @param source source input stream
* @param verbose verbose mode
*
* @return InputStream the resulting input stream
* @throws Exception if error
*/
@Override
public InputStream getDestinationStream(Item currentItem, InputStream source, boolean verbose)
throws Exception
{
throws Exception {
File f = inputStreamToTempFile(source, "imthumb", ".tmp");
File f2 = null;
try
{
try {
f2 = getThumbnailFile(f, verbose);
byte[] bytes = Files.readAllBytes(f2.toPath());
return new ByteArrayInputStream(bytes);
}
finally
{
} finally {
//noinspection ResultOfMethodCallIgnored
f.delete();
if (f2 != null)
{
if (f2 != null) {
//noinspection ResultOfMethodCallIgnored
f2.delete();
}

View File

@@ -7,39 +7,33 @@
*/
package org.dspace.app.mediafilter;
import org.dspace.content.Item;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.nio.file.Files;
import org.dspace.content.Item;
public class ImageMagickPdfThumbnailFilter extends ImageMagickThumbnailFilter {
@Override
public InputStream getDestinationStream(Item currentItem, InputStream source, boolean verbose)
throws Exception
{
throws Exception {
File f = inputStreamToTempFile(source, "impdfthumb", ".pdf");
File f2 = null;
File f3 = null;
try
{
try {
f2 = getImageFile(f, 0, verbose);
f3 = getThumbnailFile(f2, verbose);
byte[] bytes = Files.readAllBytes(f3.toPath());
return new ByteArrayInputStream(bytes);
}
finally
{
} finally {
//noinspection ResultOfMethodCallIgnored
f.delete();
if (f2 != null)
{
if (f2 != null) {
//noinspection ResultOfMethodCallIgnored
f2.delete();
}
if (f3 != null)
{
if (f3 != null) {
//noinspection ResultOfMethodCallIgnored
f3.delete();
}

View File

@@ -14,22 +14,19 @@ import java.io.InputStream;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import javax.imageio.ImageIO;
import org.dspace.content.Bitstream;
import org.dspace.content.Bundle;
import org.dspace.content.Item;
import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.ItemService;
import org.dspace.core.ConfigurationManager;
import org.dspace.core.Context;
import org.im4java.core.ConvertCmd;
import org.im4java.core.Info;
import org.im4java.core.IM4JavaException;
import org.im4java.core.IMOperation;
import org.im4java.core.Info;
import org.im4java.process.ProcessStarter;
import org.dspace.core.ConfigurationManager;
/**
* Filter image bitstreams, scaling the image to be within the bounds of
* thumbnail.maxwidth, thumbnail.maxheight, the size we want our thumbnail to be
@@ -78,7 +75,6 @@ public abstract class ImageMagickThumbnailFilter extends MediaFilter {
/**
* @return String bundle name
*
*/
@Override
public String getBundleName() {
@@ -122,6 +118,7 @@ public abstract class ImageMagickThumbnailFilter extends MediaFilter {
f2.deleteOnExit();
ConvertCmd cmd = new ConvertCmd();
IMOperation op = new IMOperation();
op.autoOrient();
op.addImage(f.getAbsolutePath());
op.thumbnail(width, height);
op.addImage(f2.getAbsolutePath());
@@ -146,7 +143,7 @@ public abstract class ImageMagickThumbnailFilter extends MediaFilter {
// PDFs using the CMYK color system can be handled specially if
// profiles are defined
if (cmyk_profile != null && srgb_profile != null) {
Info imageInfo = new Info(f.getAbsolutePath(), true);
Info imageInfo = new Info(f.getAbsolutePath() + s, true);
String imageClass = imageInfo.getImageClass();
if (imageClass.contains("CMYK")) {
op.profile(cmyk_profile);
@@ -169,10 +166,11 @@ public abstract class ImageMagickThumbnailFilter extends MediaFilter {
String n = bit.getName();
if (n != null) {
if (nsrc != null) {
if (!n.startsWith(nsrc))
if (!n.startsWith(nsrc)) {
continue;
}
}
}
String description = bit.getDescription();
// If anything other than a generated thumbnail
// is found, halt processing

View File

@@ -7,16 +7,18 @@
*/
package org.dspace.app.mediafilter;
import java.awt.Graphics2D;
import java.awt.Color;
import java.awt.image.*;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Transparency;
import java.awt.Font;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
import java.awt.image.ConvolveOp;
import java.awt.image.Kernel;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import javax.imageio.ImageIO;
import org.dspace.content.Item;
@@ -29,21 +31,17 @@ import org.dspace.core.ConfigurationManager;
*
* @author Jason Sherman jsherman@usao.edu
*/
public class JPEGFilter extends MediaFilter implements SelfRegisterInputFormats
{
public class JPEGFilter extends MediaFilter implements SelfRegisterInputFormats {
@Override
public String getFilteredName(String oldFilename)
{
public String getFilteredName(String oldFilename) {
return oldFilename + ".jpg";
}
/**
* @return String bundle name
*
*/
@Override
public String getBundleName()
{
public String getBundleName() {
return "THUMBNAIL";
}
@@ -51,8 +49,7 @@ public class JPEGFilter extends MediaFilter implements SelfRegisterInputFormats
* @return String bitstreamformat
*/
@Override
public String getFormatString()
{
public String getFormatString() {
return "JPEG";
}
@@ -60,8 +57,7 @@ public class JPEGFilter extends MediaFilter implements SelfRegisterInputFormats
* @return String description
*/
@Override
public String getDescription()
{
public String getDescription() {
return "Generated Thumbnail";
}
@@ -69,14 +65,12 @@ public class JPEGFilter extends MediaFilter implements SelfRegisterInputFormats
* @param currentItem item
* @param source source input stream
* @param verbose verbose mode
*
* @return InputStream the resulting input stream
* @throws Exception if error
*/
@Override
public InputStream getDestinationStream(Item currentItem, InputStream source, boolean verbose)
throws Exception
{
throws Exception {
// read in bitstream's image
BufferedImage buf = ImageIO.read(source);
@@ -84,8 +78,7 @@ public class JPEGFilter extends MediaFilter implements SelfRegisterInputFormats
}
public InputStream getThumb(Item currentItem, BufferedImage buf, boolean verbose)
throws Exception
{
throws Exception {
// get config params
float xmax = (float) ConfigurationManager
.getIntProperty("thumbnail.maxwidth");
@@ -99,30 +92,28 @@ public class JPEGFilter extends MediaFilter implements SelfRegisterInputFormats
return getThumbDim(currentItem, buf, verbose, xmax, ymax, blurring, hqscaling, 0, 0, null);
}
public InputStream getThumbDim(Item currentItem, BufferedImage buf, boolean verbose, float xmax, float ymax, boolean blurring, boolean hqscaling, int brandHeight, int brandFontPoint, String brandFont)
throws Exception
{
public InputStream getThumbDim(Item currentItem, BufferedImage buf, boolean verbose, float xmax, float ymax,
boolean blurring, boolean hqscaling, int brandHeight, int brandFontPoint,
String brandFont)
throws Exception {
// now get the image dimensions
float xsize = (float) buf.getWidth(null);
float ysize = (float) buf.getHeight(null);
// if verbose flag is set, print out dimensions
// to STDOUT
if (verbose)
{
if (verbose) {
System.out.println("original size: " + xsize + "," + ysize);
}
// scale by x first if needed
if (xsize > xmax)
{
if (xsize > xmax) {
// calculate scaling factor so that xsize * scale = new size (max)
float scale_factor = xmax / xsize;
// if verbose flag is set, print out extracted text
// to STDOUT
if (verbose)
{
if (verbose) {
System.out.println("x scale factor: " + scale_factor);
}
@@ -133,15 +124,13 @@ public class JPEGFilter extends MediaFilter implements SelfRegisterInputFormats
// if verbose flag is set, print out extracted text
// to STDOUT
if (verbose)
{
if (verbose) {
System.out.println("size after fitting to maximum width: " + xsize + "," + ysize);
}
}
// scale by y if needed
if (ysize > ymax)
{
if (ysize > ymax) {
float scale_factor = ymax / ysize;
// now reduce x size
@@ -151,8 +140,7 @@ public class JPEGFilter extends MediaFilter implements SelfRegisterInputFormats
}
// if verbose flag is set, print details to STDOUT
if (verbose)
{
if (verbose) {
System.out.println("size after fitting to maximum height: " + xsize + ", "
+ ysize);
}
@@ -163,16 +151,14 @@ public class JPEGFilter extends MediaFilter implements SelfRegisterInputFormats
// Use blurring if selected in config.
// a little blur before scaling does wonders for keeping moire in check.
if (blurring)
{
if (blurring) {
// send the buffered image off to get blurred.
buf = getBlurredInstance((BufferedImage) buf);
}
// Use high quality scaling method if selected in config.
// this has a definite performance penalty.
if (hqscaling)
{
if (hqscaling) {
// send the buffered image off to get an HQ downscale.
buf = getScaledInstance((BufferedImage) buf, (int) xsize, (int) ysize,
(Object) RenderingHints.VALUE_INTERPOLATION_BICUBIC, (boolean) true);
@@ -204,32 +190,27 @@ public class JPEGFilter extends MediaFilter implements SelfRegisterInputFormats
@Override
public String[] getInputMIMETypes()
{
public String[] getInputMIMETypes() {
return ImageIO.getReaderMIMETypes();
}
@Override
public String[] getInputDescriptions()
{
public String[] getInputDescriptions() {
return null;
}
@Override
public String[] getInputExtensions()
{
public String[] getInputExtensions() {
// Temporarily disabled as JDK 1.6 only
// return ImageIO.getReaderFileSuffixes();
return null;
}
public BufferedImage getNormalizedInstance(BufferedImage buf)
{
public BufferedImage getNormalizedInstance(BufferedImage buf) {
int type = (buf.getTransparency() == Transparency.OPAQUE) ?
BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB_PRE;
int w, h;
w = buf.getWidth();
h = buf.getHeight();
int w = buf.getWidth();
int h = buf.getHeight();
BufferedImage normal = new BufferedImage(w, h, type);
Graphics2D g2d = normal.createGraphics();
g2d.drawImage(buf, 0, 0, w, h, Color.WHITE, null);
@@ -244,8 +225,7 @@ public class JPEGFilter extends MediaFilter implements SelfRegisterInputFormats
* @param buf buffered image
* @return updated BufferedImage
*/
public BufferedImage getBlurredInstance(BufferedImage buf)
{
public BufferedImage getBlurredInstance(BufferedImage buf) {
buf = getNormalizedInstance(buf);
// kernel for blur op
@@ -287,12 +267,12 @@ public class JPEGFilter extends MediaFilter implements SelfRegisterInputFormats
int targetWidth,
int targetHeight,
Object hint,
boolean higherQuality)
{
boolean higherQuality) {
int type = (buf.getTransparency() == Transparency.OPAQUE) ?
BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;
BufferedImage scalebuf = (BufferedImage) buf;
int w, h;
int w;
int h;
if (higherQuality) {
// Use multi-step technique: start with original size, then
// scale down in multiple passes with drawImage()

View File

@@ -18,8 +18,7 @@ import org.dspace.core.Context;
* by the MediaFilterManager. More complex filters should likely implement the FormatFilter
* interface directly, so that they can define their own pre/postProcessing methods.
*/
public abstract class MediaFilter implements FormatFilter
{
public abstract class MediaFilter implements FormatFilter {
/**
* Perform any pre-processing of the source bitstream *before* the actual
* filtering takes place in MediaFilterManager.processBitstream().
@@ -28,20 +27,17 @@ public abstract class MediaFilter implements FormatFilter
* is necessary). Return false if bitstream should be skipped
* for any reason.
*
*
* @param c context
* @param item item containing bitstream to process
* @param source source bitstream to be processed
* @param verbose verbose mode
*
* @return true if bitstream processing should continue,
* false if this bitstream should be skipped
* @throws Exception if error
*/
@Override
public boolean preProcessBitstream(Context c, Item item, Bitstream source, boolean verbose)
throws Exception
{
throws Exception {
return true; //default to no pre-processing
}
@@ -53,20 +49,15 @@ public abstract class MediaFilter implements FormatFilter
* is necessary). Return false if bitstream should be skipped
* for some reason.
*
*
* @param c
* context
* @param item
* item containing bitstream to process
* @param generatedBitstream
* the bitstream which was generated by
* @param c context
* @param item item containing bitstream to process
* @param generatedBitstream the bitstream which was generated by
* this filter.
* @throws Exception if error
*/
@Override
public void postProcessBitstream(Context c, Item item, Bitstream generatedBitstream)
throws Exception
{
throws Exception {
//default to no post-processing necessary
}
}

Some files were not shown because too many files have changed in this diff Show More