ccc.domain
Class ResourceEntity

java.lang.Object
  extended by ccc.domain.Entity
      extended by ccc.domain.ResourceEntity
All Implemented Interfaces:
Lockable, SnapshotSupport<Resource>, Jsonable, java.io.Serializable
Direct Known Subclasses:
AliasEntity, FolderEntity, HistoricalResource, Search

public abstract class ResourceEntity
extends Entity
implements SnapshotSupport<Resource>, Lockable

An abstract superclass that contains shared behaviour for the different types of CCC resource.

Author:
Civic Computing Ltd
See Also:
Serialized Form

Constructor Summary
protected ResourceEntity()
          Constructor: for persistence only.
protected ResourceEntity(ResourceName name, java.lang.String title)
          Constructor.
  ResourceEntity(java.lang.String title)
          Constructor.
 
Method Summary
 void addGroupPermission(AccessPermission p)
          Mutator.
 void addMetadata(java.util.Map<java.lang.String,java.lang.String> metadata)
          Add metadata to this resource.
 void addMetadatum(java.lang.String key, java.lang.String value)
          Add new metadata for this resource.
 void addUserPermission(AccessPermission p)
          Mutator.
<T extends ResourceEntity>
T
as(java.lang.Class<T> resourceType)
          Type-safe helper method to convert an instance of ResourceEntity to a subclass.
 boolean canUnlock(UserEntity user)
          Determine whether a user can unlock this resource.
 void clearGroupAcl()
          Remove all group permissions.
 void clearMetadata()
          Remove all metadata for this resource.
 void clearMetadatum(java.lang.String key)
          Remove the metadatum with the specified key.
 void clearUserAcl()
          Remove all user permissions.
 Duration computeCache()
          Compute the cache duration for the resource.
 java.util.Map<java.lang.String,java.lang.String> computeMetadata()
          Compute the complete set of metadata for this resource.
 TemplateEntity computeTemplate(TemplateEntity def)
          Determine the template for this resource.
 void confirmLock(UserEntity user)
          Confirm this resource is locked by the specified user.
 void delete()
          Mark this file as deleted.
 ResourcePath getAbsolutePath()
          Determine the absolute path for a resource.
 ACL getAcl()
          Accessor.
 Duration getCacheDuration()
          Accessor.
 UserEntity getChangedBy()
          Query method - determine who last changed this resource.
 UserEntity getCreatedBy()
          Query method - determine who created this resource.
 java.util.Date getDateChanged()
          
 java.util.Date getDateCreated()
          
 java.lang.String getDescription()
          
 java.util.Collection<ACL.Entry> getGroupAcl()
          Accessor.
 java.lang.Integer getIndex()
          Accessor.
 UserEntity getLockedBy()
          Query method - determine who has locked this resource.
 java.util.Map<java.lang.String,java.lang.String> getMetadata()
          Accessor for all metadata of the resource.
 java.lang.String getMetadatum(java.lang.String key)
          Calculate the resource's metadatum for a given key.
 ResourceName getName()
          
 FolderEntity getParent()
          Accessor for the resource's parent.
 UserEntity getPublishedBy()
          Return user who published the resource.
 ResourceEntity getRoot()
          Accessor for the root parent of this resource.
 java.util.Set<java.lang.String> getTags()
          
 TemplateEntity getTemplate()
          Accessor for the template.
 java.lang.String getTitle()
          
abstract  ResourceType getType()
          Query the type of this resource.
 java.util.Collection<ACL.Entry> getUserAcl()
          Accessor.
 boolean isDeleted()
          Query method.
 boolean isIncludedInMainMenu()
          
 boolean isIndexable()
          Determine whether a resource can be indexed by the search engine.
 boolean isLocked()
          Query method to determine whether a resource is locked.
 boolean isPublished()
          Query method to determine whether a resource is published.
 boolean isReadableBy(UserEntity user)
          
 boolean isSecure()
          Query method to determine whether a resource is secure.
 boolean isVisible()
          Query method to determine whether a resource is visible.
 boolean isWriteableBy(UserEntity user)
          
 void lock(UserEntity u)
          Lock a resource.
 ResourceSummary mapResource()
          Create a summary for a resource.
static java.util.List<ResourceSummary> mapResources(java.util.Collection<? extends ResourceEntity> resources)
          Map a collection of Resource to a collection of ResourceSummary.
 void publish(UserEntity user)
          Publish the resource.
 void setCacheDuration(Duration cache)
          Mutator.
 void setDateChanged(java.util.Date changedOn, UserEntity changedBy)
          Mutator for the date the resource last changed.
 void setDateCreated(java.util.Date createdOn, UserEntity createdBy)
          Mutator for the date the resource was created.
 void setDescription(java.lang.String description)
          Mutator for the file description.
