Search in sources :

Example 16 with ProjectId

use of edu.stanford.bmir.protege.web.shared.project.ProjectId in project webprotege by protegeproject.

the class ProjectDocumentStore method loadProjectOntologiesIntoManager.

private OWLOntology loadProjectOntologiesIntoManager(OWLOntologyManager manager) throws OWLOntologyCreationException {
    logger.info("{} Loading project", projectId);
    long t0 = System.currentTimeMillis();
    OWLOntologyLoaderListener loaderListener = new OWLOntologyLoaderListener() {

        public void startedLoadingOntology(LoadingStartedEvent event) {
            logger.info("{} Ontology loading started: {}", projectId, event.getDocumentIRI());
        }

        public void finishedLoadingOntology(LoadingFinishedEvent event) {
            // Give something else a chance - in case we have LOTS of imports
            Thread.yield();
            if (event.isSuccessful()) {
                logger.info("{} Ontology loading finished: (Loaded:  {})", projectId, event.getDocumentIRI(), event.getOntologyID());
                MemoryMonitor memoryMonitor = new MemoryMonitor(logger);
                memoryMonitor.monitorMemoryUsage();
            } else {
                logger.info("Ontology loading failed: {} (Reason: )", projectId, event.getException().getMessage());
            }
        }
    };
    manager.addOntologyLoaderListener(loaderListener);
    final MissingImportListener missingImportListener = (MissingImportListener) missingImportEvent -> logger.info("{} Missing import: {} due to {}", projectId, missingImportEvent.getImportedOntologyURI(), missingImportEvent.getCreationException().getMessage());
    manager.addMissingImportListener(missingImportListener);
    manager.getIRIMappers().add((OWLOntologyIRIMapper) iri -> {
        logger.info("{} Fetching imported ontology from {}.", projectId, iri.toQuotedString());
        return iri;
    });
    // Important - add last
    ImportsCacheManager importsCacheManager = importsCacheManagerProvider.get();
    OWLOntologyIRIMapper iriMapper = importsCacheManager.getIRIMapper();
    manager.getIRIMappers().add(iriMapper);
    try {
        OWLOntologyLoaderConfiguration config = new OWLOntologyLoaderConfiguration();
        config = config.setMissingImportHandlingStrategy(MissingImportHandlingStrategy.SILENT);
        config = config.setReportStackTraces(true);
        // It is safe to turn of illegal punning fixing as we've already parsed (and saved) the ontology
        // using a manager with this turned on.
        config = config.setRepairIllegalPunnings(false);
        logger.info("{} Loading root ontology imports closure.", projectId);
        ProjectInputSource projectInputSource = new ProjectInputSource(rootOntologyDocument);
        OWLOntology rootOntology = manager.loadOntologyFromOntologyDocument(projectInputSource, config);
        importsCacheManager.cacheImports(rootOntology);
        return rootOntology;
    } finally {
        long t1 = System.currentTimeMillis();
        logger.info("{} Ontology loading completed in {} ms.", projectId, (t1 - t0));
        MemoryMonitor memoryMonitor = new MemoryMonitor(logger);
        memoryMonitor.monitorMemoryUsage();
        memoryMonitor.logMemoryUsage();
        manager.removeIRIMapper(iriMapper);
        manager.removeOntologyLoaderListener(loaderListener);
        manager.removeMissingImportListener(missingImportListener);
    }
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) IdUtil(edu.stanford.bmir.protege.web.server.util.IdUtil) Provider(javax.inject.Provider) ListMultimap(com.google.common.collect.ListMultimap) org.semanticweb.owlapi.model(org.semanticweb.owlapi.model) BinaryOWLOntologyDocumentFormat(org.semanticweb.binaryowl.owlapi.BinaryOWLOntologyDocumentFormat) LoggerFactory(org.slf4j.LoggerFactory) BinaryOWLOntologyDocumentSerializer(org.semanticweb.binaryowl.BinaryOWLOntologyDocumentSerializer) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) MemoryMonitor(edu.stanford.bmir.protege.web.server.util.MemoryMonitor) BinaryOWLMetadata(org.semanticweb.binaryowl.BinaryOWLMetadata) OntologyChangeDataList(org.semanticweb.binaryowl.change.OntologyChangeDataList) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ProjectSingleton(edu.stanford.bmir.protege.web.shared.inject.ProjectSingleton) OWLOntologyDocumentSource(org.semanticweb.owlapi.io.OWLOntologyDocumentSource) SimpleIRIMapper(org.semanticweb.owlapi.util.SimpleIRIMapper) Logger(org.slf4j.Logger) RootOntologyDocument(edu.stanford.bmir.protege.web.server.inject.project.RootOntologyDocument) OWLOntologyChangeRecord(org.semanticweb.owlapi.change.OWLOntologyChangeRecord) OWLOntologyChangeData(org.semanticweb.owlapi.change.OWLOntologyChangeData) List(java.util.List) Lock(java.util.concurrent.locks.Lock) java.io(java.io) FileDocumentSource(org.semanticweb.owlapi.io.FileDocumentSource) StreamDocumentSource(org.semanticweb.owlapi.io.StreamDocumentSource) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) OWLOntologyCreationIOException(org.semanticweb.owlapi.io.OWLOntologyCreationIOException) MemoryMonitor(edu.stanford.bmir.protege.web.server.util.MemoryMonitor)

