java.lang.Object
com.erudika.para.core.App
- All Implemented Interfaces:
Linkable
,ParaObject
,Votable
,Serializable
This is a representation of an application within Para.
It allows the user to create separate apps running on the same infrastructure. Every
Apps can have a dedicated table or they can share the same table using prefixed keys. Also, apps can have a dedicated search index or share one. These are controlled by the two flags
Usually when we have a multi-app environment there's a parent app (dedicated) and lots of child apps (shared) that share the same index with the parent app.
It allows the user to create separate apps running on the same infrastructure. Every
ParaObject
belongs to an app.
Apps can have a dedicated table or they can share the same table using prefixed keys. Also, apps can have a dedicated search index or share one. These are controlled by the two flags
isSharingTable()
and isSharingIndex()
.
Usually when we have a multi-app environment there's a parent app (dedicated) and lots of child apps (shared) that share the same index with the parent app.
- Author:
- Alex Bogdanovski [[email protected]]
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Represents HTTP methods allowed to be executed on a specific resource/type.Nested classes/interfaces inherited from interface com.erudika.para.core.Votable
Votable.VoteValue
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddAllSettings
(Map<String, Object> settings) Adds all settings to map of app settings and invokes allAppSettingAddedListener
s.static void
addAppCreatedListener
(AppCreatedListener listener) Registers a new create listener.static void
addAppDeletedListener
(AppDeletedListener listener) Registers a new delete listener.static void
Registers a new app setting added listener.static void
Registers a new app setting removed listener.void
addDatatype
(String pluralDatatype, String datatype) Adds a user-defined data type to the types map.boolean
addDatatypes
(ParaObject... objects) Adds unknown types to this app's list of data types.addSetting
(String name, Object value) Adds a new setting to the map.boolean
addValidationConstraint
(String type, String field, Constraint c) Adds a new constraint to the list of constraints for a given field and type.Clears all app settings and invokes eachAppSettingRemovedListener
s.countChildren
(String type) Count the total number of child objects for this object.countLinks
(String type2) Count the total number of links between this object and another type of object.create()
Stores this object in the data store.void
delete()
Deletes the object permanently by removing it from the data store.void
deleteChildren
(String type) Deletes all child objects permanently.boolean
boolean
exists()
Checks if an object is stored in the data store.<P extends ParaObject>
List<P> findChildren
(String type, String query, Pager... pager) Search through all child objects.<P extends ParaObject>
List<P> findLinkedObjects
(String type, String field, String query, Pager... pager) Similar toLinkable.findChildren(java.lang.String, java.lang.String, com.erudika.para.core.utils.Pager...)
but for many-to-many relationships.Returns true if this application is active (enabled).getAllResourcePermissions
(String... subjectids) Returns all resource permission for a list of subjects ids.getAllValidationConstraints
(String... types) Returns all validation constraints for a list of types.getAppid()
The application name.The App identifier (the id but without the prefixapp:
).Boolean flag which controls whether this object is cached.<P extends ParaObject>
List<P> getChildren
(String type, Pager... pager) Returns all child objects linked to this object.<P extends ParaObject>
List<P> getChildren
(String type, String field, String term, Pager... pager) Returns all child objects linked to this object.The id of the user who created this.Returns the map containing the app's access key and secret key.Returns a set of custom data types for this app.The timestamp for when this app must be deleted.final String
getId()
The id of an object.Boolean flag which controls whether this object is indexed by the search engine.<P extends ParaObject>
List<P> getLinkedObjects
(String type, Pager... pager) Similar toLinkable.getChildren(java.lang.String, com.erudika.para.core.utils.Pager...)
but for many-to-many relationships.Returns all links between this type object and another type of object.final String
getName()
The name of the object.The URI of this object.The id of the parent object.The plural name of the object.Gets read-only mode.Returns a map of resource permissions.Returns the app's secret key.getSetting
(String name) Returns the value of a setting for a given key.A map of all settings (key/values).Boolean flag which controls whether this object is stored in the database or not.getTags()
The tags associated with this object.The time when the object was created, in milliseconds.The validity period for access tokens in seconds.final String
getType()
The name of the object's class.The last time this object was updated.Returns a map of user-defined data types and their validation annotations.Returns the version number for this object.getVotes()
Returns the total sum of all votes for this object.boolean
grantResourcePermission
(String subjectid, String resourcePath, EnumSet<App.AllowedMethods> permission) Grants a new permission for a given subject and resource.boolean
grantResourcePermission
(String subjectid, String resourcePath, EnumSet<App.AllowedMethods> permission, boolean allowGuestAccess) Grants a new permission for a given subject and resource.int
hashCode()
static final String
Returns the correct id of this app with prefix.static final String
identifier
(String appid) Returns the identifier without the "app:" prefix.boolean
isAllowedTo
(String subjectid, String resourcePath, String httpMethod) Checks if a subject is allowed to call method X on resource Y.boolean
isLinked
(ParaObject toObj) Checks if a given object is linked to this one.boolean
Checks if this object is linked to another.static boolean
Return true if the app is the root app (the first one created).boolean
Return true if the app is the root app (the first one created).boolean
Is this a sharing the search index with other apps.boolean
Is this a sharing the database table with other apps.Links an object to this one in a many-to-many relationship.boolean
permissionsContainOwnKeyword
(User user, ParaObject object) Check if the permissions map contains "OWN" keyword, which restricts access to objects to their creators.void
removeDatatype
(String pluralDatatype) Removes a datatype from the types map.removeSetting
(String name) Removes a setting from the map.boolean
removeValidationConstraint
(String type, String field, String constraintName) Removes a constraint from the map.void
Resets the secret key by generating a new one.boolean
revokeAllResourcePermissions
(String subjectid) Revokes all permissions for a subject id.boolean
revokeResourcePermission
(String subjectid, String resourcePath) Revokes a permission for given subject.void
Sets the active flag.void
Sets a new app name.void
Sets the "isCached" flag.void
setCreatorid
(String creatorid) Sets a new creator id.void
setDatatypes
(Map<String, String> datatypes) Sets the data types for this app.void
setDeleteOn
(Long deleteOn) Sets the time for deletion.final void
Sets a new id.void
setIndexed
(Boolean indexed) Sets the "isIndexed" flag.final void
Sets a new name.void
setParentid
(String parentid) Sets a new parent id.void
setReadOnly
(Boolean readOnly) Sets read-only mode.void
Sets the permissions map.void
Sets the secret key.void
setSettings
(Map<String, Object> settings) Overwrites the settings map.void
setSharingIndex
(boolean sharingIndex) Sets the sharingIndex flag.void
setSharingTable
(boolean sharingTable) Sets the sharingTable flag.void
Sets the "isStored" flag.void
Merges the given tags with existing tags.void
setTimestamp
(Long timestamp) Sets the timestamp.void
setTokenValiditySec
(Long tokenValiditySec) Sets the access token validity period in seconds.final void
Sets a new object type.void
setUpdated
(Long updated) Sets the last updated timestamp.void
Sets the validation constraints map.void
setVersion
(Long version) Sets the version of this object.void
Sets the total votes for this object.toString()
void
Unlinks an object from this one.void
Unlinks all objects that are linked to this one.void
update()
Updates the object permanently.boolean
Downvotes the object.boolean
Upvotes the object.
-
Field Details
-
APP_ROLE
-
ALLOW_ALL
-
-
Constructor Details
-
App
public App()No-args constructor. -
App
-
-
Method Details
-
id
-
identifier
-
setId
Description copied from interface:ParaObject
Sets a new id. Must not be null or empty.- Specified by:
setId
in interfaceParaObject
- Parameters:
id
- the new id
-
addSetting
-
addAllSettings
Adds all settings to map of app settings and invokes allAppSettingAddedListener
s.- Parameters:
settings
- a map settings to add- Returns:
- this
-
getSetting
-
removeSetting
-
clearSettings
Clears all app settings and invokes eachAppSettingRemovedListener
s.- Returns:
- this
-
getSettings
-
setSettings
-
getValidationConstraints
-
setValidationConstraints
-
getResourcePermissions
-
setResourcePermissions
-
getAppIdentifier
The App identifier (the id but without the prefixapp:
). The identifier may start with a whitespace character e.g. " myapp". This indicates that the app is sharing a table with other apps. This is disabled by default unlesspara.prepend_shared_appids_with_space = true
- Returns:
- the identifier (appid)
-
getActive
Returns true if this application is active (enabled).- Returns:
- true if active
-
setActive
Sets the active flag. When an app is disabled (active = false) it cannot be accessed through the API.- Parameters:
active
- true if active
-
getDeleteOn
-
setDeleteOn
Sets the time for deletion.- Parameters:
deleteOn
- a timestamp
-
getTokenValiditySec
The validity period for access tokens in seconds. This setting is for current app only. Always returns a default value if local setting is null.- Returns:
- period in seconds
-
setTokenValiditySec
Sets the access token validity period in seconds.- Parameters:
tokenValiditySec
- seconds
-
getSecret
-
setSecret
-
getReadOnly
-
setReadOnly
Sets read-only mode.- Parameters:
readOnly
- true if app is in read-only mode
-
getDatatypes
-
setDatatypes
-
isSharingIndex
public boolean isSharingIndex()Is this a sharing the search index with other apps.- Returns:
- true if it does
-
setSharingIndex
public void setSharingIndex(boolean sharingIndex) Sets the sharingIndex flag.- Parameters:
sharingIndex
- false means this app should have its own dedicated index
-
isSharingTable
public boolean isSharingTable()Is this a sharing the database table with other apps.- Returns:
- true if it does
-
setSharingTable
public void setSharingTable(boolean sharingTable) Sets the sharingTable flag.- Parameters:
sharingTable
- false means this app should have its own dedicated table
-
isRootApp
public boolean isRootApp()Return true if the app is the root app (the first one created).- Returns:
- true if root
-
isRoot
Return true if the app is the root app (the first one created).- Parameters:
appid
- an app identifier- Returns:
- true if root
-
getAllValidationConstraints
-
addValidationConstraint
Adds a new constraint to the list of constraints for a given field and type.- Parameters:
type
- the typefield
- the fieldc
- the constraint- Returns:
- true if successful
-
removeValidationConstraint
-
getAllResourcePermissions
-
grantResourcePermission
public boolean grantResourcePermission(String subjectid, String resourcePath, EnumSet<App.AllowedMethods> permission) Grants a new permission for a given subject and resource.- Parameters:
subjectid
- the subject to give permissions toresourcePath
- the resource name/typepermission
- the set or HTTP methods allowed- Returns:
- true if successful
-
grantResourcePermission
public boolean grantResourcePermission(String subjectid, String resourcePath, EnumSet<App.AllowedMethods> permission, boolean allowGuestAccess) Grants a new permission for a given subject and resource.- Parameters:
subjectid
- the subject to give permissions toresourcePath
- the resource name/typepermission
- the set or HTTP methods allowedallowGuestAccess
- if true - all unauthenticated requests will go through, 'false' by default.- Returns:
- true if successful
-
revokeResourcePermission
-
revokeAllResourcePermissions
Revokes all permissions for a subject id.- Parameters:
subjectid
- subject id- Returns:
- true if successful
-
isAllowedTo
-
permissionsContainOwnKeyword
Check if the permissions map contains "OWN" keyword, which restricts access to objects to their creators.- Parameters:
user
- user in contextobject
- some object- Returns:
- true if app contains permission for this resource and it is marked with "OWN"
-
addDatatype
-
addDatatypes
Adds unknown types to this app's list of data types. Called on create().- Parameters:
objects
- a list of new objects- Returns:
- true if a new data type was added to the list
-
removeDatatype
Removes a datatype from the types map.- Parameters:
pluralDatatype
- a datatype, must not be null or empty
-
resetSecret
public void resetSecret()Resets the secret key by generating a new one. -
getCredentials
-
addAppCreatedListener
Registers a new create listener.- Parameters:
listener
- the listener
-
addAppDeletedListener
Registers a new delete listener.- Parameters:
listener
- the listener
-
addAppSettingAddedListener
Registers a new app setting added listener.- Parameters:
listener
- the listener
-
addAppSettingRemovedListener
Registers a new app setting removed listener.- Parameters:
listener
- the listener
-
create
Description copied from interface:ParaObject
Stores this object in the data store.- Specified by:
create
in interfaceParaObject
- Returns:
- the id of the object (a new id if object is new)
- See Also:
-
delete
public void delete()Description copied from interface:ParaObject
Deletes the object permanently by removing it from the data store.- Specified by:
delete
in interfaceParaObject
- See Also:
-
getId
Description copied from interface:ParaObject
The id of an object. Usually an autogenerated unique string of numbers.- Specified by:
getId
in interfaceParaObject
- Returns:
- the id
-
getType
Description copied from interface:ParaObject
The name of the object's class. This is equivalent toClass.getSimpleName()
.toLowerCase()- Specified by:
getType
in interfaceParaObject
- Returns:
- the simple name of the class
-
setType
Description copied from interface:ParaObject
Sets a new object type. Must not be null or empty.- Specified by:
setType
in interfaceParaObject
- Parameters:
type
- a new type
-
getAppid
Description copied from interface:ParaObject
The application name. Added to support multiple separate apps. Every object must belong to an app.- Specified by:
getAppid
in interfaceParaObject
- Returns:
- the app id (name). default: para
-
setAppid
Description copied from interface:ParaObject
Sets a new app name. Must not be null or empty.- Specified by:
setAppid
in interfaceParaObject
- Parameters:
appid
- the new app id (name)
-
getObjectURI
Description copied from interface:ParaObject
The URI of this object. For example: /users/123- Specified by:
getObjectURI
in interfaceParaObject
- Returns:
- the URI
- See Also:
-
getTags
Description copied from interface:ParaObject
The tags associated with this object. Tags must not be null or empty.- Specified by:
getTags
in interfaceParaObject
- Returns:
- a set of tags, or an empty set
- See Also:
-
setTags
Description copied from interface:ParaObject
Merges the given tags with existing tags.- Specified by:
setTags
in interfaceParaObject
- Parameters:
tags
- the additional tags, or clears all tags if set to null
-
getStored
Description copied from interface:ParaObject
Boolean flag which controls whether this object is stored in the database or not. Default is true.- Specified by:
getStored
in interfaceParaObject
- Returns:
- true if this object is stored in DB.
-
setStored
Description copied from interface:ParaObject
Sets the "isStored" flag.- Specified by:
setStored
in interfaceParaObject
- Parameters:
stored
- when set to true, object is stored in DB.
-
getIndexed
Description copied from interface:ParaObject
Boolean flag which controls whether this object is indexed by the search engine. Default is true.- Specified by:
getIndexed
in interfaceParaObject
- Returns:
- true if this object is indexed
-
setIndexed
Description copied from interface:ParaObject
Sets the "isIndexed" flag.- Specified by:
setIndexed
in interfaceParaObject
- Parameters:
indexed
- when set to true, object is indexed.
-
getCached
Description copied from interface:ParaObject
Boolean flag which controls whether this object is cached. Default is true.- Specified by:
getCached
in interfaceParaObject
- Returns:
- true if this object is cached on update() and create().
-
setCached
Description copied from interface:ParaObject
Sets the "isCached" flag.- Specified by:
setCached
in interfaceParaObject
- Parameters:
cached
- when set to true, object is cached.
-
getTimestamp
Description copied from interface:ParaObject
The time when the object was created, in milliseconds.- Specified by:
getTimestamp
in interfaceParaObject
- Returns:
- the timestamp of creation
-
setTimestamp
Description copied from interface:ParaObject
Sets the timestamp.- Specified by:
setTimestamp
in interfaceParaObject
- Parameters:
timestamp
- a new timestamp in milliseconds.
-
getCreatorid
Description copied from interface:ParaObject
The id of the user who created this. Should point to aUser
id.- Specified by:
getCreatorid
in interfaceParaObject
- Returns:
- the id or null
-
setCreatorid
Description copied from interface:ParaObject
Sets a new creator id. Must not be null or empty.- Specified by:
setCreatorid
in interfaceParaObject
- Parameters:
creatorid
- a new id
-
getName
Description copied from interface:ParaObject
The name of the object. Can be anything.- Specified by:
getName
in interfaceParaObject
- Returns:
- the name. default: [type id]
-
setName
Description copied from interface:ParaObject
Sets a new name. Must not be null or empty.- Specified by:
setName
in interfaceParaObject
- Parameters:
name
- the new name
-
getPlural
Description copied from interface:ParaObject
The plural name of the object. For example: user - users- Specified by:
getPlural
in interfaceParaObject
- Returns:
- the plural name
-
getParentid
Description copied from interface:ParaObject
The id of the parent object.- Specified by:
getParentid
in interfaceParaObject
- Returns:
- the id of the parent or null
-
setParentid
Description copied from interface:ParaObject
Sets a new parent id. Must not be null or empty.- Specified by:
setParentid
in interfaceParaObject
- Parameters:
parentid
- a new id
-
getUpdated
Description copied from interface:ParaObject
The last time this object was updated. Timestamp in ms.- Specified by:
getUpdated
in interfaceParaObject
- Returns:
- timestamp in milliseconds
-
setUpdated
Description copied from interface:ParaObject
Sets the last updated timestamp.- Specified by:
setUpdated
in interfaceParaObject
- Parameters:
updated
- a new timestamp
-
update
public void update()Description copied from interface:ParaObject
Updates the object permanently. Changes toLocked
fields are ignored.- Specified by:
update
in interfaceParaObject
- See Also:
-
exists
public boolean exists()Description copied from interface:ParaObject
Checks if an object is stored in the data store.- Specified by:
exists
in interfaceParaObject
- Returns:
- true if the object is persisted to the data store.
- See Also:
-
voteUp
-
voteDown
-
getVotes
-
setVotes
-
getVersion
Description copied from interface:ParaObject
Returns the version number for this object. Used primarily for optimistic locking.- Specified by:
getVersion
in interfaceParaObject
- Returns:
- a positive number,
0
if unused or-1
, indicating a failed update.
-
setVersion
Description copied from interface:ParaObject
Sets the version of this object. This value should come from the database.- Specified by:
setVersion
in interfaceParaObject
- Parameters:
version
- a positive number, different than the current value of the version field
-
countLinks
Description copied from interface:Linkable
Count the total number of links between this object and another type of object.- Specified by:
countLinks
in interfaceLinkable
- Parameters:
type2
- the other type of object- Returns:
- the number of links
-
getLinks
Description copied from interface:Linkable
Returns all links between this type object and another type of object. -
getLinkedObjects
Description copied from interface:Linkable
Similar toLinkable.getChildren(java.lang.String, com.erudika.para.core.utils.Pager...)
but for many-to-many relationships.- Specified by:
getLinkedObjects
in interfaceLinkable
- Type Parameters:
P
- type of linked objects- Parameters:
type
- type of linked objects to look forpager
- aPager
- Returns:
- a list of linked objects
-
findLinkedObjects
public <P extends ParaObject> List<P> findLinkedObjects(String type, String field, String query, Pager... pager) Description copied from interface:Linkable
Similar toLinkable.findChildren(java.lang.String, java.lang.String, com.erudika.para.core.utils.Pager...)
but for many-to-many relationships. Searches through all linked objects connected to this via aLinker
object.- Specified by:
findLinkedObjects
in interfaceLinkable
- Type Parameters:
P
- type of linked objects- Parameters:
type
- type of linked objects to look 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
-
isLinked
Description copied from interface:Linkable
Checks if a given object is linked to this one. -
link
Description copied from interface:Linkable
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. -
unlink
-
unlinkAll
-
countChildren
Description copied from interface:Linkable
Count the total number of child objects for this object.- Specified by:
countChildren
in interfaceLinkable
- Parameters:
type
- the other type of object- Returns:
- the number of links
-
getChildren
Description copied from interface:Linkable
Returns all child objects linked to this object.- Specified by:
getChildren
in interfaceLinkable
- Type Parameters:
P
- the type of children- Parameters:
type
- 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(String type, String field, String term, Pager... pager) Description copied from interface:Linkable
Returns all child objects linked to this object.- Specified by:
getChildren
in interfaceLinkable
- Type Parameters:
P
- the type of children- Parameters:
type
- 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
Description copied from interface:Linkable
Search through all child objects. Only searches child objects directly connected to this parent via theparentid
field.- Specified by:
findChildren
in interfaceLinkable
- Type Parameters:
P
- the type of children- Parameters:
type
- 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
Description copied from interface:Linkable
Deletes all child objects permanently.- Specified by:
deleteChildren
in interfaceLinkable
- Parameters:
type
- the children's type.
-
hashCode
-
equals
-
toString
-