Search in sources :

Example 1 with SPARQLRepositoryConfig

use of org.eclipse.rdf4j.repository.sparql.config.SPARQLRepositoryConfig in project inception by inception-project.

the class KnowledgeBaseServiceImpl method getConnection.

@Override
public RepositoryConnection getConnection(KnowledgeBase kb) {
    assertRegistration(kb);
    Repository repo = repoManager.getRepository(kb.getRepositoryId());
    if (repo instanceof SPARQLRepository) {
        SPARQLRepositoryConfig sparqlRepoConfig = (SPARQLRepositoryConfig) getKnowledgeBaseConfig(kb);
        URI uri = URI.create(sparqlRepoConfig.getQueryEndpointUrl());
        String userInfo = uri.getUserInfo();
        if (StringUtils.isNotBlank(userInfo)) {
            userInfo = userInfo.trim();
            String username;
            String password;
            if (userInfo.contains(":")) {
                username = substringBefore(userInfo, ":");
                password = substringAfter(userInfo, ":");
            } else {
                username = userInfo;
                password = "";
            }
            SPARQLRepository sparqlRepo = (SPARQLRepository) repo;
            sparqlRepo.setUsernameAndPassword(username, password);
        }
    }
    return new RepositoryConnectionWrapper(repo, repo.getConnection()) {

        {
            skipCertificateChecks(kb.isSkipSslValidation());
        }

        @Override
        public void close() throws RepositoryException {
            try {
                super.close();
            } finally {
                restoreSslVerification();
            }
        }
    };
}
Also used : SPARQLRepositoryConfig(org.eclipse.rdf4j.repository.sparql.config.SPARQLRepositoryConfig) SailRepository(org.eclipse.rdf4j.repository.sail.SailRepository) SPARQLRepository(org.eclipse.rdf4j.repository.sparql.SPARQLRepository) Repository(org.eclipse.rdf4j.repository.Repository) SPARQLRepository(org.eclipse.rdf4j.repository.sparql.SPARQLRepository) RepositoryConnectionWrapper(org.eclipse.rdf4j.repository.base.RepositoryConnectionWrapper) URI(java.net.URI)

Example 2 with SPARQLRepositoryConfig

use of org.eclipse.rdf4j.repository.sparql.config.SPARQLRepositoryConfig in project inception by inception-project.

the class KnowledgeBaseExporterTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    initMocks(this);
    sourceProject = new Project();
    sourceProject.setId(1l);
    sourceProject.setName("Test Project");
    targetProject = new Project();
    sourceProject.setId(2l);
    targetProject.setName("Test Project");
    when(kbService.getKnowledgeBases(sourceProject)).thenReturn(knowledgeBases());
    when(kbService.getKnowledgeBaseConfig(any())).thenReturn(new SPARQLRepositoryConfig(TestURLEndpoint));
    when(schemaService.listAnnotationFeature(sourceProject)).thenReturn(features(sourceProject));
    sut = new KnowledgeBaseExporter(kbService, new KnowledgeBasePropertiesImpl(), schemaService);
}
Also used : SPARQLRepositoryConfig(org.eclipse.rdf4j.repository.sparql.config.SPARQLRepositoryConfig) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) ExportedProject(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedProject) KnowledgeBaseExporter(de.tudarmstadt.ukp.inception.kb.exporter.KnowledgeBaseExporter) KnowledgeBasePropertiesImpl(de.tudarmstadt.ukp.inception.kb.config.KnowledgeBasePropertiesImpl) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with SPARQLRepositoryConfig

use of org.eclipse.rdf4j.repository.sparql.config.SPARQLRepositoryConfig in project inception by inception-project.

the class KnowledgeBaseExporter method exportData.

