Package org.ametys.plugins.repository
Class AmetysObjectResolver
java.lang.Object
org.ametys.runtime.plugin.component.AbstractLogEnabled
org.ametys.plugins.repository.AmetysObjectResolver
- All Implemented Interfaces:
LogEnabled
,Initializable
,Component
,Serviceable
public class AmetysObjectResolver
extends AbstractLogEnabled
implements Serviceable, Initializable, Component
Base component for accessing
AmetysObject
s.-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription<A extends AmetysObject>
AcreateAndResolve
(String parentPath, javax.jcr.Node parentNode, String childName, String nodetype) Expert.boolean
Return true if the specified id correspond to an existingAmetysObject
.void
static boolean
initRepoNodes
(javax.jcr.Session session, Logger logger) Init the repository nodes directly inside ROOTÂ node<A extends AmetysObject>
AmetysObjectIterable<A>Executes the given JCR XPath query and resolves results asAmetysObject
s.
The resultingAmetysObjectIterable
supports lazy loading, but will also fail lazily if one if the result nodes does not correspond to anAmetysObject
.<A extends AmetysObject>
AmetysObjectIterable<A>Expert.<A extends AmetysObject>
ADeprecated.Use resolveByPath instead<A extends AmetysObject>
AExpert.<A extends AmetysObject>
Aresolve
(javax.jcr.Node node, boolean allowUnknownNode) Expert.<A extends AmetysObject>
AresolveById
(String id) Retrieves anAmetysObject
by its unique id.<A extends AmetysObject>
AresolveById
(String id, javax.jcr.Session session) Expert.<A extends AmetysObject>
AresolveByPath
(String absolutePath) Retrieves anAmetysObject
from an absolute path.<A extends AmetysObject>
AresolveByPath
(String absolutePath, javax.jcr.Session session) Retrieves anAmetysObject
from an absolute path.resolveVirtualChild
(JCRAmetysObject parent, String childPath) Expert.<A extends AmetysObject>
AmetysObjectIterable<A>Expert.void
service
(ServiceManager manager) Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
Field Details
-
ROLE
Avalon ROLE. -
ROOT_REPO
JCR Relative Path to root.- See Also:
-
ROOT_TYPE
JCR type for root node.- See Also:
-
OBJECT_TYPE
JCR mixin type for objects.- See Also:
-
VIRTUAL_PROPERTY
JCR property name for virtual objects.- See Also:
-
-
Constructor Details
-
AmetysObjectResolver
public AmetysObjectResolver()
-
-
Method Details
-
service
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
initialize
- Specified by:
initialize
in interfaceInitializable
- Throws:
Exception
-
initRepoNodes
public static boolean initRepoNodes(javax.jcr.Session session, Logger logger) throws javax.jcr.RepositoryException Init the repository nodes directly inside ROOTÂ node- Parameters:
session
- the session to uselogger
- the logger to log actions- Returns:
- true if the sesion needs changes
- Throws:
javax.jcr.RepositoryException
- something went wrong
-
resolve
@Deprecated public <A extends AmetysObject> A resolve(String absolutePath) throws AmetysRepositoryException, UnknownAmetysObjectException Deprecated.Use resolveByPath insteadRetrieves anAmetysObject
from an absolute path. The given path is absolute in the Ametys tree.
The path may omit the leading'/'
, but the path is always considered absolute,null
path is forbidden.- Type Parameters:
A
- the actual type ofAmetysObject
.- Parameters:
absolutePath
- the path to use.- Returns:
- the corresponding AmetysObject.
- Throws:
AmetysRepositoryException
- if an error occurs.UnknownAmetysObjectException
- if no such object exists for the given path.
-
resolveByPath
public <A extends AmetysObject> A resolveByPath(String absolutePath) throws AmetysRepositoryException, UnknownAmetysObjectException Retrieves anAmetysObject
from an absolute path. The given path is absolute in the Ametys tree.
The path may omit the leading'/'
, but the path is always considered absolute,null
path is forbidden.- Type Parameters:
A
- the actual type ofAmetysObject
.- Parameters:
absolutePath
- the path to use.- Returns:
- the corresponding AmetysObject.
- Throws:
AmetysRepositoryException
- if an error occurs.UnknownAmetysObjectException
- if no such object exists for the given path.
-
resolveByPath
public <A extends AmetysObject> A resolveByPath(String absolutePath, javax.jcr.Session session) throws AmetysRepositoryException, UnknownAmetysObjectException Retrieves anAmetysObject
from an absolute path. The given path is absolute in the Ametys tree.
The path may omit the leading'/'
, but the path is always considered absolute,null
path is forbidden.- Type Parameters:
A
- the actual type ofAmetysObject
.- Parameters:
absolutePath
- the path to use.session
- the JCR Session to use to retrieve theAmetysObject
.- Returns:
- the corresponding AmetysObject.
- Throws:
AmetysRepositoryException
- if an error occurs.UnknownAmetysObjectException
- if no such object exists for the given path.
-
resolveById
public <A extends AmetysObject> A resolveById(String id) throws AmetysRepositoryException, UnknownAmetysObjectException Retrieves anAmetysObject
by its unique id.- Type Parameters:
A
- the actual type ofAmetysObject
.- Parameters:
id
- the identifier representing the wantedAmetysObject
is the Ametys repository.- Returns:
- the corresponding
AmetysObject
. - Throws:
AmetysRepositoryException
- if an error occurs.UnknownAmetysObjectException
- if no such object exists for the given id.
-
resolveById
public <A extends AmetysObject> A resolveById(String id, javax.jcr.Session session) throws AmetysRepositoryException, UnknownAmetysObjectException, javax.jcr.RepositoryException Expert. Retrieves anAmetysObject
by its unique id and the provided JCR Session.
It only works with id corresponding to aJCRAmetysObjectFactory
.
This method should be uses to avoid useless Session creation.- Type Parameters:
A
- the actual type ofAmetysObject
.- Parameters:
id
- the identifier representing the wantedAmetysObject
is the Ametys repository.session
- the JCR Session to use to retrieve theAmetysObject
.- Returns:
- the corresponding
AmetysObject
. - Throws:
AmetysRepositoryException
- if an error occurs.UnknownAmetysObjectException
- if no such object exists for the given id.javax.jcr.RepositoryException
- if a JCR error occurs.
-
hasAmetysObjectForId
Return true if the specified id correspond to an existingAmetysObject
.- Parameters:
id
- the identifier.- Returns:
- true if the specified id correspond to an existing
AmetysObject
. - Throws:
AmetysRepositoryException
- if an error occurs.
-
resolve
public <A extends AmetysObject> A resolve(javax.jcr.Node node, boolean allowUnknownNode) throws AmetysRepositoryException, javax.jcr.RepositoryException Expert. Returns theAmetysObject
corresponding to a given JCR Node.
It is strictly equivalent to callresolve(null, node, null, allowUnknownNode)
- Type Parameters:
A
- the actual type ofAmetysObject
s- Parameters:
node
- an existing node in the underlying JCR repository.allowUnknownNode
- iftrue
, returnsnull
if the node type does not correspond to a factory. Iffalse
and no factory corresponds, anAmetysRepositoryException
is thrown.- Returns:
- the
AmetysObject
corresponding to a given JCR node. - Throws:
AmetysRepositoryException
- if an error occurs.javax.jcr.RepositoryException
- if a JCR error occurs.
-
resolve
public <A extends AmetysObject> A resolve(String parentPath, javax.jcr.Node node, String childPath, boolean allowUnknownNode) throws AmetysRepositoryException, UnknownAmetysObjectException, javax.jcr.RepositoryException Expert. Retrieves anAmetysObject
, given a JCR Node, a relative path and the parentPath in the Ametys hierarchy.
The path is always relative, even if it begins with a'/'
,null
path or empty path are equivalent.
May return null if ignoreUnknownNodes is true.- Type Parameters:
A
- the actual type ofAmetysObject
.- Parameters:
parentPath
- the parentPath of the returned AmetysObject, in the Ametys hierarchy.node
- the context JCR node.childPath
- the path relative to the JCR node.allowUnknownNode
- iftrue
, returnsnull
if the node type does not correspond to a factory. Iffalse
and no factory corresponds, anAmetysRepositoryException
is thrown.- Returns:
- the corresponding AmetysObject.
- Throws:
AmetysRepositoryException
- if an error occurs.UnknownAmetysObjectException
- if no such object exists for the given path.javax.jcr.RepositoryException
- if a JCR error occurs.
-
resolveVirtualChildren
public <A extends AmetysObject> AmetysObjectIterable<A> resolveVirtualChildren(JCRAmetysObject parent) throws AmetysRepositoryException, javax.jcr.RepositoryException Expert. Retrieves the virtual children of a concrete JCR Node.- Type Parameters:
A
- the actual type ofAmetysObject
s.- Parameters:
parent
- theJCRAmetysObject
"hosting" theVirtualAmetysObjectFactory
reference.- Returns:
- all virtual children under the given JCR Node in the Ametys hierarchy.
- Throws:
AmetysRepositoryException
- if an error occurs.javax.jcr.RepositoryException
- if a JCR error occurs.
-
resolveVirtualChild
public AmetysObject resolveVirtualChild(JCRAmetysObject parent, String childPath) throws AmetysRepositoryException, javax.jcr.RepositoryException, UnknownAmetysObjectException Expert. Retrieves the virtual child of a concrete JCR Node.- Parameters:
parent
- theJCRAmetysObject
"hosting" theVirtualAmetysObjectFactory
reference.childPath
- the name of the virtual child.- Returns:
- a named child under the given JCR Node in the Ametys hierarchy.
- Throws:
AmetysRepositoryException
- if an error occurs.javax.jcr.RepositoryException
- if a JCR error occurs.UnknownAmetysObjectException
- if the named child does not exist
-
query
Executes the given JCR XPath query and resolves results asAmetysObject
s.
The resultingAmetysObjectIterable
supports lazy loading, but will also fail lazily if one if the result nodes does not correspond to anAmetysObject
.- Type Parameters:
A
- the actual type of the results.- Parameters:
jcrQuery
- a JCR XPath query.- Returns:
- an Iterator over the resulting
AmetysObject
.
-
query
public <A extends AmetysObject> AmetysObjectIterable<A> query(String jcrQuery, javax.jcr.Session session) throws javax.jcr.RepositoryException Expert. Executes the given JCR XPath query with the provided JCR Session and resolves results asAmetysObject
s.
The resultingAmetysObjectIterable
supports lazy loading, but will also fail lazily if one if the result nodes does not correspond to anAmetysObject
.- Type Parameters:
A
- the actual type of the results.- Parameters:
jcrQuery
- a JCR XPath query.session
- the JCR Session to use to execute the request.- Returns:
- an Iterator over the resulting
AmetysObject
. - Throws:
javax.jcr.RepositoryException
- if a JCR error occurs.
-
createAndResolve
public <A extends AmetysObject> A createAndResolve(String parentPath, javax.jcr.Node parentNode, String childName, String nodetype) throws AmetysRepositoryException, RepositoryIntegrityViolationException, javax.jcr.RepositoryException Expert. Creates a child object in the JCR tree and resolve it to anAmetysObject
.- Type Parameters:
A
- the actual type ofAmetysObject
s- Parameters:
parentPath
- the parentPath of the new object.parentNode
- the parent JCR Node of the new object.childName
- the name of the new object.nodetype
- the type of the Node backing the new object.- Returns:
- the newly created
AmetysObject
. - Throws:
AmetysRepositoryException
- if an error occurs.RepositoryIntegrityViolationException
- if an object with the same name already exists and same name siblings is not allowed.javax.jcr.RepositoryException
- if a JCR error occurs.
-