Merging BRANCHES/DEV/CMIS_10 to HEAD (phase 2 - currently up-to-date with branch):

18717: SAIL-166: Refactor CMIS to use shared services and resolve objectIds and error codes consistently
   18731: SAIL-169: CMIS REST versioning compliance
   18732: Fix failing change log test.
   18768: Add displayName and queryName attributes to rendered properties (in CMIS AtomPub binding).
   18775: Fix exception reporting when retrieving items that do not exist (in CMIS AtomPub binding).
   18784: Fix CMIS REST change logging
   18785: SAIL-174: CMIS Relationship lookup by association ID
   18812: SAIL-183: Support orderBy argument for getChildren and getCheckedOutDocs in CMIS REST and Web Service bindings
   18823: CMIS WS Bindings were moved to 1.0 cd07 schema.
   18838: Update to latest Chemistry TCK.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@18847 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
David Caruana
2010-02-25 15:02:44 +00:00
parent fc172da640
commit bd2f2441fd
65 changed files with 2477 additions and 2782 deletions

View File

@@ -1,73 +0,0 @@
/*
* Copyright (C) 2005-2008 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.cmis.ws.utils;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.cmis.mapping.CMISMapping;
import org.alfresco.model.ContentModel;
/**
* @author Dmitry Velichkevich
*/
public enum AlfrescoObjectType
{
DOCUMENT_OBJECT(ContentModel.TYPE_CONTENT.toString()),
FOLDER_OBJECT(ContentModel.TYPE_FOLDER.toString()),
DOCUMENT_OR_FOLDER_OBJECT("DOCUMENT_OR_FOLDER"),
RELATIONSHIP_OBJECT(CMISMapping.RELATIONSHIP_QNAME.toString()),
ANY_OBJECT("ANY");
String value;
final static Map<String, AlfrescoObjectType> VALUES;
static
{
VALUES = new HashMap<String, AlfrescoObjectType>();
VALUES.put(DOCUMENT_OBJECT.getValue(), DOCUMENT_OBJECT);
VALUES.put(FOLDER_OBJECT.getValue(), FOLDER_OBJECT);
}
AlfrescoObjectType(String value)
{
this.value = value;
}
public String getValue()
{
return this.value;
}
public static AlfrescoObjectType fromValue(String valueName)
{
AlfrescoObjectType result = VALUES.get(valueName);
if (result == null)
{
result = ANY_OBJECT;
}
return result;
}
}

View File

