/** * Return whether the etag should be omitted or included. * * @return */ default boolean getETag() { String value = getParameter(ETAG_PARAM_KEY); if (value != null) { return Boolean.valueOf(value); } else { return true; } }
/** * Set the fields which should be included in the response. * * @param fields * @return */ default GenericParameters setFields(String... fields) { setParameter(FIELDS_PARAM_KEY, String.join(",", fields)); return this; }
/** * Read the element with the given element by loading it from the specified root vertex. * * @param ac * @param uuid * Uuid of the element which should be loaded * @param handler * Handler which provides the root vertex which should be used when loading the element * @param perm * Permission to check against when loading the element */ public <T extends MeshCoreVertex<RM, T>, RM extends RestModel> void readElement(InternalActionContext ac, String uuid, TxAction1<RootVertex<T>> handler, GraphPermission perm) { asyncTx(ac, (tx) -> { RootVertex<T> root = handler.handle(); T element = root.loadObjectByUuid(ac, uuid, perm); // Handle etag if (ac.getGenericParameters().getETag()) { String etag = element.getETag(ac); ac.setEtag(etag, true); if (ac.matches(etag, true)) { throw new NotModifiedException(); } } return element.transformToRestSync(ac, 0); }, (model) -> ac.send(model, OK)); }
/** * Read a list of elements of the given root vertex and respond with a list response. * * @param ac * @param handler * Handler which provides the root vertex which should be used when loading the element */ public <T extends MeshCoreVertex<RM, T>, RM extends RestModel> void readElementList(InternalActionContext ac, TxAction1<RootVertex<T>> handler) { asyncTx(ac, (tx) -> { RootVertex<T> root = handler.handle(); PagingParameters pagingInfo = ac.getPagingParameters(); TransformablePage<? extends T> page = root.findAll(ac, pagingInfo); // Handle etag if (ac.getGenericParameters().getETag()) { String etag = page.getETag(ac); ac.setEtag(etag, true); if (ac.matches(etag, true)) { throw new NotModifiedException(); } } return page.transformToRest(ac, 0).blockingGet(); }, (e) -> ac.send(e, OK)); }
/** * Set the etag inclusion flag. * * @param includeEtag */ default GenericParameters setETag(boolean includeEtag) { setParameter(ETAG_PARAM_KEY, String.valueOf(includeEtag)); return this; } }
/** * Return the fields which should be included in the response. * * @return */ default FieldsSet getFields() { String value = getParameter(FIELDS_PARAM_KEY); if (value == null || value.isEmpty()) { return new FieldsSetImpl(); } else { return new FieldsSetImpl(value); } }