Example usage for org.apache.poi.ss.usermodel WorkbookFactory create

List of usage examples for org.apache.poi.ss.usermodel WorkbookFactory create

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel WorkbookFactory create.

Prototype

public static Workbook create(File file) throws IOException, EncryptedDocumentException 

Source Link

Document

Creates the appropriate HSSFWorkbook / XSSFWorkbook from the given File, which must exist and be readable.

Usage

From source file:io.konig.spreadsheet.WorkbookLoaderTest.java

License:Apache License

@Ignore
public void testOneOfCol() throws Exception {

    InputStream input = getClass().getClassLoader().getResourceAsStream("awsAuroraTransformOneOF.xlsx");
    Workbook book = WorkbookFactory.create(input);
    Graph graph = new MemoryGraph();
    NamespaceManager nsManager = new MemoryNamespaceManager();
    graph.setNamespaceManager(nsManager);

    WorkbookLoader loader = new WorkbookLoader(nsManager);
    File file = new File("src/test/resources/awsAuroraTransformOneOF.xlsx");
    loader.load(book, graph, file);/*  ww  w . ja  v a 2 s .c om*/
    input.close();

    URI shapeId = uri("http://example.com/shapes/PartyShape");

    ShapeManager shapeManager = loader.getShapeManager();

    Shape shape = shapeManager.getShapeById(shapeId);
    assertTrue(shape != null);
    assertTrue(shape.getOr() != null);
    List<Shape> list = shape.getOr().getShapes();
    assertEquals(2, list.size());
    assertEquals("http://example.com/shapes/PersonShape", list.get(0).getId().stringValue());

}

From source file:io.konig.spreadsheet.WorkbookLoaderTest.java

License:Apache License

@Ignore
public void testPrimaryKey() throws Exception {

    InputStream input = getClass().getClassLoader().getResourceAsStream("primarykey-stereotype.xlsx");
    Workbook book = WorkbookFactory.create(input);
    Graph graph = new MemoryGraph();
    NamespaceManager nsManager = new MemoryNamespaceManager();
    graph.setNamespaceManager(nsManager);

    WorkbookLoader loader = new WorkbookLoader(nsManager);
    File file = new File("src/test/resources/primarykey-stereotype.xlsx");
    loader.load(book, graph, file);/*from  www  .  j  av  a2s. co m*/
    input.close();

    URI shapeId = uri("http://example.com/shapes/SourcePersonShape");

    ShapeManager s = loader.getShapeManager();

    Shape shape = s.getShapeById(shapeId);
    List<PropertyConstraint> propertyList = shape.getProperty();
    //SequencePath sequence = null;
    for (PropertyConstraint p : propertyList) {
        //PropertyPath path = p.getPath();
        if (p.getStereotype() != null) {
            assertEquals((p.getStereotype().getLocalName()), "primaryKey");
        }
    }
    assertTrue(shape != null);

}

From source file:io.konig.spreadsheet.WorkbookLoaderTest.java

License:Apache License

@Ignore
public void testSecurityClassification() throws Exception {

    InputStream input = getClass().getClassLoader().getResourceAsStream("security-classification.xlsx");
    Workbook book = WorkbookFactory.create(input);
    Graph graph = new MemoryGraph();
    NamespaceManager nsManager = new MemoryNamespaceManager();
    graph.setNamespaceManager(nsManager);

    WorkbookLoader loader = new WorkbookLoader(nsManager);
    File file = new File("src/test/resources/security-classification.xlsx");
    loader.load(book, graph, file);//from  w  w  w  . j  a  va  2 s.c  o m
    input.close();

    URI shapeId = uri("http://example.com/shapes/PersonShape");

    ShapeManager s = loader.getShapeManager();

    Shape shape = s.getShapeById(shapeId);
    assertTrue(shape != null);

    PropertyConstraint familyName = shape.getPropertyConstraint(Schema.familyName);
    assertTrue(familyName != null);

    List<URI> qsc = familyName.getQualifiedSecurityClassification();
    assertTrue(qsc != null);
    assertEquals(1, qsc.size());

    URI Private = uri("http://example.com/ns/security/Private");
    assertEquals(Private, qsc.get(0));

    ShapeWriter shapeWriter = new ShapeWriter();
    try {
        shapeWriter.writeTurtle(nsManager, shape,
                new File("target/test/security-classification/PersonShape.ttl"));
    } catch (Exception e) {
        throw new KonigException(e);
    }

    // Verify that schema:givenName has the DCL4 security classification

    Set<URI> sc = graph.v(Schema.givenName).out(Konig.securityClassification).toUriSet();
    assertEquals(1, sc.size());

    URI DCL4 = uri("https://schema.pearson.com/ns/dcl/DCL4");
    assertEquals(DCL4, sc.iterator().next());

}

