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 accessingAmetysObject
s.
-
-
Field Summary
Fields Modifier and Type Field Description static String
OBJECT_TYPE
JCR mixin type for objects.static String
ROLE
Avalon ROLE.static String
ROOT_REPO
JCR Relative Path to root.static String
ROOT_TYPE
JCR type for root node.static String
VIRTUAL_PROPERTY
JCR property name for virtual objects.
-
Constructor Summary
Constructors Constructor Description AmetysObjectResolver()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description <A extends AmetysObject>
AcreateAndResolve(String parentPath, Node parentNode, String childName, String nodetype)
Expert.boolean
hasAmetysObjectForId(String id)
Return true if the specified id correspond to an existingAmetysObject
.void
initialize()
static boolean
initRepoNodes(Session session, org.slf4j.Logger logger)
Init the repository nodes directly inside ROOTÂ node<A extends AmetysObject>
AmetysObjectIterable<A>query(String jcrQuery)
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>query(String jcrQuery, Session session)
Expert.<A extends AmetysObject>
Aresolve(String absolutePath)
Deprecated.Use resolveByPath instead<A extends AmetysObject>
Aresolve(String parentPath, Node node, String childPath, boolean allowUnknownNode)
Expert.<A extends AmetysObject>
Aresolve(Node node, boolean allowUnknownNode)
Expert.<A extends AmetysObject>
AresolveById(String id)
Retrieves anAmetysObject
by its unique id.<A extends AmetysObject>
AresolveById(String id, Session session)
Expert.<A extends AmetysObject>
AresolveByPath(String absolutePath)
Retrieves anAmetysObject
from an absolute path.AmetysObject
resolveVirtualChild(JCRAmetysObject parent, String childPath)
Expert.<A extends AmetysObject>
AmetysObjectIterable<A>resolveVirtualChildren(JCRAmetysObject parent)
Expert.void
service(ServiceManager manager)
-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Field Detail
-
ROOT_REPO
public static final String ROOT_REPO
JCR Relative Path to root.- See Also:
- Constant Field Values
-
ROOT_TYPE
public static final String ROOT_TYPE
JCR type for root node.- See Also:
- Constant Field Values
-
OBJECT_TYPE
public static final String OBJECT_TYPE
JCR mixin type for objects.- See Also:
- Constant Field Values
-
VIRTUAL_PROPERTY
public static final String VIRTUAL_PROPERTY
JCR property name for virtual objects.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AmetysObjectResolver
public AmetysObjectResolver()
-
-
Method Detail
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
initialize
public void initialize() throws Exception
- Specified by:
initialize
in interfaceInitializable
- Throws:
Exception
-
initRepoNodes
public static boolean initRepoNodes(Session session, org.slf4j.Logger logger) throws 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:
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.
-
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, Session session) throws AmetysRepositoryException, UnknownAmetysObjectException, 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.RepositoryException
- if a JCR error occurs.
-
hasAmetysObjectForId
public boolean hasAmetysObjectForId(String id) throws AmetysRepositoryException
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(Node node, boolean allowUnknownNode) throws AmetysRepositoryException, 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.RepositoryException
- if a JCR error occurs.
-
resolve
public <A extends AmetysObject> A resolve(String parentPath, Node node, String childPath, boolean allowUnknownNode) throws AmetysRepositoryException, UnknownAmetysObjectException, 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.RepositoryException
- if a JCR error occurs.
-
resolveVirtualChildren
public <A extends AmetysObject> AmetysObjectIterable<A> resolveVirtualChildren(JCRAmetysObject parent) throws AmetysRepositoryException, 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.RepositoryException
- if a JCR error occurs.
-
resolveVirtualChild
public AmetysObject resolveVirtualChild(JCRAmetysObject parent, String childPath) throws AmetysRepositoryException, 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.RepositoryException
- if a JCR error occurs.UnknownAmetysObjectException
- if the named child does not exist
-
query
public <A extends AmetysObject> AmetysObjectIterable<A> query(String jcrQuery)
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, Session session) throws 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:
RepositoryException
- if a JCR error occurs.
-
createAndResolve
public <A extends AmetysObject> A createAndResolve(String parentPath, Node parentNode, String childName, String nodetype) throws AmetysRepositoryException, RepositoryIntegrityViolationException, 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.RepositoryException
- if a JCR error occurs.
-
-