73 lines
2.2 KiB
Java
73 lines
2.2 KiB
Java
/*
|
|
package unitest;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import eu.dnetlib.repo.manager.config.RepoManagerContextLoaderListener;
|
|
import org.apache.commons.lang.StringEscapeUtils;
|
|
import org.junit.Test;
|
|
import org.junit.runner.RunWith;
|
|
import org.springframework.context.annotation.ComponentScan;
|
|
import org.springframework.test.context.ContextConfiguration;
|
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
|
|
import java.io.IOException;
|
|
import java.io.UnsupportedEncodingException;
|
|
import java.net.URL;
|
|
import java.net.URLEncoder;
|
|
import java.util.Map;
|
|
|
|
@RunWith(SpringJUnit4ClassRunner.class)
|
|
@ContextConfiguration(classes = RepoManagerContextLoaderListener.class)
|
|
public class PiwikTest {
|
|
|
|
String analyticsURL = "https://analytics.openaire.eu/addsite.php?";
|
|
|
|
@Test
|
|
public void enableMetricsRepo1(){
|
|
|
|
String officialName = "BỘ SƯU TẬP SỐ";
|
|
String repoWebsite = "http://www.vnulib.edu.vn:8000/dspace/";
|
|
|
|
enableMetrics(officialName, repoWebsite, analyticsURL);
|
|
|
|
}
|
|
|
|
@Test
|
|
public void enableMetricsRepo2(){
|
|
|
|
String officialName = "ILC4CLARIN repository of language resources and tools";
|
|
String repoWebsite = "https://dspace-clarin-it.ilc.cnr.it/repository/xmlui";
|
|
|
|
enableMetrics(officialName, repoWebsite, analyticsURL);
|
|
}
|
|
|
|
@Test
|
|
public void enableMetricsRepo3(){
|
|
|
|
String officialName = "ANSTO Publications Online";
|
|
String repoWebsite = "http://apo.ansto.gov.au/dspace/";
|
|
|
|
enableMetrics(officialName, repoWebsite, analyticsURL);
|
|
}
|
|
|
|
private void enableMetrics(String officialName, String repoWebsite, String analyticsURL) {
|
|
String url;
|
|
try {
|
|
url = analyticsURL + "siteName=" + URLEncoder.encode(officialName, "UTF-8") + "&url="
|
|
+ URLEncoder.encode(repoWebsite, "UTF-8");
|
|
url = StringEscapeUtils.escapeJava(url);
|
|
|
|
Map map = null;
|
|
String siteId = null;
|
|
|
|
URL u = new URL(url);
|
|
map = new ObjectMapper().readValue(u, Map.class);
|
|
if(map.get("value")!=null) {
|
|
siteId = map.get("value").toString();
|
|
}
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}*/
|