if (guessed != null && !guessed.isAnonymous() && ontologyProvider.hasOntology(guessed)) {
rb = Response.status(Status.CONFLICT);
this.submitted = guessed;
if (headers.getAcceptableMediaTypes().contains(MediaType.TEXT_HTML_TYPE)) {
rb.entity(new Viewable("/imports/409", this));
rb.header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_HTML + "; charset=utf-8");
}
break;
} else {
content = new FileInputStream(file);
key = ontologyProvider.loadInStore(content, f, true, keys);
}
} catch (UnsupportedFormatException e) {
log.warn(
"POST method failed for media type {}. This should not happen (should fail earlier)",
headers.getMediaType());
// rb = Response.status(UNSUPPORTED_MEDIA_TYPE);
unsupported++;
} catch (IOException e) {
log.debug(">>> FAILURE format {} (I/O error)", f);
failed++;
} catch (Exception e) { // SAXParseException and others
log.debug(">>> FAILURE format {} (parse error)", f);
failed++;
}
} while ((key == null/* || key.isAnonymous() */) && itf.hasNext());
if ((key == null || key.isAnonymous()) && rb == null) {
if (failed > 0) {
throw new WebApplicationException(BAD_REQUEST);
} else if (unsupported > 0) {
throw new WebApplicationException(UNSUPPORTED_MEDIA_TYPE);
}
}
} else if (location != null) {
try { // Here we try every format supported by the Java API
key = ontologyProvider.loadInStore(location, null, true, keys);
} catch (Exception e) {
log.error("Failed to load ontology from " + location, e);
throw new WebApplicationException(e, BAD_REQUEST);
}
} else if (!aliases.isEmpty()) // No content but there are aliases.
{
for (Origin<?> origin : keys) {
if (origin.getReference() instanceof OWLOntologyID) {
OWLOntologyID primary = ((OWLOntologyID) origin.getReference());
if (ontologyProvider.getStatus(primary) != org.apache.stanbol.ontologymanager.servicesapi.ontology.OntologyProvider.Status.NO_MATCH) {
for (OWLOntologyID alias : aliases) {
try {
if (ontologyProvider.addAlias(primary, alias) && key == null) {
key = alias;
}
} catch (IllegalArgumentException ex) {
log.warn("Cannot add alias");
log.warn(" ... ontology key: {}", primary);
log.warn(" ... alias: {}", alias);
log.warn(" ... reason: ", ex);
continue;
}
}
}
}
}
} else {
log.error("Bad request");
log.error(" file is: {}", file);
throw new WebApplicationException(BAD_REQUEST);
}
if (key != null && !key.isAnonymous()) {
String uri = OntologyUtils.encode(key);
if (uri != null && !uri.isEmpty()) {
rb = Response.ok();
if (headers.getAcceptableMediaTypes().contains(MediaType.TEXT_HTML_TYPE)) {
rb.entity(new Viewable("index", this));
rb.header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_HTML + "; charset=utf-8");
}
} else {
rb = Response.ok();
}