cancel
Showing results for 
Search instead for 
Did you mean: 

Mapper not showing target schema for my custom snap

nikhilpurohit
New Contributor

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 )
d9af7e66-4750-4cf3-a1a6-f2caf9b4a8cb

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

3 REPLIES 3

nikhilpurohit
New Contributor

Designer screenshot: ( my snap is Test 2 which takes output of Mapper as input in test 2)
05d7c91b-bf32-4f8b-a38d-df2e8d5483e8

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

tstack
Former Employee

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();
        }
    }