Search in sources :

Example 6 with RepositoryContext

use of com.b2international.snowowl.core.domain.RepositoryContext in project snow-owl by b2ihealthcare.

the class CommitInfoRequestTest method getCommitInfoByComment.

private CommitInfo getCommitInfoByComment(final String comment) {
    Request<RepositoryContext, CommitInfos> req = RepositoryRequests.commitInfos().prepareSearchCommitInfo().filterByComment(comment).build();
    final CommitInfos commitInfos = new ResourceRepositoryRequestBuilder<CommitInfos>() {

        @Override
        public Request<RepositoryContext, CommitInfos> build() {
            return req;
        }
    }.buildAsync().execute(bus).getSync();
    assertEquals(commitInfos.getTotal(), 1);
    return Iterables.getOnlyElement(commitInfos);
}
Also used : CommitInfos(com.b2international.snowowl.core.commit.CommitInfos) RepositoryContext(com.b2international.snowowl.core.domain.RepositoryContext) Request(com.b2international.snowowl.core.events.Request) AuthorizedRequest(com.b2international.snowowl.core.authorization.AuthorizedRequest)

Example 7 with RepositoryContext

use of com.b2international.snowowl.core.domain.RepositoryContext in project snow-owl by b2ihealthcare.

the class SnomedRepositoryPreCommitHook method getChangeSetProcessors.

