Merge from SEAMIST3

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@10730 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
David Caruana
2008-09-04 11:08:13 +00:00
parent d894798ee4
commit ae909e7413
45 changed files with 4443 additions and 2171 deletions

View File

@@ -32,6 +32,7 @@ import javax.transaction.UserTransaction;
import junit.framework.TestCase;
import org.alfresco.cmis.property.CMISPropertyService;
import org.alfresco.cmis.search.CMISQueryService;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.service.ServiceRegistry;
@@ -56,6 +57,8 @@ public abstract class BaseCMISTest extends TestCase
{
private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
protected CMISMapping cmisMapping;
protected CMISDictionaryService cmisDictionaryService;
protected DictionaryService dictionaryService;
@@ -77,19 +80,22 @@ public abstract class BaseCMISTest extends TestCase
protected ServiceRegistry serviceRegistry;
protected NamespaceService namespaceService;
protected CMISQueryService cmisQueryService;
public void setUp() throws Exception
{
serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
cmisMapping = (CMISMapping) ctx.getBean("CMISMapping");
cmisDictionaryService = (CMISDictionaryService) ctx.getBean("CMISDictionaryService");
cmisPropertyService = (CMISPropertyService) ctx.getBean("CMISPropertyService");
cmisQueryService = (CMISQueryService) ctx.getBean("CMISQueryService");
dictionaryService = (DictionaryService) ctx.getBean("dictionaryService");
nodeService = (NodeService) ctx.getBean("nodeService");
fileFolderService = (FileFolderService) ctx.getBean("fileFolderService");
namespaceService = (NamespaceService) ctx.getBean("namespaceService");
transactionService = (TransactionService) ctx.getBean("transactionComponent");
authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
@@ -100,14 +106,11 @@ public abstract class BaseCMISTest extends TestCase
String storeName = "CMISTest-" + getName() + "-" + (new Date().getTime());
StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, storeName);
rootNodeRef = nodeService.getRootNode(storeRef);
}
@Override
protected void tearDown() throws Exception
{
if (testTX.getStatus() == Status.STATUS_ACTIVE)
{
testTX.rollback();

View File

@@ -33,7 +33,6 @@ import org.alfresco.service.cmr.dictionary.AspectDefinition;
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.TypeDefinition;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
/**
@@ -43,11 +42,10 @@ import org.alfresco.service.namespace.QName;
*/
public class CMISDictionaryService
{
private CMISMapping cmisMapping;
private DictionaryService dictionaryService;
private NamespaceService namespaceService;
private boolean strict = true;
/**
@@ -61,14 +59,15 @@ public class CMISDictionaryService
}
/**
* Set the namespace service
* Set the mapping service
*
* @param namespaceService
* @param cmisMapping
*/
public void setNamespaceService(NamespaceService namespaceService)
public void setCMISMapping(CMISMapping cmisMapping)
{
this.namespaceService = namespaceService;
this.cmisMapping = cmisMapping;
}
/**
* Is the service strict (CMIS types only)
@@ -116,25 +115,25 @@ public class CMISDictionaryService
for (QName typeQName : alfrescoTypeQNames)
{
if (CMISMapping.isValidCmisDocument(dictionaryService, typeQName))
if (cmisMapping.isValidCmisDocument(typeQName))
{
answer.add(CMISMapping.getCmisTypeId(CMISScope.DOCUMENT, typeQName));
answer.add(cmisMapping.getCmisTypeId(CMISScope.DOCUMENT, typeQName));
}
else if (CMISMapping.isValidCmisFolder(dictionaryService, typeQName))
else if (cmisMapping.isValidCmisFolder(typeQName))
{
answer.add(CMISMapping.getCmisTypeId(CMISScope.FOLDER, typeQName));
answer.add(cmisMapping.getCmisTypeId(CMISScope.FOLDER, typeQName));
}
else if (typeQName.equals(CMISMapping.RELATIONSHIP_QNAME))
{
answer.add(CMISMapping.getCmisTypeId(CMISScope.RELATIONSHIP, typeQName));
answer.add(cmisMapping.getCmisTypeId(CMISScope.RELATIONSHIP, typeQName));
}
}
for (QName associationName : alfrescoAssociationQNames)
{
if (CMISMapping.isValidCmisRelationship(dictionaryService, associationName))
if (cmisMapping.isValidCmisRelationship(associationName))
{
answer.add(CMISMapping.getCmisTypeId(CMISScope.RELATIONSHIP, associationName));
answer.add(cmisMapping.getCmisTypeId(CMISScope.RELATIONSHIP, associationName));
}
}
@@ -154,30 +153,23 @@ public class CMISDictionaryService
{
case RELATIONSHIP:
// Associations
AssociationDefinition associationDefinition = dictionaryService.getAssociation(typeId.getQName());
if (associationDefinition != null)
if (cmisMapping.isValidCmisRelationship(typeId.getQName()))
{
if (CMISMapping.isValidCmisRelationship(dictionaryService, typeId.getQName()))
{
return new CMISTypeDefinition(dictionaryService, namespaceService, typeId);
}
else
{
return null;
}
return new CMISTypeDefinition(cmisMapping, typeId);
}
else
{
return null;
}
case DOCUMENT:
case FOLDER:
TypeDefinition typeDefinition = dictionaryService.getType(typeId.getQName());
if (typeDefinition != null)
{
if (CMISMapping.isValidCmisType(dictionaryService, typeId.getQName()))
if (cmisMapping.isValidCmisType(typeId.getQName()))
{
return new CMISTypeDefinition(dictionaryService, namespaceService, typeId);
return new CMISTypeDefinition(cmisMapping, typeId);
}
else
{
@@ -210,7 +202,7 @@ public class CMISDictionaryService
AssociationDefinition associationDefinition = dictionaryService.getAssociation(typeId.getQName());
if (associationDefinition != null)
{
if (CMISMapping.isValidCmisRelationship(dictionaryService, typeId.getQName()))
if (cmisMapping.isValidCmisRelationship(typeId.getQName()))
{
return getPropertyDefinitions(CMISMapping.RELATIONSHIP_TYPE_ID);
}
@@ -227,13 +219,13 @@ public class CMISDictionaryService
TypeDefinition typeDefinition = dictionaryService.getType(typeId.getQName());
if (typeDefinition != null)
{
if (CMISMapping.isValidCmisDocumentOrFolder(dictionaryService, typeId.getQName()) || typeId.getQName().equals(CMISMapping.RELATIONSHIP_QNAME))
if (cmisMapping.isValidCmisDocumentOrFolder(typeId.getQName()) || typeId.getQName().equals(CMISMapping.RELATIONSHIP_QNAME))
{
for (QName qname : typeDefinition.getProperties().keySet())
{
if (CMISMapping.getPropertyType(dictionaryService, qname) != null)
if (cmisMapping.getPropertyType(qname) != null)
{
CMISPropertyDefinition cmisPropDefinition = new CMISPropertyDefinition(dictionaryService, namespaceService, qname);
CMISPropertyDefinition cmisPropDefinition = new CMISPropertyDefinition(cmisMapping, qname, typeDefinition.getName());
properties.put(cmisPropDefinition.getPropertyName(), cmisPropDefinition);
}
}
@@ -241,19 +233,19 @@ public class CMISDictionaryService
{
for (QName qname : aspect.getProperties().keySet())
{
if (CMISMapping.getPropertyType(dictionaryService, qname) != null)
if (cmisMapping.getPropertyType(qname) != null)
{
CMISPropertyDefinition cmisPropDefinition = new CMISPropertyDefinition(dictionaryService, namespaceService, qname);
CMISPropertyDefinition cmisPropDefinition = new CMISPropertyDefinition(cmisMapping, qname, typeDefinition.getName());
properties.put(cmisPropDefinition.getPropertyName(), cmisPropDefinition);
}
}
}
}
if (CMISMapping.isValidCmisDocumentOrFolder(dictionaryService, typeId.getQName()))
if (cmisMapping.isValidCmisDocumentOrFolder(typeId.getQName()))
{
// Add CMIS properties if required
if (!CMISMapping.isCmisCoreType(typeId.getQName()))
if (!cmisMapping.isCmisCoreType(typeId.getQName()))
{
properties.putAll(getPropertyDefinitions(typeId.getRootTypeId()));
}

View File

@@ -34,9 +34,8 @@ public class CMISDictionaryTest extends BaseCMISTest
System.out.println(name);
}
assertEquals(3, cmisDictionaryService.getAllObjectTypeIds().size());
}
public void testBasicTypeDefinitions()
{
cmisDictionaryService.setStrict(false);
@@ -44,7 +43,21 @@ public class CMISDictionaryTest extends BaseCMISTest
{
System.out.println(cmisDictionaryService.getType(name));
}
}
public void testTypeIds()
{
cmisDictionaryService.setStrict(false);
for (CMISTypeId name : cmisDictionaryService.getAllObjectTypeIds())
{
String typeId = name.getTypeId();
CMISTypeId lookup = cmisMapping.getCmisTypeId(typeId);
assertEquals(name, lookup);
System.out.println(name + " => " + lookup);
CMISTypeDefinition type = cmisDictionaryService.getType(lookup);
assertNotNull(type);
assertEquals(lookup, type.getObjectTypeId());
}
}
public void testBasicProperties()
@@ -57,7 +70,6 @@ public class CMISDictionaryTest extends BaseCMISTest
System.out.println(name +" -> "+ propertyName);
}
}
}
public void testBasicPropertyDefinitions()
@@ -71,7 +83,6 @@ public class CMISDictionaryTest extends BaseCMISTest
}
}
cmisDictionaryService.setStrict(false);
for (CMISTypeId name : cmisDictionaryService.getAllObjectTypeIds())
{
@@ -80,6 +91,5 @@ public class CMISDictionaryTest extends BaseCMISTest
System.out.println(proDef);
}
}
}
}

View File

@@ -27,6 +27,7 @@ package org.alfresco.cmis.dictionary;
import java.util.Collection;
import java.util.HashMap;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
@@ -121,6 +122,10 @@ public class CMISMapping
public static String PROP_IS_MAJOR_VERSION = "IS_MAJOR_VERSION";
public static String PROP_IS_LATEST_MAJOR_VERSION = "IS_LATEST_MAJOR_VERSION";
public static String PROP_VERSION_LABEL = "VERSION_LABEL";
public static String PROP_VERSION_SERIES_ID = "VERSION_SERIES_ID";
public static String PROP_VERSION_SERIES_IS_CHECKED_OUT = "VERSION_SERIES_IS_CHECKED_OUT";
@@ -195,45 +200,118 @@ public class CMISMapping
alfrescoPropertyTypesToCimsPropertyTypes.put(DataTypeDefinition.TEXT, CMISPropertyType.STRING);
}
private DictionaryService dictionaryService;
private NamespaceService namespaceService;
/**
* Set the dictionary Service
*
* @param dictionaryService
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
/**
* Gets the dictionary service
*
* @return dictionaryService
*/
/*package*/ DictionaryService getDictionaryService()
{
return this.dictionaryService;
}
/**
* Set the namespace service
*
* @param namespaceService
*/
public void setNamespaceService(NamespaceService namespaceService)
{
this.namespaceService = namespaceService;
}
/**
* Gets the namespace service
*
* @return namespaceService
*/
/*package*/ NamespaceService getNamespaceService()
{
return this.namespaceService;
}
/**
* Id this a CMIS core type defined in the Alfresco CMIS model
*
* @param typeQName
* @return
*/
public static boolean isCmisCoreType(QName typeQName)
public boolean isCmisCoreType(QName typeQName)
{
return qNameToCmisTypeId.get(typeQName) != null;
}
/**
* Get the CMIS Type Id given the Alfresco QName for the type in any Alfresco model
* Gets the CMIS Type Id given the serialized type Id
*
* @param typeId type id in the form of <ROOT_TYPE_ID>/<PREFIX>_<LOCALNAME>
* @return
*/
public CMISTypeId getCmisTypeId(String typeId)
{
// Is it a CMIS root object type id?
if (typeId.equals(DOCUMENT_TYPE_ID.getTypeId()))
{
return DOCUMENT_TYPE_ID;
}
else if (typeId.equals(FOLDER_TYPE_ID.getTypeId()))
{
return FOLDER_TYPE_ID;
}
else if (typeId.equals(RELATIONSHIP_TYPE_ID.getTypeId()))
{
return RELATIONSHIP_TYPE_ID;
}
// TODO: Policy root object type
// Is it an Alfresco type id?
if (typeId.length() < 4 || typeId.charAt(1) != '/')
{
throw new AlfrescoRuntimeException("Malformed type id '" + typeId + "'");
}
// Alfresco type id
CMISScope scope = CMISScope.toScope(typeId.charAt(0));
if (scope == null)
{
throw new AlfrescoRuntimeException("Malformed type id '" + typeId + "'; discriminator " + typeId.charAt(0) + " unknown");
}
QName typeQName = QName.resolveToQName(namespaceService, typeId.substring(2).replace('_', ':'));
// Construct CMIS Type Id
return new CMISTypeId(scope, typeQName, typeId);
}
/**
* Gets the CMIS Type Id given the Alfresco QName for the type in any Alfresco model
*
* @param typeQName
* @return
*/
public static CMISTypeId getCmisTypeId(CMISScope scope, QName typeQName)
public CMISTypeId getCmisTypeId(CMISScope scope, QName typeQName)
{
CMISTypeId typeId = qNameToCmisTypeId.get(typeQName);
if (typeId == null)
{
StringBuilder builder = new StringBuilder(128);
switch (scope)
{
case DOCUMENT:
builder.append("D");
break;
case FOLDER:
builder.append("F");
break;
case RELATIONSHIP:
builder.append("R");
break;
default:
builder.append("U");
break;
}
builder.append(typeQName.toString());
builder.append(scope.discriminator());
builder.append("/");
builder.append(buildPrefixEncodedString(typeQName, false));
return new CMISTypeId(scope, typeQName, builder.toString());
}
else
@@ -249,12 +327,12 @@ public class CMISMapping
* @param typeQName
* @return
*/
public static String getQueryName(NamespaceService namespaceService, QName typeQName)
public String getQueryName(QName typeQName)
{
return buildPrefixEncodedString(namespaceService, typeQName);
return buildPrefixEncodedString(typeQName, true);
}
private static String buildPrefixEncodedString(NamespaceService namespaceService, QName qname)
private String buildPrefixEncodedString(QName qname, boolean upperCase)
{
StringBuilder builder = new StringBuilder(128);
@@ -267,11 +345,11 @@ public class CMISMapping
}
String resolvedPrefix = prefixes.iterator().next();
builder.append(resolvedPrefix.toUpperCase());
builder.append(upperCase ? resolvedPrefix.toUpperCase() : resolvedPrefix);
builder.append("_");
}
builder.append(qname.getLocalName().toUpperCase());
builder.append(upperCase ? qname.getLocalName().toUpperCase() : qname.getLocalName());
return builder.toString();
}
@@ -283,9 +361,9 @@ public class CMISMapping
* @param typeQName
* @return
*/
public static boolean isValidCmisType(DictionaryService dictionaryService, QName typeQName)
public boolean isValidCmisType(QName typeQName)
{
return isValidCmisFolder(dictionaryService, typeQName) || isValidCmisDocument(dictionaryService, typeQName) || isValidCmisRelationship(dictionaryService, typeQName);
return isValidCmisFolder(typeQName) || isValidCmisDocument(typeQName) || isValidCmisRelationship(typeQName);
}
/**
@@ -295,9 +373,9 @@ public class CMISMapping
* @param typeQName
* @return
*/
public static boolean isValidCmisDocumentOrFolder(DictionaryService dictionaryService, QName typeQName)
public boolean isValidCmisDocumentOrFolder(QName typeQName)
{
return isValidCmisFolder(dictionaryService, typeQName) || isValidCmisDocument(dictionaryService, typeQName);
return isValidCmisFolder(typeQName) || isValidCmisDocument(typeQName);
}
/**
@@ -307,7 +385,7 @@ public class CMISMapping
* @param typeQName
* @return
*/
public static boolean isValidCmisFolder(DictionaryService dictionaryService, QName typeQName)
public boolean isValidCmisFolder(QName typeQName)
{
if (typeQName == null)
{
@@ -340,7 +418,7 @@ public class CMISMapping
* @param typeQName
* @return
*/
public static boolean isValidCmisDocument(DictionaryService dictionaryService, QName typeQName)
public boolean isValidCmisDocument(QName typeQName)
{
if (typeQName == null)
{
@@ -374,7 +452,7 @@ public class CMISMapping
* @param associationQName
* @return
*/
public static boolean isValidCmisRelationship(DictionaryService dictionaryService, QName associationQName)
public boolean isValidCmisRelationship(QName associationQName)
{
if (associationQName == null)
{
@@ -393,11 +471,11 @@ public class CMISMapping
{
return false;
}
if (!isValidCmisDocumentOrFolder(dictionaryService, getCmisType(associationDefinition.getSourceClass().getName())))
if (!isValidCmisDocumentOrFolder(getCmisType(associationDefinition.getSourceClass().getName())))
{
return false;
}
if (!isValidCmisDocumentOrFolder(dictionaryService, getCmisType(associationDefinition.getTargetClass().getName())))
if (!isValidCmisDocumentOrFolder(getCmisType(associationDefinition.getTargetClass().getName())))
{
return false;
}
@@ -411,7 +489,7 @@ public class CMISMapping
* @param typeQName
* @return
*/
public static QName getCmisType(QName typeQName)
public QName getCmisType(QName typeQName)
{
QName mapped = alfrescoToCmisTypes.get(typeQName);
if (mapped != null)
@@ -428,9 +506,9 @@ public class CMISMapping
* @param propertyQName
* @return
*/
public static String getCmisPropertyName(NamespaceService namespaceService, QName propertyQName)
public String getCmisPropertyName(QName propertyQName)
{
return buildPrefixEncodedString(namespaceService, propertyQName);
return buildPrefixEncodedString(propertyQName, true);
}
/**
@@ -440,14 +518,21 @@ public class CMISMapping
* @param propertyQName
* @return
*/
public static CMISPropertyType getPropertyType(DictionaryService dictionaryService, QName propertyQName)
public CMISPropertyType getPropertyType(QName propertyQName)
{
PropertyDefinition propertyDefinition = dictionaryService.getProperty(propertyQName);
DataTypeDefinition dataTypeDefinition = propertyDefinition.getDataType();
QName dQName = dataTypeDefinition.getName();
if (propertyQName.getNamespaceURI().equals(CMIS_MODEL_URI) && dQName.equals(DataTypeDefinition.QNAME))
if (propertyQName.getNamespaceURI().equals(CMIS_MODEL_URI))
{
return CMISPropertyType.TYPE_ID;
if(dQName.equals(DataTypeDefinition.QNAME) || dQName.equals(DataTypeDefinition.NODE_REF))
{
return CMISPropertyType.ID;
}
else
{
alfrescoPropertyTypesToCimsPropertyTypes.get(dQName);
}
}
return alfrescoPropertyTypesToCimsPropertyTypes.get(dQName);
@@ -461,7 +546,7 @@ public class CMISMapping
* @param cmisPropertyName
* @return
*/
public static QName getPropertyQName(DictionaryService dictionaryService, NamespaceService namespaceService, String cmisPropertyName)
public QName getPropertyQName(String cmisPropertyName)
{
// Try the cmis model first - it it matches we are done
QName cmisPropertyQName = QName.createQName(CMIS_MODEL_URI, cmisPropertyName);
@@ -515,7 +600,7 @@ public class CMISMapping
* @param tableName
* @return
*/
public static QName getAlfrescoClassQNameFromCmisTableName(DictionaryService dictionaryService, NamespaceService namespaceService, String tableName)
public QName getAlfrescoClassQNameFromCmisTableName(String tableName)
{
if (tableName.equals(DOCUMENT_TYPE_ID.getTypeId()))
{
@@ -577,4 +662,22 @@ public class CMISMapping
return null;
}
/**
* @param namespaceService
* @param propertyQName
* @return
*/
public String getCmisPropertyId(QName propertyQName)
{
if (propertyQName.getNamespaceURI().equals(CMIS_MODEL_URI))
{
return propertyQName.getLocalName();
}
else
{
return propertyQName.toString();
}
}
}

View File

@@ -39,9 +39,7 @@ import org.alfresco.repo.search.impl.lucene.analysis.PathAnalyser;
import org.alfresco.repo.search.impl.lucene.analysis.VerbatimAnalyser;
import org.alfresco.service.cmr.dictionary.Constraint;
import org.alfresco.service.cmr.dictionary.ConstraintDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
/**
@@ -53,9 +51,13 @@ public class CMISPropertyDefinition
{
private String propertyName;
private String propertyId;
private String displayName;
private String description;
private boolean isInherited;
private CMISPropertyType propertyType;
@@ -81,16 +83,18 @@ public class CMISPropertyDefinition
private boolean orderable;
public CMISPropertyDefinition(DictionaryService dictionaryService, NamespaceService namespaceService, QName propertyQName)
public CMISPropertyDefinition(CMISMapping cmisMapping, QName propertyQName, QName typeQName)
{
PropertyDefinition propDef = dictionaryService.getProperty(propertyQName);
PropertyDefinition propDef = cmisMapping.getDictionaryService().getProperty(propertyQName);
if (propDef.getContainerClass().getName().equals(CMISMapping.RELATIONSHIP_QNAME))
{
// Properties of associations - all the same
propertyName = CMISMapping.getCmisPropertyName(namespaceService, propertyQName);
propertyName = cmisMapping.getCmisPropertyName(propertyQName);
propertyId = cmisMapping.getCmisPropertyId(propertyQName);
displayName = propDef.getTitle();
description = propDef.getDescription();
propertyType = CMISMapping.getPropertyType(dictionaryService, propertyQName);
isInherited = false;
propertyType = cmisMapping.getPropertyType(propertyQName);
cardinality = propDef.isMultiValued() ? CMISCardinality.MULTI_VALUED : CMISCardinality.SINGLE_VALUED;
required = propDef.isMandatory();
defaultValue = propDef.getDefaultValue();
@@ -101,10 +105,19 @@ public class CMISPropertyDefinition
else
{
propertyName = CMISMapping.getCmisPropertyName(namespaceService, propertyQName);
propertyName = cmisMapping.getCmisPropertyName(propertyQName);
propertyId = cmisMapping.getCmisPropertyId(propertyQName);
displayName = propDef.getTitle();
description = propDef.getDescription();
propertyType = CMISMapping.getPropertyType(dictionaryService, propertyQName);
if(propDef.getContainerClass().isAspect())
{
isInherited = false;
}
else
{
isInherited = !propDef.getContainerClass().equals(typeQName);
}
propertyType = cmisMapping.getPropertyType(propertyQName);
cardinality = propDef.isMultiValued() ? CMISCardinality.MULTI_VALUED : CMISCardinality.SINGLE_VALUED;
for (ConstraintDefinition constraintDef : propDef.getConstraints())
{
@@ -175,6 +188,16 @@ public class CMISPropertyDefinition
{
return propertyName;
}
/**
* Get the property id
*
* @return
*/
public String getPropertyId()
{
return propertyId;
}
/**
* Get the display name
@@ -195,6 +218,16 @@ public class CMISPropertyDefinition
{
return description;
}
/**
* Is the property definition inherited?
*
* @return
*/
public boolean isInherited()
{
return isInherited;
}
/**
* Get the property type
@@ -321,8 +354,10 @@ public class CMISPropertyDefinition
StringBuilder builder = new StringBuilder();
builder.append("CMISPropertyDefinition[");
builder.append("PropertyName=").append(getPropertyName()).append(", ");
builder.append("PropertyId=").append(getPropertyId()).append(", ");
builder.append("DisplayName=").append(getDisplayName()).append(", ");
builder.append("Description=").append(getDescription()).append(", ");
builder.append("IsInherited=").append(isInherited()).append(", ");
builder.append("PropertyType=").append(getPropertyType()).append(", ");
builder.append("Cardinality=").append(getCardinality()).append(", ");
builder.append("MaximumLength=").append(getMaximumLength()).append(", ");

View File

@@ -66,9 +66,5 @@ public enum CMISPropertyType
/**
* ID
*/
ID,
/**
* Type Id
*/
TYPE_ID;
ID;
}

View File

@@ -24,6 +24,9 @@
*/
package org.alfresco.cmis.dictionary;
import java.util.HashMap;
import java.util.Map;
/**
* The scope for a CMIS name
@@ -37,5 +40,37 @@ package org.alfresco.cmis.dictionary;
*/
public enum CMISScope
{
OBJECT, RELATIONSHIP, DOCUMENT, FOLDER, POLICY, UNKNOWN;
OBJECT ('O'),
RELATIONSHIP ('R'),
DOCUMENT ('D'),
FOLDER ('F'),
POLICY ('P'),
UNKNOWN ('U');
private static Map<Character, CMISScope> discriminatorMap = new HashMap<Character, CMISScope>(10);
static
{
for (CMISScope scope : CMISScope.values())
{
discriminatorMap.put(scope.discriminator, scope);
}
}
private char discriminator;
CMISScope(char discriminator)
{
this.discriminator = discriminator;
}
public char discriminator()
{
return discriminator;
}
public static CMISScope toScope(char discrimator)
{
return discriminatorMap.get(discrimator);
}
}

View File

@@ -32,9 +32,7 @@ import java.util.List;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.dictionary.AspectDefinition;
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.TypeDefinition;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
/**
@@ -56,11 +54,17 @@ public class CMISTypeDefinition
private String description;
private boolean creatable;
private boolean fileable;
private boolean queryable;
private boolean controllable;
private boolean versionable;
private String constraints = "";
private ContentStreamAllowed contentStreamAllowed;
private boolean isAssociation;
@@ -68,72 +72,80 @@ public class CMISTypeDefinition
private ArrayList<CMISTypeId> allowedTargetTypes = new ArrayList<CMISTypeId>(1);
public CMISTypeDefinition(DictionaryService dictionaryService, NamespaceService namespaceService, CMISTypeId typeId)
public CMISTypeDefinition(CMISMapping cmisMapping, CMISTypeId typeId)
{
switch (typeId.getScope())
{
case RELATIONSHIP:
AssociationDefinition associationDefinition = dictionaryService.getAssociation(typeId.getQName());
AssociationDefinition associationDefinition = cmisMapping.getDictionaryService().getAssociation(typeId.getQName());
if (associationDefinition != null)
{
objectTypeId = typeId;
objectTypeQueryName = CMISMapping.getQueryName(namespaceService, typeId.getQName());
objectTypeQueryName = cmisMapping.getQueryName(typeId.getQName());
displayName = associationDefinition.getTitle();
parentTypeId = CMISMapping.RELATIONSHIP_TYPE_ID;
rootTypeQueryName = CMISMapping.getQueryName(namespaceService, CMISMapping.RELATIONSHIP_QNAME);
rootTypeQueryName = cmisMapping.getQueryName(CMISMapping.RELATIONSHIP_QNAME);
description = associationDefinition.getDescription();
creatable = false;
fileable = false;
queryable = false;
controllable = false;
versionable = false;
contentStreamAllowed = ContentStreamAllowed.NOT_ALLOWED;
isAssociation = true;
QName sourceType = CMISMapping.getCmisType(associationDefinition.getSourceClass().getName());
if (CMISMapping.isValidCmisDocument(dictionaryService, sourceType))
QName sourceType = cmisMapping.getCmisType(associationDefinition.getSourceClass().getName());
if (cmisMapping.isValidCmisDocument(sourceType))
{
allowedSourceTypes.add(CMISMapping.getCmisTypeId(CMISScope.DOCUMENT, sourceType));
allowedSourceTypes.add(cmisMapping.getCmisTypeId(CMISScope.DOCUMENT, sourceType));
}
else if (CMISMapping.isValidCmisFolder(dictionaryService, sourceType))
else if (cmisMapping.isValidCmisFolder(sourceType))
{
allowedSourceTypes.add(CMISMapping.getCmisTypeId(CMISScope.FOLDER, sourceType));
allowedSourceTypes.add(cmisMapping.getCmisTypeId(CMISScope.FOLDER, sourceType));
}
QName targetType = CMISMapping.getCmisType(associationDefinition.getTargetClass().getName());
if (CMISMapping.isValidCmisDocument(dictionaryService, targetType))
QName targetType = cmisMapping.getCmisType(associationDefinition.getTargetClass().getName());
if (cmisMapping.isValidCmisDocument(targetType))
{
allowedTargetTypes.add(CMISMapping.getCmisTypeId(CMISScope.DOCUMENT, targetType));
allowedTargetTypes.add(cmisMapping.getCmisTypeId(CMISScope.DOCUMENT, targetType));
}
else if (CMISMapping.isValidCmisFolder(dictionaryService, targetType))
else if (cmisMapping.isValidCmisFolder(targetType))
{
allowedTargetTypes.add(CMISMapping.getCmisTypeId(CMISScope.FOLDER, targetType));
allowedTargetTypes.add(cmisMapping.getCmisTypeId(CMISScope.FOLDER, targetType));
}
}
else
{
// TODO: Add CMIS Association mapping??
TypeDefinition typeDefinition = dictionaryService.getType(typeId.getQName());
TypeDefinition typeDefinition = cmisMapping.getDictionaryService().getType(typeId.getQName());
objectTypeId = typeId;
objectTypeQueryName = CMISMapping.getQueryName(namespaceService, typeId.getQName());
objectTypeQueryName = cmisMapping.getQueryName(typeId.getQName());
displayName = typeDefinition.getTitle();
parentTypeId = CMISMapping.RELATIONSHIP_TYPE_ID;
rootTypeQueryName = CMISMapping.getQueryName(namespaceService, CMISMapping.RELATIONSHIP_QNAME);
rootTypeQueryName = cmisMapping.getQueryName(CMISMapping.RELATIONSHIP_QNAME);
description = typeDefinition.getDescription();
creatable = false;
fileable = false;
queryable = false;
controllable = false;
versionable = false;
contentStreamAllowed = ContentStreamAllowed.NOT_ALLOWED;
isAssociation = true;
}
break;
case DOCUMENT:
case FOLDER:
TypeDefinition typeDefinition = dictionaryService.getType(typeId.getQName());
TypeDefinition typeDefinition = cmisMapping.getDictionaryService().getType(typeId.getQName());
if (typeDefinition != null)
{
objectTypeId = typeId;
objectTypeQueryName = CMISMapping.getQueryName(namespaceService, typeId.getQName());
objectTypeQueryName = cmisMapping.getQueryName(typeId.getQName());
displayName = typeDefinition.getTitle();
QName parentTypeQName = CMISMapping.getCmisType(typeDefinition.getParentName());
QName parentTypeQName = cmisMapping.getCmisType(typeDefinition.getParentName());
if (parentTypeQName == null)
{
// Core and unknown types
@@ -141,32 +153,51 @@ public class CMISTypeDefinition
}
else
{
if (CMISMapping.isValidCmisDocument(dictionaryService, parentTypeQName))
if (cmisMapping.isValidCmisDocument(parentTypeQName))
{
parentTypeId = CMISMapping.getCmisTypeId(CMISScope.DOCUMENT, parentTypeQName);
parentTypeId = cmisMapping.getCmisTypeId(CMISScope.DOCUMENT, parentTypeQName);
}
else if (CMISMapping.isValidCmisFolder(dictionaryService, parentTypeQName))
else if (cmisMapping.isValidCmisFolder(parentTypeQName))
{
parentTypeId = CMISMapping.getCmisTypeId(CMISScope.FOLDER, parentTypeQName);
parentTypeId = cmisMapping.getCmisTypeId(CMISScope.FOLDER, parentTypeQName);
}
}
rootTypeQueryName = CMISMapping.getQueryName(namespaceService, typeId.getRootTypeId().getQName());
rootTypeQueryName = cmisMapping.getQueryName(typeId.getRootTypeId().getQName());
description = typeDefinition.getDescription();
creatable = true;
fileable = true;
queryable = true;
controllable = false;
versionable = false;
List<AspectDefinition> defaultAspects = typeDefinition.getDefaultAspects();
for (AspectDefinition aspectDefinition : defaultAspects)
if (typeId.getScope() == CMISScope.DOCUMENT)
{
if (aspectDefinition.getName().equals(ContentModel.ASPECT_VERSIONABLE))
List<AspectDefinition> defaultAspects = typeDefinition.getDefaultAspects();
for (AspectDefinition aspectDefinition : defaultAspects)
{
versionable = true;
break;
if (aspectDefinition.getName().equals(ContentModel.ASPECT_VERSIONABLE))
{
versionable = true;
break;
}
}
}
if (typeId.getScope() == CMISScope.DOCUMENT)
{
contentStreamAllowed = ContentStreamAllowed.ALLOWED;
}
else
{
contentStreamAllowed = ContentStreamAllowed.NOT_ALLOWED;
}
}
break;
@@ -175,7 +206,6 @@ public class CMISTypeDefinition
break;
}
}
/**
@@ -241,6 +271,26 @@ public class CMISTypeDefinition
return description;
}
/**
* Can objects of this type be created?
*
* @return
*/
public boolean isCreatable()
{
return creatable;
}
/**
* Are objects of this type fileable?
*
* @return
*/
public boolean isFileable()
{
return fileable;
}
/**
* Is this type queryable? If not, the type may not appear in the FROM clause of a query. This property of the type
* is not inherited in the type hierarchy. It is set on each type.
@@ -252,6 +302,16 @@ public class CMISTypeDefinition
return queryable;
}
/**
* Are objects of this type controllable.
*
* @return
*/
public boolean isControllable()
{
return controllable;
}
/**
* Is this type versionable? If true this implies all instances of the type are versionable.
*
@@ -263,13 +323,13 @@ public class CMISTypeDefinition
}
/**
* Get the constraints for the type. These are not currently supported.
* Is a content stream allowed for this type? It may be disallowed, optional or mandatory.
*
* @return
*/
public String getConstraints()
public ContentStreamAllowed getContentStreamAllowed()
{
return constraints;
return contentStreamAllowed;
}
/**
@@ -312,9 +372,12 @@ public class CMISTypeDefinition
builder.append("ParentTypeId=").append(getParentTypeId()).append(", ");
builder.append("RootTypeQueryName=").append(getRootTypeQueryName()).append(", ");
builder.append("Description=").append(getDescription()).append(", ");
builder.append("Creatable=").append(isCreatable()).append(", ");
builder.append("Fileable=").append(isFileable()).append(", ");
builder.append("Queryable=").append(isQueryable()).append(", ");
builder.append("Controllable=").append(isControllable()).append(", ");
builder.append("Versionable=").append(isVersionable()).append(", ");
builder.append("Constraints=").append(getConstraints()).append(", ");
builder.append("ContentStreamAllowed=").append(getContentStreamAllowed()).append(", ");
builder.append("IsAssociation=").append(isAssociation()).append(", ");
builder.append("AllowedSourceTypes=").append(getAllowedSourceTypes()).append(", ");
builder.append("AllowedTargetTypes=").append(getAllowedTargetTypes());

View File

@@ -0,0 +1,34 @@
/*
* Copyright (C) 2005-2007 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.cmis.dictionary;
/**
* @author andyh
*
*/
public enum ContentStreamAllowed
{
NOT_ALLOWED, ALLOWED, REQUIRED;
}