/**
   * If the {@link ConfigurationProperties} has a name for the initial admin user, create the user
   * and add it to the model.
   */
  protected void createInitialAdminUser(Model model) {
    String initialAdminUsername = ConfigurationProperties.getProperty("initialAdminUser");
    if (initialAdminUsername == null) {
      return;
    }

    // A hard-coded MD5 encryption of "defaultAdmin"
    String initialAdminPassword = "******";

    String vitroDefaultNs = DEFAULT_DEFAULT_NAMESPACE;

    Resource user = model.createResource(vitroDefaultNs + "defaultAdminUser");
    model.add(
        model.createStatement(
            user,
            model.createProperty(VitroVocabulary.RDF_TYPE),
            model.getResource(VitroVocabulary.USER)));
    model.add(
        model.createStatement(
            user,
            model.createProperty(VitroVocabulary.USER_USERNAME),
            model.createTypedLiteral(initialAdminUsername)));
    model.add(
        model.createStatement(
            user,
            model.createProperty(VitroVocabulary.USER_MD5PASSWORD),
            model.createTypedLiteral(initialAdminPassword)));
    model.add(
        model.createStatement(
            user,
            model.createProperty(VitroVocabulary.USER_ROLE),
            model.createTypedLiteral("role:/50")));
  }
 public void setUp() {
   model = getModel();
   Resource S2 = model.createResource(anchor + "subject2");
   S = model.createResource(anchor + "subject");
   P = model.createProperty(anchor + "predicate");
   O = model.createLiteral(anchor + "object");
   SPO = model.createStatement(S, P, O);
   SPO2 = model.createStatement(S2, P, O);
 }
  /**
   * Builds up the one triple that states where the actual data for the target mapping comes from.
   * Such a source can be simply a database table or an SQL query.
   *
   * @param r2rml the target com.hp.hpl.jena.rdf.model.Model
   * @param relation the data source (table name or SQL query)
   * @return the whole Statement stating where the data comes from, e.g. '[] rr:tableName "EMP"'
   */
  private Statement buildLogicalTableTriple(Model r2rml, SqlOpBase relation) {
    // subject (a blank node [])
    Resource logicalTableSubject = ResourceFactory.createResource();
    // predicate (rr:tableName or rr:sqlQuery)
    Property logicalTablePredicate;
    // object (a Literal like "SELECT DEPTNO FROM DEPT WHERE DEPTNO > 23" or
    // simply a table name like "DEPTNO"
    Literal logicalTableObject;

    // it's a table
    if (relation instanceof SqlOpTable) {
      SqlOpTable tbl = (SqlOpTable) relation;
      logicalTablePredicate = ResourceFactory.createProperty(rrNamespace, "tableName");
      logicalTableObject = ResourceFactory.createPlainLiteral(tbl.getTableName());

      // it's a query
    } else if (relation instanceof SqlOpQuery) {
      SqlOpQuery query = (SqlOpQuery) relation;
      logicalTablePredicate = ResourceFactory.createProperty(rrNamespace, "sqlQuery");
      logicalTableObject = ResourceFactory.createPlainLiteral(query.getQueryString());

      // it's not possible
    } else {
      // should never be called since a relation can either be a table
      // or a query
      logicalTablePredicate = ResourceFactory.createProperty("");
      logicalTableObject = ResourceFactory.createPlainLiteral("");
    }

    Statement logicalTblStatement =
        r2rml.createStatement(logicalTableSubject, logicalTablePredicate, logicalTableObject);

    return logicalTblStatement;
  }
示例#4
0
 /**
  * create a Statement in a given Model with (S, P, O) extracted by parsing a string.
  *
  * @param lockModel the model the statement is attached to
  * @param an "S P O" string.
  * @return model.createStatement(S, P, O)
  */
 public static Statement statement(Model m, String fact) {
   StringTokenizer st = new StringTokenizer(fact);
   Resource sub = resource(m, st.nextToken());
   Property pred = property(m, st.nextToken());
   RDFNode obj = rdfNode(m, st.nextToken());
   return m.createStatement(sub, pred, obj);
 }
示例#5
0
 @Override
 public Edge addEdge(
     final Object id, final Vertex outVertex, final Vertex inVertex, final String label) {
   final Resource inV = model.createResource(inVertex.getId().toString());
   final Resource outV = model.createResource(outVertex.getId().toString());
   final Property edge = model.createProperty(label);
   final Statement statement = model.createStatement(outV, edge, inV);
   model.add(statement);
   return new JenaEdge(model, edge, inV, outV);
 }