@Override
protected Collection<ChangeSetProcessor> getChangeSetProcessors(StagingArea staging, RevisionSearcher index) throws IOException {
    final RepositoryContext context = ClassUtils.checkAndCast(staging.getContext(), RepositoryContext.class);
    // initialize OWL Expression converter on the current branch
    final SnomedOWLExpressionConverter expressionConverter = new BranchRequest<>(staging.getBranchPath(), branchContext -> {
        return new SnomedOWLExpressionConverter(branchContext.inject().bind(RevisionSearcher.class, index).build());
    }).execute(context);
    final Set<String> statedSourceIds = Sets.newHashSet();
    final Set<String> statedDestinationIds = Sets.newHashSet();
    final Set<String> inferredSourceIds = Sets.newHashSet();
    final Set<String> inferredDestinationIds = Sets.newHashSet();
    collectIds(statedSourceIds, statedDestinationIds, staging.getNewObjects(SnomedRelationshipIndexEntry.class), Concepts.STATED_RELATIONSHIP);
    collectIds(statedSourceIds, statedDestinationIds, staging.getChangedRevisions(SnomedRelationshipIndexEntry.class).map(diff -> (SnomedRelationshipIndexEntry) diff.newRevision), Concepts.STATED_RELATIONSHIP);
    collectIds(inferredSourceIds, inferredDestinationIds, staging.getNewObjects(SnomedRelationshipIndexEntry.class), Concepts.INFERRED_RELATIONSHIP);
    collectIds(inferredSourceIds, inferredDestinationIds, staging.getChangedRevisions(SnomedRelationshipIndexEntry.class).map(diff -> (SnomedRelationshipIndexEntry) diff.newRevision), Concepts.INFERRED_RELATIONSHIP);
    collectIds(statedSourceIds, statedDestinationIds, staging.getNewObjects(SnomedRefSetMemberIndexEntry.class), expressionConverter);
    collectIds(statedSourceIds, statedDestinationIds, staging.getChangedRevisions(SnomedRefSetMemberIndexEntry.class).map(diff -> (SnomedRefSetMemberIndexEntry) diff.newRevision), expressionConverter);
    staging.getRemovedObjects(SnomedRelationshipIndexEntry.class).filter(detachedRelationship -> Concepts.IS_A.equals(detachedRelationship.getTypeId())).forEach(detachedRelationship -> {
        // XXX: IS A relationships are expected to have a destination ID, not a value
        checkState(!detachedRelationship.hasValue(), "IS A relationship found with value: %s", detachedRelationship.getId());
        if (Concepts.STATED_RELATIONSHIP.equals(detachedRelationship.getCharacteristicTypeId())) {
            statedSourceIds.add(detachedRelationship.getSourceId());
            statedDestinationIds.add(detachedRelationship.getDestinationId());
        } else if (Concepts.INFERRED_RELATIONSHIP.equals(detachedRelationship.getCharacteristicTypeId())) {
            inferredSourceIds.add(detachedRelationship.getSourceId());
            inferredDestinationIds.add(detachedRelationship.getDestinationId());
        }
    });
    staging.getRemovedObjects(SnomedRefSetMemberIndexEntry.class).filter(detachedMember -> SnomedRefSetType.OWL_AXIOM == detachedMember.getReferenceSetType()).forEach(detachedOwlMember -> {
        collectIds(statedSourceIds, statedDestinationIds, detachedOwlMember, expressionConverter);
    });
    final LongSet statedConceptIds = PrimitiveSets.newLongOpenHashSet();
    final LongSet inferredConceptIds = PrimitiveSets.newLongOpenHashSet();
    if (!statedDestinationIds.isEmpty()) {
        for (SnomedConceptDocument statedDestinationConcept : index.get(SnomedConceptDocument.class, statedDestinationIds)) {
            statedConceptIds.add(Long.parseLong(statedDestinationConcept.getId()));
            if (statedDestinationConcept.getStatedParents() != null) {
                statedConceptIds.addAll(statedDestinationConcept.getStatedParents());
            }
            if (statedDestinationConcept.getStatedAncestors() != null) {
                statedConceptIds.addAll(statedDestinationConcept.getStatedAncestors());
            }
        }
    }
    if (!inferredDestinationIds.isEmpty()) {
        for (SnomedConceptDocument inferredDestinationConcept : index.get(SnomedConceptDocument.class, inferredDestinationIds)) {
            inferredConceptIds.add(Long.parseLong(inferredDestinationConcept.getId()));
            if (inferredDestinationConcept.getParents() != null) {
                inferredConceptIds.addAll(inferredDestinationConcept.getParents());
            }
            if (inferredDestinationConcept.getAncestors() != null) {
                inferredConceptIds.addAll(inferredDestinationConcept.getAncestors());
            }
        }
    }
    staging.getRemovedObjects(SnomedDescriptionIndexEntry.class).forEach(removedDescription -> {
        if (removedDescription.isFsn() && removedDescription.isActive()) {
            statedSourceIds.add(removedDescription.getConceptId());
            inferredSourceIds.add(removedDescription.getConceptId());
        }
    });
    staging.getChangedRevisions(SnomedDescriptionIndexEntry.class).filter(diff -> ((SnomedDescriptionIndexEntry) diff.newRevision).isFsn()).filter(diff -> diff.hasRevisionPropertyChanges(ACTIVE_AND_TERM_FIELDS)).forEach(diff -> {
        SnomedDescriptionIndexEntry newRevision = (SnomedDescriptionIndexEntry) diff.newRevision;
        statedSourceIds.add(newRevision.getConceptId());
        inferredSourceIds.add(newRevision.getConceptId());
    });
    staging.getNewObjects(SnomedDescriptionIndexEntry.class).filter(newDescription -> newDescription.isFsn() && newDescription.isActive()).forEach(newDescription -> {
        statedSourceIds.add(newDescription.getConceptId());
        inferredSourceIds.add(newDescription.getConceptId());
    });
    if (!statedSourceIds.isEmpty()) {
        final Query<SnomedConceptDocument> statedSourceConceptsQuery = Query.select(SnomedConceptDocument.class).where(Expressions.builder().should(SnomedConceptDocument.Expressions.ids(statedSourceIds)).should(SnomedConceptDocument.Expressions.statedParents(statedSourceIds)).should(SnomedConceptDocument.Expressions.statedAncestors(statedSourceIds)).build()).limit(Integer.MAX_VALUE).build();
        for (SnomedConceptDocument statedSourceConcept : index.search(statedSourceConceptsQuery)) {
            statedConceptIds.add(Long.parseLong(statedSourceConcept.getId()));
            if (statedSourceConcept.getStatedParents() != null) {
                statedConceptIds.addAll(statedSourceConcept.getStatedParents());
            }
            if (statedSourceConcept.getStatedAncestors() != null) {
                statedConceptIds.addAll(statedSourceConcept.getStatedAncestors());
            }
        }
    }
    if (!inferredSourceIds.isEmpty()) {
        final Query<SnomedConceptDocument> inferredSourceConceptsQuery = Query.select(SnomedConceptDocument.class).where(Expressions.builder().should(SnomedConceptDocument.Expressions.ids(inferredSourceIds)).should(SnomedConceptDocument.Expressions.parents(inferredSourceIds)).should(SnomedConceptDocument.Expressions.ancestors(inferredSourceIds)).build()).limit(Integer.MAX_VALUE).build();
        for (SnomedConceptDocument inferredSourceConcept : index.search(inferredSourceConceptsQuery)) {
            inferredConceptIds.add(Long.parseLong(inferredSourceConcept.getId()));
            if (inferredSourceConcept.getParents() != null) {
                inferredConceptIds.addAll(inferredSourceConcept.getParents());
            }
            if (inferredSourceConcept.getAncestors() != null) {
                inferredConceptIds.addAll(inferredSourceConcept.getAncestors());
            }
        }
    }
    staging.getNewObjects(SnomedConceptDocument.class).forEach(newConcept -> {
        long longId = Long.parseLong(newConcept.getId());
        statedConceptIds.add(longId);
        inferredConceptIds.add(longId);
    });
    // collect all reactivated concepts for the taxonomy to properly re-register them in the tree even if they don't carry stated/inferred information in this commit, but they have something in the index
    staging.getChangedRevisions(SnomedConceptDocument.class, Set.of(SnomedRf2Headers.FIELD_ACTIVE)).forEach(diff -> {
        RevisionPropertyDiff propertyDiff = diff.getRevisionPropertyDiff(SnomedRf2Headers.FIELD_ACTIVE);
        if ("false".equals(propertyDiff.getOldValue()) && "true".equals(propertyDiff.getNewValue())) {
            long longId = Long.parseLong(diff.newRevision.getId());
            statedConceptIds.add(longId);
            inferredConceptIds.add(longId);
        }
    });
    log.trace("Retrieving taxonomic information from store...");
    final boolean checkCycles = !(context instanceof Rf2TransactionContext);
    final Taxonomy inferredTaxonomy = Taxonomies.inferred(index, expressionConverter, staging, inferredConceptIds, checkCycles);
    final Taxonomy statedTaxonomy = Taxonomies.stated(index, expressionConverter, staging, statedConceptIds, checkCycles);
    // XXX change processor execution order is important!!!
    return List.of(// those values will be used in the ConceptChangeProcessor for example to properly compute the preferredDescriptions derived field
    new DescriptionChangeProcessor(), new ConceptChangeProcessor(DoiDataProvider.INSTANCE, SnomedIconProvider.INSTANCE.getAvailableIconIds(), statedTaxonomy, inferredTaxonomy), new RelationshipChangeProcessor());
}
Also used : BranchRequest(com.b2international.snowowl.core.request.BranchRequest) SnomedIconProvider(com.b2international.snowowl.snomed.icons.SnomedIconProvider) Query(com.b2international.index.query.Query) ClassUtils(com.b2international.commons.ClassUtils) RevisionBranch(com.b2international.index.revision.RevisionBranch) BaseRepositoryPreCommitHook(com.b2international.snowowl.core.repository.BaseRepositoryPreCommitHook) SnomedOWLExpressionConverterResult(com.b2international.snowowl.snomed.datastore.request.SnomedOWLExpressionConverterResult) Rf2ImportConfiguration(com.b2international.snowowl.snomed.datastore.request.rf2.importer.Rf2ImportConfiguration) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) PrimitiveSets(com.b2international.collections.PrimitiveSets) LongSet(com.b2international.collections.longs.LongSet) ImmutableList(com.google.common.collect.ImmutableList) RevisionSearcher(com.b2international.index.revision.RevisionSearcher) com.b2international.snowowl.snomed.datastore.index.entry(com.b2international.snowowl.snomed.datastore.index.entry) CompareUtils(com.b2international.commons.CompareUtils) RevisionPropertyDiff(com.b2international.index.revision.StagingArea.RevisionPropertyDiff) Rf2ReleaseType(com.b2international.snowowl.snomed.core.domain.Rf2ReleaseType) Logger(org.slf4j.Logger) RepositoryContext(com.b2international.snowowl.core.domain.RepositoryContext) Collection(java.util.Collection) SnomedOWLExpressionConverter(com.b2international.snowowl.snomed.datastore.request.SnomedOWLExpressionConverter) Set(java.util.Set) IOException(java.io.IOException) Taxonomy(com.b2international.snowowl.snomed.datastore.taxonomy.Taxonomy) Sets(com.google.common.collect.Sets) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) Stream(java.util.stream.Stream) Expressions(com.b2international.index.query.Expressions) Taxonomies(com.b2international.snowowl.snomed.datastore.taxonomy.Taxonomies) Rf2TransactionContext(com.b2international.snowowl.snomed.datastore.request.rf2.importer.Rf2TransactionContext) StagingArea(com.b2international.index.revision.StagingArea) ChangeSetProcessor(com.b2international.snowowl.core.repository.ChangeSetProcessor) SnomedRf2Headers(com.b2international.snowowl.snomed.common.SnomedRf2Headers) Collections(java.util.Collections) SnomedRefSetType(com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType) RepositoryContext(com.b2international.snowowl.core.domain.RepositoryContext) Taxonomy(com.b2international.snowowl.snomed.datastore.taxonomy.Taxonomy) LongSet(com.b2international.collections.longs.LongSet) RevisionPropertyDiff(com.b2international.index.revision.StagingArea.RevisionPropertyDiff) Rf2TransactionContext(com.b2international.snowowl.snomed.datastore.request.rf2.importer.Rf2TransactionContext) SnomedOWLExpressionConverter(com.b2international.snowowl.snomed.datastore.request.SnomedOWLExpressionConverter) RevisionSearcher(com.b2international.index.revision.RevisionSearcher)

