Dear
Last month I created a trial version which worked for us.
In the document attached you will find the changes I made in order to
make our DSpace 1.6 Authority Control (authors) enabled.
Roughly said you add in dspace.cfg.:
1. The database properties (driver,url,username,password)
2. The SQL Query to retrieve id,lastname, firstname.
The other, minor, changes are there to choose between binding the id to
a standard name or another spelling of this name. For example Greek
names have different (Greek & English) writings. Both can be 'bind' to
the same id.
Yours Sincerely
Christof
--- Begin Message ---
Denys
In the document attached you will find the changes I made in order to make our
DSpace 1.6 Authority Cotrol enabled.
Roughly said you add the database properties (driver,url,username,password) and
a query to retrieve id,lastname, firstname in dspace.cfg.
Yours Sincerely
Christof
1. New File
-----------
DB.java (org.dspace.storage.rdbms)
----------------------------------
This class creates the connection to an external Database.
The number, lastname and firstname for the Authority Control is
retrieved.
package org.dspace.storage.rdbms;
//Imports
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
public class DB{
//ICV
private Connection connection;
private String driver = null;
private String url = null;
private String username = null;
private String password = null;
//DC
public DB(String driver, String url, String username, String
password){
this.driver = driver;
this.url = url;
this.username = username;
this.password = password;
}
//getConnection
public boolean getConnection(){
boolean isConnected = false;
try {
Class.forName(driver);
connection = DriverManager.getConnection(url, username,
password);
isConnected = true;
System.out.println("isConnected? " + isConnected);
} catch (SQLException ex) {
Logger.getLogger(DB.class.getName()).log(Level.SEVERE,
null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(DB.class.getName()).log(Level.SEVERE,
null, ex);
}
return isConnected;
}
//getNames
public Vector getPersons(String sql, String key){
Vector persons = new Vector();
Statement stmt = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try{
try {
String orderby =
sql.substring(sql.indexOf("ORDER BY"));
stmt = connection.createStatement();
if (key.equals("")) sql = sql.substring(0,
sql.indexOf("WHERE")).concat(orderby);
else sql = sql.replace("?",
"'%"+key.toLowerCase()+"%'");
rs = stmt.executeQuery(sql);
int nCols = rs.getMetaData().getColumnCount();
String [] values = new String[nCols];
try {
while ( rs.next() ){
for (int i = 0 ; i < nCols ; i++){
if (rs.getString(i + 1) != null)
values[i] = rs.getString(i + 1);
else values[i] = "";
}
persons.add(values[1] + ", " +
values[2] +" (" + values[0] + ")");
}
} finally {
if (rs != null) rs.close();
}
} finally {
if (pstmt != null ) pstmt.close();
}
} catch (SQLException ex) {
Logger.getLogger(DB.class.getName()).log(Level.SEVERE,
null, ex);
}
return persons;
}
//closeConnection
public void closeConnection(){
if (connection != null){
try {
connection.close();
}
catch(SQLException sqle){
}
}
}
}
2. Edited files
---------------
dspace.cfg
----------
# turn plugins on
plugin.named.org.dspace.content.authority.ChoiceAuthority = \
# choose plugin to use
org.dspace.content.authority.SampleAuthority = Sample, \
#Set DB parameters
db2.driver = com.ibm.db2.jcc.DB2Driver
db2.url = jdbc:db2://ip:port/instance
db2.username = username
db2.password = password
#Set Prepared Statement Query Always needs this form number,
lastname, firstname
db2.sql = SELECT pnummer, pfamnaam, pvoornaam FROM
luc.personeel WHERE lower(pnaam) LIKE lower(?) AND pnummer between '0001' AND
'9999' ORDER BY pfamnaam
# databind plugin with field
choices.plugin.dc.contributor.author = Sample
choices.presentation.dc.contributor.author = lookup
authority.controlled.dc.contributor.author = true
# Set confidence level
authority.minconfidence.dc.contributor.author = accepted
SampleAuthority.java
--------------------
This class handles the choices.
package org.dspace.content.authority;
//Imports
import java.util.Vector;
import org.dspace.core.ConfigurationManager;
import org.dspace.storage.rdbms.DB;
//DC
public class SampleAuthority implements ChoiceAuthority{
//ICV
private boolean isConnected = false;
private DB db= null;
private static String driver = null;
private static String url = null;
private static String username = null;
private static String password = null;
private static String sql = null;
//DC
public SampleAuthority(){
if (!isConnected){
//Lees de DB parameter uit de config file
driver = ConfigurationManager.getProperty("db2.driver");
url = ConfigurationManager.getProperty("db2.url");
username =
ConfigurationManager.getProperty("db2.username");
password =
ConfigurationManager.getProperty("db2.password");
sql = ConfigurationManager.getProperty("db2.sql");
//Maak een connectie aan uit de DB class
db = new DB(driver, url, username, password);
isConnected = db.getConnection();
// sanity check
if (!isConnected) throw new
IllegalStateException("Missing DSpace configuration keys for DBName Query");
}
}
//getMatches
public Choices getMatches(String query, int collection, int
start, int limit, String locale){
int dflt = -1;
//Haal de namen op om een Choice van deze lengte te
initialiseren.
Vector persons = new Vector();
persons = db.getPersons(sql,query);
if (persons.size() == 0) persons =
db.getPersons(sql,"");
Choice[] v = new Choice[persons.size()];
for (int i = 0; i < persons.size(); ++i){
String label = (String) persons.elementAt(i);
String authority = label.substring(label.indexOf("(") +
1, label.indexOf(")"));
String value = label.substring(0, label.indexOf("("));
v[i] = new Choice(authority, value, label);
}
return new Choices(v, 0, v.length,
Choices.CF_AMBIGUOUS, false, dflt);
}
//getBestMatches
public Choices getBestMatch(String text, int collection, String
locale){
for (int i = 0; i < values.length; ++i){
if (text.equalsIgnoreCase(values[i])){
Choice v[] = new Choice[1];
v[0] = new Choice(String.valueOf(i), values[i],
labels[i]);
return new Choices(v, 0, v.length,
Choices.CF_UNCERTAIN, false, 0);
}
}
return new Choices(Choices.CF_NOTFOUND);
}
//getLabel
public String getLabel(String key, String locale){
return labels[Integer.parseInt(key)];
}
}
Lookup.jsp
----------
In this page we create an extra button to choose between:
* Fill in the id & the standard name.
* Fill in the standard name (this is used to bind different spellings
to one id).
Add a button which only updates the authority value. The text,
inserted original is kept.
<input name="setid"
onClick="javascript:DSpaceIdAcceptOnClick();" type="button"
class="ds-button-field choices-lookup"
value="<%=
LocaleSupport.getLocalizedMessage(pageContext, isRepeating ?
"jsp.tools.lookup.add":"jsp.tools.lookup.setid") %>"/>
This is set by a boolean so the second button needs to be
parameterized:
<input name="accept"
onClick="javascript:DSpaceChoicesAcceptOnClick(1);" type="button"
class="ds-button-field choices-lookup"
value="<%=
LocaleSupport.getLocalizedMessage(pageContext, isRepeating ?
"jsp.tools.lookup.add":"jsp.tools.lookup.accept") %>"/>
choice-support.js
-----------------
Changes in this class are made to handle the choice made in lookup.jsp
(see above: Lookup.jsp)
Add a boolean parameter to the function function
DSpaceChoicesAcceptOnClick()
function DSpaceChoicesAcceptOnClick (idornot){
}
Add, in this function, an extra if clause, inside the isName
clause.
if (isName){
if (idornot){
of.elements[dspace_makeFieldInput(valueInput,'_last')].value =
this.form.elements['text1'].value;
of.elements[dspace_makeFieldInput(valueInput,'_first')].value =
this.form.elements['text2'].value;
}
}
Add the function
function DSpaceIdAcceptOnClick(){
return DSpaceChoicesAcceptOnClick ('false');
}
--- End Message ---
------------------------------------------------------------------------------
_______________________________________________
DSpace-tech mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dspace-tech