Class PersistentResourceToken
- java.lang.Object
-
- org.silverpeas.core.persistence.datasource.model.jpa.AbstractJpaEntity<E,I>
-
- org.silverpeas.core.persistence.datasource.model.jpa.BasicJpaEntity<PersistentResourceToken,UniqueLongIdentifier>
-
- org.silverpeas.core.security.token.persistent.PersistentResourceToken
-
- All Implemented Interfaces:
Serializable
,IdentifiableEntity
,Token
@Entity @TokenGenerator(PersistentResourceTokenGenerator.class) public class PersistentResourceToken extends BasicJpaEntity<PersistentResourceToken,UniqueLongIdentifier> implements Token
A persistent token used to identify uniquely a resource. This token has the particularity to be persisted in a data source and to refer the resource it identifies uniquely both by the resource identifier and by the resource type.- Author:
- Yohann Chastagnier
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static PersistentResourceToken
NoneToken
Represents none token to replace in more typing way the null keyword.
-
Constructor Summary
Constructors Modifier Constructor Description protected
PersistentResourceToken()
protected
PersistentResourceToken(EntityReference resource, String value)
Constructs a new persistent token for the specified resource and with the specified value.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static PersistentResourceToken
createToken(EntityReference resource)
Creates a token for the specified resource.boolean
exists()
Indicates if the token is well registeredstatic PersistentResourceToken
getOrCreateToken(EntityReference resource)
Gets a token for the specified resource and creates it if it doesn't exist.<E,R extends EntityReference<E>>
RgetResource(Class<R> referenceClass)
Gets a reference to the resource this token is for.int
getSaveCount()
Date
getSaveDate()
static PersistentResourceToken
getToken(String token)
Gets a the token from the specified value.String
getValue()
Gets the String representation of this token.boolean
isDefined()
Is this token defined?boolean
notExists()
Indicates if the token isn't registered.protected void
performBeforePersist()
Performs some treatments before this entity is persisted into a repository.protected void
performBeforeUpdate()
Performs some treatments before its counterpart in a repository is updated with the changes in this entity.static void
removeToken(EntityReference resource)
Removes the token for the specified resource.void
setId(Long id)
void
setResource(EntityReference resource)
Sets the resource to which this token belongs.void
setSaveCount(int saveCount)
void
setSaveDate(Date saveDate)
void
setValue(String value)
String
toString()
void
validate()
Validates data-
Methods inherited from class org.silverpeas.core.persistence.datasource.model.jpa.BasicJpaEntity
performBeforeRemove
-
Methods inherited from class org.silverpeas.core.persistence.datasource.model.jpa.AbstractJpaEntity
equals, getId, getNativeId, hashCode, isPersisted, setId
-
-
-
-
Field Detail
-
NoneToken
public static final PersistentResourceToken NoneToken
Represents none token to replace in more typing way the null keyword.
-
-
Constructor Detail
-
PersistentResourceToken
protected PersistentResourceToken()
-
PersistentResourceToken
protected PersistentResourceToken(EntityReference resource, String value)
Constructs a new persistent token for the specified resource and with the specified value.- Parameters:
resource
- a reference to the resource for which this token is constructed.value
- the token value.
-
-
Method Detail
-
createToken
public static PersistentResourceToken createToken(EntityReference resource) throws TokenException
Creates a token for the specified resource. If the specified resource has already a token, then renews it. Otherwise a new token is generated and persisted into the data source.- Parameters:
resource
- the resource for which the token has to be generated.- Returns:
- a token for the specified resource.
- Throws:
TokenException
-
getOrCreateToken
public static PersistentResourceToken getOrCreateToken(EntityReference resource) throws TokenException
Gets a token for the specified resource and creates it if it doesn't exist. If the specified resource has already a token, then returns it. Otherwise a new token is generated and persisted into the data source.- Parameters:
resource
- the resource for which the token has to be generated.- Returns:
- a token for the specified resource.
- Throws:
TokenException
-
getToken
public static PersistentResourceToken getToken(String token)
Gets a the token from the specified value. If not token exist with the specified value, thenNoneToken
is returned.- Parameters:
token
- the value of the token to get.- Returns:
- the token that matches the specified value.
-
removeToken
public static void removeToken(EntityReference resource)
Removes the token for the specified resource.- Parameters:
resource
- the resource for which the token has to be removed.
-
performBeforePersist
protected void performBeforePersist()
Description copied from class:AbstractJpaEntity
Performs some treatments before this entity is persisted into a repository.- Overrides:
performBeforePersist
in classBasicJpaEntity<PersistentResourceToken,UniqueLongIdentifier>
-
performBeforeUpdate
protected void performBeforeUpdate()
Description copied from class:AbstractJpaEntity
Performs some treatments before its counterpart in a repository is updated with the changes in this entity.- Overrides:
performBeforeUpdate
in classBasicJpaEntity<PersistentResourceToken,UniqueLongIdentifier>
-
exists
public boolean exists()
Indicates if the token is well registered- Returns:
- a boolean indicating if this token exists in the data source.
-
notExists
public boolean notExists()
Indicates if the token isn't registered.- Returns:
- a boolean indicating if this token doesn't exist in the data source.
-
validate
public void validate() throws TokenValidationException
Validates data- Throws:
TokenValidationException
-
setId
public void setId(Long id)
- Parameters:
id
- the id to set
-
getResource
public <E,R extends EntityReference<E>> R getResource(Class<R> referenceClass)
Gets a reference to the resource this token is for.- Type Parameters:
E
- the concrete type of the entity.R
- the concrete type of the reference to the entity.- Parameters:
referenceClass
- the expected concrete class of theEntityReference
. This class must be conform to the type of the resource.- Returns:
- a reference to the resource that owns this token or null if there is neither no resource defined for this token nor no reference defined for the targeted type of resource.
-
setResource
public void setResource(EntityReference resource)
Sets the resource to which this token belongs.- Parameters:
resource
- an identifier of the resource for which this token is.
-
getValue
public String getValue()
Description copied from interface:Token
Gets the String representation of this token.
-
setValue
public void setValue(String value)
- Parameters:
value
- the value to set
-
getSaveCount
public int getSaveCount()
- Returns:
- the saveCount
-
setSaveCount
public void setSaveCount(int saveCount)
- Parameters:
saveCount
- the saveCount to set
-
getSaveDate
public Date getSaveDate()
- Returns:
- the saveDate
-
setSaveDate
public void setSaveDate(Date saveDate)
- Parameters:
saveDate
- the saveDate to set
-
isDefined
public boolean isDefined()
Description copied from interface:Token
Is this token defined? A token is defined if it was generated and represents correctly a well-valued token. If it is empty (a none token), then it is considered as undefined. It is expected a token can be never null and a none-token concept is used instead. This method is to check the token is not a none-token, that is to say it is well initialized.
-
-