diff --git a/doc/sphinx-guides/source/installation/config.rst b/doc/sphinx-guides/source/installation/config.rst index e40a873da6d..1f3ea5eece0 100644 --- a/doc/sphinx-guides/source/installation/config.rst +++ b/doc/sphinx-guides/source/installation/config.rst @@ -66,6 +66,17 @@ Publishing the Root Dataverse Non-superusers who are not "Admin" on the root dataverse will not be able to to do anything useful until the root dataverse has been published. +Persistent Identifiers and Publishing Datasets +++++++++++++++++++++++++++++++++++++++++++++++ + +Persistent identifiers are a required and integral part of the Dataverse platform. They provide a URL that is guaranteed to resolve to the datasets they represent. Dataverse currently supports creating identifiers using DOI and additionally displaying identifiers created using HDL. By default and for testing convenience, the installer configures a temporary DOI test namespace through EZID. This is sufficient to create and publish datasets but they are not citable nor guaranteed to be preserved. To properly configure persistent identifiers for a production installation, an account and associated namespace must be acquired for a fee from one of two DOI providers: EZID (http://ezid.cdlib.org) or DataCite (https://www.datacite.org). Once account credentials and DOI namespace have been acquired, please complete the following identifier configuration parameters: + +JVM Options: :ref:`doi.baseurlstring`, :ref:`doi.username`, :ref:`doi.password` + +Database Settings: :ref:`:DoiProvider`, :ref:`:Protocol`, :ref:`:Authority`, :ref:`:DoiSeparator` + +Please note that any datasets creating using the test configuration cannot be directly migrated and would need to be created again once a valid DOI namespace is configured. + Customizing the Root Dataverse ++++++++++++++++++++++++++++++ @@ -162,8 +173,8 @@ For limiting the size of thumbnail images generated from files. doi.baseurlstring +++++++++++++++++ - -As of this writing "https://ezid.cdlib.org" is the only valid value. See also these related database settings below: +.. _doi.baseurlstring: +As of this writing "https://ezid.cdlib.org" and "https://mds.datacite.org" are the only valid values. See also these related database settings below: - :DoiProvider - :Protocol @@ -172,12 +183,12 @@ As of this writing "https://ezid.cdlib.org" is the only valid value. See also th doi.username ++++++++++++ - +.. _doi.username: Used in conjuction with ``doi.baseurlstring``. doi.password ++++++++++++ - +.. _doi.password: Used in conjuction with ``doi.baseurlstring``. dataverse.handlenet.admcredfile @@ -239,28 +250,28 @@ This is the email address that "system" emails are sent from such as password re :DoiProvider ++++++++++++ - -As of this writing "EZID" is the only valid options. DataCite support is planned: https://github.com/IQSS/dataverse/issues/24 +.. _:DoiProvider: +As of this writing "EZID" and "DataCite" are the only valid options. ``curl -X PUT -d EZID http://localhost:8080/api/admin/settings/:DoiProvider`` :Protocol +++++++++ - +.. _:Protocol: As of this writing "doi" is the only valid option for the protocol for a persistent ID. ``curl -X PUT -d doi http://localhost:8080/api/admin/settings/:Protocol`` :Authority ++++++++++ - -Use the DOI authority assigned to you by EZID. +.. _:Authority: +Use the DOI authority assigned to you by your DoiProvider. ``curl -X PUT -d 10.xxxx http://localhost:8080/api/admin/settings/:Authority`` :DoiSeparator +++++++++++++ - +.. _:DoiSeparator: It is recommended that you keep this as a slash ("/"). ``curl -X PUT -d "/" http://localhost:8080/api/admin/settings/:DoiSeparator`` diff --git a/doc/sphinx-guides/source/installation/prep.rst b/doc/sphinx-guides/source/installation/prep.rst index 76c224b40bb..2dc0ccc8b37 100644 --- a/doc/sphinx-guides/source/installation/prep.rst +++ b/doc/sphinx-guides/source/installation/prep.rst @@ -56,7 +56,7 @@ When planning your installation you should be aware of the following components - PostgreSQL: a relational database. - Solr: a search engine. A Dataverse-specific schema is provided. - SMTP server: for sending mail for password resets and other notifications. -- Persistent indentifer service: DOI support is provided. An EZID subscription is required for production use. +- Persistent indentifier service: DOI support is provided. An EZID subscription or DataCite account is required for production use. There are a number of optional components you may choose to install or configure, including: diff --git a/pom.xml b/pom.xml index 0d4c7a0885e..725e0d0dafb 100644 --- a/pom.xml +++ b/pom.xml @@ -317,6 +317,57 @@ jacoco-maven-plugin 0.7.5.201505241946 + + + org.slf4j + slf4j-log4j12 + 1.6.1 + + + axis + axis + 1.4 + + + io.searchbox + jest + 0.1.7 + + + org.apache.httpcomponents + httpclient + 4.4.1 + + + org.apache.httpcomponents + httpcore + 4.4.1 + + + commons-codec + commons-codec + 1.9 + + + com.maxmind.geoip2 + geoip2 + 2.3.1 + + + org.apache.commons + commons-csv + 1.2 + + + net.sf.ehcache + ehcache + 2.10.1 + + + log4j + log4j + 1.2.17 + diff --git a/scripts/database/reference_data.sql b/scripts/database/reference_data.sql index 11c7c1722b4..4f22772b5c5 100644 --- a/scripts/database/reference_data.sql +++ b/scripts/database/reference_data.sql @@ -26,7 +26,7 @@ INSERT INTO guestbook( -- TODO: Remove if http://stackoverflow.com/questions/25743191/how-to-add-a-case-insensitive-jpa-unique-constraint -- gets an answer. See also https://github.com/IQSS/dataverse/issues/2598#issuecomment-158219334 -CREATE UNIQUE INDEX dataverse_alias_unique_idx on dataverse (LOWER(alias)) +CREATE UNIQUE INDEX dataverse_alias_unique_idx on dataverse (LOWER(alias)); CREATE UNIQUE INDEX index_authenticateduser_lower_email ON authenticateduser (lower(email)); CREATE UNIQUE INDEX index_builtinuser_lower_email ON builtinuser (lower(email)); diff --git a/src/main/java/Bundle.properties b/src/main/java/Bundle.properties index 479432933fe..2767358f9ac 100755 --- a/src/main/java/Bundle.properties +++ b/src/main/java/Bundle.properties @@ -787,6 +787,9 @@ dataset.email.datasetLinkBtn.tip=Link Dataset to Your Dataverse dataset.share.datasetShare=Share Dataset dataset.share.datasetShare.tip=Share this dataset on your favorite social media networks. dataset.share.datasetShare.shareText=View this dataset. +dataset.publish.error.datacite=This dataset may not be published because the DataCite Service is currently inaccessible. Please try again. Does the issue continue to persist? +dataset.publish.error.doi=This dataset may not be published because the DOI update failed. +dataset.delete.error.datacite=Could not deaccession the dataset because the DOI update failed. dataset.versionUI.draft=Draft dataset.versionUI.inReview=In Review @@ -816,6 +819,7 @@ dataset.message.metadataSuccess=The metadata for this dataset has been updated. dataset.message.termsSuccess=The terms for this dataset has been updated. dataset.message.filesSuccess=The files for this dataset have been updated. dataset.message.publishSuccess=This dataset has been published. +dataset.message.only.authenticatedUsers=Only authenticated users may release Datasets. dataset.message.deleteSuccess=This dataset has been deleted. dataset.message.bulkFileUpdateSuccess=The selected files have been updated. datasetVersion.message.deleteSuccess=This dataset draft has been deleted. diff --git a/src/main/java/edu/harvard/iq/dataverse/DOIDataCiteRegisterCache.java b/src/main/java/edu/harvard/iq/dataverse/DOIDataCiteRegisterCache.java new file mode 100644 index 00000000000..7ccd4adb78f --- /dev/null +++ b/src/main/java/edu/harvard/iq/dataverse/DOIDataCiteRegisterCache.java @@ -0,0 +1,90 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package edu.harvard.iq.dataverse; + + +import java.io.Serializable; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Lob; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import org.hibernate.validator.constraints.NotBlank; + +/** + * + * @author luopc + */ +@NamedQueries( + @NamedQuery( name="DOIDataCiteRegisterCache.findByDoi", + query="SELECT d FROM DOIDataCiteRegisterCache d WHERE d.doi=:doi") +) +@Entity +public class DOIDataCiteRegisterCache implements Serializable{ + + private static final long serialVersionUID = 8030143094734315681L; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @NotBlank + @Column(unique=true) + private String doi; + + @NotBlank + private String url; + + @NotBlank + private String status; + + @NotBlank + @Lob + private String xml; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getDoi() { + return doi; + } + + public void setDoi(String doi) { + this.doi = doi; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getXml() { + return xml; + } + + public void setXml(String xml) { + this.xml = xml; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } +} \ No newline at end of file diff --git a/src/main/java/edu/harvard/iq/dataverse/DOIDataCiteRegisterService.java b/src/main/java/edu/harvard/iq/dataverse/DOIDataCiteRegisterService.java new file mode 100644 index 00000000000..8e4176b5d4a --- /dev/null +++ b/src/main/java/edu/harvard/iq/dataverse/DOIDataCiteRegisterService.java @@ -0,0 +1,400 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package edu.harvard.iq.dataverse; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.annotation.PreDestroy; +import javax.ejb.Stateless; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; + +/** + * + * @author luopc + */ +@Stateless +public class DOIDataCiteRegisterService { + + private static final Logger logger = Logger.getLogger(DOIDataCiteRegisterService.class.getCanonicalName()); + + @PersistenceContext(unitName = "VDCNet-ejbPU") + private EntityManager em; + + private DataCiteRESTfullClient openClient() throws IOException { + return new DataCiteRESTfullClient(System.getProperty("doi.baseurlstring"), System.getProperty("doi.username"), System.getProperty("doi.password")); + } + + public String createIdentifier(String identifier, HashMap metadata, Dataset dataset) throws IOException { + DataCiteMetadataTemplate metadataTemplate = new DataCiteMetadataTemplate(); + metadataTemplate.setIdentifier(identifier.substring(identifier.indexOf(':') + 1)); + metadataTemplate.setCreators(Util.getListFromStr(metadata.get("datacite.creator"))); + metadataTemplate.setAuthors(dataset.getLatestVersion().getDatasetAuthors()); + metadataTemplate.setDescription(dataset.getLatestVersion().getDescription()); + metadataTemplate.setContacts(dataset.getLatestVersion().getDatasetContacts()); + metadataTemplate.setProducers(dataset.getLatestVersion().getDatasetProducers()); + metadataTemplate.setTitle(metadata.get("datacite.title")); + metadataTemplate.setPublisher(metadata.get("datacite.publisher")); + metadataTemplate.setPublisherYear(metadata.get("datacite.publicationyear")); + + String xmlMetadata = metadataTemplate.generateXML(); + + String status = metadata.get("_status").trim(); + String target = metadata.get("_target"); + String retString = ""; + if (status.equals("reserved")) { + DOIDataCiteRegisterCache rc = findByDOI(identifier); + if (rc == null) { + rc = new DOIDataCiteRegisterCache(); + rc.setDoi(identifier); + rc.setXml(xmlMetadata); + rc.setStatus("reserved"); + rc.setUrl(target); + em.persist(rc); + } else { + rc.setDoi(identifier); + rc.setXml(xmlMetadata); + rc.setStatus("reserved"); + rc.setUrl(target); + } + retString = "success to reserved " + identifier; + } else if (status.equals("public")) { + DOIDataCiteRegisterCache rc = findByDOI(identifier); + if (rc != null) { + rc.setDoi(identifier); + rc.setXml(xmlMetadata); + rc.setStatus("public"); + if (target == null || target.trim().length() == 0) { + target = rc.getUrl(); + } else { + rc.setUrl(target); + } + try (DataCiteRESTfullClient client = openClient()) { + retString = client.postMetadata(xmlMetadata); + client.postUrl(identifier.substring(identifier.indexOf(":") + 1), target); + } catch (UnsupportedEncodingException ex) { + Logger.getLogger(DOIDataCiteRegisterService.class.getName()).log(Level.SEVERE, null, ex); + } + } + } else if (status.equals("unavailable")) { + DOIDataCiteRegisterCache rc = findByDOI(identifier); + try (DataCiteRESTfullClient client = openClient()) { + if (rc != null) { + rc.setStatus("unavailable"); + retString = client.inactiveDataset(identifier.substring(identifier.indexOf(":") + 1)); + } + } catch (IOException io) { + + } + } + return retString; + } + + public boolean testDOIExists(String identifier) { + boolean doiExists; + try (DataCiteRESTfullClient client = openClient()) { + doiExists = client.testDOIExists(identifier.substring(identifier.indexOf(":") + 1)); + } catch (Exception e) { + logger.log(Level.INFO, identifier, e); + return false; + } + return doiExists; + } + + public HashMap getMetadata(String identifier) throws IOException { + HashMap metadata = new HashMap(); + try (DataCiteRESTfullClient client = openClient()) { + String xmlMetadata = client.getMetadata(identifier.substring(identifier.indexOf(":") + 1)); + DataCiteMetadataTemplate template = new DataCiteMetadataTemplate(xmlMetadata); + metadata.put("datacite.creator", Util.getStrFromList(template.getCreators())); + metadata.put("datacite.title", template.getTitle()); + metadata.put("datacite.publisher", template.getPublisher()); + metadata.put("datacite.publicationyear", template.getPublisherYear()); + DOIDataCiteRegisterCache rc = findByDOI(identifier); + if (rc != null) { + metadata.put("_status", rc.getStatus()); + } + } catch (RuntimeException e) { + logger.log(Level.INFO, identifier, e); + } + return metadata; + } + + public DOIDataCiteRegisterCache findByDOI(String doi) { + Query query = em.createNamedQuery("DOIDataCiteRegisterCache.findByDoi", + DOIDataCiteRegisterCache.class); + query.setParameter("doi", doi); + List rc = query.getResultList(); + if (rc.size() == 1) { + return rc.get(0); + } + return null; + } + + public void deleteIdentifier(String identifier) { + DOIDataCiteRegisterCache rc = findByDOI(identifier); + if (rc != null) { + em.remove(rc); + } + } + +} + +class DataCiteMetadataTemplate { + + private static final Logger logger = Logger.getLogger("edu.harvard.iq.dataverse.DataCiteMetadataTemplate"); + private static String template; + + static { + try (InputStream in = DataCiteMetadataTemplate.class.getResourceAsStream("datacite_metadata_template.xml")) { + template = Util.readAndClose(in, "utf-8"); + } catch (Exception e) { + logger.log(Level.SEVERE, "datacite metadata template load error"); + logger.log(Level.SEVERE, "String " + e.toString()); + logger.log(Level.SEVERE, "localized message " + e.getLocalizedMessage()); + logger.log(Level.SEVERE, "cause " + e.getCause()); + logger.log(Level.SEVERE, "message " + e.getMessage()); + } + } + + private String xmlMetadata; + private String identifier; + private List creators; + private String title; + private String publisher; + private String publisherYear; + private List authors; + private String description; + private List contacts; + private List producers; + + public List getProducers() { + return producers; + } + + public void setProducers(List producers) { + this.producers = producers; + } + + public List getContacts() { + return contacts; + } + + public void setContacts(List contacts) { + this.contacts = contacts; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public List getAuthors() { + return authors; + } + + public void setAuthors(List authors) { + this.authors = authors; + } + + public DataCiteMetadataTemplate() { + } + + public DataCiteMetadataTemplate(String xmlMetaData) { + this.xmlMetadata = xmlMetaData; + Document doc = Jsoup.parseBodyFragment(xmlMetaData); + Elements identifierElements = doc.select("identifier"); + if (identifierElements.size() > 0) { + identifier = identifierElements.get(0).html(); + } + Elements creatorElements = doc.select("creatorName"); + creators = new ArrayList(); + for (Element creatorElement : creatorElements) { + creators.add(creatorElement.html()); + } + Elements titleElements = doc.select("title"); + if (titleElements.size() > 0) { + title = titleElements.get(0).html(); + } + Elements publisherElements = doc.select("publisher"); + if (publisherElements.size() > 0) { + publisher = publisherElements.get(0).html(); + } + Elements publisherYearElements = doc.select("publicationYear"); + if (publisherYearElements.size() > 0) { + publisherYear = publisherYearElements.get(0).html(); + } + } + + public String generateXML() { + xmlMetadata = template.replace("${identifier}", this.identifier.trim()) + .replace("${title}", this.title) + .replace("${publisher}", this.publisher) + .replace("${publisherYear}", this.publisherYear) + .replace("${description}", this.description); + StringBuilder creatorsElement = new StringBuilder(); + for (DatasetAuthor author : authors) { + creatorsElement.append(""); + creatorsElement.append(author.getName().getDisplayValue()); + creatorsElement.append(""); + + if (author.getIdType() != null && author.getIdValue() != null && !author.getIdType().isEmpty() && !author.getIdValue().isEmpty() && author.getAffiliation() != null && !author.getAffiliation().getDisplayValue().isEmpty()) { + + if (author.getIdType().equals("ORCID")) { + creatorsElement.append("" + author.getIdValue() + ""); + } + if (author.getIdType().equals("ISNI")) { + creatorsElement.append("" + author.getIdValue() + ""); + } + if (author.getIdType().equals("LCNA")) { + creatorsElement.append("" + author.getIdValue() + ""); + } + } + if (author.getAffiliation() != null && !author.getAffiliation().getDisplayValue().isEmpty()) { + creatorsElement.append("" + author.getAffiliation().getDisplayValue() + ""); + } + creatorsElement.append(""); + } + xmlMetadata = xmlMetadata.replace("${creators}", creatorsElement.toString()); + + StringBuilder contributorsElement = new StringBuilder(); + for (String[] contact : this.getContacts()) { + contributorsElement.append("" + contact[0] + ""); + if (!contact[1].isEmpty()) { + contributorsElement.append("" + contact[1] + ""); + } + contributorsElement.append(""); + } + for (String[] producer : this.getProducers()) { + contributorsElement.append("" + producer[0] + ""); + if (!producer[1].isEmpty()) { + contributorsElement.append("" + producer[1] + ""); + } + contributorsElement.append(""); + } + xmlMetadata = xmlMetadata.replace("{$contributors}", contributorsElement.toString()); + return xmlMetadata; + } + + public static String getTemplate() { + return template; + } + + public static void setTemplate(String template) { + DataCiteMetadataTemplate.template = template; + } + + public String getIdentifier() { + return identifier; + } + + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + public List getCreators() { + return creators; + } + + public void setCreators(List creators) { + this.creators = creators; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getPublisher() { + return publisher; + } + + public void setPublisher(String publisher) { + this.publisher = publisher; + } + + public String getPublisherYear() { + return publisherYear; + } + + public void setPublisherYear(String publisherYear) { + this.publisherYear = publisherYear; + } +} + +class Util { + + public static void close(InputStream in) { + if (in != null) { + try { + in.close(); + } catch (IOException e) { + throw new RuntimeException("Fail to close InputStream"); + } + } + } + + public static String readAndClose(InputStream inStream, String encoding) { + ByteArrayOutputStream outStream = new ByteArrayOutputStream(); + byte[] buf = new byte[128]; + String data; + try { + int cnt; + while ((cnt = inStream.read(buf)) >= 0) { + outStream.write(buf, 0, cnt); + } + data = outStream.toString(encoding); + } catch (IOException ioe) { + throw new RuntimeException("IOException"); + } finally { + close(inStream); + } + return data; + } + + public static List getListFromStr(String str) { + return Arrays.asList(str.split("; ")); +// List authors = new ArrayList(); +// int preIdx = 0; +// for(int i=0;i authors) { + StringBuilder str = new StringBuilder(); + for (String author : authors) { + if (str.length() > 0) { + str.append("; "); + } + str.append(author); + } + return str.toString(); + } +} diff --git a/src/main/java/edu/harvard/iq/dataverse/DOIDataCiteServiceBean.java b/src/main/java/edu/harvard/iq/dataverse/DOIDataCiteServiceBean.java new file mode 100644 index 00000000000..964c4aaff2d --- /dev/null +++ b/src/main/java/edu/harvard/iq/dataverse/DOIDataCiteServiceBean.java @@ -0,0 +1,343 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package edu.harvard.iq.dataverse; + +import edu.harvard.iq.dataverse.settings.SettingsServiceBean; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.HashMap; +import java.util.SimpleTimeZone; +import java.util.TimeZone; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.ejb.EJB; +import javax.ejb.Stateless; + +/** + * + * @author luopc + */ +@Stateless +public class DOIDataCiteServiceBean { + + private static final Logger logger = Logger.getLogger("edu.harvard.iq.dataverse.DOIDataCiteServiceBean"); + + + @EJB + DataverseServiceBean dataverseService; + @EJB + SettingsServiceBean settingsService; + @EJB + DOIDataCiteRegisterService doiDataCiteRegisterService; + + private String DOISHOULDER = ""; + + public DOIDataCiteServiceBean() { + + } + + public boolean alreadyExists (Dataset dataset){ + boolean alreadyExists; + String identifier = getIdentifierFromDataset(dataset); + try{ + alreadyExists = doiDataCiteRegisterService.testDOIExists(identifier); + } catch (Exception e){ + logger.log(Level.INFO, "alreadyExists failed"); + return false; + } + return alreadyExists; + } + + public String createIdentifier(Dataset dataset) throws Exception { + String retString = ""; + String identifier = getIdentifierFromDataset(dataset); + HashMap metadata = getMetadataFromStudyForCreateIndicator(dataset); + metadata.put("_status", "reserved"); + try { + retString = doiDataCiteRegisterService.createIdentifier(identifier, metadata, dataset); + } catch (Exception e) { + logger.log(Level.INFO, "Identifier not created: create failed"); + logger.log(Level.INFO, "String " + e.toString()); + logger.log(Level.INFO, "localized message " + e.getLocalizedMessage()); + logger.log(Level.INFO, "cause " + e.getCause()); + logger.log(Level.INFO, "message " + e.getMessage()); + throw e; +// return "Identifier not created " + e.getLocalizedMessage(); + } + return retString; + } + + public HashMap getIdentifierMetadata(Dataset dataset) { + String identifier = getIdentifierFromDataset(dataset); + HashMap metadata = new HashMap(); + try { + metadata = doiDataCiteRegisterService.getMetadata(identifier); + } catch (Exception e) { + logger.log(Level.INFO, "getIdentifierMetadata failed"); + logger.log(Level.INFO, "String " + e.toString()); + logger.log(Level.INFO, "localized message " + e.getLocalizedMessage()); + logger.log(Level.INFO, "cause " + e.getCause()); + logger.log(Level.INFO, "message " + e.getMessage()); + return metadata; + } + return metadata; + } + + public HashMap lookupMetadataFromIdentifier(String protocol, String authority, String separator, String identifier) { + String identifierOut = getIdentifierForLookup(protocol, authority, separator, identifier); + HashMap metadata = new HashMap(); + try { + metadata = doiDataCiteRegisterService.getMetadata(identifierOut); + } catch (Exception e) { + logger.log(Level.INFO, "None existing so we can use this identifier"); + logger.log(Level.INFO, "identifier: {0}", identifierOut); + return metadata; + } + return metadata; + } + + public String getIdentifierForLookup(String protocol, String authority, String separator, String identifier) { + return protocol + ":" + authority + separator + identifier; + } + + public String modifyIdentifier(Dataset dataset, HashMap metadata) throws Exception { + String identifier = getIdentifierFromDataset(dataset); + try { + doiDataCiteRegisterService.createIdentifier(identifier, metadata, dataset); + } catch (Exception e) { + logger.log(Level.INFO, "modifyMetadata failed"); + logger.log(Level.INFO, "String " + e.toString()); + logger.log(Level.INFO, "localized message " + e.getLocalizedMessage()); + logger.log(Level.INFO, "cause " + e.getCause()); + logger.log(Level.INFO, "message " + e.getMessage()); + throw e; + } + return identifier; + } + + public void deleteRecordFromCache(Dataset datasetIn){ + String identifier = getIdentifierFromDataset(datasetIn); + HashMap doiMetadata = new HashMap(); + try { + doiMetadata = doiDataCiteRegisterService.getMetadata(identifier); + } catch (Exception e) { + logger.log(Level.INFO, "get matadata failed cannot delete"); + logger.log(Level.INFO, "String " + e.toString()); + logger.log(Level.INFO, "localized message " + e.getLocalizedMessage()); + logger.log(Level.INFO, "cause " + e.getCause()); + logger.log(Level.INFO, "message " + e.getMessage()); + } + + String idStatus = (String) doiMetadata.get("_status"); + + if (idStatus == null || idStatus.equals("reserved")) { + logger.log(Level.INFO, "Delete status is reserved.."); + try { + doiDataCiteRegisterService.deleteIdentifier(identifier); + } catch (Exception e) { + logger.log(Level.INFO, "delete failed"); + logger.log(Level.INFO, "String " + e.toString()); + logger.log(Level.INFO, "localized message " + e.getLocalizedMessage()); + logger.log(Level.INFO, "cause " + e.getCause()); + logger.log(Level.INFO, "message " + e.getMessage()); + throw new RuntimeException(e); + } + return; + } + + } + + + public void deleteIdentifier(Dataset datasetIn) throws Exception { + String identifier = getIdentifierFromDataset(datasetIn); + HashMap doiMetadata = new HashMap(); + try { + doiMetadata = doiDataCiteRegisterService.getMetadata(identifier); + } catch (Exception e) { + logger.log(Level.INFO, "get matadata failed cannot delete"); + logger.log(Level.INFO, "String " + e.toString()); + logger.log(Level.INFO, "localized message " + e.getLocalizedMessage()); + logger.log(Level.INFO, "cause " + e.getCause()); + logger.log(Level.INFO, "message " + e.getMessage()); + } + + String idStatus = (String) doiMetadata.get("_status"); + + if (idStatus != null && idStatus.equals("reserved")) { + logger.log(Level.INFO, "Delete status is reserved.."); + try { + doiDataCiteRegisterService.deleteIdentifier(identifier); + } catch (Exception e) { + logger.log(Level.INFO, "delete failed"); + logger.log(Level.INFO, "String " + e.toString()); + logger.log(Level.INFO, "localized message " + e.getLocalizedMessage()); + logger.log(Level.INFO, "cause " + e.getCause()); + logger.log(Level.INFO, "message " + e.getMessage()); + } + return; + } + if (idStatus != null && idStatus.equals("public")) { + //if public then it has been released set to unavailable and reset target to n2t url + updateIdentifierStatus(datasetIn, "unavailable"); + } + } + + private HashMap getUpdateMetadataFromDataset(Dataset datasetIn) { + HashMap metadata = new HashMap(); + + String authorString = datasetIn.getLatestVersion().getAuthorsStr(); + + if (authorString.isEmpty()) { + authorString = ":unav"; + } + + String producerString = dataverseService.findRootDataverse().getName() + " Dataverse"; + + if (producerString.isEmpty()) { + producerString = ":unav"; + } + metadata.put("datacite.creator", authorString); + metadata.put("datacite.title", datasetIn.getLatestVersion().getTitle()); + metadata.put("datacite.publisher", producerString); + metadata.put("datacite.publicationyear", generateYear()); + + return metadata; + } + + private HashMap getMetadataFromStudyForCreateIndicator(Dataset datasetIn) { + HashMap metadata = new HashMap(); + + String authorString = datasetIn.getLatestVersion().getAuthorsStr(); + + if (authorString.isEmpty()) { + authorString = ":unav"; + } + + String producerString = dataverseService.findRootDataverse().getName() + " Dataverse"; + + if (producerString.isEmpty()) { + producerString = ":unav"; + } + metadata.put("datacite.creator", authorString); + metadata.put("datacite.title", datasetIn.getLatestVersion().getTitle()); + metadata.put("datacite.publisher", producerString); + metadata.put("datacite.publicationyear", generateYear()); + String inetAddress = getSiteUrl(); + String targetUrl = ""; + DOISHOULDER = "doi:" + datasetIn.getAuthority(); + + if (inetAddress.equals("localhost")) { + targetUrl = "http://localhost:8080" + "/dataset.xhtml?persistentId=" + DOISHOULDER + + datasetIn.getDoiSeparator() + datasetIn.getIdentifier(); + } else { + targetUrl = inetAddress + "/dataset.xhtml?persistentId=" + DOISHOULDER + + datasetIn.getDoiSeparator() + datasetIn.getIdentifier(); + } + metadata.put("_target", targetUrl); + return metadata; + } + + public HashMap getMetadataFromDatasetForTargetURL(Dataset datasetIn) { + HashMap metadata = new HashMap(); + + String inetAddress = getSiteUrl(); + String targetUrl = ""; + DOISHOULDER = "doi:" + datasetIn.getAuthority(); + + if (inetAddress.equals("localhost")){ + targetUrl ="http://localhost:8080" + "/dataset.xhtml?persistentId=" + DOISHOULDER + + datasetIn.getDoiSeparator() + datasetIn.getIdentifier(); + } else{ + targetUrl = inetAddress + "/dataset.xhtml?persistentId=" + DOISHOULDER + + datasetIn.getDoiSeparator() + datasetIn.getIdentifier(); + } + metadata.put("_target", targetUrl); + return metadata; + } + + public String getSiteUrl() { + String hostUrl = System.getProperty("dataverse.siteUrl"); + if (hostUrl != null && !"".equals(hostUrl)) { + return hostUrl; + } + String hostName = System.getProperty("dataverse.fqdn"); + if (hostName == null) { + try { + hostName = InetAddress.getLocalHost().getCanonicalHostName(); + } catch (UnknownHostException e) { + return null; + } + } + hostUrl = "https://" + hostName; + return hostUrl; + } + + private String getIdentifierFromDataset(Dataset dataset) { + return dataset.getGlobalId(); + } + + public void publicizeIdentifier(Dataset studyIn) throws Exception { + updateIdentifierStatus(studyIn, "public"); + } + + private void updateIdentifierStatus(Dataset dataset, String statusIn) throws Exception { + String identifier = getIdentifierFromDataset(dataset); + HashMap metadata = getUpdateMetadataFromDataset(dataset); + metadata.put("_status", statusIn); + try { + doiDataCiteRegisterService.createIdentifier(identifier, metadata, dataset); + } catch (Exception e) { + logger.log(Level.INFO, "modifyMetadata failed"); + logger.log(Level.INFO, "String " + e.toString()); + logger.log(Level.INFO, "localized message " + e.getLocalizedMessage()); + logger.log(Level.INFO, "cause " + e.getCause()); + logger.log(Level.INFO, "message " + e.getMessage()); + throw e; + } + } + + public static String generateYear() { + StringBuilder guid = new StringBuilder(); + + // Create a calendar to get the date formatted properly + String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000); + SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]); + pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); + pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); + Calendar calendar = new GregorianCalendar(pdt); + Date trialTime = new Date(); + calendar.setTime(trialTime); + guid.append(calendar.get(Calendar.YEAR)); + + return guid.toString(); + } + + public static String generateTimeString() { + StringBuilder guid = new StringBuilder(); + + // Create a calendar to get the date formatted properly + String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000); + SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]); + pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); + pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); + Calendar calendar = new GregorianCalendar(pdt); + Date trialTime = new Date(); + calendar.setTime(trialTime); + guid.append(calendar.get(Calendar.YEAR)); + guid.append(calendar.get(Calendar.DAY_OF_YEAR)); + guid.append(calendar.get(Calendar.HOUR_OF_DAY)); + guid.append(calendar.get(Calendar.MINUTE)); + guid.append(calendar.get(Calendar.SECOND)); + guid.append(calendar.get(Calendar.MILLISECOND)); + double random = Math.random(); + guid.append(random); + + return guid.toString(); + } +} \ No newline at end of file diff --git a/src/main/java/edu/harvard/iq/dataverse/DOIEZIdServiceBean.java b/src/main/java/edu/harvard/iq/dataverse/DOIEZIdServiceBean.java index fb1ad692d7c..bb7c54b848b 100644 --- a/src/main/java/edu/harvard/iq/dataverse/DOIEZIdServiceBean.java +++ b/src/main/java/edu/harvard/iq/dataverse/DOIEZIdServiceBean.java @@ -53,6 +53,8 @@ public DOIEZIdServiceBean() { logger.log(Level.WARNING, "localized message {0}", e.getLocalizedMessage()); logger.log(Level.WARNING, "cause", e.getCause()); logger.log(Level.WARNING, "message {0}", e.getMessage()); + } catch(Exception e){ + System.out.print("Other Error on ezidService.login(USERNAME, PASSWORD) - not EZIDException "); } } diff --git a/src/main/java/edu/harvard/iq/dataverse/DataCiteRESTfullClient.java b/src/main/java/edu/harvard/iq/dataverse/DataCiteRESTfullClient.java new file mode 100644 index 00000000000..93607a56541 --- /dev/null +++ b/src/main/java/edu/harvard/iq/dataverse/DataCiteRESTfullClient.java @@ -0,0 +1,248 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package edu.harvard.iq.dataverse; + + +import java.io.Closeable; +import java.io.IOException; + +import java.io.UnsupportedEncodingException; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.apache.http.HttpResponse; +import org.apache.http.auth.AuthScope; +import org.apache.http.auth.UsernamePasswordCredentials; +import org.apache.http.client.CredentialsProvider; + +import org.apache.http.client.methods.HttpDelete; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.protocol.HttpClientContext; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.BasicCredentialsProvider; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; + + + +import org.apache.http.util.EntityUtils; + +/** + * DataCiteRESTfullClient + * + * @author luopc + * + */ +public class DataCiteRESTfullClient implements Closeable { + + private static final Logger logger = Logger.getLogger(DataCiteRESTfullClient.class.getCanonicalName()); + + private String url; + private CloseableHttpClient httpClient; + private HttpClientContext context; + private String encoding = "utf-8"; + + public DataCiteRESTfullClient(String url, String username, String password) throws IOException { + this.url = url; + try { + context = HttpClientContext.create(); + CredentialsProvider credsProvider = new BasicCredentialsProvider(); + credsProvider.setCredentials(new AuthScope(null, -1), + new UsernamePasswordCredentials(username, password)); + context.setCredentialsProvider(credsProvider); + + httpClient = HttpClients.createDefault(); + } catch (Exception ioe) { + close(); + logger.log(Level.SEVERE,"Fail to init Client",ioe); + throw new RuntimeException("Fail to init Client", ioe); + } + } + + public void close() throws IOException { + if (this.httpClient != null) { + httpClient.close(); + } + } + + /** + * getUrl + * + * @param doi + * @return + */ + public String getUrl(String doi) { + HttpGet httpGet = new HttpGet(this.url + "/doi/" + doi); + try { + HttpResponse response = httpClient.execute(httpGet,context); + String data = EntityUtils.toString(response.getEntity(), encoding); + if (response.getStatusLine().getStatusCode() != 200) { + throw new RuntimeException("Response code: " + response.getStatusLine().getStatusCode() + ", " + data); + } + return data; + } catch (IOException ioe) { + logger.log(Level.SEVERE,"IOException when get url",ioe); + throw new RuntimeException("IOException when get url", ioe); + } + } + + /** + * postUrl + * + * @param doi + * @param url + * @return + */ + public String postUrl(String doi, String url) throws UnsupportedEncodingException { + HttpPost httpPost = new HttpPost(this.url + "/doi"); + httpPost.setHeader("Content-Type", "text/plain;charset=UTF-8"); + httpPost.setEntity(new StringEntity("doi=" + doi + "\nurl=" + url, "utf-8")); + + try { + HttpResponse response = httpClient.execute(httpPost,context); + String data = EntityUtils.toString(response.getEntity(), encoding); + if (response.getStatusLine().getStatusCode() != 201) { + String errMsg = "Response code: " + response.getStatusLine().getStatusCode() + ", " + data; + logger.log(Level.SEVERE,errMsg); + throw new RuntimeException(errMsg); + } + return data; + } catch (IOException ioe) { + logger.log(Level.SEVERE,"IOException when post url"); + throw new RuntimeException("IOException when post url", ioe); + } + } + + /** + * getMetadata + * + * @param doi + * @return + */ + public String getMetadata(String doi) { + HttpGet httpGet = new HttpGet(this.url + "/metadata/" + doi); + httpGet.setHeader("Accept", "application/xml"); + try { + HttpResponse response = httpClient.execute(httpGet,context); + String data = EntityUtils.toString(response.getEntity(), encoding); + if (response.getStatusLine().getStatusCode() != 200) { + String errMsg = "Response code: " + response.getStatusLine().getStatusCode() + ", " + data; + logger.log(Level.SEVERE, errMsg); + throw new RuntimeException(errMsg); + } + return data; + } catch (IOException ioe) { + logger.log(Level.SEVERE, "IOException when get metadata"); + throw new RuntimeException("IOException when get metadata", ioe); + } + } + + /** + * testDOIExists + * + * @param doi + * @return boolean true if identifier already exists on DataCite site + */ + public boolean testDOIExists(String doi) { + HttpGet httpGet = new HttpGet(this.url + "/metadata/" + doi); + httpGet.setHeader("Accept", "application/xml"); + try { + HttpResponse response = httpClient.execute(httpGet,context); + if (response.getStatusLine().getStatusCode() != 200) { + return false; + } + return true; + } catch (IOException ioe) { + logger.log(Level.SEVERE, "IOException when get metadata"); + throw new RuntimeException("IOException when get metadata", ioe); + } + } + + /** + * postMetadata + * + * @param metadata + * @return + */ + public String postMetadata(String metadata) throws UnsupportedEncodingException { + HttpPost httpPost = new HttpPost(this.url + "/metadata"); + httpPost.setHeader("Content-Type", "application/xml;charset=UTF-8"); + httpPost.setEntity(new StringEntity(metadata, "utf-8")); + try { + HttpResponse response = httpClient.execute(httpPost,context); + + String data = EntityUtils.toString(response.getEntity(), encoding); + if (response.getStatusLine().getStatusCode() != 201) { + String errMsg = "Response code: " + response.getStatusLine().getStatusCode() + ", " + data; + logger.log(Level.SEVERE, errMsg); + throw new RuntimeException(errMsg); + } + return data; + } catch (IOException ioe) { + logger.log(Level.SEVERE, "IOException when post metadata"); + throw new RuntimeException("IOException when post metadata", ioe); + } + } + + /** + * inactiveDataset + * + * @param doi + * @return + */ + public String inactiveDataset(String doi) { + HttpDelete httpDelete = new HttpDelete(this.url + "/metadata/" + doi); + try { + HttpResponse response = httpClient.execute(httpDelete,context); + String data = EntityUtils.toString(response.getEntity(), encoding); + if (response.getStatusLine().getStatusCode() != 200) { + String errMsg = "Response code: " + response.getStatusLine().getStatusCode() + ", " + data; + logger.log(Level.SEVERE, errMsg); + throw new RuntimeException(errMsg); + } + return data; + } catch (IOException ioe) { + logger.log(Level.SEVERE, "IOException when inactive dataset"); + throw new RuntimeException("IOException when inactive dataset", ioe); + } + } + + public static void main(String[] args) throws Exception { + String doi = "10.5072/DVN/274533"; + DataCiteRESTfullClient client = new DataCiteRESTfullClient("https://mds.test.datacite.org", "DATACITE.HARVARD", "DVNapitest"); +// System.out.println(client.getUrl(doi)); +// System.out.println(client.getMetadata(doi)); +// System.out.println(client.postMetadata(readAndClose("C:/Users/luopc/Desktop/datacite.xml", "utf-8"))); +// System.out.println(client.postUrl("10.5072/000000001", "http://opendata.pku.edu.cn/dvn/dv/DAIM/faces/study/StudyPage.xhtml?globalId=hdl:TEST/10027&studyListingIndex=1_1acc4e9f23fa10b3cc0500d9eb5e")); +// client.close(); +// String doi2 = "10.1/1.0003"; +// SimpleRESTfullClient client2 = new SimpleRESTfullClient("https://162.105.140.119:8443/mds", "PKULIB.IR", "luopengcheng","localhost.keystore"); +// System.out.println(client2.getUrl("10.1/1.0002")); +// System.out.println(client2.getUrl("10.1/1.0002")); +// System.out.println(client2.getMetadata(doi2)); +// client2.postUrl("10.1/1.0003", "http://ir.pku.edu.cn"); +// System.out.println(client2.postUrl("10.1/1.0008", "http://ir.pku.edu.cn")); +// System.out.println(client2.postMetadata(FileUtil.loadAsString(new File("C:/Users/luopc/Desktop/test/datacite-example-ResourceTypeGeneral_Collection-v3.0.xml"), "utf-8"))); +// System.out.println(client2.getMetadata("10.1/1.0007")); +// System.out.println(client2.inactiveDataSet("10.1/1.0007")); +// client2.close(); +} + + +// private static String readAndClose(String file, String encoding) throws IOException{ +// BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file),encoding)); +// StringBuilder str = new StringBuilder(); +// String line; +// while((line = in.readLine()) != null){ +// str.append(line); +// } +// in.close(); +// return str.toString(); +// } + +} diff --git a/src/main/java/edu/harvard/iq/dataverse/DatasetAuthor.java b/src/main/java/edu/harvard/iq/dataverse/DatasetAuthor.java index 59e4549511f..b1f1e4b459c 100644 --- a/src/main/java/edu/harvard/iq/dataverse/DatasetAuthor.java +++ b/src/main/java/edu/harvard/iq/dataverse/DatasetAuthor.java @@ -60,7 +60,11 @@ public void setAffiliation(DatasetField affiliation) { private String idType; public String getIdType() { - return idType; + if ((this.idType == null || this.idType.isEmpty()) && (this.idValue != null && !this.idValue.isEmpty())){ + return ("ORCID"); + } else { + return idType; + } } public void setIdType(String idType) { @@ -76,11 +80,6 @@ public String getIdValue() { public void setIdValue(String idValue) { this.idValue = idValue; - if (!this.idValue.isEmpty()){ - setIdType("ORCID"); - } else { - setIdType(""); - } } public boolean isEmpty() { diff --git a/src/main/java/edu/harvard/iq/dataverse/DatasetFieldConstant.java b/src/main/java/edu/harvard/iq/dataverse/DatasetFieldConstant.java index 008c3e99fa1..f5275873b4c 100644 --- a/src/main/java/edu/harvard/iq/dataverse/DatasetFieldConstant.java +++ b/src/main/java/edu/harvard/iq/dataverse/DatasetFieldConstant.java @@ -52,8 +52,8 @@ public class DatasetFieldConstant implements java.io.Serializable { public final static String datasetId = "datasetId"; public final static String authorName ="authorName"; public final static String authorAffiliation = "authorAffiliation"; - public final static String authorIdType = "authorIdType"; - public final static String authorIdValue = "authorIdValue"; + public final static String authorIdType = "authorIdentifierScheme"; + public final static String authorIdValue = "authorIdentifier"; public final static String otherIdValue="otherIdValue"; public final static String otherIdAgency= "otherIdAgency"; diff --git a/src/main/java/edu/harvard/iq/dataverse/DatasetPage.java b/src/main/java/edu/harvard/iq/dataverse/DatasetPage.java index c72e9b5cc65..26fc4080119 100644 --- a/src/main/java/edu/harvard/iq/dataverse/DatasetPage.java +++ b/src/main/java/edu/harvard/iq/dataverse/DatasetPage.java @@ -79,6 +79,7 @@ import java.util.logging.Level; import javax.faces.component.UIComponent; import javax.faces.component.UIInput; +import javax.faces.context.ExternalContext; import org.primefaces.component.tabview.TabView; import org.primefaces.event.TabChangeEvent; import org.primefaces.model.LazyDataModel; @@ -1267,7 +1268,8 @@ public boolean isGeoconnectDebugAvailable(){ if (!this.isSuperUser()){ return false; } - if (settingsService.isTrueForKey(SettingsServiceBean.Key.GeoconnectDebug, true)){ + + if (settingsService.isTrueForKey(SettingsServiceBean.Key.GeoconnectDebug, false)){ return true; } return false; @@ -1643,7 +1645,7 @@ public String saveGuestbookResponse(String type) { } callDownloadServlet(downloadFormat, this.selectedDownloadFile.getId()); } - + if (type.equals("explore")) { String retVal = getDataExploreURLComplete(this.selectedDownloadFile.getId()); try { @@ -2038,7 +2040,7 @@ private String releaseDataset(boolean minor) { cmd = new PublishDatasetCommand(dataset, dvRequestService.getDataverseRequest(), minor); } dataset = commandEngine.submit(cmd); - JsfHelper.addSuccessMessage(JH.localize("dataset.message.publishSuccess")); + JsfHelper.addSuccessMessage(BundleUtil.getStringFromBundle("dataset.message.publishSuccess")); if (notifyPublish) { List authUsers = permissionService.getUsersWithPermissionOn(Permission.PublishDataset, dataset); List editUsers = permissionService.getUsersWithPermissionOn(Permission.EditDataset, dataset); @@ -2050,11 +2052,13 @@ private String releaseDataset(boolean minor) { } } } catch (CommandException ex) { - JH.addMessage(FacesMessage.SEVERITY_FATAL, JH.localize("dataset.message.publishFailure")); + + JsfHelper.addErrorMessage(ex.getLocalizedMessage()); logger.severe(ex.getMessage()); } } else { - JH.addMessage(FacesMessage.SEVERITY_ERROR, "Only authenticated users can release Datasets."); + + JsfHelper.addErrorMessage(BundleUtil.getStringFromBundle("dataset.message.only.authenticatedUsers")); } return returnToDatasetOnly(); } @@ -2082,8 +2086,10 @@ public void refresh() { logger.fine("refreshing"); //dataset = datasetService.find(dataset.getId()); + dataset = null; + logger.fine("refreshing working version"); DatasetVersionServiceBean.RetrieveDatasetVersionResponse retrieveDatasetVersionResponse = null; @@ -2112,15 +2118,20 @@ public void refresh() { if (this.workingVersion == null) { // TODO: // same as the above + return; } + if (dataset == null) { // this would be the case if we were retrieving the version by // the versionId, above. this.dataset = this.workingVersion.getDataset(); } + + + if (readOnly) { datafileService.findFileMetadataOptimizedExperimental(dataset); fileMetadatasSearch = workingVersion.getFileMetadatas(); @@ -2315,8 +2326,19 @@ public String getSelectedFilesIdsString() { } downloadIdString += fmd.getDataFile().getId(); } - return downloadIdString; - + return downloadIdString; + } + + // helper Method + public String getSelectedFilesIdsStringForDownload() { + String downloadIdString = ""; + for (FileMetadata fmd : this.selectedFiles){ + if (!StringUtil.isEmpty(downloadIdString)) { + downloadIdString += ","; + } + downloadIdString += fmd.getDataFile().getId(); + } + return downloadIdString; } public String getDownloadableFilesIdsString() { @@ -2815,6 +2837,18 @@ public void refreshLock() { /* */ + + public boolean isLockedInProgress() { + if (dataset != null) { + logger.fine("checking lock status of dataset " + dataset.getId()); + if (dataset.isLocked()) { + return true; + } + } + return false; + } + + public boolean isStillLocked() { if (dataset != null && dataset.getId() != null) { logger.fine("checking lock status of dataset " + dataset.getId()); @@ -2831,6 +2865,7 @@ public boolean isLocked() { } if (dataset != null) { + if (dataset.isLocked()) { return true; } diff --git a/src/main/java/edu/harvard/iq/dataverse/DatasetVersion.java b/src/main/java/edu/harvard/iq/dataverse/DatasetVersion.java index 5e69998b096..311851eda6b 100644 --- a/src/main/java/edu/harvard/iq/dataverse/DatasetVersion.java +++ b/src/main/java/edu/harvard/iq/dataverse/DatasetVersion.java @@ -1,5 +1,6 @@ package edu.harvard.iq.dataverse; +import edu.harvard.iq.dataverse.util.MarkupChecker; import edu.harvard.iq.dataverse.DatasetFieldType.FieldType; import edu.harvard.iq.dataverse.util.StringUtil; import java.io.Serializable; @@ -600,14 +601,92 @@ public String getProductionDate() { //todo get "Production Date" from datasetfieldvalue table return "Production Date"; } + + public String getDescription() { + for (DatasetField dsf : this.getDatasetFields()) { + if (dsf.getDatasetFieldType().getName().equals(DatasetFieldConstant.description)) { + String descriptionString = ""; + if (dsf.getDatasetFieldCompoundValues() != null && dsf.getDatasetFieldCompoundValues().get(0) != null) { + DatasetFieldCompoundValue descriptionValue = dsf.getDatasetFieldCompoundValues().get(0); + for (DatasetField subField : descriptionValue.getChildDatasetFields()) { + if (subField.getDatasetFieldType().getName().equals(DatasetFieldConstant.descriptionText) && !subField.isEmptyForDisplay()) { + descriptionString = subField.getValue(); + } + } + } + return MarkupChecker.sanitizeBasicHTML(descriptionString); + } + } + return ""; + } + + public List getDatasetContacts(){ + List retList = new ArrayList<>(); + for (DatasetField dsf : this.getDatasetFields()) { + Boolean addContributor = true; + String contributorName = ""; + String contributorAffiliation = ""; + if (dsf.getDatasetFieldType().getName().equals(DatasetFieldConstant.datasetContact)) { + for (DatasetFieldCompoundValue authorValue : dsf.getDatasetFieldCompoundValues()) { + for (DatasetField subField : authorValue.getChildDatasetFields()) { + if (subField.getDatasetFieldType().getName().equals(DatasetFieldConstant.datasetContactName)) { + if (subField.isEmptyForDisplay()) { + addContributor = false; + } + contributorName = subField.getDisplayValue(); + } + if (subField.getDatasetFieldType().getName().equals(DatasetFieldConstant.datasetContactAffiliation)) { + contributorAffiliation = subField.getDisplayValue(); + } + + } + if (addContributor) { + String[] datasetContributor = new String[] {contributorName, contributorAffiliation}; + retList.add(datasetContributor); + } + } + } + } + return retList; + } + + public List getDatasetProducers(){ + List retList = new ArrayList<>(); + for (DatasetField dsf : this.getDatasetFields()) { + Boolean addContributor = true; + String contributorName = ""; + String contributorAffiliation = ""; + if (dsf.getDatasetFieldType().getName().equals(DatasetFieldConstant.producer)) { + for (DatasetFieldCompoundValue authorValue : dsf.getDatasetFieldCompoundValues()) { + for (DatasetField subField : authorValue.getChildDatasetFields()) { + if (subField.getDatasetFieldType().getName().equals(DatasetFieldConstant.producerName)) { + if (subField.isEmptyForDisplay()) { + addContributor = false; + } + contributorName = subField.getDisplayValue(); + } + if (subField.getDatasetFieldType().getName().equals(DatasetFieldConstant.producerAffiliation)) { + contributorAffiliation = subField.getDisplayValue(); + } + + } + if (addContributor) { + String[] datasetContributor = new String[] {contributorName, contributorAffiliation}; + retList.add(datasetContributor); + } + } + } + } + return retList; + } public List getDatasetAuthors() { //todo get "List of Authors" from datasetfieldvalue table - List retList = new ArrayList(); + List retList = new ArrayList<>(); for (DatasetField dsf : this.getDatasetFields()) { Boolean addAuthor = true; if (dsf.getDatasetFieldType().getName().equals(DatasetFieldConstant.author)) { - for (DatasetFieldCompoundValue authorValue : dsf.getDatasetFieldCompoundValues()) { + for (DatasetFieldCompoundValue authorValue : dsf.getDatasetFieldCompoundValues()) { DatasetAuthor datasetAuthor = new DatasetAuthor(); for (DatasetField subField : authorValue.getChildDatasetFields()) { if (subField.getDatasetFieldType().getName().equals(DatasetFieldConstant.authorName)) { @@ -619,8 +698,14 @@ public List getDatasetAuthors() { if (subField.getDatasetFieldType().getName().equals(DatasetFieldConstant.authorAffiliation)) { datasetAuthor.setAffiliation(subField); } + if (subField.getDatasetFieldType().getName().equals(DatasetFieldConstant.authorIdType)){ + datasetAuthor.setIdType(subField.getDisplayValue()); + } + if (subField.getDatasetFieldType().getName().equals(DatasetFieldConstant.authorIdValue)){ + datasetAuthor.setIdValue(subField.getDisplayValue()); + } } - if (addAuthor) { + if (addAuthor) { retList.add(datasetAuthor); } } diff --git a/src/main/java/edu/harvard/iq/dataverse/EjbDataverseEngine.java b/src/main/java/edu/harvard/iq/dataverse/EjbDataverseEngine.java index c659e6515f5..baac2a13037 100644 --- a/src/main/java/edu/harvard/iq/dataverse/EjbDataverseEngine.java +++ b/src/main/java/edu/harvard/iq/dataverse/EjbDataverseEngine.java @@ -95,6 +95,9 @@ public class EjbDataverseEngine { @EJB DOIEZIdServiceBean doiEZId; + @EJB + DOIDataCiteServiceBean doiDataCite; + @EJB HandlenetServiceBean handleNet; @@ -305,6 +308,11 @@ public DOIEZIdServiceBean doiEZId() { return doiEZId; } + @Override + public DOIDataCiteServiceBean doiDataCite() { + return doiDataCite; + } + @Override public HandlenetServiceBean handleNet() { return handleNet; diff --git a/src/main/java/edu/harvard/iq/dataverse/engine/command/CommandContext.java b/src/main/java/edu/harvard/iq/dataverse/engine/command/CommandContext.java index 5ee56e78cb0..2bf5e719c5f 100644 --- a/src/main/java/edu/harvard/iq/dataverse/engine/command/CommandContext.java +++ b/src/main/java/edu/harvard/iq/dataverse/engine/command/CommandContext.java @@ -1,5 +1,6 @@ package edu.harvard.iq.dataverse.engine.command; +import edu.harvard.iq.dataverse.DOIDataCiteServiceBean; import edu.harvard.iq.dataverse.DOIEZIdServiceBean; import edu.harvard.iq.dataverse.HandlenetServiceBean; import edu.harvard.iq.dataverse.DataFileServiceBean; @@ -75,6 +76,8 @@ public interface CommandContext { public DOIEZIdServiceBean doiEZId(); + public DOIDataCiteServiceBean doiDataCite(); + public HandlenetServiceBean handleNet(); public GuestbookServiceBean guestbooks(); diff --git a/src/main/java/edu/harvard/iq/dataverse/engine/command/DataverseRequest.java b/src/main/java/edu/harvard/iq/dataverse/engine/command/DataverseRequest.java index c4643c0c206..f6624d03cc1 100644 --- a/src/main/java/edu/harvard/iq/dataverse/engine/command/DataverseRequest.java +++ b/src/main/java/edu/harvard/iq/dataverse/engine/command/DataverseRequest.java @@ -58,6 +58,7 @@ As of now (4.2.3), this is the ONLY situation where we check the remote -- L.A. 4.2.3 */ + logger.fine("DataverseRequest: Obtained remote address: "+remoteAddressStr); if ( remoteAddressStr == null ) { diff --git a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/CreateDatasetCommand.java b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/CreateDatasetCommand.java index db27b9d408b..8684338bc7b 100644 --- a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/CreateDatasetCommand.java +++ b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/CreateDatasetCommand.java @@ -139,21 +139,32 @@ public Dataset execute(CommandContext ctxt) throws CommandException { theDataset.setIdentifier(ctxt.datasets().generateIdentifierSequence(theDataset.getProtocol(), theDataset.getAuthority(), theDataset.getDoiSeparator())); } // Attempt the registration if importing dataset through the API, or the app (but not harvest or migrate) - if ((importType==null || importType.equals(ImportType.NEW)) - && protocol.equals("doi") - && doiProvider.equals("EZID") - && theDataset.getGlobalIdCreateTime() == null) { - String doiRetString = ctxt.doiEZId().createIdentifier(theDataset); - // Check return value to make sure registration succeeded - if (doiRetString.contains(theDataset.getIdentifier())) { - theDataset.setGlobalIdCreateTime(createDate); - } - } else { - // If harvest or migrate, and this is a released dataset, we don't need to register, - // so set the globalIdCreateTime to now - if (theDataset.getLatestVersion().getVersionState().equals(VersionState.RELEASED) ){ - theDataset.setGlobalIdCreateTime(new Date()); + if ((importType == null || importType.equals(ImportType.NEW)) + && theDataset.getGlobalIdCreateTime() == null) { + if (protocol.equals("doi")) { + String doiRetString = ""; + if (doiProvider.equals("EZID")) { + doiRetString = ctxt.doiEZId().createIdentifier(theDataset); + } + if (doiProvider.equals("DataCite")) { + try{ + doiRetString = ctxt.doiDataCite().createIdentifier(theDataset); + } catch (Exception e){ + logger.log(Level.WARNING, "Exception while creating Identifier:" + e.getMessage(), e); + } + } + + // Check return value to make sure registration succeeded + if (doiProvider.equals("EZID") && doiRetString.contains(theDataset.getIdentifier())) { + theDataset.setGlobalIdCreateTime(createDate); + } + } + + } else // If harvest or migrate, and this is a released dataset, we don't need to register, + // so set the globalIdCreateTime to now + if (theDataset.getLatestVersion().getVersionState().equals(VersionState.RELEASED)) { + theDataset.setGlobalIdCreateTime(new Date()); } if (registrationRequired && theDataset.getGlobalIdCreateTime() == null) { diff --git a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/DeaccessionDatasetVersionCommand.java b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/DeaccessionDatasetVersionCommand.java index 8daa4b9938f..625b82319a1 100644 --- a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/DeaccessionDatasetVersionCommand.java +++ b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/DeaccessionDatasetVersionCommand.java @@ -15,6 +15,9 @@ import edu.harvard.iq.dataverse.engine.command.DataverseRequest; import edu.harvard.iq.dataverse.engine.command.RequiredPermissions; import edu.harvard.iq.dataverse.engine.command.exception.CommandException; +import edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException; +import edu.harvard.iq.dataverse.settings.SettingsServiceBean; +import java.util.ResourceBundle; /** * @@ -40,9 +43,25 @@ public DatasetVersion execute(CommandContext ctxt) throws CommandException { theVersion.setVersionState(DatasetVersion.VersionState.DEACCESSIONED); - if (deleteDOIIdentifier){ - ctxt.doiEZId().deleteIdentifier(ds); - } + if (deleteDOIIdentifier) { + String nonNullDefaultIfKeyNotFound = ""; + + String doiProvider = ctxt.settings().getValueForKey(SettingsServiceBean.Key.DoiProvider, nonNullDefaultIfKeyNotFound); + + if (doiProvider.equals("EZID")) { + ctxt.doiEZId().deleteIdentifier(ds); + } + if (doiProvider.equals("DataCite")) { + try { + ctxt.doiDataCite().deleteIdentifier(ds); + } catch (Exception e) { + if (e.toString().contains("Internal Server Error")) { + throw new CommandException(ResourceBundle.getBundle("Bundle").getString("dataset.publish.error.datacite"), this); + } + throw new CommandException(ResourceBundle.getBundle("Bundle").getString("dataset.delete.error.datacite"), this); + } + } + } DatasetVersion managed = ctxt.em().merge(theVersion); boolean doNormalSolrDocCleanUp = true; diff --git a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/DestroyDatasetCommand.java b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/DestroyDatasetCommand.java index d74ffae9020..1f27ba0a199 100644 --- a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/DestroyDatasetCommand.java +++ b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/DestroyDatasetCommand.java @@ -16,6 +16,7 @@ import edu.harvard.iq.dataverse.engine.command.exception.CommandException; import edu.harvard.iq.dataverse.engine.command.exception.PermissionException; import edu.harvard.iq.dataverse.search.IndexResponse; +import edu.harvard.iq.dataverse.settings.SettingsServiceBean; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; @@ -78,7 +79,12 @@ protected void executeImpl(CommandContext ctxt) throws CommandException { // ROLES for (DataverseRole ra : ctxt.roles().findByOwnerId(doomed.getId())) { ctxt.em().remove(ra); - } + } + + //Register Cache + if(ctxt.settings().getValueForKey(SettingsServiceBean.Key.DoiProvider, "").equals("DataCite")){ + ctxt.doiDataCite().deleteRecordFromCache(doomed); + } Dataverse toReIndex = managedDoomed.getOwner(); diff --git a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/PublishDatasetCommand.java b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/PublishDatasetCommand.java index 2a20aeec15c..36792f20054 100644 --- a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/PublishDatasetCommand.java +++ b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/PublishDatasetCommand.java @@ -24,15 +24,16 @@ import edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException; import edu.harvard.iq.dataverse.search.IndexResponse; import edu.harvard.iq.dataverse.settings.SettingsServiceBean; +import java.io.IOException; import java.sql.Timestamp; import java.util.Date; import java.util.List; +import java.util.ResourceBundle; /** * * @author skraffmiller */ - @RequiredPermissions(Permission.PublishDataset) public class PublishDatasetCommand extends AbstractCommand { @@ -58,43 +59,63 @@ public Dataset execute(CommandContext ctxt) throws CommandException { if (!theDataset.getOwner().isReleased()) { throw new IllegalCommandException("This dataset may not be published because its host dataverse (" + theDataset.getOwner().getAlias() + ") has not been published.", this); } + + if (theDataset.getLatestVersion().isReleased()) { + throw new IllegalCommandException("Latest version of dataset " + theDataset.getIdentifier() + " is already released. Only draft versions can be released.", this); + } + + if (minorRelease && !theDataset.getLatestVersion().isMinorUpdate()) { + throw new IllegalCommandException("Cannot release as minor version. Re-try as major release.", this); + } /* make an attempt to register if not registered */ String nonNullDefaultIfKeyNotFound = ""; - String protocol = theDataset.getProtocol(); - String doiProvider = ctxt.settings().getValueForKey(SettingsServiceBean.Key.DoiProvider, nonNullDefaultIfKeyNotFound); - String authority = theDataset.getAuthority(); + String protocol = theDataset.getProtocol(); + String doiProvider = ctxt.settings().getValueForKey(SettingsServiceBean.Key.DoiProvider, nonNullDefaultIfKeyNotFound); + String authority = theDataset.getAuthority(); if (theDataset.getGlobalIdCreateTime() == null) { if (protocol.equals("doi") - && doiProvider.equals("EZID")) { - String doiRetString = ctxt.doiEZId().createIdentifier(theDataset); - if (doiRetString.contains(theDataset.getIdentifier())) { - theDataset.setGlobalIdCreateTime(new Timestamp(new Date().getTime())); - } else { - if (doiRetString.contains("identifier already exists")){ + && (doiProvider.equals("EZID") || doiProvider.equals("DataCite"))) { + String doiRetString = ""; + if (doiProvider.equals("EZID")) { + doiRetString = ctxt.doiEZId().createIdentifier(theDataset); + if (doiRetString.contains(theDataset.getIdentifier())) { + theDataset.setGlobalIdCreateTime(new Timestamp(new Date().getTime())); + } else if (doiRetString.contains("identifier already exists")) { theDataset.setIdentifier(ctxt.datasets().generateIdentifierSequence(protocol, authority, theDataset.getDoiSeparator())); doiRetString = ctxt.doiEZId().createIdentifier(theDataset); - if(!doiRetString.contains(theDataset.getIdentifier())){ + if (!doiRetString.contains(theDataset.getIdentifier())) { throw new IllegalCommandException("This dataset may not be published because its identifier is already in use by another dataset. Please contact Dataverse Support for assistance.", this); - } else{ + } else { theDataset.setGlobalIdCreateTime(new Timestamp(new Date().getTime())); } } else { - throw new IllegalCommandException("This dataset may not be published because it has not been registered. Please contact Dataverse Support for assistance.", this); + throw new IllegalCommandException("This dataset may not be published because it has not been registered. Please contact Dataverse Support for assistance.", this); + } + } + + if (doiProvider.equals("DataCite")) { + try { + if (!ctxt.doiDataCite().alreadyExists(theDataset)) { + ctxt.doiDataCite().createIdentifier(theDataset); + theDataset.setGlobalIdCreateTime(new Timestamp(new Date().getTime())); + } else { + theDataset.setIdentifier(ctxt.datasets().generateIdentifierSequence(protocol, authority, theDataset.getDoiSeparator())); + if (!ctxt.doiDataCite().alreadyExists(theDataset)) { + ctxt.doiDataCite().createIdentifier(theDataset); + theDataset.setGlobalIdCreateTime(new Timestamp(new Date().getTime())); + } else { + throw new IllegalCommandException("This dataset may not be published because its identifier is already in use by another dataset. Please contact Dataverse Support for assistance.", this); + } + } + } catch (Exception e) { + throw new CommandException(ResourceBundle.getBundle("Bundle").getString("dataset.publish.error.datacite"), this); } } } else { - throw new IllegalCommandException("This dataset may not be published because its DOI provider is not supported. Please contact Dataverse Support for assistance.", this); + throw new IllegalCommandException("This dataset may not be published because its DOI provider is not supported. Please contact Dataverse Support for assistance.", this); } } - - if (theDataset.getLatestVersion().isReleased()) { - throw new IllegalCommandException("Latest version of dataset " + theDataset.getIdentifier() + " is already released. Only draft versions can be released.", this); - } - - if (minorRelease && !theDataset.getLatestVersion().isMinorUpdate()) { - throw new IllegalCommandException("Cannot release as minor version. Re-try as major release.", this); - } - + if (theDataset.getPublicationDate() == null) { //Before setting dataset to released send notifications to users with download file List ras = ctxt.roles().directRoleAssignments(theDataset); @@ -114,17 +135,14 @@ public Dataset execute(CommandContext ctxt) throws CommandException { theDataset.getEditVersion().setVersionNumber(new Long(0)); theDataset.getEditVersion().setMinorVersionNumber(new Long(1)); } + } else if (!minorRelease) { + theDataset.getEditVersion().setVersionNumber(new Long(theDataset.getVersionNumber() + 1)); + theDataset.getEditVersion().setMinorVersionNumber(new Long(0)); } else { - if (!minorRelease) { - theDataset.getEditVersion().setVersionNumber(new Long(theDataset.getVersionNumber() + 1)); - theDataset.getEditVersion().setMinorVersionNumber(new Long(0)); - } else { - theDataset.getEditVersion().setVersionNumber(new Long(theDataset.getVersionNumber())); - theDataset.getEditVersion().setMinorVersionNumber(new Long(theDataset.getMinorVersionNumber() + 1)); - } + theDataset.getEditVersion().setVersionNumber(new Long(theDataset.getVersionNumber())); + theDataset.getEditVersion().setMinorVersionNumber(new Long(theDataset.getMinorVersionNumber() + 1)); } - Timestamp updateTime = new Timestamp(new Date().getTime()); theDataset.getEditVersion().setReleaseTime(updateTime); theDataset.getEditVersion().setLastUpdateTime(updateTime); @@ -137,18 +155,18 @@ public Dataset execute(CommandContext ctxt) throws CommandException { if (dataFile.getPublicationDate() == null) { // this is a new, previously unpublished file, so publish by setting date dataFile.setPublicationDate(updateTime); - + // check if any prexisting roleassignments have file download and send notifications List ras = ctxt.roles().directRoleAssignments(dataFile); for (RoleAssignment ra : ras) { if (ra.getRole().permissions().contains(Permission.DownloadFile)) { for (AuthenticatedUser au : ctxt.roleAssignees().getExplicitUsers(ctxt.roleAssignees().getRoleAssignee(ra.getAssigneeIdentifier()))) { - ctxt.notifications().sendNotification(au, new Timestamp(new Date().getTime()), UserNotification.Type.GRANTFILEACCESS, theDataset.getId()); + ctxt.notifications().sendNotification(au, new Timestamp(new Date().getTime()), UserNotification.Type.GRANTFILEACCESS, theDataset.getId()); } } - } + } } - + // set the files restriction flag to the same as the latest version's if (dataFile.getFileMetadata() != null && dataFile.getFileMetadata().getDatasetVersion().equals(theDataset.getLatestVersion())) { dataFile.setRestricted(dataFile.getFileMetadata().isRestricted()); @@ -158,23 +176,13 @@ public Dataset execute(CommandContext ctxt) throws CommandException { theDataset.setFileAccessRequest(theDataset.getLatestVersion().getTermsOfUseAndAccess().isFileAccessRequest()); Dataset savedDataset = ctxt.em().merge(theDataset); - boolean doNormalSolrDocCleanUp = true; - ctxt.index().indexDataset(savedDataset, doNormalSolrDocCleanUp); - /** - * @todo consider also ctxt.solrIndex().indexPermissionsOnSelfAndChildren(theDataset); - */ - /** - * @todo what should we do with the indexRespose? - */ - IndexResponse indexResponse = ctxt.solrIndex().indexPermissionsForOneDvObject(savedDataset); - // set the subject of the parent (all the way up) Dataverses DatasetField subject = null; for (DatasetField dsf : savedDataset.getLatestVersion().getDatasetFields()) { if (dsf.getDatasetFieldType().getName().equals(DatasetFieldConstant.subject)) { subject = dsf; break; - } + } } if (subject != null) { Dataverse dv = savedDataset.getOwner(); @@ -184,9 +192,8 @@ public Dataset execute(CommandContext ctxt) throws CommandException { } dv = dv.getOwner(); } - } - - + } + DatasetVersionUser ddu = ctxt.datasets().getDatasetVersionUser(savedDataset.getLatestVersion(), this.getUser()); if (ddu != null) { @@ -203,7 +210,39 @@ public Dataset execute(CommandContext ctxt) throws CommandException { ctxt.em().merge(datasetDataverseUser); } - ctxt.doiEZId().publicizeIdentifier(savedDataset); + if (protocol.equals("doi") + && doiProvider.equals("EZID")) { + ctxt.doiEZId().publicizeIdentifier(savedDataset); + } + if (protocol.equals("doi") + && doiProvider.equals("DataCite")) { + try { + ctxt.doiDataCite().publicizeIdentifier(savedDataset); + } catch (IOException io) { + throw new CommandException(ResourceBundle.getBundle("Bundle").getString("dataset.publish.error.datacite"), this); + } catch (Exception e) { + if (e.toString().contains("Internal Server Error")) { + throw new CommandException(ResourceBundle.getBundle("Bundle").getString("dataset.publish.error.datacite"), this); + } + throw new CommandException(ResourceBundle.getBundle("Bundle").getString("dataset.publish.error.datacite"), this); + } + } + + /* + MoveIndexing to after DOI update so that if command exception is thrown the re-index will not + + */ + + boolean doNormalSolrDocCleanUp = true; + ctxt.index().indexDataset(savedDataset, doNormalSolrDocCleanUp); + /** + * @todo consider also ctxt.solrIndex().indexPermissionsOnSelfAndChildren(theDataset); + */ + /** + * @todo what should we do with the indexRespose? + */ + IndexResponse indexResponse = ctxt.solrIndex().indexPermissionsForOneDvObject(savedDataset); + return savedDataset; } diff --git a/src/main/java/edu/harvard/iq/dataverse/settings/SettingsServiceBean.java b/src/main/java/edu/harvard/iq/dataverse/settings/SettingsServiceBean.java index 88124737f9c..befc5a8a607 100644 --- a/src/main/java/edu/harvard/iq/dataverse/settings/SettingsServiceBean.java +++ b/src/main/java/edu/harvard/iq/dataverse/settings/SettingsServiceBean.java @@ -2,7 +2,7 @@ import edu.harvard.iq.dataverse.actionlogging.ActionLogRecord; import edu.harvard.iq.dataverse.actionlogging.ActionLogServiceBean; -import edu.harvard.iq.dataverse.api.ApiBlockingFilter; +//import edu.harvard.iq.dataverse.api.ApiBlockingFilter; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; diff --git a/src/main/resources/edu/harvard/iq/dataverse/datacite_metadata_template.xml b/src/main/resources/edu/harvard/iq/dataverse/datacite_metadata_template.xml new file mode 100644 index 00000000000..c11e18b49ee --- /dev/null +++ b/src/main/resources/edu/harvard/iq/dataverse/datacite_metadata_template.xml @@ -0,0 +1,17 @@ + + + ${identifier} + ${creators} + + ${title} + + ${publisher} + ${publisherYear} + + + ${description} + + {$contributors} + diff --git a/src/main/webapp/dataset.xhtml b/src/main/webapp/dataset.xhtml index 3491e516531..3a2c478eb47 100755 --- a/src/main/webapp/dataset.xhtml +++ b/src/main/webapp/dataset.xhtml @@ -1257,11 +1257,6 @@ - -

- #{bundle['dataset.unregistered.tip']} -

-

#{bundle['dataset.publish.tip']}

@@ -1275,11 +1270,6 @@
- -

- #{bundle['dataset.unregistered.tip']} -

-

diff --git a/src/main/webapp/resources/iqbs/messages.xhtml b/src/main/webapp/resources/iqbs/messages.xhtml index 5c376fc6a0c..6dfafef95e8 100644 --- a/src/main/webapp/resources/iqbs/messages.xhtml +++ b/src/main/webapp/resources/iqbs/messages.xhtml @@ -1,12 +1,12 @@ + xmlns:cc="http://java.sun.com/jsf/composite" + xmlns:ui="http://java.sun.com/jsf/facelets" + xmlns:p="http://primefaces.org/ui" + xmlns:fn="http://java.sun.com/jsp/jstl/functions" + xmlns:o="http://omnifaces.org/ui" + xmlns:f="http://xmlns.jcp.org/jsf/core"> @@ -15,25 +15,25 @@

-  Success! -
+  Success! +
 Error - Please . -
-
+ Please contact Dataverse Support for assistance. + +
-  Info -
-
+  Info + +
-  Info -
-
+  Info + +
 Validation Error – Required fields were missed or there was a validation error. Please scroll down to see details. @@ -47,8 +47,8 @@  #{msg.summary}  - - Please . + + Please contact Dataverse Support for assistance. Date/Time: diff --git a/src/test/java/edu/harvard/iq/dataverse/engine/TestCommandContext.java b/src/test/java/edu/harvard/iq/dataverse/engine/TestCommandContext.java index 5cfc27bb2b1..10a7edfdf3d 100644 --- a/src/test/java/edu/harvard/iq/dataverse/engine/TestCommandContext.java +++ b/src/test/java/edu/harvard/iq/dataverse/engine/TestCommandContext.java @@ -99,7 +99,12 @@ public DataverseFieldTypeInputLevelServiceBean fieldTypeInputLevels() { public DOIEZIdServiceBean doiEZId() { return null; } - + + @Override + public DOIDataCiteServiceBean doiDataCite() { + return null; + } + @Override public HandlenetServiceBean handleNet() { return null;