diff --git a/julielab-neo4j-plugins-concepts-representation/pom.xml b/julielab-neo4j-plugins-concepts-representation/pom.xml
index 04283ee..4c47711 100644
--- a/julielab-neo4j-plugins-concepts-representation/pom.xml
+++ b/julielab-neo4j-plugins-concepts-representation/pom.xml
@@ -4,7 +4,7 @@
de.julielabjulielab-neo4j-server-plugins
- 2.1.0-SNAPSHOT
+ 2.1.0julielab-neo4j-plugins-concepts-representation
@@ -20,7 +20,7 @@
com.fasterxml.jackson.datatypejackson-datatype-jdk8
- ${jackson-release-version}
+ 2.9.9
\ No newline at end of file
diff --git a/julielab-neo4j-plugins-concepts-representation/src/main/java/de/julielab/neo4j/plugins/datarepresentation/ConceptCoordinates.java b/julielab-neo4j-plugins-concepts-representation/src/main/java/de/julielab/neo4j/plugins/datarepresentation/ConceptCoordinates.java
index e5e33f5..f1f0222 100644
--- a/julielab-neo4j-plugins-concepts-representation/src/main/java/de/julielab/neo4j/plugins/datarepresentation/ConceptCoordinates.java
+++ b/julielab-neo4j-plugins-concepts-representation/src/main/java/de/julielab/neo4j/plugins/datarepresentation/ConceptCoordinates.java
@@ -1,11 +1,5 @@
package de.julielab.neo4j.plugins.datarepresentation;
-import org.neo4j.shell.util.json.JSONException;
-import org.neo4j.shell.util.json.JSONObject;
-
-import de.julielab.neo4j.plugins.auxiliaries.JSON;
-import de.julielab.neo4j.plugins.datarepresentation.constants.CoordinateConstants;
-
public class ConceptCoordinates implements Cloneable {
public String sourceId;
@@ -48,30 +42,6 @@ public ConceptCoordinates(String id, String source, CoordinateType src) {
}
}
- public ConceptCoordinates(JSONObject jsonObject) throws JSONException {
- this(jsonObject, true);
- }
-
- public ConceptCoordinates(JSONObject jsonObject, boolean checkConsistency) throws JSONException {
- sourceId = JSON.getString(jsonObject, CoordinateConstants.SOURCE_ID);
- source = JSON.getString(jsonObject, CoordinateConstants.SOURCE);
- originalId = JSON.getString(jsonObject, CoordinateConstants.ORIGINAL_ID);
- originalSource = JSON.getString(jsonObject, CoordinateConstants.ORIGINAL_SOURCE);
- uniqueSourceId = JSON.getBoolean(jsonObject, CoordinateConstants.UNIQUE_SOURCE_ID);
-
- if (checkConsistency) {
- if (sourceId == null && source == null && originalId == null && originalSource == null)
- throw new CoordinatesInvalidException(
- "The passed concept coordinates JSON object did not specify any IDs or sources");
-
- if (originalId == null ^ originalSource == null)
- throw new CoordinatesInvalidException(
- "Coordinates JSON specifies originalId / original source of (" + originalId + ", "
- + originalSource + ") but when one is not null, the other must be given, too.");
- }
- }
-
-
public ConceptCoordinates(ConceptCoordinates coordinates) {
this.originalId = coordinates.originalId;
diff --git a/julielab-neo4j-plugins-concepts-representation/src/main/java/de/julielab/neo4j/plugins/datarepresentation/ImportConcept.java b/julielab-neo4j-plugins-concepts-representation/src/main/java/de/julielab/neo4j/plugins/datarepresentation/ImportConcept.java
index 1eefee6..a54ce1d 100644
--- a/julielab-neo4j-plugins-concepts-representation/src/main/java/de/julielab/neo4j/plugins/datarepresentation/ImportConcept.java
+++ b/julielab-neo4j-plugins-concepts-representation/src/main/java/de/julielab/neo4j/plugins/datarepresentation/ImportConcept.java
@@ -7,190 +7,193 @@
public class ImportConcept {
- public ImportConcept(String preferredName, ConceptCoordinates coordinates) {
- prefName = preferredName;
- this.coordinates = coordinates;
- }
-
- public ImportConcept(String preferredName, String description, ConceptCoordinates coordinates) {
- this(preferredName, coordinates);
- this.descriptions = Arrays.asList(description);
- }
-
- public ImportConcept(String preferredName, List synonyms, ConceptCoordinates coordinates) {
- this(preferredName, coordinates);
- this.synonyms = synonyms;
- }
-
- public ImportConcept(String preferredName, List synonyms, String description,
- ConceptCoordinates coordinates) {
- this(preferredName, synonyms, coordinates);
- this.descriptions = Arrays.asList(description);
- }
-
- public ImportConcept(String preferredName, List synonyms, String description,
- ConceptCoordinates coordinates, ConceptCoordinates parentCoordinates) {
- this(preferredName, synonyms, Arrays.asList(description), coordinates, Arrays.asList(parentCoordinates));
- }
-
- public ImportConcept(String preferredName, List synonyms, String description,
- ConceptCoordinates coordinates, List parentCoordinates) {
- this(preferredName, synonyms, Arrays.asList(description), coordinates, parentCoordinates);
- }
-
- public ImportConcept(String preferredName, List synonyms, List descriptions,
- ConceptCoordinates coordinates) {
- this(preferredName, synonyms, coordinates);
- this.descriptions = descriptions;
- }
-
- public ImportConcept(String preferredName, List synonyms, List descriptions,
- ConceptCoordinates coordinates, ConceptCoordinates parentCoordinates) {
- this(preferredName, synonyms, descriptions, coordinates);
+ @JsonProperty(ConceptConstants.PROP_PREF_NAME)
+ public String prefName;
+ @JsonProperty(ConceptConstants.PROP_DESCRIPTIONS)
+ public List descriptions = Collections.emptyList();
+ @JsonProperty(ConceptConstants.PROP_SYNONYMS)
+ public List synonyms = Collections.emptyList();
+ @JsonProperty(ConceptConstants.PROP_WRITING_VARIANTS)
+ public List writingVariants = Collections.emptyList();
+ @JsonProperty(ConceptConstants.COORDINATES)
+ public ConceptCoordinates coordinates;
+ @JsonProperty(ConceptConstants.PARENT_COORDINATES)
+ public List parentCoordinates = Collections.emptyList();
+ @JsonProperty(ConceptConstants.RELATIONSHIPS)
+ public List relationships = Collections.emptyList();
+ @JsonProperty(ConceptConstants.PROP_LABELS)
+ public List generalLabels = Collections.emptyList();
+ @JsonProperty(ConceptConstants.PROP_DISPLAY_NAME)
+ public String displayName;
+ @JsonProperty(ConceptConstants.PROP_QUALIFIERS)
+ public List qualifiers = Collections.emptyList();
+ // ------------- for aggregates -----------------
+ @JsonProperty(ConceptConstants.AGGREGATE)
+ public boolean aggregate;
+ @JsonProperty(ConceptConstants.ELEMENT_COORDINATES)
+ public List elementCoordinates = Collections.emptyList();
+ @JsonProperty(ConceptConstants.PROP_COPY_PROPERTIES)
+ public List copyProperties = Collections.emptyList();
+ @JsonProperty(ConceptConstants.AGGREGATE_INCLUDE_IN_HIERARCHY)
+ public boolean aggregateIncludeInHierarchy;
+
+ public ImportConcept(String preferredName, ConceptCoordinates coordinates) {
+ prefName = preferredName;
+ this.coordinates = coordinates;
+ }
+
+ public ImportConcept(String preferredName, String description, ConceptCoordinates coordinates) {
+ this(preferredName, coordinates);
+ if (description != null)
+ this.descriptions = Arrays.asList(description);
+ }
+
+ public ImportConcept(String preferredName, List synonyms, ConceptCoordinates coordinates) {
+ this(preferredName, coordinates);
+ this.synonyms = synonyms;
+ }
+
+ public ImportConcept(String preferredName, List synonyms, String description,
+ ConceptCoordinates coordinates) {
+ this(preferredName, synonyms, coordinates);
+ if (description != null)
+ this.descriptions = Arrays.asList(description);
+ }
+
+ public ImportConcept(String preferredName, List synonyms, String description,
+ ConceptCoordinates coordinates, ConceptCoordinates parentCoordinates) {
+ this(preferredName, synonyms, Arrays.asList(description), coordinates, Arrays.asList(parentCoordinates));
+ }
+
+ public ImportConcept(String preferredName, List synonyms, String description,
+ ConceptCoordinates coordinates, List parentCoordinates) {
+ this(preferredName, synonyms, Arrays.asList(description), coordinates, parentCoordinates);
+ }
+
+ public ImportConcept(String preferredName, List synonyms, List descriptions,
+ ConceptCoordinates coordinates) {
+ this(preferredName, synonyms, coordinates);
+ this.descriptions = descriptions;
+ }
+
+ public ImportConcept(String preferredName, List synonyms, List descriptions,
+ ConceptCoordinates coordinates, ConceptCoordinates parentCoordinates) {
+ this(preferredName, synonyms, descriptions, coordinates);
if (parentCoordinates == null)
throw new IllegalArgumentException("The passed parent coordinates are null which is invalid (pass an empty list instead).");
- this.parentCoordinates = Arrays.asList(parentCoordinates);
- }
+ if (parentCoordinates != null)
+ this.parentCoordinates = Arrays.asList(parentCoordinates);
+ }
- public ImportConcept(String preferredName, List synonyms, List descriptions,
- ConceptCoordinates coordinates, List parentCoordinates) {
- this(preferredName, synonyms, descriptions, coordinates);
+ public ImportConcept(String preferredName, List synonyms, List descriptions,
+ ConceptCoordinates coordinates, List parentCoordinates) {
+ this(preferredName, synonyms, descriptions, coordinates);
if (parentCoordinates == null)
throw new IllegalArgumentException("The passed parent coordinates are null which is invalid (pass an empty list instead).");
- this.parentCoordinates = parentCoordinates;
- }
+ if (parentCoordinates != null)
+ this.parentCoordinates = parentCoordinates;
+ }
- public ImportConcept(String preferredName, ConceptCoordinates coordinates, ConceptCoordinates parentCoordinates) {
- this(preferredName, coordinates);
+ public ImportConcept(String preferredName, ConceptCoordinates coordinates, ConceptCoordinates parentCoordinates) {
+ this(preferredName, coordinates);
if (parentCoordinates == null)
throw new IllegalArgumentException("The passed parent coordinates are null which is invalid (pass an empty list instead).");
- this.parentCoordinates = Arrays.asList(parentCoordinates);
- }
-
- public ImportConcept(String preferredName, ConceptCoordinates coordinates,
- List parentCoordinates) {
- this(preferredName, coordinates);
- if (parentCoordinates == null)
- throw new IllegalArgumentException("The passed parent coordinates are null which is invalid (pass an empty list instead).");
- this.parentCoordinates = parentCoordinates;
- }
-
- /**
- * Constructor for aggregate terms.
- *
- * @param elementCoords
- * Coordinates of the elements to be aggregated.
- * @param copyProperties
- * The properties that should be copied from elements to the
- * aggregates.
- */
- public ImportConcept(List elementCoords, List copyProperties) {
- this.elementCoordinates = elementCoords;
- this.copyProperties = copyProperties;
- this.aggregate = true;
- }
-
- public ImportConcept(ConceptCoordinates conceptCoordinates) {
- coordinates = conceptCoordinates;
- }
-
- public ImportConcept() {
- }
-
- @JsonProperty(ConceptConstants.PROP_PREF_NAME)
- public String prefName;
- @JsonProperty(ConceptConstants.PROP_DESCRIPTIONS)
- public List descriptions = Collections.emptyList();
- @JsonProperty(ConceptConstants.PROP_SYNONYMS)
- public List synonyms = Collections.emptyList();
- @JsonProperty(ConceptConstants.PROP_WRITING_VARIANTS)
- public List writingVariants = Collections.emptyList();
- @JsonProperty(ConceptConstants.COORDINATES)
- public ConceptCoordinates coordinates;
- @JsonProperty(ConceptConstants.PARENT_COORDINATES)
- public List parentCoordinates = Collections.emptyList();
- @JsonProperty(ConceptConstants.RELATIONSHIPS)
- public List relationships = Collections.emptyList();
- @JsonProperty(ConceptConstants.PROP_LABELS)
- public List generalLabels = Collections.emptyList();
- @JsonProperty(ConceptConstants.PROP_DISPLAY_NAME)
- public String displayName;
- @JsonProperty(ConceptConstants.PROP_QUALIFIERS)
- public List qualifiers = Collections.emptyList();
-
- // ------------- for aggregates -----------------
- @JsonProperty(ConceptConstants.AGGREGATE)
- public Boolean aggregate;
- @JsonProperty(ConceptConstants.ELEMENT_COORDINATES)
- public List elementCoordinates = Collections.emptyList();
- @JsonProperty(ConceptConstants.PROP_COPY_PROPERTIES)
- public List copyProperties = Collections.emptyList();
- @JsonProperty(ConceptConstants.AGGREGATE_INCLUDE_IN_HIERARCHY)
- public Boolean aggregateIncludeInHierarchy;
-
- public void addRelationship(ImportConceptRelationship relationship) {
- if (relationships.isEmpty())
- relationships = new ArrayList<>();
- relationships.add(relationship);
- }
-
- public void addGeneralLabel(String... labels) {
- if (generalLabels.isEmpty())
- generalLabels = new ArrayList<>();
- try {
- for (int i = 0; i < labels.length; i++) {
- String label = labels[i];
- generalLabels.add(label);
- }
- } catch (java.lang.UnsupportedOperationException e) {
- generalLabels = new ArrayList<>(generalLabels);
- addGeneralLabel(labels);
- }
- }
-
- public void addCopyProperty(String property) {
- if (copyProperties.isEmpty())
- copyProperties = new ArrayList<>();
- copyProperties.add(property);
- }
-
- public void addQualifier(String speciesQualifier) {
- if (qualifiers.isEmpty())
- qualifiers = new ArrayList<>();
- qualifiers.add(speciesQualifier);
- }
-
- public void removeGeneralLabel(String... labels) {
- if (generalLabels.isEmpty())
- return;
- Set removeLabels = new HashSet<>(labels.length);
- for (int i = 0; i < labels.length; i++) {
- String label = labels[i];
- removeLabels.add(label);
- }
- Iterator existingLabels = generalLabels.iterator();
- while (existingLabels.hasNext()) {
- String existingLabel = existingLabels.next();
- if (removeLabels.contains(existingLabel))
- existingLabels.remove();
- }
-
- }
-
- public void addParent(ConceptCoordinates parentCoordinates) {
- if (this.parentCoordinates.isEmpty())
- this.parentCoordinates = new ArrayList<>();
- this.parentCoordinates.add(parentCoordinates);
- }
-
- public void addParentIfNotExists(ConceptCoordinates parentCoordinates) {
- if (this.parentCoordinates.isEmpty() || !this.parentCoordinates.contains(parentCoordinates))
- addParent(parentCoordinates);
- }
-
- public boolean hasParents() {
- return !parentCoordinates.isEmpty();
- }
-
-
+ if (parentCoordinates != null)
+ this.parentCoordinates = Arrays.asList(parentCoordinates);
+ }
+
+ public ImportConcept(String preferredName, ConceptCoordinates coordinates,
+ List parentCoordinates) {
+ this(preferredName, coordinates);
+ if (parentCoordinates == null)
+ throw new IllegalArgumentException("The passed parent coordinates are null which is invalid (pass an empty list instead).");
+ if (parentCoordinates != null)
+ this.parentCoordinates = parentCoordinates;
+ }
+
+ /**
+ * Constructor for aggregate terms.
+ *
+ * @param elementCoords Coordinates of the elements to be aggregated.
+ * @param copyProperties The properties that should be copied from elements to the
+ * aggregates.
+ */
+ public ImportConcept(List elementCoords, List copyProperties) {
+ this.elementCoordinates = elementCoords;
+ this.copyProperties = copyProperties;
+ this.aggregate = true;
+ }
+
+ public ImportConcept(ConceptCoordinates conceptCoordinates) {
+ coordinates = conceptCoordinates;
+ }
+
+ public ImportConcept() {
+ }
+
+ public void addRelationship(ImportConceptRelationship relationship) {
+ if (relationships.isEmpty())
+ relationships = new ArrayList<>();
+ relationships.add(relationship);
+ }
+
+ public void addGeneralLabel(String... labels) {
+ if (generalLabels.isEmpty())
+ generalLabels = new ArrayList<>();
+ try {
+ for (int i = 0; i < labels.length; i++) {
+ String label = labels[i];
+ generalLabels.add(label);
+ }
+ } catch (java.lang.UnsupportedOperationException e) {
+ generalLabels = new ArrayList<>(generalLabels);
+ addGeneralLabel(labels);
+ }
+ }
+
+ public void addCopyProperty(String property) {
+ if (copyProperties.isEmpty())
+ copyProperties = new ArrayList<>();
+ copyProperties.add(property);
+ }
+
+ public void addQualifier(String speciesQualifier) {
+ if (qualifiers.isEmpty())
+ qualifiers = new ArrayList<>();
+ qualifiers.add(speciesQualifier);
+ }
+
+ public void removeGeneralLabel(String... labels) {
+ if (generalLabels.isEmpty())
+ return;
+ Set removeLabels = new HashSet<>(labels.length);
+ for (int i = 0; i < labels.length; i++) {
+ String label = labels[i];
+ removeLabels.add(label);
+ }
+ Iterator existingLabels = generalLabels.iterator();
+ while (existingLabels.hasNext()) {
+ String existingLabel = existingLabels.next();
+ if (removeLabels.contains(existingLabel))
+ existingLabels.remove();
+ }
+
+ }
+
+ public void addParent(ConceptCoordinates parentCoordinates) {
+ if (this.parentCoordinates.isEmpty())
+ this.parentCoordinates = new ArrayList<>();
+ this.parentCoordinates.add(parentCoordinates);
+ }
+
+ public void addParentIfNotExists(ConceptCoordinates parentCoordinates) {
+ if (this.parentCoordinates.isEmpty() || !this.parentCoordinates.contains(parentCoordinates))
+ addParent(parentCoordinates);
+ }
+
+ public boolean hasParents() {
+ return !parentCoordinates.isEmpty();
+ }
+
+
}
diff --git a/julielab-neo4j-plugins-concepts-representation/src/main/java/de/julielab/neo4j/plugins/datarepresentation/ImportConceptRelationship.java b/julielab-neo4j-plugins-concepts-representation/src/main/java/de/julielab/neo4j/plugins/datarepresentation/ImportConceptRelationship.java
index c083790..b8bca00 100644
--- a/julielab-neo4j-plugins-concepts-representation/src/main/java/de/julielab/neo4j/plugins/datarepresentation/ImportConceptRelationship.java
+++ b/julielab-neo4j-plugins-concepts-representation/src/main/java/de/julielab/neo4j/plugins/datarepresentation/ImportConceptRelationship.java
@@ -20,6 +20,9 @@ public class ImportConceptRelationship {
@JsonProperty(ConceptConstants.RS_PROPS)
public Map properties;
+ public ImportConceptRelationship() {
+ }
+
public ImportConceptRelationship(ConceptCoordinates targetCoordinates, String relationType) {
this.targetCoordinates = targetCoordinates;
this.type = relationType;
diff --git a/julielab-neo4j-plugins-concepts-representation/src/main/java/de/julielab/neo4j/plugins/datarepresentation/ImportConcepts.java b/julielab-neo4j-plugins-concepts-representation/src/main/java/de/julielab/neo4j/plugins/datarepresentation/ImportConcepts.java
index 382ade3..e01473c 100644
--- a/julielab-neo4j-plugins-concepts-representation/src/main/java/de/julielab/neo4j/plugins/datarepresentation/ImportConcepts.java
+++ b/julielab-neo4j-plugins-concepts-representation/src/main/java/de/julielab/neo4j/plugins/datarepresentation/ImportConcepts.java
@@ -1,27 +1,25 @@
package de.julielab.neo4j.plugins.datarepresentation;
-import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-import com.fasterxml.jackson.annotation.JsonIgnore;
-
public class ImportConcepts {
- private Stream concepts;
- private List conceptsAsList;
+ private List concepts;
private ImportFacet facet;
private ImportOptions importOptions;
+ public ImportConcepts(){}
+
public ImportConcepts(ImportFacet facet) {
this.facet = facet;
}
public ImportConcepts(Stream termList, ImportFacet facet) {
- this.concepts = termList;
- this.facet = facet;
+ this(termList != null ? termList.collect(Collectors.toList()) : Collections.emptyList(), facet);
}
public ImportConcepts(Stream termList, ImportFacet importFacet, ImportOptions importOptions) {
@@ -29,9 +27,10 @@ public ImportConcepts(Stream termList, ImportFacet importFacet, I
this.importOptions = importOptions;
}
+
/**
* Constructor for an already existing list of concepts. The list will directly
- * be used for {@link #getConcepts()} and {@link #getConceptsAsList()};
+ * be used for {@link #getConcepts()} and {@link #getConcepts()};
*
* @param concepts
* The list of concepts.
@@ -39,13 +38,13 @@ public ImportConcepts(Stream termList, ImportFacet importFacet, I
* The facet to add the concepts to.
*/
public ImportConcepts(List concepts, ImportFacet importFacet) {
- this((Stream) null, importFacet);
- this.conceptsAsList = concepts;
+ this.concepts = concepts;
+ this.facet = importFacet;
}
/**
* Constructor for an already existing list of concepts. The list will directly
- * be used for {@link #getConcepts()} and {@link #getConceptsAsList()};
+ * be used for {@link #getConcepts()} and {@link #getConcepts()};
*
* @param concepts
* The list of concepts.
@@ -56,46 +55,21 @@ public ImportConcepts(List concepts, ImportFacet importFacet) {
*/
public ImportConcepts(List concepts, ImportFacet importFacet, ImportOptions importOptions) {
this((Stream) null, importFacet, importOptions);
- this.conceptsAsList = concepts;
}
/**
* Returns the concepts as a stream. This may be the single, original stream
* given to the constructor, or a stream derived from a underlying list in case
* a list of concepts was passed to a constructor or
- * {@link #getConceptsAsList()} was called at least once.
+ * {@link #getConcepts()} was called at least once.
*
* @return The concepts as a stream.
*/
- public Stream getConcepts() {
- if (conceptsAsList != null)
- return conceptsAsList.stream();
+ public List getConcepts() {
return concepts;
}
- /**
- *
- * If index-based access to the concepts is required, this method can be called.
- * If one of the constructors was called taking a stream of ImportConcepts, this
- * causes the concept stream to be collected into a list. Starting from the
- * first call of this method, only the list representation will then be used.
- * Even {@link #getConcepts()} will return a new stream created from the list.
- * Thus, this method comes with a - possibly minor - performance penalty.
- *
- *
- * In case that one of the constructors taking a list of concepts was used, this
- * is the method to go.
- *
- *
- * @return The concepts as list.
- */
- @JsonIgnore
- public List getConceptsAsList() {
- if (conceptsAsList == null) {
- conceptsAsList = concepts.collect(Collectors.toCollection(ArrayList::new));
- }
- return conceptsAsList;
- }
+
public ImportFacet getFacet() {
return facet;
@@ -105,7 +79,7 @@ public ImportOptions getImportOptions() {
return importOptions;
}
- public void setConcepts(Stream concepts) {
+ public void setConcepts(List concepts) {
this.concepts = concepts;
}
diff --git a/julielab-neo4j-plugins-concepts-representation/src/main/java/de/julielab/neo4j/plugins/datarepresentation/ImportFacet.java b/julielab-neo4j-plugins-concepts-representation/src/main/java/de/julielab/neo4j/plugins/datarepresentation/ImportFacet.java
index 00bb973..22fd362 100644
--- a/julielab-neo4j-plugins-concepts-representation/src/main/java/de/julielab/neo4j/plugins/datarepresentation/ImportFacet.java
+++ b/julielab-neo4j-plugins-concepts-representation/src/main/java/de/julielab/neo4j/plugins/datarepresentation/ImportFacet.java
@@ -1,16 +1,15 @@
package de.julielab.neo4j.plugins.datarepresentation;
-import static de.julielab.neo4j.plugins.datarepresentation.constants.FacetConstants.FACET_GROUP;
-import static de.julielab.neo4j.plugins.datarepresentation.constants.FacetConstants.PROP_SOURCE_TYPE;
-import static de.julielab.neo4j.plugins.datarepresentation.constants.NodeConstants.PROP_LABELS;
-import static de.julielab.neo4j.plugins.datarepresentation.constants.NodeConstants.PROP_NAME;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import de.julielab.neo4j.plugins.datarepresentation.constants.FacetConstants;
import java.util.ArrayList;
import java.util.Collection;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-import de.julielab.neo4j.plugins.datarepresentation.constants.FacetConstants;
+import static de.julielab.neo4j.plugins.datarepresentation.constants.FacetConstants.FACET_GROUP;
+import static de.julielab.neo4j.plugins.datarepresentation.constants.FacetConstants.PROP_SOURCE_TYPE;
+import static de.julielab.neo4j.plugins.datarepresentation.constants.NodeConstants.PROP_LABELS;
+import static de.julielab.neo4j.plugins.datarepresentation.constants.NodeConstants.PROP_NAME;
public class ImportFacet {
/**
@@ -42,7 +41,24 @@ public class ImportFacet {
protected String shortName;
@JsonProperty(PROP_SOURCE_TYPE)
protected String sourceType;
- /**
+
+ public ImportFacet(){}
+
+ @Override
+ public String toString() {
+ return "ImportFacet{" +
+ "customId='" + customId + '\'' +
+ ", facetGroup=" + facetGroup +
+ ", id='" + id + '\'' +
+ ", labels=" + labels +
+ ", name='" + name + '\'' +
+ ", noFacet=" + noFacet +
+ ", shortName='" + shortName + '\'' +
+ ", sourceType='" + sourceType + '\'' +
+ '}';
+ }
+
+ /**
* Constructor eligible for creating new facets in the database.
*
* @param facetGroup
diff --git a/julielab-neo4j-plugins-concepts-representation/src/main/java/de/julielab/neo4j/plugins/datarepresentation/ImportFacetGroup.java b/julielab-neo4j-plugins-concepts-representation/src/main/java/de/julielab/neo4j/plugins/datarepresentation/ImportFacetGroup.java
index ffcb7fb..bc61dda 100644
--- a/julielab-neo4j-plugins-concepts-representation/src/main/java/de/julielab/neo4j/plugins/datarepresentation/ImportFacetGroup.java
+++ b/julielab-neo4j-plugins-concepts-representation/src/main/java/de/julielab/neo4j/plugins/datarepresentation/ImportFacetGroup.java
@@ -1,11 +1,10 @@
package de.julielab.neo4j.plugins.datarepresentation;
-import java.util.List;
-
import com.fasterxml.jackson.annotation.JsonProperty;
-
import de.julielab.neo4j.plugins.datarepresentation.constants.FacetGroupConstants;
+import java.util.List;
+
public class ImportFacetGroup {
public ImportFacetGroup(String name, int position, List generalLabels) {
this.name = name;
@@ -13,7 +12,18 @@ public ImportFacetGroup(String name, int position, List generalLabels) {
this.labels = generalLabels;
}
- public ImportFacetGroup(String name) {
+ public ImportFacetGroup(){}
+
+ @Override
+ public String toString() {
+ return "ImportFacetGroup{" +
+ "name='" + name + '\'' +
+ ", labels=" + labels +
+ ", type='" + type + '\'' +
+ '}';
+ }
+
+ public ImportFacetGroup(String name) {
this.name = name;
}
diff --git a/julielab-neo4j-plugins-concepts-representation/src/main/java/de/julielab/neo4j/plugins/datarepresentation/constants/ConceptConstants.java b/julielab-neo4j-plugins-concepts-representation/src/main/java/de/julielab/neo4j/plugins/datarepresentation/constants/ConceptConstants.java
index a5056ed..9459f98 100644
--- a/julielab-neo4j-plugins-concepts-representation/src/main/java/de/julielab/neo4j/plugins/datarepresentation/constants/ConceptConstants.java
+++ b/julielab-neo4j-plugins-concepts-representation/src/main/java/de/julielab/neo4j/plugins/datarepresentation/constants/ConceptConstants.java
@@ -1,7 +1,5 @@
package de.julielab.neo4j.plugins.datarepresentation.constants;
-import de.julielab.neo4j.plugins.datarepresentation.ConceptCoordinates;
-
public class ConceptConstants extends NodeConstants {
diff --git a/julielab-neo4j-plugins-concepts-representation/src/main/java/de/julielab/neo4j/plugins/datarepresentation/util/ConceptsJsonSerializer.java b/julielab-neo4j-plugins-concepts-representation/src/main/java/de/julielab/neo4j/plugins/datarepresentation/util/ConceptsJsonSerializer.java
index 73eaef1..d2a43ce 100644
--- a/julielab-neo4j-plugins-concepts-representation/src/main/java/de/julielab/neo4j/plugins/datarepresentation/util/ConceptsJsonSerializer.java
+++ b/julielab-neo4j-plugins-concepts-representation/src/main/java/de/julielab/neo4j/plugins/datarepresentation/util/ConceptsJsonSerializer.java
@@ -2,9 +2,12 @@
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
+import java.io.IOException;
+
public class ConceptsJsonSerializer {
private ConceptsJsonSerializer() {
}
@@ -22,4 +25,12 @@ public static synchronized String toJson(Object serializable) {
throw new UncheckedJsonProcessingException(e);
}
}
+
+ public static synchronized T fromJson(String json, Class cls) throws IOException {
+ return mapper.readValue(json, cls);
+ }
+
+ public static synchronized T fromJson(String json, TypeReference ref) throws IOException {
+ return mapper.readValue(json, ref);
+ }
}
diff --git a/julielab-neo4j-plugins-concepts/.gitignore b/julielab-neo4j-plugins-concepts/.gitignore
index 23c8321..6f610d6 100644
--- a/julielab-neo4j-plugins-concepts/.gitignore
+++ b/julielab-neo4j-plugins-concepts/.gitignore
@@ -3,3 +3,4 @@
/.project
/.settings/
/src/test/resources/graph.db/
+/.idea
\ No newline at end of file
diff --git a/julielab-neo4j-plugins-concepts/pom.xml b/julielab-neo4j-plugins-concepts/pom.xml
index 55a3eb5..8bf04e8 100644
--- a/julielab-neo4j-plugins-concepts/pom.xml
+++ b/julielab-neo4j-plugins-concepts/pom.xml
@@ -4,7 +4,7 @@
de.julielabjulielab-neo4j-server-plugins
- 2.1.0-SNAPSHOT
+ 2.1.0..julielab-neo4j-plugins-concepts
diff --git a/julielab-neo4j-plugins-concepts/src/main/java/de/julielab/neo4j/plugins/ConceptManager.java b/julielab-neo4j-plugins-concepts/src/main/java/de/julielab/neo4j/plugins/ConceptManager.java
index 37bc99a..4d4eab7 100644
--- a/julielab-neo4j-plugins-concepts/src/main/java/de/julielab/neo4j/plugins/ConceptManager.java
+++ b/julielab-neo4j-plugins-concepts/src/main/java/de/julielab/neo4j/plugins/ConceptManager.java
@@ -1,20 +1,19 @@
package de.julielab.neo4j.plugins;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
import com.google.gson.stream.JsonReader;
import de.julielab.neo4j.plugins.FacetManager.FacetLabel;
-import de.julielab.neo4j.plugins.auxiliaries.JSON;
import de.julielab.neo4j.plugins.auxiliaries.PropertyUtilities;
import de.julielab.neo4j.plugins.auxiliaries.semedico.*;
import de.julielab.neo4j.plugins.auxiliaries.semedico.ConceptAggregateBuilder.CopyAggregatePropertiesStatistics;
import de.julielab.neo4j.plugins.constants.semedico.SequenceConstants;
-import de.julielab.neo4j.plugins.datarepresentation.AddToNonFacetGroupCommand;
-import de.julielab.neo4j.plugins.datarepresentation.ConceptCoordinates;
-import de.julielab.neo4j.plugins.datarepresentation.ImportOptions;
-import de.julielab.neo4j.plugins.datarepresentation.PushConceptsToSetCommand;
+import de.julielab.neo4j.plugins.datarepresentation.*;
import de.julielab.neo4j.plugins.datarepresentation.PushConceptsToSetCommand.ConceptSelectionDefinition;
import de.julielab.neo4j.plugins.datarepresentation.constants.*;
+import de.julielab.neo4j.plugins.datarepresentation.util.ConceptsJsonSerializer;
import de.julielab.neo4j.plugins.util.AggregateConceptInsertionException;
import de.julielab.neo4j.plugins.util.ConceptInsertionException;
import org.apache.commons.lang.StringUtils;
@@ -30,9 +29,6 @@
import org.neo4j.server.rest.repr.MappingRepresentation;
import org.neo4j.server.rest.repr.RecursiveMappingRepresentation;
import org.neo4j.server.rest.repr.Representation;
-import org.neo4j.shell.util.json.JSONArray;
-import org.neo4j.shell.util.json.JSONException;
-import org.neo4j.shell.util.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -142,11 +138,12 @@ public void buildAggregatesByMappings(@Source GraphDatabaseService graphDb,
+ " can be aggregate concepts (with the label AGGREGATE) or just plain concepts"
+ " (with the label CONCEPT) that are not an element of an aggregate.") @Parameter(name = KEY_AGGREGATED_LABEL) String aggregatedConceptsLabelString,
@Description("Label to restrict the concepts to that are considered for aggregation creation.") @Parameter(name = KEY_LABEL, optional = true) String allowedConceptLabelString)
- throws JSONException {
- JSONArray allowedMappingTypesJson = new JSONArray(allowedMappingTypesArray);
+ throws IOException {
+ ObjectMapper om = new ObjectMapper();
+ final String[] allowedMappingTypesJson = om.readValue(allowedMappingTypesArray, String[].class);
Set allowedMappingTypes = new HashSet<>();
- for (int i = 0; i < allowedMappingTypesJson.length(); i++) {
- allowedMappingTypes.add(allowedMappingTypesJson.getString(i));
+ for (int i = 0; i < allowedMappingTypesJson.length; i++) {
+ allowedMappingTypes.add(allowedMappingTypesJson[i]);
}
Label aggregatedConceptsLabel = Label.label(aggregatedConceptsLabelString);
Label allowedConceptLabel = StringUtils.isBlank(allowedConceptLabelString) ? null
@@ -163,8 +160,7 @@ public void buildAggregatesByMappings(@Source GraphDatabaseService graphDb,
public void deleteAggregatesByMappigs(@Source GraphDatabaseService graphDb,
@Description("Label for concepts that have been processed by the aggregation algorithm. Such concepts"
+ " can be aggregate concepts (with the label AGGREGATE) or just plain concepts"
- + " (with the label CONCEPT) that are not an element of an aggregate.") @Parameter(name = KEY_AGGREGATED_LABEL) String aggregatedConceptsLabelString)
- throws JSONException {
+ + " (with the label CONCEPT) that are not an element of an aggregate.") @Parameter(name = KEY_AGGREGATED_LABEL) String aggregatedConceptsLabelString) {
Label aggregatedConceptsLabel = Label.label(aggregatedConceptsLabelString);
ConceptAggregateBuilder.deleteAggregates(graphDb, aggregatedConceptsLabel);
}
@@ -175,9 +171,9 @@ public void deleteAggregatesByMappigs(@Source GraphDatabaseService graphDb,
@PluginTarget(GraphDatabaseService.class)
public void buildAggregatesByNameAndSynonyms(@Source GraphDatabaseService graphDb,
@Description("TODO") @Parameter(name = KEY_CONCEPT_PROP_KEY) String conceptPropertyKey,
- @Description("TODO") @Parameter(name = KEY_CONCEPT_PROP_VALUES) String propertyValues)
- throws JSONException {
- JSONArray jsonPropertyValues = new JSONArray(propertyValues);
+ @Description("TODO") @Parameter(name = KEY_CONCEPT_PROP_VALUES) String propertyValues) throws IOException {
+ final ObjectMapper om = new ObjectMapper();
+ final String[] jsonPropertyValues = om.readValue(propertyValues, String[].class);
ConceptAggregateBuilder.buildAggregatesForEqualNames(graphDb, conceptPropertyKey, jsonPropertyValues);
}
@@ -226,9 +222,8 @@ private int copyAggregatePropertiesRecursively(Node aggregate, CopyAggregateProp
return alreadySeen.size();
}
- private void createRelationships(GraphDatabaseService graphDb, JSONArray jsonConcepts, Node facet,
- CoordinatesMap nodesByCoordinates, ImportOptions importOptions, InsertionReport insertionReport)
- throws JSONException {
+ private void createRelationships(GraphDatabaseService graphDb, List jsonConcepts, Node facet,
+ CoordinatesMap nodesByCoordinates, ImportOptions importOptions, InsertionReport insertionReport) {
log.info("Creating relationship between inserted concepts.");
Index idIndex = graphDb.index().forNodes(ConceptConstants.INDEX_NAME);
String facetId = null;
@@ -239,21 +234,21 @@ private void createRelationships(GraphDatabaseService graphDb, JSONArray jsonCon
relBroaderThanInFacet = RelationshipType.withName(EdgeTypes.IS_BROADER_THAN.toString() + "_" + facetId);
AddToNonFacetGroupCommand noFacetCmd = importOptions.noFacetCmd;
Node noFacet = null;
- int quarter = jsonConcepts.length() / 4;
+ int quarter = jsonConcepts.size() / 4;
int numQuarter = 1;
long totalTime = 0;
long relCreationTime = 0;
- for (int i = 0; i < jsonConcepts.length(); i++) {
+ for (int i = 0; i < jsonConcepts.size(); i++) {
long time = System.currentTimeMillis();
- JSONObject jsonConcept = jsonConcepts.getJSONObject(i);
+ ImportConcept jsonConcept = jsonConcepts.get(i);
// aggregates may be included into the taxonomy, but by default they
// are not
- if (JSON.getBoolean(jsonConcept, ConceptConstants.AGGREGATE)
- && !JSON.getBoolean(jsonConcept, ConceptConstants.AGGREGATE_INCLUDE_IN_HIERARCHY))
+ if (jsonConcept.aggregate
+ && !jsonConcept.aggregateIncludeInHierarchy)
continue;
- JSONObject coordinates = jsonConcept.getJSONObject(COORDINATES);
+ ConceptCoordinates coordinates = jsonConcept.coordinates;
// Every concept must have a source ID...
- String srcId = coordinates.getString(CoordinateConstants.SOURCE_ID);
+ String srcId = coordinates.sourceId;
// ...but it is not required to have a parent in its source.
// Then, it's a facet root.
Node concept = nodesByCoordinates.get(new ConceptCoordinates(coordinates));
@@ -266,11 +261,9 @@ private void createRelationships(GraphDatabaseService graphDb, JSONArray jsonCon
}
// Default-relationships (taxonomical).
{
- if (jsonConcept.has(PARENT_COORDINATES) && jsonConcept.getJSONArray(PARENT_COORDINATES).length() > 0) {
- JSONArray parentCoordinateArray = jsonConcept.getJSONArray(PARENT_COORDINATES);
- for (int j = 0; j < parentCoordinateArray.length(); j++) {
- ConceptCoordinates parentCoordinates = new ConceptCoordinates(
- parentCoordinateArray.getJSONObject(j));
+ final List parentCoordinateList = jsonConcept.parentCoordinates;
+ if (parentCoordinateList != null && !parentCoordinateList.isEmpty()) {
+ for (ConceptCoordinates parentCoordinates : parentCoordinateList) {
String parentSrcId = parentCoordinates.sourceId;
if (importOptions.cutParents.contains(parentSrcId)) {
@@ -405,14 +398,11 @@ private void createRelationships(GraphDatabaseService graphDb, JSONArray jsonCon
// is-mapped-to,
// whatever...)
{
- if (jsonConcept.has(ConceptConstants.RELATIONSHIPS)) {
+ if (jsonConcept.relationships != null) {
log.info("Adding explicitly specified relationships");
- JSONArray jsonRelationships = jsonConcept.getJSONArray(ConceptConstants.RELATIONSHIPS);
- for (int j = 0; j < jsonRelationships.length(); j++) {
- JSONObject jsonRelationship = jsonRelationships.getJSONObject(j);
- String rsTypeStr = jsonRelationship.getString(ConceptConstants.RS_TYPE);
- final JSONObject targetCoordinateJson = jsonRelationship.getJSONObject(ConceptConstants.RS_TARGET_COORDINATES);
- final ConceptCoordinates targetCoordinates = new ConceptCoordinates(targetCoordinateJson);
+ for (ImportConceptRelationship jsonRelationship : jsonConcept.relationships) {
+ String rsTypeStr = jsonRelationship.type;
+ final ConceptCoordinates targetCoordinates = jsonRelationship.targetCoordinates;
Node target = lookupConcept(targetCoordinates, idIndex);
if (null == target) {
log.debug("Creating hollow relationship target with orig Id/orig source " + targetCoordinates);
@@ -420,15 +410,15 @@ private void createRelationships(GraphDatabaseService graphDb, JSONArray jsonCon
}
EdgeTypes type = EdgeTypes.valueOf(rsTypeStr);
Object[] properties = null;
- if (jsonRelationship.has(ConceptConstants.RS_PROPS)) {
- JSONObject relProps = jsonRelationship.getJSONObject(ConceptConstants.RS_PROPS);
- JSONArray propNames = relProps.names();
- properties = new Object[propNames.length() * 2];
- for (int k = 0; k < propNames.length(); ++k) {
- String propName = propNames.getString(k);
- Object propValue = relProps.get(propName);
+ if (jsonRelationship.properties != null) {
+ Set propNames = jsonRelationship.properties.keySet();
+ properties = new Object[propNames.size() * 2];
+ int k = 0;
+ for (String propName : propNames) {
+ Object propValue = jsonRelationship.properties.get(propName);
properties[2 * k] = propName;
properties[2 * k + 1] = propValue;
+ ++k;
}
}
createRelationShipIfNotExists(concept, target, type, insertionReport, Direction.OUTGOING,
@@ -582,18 +572,18 @@ public void createSchemaIndexes(@Source GraphDatabaseService graphDb) {
@PluginTarget(GraphDatabaseService.class)
public MappingRepresentation getChildrenOfConcepts(@Source GraphDatabaseService graphDb,
@Description("JSON array of concept IDs for which to return their children.") @Parameter(name = KEY_CONCEPT_IDS) String conceptIdArray,
- @Description("The label agsinst which the given concept IDs are resolved. Defaults to 'CONCEPT'.") @Parameter(name = KEY_LABEL, optional = true) String labelString)
- throws JSONException {
+ @Description("The label agsinst which the given concept IDs are resolved. Defaults to 'CONCEPT'.") @Parameter(name = KEY_LABEL, optional = true) String labelString) throws IOException {
Label label = ConceptLabel.CONCEPT;
if (!StringUtils.isBlank(labelString))
label = Label.label(labelString);
- JSONArray conceptIds = new JSONArray(conceptIdArray);
+ final ObjectMapper om = new ObjectMapper();
+ final String[] conceptIds = om.readValue(conceptIdArray, String[].class);
try (Transaction tx = graphDb.beginTx()) {
Map childrenByConceptId = new HashMap<>();
- for (int i = 0; i < conceptIds.length(); i++) {
+ for (int i = 0; i < conceptIds.length; i++) {
Map> reltypesByNodeId = new HashMap<>();
Set childList = new HashSet<>();
- String conceptId = conceptIds.getString(i);
+ String conceptId = conceptIds[i];
Node concept = NodeUtilities.findSingleNodeByLabelAndProperty(graphDb, label, PROP_ID, conceptId);
if (null != concept) {
Iterator rels = concept.getRelationships(Direction.OUTGOING).iterator();
@@ -648,30 +638,26 @@ public Representation getPathsFromFacetroots(@Source GraphDatabaseService graphD
@Description("TODO") @Parameter(name = KEY_CONCEPT_IDS) String conceptIdsJsonString,
@Description("TODO") @Parameter(name = KEY_ID_TYPE) String idType,
@Description("TODO") @Parameter(name = KEY_SORT_RESULT) boolean sort,
- @Description("TODO") @Parameter(name = KEY_FACET_ID) final String facetId) throws JSONException {
- JSONArray conceptIds = new JSONArray(conceptIdsJsonString);
-
- Evaluator rootConceptEvaluator = new Evaluator() {
-
- @Override
- public Evaluation evaluate(Path path) {
- Node endNode = path.endNode();
-
- Iterator iterator = endNode.getRelationships(EdgeTypes.HAS_ROOT_CONCEPT).iterator();
- if (iterator.hasNext()) {
- if (StringUtils.isBlank(facetId)) {
- return Evaluation.INCLUDE_AND_CONTINUE;
- } else {
- String[] facetIds = (String[]) endNode.getProperty(PROP_FACETS);
- for (String facetIdOfRootNode : facetIds) {
- if (facetIdOfRootNode.equals(facetId))
- return Evaluation.INCLUDE_AND_CONTINUE;
- }
+ @Description("TODO") @Parameter(name = KEY_FACET_ID) final String facetId) throws IOException {
+ final ObjectMapper om = new ObjectMapper();
+ final String[] conceptIds = om.readValue(conceptIdsJsonString, String[].class);
+
+ Evaluator rootConceptEvaluator = path -> {
+ Node endNode = path.endNode();
+
+ Iterator iterator = endNode.getRelationships(EdgeTypes.HAS_ROOT_CONCEPT).iterator();
+ if (iterator.hasNext()) {
+ if (StringUtils.isBlank(facetId)) {
+ return Evaluation.INCLUDE_AND_CONTINUE;
+ } else {
+ String[] facetIds = (String[]) endNode.getProperty(PROP_FACETS);
+ for (String facetIdOfRootNode : facetIds) {
+ if (facetIdOfRootNode.equals(facetId))
+ return Evaluation.INCLUDE_AND_CONTINUE;
}
}
- return Evaluation.EXCLUDE_AND_CONTINUE;
}
-
+ return Evaluation.EXCLUDE_AND_CONTINUE;
};
RelationshipType relType = StringUtils.isBlank(facetId) ? ConceptManager.EdgeTypes.IS_BROADER_THAN
: RelationshipType.withName(ConceptManager.EdgeTypes.IS_BROADER_THAN.name() + "_" + facetId);
@@ -680,12 +666,12 @@ public Evaluation evaluate(Path path) {
try (Transaction tx = graphDb.beginTx()) {
StringBuilder sb = new StringBuilder();
- for (int i = 0; i < conceptIds.length(); i++) {
- String conceptId = conceptIds.getString(i);
+ for (int i = 0; i < conceptIds.length; i++) {
+ String conceptId = conceptIds[i];
// escape the conceptId for the Lucene lookup
conceptId = QueryParser.escape(conceptId);
sb.append(idType).append(":").append(conceptId);
- if (i < conceptIds.length() - 1)
+ if (i < conceptIds.length - 1)
sb.append(" ");
}
String conceptQuery = sb.toString();
@@ -771,24 +757,23 @@ public int compare(String[] o1, String[] o2) {
* @param insertionReport
* @param importOptions
* @return
- * @throws JSONException
* @throws AggregateConceptInsertionException
*/
- private void insertAggregateConcept(GraphDatabaseService graphDb, Index conceptIndex, JSONObject jsonConcept,
+ private void insertAggregateConcept(GraphDatabaseService graphDb, Index conceptIndex, ImportConcept jsonConcept,
CoordinatesMap nodesByCoordinates, InsertionReport insertionReport, ImportOptions importOptions)
throws AggregateConceptInsertionException {
try {
- JSONObject aggCoordinates = jsonConcept.has(COORDINATES) ? jsonConcept.getJSONObject(COORDINATES)
- : new JSONObject();
- String aggOrgId = JSON.getString(aggCoordinates, CoordinateConstants.ORIGINAL_ID);
- String aggOrgSource = JSON.getString(aggCoordinates, CoordinateConstants.ORIGINAL_SOURCE);
- String aggSrcId = JSON.getString(aggCoordinates, CoordinateConstants.SOURCE_ID);
- String aggSource = JSON.getString(aggCoordinates, CoordinateConstants.SOURCE);
+ ConceptCoordinates aggCoordinates = jsonConcept.coordinates != null ? jsonConcept.coordinates
+ : new ConceptCoordinates();
+ String aggOrgId = aggCoordinates.originalId;
+ String aggOrgSource = aggCoordinates.originalSource;
+ String aggSrcId = aggCoordinates.sourceId;
+ String aggSource = aggCoordinates.source;
if (null == aggSource)
aggSource = UNKNOWN_CONCEPT_SOURCE;
log.trace("Looking up aggregate ({}, {}) / ({}, {}), original/source coordinates.", aggOrgId, aggOrgSource,
aggSrcId, aggSource);
- Node aggregate = lookupConcept(new ConceptCoordinates(aggCoordinates, false), conceptIndex);
+ Node aggregate = lookupConcept(aggCoordinates, conceptIndex);
if (null != aggregate) {
String isHollowMessage = "";
if (aggregate.hasLabel(ConceptLabel.HOLLOW))
@@ -805,17 +790,14 @@ private void insertAggregateConcept(GraphDatabaseService graphDb, Index co
log.trace(" aggregate is being created");
aggregate = graphDb.createNode(ConceptLabel.AGGREGATE);
}
- boolean includeAggreationInHierarchy = jsonConcept.has(AGGREGATE_INCLUDE_IN_HIERARCHY)
- && jsonConcept.getBoolean(AGGREGATE_INCLUDE_IN_HIERARCHY);
+ boolean includeAggreationInHierarchy = jsonConcept.aggregateIncludeInHierarchy;
// If the aggregate is to be included into the hierarchy, it also should
// be a CONCEPT for path creation
if (includeAggreationInHierarchy)
aggregate.addLabel(ConceptLabel.CONCEPT);
- JSONArray elementCoords = jsonConcept.getJSONArray(ConceptConstants.ELEMENT_COORDINATES);
+ List elementCoords = jsonConcept.elementCoordinates;
log.trace(" looking up aggregate elements");
- for (int i = 0; i < elementCoords.length(); i++) {
- JSONObject elementCoord = elementCoords.getJSONObject(i);
- final ConceptCoordinates elementCoordinates = new ConceptCoordinates(elementCoord);
+ for (ConceptCoordinates elementCoordinates : elementCoords) {
String elementSource = elementCoordinates.source;
if (null == elementCoordinates.source)
elementSource = UNKNOWN_CONCEPT_SOURCE;
@@ -869,13 +851,13 @@ private void insertAggregateConcept(GraphDatabaseService graphDb, Index co
aggregate.setProperty(PROP_ORG_ID, aggOrgId);
if (null != aggOrgSource)
aggregate.setProperty(PROP_ORG_SRC, aggOrgSource);
- JSONArray copyProperties = JSON.getJSONArray(jsonConcept, ConceptConstants.PROP_COPY_PROPERTIES);
- if (null != copyProperties && copyProperties.length() > 0)
- aggregate.setProperty(ConceptConstants.PROP_COPY_PROPERTIES, JSON.json2JavaArray(copyProperties));
+ List copyProperties = jsonConcept.copyProperties;
+ if (null != copyProperties && !copyProperties.isEmpty())
+ aggregate.setProperty(ConceptConstants.PROP_COPY_PROPERTIES, copyProperties.toArray(new String[0]));
- JSONArray generalLabels = JSON.getJSONArray(jsonConcept, ConceptConstants.PROP_LABELS);
- for (int i = 0; null != generalLabels && i < generalLabels.length(); i++) {
- aggregate.addLabel(Label.label(generalLabels.getString(i)));
+ List generalLabels = jsonConcept.generalLabels;
+ for (int i = 0; null != generalLabels && i < generalLabels.size(); i++) {
+ aggregate.addLabel(Label.label(generalLabels.get(i)));
}
String aggregateId = NodeIDPrefixConstants.AGGREGATE_TERM
@@ -891,31 +873,31 @@ private void insertAggregateConcept(GraphDatabaseService graphDb, Index co
}
private void insertConcept(GraphDatabaseService graphDb, String facetId, Index conceptIndex,
- JSONObject jsonConcept, CoordinatesMap nodesByCoordinates, InsertionReport insertionReport,
- ImportOptions importOptions) throws JSONException {
+ ImportConcept jsonConcept, CoordinatesMap nodesByCoordinates, InsertionReport insertionReport,
+ ImportOptions importOptions) {
// Name is mandatory, thus we don't use the
// null-convenience method here.
- String prefName = JSON.getString(jsonConcept, PROP_PREF_NAME);
- JSONArray synonyms = JSON.getJSONArray(jsonConcept, PROP_SYNONYMS);
- JSONArray generalLabels = JSON.getJSONArray(jsonConcept, ConceptConstants.PROP_LABELS);
+ String prefName = jsonConcept.prefName;
+ List synonyms = jsonConcept.synonyms;
+ List generalLabels = jsonConcept.generalLabels;
- JSONObject coordinatesJson = jsonConcept.getJSONObject(COORDINATES);
- ConceptCoordinates coordinates = new ConceptCoordinates(coordinatesJson);
+ ConceptCoordinates coordinates = jsonConcept.coordinates;
- if (!jsonConcept.has(COORDINATES) || coordinatesJson.length() == 0)
+ if (coordinates == null)
throw new IllegalArgumentException(
- "The concept " + jsonConcept.toString(2) + " does not specify coordinates.");
+ "The concept " + jsonConcept + " does not specify coordinates.");
// Source ID is mandatory if we have a real concept import and not just a
// merging operation.
- String srcId = importOptions.merge ? JSON.getString(coordinatesJson, CoordinateConstants.SOURCE_ID)
- : coordinatesJson.getString(CoordinateConstants.SOURCE_ID);
+ if (!importOptions.merge && coordinates.sourceId == null)
+ throw new IllegalArgumentException("The concept " + jsonConcept + " does not specify a source ID.");
// The other properties may have values or not, make it
// null-proof.
- String orgId = JSON.getString(coordinatesJson, CoordinateConstants.ORIGINAL_ID);
- String source = JSON.getString(coordinatesJson, CoordinateConstants.SOURCE);
- String orgSource = JSON.getString(coordinatesJson, CoordinateConstants.ORIGINAL_SOURCE);
- boolean uniqueSourceId = JSON.getBoolean(coordinatesJson, CoordinateConstants.UNIQUE_SOURCE_ID, false);
+ String srcId = coordinates.sourceId;
+ String orgId = coordinates.originalId;
+ String source = coordinates.source;
+ String orgSource = coordinates.originalSource;
+ boolean uniqueSourceId = coordinates.uniqueSourceId;
boolean srcIduniqueMarkerChanged = false;
@@ -932,7 +914,7 @@ private void insertConcept(GraphDatabaseService graphDb, String facetId, Index relationships = concept.getRelationships(EdgeTypes.HAS_ROOT_CONCEPT);
@@ -987,9 +969,17 @@ else if (concept == null)
concept.setProperty(PROP_ORG_SRC, coordinates.originalSource);
}
- PropertyUtilities.mergeJSONObjectIntoPropertyContainer(jsonConcept, concept, ConceptConstants.PROP_LABELS,
- PROP_SRC_IDS, PROP_SOURCES, PROP_SYNONYMS, COORDINATES, PARENT_COORDINATES,
- ConceptConstants.RELATIONSHIPS);
+ // PropertyUtilities.mergeObjectIntoPropertyContainer(jsonConcept, concept, ConceptConstants.PROP_LABELS,
+ // PROP_SRC_IDS, PROP_SOURCES, PROP_SYNONYMS, COORDINATES, PARENT_COORDINATES,
+ // ConceptConstants.RELATIONSHIPS);
+
+ PropertyUtilities.setNonNullNodeProperty(concept, PROP_PREF_NAME, jsonConcept.prefName);
+ PropertyUtilities.mergeArrayProperty(concept, PROP_DESCRIPTIONS, () -> jsonConcept.descriptions.toArray(new String[0]));
+ PropertyUtilities.mergeArrayProperty(concept, PROP_WRITING_VARIANTS, () -> jsonConcept.writingVariants.toArray(new String[0]));
+ PropertyUtilities.mergeArrayProperty(concept, PROP_COPY_PROPERTIES, () -> jsonConcept.copyProperties.toArray(new String[0]));
+ mergeArrayProperty(concept, ConceptConstants.PROP_SYNONYMS, synonyms.stream().filter(s -> !s.equals(prefName)).toArray());
+ addToArrayProperty(concept, PROP_FACETS, facetId);
+
// There could be multiple sources containing a concept. For
// now, we just note that facet (if these sources give the same original
// ID, otherwise we won't notice) but don't do anything about
@@ -1013,11 +1003,9 @@ else if (concept == null)
addToArrayProperty(concept, PROP_SOURCES, source, true);
addToArrayProperty(concept, PROP_UNIQUE_SRC_ID, uniqueSourceId, true);
}
- mergeArrayProperty(concept, ConceptConstants.PROP_SYNONYMS, JSON.json2JavaArray(synonyms, prefName));
- addToArrayProperty(concept, PROP_FACETS, facetId);
- for (int i = 0; null != generalLabels && i < generalLabels.length(); i++) {
- concept.addLabel(Label.label(generalLabels.getString(i)));
+ for (int i = 0; null != generalLabels && i < generalLabels.size(); i++) {
+ concept.addLabel(Label.label(generalLabels.get(i)));
}
if (srcIduniqueMarkerChanged) {
@@ -1103,134 +1091,126 @@ private boolean checkUniqueIdMarkerClash(Node conceptNode, String srcId, boolean
* @param nodesByCoordinates
* @param importOptions
* @return
- * @throws JSONException
* @throws AggregateConceptInsertionException
*/
- private InsertionReport insertConcepts(GraphDatabaseService graphDb, JSONArray jsonConcepts, String facetId,
+ private InsertionReport insertConcepts(GraphDatabaseService graphDb, List jsonConcepts, String facetId,
CoordinatesMap nodesByCoordinates, ImportOptions importOptions) throws ConceptInsertionException {
- try {
- long time = System.currentTimeMillis();
- InsertionReport insertionReport = new InsertionReport();
- // Idea: First create all nodes and just store which Node has which
- // parent. Then, after all nodes have been created, do the actual
- // connection.
- Index conceptIndex = null;
- IndexManager indexManager = graphDb.index();
- conceptIndex = indexManager.forNodes(INDEX_NAME);
-
- // this MUST be a TreeSort or at least some collection using the
- // Comparable interface because ConceptCoordinates are rather
- // complicated regarding equality
- CoordinatesSet toBeCreated = new CoordinatesSet();
- // First, iterate through all concepts and check if their parents
- // already exist, before any nodes are created (for more efficient
- // relationship creation).
-
- // When merging, we don't care about parents.
- if (!importOptions.merge) {
- for (int i = 0; i < jsonConcepts.length(); i++) {
- JSONObject jsonConcept = jsonConcepts.getJSONObject(i);
- if (jsonConcept.has(PARENT_COORDINATES) && jsonConcept.getJSONArray(PARENT_COORDINATES).length() > 0) {
- JSONArray parentCoordinatesArray = jsonConcept.getJSONArray(PARENT_COORDINATES);
- for (int j = 0; j < parentCoordinatesArray.length(); j++) {
- ConceptCoordinates parentCoordinates = new ConceptCoordinates(
- parentCoordinatesArray.getJSONObject(j));
- Node parentNode = lookupConcept(parentCoordinates, conceptIndex);
- if (parentNode != null) {
- insertionReport.addExistingConcept(parentNode);
- nodesByCoordinates.put(parentCoordinates, parentNode);
- } else {
- toBeCreated.add(parentCoordinates);
- }
+ long time = System.currentTimeMillis();
+ InsertionReport insertionReport = new InsertionReport();
+ // Idea: First create all nodes and just store which Node has which
+ // parent. Then, after all nodes have been created, do the actual
+ // connection.
+ Index conceptIndex = null;
+ IndexManager indexManager = graphDb.index();
+ conceptIndex = indexManager.forNodes(INDEX_NAME);
+
+ // this MUST be a TreeSort or at least some collection using the
+ // Comparable interface because ConceptCoordinates are rather
+ // complicated regarding equality
+ CoordinatesSet toBeCreated = new CoordinatesSet();
+ // First, iterate through all concepts and check if their parents
+ // already exist, before any nodes are created (for more efficient
+ // relationship creation).
+
+ // When merging, we don't care about parents.
+ if (!importOptions.merge) {
+ for (int i = 0; i < jsonConcepts.size(); i++) {
+ ImportConcept jsonConcept = jsonConcepts.get(i);
+ if (jsonConcept.parentCoordinates != null) {
+ for (ConceptCoordinates parentCoordinates : jsonConcept.parentCoordinates) {
+ Node parentNode = lookupConcept(parentCoordinates, conceptIndex);
+ if (parentNode != null) {
+ insertionReport.addExistingConcept(parentNode);
+ nodesByCoordinates.put(parentCoordinates, parentNode);
+ } else {
+ toBeCreated.add(parentCoordinates);
}
}
}
}
- // Finished finding parents
-
- // When merging, we remove those import concepts that are not known in
- // the database from the input data
- List importConceptsToRemove = new ArrayList<>();
- // Second, iterate through all concepts to be imported and check if
- // they already exist themselves or not. Not existing nodes will be
- // created as
- // HOLLOW nodes.
- // The following methods can then just access the nodes by their source
- // Id which ought to be unique for each import.
- for (int i = 0; i < jsonConcepts.length(); i++) {
- JSONObject jsonConcept = jsonConcepts.getJSONObject(i);
- ConceptCoordinates coordinates;
- if (jsonConcept.has(ConceptConstants.COORDINATES)) {
- coordinates = new ConceptCoordinates(jsonConcept.getJSONObject(ConceptConstants.COORDINATES));
- insertionReport.addImportedCoordinates(coordinates);
- } else if (!JSON.getBoolean(jsonConcept, ConceptConstants.AGGREGATE)) {
- throw new IllegalArgumentException("Concept " + jsonConcept + " does not define concept coordinates.");
- } else {
- continue;
- }
- // many nodes will actually already have been seen as parents
- // above
- if (nodesByCoordinates.containsKey(coordinates) || toBeCreated.contains(coordinates, true))
- continue;
- Node conceptNode = lookupConcept(coordinates, conceptIndex);
- if (conceptNode != null) {
- insertionReport.addExistingConcept(conceptNode);
- nodesByCoordinates.put(coordinates, conceptNode);
- } else if (!importOptions.merge) {
- // When merging, we don't create new concepts
-
- // The concept coordinates are not yet known, create an
- // empty
- // concept node with its coordinates.
- // Node newConcept = registerNewHollowConceptNode(graphDb,
- // coordinates, conceptIndex);
- toBeCreated.add(coordinates);
-
- // conceptNode = newConcept;
- } else {
- // We are in merging mode and requested concept is not in the
- // database; mark it for removal from the input data and
- // continue
- importConceptsToRemove.add(i);
- continue;
- }
-
+ }
+ // Finished finding parents
+
+ // When merging, we remove those import concepts that are not known in
+ // the database from the input data
+ List importConceptsToRemove = new ArrayList<>();
+ // Second, iterate through all concepts to be imported and check if
+ // they already exist themselves or not. Not existing nodes will be
+ // created as
+ // HOLLOW nodes.
+ // The following methods can then just access the nodes by their source
+ // Id which ought to be unique for each import.
+ for (int i = 0; i < jsonConcepts.size(); i++) {
+ ImportConcept jsonConcept = jsonConcepts.get(i);
+ ConceptCoordinates coordinates;
+ if (jsonConcept.coordinates != null) {
+ coordinates = jsonConcept.coordinates;
+ insertionReport.addImportedCoordinates(coordinates);
+ } else if (!jsonConcept.aggregate) {
+ throw new IllegalArgumentException("Concept " + jsonConcept + " does not define concept coordinates.");
+ } else {
+ continue;
}
- // Finished getting existing nodes and creating HOLLOW nodes
+ // many nodes will actually already have been seen as parents
+ // above
+ if (nodesByCoordinates.containsKey(coordinates) || toBeCreated.contains(coordinates, true))
+ continue;
+ Node conceptNode = lookupConcept(coordinates, conceptIndex);
+ if (conceptNode != null) {
+ insertionReport.addExistingConcept(conceptNode);
+ nodesByCoordinates.put(coordinates, conceptNode);
+ } else if (!importOptions.merge) {
+ // When merging, we don't create new concepts
- for (ConceptCoordinates coordinates : toBeCreated) {
- Node conceptNode = registerNewHollowConceptNode(graphDb, coordinates, conceptIndex);
- ++insertionReport.numConcepts;
+ // The concept coordinates are not yet known, create an
+ // empty
+ // concept node with its coordinates.
+ // Node newConcept = registerNewHollowConceptNode(graphDb,
+ // coordinates, conceptIndex);
+ toBeCreated.add(coordinates);
- nodesByCoordinates.put(coordinates, conceptNode);
+ // conceptNode = newConcept;
+ } else {
+ // We are in merging mode and requested concept is not in the
+ // database; mark it for removal from the input data and
+ // continue
+ importConceptsToRemove.add(i);
+ continue;
}
- log.info("removing " + importConceptsToRemove.size()
- + " input concepts that should be omitted because we are merging and don't have them in the database");
- for (int index = importConceptsToRemove.size() - 1; index >= 0; --index)
- jsonConcepts.remove(importConceptsToRemove.get(index));
-
- log.info("Starting to insert " + jsonConcepts.length() + " concepts.");
- for (int i = 0; i < jsonConcepts.length(); i++) {
- JSONObject jsonConcept = jsonConcepts.getJSONObject(i);
- boolean isAggregate = JSON.getBoolean(jsonConcept, ConceptConstants.AGGREGATE);
- if (isAggregate) {
- insertAggregateConcept(graphDb, conceptIndex, jsonConcept, nodesByCoordinates, insertionReport,
- importOptions);
- } else {
- insertConcept(graphDb, facetId, conceptIndex, jsonConcept, nodesByCoordinates, insertionReport,
- importOptions);
- }
+ }
+ // Finished getting existing nodes and creating HOLLOW nodes
+
+ for (ConceptCoordinates coordinates : toBeCreated) {
+ Node conceptNode = registerNewHollowConceptNode(graphDb, coordinates, conceptIndex);
+ ++insertionReport.numConcepts;
+
+ nodesByCoordinates.put(coordinates, conceptNode);
+ }
+
+ log.info("removing " + importConceptsToRemove.size()
+ + " input concepts that should be omitted because we are merging and don't have them in the database");
+ for (int index = importConceptsToRemove.size() - 1; index >= 0; --index)
+ jsonConcepts.remove(importConceptsToRemove.get(index));
+
+ log.info("Starting to insert " + jsonConcepts.size() + " concepts.");
+ for (int i = 0; i < jsonConcepts.size(); i++) {
+ ImportConcept jsonConcept = jsonConcepts.get(i);
+ boolean isAggregate = jsonConcept.aggregate;
+ if (isAggregate) {
+ insertAggregateConcept(graphDb, conceptIndex, jsonConcept, nodesByCoordinates, insertionReport,
+ importOptions);
+ } else {
+ insertConcept(graphDb, facetId, conceptIndex, jsonConcept, nodesByCoordinates, insertionReport,
+ importOptions);
}
- log.debug(jsonConcepts.length() + " concepts inserted.");
- time = System.currentTimeMillis() - time;
- log.info(insertionReport.numConcepts
- + " new concepts - but not yet relationships - have been inserted. This took " + time + " ms ("
- + (time / 1000) + " s)");
- return insertionReport;
- } catch (JSONException e) {
- throw new ConceptInsertionException(e);
}
+ log.debug(jsonConcepts.size() + " concepts inserted.");
+ time = System.currentTimeMillis() - time;
+ log.info(insertionReport.numConcepts
+ + " new concepts - but not yet relationships - have been inserted. This took " + time + " ms ("
+ + (time / 1000) + " s)");
+ return insertionReport;
}
/**
@@ -1266,13 +1246,14 @@ private Node registerNewHollowConceptNode(GraphDatabaseService graphDb, ConceptC
return node;
}
- public Representation insertConcepts(GraphDatabaseService graphDb, String conceptsWithFacet) throws JSONException, ConceptInsertionException {
- JSONObject input = new JSONObject(conceptsWithFacet);
- JSONObject jsonFacet = JSON.getJSONObject(input, KEY_FACET);
- JSONArray jsonConcepts = input.getJSONArray(KEY_CONCEPTS);
- JSONObject importOptionsJson = JSON.getJSONObject(input, KEY_IMPORT_OPTIONS);
- return insertConcepts(graphDb, jsonFacet != null ? jsonFacet.toString() : null, jsonConcepts.toString(),
- importOptionsJson != null ? importOptionsJson.toString() : null);
+ public Representation insertConcepts(GraphDatabaseService graphDb, String conceptsWithFacet) throws ConceptInsertionException, IOException {
+ final ObjectMapper om = new ObjectMapper();
+ final ImportConcepts importConcepts = ConceptsJsonSerializer.fromJson(conceptsWithFacet, ImportConcepts.class);
+ ImportFacet jsonFacet = importConcepts.getFacet();
+ List jsonConcepts = importConcepts.getConcepts();
+ ImportOptions importOptionsJson = importConcepts.getImportOptions();
+ return insertConcepts(graphDb, jsonFacet != null ? om.writeValueAsString(jsonFacet) : null, om.writeValueAsString(jsonConcepts),
+ importOptionsJson != null ? om.writeValueAsString(importOptionsJson) : null);
}
@Name(INSERT_CONCEPTS)
@@ -1283,26 +1264,25 @@ public Representation insertConcepts(@Source GraphDatabaseService graphDb,
@Description("TODO") @Parameter(name = KEY_FACET, optional = true) String facetJson,
@Description("TODO") @Parameter(name = KEY_CONCEPTS, optional = true) String conceptsJson,
@Description("TODO") @Parameter(name = KEY_IMPORT_OPTIONS, optional = true) String importOptionsJsonString)
- throws JSONException, ConceptInsertionException {
+ throws ConceptInsertionException, IOException {
log.info("{} was called", INSERT_CONCEPTS);
long time = System.currentTimeMillis();
- Gson gson = new Gson();
+ final ObjectMapper om = new ObjectMapper();
log.debug("Parsing input.");
- JSONObject jsonFacet = null;
- JSONArray jsonConcepts = null;
- JSONObject importOptionsJson = null;
- jsonFacet = !StringUtils.isEmpty(facetJson) ? new JSONObject(facetJson) : null;
+ ImportFacet jsonFacet = null;
+ List jsonConcepts = null;
+ jsonFacet = !StringUtils.isEmpty(facetJson) ? om.readValue(facetJson, ImportFacet.class) : null;
if (null != conceptsJson) {
- jsonConcepts = new JSONArray(conceptsJson);
- log.info("Got {} input concepts for import.", jsonConcepts.length());
+ jsonConcepts = om.readValue(conceptsJson, new TypeReference>() {
+ });
+ log.info("Got {} input concepts for import.", jsonConcepts.size());
} else {
log.info("Got 0 input concepts for import.");
}
ImportOptions importOptions;
if (null != importOptionsJsonString) {
- importOptionsJson = new JSONObject(importOptionsJsonString);
- importOptions = gson.fromJson(importOptionsJson.toString(), ImportOptions.class);
+ importOptions = om.readValue(importOptionsJsonString, ImportOptions.class);
} else {
importOptions = new ImportOptions();
}
@@ -1316,10 +1296,10 @@ public Representation insertConcepts(@Source GraphDatabaseService graphDb,
// The facet Id will be added to the facets-property of the concept
// nodes.
log.debug("Handling import of facet.");
- if (null != jsonFacet && jsonFacet.has(PROP_ID)) {
- facetId = jsonFacet.getString(PROP_ID);
+ if (null != jsonFacet && jsonFacet.getId() != null) {
+ facetId = jsonFacet.getId();
log.info("Facet ID {} has been given to add the concepts to.", facetId);
- boolean isNoFacet = JSON.getBoolean(jsonFacet, FacetConstants.NO_FACET);
+ boolean isNoFacet = jsonFacet.isNoFacet();
if (isNoFacet)
facet = FacetManager.getNoFacet(graphDb, facetId);
else
@@ -1327,12 +1307,12 @@ public Representation insertConcepts(@Source GraphDatabaseService graphDb,
if (null == facet)
throw new IllegalArgumentException("The facet with ID \"" + facetId
+ "\" was not found. You must pass the ID of an existing facet or deliver all information required to create the facet from scratch. Then, the facetId must not be included in the request, it will be created dynamically.");
- } else if (null != jsonFacet && jsonFacet.has(FacetConstants.PROP_NAME)) {
+ } else if (null != jsonFacet && jsonFacet.getName() != null) {
ResourceIterator facetIterator = graphDb.findNodes(FacetLabel.FACET);
while (facetIterator.hasNext()) {
facet = facetIterator.next();
if (facet.getProperty(FacetConstants.PROP_NAME)
- .equals(jsonFacet.getString(FacetConstants.PROP_NAME)))
+ .equals(jsonFacet.getName()))
break;
facet = null;
}
@@ -1363,16 +1343,16 @@ public Representation insertConcepts(@Source GraphDatabaseService graphDb,
insertionReport);
else
log.info("This is a property merging import, no relationships are created.");
- time = System.currentTimeMillis() - time;
report.put(RET_KEY_NUM_CREATED_CONCEPTS, insertionReport.numConcepts);
report.put(RET_KEY_NUM_CREATED_RELS, insertionReport.numRelationships);
- report.put(KEY_FACET_ID, facetId);
- report.put(KEY_TIME, time);
log.debug("Done creating concepts and relationships.");
} else {
log.info("No concepts were included in the request.");
}
+ time = System.currentTimeMillis() - time;
+ report.put(KEY_TIME, time);
+ report.put(KEY_FACET_ID, facetId);
tx.success();
}
log.info("Concept insertion complete.");
@@ -1693,7 +1673,7 @@ else if (facetsContainingChildren.size() > 0)
@Name("include_concepts")
@Description("This is only a remedy for a problem we shouldnt have, delete in the future.")
@PluginTarget(GraphDatabaseService.class)
- public void includeConcepts(@Source GraphDatabaseService graphDb) throws JSONException {
+ public void includeConcepts(@Source GraphDatabaseService graphDb) {
Label includeLabel = Label.label("INCLUDE");
try (Transaction tx = graphDb.beginTx()) {
ResourceIterable concepts = () -> graphDb.findNodes(includeLabel);
@@ -1737,7 +1717,7 @@ public void includeConcepts(@Source GraphDatabaseService graphDb) throws JSONExc
@Name("exclude_concepts")
@Description("This is only a remedy for a problem we shouldnt have, delete in the future.")
@PluginTarget(GraphDatabaseService.class)
- public void excludeConcepts(@Source GraphDatabaseService graphDb) throws JSONException {
+ public void excludeConcepts(@Source GraphDatabaseService graphDb) {
Label includeLabel = Label.label("INCLUDE");
Label excludeLabel = Label.label("EXCLUDE");
Label mappingAggregateLabel = Label.label("MAPPING_AGGREGATE");
@@ -1775,20 +1755,21 @@ public void excludeConcepts(@Source GraphDatabaseService graphDb) throws JSONExc
+ " but that reading commands don't care about the relationship direction.")
@PluginTarget(GraphDatabaseService.class)
public int insertMappings(@Source GraphDatabaseService graphDb,
- @Description("An array of mappings in JSON format. Each mapping is an object with the keys for \"id1\", \"id2\" and \"mappingType\", respectively.") @Parameter(name = KEY_MAPPINGS) String mappingsJson)
- throws JSONException {
- JSONArray mappings = new JSONArray(mappingsJson);
- log.info("Starting to insert " + mappings.length() + " mappings.");
+ @Description("An array of mappings in JSON format. Each mapping is an object with the keys for \"id1\", \"id2\" and \"mappingType\", respectively.") @Parameter(name = KEY_MAPPINGS) String mappingsJson) throws IOException {
+ final ObjectMapper om = new ObjectMapper();
+ final List