Example 17 with ProjectId

use of edu.stanford.bmir.protege.web.shared.project.ProjectId in project webprotege by protegeproject.

the class ProjectCache method getProject.

public ProjectId getProject(NewProjectSettings newProjectSettings) throws ProjectAlreadyExistsException, OWLOntologyCreationException, OWLOntologyStorageException, IOException {
    ProjectId projectId = ProjectIdFactory.getFreshProjectId();
    if (newProjectSettings.hasSourceDocument()) {
        ProjectImporter importer = projectImporterFactory.getProjectImporter(projectId);
        importer.createProjectFromSources(newProjectSettings.getSourceDocumentId(), newProjectSettings.getProjectOwner());
    }
    return getProjectInternal(projectId, AccessMode.NORMAL).getProjectId();
}
Also used : ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId)

Example 18 with ProjectId

use of edu.stanford.bmir.protege.web.shared.project.ProjectId in project webprotege by protegeproject.

the class ProjectCache method purgeDormantProjects.

private void purgeDormantProjects() {
    // No locking needed
    for (ProjectId projectId : getCachedProjectIds()) {
        long time = getLastAccessTime(projectId);
        long lastAccessTimeDiff = System.currentTimeMillis() - time;
        if (time == 0 || lastAccessTimeDiff > DORMANT_PROJECT_TIME_MS) {
            purge(projectId);
        }
    }
}
Also used : ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId)

Example 19 with ProjectId

use of edu.stanford.bmir.protege.web.shared.project.ProjectId in project webprotege by protegeproject.

the class CreateNewProjectActionHandler method execute.

