Search in sources :

Example 31 with IBranchPath

use of com.b2international.snowowl.core.api.IBranchPath in project snow-owl by b2ihealthcare.

the class SnomedImportApiTest method import01InvalidBranchPath.

@Test
public void import01InvalidBranchPath() throws Exception {
    final IBranchPath branchPath = BranchPathUtils.createPath("MAIN/notfound");
    final Map<String, ?> importConfiguration = ImmutableMap.<String, Object>builder().put("type", Rf2ReleaseType.DELTA.name()).put("createVersions", false).build();
    final String importId = lastPathSegment(doImport(branchPath, importConfiguration, getClass(), "SnomedCT_Release_INT_20150131_new_concept.zip").statusCode(201).extract().header("Location"));
    waitForImportJob(branchPath, importId).statusCode(200).body("status", equalTo(RemoteJobState.FAILED.name()));
}
Also used : IBranchPath(com.b2international.snowowl.core.api.IBranchPath) Test(org.junit.Test) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)

Example 32 with IBranchPath

use of com.b2international.snowowl.core.api.IBranchPath in project snow-owl by b2ihealthcare.

the class SnomedExtensionUpgradeTest method upgrade22UpgradeSychronizeHead.

@Test
public void upgrade22UpgradeSychronizeHead() throws Exception {
    // create extension on the latest SI VERSION
    CodeSystem extension = createExtension(latestInternationalVersion, branchPath.lastSegment());
    // new SI concept
    createConcept(SnomedContentRule.SNOMEDCT, createConceptRequestBody(Concepts.ROOT_CONCEPT, Concepts.MODULE_SCT_CORE));
    // create a new INT version
    LocalDate effectiveDate = getNextAvailableEffectiveDate(SNOMEDCT);
    createVersion(SNOMEDCT, effectiveDate).statusCode(201);
    ResourceURI upgradeVersion = CodeSystem.uri(SNOMEDCT, effectiveDate.toString());
    // new SE concept
    String extensionModuleId = createModule(extension);
    createConcept(extension.getResourceURI(), createConceptRequestBody(Concepts.ROOT_CONCEPT, extensionModuleId));
    // version extension
    LocalDate effectiveDate2 = LocalDate.now();
    createVersion(extension.getId(), effectiveDate2).statusCode(201);
    ResourceURI extensionVersion = CodeSystem.uri(extension.getId(), effectiveDate2.toString());
    // new SE concept
    createConcept(extension.getResourceURI(), createConceptRequestBody(Concepts.ROOT_CONCEPT, extensionModuleId));
    // version extension
    LocalDate effectiveDate3 = getNextAvailableEffectiveDate(extension.getId());
    createVersion(extension.getId(), effectiveDate3).statusCode(201);
    ResourceURI extensionVersion2 = CodeSystem.uri(extension.getId(), effectiveDate3.toString());
    // start upgrade to the new available upgrade version
    CodeSystem upgradeCodeSystem = createExtensionUpgrade(extensionVersion, upgradeVersion);
    CodeSystems expandedCodeSystems = CodeSystemRestRequests.search(upgradeCodeSystem.getId(), CodeSystem.Expand.UPGRADE_INFO + "()");
    assertEquals(upgradeVersion, upgradeCodeSystem.getExtensionOf());
    assertThat(expandedCodeSystems.first().get().getUpgradeInfo().getAvailableVersions()).doesNotContainSequence(extensionVersion);
    assertThat(expandedCodeSystems.first().get().getUpgradeInfo().getAvailableVersions()).contains(extensionVersion2);
    IBranchPath extensionBranch = BranchPathUtils.createPath(extension.getBranchPath());
    IBranchPath upgradeBranch = BranchPathUtils.createPath(upgradeCodeSystem.getBranchPath());
    merge(extensionBranch, upgradeBranch, "Merged new concept from child branch").body("status", equalTo(Merge.Status.COMPLETED.name()));
    Boolean result = CodeSystemRequests.prepareUpgradeSynchronization(upgradeCodeSystem.getResourceURI(), extension.getResourceURI()).buildAsync().execute(getBus()).getSync(1, TimeUnit.MINUTES);
    assertTrue(result);
    CodeSystems expandedCodeSystemsAfterMerge = CodeSystemRestRequests.search(upgradeCodeSystem.getId(), CodeSystem.Expand.UPGRADE_INFO + "()");
    assertThat(expandedCodeSystemsAfterMerge.first().get().getUpgradeInfo().getAvailableVersions()).isEmpty();
}
Also used : ResourceURI(com.b2international.snowowl.core.ResourceURI) CodeSystems(com.b2international.snowowl.core.codesystem.CodeSystems) CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) LocalDate(java.time.LocalDate) IBranchPath(com.b2international.snowowl.core.api.IBranchPath) Test(org.junit.Test)

Example 33 with IBranchPath

use of com.b2international.snowowl.core.api.IBranchPath in project snow-owl by b2ihealthcare.

the class SnomedExportApiTest method exportSnapshotWithBranchRange.

@Test
public void exportSnapshotWithBranchRange() throws Exception {
    final IBranchPath taskBranchPath = BranchPathUtils.createPath(branchPath, "task");
    branching.createBranch(taskBranchPath).statusCode(201);
    final Json exportConfig = Json.object("type", Rf2ReleaseType.SNAPSHOT.name());
    export(RevisionIndex.toRevisionRange(branchPath.getPath(), taskBranchPath.getPath()), exportConfig).then().statusCode(400);
}
Also used : Json(com.b2international.commons.json.Json) IBranchPath(com.b2international.snowowl.core.api.IBranchPath) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest) Test(org.junit.Test)

Example 34 with IBranchPath

use of com.b2international.snowowl.core.api.IBranchPath in project snow-owl by b2ihealthcare.

the class SnomedExportApiTest method exportDeltaWithBranchRange.

@Test
public void exportDeltaWithBranchRange() throws Exception {
    final String relationshipOnParent = createNewRelationship(branchPath);
    final IBranchPath taskBranchPath = BranchPathUtils.createPath(branchPath, "task");
    branching.createBranch(taskBranchPath).statusCode(201);
    final String relationshipOnTask = createNewRelationship(taskBranchPath);
    final Map<String, Object> config = Map.of("type", Rf2ReleaseType.DELTA.name(), "includeUnpublished", true);
    // A "standard" delta export should include both unpublished lines
    final File exportArchive = doExport(taskBranchPath, config);
    final String relationshipFileName = "sct2_StatedRelationship_Delta";
    final Multimap<String, Pair<Boolean, String>> fileToLinesMap = ArrayListMultimap.<String, Pair<Boolean, String>>create();
    fileToLinesMap.put(relationshipFileName, Pair.of(true, createRelationshipLine(relationshipOnParent)));
    fileToLinesMap.put(relationshipFileName, Pair.of(true, createRelationshipLine(relationshipOnTask)));
    assertArchiveContainsLines(exportArchive, fileToLinesMap);
    // Delta export with a path range can restrict the set of visible components
    final IBranchPath branchRange = BranchPathUtils.createPath(branchPath.getPath() + RevisionIndex.REV_RANGE + taskBranchPath.getPath());
    final File exportArchiveWithBranchRange = doExport(branchRange, config);
    fileToLinesMap.clear();
    fileToLinesMap.put(relationshipFileName, Pair.of(false, createRelationshipLine(relationshipOnParent)));
    fileToLinesMap.put(relationshipFileName, Pair.of(true, createRelationshipLine(relationshipOnTask)));
    assertArchiveContainsLines(exportArchiveWithBranchRange, fileToLinesMap);
}
Also used : File(java.io.File) IBranchPath(com.b2international.snowowl.core.api.IBranchPath) Pair(com.b2international.commons.Pair) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest) Test(org.junit.Test)

Example 35 with IBranchPath

use of com.b2international.snowowl.core.api.IBranchPath 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);
}
Also used : CommitResult(com.b2international.snowowl.core.request.CommitResult) TransactionContext(com.b2international.snowowl.core.domain.TransactionContext) Stopwatch(com.google.common.base.Stopwatch) SnomedConcepts(com.b2international.snowowl.snomed.core.domain.SnomedConcepts) IBranchPath(com.b2international.snowowl.core.api.IBranchPath) Test(org.junit.Test) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)

Aggregations

IBranchPath (com.b2international.snowowl.core.api.IBranchPath)79 Test (org.junit.Test)73 AbstractSnomedApiTest (com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)70 Merge (com.b2international.snowowl.core.merge.Merge)10 MergeConflict (com.b2international.snowowl.core.merge.MergeConflict)10 SnomedConcept (com.b2international.snowowl.snomed.core.domain.SnomedConcept)8 ConflictingAttribute (com.b2international.snowowl.core.merge.ConflictingAttribute)6 LocalDate (java.time.LocalDate)5 Pair (com.b2international.commons.Pair)4 File (java.io.File)4 Ignore (org.junit.Ignore)2 BackwardListIterator (com.b2international.commons.collections.BackwardListIterator)1 Json (com.b2international.commons.json.Json)1 BaseRevisionBranching (com.b2international.index.revision.BaseRevisionBranching)1 RevisionBranch (com.b2international.index.revision.RevisionBranch)1 ComponentIdentifier (com.b2international.snowowl.core.ComponentIdentifier)1 Repository (com.b2international.snowowl.core.Repository)1 RepositoryManager (com.b2international.snowowl.core.RepositoryManager)1 ResourceURI (com.b2international.snowowl.core.ResourceURI)1 BranchCompareResult (com.b2international.snowowl.core.branch.compare.BranchCompareResult)1