Search in sources :

Example 31 with OWLEntity

use of org.semanticweb.owlapi.model.OWLEntity in project webprotege by protegeproject.

the class EntityDiscussionThreadRepository_IT method shouldReplaceEntity.

@Test
public void shouldReplaceEntity() {
    OWLEntity theReplacement = MockingUtils.mockOWLClass();
    repository.replaceEntity(projectId, entity, theReplacement);
    List<EntityDiscussionThread> threads = repository.findThreads(projectId, theReplacement);
    assertThat(threads.size(), is(1));
}
Also used : OWLEntity(org.semanticweb.owlapi.model.OWLEntity) Test(org.junit.Test)

Example 32 with OWLEntity

use of org.semanticweb.owlapi.model.OWLEntity in project webprotege by protegeproject.

the class OWLEntityReadConverter_TestCase method shouldReadOWLNamedIndividual.

@Test
public void shouldReadOWLNamedIndividual() {
    when(dbObject.get("type")).thenReturn(EntityType.NAMED_INDIVIDUAL.getName());
    OWLEntity entity = converter.convert(dbObject);
    assertThat(entity.isOWLNamedIndividual(), is(true));
    assertThat(entity.getIRI(), is(iri));
}
Also used : OWLEntity(org.semanticweb.owlapi.model.OWLEntity) Test(org.junit.Test)

Example 33 with OWLEntity

use of org.semanticweb.owlapi.model.OWLEntity in project webprotege by protegeproject.

the class TagsManager method setProjectTags.

/**
 * Sets the tags for the project that this manager is associated with.
 */
public void setProjectTags(@Nonnull Collection<TagData> newProjectTags) {
    checkNotNull(newProjectTags);
    Collection<Tag> currentProjectTags = getProjectTags();
    Set<OWLEntity> modifiedEntityTags = new HashSet<>();
    try {
        writeLock.lock();
        projectTags = null;
        Set<TagId> tagIds = newProjectTags.stream().map(TagData::getTagId).filter(Optional::isPresent).map(Optional::get).collect(toSet());
        // Remove current tags
        currentProjectTags.stream().map(Tag::getTagId).peek(tagId -> {
            if (!tagIds.contains(tagId)) {
                // Record modified entity tags
                entityTagsRepository.findByTagId(tagId).stream().map(EntityTags::getEntity).forEach(modifiedEntityTags::add);
                // Remove tag from entity
                entityTagsRepository.removeTag(projectId, tagId);
            }
        }).forEach(tagRepository::deleteTag);
        // Set fresh tags
        List<Tag> tags = newProjectTags.stream().map(tagData -> new Tag(tagData.getTagId().orElse(createTagId()), projectId, tagData.getLabel(), tagData.getDescription(), tagData.getColor(), tagData.getBackgroundColor())).peek(tag -> {
            // Find the modified entities for this tag
            entityTagsRepository.findByTagId(tag.getTagId()).stream().map(EntityTags::getEntity).forEach(modifiedEntityTags::add);
        }).collect(toList());
        tagRepository.saveTags(tags);
    } finally {
        writeLock.unlock();
    }
    Set<Tag> oldProjectTags = new HashSet<>(currentProjectTags);
    Set<Tag> projectTags = new HashSet<>(getProjectTags());
    if (!oldProjectTags.equals(projectTags)) {
        List<ProjectEvent<?>> events = new ArrayList<>();
        for (OWLEntity entity : modifiedEntityTags) {
            EntityTagsChangedEvent event = new EntityTagsChangedEvent(projectId, entity, getTags(entity));
            events.add(event);
        }
        events.add(new ProjectTagsChangedEvent(projectId, projectTags));
        eventBus.postEvents(events);
    }
}
Also used : java.util(java.util) ProjectEvent(edu.stanford.bmir.protege.web.shared.event.ProjectEvent) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) TagId.createTagId(edu.stanford.bmir.protege.web.shared.tag.TagId.createTagId) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Multimap(com.google.common.collect.Multimap) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) HasPostEvents(edu.stanford.bmir.protege.web.server.events.HasPostEvents) edu.stanford.bmir.protege.web.shared.tag(edu.stanford.bmir.protege.web.shared.tag) Lock(java.util.concurrent.locks.Lock) HashMultimap(com.google.common.collect.HashMultimap) OWLEntity(org.semanticweb.owlapi.model.OWLEntity) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ProjectSingleton(edu.stanford.bmir.protege.web.shared.inject.ProjectSingleton) OWLEntity(org.semanticweb.owlapi.model.OWLEntity) TagId.createTagId(edu.stanford.bmir.protege.web.shared.tag.TagId.createTagId) ProjectEvent(edu.stanford.bmir.protege.web.shared.event.ProjectEvent)

