use of com.b2international.commons.exceptions.FormattedRuntimeException in project snow-owl by b2ihealthcare.
the class EsDocumentSearcher method fromSearchAfterToken.
private Object[] fromSearchAfterToken(final String searchAfterToken) throws BadRequestException {
if (Strings.isNullOrEmpty(searchAfterToken)) {
return null;
}
final byte[] decodedToken = Base64.getUrlDecoder().decode(searchAfterToken);
try (final DataInputStream dis = new DataInputStream(new ByteArrayInputStream(decodedToken))) {
JavaBinCodec codec = new JavaBinCodec();
List<?> obj = (List<?>) codec.unmarshal(dis);
codec.close();
return obj.toArray();
} catch (final IOException e) {
throw new FormattedRuntimeException("Couldn't decode searchAfter token.", e);
} catch (final IllegalArgumentException e) {
throw new BadRequestException("Invalid 'searchAfter' parameter value '%s'", searchAfterToken);
}
}
use of com.b2international.commons.exceptions.FormattedRuntimeException in project snow-owl by b2ihealthcare.
the class SnomedNamespaceAndModuleAssigner method create.
/**
* Instantiate a namespace and module assigner instance based on the given type.
*
* @param context
* @param assignerType
* @param moduleId
* @param namespace
* @return
*/
static SnomedNamespaceAndModuleAssigner create(ServiceProvider context, String assignerType, String moduleId, String namespace) {
SnomedNamespaceAndModuleAssigner assigner = context.service(ClassPathScanner.class).getComponentsByInterface(SnomedNamespaceAndModuleAssigner.class).stream().filter(a -> assignerType.equals(a.getName())).findFirst().orElseThrow(() -> new FormattedRuntimeException("Couldn't find namespace and module assigner '%s'.", assignerType));
assigner.init(namespace, moduleId);
return assigner;
}
use of com.b2international.commons.exceptions.FormattedRuntimeException in project snow-owl by b2ihealthcare.
the class EsDocumentSearcher method toSearchAfterToken.
private String toSearchAfterToken(final Object[] searchAfter) {
if (searchAfter == null) {
return null;
}
try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
final JavaBinCodec codec = new JavaBinCodec();
codec.marshal(searchAfter, baos);
codec.close();
final byte[] tokenBytes = baos.toByteArray();
return Base64.getUrlEncoder().encodeToString(tokenBytes);
} catch (IOException e) {
throw new FormattedRuntimeException("Couldn't encode searchAfter parameters to a token.", e);
}
}
Aggregations