use of com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry in project snow-owl by b2ihealthcare.
the class SnomedDescriptionAcceptabilityUpdateRequest method doExecute.
@Override
protected void doExecute(TransactionContext context, SnomedComponentDocument componentToUpdate) {
final Iterable<SnomedReferenceSetMember> existingMembers = create ? Collections.emptySet() : SnomedRequests.prepareSearchMember().all().filterByReferencedComponent(componentToUpdate.getId()).filterByRefSetType(Collections.singleton(SnomedRefSetType.LANGUAGE)).build().execute(context);
final Map<String, Acceptability> newLanguageMembersToCreate = newHashMap(newAcceptabilityMap);
final ModuleIdProvider moduleIdSupplier = context.service(ModuleIdProvider.class);
// check if there are existing matches
for (SnomedReferenceSetMember existingMember : existingMembers) {
final String acceptabilityId = (String) existingMember.getProperties().get(SnomedRf2Headers.FIELD_ACCEPTABILITY_ID);
final Acceptability acceptability = Acceptability.getByConceptId(acceptabilityId);
final String languageReferenceSetId = existingMember.getRefsetId();
if (null == acceptability) {
continue;
}
final SnomedRefSetMemberIndexEntry.Builder updatedMember = SnomedRefSetMemberIndexEntry.builder(existingMember);
final SnomedRefSetMemberIndexEntry oldRevision = updatedMember.build();
if (acceptability.equals(newLanguageMembersToCreate.get(languageReferenceSetId))) {
// Exact match: make sure that the member is active
if (ensureMemberActive(context, existingMember, updatedMember)) {
context.update(oldRevision, updatedMember.build());
}
// Remove it from the working list, as we have found a match
newLanguageMembersToCreate.remove(languageReferenceSetId);
} else if (newLanguageMembersToCreate.containsKey(languageReferenceSetId)) {
// Change acceptability, set status to active if required, place it in the supplied module
final Acceptability newAcceptability = newLanguageMembersToCreate.get(languageReferenceSetId);
updatedMember.field(SnomedRf2Headers.FIELD_ACCEPTABILITY_ID, newAcceptability.getConceptId());
ensureMemberActive(context, existingMember, updatedMember);
updateModule(context, existingMember, updatedMember, moduleIdSupplier.apply(componentToUpdate));
unsetEffectiveTime(existingMember, updatedMember);
context.update(oldRevision, updatedMember.build());
newLanguageMembersToCreate.remove(languageReferenceSetId);
} else {
// Not acceptable in this language reference set, remove or inactivate if already released
if (removeOrDeactivate(context, existingMember, updatedMember)) {
context.update(oldRevision, updatedMember.build());
}
}
}
for (final Entry<String, Acceptability> languageMemberEntry : newLanguageMembersToCreate.entrySet()) {
SnomedComponents.newLanguageMember().withAcceptability(languageMemberEntry.getValue()).withRefSet(languageMemberEntry.getKey()).withModuleId(moduleIdSupplier.apply(componentToUpdate)).withReferencedComponent(componentToUpdate.getId()).addTo(context);
}
}
use of com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry in project snow-owl by b2ihealthcare.
the class SnomedExtendedMapMemberCreateDelegate method execute.
@Override
public String execute(SnomedReferenceSet refSet, TransactionContext context) {
checkRefSetType(refSet, SnomedRefSetType.EXTENDED_MAP);
checkReferencedComponent(refSet);
checkHasProperty(SnomedRf2Headers.FIELD_MAP_GROUP);
checkHasProperty(SnomedRf2Headers.FIELD_MAP_PRIORITY);
checkHasProperty(SnomedRf2Headers.FIELD_MAP_RULE);
checkHasProperty(SnomedRf2Headers.FIELD_MAP_ADVICE);
checkComponentExists(refSet, context, SnomedRf2Headers.FIELD_MODULE_ID, getModuleId());
checkComponentExists(refSet, context, SnomedRf2Headers.FIELD_REFERENCED_COMPONENT_ID, getReferencedComponentId());
checkComponentExists(refSet, context, SnomedRf2Headers.FIELD_CORRELATION_ID);
final String mapCategoryId = getComponentId(SnomedRf2Headers.FIELD_MAP_CATEGORY_ID);
if (SnomedIdentifiers.isValid(mapCategoryId)) {
checkComponentExists(refSet, context, SnomedRf2Headers.FIELD_MAP_CATEGORY_ID);
}
if (SnomedIdentifiers.isValid(getProperty(SnomedRf2Headers.FIELD_MAP_TARGET))) {
checkComponentExists(refSet, context, SnomedRf2Headers.FIELD_MAP_TARGET);
}
SnomedRefSetMemberIndexEntry member = SnomedComponents.newComplexMapMember().withId(getId()).withActive(isActive()).withReferencedComponent(getReferencedComponentId()).withModuleId(getModuleId()).withRefSet(getReferenceSetId()).withMapTargetId(getComponentId(SnomedRf2Headers.FIELD_MAP_TARGET)).withGroup(getProperty(SnomedRf2Headers.FIELD_MAP_GROUP, Integer.class)).withPriority(getProperty(SnomedRf2Headers.FIELD_MAP_PRIORITY, Integer.class)).withMapRule(getProperty(SnomedRf2Headers.FIELD_MAP_RULE)).withMapAdvice(getProperty(SnomedRf2Headers.FIELD_MAP_ADVICE)).withCorrelationId(getComponentId(SnomedRf2Headers.FIELD_CORRELATION_ID)).withMapCategoryId(mapCategoryId).addTo(context);
return member.getId();
}
use of com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry in project snow-owl by b2ihealthcare.
the class SnomedMemberBuilder method addTo.
public final SnomedRefSetMemberIndexEntry addTo(TransactionContext context) {
final SnomedRefSetMemberIndexEntry member = build(context);
context.add(member);
return member;
}
use of com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry in project snow-owl by b2ihealthcare.
the class SnomedRefSetMemberUpdateRequest method execute.
@Override
public Boolean execute(TransactionContext context) {
SnomedRefSetMemberIndexEntry member = context.lookup(componentId(), SnomedRefSetMemberIndexEntry.class);
SnomedRefSetMemberIndexEntry.Builder updatedMember = SnomedRefSetMemberIndexEntry.builder(member);
/*
* TODO: Generalize the logic below: any attempts of retrieving a missing component during component update
* (with the exception of the component that is being updated) should return a 400 response instead of a 404.
*/
try {
SnomedRefSetType type = member.getReferenceSetType();
boolean changed = false;
changed |= updateStatus(member, updatedMember);
changed |= updateModule(member, updatedMember);
changed |= updateEffectiveTime(member, updatedMember);
SnomedRefSetMemberUpdateDelegate delegate = getDelegate(type);
changed |= delegate.execute(member, updatedMember, context);
if (changed) {
if (!isEffectiveTimeUpdate()) {
updatedMember.effectiveTime(EffectiveTimes.UNSET_EFFECTIVE_TIME);
}
context.update(member, updatedMember.build());
}
return changed;
} catch (ComponentNotFoundException e) {
throw e.toBadRequestException();
}
}
use of com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry in project snow-owl by b2ihealthcare.
the class SnomedSimpleMapMemberCreateDelegate method execute.
@Override
public String execute(SnomedReferenceSet refSet, TransactionContext context) {
checkRefSetType(refSet, SnomedRefSetType.SIMPLE_MAP);
checkReferencedComponent(refSet);
checkComponentExists(refSet, context, SnomedRf2Headers.FIELD_MODULE_ID, getModuleId());
checkComponentExists(refSet, context, SnomedRf2Headers.FIELD_REFERENCED_COMPONENT_ID, getReferencedComponentId());
if (SnomedIdentifiers.isValid(getProperty(SnomedRf2Headers.FIELD_MAP_TARGET))) {
checkComponentExists(refSet, context, SnomedRf2Headers.FIELD_MAP_TARGET);
}
SnomedRefSetMemberIndexEntry member = SnomedComponents.newSimpleMapMember().withId(getId()).withActive(isActive()).withReferencedComponent(getReferencedComponentId()).withModuleId(getModuleId()).withRefSet(getReferenceSetId()).withMapTargetId(getComponentId(SnomedRf2Headers.FIELD_MAP_TARGET)).addTo(context);
return member.getId();
}
Aggregations