Commit df87056822aad801df863f07163093abf7bbe531

Authored by Fernando Ribeiro
0 parents

First Commit

openaireauthcontrol_v3.1_dspace3.2/Readme.md
... ... @@ -0,0 +1,119 @@
  1 +# How to install the Add-on
  2 +The detailed instructions can be found in the docs folder.
  3 +
  4 +## Copy the new files
  5 +Copy the new files to the source directory
  6 +
  7 +If you are in Linux
  8 +
  9 + cp -r $PATH_TO _ADDON/setup-data/dspace-source/* $DSPACE_SRC/
  10 +
  11 +Where $PATH_TO _ADDON is the directory where you put the add-on for instalation and $DSPACE_SRC/ is the source directory.
  12 +
  13 +As an example: If the addon is in the opt directory and dspace source is in /src-dspace/dspace32 the command is:
  14 +
  15 + cp -r /opt/setup-data/dspace-source/* /src-dspace/dspace32/
  16 +
  17 +
  18 +## Adding the new entries in the Messages.properties and in Messages_pt_PT.properties
  19 +Add the fowlowing messages to Messages.properties:
  20 +
  21 + jsp.authority.confidence.description.blank = OpenAIRE project checked
  22 + jsp.tools.lookup.title = FP7/ERC project selection
  23 + jsp.tools.lookup.heading = Verifying value…
  24 + jsp.tools.lookup.accept = Accept
  25 + jsp.tools.lookup.add = Add
  26 + jsp.tools.lookup.cancel = Cancel
  27 + jsp.tools.lookup.more = See more results
  28 + jsp.tools.lookup.fail = Failed to load information:
  29 + jsp.tools.lookup.results = Results @1@ until @2@ of @3@ for the search "@4@"
  30 + jsp.tools.lookup.lookup = Search
  31 + jsp.tools.lookup.field.dc_relation.title = FP7 project containing the term
  32 + jsp.tools.lookup.field.dc_relation.help = FP7 Project ID (If accepted this value will pass to the textbox)
  33 + jsp.tools.lookup.field.dc_relation.nonauthority = Not identified
  34 +
  35 +Add the fowlowing messages to Messages_pt_PT.properties:
  36 +
  37 + jsp.authority.confidence.description.blank = Projecto OpenAIRE verificado
  38 + jsp.tools.lookup.title = Selecção do projecto FP7/ERC
  39 + jsp.tools.lookup.heading = A Verificar valor…
  40 + jsp.tools.lookup.accept = Aceitar
  41 + jsp.tools.lookup.add = Adicionar
  42 + jsp.tools.lookup.cancel = Cancelar
  43 + jsp.tools.lookup.more = Ver Mais Resultados
  44 + jsp.tools.lookup.fail = Falha ao carregar informação:
  45 + jsp.tools.lookup.results = Resultados @1@ até @2@ de @3@ para o termo "@4@"
  46 + jsp.tools.lookup.lookup = Pesquisar
  47 + jsp.tools.lookup.field.dc_relation.title = Projetos FP7 contendo o termo pesquisado
  48 + jsp.tools.lookup.field.dc_relation.help = Identificador do projeto (Se aceitar este valor ser colocado na caixa de texto do projecto)
  49 + jsp.tools.lookup.field.dc_relation.nonauthority = Projecto não identificado
  50 +
  51 +#Change the dspace.cfg
  52 +Edit dspace.cfg in $DSPACE_SRC/dspace/config/dspace.cfg.
  53 +Uncomment the lines of the authority control plugins and add OpenAire.
  54 +
  55 + plugin.named.org.dspace.content.authority.ChoiceAuthority = \
  56 + org.dspace.content.authority.OpenAIREAuthority = OpenAIRE
  57 +
  58 +If there are more Choices of authority the options must be added like the example:
  59 + plugin.named.org.dspace.content.authority.ChoiceAuthority = \
  60 + org.dspace.content.authority.SampleAuthority = Sample, \
  61 + ...
  62 + ...
  63 + org.dspace.content.authority.OpenAIREAuthority = OpenAIRE
  64 +
  65 + where ... are the other authority options
  66 +
  67 +Add also, the following options to dspace.cfg (if they exist, only change their values)
  68 +
  69 + choices.plugin.dc.relation = OpenAIRE
  70 + choices.presentation.dc.relation = suggest
  71 + authority.controlled.dc.relation = true
  72 +
  73 +Add also the following lines (if they exist, only change their values)
  74 +
  75 + openaire.projects.filename = ${dspace.dir}/config/openaire-cache.list
  76 + # One or more urls/file paths (separeted by 3 hash chars (#, i.e. ###)) in DSpace form-value-pairs XML format (take http://api.openaire.eu/projects/dspace/FP7/ALL/ALL as an example)
  77 + openaire.projects.url = "http://api.openaire.eu/projects/dspace/FP7/ALL/ALL###http://api.openaire.eu/projects/dspace/WT/ALL/ALL"
  78 + # Minimum of chars to start searching on the list (default >= 4)
  79 + openaire.projects.suggest.minchar = 4
  80 + # Maximum of projects listed (default <= 10)
  81 + openaire.projects.suggest.max = 20
  82 +
  83 +For the Portuguese projects change to:
  84 + openaire.projects.url = "http://api.openaire.eu/projects/dspace/FP7/ALL/ALL###http://api.openaire.eu/projects/dspace/WT/ALL/ALL###http://api.openaire.eu/projects/dspace/FCT/ALL/ALL"
  85 +
  86 +## Change the inupt-forms.xml
  87 +
  88 +At $DSPACE_SRC/config/input-forms.xml after '<page number="1">' add:
  89 +
  90 + <field>
  91 + <dc-schema>dc</dc-schema>
  92 + <dc-element>relation</dc-element>
  93 + <dc-qualifier></dc-qualifier>
  94 + <repeatable>false</repeatable>
  95 + <label>OpenAIRE Project Identifier</label>
  96 + <input-type>onebox</input-type>
  97 + <hint>Enter the search term (number, name or acronym) of the European project (EC / ERC), National project (FCT) or any other international project/initiative (WT)gt;</hint>
  98 + </field>
  99 +
  100 +## After instalation
  101 +After building DSpace (mvn & ant - see the DSpace Documentation), configure cron to refresh the openaire project list, for example:
  102 +
  103 + 0 0 * * * $DSPACE_BIN/bin/openaire-refresh-list
  104 +
  105 +Run the script (for the addon to work)
  106 +
  107 + $DSPACE_BIN/bin/openaire-refresh-list
  108 +
  109 +## Developers
  110 +The OpenaAirAuthorityControl Add-on was developed in the context of RCAAP Project[RCAAP](www.rcaap.pt) by [KEEP SOLUTIONS](http:///www.keep.pt), a spin-off of the University of Minho, specialized in digital preservation and advanced solutions for digital archives and libraries, in partnership with the [Documentation Services](http://www.sdum.uminho.pt/) of the University of Minho.
  111 +
  112 +
  113 +## Need help, or give any type of contribution?
  114 +
  115 +Please contact us at [FCT|FCCN](http://www.fccn.pt) or any commiter.
  116 +
  117 +## License
  118 +
  119 +Please contact us at [FCT|FCCN](http://www.fccn.pt).
0 120 \ No newline at end of file
... ...
openaireauthcontrol_v3.1_dspace3.2/info.txt
... ... @@ -0,0 +1 @@
  1 +Version: 3.1
... ...
openaireauthcontrol_v3.1_dspace3.2/setup-data/Messages.properties
... ... @@ -0,0 +1,13 @@
  1 +jsp.authority.confidence.description.blank = OpenAIRE project checked
  2 +jsp.tools.lookup.title = FP7/ERC project selection
  3 +jsp.tools.lookup.heading = Verifying value…
  4 +jsp.tools.lookup.accept = Accept
  5 +jsp.tools.lookup.add = Add
  6 +jsp.tools.lookup.cancel = Cancel
  7 +jsp.tools.lookup.more = See more results
  8 +jsp.tools.lookup.fail = Failed to load information:
  9 +jsp.tools.lookup.results = Results @1@ until @2@ of @3@ for the search "@4@"
  10 +jsp.tools.lookup.lookup = Search
  11 +jsp.tools.lookup.field.dc_relation.title = FP7 project containing the term
  12 +jsp.tools.lookup.field.dc_relation.help = FP7 Project ID (If accepted this value will pass to the textbox)
  13 +jsp.tools.lookup.field.dc_relation.nonauthority = Not identified
... ...
openaireauthcontrol_v3.1_dspace3.2/setup-data/Messages_pt_PT.properties
... ... @@ -0,0 +1,13 @@
  1 +jsp.authority.confidence.description.blank = Projecto OpenAIRE verificado
  2 +jsp.tools.lookup.title = Selec&ccedil;&atilde;o do projecto FP7/ERC
  3 +jsp.tools.lookup.heading = A Verificar valor…
  4 +jsp.tools.lookup.accept = Aceitar
  5 +jsp.tools.lookup.add = Adicionar
  6 +jsp.tools.lookup.cancel = Cancelar
  7 +jsp.tools.lookup.more = Ver Mais Resultados
  8 +jsp.tools.lookup.fail = Falha ao carregar informa&ccedil;&atilde;o:
  9 +jsp.tools.lookup.results = Resultados @1@ at&eacute; @2@ de @3@ para o termo "@4@"
  10 +jsp.tools.lookup.lookup = Pesquisar
  11 +jsp.tools.lookup.field.dc_relation.title = Projetos FP7 contendo o termo pesquisado
  12 +jsp.tools.lookup.field.dc_relation.help = Identificador do projeto (Se aceitar este valor ser colocado na caixa de texto do projecto)
  13 +jsp.tools.lookup.field.dc_relation.nonauthority = Projecto n&atilde;o identificado
... ...
openaireauthcontrol_v3.1_dspace3.2/setup-data/dspace-source/dspace-api/src/main/java/org/dspace/content/authority/OpenAIREAuthority.java
... ... @@ -0,0 +1,189 @@
  1 +/*
  2 + * DCInputAuthority.java
  3 + *
  4 + * Version: $Revision: 1.1 $
  5 + *
  6 + * Date: $Date: 2009/07/23 05:07:01 $
  7 + *
  8 + * Copyright (c) 2002-2009, The DSpace Foundation. All rights reserved.
  9 + *
  10 + * Redistribution and use in source and binary forms, with or without
  11 + * modification, are permitted provided that the following conditions are
  12 + * met:
  13 + *
  14 + * - Redistributions of source code must retain the above copyright
  15 + * notice, this list of conditions and the following disclaimer.
  16 + *
  17 + * - Redistributions in binary form must reproduce the above copyright
  18 + * notice, this list of conditions and the following disclaimer in the
  19 + * documentation and/or other materials provided with the distribution.
  20 + *
  21 + * - Neither the name of the DSpace Foundation nor the names of its
  22 + * contributors may be used to endorse or promote products derived from
  23 + * this software without specific prior written permission.
  24 + *
  25 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  26 + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  27 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  28 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  29 + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  30 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  31 + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  32 + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  33 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  34 + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  35 + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  36 + * DAMAGE.
  37 + */
  38 +package org.dspace.content.authority;
  39 +
  40 +import java.io.File;
  41 +import java.util.ArrayList;
  42 +import java.util.List;
  43 +
  44 +import javax.xml.parsers.DocumentBuilder;
  45 +import javax.xml.parsers.DocumentBuilderFactory;
  46 +
  47 +import org.apache.log4j.Logger;
  48 +import org.dspace.core.ConfigurationManager;
  49 +import org.w3c.dom.Document;
  50 +import org.w3c.dom.Element;
  51 +import org.w3c.dom.Node;
  52 +import org.w3c.dom.NodeList;
  53 +
  54 +/**
  55 + * ChoiceAuthority source that reads the same input-forms which drive
  56 + * configurable submission.
  57 + *
  58 + * Configuration:
  59 + * This MUST be configured aas a self-named plugin, e.g.:
  60 + * plugin.selfnamed.org.dspace.content.authority.ChoiceAuthority = \
  61 + * org.dspace.content.authority.DCInputAuthority
  62 + *
  63 + * It AUTOMATICALLY configures a plugin instance for each <value-pairs>
  64 + * element (within <form-value-pairs>) of the input-forms.xml. The name
  65 + * of the instance is the "value-pairs-name" attribute, e.g.
  66 + * the element: <value-pairs value-pairs-name="common_types" dc-term="type">
  67 + * defines a plugin instance "common_types".
  68 + *
  69 + * IMPORTANT NOTE: Since these value-pairs do NOT include authority keys,
  70 + * the choice lists derived from them do not include authority values.
  71 + * So you should not use them as the choice source for authority-controlled
  72 + * fields.
  73 + */
  74 +public class OpenAIREAuthority implements ChoiceAuthority
  75 +{
  76 + static {
  77 + try {
  78 + load();
  79 + } catch (Exception ex) {
  80 + OpenAIREAuthority.log.error("Error",ex);
  81 + OpenAIREAuthority.pairs = new ArrayList<Pair<String,String>>();
  82 + }
  83 + }
  84 +
  85 + private static Logger log = Logger.getLogger(OpenAIREAuthority.class);
  86 + private static final String FileProperty = "openaire.projects.filename";
  87 + private static final String MinimumChars = "openaire.projects.suggest.minchar";
  88 + private static final String MaxSuggests = "openaire.projects.suggest.max";
  89 + private static final int MaxSuggestionLength = 66;
  90 +
  91 +
  92 + private static List<Pair<String, String>> pairs = null;
  93 +
  94 + /**
  95 + * Loads the data, parsing the file defined at the 'openaire.projects.filename' dspace
  96 + * property.
  97 + */
  98 + @SuppressWarnings("unused")
  99 + private static void load () {
  100 + if (OpenAIREAuthority.pairs == null) {
  101 + OpenAIREAuthority.pairs = new ArrayList<Pair<String, String>>();
  102 + String defsFile = ConfigurationManager.getProperty(OpenAIREAuthority.FileProperty);
  103 + if (defsFile == null) OpenAIREAuthority.log.error("Configuration "+OpenAIREAuthority.FileProperty+" not found in dspace.cfg file.");
  104 + else {
  105 + try {
  106 + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  107 + DocumentBuilder builder = factory.newDocumentBuilder();
  108 + Document doc = builder.parse(new File(defsFile));
  109 + doc.getDocumentElement().normalize();
  110 +
  111 + NodeList nodes = doc.getElementsByTagName("pair");
  112 + for (int i = 0; i < nodes.getLength(); i++) {
  113 + Node node = nodes.item(i);
  114 + if (node.getNodeType() == Node.ELEMENT_NODE) {
  115 + // OK!
  116 + Element element = (Element) node;
  117 + Pair<String, String> pair = new Pair<String, String>();
  118 + pair.fst = element.getElementsByTagName("displayed-value").item(0).getFirstChild().getNodeValue();
  119 + pair.snd = element.getElementsByTagName("stored-value").item(0).getFirstChild().getNodeValue();
  120 + OpenAIREAuthority.pairs.add(pair);
  121 + } else
  122 + throw new Exception("Invalid Node readed");
  123 + }
  124 + } catch (Exception e) {
  125 + OpenAIREAuthority.log.error("Unable to parse file "+defsFile, e);
  126 + }
  127 + }
  128 + }
  129 + }
  130 +
  131 + private String getPrettyChoiceText (String text) {
  132 + if (text.length() > OpenAIREAuthority.MaxSuggestionLength) {
  133 + return text.substring(0, OpenAIREAuthority.MaxSuggestionLength - 3) + "...";
  134 + } else return text;
  135 + }
  136 +
  137 + public Choices getMatches(String field, String text, int collection, int start,
  138 + int limit, String locale) {
  139 + OpenAIREAuthority.load();
  140 + int minChars = ConfigurationManager.getIntProperty(OpenAIREAuthority.MinimumChars, 4);
  141 + int maxSuggests = ConfigurationManager.getIntProperty(OpenAIREAuthority.MaxSuggests, 10);
  142 +
  143 + List<Choice> result = new ArrayList<Choice>();
  144 + int dflt = -1;
  145 + int type = Choices.CF_NOTFOUND;
  146 + int added = 0;
  147 + if (text != null && text.length() >= minChars) {
  148 + for (int i = 0; i < OpenAIREAuthority.pairs.size() && added < maxSuggests; ++i)
  149 + {
  150 + if (OpenAIREAuthority.pairs.get(i).fst.toLowerCase().contains(text.toLowerCase()))
  151 + {
  152 + Choice cs = new Choice(String.valueOf(i), OpenAIREAuthority.pairs.get(i).snd, this.getPrettyChoiceText(OpenAIREAuthority.pairs.get(i).fst));
  153 + result.add(cs);
  154 + added++;
  155 + if (OpenAIREAuthority.pairs.get(i).fst.equalsIgnoreCase(text))
  156 + dflt = i;
  157 + }
  158 + }
  159 + if (added > 0) type = Choices.CF_AMBIGUOUS;
  160 + else type = Choices.CF_NOTFOUND;
  161 + }
  162 + return new Choices(result.toArray(new Choice[] {}), 0, result.size(), type, false, dflt);
  163 + }
  164 +
  165 + public Choices getBestMatch(String field, String text, int collection, String locale) {
  166 + OpenAIREAuthority.load();
  167 + for (int i = 0; i < OpenAIREAuthority.pairs.size(); ++i)
  168 + {
  169 + if (OpenAIREAuthority.pairs.get(i).fst.toLowerCase().equals(text.toLowerCase()))
  170 + {
  171 + Choice v[] = new Choice[1];
  172 + v[0] = new Choice(String.valueOf(i), OpenAIREAuthority.pairs.get(i).snd, this.getPrettyChoiceText(OpenAIREAuthority.pairs.get(i).fst));
  173 + return new Choices(v, 0, v.length, Choices.CF_UNCERTAIN, false, 0);
  174 + }
  175 + }
  176 + return new Choices(Choices.CF_NOTFOUND);
  177 + }
  178 +
  179 + public String getLabel(String field, String key, String locale) {
  180 + OpenAIREAuthority.load();
  181 + return OpenAIREAuthority.pairs.get(Integer.parseInt(key)).fst;
  182 + }
  183 +
  184 +}
  185 +
  186 +class Pair<T, V> {
  187 + public T fst;
  188 + public V snd;
  189 +}
