Search in sources :

Example 1 with ClassificationTask

use of com.b2international.snowowl.snomed.reasoner.domain.ClassificationTask in project snow-owl by b2ihealthcare.

the class ClassificationSaveRequest method execute.

@Override
public String execute(final RepositoryContext context) {
    final Request<RepositoryContext, ClassificationTask> classificationRequest = ClassificationRequests.prepareGetClassification(classificationId).build();
    final ClassificationTask classification = classificationRequest.execute(context);
    final String branchPath = classification.getBranch();
    final Request<RepositoryContext, Branch> branchRequest = RepositoryRequests.branching().prepareGet(branchPath).build();
    final Branch branch = branchRequest.execute(context);
    if (!SAVEABLE_STATUSES.contains(classification.getStatus())) {
        throw new BadRequestException("Classification '%s' is not in the expected state to start saving changes.", classificationId);
    }
    if (classification.getTimestamp() < branch.headTimestamp()) {
        throw new BadRequestException("Classification '%s' on branch '%s' is stale (classification timestamp: %s, head timestamp: %s).", classificationId, branchPath, classification.getTimestamp(), branch.headTimestamp());
    }
    final String user = !Strings.isNullOrEmpty(userId) ? userId : context.service(User.class).getUsername();
    final AsyncRequest<?> saveRequest = new SaveJobRequestBuilder().setClassificationId(classificationId).setUserId(user).setParentLockContext(parentLockContext).setCommitComment(commitComment).setModuleId(moduleId).setNamespace(namespace).setAssignerType(assignerType).setFixEquivalences(fixEquivalences).setHandleConcreteDomains(handleConcreteDomains).build(branchPath);
    return JobRequests.prepareSchedule().setUser(userId).setRequest(saveRequest).setDescription(String.format("Saving classification changes on %s", branch.path())).buildAsync().get(context, SCHEDULE_TIMEOUT_MILLIS);
}
Also used : RepositoryContext(com.b2international.snowowl.core.domain.RepositoryContext) ClassificationTask(com.b2international.snowowl.snomed.reasoner.domain.ClassificationTask) Branch(com.b2international.snowowl.core.branch.Branch) BadRequestException(com.b2international.commons.exceptions.BadRequestException)

Example 2 with ClassificationTask

use of com.b2international.snowowl.snomed.reasoner.domain.ClassificationTask in project snow-owl by b2ihealthcare.

the class ClassificationTaskConverter method expandRelationshipChanges.

private void expandRelationshipChanges(final List<ClassificationTask> results, final Set<String> classificationTaskIds) {
    if (!expand().containsKey(ClassificationTask.Expand.RELATIONSHIP_CHANGES)) {
        return;
    }
    final Options expandOptions = expand().get(ClassificationTask.Expand.RELATIONSHIP_CHANGES, Options.class);
    final RelationshipChangeSearchRequestBuilder builder = ClassificationRequests.prepareSearchRelationshipChange().all().filterByClassificationId(classificationTaskIds);
    if (expandOptions.containsKey("sourceId")) {
        builder.filterBySourceId(expandOptions.getCollection("sourceId", String.class));
    }
    final RelationshipChanges relationshipChanges = builder.setExpand(expandOptions.get("expand", Options.class)).setLocales(locales()).build().execute(context());
    final ListMultimap<String, RelationshipChange> relationshipChangesByTaskId = Multimaps.index(relationshipChanges, RelationshipChange::getClassificationId);
    for (final ClassificationTask classificationTask : results) {
        final List<RelationshipChange> taskChanges = relationshipChangesByTaskId.get(classificationTask.getId());
        classificationTask.setRelationshipChanges(new RelationshipChanges(taskChanges, null, taskChanges.size(), taskChanges.size()));
    }
}
Also used : Options(com.b2international.commons.options.Options) ClassificationTask(com.b2international.snowowl.snomed.reasoner.domain.ClassificationTask) RelationshipChange(com.b2international.snowowl.snomed.reasoner.domain.RelationshipChange) RelationshipChangeSearchRequestBuilder(com.b2international.snowowl.snomed.reasoner.request.RelationshipChangeSearchRequestBuilder) RelationshipChanges(com.b2international.snowowl.snomed.reasoner.domain.RelationshipChanges)

Example 3 with ClassificationTask

use of com.b2international.snowowl.snomed.reasoner.domain.ClassificationTask in project snow-owl by b2ihealthcare.

the class ClassificationTaskConverter method expandEquivalentConceptSets.

private void expandEquivalentConceptSets(final List<ClassificationTask> results, final Set<String> classificationTaskIds) {
    if (!expand().containsKey(ClassificationTask.Expand.EQUIVALENT_CONCEPT_SETS)) {
        return;
    }
    final Options expandOptions = expand().get(ClassificationTask.Expand.EQUIVALENT_CONCEPT_SETS, Options.class);
    final EquivalentConceptSets equivalentConceptSets = ClassificationRequests.prepareSearchEquivalentConceptSet().filterByClassificationId(classificationTaskIds).all().setExpand(expandOptions.get("expand", Options.class)).setLocales(locales()).build().execute(context());
    final ListMultimap<String, EquivalentConceptSet> setsByTaskId = Multimaps.index(equivalentConceptSets, EquivalentConceptSet::getClassificationId);
    for (final ClassificationTask classificationTask : results) {
        final List<EquivalentConceptSet> taskSets = setsByTaskId.get(classificationTask.getId());
        classificationTask.setEquivalentConceptSets(new EquivalentConceptSets(taskSets, null, taskSets.size(), taskSets.size()));
    }
}
Also used : Options(com.b2international.commons.options.Options) EquivalentConceptSets(com.b2international.snowowl.snomed.reasoner.domain.EquivalentConceptSets) ClassificationTask(com.b2international.snowowl.snomed.reasoner.domain.ClassificationTask) EquivalentConceptSet(com.b2international.snowowl.snomed.reasoner.domain.EquivalentConceptSet)

