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 TypeMethodDescriptionvoid
addAppSetting
(String key, Object value) Adds or overwrites an app-specific setting.addValidationConstraint
(String type, String field, Constraint c) Add a new constraint for a given field.approximately
(long delta) Returns the number of minutes, hours, months elapsed for a time delta (milliseconds).Returns the map containing app-specific settings.appSettings
(String key) Returns the value of a specific app setting (property).void
close()
Closes the underlying Jersey client and releases resources.countChildren
(ParaObject obj, String type2) Count the total number of child objects for this object.countLinks
(ParaObject obj, String type2) Count the total number of links between this object and another type of object.<P extends ParaObject>
Pcreate
(P obj) Persists an object to the data store.<P extends ParaObject>
List<P>Saves multiple objects to the data store.<P extends ParaObject>
voiddelete
(P obj) Deletes an object permanently.void
Deletes multiple objects.void
deleteChildren
(ParaObject obj, String type2) Deletes all child objects permanently.<P extends ParaObject>
PSimple id search.<P extends ParaObject>
List<P>Simple multi id search.<P extends ParaObject>
List<P>findChildren
(ParaObject obj, String type2, String query, Pager... pager) Search through all child objects.<P extends ParaObject>
List<P>findLinkedObjects
(ParaObject obj, String type2, String field, String query, Pager... pager) Searches through all linked objects in many-to-many relationships.<P extends ParaObject>
List<P>findNearby
(String type, String query, int radius, double lat, double lng, Pager... pager) Search forAddress
objects in a radius of X km from a given point.<P extends ParaObject>
List<P>findNestedQuery
(String type, String field, String query, Pager... pager) Searches within a nested field.<P extends ParaObject>
List<P>findPrefix
(String type, String field, String prefix, Pager... pager) Searches for objects that have a property which value starts with a given prefix.<P extends ParaObject>
List<P>Simple query string search.<P extends ParaObject>
List<P>Searches for objects that have similar property values to a given text.<P extends ParaObject>
List<P>findTagged
(String type, String[] tags, Pager... pager) Searches for objects tagged with one or more tags.<P extends ParaObject>
List<P>Searches forTag
objects.<P extends ParaObject>
List<P>Searches for objects having a property value that is in list of possible values.<P extends ParaObject>
List<P>Searches for objects that have properties matching some given values.<P extends ParaObject>
List<P>findWildcard
(String type, String field, String wildcard, Pager... pager) Searches for objects that have a property with a value matching a wildcard query.formatDate
(String format, Locale loc) Formats a date in a specific format.Returns the JWT access token if any.Returns the API request path.getApp()
Returns theApp
for the current access key (appid).<P extends ParaObject>
List<P>getChildren
(ParaObject obj, String type2, Pager... pager) Returns all child objects linked to this object.<P extends ParaObject>
List<P>getChildren
(ParaObject obj, String type2, String field, String term, Pager... pager) Returns all child objects linked to this object.int
Returns the batch chunk size.Counts indexed objects.Counts indexed objects matching a set of terms/values.Returns the endpoint URL.<P extends ParaObject>
List<P>Converts a list of Maps to a List of ParaObjects, at a given path within the JSON tree structure.<P extends ParaObject>
List<P>getItemsFromList
(List<?> result) Deserializes ParaObjects from a JSON array (the "items:[]" field in search results).<P extends ParaObject>
List<P>getLinkedObjects
(ParaObject obj, String type2, Pager... pager) Returns all objects linked to the given one.Returns the Para server version.long
Returns the current timestamp.grantResourcePermission
(String subjectid, String resourcePath, EnumSet<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<App.AllowedMethods> permission, boolean allowGuestAccess) Grants a permission to a subject that allows them to call the specified HTTP methods on a given resource.<T> T
invokeDelete
(String resourcePath, javax.ws.rs.core.MultivaluedMap<String, String> params, Class<?> returnType) Invoke a DELETE request to the Para API.<T> T
invokeGet
(String resourcePath, javax.ws.rs.core.MultivaluedMap<String, String> params, Class<?> returnType) Invoke a GET request to the Para API.<T> T
invokePatch
(String resourcePath, Object entity, Class<?> returnType) Invoke a PATCH request to the Para API.<T> T
invokePost
(String resourcePath, Object entity, Class<?> returnType) Invoke a POST request to the Para API.<T> T
Invoke a PUT request to the Para API.boolean
isAllowedTo
(String subjectid, String resourcePath, String httpMethod) Checks if a subject is allowed to call method X on resource Y.boolean
isLinked
(ParaObject obj, ParaObject toObj) Checks if a given object is linked to this one.boolean
isLinked
(ParaObject obj, String type2, String id2) Checks if this object is linked to another.link
(ParaObject obj, String id2) Links an object to this one in a many-to-many relationship.<P extends ParaObject>
List<P>Returns a list all objects found for the given type.markdownToHtml
(String markdownString) Converts Markdown to HTML.<P extends ParaObject>
Pme()
<P extends ParaObject>
PVerifies a given JWT and returns the authenticated subject.newId()
Generates a new unique id.newKeys()
Generates a new set of access/secret keys.Converts spaces to dashes.pagerToParams
(Pager... pager) Converts aPager
object to query parameters.<P extends ParaObject>
PRetrieves an object from the data store.<P extends ParaObject>
PRetrieves an object from the data store.<P extends ParaObject>
List<P>Retrieves multiple objects from the data store.<T extends ParaObject>
voidreadEverything
(Function<Pager, List<T>> paginatingFunc) Paginates through all objects and executes the provided function on the results.<T extends ParaObject>
voidreadEverything
(Function<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.void
removeAppSetting
(String key) Removes an app-specific setting.removeValidationConstraint
(String type, String field, String constraintName) Removes a validation constraint for a given field.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.revokeAllResourcePermissions
(String subjectid) Revokes all permission for a subject.boolean
Revokes all user tokens for a given user id.revokeResourcePermission
(String subjectid, String resourcePath) Revokes a permission for a subject, meaning they no longer will be able to access the given resource.void
setAccessToken
(String token) Sets the JWT access token.void
setApiPath
(String path) Sets the API request path.void
setAppSettings
(Map<?, ?> settings) Overwrites all app-specific settings.void
setChunkSize
(int chunkSize) Sets the chunk size for batch CRUD operations.void
setEndpoint
(String endpoint) Sets the host URL of the Para server.Takes an identity provider access token and fetches the user data from that provider.Takes an identity provider access token and fetches the user data from that provider.void
signOut()
Clears the JWT access token but token is not revoked.stripAndTrim
(String str) Strips all symbols, punctuation, whitespace and control chars from a string.void
throwExceptionOnHTTPError
(boolean enabled) Enable/disable exception throwing in ParaClient.types()
Returns all registered types for this App.Returns the number of objects for each existing type in this App.void
unlink
(ParaObject obj, String type2, String id2) Unlinks an object from this one.void
unlinkAll
(ParaObject obj) Unlinks all objects that are linked to this one.<P extends ParaObject>
Pupdate
(P obj) Updates an object permanently.<P extends ParaObject>
List<P>Updates multiple objects.<T extends ParaObject>
voidupdateAllPartially
(BiFunction<List<Map<String, Object>>, Pager, List<T>> paginatingFunc) Performs a partial batch update on all objects of given type.<T extends ParaObject>
voidupdateAllPartially
(BiFunction<List<Map<String, Object>>, Pager, List<T>> paginatingFunc, int pageSize, int updateBatchSize) Performs a partial batch update on all objects of given type.Returns the validation constraints map.validationConstraints
(String type) Returns the validation constraints map.boolean
voteDown
(ParaObject obj, String voterid) Downvote an object and register the vote in DB.boolean
voteDown
(ParaObject obj, String voterid, Integer expiresAfter, Integer lockedAfter) Downvote an object and register the vote in DB.boolean
voteUp
(ParaObject obj, String voterid) Upvote an object and register the vote in DB.boolean
voteUp
(ParaObject obj, String voterid, Integer expiresAfter, Integer lockedAfter) Upvote an object and register the vote in DB.
-
Constructor Details
-
ParaClient
Default constructor.- Parameters:
accessKey
- app access keysecretKey
- app secret key
-
-
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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
getApp
Returns theApp
for the current access key (appid).- Returns:
- the App object
-
getEndpoint
Returns the endpoint URL.- Returns:
- the endpoint
-
setApiPath
Sets the API request path.- Parameters:
path
- a new path
-
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
-
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
public <T> T invokeGet(String resourcePath, javax.ws.rs.core.MultivaluedMap<String, String> params, Class<?> returnType) 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, javax.ws.rs.core.MultivaluedMap<String, 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
-
pagerToParams
Converts aPager
object to query parameters.- Parameters:
pager
- a Pager- Returns:
- list of query parameters
-
getItemsFromList
Deserializes ParaObjects from a JSON array (the "items:[]" field in search results).- Type Parameters:
P
- type- Parameters:
result
- a list of deserialized maps- Returns:
- a list of ParaObjects
-
getItems
public <P extends ParaObject> List<P> getItems(String at, Map<String, Object> result, 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
- aPager
object- Returns:
- a list of ParaObjects
-
create
Persists an object to the data store. If the object's type and id are given, then the request will be aPUT
request 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.
-
read
Retrieves an object from the data store.- Type Parameters:
P
- the type of object- Parameters:
type
- the type of the objectid
- the id of the object- Returns:
- 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
-
update
Updates an object permanently. Supports partial updates.- Type Parameters:
P
- the type of object- Parameters:
obj
- the object to update- Returns:
- the updated object
-
delete
Deletes an object permanently.- Type Parameters:
P
- the type of object- Parameters:
obj
- the object
-
createAll
Saves multiple objects to the data store.- Type Parameters:
P
- the type of object- Parameters:
objects
- the list of objects to save- Returns:
- a list of objects
-
readAll
Retrieves multiple objects from the data store.- Type Parameters:
P
- the type of object- Parameters:
keys
- a list of object ids- Returns:
- a list of objects
-
updateAll
Updates multiple objects.- Type Parameters:
P
- the type of object- Parameters:
objects
- the objects to update- Returns:
- a list of objects
-
deleteAll
Deletes multiple objects.- Parameters:
keys
- the ids of the objects to delete
-
list
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
-
findById
Simple id search.- Type Parameters:
P
- type of the object- Parameters:
id
- the id- Returns:
- the object if found or null
-
findByIds
Simple multi id search.- Type Parameters:
P
- type of the object- Parameters:
ids
- a list of ids to search for- Returns:
- a list of object found
-
findNearby
public <P extends ParaObject> List<P> findNearby(String type, String query, int radius, double lat, double lng, Pager... pager) Search forAddress
objects 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
-
findPrefix
public <P extends ParaObject> List<P> findPrefix(String type, String field, String prefix, 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
-
findQuery
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
-
findNestedQuery
public <P extends ParaObject> List<P> findNestedQuery(String type, String field, String query, 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
-
findSimilar
public <P extends ParaObject> List<P> findSimilar(String type, String filterKey, String[] fields, String liketext, 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
-
findTagged
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
-
findTags
Searches forTag
objects. 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
-
findTermInList
public <P extends ParaObject> List<P> findTermInList(String type, String field, List<String> terms, 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
-
findTerms
public <P extends ParaObject> List<P> findTerms(String type, Map<String, ?> terms, boolean matchAll, Pager... pager) Searches for objects that have properties matching some given values. A terms query.- 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 list of objects found
-
findWildcard
public <P extends ParaObject> List<P> findWildcard(String type, String field, String wildcard, 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
-
getCount
Counts indexed objects.- Parameters:
type
- the type of object to search for. SeeParaObject.getType()
- Returns:
- the number of results found
-
getCount
Counts indexed objects matching a set of terms/values.- Parameters:
type
- the type of object to search for. SeeParaObject.getType()
terms
- a list of terms (property values)- Returns:
- the number of results found
-
countLinks
Count the total number of links between this object and another type of object.- Parameters:
obj
- the object to execute this method ontype2
- the other type of object- Returns:
- the number of links for the given object
-
getLinkedObjects
public <P extends ParaObject> List<P> getLinkedObjects(ParaObject obj, String type2, 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
-
findLinkedObjects
public <P extends ParaObject> List<P> findLinkedObjects(ParaObject obj, String type2, String field, String query, 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
-
isLinked
Checks if this object is linked to another.- Parameters:
obj
- the object to execute this method ontype2
- the other typeid2
- the other id- Returns:
- true if the two are linked
-
isLinked
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
-
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
Linker
object that is created
-
unlink
Unlinks an object from this one. Only a link is deleted. Objects are left untouched.- Parameters:
obj
- the object to execute this method ontype2
- the other typeid2
- the other id
-
unlinkAll
Unlinks all objects that are linked to this one.- Parameters:
obj
- the object to execute this method on OnlyLinker
objects are deleted.ParaObject
s are left untouched.
-
countChildren
Count the total number of child objects for this object.- Parameters:
obj
- the object to execute this method ontype2
- the type of the other object- Returns:
- the number of links
-
getChildren
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
ParaObject
in a one-to-many relationship with this object
-
getChildren
public <P extends ParaObject> List<P> getChildren(ParaObject obj, String type2, String field, String term, 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
ParaObject
in a one-to-many relationship with this object
-
findChildren
public <P extends ParaObject> List<P> findChildren(ParaObject obj, String type2, String query, Pager... pager) Search through all child objects. Only searches child objects directly connected to this parent via theparentid
field.- 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
ParaObject
in 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.
-
newId
Generates a new unique id.- Returns:
- a new id
-
getTimestamp
public long getTimestamp()Returns the current timestamp.- Returns:
- a long number
-
formatDate
Formats a date in a specific format.- Parameters:
format
- the date formatloc
- the locale instance- Returns:
- a formatted date
-
noSpaces
Converts spaces to dashes.- Parameters:
str
- a string with spacesreplaceWith
- a string to replace spaces with- Returns:
- a string with dashes
-
stripAndTrim
Strips all symbols, punctuation, whitespace and control chars from a string.- Parameters:
str
- a dirty string- Returns:
- a clean string
-
markdownToHtml
Converts Markdown to HTML.- Parameters:
markdownString
- Markdown- Returns:
- 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"
-
newKeys
Generates a new set of access/secret keys. Old keys are discarded and invalid after this.- Returns:
- a map of new credentials
-
types
Returns all registered types for this App.- Returns:
- a map of plural-singular form of all the registered types.
-
typesCount
Returns the number of objects for each existing type in this App.- Returns:
- a map of singular object type to object count.
-
me
-
me
Verifies a given JWT and returns the authenticated subject. This request will not remember the JWT in memory. -
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
-
voteUp
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
-
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
-
voteDown
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
-
rebuildIndex
Rebuilds the entire search index.- Returns:
- a response object with properties "tookMillis" and "reindexed"
-
rebuildIndex
Rebuilds the entire search index.- Parameters:
destinationIndex
- an existing index as destination- Returns:
- a response object with properties "tookMillis" and "reindexed"
-
validationConstraints
Returns the validation constraints map.- Returns:
- a map containing all validation constraints.
-
validationConstraints
Returns the validation constraints map.- Parameters:
type
- a type- Returns:
- a map containing all validation constraints for this type.
-
addValidationConstraint
public Map<String,Map<String, addValidationConstraintMap<String, Map<String, ?>>>> (String type, String field, 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.
-
removeValidationConstraint
public Map<String,Map<String, removeValidationConstraintMap<String, Map<String, ?>>>> (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.
-
resourcePermissions
Returns the permissions for all subjects and resources for current app.- Returns:
- a map of subject ids to resource names to a list of allowed methods
-
resourcePermissions
Returns only the permissions for a given subject (user) of the current app.- Parameters:
subjectid
- the subject id (user id)- Returns:
- a map of subject ids to resource names to a list of allowed methods
-
grantResourcePermission
public Map<String,Map<String, grantResourcePermissionList<String>>> (String subjectid, String resourcePath, EnumSet<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
-
grantResourcePermission
public Map<String,Map<String, grantResourcePermissionList<String>>> (String subjectid, String resourcePath, EnumSet<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
-
revokeResourcePermission
public Map<String,Map<String, revokeResourcePermissionList<String>>> (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
-
revokeAllResourcePermissions
Revokes all permission for a subject.- Parameters:
subjectid
- subject id (user id)- Returns:
- a map of the permissions for this subject id
-
isAllowedTo
Checks if a subject is allowed to call method X on resource Y.- Parameters:
subjectid
- subject idresourcePath
- resource path or object typehttpMethod
- HTTP method name- Returns:
- true if allowed
-
appSettings
Returns the map containing app-specific settings.- Returns:
- a map
-
appSettings
Returns the value of a specific app setting (property).- Parameters:
key
- a key- Returns:
- a map containing one element {"value": "the_value"} or an empty map.
-
addAppSetting
Adds or overwrites an app-specific setting.- Parameters:
key
- a keyvalue
- a value
-
setAppSettings
Overwrites all app-specific settings.- Parameters:
settings
- a key-value map of properties
-
removeAppSetting
Removes an app-specific setting.- Parameters:
key
- a key
-
signIn
Takes an identity provider access token and fetches the user data from that provider. A newUser
object 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
User
object 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
User
object 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
-
readEverything
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 ParaObject> void readEverything(Function<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 ParaObject> void updateAllPartially(BiFunction<List<Map<String, Object>>, Pager, List<T>> paginatingFunc) 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
-
updateAllPartially
public <T extends ParaObject> void updateAllPartially(BiFunction<List<Map<String, Object>>, 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
-