From source file:io.konig.spreadsheet.WorkbookLoaderTest.java

License:Apache License

public void testTabularNodeShape_1() throws Exception {

    InputStream input = getClass().getClassLoader().getResourceAsStream("rdbms-node-shape.xlsx");
    Workbook book = WorkbookFactory.create(input);
    Graph graph = new MemoryGraph();
    NamespaceManager nsManager = new MemoryNamespaceManager();
    graph.setNamespaceManager(nsManager);

    WorkbookLoader loader = new WorkbookLoader(nsManager);
    File file = new File("src/test/resources/rdbms-node-shape.xlsx");
    loader.load(book, graph, file);/*w  ww  .j  a va2  s  .  co m*/
    input.close();

    URI shapeId = uri("http://example.com/shapes/SourcePersonShape");

    ShapeManager s = loader.getShapeManager();

    ShapeWriter shapeWriter = new ShapeWriter();
    Shape shape = s.getShapeById(shapeId);

    assertTrue(shape != null);
    try {
        shapeWriter.writeTurtle(nsManager, shape, new File("target/test/rdbmsNodeShape/PersonShape.ttl"));
    } catch (Exception e) {
        throw new KonigException(e);
    }
}

From source file:io.konig.spreadsheet.WorkbookLoaderTest.java

License:Apache License

@Test
public void testDataDictionaryForDerivedProperty() throws Exception {
    InputStream input = getClass().getClassLoader().getResourceAsStream("data-dictionary.xlsx");
    Workbook book = WorkbookFactory.create(input);
    Graph graph = new MemoryGraph();
    NamespaceManager nsManager = new MemoryNamespaceManager();
    nsManager.add("ex", "http://example.com/alias/");
    graph.setNamespaceManager(nsManager);

    WorkbookLoader loader = new WorkbookLoader(nsManager);
    File file = new File("src/test/resources/data-dictionary.xlsx");
    loader.load(book, graph, file);/*from  www  . j  a  v a 2s  .c om*/
    input.close();
    ShapeManager s = loader.getShapeManager();

    URI shapeId = uri("http://example.com/shapes/ORACLE_EBS/OE_ORDER_LINES_ALL");
    Shape shape = s.getShapeById(shapeId);
    assertTrue(shape != null);
    assertEquals(1, shape.getDerivedProperty().size());
    PropertyConstraint pc = shape.getDerivedProperty().get(0);
    assertEquals(uri("ex:ORDER_KEY"), pc.getPredicate());
}

From source file:io.konig.spreadsheet.WorkbookLoaderTest.java

License:Apache License