@Nonnull
@Override
public CreateNewProjectResult execute(@Nonnull CreateNewProjectAction action, @Nonnull ExecutionContext executionContext) {
    try {
        UserId userId = executionContext.getUserId();
        if (!accessManager.hasPermission(forUser(userId), ApplicationResource.get(), CREATE_EMPTY_PROJECT)) {
            throw new PermissionDeniedException("You do not have permission to create new projects", userInSessionFactory.getUserInSession(userId));
        }
        NewProjectSettings newProjectSettings = action.getNewProjectSettings();
        if (newProjectSettings.hasSourceDocument()) {
            if (!accessManager.hasPermission(forUser(userId), ApplicationResource.get(), UPLOAD_PROJECT)) {
                throw new PermissionDeniedException("You do not have permission to upload projects", userInSessionFactory.getUserInSession(userId));
            }
        }
        ProjectId projectId = pm.createNewProject(newProjectSettings);
        if (!projectDetailsManager.isExistingProject(projectId)) {
            projectDetailsManager.registerProject(projectId, newProjectSettings);
            applyDefaultPermissions(projectId, userId);
        }
        return new CreateNewProjectResult(projectDetailsManager.getProjectDetails(projectId));
    } catch (OWLOntologyCreationException | OWLOntologyStorageException | IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) NewProjectSettings(edu.stanford.bmir.protege.web.shared.project.NewProjectSettings) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) PermissionDeniedException(edu.stanford.bmir.protege.web.shared.permissions.PermissionDeniedException) CreateNewProjectResult(edu.stanford.bmir.protege.web.shared.project.CreateNewProjectResult) IOException(java.io.IOException) OWLOntologyStorageException(org.semanticweb.owlapi.model.OWLOntologyStorageException) Nonnull(javax.annotation.Nonnull)

Example 20 with ProjectId

use of edu.stanford.bmir.protege.web.shared.project.ProjectId in project webprotege by protegeproject.

the class GetProjectPrefixDeclarationsActionHandler method execute.

@Nonnull
@Override
public GetProjectPrefixDeclarationsResult execute(@Nonnull GetProjectPrefixDeclarationsAction action, @Nonnull ExecutionContext executionContext) {
    ProjectId projectId = action.getProjectId();
    List<PrefixDeclaration> decls = store.find(projectId).getPrefixes().entrySet().stream().map(entry -> PrefixDeclaration.get(entry.getKey(), entry.getValue())).collect(toList());
    return new GetProjectPrefixDeclarationsResult(projectId, decls);
}
Also used : GetProjectPrefixDeclarationsAction(edu.stanford.bmir.protege.web.shared.project.GetProjectPrefixDeclarationsAction) PrefixDeclaration(edu.stanford.bmir.protege.web.shared.project.PrefixDeclaration) BuiltInAction(edu.stanford.bmir.protege.web.shared.access.BuiltInAction) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Inject(javax.inject.Inject) AbstractProjectActionHandler(edu.stanford.bmir.protege.web.server.dispatch.AbstractProjectActionHandler) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) AccessManager(edu.stanford.bmir.protege.web.server.access.AccessManager) ExecutionContext(edu.stanford.bmir.protege.web.server.dispatch.ExecutionContext) GetProjectPrefixDeclarationsResult(edu.stanford.bmir.protege.web.shared.project.GetProjectPrefixDeclarationsResult) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) GetProjectPrefixDeclarationsResult(edu.stanford.bmir.protege.web.shared.project.GetProjectPrefixDeclarationsResult) PrefixDeclaration(edu.stanford.bmir.protege.web.shared.project.PrefixDeclaration) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) Nonnull(javax.annotation.Nonnull)

Aggregations

ProjectId (edu.stanford.bmir.protege.web.shared.project.ProjectId)51 Nonnull (javax.annotation.Nonnull)19 UserId (edu.stanford.bmir.protege.web.shared.user.UserId)16 Inject (javax.inject.Inject)14 AccessManager (edu.stanford.bmir.protege.web.server.access.AccessManager)8 java.util (java.util)7 HasProjectId (edu.stanford.bmir.protege.web.shared.project.HasProjectId)6 Collectors.toList (java.util.stream.Collectors.toList)6 Nullable (javax.annotation.Nullable)6 Test (org.junit.Test)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)5 ExecutionContext (edu.stanford.bmir.protege.web.server.dispatch.ExecutionContext)5 Optional (java.util.Optional)5 OWLEntity (org.semanticweb.owlapi.model.OWLEntity)5 Subject.forUser (edu.stanford.bmir.protege.web.server.access.Subject.forUser)4 ProjectDetails (edu.stanford.bmir.protege.web.shared.project.ProjectDetails)4 List (java.util.List)4 ImmutableSet (com.google.common.collect.ImmutableSet)3