Search in sources :

Example 1 with QueryRefSetMemberEvaluation

use of com.b2international.snowowl.snomed.core.domain.refset.QueryRefSetMemberEvaluation in project snow-owl by b2ihealthcare.

the class QueryRefSetMemberUpdateRequest method execute.

@Override
public Boolean execute(TransactionContext context) {
    // evaluate query member
    final QueryRefSetMemberEvaluation evaluation = SnomedRequests.prepareQueryRefSetMemberEvaluation(memberId).build().execute(context);
    // lookup IDs before applying change to speed up query member update
    final Set<String> referencedComponents = evaluation.getChanges().stream().map(MemberChange::getReferencedComponent).map(SnomedConcept::getId).collect(Collectors.toSet());
    context.lookup(referencedComponents, SnomedConceptDocument.class);
    // apply all change as request on the target reference set
    for (MemberChange change : evaluation.getChanges()) {
        switch(change.getChangeKind()) {
            case ADD:
                SnomedRequests.prepareNewMember().setModuleId(moduleId).setReferencedComponentId(change.getReferencedComponent().getId()).setRefsetId(evaluation.getReferenceSetId()).buildNoContent().execute(context);
                break;
            case REMOVE:
                final SnomedReferenceSetMember member = SnomedRequests.prepareGetMember(change.getMemberId()).build().execute(context);
                if (member.isReleased()) {
                    SnomedRequests.prepareUpdateMember(change.getMemberId()).setSource(Map.of(SnomedRf2Headers.FIELD_ACTIVE, Boolean.FALSE)).build().execute(context);
                } else {
                    SnomedRequests.prepareDeleteMember(change.getMemberId()).build().execute(context);
                }
                break;
            case CHANGE:
                final SnomedReferenceSetMember memberToChange = SnomedRequests.prepareGetMember(change.getMemberId()).build().execute(context);
                if (!memberToChange.isActive()) {
                    SnomedRequests.prepareUpdateMember(change.getMemberId()).setSource(Map.of(SnomedRf2Headers.FIELD_ACTIVE, Boolean.TRUE)).build().execute(context);
                }
                break;
            default:
                throw new UnsupportedOperationException("Not implemented case: " + change.getChangeKind());
        }
    }
    return Boolean.TRUE;
}
Also used : QueryRefSetMemberEvaluation(com.b2international.snowowl.snomed.core.domain.refset.QueryRefSetMemberEvaluation) MemberChange(com.b2international.snowowl.snomed.core.domain.refset.MemberChange) SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember)

Aggregations

MemberChange (com.b2international.snowowl.snomed.core.domain.refset.MemberChange)1 QueryRefSetMemberEvaluation (com.b2international.snowowl.snomed.core.domain.refset.QueryRefSetMemberEvaluation)1 SnomedReferenceSetMember (com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember)1