@Ignore
public void testDataDictionaryForString() throws Exception {

    InputStream input = getClass().getClassLoader().getResourceAsStream("data-dictionary.xlsx");
    Workbook book = WorkbookFactory.create(input);
    Graph graph = new MemoryGraph();
    NamespaceManager nsManager = new MemoryNamespaceManager();
    graph.setNamespaceManager(nsManager);

    WorkbookLoader loader = new WorkbookLoader(nsManager);
    File file = new File("src/test/resources/data-dictionary.xlsx");
    loader.load(book, graph, file);/* www.j  ava  2  s .  c o m*/
    input.close();
    URI shapeId = uri("http://example.com/shapes/MDM/RA_CUSTOMER_TRX_ALL");
    ShapeManager s = loader.getShapeManager();

    Shape shape1 = s.getShapeById(shapeId);
    assertTrue(shape1 != null);
    //assertTrue(shape1.getType()!=null && shape1.getType().contains(Konig.TabularNodeShape));      

    //Test String property
    PropertyConstraint pc = shape1
            .getPropertyConstraint(uri("http://example.com/alias/ADDRESS_VERIFICATION_CODE"));
    assertTrue(pc != null);
    assertTrue("Address Verification Code".equals(pc.getComment()));
    assertTrue(Konig.primaryKey.equals(pc.getStereotype()));
    assertTrue(XMLSchema.STRING.equals(pc.getDatatype()));
    assertTrue(pc.getMinCount() == 1);
    assertTrue(pc.getMaxCount() == 1);
    assertTrue(pc.getMaxLength() == 80);
    assertTrue(pc.getMaxInclusive() == null);
    assertTrue(pc.getMinInclusive() == null);
    assertTrue(pc.getDecimalScale() == null);
    assertTrue(pc.getDecimalPrecision() == null);
    Person person = pc.getDataSteward();
    assertTrue(person != null);
    assertEquals("Sample Data Steward", person.getName());
    assertTrue(pc.getQualifiedSecurityClassification() != null
            && pc.getQualifiedSecurityClassification().contains(uri("https://schema.pearson.com/ns/dcl/DCL1")));

    pc = shape1.getPropertyConstraint(uri("http://example.com/alias/NAME"));
    assertTrue(XMLSchema.STRING.equals(pc.getDatatype()) && pc.getMaxLength() == 80);
    assertTrue(pc.getQualifiedSecurityClassification() != null
            && pc.getQualifiedSecurityClassification().contains(uri("https://schema.pearson.com/ns/dcl/DCL3")));
    pc = shape1.getPropertyConstraint(uri("http://example.com/alias/GENDER"));
    assertTrue(XMLSchema.STRING.equals(pc.getDatatype()) && pc.getMaxLength() == 1);
    pc = shape1.getPropertyConstraint(uri("http://example.com/alias/ADDRESS"));
    assertTrue(XMLSchema.STRING.equals(pc.getDatatype()) && pc.getMaxLength() == 80);
    assertTrue(pc != null);

    shapeId = uri("http://example.com/shapes/ORACLE_EBS/OE_ORDER_LINES_ALL");
    Shape shape2 = s.getShapeById(shapeId);
    assertTrue(shape2 != null);
}

From source file:io.konig.spreadsheet.WorkbookLoaderTest.java

License:Apache License

