ALF-19690 "CMIS TCK Test Failures": fixed up failing TCK tests for 1.0 and 1.1 endpoints, refactoring of tests to aid in this aim, other fixes for things I found whilst testing, hopefully have addressed CLOUD-2051 too, upgrade alfresco-opencmis-extension (with updated chemistry dependency) to fix transitive dependency issue in maven

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@55695 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Steven Glover
2013-09-19 16:35:41 +00:00
parent c03263d5ff
commit 4b7ed3bd55
11 changed files with 493 additions and 315 deletions

View File

@@ -116,7 +116,8 @@
<property name="sqlSessionTemplate" ref="repoSqlSessionTemplate"/>
<property name="qnameDAO" ref="qnameDAO"/>
<property name="nodeService" ref="nodeService"/>
<property name="nodeDAO" ref="nodeDAO"/>
<property name="nodeDAO" ref="nodeDAO"/>
<property name="tenantService" ref="tenantService"/>
</bean>
</beans>

View File

@@ -49,6 +49,12 @@
<property name="dictionaryService">
<ref bean="dictionaryService" />
</property>
<property name="namespacePrefixResolver">
<ref bean="namespaceService" />
</property>
<property name="queryRegister">
<ref bean="search.queryRegisterComponent" />
</property>
</bean>
<alias name="search.indexerAndSearcherFactory" alias="search.admLuceneIndexerAndSearcherFactory"/>

View File

