use of com.b2international.snowowl.core.api.SnowowlRuntimeException in project snow-owl by b2ihealthcare.
the class CisSnomedIdentifierService method reserveSctIds.
@Override
public Map<String, SctId> reserveSctIds(String namespace, ComponentCategory category, int quantity) {
checkNotNull(category, "Component category must not be null.");
checkArgument(quantity > 0, "Number of requested IDs should be non-negative.");
checkCategory(category);
LOGGER.debug("Reserving {} component IDs for category {}.", quantity, category.getDisplayName());
HttpPost reserveRequest = null;
HttpGet recordsRequest = null;
try {
if (quantity > 1) {
LOGGER.debug("Sending {} ID bulk reservation request.", category.getDisplayName());
reserveRequest = httpPost(String.format("sct/bulk/reserve?token=%s", getToken()), createBulkReservationData(namespace, category, quantity));
final String bulkResponse = execute(reserveRequest);
final String jobId = mapper.readValue(bulkResponse, JsonNode.class).get("id").asText();
joinBulkJobPolling(jobId, quantity, getToken());
recordsRequest = httpGet(String.format("bulk/jobs/%s/records?token=%s", jobId, getToken()));
final String recordsResponse = execute(recordsRequest);
final JsonNode[] records = mapper.readValue(recordsResponse, JsonNode[].class);
return readSctIds(getComponentIds(records));
} else {
LOGGER.debug("Sending {} ID reservation request.", category.getDisplayName());
reserveRequest = httpPost(String.format("sct/reserve?token=%s", getToken()), createReservationData(namespace, category));
final String response = execute(reserveRequest);
final SctId sctid = mapper.readValue(response, SctId.class);
return readSctIds(Collections.singleton(sctid.getSctid()));
}
} catch (IOException e) {
throw new SnowowlRuntimeException("Exception while bulk reserving IDs.", e);
} finally {
release(reserveRequest);
release(recordsRequest);
}
}
use of com.b2international.snowowl.core.api.SnowowlRuntimeException in project snow-owl by b2ihealthcare.
the class CisSnomedIdentifierService method publish.
@Override
public Map<String, SctId> publish(final Set<String> componentIds) {
LOGGER.debug("Publishing {} component IDs.", componentIds.size());
final Map<String, SctId> sctIds = getSctIds(componentIds);
HttpPut publishRequest = null;
String currentNamespace = null;
try {
final Map<String, SctId> sctIdsToPublish = ImmutableMap.copyOf(Maps.filterValues(sctIds, Predicates.not(SctId::isPublished)));
if (!sctIdsToPublish.isEmpty()) {
if (sctIdsToPublish.size() > 1) {
final Multimap<String, String> componentIdsByNamespace = toNamespaceMultimap(sctIdsToPublish.keySet());
for (final Entry<String, Collection<String>> entry : componentIdsByNamespace.asMap().entrySet()) {
currentNamespace = entry.getKey();
for (final Collection<String> bulkIds : Iterables.partition(entry.getValue(), requestBulkLimit)) {
LOGGER.debug("Sending bulk publication request for namespace {} with size {}.", currentNamespace, bulkIds.size());
publishRequest = httpPut(String.format("sct/bulk/publish?token=%s", getToken()), createBulkPublishData(currentNamespace, bulkIds));
execute(publishRequest);
}
}
} else {
final String componentId = Iterables.getOnlyElement(sctIdsToPublish.keySet());
currentNamespace = SnomedIdentifiers.getNamespace(componentId);
publishRequest = httpPut(String.format("sct/publish?token=%s", getToken()), createPublishData(componentId));
execute(publishRequest);
}
}
return ImmutableMap.copyOf(sctIdsToPublish);
} catch (IOException e) {
throw new SnowowlRuntimeException(String.format("Exception while publishing IDs for namespace %s.", currentNamespace), e);
} finally {
release(publishRequest);
}
}
use of com.b2international.snowowl.core.api.SnowowlRuntimeException in project snow-owl by b2ihealthcare.
the class CisSnomedIdentifierService method register.
@Override
public Map<String, SctId> register(final Set<String> componentIds) {
if (CompareUtils.isEmpty(componentIds)) {
return Collections.emptyMap();
}
LOGGER.debug("Registering {} component IDs.", componentIds.size());
final Map<String, SctId> sctIds = getSctIds(componentIds);
final Map<String, SctId> availableOrReservedSctIds = ImmutableMap.copyOf(Maps.filterValues(sctIds, Predicates.or(SctId::isAvailable, SctId::isReserved)));
if (availableOrReservedSctIds.isEmpty()) {
return Collections.emptyMap();
}
HttpPost registerRequest = null;
String currentNamespace = null;
try {
if (availableOrReservedSctIds.size() > 1) {
final Multimap<String, String> componentIdsByNamespace = toNamespaceMultimap(availableOrReservedSctIds.keySet());
for (final Entry<String, Collection<String>> entry : componentIdsByNamespace.asMap().entrySet()) {
currentNamespace = entry.getKey();
for (final Collection<String> bulkIds : Iterables.partition(entry.getValue(), requestBulkLimit)) {
LOGGER.debug("Sending bulk registration request for namespace {} with size {}.", currentNamespace, bulkIds.size());
registerRequest = httpPost(String.format("sct/bulk/register?token=%s", getToken()), createBulkRegistrationData(bulkIds));
execute(registerRequest);
}
}
} else {
final String componentId = Iterables.getOnlyElement(availableOrReservedSctIds.keySet());
currentNamespace = SnomedIdentifiers.getNamespace(componentId);
registerRequest = httpPost(String.format("sct/register?token=%s", getToken()), createRegistrationData(componentId));
execute(registerRequest);
}
return ImmutableMap.copyOf(availableOrReservedSctIds);
} catch (IOException e) {
throw new SnowowlRuntimeException(String.format("Exception while reserving IDs for namespace %s.", currentNamespace), e);
} finally {
release(registerRequest);
}
}
use of com.b2international.snowowl.core.api.SnowowlRuntimeException in project snow-owl by b2ihealthcare.
the class CisSnomedIdentifierService method deprecate.
@Override
public Map<String, SctId> deprecate(final Set<String> componentIds) {
LOGGER.debug("Deprecating {} component IDs.", componentIds.size());
final Map<String, SctId> sctIds = getSctIds(componentIds);
final Map<String, SctId> problemSctIds = ImmutableMap.copyOf(Maps.filterValues(sctIds, Predicates.<SctId>not(Predicates.or(SctId::isAssigned, SctId::isPublished, SctId::isDeprecated))));
if (!problemSctIds.isEmpty()) {
throw new SctIdStatusException("Cannot deprecate '%s' component IDs because they are not assigned, published, or already deprecated.", problemSctIds);
}
final Map<String, SctId> assignedOrPublishedSctIds = ImmutableMap.copyOf(Maps.filterValues(sctIds, Predicates.or(SctId::isAssigned, SctId::isPublished)));
if (assignedOrPublishedSctIds.isEmpty()) {
return Collections.emptyMap();
}
HttpPut deprecateRequest = null;
String currentNamespace = null;
try {
if (assignedOrPublishedSctIds.size() > 1) {
final Multimap<String, String> componentIdsByNamespace = toNamespaceMultimap(assignedOrPublishedSctIds.keySet());
for (final Entry<String, Collection<String>> entry : componentIdsByNamespace.asMap().entrySet()) {
currentNamespace = entry.getKey();
for (final Collection<String> bulkIds : Iterables.partition(entry.getValue(), requestBulkLimit)) {
LOGGER.debug("Sending bulk deprecation request for namespace {} with size {}.", currentNamespace, bulkIds.size());
deprecateRequest = httpPut(String.format("sct/bulk/deprecate?token=%s", getToken()), createBulkDeprecationData(currentNamespace, bulkIds));
execute(deprecateRequest);
}
}
} else {
final String componentId = Iterables.getOnlyElement(assignedOrPublishedSctIds.keySet());
currentNamespace = SnomedIdentifiers.getNamespace(componentId);
deprecateRequest = httpPut(String.format("sct/deprecate?token=%s", getToken()), createDeprecationData(componentId));
execute(deprecateRequest);
}
return ImmutableMap.copyOf(assignedOrPublishedSctIds);
} catch (IOException e) {
throw new SnowowlRuntimeException(String.format("Exception while deprecating IDs for namespace %s.", currentNamespace), e);
} finally {
release(deprecateRequest);
}
}
use of com.b2international.snowowl.core.api.SnowowlRuntimeException in project snow-owl by b2ihealthcare.
the class RepositoryPlugin method preRun.
@Override
public void preRun(SnowOwlConfiguration configuration, Environment env) {
if (env.isServer()) {
LOG.debug("Initializing repository plugin.");
final MeterRegistry registry = env.service(MeterRegistry.class);
final IEventBus eventBus = env.service(IEventBus.class);
// Add event bus based request metrics
registerRequestMetrics(registry, eventBus);
final IManagedContainer container = env.container();
RpcUtil.getInitialServerSession(container).registerServiceLookup(env::service);
Net4jUtil.prepareContainer(container);
JVMUtil.prepareContainer(container);
TCPUtil.prepareContainer(container);
LifecycleUtil.activate(container);
final HostAndPort hostAndPort = env.service(RepositoryConfiguration.class).getHostAndPort();
// open port in server environments
if (hostAndPort.getPort() > 0) {
// Starts the TCP transport
TCPUtil.getAcceptor(container, hostAndPort.toString());
LOG.info("Listening on {} for connections", hostAndPort);
}
// Starts the JVM transport
JVMUtil.getAcceptor(container, TransportClient.NET_4_J_CONNECTOR_NAME);
final RepositoryManager repositoryManager = new DefaultRepositoryManager();
env.services().registerService(RepositoryManager.class, repositoryManager);
env.services().registerService(RepositoryContextProvider.class, repositoryManager);
int numberOfWorkers = env.service(RepositoryConfiguration.class).getMaxThreads();
initializeRequestSupport(env, numberOfWorkers);
LOG.debug("Initialized repository plugin.");
} else {
LOG.debug("Snow Owl application is running in remote mode.");
}
if (env.isServer()) {
try {
connectSystemUser(env.container());
} catch (SnowowlServiceException e) {
throw new SnowowlRuntimeException(e);
}
}
}
Aggregations