@@ -1,364 +0,0 @@
/*
* Copyright (C) 2005-2009 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.cmis.ws.utils;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.cmis.ws.EnumUnfileObject;
import org.alfresco.repo.model.filefolder.FileInfoImpl;
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.version.VersionService;
import org.alfresco.service.namespace.QName;
/**
* This class enumerates Documents and Folders hierarchy that begins from specified folder. Iterator returns Document or Empty Folder Objects those may be removed or deleted from
* repository according to {@link EnumUnfileObject} <b>unfileObject</b> and {@link Boolean} <b>continueOnFailure</b> parameters. After hierarchy enumerating completion iterator may
* introduce Object Id(s) {@link List} those were not deleted due to {@link Exception}(s)
*
* @author Dmitry Velichkevich
*/
public class CmisObjectIterator implements Iterator<FileInfo>
{
private EnumUnfileObject unfillingStrategy;
private boolean continueOnFailure;
private NodeService nodeService;
private FileFolderService fileFolderService;
private VersionService versionService;
private CheckOutCheckInService checkOutCheckInService;
private CmisObjectsUtils objectsUtils;
private Map<FileInfo, List<FileInfo>> hierarchy = new HashMap<FileInfo, List<FileInfo>>();
private LinkedList<FileInfo> objects = new LinkedList<FileInfo>();
private List<String> failToDelete = new LinkedList<String>();
private FileInfo next;
private boolean lastDeleted;
private boolean nextFound;
private boolean deleteAllVersions;
/**
* Mandatory constructor
*
* @param rootObject - {@link NodeRef} instance that represents Root folder for hierarchy
* @param unfillingStrategy - {@link EnumUnfileObject} value that determines File-able Objects deletion or removing strategy
* @param continueOnFailure - {@link Boolean} value that determines whether it is necessary continue deletion after some {@link Exception} occurred
* @param nodeService - A {@link NodeService} implementation instance for manipulating with Object Properties
* @param fileFolderService - A {@link FileFolderService} implementation instance for manipulating with Objects
* @param objectsUtils - {@link CmisObjectsUtils} service instance for simplifying manipulations with Objects and Object Properties
*/
public CmisObjectIterator(NodeRef rootObject, EnumUnfileObject unfillingStrategy, boolean continueOnFailure, boolean deleteAllVersions, NodeService nodeService,
FileFolderService fileFolderService, VersionService versionService, CheckOutCheckInService checkOutCheckInService, CmisObjectsUtils objectsUtils)
{
this.unfillingStrategy = unfillingStrategy;
this.deleteAllVersions = deleteAllVersions;
this.continueOnFailure = continueOnFailure;
this.nodeService = nodeService;
this.fileFolderService = fileFolderService;
this.versionService = versionService;
this.checkOutCheckInService = checkOutCheckInService;
this.objectsUtils = objectsUtils;
objects.add(new ParentedFileInfo(fileFolderService.getFileInfo(rootObject), null));
}
/**
* This method performs searching for next Object (see {@link CmisObjectIterator})
*/
public boolean hasNext()
{
if (nextFound)
{
return true;
}
if (objects.isEmpty() || (!failToDelete.isEmpty() && !continueOnFailure))
{
return false;
}
for (next = objects.removeFirst(); processFolder() && !objects.isEmpty(); next = objects.removeFirst())
{
}
nextFound = (null != next) && (!next.isFolder() || (null == receiveChildren(next.getNodeRef())));
return nextFound;
}
private boolean processFolder()
{
if (next.isFolder())
{
List<ChildAssociationRef> children = receiveChildren(next.getNodeRef());
if (null != children)
{
objects.addFirst(next);
for (ChildAssociationRef child : children)
{
FileInfo info = fileFolderService.getFileInfo(child.getChildRef());
ParentedFileInfo childInfo = new ParentedFileInfo(info, next);
objects.addFirst(childInfo);
addChildToParent(next, childInfo);
}
return true;
}
}
return false;
}
private void addChildToParent(FileInfo parent, FileInfo child)
{
if (null != parent)
{
List<FileInfo> children;
if (hierarchy.containsKey(parent))
{
children = hierarchy.get(parent);
}
else
{
children = new LinkedList<FileInfo>();
hierarchy.put(parent, children);
}
children.add(child);
}
}
private List<ChildAssociationRef> receiveChildren(NodeRef folderRef)
{
if (null != folderRef)
{
List<ChildAssociationRef> result = nodeService.getChildAssocs(folderRef);
if ((null != result) && !result.isEmpty())
{
return result;
}
}
return null;
}
/**
* This method returns currently enumerated Object and changes flag to enumerate next Object
*
* @see CmisObjectIterator
* @see CmisObjectIterator#hasNext()
* @see CmisObjectIterator#remove()
*/
public FileInfo next()
{
nextFound = false;
return next;
}
/**
* This method removes currently enumerated Object (see {@link CmisObjectIterator}). If Object deletion or removing fails due to {@link Exception} then according to
* <b>continueOnFailure</b> parameter current Object Id and (if <b>continueOnFailure</b>="<b>true</b>") current Object Parent(s)' Id(s) will be stored in <b>failedToDelete</b>
* {@link List}. Not deleted Object and its Parent(s) never will be enumerated again
*
* @see CmisObjectIterator
* @see CmisObjectIterator#hasNext()
* @see CmisObjectIterator#next()
*/
public void remove()
{
lastDeleted = false;
NodeRef parentRef = null;
ParentedFileInfo info = null;
if (null != next)
{
info = (ParentedFileInfo) next;
EnumUnfileObject howToDelete = null;
parentRef = (null != info.getExactParent()) ? (info.getExactParent().getNodeRef()) : (null);
if ((null != parentRef) && ((EnumUnfileObject.DELETESINGLEFILED == unfillingStrategy) || !objectsUtils.isPrimaryObjectParent(parentRef, info.getNodeRef())))
{
howToDelete = EnumUnfileObject.DELETESINGLEFILED;
}
else
{
howToDelete = EnumUnfileObject.DELETE;
}
if (EnumUnfileObject.DELETESINGLEFILED == howToDelete)
{
lastDeleted = objectsUtils.removeObject(info.getNodeRef(), parentRef);
}
else
{
if (deleteAllVersions)
{
NodeRef workingCopyRef = (objectsUtils.isWorkingCopy(info.getNodeRef())) ? (info.getNodeRef()) : (checkOutCheckInService.getWorkingCopy(info.getNodeRef()));
if (null == workingCopyRef)
{
versionService.deleteVersionHistory(info.getNodeRef());
}
}
lastDeleted = (objectsUtils.deleteObject(info.getNodeRef()));
}
}
if (!lastDeleted && (null != info))
{
failToDelete.add(generateId(info));
if ((null == info.getExactParent()) && info.isFolder())
{
removeFolderFromCollections(info);
}
if (continueOnFailure)
{
for (; null != info.getExactParent(); info = (ParentedFileInfo) info.getExactParent())
{
failToDelete.add(generateId(info.getExactParent()));
removeFolderFromCollections(info.getExactParent());
}
}
}
}
private void removeFolderFromCollections(FileInfo object)
{
if (hierarchy.containsKey(object))
{
hierarchy.remove(object);
objects.remove(object);
}
}
private String generateId(FileInfo object)
{
StringBuilder generator = new StringBuilder(object.getNodeRef().toString());
Map<QName, Serializable> properties = object.getProperties();
String versionLabel = (null != properties) ? ((String) properties.get(ContentModel.PROP_VERSION_LABEL)) : (null);
if (null != versionLabel)
{
generator.append(CmisObjectsUtils.NODE_REFERENCE_ID_DELIMITER).append(versionLabel);
}
return generator.toString();
}
public boolean wasLastRemoved()
{
return lastDeleted;
}
public List<String> getFailToDelete()
{
return failToDelete;
}
/**
* This class is {@link org.alfresco.jlan.server.filesys.FileInfo} implementation that uses {@link FileInfoImpl} instances to delegate core functionality. The main target of
* this class is extended standard {@link FileInfo} Objects with Parent Object
*
* @author Dmitry Velichkevich
*/
private class ParentedFileInfo implements FileInfo, Serializable
{
private static final long serialVersionUID = -3024276223816623074L;
private FileInfo delegator;
private FileInfo exactParent;
public ParentedFileInfo(FileInfo delegator, FileInfo exactParent)
{
this.delegator = delegator;
this.exactParent = exactParent;
}
public ContentData getContentData()
{
return delegator.getContentData();
}
public Date getCreatedDate()
{
return delegator.getCreatedDate();
}
public NodeRef getLinkNodeRef()
{
return delegator.getLinkNodeRef();
}
public Date getModifiedDate()
{
return delegator.getModifiedDate();
}
public String getName()
{
return delegator.getName();
}
public NodeRef getNodeRef()
{
return delegator.getNodeRef();
}
public Map<QName, Serializable> getProperties()
{
return delegator.getProperties();
}
public boolean isFolder()
{
return delegator.isFolder();
}
public boolean isLink()
{
return delegator.isLink();
}
public FileInfo getExactParent()
{
return exactParent;
}
@Override
public boolean equals(Object obj)
{
return delegator.equals(obj);
}
@Override
public int hashCode()
{
return delegator.hashCode();
}
@Override
public String toString()
{
return delegator.toString();
}
}
}

