Search in sources :

Example 1 with RemoteJobEntry

use of com.b2international.snowowl.core.jobs.RemoteJobEntry in project snow-owl by b2ihealthcare.

the class SnomedRf2NextReleaseImportTest method doImport.

private void doImport(final String importFile, final String importUntil) {
    Attachment attachment = Attachment.upload(Services.context(), PlatformUtil.toAbsolutePathBundleEntry(SnomedContentRule.class, importFile));
    String jobId = SnomedRequests.rf2().prepareImport().setRf2Archive(attachment).setReleaseType(Rf2ReleaseType.FULL).setCreateVersions(true).setImportUntil(importUntil).build(SnomedContentRule.SNOMEDCT).runAsJobWithRestart(SnomedRf2Requests.importJobKey(SnomedContentRule.SNOMEDCT), String.format("Import %s release", importFile)).execute(Services.bus()).getSync(1, TimeUnit.MINUTES);
    RemoteJobEntry job = JobRequests.waitForJob(Services.bus(), jobId, 2000);
    assertTrue("Failed to import RF2 archive", job.isSuccessful());
    // assert that the version for importUntil is present in the system
    Version latestVersion = CodeSystemVersionRestRequests.getLatestVersion(SnomedContentRule.SNOMEDCT_ID).get();
    assertEquals(importUntil, EffectiveTimes.format(latestVersion.getEffectiveTime(), DateFormats.SHORT));
}
Also used : SnomedContentRule(com.b2international.snowowl.test.commons.SnomedContentRule) Version(com.b2international.snowowl.core.version.Version) Attachment(com.b2international.snowowl.core.attachments.Attachment) RemoteJobEntry(com.b2international.snowowl.core.jobs.RemoteJobEntry)

Example 2 with RemoteJobEntry

use of com.b2international.snowowl.core.jobs.RemoteJobEntry in project snow-owl by b2ihealthcare.

the class SnomedBranchRequestTest method createBranchAndCommitToParent.

@Test
public void createBranchAndCommitToParent() throws Exception {
    final Branching branches = RepositoryRequests.branching();
    final Merging merges = RepositoryRequests.merging();
    final String branchA = UUID.randomUUID().toString();
    final String branchB = UUID.randomUUID().toString();
    final String first = branches.prepareCreate().setParent(branchPath).setName(branchA).build(REPOSITORY_ID).execute(bus).getSync();
    final SnomedDescriptionCreateRequestBuilder fsnBuilder = SnomedRequests.prepareNewDescription().setIdFromNamespace(SnomedIdentifiers.INT_NAMESPACE).setModuleId(Concepts.MODULE_ROOT).setTerm("FSN " + branchA).setTypeId(Concepts.FULLY_SPECIFIED_NAME).setAcceptability(ImmutableMap.of(Concepts.REFSET_LANGUAGE_TYPE_UK, Acceptability.PREFERRED));
    final SnomedDescriptionCreateRequestBuilder ptBuilder = SnomedRequests.prepareNewDescription().setIdFromNamespace(SnomedIdentifiers.INT_NAMESPACE).setModuleId(Concepts.MODULE_ROOT).setTerm("PT " + branchA).setTypeId(Concepts.SYNONYM).setAcceptability(ImmutableMap.of(Concepts.REFSET_LANGUAGE_TYPE_UK, Acceptability.PREFERRED));
    final AsyncRequest<CommitResult> conceptRequest = SnomedRequests.prepareNewConcept().setModuleId(Concepts.MODULE_ROOT).setIdFromNamespace(SnomedIdentifiers.INT_NAMESPACE).addParent(Concepts.ROOT_CONCEPT).addDescription(fsnBuilder).addDescription(ptBuilder).build(first, RestExtensions.USER, "Created new concept");
    final CommitResult info = conceptRequest.execute(bus).getSync();
    final String conceptId = info.getResultAs(String.class);
    final String firstParentPath = BranchPathUtils.createPath(first).getParentPath();
    final Request<ServiceProvider, Merge> mergeRequest = merges.prepareCreate().setSource(first).setTarget(firstParentPath).setUserId(User.SYSTEM.getUsername()).setCommitComment("Merging changes").build(REPOSITORY_ID).getRequest();
    final String mergeJobId = JobRequests.prepareSchedule().setDescription("Merging changes").setRequest(mergeRequest).setUser(User.SYSTEM.getUsername()).buildAsync().execute(bus).getSync();
    final RemoteJobEntry mergeJobResult = JobRequests.waitForJob(bus, mergeJobId);
    final Merge merge = mergeJobResult.getResultAs(JsonSupport.getDefaultObjectMapper(), Merge.class);
    assertEquals(true, merge.getConflicts().isEmpty());
    String second = branches.prepareCreate().setParent(firstParentPath).setName(branchB).build(REPOSITORY_ID).execute(bus).getSync();
    final Branch sourceBranch = branches.prepareGet(merge.getSource()).build(REPOSITORY_ID).execute(bus).getSync();
    final Branch secondBranch = branches.prepareGet(second).build(REPOSITORY_ID).execute(bus).getSync();
    assertBranchesCreated(branchA, branchB, sourceBranch, secondBranch);
    assertBranchSegmentsValid(merge.getTarget(), sourceBranch.path(), secondBranch.path());
    // Check that the concept is visible on parent
    SnomedRequests.prepareGetConcept(conceptId).build(firstParentPath).execute(bus).getSync();
}
Also used : BaseRevisionBranching(com.b2international.index.revision.BaseRevisionBranching) Branching(com.b2international.snowowl.core.branch.Branching) Merge(com.b2international.snowowl.core.merge.Merge) Merging(com.b2international.snowowl.core.branch.Merging) CommitResult(com.b2international.snowowl.core.request.CommitResult) RevisionBranch(com.b2international.index.revision.RevisionBranch) Branch(com.b2international.snowowl.core.branch.Branch) ServiceProvider(com.b2international.snowowl.core.ServiceProvider) SnomedDescriptionCreateRequestBuilder(com.b2international.snowowl.snomed.datastore.request.SnomedDescriptionCreateRequestBuilder) RemoteJobEntry(com.b2international.snowowl.core.jobs.RemoteJobEntry) Test(org.junit.Test)

