Skip to content

Commit

Permalink
Fix proxy usage
Browse files Browse the repository at this point in the history
  • Loading branch information
vpinna80 committed Jul 11, 2024
1 parent 1adb815 commit ec92c92
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ public static void loadConfiguration(Reader input) throws IOException
props.forEach((k, v) -> {
if (k != null && v != null && k instanceof String && ((String) k).startsWith("vtl."))
System.setProperty(k.toString(), v.toString());

if (List.of("http.proxyHost", "http.proxyPort", "https.proxyHost", "https.proxyPort").contains(k))
{
// Set proxy only if not already set (i.e. by command line parameters)
String proxyValue = System.getProperty(k.toString());
if (proxyValue == null)
System.setProperty(k.toString(), v.toString());
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -69,6 +68,9 @@ static class Operation
@Option(names = { "--jupyter" }, description = "Location of Jupyter executable.", paramLabel = "jupyter", defaultValue = "jupyter")
Path jupyter;

@Option(names = { "-c", "--conf" }, description = "The configuration file to use. The file must be accessible both at installation and at run time", paramLabel = "conf")
Path conf;

@ArgGroup(exclusive = true, multiplicity = "1")
Operation operation;

Expand Down Expand Up @@ -98,9 +100,15 @@ private void exec() throws IOException, InvalidKeyException, NoSuchAlgorithmExce
@SuppressWarnings("unchecked")
Map<String, Object> connInfo = JsonFactory.builder().build().setCodec(new JsonMapper()).createParser(operation.exec).readValueAs(Map.class);

ConfigurationManagerFactory.loadConfiguration(new FileReader(System.getProperty("user.home") + "/.vtlStudio.properties"));
if (conf == null)
conf = Paths.get(System.getProperty("user.home") + "/.vtlStudio.properties");
if (Files.exists(conf) && Files.isRegularFile(conf) && Files.isReadable(conf));
ConfigurationManagerFactory.loadConfiguration(Files.newBufferedReader(conf));

// Change the session implementation with the Jupyter specific one
SESSION_IMPLEMENTATION.setValue(VTLJupyterSession.class.getName());

// Change the standard Workspace implementation class with the Jupyter specific one
ENVIRONMENT_IMPLEMENTATION.setValues(
Stream.concat(ENVIRONMENT_IMPLEMENTATION.getValues().stream()
.filter(not(cls -> {
Expand Down Expand Up @@ -145,11 +153,16 @@ private void install() throws IOException, InterruptedException
Path copyJar = Files.copy(jar, kernelPath.resolve("vtl-jupyter.jar"), REPLACE_EXISTING);

Map<String, Object> kernelspec = new LinkedHashMap<>();
kernelspec.put("argv", List.of(java, "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=127.0.0.1:28000", "-jar", copyJar.toString(), "--exec", "{connection_file}"));
kernelspec.put("argv", List.of(java, "-jar", copyJar.toString(), "--exec", "{connection_file}"));
kernelspec.put("display_name", "VTL E&E");
kernelspec.put("interrupt_mode", "message");
kernelspec.put("language", "VTL");

if (conf == null)
conf = Paths.get(System.getProperty("user.home") + "/.vtlStudio.properties");
if (!Files.exists(conf) || !Files.isRegularFile(conf) || !Files.isReadable(conf));
ConfigurationManagerFactory.loadConfiguration(Files.newBufferedReader(conf));

try (FileWriter writer = new FileWriter(kernelPath.resolve("kernel.json").toFile()))
{
JsonFactory.builder().build().setCodec(new JsonMapper()).createGenerator(writer).useDefaultPrettyPrinter().writeObject(kernelspec);
Expand Down
2 changes: 0 additions & 2 deletions vtl-bundles/vtl-r/RVTL/src/main/resources/R/R/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,6 @@ shinydashboard::dashboardPage(title="VTL Studio!",
shinydashboard::box(title = 'Network Proxy', status = 'primary', solidHeader = T, collapsible = T,
textInput(inputId = 'proxyHost', label = 'Host:', value = defaultProxy()$host),
textInput(inputId = 'proxyPort', label = 'Port:', value = defaultProxy()$port),
textInput(inputId = 'proxyUser', label = 'User:', value = defaultProxy()$user),
passwordInput(inputId = 'proxyPassword', label = 'Password:'),
actionButton(inputId = 'setProxy', label = 'Save')
),
shinydashboard::box(title = 'Status', status = 'primary', solidHeader = T, width = 12,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ public void saveConfiguration(Writer output) throws IOException

for (VTLProperty prop: vtlProps)
props.setProperty(prop.getName(), prop.getValue());

for (String proxyProp: List.of("http.proxyHost", "http.proxyPort", "https.proxyHost", "https.proxyPort"))
{
String proxyValue = System.getProperty(proxyProp);
if (proxyValue != null)
props.put(proxyProp, proxyValue);
}

props.store(output, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public JsonMetadataRepository() throws IOException

varDefs.forEach((n, d) -> variables.put(n, VariableImpl.of(n, getDomain(d))));
strDefs.forEach((n, l) -> structures.put(n, l.entrySet().stream().map(splitting((c, r) -> {
Objects.requireNonNull(variables.get(c));
Objects.requireNonNull(variables.get(c), "Undefined variable " + c);
return variables.get(c).as(r);
})).collect(toDataStructure())));
dsDefs.forEach((n, e) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,17 @@ public SDMXRepository() throws IOException, SAXException, ParserConfigurationExc

for (DimensionBean dimBean: dsd.getDimensionList().getDimensions())
{
ValueDomainSubset<?, ?> domain = dimBean.isTimeDimension() ? TIMEDS : getDomain(sdmxRef2VtlName(dimBean.getEnumeratedRepresentation()));
ValueDomainSubset<?, ?> domain;

if (dimBean.isTimeDimension())
domain = TIMEDS;
else if (dimBean.hasCodedRepresentation())
domain = getDomain(sdmxRef2VtlName(dimBean.getEnumeratedRepresentation()));
else
domain = sdmxRepr2VTLDomain(dimBean);

DataStructureComponent<Identifier, ?, ?> id = createComponent(dimBean, Identifier.class, domain);
LOGGER.debug("From dsd {} created identifier {}", dsdName, id);
builder.addComponent(id);
enumIds.put(dimBean.getPosition() - 1, id);
}
Expand All @@ -217,71 +226,11 @@ public SDMXRepository() throws IOException, SAXException, ParserConfigurationExc
if (attrBean.hasCodedRepresentation())
domain = getDomain(sdmxRef2VtlName(attrBean.getEnumeratedRepresentation()));
else
{
Optional<TextFormatBean> optFormat = Optional.of(attrBean)
.map(AttributeBean::getRepresentation)
.map(RepresentationBean::getTextFormat);

TEXT_TYPE type = optFormat
.map(TextFormatBean::getTextType)
.orElse(STRING);

boolean inclusive = true;

switch (type)
{
case ALPHA: domain = VTL_ALPHA; break;
case ALPHA_NUMERIC: domain = VTL_ALPHA_NUMERIC; break;
case NUMERIC: domain = VTL_NUMERIC; break;
case BOOLEAN: domain = BOOLEANDS; break;
case STRING: case URI: domain = STRINGDS; break;
case INCLUSIVE_VALUE_RANGE: domain = NUMBERDS; break;
case EXCLUSIVE_VALUE_RANGE: domain = NUMBERDS; inclusive = false; break;
case FLOAT: case DOUBLE: case DECIMAL: case INCREMENTAL: domain = NUMBERDS; break;
case BIG_INTEGER: case COUNT: case LONG: case INTEGER: case SHORT: domain = INTEGERDS; break;
case DURATION: domain = DURATIONDS; break;
case OBSERVATIONAL_TIME_PERIOD: case STANDARD_TIME_PERIOD: case TIME_RANGE: domain = TIMEDS; break;
case DATE_TIME: case BASIC_TIME_PERIOD: case GREGORIAN_TIME_PERIOD: case GREGORIAN_DAY: case GREGORIAN_YEAR: case GREGORIAN_YEAR_MONTH: domain = DATEDS; break;
case MONTH: case MONTH_DAY: case DAY: case TIME: domain = STRINGDS; break;
case REPORTING_DAY: case REPORTING_MONTH: case REPORTING_QUARTER: case REPORTING_SEMESTER:
case REPORTING_TIME_PERIOD: case REPORTING_TRIMESTER: case REPORTING_WEEK: case REPORTING_YEAR: domain = TIME_PERIODDS; break;
case GEO: case XHTML: default: LOGGER.warn("Representation {} is not implemented, String will be used instead.", type); domain = STRINGDS; break;
}

if (optFormat.isPresent())
{
TextFormatBean format = optFormat.get();
if (STRINGDS.isAssignableFrom(domain))
{
OptionalInt minLen = Stream.ofNullable(format.getMinLength()).mapToInt(BigInteger::intValueExact).findAny();
OptionalInt maxLen = Stream.ofNullable(format.getMaxLength()).mapToInt(BigInteger::intValueExact).findAny();
domain = new StrlenDomainSubset<>(STRINGDS, minLen, maxLen);
}
else if (INTEGERDS.isAssignableFrom(domain))
{
OptionalLong minLen = Stream.ofNullable(format.getMinValue()).mapToLong(BigDecimal::longValueExact).findAny();
OptionalLong maxLen = Stream.ofNullable(format.getMaxValue()).mapToLong(BigDecimal::longValueExact).findAny();
String name = domain.getName() + ">=" + minLen.orElse(Long.MIN_VALUE) + "<" + maxLen.orElse(Long.MAX_VALUE);
domain = new RangeIntegerDomainSubset<>(name, INTEGERDS, minLen, maxLen, inclusive);
}
else if (NUMBERDS.isAssignableFrom(domain))
{
OptionalDouble minLen = Stream.ofNullable(format.getMinValue()).mapToDouble(BigDecimal::doubleValue).findAny();
OptionalDouble maxLen = Stream.ofNullable(format.getMaxValue()).mapToDouble(BigDecimal::doubleValue).findAny();
String name = domain.getName() + ">=" + minLen.orElse(Long.MIN_VALUE) + "<" + maxLen.orElse(Long.MAX_VALUE);
domain = new RangeNumberDomainSubset<>(name, NUMBERDS, minLen, maxLen, inclusive);
}

if (attrBean.isMandatory())
{
@SuppressWarnings({ "rawtypes", "unchecked" })
NonNullDomainSubset<?, ?> nonNullDomainSubset = new NonNullDomainSubset(domain);
domain = nonNullDomainSubset;
}
}
}
domain = sdmxRepr2VTLDomain(attrBean);

builder.addComponent(createComponent(attrBean, Attribute.class, domain));
DataStructureComponent<Attribute, ?, ?> attr = createComponent(attrBean, Attribute.class, domain);
LOGGER.debug("From dsd {} created attribute {}", dsdName, attr);
builder.addComponent(attr);
}

structures.put(dsdName, new SimpleEntry<>(builder.build(), new ArrayList<>(enumIds.values())));
Expand All @@ -299,12 +248,83 @@ else if (NUMBERDS.isAssignableFrom(domain))
// Load transformation schemes
for (ITransformationSchemeBean scheme: rbrm.getIdentifiables(ITransformationSchemeBean.class))
{
String tsName = sdmxRef2VtlName(scheme.asReference());
LOGGER.info("Loading transformation scheme {}", tsName);
String code = scheme.getItems().stream()
.map(t -> t.getResult() + (t.isPersistent() ? "<-" : ":=") + t.getExpression())
.collect(joining(";" + lineSeparator() + lineSeparator(), "", ";" + lineSeparator()));
schemes.put(sdmxRef2VtlName(scheme.asReference()), code);
LOGGER.debug("Loaded transformation scheme {} with code:\n{}\n", tsName, code);
schemes.put(tsName, code);
}
}

private ValueDomainSubset<?, ?> sdmxRepr2VTLDomain(ComponentBean compBean)
{
Optional<TextFormatBean> optFormat = Optional.of(compBean)
.map(ComponentBean::getRepresentation)
.map(RepresentationBean::getTextFormat);

TEXT_TYPE type = optFormat
.map(TextFormatBean::getTextType)
.orElse(STRING);

ValueDomainSubset<?, ?> domain;
boolean inclusive = true;

switch (type)
{
case ALPHA: domain = VTL_ALPHA; break;
case ALPHA_NUMERIC: domain = VTL_ALPHA_NUMERIC; break;
case NUMERIC: domain = VTL_NUMERIC; break;
case BOOLEAN: domain = BOOLEANDS; break;
case STRING: case URI: domain = STRINGDS; break;
case INCLUSIVE_VALUE_RANGE: domain = NUMBERDS; break;
case EXCLUSIVE_VALUE_RANGE: domain = NUMBERDS; inclusive = false; break;
case FLOAT: case DOUBLE: case DECIMAL: case INCREMENTAL: domain = NUMBERDS; break;
case BIG_INTEGER: case COUNT: case LONG: case INTEGER: case SHORT: domain = INTEGERDS; break;
case DURATION: domain = DURATIONDS; break;
case OBSERVATIONAL_TIME_PERIOD: case STANDARD_TIME_PERIOD: case TIME_RANGE: domain = TIMEDS; break;
case DATE_TIME: case BASIC_TIME_PERIOD: case GREGORIAN_TIME_PERIOD: case GREGORIAN_DAY: case GREGORIAN_YEAR: case GREGORIAN_YEAR_MONTH: domain = DATEDS; break;
case MONTH: case MONTH_DAY: case DAY: case TIME: domain = STRINGDS; break;
case REPORTING_DAY: case REPORTING_MONTH: case REPORTING_QUARTER: case REPORTING_SEMESTER:
case REPORTING_TIME_PERIOD: case REPORTING_TRIMESTER: case REPORTING_WEEK: case REPORTING_YEAR: domain = TIME_PERIODDS; break;
case GEO: case XHTML: default: LOGGER.warn("Representation {} is not implemented, String will be used instead.", type); domain = STRINGDS; break;
}

if (optFormat.isPresent())
{
TextFormatBean format = optFormat.get();
if (STRINGDS.isAssignableFrom(domain))
{
OptionalInt minLen = Stream.ofNullable(format.getMinLength()).mapToInt(BigInteger::intValueExact).findAny();
OptionalInt maxLen = Stream.ofNullable(format.getMaxLength()).mapToInt(BigInteger::intValueExact).findAny();
domain = new StrlenDomainSubset<>(STRINGDS, minLen, maxLen);
}
else if (INTEGERDS.isAssignableFrom(domain))
{
OptionalLong minLen = Stream.ofNullable(format.getMinValue()).mapToLong(BigDecimal::longValueExact).findAny();
OptionalLong maxLen = Stream.ofNullable(format.getMaxValue()).mapToLong(BigDecimal::longValueExact).findAny();
String name = domain.getName() + ">=" + minLen.orElse(Long.MIN_VALUE) + "<" + maxLen.orElse(Long.MAX_VALUE);
domain = new RangeIntegerDomainSubset<>(name, INTEGERDS, minLen, maxLen, inclusive);
}
else if (NUMBERDS.isAssignableFrom(domain))
{
OptionalDouble minLen = Stream.ofNullable(format.getMinValue()).mapToDouble(BigDecimal::doubleValue).findAny();
OptionalDouble maxLen = Stream.ofNullable(format.getMaxValue()).mapToDouble(BigDecimal::doubleValue).findAny();
String name = domain.getName() + ">=" + minLen.orElse(Long.MIN_VALUE) + "<" + maxLen.orElse(Long.MAX_VALUE);
domain = new RangeNumberDomainSubset<>(name, NUMBERDS, minLen, maxLen, inclusive);
}

if (compBean instanceof DimensionBean || compBean.isMandatory())
{
@SuppressWarnings({ "rawtypes", "unchecked" })
NonNullDomainSubset<?, ?> nonNullDomainSubset = new NonNullDomainSubset(domain);
domain = nonNullDomainSubset;
}
}

return domain;
}

private DataStructureComponent<Measure, ?, ?> createObsValue(PrimaryMeasureBean obs_value)
{
Expand Down

0 comments on commit ec92c92

Please sign in to comment.