package de.linkvt.bachelor.config;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLMutableOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.web.context.WebApplicationContext;

import javax.servlet.http.HttpServletRequest;

/**
 * Creates beans for OWL API classes.
 */
@Configuration
public class OwlApiConfig {

  @Bean
  public OWLDataFactory dataFactory() {
    return OWLManager.getOWLDataFactory();
  }

  @Bean
  @Scope(value = WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.INTERFACES)
  public OWLMutableOntology owlOntology(HttpServletRequest request) throws OWLOntologyCreationException {
    OWLOntologyManager ontologyManager = OWLManager.createOWLOntologyManager();
    // Cast to a mutable ontology to pass OWLApi's strange checks
    return (OWLMutableOntology) ontologyManager.createOntology(IRI.create(createOntologyUrl(request)));
  }

  private String createOntologyUrl(HttpServletRequest request) {
    String url = request.getRequestURL().toString();
    // trim the extension
    url = FilenameUtils.removeExtension(url);

    String queryString = request.getQueryString();
    if (StringUtils.isNotEmpty(queryString)) {
      url = url + "?" + queryString;
    }

    return url;
  }
}

@@ -33,97 +33,8 @@
 g;%0A%0A
-import org.apache.commons.io.FilenameUtils;%0Aimport org.apache.commons.lang3.StringUtils;%0A
 impo
@@ -1310,394 +1310,49 @@
 ate(
-createOntologyUrl(request)));%0A  %7D%0A%0A  private String createOntologyUrl(HttpServletRequest request) %7B%0A    String url = request.getRequestURL().toString();%0A    // trim the extension%0A    url = FilenameUtils.removeExtension(url);%0A%0A    String queryString = request.getQueryString();%0A    if (StringUtils.isNotEmpty(queryString)) %7B%0A      url = url + %22?%22 + queryString;%0A    %7D%0A%0A    return url;%0A  %7D
+request.getRequestURL().toString()));%0A  %7D%0A
 %0A%7D%0A

Trim query string from ontology iri