List of usage examples for org.apache.poi.ss.usermodel WorkbookFactory create
public static Workbook create(File file) throws IOException, EncryptedDocumentException
From source file:io.konig.spreadsheet.WorkbookLoaderTest.java
License:Apache License
@Ignore public void testJsonPathNestedString() throws Exception { InputStream input = getClass().getClassLoader().getResourceAsStream("json-path-nested-string.xlsx"); Workbook book = WorkbookFactory.create(input); Graph graph = new MemoryGraph(); NamespaceManager nsManager = new MemoryNamespaceManager(); graph.setNamespaceManager(nsManager); WorkbookLoader loader = new WorkbookLoader(nsManager); loader.setFailOnErrors(false);// ww w. ja va 2 s.co m loader.setFailOnWarnings(false); loader.load(book, graph); URI userShapeId = uri("https://example.com/shapes/USER_STG_Shape"); URI addressShapeId = uri("https://example.com/shapes/USER_STG_.addressShape"); URI addressId = uri("https://example.com/ns/alias/address"); URI postalCodeId = uri("https://example.com/ns/alias/postalCode"); ShapeManager shapeManager = loader.getShapeManager(); Shape userShape = shapeManager.getShapeById(userShapeId); Shape addressShape = shapeManager.getShapeById(addressShapeId); assertTrue(userShape != null); PropertyConstraint address = userShape.getPropertyConstraint(addressId); assertTrue(address != null); assertEquals(new Integer(1), address.getMaxCount()); Shape nestedAddressShape = address.getShape(); assertTrue(nestedAddressShape == addressShape); assertTrue(addressShape != null); PropertyConstraint postalCode = addressShape.getPropertyConstraint(postalCodeId); assertTrue(postalCode != null); assertEquals(new Integer(1), postalCode.getMaxCount()); assertEquals(XMLSchema.STRING, postalCode.getDatatype()); }
From source file:io.konig.spreadsheet.WorkbookLoaderTest.java
License:Apache License
@Ignore public void testJsonPathString() throws Exception { InputStream input = getClass().getClassLoader().getResourceAsStream("json-path-string.xlsx"); Workbook book = WorkbookFactory.create(input); Graph graph = new MemoryGraph(); NamespaceManager nsManager = new MemoryNamespaceManager(); graph.setNamespaceManager(nsManager); WorkbookLoader loader = new WorkbookLoader(nsManager); loader.setFailOnErrors(false);/*from w w w . j a va 2s.c o m*/ loader.setFailOnWarnings(false); loader.load(book, graph); URI shapeId = uri("https://example.com/shapes/USER_STG_Shape"); ShapeManager shapeManager = loader.getShapeManager(); Shape shape = shapeManager.getShapeById(shapeId); URI givenName = uri("https://example.com/ns/alias/givenName"); PropertyConstraint p = shape.getPropertyConstraint(givenName); assertTrue(p != null); assertEquals(new Integer(1), p.getMaxCount()); assertEquals(XMLSchema.STRING, p.getDatatype()); }
From source file:io.konig.spreadsheet.WorkbookLoaderTest.java
License:Apache License
@Ignore public void testBigQueryJsonBucket() throws Exception { GcpShapeConfig.init();// www .jav a 2 s. c o m InputStream input = getClass().getClassLoader().getResourceAsStream("bigquery-json-bucket.xlsx"); Workbook book = WorkbookFactory.create(input); Graph graph = new MemoryGraph(); NamespaceManager nsManager = new MemoryNamespaceManager(); graph.setNamespaceManager(nsManager); WorkbookLoader loader = new WorkbookLoader(nsManager); loader.setFailOnErrors(false); loader.setFailOnWarnings(false); loader.load(book, graph); URI shapeId = uri("http://example.com/shapes/PersonShape"); ShapeManager shapeManager = loader.getShapeManager(); Shape shape = shapeManager.getShapeById(shapeId); Optional<GoogleBigQueryTable> ds = shape.getShapeDataSource().stream() .filter(d -> d instanceof GoogleBigQueryTable).map(d -> (GoogleBigQueryTable) d).findAny(); assertTrue(ds.isPresent()); assertEquals("schema.Person", ds.get().getTableIdentifier()); // ShapeWriter writer = new ShapeWriter(); // MemoryGraph shapeGraph = new MemoryGraph(); // writer.emitShape(shape, shapeGraph); // RdfUtil.prettyPrintTurtle(shapeGraph, System.out); }
From source file:io.konig.spreadsheet.WorkbookLoaderTest.java
License:Apache License
@Ignore public void testXone() throws Exception { GcpShapeConfig.init();//ww w . jav a 2 s. c o m InputStream input = getClass().getClassLoader().getResourceAsStream("xone.xlsx"); Workbook book = WorkbookFactory.create(input); Graph graph = new MemoryGraph(); NamespaceManager nsManager = new MemoryNamespaceManager(); graph.setNamespaceManager(nsManager); WorkbookLoader loader = new WorkbookLoader(nsManager); loader.setFailOnErrors(false); loader.setFailOnWarnings(false); loader.load(book, graph); URI agentShapeId = uri("http://example.com/shapes/AgentShape"); URI personShapeId = uri("http://example.com/shapes/PersonShape"); URI orgShapeId = uri("http://example.com/shapes/OrgShape"); ShapeManager shapeManager = loader.getShapeManager(); Shape agentShape = shapeManager.getShapeById(agentShapeId); XoneConstraint constraint = agentShape.getXone(); assertTrue(constraint != null); assertTrue(contains(constraint, personShapeId)); assertTrue(contains(constraint, orgShapeId)); }
From source file:io.konig.spreadsheet.WorkbookLoaderTest.java
License:Apache License
@Ignore public void testTriples() throws Exception { GcpShapeConfig.init();/* ww w . j a v a2 s .c o m*/ InputStream input = getClass().getClassLoader().getResourceAsStream("triples.xlsx"); Workbook book = WorkbookFactory.create(input); Graph graph = new MemoryGraph(); NamespaceManager nsManager = new MemoryNamespaceManager(); graph.setNamespaceManager(nsManager); WorkbookLoader loader = new WorkbookLoader(nsManager); loader.setFailOnErrors(false); loader.setFailOnWarnings(false); loader.load(book, graph); URI instanceId = uri("http://example.com/ns/deployment/myproject/gcp/sqladmin/instance/mdm"); Vertex v = graph.getVertex(instanceId); assertTrue(v != null); Set<Edge> out = v.outProperty(GCP.instanceType); assertEquals(1, out.size()); URI myproject = uri("http://example.com/ns/deployment/myproject/"); assertEquals(myproject, out.iterator().next().getContext()); Value instanceType = v.getValue(GCP.instanceType); assertEquals("CLOUD_SQL_INSTANCE", instanceType.stringValue()); Vertex settings = v.getVertex(GCP.settings); assertEquals("db-f1-micro", settings.getValue(GCP.tier).stringValue()); Optional<Resource> settingsContext = settings.outProperty(GCP.tier).stream().map(edge -> edge.getContext()) .findFirst(); assertTrue(settingsContext.isPresent()); assertEquals(settingsContext.get(), myproject); }
From source file:io.konig.spreadsheet.WorkbookLoaderTest.java
License:Apache License
@Ignore public void testPreferredTabularShape() throws Exception { GcpShapeConfig.init();//from w ww. ja va2 s .co m InputStream input = getClass().getClassLoader().getResourceAsStream("preferred-tabular-shape.xlsx"); Workbook book = WorkbookFactory.create(input); Graph graph = new MemoryGraph(); NamespaceManager nsManager = new MemoryNamespaceManager(); graph.setNamespaceManager(nsManager); WorkbookLoader loader = new WorkbookLoader(nsManager); loader.setFailOnErrors(true); loader.load(book, graph); URI shapeId = uri("http://example.com/shapes/PersonShape"); Shape shape = loader.getShapeManager().getShapeById(shapeId); URI orgShapeId = uri("http://example.com/shapes/OrganizationShape"); PropertyConstraint p = shape.getPropertyConstraint(Schema.worksFor); assertEquals(orgShapeId, p.getPreferredTabularShape()); }
From source file:io.konig.spreadsheet.WorkbookLoaderTest.java
License:Apache License
@Ignore public void testClassSubjectArea() throws Exception { GcpShapeConfig.init();/*w w w . j a v a 2s .com*/ InputStream input = getClass().getClassLoader().getResourceAsStream("class-subject-area.xlsx"); Workbook book = WorkbookFactory.create(input); Graph graph = new MemoryGraph(); NamespaceManager nsManager = new MemoryNamespaceManager(); graph.setNamespaceManager(nsManager); WorkbookLoader loader = new WorkbookLoader(nsManager); loader.setFailOnErrors(true); loader.load(book, graph); Vertex v = graph.getVertex(Schema.Order); URI finance = uri("http://example.com/subject/Finance"); URI crm = uri("http://example.com/subject/CRM"); Set<Value> set = v.getValueSet(SKOS.BROADER); assertEquals(2, set.size()); assertTrue(set.contains(finance)); assertTrue(set.contains(crm)); }
From source file:io.konig.spreadsheet.WorkbookLoaderTest.java
License:Apache License
@Ignore public void testDefaultDataSource() throws Exception { GcpShapeConfig.init();//from w ww . j a v a2 s.c om InputStream input = getClass().getClassLoader().getResourceAsStream("default-data-source.xlsx"); Workbook book = WorkbookFactory.create(input); Graph graph = new MemoryGraph(); NamespaceManager nsManager = new MemoryNamespaceManager(); graph.setNamespaceManager(nsManager); WorkbookLoader loader = new WorkbookLoader(nsManager); loader.setFailOnErrors(true); loader.load(book, graph); StringWriter writer = new StringWriter(); RdfUtil.prettyPrintTurtle(graph, writer); writer.close(); URI shapeId = uri("https://schema.pearson.com/shapes/PERSON_STG_Shape"); ShapeManager shapeManager = loader.getShapeManager(); Shape shape = shapeManager.getShapeById(shapeId); List<DataSource> list = shape.getShapeDataSource(); assertTrue(list != null); assertTrue(list.size() == 2); assertTrue(list.stream().filter(ds -> ds.isA(Konig.GoogleBigQueryTable)).count() == 1); assertTrue(list.stream().filter(ds -> ds.isA(Konig.GoogleCloudStorageBucket)).count() == 1); }
From source file:io.konig.spreadsheet.WorkbookLoaderTest.java
License:Apache License
@Ignore public void testSddFormula() throws Exception { GcpShapeConfig.init();// www . j a va 2 s . c o m InputStream input = getClass().getClassLoader().getResourceAsStream("sdd-formula.xlsx"); Workbook book = WorkbookFactory.create(input); Graph graph = new MemoryGraph(); NamespaceManager nsManager = new MemoryNamespaceManager(); graph.setNamespaceManager(nsManager); WorkbookLoader loader = new WorkbookLoader(nsManager); loader.setFailOnErrors(true); loader.load(book, graph); StringWriter writer = new StringWriter(); RdfUtil.prettyPrintTurtle(graph, writer); writer.close(); URI shapeId = uri("https://schema.pearson.com/shapes/PERSON_STG_Shape"); ShapeManager shapeManager = loader.getShapeManager(); URI predicate = uri("https://schema.pearson.com/ns/alias/GIVEN_NAME"); Shape shape = shapeManager.getShapeById(shapeId); assertTrue(shape != null); PropertyConstraint p = shape.getPropertyConstraint(predicate); assertTrue(p != null); QuantifiedExpression formula = p.getFormula(); assertTrue(formula != null); String text = formula.toSimpleString(); assertEquals("$.givenName", text); }
From source file:io.konig.spreadsheet.WorkbookLoaderTest.java
License:Apache License
@Ignore public void testDictionaryDefaultDatatype() throws Exception { GcpShapeConfig.init();//from ww w . ja v a 2s . c o m InputStream input = getClass().getClassLoader().getResourceAsStream("dictionary-default-datatype.xlsx"); Workbook book = WorkbookFactory.create(input); Graph graph = new MemoryGraph(); NamespaceManager nsManager = new MemoryNamespaceManager(); graph.setNamespaceManager(nsManager); WorkbookLoader loader = new WorkbookLoader(nsManager); loader.setFailOnErrors(true); loader.load(book, graph); StringWriter writer = new StringWriter(); RdfUtil.prettyPrintTurtle(graph, writer); writer.close(); URI shapeId = uri("https://schema.pearson.com/shapes/PERSON_STG_Shape"); ShapeManager shapeManager = loader.getShapeManager(); URI predicate = uri("https://schema.pearson.com/ns/alias/FIRST_NAME"); Shape shape = shapeManager.getShapeById(shapeId); PropertyConstraint p = shape.getPropertyConstraint(predicate); assertEquals(XMLSchema.STRING, p.getDatatype()); }