Esempio n. 1
0
 public static String getAcceptPostHeader(String extraFormats) {
   final Collection<RDFFormat> rdfFormats =
       filterAvailableParsers(LdpService.SERVER_PREFERED_RDF_FORMATS);
   final StringBuilder sb = new StringBuilder();
   for (RDFFormat rdfFormat : rdfFormats) {
     sb.append(rdfFormat.getDefaultMIMEType());
     sb.append(", ");
   }
   if (StringUtils.isNotBlank(extraFormats)) {
     sb.append(extraFormats);
   } else {
     sb.delete(sb.length() - 2, sb.length());
   }
   return sb.toString();
 }
Esempio n. 2
0
 /**
  * Import data from URI source Request is made with proper HTTP ACCEPT header and will follow
  * redirects for proper LOD source negotiation
  *
  * @param urlstring absolute URI of the data source
  * @param format RDF format to request/parse from data source
  */
 public void addURI(String urlstring, RDFFormat format) {
   try {
     RepositoryConnection con = currentRepository.getConnection();
     try {
       URL url = new URL(urlstring);
       URLConnection uricon = (URLConnection) url.openConnection();
       uricon.addRequestProperty("accept", format.getDefaultMIMEType());
       InputStream instream = uricon.getInputStream();
       con.add(instream, urlstring, format);
     } finally {
       con.close();
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
  @Test
  public void testPostRdfBasic() throws Exception {
    // prepare: add an artifact
    final InferredOWLOntologyID testArtifact =
        this.loadTestArtifact(
            TestConstants.TEST_ARTIFACT_20130206, MediaType.APPLICATION_RDF_TURTLE);

    final ClientResource searchClientResource =
        new ClientResource(this.getUrl(PoddWebConstants.PATH_SEARCH));
    try {
      searchClientResource.addQueryParameter(
          PoddWebConstants.KEY_ARTIFACT_IDENTIFIER, testArtifact.getOntologyIRI().toString());

      // prepare: the test input
      final String[] objectUris = {
        "http://purl.org/podd/basic-1-20130206/object:2966",
        "http://purl.org/podd/basic-2-20130206/artifact:1#Demo-Genotype",
        "http://purl.org/podd/basic-2-20130206/artifact:1#SqueekeeMaterial",
        "http://purl.org/podd/ns/poddScience#WildType_NotApplicable",
        "http://purl.org/podd/ns/poddPlant#DeltaTporometer-63",
        "http://purl.org/podd/ns/poddBase#DisplayType_LongText"
      };

      final String[] expectedLabels = {
        "Project#2012-0006_ Cotton Leaf Morphology",
        "Demo genotype",
        "Squeekee material",
        "Not Applicable",
        "Delta-T porometer",
        null
      };

      final Model testModel = new LinkedHashModel();
      for (final String s : objectUris) {
        testModel.add(PODD.VF.createURI(s), RDFS.LABEL, PODD.VF.createLiteral("?blank"));
      }

      final RDFFormat inputFormat = RDFFormat.RDFXML;
      final MediaType inputMediaType = MediaType.valueOf(inputFormat.getDefaultMIMEType());

      // build input representation
      final ByteArrayOutputStream output = new ByteArrayOutputStream(8096);
      Rio.write(testModel, output, inputFormat);
      final Representation input = new StringRepresentation(output.toString(), inputMediaType);

      // invoke service
      final Representation results =
          this.doTestAuthenticatedRequest(
              searchClientResource,
              Method.POST,
              input,
              inputMediaType,
              Status.SUCCESS_OK,
              AbstractResourceImplTest.WITH_ADMIN);

      // verify: response
      final Model resultModel = this.assertRdf(results, RDFFormat.RDFXML, 5);

      // verify: each URI has the expected label
      for (int i = 0; i < objectUris.length; i++) {
        final String objectString =
            resultModel.filter(PODD.VF.createURI(objectUris[i]), RDFS.LABEL, null).objectString();
        Assert.assertEquals("Not the expected label", expectedLabels[i], objectString);
      }
    } finally {
      this.releaseClient(searchClientResource);
    }
  }