Example 34 with OWLEntity

use of org.semanticweb.owlapi.model.OWLEntity in project webprotege by protegeproject.

the class GetEntityTagsActionHandler method execute.

@Nonnull
@Override
public GetEntityTagsResult execute(@Nonnull GetEntityTagsAction action, @Nonnull ExecutionContext executionContext) {
    ProjectId projectId = action.getProjectId();
    OWLEntity entity = action.getEntity();
    return new GetEntityTagsResult(tagsManager.getTags(entity), tagsManager.getProjectTags());
}
Also used : OWLEntity(org.semanticweb.owlapi.model.OWLEntity) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) GetEntityTagsResult(edu.stanford.bmir.protege.web.shared.tag.GetEntityTagsResult) Nonnull(javax.annotation.Nonnull)

Example 35 with OWLEntity

use of org.semanticweb.owlapi.model.OWLEntity in project webprotege by protegeproject.

the class CSVImportViewImpl method getImportDescriptor.

@Override
public Optional<CSVImportDescriptor> getImportDescriptor() {
    List<CSVColumnDescriptor> columnDescriptors = new ArrayList<CSVColumnDescriptor>();
    for (int rowIndex = 0; rowIndex < flexTable.getRowCount(); rowIndex++) {
        CSVColumnRelationEditorViewImpl relView = (CSVColumnRelationEditorViewImpl) flexTable.getWidget(rowIndex, 1);
        if (!relView.getProperty().isPresent()) {
            continue;
        }
        if (!relView.getColumnType().isPresent()) {
            continue;
        }
        final OWLEntity columnProperty = (OWLEntity) relView.getProperty().get().getObject();
        final ColumnType columnType = relView.getColumnType().get();
        CSVColumnDescriptor csvColumnDescriptor = CSVColumnDescriptor.create(rowIndex, columnProperty, columnType);
        columnDescriptors.add(csvColumnDescriptor);
    }
    return Optional.of(new CSVImportDescriptor(CSVRowImportType.values()[importTypeField.getSelectedIndex()], displayNameField.getSelectedIndex(), columnDescriptors));
}
Also used : OWLEntity(org.semanticweb.owlapi.model.OWLEntity) ArrayList(java.util.ArrayList)

Aggregations

OWLEntity (org.semanticweb.owlapi.model.OWLEntity)45 Test (org.junit.Test)13 OWLOntologyChange (org.semanticweb.owlapi.model.OWLOntologyChange)7 OWLEntityData (edu.stanford.bmir.protege.web.shared.entity.OWLEntityData)6 ArrayList (java.util.ArrayList)6 Nonnull (javax.annotation.Nonnull)6 Inject (javax.inject.Inject)6 UserId (edu.stanford.bmir.protege.web.shared.user.UserId)5 ProjectId (edu.stanford.bmir.protege.web.shared.project.ProjectId)4 AccessManager (edu.stanford.bmir.protege.web.server.access.AccessManager)3 IRI (org.semanticweb.owlapi.model.IRI)3 DBObject (com.mongodb.DBObject)2 EntitySuggestion (edu.stanford.bmir.protege.web.client.library.suggest.EntitySuggestion)2 AbstractProjectActionHandler (edu.stanford.bmir.protege.web.server.dispatch.AbstractProjectActionHandler)2 ExecutionContext (edu.stanford.bmir.protege.web.server.dispatch.ExecutionContext)2 VIEW_PROJECT (edu.stanford.bmir.protege.web.shared.access.BuiltInAction.VIEW_PROJECT)2 ColumnType (edu.stanford.bmir.protege.web.shared.csv.ColumnType)2 OWLPrimitiveData (edu.stanford.bmir.protege.web.shared.entity.OWLPrimitiveData)2 ProjectEvent (edu.stanford.bmir.protege.web.shared.event.ProjectEvent)2 Comparator.comparing (java.util.Comparator.comparing)2