Skip to content

Commit

Permalink
refactoring, including stata2java interaction and availability querie…
Browse files Browse the repository at this point in the history
…s for 2.1 providers
  • Loading branch information
amattioc committed Jul 25, 2024
1 parent f2ecc03 commit a13cfb5
Show file tree
Hide file tree
Showing 69 changed files with 1,313 additions and 1,740 deletions.
2 changes: 1 addition & 1 deletion BUILD
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20240618-1340
20240725-1625
42 changes: 2 additions & 40 deletions JAVA/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<!-- set global properties for this build -->
<property name="src" location="src/main/java"/>
<property name="resources" location="src/main/resources"/>
<property name="stata_src" location="stata_src"/>
<property name="test" location="src/test/java"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
Expand Down Expand Up @@ -44,11 +43,6 @@
<copydir src="${resources}" dest="${build}" />
</target>

<target name="compile-debug" depends="clean, init" description="compile the source for base java lib with debug info" >
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}" target="1.8" source="1.8" debug="true" />
</target>

<target name="sdmxunittest" depends="compile" description="compile the test source ">
<!-- Compile the java code from ${test} into ${build}, junit libraries are needed in the classpath -->
<javac srcdir="${test}" destdir="${build}" target="1.8" source="1.8" />
Expand All @@ -69,42 +63,10 @@
<copy file="${dist}/lib/SDMX.jar" todir="${matlab_libdir}"/>
<copy file="${dist}/lib/SDMX.jar" todir="${sas_libdir}"/>
<copy file="${dist}/lib/SDMX.jar" todir="${excel_libdir}"/>
<copy file="${dist}/lib/SDMX.jar" todir="${stata_libdir}"/>
</target>

<target name="dist-debug" depends="compile-debug" description="generate the distribution with debug info" >
<!-- Create the distribution directory -->
<mkdir dir="${dist}/lib"/>
<!-- copy resources -->
<copydir src="${resources}" dest="${build}" />
<!-- Put everything in ${build} into the jar file -->
<jar jarfile="${dist}/lib/SDMX.jar" basedir="${build}">
<manifest>
<attribute name="Main-Class" value="it.bancaditalia.oss.sdmx.helper.SDMXHelper"/>
<attribute name="BUILD" value="${build_id}"/>
</manifest>
</jar>
<!-- Now distribute the jar file to the plugins -->
<copy file="${dist}/lib/SDMX.jar" todir="${rjsdmx_libdir}"/>
<copy file="${dist}/lib/SDMX.jar" todir="${matlab_libdir}"/>
<copy file="${dist}/lib/SDMX.jar" todir="${sas_libdir}"/>
<copy file="${dist}/lib/SDMX.jar" todir="${excel_libdir}"/>
</target>

<target name="STATA" depends="dist" description="compile the source for stata java lib" >
<!-- Compile the java code from ${src} into ${build} stata java libs (stata-sfi.jar) are needed in the classpath -->
<javac srcdir="${stata_src}" destdir="${build}" target="1.8" source="1.8" />
<!-- copy resources -->
<copydir src="${resources}" dest="${build}" />
<!-- Create the stata enabled jar in the stata plugin jar directory -->
<jar jarfile="${stata_libdir}/SDMX.jar" basedir="${build}">
<manifest>
<attribute name="Main-Class" value="it.bancaditalia.oss.sdmx.helper.SDMXHelper"/>
<attribute name="BUILD" value="${build_id}"/>
</manifest>
</jar>
</target>

<target name="release" depends="dist, STATA" description="create release packages" >
<target name="release" depends="dist" description="create release packages" >
<tar destfile="${dist}/statasdmx.tar" basedir="${stata_dir}"/>
<gzip destfile="${dist}/statasdmx.tar.gz" src="${dist}/statasdmx.tar"/>
<delete file="${dist}/statasdmx.tar"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package it.bancaditalia.oss.sdmx.api;

import static java.util.Objects.requireNonNull;

import java.io.Serializable;
import java.security.InvalidParameterException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.Function;