@Override
public void exportData(FullProjectExportRequest aRequest, ProjectExportTaskMonitor aMonitor, ExportedProject aExProject, File aFile) throws Exception {
    Project project = aRequest.getProject();
    List<ExportedKnowledgeBase> exportedKnowledgeBases = new ArrayList<>();
    for (KnowledgeBase kb : kbService.getKnowledgeBases(project)) {
        // check if the export has been cancelled
        if (Thread.interrupted()) {
            throw new InterruptedException();
        }
        ExportedKnowledgeBase exportedKB = new ExportedKnowledgeBase();
        exportedKB.setId(kb.getRepositoryId());
        exportedKB.setName(kb.getName());
        exportedKB.setType(kb.getType().toString());
        exportedKB.setClassIri(kb.getClassIri());
        exportedKB.setSubclassIri(kb.getSubclassIri());
        exportedKB.setTypeIri(kb.getTypeIri());
        exportedKB.setDescriptionIri(kb.getDescriptionIri());
        exportedKB.setLabelIri(kb.getLabelIri());
        exportedKB.setPropertyTypeIri(kb.getPropertyTypeIri());
        exportedKB.setPropertyLabelIri(kb.getPropertyLabelIri());
        exportedKB.setPropertyDescriptionIri(kb.getPropertyDescriptionIri());
        exportedKB.setFullTextSearchIri(kb.getFullTextSearchIri());
        exportedKB.setReadOnly(kb.isReadOnly());
        exportedKB.setEnabled(kb.isEnabled());
        exportedKB.setReification(kb.getReification().toString());
        exportedKB.setSupportConceptLinking(kb.isSupportConceptLinking());
        exportedKB.setBasePrefix(kb.getBasePrefix());
        exportedKB.setRootConcepts(new ArrayList<>(kb.getRootConcepts()));
        exportedKB.setAdditionalMatchingProperties(new ArrayList<>(kb.getAdditionalMatchingProperties()));
        exportedKB.setDefaultLanguage(kb.getDefaultLanguage());
        exportedKB.setDefaultDatasetIri(kb.getDefaultDatasetIri() != null ? kb.getDefaultDatasetIri() : null);
        exportedKB.setMaxResults(kb.getMaxResults());
        exportedKB.setSubPropertyIri(kb.getSubPropertyIri());
        exportedKnowledgeBases.add(exportedKB);
        if (kb.getType() == RepositoryType.REMOTE) {
            // set url for remote KB
            RepositoryImplConfig cfg = kbService.getKnowledgeBaseConfig(kb);
            String url = ((SPARQLRepositoryConfig) cfg).getQueryEndpointUrl();
            exportedKB.setRemoteURL(url);
        } else {
            // export local kb files
            exportKnowledgeBaseFiles(aFile, kb);
        }
    }
    aExProject.setProperty(KEY, exportedKnowledgeBases);
    int n = exportedKnowledgeBases.size();
    LOG.info("Exported [{}] knowledge bases for project [{}]", n, project.getName());
}
Also used : SPARQLRepositoryConfig(org.eclipse.rdf4j.repository.sparql.config.SPARQLRepositoryConfig) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) ExportedProject(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedProject) RepositoryImplConfig(org.eclipse.rdf4j.repository.config.RepositoryImplConfig) KnowledgeBase(de.tudarmstadt.ukp.inception.kb.model.KnowledgeBase) ArrayList(java.util.ArrayList)

Aggregations

SPARQLRepositoryConfig (org.eclipse.rdf4j.repository.sparql.config.SPARQLRepositoryConfig)3 ExportedProject (de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedProject)2 Project (de.tudarmstadt.ukp.clarin.webanno.model.Project)2 KnowledgeBasePropertiesImpl (de.tudarmstadt.ukp.inception.kb.config.KnowledgeBasePropertiesImpl)1 KnowledgeBaseExporter (de.tudarmstadt.ukp.inception.kb.exporter.KnowledgeBaseExporter)1 KnowledgeBase (de.tudarmstadt.ukp.inception.kb.model.KnowledgeBase)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Repository (org.eclipse.rdf4j.repository.Repository)1 RepositoryConnectionWrapper (org.eclipse.rdf4j.repository.base.RepositoryConnectionWrapper)1 RepositoryImplConfig (org.eclipse.rdf4j.repository.config.RepositoryImplConfig)1 SailRepository (org.eclipse.rdf4j.repository.sail.SailRepository)1 SPARQLRepository (org.eclipse.rdf4j.repository.sparql.SPARQLRepository)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1