05-23-2018 10:03 PM
Hi,
In this i am creating snap which takes input as document and output as document it works fine right now. But when i am putting my snap as input for mapper it shows data on Input Schema perfectly.
but when i am using mapper output as input of my snap Test 2 it shows no data on target schema.
Test2 snap code snippet below
@General(title = "Test 2", purpose = "Consumes the incoming documents",
author = "Your Company Name", docLink = "http://yourdocslinkhere.com")
@Inputs(min = 1, max = 1, accepts = {ViewType.DOCUMENT})
@Outputs(min = 1, max = 1, offers = {ViewType.BINARY})
@Errors(min = 1, max = 1, offers = {ViewType.DOCUMENT})
@Version(snap = 1)
@Category(snap = SnapCategory.FORMAT)
public class Test2 implements Snap {
private String filePath;
@Inject
private DocumentUtility documentUtility;
String filetype;
String type;
String fileBrowser;
Map<String, Object> composite;
private AtomicInteger count = new AtomicInteger(0);
@Inject
private InputViews inputViews;
@Inject
private OutputViews outputViews;
@Inject
protected ErrorViews errorViews;
@Override
public void defineProperties(PropertyBuilder propertyBuilder) {
}
@Override
public void configure(PropertyValues propertyValues) throws ConfigurationException {
}
@Override
public void execute() throws ExecutionException {
InputView inputView = inputViews.get();
Iterator<Document> documentIterator = inputViews.getDocumentsFrom(inputView);
while (documentIterator.hasNext()) {
Document next = documentIterator.next();
Map<String, Object> asMap = documentUtility.getAsMap(next, errorViews);
try {
List<String> EntriesList = Formatter(asMap);
outputViews.write(new BinaryOutput() {
@Override
public void write(WritableByteChannel writeChannel) throws IOException {
OutputStream outputStream = Channels.newOutputStream(writeChannel);
try {
IOUtils.writeLines(EntriesList, null, outputStream, UTF_8);
} finally {
IOUtils.closeQuietly(outputStream);
}
}
@Override
public Document getHeader() {
// TODO Auto-generated method stub
return next;
}
});
} catch (JAXBException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
count.getAndIncrement();
}
}
@Override
public void cleanup() throws ExecutionException {
log.debug("Consumed {} documents", count.get());
}
}
Mapper Configuration screenshot: ( Target schema is blank )
Now please help me what i need to change in my code or provide me code snippet to expose my data on target schema.
Thanks
05-23-2018 10:04 PM
Designer screenshot: ( my snap is Test 2 which takes output of Mapper as input in test 2)
05-24-2018 08:08 AM
you can try putting a ‘copy’ snap after the mapper and revalidating. then see if the mapper cache has refreshed, and it may show your targets
05-24-2018 09:25 AM
Your Snap needs to implement the InputSchemaProvider interface in order for the Mapper to show any target schema. An example implementation that should show two fields, ‘field1’ and ‘field2’, would be:
@Override
public void defineInputSchema(SchemaProvider provider) {
for (String inputViewName : provider.getRegisteredViewNames()) {
Schema field1Schema = provider.createSchema(SnapType.STRING, "field1");
Schema field2Schema = provider.createSchema(SnapType.STRING, "field2");
provider.getSchemaBuilder(inputViewName)
.withChildSchema(field1Schema)
.withChildSchema(field2Schema)
.build();
}
}