Skip to content

Commit

Permalink
basic framework for reading Json/GeoJson data (#1042)
Browse files Browse the repository at this point in the history
ING-3128
* fix: fix Groovy compiler level in Eclipse projects
* build: fix missing package import for test bundle
* refactor: delete obsolete JSON related classes
* refactor: rename JSON writer package
* refactor: stub implementation of reading JSON instances
* refactor: don't use outdated jackson library for Json processing
* feat: improve content type matching based on extension
Value matches related to file extensions higher depending on the number
if dots they contain.
Goal is to for example not match a `.xml.gz` file to a random content
type with a `gz` extension, but to prefer the one with `xml.gz`.
  • Loading branch information
stempler authored Jul 17, 2023
1 parent 5d33569 commit 96667c8
Show file tree
Hide file tree
Showing 47 changed files with 1,250 additions and 1,325 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
eclipse.preferences.version=1
groovy.compiler.level=40
groovy.compiler.level=25
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
eclipse.preferences.version=1
groovy.compiler.level=40
groovy.compiler.level=25
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Fragment-Host: eu.esdihumboldt.hale.common.cache;bundle-version="2.5.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-Vendor: data harmonisation panel
Automatic-Module-Name: eu.esdihumboldt.hale.common.cache.test
Import-Package: org.junit
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,28 @@ public static List<IContentType> findContentTypesFor(Collection<IContentType> ty

List<IContentType> results = new ArrayList<IContentType>();

IContentType highestScoreMatch = null;
long highestScore = 0;

if (filename != null && !filename.isEmpty()) {
// test file extension
String lowerFile = filename.toLowerCase();

for (IContentType type : types) {
String[] extensions = type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
boolean match = false;
for (int i = 0; i < extensions.length && !match; i++) {
if (lowerFile.endsWith("." + extensions[i].toLowerCase())) {
match = true;

// determine score based on how many dots are contained
// in the extension (e.g. `gml.gz` has a score of 1 and
// is considered a match with a high score)
long extensionScore = extensions[i].chars().filter(ch -> ch == '.').count();
if (extensionScore > highestScore) {
highestScoreMatch = type;
highestScore = extensionScore;
}
}
}
if (match) {
Expand All @@ -226,6 +239,13 @@ public static List<IContentType> findContentTypesFor(Collection<IContentType> ty
}
}

if (results.size() > 1 && highestScoreMatch != null) {
// if there are multiple results based on extension, use the
// available match with the highest score.
results.clear();
results.add(highestScoreMatch);
}

if ((results.isEmpty() || results.size() > 1) && in != null) {
// remember previous results
List<IContentType> extensionResults = null;
Expand Down Expand Up @@ -322,9 +342,7 @@ public boolean acceptCollection(
/**
* Find an I/O provider factory
*
* @param
* <P>
* the provider interface type
* @param <P> the provider interface type
*
* @param providerType the provider type, usually an interface
* @param contentType the content type the provider must match, may be
Expand Down Expand Up @@ -366,9 +384,7 @@ public static <P extends IOProvider> IOProviderDescriptor findIOProviderFactory(
/**
* Creates an I/O provider instance
*
* @param
* <P>
* the provider interface type
* @param <P> the provider interface type
*
* @param providerType the provider type, usually an interface
* @param contentType the content type the provider must match, may be
Expand Down Expand Up @@ -399,9 +415,7 @@ public static <P extends IOProvider> P createIOProvider(Class<P> providerType,
/**
* Find the content type for the given input
*
* @param
* <P>
* the provider interface type
* @param <P> the provider interface type
*
* @param providerType the provider type, usually an interface
* @param in the input supplier to use for testing, may be <code>null</code>
Expand Down Expand Up @@ -435,9 +449,7 @@ public static <P extends IOProvider> IContentType findContentType(Class<P> provi
/**
* Find an I/O provider instance for the given input
*
* @param
* <P>
* the provider interface type
* @param <P> the provider interface type
*
* @param providerType the provider type, usually an interface
* @param in the input supplier to use for testing, may be <code>null</code>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
eclipse.preferences.version=1
groovy.compiler.level=40
groovy.compiler.level=25
groovy.script.filters=**/*.dsld,y,**/*.gradle,n
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
eclipse.preferences.version=1
groovy.compiler.level=40
groovy.compiler.level=25
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
eclipse.preferences.version=1
groovy.compiler.level=40
groovy.compiler.level=25
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ Require-Bundle: eu.esdihumboldt.hale.io.json;bundle-version="2.9.0",
eu.esdihumboldt.cst.functions.geometric;bundle-version="4.2.0",
org.locationtech.jts.jts-core;bundle-version="1.16.0",
org.junit;bundle-version="4.13.0",
eu.esdihumboldt.hale.common.align.groovy;bundle-version="2.9.0"
eu.esdihumboldt.hale.common.align.groovy;bundle-version="2.9.0",
com.fasterxml.jackson.core.jackson-core;bundle-version="2.13.4",
com.fasterxml.jackson.core.jackson-databind;bundle-version="2.13.4"
Import-Package: de.fhg.igd.slf4jplus,
eu.esdihumboldt.hale.common.instance.groovy,
eu.esdihumboldt.hale.common.instance.model,
eu.esdihumboldt.util.io,
eu.esdihumboldt.util.xml,
net.jcip.annotations,
org.assertj.core.api;version="3.22.0",
org.hamcrest.core;version="1.3.0",
org.slf4j;version="1.7.2"
Automatic-Module-Name: eu.esdihumboldt.hale.io.json.test

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import eu.esdihumboldt.hale.common.core.report.SimpleLog
import eu.esdihumboldt.hale.common.instance.groovy.InstanceBuilder
import eu.esdihumboldt.hale.common.schema.groovy.SchemaBuilder
import eu.esdihumboldt.hale.common.schema.model.Schema
import eu.esdihumboldt.hale.io.json.writer.InstanceToJson
import eu.esdihumboldt.hale.io.json.internal.InstanceToJson
import groovy.json.JsonSlurper

class InstanceToJsonTest {
Expand Down
Loading

0 comments on commit 96667c8

Please sign in to comment.