import it.bancaditalia.oss.sdmx.util.Utils.BiFunction;
import it.bancaditalia.oss.sdmx.util.Utils.Function;
import it.bancaditalia.oss.sdmx.exceptions.SdmxInvalidParameterException;

/**
* An immutable observation in a series.
Expand All @@ -30,13 +32,11 @@ public abstract class BaseObservation<T> implements Serializable, Comparable<Bas
*
* @param timeslot The timestamp of the observation.
* @param obsAttributes A map of observation-level attributes.
* @throws SdmxInvalidParameterException
*/
protected BaseObservation(String timeslot, Map<String, String> obsAttributes)
{
if (timeslot == null || timeslot.isEmpty())
throw new InvalidParameterException("The timeslot for an observation cannot be null or empty.");

this.timeslot = timeslot;
this.timeslot = requireNonNull(timeslot, "The timeslot for an observation cannot be null or empty.");
this.obsAttributes = obsAttributes == null ? new HashMap<String, String>() : obsAttributes;
}

Expand Down
6 changes: 6 additions & 0 deletions JAVA/src/main/java/it/bancaditalia/oss/sdmx/api/Codelist.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ public Codelist(SDMXReference coordinates, Map<String, LocalizedText> codes, Map
this.parents.putAll(parents);
}

public void importFrom(Codelist other)
{
this.codes.putAll(other.codes);
this.parents.putAll(other.parents);
}