Example 8 with RepositoryContext

use of com.b2international.snowowl.core.domain.RepositoryContext in project snow-owl by b2ihealthcare.

the class CommitInfoRequestTest method getCommitInfo.

@Test
public void getCommitInfo() {
    final String oid = UUID.randomUUID().toString();
    final String shortName = UUID.randomUUID().toString();
    final String comment = "Code system for commit info 1";
    createCodeSystem(oid, shortName, comment);
    final String id = getCommitInfoByComment(comment).getId();
    Request<RepositoryContext, CommitInfo> req = RepositoryRequests.commitInfos().prepareGetCommitInfo(id).build();
    CommitInfo commitInfo = new ResourceRepositoryRequestBuilder<CommitInfo>() {

        @Override
        public Request<RepositoryContext, CommitInfo> build() {
            return req;
        }
    }.buildAsync().execute(bus).getSync();
    assertEquals(id, commitInfo.getId());
    assertEquals(comment, commitInfo.getComment());
    assertEquals(BRANCH, commitInfo.getBranch());
    assertEquals(USER_ID, commitInfo.getAuthor());
}
Also used : RepositoryContext(com.b2international.snowowl.core.domain.RepositoryContext) Request(com.b2international.snowowl.core.events.Request) AuthorizedRequest(com.b2international.snowowl.core.authorization.AuthorizedRequest) CommitInfo(com.b2international.snowowl.core.commit.CommitInfo) Test(org.junit.Test)