示例#6
0
  @Test
  public void shouldIgnoreHashUrisOutsideTheRepositoryDomain() throws RepositoryException {
    final Model m = createDefaultModel();

    final Statement x =
        m.createStatement(
            testSubjects.toDomain("/"), createProperty("info:x"), createResource("info:x#abc"));
    final Statement statement = testObj.skolemize(testSubjects, x);
    assertEquals(x, statement);
  }
示例#7
0
  @Test
  public void shouldPassthroughValidStatements() throws RepositoryException {
    final Model m = createDefaultModel();
    final Statement x =
        m.createStatement(
            testSubjects.toDomain("/"), createProperty("info:x"), createPlainLiteral("x"));
    final Statement statement = testObj.skolemize(testSubjects, x);

    assertEquals(x, statement);
  }
 public void testIsReified() {
   ReifiedStatement rs = model.createReifiedStatement(aURI, SPO);
   Resource BS = model.createResource(anchor + "BS");
   Property BP = model.createProperty(anchor + "BP");
   RDFNode BO = model.createProperty(anchor + "BO");
   model.add(rs, P, O);
   assertTrue("st should be reified now", SPO.isReified());
   assertTrue("m should have st reified now", model.isReified(SPO));
   assertFalse(
       "this new statement should not be reified", model.createStatement(BS, BP, BO).isReified());
 }
示例#9
0
  @Test
  public void shouldSkolemizeBlankNodeObjects() throws RepositoryException {
    final Model m = createDefaultModel();
    final Statement x =
        m.createStatement(testSubjects.toDomain("/"), createProperty("info:x"), createResource());
    testObj.jcrTools = mock(JcrTools.class);
    when(testObj.jcrTools.findOrCreateNode(eq(mockSession), anyString())).thenReturn(mockNode);
    when(mockNode.getPath()).thenReturn("/.well-known/x");
    final Statement statement = testObj.skolemize(testSubjects, x);

    assertEquals("info:fedora/.well-known/x", statement.getObject().toString());
  }
 /**
  * check that, from a model with any combination of the statements given, we can convert R into a
  * ReifiedStatement iff the four components of the quad are in the model.
  */
 public void testReificationCombinations() {
   Resource RR = model.createResource(aURI), SS = model.createResource(anotherURI);
   Property PP = (Property) RR.as(Property.class);
   Object[][] statements = {
     {model.createStatement(RR, RDF.type, RDF.Statement), new Integer(1)},
     {model.createStatement(RR, RDF.subject, SS), new Integer(2)},
     {model.createStatement(RR, RDF.predicate, PP), new Integer(4)},
     {model.createStatement(RR, RDF.object, O), new Integer(8)},
     {model.createStatement(SS, PP, O), new Integer(16)},
     {model.createStatement(RR, PP, O), new Integer(32)},
     {model.createStatement(SS, RDF.subject, SS), new Integer(64)},
     {model.createStatement(SS, RDF.predicate, PP), new Integer(128)},
     {model.createStatement(SS, RDF.object, O), new Integer(256)},
     {model.createStatement(SS, RDF.type, RDF.Statement), new Integer(512)}
   };
   if (model.getReificationStyle() != ModelFactory.Minimal)
     testCombinations(model, RR, 0, statements, statements.length);
 }
示例#11
0
 @Test(expected = PathNotFoundException.class)
 public void shouldNotAllowHashUriSubjectsForResourcesThatDontExist() throws RepositoryException {
   final Model m = createDefaultModel();
   final Statement x =
       m.createStatement(
           testSubjects.toDomain("/some/#/abc"),
           createProperty("info:x"),
           testSubjects.toDomain("/"));
   testObj.jcrTools = mock(JcrTools.class);
   when(mockNode.getParent()).thenReturn(mockHashNode);
   when(mockHashNode.getParent()).thenReturn(mockChildNode);
   when(mockSession.nodeExists("/some")).thenReturn(false);
   when(testObj.jcrTools.findOrCreateNode(mockSession, "/some/#/abc", NT_FOLDER))
       .thenReturn(mockNode);
   testObj.skolemize(testSubjects, x);
 }
  public static Statement createStatement(Triple triple) throws OREException {
    Model model = ModelFactory.createDefaultModel();

    Resource resource = model.createResource(triple.getSubjectURI().toString());
    Property property = model.createProperty(triple.getPredicate().getURI().toString());

    RDFNode node;
    if (triple.isLiteral()) {
      node = model.createTypedLiteral(triple.getObjectLiteral());
    } else {
      node = model.createResource(triple.getObjectURI().toString());
    }

    Statement statement = model.createStatement(resource, property, node);

    return statement;
  }
