Added resolver URL check for preprod.

This commit is contained in:
Luca Frosini 2019-12-19 14:13:44 +01:00
parent 78c60541d8
commit cbf7f04655
2 changed files with 31 additions and 1 deletions

View File

@ -63,6 +63,7 @@ public class CKANResource extends CKAN {
/* TODO Remove this code ASAP. It requires a function from Storage HUB */
private static final String URI_RESOLVER_STORAGE_HUB_HOST_PROD = "data.d4science.org";
private static final String URI_RESOLVER_STORAGE_HUB_HOST_PRE = "data-pre.d4science.org";
private static final String URI_RESOLVER_STORAGE_HUB_HOST_DEV = "data-d.d4science.org";
public static final String URI_RESOLVER_STORAGE_HUB_HOST;
@ -72,6 +73,8 @@ public class CKANResource extends CKAN {
String context = ContextUtility.getCurrentContext();
if(context.startsWith("/gcube")) {
URI_RESOLVER_STORAGE_HUB_HOST = URI_RESOLVER_STORAGE_HUB_HOST_DEV;
} else if(context.startsWith("/pred4s")){
URI_RESOLVER_STORAGE_HUB_HOST = URI_RESOLVER_STORAGE_HUB_HOST_PRE;
} else {
URI_RESOLVER_STORAGE_HUB_HOST = URI_RESOLVER_STORAGE_HUB_HOST_PROD;
}
@ -293,7 +296,7 @@ public class CKANResource extends CKAN {
try {
urlToCheck = getFinalURL(url);
} catch(Exception e) {
// TODO Evaluate if we want to validate the URL. If th URL does not exists the service
// TODO Evaluate if we want to validate the URL. If the URL does not exists the service
// could decide refuse the Resource Creation
}
if(urlToCheck.getHost().compareTo(URI_RESOLVER_STORAGE_HUB_HOST) == 0) {

View File

@ -1,6 +1,8 @@
package org.gcube.gcat.persistence.ckan;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.gcube.gcat.ContextTest;
@ -96,4 +98,29 @@ public class CKANResourceTest extends ContextTest {
Assert.assertTrue(format.compareTo("jpg") == 0);
}
@Test
public void testFinalURIResolverURL() throws Exception {
List<String> urlsString = new ArrayList<>();
urlsString.add("https://data-pre.d4science.net/wgsZ");
urlsString.add("https://data-dev.d4science.net/TzQv");
urlsString.add("https://data-d.d4science.org/shub/E_MkxMbitjYzY3R3VlTmp1cDF6cHVHY2w1Zk15RTdFakUrZnpKYXVLN1R6T0dtT1FXaXpIOHJmb2dSZ2p4WS9hYw==");
urlsString.add("https://data.d4science.net/Cuvn");
//urlsString.add("");
for(String urlString : urlsString) {
try {
URL url = CKANResource.getFinalURL(new URL(urlString));
System.out.println(urlString + " -> " + url.toString());
logger.debug("{} -> {}", urlString, url.toString());
}catch (Exception e) {
System.out.println("Error while getting final URL for " + urlString);
logger.debug("Error while getting final URL for {}", urlString);
}
}
}
}