@@ -144,8 +144,8 @@ public class AlfrescoCmisServiceImpl extends AbstractCmisService implements Alfr
private static final QName PARAM_PARENT = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "parent");
private static final QName PARAM_USERNAME = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "username");
private static final String LUCENE_QUERY_CHECKEDOUT = "+@cm\\:workingCopyOwner:${cm:username}";
private static final String LUCENE_QUERY_CHECKEDOUT_IN_FOLDER = "+@cm\\:workingCopyOwner:${cm:username} +PARENT:\"${cm:parent}\"";
private static final String LUCENE_QUERY_CHECKEDOUT = "+=@cm\\:workingCopyOwner:${cm:username}";
private static final String LUCENE_QUERY_CHECKEDOUT_IN_FOLDER = "+=@cm\\:workingCopyOwner:${cm:username} +=PARENT:\"${cm:parent}\"";
private static final String MIN_FILTER = "cmis:name,cmis:baseTypeId,cmis:objectTypeId,"
+ "cmis:createdBy,cmis:creationDate,cmis:lastModifiedBy,cmis:lastModificationDate,"
@@ -811,7 +811,7 @@ public class AlfrescoCmisServiceImpl extends AbstractCmisService implements Alfr
// prepare query
SearchParameters params = new SearchParameters();
params.setLanguage(SearchService.LANGUAGE_LUCENE);
params.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO);
QueryParameterDefinition usernameDef = new QueryParameterDefImpl(
PARAM_USERNAME,
connector.getDictionaryService().getDataType(DataTypeDefinition.TEXT),
@@ -1121,65 +1121,55 @@ public class AlfrescoCmisServiceImpl extends AbstractCmisService implements Alfr
throw new CmisConstraintException("This document type is not versionable!");
}
FileInfo fileInfo = connector.getFileFolderService().create(
parentInfo.getNodeRef(), name, type.getAlfrescoClass());
NodeRef nodeRef = fileInfo.getNodeRef();
connector.setProperties(nodeRef, type, properties, new String[] { PropertyIds.NAME, PropertyIds.OBJECT_TYPE_ID });
connector.applyPolicies(nodeRef, type, policies);
connector.applyACL(nodeRef, type, addAces, removeAces);
// handle content
File tempFile = null;
try
{
// don't want auto-versioning to create a version
connector.disableBehaviour(ContentModel.ASPECT_VERSIONABLE);
FileInfo fileInfo = connector.getFileFolderService().create(
parentInfo.getNodeRef(), name, type.getAlfrescoClass());
NodeRef nodeRef = fileInfo.getNodeRef();
connector.setProperties(nodeRef, type, properties, new String[] { PropertyIds.NAME, PropertyIds.OBJECT_TYPE_ID });
connector.applyPolicies(nodeRef, type, policies);
connector.applyACL(nodeRef, type, addAces, removeAces);
// handle content
File tempFile = null;
try
if (contentStream != null)
{
if (contentStream != null)
{
// write content
String mimeType = parseMimeType(contentStream);
// write content
String mimeType = parseMimeType(contentStream);
// copy stream to temp file
// OpenCMIS does this for us ....
tempFile = copyToTempFile(contentStream);
final Charset encoding = (tempFile == null ? null : getEncoding(tempFile, contentStream.getMimeType()));
// copy stream to temp file
// OpenCMIS does this for us ....
tempFile = copyToTempFile(contentStream);
final Charset encoding = (tempFile == null ? null : getEncoding(tempFile, contentStream.getMimeType()));
ContentWriter writer = connector.getFileFolderService().getWriter(nodeRef);
writer.setMimetype(mimeType);
writer.setEncoding(encoding.name());
writer.putContent(tempFile);
}
ContentWriter writer = connector.getFileFolderService().getWriter(nodeRef);
writer.setMimetype(mimeType);
writer.setEncoding(encoding.name());
writer.putContent(tempFile);
}
finally
{
if(tempFile != null)
{
removeTempFile(tempFile);
}
}
connector.extractMetadata(nodeRef);
// generate "doclib" thumbnail asynchronously
connector.createThumbnails(nodeRef, Collections.singleton("doclib"));
connector.applyVersioningState(nodeRef, versioningState);
removeTempFile(tempFile);
String objectId = connector.createObjectId(nodeRef);
connector.getActivityPoster().postFileFolderAdded(nodeRef);
return objectId;
}
finally
{
connector.enableBehaviour(ContentModel.ASPECT_VERSIONABLE);
if(tempFile != null)
{
removeTempFile(tempFile);
}
}
connector.extractMetadata(nodeRef);
// generate "doclib" thumbnail asynchronously
connector.createThumbnails(nodeRef, Collections.singleton("doclib"));
connector.applyVersioningState(nodeRef, versioningState);
removeTempFile(tempFile);
String objectId = connector.createObjectId(nodeRef);
connector.getActivityPoster().postFileFolderAdded(nodeRef);
return objectId;
}
@Override
@@ -1216,9 +1206,6 @@ public class AlfrescoCmisServiceImpl extends AbstractCmisService implements Alfr
try
{
// don't want auto-versioning to create a version
connector.disableBehaviour(ContentModel.ASPECT_VERSIONABLE);
FileInfo fileInfo = connector.getFileFolderService().copy(
sourceNodeRef, parentInfo.getNodeRef(), name);
NodeRef nodeRef = fileInfo.getNodeRef();
@@ -1232,23 +1219,14 @@ public class AlfrescoCmisServiceImpl extends AbstractCmisService implements Alfr
connector.applyVersioningState(nodeRef, versioningState);
// connector.setAutoVersionable(nodeRef);
connector.getActivityPoster().postFileFolderAdded(nodeRef);
// connector.createVersion(nodeRef, VersionType.MINOR, "Thumbnails");
// connector.createThumbnails(nodeRef, Collections.singleton("doclib"));
return connector.createObjectId(nodeRef);
}
catch (FileNotFoundException e)
{
throw new CmisContentAlreadyExistsException("An object with this name already exists!", e);
}
finally
{
connector.enableBehaviour(ContentModel.ASPECT_VERSIONABLE);
}
}
@Override
@@ -2002,24 +1980,14 @@ public class AlfrescoCmisServiceImpl extends AbstractCmisService implements Alfr
throw new CmisConstraintException("Document is not versionable!");
}
try
{
// don't want auto-versioning to create a version
connector.disableBehaviour(ContentModel.ASPECT_VERSIONABLE);
// check out
NodeRef pwcNodeRef = connector.getCheckOutCheckInService().checkout(nodeRef);
CMISNodeInfo pwcNodeInfo = createNodeInfo(pwcNodeRef);
objectId.setValue(pwcNodeInfo.getObjectId());
// check out
NodeRef pwcNodeRef = connector.getCheckOutCheckInService().checkout(nodeRef);
CMISNodeInfo pwcNodeInfo = createNodeInfo(pwcNodeRef);
objectId.setValue(pwcNodeInfo.getObjectId());
if (contentCopied != null)
{
contentCopied.setValue(connector.getFileFolderService().getReader(pwcNodeRef) != null);
}
}
finally
if (contentCopied != null)
{
connector.enableBehaviour(ContentModel.ASPECT_VERSIONABLE);
contentCopied.setValue(connector.getFileFolderService().getReader(pwcNodeRef) != null);
}
}
@@ -2033,24 +2001,20 @@ public class AlfrescoCmisServiceImpl extends AbstractCmisService implements Alfr
// only accept a PWC
if (!info.isVariant(CMISObjectVariant.PWC))
{
throw new CmisVersioningException("Object is not a PWC!");
NodeRef nodeRef = info.getNodeRef();
NodeRef workingCopyNodeRef = connector.getCheckOutCheckInService().getWorkingCopy(nodeRef);
info = getOrCreateNodeInfo(workingCopyNodeRef.getId());
if (!info.isVariant(CMISObjectVariant.PWC))
{
throw new CmisVersioningException("Object is not a PWC!");
}
}
// get object
final NodeRef nodeRef = info.getNodeRef();
try
{
// don't want auto-versioning to create a version
connector.disableBehaviour(ContentModel.ASPECT_VERSIONABLE);
// cancel check out
connector.getCheckOutCheckInService().cancelCheckout(nodeRef);
}
finally
{
connector.enableBehaviour(ContentModel.ASPECT_VERSIONABLE);
}
// cancel check out
connector.getCheckOutCheckInService().cancelCheckout(nodeRef);
}
@Override
@@ -2077,58 +2041,39 @@ public class AlfrescoCmisServiceImpl extends AbstractCmisService implements Alfr
final File tempFile = copyToTempFile(contentStream);
final Charset encoding = (tempFile == null ? null : getEncoding(tempFile, contentStream.getMimeType()));
try
// check in
// update PWC
connector.setProperties(nodeRef, type, properties,
new String[] { PropertyIds.OBJECT_TYPE_ID });
connector.applyPolicies(nodeRef, type, policies);
connector.applyACL(nodeRef, type, addAces, removeAces);
// handle content
if (contentStream != null)
{
// don't want auto-versioning to create a version
connector.disableBehaviour(ContentModel.ASPECT_VERSIONABLE);
// check in
// update PWC
connector.setProperties(nodeRef, type, properties,
new String[] { PropertyIds.OBJECT_TYPE_ID });
connector.applyPolicies(nodeRef, type, policies);
connector.applyACL(nodeRef, type, addAces, removeAces);
// handle content
if (contentStream != null)
{
// write content
ContentWriter writer = connector.getFileFolderService().getWriter(nodeRef);
writer.setMimetype(parseMimeType(contentStream));
writer.setEncoding(encoding.name());
writer.putContent(tempFile);
}
// check aspect
// if (connector.getNodeService().hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE) == false)
// {
// Map<QName, Serializable> props = new HashMap<QName, Serializable>();
// props.put(ContentModel.PROP_INITIAL_VERSION, false);
// props.put(ContentModel.PROP_AUTO_VERSION, false);
// connector.getNodeService().addAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE, props);
// }
// create version properties
Map<String, Serializable> versionProperties = new HashMap<String, Serializable>(5);
versionProperties.put(VersionModel.PROP_VERSION_TYPE, major ? VersionType.MAJOR
: VersionType.MINOR);
if (checkinComment != null)
{
versionProperties.put(VersionModel.PROP_DESCRIPTION, checkinComment);
}
// check in
NodeRef newNodeRef = connector.getCheckOutCheckInService().checkin(nodeRef, versionProperties);
connector.getActivityPoster().postFileFolderUpdated(info.isFolder(), newNodeRef);
objectId.setValue(connector.createObjectId(newNodeRef));
// write content
ContentWriter writer = connector.getFileFolderService().getWriter(nodeRef);
writer.setMimetype(parseMimeType(contentStream));
writer.setEncoding(encoding.name());
writer.putContent(tempFile);
}
finally
// create version properties
Map<String, Serializable> versionProperties = new HashMap<String, Serializable>(5);
versionProperties.put(VersionModel.PROP_VERSION_TYPE, major ? VersionType.MAJOR
: VersionType.MINOR);
if (checkinComment != null)
{
connector.enableBehaviour(ContentModel.ASPECT_VERSIONABLE);
versionProperties.put(VersionModel.PROP_DESCRIPTION, checkinComment);
}
// check in
NodeRef newNodeRef = connector.getCheckOutCheckInService().checkin(nodeRef, versionProperties);
connector.getActivityPoster().postFileFolderUpdated(info.isFolder(), newNodeRef);
objectId.setValue(connector.createObjectId(newNodeRef));
removeTempFile(tempFile);
}
@@ -2605,19 +2550,6 @@ public class AlfrescoCmisServiceImpl extends AbstractCmisService implements Alfr
return info;
}
protected String getGuid(String nodeId)
{
int idx = nodeId.lastIndexOf("/");
if(idx != -1)
{
return nodeId.substring(idx+1);
}
else
{
return nodeId;
}
}
/**
* Collects the {@link ObjectInfo} about an object.
*
@@ -2722,7 +2654,7 @@ public class AlfrescoCmisServiceImpl extends AbstractCmisService implements Alfr
info.setWorkingCopyId(null);
info.setWorkingCopyOriginalId(null);
info.setVersionSeriesId(getGuid(ni.getCurrentNodeId()));
info.setVersionSeriesId(ni.getCurrentNodeId());
if (ni.isPWC())
{
@@ -2736,7 +2668,7 @@ public class AlfrescoCmisServiceImpl extends AbstractCmisService implements Alfr
if (ni.hasPWC())
{
info.setWorkingCopyId(getGuid(ni.getCurrentNodeId()) + CMISConnector.ID_SEPERATOR
info.setWorkingCopyId(ni.getCurrentNodeId() + CMISConnector.ID_SEPERATOR
+ CMISConnector.PWC_VERSION_LABEL);
info.setWorkingCopyOriginalId(ni.getCurrentObjectId());
} else

View File

@@ -36,6 +36,7 @@ import java.util.EnumSet;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -93,6 +94,7 @@ import org.alfresco.service.cmr.audit.AuditQueryParameters;
import org.alfresco.service.cmr.audit.AuditService;
import org.alfresco.service.cmr.audit.AuditService.AuditQueryCallback;
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
import org.alfresco.service.cmr.dictionary.AspectDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.InvalidAspectException;
@@ -1167,15 +1169,7 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen
}
else
{
// if input is NodeRef, return NodeRef. If input is guid, return guid.
if(NodeRef.isNodeRef(incomingNodeId))
{
sb.append(incomingNodeId);
}
else
{
sb.append(getGuid(incomingNodeId));
}
sb.append(incomingNodeId);
}
if(versionLabel != null)
{
@@ -1187,28 +1181,19 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen
private void createVersion(NodeRef nodeRef, VersionType versionType, String reason)
{
// disable auto-versioning behaviour for this
disableBehaviour(ContentModel.ASPECT_VERSIONABLE);
try
if(versionService.getVersionHistory(nodeRef) == null)
{
if(versionService.getVersionHistory(nodeRef) == null)
{
// no version history. Make sure we have an initial major version 1.0.
Map<String, Serializable> versionProperties = new HashMap<String, Serializable>(2);
versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MAJOR);
versionProperties.put(VersionModel.PROP_DESCRIPTION, "Initial version");
versionService.createVersion(nodeRef, versionProperties);
}
// no version history. Make sure we have an initial major version 1.0.
Map<String, Serializable> versionProperties = new HashMap<String, Serializable>(2);
versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MAJOR);
versionProperties.put(VersionModel.PROP_DESCRIPTION, "Initial version");
versionService.createVersion(nodeRef, versionProperties);
}
Map<String, Serializable> versionProperties = new HashMap<String, Serializable>(2);
versionProperties.put(VersionModel.PROP_VERSION_TYPE, versionType);
versionProperties.put(VersionModel.PROP_DESCRIPTION, reason);
versionService.createVersion(nodeRef, versionProperties);
}
finally
{
enableBehaviour(ContentModel.ASPECT_VERSIONABLE);
}
Map<String, Serializable> versionProperties = new HashMap<String, Serializable>(2);
versionProperties.put(VersionModel.PROP_VERSION_TYPE, versionType);
versionProperties.put(VersionModel.PROP_DESCRIPTION, reason);
versionService.createVersion(nodeRef, versionProperties);
}
private boolean isPublicApi()
@@ -1349,18 +1334,7 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen
versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MAJOR);
versionProperties.put(VersionModel.PROP_DESCRIPTION, "Initial Version");
try
{
// don't want auto-versioning to create a version
disableBehaviour(ContentModel.ASPECT_VERSIONABLE, nodeRef);
versionService.createVersion(nodeRef, versionProperties);
getCheckOutCheckInService().checkout(nodeRef);
}
finally
{
enableBehaviour(ContentModel.ASPECT_VERSIONABLE, nodeRef);
}
getCheckOutCheckInService().checkout(nodeRef);
}
else if ((versioningState == VersioningState.MAJOR) || (versioningState == VersioningState.MINOR))
{
@@ -1378,17 +1352,7 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen
versioningState == VersioningState.MAJOR ? VersionType.MAJOR : VersionType.MINOR);
versionProperties.put(VersionModel.PROP_DESCRIPTION, "Initial Version");
try
{
// don't want auto-versioning to create a version
disableBehaviour(ContentModel.ASPECT_VERSIONABLE, nodeRef);
versionService.createVersion(nodeRef, versionProperties);
}
finally
{
enableBehaviour(ContentModel.ASPECT_VERSIONABLE, nodeRef);
}
versionService.createVersion(nodeRef, versionProperties);
}
}
@@ -2766,7 +2730,11 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen
// set allowable actions
if (includeAllowableActions)
{
hit.setAllowableActions(getAllowableActions(createNodeInfo(nodeRef)));
CMISNodeInfoImpl nodeInfo = createNodeInfo(nodeRef);
if(!nodeInfo.getObjectVariant().equals(CMISObjectVariant.NOT_EXISTING))
{
hit.setAllowableActions(getAllowableActions(nodeInfo));
}
}
// set relationships
@@ -2811,6 +2779,7 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen
/**
* Sets property values.
*/
@SuppressWarnings({ "rawtypes" })
public void setProperties(NodeRef nodeRef, TypeDefinitionWrapper type, Properties properties, String... exclude)
{
if (properties == null)
@@ -2818,26 +2787,66 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen
return;
}
// Need to do this first
Map<String, PropertyData<?>> propsMap = properties.getProperties();
PropertyData<?> secondaryTypes = propsMap.get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS);
if(secondaryTypes != null && secondaryTypes.getValues().size() > 0)
Map<String, PropertyData<?>> incomingPropsMap = properties.getProperties();
if (incomingPropsMap == null)
{
setProperty(nodeRef, type, secondaryTypes);
return;
}
List<PropertyData<?>> props = properties.getPropertyList();
for (PropertyData<?> property : props)
// extract property data into an easier to use form
Map<String, Pair<TypeDefinitionWrapper, Serializable>> propsMap = new HashMap<String, Pair<TypeDefinitionWrapper, Serializable>>();
for (String propertyId : incomingPropsMap.keySet())
{
String propertyId = property.getId();
if(propertyId.equals(PropertyIds.SECONDARY_OBJECT_TYPE_IDS))
{
// handled above
continue;
}
PropertyData<?> property = incomingPropsMap.get(propertyId);
PropertyDefinitionWrapper propDef = type.getPropertyById(property.getId());
if (propDef == null)
{
throw new CmisInvalidArgumentException("Property " + property.getId() + " is unknown!");
}
Updatability updatability = propDef.getPropertyDefinition().getUpdatability();
if ((updatability == Updatability.READONLY)
|| (updatability == Updatability.WHENCHECKEDOUT && !checkOutCheckInService.isWorkingCopy(nodeRef)))
{
throw new CmisInvalidArgumentException("Property " + property.getId() + " is read-only!");
}
TypeDefinitionWrapper propType = propDef.getOwningType();
Serializable value = getValue(property, propDef.getPropertyDefinition().getCardinality() == Cardinality.MULTI);
Pair<TypeDefinitionWrapper, Serializable> pair = new Pair<TypeDefinitionWrapper, Serializable>(propType, value);
propsMap.put(propertyId, pair);
}
// Need to do deal with secondary types first
Pair<TypeDefinitionWrapper, Serializable> pair = propsMap.get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS);
Serializable secondaryTypesProperty = (pair != null ? pair.getSecond() : null);
if(secondaryTypesProperty != null)
{
if (!(secondaryTypesProperty instanceof List))
{
throw new CmisInvalidArgumentException("Secondary types must be a list!");
}
List secondaryTypes = (List)secondaryTypesProperty;
if(secondaryTypes != null && secondaryTypes.size() > 0)
{
// add/remove secondary types/aspects
processSecondaryTypes(nodeRef, secondaryTypes, propsMap);
}
}
for (String propertyId : propsMap.keySet())
{
if(propertyId.equals(PropertyIds.SECONDARY_OBJECT_TYPE_IDS))
{
// already handled above
continue;
}
pair = propsMap.get(propertyId);
TypeDefinitionWrapper propType = pair.getFirst();
Serializable value = pair.getSecond();
if (Arrays.binarySearch(exclude, propertyId) < 0)
{
setProperty(nodeRef, type, property);
setProperty(nodeRef, propType, propertyId, value);
}
}
@@ -2858,6 +2867,93 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen
}
}
@SuppressWarnings("rawtypes")
private void processSecondaryTypes(NodeRef nodeRef, List secondaryTypes, Map<String, Pair<TypeDefinitionWrapper, Serializable>> propsToAdd)
{
// diff existing aspects and secondaryTypes/aspects list
Set<QName> existingAspects = nodeService.getAspects(nodeRef);
Set<QName> secondaryTypeAspects = new HashSet<QName>();
for(Object o : secondaryTypes)
{
String secondaryType = (String)o;
TypeDefinitionWrapper wrapper = cmisDictionaryService.findType(secondaryType);
if(wrapper != null)
{
QName aspectQName = wrapper.getAlfrescoName();
secondaryTypeAspects.add(aspectQName);
}
else
{
throw new CmisInvalidArgumentException("Invalid secondary type id " + secondaryType);
}
}
Set<QName> ignore = new HashSet<QName>();
ignore.add(ContentModel.ASPECT_REFERENCEABLE);
ignore.add(ContentModel.ASPECT_LOCALIZED);
// aspects to add == the list of secondary types - existing aspects - ignored aspects
Set<QName> toAdd = new HashSet<QName>(secondaryTypeAspects);
toAdd.removeAll(existingAspects);
toAdd.removeAll(ignore);
// aspects to remove == existing aspects - secondary types
Set<QName> aspectsToRemove = new HashSet<QName>();
aspectsToRemove.addAll(existingAspects);
aspectsToRemove.removeAll(ignore);
Iterator<QName> it = aspectsToRemove.iterator();
while(it.hasNext())
{
QName aspectQName = it.next();
TypeDefinitionWrapper w = cmisDictionaryService.findNodeType(aspectQName);
if(w == null || secondaryTypeAspects.contains(aspectQName))
{
// the type is not exposed or is in the secondary types to set, so remove it from the to remove set
it.remove();
}
}
// first, remove aspects
for(QName aspectQName : aspectsToRemove)
{
nodeService.removeAspect(nodeRef, aspectQName);
// aspect is being removed so remove all of its properties from the propsToAdd map
TypeDefinitionWrapper w = cmisDictionaryService.findNodeType(aspectQName);
for(PropertyDefinitionWrapper wr : w.getProperties())
{
String propertyId = wr.getPropertyId();
propsToAdd.remove(propertyId);
}
}
// add aspects and properties
for(QName aspectQName : toAdd)
{
nodeService.addAspect(nodeRef, aspectQName, null);
// get aspect properties
AspectDefinition aspectDef = dictionaryService.getAspect(aspectQName);
Map<QName, org.alfresco.service.cmr.dictionary.PropertyDefinition> aspectPropDefs = aspectDef.getProperties();
TypeDefinitionWrapper w = cmisDictionaryService.findNodeType(aspectQName);
// for each aspect property...
for(QName propQName : aspectPropDefs.keySet())
{
// find CMIS property id
PropertyDefinitionWrapper property = w.getPropertyByQName(propQName);
String propertyId = property.getPropertyId();
if(!propsToAdd.containsKey(propertyId))
{
TypeDefinitionWrapper propType = property.getOwningType();
// CMIS 1.1 secondary types specification requires that all secondary type properties are set
// property not included in propsToAdd, add it with null value
Pair<TypeDefinitionWrapper, Serializable> pair = new Pair<TypeDefinitionWrapper, Serializable>(propType, null);
propsToAdd.put(propertyId, pair);
}
}
}
}
public void addSecondaryTypes(NodeRef nodeRef, List<String> secondaryTypes)
{
if(secondaryTypes != null && secondaryTypes.size() > 0)
@@ -3176,62 +3272,39 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen
/**
* Sets a property value.
*/
@SuppressWarnings("rawtypes")
public void setProperty(NodeRef nodeRef, TypeDefinitionWrapper type, PropertyData<?> property)
public void setProperty(NodeRef nodeRef, TypeDefinitionWrapper type, String propertyId, Serializable value)
{
if (property == null)
if (propertyId == null)
{
throw new CmisInvalidArgumentException("Cannot process not null property!");
}
PropertyDefinitionWrapper propDef = type.getPropertyById(property.getId());
PropertyDefinitionWrapper propDef = type.getPropertyById(propertyId);
if (propDef == null)
{
throw new CmisInvalidArgumentException("Property " + property.getId() + " is unknown!");
throw new CmisInvalidArgumentException("Property " + propertyId + " is unknown!");
}
Updatability updatability = propDef.getPropertyDefinition().getUpdatability();
if ((updatability == Updatability.READONLY)
|| (updatability == Updatability.WHENCHECKEDOUT && !checkOutCheckInService.isWorkingCopy(nodeRef)))
{
throw new CmisInvalidArgumentException("Property " + property.getId() + " is read-only!");
throw new CmisInvalidArgumentException("Property " + propertyId + " is read-only!");
}
// get the value
Serializable value = getValue(property, propDef.getPropertyDefinition().getCardinality() == Cardinality.MULTI);
if(propDef.getPropertyId().equals(PropertyIds.SECONDARY_OBJECT_TYPE_IDS))
{
if (!(value instanceof List))
{
throw new CmisInvalidArgumentException("Secondary types must be a list!");
}
List secondaryTypes = (List)value;
for(Object o : secondaryTypes)
{
String secondaryType = (String)o;
TypeDefinitionWrapper wrapper = cmisDictionaryService.findType(secondaryType);
if(wrapper != null)
{
nodeService.addAspect(nodeRef, wrapper.getAlfrescoName(), null);
}
else
{
throw new CmisInvalidArgumentException("Invalid type id " + secondaryType);
}
}
throw new IllegalArgumentException("Cannot process " + PropertyIds.SECONDARY_OBJECT_TYPE_IDS + " in setProperty");
}
else
{
QName propertyQName = propDef.getPropertyAccessor().getMappedProperty();
if (propertyQName == null)
{
throw new CmisConstraintException("Unable to set property " + property.getId() + "!");
throw new CmisConstraintException("Unable to set property " + propertyId + "!");
}
if (property.getId().equals(PropertyIds.NAME))
if (propertyId.equals(PropertyIds.NAME))
{
if (!(value instanceof String))
{
@@ -3259,25 +3332,25 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen
}
else
{
// overflow check
if(propDef.getPropertyDefinition().getPropertyType() == PropertyType.INTEGER && value instanceof BigInteger)
{
org.alfresco.service.cmr.dictionary.PropertyDefinition def = dictionaryService.getProperty(propertyQName);
QName dataDef = def.getDataType().getName();
BigInteger bigValue = (BigInteger)value;
// overflow check
if(propDef.getPropertyDefinition().getPropertyType() == PropertyType.INTEGER && value instanceof BigInteger)
{
org.alfresco.service.cmr.dictionary.PropertyDefinition def = dictionaryService.getProperty(propertyQName);
QName dataDef = def.getDataType().getName();
BigInteger bigValue = (BigInteger)value;
if ((bigValue.compareTo(maxInt) > 0 || bigValue.compareTo(minInt) < 0 ) && dataDef.equals(DataTypeDefinition.INT))
{
throw new CmisConstraintException("Value is out of range for property " + propertyQName.getLocalName());
}
if ((bigValue.compareTo(maxInt) > 0 || bigValue.compareTo(minInt) < 0 ) && dataDef.equals(DataTypeDefinition.INT))
{
throw new CmisConstraintException("Value is out of range for property " + propertyQName.getLocalName());
}
if ((bigValue.compareTo(maxLong) > 0 || bigValue.compareTo(minLong) < 0 ) && dataDef.equals(DataTypeDefinition.LONG))
{
throw new CmisConstraintException("Value is out of range for property " + propertyQName.getLocalName());
}
}
if ((bigValue.compareTo(maxLong) > 0 || bigValue.compareTo(minLong) < 0 ) && dataDef.equals(DataTypeDefinition.LONG))
{
throw new CmisConstraintException("Value is out of range for property " + propertyQName.getLocalName());
}
}
nodeService.setProperty(nodeRef, propertyQName, value);
nodeService.setProperty(nodeRef, propertyQName, value);
}
}
}

View File

@@ -37,7 +37,6 @@ import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.repo.version.Version2Model;
import org.alfresco.repo.version.VersionBaseModel;
import org.alfresco.repo.version.VersionModel;
import org.alfresco.service.cmr.lock.LockType;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
@@ -503,7 +502,7 @@ public class CMISNodeInfoImpl implements CMISNodeInfo
}
objecVariant = CMISObjectVariant.ASSOC;
objectId = connector.constructObjectId(associationRef, null);
objectId = CMISConnector.ASSOC_ID_PREFIX + associationRef.getId();
}
private void determineType()
@@ -583,7 +582,7 @@ public class CMISNodeInfoImpl implements CMISNodeInfo
public boolean isLatestVersion()
{
return isPWC() || (isCurrentVersion() && !hasPWC());
return isCurrentVersion();
}
public boolean isLatestMajorVersion()
@@ -865,16 +864,16 @@ public class CMISNodeInfoImpl implements CMISNodeInfo
private NodeRef getLatestNonMajorVersionNodeRef()
{
if (isPWC())
{
return nodeRef;
} else if (hasPWC())
{
return connector.getCheckOutCheckInService().getWorkingCopy(getCurrentNodeNodeRef());
} else
{
// if (isPWC())
// {
// return nodeRef;
// } else if (hasPWC())
// {
// return connector.getCheckOutCheckInService().getWorkingCopy(getCurrentNodeNodeRef());
// } else
// {
return getCurrentNodeNodeRef();
}
// }
}
// TODO lock here??