@Test
public void testDataDictionaryForInteger() throws Exception {

    InputStream input = getClass().getClassLoader().getResourceAsStream("data-dictionary.xlsx");
    Workbook book = WorkbookFactory.create(input);
    Graph graph = new MemoryGraph();
    NamespaceManager nsManager = new MemoryNamespaceManager();
    graph.setNamespaceManager(nsManager);

    WorkbookLoader loader = new WorkbookLoader(nsManager);
    File file = new File("src/test/resources/data-dictionary.xlsx");
    loader.load(book, graph, file);//ww w  .  j  a v a 2  s  .  c o  m
    input.close();
    URI shapeId = uri("http://example.com/shapes/MDM/RA_CUSTOMER_TRX_ALL");
    ShapeManager s = loader.getShapeManager();

    Shape shape1 = s.getShapeById(shapeId);
    assertTrue(shape1 != null);
    //assertTrue(shape1.getType()!=null && shape1.getType().contains(Konig.TabularNodeShape));

    shapeId = uri("http://example.com/shapes/ORACLE_EBS/OE_ORDER_LINES_ALL");
    Shape shape2 = s.getShapeById(shapeId);
    assertTrue(shape2 != null);

    PropertyConstraint pc = shape2.getPropertyConstraint(uri("http://example.com/alias/ORDER_DATE"));
    assertTrue(XMLSchema.DATE.equals(pc.getDatatype()) && pc.getMaxLength() == null);

    pc = shape2.getPropertyConstraint(uri("http://example.com/alias/ORDER_TIME"));
    assertTrue(XMLSchema.DATETIME.equals(pc.getDatatype()) && pc.getMaxLength() == null);
    pc = shape2.getPropertyConstraint(uri("http://example.com/alias/INVOICE_VALUE"));

    assertTrue(XMLSchema.DECIMAL.equals(pc.getDatatype()));
    assertEquals(15, pc.getDecimalPrecision().intValue());
    assertEquals(6, pc.getDecimalScale().intValue());

    pc = shape2.getPropertyConstraint(uri("http://example.com/alias/DICOUNT_PC"));

    assertTrue(XMLSchema.INTEGER.equals(pc.getDatatype()) && pc.getMinInclusive().intValue() == -32768
            && pc.getMaxInclusive().intValue() == 32767);

    pc = shape2.getPropertyConstraint(uri("http://example.com/alias/NO_OF_ITEMS"));

    assertTrue(XMLSchema.INTEGER.equals(pc.getDatatype()) && pc.getMinInclusive().intValue() == 0
            && pc.getMaxInclusive().intValue() == 65535);

    pc = shape2.getPropertyConstraint(uri("http://example.com/alias/CREDIT_VALUE"));

    assertTrue(XMLSchema.INTEGER.equals(pc.getDatatype()) && pc.getMinInclusive().intValue() == -2147483648
            && pc.getMaxInclusive().intValue() == 2147483647);

    pc = shape2.getPropertyConstraint(uri("http://example.com/alias/ORDER_NUMBER"));
    assertTrue(Konig.uniqueKey.equals(pc.getStereotype()));
    assertTrue(XMLSchema.INTEGER.equals(pc.getDatatype()) && pc.getMinInclusive().intValue() == 0
            && pc.getMaxInclusive().longValue() == 4294967295L);

    pc = shape2.getPropertyConstraint(uri("http://example.com/alias/TOTAL_VALUE"));

    assertTrue(XMLSchema.INTEGER.equals(pc.getDatatype())
            && (pc.getMinInclusive().longValue() == -9223372036854775808L)
            && (pc.getMaxInclusive().longValue() == 9223372036854775807L));

    pc = shape2.getPropertyConstraint(uri("http://example.com/alias/INVOICE_NUMBER"));
    assertTrue(XMLSchema.INTEGER.equals(pc.getDatatype()) && pc.getMinInclusive().intValue() == 0
            && pc.getMaxInclusive().equals(new BigInteger("18446744073709551615")));

    pc = shape2.getPropertyConstraint(uri("http://example.com/alias/DISCOUNT_AMOUNT"));
    assertTrue(XMLSchema.FLOAT.equals(pc.getDatatype()));
    assertTrue(pc.getMinInclusive() == null);
    assertTrue(pc.getMaxInclusive() == null);
    assertTrue(pc.getDecimalPrecision() != null);
    assertEquals(15, pc.getDecimalPrecision().intValue());
    assertTrue(pc.getDecimalScale() != null);
    assertEquals(6, pc.getDecimalScale().intValue());

    pc = shape2.getPropertyConstraint(uri("http://example.com/alias/VALUE_OF_ITEMS"));
    assertTrue(XMLSchema.DOUBLE.equals(pc.getDatatype()));
    assertTrue(pc.getMinInclusive() == null);
    assertTrue(pc.getMaxInclusive() == null);
    assertTrue(pc.getDecimalPrecision() != null);
    assertEquals(15, pc.getDecimalPrecision().intValue());
    assertTrue(pc.getDecimalScale() != null);
    assertEquals(6, pc.getDecimalScale().intValue());

    pc = shape2.getPropertyConstraint(uri("http://example.com/alias/SERVICE_TAX_APPLIED"));
    assertTrue(XMLSchema.DECIMAL.equals(pc.getDatatype()));
    assertTrue(pc.getMinInclusive() == null);
    assertTrue(pc.getMaxInclusive() == null);
    assertTrue(pc.getDecimalPrecision() != null);
    assertEquals(15, pc.getDecimalPrecision().intValue());
    assertTrue(pc.getDecimalScale() != null);
    assertEquals(6, pc.getDecimalScale().intValue());

    pc = shape2.getPropertyConstraint(uri("http://example.com/alias/CODE"));
    assertTrue(XMLSchema.BASE64BINARY.equals(pc.getDatatype()) && pc.getMaxLength() == 5);
    pc = shape2.getPropertyConstraint(uri("http://example.com/alias/IS_NEW"));
    assertTrue(XMLSchema.BOOLEAN.equals(pc.getDatatype()));
}