示例#13
0
 @Test
 public void shouldCreateHashUriObjects() throws RepositoryException {
   final Model m = createDefaultModel();
   final Statement x =
       m.createStatement(
           testSubjects.toDomain("/"),
           createProperty("info:x"),
           testSubjects.toDomain("/some/#/abc"));
   testObj.jcrTools = mock(JcrTools.class);
   when(mockNode.getParent()).thenReturn(mockHashNode);
   when(mockHashNode.getParent()).thenReturn(mockChildNode);
   when(mockSession.nodeExists("/some")).thenReturn(true);
   when(mockSession.getNode("/some")).thenReturn(mockChildNode);
   when(testObj.jcrTools.findOrCreateNode(mockSession, "/some/#/abc", NT_FOLDER))
       .thenReturn(mockNode);
   final Statement statement = testObj.skolemize(testSubjects, x);
   assertEquals(x, statement);
   verify(testObj.jcrTools).findOrCreateNode(mockSession, "/some/#/abc", NT_FOLDER);
   verify(mockNode).addMixin(FEDORA_RESOURCE);
 }
示例#14
0
 @Test
 public void shouldAddBlankNodePairtreeMixin() throws RepositoryException {
   final Model m = createDefaultModel();
   final Resource resource = createResource();
   final Statement x = m.createStatement(resource, createProperty("info:x"), resource);
   testObj.jcrTools = mock(JcrTools.class);
   when(testObj.jcrTools.findOrCreateNode(eq(mockSession), anyString())).thenReturn(mockNode);
   when(mockNode.getPath()).thenReturn("/x");
   when(mockNode.getParent()).thenReturn(mockHashNode);
   when(mockHashNode.getParent()).thenReturn(mockChildNode);
   when(mockHashNode.isNew()).thenReturn(true);
   when(FedoraTypesUtils.getClosestExistingAncestor(mockSession, "/.well-known/genid/"))
       .thenReturn(mockChildNode);
   final Statement statement = testObj.skolemize(testSubjects, x);
   assertEquals("info:fedora/x", statement.getSubject().toString());
   assertEquals("info:fedora/x", statement.getObject().toString());
   verify(testObj.jcrTools).findOrCreateNode(mockSession, "/.well-known/genid/");
   verify(mockNode).addMixin(FEDORA_SKOLEM);
   verify(mockNode.getParent()).addMixin(FEDORA_PAIRTREE);
 }
  /**
   * Builds up statements like [] rr:template "http://data.example.com/department/{DEPTNO}" or []
   * rr:class ex:Department and returns them as a Statement List.
   *
   * @param r2rml the target com.hp.hpl.jena.rdf.model.Model
   * @param mappingData the target that should be mapped to relational structures (subject,
   *     predicate or object)
   * @param varDefs the construction definition of the target value based in the actual database
   *     value and some additional data like prefix strings or certain functions like uri( ... )
   * @return a List<Statement> containing all the subject map statements
   */
  private List<Statement> buildMapStatements(Model r2rml, Node mappingData, VarDefinition varDefs) {

    List<Statement> results = new ArrayList<Statement>();

    // a blank node []
    Resource mapSubject = ResourceFactory.createResource();
    // rr:template or rr:column or rr:constant
    Property mapPredicate;
    // a literal like "http://data.example.com/department/{DEPTNO}" or
    // simply "DEPTNO" (column name) or a constant "Foo bar!!"
    // (or in rare cases a URI, which is handled separately)
    Literal mapObject;

    // template or column or constant
    if (mappingData.isVariable()) {
      Collection<RestrictedExpr> restrictions = varDefs.getDefinitions((Var) mappingData);
      List<PredicateAndObject> mapPredicateAndObjects = processRestrictions(restrictions);

      for (PredicateAndObject result : mapPredicateAndObjects) {

        mapPredicate = result.getPrediacte();
        Statement resultStatement;
        RDFNode rawObject = result.getRawObject();

        // object is literal
        if (rawObject.isLiteral()) {
          mapObject = rawObject.asLiteral();
          resultStatement = r2rml.createStatement(mapSubject, mapPredicate, mapObject);

          // object is blank node
        } else if (rawObject.isAnon()) {
          Resource mapResObject = rawObject.asResource();
          resultStatement = r2rml.createStatement(mapSubject, mapPredicate, mapResObject);

          // object is resource
        } else {
          Resource mapResObject = rawObject.asResource();
          resultStatement = r2rml.createStatement(mapSubject, mapPredicate, mapResObject);
        }

        results.add(resultStatement);
      }

      // everything that is not a variable is handled as a constant
    } else if (mappingData.isConcrete()) {
      // URIs and Literals have to be handled separately since the methods
      // to retrieve the respective value are different

      Statement resultStatement;

      // URI
      if (mappingData.isURI()) {
        /*
         * This case is somewhat special since the mapObject is not a
         * Literal. So, this needs some special handling:
         * - the Literal mapObject will not be used
         * - a special mapObject_uri Resource will be created
         * - the result will be created, appended to the List and
         *   returned to not go through any further ordinary processing
         */

        Resource mapObject_uri = ResourceFactory.createResource(mappingData.getURI());
        mapPredicate = ResourceFactory.createProperty(rrNamespace, "constant");

        resultStatement = r2rml.createStatement(mapSubject, mapPredicate, mapObject_uri);
        results.add(resultStatement);

        return results;

        // Literal
      } else if (mappingData.isLiteral()) {

        mapObject = ResourceFactory.createPlainLiteral(mappingData.getLiteral().toString(false));

        // else (e.g. blank node)
      } else { // mapSubject.isBlank() == true
        /*
         * Hmm... I think this violates the standard. So lean back and
         *  enjoy the trace...
         */

        mapObject = null;
      }

      mapPredicate = ResourceFactory.createProperty(rrPrefix, "constant");

      resultStatement = r2rml.createStatement(mapSubject, mapPredicate, mapObject);
      results.add(resultStatement);
    }

    return results;
  }
  /**
   * Builds up the RDF model "r2ml" representing the R2RML structure of the given Sparqlify-ML
   * definitions. At this point only parts of the Sparqlify-ML view definitions are considered.
   * These are so called patterns representing quads (graph, subject, predicate, object) that can be
   * valid resources or variables with certain restrictions derived from Sparqlify-ML expressions
   * like "uri(concat("http://panlex.org/plx/", ?li))" meaning that the actual value is constructed
   * by creating a URI based on the concatenation of "http://panlex.org/plx/" and the value of the
   * "li" column in the current line of the table and database at hand.
   *
   * @param r2rml the target com.hp.hpl.jena.rdf.model.Model
   * @param pattern a quad that may contain variables in the subject, predicate or object position
   * @param relation the considered database table or constructed logical relation defined by a
   *     query or view
   * @param varDefs the construction definition of the target value based in the actual database
   *     value and some additional data like prefix strings or certain functions like uri( ... )
   */
  private void exportPattern(Model r2rml, Quad pattern, SqlOpBase relation, VarDefinition varDefs) {
    /*
     * Just some hints concerning the variable names: I will give my best to
     * be as consistent as possible obeying the following rules:
     * - there is always a scope of a triple that defines the current
     *   subject predicate and object
     * - since triples can be nested it may be ambiguous what the
     *   current subject, predicate or object is
     * - since triples in R2RML refer to a subject ("rr:subjectMap"),
     *   predicate or object ("predicateObjectMap") things become even
     *   more unclear
     * - I will determine a scope based on the its subject, so if the
     *   subject is "foo", "fooSubject" is the subject in the "foo" scope.
     *   "fooPredicate" is the predicate in the "foo" scope and so on.
     * - since there may be several predicates and objects I will prefix a
     *   hint stating the special use of the considered part of a triple,
     *   so "fooPredicate_bar" is the predicate in the "foo" scope to
     *   define "bar"
     * - statements are named the same way: <scope>Statement_<use>
     */

    // create the triples map subject
    String triplesMapId = String.format("#TriplesMap%d", idCounter++);
    Resource triplesMapSubject = ResourceFactory.createResource(triplesMapId);

    // create logical table triple
    Property triplesMapPredicate_logicalTable =
        ResourceFactory.createProperty(rrNamespace + "logicalTable");

    Statement logicalTblStatement_tblDefinition = buildLogicalTableTriple(r2rml, relation);
    r2rml.add(logicalTblStatement_tblDefinition);

    Statement triplesMapStatement_logicalTable =
        r2rml.createStatement(
            triplesMapSubject,
            triplesMapPredicate_logicalTable,
            logicalTblStatement_tblDefinition.getSubject());
    r2rml.add(triplesMapStatement_logicalTable);

    /*
     * subject map
     */
    Node subjectMapObject_templColOrConst = pattern.getSubject();
    List<Statement> triplesMapStatement_subjectMaps =
        buildMapStatements(r2rml, subjectMapObject_templColOrConst, varDefs);

    // there may be more than one entry, e.g.
    // [] rr:template "http://data.example.com/department/{DEPTNO}" and
    // [] rr:class ex:Department
    for (Statement statement : triplesMapStatement_subjectMaps) {
      r2rml.add(statement);
    }

    // build up the subject map triple that looks sth. like this:
    // <#TriplesMap2> rr:subjectMap []
    if (triplesMapStatement_subjectMaps.size() > 0) {
      // rr:subjectMap
      Property triplesMapPredicate_subjectMap =
          ResourceFactory.createProperty(rrNamespace, "subjectMap");
      // []
      RDFNode triplesMapObject_subjectMap =
          (RDFNode) triplesMapStatement_subjectMaps.get(0).getSubject();
      // <#TriplesMap2> rr:subjectMap []
      Statement subjectMapTriple =
          r2rml.createStatement(
              triplesMapSubject, triplesMapPredicate_subjectMap, triplesMapObject_subjectMap);
      r2rml.add(subjectMapTriple);
    }

    /*
     * predicate map
     */
    Node predicateMap_templColOrConst = pattern.getPredicate();
    List<Statement> prediacteMapStatements =
        buildMapStatements(r2rml, predicateMap_templColOrConst, varDefs);

    // there may be more than one entry, e.g.
    // [] rr:template "http://data.example.com/department/{DEPTNO}" and
    // [] rr:class ex:Department
    for (Statement statement : prediacteMapStatements) {
      r2rml.add(statement);
    }

    /*
     * object map
     */
    Node objectMap_templColOrConst = pattern.getObject();
    List<Statement> objectMapStatements =
        buildMapStatements(r2rml, objectMap_templColOrConst, varDefs);

    // there may be more than one entry, e.g.
    // [] rr:template "http://data.example.com/department/{DEPTNO}" and
    // [] rr:class ex:Department
    for (Statement statement : objectMapStatements) {
      r2rml.add(statement);
    }

    /*
     * predicate object map
     */
    // build the predicate-object map triple that may look like this:
    // <#TriplesMap2> rr:prediacteObjectMap
    //			[ rr:predicateMap
    //					[ rr:constant
    //							ex:name
    //					] ;
    // 			  rr:objectMap
    //					[ rr:column "ENAME"
    //					];
    // 			]

    // [#1]
    Resource triplesMapObject_predicateObjectMap = ResourceFactory.createResource();

    // 1) the statement for [#1] rr:predicateMap [#2]
    Property predicateObjectMapPredicate_predicateMap =
        ResourceFactory.createProperty(rrNamespace, "predicateMap");
    // [#2]
    RDFNode predicateObjectMapObject_predicateMap =
        (RDFNode) prediacteMapStatements.get(0).getSubject();

    Statement predicateObjectMapStatement_predicateMap =
        r2rml.createStatement(
            triplesMapObject_predicateObjectMap,
            predicateObjectMapPredicate_predicateMap,
            predicateObjectMapObject_predicateMap);

    r2rml.add(predicateObjectMapStatement_predicateMap);

    // 2) the statement for [#1] rr:objectMap [#3]
    Property prediacteObjectMapPrediacte_objectMap =
        ResourceFactory.createProperty(rrNamespace, "objectMap");
    // [#3]
    RDFNode prediacteObjectMapObject_objectMap = (RDFNode) objectMapStatements.get(0).getSubject();

    Statement predicateObjectMapStatement_objectMap =
        r2rml.createStatement(
            triplesMapObject_predicateObjectMap,
            prediacteObjectMapPrediacte_objectMap,
            prediacteObjectMapObject_objectMap);

    r2rml.add(predicateObjectMapStatement_objectMap);

    // 3) the statement for <#TriplesMap2> rr:prediacteObjectMap [#1]
    Property triplesMapPredicate_predicateObjectMap =
        ResourceFactory.createProperty(rrNamespace, "predicateObjectMap");

    Statement triplesMapStatement_predicateObjectMap =
        r2rml.createStatement(
            triplesMapSubject,
            triplesMapPredicate_predicateObjectMap,
            triplesMapObject_predicateObjectMap);

    r2rml.add(triplesMapStatement_predicateObjectMap);
  }