View File

@@ -1,566 +0,0 @@
/*
* Copyright (C) 2005-2008 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.cmis.ws.utils;
import java.math.BigInteger;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import org.alfresco.cmis.CMISDictionaryService;
import org.alfresco.cmis.CMISQueryException;
import org.alfresco.cmis.CMISScope;
import org.alfresco.cmis.CMISTypeDefinition;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.cmis.ws.CmisException;
import org.alfresco.repo.cmis.ws.CmisFaultType;
import org.alfresco.repo.cmis.ws.EnumBaseObjectTypeIds;
import org.alfresco.repo.cmis.ws.EnumRelationshipDirection;
import org.alfresco.repo.cmis.ws.EnumServiceException;
import org.alfresco.repo.cmis.ws.EnumUnfileObject;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
import org.alfresco.service.cmr.lock.LockService;
import org.alfresco.service.cmr.lock.LockStatus;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentIOException;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.security.AuthorityService;
import org.alfresco.service.cmr.version.Version;
import org.alfresco.service.cmr.version.VersionHistory;
import org.alfresco.service.cmr.version.VersionService;
import org.alfresco.service.cmr.version.VersionType;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.QNamePattern;
import org.springframework.extensions.surf.util.Pair;
/**
* @author Dmitry Velichkevich
*/
public class CmisObjectsUtils
{
public static final String NODE_REFERENCE_ID_DELIMITER = ";";
private static final Pattern VERSION_LABEL_MATCHING_COMPILED_PATTERN = Pattern.compile("([\\p{Graph}])+([\\p{Digit}]*)\\.([\\p{Digit}]*)$");
private static final String INVALID_OBJECT_IDENTIFIER_MESSAGE = "Invalid Object Identifier was specified: Identifier is incorrect or Object with the specified Identifier does not exist";
private static final List<QName> DOCUMENT_AND_FOLDER_TYPES;
static
{
DOCUMENT_AND_FOLDER_TYPES = new LinkedList<QName>();
DOCUMENT_AND_FOLDER_TYPES.add(ContentModel.TYPE_CONTENT);
DOCUMENT_AND_FOLDER_TYPES.add(ContentModel.TYPE_FOLDER);
}
private static final Map<String, EnumServiceException> CLASS_TO_ENUM_EXCEPTION_MAPPING;
static
{
CLASS_TO_ENUM_EXCEPTION_MAPPING = new HashMap<String, EnumServiceException>();
CLASS_TO_ENUM_EXCEPTION_MAPPING.put(AccessDeniedException.class.getName(), EnumServiceException.PERMISSION_DENIED);
CLASS_TO_ENUM_EXCEPTION_MAPPING.put(java.lang.RuntimeException.class.getName(), EnumServiceException.RUNTIME);
CLASS_TO_ENUM_EXCEPTION_MAPPING.put(UnsupportedOperationException.class.getName(), EnumServiceException.NOT_SUPPORTED);
CLASS_TO_ENUM_EXCEPTION_MAPPING.put(InvalidNodeRefException.class.getName(), EnumServiceException.INVALID_ARGUMENT);
CLASS_TO_ENUM_EXCEPTION_MAPPING.put(ContentIOException.class.getName(), EnumServiceException.NOT_SUPPORTED);
CLASS_TO_ENUM_EXCEPTION_MAPPING.put(CMISQueryException.class.getName(), EnumServiceException.INVALID_ARGUMENT);
// TODO: insert CLASS_TO_ENUM_EXCEPTION_MAPPING.put(<Concreate_Exception_Type>.class.getName(), EnumServiceException.<Appropriate_Enum_value>);
}
private CheckOutCheckInService checkOutCheckInService;
private CMISDictionaryService cmisDictionaryService;
private FileFolderService fileFolderService;
private AuthorityService authorityService;
private VersionService versionService;
private NodeService nodeService;
private LockService lockService;
private Throwable lastException;
public void setCmisDictionaryService(CMISDictionaryService cmisDictionaryService)
{
this.cmisDictionaryService = cmisDictionaryService;
}
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
public void setFileFolderService(FileFolderService fileFolderService)
{
this.fileFolderService = fileFolderService;
}
public void setLockService(LockService lockService)
{
this.lockService = lockService;
}
public void setCheckOutCheckInService(CheckOutCheckInService checkOutCheckInService)
{
this.checkOutCheckInService = checkOutCheckInService;
}
public void setAuthorityService(AuthorityService authorityService)
{
this.authorityService = authorityService;
}
public void setVersionService(VersionService versionService)
{
this.versionService = versionService;
}
public CmisException createCmisException(String message, EnumServiceException exceptionType)
{
return createCmisException(message, exceptionType, null, 0);
}
public CmisException createCmisException(String message, Throwable cause)
{
EnumServiceException exceptionType = null;
if (CLASS_TO_ENUM_EXCEPTION_MAPPING.containsKey(cause.getClass().getName()))
{
exceptionType = CLASS_TO_ENUM_EXCEPTION_MAPPING.get(cause.getClass().getName());
}
exceptionType = (exceptionType == null) ? (EnumServiceException.RUNTIME) : (exceptionType);
return createCmisException(message, exceptionType, cause, 0);
}
public CmisException createCmisException(String message, EnumServiceException exceptionType, Throwable cause)
{
return createCmisException(message, exceptionType, cause, 0);
}
public CmisException createCmisException(String message, EnumServiceException exceptionType, Throwable cause, int errorCode)
{
CmisFaultType fault = new CmisFaultType();
fault.setMessage(message);
fault.setType(exceptionType);
fault.setCode(BigInteger.valueOf(errorCode));
return new CmisException(message, fault, cause);
}
@SuppressWarnings("unchecked")
public <IdentifierType> IdentifierType getIdentifierInstance(String identifier, AlfrescoObjectType expectedType) throws CmisException
{
if (!(identifier instanceof String))
{
throw createCmisException("Invalid Object Identifier was specified", EnumServiceException.INVALID_ARGUMENT);
}
IdentifierType result;
AlfrescoObjectType actualObjectType;
if (isRelationship(identifier))
{
result = (IdentifierType) safeGetAssociationRef(identifier);
actualObjectType = AlfrescoObjectType.RELATIONSHIP_OBJECT;
}
else
{
NodeRef nodeReference = safeGetNodeRef(identifier);
result = (IdentifierType) nodeReference;
actualObjectType = determineActualObjectType(expectedType, this.nodeService.getType(nodeReference));
}
if ((AlfrescoObjectType.ANY_OBJECT == expectedType) || (actualObjectType == expectedType))
{
return result;
}
throw createCmisException(("Unexpected object type of the specified Object with \"" + identifier + "\" identifier"), EnumServiceException.INVALID_ARGUMENT);
}
public List<String> deleteFolder(NodeRef folderNodeReference, boolean continueOnFailure, EnumUnfileObject unfillingStrategy, boolean deleteAllVersions) throws CmisException
{
CmisObjectIterator iterator = new CmisObjectIterator(folderNodeReference, unfillingStrategy, continueOnFailure, deleteAllVersions, nodeService, fileFolderService,
versionService, checkOutCheckInService, this);
if (iterator.hasNext())
{
for (; iterator.hasNext(); iterator.next())
{
iterator.remove();
}
}
return iterator.getFailToDelete();
}
public boolean deleteObject(NodeRef objectNodeReference)
{
if (null == objectNodeReference)
{
return false;
}
if (versionService.getVersionStoreReference().getIdentifier().equals(objectNodeReference.getStoreRef().getIdentifier()))
{
String versionLabel = (String) nodeService.getProperty(objectNodeReference, ContentModel.PROP_VERSION_LABEL);
if ((null != versionLabel) && !versionLabel.equals(""))
{
Version currentVersion = versionService.getCurrentVersion(objectNodeReference);
if ((null != currentVersion) && nodeService.exists(currentVersion.getVersionedNodeRef()))
{
versionService.deleteVersion(currentVersion.getVersionedNodeRef(), currentVersion);
return true;
}
}
return false;
}
return canLock(objectNodeReference) && performNodeDeletion(objectNodeReference);
}
public boolean removeObject(NodeRef objectNodeReference, NodeRef folderNodeReference)
{
if (isChildOfThisFolder(objectNodeReference, folderNodeReference))
{
try
{
this.nodeService.removeChild(folderNodeReference, objectNodeReference);
}
catch (Throwable e)
{
lastException = e;
return false;
}
return true;
}
return false;
}
public boolean addObjectToFolder(NodeRef objectNodeRef, NodeRef parentFolderNodeRef)
{
try
{
QName name = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName((String) nodeService.getProperty(objectNodeRef,
ContentModel.PROP_NAME)));
nodeService.addChild(parentFolderNodeRef, objectNodeRef, ContentModel.ASSOC_CONTAINS, name);
return true;
}
catch (Throwable e)
{
lastException = e;
return false;
}
}
public boolean isFolder(NodeRef folderNodeRef)
{
if (folderNodeRef == null)
{
return false;
}
QName typeQName = nodeService.getType(folderNodeRef);
CMISTypeDefinition typeDef = cmisDictionaryService.findTypeForClass(typeQName, CMISScope.FOLDER);
return typeDef != null;
}
public boolean isDocument(NodeRef documentNodeRef)
{
if (documentNodeRef == null)
{
return false;
}
QName typeQName = nodeService.getType(documentNodeRef);
CMISTypeDefinition typeDef = cmisDictionaryService.findTypeForClass(typeQName, CMISScope.DOCUMENT);
return typeDef != null;
}
public boolean isRelationship(String identifier)
{
try
{
new AssociationRef(identifier);
return true;
}
catch (Throwable e)
{
return false;
}
}
public boolean isPolicy(NodeRef policyNodeRef)
{
// TODO: Policy
return false;
}
public EnumBaseObjectTypeIds determineObjectType(String identifier)
{
if (isRelationship(identifier))
{
return EnumBaseObjectTypeIds.CMIS_RELATIONSHIP;
}
NodeRef objectNodeReference = new NodeRef(identifier);
if (isFolder(objectNodeReference))
{
return EnumBaseObjectTypeIds.CMIS_FOLDER;
}
if (isDocument(objectNodeReference))
{
return EnumBaseObjectTypeIds.CMIS_DOCUMENT;
}
return EnumBaseObjectTypeIds.CMIS_POLICY;
}
public boolean isChildOfThisFolder(NodeRef objectNodeReference, NodeRef folderNodeReference)
{
NodeRef searchedObjectNodeReference = fileFolderService.searchSimple(folderNodeReference, (String) nodeService.getProperty(objectNodeReference, ContentModel.PROP_NAME));
return (searchedObjectNodeReference != null) && searchedObjectNodeReference.equals(objectNodeReference);
}
public boolean isPrimaryObjectParent(NodeRef folderNodeReference, NodeRef objectNodeReference)
{
NodeRef searchedParentObject = nodeService.getPrimaryParent(objectNodeReference).getParentRef();
return (searchedParentObject != null) && searchedParentObject.equals(folderNodeReference);
}
public boolean isWorkingCopy(NodeRef objectIdentifier)
{
return nodeService.hasAspect(objectIdentifier, ContentModel.ASPECT_WORKING_COPY);
}
public List<AssociationRef> receiveAssociations(NodeRef objectNodeReference, QNamePattern qnameFilter, EnumRelationshipDirection direction)
{
List<AssociationRef> result = new LinkedList<AssociationRef>();
if ((direction == EnumRelationshipDirection.EITHER) || (direction == EnumRelationshipDirection.TARGET))
{
result.addAll(nodeService.getSourceAssocs(objectNodeReference, qnameFilter));
}
if ((direction == EnumRelationshipDirection.EITHER) || (direction == EnumRelationshipDirection.SOURCE))
{
result.addAll(nodeService.getTargetAssocs(objectNodeReference, qnameFilter));
}
return result;
}
/**
* Returns latest minor or major version of document
*
* @param documentNodeRef document node reference
* @param major need latest major version
* @return latest version node reference
*/
public NodeRef getLatestNode(NodeRef documentNodeRef, boolean major)
{
NodeRef latestVersionNodeRef = documentNodeRef;
VersionHistory versionHistory = versionService.getVersionHistory(documentNodeRef);
if (null != versionHistory)
{
Collection<Version> allVersions = versionHistory.getAllVersions();
Iterator<Version> versionsIterator = ((null != allVersions) && !allVersions.isEmpty()) ? (allVersions.iterator()) : (null);
Version latestVersion = (null == versionsIterator) ? (null) : (versionsIterator.next());
String currentVersionLabel = (null != latestVersion) ? (latestVersion.getVersionLabel()) : (null);
if (major && (null != latestVersion))
{
for (; (VersionType.MAJOR != latestVersion.getVersionType()) && versionsIterator.hasNext(); latestVersion = versionsIterator.next())
{
}
latestVersion = (VersionType.MAJOR != latestVersion.getVersionType()) ? (null) : (latestVersion);
}
if ((null != latestVersion) && (null != latestVersion.getVersionLabel()))
{
latestVersionNodeRef = (!latestVersion.getVersionLabel().equals(currentVersionLabel) || (null == latestVersion.getVersionedNodeRef()) || !nodeService
.exists(latestVersion.getVersionedNodeRef())) ? (latestVersion.getFrozenStateNodeRef()) : (latestVersion.getVersionedNodeRef());
}
}
return latestVersionNodeRef;
}
private boolean performNodeDeletion(NodeRef objectNodeReference)
{
if (nodeService.hasAspect(objectNodeReference, ContentModel.ASPECT_WORKING_COPY))
{
checkOutCheckInService.cancelCheckout(objectNodeReference);
return true;
}
try
{
List<AssociationRef> associations = receiveAssociations(objectNodeReference, new MatcheAllQNames(), EnumRelationshipDirection.EITHER);
for (AssociationRef association : associations)
{
if ((null != association) && (null != association.getSourceRef()) && (null != association.getTargetRef()) && (null != association.getTypeQName()))
{
nodeService.removeAssociation(association.getSourceRef(), association.getTargetRef(), association.getTypeQName());
}
}
for (ChildAssociationRef parentAssociation : nodeService.getParentAssocs(objectNodeReference))
{
if (!parentAssociation.isPrimary())
{
nodeService.removeChildAssociation(parentAssociation);
}
}
nodeService.deleteNode(objectNodeReference);
}
catch (Throwable e)
{
lastException = e;
return false;
}
return true;
}
private boolean canLock(NodeRef objectNodeReference)
{
String currentUserName = AuthenticationUtil.getFullyAuthenticatedUser();
return (this.lockService.getLockStatus(objectNodeReference, currentUserName) != LockStatus.LOCKED) || authorityService.isAdminAuthority(currentUserName);
}
private AssociationRef safeGetAssociationRef(String identifier) throws CmisException
{
AssociationRef result = new AssociationRef(identifier);
if (!nodeService.exists(result.getSourceRef()) || !nodeService.exists(result.getTargetRef()))
{
throw createCmisException(INVALID_OBJECT_IDENTIFIER_MESSAGE, EnumServiceException.INVALID_ARGUMENT);
}
return result;
}
private NodeRef safeGetNodeRef(String nodeIdentifier) throws CmisException
{
Pair<String, String> nodeRefAndVersionLabel = (null != nodeIdentifier) ? (splitOnNodeRefAndVersionLabel(nodeIdentifier)) : (null);
if ((null != nodeRefAndVersionLabel) && (null != nodeRefAndVersionLabel.getFirst()) && NodeRef.isNodeRef(nodeRefAndVersionLabel.getFirst()))
{
NodeRef result = new NodeRef(nodeRefAndVersionLabel.getFirst());
if (nodeService.exists(result))
{
result = getNodeRefFromVersion(result, nodeRefAndVersionLabel.getSecond());
if ((null != result) && nodeService.exists(result))
{
return result;
}
}
}
throw createCmisException(INVALID_OBJECT_IDENTIFIER_MESSAGE, EnumServiceException.OBJECT_NOT_FOUND);
}
private Pair<String, String> splitOnNodeRefAndVersionLabel(String nodeIdentifier)
{
String versionLabel = null;
int versionDelimeterIndex = nodeIdentifier.lastIndexOf(NODE_REFERENCE_ID_DELIMITER);
if (versionDelimeterIndex > 0)
{
versionLabel = nodeIdentifier.substring(versionDelimeterIndex + 1);
if ((null != versionLabel) && !versionLabel.equals("") && VERSION_LABEL_MATCHING_COMPILED_PATTERN.matcher(versionLabel).matches())
{
nodeIdentifier = nodeIdentifier.substring(0, versionDelimeterIndex);
}
else
{
versionLabel = null;
}
}
return new Pair<String, String>(nodeIdentifier, versionLabel);
}
private NodeRef getNodeRefFromVersion(NodeRef nodeRef, String versionLabel) throws CmisException
{
NodeRef result = nodeRef;
NodeRef latestNodeRef = ((null != versionLabel) && (null != nodeRef)) ? (getLatestNode(nodeRef, false)) : (null);
if ((null != latestNodeRef) && nodeService.exists(latestNodeRef) && !versionLabel.equals(nodeService.getProperty(latestNodeRef, ContentModel.PROP_VERSION_LABEL)))
{
VersionHistory versionHistory = versionService.getVersionHistory(latestNodeRef);
if (null != versionHistory)
{
Version version = versionHistory.getVersion(versionLabel);
if ((null == version) || (null == version.getFrozenStateNodeRef()))
{
throw createCmisException(("Specified object has no " + versionLabel + " version"), EnumServiceException.INVALID_ARGUMENT);
}
result = version.getFrozenStateNodeRef();
}
}
return result;
}
private AlfrescoObjectType determineActualObjectType(AlfrescoObjectType expectedType, QName objectType)
{
CMISTypeDefinition typeDef = cmisDictionaryService.findTypeForClass(objectType);
if ((expectedType == AlfrescoObjectType.DOCUMENT_OBJECT || expectedType == AlfrescoObjectType.DOCUMENT_OR_FOLDER_OBJECT)
&& typeDef.getTypeId().getScope() == CMISScope.DOCUMENT)
{
return expectedType;
}
if ((expectedType == AlfrescoObjectType.FOLDER_OBJECT || expectedType == AlfrescoObjectType.DOCUMENT_OR_FOLDER_OBJECT)
&& typeDef.getTypeId().getScope() == CMISScope.FOLDER)
{
return expectedType;
}
return AlfrescoObjectType.ANY_OBJECT;
}
private class MatcheAllQNames implements QNamePattern
{
public boolean isMatch(QName qname)
{
return true;
}
}
public Throwable getLastOperationException()
{
Throwable result = lastException;
lastException = null;
return result;
}
}

