Skip to content

Commit

Permalink
got rid of an inefficient/unnecessary instance of .replaceAll() (#8372)
Browse files Browse the repository at this point in the history
  • Loading branch information
landreev committed Jul 13, 2022
1 parent 088d9b8 commit f81a010
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public class HarvesterServiceBean {
public static final String HARVEST_RESULT_SUCCESS="success";
public static final String HARVEST_RESULT_FAILED="failed";
public static final String DATAVERSE_PROPRIETARY_METADATA_FORMAT="dataverse_json";
public static final String DATAVERSE_PROPRIETARY_METADATA_API="/api/datasets/export?exporter="+DATAVERSE_PROPRIETARY_METADATA_FORMAT;
public static final String DATAVERSE_PROPRIETARY_METADATA_API="/api/datasets/export?exporter="+DATAVERSE_PROPRIETARY_METADATA_FORMAT+"&persistentId=";

public HarvesterServiceBean() {

Expand Down Expand Up @@ -302,8 +302,9 @@ private Long processRecord(DataverseRequest dataverseRequest, Logger hdLogger, P
if (DATAVERSE_PROPRIETARY_METADATA_FORMAT.equals(oaiHandler.getMetadataPrefix())) {
// Make direct call to obtain the proprietary Dataverse metadata
// in JSON from the remote Dataverse server:
String extendedApiUrl = getProprietaryDataverseMetadataURL(oaiHandler.getBaseOaiUrl(), identifier);
tempFile = retrieveProprietaryDataverseMetadata(httpClient, extendedApiUrl);
String metadataApiUrl = oaiHandler.getProprietaryDataverseMetadataURL(identifier);
logger.info("calling "+metadataApiUrl);
tempFile = retrieveProprietaryDataverseMetadata(httpClient, metadataApiUrl);

} else {
FastGetRecord record = oaiHandler.runGetRecord(identifier);
Expand Down Expand Up @@ -409,18 +410,7 @@ private void deleteHarvestedDatasetIfExists(String persistentIdentifier, Dataver
}
hdLogger.info("No dataset found for " + persistentIdentifier + ", skipping delete. ");
}

private static String getProprietaryDataverseMetadataURL(String baseURL, String identifier) {

baseURL = baseURL.replaceAll("/oai", "");

StringBuilder requestURL = new StringBuilder(baseURL);
requestURL.append(DATAVERSE_PROPRIETARY_METADATA_API);
requestURL.append("&persistentId=").append(identifier);

return requestURL.toString();
}


private void logBeginOaiHarvest(Logger hdLogger, HarvestingClient harvestingClient) {
hdLogger.log(Level.INFO, "BEGIN HARVEST, oaiUrl="
+harvestingClient.getHarvestingUrl()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
package edu.harvard.iq.dataverse.harvest.client.oai;

import io.gdcc.xoai.model.oaipmh.results.Description;
import io.gdcc.xoai.model.oaipmh.Granularity;
import io.gdcc.xoai.model.oaipmh.results.record.Header;
import io.gdcc.xoai.model.oaipmh.results.MetadataFormat;
import io.gdcc.xoai.model.oaipmh.results.Set;
import io.gdcc.xoai.serviceprovider.ServiceProvider;
import io.gdcc.xoai.serviceprovider.client.JdkHttpOaiClient; //.HttpOAIClient;
import io.gdcc.xoai.serviceprovider.client.JdkHttpOaiClient;
import io.gdcc.xoai.serviceprovider.exceptions.BadArgumentException;
import io.gdcc.xoai.serviceprovider.exceptions.InvalidOAIResponse;
import io.gdcc.xoai.serviceprovider.exceptions.NoSetHierarchyException;
import io.gdcc.xoai.serviceprovider.exceptions.IdDoesNotExistException;
import io.gdcc.xoai.serviceprovider.model.Context;
import io.gdcc.xoai.serviceprovider.parameters.ListIdentifiersParameters;
import edu.harvard.iq.dataverse.harvest.client.FastGetRecord;
import static edu.harvard.iq.dataverse.harvest.client.HarvesterServiceBean.DATAVERSE_PROPRIETARY_METADATA_API;
import edu.harvard.iq.dataverse.harvest.client.HarvestingClient;
import java.io.IOException;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.commons.lang3.StringUtils;
import org.xml.sax.SAXException;
import javax.xml.transform.TransformerException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
Expand Down Expand Up @@ -70,8 +68,9 @@ public OaiHandler(HarvestingClient harvestingClient) throws OaiHandlerException
this.harvestingClient = harvestingClient;
}

private String baseOaiUrl; //= harvestingClient.getHarvestingUrl();
private String metadataPrefix; // = harvestingClient.getMetadataPrefix();
private String baseOaiUrl;
private String dataverseApiUrl; // if the remote server is a Dataverse and we access its native metadata
private String metadataPrefix;
private String setName;
private Date fromDate;
private Boolean setListTruncated = false;
Expand Down Expand Up @@ -120,7 +119,7 @@ public boolean isSetListTruncated() {
return setListTruncated;
}

private ServiceProvider getServiceProvider() throws OaiHandlerException {
public ServiceProvider getServiceProvider() throws OaiHandlerException {
if (serviceProvider == null) {
if (baseOaiUrl == null) {
throw new OaiHandlerException("Could not instantiate Service Provider, missing OAI server URL.");
Expand Down Expand Up @@ -277,6 +276,18 @@ private ListIdentifiersParameters buildListIdentifiersParams() throws OaiHandler
return mip;
}

public String getProprietaryDataverseMetadataURL(String identifier) {

if (dataverseApiUrl == null) {
dataverseApiUrl = baseOaiUrl.replaceFirst("/oai", "");
}

StringBuilder requestURL = new StringBuilder(dataverseApiUrl);
requestURL.append(DATAVERSE_PROPRIETARY_METADATA_API).append(identifier);

return requestURL.toString();
}

public void runIdentify() {
// not implemented yet
// (we will need it, both for validating the remote server,
Expand Down

0 comments on commit f81a010

Please sign in to comment.