From source file:io.konig.spreadsheet.WorkbookLoaderTest.java

License:Apache License

@Ignore
public void testDataDictionaryForAbbreviations() throws Exception {

    InputStream input = getClass().getClassLoader().getResourceAsStream("data-dictionary.xlsx");
    Workbook book = WorkbookFactory.create(input);
    Graph graph = new MemoryGraph();
    NamespaceManager nsManager = new MemoryNamespaceManager();
    graph.setNamespaceManager(nsManager);

    WorkbookLoader loader = new WorkbookLoader(nsManager);
    File file = new File("src/test/resources/data-dictionary.xlsx");
    loader.load(book, graph, file);//ww w .ja v  a2 s . com
    input.close();
    URI shapeId = uri("http://example.com/shapes/MDM/RA_CUSTOMER_TRX_ALL");
    ShapeManager s = loader.getShapeManager();

    // We'll also test the SkosEmitter in this test case.

    File testDir = new File("target/test/WorkbookLoaderTest/dataDictionaryAbbrev");
    SkosEmitter emitter = new SkosEmitter(testDir);
    emitter.emit(graph);

    graph = new MemoryGraph(nsManager);
    RdfUtil.loadTurtle(testDir, graph);

    Shape shape1 = s.getShapeById(shapeId);
    assertTrue(shape1 != null);
    assertTrue(shape1.getUsesAbbreviationScheme() != null
            && uri("https://example.com/exampleModel/AbbreviationScheme/")
                    .equals(shape1.getUsesAbbreviationScheme()));

    shapeId = uri("http://example.com/shapes/ORACLE_EBS/OE_ORDER_LINES_ALL");
    Shape shape2 = s.getShapeById(shapeId);
    assertTrue(shape2 != null);
    assertTrue(shape2.getUsesAbbreviationScheme() != null
            && uri("https://example.com/exampleModel/AbbreviationScheme/")
                    .equals(shape2.getUsesAbbreviationScheme()));

    List<Vertex> vertexList = graph.v(SKOS.CONCEPT_SCHEME).in(RDF.TYPE).toVertexList();
    assertTrue(vertexList != null && vertexList.size() == 1);
    Vertex abbrev = vertexList.get(0);
    assertTrue(uri("https://example.com/exampleModel/AbbreviationScheme/").equals(abbrev.getId()));

    vertexList = graph.v(SKOS.CONCEPT).in(RDF.TYPE).toVertexList();
    assertTrue(vertexList != null && vertexList.size() == 3);
    Vertex mfgVertex = vertexList.get(0);
    assertTrue(
            uri("https://example.com/exampleModel/AbbreviationScheme/MANUFACTURING").equals(mfgVertex.getId()));
    ValueFactory vf = new ValueFactoryImpl();
    assertTrue(vf.createLiteral("MANUFACTURING").equals(mfgVertex.getValue(SKOS.PREF_LABEL)));
    assertTrue(vf.createLiteral("MFG").equals(mfgVertex.getValue(Konig.abbreviationLabel)));
    assertTrue(vf.createURI("https://example.com/exampleModel/AbbreviationScheme/")
            .equals(mfgVertex.getValue(SKOS.IN_SCHEME)));

    Vertex uda = vertexList.get(1);
    assertTrue(uri("https://example.com/exampleModel/AbbreviationScheme/USER_DEFINED_ATTRIBUTES")
            .equals(uda.getId()));
    assertTrue(vf.createLiteral("USER_DEFINED_ATTRIBUTES").equals(uda.getValue(SKOS.PREF_LABEL)));
    assertTrue(vf.createLiteral("UDA").equals(uda.getValue(Konig.abbreviationLabel)));
    assertTrue(vf.createURI("https://example.com/exampleModel/AbbreviationScheme/")
            .equals(uda.getValue(SKOS.IN_SCHEME)));

    Vertex org = vertexList.get(2);
    assertTrue(uri("https://example.com/exampleModel/AbbreviationScheme/ORGANIZATION").equals(org.getId()));
    assertTrue(vf.createLiteral("ORGANIZATION").equals(org.getValue(SKOS.PREF_LABEL)));
    assertTrue(vf.createLiteral("ORG").equals(org.getValue(Konig.abbreviationLabel)));
    assertTrue(vf.createURI("https://example.com/exampleModel/AbbreviationScheme/")
            .equals(org.getValue(SKOS.IN_SCHEME)));

    IOUtil.recursiveDelete(testDir);

}

From source file:io.konig.spreadsheet.WorkbookLoaderTest.java

License:Apache License

@Ignore
public void testDataDictionaryForDatasource() throws Exception {
    InputStream input = getClass().getClassLoader().getResourceAsStream("data-dictionary.xlsx");
    Workbook book = WorkbookFactory.create(input);
    Graph graph = new MemoryGraph();
    NamespaceManager nsManager = new MemoryNamespaceManager();
    graph.setNamespaceManager(nsManager);

    WorkbookLoader loader = new WorkbookLoader(nsManager);
    loader.load(book, graph);/* ww  w  .j  a  va 2  s.  c om*/
    input.close();
    URI shapeId = uri("http://example.com/shapes/MDM/RA_CUSTOMER_TRX_ALL");
    ShapeManager s = loader.getShapeManager();

    Shape shape1 = s.getShapeById(shapeId);
    assertTrue(shape1 != null);
    assertTrue(shape1.getShapeDataSource() != null);
    List<DataSource> datasourceList = shape1.getShapeDataSource();
    assertTrue(datasourceList.size() == 1);
    assertTrue(datasourceList.get(0).getType() != null && datasourceList.get(0).getType().size() == 2);
    assertTrue(datasourceList.get(0).getType().contains(Konig.AwsAuroraTable));

    shapeId = uri("http://example.com/shapes/ORACLE_EBS/OE_ORDER_LINES_ALL");
    Shape shape2 = s.getShapeById(shapeId);
    assertTrue(shape2 != null);
    assertTrue(shape2.getShapeDataSource() != null);
    datasourceList = shape2.getShapeDataSource();
    assertTrue(datasourceList.size() == 1);
    assertTrue(datasourceList.get(0).getType() != null && datasourceList.get(0).getType().size() == 2);
    assertTrue(datasourceList.get(0).getType().contains(Konig.AwsAuroraTable));

}

From source file:io.konig.spreadsheet.WorkbookLoaderTest.java

License:Apache License

public void testTabularNodeShape_2() throws Exception {

    InputStream input = getClass().getClassLoader().getResourceAsStream("rdbms-node-shape-generator.xlsx");
    Workbook book = WorkbookFactory.create(input);
    Graph graph = new MemoryGraph();
    NamespaceManager nsManager = new MemoryNamespaceManager();
    graph.setNamespaceManager(nsManager);

    WorkbookLoader loader = new WorkbookLoader(nsManager);
    File file = new File("src/test/resources/rdbms-node-shape-generator.xlsx");
    loader.load(book, graph, file);/*from ww  w .j a va 2s. c o m*/
    input.close();
    URI shapeId = uri("http://example.com/shapes/TargetPersonRdbmsShape");

    ShapeManager s = loader.getShapeManager();

    ShapeWriter shapeWriter = new ShapeWriter();
    Shape shape = s.getShapeById(shapeId);
    System.out.println(shape.getTabularOriginShape() + " shape.getTabularOriginShape()");
    assertTrue(shape != null);
    try {
        shapeWriter.writeTurtle(nsManager, shape, new File("target/test/rdbmsNodeShape/Shape_TargetShape.ttl"));
    } catch (Exception e) {
        throw new KonigException(e);
    }
}