Skip to content
This repository was archived by the owner on May 24, 2022. It is now read-only.

Commit 272f0ec

Browse files
committed
Merge pull request #22 from zazi/content_schema_bug
enhanced namespace index handling + added a bit more (debug) logging
2 parents 24d8f77 + 25ba1e3 commit 272f0ec

File tree

9 files changed

+79
-199
lines changed

9 files changed

+79
-199
lines changed

src/main/java/org/dswarm/graph/BasicNeo4jProcessor.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,6 @@ protected void initIndices() throws DMPGraphException {
134134

135135
tempStatementHashes.clear();
136136
}
137-
138-
namespaceIndex.resetTXNamespaces();
139137
} catch (final Exception e) {
140138

141139
failTx();
@@ -218,16 +216,9 @@ public void clearMaps() {
218216

219217
LOG.debug("start clearing and closing mapdb indices");
220218

221-
if (!tempStatementHashesDB.isClosed()) {
222-
223-
tempStatementHashes.clear();
224-
tempStatementHashesDB.close();
225-
}
226-
227-
if (!statementHashesDB.isClosed()) {
228-
229-
statementHashesDB.close();
230-
}
219+
tempStatementHashes.clear();
220+
closeMapDBIndex(tempStatementHashesDB);
221+
closeMapDBIndex(statementHashesDB);
231222

232223
namespaceIndex.clearMaps();
233224

@@ -238,6 +229,8 @@ public void beginTx() throws DMPGraphException {
238229

239230
BasicNeo4jProcessor.LOG.debug("beginning new tx");
240231

232+
// (optionally) persist namespaces that where utilised before
233+
namespaceIndex.resetTXNamespaces();
241234
tx.ensureRunningTx();
242235
initIndices();
243236

src/main/java/org/dswarm/graph/index/NamespaceIndex.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class NamespaceIndex {
5353
private final Map<String, String> prefixedURIURIMap;
5454

5555
private final GraphDatabaseService database;
56-
private final TransactionHandler tx;
56+
private final TransactionHandler tx;
5757

5858
public NamespaceIndex(final GraphDatabaseService databaseArg, final TransactionHandler txArg) {
5959

@@ -78,7 +78,7 @@ public void resetTXNamespaces() throws DMPGraphException {
7878

7979
if (tempNamespacePrefixes != null) {
8080

81-
if(!tempNamespacePrefixes.isEmpty()) {
81+
if (!tempNamespacePrefixes.isEmpty()) {
8282

8383
// to ensure that no namespace prefix mapping get lost
8484
pumpNFlushNamespacePrefixIndex();
@@ -137,10 +137,14 @@ public void pumpNFlushNamespacePrefixIndex() throws DMPGraphException {
137137
inMemoryNamespacePrefixesDB.commit();
138138

139139
LOG.debug("finished flushing namespace prefix index");
140+
141+
tempNamespacePrefixes.clear();
140142
}
141143

142144
public void addPrefix(final String namespace, final String prefix) {
143145

146+
LOG.debug("write namespace '{}' with prefix '{}' to graph", namespace, prefix);
147+
144148
final Node prefixNode = database.createNode(GraphProcessingStatics.PREFIX_LABEL);
145149
prefixNode.setProperty(GraphStatics.URI_PROPERTY, namespace);
146150
prefixNode.setProperty(GraphProcessingStatics.PREFIX_PROPERTY, prefix);
@@ -151,17 +155,11 @@ public void clearMaps() {
151155
uriPrefixedURIMap.clear();
152156
prefixedURIURIMap.clear();
153157

154-
if (!tempNamespacePrefixesDB.isClosed()) {
155-
156-
tempNamespacePrefixes.clear();
157-
tempNamespacePrefixesDB.close();
158-
}
158+
tempNamespacePrefixes.clear();
159+
inMemoryNamespacePrefixes.clear();
159160

160-
if (!inMemoryNamespacePrefixesDB.isClosed()) {
161-
162-
inMemoryNamespacePrefixes.clear();
163-
inMemoryNamespacePrefixesDB.close();
164-
}
161+
closeMapDBIndex(tempNamespacePrefixesDB);
162+
closeMapDBIndex(inMemoryNamespacePrefixesDB);
165163
}
166164

167165
public void closeMapDBIndices() {

src/main/java/org/dswarm/graph/resources/GDMResource.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,11 @@ private ObjectNode getMetadata(final List<BodyPart> bodyParts) throws DMPGraphEx
13231323
throw new DMPGraphException(message);
13241324
}
13251325

1326+
if(LOG.isDebugEnabled()) {
1327+
1328+
LOG.debug("metadata of request '{}'", metadataString);
1329+
}
1330+
13261331
try {
13271332

13281333
return objectMapper.readValue(metadataString, ObjectNode.class);
@@ -1421,8 +1426,19 @@ private Optional<ContentSchema> getPrefixedContentSchema(final ObjectNode metada
14211426
try {
14221427

14231428
final String contentSchemaJSONString = objectMapper.writeValueAsString(optionalContentSchemaJSON.get());
1429+
1430+
if(LOG.isDebugEnabled()) {
1431+
1432+
LOG.debug("content schema JSON string '{}'", contentSchemaJSONString);
1433+
}
1434+
14241435
final ContentSchema contentSchema = objectMapper.readValue(contentSchemaJSONString, ContentSchema.class);
14251436

1437+
if(LOG.isDebugEnabled()) {
1438+
1439+
LOG.debug("try to prefix URIs of content schema '{}'", objectMapper.writeValueAsString(contentSchema));
1440+
}
1441+
14261442
final Optional<ContentSchema> contentSchemaOptional = Optional.fromNullable(contentSchema);
14271443

14281444
if (contentSchemaOptional.isPresent()) {
@@ -1435,7 +1451,7 @@ private Optional<ContentSchema> getPrefixedContentSchema(final ObjectNode metada
14351451

14361452
final String message = "could not deserialise content schema JSON for write from graph DB request";
14371453

1438-
GDMResource.LOG.debug(message);
1454+
GDMResource.LOG.error(message);
14391455

14401456
return Optional.absent();
14411457
}
@@ -1521,6 +1537,16 @@ private Attribute prefixAttribute(final Attribute attribute, final Map<Attribute
15211537
if (!prefixedAttributeMap.containsKey(attribute)) {
15221538

15231539
final String attributeUri = attribute.getUri();
1540+
1541+
if(attributeUri == null || attributeUri.trim().isEmpty()) {
1542+
1543+
final String message = "attribute URI shouldn't be null or empty";
1544+
1545+
LOG.error(message);
1546+
1547+
throw new DMPGraphException(message);
1548+
}
1549+
15241550
final String prefixedAttributeURI = namespaceIndex.createPrefixedURI(attributeUri);
15251551

15261552
final Attribute prefixedAttribute = new Attribute(prefixedAttributeURI);

src/main/java/org/dswarm/graph/resources/RDFResource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ private Optional<String> exportSingleRDFInternal(final GraphDatabaseService data
565565

566566
final String prefixedDataModelURI = namespaceIndex.createPrefixedURI(dataModelURI);
567567

568-
RDFResource.LOG.debug("try to export all RDF statements for dataModelURI \"{}\" ('') from graph db to format \"{}\"", dataModelURI,
568+
RDFResource.LOG.debug("try to export all RDF statements for dataModelURI \"{}\" ('{}') from graph db to format \"{}\"", dataModelURI,
569569
prefixedDataModelURI, exportLanguage.getLabel());
570570

571571
final RDFExporter rdfExporter = new DataModelRDFExporter(database, dataModelURI, tx, namespaceIndex);
@@ -581,7 +581,7 @@ private Optional<String> exportSingleRDFInternal(final GraphDatabaseService data
581581
final String result = writer.toString();
582582

583583
RDFResource.LOG
584-
.debug("finished exporting {} RDF statements from graph db (processed statements = '{}' (successfully processed statements = '{}')) for data model '{}' ('')",
584+
.debug("finished exporting {} RDF statements from graph db (processed statements = '{}' (successfully processed statements = '{}')) for data model '{}' ('{}')",
585585
rdfExporter.countStatements(), rdfExporter.processedStatements(), rdfExporter.successfullyProcessedStatements(),
586586
dataModelURI, prefixedDataModelURI);
587587

src/main/java/org/dswarm/graph/tx/Neo4jTransactionHandler.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,16 @@ public Neo4jTransactionHandler(final GraphDatabaseService databaseArg) {
9191
}
9292
}
9393

94-
@Override public void ensureRunningTx() {
94+
@Override public boolean ensureRunningTx() {
9595

9696
if (txIsClosed()) {
9797

9898
beginTx();
99+
100+
return true;
99101
}
102+
103+
return false;
100104
}
101105

102106
@Override public boolean txIsClosed() {

src/main/java/org/dswarm/graph/tx/TransactionHandler.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ public interface TransactionHandler {
2929

3030
void succeedTx();
3131

32-
void ensureRunningTx();
32+
/**
33+
* Return true, if a new transaction was create; if an existing transaction is still open, this one will be returned.
34+
*
35+
* @return true, if a new transaction was create; if an existing transaction is still open, this one will be returned.
36+
*/
37+
boolean ensureRunningTx();
3338

3439
boolean txIsClosed();
3540
}

src/main/java/org/dswarm/graph/utils/NamespaceUtils.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,14 @@ public static String getPrefix(final String namespace, final Map<String, String>
139139
tempNamespacesPrefixesMap.put(namespace, prefix);
140140
}
141141

142+
LOG.debug("minted new prefix '{}' for namespace '{}'", prefix, namespace);
143+
142144
return prefix;
143145
} catch (final Exception e) {
144146

145147
tx.failTx();
146148

147-
final String message = "couldn't retrieve prefix successfully";
149+
final String message = String.format("couldn't retrieve prefix for namespace '%s' successfully", namespace);
148150

149151
LOG.error(message);
150152

@@ -158,43 +160,43 @@ public static Optional<Node> getPrefix(final String namespace, final GraphDataba
158160
.fromNullable(database.findNode(GraphProcessingStatics.PREFIX_LABEL, GraphStatics.URI_PROPERTY, namespace));
159161
}
160162

161-
public static String getNamespace(final String prefix, final GraphDatabaseService database, final TransactionHandler tx) throws DMPGraphException {
163+
public static String getNamespace(final String prefix, final GraphDatabaseService database, final TransactionHandler tx)
164+
throws DMPGraphException {
162165

163166
if (prefix == null || prefix.trim().isEmpty()) {
164167

165168
throw new DMPGraphException("prefix shouldn't be null or empty");
166169
}
167170

168-
Optional<Node> optionalNode = null;
169-
170171
try {
171172

172173
tx.ensureRunningTx();
173174

174-
optionalNode = Optional.fromNullable(
175+
final Optional<Node> optionalNode = Optional.fromNullable(
175176
database.findNode(GraphProcessingStatics.PREFIX_LABEL, GraphProcessingStatics.PREFIX_PROPERTY, prefix));
177+
178+
if (!optionalNode.isPresent()) {
179+
180+
throw new DMPGraphException(String.format("couldn't find a namespace for prefix '%s'", prefix));
181+
}
182+
183+
final Node node = optionalNode.get();
184+
return (String) node.getProperty(GraphStatics.URI_PROPERTY);
176185
} catch (final Exception e) {
177186

178187
tx.failTx();
179188

180-
final String message = "couldn't retrieve namespace successfully";
189+
final String message = String.format("couldn't retrieve namespace for prefix '%s' successfully", prefix);
181190

182191
LOG.error(message);
183192

184193
throw new DMPGraphException(message, e);
185194
}
186-
187-
if (optionalNode == null || !optionalNode.isPresent()) {
188-
189-
throw new DMPGraphException(String.format("couldn't find a namespace for prefix '%s'", prefix));
190-
}
191-
192-
final Node node = optionalNode.get();
193-
return (String) node.getProperty(GraphStatics.URI_PROPERTY);
194195
}
195196

196197
public static String determinePrefixedURI(final String fullURI, final Map<String, String> tempNamespacePrefixes,
197-
final Map<String, String> inMemoryNamespacePrefixes, final GraphDatabaseService database, final TransactionHandler tx) throws DMPGraphException {
198+
final Map<String, String> inMemoryNamespacePrefixes, final GraphDatabaseService database, final TransactionHandler tx)
199+
throws DMPGraphException {
198200

199201
final Tuple<String, String> uriParts = URI.determineParts(fullURI);
200202
final String namespaceURI = uriParts.v1();
@@ -205,7 +207,8 @@ public static String determinePrefixedURI(final String fullURI, final Map<String
205207
return prefix + NamespaceUtils.PREFIX_DELIMITER + localName;
206208
}
207209

208-
public static String determineFullURI(final String prefixedURI, final GraphDatabaseService database, final TransactionHandler tx) throws DMPGraphException {
210+
public static String determineFullURI(final String prefixedURI, final GraphDatabaseService database, final TransactionHandler tx)
211+
throws DMPGraphException {
209212

210213
final String[] splittedPrefixedURI = prefixedURI.split(PREFIX_DELIMTER_STRING);
211214

src/main/java/org/dswarm/graph/xml/read/PropertyGraphXMLReader.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import org.dswarm.common.model.AttributePath;
5151
import org.dswarm.common.types.Tuple;
5252
import org.dswarm.common.web.URI;
53+
import org.dswarm.common.xml.utils.XMLStreamWriterUtils;
5354
import org.dswarm.graph.DMPGraphException;
5455
import org.dswarm.graph.gdm.read.PropertyGraphGDMReaderHelper;
5556
import org.dswarm.graph.index.NamespaceIndex;
@@ -61,7 +62,6 @@
6162
import org.dswarm.graph.versioning.Range;
6263
import org.dswarm.graph.versioning.VersioningStatics;
6364
import org.dswarm.graph.versioning.utils.GraphVersionUtils;
64-
import org.dswarm.graph.xml.utils.XMLStreamWriterUtils;
6565

6666
/**
6767
* @author tgaengler
@@ -153,9 +153,9 @@ public PropertyGraphXMLReader(final Optional<AttributePath> optionalRootAttribut
153153

154154
allVersions = false;
155155

156-
tx.ensureRunningTx();
156+
final boolean createdNewTx = tx.ensureRunningTx();
157157

158-
PropertyGraphXMLReader.LOG.debug("start read XML TX");
158+
PropertyGraphXMLReader.LOG.debug("start read XML TX (createdNewTx = '{}')", createdNewTx);
159159

160160
try {
161161

@@ -182,9 +182,9 @@ public Optional<XMLStreamWriter> read(final OutputStream outputStream) throws DM
182182

183183
try {
184184

185-
PropertyGraphXMLReader.LOG.debug("start read XML TX");
185+
final boolean createdNewTx = tx.ensureRunningTx();
186186

187-
tx.ensureRunningTx();
187+
PropertyGraphXMLReader.LOG.debug("start read XML TX (createdNewTx = '{}')", createdNewTx);
188188
} catch (final Exception e) {
189189

190190
final String message = "couldn't acquire tx successfully";

0 commit comments

Comments
 (0)