
org.nbnResolving.resolver.EpicurLocalResolver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of resolver-core Show documentation
Show all versions of resolver-core Show documentation
Java classes providing resolving functionality for Persistent Identifiers.
Main focus is on National Bibliography Numbers, but some other known systems are also supported.
See the official URN:NBN Resolver http://nbn-resolving.org or http://persid.org
The newest version!
/* *********************************************************************
* Class EpicurLocalResolver
*
* Copyright (c) 2010-2013, German National Library/Deutsche Nationalbibliothek
* Adickesallee 1, D-60322 Frankfurt am Main, Federal Republic of Germany
*
* This program is free software.
* For your convenience it is dual licensed.
* You can redistribute it and/or modify it under the terms of
* one of the following licenses:
*
* 1.)
* The GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
* You should have received a copy of the GNU General Public License
* along with this program (gpl-3.0.txt); if not please read
* http://www.gnu.org/licenses/gpl.html
*
* 2.)
* The European Union Public Licence as published by
* The European Commission (executive body of the European Union);
* either version 1.1 of the License, or (at your option) any later version.
* You should have received a copy of the European Union Public Licence
* along with this program (eupl_v1.1_en.pdf); if not please read
* http://www.osor.eu/eupl
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the above licenses for more details.
*
* Kadir Karaca Kocer -- German National Library
*
**********************************************************************/
/* ********************************************************************
* CHANGELOG:
*
* 2013-08-05 Some fixes for valid XML serialisation (NULL checks)
* 2012-04-03 Port to Maven by Timo Heck & Karaca Kocer
* Created on 2010-07-27 by Karaca Kocer
********************************************************************/
package org.nbnResolving.resolver;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
//import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nbnResolving.common.URNUtils;
import org.nbnResolving.database.DataAccessException;
import org.nbnResolving.database.impl.EpicurDaoImpl;
import org.nbnResolving.database.impl.DatabaseUtils;
import org.nbnResolving.database.model.TableINSTITUTION;
import org.nbnResolving.database.model.TableNAMESPACE;
import org.nbnResolving.database.model.TableURL;
import org.nbnResolving.database.model.TableURN;
import org.nbnResolving.pidef.*;
import eu.europeanaconnect.erds.DataProvider;
import eu.europeanaconnect.erds.ResolverException;
import eu.europeanaconnect.erds.ResolverRequest;
/**
* Class implementing a resolver for URNs that are locally
* saved in National Libraries which are using EPICUR database model.
* Please see http://www.dnb.de/eng/wir/projekte/epicur.htm
* for more information.
*
* (This class gets its data from a legacy Sybase ASE database.
* So you have to know the structure of this database to understand
* how things work and why.)
*
* @see eu.europeanaconnect.erds.DataProvider
* @see org.nbnResolving.database.impl.DatabaseUtils
* @see org.nbnResolving.database.model.TableURN
* @see org.nbnResolving.database.model.TableURL
*
* @author Kadir Karaca Kocer
*/
public class EpicurLocalResolver implements DataProvider {
private static final Log LOGGER = LogFactory.getLog(EpicurLocalResolver.class);
protected String requestUrlPattern;
protected String id;
protected String label;
protected List supportedNamespaces;
protected String identifierPattern;
protected boolean showAdress = true;
//protected String driver;
//protected String database;
//protected String user;
//protected String password;
//protected javax.sql.DataSource dataSource;
protected EpicurDaoImpl dao;
private static final boolean EXTENDED = true; //Ask RDBMS more information. TRUE for debugging
protected final static String FRAG_CHAR="/fragment/"; //experimental! resolving for URNs with fragments
/**
* Default Constructor
*/
public EpicurLocalResolver() {
LOGGER.debug("EpicurLocalResolver: Hallo World. Here I am!");
}
/**
* {@inheritDoc}
*/
@Override
public EpicurResolverResponse getResponse(ResolverRequest req) throws ResolverException {
LOGGER.debug("EpicurLocalResolver.getResponse() - Start");
//first check if the parameters are ok
if (req == null) throw new ResolverException("ERROR: EpicurLocalResolver.getResponse() " +
"ResolverRequest can not be NULL!", ResolverException.ResolverExceptionCode.INVALID_IDENTIFIER);
String action = req.getAction();
//full information is default
if ((action != null) && (!action.isEmpty())) {
action = action.trim().toLowerCase();
} else action = "full";
Connection connection = null;
EpicurResolverResponse response = null;
//connecting to the database using the data source (server:port, user name and password -> see the XML config file)
try {
//connection = DatabaseUtils.connectToDatabase(this.database, this.driver, this.user, this.password, true); //true -> readOnly
connection = this.dao.getConnection(true);
if (connection == null) {
throw new ResolverException("ERROR: EpicurLocalResolver.getResponse() " +
"Connection can not be NULL!", ResolverException.ResolverExceptionCode.IO_ERROR);
}
connection.setReadOnly(true);
} catch (Exception e) {
LOGGER.error("Exception! EpicurLocalResolver: Can not connect to Database.");
e.printStackTrace();
throw new ResolverException("EXCEPTION! Can not connect to Database!\n" + e.getMessage(),
ResolverException.ResolverExceptionCode.IO_ERROR, e);
}
//DBMS ok. Analyse what the user wants
LOGGER.debug("Database ok. Processing the request.");
try {
if (action.equals("full") || action.equals("geturl")) {
response = getURNResolvingResponse(req.getIdentifier(), Constants.RESOLVE_FULL_INFO, this.showAdress, connection);
} else if (action.equals("frontpage")) {
response = getURNResolvingResponse(req.getIdentifier(), Constants.RESOLVE_ONLY_FRONTPAGE, this.showAdress, connection);
} else if (action.equals("first")) {
response = getURNResolvingResponse(req.getIdentifier(), Constants.RESOLVE_FIRST_URL, this.showAdress, connection);
} else if (action.equals("archive")) {
response = getURNResolvingResponse(req.getIdentifier(), Constants.RESOLVE_ONLY_ARCHIVE, this.showAdress, connection);
} else if (action.equals("reverse")) {
//Read the URL to reverse look up from the parameters
String url = req.getParameters().get("url");
response = getURNForURL(url, connection);
} else if (action.equals("namespaces")) {
response = getNamespaceList(connection);
} else if (action.equals("institutions")) {
response = getInstitutionList(this.showAdress, connection);
} else throw new ResolverException("ERROR: EpicurLocalResolver.getResponse() -- The action: " +
action + " is not defined! Please check.", ResolverException.ResolverExceptionCode.INVALID_IDENTIFIER);
} catch (Exception e) {
LOGGER.error("ERROR: EpicurLocalResolver.getResponse() - Exception during getting response", e);
throw new ResolverException("ERROR: EpicurLocalResolver.getResponse() " +
"Exception during getting response", ResolverException.ResolverExceptionCode.IO_ERROR, e);
} finally {
//shut down the database connection
LOGGER.debug("EpicurLocalResolver: Checking if the Connection is open.");
try {
EpicurDaoImpl.closeConnection(connection);
} catch (DataAccessException e) {
LOGGER.error("ERROR: EpicurLocalResolver.getResponse() - Exception during getting response", e);
throw new ResolverException("ERROR: EpicurLocalResolver.getResponse() " +
"Exception during getting response", ResolverException.ResolverExceptionCode.IO_ERROR, e);
}
}
LOGGER.debug("EpicurLocalResolver.getResponse() -- End");
return response;
}
/*
* @param urn URN to validate.
* @param cc TRUE if you want the Checksum also to be validated.
* @param cns TRUE if you want the Namespace also to be validated.
* @return Returns:
0 for URN:NBN comforms all the rules.
1 if the is a syntax error
*
public static int validateURN(String urn, boolean cc, boolean cns) {
int statuscode = 0;
// implement logic. Till then all URNs are OK.
return statuscode;
}*/
/**
*
* @return Found URLs for this URN.
* @throws ResolverException
* @throws SQLException
* @throws UnsupportedEncodingException
* @throws MalformedURLException
* @throws URISyntaxException
*/
private static EpicurResolverResponse getURNResolvingResponse(String pi, short action, boolean showAdress, Connection connection)
throws SQLException, ResolverException, MalformedURLException, UnsupportedEncodingException, URISyntaxException{
//TODO: catch SQLException --> throw ResolverException
LOGGER.debug("EpicurLocalResolver.getURNResolvingResponse() -- Start\nURN = " + pi);
if (pi == null) throw new ResolverException("ERROR: EpicurLocalResolver.getURNResolvingResponse()" +
"Identifier can not be null!", ResolverException.ResolverExceptionCode.INVALID_IDENTIFIER);
//TODO: URL decode? activate lowercase again?
String urn = pi.trim(); //.toLowerCase();
//URN granular: alpha version
String[] parts = urn.split(FRAG_CHAR);
String fragment = null;
if (parts.length > 1) {
urn = parts[0];
fragment = parts[1];
//if ((fragment != null) && (!fragment.isEmpty())) fragment = fragment.replaceAll("/", "&");
}
LOGGER.debug("getURNResolvingResponse(): Fragment= " + fragment);
if (urn.length() < 16) throw new ResolverException("ERROR: EpicurLocalResolver.getURNResolvingResponse()"
+ " Wrong identifier format. Expected: urn:nbn:(at|ch|de):[Namespace]-[UniqueIdentifier][Checksum]",
ResolverException.ResolverExceptionCode.INVALID_IDENTIFIER);
TableURN urnInfo = DatabaseUtils.getURNInfo(connection, urn, true);
EpicurResolverResponse response = new EpicurResolverResponse();
HeaderType header = response.getDoc().getPidef().getHeader();
MessageType message = header.insertNewMessage(0);
message.setLang("en");
if (urnInfo != null) {
if (LOGGER.isDebugEnabled()) LOGGER.debug(urnInfo.toString());
if (urnInfo.getNewer_version() > 0) {
//there is a newer version. no need to process further
LOGGER.debug("EpicurLocalResolver: There exists a newer version of this URN. Skipping URLs.");
header.setStatusCode(Constants.URN_HAS_NEWER_VERSION);
message.setStringValue(DatabaseUtils.getURNasString(connection, urnInfo.getNewer_version()));
} else {
int active = urnInfo.getActive();
switch (active) {
case Constants.URN_STATUS_ACTIVE:
//there exists an active URN: ask for the Institution and URLs
LOGGER.debug("EpicurLocalResolver: Active URN found. Getting its URLs.");
DataType data = response.getDoc().getPidef().getData();
ResolvingInfoType resInfo = data.addNewResolvingInformation();
PiInfoType uit = resInfo.addNewPiInfo();
long urnId = urnInfo.getUrn_id();
uit.setNum(urnId);
uit.setIdentifier(urn);
if ((fragment != null) && (!fragment.isEmpty())) {uit.setFragment(fragment);}
//else {uit.setFragment(null);}
uit.setStatus(Constants.URN_STATUS_ACTIVE);
//TODO: get the first one in the list but there must be a better way
int instId = DatabaseUtils.getInstitutionIdsForNamespace(connection, urnInfo.getNs_id()).get(0).intValue();
TableINSTITUTION ti = DatabaseUtils.getInstitution(connection, instId, EXTENDED);
convertInstitutionTable(ti, uit.addNewOwner(), showAdress);
if (urnInfo.getCreated() != null) {
Calendar cal = Calendar.getInstance();
cal.setTime(urnInfo.getCreated());
uit.setCreated(cal);
}
if (urnInfo.getLast_modified()!= null) {
Calendar cal = Calendar.getInstance();
cal.setTime(urnInfo.getLast_modified());
uit.setLastModified(cal);
}
//Everything ok so far. get the URLs for this URN
ArrayList urls = null;
UrlInfoType urlInfo = null;
switch (action) {
case Constants.RESOLVE_FIRST_URL:
//get only the first URL
LOGGER.debug("Getting the first URL for: " + urn);
/*
urls = new ArrayList();
TableURL firsturl = new TableURL();
firsturl.setUrl(DatabaseUtils.getURLsAsString(this.connection, urnId).get(0));
urls.add(firsturl);
*/
urlInfo = resInfo.addNewUrlInfo();
String firsturl = DatabaseUtils.getURLsAsString(connection, urnId).get(0);
if (firsturl != null && !firsturl.isEmpty()) {
header.setStatusCode(Constants.URN_RESOLVING_OK);
message.setStringValue("URN with the highest priority follows.");
//add the fragment if one exists
if ((fragment != null) && (!fragment.isEmpty())) {
//add the fragment as URL query parameter
firsturl = URNUtils.addParamsToUrl(firsturl, URNUtils.getParameterMap(fragment, "/"));
//firsturl = URNUtils.addQueryToUrl(firsturl, fragment);
//firsturl + FRAG_CHAR + fragment;
}
urlInfo.setUrl(firsturl);
} else {
header.setStatusCode(Constants.NO_REGISTERED_URL);
message.setStringValue("URN: " + urn + " has no active URLs registered.");
}
break;
case Constants.RESOLVE_ONLY_FRONTPAGE:
//get only the fronpage(s)
LOGGER.debug("Getting URLs that are marked as Frontpage for URN: " + urn);
urls = DatabaseUtils.getFrontpage(connection, urnId, EXTENDED, true);
break;
case Constants.RESOLVE_ONLY_ARCHIVE:
//get only the fronpage(s)
LOGGER.debug("Getting URLs that are marked as Frontpage for URN: " + urn);
urls = DatabaseUtils.getArchive(connection, urnId, EXTENDED, true);
break;
default:
//Full information is default
LOGGER.debug("Getting full information for URN: " + urn);
urls = DatabaseUtils.getActiveURLs(connection, urnId, EXTENDED, true);
}
if (action != Constants.RESOLVE_FIRST_URL) {
if (urls != null && !urls.isEmpty()) {
for (TableURL url : urls) {
urlInfo = resInfo.addNewUrlInfo();
urlInfo = convertURLtoUrlInfo(url, urlInfo, fragment, showAdress, connection);
}
header.setStatusCode(Constants.URN_RESOLVING_OK);
message.setStringValue(urn + " is successfully resolved.");
} else {
header.setStatusCode(Constants.NO_REGISTERED_URL);
message.setStringValue("URN: " + urn + " has no active URLs registered.");
}
}
break;
case Constants.URN_STATUS_INACTIVE:
//URN is marked as inactive
LOGGER.debug("EpicurLocalResolver: This URN is marked inactive. Skipping URLs.");
header.setStatusCode(Constants.REQUESTED_URN_IS_INACTIVE);
message.setStringValue(urn + " is marked as INACTIVE. Please contact the responsible institution.");
break;
case Constants.URN_STATUS_RESERVED:
//URN is marked as reserved
LOGGER.debug("EpicurLocalResolver: This URN is marked reserved. Skipping URLs.");
header.setStatusCode(Constants.REQUESTED_URN_IS_RESERVED);
message.setStringValue(urn + " has been RESERVED but not set active yet. Please contact the responsible institution.");
break;
default:
//any other value is not allowed -> ERROR
LOGGER.error("The value " + active + " is not defined for URN.ACTIVE!");
header.setStatusCode(Constants.NO_SUCH_URN_STATUS);
message.setStringValue(urn + " has an undefined activation code. Please contact the responsible institution.");
}
}
//response.setUrnInfo(urnInfo);
} else {
//urnInfo is NULL! no such URN! Error handling!
//TODO: hier testen, ob NAMENSRAUM existiert. evt. andere Fehlercode
LOGGER.debug("EpicurLocalResolver: This URN is not registered at the German National Library");
header.setStatusCode(Constants.NO_SUCH_URN_IN_DATABASE);
message.setStringValue(urn + " is not registered at the German National Library");
}
LOGGER.debug("EpicurLocalResolver.getFullResolvingResponse() -- End.");
return response;
}
/**
* @return Found URLs for this URN.
* @throws SQLException
* @throws ResolverException
*/
private static EpicurResolverResponse getURNForURL(String identifier, Connection connection) throws SQLException {
LOGGER.debug("EpicurLocalResolver.getURNForURL() -- Start\nURL = " + identifier);
//TODO: prüfen & URL encoding!
String url = identifier.trim(); //.toLowerCase(); blöde Idee! NICHT tun.
EpicurResolverResponse response = new EpicurResolverResponse();
HeaderType header = response.getDoc().getPidef().getHeader();
MessageType message = header.insertNewMessage(0);
message.setLang("en");
long urnId = DatabaseUtils.getURNidForURL(connection, url);
if (urnId > 0) {
String urn = DatabaseUtils.getURNasString(connection, urnId);
if ((urn != null) && (urn.length() > 15)) {
DataType data = response.getDoc().getPidef().getData();
ResolvingInfoType resInfo = data.addNewResolvingInformation();
PiInfoType urnInfo = resInfo.addNewPiInfo();
urnInfo.setIdentifier(urn);
resInfo.addNewUrlInfo().setUrl(url);
header.setStatusCode(Constants.URN_FOR_URL_FOLLOWS);
message.setStringValue("The given URL is registered for following URN");
} else {
header.setStatusCode(Constants.PROBLEM_WITH_URN_ID);
message.setStringValue("The registered URN for given URL is not valid. Please inform the owner.");
LOGGER.error("URL: " + url + " URN_ID: " + urnId + " returned NULL or invalid URN. Please check.");
}
} else {
header.setStatusCode(Constants.NO_URN_WITH_THIS_URL);
message.setStringValue("This URL is not registered in the German National Library URN:NBN database");
}
//TODO: set other header data
LOGGER.debug("EpicurLocalResolver.getURNForURL() -- End.");
return response;
}
/**
* Returns all registered Namespaces.
*
* @return All registered namespaces.
* @throws SQLException
*/
private static EpicurResolverResponse getNamespaceList(Connection connection) throws SQLException {
LOGGER.debug("EpicurLocalResolver.getNamespaceList() -- Start");
EpicurResolverResponse response = new EpicurResolverResponse();
HeaderType header = response.getDoc().getPidef().getHeader();
MessageType message = header.insertNewMessage(0);
message.setLang("en");
ArrayList namespaceList = DatabaseUtils.getNamespaceList(connection);
if ((namespaceList != null) && (namespaceList.size() > 0)) {
LOGGER.debug(namespaceList.size() + " namespaces found in database. Generating the list.");
DataType data = response.getDoc().getPidef().getData();
NamespaceArray namespaces = data.addNewNamespaces();
//loop all found namespaces
for (TableNAMESPACE nst : namespaceList) {
NamespaceType namespace = namespaces.addNewNamespace();
namespace.setNum((nst.getNs_id()));
namespace.setName(nst.getName());
namespace.setCountry(nst.getCountry());
namespace.setStatus(nst.getNs_status());
//RESOLVER_ADRESS
//IS_PART_OF does not exist!
namespace.setActive(nst.isActive());
//LAST_SEPERATOR
if (nst.isDig_signed()) {
namespace.setDigSigned(true);
String pk = nst.getPublic_key();
if ((pk != null) && (pk.length() > 50)) {
namespace.setPublicKey(pk);
} else {
LOGGER.error("ERROR: Signed NAMESPACE has no valid Public Key!");
namespace.setPublicKey("ERROR: Invalid Public Key: " + pk +
" ! Please inform the namespace owner.");
}
} else {
namespace.setDigSigned(false);
}
//APPEARS_IN_STATISTIC
//URN_GENERATION_COUNTER
//URN_GENERATION_DATE
if (nst.getCreated() != null) {
Calendar cal = Calendar.getInstance();
cal.setTime(nst.getCreated());
namespace.setCreated(cal);
}
if (nst.getLast_modified()!= null) {
Calendar cal = Calendar.getInstance();
cal.setTime(nst.getLast_modified());
namespace.setLastModified(cal);
}
//TODO: set last checked!
//COMMENT
}
header.setStatusCode(Constants.NAMESPACE_LISTING_SUCCESSFUL);
message.setStringValue(namespaceList.size() + " namespaces listed");
} else {
//no namespace? this is a serious ERROR!
LOGGER.error("ERROR: No namespace found. Please check!");
header.setStatusCode(Constants.NO_NAMESPACE_FOUND);
message.setStringValue("No namespace found. Please check the database");
}
LOGGER.debug("EpicurLocalResolver.getNamespaceList() -- End.");
return response;
}
/**
* Returns all registered Institutions.
*
* @return All registered institutions.
* @throws SQLException
*/
private static EpicurResolverResponse getInstitutionList(boolean showAdress, Connection connection) throws SQLException{
LOGGER.debug("EpicurLocalResolver.getInstitutionList() -- Start");
EpicurResolverResponse response = new EpicurResolverResponse();
HeaderType header = response.getDoc().getPidef().getHeader();
MessageType message = header.insertNewMessage(0);
message.setLang("en");
ArrayList institutionList = DatabaseUtils.getInstitutionList(connection);
if ((institutionList != null) && (institutionList.size() > 0)) {
LOGGER.debug(institutionList.size() + " institutions found in database. Generating the list.");
DataType data = response.getDoc().getPidef().getData();
InstitutionArray institutions = data.addNewInstitutions();
//loop all found namespaces
for (TableINSTITUTION inst : institutionList) {
InstitutionType it = institutions.addNewInstitution();
it = convertInstitutionTable(inst, it, showAdress);
}
header.setStatusCode(Constants.INSTITUTION_LISTING_SUCCESSFUL);
message.setStringValue(institutionList.size() + " institutions listed");
} else {
//no institution? this is a serious ERROR!
LOGGER.error("ERROR: No institution found. Please check!");
header.setStatusCode(Constants.NO_INSTITUTION_FOUND);
message.setStringValue("No institution found. Please check the database");
}
LOGGER.debug("EpicurLocalResolver.getInstitutionList() -- End.");
return response;
}
private static UrlInfoType convertURLtoUrlInfo(TableURL url, UrlInfoType uit, String fragment, boolean showAdress, Connection connection)
throws SQLException, MalformedURLException, UnsupportedEncodingException, URISyntaxException {
//check if the URN has fragments
if ((fragment != null) && (!fragment.isEmpty())) {
String urlWithFragment = URNUtils.addParamsToUrl(url.getUrl(), URNUtils.getParameterMap(fragment, "/"));
//URNUtils.addQueryToUrl(, fragment);
if (LOGGER.isDebugEnabled()) LOGGER.debug("convertURLtoUrlInfo(): URL= " + urlWithFragment);
uit.setUrl(urlWithFragment);
} else uit.setUrl(url.getUrl());
//InstitutionType owner = uit.addNewOwner();
int instId = url.getInstitution_id();
TableINSTITUTION ti = DatabaseUtils.getInstitution(connection, instId, EXTENDED);
//InstitutionType owner =
convertInstitutionTable(ti, uit.addNewOwner(), showAdress);
if (url.getMimeType() != null) uit.setMimetype(url.getMimeType());
uit.setFrontpage(url.isN2c());
uit.setOrigin(url.getOrigin());
uit.setStatus(url.getStatus());
if (url.getFilesize() > 0) uit.setFilesize(url.getFilesize());
ChecksumInfoType cit = uit.addNewChecksumInfo();
if (url.isChecksum_check() && (url.getChecksum() != null) && (!url.getChecksum().isEmpty())) {
cit.setChecksumCheck(true);
cit.setChecksumAlgorithm("MD5"); //TODO: find a solution
cit.setChecksum(url.getChecksum());
cit.setChecksumError(url.isChecksum_error());
if (url.getLast_checksum_check() != null) {
Calendar cal = Calendar.getInstance();
cal.setTime(url.getLast_checksum_check());
cit.setLastChecksumCheck(cal);
}
} else {
cit.setChecksumCheck(false);
}
LinkCheckType lct = uit.addNewLinkCheckInfo();
lct.setUrlCheck(false); /* deactivated until Link-Checker is implemented and function properly
if (url.isUrl_check()) {
lct.setUrlCheck(true);
lct.setHttpStatus((short) HttpServletResponse.SC_OK);
lct.setErrorCount((short) 0);
if (url.getLast_url_check() != null) {
Calendar cal = Calendar.getInstance();
cal.setTime(url.getLast_url_check());
lct.setLastUrlCheck(cal);
}
} else {
lct.setUrlCheck(false);
} */
if (url.getBlocking_time() != null) {
Calendar cal = Calendar.getInstance();
cal.setTime(url.getLast_modified());
uit.setDeactivationTime(cal);
}
if (url.getCreated() != null) {
Calendar cal = Calendar.getInstance();
cal.setTime(url.getCreated());
uit.setCreated(cal);
}
if (url.getLast_modified() != null) {
Calendar cal = Calendar.getInstance();
cal.setTime(url.getLast_modified());
uit.setLastModified(cal);
}
return uit;
}
private static InstitutionType convertInstitutionTable(TableINSTITUTION inst, InstitutionType it, boolean showAdress) {
//TODO: eliminate IllegalArgumentException
if ((inst == null) || (it == null)) throw new IllegalArgumentException("ERROR: institution table or type can not be NULL!");
if (inst.getSign() != null) it.setRef(Constants.GND_URI_ROOT + "/" + inst.getSign());
if (inst.getInstitution_id() > 0) it.setNum(inst.getInstitution_id());
//name is mandatory
it.setName(inst.getName());
if (showAdress) {
if (inst.getStreet() != null) it.setStreet(inst.getStreet());
if (inst.getOffice_box() != null) it.setOfficeBox(inst.getOffice_box());
if (inst.getZip() != null) it.setZip(inst.getZip());
if (inst.getCity() != null) it.setCity(inst.getCity());
//Homepage & E-Mail ??
}
if (inst.getCountry() != null) it.setCountry(inst.getCountry());
it.setCheckChecksum(inst.isCheck_checksum());
if (inst.getChecksum_algorithm() != null) it.setChecksumAlgorithm(inst.getChecksum_algorithm());
if (inst.getCreated() != null) {
Calendar cal = Calendar.getInstance();
cal.setTime(inst.getCreated());
it.setCreated(cal);
}
if (inst.getLast_modified()!= null) {
Calendar cal = Calendar.getInstance();
cal.setTime(inst.getLast_modified());
it.setLastModified(cal);
}
//TODO: set last checked!
return it;
}
/**
* {@inheritDoc}
*/
@Override
public String getId() {
return this.id;
}
/**
* {@inheritDoc}
*/
@Override
public String getIdentifierPattern() {
return this.identifierPattern;
}
/**
* {@inheritDoc}
*/
@Override
public List getSupportedNamespaces() {
return this.supportedNamespaces;
}
/**
* @return the requestUrlPattern
*/
public String getRequestUrlPattern() {
return this.requestUrlPattern;
}
/**
* @param pattern the requestUrlPattern to set
*/
public void setRequestUrlPattern(String pattern) {
this.requestUrlPattern = pattern;
}
/**
* @return the label
*/
public String getLabel() {
return this.label;
}
/**
* @param newLabel the label to set
*/
public void setLabel(String newLabel) {
this.label = newLabel;
}
/**
* @param newId the id to set
*/
public void setId(String newId) {
this.id = newId;
}
/**
* @param namespaces Supported Namespaces to set
*/
public void setSupportedNamespaces(List namespaces) {
this.supportedNamespaces = namespaces;
}
/**
* @param pattern the identifierPattern to set
*/
public void setIdentifierPattern(String pattern) {
this.identifierPattern = pattern;
}
/**
* @return the datasource
*/
public EpicurDaoImpl getDao() {
return this.dao;
}
/**
* @param dao The DataAccessObject to set
*/
public void setDao(EpicurDaoImpl dao) {
this.dao = dao;
}
/**
* @return the showAdress
*/
public boolean isShowAdress() {
return this.showAdress;
}
/**
* @param showAdress the showAdress to set
*/
public void setShowAdress(boolean showAdress) {
this.showAdress = showAdress;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy