Skip to content

Commit b25aa5f

Browse files
committed
Release VTL Studio with CodeMirror 6
1 parent 4461473 commit b25aa5f

File tree

6 files changed

+77
-188
lines changed

6 files changed

+77
-188
lines changed

vtl-api/src/main/java/it/bancaditalia/oss/vtl/config/ConfigurationManager.java

+15-8
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,18 @@
4444
public interface ConfigurationManager
4545
{
4646
/**
47-
* @return The {@link MetadataRepository} instance
48-
*/
49-
public MetadataRepository getMetadataRepository();
50-
51-
/**
52-
* @return The {@link VTLSession} instance
47+
* Creates a VTL session from the passed VTL code.
48+
*
49+
* @param code The VTL code to base to this session on.
50+
* @return The {@link VTLSession} instance.
5351
*/
5452
public VTLSession createSession(String code);
5553

5654
/**
57-
* @return The {@link VTLSession} instance
55+
* Creates a VTL session from the passed VTL code.
56+
*
57+
* @param reader the {@link Reader} instance to read the VTL code from. It will be closed when the script is read.
58+
* @return The {@link VTLSession} instance.
5859
*/
5960
public default VTLSession createSession(Reader reader) throws IOException
6061
{
@@ -64,6 +65,11 @@ public default VTLSession createSession(Reader reader) throws IOException
6465
}
6566
}
6667

68+
/**
69+
* @return The {@link MetadataRepository} instance
70+
*/
71+
public MetadataRepository getMetadataRepository();
72+
6773
/**
6874
* @return The {@link Engine} instance
6975
*/
@@ -78,7 +84,8 @@ public default VTLSession createSession(Reader reader) throws IOException
7884
* Saves the current configuration to the provided Writer as a list of Java properties.
7985
*
8086
* @param output The stream to write the properties to.
81-
* @throws IOException
87+
* @throws IOException if a i/o problem arises while saving properties.
88+
* @throws UnsupportedOperationException in case the operation is not supported by this ConfigurationManager.
8289
*/
8390
public default void saveConfiguration(Writer output) throws IOException
8491
{

vtl-bundles/vtl-coverage/src/test/java/it/bancaditalia/oss/vtl/coverage/tests/IntegrationTestSuite.java

+1-163
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
import java.nio.file.Paths;
4141
import java.util.ArrayList;
4242
import java.util.List;
43-
import java.util.Set;
44-
import java.util.stream.Collectors;
4543
import java.util.stream.Stream;
4644

4745
import org.hamcrest.Matchers;
@@ -76,171 +74,11 @@ public static Stream<Arguments> test() throws IOException, URISyntaxException
7674
List<Arguments> tests = new ArrayList<>();
7775
String testName;
7876
StringBuilder testCode = new StringBuilder();
79-
80-
Set<String> skipped = Stream.of(
81-
"abs",
82-
"absolute_value_1",
83-
"absolute_value_2",
84-
"aggr",
85-
"aggr_1",
86-
"aggr_2",
87-
"and_1",
88-
"and_2",
89-
"and_or",
90-
"average",
91-
"basic_arithmetic_1",
92-
"basic_arithmetic_2",
93-
"between_1",
94-
"between_2",
95-
"boolean_and_1",
96-
"boolean_and_2",
97-
"boolean_not_1",
98-
"boolean_or_1",
99-
"boolean_or_2",
100-
"boolean_xor_1",
101-
"boolean_xor_2",
102-
"calc",
103-
"calc_1",
104-
"case_conversion_1",
105-
"case_conversion_2",
106-
"case_conversion_3",
107-
"ceil",
108-
"ceil_1",
109-
"ceil_floor_1",
110-
"count",
111-
"div",
112-
"drop",
113-
"element_of_1",
114-
"element_of_2",
115-
"element_of_3",
116-
"equal",
117-
"equal_1",
118-
"equal_2",
119-
"exists_in_1",
120-
"exists_in_2",
121-
"exists_in_3",
122-
"exp",
123-
"exp_2",
124-
"fill_timeseries_1",
125-
"fill_timeseries_2",
126-
"filter",
127-
"filter_1",
128-
"filter_2",
129-
"first_value_1",
130-
"first_value_2",
131-
"floor",
132-
"floor_1",
133-
"flow_to_stock_1",
134-
"flow_to_stock_2",
135-
"greater",
136-
"greatereq",
137-
"greater_than_1",
138-
"greater_than_2",
139-
"if-then-else_1",
140-
"if-then-else_2",
141-
"intersection",
142-
"is_null_1",
143-
"is_null_2",
144-
"keep",
145-
"keep_1",
146-
"lag_1",
147-
"lag_2",
148-
"last_value_1",
149-
"last_value_2",
150-
"lead_1",
151-
"lead_2",
152-
"lesser",
153-
"lessereq",
154-
"less_than_1",
155-
"ln",
156-
"ln_1",
157-
"ln_2",
158-
"log_1",
159-
"log_2",
160-
"match_characters_1",
161-
"match_characters_2",
162-
"max",
163-
"median",
164-
"membership_1",
165-
"min",
166-
"minus",
167-
"mod",
168-
"mod_1",
169-
"mod_2",
170-
"mult",
171-
"notequal",
172-
"not_1",
173-
"not_2",
174-
"not_equal_1",
175-
"not_equal_2",
176-
"not_xor",
177-
"nvl_1",
178-
"nvl_2",
179-
"nvl_3",
180-
"op_with_calculated_scalar",
181-
"or_1",
182-
"or_2",
183-
"parentheses_1",
184-
"parentheses_2",
185-
"pattern_location_1",
186-
"pattern_location_2",
187-
"pattern_replacement_1",
188-
"pattern_replacement_2",
189-
"pattern_replacement_3",
190-
"plus",
191-
"pow",
192-
"power_1",
193-
"power_2",
194-
"rank_1",
195-
"ratio_to_report_1",
196-
"ratio_to_report_2",
197-
"rename",
198-
"rename_1",
199-
"round",
200-
"round_1",
201-
"round_2",
202-
"self_defined_operator1",
203-
"self_defined_operator2",
204-
"set_difference_1",
205-
"sqrt",
206-
"sqrt_1",
207-
"sqrt_2",
208-
"standard_deviation_pop",
209-
"standard_deviation_samp",
210-
"stock_to_flow_1",
211-
"stock_to_flow_2",
212-
"string_concatenation_1",
213-
"string_concatenation_2",
214-
"string_concatenation_3",
215-
"string_trim_1",
216-
"string_trim_2",
217-
"string_trim_3",
218-
"string_trim_4",
219-
"sub",
220-
"substring_extraction_1",
221-
"substring_extraction_2",
222-
"sub_1",
223-
"sum",
224-
"sum_1",
225-
"symmetric_difference_1",
226-
"timeshift_1",
227-
"timeshift_2",
228-
"trunc_1",
229-
"trunc_2",
230-
"uminus",
231-
"union_1",
232-
"union_2",
233-
"uplus",
234-
"var_pop",
235-
"var_samp",
236-
"xor_1",
237-
"xor_2"
238-
).collect(Collectors.toSet());
23977

24078
try (BufferedReader dirReader = new BufferedReader(new InputStreamReader(IntegrationTestSuite.class.getResourceAsStream("../tests"), UTF_8)))
24179
{
24280
while ((testName = dirReader.readLine()) != null)
243-
if (!testName.endsWith(".class")/* && !skipped.contains(testName) */)
81+
if (!testName.endsWith(".class"))
24482
{
24583
try (BufferedReader testReader = Files.newBufferedReader(root.resolve(testName).resolve(testName + ".vtl")))
24684
{

vtl-bundles/vtl-r/RVTL/src/main/resources/R/R/VTLSessionManager.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ VTLSessionManagerClass <- R6Class("VTLSessionManager", public = list(
4949
#' If an active SDMX metadata repository is active, also load Transformation schemes from it
5050
list = function() {
5151
ss <- ls(private$sessions)
52-
metaRepo <- J("it.bancaditalia.oss.vtl.config.ConfigurationManagerFactory")$getInstance()$getMetadataRepository()
52+
metaRepo <- J("it.bancaditalia.oss.vtl.config.ConfigurationManagerFactory")$newManager()$getMetadataRepository()
5353
if (metaRepo %instanceof% 'it.bancaditalia.oss.vtl.impl.meta.sdmx.SDMXRepository') {
5454
sdmxTs <- sapply(metaRepo$getAvailableSchemes(), .jstrVal)
5555
ss <- unique(c(ss, sdmxTs))

vtl-bundles/vtl-r/RVTL/src/main/resources/R/R/server.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ vtlServer <- function(input, output, session) {
157157
propfile = paste0(J("java.lang.System")$getProperty("user.home"), '/.vtlStudio.properties')
158158
writer = .jnew("java.io.FileWriter", propfile)
159159
tryCatch({
160-
configManager$getInstance()$saveConfiguration(writer)
160+
configManager$newManager()$saveConfiguration(writer)
161161
}, finally = {
162162
writer$close()
163163
})

vtl-bundles/vtl-r/RVTL/src/main/resources/R/inst/www/vtl-editor.css

+16-5
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,23 @@
6767
overflow-y: hidden;
6868
}
6969

70+
#vtlwell {
71+
flex-grow: 1;
72+
}
73+
74+
.cm-editor {
75+
height: 100%;
76+
}
77+
7078
#vtl_output {
71-
border-radius: 0;
72-
padding: 0;
73-
margin: 0;
74-
flex-shrink: 1;
75-
flex-grow: 1;
79+
border-radius: 0;
80+
padding: 0;
81+
margin: 0;
82+
flex-shrink: 1;
83+
flex-grow: 0;
84+
flex-basis: auto;
85+
max-height: 30%;
86+
overflow-y: auto;
7687
}
7788

7889
#saveas {

vtl-bundles/vtl-r/vtl-java2r/src/main/java/it/bancaditalia/oss/vtl/util/Paginator.java

+43-10
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import java.io.Serializable;
2525
import java.time.LocalDate;
2626
import java.util.ArrayList;
27-
import java.util.Iterator;
27+
import java.util.concurrent.ArrayBlockingQueue;
2828
import java.util.stream.Stream;
2929

3030
import org.slf4j.Logger;
@@ -41,16 +41,18 @@
4141
public class Paginator
4242
{
4343
private static final Logger LOGGER = LoggerFactory.getLogger(Paginator.class);
44+
private static final LocalDate R_EPOCH_DATE = LocalDate.of(1970, 1, 1);
4445
private static final double R_DOUBLE_NA = Double.longBitsToDouble(0x7ff00000000007a2L);
4546
private static final int R_INT_NA = Integer.MIN_VALUE;
4647

4748
private final DataSetMetadata dataStructure;
48-
private final Iterator<DataPoint> iterator;
49+
private final ArrayBlockingQueue<DataPoint> queue;
4950
private final DataStructureComponent<?, ?, ?>[] comps;
5051
private final int[] types;
5152
private final int size;
5253
private final Object[] result;
53-
54+
55+
private boolean closed = false;
5456

5557
public Paginator(DataSet dataset, int size)
5658
{
@@ -59,6 +61,8 @@ public Paginator(DataSet dataset, int size)
5961
comps = dataStructure.stream().toArray(DataStructureComponent<?, ?, ?>[]::new);
6062
result = new Object[comps.length];
6163
types = new int[comps.length];
64+
queue = new ArrayBlockingQueue<>(size);
65+
6266
for (int i = 0; i < comps.length; i++)
6367
{
6468
if (comps[i].getVariable().getDomain() instanceof NumberDomain)
@@ -71,10 +75,28 @@ else if (comps[i].getVariable().getDomain() instanceof DateDomain)
7175
types[i] = 4;
7276
}
7377

74-
try (Stream<DataPoint> stream = dataset.stream())
75-
{
76-
iterator = stream.iterator();
77-
}
78+
Thread t = new Thread(() -> {
79+
try (Stream<DataPoint> stream = dataset.stream().onClose(() -> closed = true))
80+
{
81+
stream.forEach(dp -> {
82+
try
83+
{
84+
if (!closed)
85+
queue.put(dp);
86+
}
87+
catch (InterruptedException e)
88+
{
89+
closed = true;
90+
}
91+
});
92+
}
93+
finally
94+
{
95+
closed = true;
96+
}
97+
}, "Paginator@" + hashCode());
98+
t.setDaemon(true);
99+
t.start();
78100
}
79101

80102
public DataSetMetadata getDataStructure()
@@ -110,8 +132,19 @@ public String[] getStringColumn(int i)
110132
public void prepareMore()
111133
{
112134
ArrayList<DataPoint> dps = new ArrayList<>(size);
113-
for (int i = 0; i < size && iterator.hasNext(); i++)
114-
dps.add(iterator.next());
135+
queue.drainTo(dps);
136+
while (!closed && dps.size() == 0)
137+
{
138+
try
139+
{
140+
Thread.sleep(500);
141+
queue.drainTo(dps);
142+
}
143+
catch (InterruptedException e)
144+
{
145+
break;
146+
}
147+
}
115148

116149
int newSize = dps.size();
117150

@@ -147,7 +180,7 @@ public void prepareMore()
147180
{
148181
case 1: ((double[]) array)[j] = value == null ? R_DOUBLE_NA : ((Number) value).doubleValue(); break;
149182
case 2: ((int[]) array)[j] = value == null ? R_INT_NA : value == Boolean.TRUE ? 1 : 0; break;
150-
case 3: ((int[]) array)[j] = value == null ? R_INT_NA : (int) DAYS.between(LocalDate.of(1970, 1, 1), (LocalDate) value); break;
183+
case 3: ((int[]) array)[j] = value == null ? R_INT_NA : (int) DAYS.between(R_EPOCH_DATE, (LocalDate) value); break;
151184
case 4: ((String[]) array)[j] = value == null ? null : value.toString(); break;
152185
}
153186
}

0 commit comments

Comments
 (0)