... ...
openaireauthcontrol_v3.1_dspace3.2/setup-data/dspace-source/dspace/bin/openaire-refresh-list
... ... @@ -0,0 +1,51 @@
  1 +#!/bin/bash
  2 +
  3 +# Get the DSPACE/bin directory
  4 +BINDIR=$(dirname $0)
  5 +
  6 +echo "> Starting \"$0\" execution..."
  7 +
  8 +echo "Updating OpenAIRE Project list"
  9 +
  10 +# Read parameters from DSpace config
  11 +FILE=$($BINDIR/dspace dsrun org.dspace.core.ConfigurationManager -property openaire.projects.filename)
  12 +ONLINE=$($BINDIR/dspace dsrun org.dspace.core.ConfigurationManager -property openaire.projects.url)
  13 +
  14 +ONLINE=$(echo $ONLINE | sed 's/\"//g')
  15 +
  16 +
  17 +XML_CLOSE_ELEMENTS="</value-pairs>\n</form-value-pairs>"
  18 +
  19 +IFS=$'\n'
  20 +i=1
  21 +
  22 +for url in $(echo "$ONLINE" | sed 's_###_\n_g');
  23 +do
  24 + if [ $i -eq 1 ]; then
  25 + if [[ $url == http* ]]; then
  26 + wget --no-check-certificate "$url" -O "${i}.xml"
  27 + else
  28 + cp "$url" "${i}.xml"
  29 + fi
  30 +
  31 + xmllint --format "${i}.xml" | head -n -2 > $FILE
  32 + rm "${i}.xml"
  33 +
  34 + i=$(($i+1))
  35 + else
  36 + if [[ $url == http* ]]; then
  37 + wget --no-check-certificate "$url" -O "${i}.xml"
  38 + else
  39 + cp "$url" "${i}.xml"
  40 + fi
  41 +
  42 + xmllint --format "${i}.xml" | head -n -2 | tail -n +4 >> $FILE
  43 + rm "${i}.xml"
  44 +
  45 + i=$(($i+1))
  46 + fi
  47 +done
  48 +
  49 +echo -e "\n$XML_CLOSE_ELEMENTS" >> $FILE
  50 +
  51 +echo "> Ended \"$0\" execution."
... ...