Class ParaClient
java.lang.Object
com.erudika.para.client.ParaClient
- All Implemented Interfaces:
Closeable, AutoCloseable
The Java REST client for communicating with a Para API server.
- Author:
- Alex Bogdanovski [[email protected]]
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAppSetting(String key, Object value) Adds or overwrites an app-specific setting.addAppSettingAsync(String key, Object value) Adds or overwrites an app-specific setting asynchronously.addValidationConstraint(String type, String field, com.erudika.para.core.validation.Constraint c) Add a new constraint for a given field.addValidationConstraintAsync(String type, String field, com.erudika.para.core.validation.Constraint c) Add a new constraint for a given field asynchronously.approximately(long delta) Returns the number of minutes, hours, months elapsed for a time delta (milliseconds).approximatelyAsync(long delta) Returns the number of minutes, hours, months elapsed for a time delta (milliseconds) asynchronously.Returns the map containing app-specific settings.appSettings(String key) Returns the value of a specific app setting (property).Returns the map containing app-specific settings asynchronously.appSettingsAsync(String key) Returns the value of a specific app setting (property) asynchronously.voidclose()Closes the underlying Jersey client and releases resources.countChildren(com.erudika.para.core.ParaObject obj, String type2) Count the total number of child objects for this object.countChildrenAsync(com.erudika.para.core.ParaObject obj, String type2) Count the total number of child objects for this object asynchronously.countLinks(com.erudika.para.core.ParaObject obj, String type2) Count the total number of links between this object and another type of object.countLinksAsync(com.erudika.para.core.ParaObject obj, String type2) Count the total number of links between this object and another type of object asynchronously.<P extends com.erudika.para.core.ParaObject>
Pcreate(P obj) Persists an object to the data store.<P extends com.erudika.para.core.ParaObject>
List<P> Saves multiple objects to the data store.<P extends com.erudika.para.core.ParaObject>
CompletableFuture<List<P>> createAllAsync(List<P> objects) Saves multiple objects to the data store asynchronously.<P extends com.erudika.para.core.ParaObject>
CompletableFuture<P> createAsync(P obj) Persists an object to the data store asynchronously.<P extends com.erudika.para.core.ParaObject>
voiddelete(P obj) Deletes an object permanently.voidDeletes multiple objects.deleteAllAsync(List<String> keys) Deletes multiple objects asynchronously.<P extends com.erudika.para.core.ParaObject>
CompletableFuture<Void> deleteAsync(P obj) Deletes an object permanently asynchronously.voiddeleteChildren(com.erudika.para.core.ParaObject obj, String type2) Deletes all child objects permanently.deleteChildrenAsync(com.erudika.para.core.ParaObject obj, String type2) Deletes all child objects permanently asynchronously.<P extends com.erudika.para.core.ParaObject>
PSimple id search.<P extends com.erudika.para.core.ParaObject>
CompletableFuture<P> findByIdAsync(String id) Simple id search asynchronously.<P extends com.erudika.para.core.ParaObject>
List<P> Simple multi id search.<P extends com.erudika.para.core.ParaObject>
CompletableFuture<List<P>> findByIdsAsync(List<String> ids) Simple multi id search asynchronously.<P extends com.erudika.para.core.ParaObject>
List<P> findChildren(com.erudika.para.core.ParaObject obj, String type2, String query, com.erudika.para.core.utils.Pager... pager) Search through all child objects.<P extends com.erudika.para.core.ParaObject>
CompletableFuture<List<P>> findChildrenAsync(com.erudika.para.core.ParaObject obj, String type2, String query, com.erudika.para.core.utils.Pager... pager) Search through all child objects.<P extends com.erudika.para.core.ParaObject>
List<P> findLinkedObjects(com.erudika.para.core.ParaObject obj, String type2, String field, String query, com.erudika.para.core.utils.Pager... pager) Searches through all linked objects in many-to-many relationships.<P extends com.erudika.para.core.ParaObject>
CompletableFuture<List<P>> findLinkedObjectsAsync(com.erudika.para.core.ParaObject obj, String type2, String field, String query, com.erudika.para.core.utils.Pager... pager) Searches through all linked objects in many-to-many relationships asynchronously.<P extends com.erudika.para.core.ParaObject>
List<P> findNearby(String type, String query, int radius, double lat, double lng, com.erudika.para.core.utils.Pager... pager) Search forAddressobjects in a radius of X km from a given point.<P extends com.erudika.para.core.ParaObject>
CompletableFuture<List<P>> findNearbyAsync(String type, String query, int radius, double lat, double lng, com.erudika.para.core.utils.Pager... pager) Searches for objects of a given type in a given radius asynchronously.<P extends com.erudika.para.core.ParaObject>
List<P> findNestedQuery(String type, String field, String query, com.erudika.para.core.utils.Pager... pager) Searches within a nested field.<P extends com.erudika.para.core.ParaObject>
CompletableFuture<List<P>> findNestedQueryAsync(String type, String field, String query, com.erudika.para.core.utils.Pager... pager) Searches within a nested field.<P extends com.erudika.para.core.ParaObject>
List<P> findPrefix(String type, String field, String prefix, com.erudika.para.core.utils.Pager... pager) Searches for objects that have a property which value starts with a given prefix.<P extends com.erudika.para.core.ParaObject>
CompletableFuture<List<P>> findPrefixAsync(String type, String field, String prefix, com.erudika.para.core.utils.Pager... pager) Searches for objects that have a property which value starts with a given prefix asynchronously.<P extends com.erudika.para.core.ParaObject>
List<P> Simple query string search.<P extends com.erudika.para.core.ParaObject>
CompletableFuture<List<P>> findQueryAsync(String type, String query, com.erudika.para.core.utils.Pager... pager) Simple query string search.<P extends com.erudika.para.core.ParaObject>
List<P> findSimilar(String type, String filterKey, String[] fields, String liketext, com.erudika.para.core.utils.Pager... pager) Searches for objects that have similar property values to a given text.<P extends com.erudika.para.core.ParaObject>
CompletableFuture<List<P>> findSimilarAsync(String type, String filterKey, String[] fields, String liketext, com.erudika.para.core.utils.Pager... pager) Searches for objects that have similar property values to a given text.<P extends com.erudika.para.core.ParaObject>
List<P> findTagged(String type, String[] tags, com.erudika.para.core.utils.Pager... pager) Searches for objects tagged with one or more tags.<P extends com.erudika.para.core.ParaObject>
CompletableFuture<List<P>> findTaggedAsync(String type, String[] tags, com.erudika.para.core.utils.Pager... pager) Searches for objects tagged with one or more tags asynchronously.<P extends com.erudika.para.core.ParaObject>
List<P> Searches forTagobjects.<P extends com.erudika.para.core.ParaObject>
CompletableFuture<List<P>> findTagsAsync(String keyword, com.erudika.para.core.utils.Pager... pager) Searches forTagobjects asynchronously.<P extends com.erudika.para.core.ParaObject>
List<P> findTermInList(String type, String field, List<String> terms, com.erudika.para.core.utils.Pager... pager) Searches for objects having a property value that is in list of possible values.<P extends com.erudika.para.core.ParaObject>
CompletableFuture<List<P>> findTermInListAsync(String type, String field, List<String> terms, com.erudika.para.core.utils.Pager... pager) Searches for objects having a property value that is in list of possible values asynchronously.<P extends com.erudika.para.core.ParaObject>
List<P> findTerms(String type, Map<String, ?> terms, boolean matchAll, com.erudika.para.core.utils.Pager... pager) Searches for objects that have properties matching some given values.<P extends com.erudika.para.core.ParaObject>
CompletableFuture<List<P>> findTermsAsync(String type, Map<String, ?> terms, boolean matchAll, com.erudika.para.core.utils.Pager... pager) Searches for objects that have properties matching some given values.<P extends com.erudika.para.core.ParaObject>
List<P> findWildcard(String type, String field, String wildcard, com.erudika.para.core.utils.Pager... pager) Searches for objects that have a property with a value matching a wildcard query.<P extends com.erudika.para.core.ParaObject>
CompletableFuture<List<P>> findWildcardAsync(String type, String field, String wildcard, com.erudika.para.core.utils.Pager... pager) Searches for objects that have a property with a value matching a wildcard query asynchronously.formatDate(String format, Locale loc) Formats a date in a specific format.formatDateAsync(String format, Locale loc) Formats a date in a specific format asynchronously.Returns the JWT access token if any.Returns the API request path.com.erudika.para.core.AppgetApp()Returns theAppfor the current access key (appid).CompletableFuture<com.erudika.para.core.App> Returns theAppfor the current access key (appid) asynchronously.<P extends com.erudika.para.core.ParaObject>
List<P> getChildren(com.erudika.para.core.ParaObject obj, String type2, com.erudika.para.core.utils.Pager... pager) Returns all child objects linked to this object.<P extends com.erudika.para.core.ParaObject>
List<P> getChildren(com.erudika.para.core.ParaObject obj, String type2, String field, String term, com.erudika.para.core.utils.Pager... pager) Returns all child objects linked to this object.<P extends com.erudika.para.core.ParaObject>
CompletableFuture<List<P>> getChildrenAsync(com.erudika.para.core.ParaObject obj, String type2, com.erudika.para.core.utils.Pager... pager) Returns all child objects linked to this object asynchronously.<P extends com.erudika.para.core.ParaObject>
CompletableFuture<List<P>> getChildrenAsync(com.erudika.para.core.ParaObject obj, String type2, String field, String term, com.erudika.para.core.utils.Pager... pager) Returns all child objects linked to this object asynchronously.intReturns the batch chunk size.Counts indexed objects.Counts indexed objects matching a set of terms/values.getCountAsync(String type) Counts indexed objects asynchronously.getCountAsync(String type, Map<String, ?> terms) Counts indexed objects matching a set of terms/values asynchronously.Returns the endpoint URL.<P extends com.erudika.para.core.ParaObject>
List<P> Converts a list of Maps to a List of ParaObjects, at a given path within the JSON tree structure.<P extends com.erudika.para.core.ParaObject>
List<P> getItemsFromList(List<?> result) Deserializes ParaObjects from a JSON array (the "items:[]" field in search results).<P extends com.erudika.para.core.ParaObject>
List<P> getLinkedObjects(com.erudika.para.core.ParaObject obj, String type2, com.erudika.para.core.utils.Pager... pager) Returns all objects linked to the given one.<P extends com.erudika.para.core.ParaObject>
CompletableFuture<List<P>> getLinkedObjectsAsync(com.erudika.para.core.ParaObject obj, String type2, com.erudika.para.core.utils.Pager... pager) Returns all objects linked to the given one.Returns the Para server version.Returns the Para server version asynchronously.longReturns the current timestamp.Returns the current timestamp asynchronously.grantResourcePermission(String subjectid, String resourcePath, EnumSet<com.erudika.para.core.App.AllowedMethods> permission) Grants a permission to a subject that allows them to call the specified HTTP methods on a given resource.grantResourcePermission(String subjectid, String resourcePath, EnumSet<com.erudika.para.core.App.AllowedMethods> permission, boolean allowGuestAccess) Grants a permission to a subject that allows them to call the specified HTTP methods on a given resource.grantResourcePermissionAsync(String subjectid, String resourcePath, EnumSet<com.erudika.para.core.App.AllowedMethods> permission) Grants a permission to a subject that allows them to call the specified HTTP methods on a given resource asynchronously.grantResourcePermissionAsync(String subjectid, String resourcePath, EnumSet<com.erudika.para.core.App.AllowedMethods> permission, boolean allowGuestAccess) Grants a permission to a subject that allows them to call the specified HTTP methods on a given resource asynchronously.<T> TInvoke a DELETE request to the Para API.<T> CompletableFuture<T> Invoke a DELETE request to the Para API asynchronously.<T> TInvoke a GET request to the Para API.<T> CompletableFuture<T> Invoke a GET request to the Para API asynchronously.<T> TinvokePatch(String resourcePath, Object entity, Class<?> returnType) Invoke a PATCH request to the Para API.<T> CompletableFuture<T> invokePatchAsync(String resourcePath, Object entity, Class<?> returnType) Invoke a PATCH request to the Para API asynchronously.<T> TinvokePost(String resourcePath, Object entity, Class<?> returnType) Invoke a POST request to the Para API.<T> CompletableFuture<T> invokePostAsync(String resourcePath, Object entity, Class<?> returnType) Invoke a POST request to the Para API asynchronously.<T> TInvoke a PUT request to the Para API.<T> CompletableFuture<T> invokePutAsync(String resourcePath, Object entity, Class<?> returnType) Invoke a PUT request to the Para API asynchronously.booleanisAllowedTo(String subjectid, String resourcePath, String httpMethod) Checks if a subject is allowed to call method X on resource Y.isAllowedToAsync(String subjectid, String resourcePath, String httpMethod) Checks if a subject is allowed to call method X on resource Y asynchronously.booleanisLinked(com.erudika.para.core.ParaObject obj, com.erudika.para.core.ParaObject toObj) Checks if a given object is linked to this one.booleanChecks if this object is linked to another.isLinkedAsync(com.erudika.para.core.ParaObject obj, com.erudika.para.core.ParaObject toObj) Checks if a given object is linked to this one asynchronously.isLinkedAsync(com.erudika.para.core.ParaObject obj, String type2, String id2) Checks if this object is linked to another asynchronously.Links an object to this one in a many-to-many relationship.Links an object to this one in a many-to-many relationship asynchronously.<P extends com.erudika.para.core.ParaObject>
List<P> Returns a list all objects found for the given type.<P extends com.erudika.para.core.ParaObject>
CompletableFuture<List<P>> Returns a list all objects found for the given type asynchronously.markdownToHtml(String markdownString) Converts Markdown to HTML.markdownToHtmlAsync(String markdownString) Converts Markdown to HTML asynchronously.<P extends com.erudika.para.core.ParaObject>
Pme()Returns aUseror anAppthat is currently authenticated.<P extends com.erudika.para.core.ParaObject>
PVerifies a given JWT and returns the authenticated subject.<P extends com.erudika.para.core.ParaObject>
CompletableFuture<P> meAsync()Returns aUseror anAppthat is currently authenticated asynchronously.<P extends com.erudika.para.core.ParaObject>
CompletableFuture<P> Verifies a given JWT and returns the authenticated subject.newId()Generates a new unique id.Generates a new unique id asynchronously.newKeys()Generates a new set of access/secret keys.Generates a new set of access/secret keys asynchronously.Converts spaces to dashes.noSpacesAsync(String str, String replaceWith) Converts spaces to dashes asynchronously.pagerToParams(com.erudika.para.core.utils.Pager... pager) Converts aPagerobject to query parameters.<P extends com.erudika.para.core.ParaObject>
PRetrieves an object from the data store.<P extends com.erudika.para.core.ParaObject>
PRetrieves an object from the data store.<P extends com.erudika.para.core.ParaObject>
List<P> Retrieves multiple objects from the data store.<P extends com.erudika.para.core.ParaObject>
CompletableFuture<List<P>> readAllAsync(List<String> keys) Retrieves multiple objects from the data store asynchronously.<P extends com.erudika.para.core.ParaObject>
CompletableFuture<P> Retrieves an object from the data store asynchronously.<P extends com.erudika.para.core.ParaObject>
CompletableFuture<P> Retrieves an object from the data store asynchronously.<T extends com.erudika.para.core.ParaObject>
voidreadEverything(Function<com.erudika.para.core.utils.Pager, List<T>> paginatingFunc) Paginates through all objects and executes the provided function on the results.<T extends com.erudika.para.core.ParaObject>
voidreadEverything(Function<com.erudika.para.core.utils.Pager, List<T>> paginatingFunc, int pageSize) Paginates through all objects and executes the provided function on the results.Rebuilds the entire search index.rebuildIndex(String destinationIndex) Rebuilds the entire search index.Rebuilds the entire search index asynchronously.rebuildIndexAsync(String destinationIndex) Rebuilds the entire search index asynchronously.voidremoveAppSetting(String key) Removes an app-specific setting.Removes an app-specific setting asynchronously.removeValidationConstraint(String type, String field, String constraintName) Removes a validation constraint for a given field.removeValidationConstraintAsync(String type, String field, String constraintName) Removes a validation constraint for a given field asynchronously.Returns the permissions for all subjects and resources for current app.resourcePermissions(String subjectid) Returns only the permissions for a given subject (user) of the current app.Returns the permissions for all subjects and resources for current app asynchronously.resourcePermissionsAsync(String subjectid) Returns only the permissions for a given subject (user) of the current app asynchronously.revokeAllResourcePermissions(String subjectid) Revokes all permission for a subject.revokeAllResourcePermissionsAsync(String subjectid) Revokes all permission for a subject asynchronously.booleanRevokes all user tokens for a given user id.Revokes all user tokens for a given user id asynchronously.revokeResourcePermission(String subjectid, String resourcePath) Revokes a permission for a subject, meaning they no longer will be able to access the given resource.revokeResourcePermissionAsync(String subjectid, String resourcePath) Revokes a permission for a subject, meaning they no longer will be able to access the given resource asynchronously.booleansendEmail(List<String> toEmails, String subject, String fromEmail, String senderName, String message) Endpoint for sending transactional emails.booleansendEmail(List<String> toEmails, String subject, String fromEmail, String senderName, String message, boolean plaintextOnly, boolean markdownEnabled, InputStream file, String fileContentType) Endpoint for sending transactional emails.sendEmailAsync(List<String> toEmails, String subject, String fromEmail, String senderName, String message) Endpoint for sending transactional emails asynchronously.sendEmailAsync(List<String> toEmails, String subject, String fromEmail, String senderName, String message, boolean plaintextOnly, boolean markdownEnabled, InputStream file, String fileContentType) Endpoint for sending transactional emails asynchronously.voidsetAccessToken(String token) Sets the JWT access token.voidsetApiPath(String path) Sets the API request path.voidsetAppSettings(Map<?, ?> settings) Overwrites all app-specific settings.setAppSettingsAsync(Map<?, ?> settings) Overwrites all app-specific settings asynchronously.voidsetChunkSize(int chunkSize) Sets the chunk size for batch CRUD operations.voidsetEndpoint(String endpoint) Sets the host URL of the Para server.com.erudika.para.core.UserTakes an identity provider access token and fetches the user data from that provider.com.erudika.para.core.UserTakes an identity provider access token and fetches the user data from that provider.CompletableFuture<com.erudika.para.core.User> signInAsync(String provider, String providerToken) Takes an identity provider access token and fetches the user data from that provider asynchronously.CompletableFuture<com.erudika.para.core.User> signInAsync(String provider, String providerToken, boolean rememberJWT) Takes an identity provider access token and fetches the user data from that provider asynchronously.voidsignOut()Clears the JWT access token but token is not revoked.stripAndTrim(String str) Strips all symbols, punctuation, whitespace and control chars from a string.stripAndTrimAsync(String str) Strips all symbols, punctuation, whitespace and control chars from a string asynchronously.voidthrowExceptionOnHTTPError(boolean enabled) Enable/disable exception throwing in ParaClient.types()Returns all registered types for this App.Returns all registered types for this App asynchronously.Returns the number of objects for each existing type in this App.Returns the number of objects for each existing type in this App asynchronously.voidUnlinks an object from this one.voidunlinkAll(com.erudika.para.core.ParaObject obj) Unlinks all objects that are linked to this one.unlinkAllAsync(com.erudika.para.core.ParaObject obj) Unlinks all objects that are linked to this one asynchronously.unlinkAsync(com.erudika.para.core.ParaObject obj, String type2, String id2) Unlinks an object from this one asynchronously.<P extends com.erudika.para.core.ParaObject>
Pupdate(P obj) Updates an object permanently.<P extends com.erudika.para.core.ParaObject>
List<P> Updates multiple objects.<P extends com.erudika.para.core.ParaObject>
CompletableFuture<List<P>> updateAllAsync(List<P> objects) Updates multiple objects asynchronously.<T extends com.erudika.para.core.ParaObject>
CompletableFuture<Void> updateAllPartially(BiFunction<List<Map<String, Object>>, com.erudika.para.core.utils.Pager, List<T>> paginatingFunc) Performs a partial batch update (async) on all objects of given type.<T extends com.erudika.para.core.ParaObject>
CompletableFuture<Void> updateAllPartially(BiFunction<List<Map<String, Object>>, com.erudika.para.core.utils.Pager, List<T>> paginatingFunc, int pageSize, int updateBatchSize) Performs a partial batch update on all objects of given type.<P extends com.erudika.para.core.ParaObject>
CompletableFuture<P> updateAsync(P obj) Updates an object permanently asynchronously.Returns the validation constraints map.validationConstraints(String type) Returns the validation constraints map.Returns the validation constraints map asynchronously.Returns the validation constraints map asynchronously.booleanDownvote an object and register the vote in DB.booleanvoteDown(com.erudika.para.core.ParaObject obj, String voterid, Integer expiresAfter, Integer lockedAfter) Downvote an object and register the vote in DB.voteDownAsync(com.erudika.para.core.ParaObject obj, String voterid) Downvote an object and register the vote in DB asynchronously.voteDownAsync(com.erudika.para.core.ParaObject obj, String voterid, Integer expiresAfter, Integer lockedAfter) Downvote an object and register the vote in DB asynchronously.booleanUpvote an object and register the vote in DB.booleanvoteUp(com.erudika.para.core.ParaObject obj, String voterid, Integer expiresAfter, Integer lockedAfter) Upvote an object and register the vote in DB.voteUpAsync(com.erudika.para.core.ParaObject obj, String voterid) Upvote an object and register the vote in DB asynchronously.voteUpAsync(com.erudika.para.core.ParaObject obj, String voterid, Integer expiresAfter, Integer lockedAfter) Upvote an object and register the vote in DB asynchronously.
-
Constructor Details
-
ParaClient
-
-
Method Details
-
setEndpoint
Sets the host URL of the Para server.- Parameters:
endpoint- the Para server location
-
close
public void close()Closes the underlying Jersey client and releases resources.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
getApp
public com.erudika.para.core.App getApp()Returns theAppfor the current access key (appid).- Returns:
- the App object
-
getAppAsync
Returns theAppfor the current access key (appid) asynchronously.- Returns:
- a future of the App object
-
getEndpoint
-
setApiPath
-
getApiPath
Returns the API request path.- Returns:
- the request path without parameters
-
getAccessToken
Returns the JWT access token if any.- Returns:
- the JWT access token, or null if not signed in
-
getServerVersion
Returns the Para server version.- Returns:
- the version of Para server
-
getServerVersionAsync
Returns the Para server version asynchronously.- Returns:
- a future of the version of Para server
-
setAccessToken
Sets the JWT access token.- Parameters:
token- a valid token
-
setChunkSize
public void setChunkSize(int chunkSize) Sets the chunk size for batch CRUD operations. If chunkSize is greater than zero, any requests made to createAll(), readAll(), updateAll() and deleteAll() will be partitioned into chunks equal to this size. The chunked requests made to Para Server will be executed synchronously, and the results of all chunk operations are aggregated into a single response.- Parameters:
chunkSize- the number of objects per chunk
-
getChunkSize
public int getChunkSize()Returns the batch chunk size.- Returns:
- the chunk size used for batch CRUD operations
-
throwExceptionOnHTTPError
public void throwExceptionOnHTTPError(boolean enabled) Enable/disable exception throwing in ParaClient.- Parameters:
enabled- if true, the client will throw an exception when an error response is received. If false, the error is only logged. Default is false.
-
invokeGet
Invoke a GET request to the Para API.- Type Parameters:
T- return type- Parameters:
resourcePath- the subpath after '/v1/', should not start with '/'params- query parametersreturnType- the type of object to return- Returns:
- a POJO
-
invokePost
Invoke a POST request to the Para API.- Type Parameters:
T- return type- Parameters:
resourcePath- the subpath after '/v1/', should not start with '/'entity- request bodyreturnType- the type of object to return- Returns:
- a POJO
-
invokePut
Invoke a PUT request to the Para API.- Type Parameters:
T- return type- Parameters:
resourcePath- the subpath after '/v1/', should not start with '/'entity- request bodyreturnType- the type of object to return- Returns:
- a POJO
-
invokePatch
Invoke a PATCH request to the Para API.- Type Parameters:
T- return type- Parameters:
resourcePath- the subpath after '/v1/', should not start with '/'entity- request bodyreturnType- the type of object to return- Returns:
- a POJO
-
invokeDelete
public <T> T invokeDelete(String resourcePath, Map<String, List<String>> params, Class<?> returnType) Invoke a DELETE request to the Para API.- Type Parameters:
T- return type- Parameters:
resourcePath- the subpath after '/v1/', should not start with '/'params- query parametersreturnType- the type of object to return- Returns:
- a POJO
-
invokeGetAsync
public <T> CompletableFuture<T> invokeGetAsync(String resourcePath, Map<String, List<String>> params, Class<?> returnType) Invoke a GET request to the Para API asynchronously.- Type Parameters:
T- return type- Parameters:
resourcePath- the subpath after '/v1/', should not start with '/'params- query parametersreturnType- the type of object to return- Returns:
- a future of a POJO
-
invokePostAsync
public <T> CompletableFuture<T> invokePostAsync(String resourcePath, Object entity, Class<?> returnType) Invoke a POST request to the Para API asynchronously.- Type Parameters:
T- return type- Parameters:
resourcePath- the subpath after '/v1/', should not start with '/'entity- request bodyreturnType- the type of object to return- Returns:
- a future of a POJO
-
invokePutAsync
public <T> CompletableFuture<T> invokePutAsync(String resourcePath, Object entity, Class<?> returnType) Invoke a PUT request to the Para API asynchronously.- Type Parameters:
T- return type- Parameters:
resourcePath- the subpath after '/v1/', should not start with '/'entity- request bodyreturnType- the type of object to return- Returns:
- a future of a POJO
-
invokePatchAsync
public <T> CompletableFuture<T> invokePatchAsync(String resourcePath, Object entity, Class<?> returnType) Invoke a PATCH request to the Para API asynchronously.- Type Parameters:
T- return type- Parameters:
resourcePath- the subpath after '/v1/', should not start with '/'entity- request bodyreturnType- the type of object to return- Returns:
- a future of a POJO
-
invokeDeleteAsync
public <T> CompletableFuture<T> invokeDeleteAsync(String resourcePath, Map<String, List<String>> params, Class<?> returnType) Invoke a DELETE request to the Para API asynchronously.- Type Parameters:
T- return type- Parameters:
resourcePath- the subpath after '/v1/', should not start with '/'params- query parametersreturnType- the type of object to return- Returns:
- a future of a POJO
-
pagerToParams
-
getItemsFromList
-
getItems
public <P extends com.erudika.para.core.ParaObject> List<P> getItems(String at, Map<String, Object> result, com.erudika.para.core.utils.Pager... pager) Converts a list of Maps to a List of ParaObjects, at a given path within the JSON tree structure.- Type Parameters:
P- type- Parameters:
at- the path (field) where the array of objects is locatedresult- the response body for an API requestpager- aPagerobject- Returns:
- a list of ParaObjects
-
create
public <P extends com.erudika.para.core.ParaObject> P create(P obj) Persists an object to the data store. If the object's type and id are given, then the request will be aPUTrequest and any existing object will be overwritten.- Type Parameters:
P- the type of object- Parameters:
obj- the domain object- Returns:
- the same object with assigned id or null if not created.
-
createAsync
Persists an object to the data store asynchronously.- Type Parameters:
P- the type of object- Parameters:
obj- the domain object- Returns:
- a future of the same object with assigned id or null if not created
-
read
-
readAsync
public <P extends com.erudika.para.core.ParaObject> CompletableFuture<P> readAsync(String type, String id) Retrieves an object from the data store asynchronously.- Type Parameters:
P- the type of object- Parameters:
type- the type of the objectid- the id of the object- Returns:
- a future of the retrieved object or null if not found
-
read
Retrieves an object from the data store.- Type Parameters:
P- the type of object- Parameters:
id- the id of the object- Returns:
- the retrieved object or null if not found
-
readAsync
Retrieves an object from the data store asynchronously.- Type Parameters:
P- the type of object- Parameters:
id- the id of the object- Returns:
- a future of the retrieved object or null if not found
-
update
public <P extends com.erudika.para.core.ParaObject> P update(P obj) Updates an object permanently. Supports partial updates.- Type Parameters:
P- the type of object- Parameters:
obj- the object to update- Returns:
- the updated object
-
updateAsync
Updates an object permanently asynchronously. Supports partial updates.- Type Parameters:
P- the type of object- Parameters:
obj- the object to update- Returns:
- a future of the updated object
-
delete
public <P extends com.erudika.para.core.ParaObject> void delete(P obj) Deletes an object permanently.- Type Parameters:
P- the type of object- Parameters:
obj- the object
-
deleteAsync
Deletes an object permanently asynchronously.- Type Parameters:
P- the type of object- Parameters:
obj- the object- Returns:
- a future completed when the delete request finishes
-
createAll
-
createAllAsync
public <P extends com.erudika.para.core.ParaObject> CompletableFuture<List<P>> createAllAsync(List<P> objects) Saves multiple objects to the data store asynchronously.- Type Parameters:
P- the type of object- Parameters:
objects- the list of objects to save- Returns:
- a future of a list of objects
-
readAll
-
readAllAsync
public <P extends com.erudika.para.core.ParaObject> CompletableFuture<List<P>> readAllAsync(List<String> keys) Retrieves multiple objects from the data store asynchronously.- Type Parameters:
P- the type of object- Parameters:
keys- a list of object ids- Returns:
- a future of a list of objects
-
updateAll
-
updateAllAsync
public <P extends com.erudika.para.core.ParaObject> CompletableFuture<List<P>> updateAllAsync(List<P> objects) Updates multiple objects asynchronously.- Type Parameters:
P- the type of object- Parameters:
objects- the objects to update- Returns:
- a future of a list of objects
-
deleteAll
-
deleteAllAsync
Deletes multiple objects asynchronously.- Parameters:
keys- the ids of the objects to delete- Returns:
- a future completed when all chunks finish
-
list
public <P extends com.erudika.para.core.ParaObject> List<P> list(String type, com.erudika.para.core.utils.Pager... pager) Returns a list all objects found for the given type. The result is paginated so only one page of items is returned, at a time.- Type Parameters:
P- the type of object- Parameters:
type- the type of objects to search forpager- aPager- Returns:
- a list of objects
-
listAsync
public <P extends com.erudika.para.core.ParaObject> CompletableFuture<List<P>> listAsync(String type, com.erudika.para.core.utils.Pager... pager) Returns a list all objects found for the given type asynchronously.- Type Parameters:
P- the type of object- Parameters:
type- the type of objects to search forpager- a Pager- Returns:
- a future of a list of objects
-
findById
Simple id search.- Type Parameters:
P- type of the object- Parameters:
id- the id- Returns:
- the object if found or null
-
findByIdAsync
Simple id search asynchronously.- Type Parameters:
P- type of the object- Parameters:
id- the id- Returns:
- a future of the object if found or null
-
findByIds
-
findByIdsAsync
public <P extends com.erudika.para.core.ParaObject> CompletableFuture<List<P>> findByIdsAsync(List<String> ids) Simple multi id search asynchronously.- Type Parameters:
P- type of the object- Parameters:
ids- a list of ids to search for- Returns:
- a future of a list of objects found
-
findNearby
public <P extends com.erudika.para.core.ParaObject> List<P> findNearby(String type, String query, int radius, double lat, double lng, com.erudika.para.core.utils.Pager... pager) Search forAddressobjects in a radius of X km from a given point.- Type Parameters:
P- type of the object- Parameters:
type- the type of object to search for. SeeParaObject.getType()query- the query stringradius- the radius of the search circlelat- latitudelng- longitudepager- aPager- Returns:
- a list of objects found
-
findNearbyAsync
public <P extends com.erudika.para.core.ParaObject> CompletableFuture<List<P>> findNearbyAsync(String type, String query, int radius, double lat, double lng, com.erudika.para.core.utils.Pager... pager) Searches for objects of a given type in a given radius asynchronously.- Type Parameters:
P- type of the object- Parameters:
type- the type of object to search for. SeeParaObject.getType()query- the query stringradius- the radius of the search circlelat- latitudelng- longitudepager- aPager- Returns:
- a future of a list of objects found
-
findPrefix
public <P extends com.erudika.para.core.ParaObject> List<P> findPrefix(String type, String field, String prefix, com.erudika.para.core.utils.Pager... pager) Searches for objects that have a property which value starts with a given prefix.- Type Parameters:
P- type of the object- Parameters:
type- the type of object to search for. SeeParaObject.getType()field- the property name of an objectprefix- the prefixpager- aPager- Returns:
- a list of objects found
-
findPrefixAsync
public <P extends com.erudika.para.core.ParaObject> CompletableFuture<List<P>> findPrefixAsync(String type, String field, String prefix, com.erudika.para.core.utils.Pager... pager) Searches for objects that have a property which value starts with a given prefix asynchronously.- Type Parameters:
P- type of the object- Parameters:
type- the type of object to search for. SeeParaObject.getType()field- the property name of an objectprefix- the prefixpager- aPager- Returns:
- a future of a list of objects found
-
findQuery
public <P extends com.erudika.para.core.ParaObject> List<P> findQuery(String type, String query, com.erudika.para.core.utils.Pager... pager) Simple query string search. This is the basic search method.- Type Parameters:
P- type of the object- Parameters:
type- the type of object to search for. SeeParaObject.getType()query- the query stringpager- aPager- Returns:
- a list of objects found
-
findQueryAsync
public <P extends com.erudika.para.core.ParaObject> CompletableFuture<List<P>> findQueryAsync(String type, String query, com.erudika.para.core.utils.Pager... pager) Simple query string search. This is the basic search method asynchronously.- Type Parameters:
P- type of the object- Parameters:
type- the type of object to search for. SeeParaObject.getType()query- the query stringpager- aPager- Returns:
- a future of a list of objects found
-
findNestedQuery
public <P extends com.erudika.para.core.ParaObject> List<P> findNestedQuery(String type, String field, String query, com.erudika.para.core.utils.Pager... pager) Searches within a nested field. The objects of the given type must contain a nested field "nstd".- Type Parameters:
P- type of the object- Parameters:
type- the type of object to search for. SeeParaObject.getType()field- the name of the field to target (within a nested field "nstd")query- the query stringpager- aPager- Returns:
- a list of objects found
-
findNestedQueryAsync
public <P extends com.erudika.para.core.ParaObject> CompletableFuture<List<P>> findNestedQueryAsync(String type, String field, String query, com.erudika.para.core.utils.Pager... pager) Searches within a nested field. The objects of the given type must contain a nested field "nstd" asynchronously.- Type Parameters:
P- type of the object- Parameters:
type- the type of object to search for. SeeParaObject.getType()field- the name of the field to target (within a nested field "nstd")query- the query stringpager- aPager- Returns:
- a future of a list of objects found
-
findSimilar
public <P extends com.erudika.para.core.ParaObject> List<P> findSimilar(String type, String filterKey, String[] fields, String liketext, com.erudika.para.core.utils.Pager... pager) Searches for objects that have similar property values to a given text. A "find like this" query.- Type Parameters:
P- type of the object- Parameters:
type- the type of object to search for. SeeParaObject.getType()filterKey- exclude an object with this key from the results (optional)fields- a list of property namesliketext- text to compare topager- aPager- Returns:
- a list of objects found
-
findSimilarAsync
public <P extends com.erudika.para.core.ParaObject> CompletableFuture<List<P>> findSimilarAsync(String type, String filterKey, String[] fields, String liketext, com.erudika.para.core.utils.Pager... pager) Searches for objects that have similar property values to a given text. A "find like this" query asynchronously.- Type Parameters:
P- type of the object- Parameters:
type- the type of object to search for. SeeParaObject.getType()filterKey- exclude an object with this key from the results (optional)fields- a list of property namesliketext- text to compare topager- aPager- Returns:
- a future of a list of objects found
-
findTagged
public <P extends com.erudika.para.core.ParaObject> List<P> findTagged(String type, String[] tags, com.erudika.para.core.utils.Pager... pager) Searches for objects tagged with one or more tags.- Type Parameters:
P- type of the object- Parameters:
type- the type of object to search for. SeeParaObject.getType()tags- the list of tagspager- aPager- Returns:
- a list of objects found
-
findTaggedAsync
public <P extends com.erudika.para.core.ParaObject> CompletableFuture<List<P>> findTaggedAsync(String type, String[] tags, com.erudika.para.core.utils.Pager... pager) Searches for objects tagged with one or more tags asynchronously.- Type Parameters:
P- type of the object- Parameters:
type- the type of object to search for. SeeParaObject.getType()tags- the list of tagspager- aPager- Returns:
- a future of a list of objects found
-
findTags
public <P extends com.erudika.para.core.ParaObject> List<P> findTags(String keyword, com.erudika.para.core.utils.Pager... pager) Searches forTagobjects. This method might be deprecated in the future.- Type Parameters:
P- type of the object- Parameters:
keyword- the tag keyword to search forpager- aPager- Returns:
- a list of objects found
-
findTagsAsync
public <P extends com.erudika.para.core.ParaObject> CompletableFuture<List<P>> findTagsAsync(String keyword, com.erudika.para.core.utils.Pager... pager) Searches forTagobjects asynchronously. This method might be deprecated in the future.- Type Parameters:
P- type of the object- Parameters:
keyword- the tag keyword to search forpager- aPager- Returns:
- a future of a list of objects found
-
findTermInList
public <P extends com.erudika.para.core.ParaObject> List<P> findTermInList(String type, String field, List<String> terms, com.erudika.para.core.utils.Pager... pager) Searches for objects having a property value that is in list of possible values.- Type Parameters:
P- type of the object- Parameters:
type- the type of object to search for. SeeParaObject.getType()field- the property name of an objectterms- a list of terms (property values)pager- aPager- Returns:
- a list of objects found
-
findTermInListAsync
public <P extends com.erudika.para.core.ParaObject> CompletableFuture<List<P>> findTermInListAsync(String type, String field, List<String> terms, com.erudika.para.core.utils.Pager... pager) Searches for objects having a property value that is in list of possible values asynchronously.- Type Parameters:
P- type of the object- Parameters:
type- the type of object to search for. SeeParaObject.getType()field- the property name of an objectterms- a list of terms (property values)pager- aPager- Returns:
- a future of a list of objects found
-
findTerms
public <P extends com.erudika.para.core.ParaObject> List<P> findTerms(String type, Map<String, ?> terms, boolean matchAll, com.erudika.para.core.utils.Pager... pager) Searches for objects that have properties matching some given values. A terms query asynchronously.- Type Parameters:
P- type of the object- Parameters:
type- the type of object to search for. SeeParaObject.getType()terms- a map of fields (property names) to terms (property values)matchAll- match all terms. If true - AND search, if false - OR searchpager- aPager- Returns:
- a future of a list of objects found
-
findTermsAsync
public <P extends com.erudika.para.core.ParaObject> CompletableFuture<List<P>> findTermsAsync(String type, Map<String, ?> terms, boolean matchAll, com.erudika.para.core.utils.Pager... pager) Searches for objects that have properties matching some given values. A terms query asynchronously.- Type Parameters:
P- type of the object- Parameters:
type- the type of object to search for. SeeParaObject.getType()terms- a map of fields (property names) to terms (property values)matchAll- match all terms. If true - AND search, if false - OR searchpager- aPager- Returns:
- a future of a list of objects found
-
findWildcard
public <P extends com.erudika.para.core.ParaObject> List<P> findWildcard(String type, String field, String wildcard, com.erudika.para.core.utils.Pager... pager) Searches for objects that have a property with a value matching a wildcard query.- Type Parameters:
P- type of the object- Parameters:
type- the type of object to search for. SeeParaObject.getType()field- the property name of an objectwildcard- wildcard query string. For example "cat*".pager- aPager- Returns:
- a list of objects found
-
findWildcardAsync
public <P extends com.erudika.para.core.ParaObject> CompletableFuture<List<P>> findWildcardAsync(String type, String field, String wildcard, com.erudika.para.core.utils.Pager... pager) Searches for objects that have a property with a value matching a wildcard query asynchronously.- Type Parameters:
P- type of the object- Parameters:
type- the type of object to search for. SeeParaObject.getType()field- the property name of an objectwildcard- wildcard query string. For example "cat*".pager- aPager- Returns:
- a future of a list of objects found
-
getCount
-
getCountAsync
Counts indexed objects asynchronously.- Parameters:
type- the type of object to search for. SeeParaObject.getType()- Returns:
- a future of the number of results found
-
getCount
-
getCountAsync
Counts indexed objects matching a set of terms/values asynchronously.- Parameters:
type- the type of object to search for. SeeParaObject.getType()terms- a list of terms (property values)- Returns:
- a future of the number of results found
-
countLinks
-
countLinksAsync
Count the total number of links between this object and another type of object asynchronously.- Parameters:
obj- the object to execute this method ontype2- the other type of object- Returns:
- a future of the number of links for the given object
-
getLinkedObjects
public <P extends com.erudika.para.core.ParaObject> List<P> getLinkedObjects(com.erudika.para.core.ParaObject obj, String type2, com.erudika.para.core.utils.Pager... pager) Returns all objects linked to the given one. Only applicable to many-to-many relationships.- Type Parameters:
P- type of linked objects- Parameters:
obj- the object to execute this method ontype2- type of linked objects to search forpager- aPager- Returns:
- a list of linked objects
-
getLinkedObjectsAsync
public <P extends com.erudika.para.core.ParaObject> CompletableFuture<List<P>> getLinkedObjectsAsync(com.erudika.para.core.ParaObject obj, String type2, com.erudika.para.core.utils.Pager... pager) Returns all objects linked to the given one. Only applicable to many-to-many relationships asynchronously.- Type Parameters:
P- type of linked objects- Parameters:
obj- the object to execute this method ontype2- type of linked objects to search forpager- aPager- Returns:
- a future of a list of linked objects
-
findLinkedObjects
public <P extends com.erudika.para.core.ParaObject> List<P> findLinkedObjects(com.erudika.para.core.ParaObject obj, String type2, String field, String query, com.erudika.para.core.utils.Pager... pager) Searches through all linked objects in many-to-many relationships.- Type Parameters:
P- type of linked objects- Parameters:
obj- the object to execute this method ontype2- type of linked objects to search forfield- the name of the field to target (within a nested field "nstd")query- a query stringpager- aPager- Returns:
- a list of linked objects matching the search query
-
findLinkedObjectsAsync
public <P extends com.erudika.para.core.ParaObject> CompletableFuture<List<P>> findLinkedObjectsAsync(com.erudika.para.core.ParaObject obj, String type2, String field, String query, com.erudika.para.core.utils.Pager... pager) Searches through all linked objects in many-to-many relationships asynchronously.- Type Parameters:
P- type of linked objects- Parameters:
obj- the object to execute this method ontype2- type of linked objects to search forfield- the name of the field to target (within a nested field "nstd")query- a query stringpager- aPager- Returns:
- a future of a list of linked objects matching the search query
-
isLinked
-
isLinkedAsync
public CompletableFuture<Boolean> isLinkedAsync(com.erudika.para.core.ParaObject obj, String type2, String id2) Checks if this object is linked to another asynchronously.- Parameters:
obj- the object to execute this method ontype2- the other typeid2- the other id- Returns:
- a future of true if the two are linked
-
isLinked
public boolean isLinked(com.erudika.para.core.ParaObject obj, com.erudika.para.core.ParaObject toObj) Checks if a given object is linked to this one.- Parameters:
obj- the object to execute this method ontoObj- the other object- Returns:
- true if linked
-
isLinkedAsync
public CompletableFuture<Boolean> isLinkedAsync(com.erudika.para.core.ParaObject obj, com.erudika.para.core.ParaObject toObj) Checks if a given object is linked to this one asynchronously.- Parameters:
obj- the object to execute this method ontoObj- the other object- Returns:
- a future of true if linked
-
link
Links an object to this one in a many-to-many relationship. Only a link is created. Objects are left untouched. The type of the second object is automatically determined on read.- Parameters:
obj- the object to execute this method onid2- link to the object with this id- Returns:
- the id of the
Linkerobject that is created
-
linkAsync
Links an object to this one in a many-to-many relationship asynchronously. Only a link is created. Objects are left untouched. The type of the second object is automatically determined on read.- Parameters:
obj- the object to execute this method onid2- link to the object with this id- Returns:
- a future of the id of the
Linkerobject that is created
-
unlink
-
unlinkAsync
public CompletableFuture<Void> unlinkAsync(com.erudika.para.core.ParaObject obj, String type2, String id2) Unlinks an object from this one asynchronously. Only a link is deleted. Objects are left untouched.- Parameters:
obj- the object to execute this method ontype2- the other typeid2- the other id- Returns:
- a future of null
-
unlinkAll
public void unlinkAll(com.erudika.para.core.ParaObject obj) Unlinks all objects that are linked to this one.- Parameters:
obj- the object to execute this method on OnlyLinkerobjects are deleted.ParaObjects are left untouched.
-
unlinkAllAsync
Unlinks all objects that are linked to this one asynchronously.- Parameters:
obj- the object to execute this method on OnlyLinkerobjects are deleted.ParaObjects are left untouched.- Returns:
- a future of null
-
countChildren
-
countChildrenAsync
public CompletableFuture<Long> countChildrenAsync(com.erudika.para.core.ParaObject obj, String type2) Count the total number of child objects for this object asynchronously.- Parameters:
obj- the object to execute this method ontype2- the type of the other object- Returns:
- a future of the number of links
-
getChildren
public <P extends com.erudika.para.core.ParaObject> List<P> getChildren(com.erudika.para.core.ParaObject obj, String type2, com.erudika.para.core.utils.Pager... pager) Returns all child objects linked to this object.- Type Parameters:
P- the type of children- Parameters:
obj- the object to execute this method ontype2- the type of children to look forpager- aPager- Returns:
- a list of
ParaObjectin a one-to-many relationship with this object
-
getChildrenAsync
public <P extends com.erudika.para.core.ParaObject> CompletableFuture<List<P>> getChildrenAsync(com.erudika.para.core.ParaObject obj, String type2, com.erudika.para.core.utils.Pager... pager) Returns all child objects linked to this object asynchronously.- Type Parameters:
P- the type of children- Parameters:
obj- the object to execute this method ontype2- the type of children to look forpager- aPager- Returns:
- a future of a list of
ParaObjectin a one-to-many relationship with this object
-
getChildren
public <P extends com.erudika.para.core.ParaObject> List<P> getChildren(com.erudika.para.core.ParaObject obj, String type2, String field, String term, com.erudika.para.core.utils.Pager... pager) Returns all child objects linked to this object.- Type Parameters:
P- the type of children- Parameters:
obj- the object to execute this method ontype2- the type of children to look forfield- the field name to use as filterterm- the field value to use as filterpager- aPager- Returns:
- a list of
ParaObjectin a one-to-many relationship with this object
-
getChildrenAsync
public <P extends com.erudika.para.core.ParaObject> CompletableFuture<List<P>> getChildrenAsync(com.erudika.para.core.ParaObject obj, String type2, String field, String term, com.erudika.para.core.utils.Pager... pager) Returns all child objects linked to this object asynchronously.- Type Parameters:
P- the type of children- Parameters:
obj- the object to execute this method ontype2- the type of children to look forfield- the field name to use as filterterm- the field value to use as filterpager- aPager- Returns:
- a future of a list of
ParaObjectin a one-to-many relationship with this object
-
findChildren
public <P extends com.erudika.para.core.ParaObject> List<P> findChildren(com.erudika.para.core.ParaObject obj, String type2, String query, com.erudika.para.core.utils.Pager... pager) Search through all child objects. Only searches child objects directly connected to this parent via theparentidfield.- Type Parameters:
P- the type of children- Parameters:
obj- the object to execute this method ontype2- the type of children to look forquery- a query stringpager- aPager- Returns:
- a list of
ParaObjectin a one-to-many relationship with this object
-
findChildrenAsync
public <P extends com.erudika.para.core.ParaObject> CompletableFuture<List<P>> findChildrenAsync(com.erudika.para.core.ParaObject obj, String type2, String query, com.erudika.para.core.utils.Pager... pager) Search through all child objects. Only searches child objects directly connected to this parent via theparentidfield asynchronously.- Type Parameters:
P- the type of children- Parameters:
obj- the object to execute this method ontype2- the type of children to look forquery- a query stringpager- aPager- Returns:
- a future of a list of
ParaObjectin a one-to-many relationship with this object
-
deleteChildren
Deletes all child objects permanently.- Parameters:
obj- the object to execute this method ontype2- the children's type.
-
deleteChildrenAsync
public CompletableFuture<Void> deleteChildrenAsync(com.erudika.para.core.ParaObject obj, String type2) Deletes all child objects permanently asynchronously.- Parameters:
obj- the object to execute this method ontype2- the children's type.- Returns:
- a future of null
-
newId
-
newIdAsync
Generates a new unique id asynchronously.- Returns:
- a future of a new id
-
getTimestamp
public long getTimestamp()Returns the current timestamp.- Returns:
- a long number
-
getTimestampAsync
Returns the current timestamp asynchronously.- Returns:
- a future of a long number
-
formatDate
-
formatDateAsync
Formats a date in a specific format asynchronously.- Parameters:
format- the date formatloc- the locale instance- Returns:
- a future of a formatted date
-
noSpaces
-
noSpacesAsync
Converts spaces to dashes asynchronously.- Parameters:
str- a string with spacesreplaceWith- a string to replace spaces with- Returns:
- a future of a string with dashes
-
stripAndTrim
-
stripAndTrimAsync
Strips all symbols, punctuation, whitespace and control chars from a string asynchronously.- Parameters:
str- a dirty string- Returns:
- a future of a clean string
-
markdownToHtml
-
markdownToHtmlAsync
Converts Markdown to HTML asynchronously.- Parameters:
markdownString- Markdown- Returns:
- a future of HTML
-
approximately
Returns the number of minutes, hours, months elapsed for a time delta (milliseconds).- Parameters:
delta- the time delta between two events, in milliseconds- Returns:
- a string like "5m", "1h"
-
approximatelyAsync
Returns the number of minutes, hours, months elapsed for a time delta (milliseconds) asynchronously.- Parameters:
delta- the time delta between two events, in milliseconds- Returns:
- a future of a string like "5m", "1h"
-
newKeys
-
newKeysAsync
Generates a new set of access/secret keys asynchronously. Old keys are discarded and invalid after this.- Returns:
- a future of a map of new credentials
-
types
-
typesAsync
Returns all registered types for this App asynchronously.- Returns:
- a future of a map of plural-singular form of all the registered types.
-
typesCount
-
typesCountAsync
Returns the number of objects for each existing type in this App asynchronously.- Returns:
- a future of a map of singular object type to object count.
-
me
public <P extends com.erudika.para.core.ParaObject> P me()Returns aUseror anAppthat is currently authenticated.- Type Parameters:
P- an App or User- Returns:
- a
Useror anApp
-
meAsync
Returns aUseror anAppthat is currently authenticated asynchronously.- Type Parameters:
P- an App or User- Returns:
- a future of a
Useror anApp
-
me
Verifies a given JWT and returns the authenticated subject. This request will not remember the JWT in memory.- Type Parameters:
P- an App or User- Parameters:
accessToken- a valid JWT access token- Returns:
- a
Useror anApp
-
meAsync
public <P extends com.erudika.para.core.ParaObject> CompletableFuture<P> meAsync(String accessToken) Verifies a given JWT and returns the authenticated subject. This request will not remember the JWT in memory asynchronously.- Type Parameters:
P- an App or User- Parameters:
accessToken- a valid JWT access token- Returns:
- a future of a
Useror anApp
-
voteUp
Upvote an object and register the vote in DB.- Parameters:
obj- the object to receive +1 votesvoterid- the userid of the voter- Returns:
- true if vote was successful
-
voteUpAsync
Upvote an object and register the vote in DB asynchronously.- Parameters:
obj- the object to receive +1 votesvoterid- the userid of the voter- Returns:
- a future of true if vote was successful
-
voteUp
public boolean voteUp(com.erudika.para.core.ParaObject obj, String voterid, Integer expiresAfter, Integer lockedAfter) Upvote an object and register the vote in DB.- Parameters:
obj- the object to receive +1 votesvoterid- the userid of the voterexpiresAfter- expires after secondslockedAfter- locked after seconds- Returns:
- true if vote was successful
-
voteUpAsync
public CompletableFuture<Boolean> voteUpAsync(com.erudika.para.core.ParaObject obj, String voterid, Integer expiresAfter, Integer lockedAfter) Upvote an object and register the vote in DB asynchronously.- Parameters:
obj- the object to receive +1 votesvoterid- the userid of the voterexpiresAfter- expires after secondslockedAfter- locked after seconds- Returns:
- a future of true if vote was successful
-
voteDown
Downvote an object and register the vote in DB.- Parameters:
obj- the object to receive -1 votesvoterid- the userid of the voter- Returns:
- true if vote was successful
-
voteDownAsync
public CompletableFuture<Boolean> voteDownAsync(com.erudika.para.core.ParaObject obj, String voterid) Downvote an object and register the vote in DB asynchronously.- Parameters:
obj- the object to receive -1 votesvoterid- the userid of the voter- Returns:
- a future of true if vote was successful
-
voteDown
public boolean voteDown(com.erudika.para.core.ParaObject obj, String voterid, Integer expiresAfter, Integer lockedAfter) Downvote an object and register the vote in DB.- Parameters:
obj- the object to receive -1 votesvoterid- the userid of the voterexpiresAfter- expires after secondslockedAfter- locked after seconds- Returns:
- true if vote was successful
-
voteDownAsync
public CompletableFuture<Boolean> voteDownAsync(com.erudika.para.core.ParaObject obj, String voterid, Integer expiresAfter, Integer lockedAfter) Downvote an object and register the vote in DB asynchronously.- Parameters:
obj- the object to receive -1 votesvoterid- the userid of the voterexpiresAfter- expires after secondslockedAfter- locked after seconds- Returns:
- a future of true if vote was successful
-
rebuildIndex
-
rebuildIndexAsync
Rebuilds the entire search index asynchronously.- Returns:
- a future of a response object with properties "tookMillis" and "reindexed"
-
rebuildIndex
-
rebuildIndexAsync
Rebuilds the entire search index asynchronously.- Parameters:
destinationIndex- an existing index as destination- Returns:
- a future of a response object with properties "tookMillis" and "reindexed"
-
sendEmail
public boolean sendEmail(List<String> toEmails, String subject, String fromEmail, String senderName, String message) Endpoint for sending transactional emails.- Parameters:
toEmails- list of email recipientssubject- subjectfromEmail- from email addresssenderName- sender namemessage- message body- Returns:
- true if email was sent
-
sendEmailAsync
public CompletableFuture<Boolean> sendEmailAsync(List<String> toEmails, String subject, String fromEmail, String senderName, String message) Endpoint for sending transactional emails asynchronously.- Parameters:
toEmails- list of email recipientssubject- subjectfromEmail- from email addresssenderName- sender namemessage- message body- Returns:
- a future of true if email was sent
-
sendEmail
public boolean sendEmail(List<String> toEmails, String subject, String fromEmail, String senderName, String message, boolean plaintextOnly, boolean markdownEnabled, InputStream file, String fileContentType) Endpoint for sending transactional emails.- Parameters:
toEmails- list of email recipientssubject- subjectfromEmail- from email addresssenderName- sender namemessage- message bodyplaintextOnly- true if plain textmarkdownEnabled- true if Markdown is enabledfile- file input streamfileContentType- file MIME type- Returns:
- true if email was sent
-
sendEmailAsync
public CompletableFuture<Boolean> sendEmailAsync(List<String> toEmails, String subject, String fromEmail, String senderName, String message, boolean plaintextOnly, boolean markdownEnabled, InputStream file, String fileContentType) Endpoint for sending transactional emails asynchronously.- Parameters:
toEmails- list of email recipientssubject- subjectfromEmail- from email addresssenderName- sender namemessage- message bodyplaintextOnly- true if plain textmarkdownEnabled- true if Markdown is enabledfile- file input streamfileContentType- file MIME type- Returns:
- a future of true if email was sent
-
validationConstraints
-
validationConstraintsAsync
-
validationConstraints
-
validationConstraintsAsync
-
addValidationConstraint
public Map<String, Map<String, Map<String, Map<String,?>>>> addValidationConstraint(String type, String field, com.erudika.para.core.validation.Constraint c) Add a new constraint for a given field.- Parameters:
type- a typefield- a field namec- the constraint- Returns:
- a map containing all validation constraints for this type.
-
addValidationConstraintAsync
public CompletableFuture<Map<String, Map<String, Map<String, Map<String,?>>>>> addValidationConstraintAsync(String type, String field, com.erudika.para.core.validation.Constraint c) Add a new constraint for a given field asynchronously.- Parameters:
type- a typefield- a field namec- the constraint- Returns:
- a future of a map containing all validation constraints for this type.
-
removeValidationConstraint
public Map<String, Map<String, Map<String, Map<String,?>>>> removeValidationConstraint(String type, String field, String constraintName) Removes a validation constraint for a given field.- Parameters:
type- a typefield- a field nameconstraintName- the name of the constraint to remove- Returns:
- a map containing all validation constraints for this type.
-
removeValidationConstraintAsync
public CompletableFuture<Map<String, Map<String, Map<String, Map<String,?>>>>> removeValidationConstraintAsync(String type, String field, String constraintName) Removes a validation constraint for a given field asynchronously.- Parameters:
type- a typefield- a field nameconstraintName- the name of the constraint to remove- Returns:
- a future of a map containing all validation constraints for this type.
-
resourcePermissions
-
resourcePermissionsAsync
-
resourcePermissions
-
resourcePermissionsAsync
public CompletableFuture<Map<String, Map<String, List<String>>>> resourcePermissionsAsync(String subjectid) Returns only the permissions for a given subject (user) of the current app asynchronously.- Parameters:
subjectid- the subject id (user id)- Returns:
- a future of a map of subject ids to resource names to a list of allowed methods
-
grantResourcePermission
public Map<String, Map<String, List<String>>> grantResourcePermission(String subjectid, String resourcePath, EnumSet<com.erudika.para.core.App.AllowedMethods> permission) Grants a permission to a subject that allows them to call the specified HTTP methods on a given resource.- Parameters:
subjectid- subject id (user id)resourcePath- resource path or object typepermission- a set of HTTP methods- Returns:
- a map of the permissions for this subject id
-
grantResourcePermissionAsync
public CompletableFuture<Map<String, Map<String, List<String>>>> grantResourcePermissionAsync(String subjectid, String resourcePath, EnumSet<com.erudika.para.core.App.AllowedMethods> permission) Grants a permission to a subject that allows them to call the specified HTTP methods on a given resource asynchronously.- Parameters:
subjectid- subject id (user id)resourcePath- resource path or object typepermission- a set of HTTP methods- Returns:
- a future of a map of the permissions for this subject id
-
grantResourcePermission
public Map<String, Map<String, List<String>>> grantResourcePermission(String subjectid, String resourcePath, EnumSet<com.erudika.para.core.App.AllowedMethods> permission, boolean allowGuestAccess) Grants a permission to a subject that allows them to call the specified HTTP methods on a given resource.- Parameters:
subjectid- subject id (user id)resourcePath- resource path or object typepermission- a set of HTTP methodsallowGuestAccess- if true - all unauthenticated requests will go through, 'false' by default.- Returns:
- a map of the permissions for this subject id
-
grantResourcePermissionAsync
public CompletableFuture<Map<String, Map<String, List<String>>>> grantResourcePermissionAsync(String subjectid, String resourcePath, EnumSet<com.erudika.para.core.App.AllowedMethods> permission, boolean allowGuestAccess) Grants a permission to a subject that allows them to call the specified HTTP methods on a given resource asynchronously.- Parameters:
subjectid- subject id (user id)resourcePath- resource path or object typepermission- a set of HTTP methodsallowGuestAccess- if true - all unauthenticated requests will go through, 'false' by default.- Returns:
- a future of a map of the permissions for this subject id
-
revokeResourcePermission
public Map<String, Map<String, List<String>>> revokeResourcePermission(String subjectid, String resourcePath) Revokes a permission for a subject, meaning they no longer will be able to access the given resource.- Parameters:
subjectid- subject id (user id)resourcePath- resource path or object type- Returns:
- a map of the permissions for this subject id
-
revokeResourcePermissionAsync
public CompletableFuture<Map<String, Map<String, List<String>>>> revokeResourcePermissionAsync(String subjectid, String resourcePath) Revokes a permission for a subject, meaning they no longer will be able to access the given resource asynchronously.- Parameters:
subjectid- subject id (user id)resourcePath- resource path or object type- Returns:
- a future of a map of the permissions for this subject id
-
revokeAllResourcePermissions
-
revokeAllResourcePermissionsAsync
-
isAllowedTo
-
isAllowedToAsync
public CompletableFuture<Boolean> isAllowedToAsync(String subjectid, String resourcePath, String httpMethod) Checks if a subject is allowed to call method X on resource Y asynchronously.- Parameters:
subjectid- subject idresourcePath- resource path or object typehttpMethod- HTTP method name- Returns:
- a future of true if allowed
-
appSettings
-
appSettingsAsync
Returns the map containing app-specific settings asynchronously.- Returns:
- a future of a map
-
appSettings
-
appSettingsAsync
Returns the value of a specific app setting (property) asynchronously.- Parameters:
key- a key- Returns:
- a future of a map containing one element {"value": "the_value"} or an empty map.
-
addAppSetting
-
addAppSettingAsync
Adds or overwrites an app-specific setting asynchronously.- Parameters:
key- a keyvalue- a value- Returns:
- a future of null
-
setAppSettings
Overwrites all app-specific settings.- Parameters:
settings- a key-value map of properties
-
setAppSettingsAsync
Overwrites all app-specific settings asynchronously.- Parameters:
settings- a key-value map of properties- Returns:
- a future of null
-
removeAppSetting
-
removeAppSettingAsync
Removes an app-specific setting asynchronously.- Parameters:
key- a key- Returns:
- a future of null
-
signIn
public com.erudika.para.core.User signIn(String provider, String providerToken, boolean rememberJWT) Takes an identity provider access token and fetches the user data from that provider. A newUserobject is created if that user doesn't exist. Access tokens are returned upon successful authentication using one of the SDKs from Facebook, Google, Twitter, etc. Note: Twitter uses OAuth 1 and gives you a token and a token secret. You must concatenate them like this:{oauth_token}:{oauth_token_secret}and use that as the provider access token.- Parameters:
provider- identity provider, e.g. 'facebook', 'google'...providerToken- access token from a provider like Facebook, Google, TwitterrememberJWT- it true the access token returned by Para will be stored locally and available throughgetAccessToken()- Returns:
- a
Userobject or null if something failed. The JWT is available on the returned User object viaUser.getPassword().
-
signInAsync
public CompletableFuture<com.erudika.para.core.User> signInAsync(String provider, String providerToken, boolean rememberJWT) Takes an identity provider access token and fetches the user data from that provider asynchronously. A newUserobject is created if that user doesn't exist. Access tokens are returned upon successful authentication using one of the SDKs from Facebook, Google, Twitter, etc. Note: Twitter uses OAuth 1 and gives you a token and a token secret. You must concatenate them like this:{oauth_token}:{oauth_token_secret}and use that as the provider access token.- Parameters:
provider- identity provider, e.g. 'facebook', 'google'...providerToken- access token from a provider like Facebook, Google, TwitterrememberJWT- it true the access token returned by Para will be stored locally and available throughgetAccessToken()- Returns:
- a future of a
Userobject or null if something failed. The JWT is available on the returned User object viaUser.getPassword().
-
signIn
Takes an identity provider access token and fetches the user data from that provider.- Parameters:
provider- identity provider, e.g. 'facebook', 'google'...providerToken- access token from a provider like Facebook, Google, Twitter- Returns:
- a
Userobject or null if something failed - See Also:
-
signInAsync
public CompletableFuture<com.erudika.para.core.User> signInAsync(String provider, String providerToken) Takes an identity provider access token and fetches the user data from that provider asynchronously.- Parameters:
provider- identity provider, e.g. 'facebook', 'google'...providerToken- access token from a provider like Facebook, Google, Twitter- Returns:
- a future of a
Userobject or null if something failed - See Also:
-
signOut
public void signOut()Clears the JWT access token but token is not revoked. Tokens can be revoked globally per user withrevokeAllTokens(). -
revokeAllTokens
public boolean revokeAllTokens()Revokes all user tokens for a given user id. This would be equivalent to "logout everywhere". Note: Generating a new API secret on the server will also invalidate all client tokens. Requires a valid existing token.- Returns:
- true if successful
-
revokeAllTokensAsync
Revokes all user tokens for a given user id asynchronously. This would be equivalent to "logout everywhere". Note: Generating a new API secret on the server will also invalidate all client tokens. Requires a valid existing token.- Returns:
- a future of true if successful
-
readEverything
public <T extends com.erudika.para.core.ParaObject> void readEverything(Function<com.erudika.para.core.utils.Pager, List<T>> paginatingFunc) Paginates through all objects and executes the provided function on the results.- Type Parameters:
T- type of object- Parameters:
paginatingFunc- paginating function
-
readEverything
public <T extends com.erudika.para.core.ParaObject> void readEverything(Function<com.erudika.para.core.utils.Pager, List<T>> paginatingFunc, int pageSize) Paginates through all objects and executes the provided function on the results.- Type Parameters:
T- type of object- Parameters:
paginatingFunc- paginating functionpageSize- page size for pager (pager.limit)
-
updateAllPartially
public <T extends com.erudika.para.core.ParaObject> CompletableFuture<Void> updateAllPartially(BiFunction<List<Map<String, Object>>, com.erudika.para.core.utils.Pager, List<T>> paginatingFunc) Performs a partial batch update (async) on all objects of given type. This method encapsulates the specific logic for performing the batch update safely because updating while searching for objects can lead to bugs due to the fact that _docid values change on each update call.- Type Parameters:
T- type of object- Parameters:
paginatingFunc- paginating function- Returns:
- a Future
-
updateAllPartially
public <T extends com.erudika.para.core.ParaObject> CompletableFuture<Void> updateAllPartially(BiFunction<List<Map<String, Object>>, com.erudika.para.core.utils.Pager, List<T>> paginatingFunc, int pageSize, int updateBatchSize) Performs a partial batch update on all objects of given type. This method encapsulates the specific logic for performing the batch update safely because updating while searching for objects can lead to bugs due to the fact that _docid values change on each update call.- Type Parameters:
T- type of object- Parameters:
paginatingFunc- paginating function which returns a list of objectpageSize- page size for pager (pager.limit)updateBatchSize- batch size for updating objects- Returns:
- a Future
-