Previous method getVersionLabels() was mistake, because there is no
'latest' version in JCR. Because version are stored as direct acyclic
graph there is no information which version is the 'newest'. I think
application logic must decide with version labels, so if my application
support two dimensional versioning (1.0, 1.1, 2.0, 3.0 ..), method:
public String[] getVersionLabels(final String absPath, final Object
cmsObject) {
try {
Node node = getNode(absPath);
VersionHistory vh = node.getVersionHistory();
String[] versionLabels = vh.getVersionLabels();
return versionLabels;
} catch (UnsupportedRepositoryOperationException e) {
// node.getVersionHistory() throws
UnsupportedRepositoryOperationException if this node is not versionable.
throw new
org.apache.portals.graffito.jcr.exception.RepositoryException("Node is
not versionable: " + absPath);
} catch (RepositoryException e) {
throw new
org.apache.portals.graffito.jcr.exception.RepositoryException(e.getMessage(),
e);
}
}
is more appropriate. It returns ALL version labels for persistent object
on some path and util method getLatestVersionLabel(versinLabels) returns
3.0 (from previous example). So then i know latest (newest) version.
Martin Koci wrote:
Hi,
suggested API:
void checkin(String absPath, Object versionableEntity, String[]
newVersionNumbers) throws LockedException;
void checkout(String absPath, Object versionableEntity) throws
LockedException;
String[] getVersionLabels(String absPath, Object cmsObject);
void addVersionLabel(String absPath, Object entity, String versionLabel);
and (maybe) working implementation:
public void checkin(final String absPath, final Object
versionableEntity, final String[] newVersionNumbers) throws
LockedException {
try {
Node node = getNode(absPath);
checkIfNodeLocked(absPath);
Version newVersion = node.checkin();
VersionHistory versionHistory = node.getVersionHistory();
if (newVersionNumbers != null) {
for (int i = 0; i < newVersionNumbers.length; i++) {
String versionLabel = newVersionNumbers[i];
versionHistory.addVersionLabel(newVersion.getName(), versionLabel,
false);
}
}
} catch (UnsupportedRepositoryOperationException e) {
// This catch UnsupportedRepositoryOperationException potentionally
throwed with Node.checkout()
// indicates that node is not versionable - it means coding bug in
jcrmapping.xml/custom_nodes_types.xml
throw new
org.apache.portals.graffito.jcr.exception.RepositoryException("Node is
not mix:versionable. Path: " + absPath, e);
} catch (RepositoryException e) {
// This typically 'If another error occurs'.
throw new
org.apache.portals.graffito.jcr.exception.RepositoryException("Unknown
error on checkin: ", e);
}
}
public void checkout(final String absPath, final Object
versionableEntity) throws LockedException {
Node node;
try {
checkIfNodeLocked(absPath);
node = getNode(absPath);
node.checkout();
} catch (UnsupportedRepositoryOperationException e) {
// This catch UnsupportedRepositoryOperationException potentionally
throwed with Node.checkout()
// indicates that node is not versionable - it means coding bug in
jcrmapping.xml
throw new
org.apache.portals.graffito.jcr.exception.RepositoryException("Node is
not mix:versionable. Path: " + absPath, e);
} catch (RepositoryException e) {
// This eventually catch LockException e, but
// this colud never happen - see upper code
throw new
org.apache.portals.graffito.jcr.exception.RepositoryException("Unknown
error on checkout: ", e);
}
}
public String[] getVersionLabels(final String absPath, final Object
cmsObject) {
try {
Node node = getNode(absPath);
VersionHistory vh = node.getVersionHistory();
VersionIterator versionIterator = vh.getAllVersions();
versionIterator.skip(1);
vh.getBaseVersion();
Version version = versionIterator.nextVersion();
String[] versionLabels = vh.getVersionLabels(version);
return versionLabels;
} catch (UnsupportedRepositoryOperationException e) {
// node.getVersionHistory() throws
UnsupportedRepositoryOperationException if this node is not versionable.
throw new
org.apache.portals.graffito.jcr.exception.RepositoryException("Node is
not versionable: " + absPath);
} catch (RepositoryException e) {
throw new
org.apache.portals.graffito.jcr.exception.RepositoryException(e.getMessage(),
e);
}
}
public void addVersionLabel(final String absPath, final Object entity,
final String versionLabel) {
try {
final Node node = getNode(absPath);
final VersionHistory versionHistory = node.getVersionHistory();
final boolean moveLabel = false;
versionHistory.addVersionLabel(node.getBaseVersion().getName(),
versionLabel, moveLabel);
} catch (UnsupportedRepositoryOperationException e) {
// node.getVersionHistory() throws
UnsupportedRepositoryOperationException if this node is not versionable.
throw new
org.apache.portals.graffito.jcr.exception.RepositoryException("Node is
not versionable: " + absPath);
} catch (RepositoryException e) {
throw new
org.apache.portals.graffito.jcr.exception.RepositoryException("Unknown
error on addVersionLabel: ", e);
}
}
Christophe Lombart wrote:
Hi all,
I'm still working on the JCR integration and I'm wondering what are our
needs in point of view content versionning ?
I would like to start with simple use cases but I want to know if
someone
has specific requirements.
Furthermore, how do you see the versionning API in the JCR-mapping
subproject ?
Do we create a new component (like the QueryManager) or add new
methods in
the PersistenceManager ?
All ideas, comments, thoughts are welcome.
kind regards,
Christophe
--
Mgr. Martin Kočí
---------------------------------
AURA, s.r.o.
Úvoz 499/56; 602 00 Brno
ISO 9001 certifikovaná společnost
tel./fax: +420 5 43 24 51 11
e-mail: [EMAIL PROTECTED]
internet: http://www.aura.cz
http://www.j2ee.cz
---------------------------------