View File

@@ -2,6 +2,7 @@ package org.alfresco.opencmis;
import java.util.List;
import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.Path;
@@ -44,9 +45,16 @@ public class PathObjectFilter implements ObjectFilter
@Override
public boolean filter(NodeRef nodeRef)
{
Path path = nodeService.getPath(nodeRef);
String s = path.toPrefixString(this.namespaceService);
return filter(s);
try
{
Path path = nodeService.getPath(nodeRef);
String s = path.toPrefixString(this.namespaceService);
return filter(s);
}
catch(AccessDeniedException e)
{
return true;
}
}
public boolean filter(String path)

View File

@@ -5,11 +5,13 @@ import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.chemistry.opencmis.server.shared.CallContextHandler;
import org.apache.chemistry.opencmis.server.shared.BasicAuthCallContextHandler;
public class PublicApiCallContextHandler implements CallContextHandler
public class PublicApiCallContextHandler extends BasicAuthCallContextHandler
{
@Override
private static final long serialVersionUID = 8877878113507734452L;
@Override
public Map<String, String> getCallContextMap(HttpServletRequest request)
{
Map<String, String> map = new HashMap<String, String>();

View File

@@ -109,7 +109,8 @@ public abstract class AbstractProperty implements CMISPropertyAccessor
{
if (nodeInfo.containsPropertyValue(propertyName))
{
return nodeInfo.getPropertyValue(propertyName);
Serializable value = nodeInfo.getPropertyValue(propertyName);
return value;
} else
{
Serializable value = getValueInternal(nodeInfo);

View File

@@ -49,6 +49,6 @@ public class VersionSeriesCheckedOutIdProperty extends AbstractProperty
return null;
}
return getGuid(nodeInfo.getCurrentNodeId()) + CMISConnector.ID_SEPERATOR + CMISConnector.PWC_VERSION_LABEL;
return connector.constructObjectId(nodeInfo.getCurrentNodeId(), CMISConnector.PWC_VERSION_LABEL);
}
}

View File

@@ -27,7 +27,6 @@ import java.util.Map;
import java.util.Set;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.domain.mimetype.MimetypeDAO;
import org.alfresco.repo.domain.node.Node;
import org.alfresco.repo.domain.node.NodeDAO;
import org.alfresco.repo.domain.qname.QNameDAO;
@@ -39,9 +38,10 @@ import org.alfresco.repo.search.impl.querymodel.QueryEngineResults;
import org.alfresco.repo.search.impl.querymodel.QueryModelException;
import org.alfresco.repo.search.impl.querymodel.QueryModelFactory;
import org.alfresco.repo.search.impl.querymodel.QueryOptions;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
@@ -67,6 +67,13 @@ public class DBQueryEngine implements QueryEngine
private NodeService nodeService;
private TenantService tenantService;
public void setTenantService(TenantService tenantService)
{
this.tenantService = tenantService;
}
public final void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate)
{
this.template = sqlSessionTemplate;
@@ -148,7 +155,12 @@ public class DBQueryEngine implements QueryEngine
key.add("");
Map<Set<String>, ResultSet> answer = new HashMap<Set<String>, ResultSet>();
DBQuery dbQuery = (DBQuery)query;
dbQuery.setStoreId(nodeDAO.getStore(options.getStores().get(0)).getFirst());
// MT
StoreRef storeRef = options.getStores().get(0);
storeRef = storeRef != null ? tenantService.getName(storeRef) : null;
dbQuery.setStoreId(nodeDAO.getStore(storeRef).getFirst());
Pair<Long, QName> sysDeletedType = qnameDAO.getQName(ContentModel.TYPE_DELETED);
if(sysDeletedType == null)
{

View File

@@ -10,6 +10,7 @@ import java.io.File;
import java.io.Serializable;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.GregorianCalendar;
import java.util.HashMap;
@@ -34,9 +35,9 @@ import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.rule.Rule;
import org.alfresco.service.cmr.rule.RuleService;
import org.alfresco.service.cmr.rule.RuleType;
import org.alfresco.service.cmr.version.VersionService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.cmr.version.VersionService;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.ApplicationContextHelper;
import org.apache.chemistry.opencmis.commons.PropertyIds;
@@ -88,7 +89,8 @@ public class CMISTest
private VersionService versionService;
private LockService lockService;
private AlfrescoCmisServiceFactory factory;
private AlfrescoCmisServiceFactory factory10;
private AlfrescoCmisServiceFactory factory11;
private SimpleCallContext context;
private ActionService actionService;
@@ -123,6 +125,33 @@ public class CMISTest
}
}
/**
* Test class to provide the service factory
*
* @author Derek Hulley
* @since 4.0
*/
public static class TestCmisServiceFactory11 extends AbstractServiceFactory
{
private static AlfrescoCmisServiceFactory serviceFactory = (AlfrescoCmisServiceFactory) ctx.getBean("CMISServiceFactory1.1");
@Override
public void init(Map<String, String> parameters)
{
serviceFactory.init(parameters);
}
@Override
public void destroy()
{
}
@Override
public CmisService getService(CallContext context)
{
return serviceFactory.getService(context);
}
}
private static class SimpleCallContext implements CallContext
{
private final Map<String, Object> contextMap = new HashMap<String, Object>();
@@ -224,7 +253,8 @@ public class CMISTest
this.versionService = (VersionService) ctx.getBean("versionService");
this.lockService = (LockService) ctx.getBean("lockService");
this.repositoryHelper = (Repository)ctx.getBean("repositoryHelper");
this.factory = (AlfrescoCmisServiceFactory)ctx.getBean("CMISServiceFactory");
this.factory10 = (AlfrescoCmisServiceFactory)ctx.getBean("CMISServiceFactory");
this.factory11 = (AlfrescoCmisServiceFactory)ctx.getBean("CMISServiceFactory1.1");
this.cmisConnector = (CMISConnector) ctx.getBean("CMISConnector");
this.context = new SimpleCallContext("admin", "admin");
}
@@ -307,7 +337,7 @@ public class CMISTest
try
{
cmisService = factory.getService(context);
cmisService = factory10.getService(context);
T ret = callback.execute(cmisService);
return ret;
}
@@ -320,6 +350,25 @@ public class CMISTest
}
}
private <T extends Object> T withCmisService11(CmisServiceCallback<T> callback)
{
CmisService cmisService = null;
try
{
cmisService = factory11.getService(context);
T ret = callback.execute(cmisService);
return ret;
}
finally
{
if(cmisService != null)
{
cmisService.close();
}
}
}
private static interface CmisServiceCallback<T>
{
T execute(CmisService cmisService);
@@ -524,7 +573,7 @@ public class CMISTest
}
});
CmisService service = factory.getService(context);
CmisService service = factory10.getService(context);
try
{
List<RepositoryInfo> repositories = service.getRepositoryInfos(null);
@@ -546,7 +595,7 @@ public class CMISTest
// AtomPub cancel checkout
try
{
service = factory.getService(context);
service = factory10.getService(context);
// check allowable actions
ObjectData originalDoc = service.getObject(repositoryId, objectData.getId(), null, true, IncludeRelationships.NONE, null, false, true, null);
@@ -569,7 +618,7 @@ public class CMISTest
try
{
service = factory.getService(context);
service = factory10.getService(context);
// cancel checkout on pwc
service.deleteObjectOrCancelCheckOut(repositoryId, objectId.getValue(), Boolean.TRUE, null);
@@ -581,7 +630,7 @@ public class CMISTest
try
{
service = factory.getService(context);
service = factory10.getService(context);
// get original document
ObjectData originalDoc = service.getObject(repositoryId, objectData.getId(), null, true, IncludeRelationships.NONE, null, false, true, null);
@@ -599,7 +648,7 @@ public class CMISTest
try
{
service = factory.getService(context);
service = factory10.getService(context);
// delete original document
service.deleteObject(repositoryId, objectData.getId(), true, null);
@@ -665,7 +714,7 @@ public class CMISTest
FileInfo folderEmptyWithRule = createContent(folderNameEmptyRule, null, true);
testFolderMap.put(folderEmptyWithRule, Boolean.TRUE);
CmisService service = factory.getService(context);
CmisService service = factory10.getService(context);
try
{
@@ -751,7 +800,7 @@ public class CMISTest
}
});
CmisService service = factory.getService(context);
CmisService service = factory10.getService(context);
try
{
List<RepositoryInfo> repositories = service.getRepositoryInfos(null);
@@ -849,7 +898,7 @@ public class CMISTest
AuthenticationUtil.popAuthentication();
}
CmisService cmisService = factory.getService(context);
CmisService cmisService = factory10.getService(context);
try
{
// get repository id
@@ -901,6 +950,101 @@ public class CMISTest
}
}
@SuppressWarnings("rawtypes")
@Test
public void testSecondaryTypes()
{
CmisService cmisService = factory11.getService(context);
try
{
// get repository id
List<RepositoryInfo> repositories = cmisService.getRepositoryInfos(null);
assertTrue(repositories.size() > 0);
RepositoryInfo repo = repositories.get(0);
final String repositoryId = repo.getId();
final String aspectName = "P:cm:indexControl";
System.out.println("START");
final String objectId = withCmisService11(new CmisServiceCallback<String>()
{
@Override
public String execute(CmisService cmisService)
{
final PropertiesImpl properties = new PropertiesImpl();
String objectTypeId = "cmis:document";
properties.addProperty(new PropertyIdImpl(PropertyIds.OBJECT_TYPE_ID, objectTypeId));
String fileName = "textFile" + GUID.generate();
properties.addProperty(new PropertyStringImpl(PropertyIds.NAME, fileName));
final ContentStreamImpl contentStream = new ContentStreamImpl(fileName, MimetypeMap.MIMETYPE_TEXT_PLAIN, "Simple text plain document");
String objectId = cmisService.create(repositoryId, properties, repositoryHelper.getCompanyHome().getId(), contentStream, VersioningState.MAJOR, null, null);
return objectId;
}
});
final Holder<String> objectIdHolder = new Holder<String>(objectId);
withCmisService11(new CmisServiceCallback<Void>()
{
@Override
public Void execute(CmisService cmisService)
{
final PropertiesImpl properties = new PropertiesImpl();
properties.addProperty(new PropertyStringImpl(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, Arrays.asList(aspectName)));
cmisService.updateProperties(repositoryId, objectIdHolder, null, properties, null);
return null;
}
});
final Properties currentProperties = withCmisService11(new CmisServiceCallback<Properties>()
{
@Override
public Properties execute(CmisService cmisService)
{
Properties properties = cmisService.getProperties(repositoryId, objectIdHolder.getValue(), null, null);
return properties;
}
});
System.out.println("objectId = " + objectIdHolder.getValue());
List secondaryTypeIds = currentProperties.getProperties().get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS).getValues();
System.out.println("secondaryTypeIds = " + secondaryTypeIds);
secondaryTypeIds.remove(aspectName);
System.out.println("secondaryTypeIds = " + secondaryTypeIds);
final PropertiesImpl newProperties = new PropertiesImpl();
newProperties.addProperty(new PropertyStringImpl(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, secondaryTypeIds));
withCmisService11(new CmisServiceCallback<Void>()
{
@Override
public Void execute(CmisService cmisService)
{
cmisService.updateProperties(repositoryId, objectIdHolder, null, newProperties, null);
return null;
}
});
Properties currentProperties1 = withCmisService11(new CmisServiceCallback<Properties>()
{
@Override
public Properties execute(CmisService cmisService)
{
Properties properties = cmisService.getProperties(repositoryId, objectIdHolder.getValue(), null, null);
return properties;
}
});
secondaryTypeIds = currentProperties1.getProperties().get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS).getValues();
System.out.println("secondaryTypeIds = " + secondaryTypeIds);
}
finally
{
cmisService.close();
}
}
/**
* Test for MNT-9089
*/
@@ -910,7 +1054,7 @@ public class CMISTest
AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
CmisService cmisService = factory.getService(context);
CmisService cmisService = factory10.getService(context);
try
{
@@ -1052,7 +1196,7 @@ public class CMISTest
AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
CmisService cmisService = factory.getService(context);
CmisService cmisService = factory10.getService(context);
try
{