@Override
public Iterator<String> iterator()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public List<SdmxAttribute> getAttributes()
*
* @param dim The dimension which is to put.
*/
public void setDimension(Dimension dim)
public void addDimension(Dimension dim)
{
this.dimensions.put(dim.getId(), dim);
}
Expand All @@ -112,7 +112,7 @@ public Dimension getDimension(String dimensionId)
*
* @param attr The attribute to set.
*/
public void setAttribute(SdmxAttribute attr)
public void addAttribute(SdmxAttribute attr)
{
this.attributes.put(attr.getId(), attr);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/
public class Dataflow extends SDMXReference
{
private LocalizedText name; // the description
private final LocalizedText name; // the description
private SDMXReference dsdIdentifier;

public Dataflow(SDMXReference other, String name)
Expand Down
19 changes: 5 additions & 14 deletions JAVA/src/main/java/it/bancaditalia/oss/sdmx/api/Dimension.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,19 @@

public class Dimension extends SdmxMetaElement
{
private int position;
private final int position;

/**
* Creates a Dimension with given attributes.
*
* @param id The dimension id
* @param position The dimension ordinality in the dataflow structure
* @param name The description
* @param codeList the Codelist object associated with this dimension.
* @param position The dimension ordinality in the dataflow structure
*/
public Dimension(String id, int position, Codelist codeList)
{
super(id);
this.position = position;
setCodeList(codeList);
}

/**
* Creates an empty dimension.
*/
public Dimension(String id, int position)
public Dimension(String id, String name, Codelist codeList, int position)
{
super(id);
super(id, name, codeList);
this.position = position;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package it.bancaditalia.oss.sdmx.api;

import java.util.Map;

import it.bancaditalia.oss.sdmx.util.Utils.BiFunction;
import it.bancaditalia.oss.sdmx.util.Utils.Function;
import java.util.function.BiFunction;
import java.util.function.Function;

/**
* A specialized implementation of {link {@link BaseObservation} for {@code double} type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import it.bancaditalia.oss.sdmx.exceptions.SdmxException;

import java.net.MalformedURLException;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -176,9 +177,9 @@ public List<PortableTimeSeries<Double>> getTimeSeries(Dataflow dataflow, DataFlo
* @param includeHistory whether to include the history in the request
* @return the query URL for the endpoint
* @throws SdmxException
* @throws MalformedURLException
*/
public String buildDataURL(Dataflow dataflow, String resource,
String startTime, String endTime,
public String buildDataURL(Dataflow dataflow, String resource, String startTime, String endTime,
boolean seriesKeyOnly, String updatedAfter, boolean includeHistory) throws SdmxException;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package it.bancaditalia.oss.sdmx.api;

import java.util.Map;

import it.bancaditalia.oss.sdmx.util.Utils.BiFunction;
import it.bancaditalia.oss.sdmx.util.Utils.Function;
import java.util.function.BiFunction;
import java.util.function.Function;

/**
* A specialized implementation of {link {@link BaseObservation} for {@code long} type.
Expand Down
12 changes: 3 additions & 9 deletions JAVA/src/main/java/it/bancaditalia/oss/sdmx/api/Measure.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,14 @@

public class Measure extends SdmxMetaElement
{
private int position;
private final int position;

/**
* Creates an empty dimension.
*/
public Measure(String id, int position)
public Measure(String id, String name, int position)
{
super(id);
super(id, name, null);
this.position = position;
}

/**
* @return The dimension ordinality in the dataflow structure.
*/
public int getPosition()
{
return position;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package it.bancaditalia.oss.sdmx.api;

import java.util.Map;

import it.bancaditalia.oss.sdmx.util.Utils.BiFunction;
import it.bancaditalia.oss.sdmx.util.Utils.Function;
import java.util.function.BiFunction;
import java.util.function.Function;

/**
* Generic specialization for a {@link BaseObservation}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
import java.io.Serializable;
import java.time.Year;
import java.time.YearMonth;
import java.time.temporal.TemporalAdjusters;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import java.util.StringJoiner;
import java.util.logging.Logger;

import javax.swing.table.DefaultTableModel;
Expand Down Expand Up @@ -59,7 +59,7 @@ public class PortableDataSet<T> implements Serializable

private boolean errorFlag = false;
private boolean numeric = false;
private String errorObjects = null;
private StringJoiner errorObjects = new StringJoiner(", ");
private String dataflow = null;

private DefaultTableModel model = null;
Expand Down Expand Up @@ -365,18 +365,15 @@ public void setErrorFlag(boolean errorFlag)
*/
public String getErrorObjects()
{
return errorObjects;
return errorObjects.toString();
}

/**
* @param text a text to concatenate to the error message of this dataset.
*/
public void addErrorObjects(String text)
{
if (this.errorObjects == null || this.errorObjects.isEmpty())
this.errorObjects = text;
else
this.errorObjects += ", " + text;
errorObjects.add(text);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
import java.util.Map.Entry;
import java.util.RandomAccess;
import java.util.Set;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.logging.Logger;

import it.bancaditalia.oss.sdmx.exceptions.SdmxInvalidParameterException;
import it.bancaditalia.oss.sdmx.util.Configuration;
import it.bancaditalia.oss.sdmx.util.Utils;
import it.bancaditalia.oss.sdmx.util.Utils.BiFunction;
import it.bancaditalia.oss.sdmx.util.Utils.Function;

/**
* This is a Java container for a Time Series. It will be transformed by a converter in the various statistical packages
Expand Down Expand Up @@ -350,7 +350,7 @@ public void addDimension(String key, String value)
@Deprecated
public List<T> getObservations()
{
return new ListWrapper<>(Utils.<T>obsExtractor());
return new ListWrapper<T>(BaseObservation::getValue);
}

/**
Expand Down Expand Up @@ -381,7 +381,7 @@ public Object[] getObservationsArray()
@Deprecated
public List<String> getTimeSlots()
{
return new ListWrapper<>(Utils.<T>timeslotExtractor());
return new ListWrapper<>(BaseObservation::getTimeslot);
}

/**
Expand Down Expand Up @@ -422,7 +422,7 @@ public String[] getObsLevelAttributesNamesArray()
*/
public List<String> getObsLevelAttributes(String attributeName)
{
return new ListWrapper<>(Utils.<T>obsLevelAttrsExtractor(attributeName));
return new ListWrapper<>(obs -> obs.getAttributeValue(attributeName));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@
*/
package it.bancaditalia.oss.sdmx.api;



public class SdmxAttribute extends SdmxMetaElement{

public SdmxAttribute(String id)
public class SdmxAttribute extends SdmxMetaElement
{
public SdmxAttribute(String id, String name, Codelist codelist)
{
super(id);
super(id, name, codelist);
}
}
Loading

0 comments on commit a13cfb5

Please sign in to comment.