/** * Extracts the given hash from the given request. Returns null if no hash was given. */ private String getAuthHash(WebContext ctx) { Value authorizationHeaderValue = ctx.getHeaderValue(HttpHeaderNames.AUTHORIZATION); if (!authorizationHeaderValue.isFilled()) { return ctx.get("Signature").getString(); } String authentication = Strings.isEmpty(authorizationHeaderValue.getString()) ? "" : authorizationHeaderValue.getString(); Matcher m = AWS_AUTH_PATTERN.matcher(authentication); if (m.matches()) { return m.group(2); } m = AWS_AUTH4_PATTERN.matcher(authentication); if (m.matches()) { return m.group(7); } return null; }
/** * Adds a term facet to be filled by the query. Loads the filter value directly from the given http request. * * @param field the field to scan * @param request the request to read the current filter value from * @return the query itself for fluent method calls */ public Query<E> addTermFacet(String field, WebContext request) { addTermFacet(field, request.get(field).getString()); return this; }
/** * Adds a facet filter on a date field with the given ranges as facets (buckets). * * @param field the field to filter on * @param request a request to fetch the current filter value from * @param ranges the ranges to group entities by * @return the query itself for fluent method calls */ public Query<E> addDateRangeFacet(String field, WebContext request, DateRange... ranges) { addDateRangeFacet(field, request.get(field).getString(), ranges); return this; }
/** * Adds a term facet to be filled by the query. Loads the filter value directly from the given http request. * * @param field the field to scan * @param request the request to read the current filter value from * @param translator the translator used to turn field values into visible filter values * @return the query itself for fluent method calls */ public Query<E> addTermFacet(String field, WebContext request, ValueComputer<String, String> translator) { addTermFacet(field, request.get(field).getString(), translator); return this; }
@SuppressWarnings("unchecked") @Override protected <E extends ElasticEntity> Optional<E> findEntity(Object id, EntityDescriptor ed, Function<String, Value> context) throws Exception { String routing = context.apply(CONTEXT_ROUTING).getString(); if (routing == null && isRouted(ed)) { LOG.WARN("Trying to FIND an entity of type '%s' with id '%s' without providing a routing! " + "This will most probably return an invalid result!\n%s", ed.getType().getName(), id, ExecutionPoint.snapshot()); } String index = isStoredPerYear(ed) ? determineYearIndex(ed, id.toString().substring(0, 4)) : determineIndex(ed, null); JSONObject obj = getLowLevelClient().get(index, determineTypeName(ed), id.toString(), routing, true); if (obj == null || !Boolean.TRUE.equals(obj.getBoolean(RESPONSE_FOUND))) { return Optional.empty(); } E result = (E) make(ed, obj); return Optional.of(result); }
@Override protected Object transformFromRequest(String name, WebContext ctx) { Value value = ctx.get(name); if (value.isEmptyString()) { return null; } try { return NLS.parseUserString(LocalDateTime.class, value.getString()); } catch (IllegalArgumentException e) { Exceptions.ignore(e); UserContext.setFieldError(name, value.get()); throw Exceptions.createHandled() .withNLSKey("Property.invalidInput") .set("field", NLS.get(getField().getDeclaringClass().getSimpleName() + "." + name)) .set("value", value.asString()) .handle(); } }
@Override protected Object transformFromRequest(String name, WebContext ctx) { Value value = ctx.get(name); if (value.isEmptyString()) { return null; } try { return NLS.parseUserString(LocalDate.class, value.getString()); } catch (IllegalArgumentException e) { Exceptions.ignore(e); UserContext.setFieldError(name, value.get()); throw Exceptions.createHandled() .withNLSKey("Property.invalidInput") .set("field", NLS.get(getField().getDeclaringClass().getSimpleName() + "." + name)) .set("value", value.asString()) .handle(); } }