Example 9 with RepositoryContext

use of com.b2international.snowowl.core.domain.RepositoryContext in project snow-owl by b2ihealthcare.

the class CommitInfoRequestTest method searchCommitInfoByTimestamp.

@Test
public void searchCommitInfoByTimestamp() {
    final String oid = UUID.randomUUID().toString();
    final String shortName = UUID.randomUUID().toString();
    final String comment = "Code system for commit info 5";
    createCodeSystem(shortName, oid, comment);
    final CommitInfo commitInfo = getCommitInfoByComment(comment);
    Request<RepositoryContext, CommitInfos> req = RepositoryRequests.commitInfos().prepareSearchCommitInfo().filterByTimestamp(commitInfo.getTimestamp()).build();
    final CommitInfos commitInfos = new ResourceRepositoryRequestBuilder<CommitInfos>() {

        @Override
        public Request<RepositoryContext, CommitInfos> build() {
            return req;
        }
    }.buildAsync().execute(bus).getSync();
    assertTrue(commitInfos.getTotal() == 1);
    assertEquals(commitInfo.getTimestamp(), Iterables.getOnlyElement(commitInfos.getItems()).getTimestamp());
}
Also used : CommitInfos(com.b2international.snowowl.core.commit.CommitInfos) RepositoryContext(com.b2international.snowowl.core.domain.RepositoryContext) Request(com.b2international.snowowl.core.events.Request) AuthorizedRequest(com.b2international.snowowl.core.authorization.AuthorizedRequest) CommitInfo(com.b2international.snowowl.core.commit.CommitInfo) Test(org.junit.Test)

