use of com.b2international.snowowl.core.domain.TransactionContext in project snow-owl by b2ihealthcare.
the class SnomedRefSetMemberApiTest method issue_SO_2501_ioobe_during_member_deletion.
/**
* Removals are sent in a BulkRequest which includes individual DeleteRequests for each member to be deleted. The version of SnomedEditingContext prior to the fix, however, used
* a server-side query to determine the list index for each member, and the list index reported by the database become misaligned with the actual
* contents if the members were not removed in decreasing index order. This test verifies that order of delete requests inside a bulk request does not matter.
*/
@Test
public void issue_SO_2501_ioobe_during_member_deletion() throws Exception {
String simpleRefSetId = createNewRefSet(branchPath);
final Json memberRequest = Json.object(SnomedRf2Headers.FIELD_MODULE_ID, Concepts.MODULE_SCT_CORE, "refsetId", simpleRefSetId, SnomedRf2Headers.FIELD_REFERENCED_COMPONENT_ID, simpleRefSetId, "commitComment", "Created new simple reference set member");
final String member1Id = assertCreated(createComponent(branchPath, SnomedComponentType.MEMBER, memberRequest));
final String member2Id = assertCreated(createComponent(branchPath, SnomedComponentType.MEMBER, memberRequest));
final String member3Id = assertCreated(createComponent(branchPath, SnomedComponentType.MEMBER, memberRequest));
final BulkRequestBuilder<TransactionContext> bulk = BulkRequest.create();
bulk.add(SnomedRequests.prepareDeleteMember(member1Id));
bulk.add(SnomedRequests.prepareDeleteMember(member3Id));
SnomedRequests.prepareCommit().setBody(bulk).setCommitComment("Delete reference set members in ascending index order").setAuthor("test").build(branchPath.getPath()).execute(Services.bus()).getSync();
// Check that member 2 still exists
getComponent(branchPath, SnomedComponentType.MEMBER, member2Id).statusCode(200);
}
use of com.b2international.snowowl.core.domain.TransactionContext in project snow-owl by b2ihealthcare.
the class SnomedConcreteDomainImportPostProcessor method postProcess.
@Override
public void postProcess(final BranchContext context, String userId, Logger logger) {
final SnomedCoreConfiguration config = context.service(SnomedCoreConfiguration.class);
if (!config.isConcreteDomainSupported()) {
return;
}
List<RequestBuilder<TransactionContext, ?>> requests = newArrayList();
if (!conceptExists(config.getConcreteDomainTypeRefsetIdentifier(), context)) {
// create module
createConcept(context, logger, MODULE_B2I_EXTENSION, B2I_MODULE_FSN, B2I_MODULE_PT, MODULE_ROOT, requests);
// create defining type refset concept
createConcept(context, logger, REFSET_DEFINING_TYPE, DEFINING_TYPE_REFSET_FSN, DEFINING_TYPE_REFSET_PT, REFSET_ROOT_CONCEPT, requests);
// create concrete domain type refset concept
createConcept(context, logger, config.getConcreteDomainTypeRefsetIdentifier(), CONCRETE_DOMAIN_TYPE_REFSET_FSN, CONCRETE_DOMAIN_TYPE_REFSET_PT, REFSET_DEFINING_TYPE, requests);
// create measurement type concrete domain refset concept
createConcept(context, logger, REFSET_MEASUREMENT_TYPE, MEASUREMENT_TYPE_REFSET_FSN, MEASUREMENT_TYPE_REFSET_PT, config.getConcreteDomainTypeRefsetIdentifier(), requests);
}
// create boolean concrete domain refset identifier concept and refset
createRefsetAndConcept(context, logger, config.getBooleanDatatypeRefsetIdentifier(), BOOLEAN_DATATYPE_REFSET_FSN, BOOLEAN_DATATYPE_REFSET_PT, config.getConcreteDomainTypeRefsetIdentifier(), requests);
// create string concrete domain refset identifier concept and refset
createRefsetAndConcept(context, logger, config.getStringDatatypeRefsetIdentifier(), STRING_DATATYPE_REFSET_FSN, STRING_DATATYPE_REFSET_PT, config.getConcreteDomainTypeRefsetIdentifier(), requests);
// create date-time concrete domain refset identifier concept and refset
createRefsetAndConcept(context, logger, config.getDatetimeDatatypeRefsetIdentifier(), DATETIME_DATATYPE_REFSET_FSN, DATETIME_DATATYPE_REFSET_PT, config.getConcreteDomainTypeRefsetIdentifier(), requests);
// create integer concrete domain refset identifier concept and refset
createRefsetAndConcept(context, logger, config.getIntegerDatatypeRefsetIdentifier(), INTEGER_DATATYPE_REFSET_FSN, INTEGER_DATATYPE_REFSET_PT, REFSET_MEASUREMENT_TYPE, requests);
// create float concrete domain refset identifier concept and refset
createRefsetAndConcept(context, logger, config.getFloatDatatypeRefsetIdentifier(), FLOAT_DATATYPE_REFSET_FSN, FLOAT_DATATYPE_REFSET_PT, REFSET_MEASUREMENT_TYPE, requests);
if (!requests.isEmpty()) {
try {
final BulkRequestBuilder<TransactionContext> bulkRequest = BulkRequest.create();
requests.forEach(bulkRequest::add);
SnomedRequests.prepareCommit().setBody(bulkRequest).setAuthor(userId).setCommitComment("Import post processor created concrete domain reference sets").setParentContextDescription(DatastoreLockContextDescriptions.IMPORT).build().execute(context);
} catch (final Exception e) {
logger.error("Caught exception while creating concrete domain reference sets in {}", getClass().getSimpleName(), e);
}
}
}
use of com.b2international.snowowl.core.domain.TransactionContext in project snow-owl by b2ihealthcare.
the class MapDBRf2EffectiveTimeSlice method swapValueType.
private void swapValueType(final BranchContext context, final LongSet idsToUpdate) throws Exception {
if (idsToUpdate.isEmpty()) {
return;
}
final Set<String> idsAsString = LongSets.toStringSet(idsToUpdate);
idsToUpdate.clear();
try (final TransactionContext tx = context.openTransaction(context, DatastoreLockContextDescriptions.IMPORT)) {
for (final List<String> batch : Iterables.partition(idsAsString, BATCH_SIZE)) {
final Map<String, SnomedRelationshipIndexEntry> entriesById = tx.lookup(batch, SnomedRelationshipIndexEntry.class);
for (final SnomedRelationshipIndexEntry existingEntry : entriesById.values()) {
final RelationshipValue oldValue = existingEntry.getValueAsObject();
final BigDecimal numericValue = oldValue.map(i -> new BigDecimal(i), d -> null, s -> null);
if (numericValue != null) {
final RelationshipValue newValue = RelationshipValue.fromTypeAndObjects(RelationshipValueType.DECIMAL, numericValue, null);
final SnomedRelationshipIndexEntry updatedEntry = SnomedRelationshipIndexEntry.builder(existingEntry).value(newValue).build();
tx.update(existingEntry, updatedEntry);
} else {
context.log().warn("Non-integer value found on relationship {}, can not convert value type", existingEntry.getId());
}
}
}
tx.commit("Update value types using MRCM range constraints");
}
}
use of com.b2international.snowowl.core.domain.TransactionContext in project snow-owl by b2ihealthcare.
the class SnomedMergePerformanceTest method testPerf.
@Test
public void testPerf() throws Exception {
IBranchPath branch = BranchPathUtils.createPath(branchPath, "merge-test");
branching.createBranch(branch).statusCode(201);
BulkRequestBuilder<TransactionContext> bulk = BulkRequest.create();
final int numberOfConceptsToWorkWith = 10_000;
for (int i = 0; i < numberOfConceptsToWorkWith; i++) {
bulk.add(SnomedRequests.prepareNewConcept().setIdFromNamespace(null).setActive(true).setModuleId(Concepts.MODULE_SCT_CORE).addDescription(SnomedRequests.prepareNewDescription().setIdFromNamespace(null).setTerm("MergeTest FSN " + i).setTypeId(Concepts.FULLY_SPECIFIED_NAME).setLanguageCode("en").preferredIn(Concepts.REFSET_LANGUAGE_TYPE_UK)).addDescription(SnomedRequests.prepareNewDescription().setIdFromNamespace(null).setTerm("MergeTest PT " + i).setTypeId(Concepts.SYNONYM).setLanguageCode("en").preferredIn(Concepts.REFSET_LANGUAGE_TYPE_UK)).addRelationship(SnomedRequests.prepareNewRelationship().setIdFromNamespace(null).setCharacteristicTypeId(Concepts.STATED_RELATIONSHIP).setTypeId(Concepts.IS_A).setDestinationId(Concepts.ROOT_CONCEPT)));
}
Stopwatch w = Stopwatch.createStarted();
// commit large changeset
CommitResult createCommitResult = SnomedRequests.prepareCommit().setBody(bulk).setCommitComment("Commit large bulk request").build(branch.getPath()).execute(getBus()).getSync();
System.err.println("Bulk create 10_000 concepts commit took: " + w);
w.reset().start();
// extract the new IDs assigned to the concepts
Set<String> idsOfCreatedConcepts = createCommitResult.getResultAs(BulkResponse.class).stream().filter(String.class::isInstance).map(String.class::cast).collect(Collectors.toSet());
// retrieve the first 100 created concepts back, check the module
SnomedConcepts first100 = SnomedRequests.prepareSearchConcept().setLimit(100).filterByIds(idsOfCreatedConcepts).build(branch.getPath()).execute(getBus()).getSync();
assertThat(first100.getTotal()).isEqualTo(numberOfConceptsToWorkWith);
first100.forEach(concept -> {
assertThat(concept.getModuleId()).isEqualTo(Concepts.MODULE_SCT_CORE);
});
// check that SNOMED CT ROOT has 10_000
int totalDescendants = SnomedRequests.prepareSearchConcept().setLimit(0).filterByStatedParent(Concepts.ROOT_CONCEPT).build(branch.getPath()).execute(getBus()).getSync().getTotal();
assertThat(totalDescendants).isGreaterThanOrEqualTo(numberOfConceptsToWorkWith);
// find the relationship IDs of the concepts
final Set<String> conceptRelationshipIds = SnomedRequests.prepareSearchRelationship().all().filterByActive(true).filterBySources(idsOfCreatedConcepts).filterByDestination(Concepts.ROOT_CONCEPT).setFields(SnomedRelationshipIndexEntry.Fields.ID).build(branch.getPath()).execute(getBus()).getSync().stream().map(SnomedRelationship::getId).collect(Collectors.toSet());
System.err.println("Verify creation of 10_000 concepts took: " + w);
w.reset().start();
// prepare module bulk update
bulk = BulkRequest.create();
for (String conceptIdToUpdate : idsOfCreatedConcepts) {
bulk.add(SnomedRequests.prepareUpdateConcept(conceptIdToUpdate).setModuleId(Concepts.MODULE_SCT_MODEL_COMPONENT));
}
// commit module bulk update
SnomedRequests.prepareCommit().setBody(bulk).setCommitComment("Commit update bulk request").build(branch.getPath()).execute(getBus()).getSync();
System.err.println("Bulk update 10_000 concepts commit took: " + w);
w.reset().start();
// prepare move concepts in hierarchy to clinical finding update
bulk = BulkRequest.create();
// inactivate all current relationships
for (String relationshipIdToInactive : conceptRelationshipIds) {
bulk.add(SnomedRequests.prepareUpdateRelationship(relationshipIdToInactive).setActive(false));
}
// add new relationships to concepts
for (String conceptIdToUpdate : idsOfCreatedConcepts) {
bulk.add(SnomedRequests.prepareNewRelationship().setIdFromNamespace(null).setSourceId(conceptIdToUpdate).setTypeId(Concepts.IS_A).setDestinationId("404684003").setModuleId(Concepts.MODULE_SCT_MODEL_COMPONENT));
}
// commit move concepts in hierarchy to clinical finding update
SnomedRequests.prepareCommit().setBody(bulk).setCommitComment("Commit update bulk request").build(branch.getPath()).execute(getBus()).getSync();
System.err.println("Bulk move 10_000 concepts to Clinical Finding took: " + w);
w.reset().start();
SnomedRestFixtures.merge(branch, branchPath, "Promote changes from task...").body("status", CoreMatchers.equalTo(Merge.Status.COMPLETED.name()));
System.err.println("Merge took: " + w);
}
use of com.b2international.snowowl.core.domain.TransactionContext in project snow-owl by b2ihealthcare.
the class SnomedReferenceSetMemberRestService method executeAction.
@Operation(summary = "Executes an action", description = "Executes an action specified via the request body on a reference set member." + "<p>Supported actions are:" + "• 'sync' - Executes sync action on a query type member" + "• 'create|update|delete' - allowed (mainly resolved and used in bulk requests), but in case of single member action use the dedicated endpoints instead" + "</p>")
@ApiResponses({ @ApiResponse(responseCode = "200", description = "Action execution successful"), @ApiResponse(responseCode = "204", description = "No content"), @ApiResponse(responseCode = "404", description = "Branch or member not found") })
@PostMapping(value = "/{id}/actions", consumes = { AbstractRestService.JSON_MEDIA_TYPE }, produces = { AbstractRestService.JSON_MEDIA_TYPE })
@ResponseBody
public Object executeAction(@Parameter(description = "The resource path", required = true) @PathVariable(value = "path") final String path, @Parameter(description = "The reference set member identifier") @PathVariable(value = "id") final String memberId, @Parameter(description = "Reference set member action") @RequestBody final SnomedResourceRequest<RestRequest> body, @RequestHeader(value = X_AUTHOR, required = false) final String author) {
final RequestResolver<TransactionContext> resolver = new RefSetMemberRequestResolver();
final RestRequest change = body.getChange();
final String commitComment = body.getCommitComment();
final String defaultModuleId = body.getDefaultModuleId();
change.setSource("memberId", memberId);
return SnomedRequests.prepareCommit().setDefaultModuleId(defaultModuleId).setAuthor(author).setBody(change.resolve(resolver)).setCommitComment(commitComment).build(path).execute(getBus()).getSync();
}
Aggregations