in document_ai_warehouse/document-ai-warehouse-java-samples/src/main/java/org/example/CreateDocumentDocAi.java [146:188]
public static void main(String[] args) {
String projectNumber = System.getenv("PROJECT_NUMBER");
if (projectNumber == null) {
System.err.println("No PROJECT_NUMBER environment variable set");
return;
}
String userid = System.getenv("USERID");
if (userid == null) {
System.err.println("No USERID environment variable set");
return;
}
String location = System.getenv("LOCATION");
if (location == null) {
location = "us"; // Default to us location
}
if (args.length < 2) {
System.err.println("Usage: CreateDocumentDocAI [FILENAME]");
return;
}
String schemaName = args[0]; // Name of schema to associate with document.
String fileName = args[1]; // Local file name of document.
String processorName = args[2]; // Name of the DocAI processor to use
try {
// Read the document data into memory for passing to
// Document AI Warehouse.
ByteString fileData = ByteString.readFrom(new FileInputStream(fileName));
CreateDocumentDocAi app = new CreateDocumentDocAi();
app.setProjectNumber(projectNumber);
app.setUserId(userid);
app.setLocation(location);
com.google.cloud.documentai.v1.Document docAiDocument =
app.processDocAi(processorName, fileData);
app.createDocument(schemaName, docAiDocument, fileData);
} catch (Exception e) {
e.printStackTrace();
return;
}
System.out.println("CreateDocumentDocAI completed");
} // main