Example 3 with RemoteJobEntry

use of com.b2international.snowowl.core.jobs.RemoteJobEntry in project snow-owl by b2ihealthcare.

the class SnomedContentRule method before.

@Override
protected void before() throws Throwable {
    createCodeSystemIfNotExist();
    Attachment attachment = Attachment.upload(Services.context(), importArchive);
    String jobId = SnomedRequests.rf2().prepareImport().setRf2Archive(attachment).setReleaseType(contentType).setCreateVersions(true).setImportUntil(importUntil).build(codeSystemId).runAsJobWithRestart(SnomedRf2Requests.importJobKey(codeSystemId), "Importing RF2 content into " + codeSystemId).execute(Services.bus()).getSync(1, TimeUnit.MINUTES);
    RemoteJobEntry job = JobRequests.waitForJob(Services.bus(), jobId, 2000);
    assertTrue("Failed to import RF2 archive", job.isSuccessful());
}
Also used : Attachment(com.b2international.snowowl.core.attachments.Attachment) RemoteJobEntry(com.b2international.snowowl.core.jobs.RemoteJobEntry)

Example 4 with RemoteJobEntry

use of com.b2international.snowowl.core.jobs.RemoteJobEntry in project snow-owl by b2ihealthcare.

the class BranchCompareRequestTest method compareOnJob.

private BranchCompareResult compareOnJob(String base, String compare) {
    final String compareJobId = JobRequests.prepareSchedule().setRequest(prepareCompare(base, compare).getRequest()).setUser(RestExtensions.USER).setDescription(String.format("Comparing %s changes", branchPath)).buildAsync().execute(bus).getSync();
    final RemoteJobEntry job = JobRequests.waitForJob(bus, compareJobId, 100);
    return job.getResultAs(JsonSupport.getDefaultObjectMapper(), BranchCompareResult.class);
}
Also used : RemoteJobEntry(com.b2international.snowowl.core.jobs.RemoteJobEntry)

Example 5 with RemoteJobEntry

