Skip to content

Commit

Permalink
Add specific exceptions for import relationships errors, update id fo…
Browse files Browse the repository at this point in the history
…r 'ID Spaces' section to be specific instead of generated, rename Mute to SuppressOutput, add possiblity to check output messages in SuppressOutput rule
  • Loading branch information
MishaDemianenko committed Jul 6, 2015
1 parent e2333c7 commit e14374d
Show file tree
Hide file tree
Showing 37 changed files with 387 additions and 203 deletions.
Expand Up @@ -43,7 +43,7 @@
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.neo4j.test.Mute.muteAll; import static org.neo4j.test.SuppressOutput.suppressAll;


/* /*
Note that when running this test from within an IDE, the version field will be an empty string. This is because the Note that when running this test from within an IDE, the version field will be an empty string. This is because the
Expand Down Expand Up @@ -78,7 +78,7 @@ public static void setupServer() throws Exception
.withClock( clock ) .withClock( clock )
.build(); .build();


muteAll().call( new Callable<Void>() suppressAll().call( new Callable<Void>()
{ {
@Override @Override
public Void call() throws Exception public Void call() throws Exception
Expand All @@ -99,7 +99,7 @@ public void setupTheDatabase() throws Exception
@AfterClass @AfterClass
public static void stopServer() throws Exception public static void stopServer() throws Exception
{ {
muteAll().call( new Callable<Void>() suppressAll().call( new Callable<Void>()
{ {
@Override @Override
public Void call() throws Exception public Void call() throws Exception
Expand Down
1 change: 1 addition & 0 deletions community/import-tool/src/docs/ops/import-tool.asciidoc
Expand Up @@ -71,6 +71,7 @@ START_ID::
END_ID:: END_ID::
The id of the end node of the relationship to create. The id of the end node of the relationship to create.


[[import-tool-id-spaces]]
=== ID Spaces === ID Spaces


The import tool assumes that node identifiers are unique across node files. The import tool assumes that node identifiers are unique across node files.
Expand Down
Expand Up @@ -53,14 +53,14 @@
import org.neo4j.unsafe.impl.batchimport.input.Input; import org.neo4j.unsafe.impl.batchimport.input.Input;
import org.neo4j.unsafe.impl.batchimport.input.InputNode; import org.neo4j.unsafe.impl.batchimport.input.InputNode;
import org.neo4j.unsafe.impl.batchimport.input.InputRelationship; import org.neo4j.unsafe.impl.batchimport.input.InputRelationship;
import org.neo4j.unsafe.impl.batchimport.input.MissingRelationshipDataException;
import org.neo4j.unsafe.impl.batchimport.input.csv.Configuration; import org.neo4j.unsafe.impl.batchimport.input.csv.Configuration;
import org.neo4j.unsafe.impl.batchimport.input.csv.CsvInput; import org.neo4j.unsafe.impl.batchimport.input.csv.CsvInput;
import org.neo4j.unsafe.impl.batchimport.input.csv.DataFactory; import org.neo4j.unsafe.impl.batchimport.input.csv.DataFactory;
import org.neo4j.unsafe.impl.batchimport.input.csv.IdType; import org.neo4j.unsafe.impl.batchimport.input.csv.IdType;
import org.neo4j.unsafe.impl.batchimport.staging.ExecutionMonitors; import org.neo4j.unsafe.impl.batchimport.staging.ExecutionMonitors;


import static java.nio.charset.Charset.defaultCharset; import static java.nio.charset.Charset.defaultCharset;

import static org.neo4j.helpers.Exceptions.launderedException; import static org.neo4j.helpers.Exceptions.launderedException;
import static org.neo4j.helpers.Format.bytes; import static org.neo4j.helpers.Format.bytes;
import static org.neo4j.kernel.impl.util.Converters.withDefault; import static org.neo4j.kernel.impl.util.Converters.withDefault;
Expand Down Expand Up @@ -428,28 +428,38 @@ public int bigFileChannelBufferSizeMultiplier()
}; };
} }


private static String manualReference( String page ) private static String manualReference( ManualPage page, Anchor anchor )
{ {
return " http://neo4j.com/docs/" + Version.getKernel().getVersion() + "/" + page; return " http://neo4j.com/docs/" + Version.getKernel().getVersion() + "/" + page.getReference( anchor );
} }




/** /**
* Method name looks strange, but look at how it's used and you'll see why it's named like that. * Method name looks strange, but look at how it's used and you'll see why it's named like that.
* @param stackTrace whether or not to also print the stack trace of the error. * @param stackTrace whether or not to also print the stack trace of the error.
*/ */
private static RuntimeException andPrintError( String typeOfError, Exception e, boolean stackTrace ) private static RuntimeException andPrintError( String typeOfError, Exception e, boolean stackTrace )
{ {
if ( e.getClass().equals( DuplicateInputIdException.class ) ) if ( DuplicateInputIdException.class.equals( e.getClass() ) )
{ {
System.err.println( "Duplicate input ids that would otherwise clash can be put into separate id space," + System.err.println( "Duplicate input ids that would otherwise clash can be put into separate id space, " +
" read more about how to use id spaces in the manual:" + "read more about how to use id spaces in the manual:" +
manualReference( "import-tool-header-format.html#_id_spaces" ) ); manualReference( ManualPage.IMPORT_TOOL_FORMAT, Anchor.ID_SPACES ) );
} }
else if ( e.getClass().equals( IllegalMultilineFieldException.class ) ) else if ( MissingRelationshipDataException.class.equals( e.getClass() ) )
{ {
System.err.println( "Detected field which spanned multiple lines for an import where " + System.err.println( String.format( "Relationship missing mandatory field '%s', " +
Options.MULTILINE_FIELDS.argument() + "=false. If you know that your input data include " + "read more about relationship format in the manual: %s",
"fields containing new-line characters then import with this option set to true." ); ((MissingRelationshipDataException) e).getFieldType(),
manualReference( ManualPage.IMPORT_TOOL_FORMAT, Anchor.RELATIONSHIP) ) );
}
else if ( IllegalMultilineFieldException.class.equals( e.getClass() ) )
{
System.err.println( String.format("Detected field which spanned multiple lines for an import where " +
"%s=false. If you know that your input data include " +
"fields containing new-line characters then import with this option set to true.",
Options.MULTILINE_FIELDS.argument() ) );
} }


System.err.println( typeOfError + ": " + e.getMessage() ); System.err.println( typeOfError + ": " + e.getMessage() );
Expand Down Expand Up @@ -645,4 +655,35 @@ static void warn( String warning )
{ {
System.err.println( warning ); System.err.println( warning );
} }

private enum ManualPage
{
IMPORT_TOOL_FORMAT("import-tool-header-format.html");

private String page;

ManualPage( String page )
{
this.page = page;
}

public String getReference(Anchor anchor)
{
return page + "#" + anchor.anchor;
}
}

private enum Anchor
{
ID_SPACES("import-tool-id-spaces"),
RELATIONSHIP("import-tool-header-format-rels");

private String anchor;

Anchor( String anchor )
{
this.anchor = anchor;
}
}

} }

0 comments on commit e14374d

Please sign in to comment.