use of com.b2international.snowowl.core.ResourceURI in project snow-owl by b2ihealthcare.
the class RepositoryValidationRestService method getValidationResults.
@Operation(summary = "Retrieve the validation issues from a completed validation on a branch. Output may differ by the chosen content type.")
@ApiResponses({ @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "Branch not found") })
@RequestMapping(value = "/validations/{validationId}/issues", method = RequestMethod.GET, produces = { AbstractRestService.JSON_MEDIA_TYPE, AbstractRestService.CSV_MEDIA_TYPE })
@ResponseBody
public Promise<Collection<Object>> getValidationResults(@Parameter(description = "The unique validation identifier.") @PathVariable(value = "validationId") final String validationId, @Parameter(description = "The search key to use for retrieving the next page of results") @RequestParam(value = "searchAfter", required = false) final String searchAfter, @Parameter(description = "The maximum number of items to return") @RequestParam(value = "limit", defaultValue = "50", required = false) final int limit, @Parameter(hidden = true) @RequestHeader(value = HttpHeaders.ACCEPT, defaultValue = AbstractRestService.JSON_MEDIA_TYPE, required = false) final String contentType) {
final IEventBus bus = getBus();
return getValidationRun(validationId).thenWith(validationJob -> {
final ResourceURI codeSystemURI = getCodeSystemURIFromJob(validationJob);
if (AbstractRestService.CSV_MEDIA_TYPE.equals(contentType)) {
return ValidationRequests.issues().prepareSearch().isWhitelisted(false).all().filterByResourceUri(codeSystemURI).sortBy(Sort.fieldAsc(ValidationIssue.Fields.RULE_ID)).buildAsync().execute(bus).then(issues -> {
final Set<String> rulesToFetch = issues.stream().map(ValidationIssue::getRuleId).collect(Collectors.toSet());
final Map<String, String> ruleDescriptionById = ValidationRequests.rules().prepareSearch().all().filterByIds(rulesToFetch).buildAsync().execute(bus).getSync(1, TimeUnit.MINUTES).stream().collect(Collectors.toMap(ValidationRule::getId, ValidationRule::getMessageTemplate));
return issues.stream().map(issue -> {
final String ruleId = issue.getRuleId();
final String ruleDescription = ruleDescriptionById.get(ruleId);
final String affectedComponentLabel = Iterables.getFirst(issue.getAffectedComponentLabels(), "No label found");
final String affectedComponentId = issue.getAffectedComponent().getComponentId();
return new ValidationIssueReport(ruleId, ruleDescription, affectedComponentId, affectedComponentLabel);
}).collect(Collectors.toList());
});
} else {
return ValidationRequests.issues().prepareSearch().isWhitelisted(false).setLimit(limit).setSearchAfter(searchAfter).filterByResourceUri(codeSystemURI).buildAsync().execute(bus).then(issues -> issues.getItems().stream().collect(Collectors.toList()));
}
});
}
use of com.b2international.snowowl.core.ResourceURI in project snow-owl by b2ihealthcare.
the class CodeSystemUpgradeRestService method upgrade.
@Operation(summary = "Start a Code System dependency upgrade (EXPERIMENTAL)", description = "Starts the upgrade process of a Code System to a newer extensionOf Code System dependency than the current extensionOf.")
@ApiResponses({ @ApiResponse(responseCode = "201", description = "Upgrade created"), @ApiResponse(responseCode = "400", description = "Code System cannot be upgraded") })
@PostMapping(consumes = { AbstractRestService.JSON_MEDIA_TYPE })
@ResponseStatus(HttpStatus.CREATED)
public Promise<ResponseEntity<Void>> upgrade(@RequestBody final UpgradeRestInput body) {
final UriComponentsBuilder uriBuilder = createURIBuilder();
final ResourceURI upgradeOf = new ResourceURI(body.getUpgradeOf());
final IEventBus bus = getBus();
return // TODO move this to generic resource controller
CodeSystemRequests.prepareGetCodeSystem(upgradeOf.getResourceId()).buildAsync().execute(bus).thenWith(codeSystem -> {
return CodeSystemRequests.prepareUpgrade(upgradeOf, new ResourceURI(body.getExtensionOf())).setResourceId(body.getCodeSystemId()).buildAsync().execute(bus);
}).then(upgradeCodeSystemId -> {
return ResponseEntity.created(uriBuilder.pathSegment(upgradeCodeSystemId).build().toUri()).build();
});
}
use of com.b2international.snowowl.core.ResourceURI in project snow-owl by b2ihealthcare.
the class CodeSystemUpgradeRestService method sync.
@Operation(summary = "Synchronize upgrade codesystem with the original codesystem (EXPERIMENTAL)", description = "Synchronize any changes on the original code system with the upgrade code system.")
@ApiResponses({ @ApiResponse(responseCode = "204", description = "Upgrade code system synchronized"), @ApiResponse(responseCode = "400", description = "Code system could not be synchronized with the downstream code system") })
@PostMapping(value = "/sync/", consumes = { AbstractRestService.JSON_MEDIA_TYPE })
@ResponseStatus(HttpStatus.NO_CONTENT)
public void sync(@RequestBody final CodeSystemUpgradeSyncRestInput body) {
final String codeSystemId = body.getCodeSystemId();
final ResourceURI source = body.getSource();
final CodeSystem codeSystem = CodeSystemRequests.prepareSearchCodeSystem().filterById(codeSystemId).buildAsync().execute(getBus()).getSync(1, TimeUnit.MINUTES).first().orElseThrow(() -> new NotFoundException("Code System", codeSystemId));
CodeSystemRequests.prepareUpgradeSynchronization(codeSystem.getResourceURI(), source).buildAsync().execute(getBus());
}
use of com.b2international.snowowl.core.ResourceURI in project snow-owl by b2ihealthcare.
the class ComponentURITest method create.
@Test
public void create() {
final ResourceURI codeSystemURI = CodeSystem.uri("SNOMEDCT/2019-09-30");
final String componentType = "concept";
final String identifier = "123456789";
ComponentURI componentURI = ComponentURI.of(codeSystemURI, componentType, identifier);
assertEquals("SNOMEDCT", componentURI.resourceId());
assertEquals("codesystems/SNOMEDCT/2019-09-30", componentURI.resourceUri().toString());
assertEquals("concept", componentURI.componentType());
assertEquals(identifier, componentURI.identifier());
assertEquals(ComponentIdentifier.of(componentType, identifier), componentURI.toComponentIdentifier());
// verify interner
assertTrue(componentURI == ComponentURI.of(codeSystemURI, ComponentIdentifier.of(componentType, identifier)));
assertTrue(componentURI == ComponentURI.of(codeSystemURI.toString(), componentType, identifier));
}
use of com.b2international.snowowl.core.ResourceURI in project snow-owl by b2ihealthcare.
the class ResourceURITest method timestampPart.
@Test
public void timestampPart() throws Exception {
final ResourceURI uri = CodeSystem.uri("SNOMEDCT-EXT/a/b@1234567890");
assertEquals("SNOMEDCT-EXT", uri.getResourceId());
assertEquals("a/b", uri.getPath());
assertEquals("@1234567890", uri.getTimestampPart());
}
Aggregations