use of com.b2international.snowowl.core.jobs.RemoteJobEntry in project snow-owl by b2ihealthcare.

the class VersionRestService method createVersion.

@Operation(summary = "Create a new resource version", description = "Creates a new resource version. " + "The version tag (represented by an empty branch) is created on the resource's current working branch. " + "Where applicable, effective times are set on the unpublished content as part of this operation.")
@ApiResponses({ @ApiResponse(responseCode = "201", description = "Created"), @ApiResponse(responseCode = "404", description = "Not found"), @ApiResponse(responseCode = "409", description = "Code system version conflicts with existing branch") })
@PostMapping(consumes = { AbstractRestService.JSON_MEDIA_TYPE })
@ResponseStatus(value = HttpStatus.CREATED)
public ResponseEntity<Void> createVersion(@Parameter(description = "Version parameters") @RequestBody final ResourceRequest<VersionRestInput> input) {
    final VersionRestInput change = input.getChange();
    ApiValidation.checkInput(change);
    String newVersionUri = String.join(Branch.SEPARATOR, change.getResource().toString(), change.getVersion());
    String jobId = ResourceRequests.prepareNewVersion().setResource(change.getResource()).setVersion(change.getVersion()).setDescription(change.getDescription()).setEffectiveTime(change.getEffectiveTime()).setForce(change.isForce()).setCommitComment(input.getCommitComment()).buildAsync().runAsJobWithRestart(ResourceRequests.versionJobKey(change.getResource()), "Creating version " + newVersionUri).execute(getBus()).getSync(1, TimeUnit.MINUTES);
    RemoteJobEntry job = JobRequests.waitForJob(getBus(), jobId, 500);
    if (job.isSuccessful()) {
        final URI location = MvcUriComponentsBuilder.fromMethodName(VersionRestService.class, "getVersion", newVersionUri).build().toUri();
        return ResponseEntity.created(location).build();
    } else if (!Strings.isNullOrEmpty(job.getResult())) {
        ApiError error = job.getResultAs(ApplicationContext.getServiceForClass(ObjectMapper.class), ApiError.class);
        throw new ApiErrorException(error.withMessage(error.getMessage().replace("Branch name", "Version")));
    } else {
        throw new SnowowlRuntimeException("Version creation failed.");
    }
}
Also used : ApiError(com.b2international.commons.exceptions.ApiError) URI(java.net.URI) ApiErrorException(com.b2international.commons.exceptions.ApiErrorException) RemoteJobEntry(com.b2international.snowowl.core.jobs.RemoteJobEntry) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Aggregations

RemoteJobEntry (com.b2international.snowowl.core.jobs.RemoteJobEntry)6 SnowowlRuntimeException (com.b2international.snowowl.core.api.SnowowlRuntimeException)2 Attachment (com.b2international.snowowl.core.attachments.Attachment)2 ApiError (com.b2international.commons.exceptions.ApiError)1 ApiErrorException (com.b2international.commons.exceptions.ApiErrorException)1 BaseRevisionBranching (com.b2international.index.revision.BaseRevisionBranching)1 RevisionBranch (com.b2international.index.revision.RevisionBranch)1 ApplicationContext (com.b2international.snowowl.core.ApplicationContext)1 ApplicationContext.getServiceForClass (com.b2international.snowowl.core.ApplicationContext.getServiceForClass)1 ServiceProvider (com.b2international.snowowl.core.ServiceProvider)1 Branch (com.b2international.snowowl.core.branch.Branch)1 Branching (com.b2international.snowowl.core.branch.Branching)1 Merging (com.b2international.snowowl.core.branch.Merging)1 Notifications (com.b2international.snowowl.core.events.Notifications)1 IDs (com.b2international.snowowl.core.id.IDs)1 DatastoreLockContextDescriptions (com.b2international.snowowl.core.internal.locks.DatastoreLockContextDescriptions)1 JobRequests (com.b2international.snowowl.core.jobs.JobRequests)1 RemoteJobNotification (com.b2international.snowowl.core.jobs.RemoteJobNotification)1 RemoteJobs (com.b2international.snowowl.core.jobs.RemoteJobs)1 Merge (com.b2international.snowowl.core.merge.Merge)1