Analysis
(Give as much as possible of the needed information for designing and implementing the task in the following sections.)
Overview
Define a stable resource design. Explain and document what is achieved.
Resource is an object that can exist by itself and can be persisted. Some of the resources can be used as frame content or a timeline. Resources can be nested in other resources (i.g. book can have nested another book (embedded book)).
Base resource model should have the following information
- UUID
- Content
- Data
- URL
- MetaInfo (comments, versions, names, etc...)
Types of resources
- Text
- Plain
- RTF
- HTML
- Image
- Audio
- Movie
- Book
- Templates
- User
- Group
- Book
- Page
- Frame
- Workspace
- Server Root
MetaInfo of the resource is:
- The name of the resource
- The author of the resource
- The date the resource was created
- Version of the resource
- The date the resource was last modified
- Who was the last that modified the resource
- The dimensions of the image (if the target of the resource is an image)
- etc.
Operations over a resource:
- The resource can be created.
- The resource can be modified.
- The resource can be deleted.
- The resource can be persisted.
- The resource can be uploaded (downloaded) to a server, which is the same thing as persisting but on the server.
- The resource can be previewed (in a separate window).
Task requirements
- Define which properties should be immutable, default, list, etc.
- Define a way to refer (access) resources
- The resource reference should be like UID
- The resource reference should allow finding the resource even if it is not loaded yet (location)
- The reference mechanism should handle the case when the resource is not available (for example - server not available)
- Define methods for
- Checking if a resource is available (this should be different from get method)
- This should update the status property
- Getting resource location
- Resource getting its parent
- Resource getting list of its children
- Attaching a resource to another resource
- Detaching a resource from another resource
- Renaming a resource (Ensure that the locations will be preserved and the new name doesn't collide with the names of the resources-siblings)
- Cloning/Copying a resource
- Checking if a resource is available (this should be different from get method)
- Explain annotations
* annotations related to Resources * explain ownership related with Resources and use of @Own * make a parallel with referencing Resources * An annotation that marks a property in a resource as metadata
- Document the defined structure
- Apply the defined structure for the existing resources
Task result
The result of this task is source code and wiki pages.
Implementation idea
The reference id can be combination of unique id and path like in operating system. Referring children and other resources will be easy (./ ../ etc)
Related
How to demo
Show source code, working current resource viewer (maybe a palette), unit tests.
Design
A resource is represented by the Resource class and the ResourceSpace class. The Resource class is more like a representation of the content of the resource and the ResourceSpace is what manages its Resource and its sub-objects which state is trackable.
- Resource :
- Can retrieve its parent if it has such.
- The Resource's entity id is its unique identifier, it can not be changed and it is generated and set by the ResourceSpace upon creation. It is used for searching in the ResourceLocalCache or on a outer location.
- The resource location is absolute location of the resource, it can be:
- Location on the file system
- Location on a server
- Temporary location in the Sophie 2 application if the Resource is not saved anywhere.
- Every resource type must implement the getResourceKind method that can identify the resource type.
- If there are important actions that must be executed when the resource is created and cached they must be put in the initialized method.
- All the meta information providing fields in a resource must be annotated with the @ResourceMeta annotation.
- Two Resources are equal if their entity id and location are equal.
- The entity id and the location of a Resource are held in the ResourceSpace of the Resource.
- All the ProObjects, which state is important for the state and the reconstruction of a Resource must be annotated with the annotation @Own
- A Resource can only be created with a ResourceSpace!
- All the Resources referred from a Resource are represented by ResourceRefs.
- All the sub-resources that are owned by a Resource (The Resource is their parent) are contained in the children list. It is possible to have outer resources refered from it but they are not in that children list.
- The resource name is unique for the level in the Resource's hierarchy it is. The siblings of the Resource in the Resource tree have to have different names. The name is set from the ResourceSpace at the resource's creation.
- ResourceSpace :
- It is responsible for the creation of a resource. Resource can be created in three ways:
- By its class => In that case the Resource's name is generated by its id and the Resource location is set in the temporary sophie 2 resource location with path the newly generated name.
- By its class and name => In that case the Resource is created in the temporary sophie 2 resource location with the passed name.
- By its class, passed name and Resource parent => in that case the resource is nested in the parent. Its location is in the parent's location with path the passed name and the name is validated to be unique against its siblings in the parent.
- The ResourceSpace keeps the location and the entity id of its Resource.
- The ResourceSpace gives unique ids for all the ProObjects in it (They are fields in its Resource or are fields in such ProObjects).
- The ResourceSpace can get all the Resources in the tree of its Resource
- The ResourceSpace is able to clone Resource -> in this case the Resource tree is copied and all the resources have new entity ids and their inner ResourceRefs are redirected in the tree. The outer ResourceRef are kept.
- The ResourceSpace is able to copy a Resource into another Resource, and that is the way to add a Resource to another location.
- Deleting resources will be designed and implemented in the next revision.
- It is responsible for the creation of a resource. Resource can be created in three ways:
The Resource and the ResourceSpace are unseparateble, they represent the sophie 2 resources and will be able to execute all the operations on a resource and to maintain it.
Locating a Resource is hard task, a Resource can be cached in a cache in the application or can be contained/persisted on a given URL (server/file system). The ResourceRef is smart immutable object that has all the information needed to find a Resource.
- ResourceRef
- It can be constructed in four ways :
- By an absolute path, that can be used for searching a Resource on a distant location.
- By entity id and location, can be used for searching an unknown resource on a distant location or to copy a Reference.
- By a Resource and Resource source of the Resource, so it can be used for smart finding of a Resource by other in a Resource tree.
- By generating child Reference from a parent Resource (something like ./name as location)
- Two ResourceRefs are equal if the entity id's and the locations they are pointing to are the equal.
- The ResourceRef is can determine whether the Resource it's pointing to is available.
- The ResourceRef can retrieve its Resource in two ways :
- By its class, if the Resource is top level.
- By its locating Resource (i.e. where the ResourceRef is held) and the class of the Resource that is searched.
- The ResourceRef can determine if it points to a Resource.
- It can be constructed in four ways :
- ResourceLocalCache :
- It keeps the Resources that are loaded in the application and provides functionality for finding them by their entity ids and locations, absolute or relative.
- It can search for Resources only in the cache but it will be able to search for Resources and on the File System and the Server in the next Revisions.
- It provides functionality for locating a parent of a Resource and even the nearest parent in the tree by given type.
- Is used to locate the Resources by the ResourceRefs, first by their entity ids, second by their absolute or relative paths, the paths are constructed like /parent1_name/parent2_name/resource_name, so the parents and the siblings can be retrieved easily. If a Resource is not found in the cache it can be found where it is stored and that cached.
All this four structures build the Resource trees and will be used to store resource content and to retrieve it. The attaching a resource to another is simply creating it or coping it to the parent resource. Renaming is not permitted so the parents and the siblings can be determined by their locations. Deleting(Detaching) and moving a resource can be done in the next revision with copying the resource in the new place, and destroying it. In such way we can have all the operation on a resource and can locate it anywhere.
Implementation
Changesets:
[1955], [2092], [2093], [2094], [2095], [2098], [2112], [2118], [2124].
Testing
(Place the testing results here.)
Comments
(Write comments for this or later revisions here.)