protected  void setDtoProps(Resource dto)
          Populate the specified DTO with data from this resource.
 void setIncludedInMainMenu(boolean shouldInclude)
          Mutator for 'include in main menu' property.
 void setIndexPosition(int index)
          Set the index value for this resource.
 void setName(ResourceName resourceName)
          Mutator for the name field.
 void setTags(java.util.Set<java.lang.String> tags)
          Set the tags for this resource.
 void setTemplate(TemplateEntity template)
          Sets the template for this resource.
 void setTitle(java.lang.String titleString)
          Sets the title of the resource.
 void toJson(Json json)
          Convert to JSON.
 void undelete()
          Mark this file as un-deleted.
 void unlock(UserEntity user)
          Unlock the resource.
 void unpublish()
          Unpublish the resource.
 
Methods inherited from class ccc.domain.Entity
equals, getId, getVersion, hashCode, setId, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ccc.domain.SnapshotSupport
forCurrentRevision, forSpecificRevision, forWorkingCopy
 

Constructor Detail

ResourceEntity

protected ResourceEntity()
Constructor: for persistence only.


ResourceEntity

protected ResourceEntity(ResourceName name,
                         java.lang.String title)
Constructor.

Parameters:
name - The name for this resource.
title - The title of this resource, as a string.

ResourceEntity

public ResourceEntity(java.lang.String title)
Constructor. The title parameter is escaped via ResourceName.escape(String) to determine the resource's name.

Parameters:
title - The title of this resource, as a string.
Method Detail

getType

public abstract ResourceType getType()
Query the type of this resource.

Returns:
The ResourceType that describes this resource.

as

public final <T extends ResourceEntity> T as(java.lang.Class<T> resourceType)
Type-safe helper method to convert an instance of ResourceEntity to a subclass.

Type Parameters:
T - The type that this resource should be converted to.
Parameters:
resourceType - The class representing the type that this resource should be converted to.
Returns:
This resource as a Page.

computeTemplate

public final TemplateEntity computeTemplate(TemplateEntity def)
Determine the template for this resource. Iterates up the parent hierarchy if necessary.

Parameters:
def - The default template to use if we cannot compute one.
Returns:
The template or null if none is found.

getAbsolutePath

public final ResourcePath getAbsolutePath()
Determine the absolute path for a resource.

Returns:
The absolute path as a ResourcePath.

getName

public ResourceName getName()


setName

public void setName(ResourceName resourceName)
Mutator for the name field.

Parameters:
resourceName - The new resource name.

getTitle

public java.lang.String getTitle()


setTitle

public void setTitle(java.lang.String titleString)
Sets the title of the resource.

Parameters:
titleString - The new title for this resource.

getTemplate

public TemplateEntity getTemplate()
Accessor for the template.

Returns:
The TemplateEntity.

setTemplate

public void setTemplate(TemplateEntity template)
Sets the template for this resource.

Parameters:
template - The new template.

getParent

public FolderEntity getParent()
Accessor for the resource's parent.

Returns:
The folder containing this resource.

isLocked

public boolean isLocked()
Query method to determine whether a resource is locked.

Returns:
True if the resource is locked, false otherwise.

lock

public void lock(UserEntity u)
Lock a resource.

Specified by:
lock in interface Lockable
Parameters:
u - The user who is locking the resource.

getLockedBy

public UserEntity getLockedBy()
Query method - determine who has locked this resource.

Returns:
The locking user or null if the resource is not locked.

unlock

public void unlock(UserEntity user)
Unlock the resource. Only the user who locked the resource, or an administrator may call this method.

Specified by:
unlock in interface Lockable
Parameters:
user - The user releasing the lock.

canUnlock

public boolean canUnlock(UserEntity user)
Determine whether a user can unlock this resource.

Parameters:
user - The user trying to unlock the resource.
Returns:
True if the user can unlock the resource, false otherwise.

setTags

public void setTags(java.util.Set<java.lang.String> tags)
Set the tags for this resource.

Parameters:
tags - A set of string tags.

getTags

public java.util.Set<java.lang.String> getTags()


publish

public void publish(UserEntity user)
Publish the resource.

Parameters:
user - The user.

isPublished

public boolean isPublished()
Query method to determine whether a resource is published.

Returns:
True if the resource is published, false otherwise.

getPublishedBy

public UserEntity getPublishedBy()
Return user who published the resource.

Returns:
The user or null if the resource is unpublished.

unpublish

public void unpublish()
Unpublish the resource.


isVisible

public boolean isVisible()
Query method to determine whether a resource is visible. A resource is visible if itself and all of its parents are published.

Returns:
True if this resource and all parents are published.

isSecure

public boolean isSecure()
Query method to determine whether a resource is secure. A resource is secure if itself or any of its parents has access control entries.

Returns:
True if this resource is secure.

confirmLock

public void confirmLock(UserEntity user)
Confirm this resource is locked by the specified user. If this resource is locked by the specified user this method does nothing; otherwise an exception is thrown.

Specified by:
confirmLock in interface Lockable
Parameters:
user - The user who should have the lock.

isIncludedInMainMenu

public boolean isIncludedInMainMenu()


setIncludedInMainMenu

public void setIncludedInMainMenu(boolean shouldInclude)
Mutator for 'include in main menu' property.

Parameters:
shouldInclude - Should the resource be included?

