コード例 #1
0
  @Override
  public void transform(Repository repository, URI graph, TransformContext context)
      throws TransformException {
    String catalogUrl = odsUrl + "id/catalog/" + catalogIdentifier + '/';
    context.getCustomData().put("dcatTransformerGraph", catalogUrl);
    Collection<String> warnings = context.getWarnings();
    URI catalogUri = valueFactory.createURI(catalogUrl);
    Value rawGraph = getRawGraph(repository, graph);
    if (rawGraph == null) {
      warnings.add("no catalog found");
      throw new TransformException("no catalog found in raw data");
    }

    try {
      RepositoryConnection connection = repository.getConnection();
      try {
        connection.add(
            valueFactory.createStatement(catalogUri, rawCatalogPredicate, rawGraph), graph);
        connection.add(
            valueFactory.createStatement(
                catalogUri, LODMSPredicates.RDFTYPE, LODMSPredicates.DCAT_CATALOG),
            graph);
        copyCatalogAttributes(graph, catalogUri, rawGraph, connection);
        extractDatasetInfo(graph, catalogUri, rawGraph, connection);
      } catch (RepositoryException e) {
        warnings.add(e.getMessage());
        throw new TransformException(e.getMessage(), e);
      } catch (MalformedQueryException e) {
        warnings.add(e.getMessage());
        throw new TransformException(e.getMessage(), e);
      } catch (UpdateExecutionException e) {
        warnings.add(e.getMessage());
        throw new TransformException(e.getMessage(), e);
      } finally {
        connection.close();
      }
    } catch (Exception e) {
      throw new TransformException(e.getMessage(), e);
    }
  }
コード例 #2
0
  @Override
  public IResultSet<Value, URI, Literal> selectQuery(String query, String graph) {
    connect();

    final SPARQLParser parser = new SPARQLParser();

    CloseableIteration<? extends BindingSet, QueryEvaluationException> sparqlResults = null;
    ParsedQuery parsedQuery = null;

    try {
      parsedQuery = parser.parseQuery(query, null);
    } catch (MalformedQueryException e) {
      e.printStackTrace();
    }
    try {
      sparqlResults =
          connection.evaluate(
              parsedQuery.getTupleExpr(), parsedQuery.getDataset(), new EmptyBindingSet(), false);
    } catch (SailException e) {
      e.printStackTrace();
    }

    return new SailResultSet(sparqlResults);
  }