Example 10 with RepositoryContext

use of com.b2international.snowowl.core.domain.RepositoryContext in project snow-owl by b2ihealthcare.

the class CommitInfoRequestTest method searchCommitInfoByUserId.

@Test
public void searchCommitInfoByUserId() {
    final String oid = UUID.randomUUID().toString();
    final String shortName = UUID.randomUUID().toString();
    final String comment = "Code system for commit info 3";
    final String userId = "commitInfo";
    createCodeSystem(oid, shortName, comment, userId);
    Request<RepositoryContext, CommitInfos> req = RepositoryRequests.commitInfos().prepareSearchCommitInfo().filterByAuthor(userId).build();
    final CommitInfos commitInfos = new ResourceRepositoryRequestBuilder<CommitInfos>() {

        @Override
        public Request<RepositoryContext, CommitInfos> build() {
            return req;
        }
    }.buildAsync().execute(bus).getSync();
    assertEquals(commitInfos.getTotal(), 1);
    final CommitInfo commitInfo = Iterables.getOnlyElement(commitInfos);
    assertEquals(userId, commitInfo.getAuthor());
}
Also used : CommitInfos(com.b2international.snowowl.core.commit.CommitInfos) RepositoryContext(com.b2international.snowowl.core.domain.RepositoryContext) Request(com.b2international.snowowl.core.events.Request) AuthorizedRequest(com.b2international.snowowl.core.authorization.AuthorizedRequest) CommitInfo(com.b2international.snowowl.core.commit.CommitInfo) Test(org.junit.Test)

Aggregations

RepositoryContext (com.b2international.snowowl.core.domain.RepositoryContext)18 Request (com.b2international.snowowl.core.events.Request)8 Collectors (java.util.stream.Collectors)8 CompareUtils (com.b2international.commons.CompareUtils)5 BadRequestException (com.b2international.commons.exceptions.BadRequestException)5 Branch (com.b2international.snowowl.core.branch.Branch)5 EffectiveTimes (com.b2international.snowowl.core.date.EffectiveTimes)5 Permission (com.b2international.snowowl.core.identity.Permission)5 IOException (java.io.IOException)5 ResourceURI (com.b2international.snowowl.core.ResourceURI)4 TerminologyResource (com.b2international.snowowl.core.TerminologyResource)4 AccessControl (com.b2international.snowowl.core.authorization.AccessControl)4 RepositoryRequests (com.b2international.snowowl.core.repository.RepositoryRequests)4 SnomedRf2Headers (com.b2international.snowowl.snomed.common.SnomedRf2Headers)4 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)4 LocalDate (java.time.LocalDate)4 java.util (java.util)4 List (java.util.List)4 Stream (java.util.stream.Stream)4 NotNull (javax.validation.constraints.NotNull)4