View File

@@ -0,0 +1,100 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have received a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.cmis.ws.utils;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.cmis.CMISQueryException;
import org.alfresco.cmis.CMISServiceException;
import org.alfresco.repo.cmis.ws.CmisException;
import org.alfresco.repo.cmis.ws.CmisFaultType;
import org.alfresco.repo.cmis.ws.EnumServiceException;
import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.service.cmr.repository.ContentIOException;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
/**
* @author Dmitry Velichkevich
*/
public abstract class ExceptionUtil
{
private static final Map<String, EnumServiceException> CLASS_TO_ENUM_EXCEPTION_MAPPING;
static
{
CLASS_TO_ENUM_EXCEPTION_MAPPING = new HashMap<String, EnumServiceException>();
CLASS_TO_ENUM_EXCEPTION_MAPPING.put(AccessDeniedException.class.getName(), EnumServiceException.PERMISSION_DENIED);
CLASS_TO_ENUM_EXCEPTION_MAPPING.put(java.lang.RuntimeException.class.getName(), EnumServiceException.RUNTIME);
CLASS_TO_ENUM_EXCEPTION_MAPPING.put(UnsupportedOperationException.class.getName(), EnumServiceException.NOT_SUPPORTED);
CLASS_TO_ENUM_EXCEPTION_MAPPING.put(InvalidNodeRefException.class.getName(), EnumServiceException.INVALID_ARGUMENT);
CLASS_TO_ENUM_EXCEPTION_MAPPING.put(ContentIOException.class.getName(), EnumServiceException.NOT_SUPPORTED);
CLASS_TO_ENUM_EXCEPTION_MAPPING.put(CMISQueryException.class.getName(), EnumServiceException.INVALID_ARGUMENT);
}
public static CmisException createCmisException(String message, EnumServiceException exceptionType)
{
return createCmisException(message, exceptionType, null, 0);
}
public static CmisException createCmisException(String message, Throwable cause)
{
EnumServiceException exceptionType = null;
if (cause instanceof CMISServiceException)
{
return createCmisException((CMISServiceException)cause);
}
if (CLASS_TO_ENUM_EXCEPTION_MAPPING.containsKey(cause.getClass().getName()))
{
exceptionType = CLASS_TO_ENUM_EXCEPTION_MAPPING.get(cause.getClass().getName());
}
exceptionType = (exceptionType == null) ? (EnumServiceException.RUNTIME) : (exceptionType);
return createCmisException(message, exceptionType, cause, 0);
}
public static CmisException createCmisException(String message, EnumServiceException exceptionType, Throwable cause)
{
return createCmisException(message, exceptionType, cause, 0);
}
public static CmisException createCmisException(CMISServiceException exception)
{
return createCmisException(exception.getMessage(), EnumServiceException.fromValue(exception.getFaultName()), exception, exception.getStatusCode());
}
public static CmisException createCmisException(String message, EnumServiceException exceptionType, Throwable cause, int errorCode)
{
CmisFaultType fault = new CmisFaultType();
fault.setMessage(message);
fault.setType(exceptionType);
fault.setCode(BigInteger.valueOf(errorCode));
return new CmisException(message, fault, cause);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2009 Alfresco Software Limited.
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -15,11 +15,11 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have received a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.cmis.ws.utils;
@@ -40,6 +40,7 @@ import javax.xml.datatype.XMLGregorianCalendar;
import org.alfresco.cmis.CMISDataTypeEnum;
import org.alfresco.cmis.CMISDictionaryModel;
import org.alfresco.cmis.CMISDictionaryService;
import org.alfresco.cmis.CMISInvalidArgumentException;
import org.alfresco.cmis.CMISPropertyDefinition;
import org.alfresco.cmis.CMISScope;
import org.alfresco.cmis.CMISServices;
@@ -65,6 +66,7 @@ import org.alfresco.service.cmr.dictionary.TypeDefinition;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.version.Version;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
@@ -98,7 +100,6 @@ public class PropertyUtil
private NamespaceService namespaceService;
private CMISServices cmisService;
private CMISDictionaryService cmisDictionaryService;
private CmisObjectsUtils cmisObjectsUtils;
public PropertyUtil()
{
@@ -129,11 +130,6 @@ public class PropertyUtil
this.cmisDictionaryService = cmisDictionaryService;
}
public void setCmisObjectsUtils(CmisObjectsUtils cmisObjectsUtils)
{
this.cmisObjectsUtils = cmisObjectsUtils;
}
/**
* Gets property value by its name from Node Reference object
*
@@ -275,7 +271,7 @@ public class PropertyUtil
if ((PropertyMultiValueStateEnum.PROPERTY_NOT_MULTIVALUED == state) && (values.size() > 1))
{
throw cmisObjectsUtils.createCmisException("\"" + propertyName + "\" property is not Multi Valued", EnumServiceException.INVALID_ARGUMENT);
throw ExceptionUtil.createCmisException("\"" + propertyName + "\" property is not Multi Valued", EnumServiceException.INVALID_ARGUMENT);
}
return PropertyMultiValueStateEnum.PROPERTY_MULTIVALUED == state;
@@ -379,7 +375,7 @@ public class PropertyUtil
if ((null == cmisObjectType) && (null == nativeObjectType))
{
throw cmisObjectsUtils.createCmisException(("Can't find type definition for current object with \"" + typeId + "\" type Id"), EnumServiceException.INVALID_ARGUMENT);
throw ExceptionUtil.createCmisException(("Can't find type definition for current object with \"" + typeId + "\" type Id"), EnumServiceException.INVALID_ARGUMENT);
}
for (CmisProperty property : properties.getProperty())
@@ -406,7 +402,7 @@ public class PropertyUtil
}
case PROPERTY_NOT_UPDATABLE:
{
throw cmisObjectsUtils.createCmisException(("\"" + propertyName + "\" property is not updatable by repository for specified Object id"),
throw ExceptionUtil.createCmisException(("\"" + propertyName + "\" property is not updatable by repository for specified Object id"),
EnumServiceException.CONSTRAINT);
}
}
@@ -479,7 +475,7 @@ public class PropertyUtil
if (propertyDefinition.isRequired() && (null == value))
{
throw cmisObjectsUtils.createCmisException((propertyName + " property required"), EnumServiceException.CONSTRAINT);
throw ExceptionUtil.createCmisException((propertyName + " property required"), EnumServiceException.CONSTRAINT);
}
switch (propertyDefinition.getDataType())
@@ -514,7 +510,7 @@ public class PropertyUtil
{
if (value != null && (propertyDefinition.getMaximumLength() > 0) && (value.length() > propertyDefinition.getMaximumLength()))
{
throw cmisObjectsUtils.createCmisException((propertyName + " property value is too long"), EnumServiceException.CONSTRAINT);
throw ExceptionUtil.createCmisException((propertyName + " property value is too long"), EnumServiceException.CONSTRAINT);
}
}
@@ -525,21 +521,32 @@ public class PropertyUtil
* @param filter property filter
* @return properties
*/
public CmisPropertiesType getPropertiesType(String identifier, PropertyFilter filter) throws CmisException
public CmisPropertiesType getProperties(Object object, PropertyFilter filter) throws CmisException
{
Map<String, Serializable> properties;
if (!identifier.contains("|"))
try
{
properties = cmisService.getProperties(new NodeRef(identifier));
}
else
{
properties = createBaseRelationshipProperties(new AssociationRef(identifier));
}
Map<String, Serializable> properties;
if (object instanceof NodeRef)
{
properties = cmisService.getProperties((NodeRef) object);
}
else if (object instanceof Version)
{
properties = cmisService.getProperties(((Version) object).getFrozenStateNodeRef());
}
else
{
properties = createBaseRelationshipProperties((AssociationRef) object);
}
CmisPropertiesType result = new CmisPropertiesType();
convertToCmisProperties(properties, filter, result);
return result;
CmisPropertiesType result = new CmisPropertiesType();
convertToCmisProperties(properties, filter, result);
return result;
}
catch (CMISInvalidArgumentException e)
{
throw ExceptionUtil.createCmisException(e.getMessage(), EnumServiceException.INVALID_ARGUMENT, e);
}
}
private Map<String, Serializable> createBaseRelationshipProperties(AssociationRef association)
@@ -562,7 +569,7 @@ public class PropertyUtil
if (null == type)
{
throw cmisObjectsUtils.createCmisException(("Type with " + typeId + " typeId was not found"), EnumServiceException.RUNTIME);
throw ExceptionUtil.createCmisException(("Type with " + typeId + " typeId was not found"), EnumServiceException.RUNTIME);
}
for (String propertyName : properties.keySet())