Skip to content

Commit

Permalink
upload candidate version 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
amattioc committed Jun 19, 2018
1 parent 326f273 commit eee3c7b
Show file tree
Hide file tree
Showing 18 changed files with 90 additions and 39 deletions.
2 changes: 1 addition & 1 deletion BUILD
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20180504-1035
20180619-1557
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public abstract class BaseObservation<T> implements Serializable, Comparable<Bas
{
private static final long serialVersionUID = 1L;

protected final String timeslot;
protected String timeslot;
protected final Map<String, String> obsAttributes;

/**
Expand Down Expand Up @@ -83,17 +83,25 @@ public String getTimeslot()
{
return timeslot;
}

/**
* @param Set this observation's timestamp
*/
public void setTimeslot(String newTime)
{
this.timeslot = newTime;
}

/**
* @return This observation's value
*/
public abstract T getValue();

/**
* Get this observation's value as a {@code double} number.<br/>
* If either value is null, is not a {@link Number} instance, or if its {@link T#toString()} method returns an
* Get this observation's value as a {@code double} number.
* If either value is null, is not a {@link Number} instance, or if its {@link Object#toString() toString()} method returns an
* invalid number representation, a {@link Double#NaN} is returned instead.
* <p />
*
* <b>IMPLEMENTATION NOTE:</b> This method will cause major boxing/unboxing performance impact. It was implemented
* as a compatibility layer for other tools. Please use the specialized instances for series based on primitive types.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,12 @@ public String buildDataURL(Dataflow dataflow, String resource,
* @return the client name
*/
public String getName();

/**
* <p>Sets the name of this client
* @param name the name of this client
*/

public void setName(String name);

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public class LongObservation extends BaseObservation<Long>
* @param timeslot The timestamp of the observation.
* @param value The value of the observation
* @param obsAttributes A map of observation-level attributes.
* @param frequency The frequency of the series.
*/
public LongObservation(String timeslot, long value, Map<String, String> obsAttributes)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ public void addDimension(String dimension)
* @deprecated Use this series iterator to extract the status from each
* {@link BaseObservation#getAttributeValue(String) BaseObservation}.
*
* @See {@link BaseObservation#getAttributeValue(String) BaseObservation.getAttributeValue("OBS_STATUS")}
* @see BaseObservation#getAttributeValue(String) BaseObservation.getAttributeValue("OBS_STATUS")
*/
@Deprecated
public List<String> getStatus()
Expand All @@ -704,7 +704,7 @@ public List<String> getStatus()
* @deprecated Use this series iterator to extract the status from each
* {@link BaseObservation#getAttributeValue(String) BaseObservation}.
*
* @See {@link BaseObservation#getAttributeValue(String) BaseObservation.getAttributeValue("OBS_STATUS")}
* @see BaseObservation#getAttributeValue(String) BaseObservation.getAttributeValue("OBS_STATUS")
*/
@Deprecated
public String[] getStatusArray()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public class RestSdmxClient implements GenericSDMXClient
private static final String sourceClass = RestSdmxClient.class.getSimpleName();
protected static final Logger logger = Configuration.getSdmxLogger();

protected final String name;
protected String name;
protected final boolean needsURLEncoding;
protected final boolean supportsCompression;

Expand Down Expand Up @@ -267,6 +267,12 @@ public String getName()
{
return name;
}

@Override
public void setName(String name)
{
this.name = name;
}

@Override
public String buildDataURL(Dataflow dataflow, String resource, String startTime, String endTime, boolean seriesKeyOnly, String updatedAfter,
Expand Down Expand Up @@ -389,8 +395,10 @@ else if (conn.getContentType() != null && conn.getContentType().contains("applic
}
else
{
InputStream is = ((HttpURLConnection)conn).getErrorStream();
String msg = new BufferedReader(new InputStreamReader(is)).readLine();
SdmxException ex = SdmxExceptionFactory.createRestException(code, null, null);
logger.severe(ex.getMessage());
logger.severe(msg);
if (conn instanceof HttpURLConnection)
((HttpURLConnection) conn).disconnect();
throw ex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class SDMXClientFactory {
private static final String INEGI_PROVIDER = "http://sdmx.snieg.mx/service/Rest";
private static final String IMF_SDMX_CENTRAL_PROVIDER = "https://sdmxcentral.imf.org/ws/public/sdmxapi/rest";
private static final String WB_PROVIDER = "https://api.worldbank.org/v2/sdmx/rest";
private static final String ILO_PROVIDER = "https://www.ilo.org/sdmx/rest";

//read the configuration file
static {
Expand Down Expand Up @@ -100,27 +101,21 @@ private static void initBuiltInProviders() throws SdmxException{
addBuiltInProvider("INEGI", INEGI_PROVIDER, false, false, false, "Instituto Nacional de Estadistica y Geografia", false);
addBuiltInProvider("IMF_SDMX_CENTRAL", IMF_SDMX_CENTRAL_PROVIDER, false, false, true, "International Monetary Fund SDMX Central", false);
addBuiltInProvider("WB", WB_PROVIDER, false, false, false, "World Bank - World Development Indicators", false);
addBuiltInProvider("ILO", ILO_PROVIDER, false, false, false, "International Labour Organization", false);


//add internal 2.0 providers
addBuiltInProvider("ISTAT", null, false, false, false, "Italian National Institute of Statistics ", true);
addBuiltInProvider("OECD", null, false, false, false, "The Organisation for Economic Co-operation and Development", true);
addBuiltInProvider("StatsEE", null, false, false, false, "Statistics Estonia (BETA)", true);
addBuiltInProvider("OECD_RESTR", null, true, false, false, "The Organisation for Economic Co-operation and Development, RESTRICTED ACCESS", true);
addBuiltInProvider("ILO", null, false, false, false, "International Labour Organization", true);
addBuiltInProvider("ILO_Legacy", null, false, false, false, "International Labour Organization - Old Endpoint", true);
addBuiltInProvider("IMF2", null, false, false, false, "New International Monetary Fund endpoint", true);
addBuiltInProvider("ABS", null, false, false, false, "Australian Bureau of Statistics", true);
addBuiltInProvider("NBB", null, false, false, false, "National Bank Belgium", true);
addBuiltInProvider("UIS", null, false, false, false, "Unesco Institute for Statistics", true);
addBuiltInProvider("EUROSTAT", null, false, false, false, "Eurostat", true);

//addBuiltInProvider("FILE", null, false, false, false, "File offline provider", true);

//Legacy 2.0
ServiceLoader<GenericSDMXClient> ldr = ServiceLoader.load(GenericSDMXClient.class);
for (GenericSDMXClient provider : ldr) {
addProvider(provider.getClass().getSimpleName(), null, null, provider.needsCredentials(), false, false, provider.getClass().getSimpleName(), true);
}
}

/**
Expand Down Expand Up @@ -253,9 +248,11 @@ public static GenericSDMXClient createClient(String providerName) throws SdmxExc
logger.fine("Create an SDMX client for '" + providerName + "'");
GenericSDMXClient client = null;
Provider provider = providers.get(providerName);
if(provider == null){
throw new SdmxInvalidParameterException("The provider '" + providerName + "' is not available in this configuration.");
}
String hostname = null;

String errorMsg = "The provider '" + providerName + "' is not available in this configuration.";
if(provider != null && !provider.isCustom())
{
hostname = provider.getEndpoint().getHost();
Expand All @@ -267,8 +264,7 @@ else if(provider.getEndpoint().getScheme().toLowerCase().equals("file")){
}
else
{
logger.severe("The protocol '" + provider.getEndpoint().getScheme() + "' is not supported.");
throw new SdmxInvalidParameterException(errorMsg);
throw new SdmxInvalidParameterException("The protocol '" + provider.getEndpoint().getScheme() + "' is not supported.");
}
}
else {
Expand All @@ -283,6 +279,8 @@ else if(provider.getEndpoint().getScheme().toLowerCase().equals("file")){

if (client.getEndpoint() != null)
hostname = client.getEndpoint().getHost();

client.setName(providerName);
}
catch (ClassNotFoundException e) {
logger.severe("The provider '" + providerName + "' is not available in this configuration.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
* @author Attilio Mattiocco
*
*/
public class ILO extends RestSdmx20Client {
public class ILO_Legacy extends RestSdmx20Client {

protected static Logger logger = Configuration.getSdmxLogger();

public ILO() throws URISyntaxException {
public ILO_Legacy() throws URISyntaxException {
//the ILO providers supports https but it gets errors with java 1.6
super("ILO", new URI("https://www.ilo.org/ilostat/sdmx/ws/rest"), false, "application/vnd.sdmx.structurespecificdata+xml;version=2.1", "");
super("ILO_Legacy", new URI("https://www.ilo.org/ilostat/sdmx/ws/rest"), false, "application/vnd.sdmx.structurespecificdata+xml;version=2.1", "");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ else if (name.equals(dsd.getMeasure()))
try {
ts.add(new DoubleObservation(time, Double.valueOf(obs_val), obs_attr));
} catch (NumberFormatException e) {
logger.fine("The date: " + time + "has an obs value that is not parseable to a numer: " + obs_val + ". A NaN will be set.");
ts.add(new DoubleObservation(time, Double.NaN, obs_attr));
}
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,20 +200,40 @@ else if (attribute.getName().toString().equalsIgnoreCase(VALUE)) {

private static void setSeriesSingleObs(PortableTimeSeries<Double> ts, XMLEventReader eventReader) throws XMLStreamException, SdmxException {
String time = null;
String val = null;
String val = "";
Hashtable<String, String> obs_attr = new Hashtable<String, String>();
while (eventReader.hasNext()) {
XMLEvent event = eventReader.nextEvent();
logger.finest(event.toString());
if (event.isStartElement()) {
StartElement startElement = event.asStartElement();
if (startElement.getName().getLocalPart() == (OBS_TIME)) {
time = startElement.getAttributeByName(new QName(VALUE)).getValue();
@SuppressWarnings("unchecked")
Iterator<Attribute> attributes = startElement.getAttributes();
while (attributes.hasNext())
{
Attribute attribute = attributes.next();
String name = attribute.getName().toString();
if (name.equals(VALUE))
{
time = attribute.getValue();
}
}
}
if (startElement.getName().getLocalPart() == (OBS_VALUE)) {
val = startElement.getAttributeByName(new QName(VALUE)).getValue();
else if (startElement.getName().getLocalPart() == (OBS_VALUE)) {
@SuppressWarnings("unchecked")
Iterator<Attribute> attributes = startElement.getAttributes();
while (attributes.hasNext())
{
Attribute attribute = attributes.next();
String name = attribute.getName().toString();
if (name.equals(VALUE))
{
val = attribute.getValue();
}
}
}
if (startElement.getName().getLocalPart() == (ATTRIBUTEVALUE)) {
else if (startElement.getName().getLocalPart() == (ATTRIBUTEVALUE)) {
String name = startElement.getAttributeByName(new QName(ID)).getValue();
String value = startElement.getAttributeByName(new QName(VALUE)).getValue();
obs_attr.put(name, value);
Expand All @@ -225,6 +245,7 @@ private static void setSeriesSingleObs(PortableTimeSeries<Double> ts, XMLEventRe
try {
ts.add(new DoubleObservation(time, Double.valueOf(val), obs_attr));
} catch (NumberFormatException e) {
logger.fine("The date: " + time + "has an obs value that is not parseable to a numer: " + val + ". A NaN will be set.");
ts.add(new DoubleObservation(time, Double.NaN, obs_attr));
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ protected static void setSdmxLogger()

public static Logger getSdmxLogger()
{
return SDMX_LOGGER == null ? (SDMX_LOGGER = Logger.getLogger(LOGGER_NAME)) : SDMX_LOGGER;
Logger r = SDMX_LOGGER == null ? (SDMX_LOGGER = Logger.getLogger(LOGGER_NAME)) : SDMX_LOGGER;
return r;
}

public static Properties getConfiguration(){
Expand Down Expand Up @@ -229,7 +230,9 @@ private static void init() {
SDMX_LOGGER.info("Local configuration file found: " + confType );
} catch (SecurityException e) {
// impossible
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
SDMX_LOGGER.finer(logException(e));
}
}
Expand All @@ -245,8 +248,10 @@ private static void init() {
confType = central;
SDMX_LOGGER.info("Central configuration file found: " + confType);
} catch (SecurityException e) {
e.printStackTrace();
// impossible
} catch (IOException e) {
e.printStackTrace();
SDMX_LOGGER.finer(logException(e));
}
}
Expand All @@ -268,13 +273,18 @@ private static void init() {
SDMX_LOGGER.fine("Class configuration not found, skipping to global conf");
} catch (SecurityException e) {
// impossible
e.printStackTrace();
} catch (NoSuchMethodException e) {
// impossible
e.printStackTrace();
} catch (IllegalArgumentException e) {
// impossible
e.printStackTrace();
} catch (IllegalAccessException e) {
// impossible
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
SDMX_LOGGER.info("Error during SdmxConfiguration class initialization, skipping to global conf.");
SDMX_LOGGER.severe(logException(e.getCause()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static Collection<Object[]> data() {
{ "ISTAT", "144_125", "FREQ", "A", "annual", "[Dimension [id=FREQ, position=1, codelist=Codelist [id=IT1/CL_FREQ/1.0, codes={D=daily, E=event (not supported), W=weekly, Q=quarterly, A=an" },
{ "INSEE", "CNA-2010-CONSO-SI", "FREQ", "A", "Annual", "[Dimension [id=FREQ, position=1, codelist=Codelist [id=FR1/CL_PERIODICITE/1.0, codes={T=Quarterly, A=Annual, B=Two-monthly, S=Semi-annual, M=Monthly}]]" },
{ "INEGI", "DF_STEI", "REF_AREA", "MX", "Mexico", "[Dimension [id=REF_AREA, position=1, codelist=Codelist [id=SDMX/CL_AREA/1.0, codes={VU=Vanuatu, EC=Ecuador, VN=Viet Nam, VI=U.S.\", DZ=Algeria, VG=British\", DM=Dominica, VE=Venezuela, DO=Dominican " },
{ "ILO", "DF_YI_ALL_EMP_TEMP_SEX_AGE_NB", "COLLECTION", "MIG", "Labour Migration Statistics", "[Dimension [id=COLLECTION, position=1, codelist=Codelist [id=ILO/CL_COLLECTION, codes={YTH=youthSTATS - discontinued (latest period: 2013), SSI=Social Security Indicators, KIST=Key I" },
{ "ILO", "DF_YI_ALL_EMP_TEMP_SEX_AGE_NB", "COLLECTION", "YI", "Yearly indicators", "[Dimension [id=COLLECTION, position=1, codelist=Codelist [id=ILO/CL_COLLECTION/1.0, codes={YI=Yearly indica" },
{ "EUROSTAT", "prc_hicp_midx", "FREQ", "A", "Annual", "[Dimension [id=FREQ, position=1, codelist=Codelist [id=ESTAT/CL_FREQ/1.0, codes={D=Daily, W=Weekly, Q=Quarterly, A=Annual, S=Semi-annual, M=Monthly, H" },
{ "IMF2", "DS-WHDREO", "FREQ", "A", "Annual", "[Dimension [id=FREQ, position=1, codelist=Codelist [id=IMF/CL_FREQ, codes={D=Daily, W=Weekly, Q=Quarterly, A=Annu" },
{ "IMF_SDMX_CENTRAL", "SPI", "FREQ", "A", "Annual", "[Dimension [id=DATA_DOMAIN, position=1, codelist=Codelist [id=IMF/CL_DATADOMAIN/1.0, codes={SPI=S" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
@Suite.SuiteClasses( { SdmxInterfaceTest.class,
DimensionsAndCodesIT.class,
DSDIdentifiersIT.class,
// NBBTest.class,
ProxyTest.class,
// FileTest.class,
LanguagePriorityListTest.class,
Expand Down
2 changes: 1 addition & 1 deletion MATLAB/Contents.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
% Toolbox MatSDMX
% Version 2.0.6
% Version 2.1.0
% MATLAB interface to SDMX Web Services
%
% Files
Expand Down
2 changes: 1 addition & 1 deletion RJSDMX/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: RJSDMX
Version: 2.0-7
Version: 2.1-0
Title: R Interface to SDMX Web Services
Author: Attilio Mattiocco, Diana Nicoletti, Gianpaolo Lopez, Banca d'Italia
Maintainer: Attilio Mattiocco <[email protected]>
Expand Down
10 changes: 5 additions & 5 deletions RJSDMX/R/onLoad.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
#
.onLoad <- function(libname, pkgname) {
.jpackage(pkgname, lib.loc = libname)
jv <- .jcall("java/lang/System", "S", "getProperty", "java.runtime.version")
if(substr(jv, 1L, 1L) == "1") {
jvn <- as.numeric(paste0(strsplit(jv, "[.]")[[1L]][1:2], collapse = "."))
if(jvn < 1.7) stop(paste("Java 7 is needed for this package but rJava is linked to Java ", jvn))
}
#jv <- .jcall("java/lang/System", "S", "getProperty", "java.runtime.version")
#if(substr(jv, 1L, 1L) == "1") {
# jvn <- as.numeric(paste0(strsplit(jv, "[.]")[[1L]][1:2], collapse = "."))
# if(jvn < 1.7) stop(paste("Java 7 is needed for this package but rJava is linked to Java ", jvn))
#}

}
Binary file modified RJSDMX/inst/java/SDMX.jar
Binary file not shown.
Binary file modified STATA/jar/SDMX.jar
Binary file not shown.

0 comments on commit eee3c7b

Please sign in to comment.