- java.lang.Object
-
- com.erudika.para.core.User
-
- All Implemented Interfaces:
Linkable,ParaObject,Votable,Serializable
public class User extends Object implements ParaObject
The core user object. Stores information about users.- Author:
- Alex Bogdanovski [alex@erudika.com]
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classUser.GroupsSimple groups enum.static classUser.RolesSimple user roles enum.-
Nested classes/interfaces inherited from interface com.erudika.para.core.Votable
Votable.VoteValue
-
-
Field Summary
Fields Modifier and Type Field Description static intMAX_PASSWORD_LENGTHMaximum password length.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanactivateWithEmailToken(String token)Activates a user if a given token matches the one stored.voidattachIdentifier(String identifier)Attaches a new identifier to this user.booleancanModify(ParaObject obj)Note: this method assumes that child objects can be modified by their parents.LongcountChildren(String type)Count the total number of child objects for this object.LongcountLinks(String type2)Count the total number of links between this object and another type of object.Stringcreate()Stores this object in the data store.voiddelete()Deletes the object permanently by removing it from the data store.voiddeleteChildren(String type)Deletes all child objects permanently.voiddetachIdentifier(String identifier)Detaches a secondary identifier which is not already used by this user.booleanequals(Object obj)booleanexists()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.StringgenerateEmailConfirmationToken()Generates a new email confirmation token.StringgeneratePasswordResetToken()Generates a new password reset token.BooleangetActive()Returns true if this account is active.StringgetAppid()The application name.BooleangetCached()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.StringgetCreatorid()The id of the user who created this.StringgetCurrency()The user's currency preference.StringgetEmail()The user's email.StringgetGroups()Returns the security groups for this user.StringgetId()The id of an object.StringgetIdentifier()Returns the main identifier for this user.StringgetIdentityProvider()Returns the name of the identity provider.StringgetIdpAccessToken()Used for storing the access token from an OpenID Connect/OAuth 2.0 identity provider.StringgetIdpAccessTokenPayload()Returns the JWT payload for the access token coming from the IDP.StringgetIdpIdToken()Used for storing the ID token from an OpenID Connect/OAuth 2.0 identity provider.StringgetIdpIdTokenPayload()Returns the JWT payload for the ID token coming from the IDP.StringgetIdpRefreshToken()Stores the refresh token from the identity provider.BooleangetIndexed()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.List<Linker>getLinks(String type2, Pager... pager)Returns all links between this type object and another type of object.StringgetName()The name of the object.StringgetObjectURI()The URI of this object.StringgetParentid()The id of the parent object.StringgetPassword()The password.StringgetPicture()The profile picture URL.StringgetPlural()The plural name of the object.BooleangetStored()Boolean flag which controls whether this object is stored in the database or not.List<String>getTags()The tags associated with this object.LonggetTimestamp()The time when the object was created, in milliseconds.StringgetTokenSecret()Token secret - used for generating JWT tokens.BooleangetTwoFA()StringgetTwoFAbackupKeyHash()StringgetTwoFAkey()StringgetType()The name of the object's class.LonggetUpdated()The last time this object was updated.LonggetVersion()Returns the version number for this object.IntegergetVotes()Returns the total sum of all votes for this object.inthashCode()booleanisAdmin()Checks for admin rights.booleanisAmazonUser()Is the main identifier a Amazon account id.booleanisFacebookUser()Is the main identifier a Facebook id.booleanisGitHubUser()Is the main identifier a GitHub id.booleanisGooglePlusUser()Is the main identifier a Google+ id.booleanisLDAPUser()Is the main identifier a LDAP account.booleanisLinked(ParaObject toObj)Checks if a given object is linked to this one.booleanisLinked(String type2, String id2)Checks if this object is linked to another.booleanisLinkedInUser()Is the main identifier a LinkedIn id.booleanisMattermostUser()Is the main identifier a Mattermost account id.booleanisMicrosoftUser()Is the main identifier a Microsoft/Windows account id.booleanisModerator()Checks for moderator rights.booleanisOAuth2User()Is the main identifier from a generic OAuth 2.0/OpenID Connect provider.booleanisSAMLUser()Is the main identifier a SAML account.booleanisSlackUser()Is the main identifier a Slack account id.booleanisTwitterUser()Is the main identifier a Twitter id.booleanisValidEmailConfirmationToken(String token)Validates a token sent for email confirmation.booleanisValidPasswordResetToken(String token)Validates a token sent via email for password reset.Stringlink(String id2)Links an object to this one in a many-to-many relationship.static booleanpasswordMatches(User u)Checks if a user has entered the correct password.static UserreadUserForIdentifier(User u)Returns a user object for a given identifier.booleanresetPassword(String token, String newpass)Changes the user password permanently.voidresetTokenSecret()Generates a new token secret.voidsetActive(Boolean active)Sets the account active.voidsetAppid(String appid)Sets a new app name.voidsetCached(Boolean cached)Sets the "isCached" flag.voidsetCreatorid(String creatorid)Sets a new creator id.voidsetCurrency(String currency)Sets a preferred currency.voidsetEmail(String email)Sets the email.voidsetGroups(String groups)Sets the security groups for this user.voidsetId(String id)Sets a new id.voidsetIdentifier(String identifier)Sets the main identifier.voidsetIdpAccessToken(String idpAccessToken)Sets the IDP access token.voidsetIdpIdToken(String idpIdToken)Sets the IDP ID token.voidsetIdpRefreshToken(String idpRefreshToken)Sets the refresh token.voidsetIndexed(Boolean indexed)Sets the "isIndexed" flag.voidsetName(String name)Sets a new name.voidsetParentid(String parentid)Sets a new parent id.voidsetPassword(String password)Sets a password.voidsetPicture(String picture)Sets the profile picture URL.voidsetStored(Boolean stored)Sets the "isStored" flag.voidsetTags(List<String> tags)Merges the given tags with existing tags.voidsetTimestamp(Long timestamp)Sets the timestamp.voidsetTokenSecret(String tokenSecret)Sets the token secret.voidsetTwoFA(Boolean twoFA)Sets 2FA enabled/disabled.voidsetTwoFAbackupKeyHash(String twoFAbackupKeyHash)Sets the 2FA backup key hash.voidsetTwoFAkey(String twoFAkey)Sets the 2FA secret key.voidsetType(String type)Sets a new object type.voidsetUpdated(Long updated)Sets the last updated timestamp.voidsetVersion(Long version)Sets the version of this object.voidsetVotes(Integer votes)Sets the total votes for this object.StringtoString()voidunlink(String type, String id2)Unlinks an object from this one.voidunlinkAll()Unlinks all objects that are linked to this one.voidupdate()Updates the object permanently.booleanvoteDown(String userid)Downvotes the object.booleanvoteUp(String userid)Upvotes the object.
-
-
-
Field Detail
-
MAX_PASSWORD_LENGTH
public static final int MAX_PASSWORD_LENGTH
Maximum password length.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
User
public User()
No-args constructor.
-
User
public User(String id)
Default constructor.- Parameters:
id- the id
-
-
Method Detail
-
getTokenSecret
public String getTokenSecret()
Token secret - used for generating JWT tokens. Changing this secret would invalidate all existing user tokens. A kind of global "logout".- Returns:
- a random string
-
setTokenSecret
public void setTokenSecret(String tokenSecret)
Sets the token secret.- Parameters:
tokenSecret- a random string
-
getPicture
public String getPicture()
The profile picture URL.- Returns:
- a URL or null
-
setPicture
public void setPicture(String picture)
Sets the profile picture URL.- Parameters:
picture- the picture URL.
-
getActive
public Boolean getActive()
Returns true if this account is active.- Returns:
- true if active
-
setActive
public void setActive(Boolean active)
Sets the account active.- Parameters:
active- true if active
-
getTwoFA
public Boolean getTwoFA()
- Returns:
- true if 2FA is enabled
-
setTwoFA
public void setTwoFA(Boolean twoFA)
Sets 2FA enabled/disabled.- Parameters:
twoFA- true if 2FA is enabled
-
getTwoFAkey
public String getTwoFAkey()
- Returns:
- the 2FA secret key. Used for checking the TOTP code.
-
setTwoFAkey
public void setTwoFAkey(String twoFAkey)
Sets the 2FA secret key.- Parameters:
twoFAkey- secret key
-
getTwoFAbackupKeyHash
public String getTwoFAbackupKeyHash()
- Returns:
- the hashed backup key (shown only once). Used for disabling 2FA.
-
setTwoFAbackupKeyHash
public void setTwoFAbackupKeyHash(String twoFAbackupKeyHash)
Sets the 2FA backup key hash.- Parameters:
twoFAbackupKeyHash- bcrypt hash
-
getGroups
public String getGroups()
Returns the security groups for this user.- Returns:
- the groups string
-
setGroups
public void setGroups(String groups)
Sets the security groups for this user.- Parameters:
groups- the groups string
-
getIdentifier
public String getIdentifier()
Returns the main identifier for this user. An identifier is basically a unique username that identifies a user.- Returns:
- the main identifier
-
setIdentifier
public void setIdentifier(String identifier)
Sets the main identifier.- Parameters:
identifier- the main identifier
-
getEmail
public String getEmail()
The user's email.- Returns:
-
setEmail
public void setEmail(String email)
Sets the email.- Parameters:
email- email
-
getCurrency
public String getCurrency()
The user's currency preference.- Returns:
- a currency 3-letter code in uppercase
-
setCurrency
public void setCurrency(String currency)
Sets a preferred currency. Default is "EUR".- Parameters:
currency- a 3-letter currency code
-
resetTokenSecret
public void resetTokenSecret()
Generates a new token secret. This is whould be equivalent to "logout everywhere".
-
canModify
public boolean canModify(ParaObject obj)
Note: this method assumes that child objects can be modified by their parents. This might not work for special cases where a parent has no rights over a child.- Parameters:
obj- an object- Returns:
- true if the user is the creator or parent of this object or an admin user
-
create
public String create()
Description copied from interface:ParaObjectStores this object in the data store.- Specified by:
createin interfaceParaObject- Returns:
- the id of the object (a new id if object is new)
- See Also:
Stored,DAO.create(com.erudika.para.core.ParaObject)
-
delete
public void delete()
Description copied from interface:ParaObjectDeletes the object permanently by removing it from the data store.- Specified by:
deletein interfaceParaObject- See Also:
DAO.delete(com.erudika.para.core.ParaObject)
-
attachIdentifier
public void attachIdentifier(String identifier)
Attaches a new identifier to this user.- Parameters:
identifier- a new identifier
-
detachIdentifier
public void detachIdentifier(String identifier)
Detaches a secondary identifier which is not already used by this user.- Parameters:
identifier- an attached identifier
-
isFacebookUser
public boolean isFacebookUser()
Is the main identifier a Facebook id.- Returns:
- true if user is signed in with Facebook
-
isGooglePlusUser
public boolean isGooglePlusUser()
Is the main identifier a Google+ id.- Returns:
- true if user is signed in with Google+
-
isLinkedInUser
public boolean isLinkedInUser()
Is the main identifier a LinkedIn id.- Returns:
- true if user is signed in with LinkedIn
-
isTwitterUser
public boolean isTwitterUser()
Is the main identifier a Twitter id.- Returns:
- true if user is signed in with Twitter
-
isGitHubUser
public boolean isGitHubUser()
Is the main identifier a GitHub id.- Returns:
- true if user is signed in with GitHub
-
isMicrosoftUser
public boolean isMicrosoftUser()
Is the main identifier a Microsoft/Windows account id.- Returns:
- true if user is signed in with a Microsoft account
-
isSlackUser
public boolean isSlackUser()
Is the main identifier a Slack account id.- Returns:
- true if user is signed in with a Slack account
-
isMattermostUser
public boolean isMattermostUser()
Is the main identifier a Mattermost account id.- Returns:
- true if user is signed in with a Mattermost account
-
isAmazonUser
public boolean isAmazonUser()
Is the main identifier a Amazon account id.- Returns:
- true if user is signed in with a Amazon account
-
isLDAPUser
public boolean isLDAPUser()
Is the main identifier a LDAP account.- Returns:
- true if user is signed in with a LDAP account
-
isSAMLUser
public boolean isSAMLUser()
Is the main identifier a SAML account.- Returns:
- true if user is signed in with a SAML account
-
isOAuth2User
public boolean isOAuth2User()
Is the main identifier from a generic OAuth 2.0/OpenID Connect provider.- Returns:
- true if user is signed in with a generic OAauth 2.0 account
-
isAdmin
public boolean isAdmin()
Checks for admin rights.- Returns:
- true if user has admin rights
-
isModerator
public boolean isModerator()
Checks for moderator rights.- Returns:
- true if user has mod rights
-
getIdentityProvider
public String getIdentityProvider()
Returns the name of the identity provider.- Returns:
- "facebook", "google"... etc.
-
getPassword
public String getPassword()
The password. A transient field used for validation.- Returns:
- the password.
-
setPassword
public void setPassword(String password)
Sets a password.- Parameters:
password- a password
-
getIdpIdToken
public String getIdpIdToken()
Used for storing the ID token from an OpenID Connect/OAuth 2.0 identity provider.- Returns:
- an ID token (JWT is always assumed to be the format)
-
setIdpIdToken
public void setIdpIdToken(String idpIdToken)
Sets the IDP ID token.- Parameters:
idpIdToken- a token
-
getIdpAccessToken
public String getIdpAccessToken()
Used for storing the access token from an OpenID Connect/OAuth 2.0 identity provider.- Returns:
- a JWT access token (JWT is always assumed to be the format)
-
setIdpAccessToken
public void setIdpAccessToken(String idpAccessToken)
Sets the IDP access token.- Parameters:
idpAccessToken- a token
-
getIdpRefreshToken
public String getIdpRefreshToken()
Stores the refresh token from the identity provider.- Returns:
- a JWT refresh token
-
setIdpRefreshToken
public void setIdpRefreshToken(String idpRefreshToken)
Sets the refresh token.- Parameters:
idpRefreshToken- a refresh token
-
getIdpIdTokenPayload
public String getIdpIdTokenPayload()
Returns the JWT payload for the ID token coming from the IDP. Used for delegating user attributes data to clients. This must be a Base64-encoded JSON string.- Returns:
- the payload part in Base64
-
getIdpAccessTokenPayload
public String getIdpAccessTokenPayload()
Returns the JWT payload for the access token coming from the IDP. Used for delegating user attributes data to clients. This must be a Base64-encoded JSON string.- Returns:
- the payload part in Base64
-
readUserForIdentifier
public static final User readUserForIdentifier(User u)
Returns a user object for a given identifier.- Parameters:
u- a user having a valid identifier set.- Returns:
- a user or null if no user is found for this identifier
-
passwordMatches
public static final boolean passwordMatches(User u) throws LimitExceededException
Checks if a user has entered the correct password. Compares password hashes.- Parameters:
u- a user with a set password- Returns:
- true if password matches the one in the data store
- Throws:
LimitExceededException- if rate limit is exceeded when password doesn't match.
-
generatePasswordResetToken
public final String generatePasswordResetToken()
Generates a new password reset token. Sent via email for pass reset.- Returns:
- the pass reset token
-
resetPassword
public final boolean resetPassword(String token, String newpass)
Changes the user password permanently.- Parameters:
token- the reset token. seegeneratePasswordResetToken()newpass- the new password- Returns:
- true if successful
-
generateEmailConfirmationToken
public String generateEmailConfirmationToken()
Generates a new email confirmation token. Sent via email for user activation.- Returns:
- a Base64 encoded UUID
-
activateWithEmailToken
public final boolean activateWithEmailToken(String token)
Activates a user if a given token matches the one stored.- Parameters:
token- the email confirmation token. seegenerateEmailConfirmationToken()- Returns:
- true if successful
-
isValidPasswordResetToken
public final boolean isValidPasswordResetToken(String token)
Validates a token sent via email for password reset.- Parameters:
token- a token- Returns:
- true if valid
-
isValidEmailConfirmationToken
public final boolean isValidEmailConfirmationToken(String token)
Validates a token sent for email confirmation.- Parameters:
token- a token- Returns:
- true if valid
-
getId
public final String getId()
Description copied from interface:ParaObjectThe id of an object. Usually an autogenerated unique string of numbers.- Specified by:
getIdin interfaceParaObject- Returns:
- the id
-
setId
public final void setId(String id)
Description copied from interface:ParaObjectSets a new id. Must not be null or empty.- Specified by:
setIdin interfaceParaObject- Parameters:
id- the new id
-
getType
public final String getType()
Description copied from interface:ParaObjectThe name of the object's class. This is equivalent toClass.getSimpleName().toLowerCase()- Specified by:
getTypein interfaceParaObject- Returns:
- the simple name of the class
-
setType
public final void setType(String type)
Description copied from interface:ParaObjectSets a new object type. Must not be null or empty.- Specified by:
setTypein interfaceParaObject- Parameters:
type- a new type
-
getAppid
public String getAppid()
Description copied from interface:ParaObjectThe application name. Added to support multiple separate apps. Every object must belong to an app.- Specified by:
getAppidin interfaceParaObject- Returns:
- the app id (name). default: para
-
setAppid
public void setAppid(String appid)
Description copied from interface:ParaObjectSets a new app name. Must not be null or empty.- Specified by:
setAppidin interfaceParaObject- Parameters:
appid- the new app id (name)
-
getObjectURI
public String getObjectURI()
Description copied from interface:ParaObjectThe URI of this object. For example: /users/123- Specified by:
getObjectURIin interfaceParaObject- Returns:
- the URI
- See Also:
Utils.getObjectURI(com.erudika.para.core.ParaObject, boolean, boolean)
-
getTags
public List<String> getTags()
Description copied from interface:ParaObjectThe tags associated with this object. Tags must not be null or empty.- Specified by:
getTagsin interfaceParaObject- Returns:
- a set of tags, or an empty set
- See Also:
Tag
-
setTags
public void setTags(List<String> tags)
Description copied from interface:ParaObjectMerges the given tags with existing tags.- Specified by:
setTagsin interfaceParaObject- Parameters:
tags- the additional tags, or clears all tags if set to null
-
getStored
public Boolean getStored()
Description copied from interface:ParaObjectBoolean flag which controls whether this object is stored in the database or not. Default is true.- Specified by:
getStoredin interfaceParaObject- Returns:
- true if this object is stored in DB.
-
setStored
public void setStored(Boolean stored)
Description copied from interface:ParaObjectSets the "isStored" flag.- Specified by:
setStoredin interfaceParaObject- Parameters:
stored- when set to true, object is stored in DB.
-
getIndexed
public Boolean getIndexed()
Description copied from interface:ParaObjectBoolean flag which controls whether this object is indexed by the search engine. Default is true.- Specified by:
getIndexedin interfaceParaObject- Returns:
- true if this object is indexed
-
setIndexed
public void setIndexed(Boolean indexed)
Description copied from interface:ParaObjectSets the "isIndexed" flag.- Specified by:
setIndexedin interfaceParaObject- Parameters:
indexed- when set to true, object is indexed.
-
getCached
public Boolean getCached()
Description copied from interface:ParaObjectBoolean flag which controls whether this object is cached. Default is true.- Specified by:
getCachedin interfaceParaObject- Returns:
- true if this object is cached on update() and create().
-
setCached
public void setCached(Boolean cached)
Description copied from interface:ParaObjectSets the "isCached" flag.- Specified by:
setCachedin interfaceParaObject- Parameters:
cached- when set to true, object is cached.
-
getTimestamp
public Long getTimestamp()
Description copied from interface:ParaObjectThe time when the object was created, in milliseconds.- Specified by:
getTimestampin interfaceParaObject- Returns:
- the timestamp of creation
-
setTimestamp
public void setTimestamp(Long timestamp)
Description copied from interface:ParaObjectSets the timestamp.- Specified by:
setTimestampin interfaceParaObject- Parameters:
timestamp- a new timestamp in milliseconds.
-
getCreatorid
public String getCreatorid()
Description copied from interface:ParaObjectThe id of the user who created this. Should point to aUserid.- Specified by:
getCreatoridin interfaceParaObject- Returns:
- the id or null
-
setCreatorid
public void setCreatorid(String creatorid)
Description copied from interface:ParaObjectSets a new creator id. Must not be null or empty.- Specified by:
setCreatoridin interfaceParaObject- Parameters:
creatorid- a new id
-
getName
public final String getName()
Description copied from interface:ParaObjectThe name of the object. Can be anything.- Specified by:
getNamein interfaceParaObject- Returns:
- the name. default: [type id]
-
setName
public final void setName(String name)
Description copied from interface:ParaObjectSets a new name. Must not be null or empty.- Specified by:
setNamein interfaceParaObject- Parameters:
name- the new name
-
getPlural
public String getPlural()
Description copied from interface:ParaObjectThe plural name of the object. For example: user - users- Specified by:
getPluralin interfaceParaObject- Returns:
- the plural name
-
getParentid
public String getParentid()
Description copied from interface:ParaObjectThe id of the parent object.- Specified by:
getParentidin interfaceParaObject- Returns:
- the id of the parent or null
-
setParentid
public void setParentid(String parentid)
Description copied from interface:ParaObjectSets a new parent id. Must not be null or empty.- Specified by:
setParentidin interfaceParaObject- Parameters:
parentid- a new id
-
getUpdated
public Long getUpdated()
Description copied from interface:ParaObjectThe last time this object was updated. Timestamp in ms.- Specified by:
getUpdatedin interfaceParaObject- Returns:
- timestamp in milliseconds
-
setUpdated
public void setUpdated(Long updated)
Description copied from interface:ParaObjectSets the last updated timestamp.- Specified by:
setUpdatedin interfaceParaObject- Parameters:
updated- a new timestamp
-
update
public void update()
Description copied from interface:ParaObjectUpdates the object permanently. Changes toLockedfields are ignored.- Specified by:
updatein interfaceParaObject- See Also:
Locked,DAO.update(com.erudika.para.core.ParaObject)
-
exists
public boolean exists()
Description copied from interface:ParaObjectChecks if an object is stored in the data store.- Specified by:
existsin interfaceParaObject- Returns:
- true if the object is persisted to the data store.
- See Also:
DAO.read(java.lang.String)
-
voteUp
public boolean voteUp(String userid)
Description copied from interface:VotableUpvotes the object.
-
voteDown
public boolean voteDown(String userid)
Description copied from interface:VotableDownvotes the object.
-
getVotes
public Integer getVotes()
Description copied from interface:VotableReturns the total sum of all votes for this object. For example: (+6) + (-4) = 2
-
setVotes
public void setVotes(Integer votes)
Description copied from interface:VotableSets the total votes for this object.
-
getVersion
public Long getVersion()
Description copied from interface:ParaObjectReturns the version number for this object. Used primarily for optimistic locking.- Specified by:
getVersionin interfaceParaObject- Returns:
- a positive number,
0if unused or-1, indicating a failed update.
-
setVersion
public void setVersion(Long version)
Description copied from interface:ParaObjectSets the version of this object. This value should come from the database.- Specified by:
setVersionin interfaceParaObject- Parameters:
version- a positive number, different than the current value of the version field
-
countLinks
public Long countLinks(String type2)
Description copied from interface:LinkableCount the total number of links between this object and another type of object.- Specified by:
countLinksin interfaceLinkable- Parameters:
type2- the other type of object- Returns:
- the number of links
-
getLinks
public List<Linker> getLinks(String type2, Pager... pager)
Description copied from interface:LinkableReturns all links between this type object and another type of object.
-
getLinkedObjects
public <P extends ParaObject> List<P> getLinkedObjects(String type, Pager... pager)
Description copied from interface:LinkableSimilar toLinkable.getChildren(java.lang.String, com.erudika.para.core.utils.Pager...)but for many-to-many relationships.- Specified by:
getLinkedObjectsin 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:LinkableSimilar 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 aLinkerobject.- Specified by:
findLinkedObjectsin 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
public boolean isLinked(String type2, String id2)
Description copied from interface:LinkableChecks if this object is linked to another.
-
isLinked
public boolean isLinked(ParaObject toObj)
Description copied from interface:LinkableChecks if a given object is linked to this one.
-
link
public String link(String id2)
Description copied from interface:LinkableLinks 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
public void unlink(String type, String id2)
Description copied from interface:LinkableUnlinks an object from this one. Only a link is deleted. Objects are left untouched.
-
unlinkAll
public void unlinkAll()
Description copied from interface:LinkableUnlinks all objects that are linked to this one. Deletes allLinkerobjects. Only the links are deleted. Objects are left untouched.
-
countChildren
public Long countChildren(String type)
Description copied from interface:LinkableCount the total number of child objects for this object.- Specified by:
countChildrenin interfaceLinkable- Parameters:
type- the other type of object- Returns:
- the number of links
-
getChildren
public <P extends ParaObject> List<P> getChildren(String type, Pager... pager)
Description copied from interface:LinkableReturns all child objects linked to this object.- Specified by:
getChildrenin interfaceLinkable- Type Parameters:
P- the type of children- Parameters:
type- the type of children to look forpager- aPager- Returns:
- a list of
ParaObjectin 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:LinkableReturns all child objects linked to this object.- Specified by:
getChildrenin 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
ParaObjectin a one-to-many relationship with this object
-
findChildren
public <P extends ParaObject> List<P> findChildren(String type, String query, Pager... pager)
Description copied from interface:LinkableSearch through all child objects. Only searches child objects directly connected to this parent via theparentidfield.- Specified by:
findChildrenin 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
ParaObjectin a one-to-many relationship with this object
-
deleteChildren
public void deleteChildren(String type)
Description copied from interface:LinkableDeletes all child objects permanently.- Specified by:
deleteChildrenin interfaceLinkable- Parameters:
type- the children's type.
-
-