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));
}
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();
}
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());
}
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);
}
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.");
}
}
Aggregations