use of com.b2international.snowowl.core.events.util.Promise in project snow-owl by b2ihealthcare.
the class ValidationThreadPoolTest method testConcurrentFastJobsWithExpensiveOnes.
@Test
public void testConcurrentFastJobsWithExpensiveOnes() {
final IJobManager manager = Job.getJobManager();
final List<Promise<Object>> validationPromises = Lists.newArrayList();
for (int i = 0; i < 10; i++) {
validationPromises.add(pool.submit(CheckType.FAST, createValidatableRunnable(CheckType.FAST, manager)));
if (i % 3 == 0) {
validationPromises.add(pool.submit(CheckType.EXPENSIVE, createValidatableRunnable(CheckType.EXPENSIVE, manager)));
}
}
Promise.all(validationPromises).getSync();
}
use of com.b2international.snowowl.core.events.util.Promise in project snow-owl by b2ihealthcare.
the class ValidationThreadPoolTest method testConcurrentExpensiveJobs.
@Test
public void testConcurrentExpensiveJobs() {
final IJobManager manager = Job.getJobManager();
final Runnable expensiveRunnable = createValidatableRunnable(CheckType.EXPENSIVE, manager);
final List<Promise<Object>> validationPromises = Lists.newArrayList();
for (int i = 0; i < 10; i++) {
validationPromises.add(pool.submit(CheckType.EXPENSIVE, expensiveRunnable));
}
Promise.all(validationPromises).getSync();
}
use of com.b2international.snowowl.core.events.util.Promise in project snow-owl by b2ihealthcare.
the class LdapIdentityProvider method searchUsers.
@Override
public Promise<Users> searchUsers(Collection<String> usernames, int limit) {
final ImmutableList.Builder<User> resultBuilder = ImmutableList.builder();
final String uidProp = conf.getUserIdProperty();
InitialLdapContext context = null;
NamingEnumeration<SearchResult> searchResultEnumeration = null;
try {
context = createLdapContext();
Collection<LdapRole> ldapRoles = getAllLdapRoles(context);
searchResultEnumeration = context.search(conf.getBaseDn(), conf.getUserFilter(), createSearchControls(ATTRIBUTE_DN, uidProp));
for (final SearchResult searchResult : ImmutableList.copyOf(Iterators.forEnumeration(searchResultEnumeration))) {
final Attributes attributes = searchResult.getAttributes();
if (hasAttribute(attributes, uidProp)) {
final String userName = (String) attributes.get(uidProp).get();
final List<Role> userRoles = ldapRoles.stream().filter(role -> role.getUniqueMembers().contains(searchResult.getNameInNamespace())).map(role -> new Role(role.getName(), role.getPermissions())).collect(Collectors.toList());
resultBuilder.add(new User(userName, userRoles));
}
}
final List<User> users = resultBuilder.build().stream().sorted((u1, u2) -> u1.getUsername().compareTo(u2.getUsername())).filter(user -> usernames.isEmpty() || usernames.contains(user.getUsername())).limit(limit).collect(Collectors.toList());
return Promise.immediate(new Users(users, limit, users.size()));
} catch (final NamingException e) {
LOG.error("Couldn't search users/roles due to LDAP communication error: {}", e.getMessage(), e);
throw new SnowowlRuntimeException(e);
} finally {
closeNamingEnumeration(searchResultEnumeration);
closeLdapContext(context);
}
}
use of com.b2international.snowowl.core.events.util.Promise 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.events.util.Promise in project snow-owl by b2ihealthcare.
the class ValidationThreadPoolTest method testConcurrentFastJobs.
@Test
public void testConcurrentFastJobs() {
final IJobManager manager = Job.getJobManager();
final Runnable fastRunnable = createValidatableRunnable(CheckType.FAST, manager);
final List<Promise<Object>> validationPromises = Lists.newArrayList();
for (int i = 0; i < 10; i++) {
validationPromises.add(pool.submit(CheckType.FAST, fastRunnable));
}
Promise.all(validationPromises).getSync();
}
Aggregations