getRoot

public ResourceEntity getRoot()
Accessor for the root parent of this resource.

Returns:
The root parent of this resource.

addMetadatum

public void addMetadatum(java.lang.String key,
                         java.lang.String value)
Add new metadata for this resource.

Parameters:
key - The key by which the datum will be accessed.
value - The value of the datum. May not be NULL.

getMetadatum

public java.lang.String getMetadatum(java.lang.String key)
Calculate the resource's metadatum for a given key.

If this resource has no value for the key its parents will be checked recursively.

Parameters:
key - The key to the metadatum.
Returns:
The metadatum's value.

clearMetadatum

public void clearMetadatum(java.lang.String key)
Remove the metadatum with the specified key.

Parameters:
key - The key with which the datum was stored.

getMetadata

public java.util.Map<java.lang.String,java.lang.String> getMetadata()
Accessor for all metadata of the resource. Does not return any parent metadata.

Returns:
The metadata as a hash map.

computeMetadata

public java.util.Map<java.lang.String,java.lang.String> computeMetadata()
Compute the complete set of metadata for this resource. This method recursively queries all parents to determine the complete set of metadata.

Returns:
The metadata as a map.

clearMetadata

public void clearMetadata()
Remove all metadata for this resource.


getDateCreated

public java.util.Date getDateCreated()


getCreatedBy

public UserEntity getCreatedBy()
Query method - determine who created this resource.

Returns:
The creating user.

setDateCreated

public void setDateCreated(java.util.Date createdOn,
                           UserEntity createdBy)
Mutator for the date the resource was created.

Parameters:
createdOn - The date of creation.
createdBy - The user who created.

getDateChanged

public java.util.Date getDateChanged()


getChangedBy

public UserEntity getChangedBy()
Query method - determine who last changed this resource.

Returns:
The last user to change this resource.

setDateChanged

public void setDateChanged(java.util.Date changedOn,
                           UserEntity changedBy)
Mutator for the date the resource last changed.

Parameters:
changedOn - The date the resource changed.
changedBy - The user who changed the resource.

addGroupPermission

public void addGroupPermission(AccessPermission p)
Mutator.

Parameters:
p - The permission to add.

getGroupAcl

public java.util.Collection<ACL.Entry> getGroupAcl()
Accessor.

Returns:
This resource's groups.

addUserPermission

public void addUserPermission(AccessPermission p)
Mutator.

Parameters:
p - The permission to add.

getUserAcl

public java.util.Collection<ACL.Entry> getUserAcl()
Accessor.

Returns:
The users allowed to access this resource.

isReadableBy

public boolean isReadableBy(UserEntity user)


isWriteableBy

public boolean isWriteableBy(UserEntity user)


setCacheDuration

public void setCacheDuration(Duration cache)
Mutator.

Parameters:
cache - The cache duration for the resource.

getCacheDuration

public Duration getCacheDuration()
Accessor.

Returns:
This resource's cache duration.

computeCache

public Duration computeCache()
Compute the cache duration for the resource.

Returns:
This resource's computed cache duration or null if cache is not set in hierarchy.

getDescription

public final java.lang.String getDescription()


setDescription

public void setDescription(java.lang.String description)
Mutator for the file description.

Parameters:
description - The new description as a string.

addMetadata

public void addMetadata(java.util.Map<java.lang.String,java.lang.String> metadata)
Add metadata to this resource.

Parameters:
metadata - The metadata to add, as a hashmap.

isDeleted

public boolean isDeleted()
Query method.

Returns:
True if this resource is deleted; false otherwise.

delete

public void delete()
Mark this file as deleted.


undelete

public void undelete()
Mark this file as un-deleted.


toJson

public void toJson(Json json)
Convert to JSON.

Specified by:
toJson in interface Jsonable
Overrides:
toJson in class Entity
Parameters:
json - The JSON object to write to.

getAcl

public ACL getAcl()
Accessor.

Returns:
An ACL for this resource.

setDtoProps

protected void setDtoProps(Resource dto)
Populate the specified DTO with data from this resource.

Parameters:
dto - The DTO to populate.

mapResources

public static java.util.List<ResourceSummary> mapResources(java.util.Collection<? extends ResourceEntity> resources)
Map a collection of Resource to a collection of ResourceSummary.

Parameters:
resources - The collection of resources to map.
Returns:
The corresponding collection of ResourceSummary.

mapResource

public ResourceSummary mapResource()
Create a summary for a resource.

Returns:
The corresponding summary.

isIndexable

public boolean isIndexable()
Determine whether a resource can be indexed by the search engine.

Returns:
True if the resource can be indexed; false otherwise.

setIndexPosition

public void setIndexPosition(int index)
Set the index value for this resource.

Parameters:
index - The index value.

getIndex

public java.lang.Integer getIndex()
Accessor.

Returns:
The resource's index in its parent folder.

clearGroupAcl

public void clearGroupAcl()
Remove all group permissions.


clearUserAcl

public void clearUserAcl()
Remove all user permissions.



Copyright © 2010. All Rights Reserved.