Example 4 with ClassificationTask

use of com.b2international.snowowl.snomed.reasoner.domain.ClassificationTask in project snow-owl by b2ihealthcare.

the class ClassificationTaskConverter method toResource.

@Override
protected ClassificationTask toResource(final ClassificationTaskDocument entry) {
    final ClassificationTask resource = new ClassificationTask();
    resource.setId(entry.getId());
    resource.setUserId(entry.getUserId());
    resource.setReasonerId(entry.getReasonerId());
    resource.setBranch(entry.getBranch());
    resource.setTimestamp(entry.getTimestamp());
    resource.setStatus(entry.getStatus());
    resource.setCreationDate(entry.getCreationDate());
    resource.setCompletionDate(entry.getCompletionDate());
    resource.setSaveDate(entry.getSaveDate());
    resource.setInferredRelationshipChangesFound(entry.getHasInferredChanges());
    resource.setRedundantStatedRelationshipsFound(entry.getHasRedundantStatedChanges());
    resource.setEquivalentConceptsFound(entry.getHasEquivalentConcepts());
    return resource;
}
Also used : ClassificationTask(com.b2international.snowowl.snomed.reasoner.domain.ClassificationTask)

Example 5 with ClassificationTask

use of com.b2international.snowowl.snomed.reasoner.domain.ClassificationTask in project snow-owl by b2ihealthcare.

the class ClassificationTaskConverter method expandConcreteDomainChanges.

private void expandConcreteDomainChanges(final List<ClassificationTask> results, final Set<String> classificationTaskIds) {
    if (!expand().containsKey(ClassificationTask.Expand.CONCRETE_DOMAIN_CHANGES)) {
        return;
    }
    final Options expandOptions = expand().get(ClassificationTask.Expand.CONCRETE_DOMAIN_CHANGES, Options.class);
    final ConcreteDomainChanges concreteDomainChanges = ClassificationRequests.prepareSearchConcreteDomainChange().filterByClassificationId(classificationTaskIds).all().setExpand(expandOptions.get("expand", Options.class)).setLocales(locales()).build().execute(context());
    final ListMultimap<String, ConcreteDomainChange> concreteDomainChangesByTaskId = Multimaps.index(concreteDomainChanges, ConcreteDomainChange::getClassificationId);
    for (final ClassificationTask classificationTask : results) {
        final List<ConcreteDomainChange> taskChanges = concreteDomainChangesByTaskId.get(classificationTask.getId());
        classificationTask.setConcreteDomainChanges(new ConcreteDomainChanges(taskChanges, null, taskChanges.size(), taskChanges.size()));
    }
}
Also used : Options(com.b2international.commons.options.Options) ClassificationTask(com.b2international.snowowl.snomed.reasoner.domain.ClassificationTask) ConcreteDomainChange(com.b2international.snowowl.snomed.reasoner.domain.ConcreteDomainChange) ConcreteDomainChanges(com.b2international.snowowl.snomed.reasoner.domain.ConcreteDomainChanges)

Aggregations

ClassificationTask (com.b2international.snowowl.snomed.reasoner.domain.ClassificationTask)7 Options (com.b2international.commons.options.Options)3 EquivalentConceptSets (com.b2international.snowowl.snomed.reasoner.domain.EquivalentConceptSets)2 LongKeyLongMap (com.b2international.collections.longs.LongKeyLongMap)1 BadRequestException (com.b2international.commons.exceptions.BadRequestException)1 Branch (com.b2international.snowowl.core.branch.Branch)1 Branches (com.b2international.snowowl.core.branch.Branches)1 RepositoryContext (com.b2international.snowowl.core.domain.RepositoryContext)1 ConcreteDomainChange (com.b2international.snowowl.snomed.reasoner.domain.ConcreteDomainChange)1 ConcreteDomainChanges (com.b2international.snowowl.snomed.reasoner.domain.ConcreteDomainChanges)1 EquivalentConceptSet (com.b2international.snowowl.snomed.reasoner.domain.EquivalentConceptSet)1 RelationshipChange (com.b2international.snowowl.snomed.reasoner.domain.RelationshipChange)1 RelationshipChanges (com.b2international.snowowl.snomed.reasoner.domain.RelationshipChanges)1 ReasonerApiException (com.b2international.snowowl.snomed.reasoner.exceptions.ReasonerApiException)1 RelationshipChangeSearchRequestBuilder (com.b2international.snowowl.snomed.reasoner.request.RelationshipChangeSearchRequestBuilder)1