All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sixestates.example.Example Maven / Gradle / Ivy

Go to download

A Java SDK for communicating with the 6Estates Intelligent Document Processing(IDP) Platform

There is a newer version: 8.2.3
Show newest version
package com.sixestates.example;


import com.sixestates.Idp;
import com.sixestates.exception.ApiConnectionException;
import com.sixestates.exception.ApiException;
import com.sixestates.rest.v1.ExtractSubmitter;
import com.sixestates.rest.v1.ResultExtractor;
import com.sixestates.type.ResultDTO;
import com.sixestates.type.TaskDTO;
import com.sixestates.type.TaskInfo;
import java.io.FileInputStream;

public class Example {

    public static final String TOKEN = "XXXXXXX";
    public static final String FILE_NAME = "acount_statement_mandiri.pdf";
    public static final String FILE_PATH = "/home//lay/Documents/acount_statement_mandiri.pdf" ;
    public static final String FILE_TYPE = "CBKS";

    /**
     * Example IDP usage.
     *
     * @param  args command line args
     * @throws Exception if unable to generate InterruptedException or ApiException
     */
    public static void main(String[] args) throws Exception {

        Idp.init(TOKEN);

        // Submit a task
        TaskDTO taskDto = null;
        try {
            TaskInfo taskInfo = TaskInfo.builder()
                    .fileName(FILE_NAME)
                    .filePath(FILE_PATH)
                    .fileType(FILE_TYPE)
                    .hitl(true)
                    .build();
            taskDto = ExtractSubmitter.submit(taskInfo);

            System.out.println("taskId: " + taskDto.getData());
        }catch (final ApiException | ApiConnectionException e) {
            System.err.println(e);
        }

        // Extract the result
        if(taskDto != null && taskDto.getStatus() == 200) {

            try {
                System.out.println(ResultExtractor.extractResultByTaskid(taskDto.getData()));
            }catch (ApiException e) {
                System.err.println(e);
            }
        }


        // Submit the  new task
        TaskInfo taskInfo = TaskInfo.builder()
                .fileName("1006027_doc_MutasiBank_Bulan_2-1646623361478.jpg")
                .filePath("/home/Documents/1006027_doc_MutasiBank_Bulan_2-1646623361478.jpg")
                .fileType("CBKS")
                .build();
        taskDto = ExtractSubmitter.submit(taskInfo);
        System.out.println("taskId: " + taskDto.getData());

        // Extract the result
        if(taskDto.getStatus() == 200) {
            try{
                boolean taskDone = false;
                while(!taskDone){
                    String taskId = taskDto.getData();
                    ResultDTO resultDto = ResultExtractor.extractResultByTaskid(taskId);

                    if(resultDto.getTaskStatus().equals("Done")) {
                        //Print the response json string
                        System.out.println(resultDto.getRespJson());
                        taskDone = true;
                    }else {
                        System.out.println("The status is Doing or Init, please request again after 30 seconds ");
                        Thread.sleep( 1000 * 30);
                    }
                }
            }catch(ApiException e ){
                System.err.println(e);
            }
        }

        // Submit task using InputStream
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(FILE_PATH);

            taskInfo = TaskInfo.builder()
                    .fileName("acount_statement_mandiri.pdf")
                    .inputStream(fis)
                    .fileType("CBKS")
                    .build();

            taskDto = ExtractSubmitter.submit(taskInfo);
            System.out.println("taskId: " + taskDto.getData());
            fis.close();
        }catch(Exception e) {
            System.out.println(e);
        }finally {
            if(fis!=null) fis.close();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy