Merged DEV/SWIFT to HEAD

26373: WIP: ALF-7339: RSOLR 009: Index track and build from SOLR
          - track content, track dates, basic sorting
   26388: WIP: ALF-7339: RSOLR 009: Index track and build from SOLR
          - basic tracking of d:text and d:mltext (not dual tokenisation and identifier support)
   26527: WIP ALF-7339: RSOLR 009: Index track and build from SOLR
          - track d:content, d:mltext, d:text
          - start of cross locale search and ordering support int the index (not at query time yet)
          - no dual tokenisation support yet - currently adding all fields for tokenized BOTH
          - .sort needs additional tokenisation support to use a different separator (\u0000 used to indicate locale and split stuff - better toe use {en}woof style with \u0000 split
   26822: ALF-8166: RINF 10: treenode.get.js - tweak to use "childFileFolders"
   26825: ALF-8133: RINF 10: ScriptNode - update "childByNamePath" to use optimised NodeService.getChildByName
   26850: ALF-8133: RINF 10: ScriptNode - update "childByNamePath" to use optimised NodeService.getChildByName
          - follow-on to r26825
   26862: ALF-8110: RINF 10: doclist.get.js - update "path" filter to use DB-based queries (by default)
          - milestone check-in for review and comparison (note: sorting will be pushed down as part of paging support in lower layers)
   26872: Updated SOLR dev env
   26915: ALF-8224: part 1: encapsulate cmis dictionary for SOLR usage
   27017: Javadoc: removed uncommented param
   27018: Added 'namePattern' property to NamedObjectRegistry to enforce naming conventions where required
   27019: CannedQuery interface and related infrastructure
           - Provides basic support for query, sort, filter and page
           - CannedQueryFactory allows more complex implementations where required
           - Should be enough of a starter for tasks requiring miscellaneous queries
           - ALF-7167: Canned queries
   27037: WCM QS Needs the Web-Client, so define the dependency to Eclipse
   27041: Move WCM-QS test setup to a common base class
   27044: Start to conver the WCM QS behaviour from JS to Java
   27080: Added comment section for NodeLocator script declarations
   27081: General cleanup: Removed non-javadocs, empty javadocs, unused code, etc
   27104: Fixed ALF-7476: Typo in output from MMT
   27114: ALF-7479: RSOLR 016: Query Handler
          ALF-7480: RSOLR 017: SOLR result set
          ALF-7481: RSOLR 018: Execute query against SOLR
          - First working stack

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28286 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2011-06-08 15:38:14 +00:00
parent 8e6c0d9c00
commit 2f697cebb9
82 changed files with 2732 additions and 7275 deletions

View File

@@ -1,39 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.opencmis;
import org.apache.chemistry.opencmis.commons.enums.Action;
public interface CMISActionEvaluator<T>
{
/**
* Gets the CMIS Allowed Action
*
* @return
*/
public Action getAction();
/**
* Determines if an action is allowed on an object
*
* @param object
* @return
*/
public boolean isAllowed(T object);
}

View File

@@ -42,6 +42,7 @@ import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import org.alfresco.model.ContentModel;
import org.alfresco.opencmis.dictionary.CMISActionEvaluator;
import org.alfresco.opencmis.dictionary.CMISAllowedActionEnum;
import org.alfresco.opencmis.dictionary.CMISDictionaryService;
import org.alfresco.opencmis.dictionary.DocumentTypeDefinitionWrapper;

View File

@@ -1,162 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.opencmis;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
public class CMISUtils
{
@SuppressWarnings("unchecked")
public static <T> T copy(T source)
{
T target = null;
try
{
CopyOutputStream cos = new CopyOutputStream();
ObjectOutputStream out = new ObjectOutputStream(cos);
out.writeObject(source);
out.flush();
out.close();
ObjectInputStream in = new ObjectInputStream(cos.getInputStream());
target = (T) in.readObject();
} catch (Exception e)
{
throw new CmisRuntimeException("Object copy failed!", e);
}
return target;
}
private static class CopyOutputStream extends OutputStream
{
protected byte[] buf = null;
protected int size = 0;
public CopyOutputStream()
{
this(16 * 1024);
}
public CopyOutputStream(int initSize)
{
this.size = 0;
this.buf = new byte[initSize];
}
private void verifyBufferSize(int sz)
{
if (sz > buf.length)
{
byte[] old = buf;
buf = new byte[Math.max(sz, 2 * buf.length)];
System.arraycopy(old, 0, buf, 0, old.length);
old = null;
}
}
public final void write(byte b[])
{
verifyBufferSize(size + b.length);
System.arraycopy(b, 0, buf, size, b.length);
size += b.length;
}
public final void write(byte b[], int off, int len)
{
verifyBufferSize(size + len);
System.arraycopy(b, off, buf, size, len);
size += len;
}
public final void write(int b)
{
verifyBufferSize(size + 1);
buf[size++] = (byte) b;
}
public InputStream getInputStream()
{
return new CopyInputStream(buf, size);
}
}
private static class CopyInputStream extends InputStream
{
protected byte[] buf = null;
protected int count = 0;
protected int pos = 0;
public CopyInputStream(byte[] buf, int count)
{
this.buf = buf;
this.count = count;
}
public final int available()
{
return count - pos;
}
public final int read()
{
return (pos < count) ? (buf[pos++] & 0xff) : -1;
}
public final int read(byte[] b, int off, int len)
{
if (pos >= count)
{
return -1;
}
if ((pos + len) > count)
{
len = (count - pos);
}
System.arraycopy(buf, pos, b, off, len);
pos += len;
return len;
}
public final long skip(long n)
{
if ((pos + n) > count)
{
n = count - pos;
}
if (n < 0)
{
return 0;
}
pos += n;
return n;
}
}
}

View File

@@ -1,658 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.opencmis.dictionary;
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.opencmis.CMISActionEvaluator;
import org.alfresco.opencmis.dictionary.CMISAbstractDictionaryService.DictionaryRegistry;
import org.alfresco.opencmis.mapping.AbstractProperty;
import org.alfresco.opencmis.mapping.CMISMapping;
import org.alfresco.opencmis.mapping.DirectProperty;
import org.alfresco.repo.dictionary.IndexTokenisationMode;
import org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint;
import org.alfresco.repo.dictionary.constraint.NumericRangeConstraint;
import org.alfresco.repo.dictionary.constraint.StringLengthConstraint;
import org.alfresco.repo.search.impl.lucene.analysis.DateAnalyser;
import org.alfresco.repo.search.impl.lucene.analysis.DateTimeAnalyser;
import org.alfresco.repo.search.impl.lucene.analysis.DoubleAnalyser;
import org.alfresco.repo.search.impl.lucene.analysis.FloatAnalyser;
import org.alfresco.repo.search.impl.lucene.analysis.IntegerAnalyser;
import org.alfresco.repo.search.impl.lucene.analysis.LongAnalyser;
import org.alfresco.repo.search.impl.lucene.analysis.PathAnalyser;
import org.alfresco.repo.search.impl.lucene.analysis.VerbatimAnalyser;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.cmr.dictionary.Constraint;
import org.alfresco.service.cmr.dictionary.ConstraintDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.namespace.QName;
import org.apache.chemistry.abdera.ext.utils.ISO8601DateFormat;
import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.chemistry.opencmis.commons.definitions.Choice;
import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
import org.apache.chemistry.opencmis.commons.enums.Action;
import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
import org.apache.chemistry.opencmis.commons.enums.Cardinality;
import org.apache.chemistry.opencmis.commons.enums.PropertyType;
import org.apache.chemistry.opencmis.commons.enums.Updatability;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.AbstractPropertyDefinition;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.AbstractTypeDefinition;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.ChoiceImpl;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyBooleanDefinitionImpl;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDateTimeDefinitionImpl;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDecimalDefinitionImpl;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyHtmlDefinitionImpl;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIdDefinitionImpl;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerDefinitionImpl;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringDefinitionImpl;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyUriDefinitionImpl;
/**
* Base class for type definition wrappers.
*
* @author florian.mueller
*/
public abstract class AbstractTypeDefinitionWrapper implements TypeDefinitionWrapper, Serializable
{
private static final long serialVersionUID = 1L;
protected AbstractTypeDefinition typeDef;
protected AbstractTypeDefinition typeDefInclProperties;
protected TypeDefinitionWrapper parent;
protected List<TypeDefinitionWrapper> children;
protected QName alfrescoName = null;
protected QName alfrescoClass = null;
protected Map<Action, CMISActionEvaluator<? extends Object>> actionEvaluators;
protected Map<String, PropertyDefintionWrapper> propertiesById = new HashMap<String, PropertyDefintionWrapper>();
protected Map<String, PropertyDefintionWrapper> propertiesByQueryName = new HashMap<String, PropertyDefintionWrapper>();
protected Map<QName, PropertyDefintionWrapper> propertiesByQName = new HashMap<QName, PropertyDefintionWrapper>();
// interface
public TypeDefinition getTypeDefinition(boolean includePropertyDefinitions)
{
if (includePropertyDefinitions)
{
return typeDefInclProperties;
} else
{
return typeDef;
}
}
protected void setTypeDefinition(AbstractTypeDefinition typeDef, AbstractTypeDefinition typeDefInclProperties)
{
this.typeDef = typeDef;
this.typeDefInclProperties = typeDefInclProperties;
}
@Override
public String getTypeId()
{
return typeDef.getId();
}
@Override
public BaseTypeId getBaseTypeId()
{
return typeDef.getBaseTypeId();
}
@Override
public boolean isBaseType()
{
return typeDef.getId().equals(typeDef.getBaseTypeId().value());
}
@Override
public QName getAlfrescoName()
{
return alfrescoName;
}
@Override
public QName getAlfrescoClass()
{
return alfrescoClass;
}
@Override
public TypeDefinitionWrapper getParent()
{
return parent;
}
@Override
public List<TypeDefinitionWrapper> getChildren()
{
return children;
}
@Override
public Map<Action, CMISActionEvaluator<? extends Object>> getActionEvaluators()
{
return actionEvaluators;
}
@Override
public Collection<PropertyDefintionWrapper> getProperties()
{
return propertiesById.values();
}
@Override
public PropertyDefintionWrapper getPropertyById(String propertyId)
{
return propertiesById.get(propertyId);
}
@Override
public PropertyDefintionWrapper getPropertyByQueryName(String queryName)
{
return propertiesByQueryName.get(queryName);
}
@Override
public PropertyDefintionWrapper getPropertyByQName(QName name)
{
return propertiesByQName.get(name);
}
// create
public abstract void connectParentAndSubTypes(CMISMapping cmisMapping, DictionaryRegistry registry,
DictionaryService dictionaryService);
public abstract void resolveInheritance(CMISMapping cmisMapping, ServiceRegistry serviceRegistry,
DictionaryRegistry registry, DictionaryService dictionaryService);
public void assertComplete()
{
if (typeDef == null)
throw new IllegalStateException("typeDef is not set");
if (typeDefInclProperties == null)
throw new IllegalStateException("typeDefInclProperties is not set");
if (alfrescoName == null)
throw new IllegalStateException("alfrescoName is not set");
if (alfrescoClass == null)
throw new IllegalStateException("alfrescoClass is not set");
if (propertiesById == null)
throw new IllegalStateException("propertiesById is not set");
if (propertiesByQueryName == null)
throw new IllegalStateException("propertiesByQueryName is not set");
if (propertiesByQName == null)
throw new IllegalStateException("propertiesByQName is not set");
if (propertiesById.size() == 0)
throw new IllegalStateException("property map empty");
if (propertiesById.size() != propertiesByQueryName.size())
throw new IllegalStateException("property map mismatch");
if (propertiesById.size() != propertiesByQName.size())
throw new IllegalStateException("property map mismatch");
}
/**
* Adds all property definitions owned by that type.
*/
protected void createOwningPropertyDefinitions(CMISMapping cmisMapping, ServiceRegistry serviceRegistry,
ClassDefinition cmisClassDef)
{
PropertyDefinition<?> propertyDefintion;
for (org.alfresco.service.cmr.dictionary.PropertyDefinition alfrescoPropDef : cmisClassDef.getProperties()
.values())
{
if (!isBaseType())
{
if (!alfrescoPropDef.getContainerClass().equals(cmisClassDef))
{
continue;
}
}
// compile property id
String propertyId = cmisMapping.buildPrefixEncodedString(alfrescoPropDef.getName());
// create property definition
propertyDefintion = createPropertyDefinition(cmisMapping, propertyId, alfrescoPropDef.getName(),
alfrescoPropDef, false);
// if the datatype is not supported, the property defintion will be
// null
if (propertyDefintion != null)
{
AbstractProperty propertyAccessor = cmisMapping.getPropertyAccessor(propertyId);
if (propertyAccessor == null)
{
propertyAccessor = new DirectProperty(serviceRegistry, propertyId, alfrescoPropDef.getName());
}
registerProperty(new BasePropertyDefintionWrapper(propertyDefintion, alfrescoPropDef.getName(), this,
propertyAccessor, propertyAccessor));
}
}
}
/**
* Registers a property definition with this type
*/
protected void registerProperty(PropertyDefintionWrapper propDefWrapper)
{
if (propDefWrapper == null)
{
return;
}
if (propertiesById.containsKey(propDefWrapper.getPropertyId()))
{
throw new AlfrescoRuntimeException("Property defintion " + propDefWrapper.getPropertyId()
+ " already exists on type " + typeDef.getId());
}
propertiesById.put(propDefWrapper.getPropertyId(), propDefWrapper);
propertiesByQueryName.put(propDefWrapper.getPropertyDefinition().getQueryName(), propDefWrapper);
propertiesByQName.put(propDefWrapper.getAlfrescoName(), propDefWrapper);
typeDefInclProperties.addPropertyDefinition(propDefWrapper.getPropertyDefinition());
}
/**
* Creates a property definition object.
*/
protected PropertyDefinition<?> createPropertyDefinition(CMISMapping cmisMapping, String id,
QName alfrescoPropName, org.alfresco.service.cmr.dictionary.PropertyDefinition propDef, boolean inherited)
{
PropertyType datatype = cmisMapping.getDataType(propDef.getDataType());
if (datatype == null)
{
return null;
}
AbstractPropertyDefinition<?> result = null;
switch (datatype)
{
case BOOLEAN:
result = new PropertyBooleanDefinitionImpl();
break;
case DATETIME:
result = new PropertyDateTimeDefinitionImpl();
break;
case DECIMAL:
result = new PropertyDecimalDefinitionImpl();
break;
case HTML:
result = new PropertyHtmlDefinitionImpl();
break;
case ID:
result = new PropertyIdDefinitionImpl();
break;
case INTEGER:
result = new PropertyIntegerDefinitionImpl();
break;
case STRING:
result = new PropertyStringDefinitionImpl();
break;
case URI:
result = new PropertyUriDefinitionImpl();
break;
default:
throw new RuntimeException("Unknown datatype! Spec change?");
}
if (id.equals(PropertyIds.OBJECT_TYPE_ID) || id.equals(PropertyIds.SOURCE_ID)
|| id.equals(PropertyIds.TARGET_ID))
{
// the CMIS spec requirement
result.setUpdatability(Updatability.ONCREATE);
} else
{
result.setUpdatability(propDef.isProtected() ? Updatability.READONLY : Updatability.READWRITE);
}
result.setId(id);
result.setLocalName(alfrescoPropName.getLocalName());
result.setLocalNamespace(alfrescoPropName.getNamespaceURI());
result.setDisplayName(propDef.getTitle() != null ? propDef.getTitle() : id);
result.setDescription(propDef.getDescription() != null ? propDef.getDescription() : result.getDisplayName());
result.setPropertyType(datatype);
result.setCardinality(propDef.isMultiValued() ? Cardinality.MULTI : Cardinality.SINGLE);
result.setIsInherited(inherited);
result.setIsRequired(propDef.isMandatory());
addDefaultValue(propDef.getDefaultValue(), result);
// query and order
result.setQueryName(cmisMapping.buildPrefixEncodedString(alfrescoPropName));
result.setIsQueryable(propDef.isIndexed());
result.setIsOrderable(false);
if (result.isQueryable())
{
if (result.getCardinality() == Cardinality.SINGLE)
{
IndexTokenisationMode indexTokenisationMode = IndexTokenisationMode.TRUE;
if (propDef.getIndexTokenisationMode() != null)
{
indexTokenisationMode = propDef.getIndexTokenisationMode();
}
switch (indexTokenisationMode)
{
case BOTH:
case FALSE:
result.setIsOrderable(true);
break;
case TRUE:
default:
String analyserClassName = propDef.getDataType().getAnalyserClassName();
if (propDef.getDataType().getName().equals(DataTypeDefinition.BOOLEAN))
{
result.setIsOrderable(true);
} else if (analyserClassName.equals(DateTimeAnalyser.class.getCanonicalName())
|| analyserClassName.equals(DateAnalyser.class.getCanonicalName())
|| analyserClassName.equals(DoubleAnalyser.class.getCanonicalName())
|| analyserClassName.equals(FloatAnalyser.class.getCanonicalName())
|| analyserClassName.equals(IntegerAnalyser.class.getCanonicalName())
|| analyserClassName.equals(LongAnalyser.class.getCanonicalName())
|| analyserClassName.equals(PathAnalyser.class.getCanonicalName())
|| analyserClassName.equals(VerbatimAnalyser.class.getCanonicalName()))
{
result.setIsOrderable(true);
}
}
}
}
// constraints and choices
for (ConstraintDefinition constraintDef : propDef.getConstraints())
{
Constraint constraint = constraintDef.getConstraint();
if (constraint instanceof ListOfValuesConstraint)
{
addChoiceList((ListOfValuesConstraint) constraint, result);
}
if ((constraint instanceof StringLengthConstraint) && (result instanceof PropertyStringDefinitionImpl))
{
StringLengthConstraint slc = (StringLengthConstraint) constraint;
((PropertyStringDefinitionImpl) result).setMaxLength(BigInteger.valueOf(slc.getMaxLength()));
}
if (constraint instanceof NumericRangeConstraint)
{
NumericRangeConstraint nrc = (NumericRangeConstraint) constraint;
if (result instanceof PropertyIntegerDefinitionImpl)
{
((PropertyIntegerDefinitionImpl) result)
.setMinValue(BigInteger.valueOf(((Double) nrc.getMinValue()).longValue()));
((PropertyIntegerDefinitionImpl) result)
.setMaxValue(BigInteger.valueOf(((Double) nrc.getMaxValue()).longValue()));
}
if (result instanceof PropertyDecimalDefinitionImpl)
{
((PropertyDecimalDefinitionImpl) result).setMinValue(BigDecimal.valueOf(nrc.getMinValue()));
((PropertyDecimalDefinitionImpl) result).setMaxValue(BigDecimal.valueOf(nrc.getMaxValue()));
}
}
}
return result;
}
@SuppressWarnings("unchecked")
private <T> T convertValueFromString(String value, PropertyType datatype)
{
if (value == null)
{
return null;
}
switch (datatype)
{
case BOOLEAN:
return (T) Boolean.valueOf(value);
case DATETIME:
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(ISO8601DateFormat.parse(value));
return (T) cal;
case DECIMAL:
return (T) new BigDecimal(value);
case HTML:
return (T) value;
case ID:
return (T) value;
case INTEGER:
return (T) new BigInteger(value);
case STRING:
return (T) value;
case URI:
return (T) value;
default:
throw new RuntimeException("Unknown datatype! Spec change?");
}
}
/**
* Adds the default value to a property definition.
*/
private void addDefaultValue(String value, PropertyDefinition<?> propDef)
{
if (value == null)
{
return;
}
if (propDef instanceof PropertyBooleanDefinitionImpl)
{
PropertyBooleanDefinitionImpl propDefImpl = (PropertyBooleanDefinitionImpl) propDef;
propDefImpl.setDefaultValue(Collections.singletonList((Boolean) convertValueFromString(value,
PropertyType.BOOLEAN)));
} else if (propDef instanceof PropertyDateTimeDefinitionImpl)
{
PropertyDateTimeDefinitionImpl propDefImpl = (PropertyDateTimeDefinitionImpl) propDef;
propDefImpl.setDefaultValue(Collections.singletonList((GregorianCalendar) convertValueFromString(value,
PropertyType.DATETIME)));
} else if (propDef instanceof PropertyDecimalDefinitionImpl)
{
PropertyDecimalDefinitionImpl propDefImpl = (PropertyDecimalDefinitionImpl) propDef;
propDefImpl.setDefaultValue(Collections.singletonList((BigDecimal) convertValueFromString(value,
PropertyType.DECIMAL)));
} else if (propDef instanceof PropertyHtmlDefinitionImpl)
{
PropertyHtmlDefinitionImpl propDefImpl = (PropertyHtmlDefinitionImpl) propDef;
propDefImpl.setDefaultValue(Collections.singletonList((String) convertValueFromString(value,
PropertyType.HTML)));
} else if (propDef instanceof PropertyIdDefinitionImpl)
{
PropertyIdDefinitionImpl propDefImpl = (PropertyIdDefinitionImpl) propDef;
propDefImpl.setDefaultValue(Collections.singletonList((String) convertValueFromString(value,
PropertyType.ID)));
} else if (propDef instanceof PropertyIntegerDefinitionImpl)
{
PropertyIntegerDefinitionImpl propDefImpl = (PropertyIntegerDefinitionImpl) propDef;
propDefImpl.setDefaultValue(Collections.singletonList((BigInteger) convertValueFromString(value,
PropertyType.INTEGER)));
} else if (propDef instanceof PropertyStringDefinitionImpl)
{
PropertyStringDefinitionImpl propDefImpl = (PropertyStringDefinitionImpl) propDef;
propDefImpl.setDefaultValue(Collections.singletonList((String) convertValueFromString(value,
PropertyType.STRING)));
} else if (propDef instanceof PropertyUriDefinitionImpl)
{
PropertyUriDefinitionImpl propDefImpl = (PropertyUriDefinitionImpl) propDef;
propDefImpl.setDefaultValue(Collections.singletonList((String) convertValueFromString(value,
PropertyType.URI)));
}
}
/**
* Adds choices to the property defintion.
*/
private void addChoiceList(ListOfValuesConstraint lovc, PropertyDefinition<?> propDef)
{
if (propDef instanceof PropertyBooleanDefinitionImpl)
{
PropertyBooleanDefinitionImpl propDefImpl = (PropertyBooleanDefinitionImpl) propDef;
propDefImpl.setIsOpenChoice(false);
List<Choice<Boolean>> choiceList = new ArrayList<Choice<Boolean>>();
for (String allowed : lovc.getAllowedValues())
{
ChoiceImpl<Boolean> choice = new ChoiceImpl<Boolean>();
choice.setDisplayName(allowed);
choice.setValue(Collections.singletonList((Boolean) convertValueFromString(allowed,
PropertyType.BOOLEAN)));
choiceList.add(choice);
}
propDefImpl.setChoices(choiceList);
} else if (propDef instanceof PropertyDateTimeDefinitionImpl)
{
PropertyDateTimeDefinitionImpl propDefImpl = (PropertyDateTimeDefinitionImpl) propDef;
propDefImpl.setIsOpenChoice(false);
List<Choice<GregorianCalendar>> choiceList = new ArrayList<Choice<GregorianCalendar>>();
for (String allowed : lovc.getAllowedValues())
{
ChoiceImpl<GregorianCalendar> choice = new ChoiceImpl<GregorianCalendar>();
choice.setDisplayName(allowed);
choice.setValue(Collections.singletonList((GregorianCalendar) convertValueFromString(allowed,
PropertyType.DATETIME)));
choiceList.add(choice);
}
propDefImpl.setChoices(choiceList);
} else if (propDef instanceof PropertyDecimalDefinitionImpl)
{
PropertyDecimalDefinitionImpl propDefImpl = (PropertyDecimalDefinitionImpl) propDef;
propDefImpl.setIsOpenChoice(false);
List<Choice<BigDecimal>> choiceList = new ArrayList<Choice<BigDecimal>>();
for (String allowed : lovc.getAllowedValues())
{
ChoiceImpl<BigDecimal> choice = new ChoiceImpl<BigDecimal>();
choice.setDisplayName(allowed);
choice.setValue(Collections.singletonList((BigDecimal) convertValueFromString(allowed,
PropertyType.DECIMAL)));
choiceList.add(choice);
}
propDefImpl.setChoices(choiceList);
} else if (propDef instanceof PropertyHtmlDefinitionImpl)
{
PropertyHtmlDefinitionImpl propDefImpl = (PropertyHtmlDefinitionImpl) propDef;
propDefImpl.setIsOpenChoice(false);
List<Choice<String>> choiceList = new ArrayList<Choice<String>>();
for (String allowed : lovc.getAllowedValues())
{
ChoiceImpl<String> choice = new ChoiceImpl<String>();
choice.setDisplayName(allowed);
choice.setValue(Collections.singletonList((String) convertValueFromString(allowed, PropertyType.HTML)));
choiceList.add(choice);
}
propDefImpl.setChoices(choiceList);
} else if (propDef instanceof PropertyIdDefinitionImpl)
{
PropertyIdDefinitionImpl propDefImpl = (PropertyIdDefinitionImpl) propDef;
propDefImpl.setIsOpenChoice(false);
List<Choice<String>> choiceList = new ArrayList<Choice<String>>();
for (String allowed : lovc.getAllowedValues())
{
ChoiceImpl<String> choice = new ChoiceImpl<String>();
choice.setDisplayName(allowed);
choice.setValue(Collections.singletonList((String) convertValueFromString(allowed, PropertyType.ID)));
choiceList.add(choice);
}
propDefImpl.setChoices(choiceList);
} else if (propDef instanceof PropertyIntegerDefinitionImpl)
{
PropertyIntegerDefinitionImpl propDefImpl = (PropertyIntegerDefinitionImpl) propDef;
propDefImpl.setIsOpenChoice(false);
List<Choice<BigInteger>> choiceList = new ArrayList<Choice<BigInteger>>();
for (String allowed : lovc.getAllowedValues())
{
ChoiceImpl<BigInteger> choice = new ChoiceImpl<BigInteger>();
choice.setDisplayName(allowed);
choice.setValue(Collections.singletonList((BigInteger) convertValueFromString(allowed,
PropertyType.INTEGER)));
choiceList.add(choice);
}
propDefImpl.setChoices(choiceList);
} else if (propDef instanceof PropertyStringDefinitionImpl)
{
PropertyStringDefinitionImpl propDefImpl = (PropertyStringDefinitionImpl) propDef;
propDefImpl.setIsOpenChoice(false);
List<Choice<String>> choiceList = new ArrayList<Choice<String>>();
for (String allowed : lovc.getAllowedValues())
{
ChoiceImpl<String> choice = new ChoiceImpl<String>();
choice.setDisplayName(allowed);
choice.setValue(Collections
.singletonList((String) convertValueFromString(allowed, PropertyType.STRING)));
choiceList.add(choice);
}
propDefImpl.setChoices(choiceList);
} else if (propDef instanceof PropertyUriDefinitionImpl)
{
PropertyUriDefinitionImpl propDefImpl = (PropertyUriDefinitionImpl) propDef;
propDefImpl.setIsOpenChoice(false);
List<Choice<String>> choiceList = new ArrayList<Choice<String>>();
for (String allowed : lovc.getAllowedValues())
{
ChoiceImpl<String> choice = new ChoiceImpl<String>();
choice.setDisplayName(allowed);
choice.setValue(Collections.singletonList((String) convertValueFromString(allowed, PropertyType.URI)));
choiceList.add(choice);
}
propDefImpl.setChoices(choiceList);
}
}
}

View File

@@ -1,84 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.opencmis.dictionary;
import java.io.Serializable;
import org.alfresco.cmis.CMISPropertyAccessor;
import org.alfresco.cmis.CMISPropertyLuceneBuilder;
import org.alfresco.service.namespace.QName;
import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
public class BasePropertyDefintionWrapper implements PropertyDefintionWrapper, Serializable
{
private static final long serialVersionUID = 1L;
private PropertyDefinition<?> propDef;
private QName alfrescoName;
private TypeDefinitionWrapper owningType;
private CMISPropertyAccessor accessor;
private CMISPropertyLuceneBuilder luceneBuilder;
public BasePropertyDefintionWrapper(PropertyDefinition<?> propDef, QName alfrescoName,
TypeDefinitionWrapper owningType, CMISPropertyAccessor accessor, CMISPropertyLuceneBuilder luceneBuilder)
{
this.propDef = propDef;
this.alfrescoName = alfrescoName;
this.owningType = owningType;
this.accessor = accessor;
this.luceneBuilder = luceneBuilder;
}
@Override
public PropertyDefinition<?> getPropertyDefinition()
{
return propDef;
}
@Override
public String getPropertyId()
{
return propDef.getId();
}
@Override
public QName getAlfrescoName()
{
return alfrescoName;
}
@Override
public TypeDefinitionWrapper getOwningType()
{
return owningType;
}
@Override
public CMISPropertyAccessor getPropertyAccessor()
{
return accessor;
}
@Override
public CMISPropertyLuceneBuilder getPropertyLuceneBuilder()
{
return luceneBuilder;
}
}

View File

@@ -1,428 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.opencmis.dictionary;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.opencmis.mapping.CMISMapping;
import org.alfresco.repo.dictionary.DictionaryDAO;
import org.alfresco.repo.dictionary.DictionaryListener;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.namespace.QName;
import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
import org.apache.chemistry.opencmis.commons.enums.PropertyType;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationEvent;
import org.springframework.extensions.surf.util.AbstractLifecycleBean;
/**
* Common CMIS Dictionary Support including registry of Types.
*
* @author davidc
* @author florian.mueller
*/
public abstract class CMISAbstractDictionaryService extends AbstractLifecycleBean implements CMISDictionaryService,
DictionaryListener
{
// Logger
protected static final Log logger = LogFactory.getLog(CMISAbstractDictionaryService.class);
// service dependencies
private DictionaryDAO dictionaryDAO;
protected CMISMapping cmisMapping;
protected DictionaryService dictionaryService;
protected TenantService tenantService;
protected ServiceRegistry serviceRegistry;
/**
* Set the mapping service
*
* @param cmisMapping
*/
public void setOpenCMISMapping(CMISMapping cmisMapping)
{
this.cmisMapping = cmisMapping;
}
/**
* Set the dictionary Service
*
* @param dictionaryService
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
/**
* Set the dictionary DAO
*
* @param dictionaryDAO
*/
public void setDictionaryDAO(DictionaryDAO dictionaryDAO)
{
this.dictionaryDAO = dictionaryDAO;
}
/**
* Set the tenant Service
*
* @param tenantService
*/
public void setTenantService(TenantService tenantService)
{
this.tenantService = tenantService;
}
/**
* Set the service registry
*
* @param serviceRegistry
*/
public void setServiceRegistry(ServiceRegistry serviceRegistry)
{
this.serviceRegistry = serviceRegistry;
}
/** CMIS Dictionary Registry (tenant-aware) */
private Map<String, DictionaryRegistry> registryMap = new ConcurrentHashMap<String, DictionaryRegistry>(4);
/**
* CMIS Dictionary registry
*
* Index of CMIS Type Definitions
*/
/* package */class DictionaryRegistry
{
// Type Definitions Index
Map<QName, TypeDefinitionWrapper> typeDefsByQName = new HashMap<QName, TypeDefinitionWrapper>();
Map<QName, TypeDefinitionWrapper> assocDefsByQName = new HashMap<QName, TypeDefinitionWrapper>();
Map<String, AbstractTypeDefinitionWrapper> typeDefsByTypeId = new HashMap<String, AbstractTypeDefinitionWrapper>();
Map<String, TypeDefinitionWrapper> typeDefsByQueryName = new HashMap<String, TypeDefinitionWrapper>();
List<TypeDefinitionWrapper> baseTypes = new ArrayList<TypeDefinitionWrapper>();
Map<String, PropertyDefintionWrapper> propDefbyPropId = new HashMap<String, PropertyDefintionWrapper>();
Map<String, PropertyDefintionWrapper> propDefbyQueryName = new HashMap<String, PropertyDefintionWrapper>();
/**
* Register type definition.
*
* @param typeDef
*/
public void registerTypeDefinition(AbstractTypeDefinitionWrapper typeDef)
{
AbstractTypeDefinitionWrapper existingTypeDef = typeDefsByTypeId.get(typeDef.getTypeId());
if (existingTypeDef != null)
{
throw new AlfrescoRuntimeException("Type " + typeDef.getTypeId() + " already registered");
}
typeDefsByTypeId.put(typeDef.getTypeId(), typeDef);
QName typeQName = typeDef.getAlfrescoName();
if (typeQName != null)
{
if ((typeDef instanceof RelationshipTypeDefintionWrapper) && !typeDef.isBaseType())
{
assocDefsByQName.put(typeQName, typeDef);
} else
{
typeDefsByQName.put(typeQName, typeDef);
}
}
typeDefsByQueryName.put(typeDef.getTypeDefinition(false).getQueryName(), typeDef);
if (logger.isDebugEnabled())
{
logger.debug("Registered type " + typeDef.getTypeId() + " (scope=" + typeDef.getBaseTypeId() + ")");
logger.debug(" QName: " + typeDef.getAlfrescoName());
logger.debug(" Table: " + typeDef.getTypeDefinition(false).getQueryName());
logger.debug(" Action Evaluators: " + typeDef.getActionEvaluators().size());
}
}
/**
* Register property definitions.
*
* @param typeDef
*/
public void registerPropertyDefinitions(AbstractTypeDefinitionWrapper typeDef)
{
for (PropertyDefintionWrapper propDef : typeDef.getProperties())
{
if (propDef.getPropertyDefinition().isInherited())
{
continue;
}
propDefbyPropId.put(propDef.getPropertyId(), propDef);
propDefbyQueryName.put(propDef.getPropertyDefinition().getQueryName(), propDef);
}
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
StringBuilder builder = new StringBuilder();
builder.append("DictionaryRegistry[");
builder.append("Types=").append(typeDefsByTypeId.size()).append(", ");
builder.append("Base Types=").append(baseTypes.size()).append(", ");
builder.append("]");
return builder.toString();
}
}
private DictionaryRegistry getRegistry()
{
String tenantDomain = tenantService.getCurrentUserDomain();
DictionaryRegistry registry = registryMap.get(tenantDomain);
if (registry == null)
{
init();
registry = registryMap.get(tenantDomain);
}
return registry;
}
public TypeDefinitionWrapper findType(String typeId)
{
return getRegistry().typeDefsByTypeId.get(typeId);
}
public TypeDefinitionWrapper findTypeForClass(QName clazz, BaseTypeId... matchingScopes)
{
// searching for relationship
boolean scopeByRelationship = false;
for (BaseTypeId scope : matchingScopes)
{
if (scope == BaseTypeId.CMIS_RELATIONSHIP)
{
scopeByRelationship = true;
break;
}
}
// locate type in registry
clazz = cmisMapping.getCmisType(clazz);
TypeDefinitionWrapper typeDef = null;
if (scopeByRelationship)
{
typeDef = getRegistry().assocDefsByQName.get(clazz);
} else
{
typeDef = getRegistry().typeDefsByQName.get(clazz);
if (typeDef == null)
{
typeDef = getRegistry().assocDefsByQName.get(clazz);
}
}
// ensure matches one of provided matching scopes
TypeDefinitionWrapper matchingTypeDef = (matchingScopes.length == 0) ? typeDef : null;
if (typeDef != null)
{
for (BaseTypeId scope : matchingScopes)
{
if (typeDef.getBaseTypeId() == scope)
{
matchingTypeDef = typeDef;
break;
}
}
}
return matchingTypeDef;
}
public TypeDefinitionWrapper findNodeType(QName clazz)
{
return getRegistry().typeDefsByQName.get(cmisMapping.getCmisType(clazz));
}
public TypeDefinitionWrapper findAssocType(QName clazz)
{
return getRegistry().assocDefsByQName.get(cmisMapping.getCmisType(clazz));
}
public TypeDefinitionWrapper findTypeByQueryName(String queryName)
{
return getRegistry().typeDefsByQueryName.get(queryName);
}
public QName getAlfrescoClass(QName name)
{
return cmisMapping.getAlfrescoClass(name);
}
public PropertyDefintionWrapper findProperty(String propId)
{
return getRegistry().propDefbyPropId.get(propId);
}
@Override
public PropertyDefintionWrapper findPropertyByQueryName(String queryName)
{
return getRegistry().propDefbyQueryName.get(queryName);
}
public List<TypeDefinitionWrapper> getBaseTypes()
{
return Collections.unmodifiableList(getRegistry().baseTypes);
}
public List<TypeDefinitionWrapper> getAllTypes()
{
return Collections.unmodifiableList(new ArrayList<TypeDefinitionWrapper>(getRegistry().typeDefsByTypeId
.values()));
}
public PropertyType findDataType(QName dataType)
{
return cmisMapping.getDataType(dataType);
}
public QName findAlfrescoDataType(PropertyType propertyType)
{
return cmisMapping.getAlfrescoDataType(propertyType);
}
/**
* Factory for creating CMIS Definitions
*
* @param registry
*/
abstract protected void createDefinitions(DictionaryRegistry registry);
/**
* Dictionary Initialization - creates a new registry
*/
private void init()
{
DictionaryRegistry registry = new DictionaryRegistry();
if (logger.isDebugEnabled())
logger.debug("Creating type definitions...");
// phase 1: construct type definitions and link them together
createDefinitions(registry);
for (AbstractTypeDefinitionWrapper objectTypeDef : registry.typeDefsByTypeId.values())
{
objectTypeDef.connectParentAndSubTypes(cmisMapping, registry, dictionaryService);
}
// phase 2: register base types and inherit property definitions
for (AbstractTypeDefinitionWrapper typeDef : registry.typeDefsByTypeId.values())
{
if (typeDef.getTypeDefinition(false).getParentTypeId() == null)
{
registry.baseTypes.add(typeDef);
typeDef.resolveInheritance(cmisMapping, serviceRegistry, registry, dictionaryService);
}
}
// phase 3: register properties
for (AbstractTypeDefinitionWrapper typeDef : registry.typeDefsByTypeId.values())
{
registry.registerPropertyDefinitions(typeDef);
}
// phase 4: assert valid
for (AbstractTypeDefinitionWrapper typeDef : registry.typeDefsByTypeId.values())
{
typeDef.assertComplete();
}
// publish new registry
registryMap.put(tenantService.getCurrentUserDomain(), registry);
if (logger.isInfoEnabled())
logger.info("Initialized CMIS Dictionary. Types:" + registry.typeDefsByTypeId.size() + ", Base Types:"
+ registry.baseTypes.size());
}
/*
* (non-Javadoc)
*
* @see org.alfresco.repo.dictionary.DictionaryListener#onInit()
*/
public void onDictionaryInit()
{
}
/*
* (non-Javadoc)
*
* @see org.alfresco.repo.dictionary.DictionaryListener#afterInit()
*/
public void afterDictionaryInit()
{
init();
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.repo.dictionary.DictionaryListener#afterDictionaryDestroy()
*/
public void afterDictionaryDestroy()
{
registryMap.remove(tenantService.getCurrentUserDomain());
}
/*
* (non-Javadoc)
*
* @see
* org.springframework.extensions.surf.util.AbstractLifecycleBean#onBootstrap
* (org.springframework.context.ApplicationEvent)
*/
protected void onBootstrap(ApplicationEvent event)
{
afterDictionaryInit();
dictionaryDAO.register(this);
}
/*
* (non-Javadoc)
*
* @see
* org.springframework.extensions.surf.util.AbstractLifecycleBean#onShutdown
* (org.springframework.context.ApplicationEvent)
*/
protected void onShutdown(ApplicationEvent event)
{
}
}

View File

@@ -1,89 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco 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 Lesser General License for more details.
*
* You should have received a copy of the GNU Lesser General License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.opencmis.dictionary;
import java.util.List;
import org.alfresco.service.namespace.QName;
import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
import org.apache.chemistry.opencmis.commons.enums.PropertyType;
/**
* Service to query the CMIS meta model
*
* @author davidc
*/
public interface CMISDictionaryService
{
/**
* Find type for type id
*
* @param typeId
* @return
*/
TypeDefinitionWrapper findType(String typeId);
/**
* Find type for Alfresco class name. Optionally, constrain match to one of
* specified CMIS scopes
*
* @param clazz
* @param matchingScopes
* @return
*/
TypeDefinitionWrapper findTypeForClass(QName clazz, BaseTypeId... matchingScopes);
TypeDefinitionWrapper findNodeType(QName clazz);
TypeDefinitionWrapper findAssocType(QName clazz);
PropertyDefintionWrapper findProperty(String propId);
PropertyDefintionWrapper findPropertyByQueryName(String queryName);
/**
* Find a type by its query name
*
* @param queryName
* @return
*/
TypeDefinitionWrapper findTypeByQueryName(String queryName);
/**
* Get Base Types
*/
List<TypeDefinitionWrapper> getBaseTypes();
/**
* Get all Types
*
* @return
*/
List<TypeDefinitionWrapper> getAllTypes();
/**
* Find data type
*
* @param dataType
* @return
*/
PropertyType findDataType(QName dataType);
QName findAlfrescoDataType(PropertyType propertyType);
}

View File

@@ -1,117 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.opencmis.dictionary;
import java.util.Collection;
import org.alfresco.cmis.mapping.CMISMapping;
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.namespace.QName;
import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
/**
* CMIS Dictionary which provides Types that strictly conform to the CMIS
* specification.
*
* That is, only maps types to one of root Document, Folder, Relationship &
* Policy.
*
* @author davidc
*/
public class CMISStrictDictionaryService extends CMISAbstractDictionaryService
{
@Override
protected void createDefinitions(DictionaryRegistry registry)
{
createTypeDefs(registry, dictionaryService.getAllTypes());
createAssocDefs(registry, dictionaryService.getAllAssociations());
createTypeDefs(registry, dictionaryService.getAllAspects());
}
/**
* Create Type Definitions
*
* @param registry
* @param classQNames
*/
private void createTypeDefs(DictionaryRegistry registry, Collection<QName> classQNames)
{
for (QName classQName : classQNames)
{
// skip items that are remapped to CMIS model
if (cmisMapping.isRemappedType(classQName))
continue;
// create appropriate kind of type definition
ClassDefinition classDef = dictionaryService.getClass(classQName);
String typeId = null;
AbstractTypeDefinitionWrapper objectTypeDef = null;
if (cmisMapping.isValidCmisDocument(classQName))
{
typeId = cmisMapping.getCmisTypeId(BaseTypeId.CMIS_DOCUMENT, classQName);
objectTypeDef = new DocumentTypeDefinitionWrapper(cmisMapping, serviceRegistry, typeId, classDef);
} else if (cmisMapping.isValidCmisFolder(classQName))
{
typeId = cmisMapping.getCmisTypeId(BaseTypeId.CMIS_FOLDER, classQName);
objectTypeDef = new FolderTypeDefintionWrapper(cmisMapping, serviceRegistry, typeId, classDef);
} else if (cmisMapping.isValidCmisPolicy(classQName))
{
typeId = cmisMapping.getCmisTypeId(BaseTypeId.CMIS_POLICY, classQName);
objectTypeDef = new PolicyTypeDefintionWrapper(cmisMapping, serviceRegistry, typeId, classDef);
}
if (objectTypeDef != null)
{
registry.registerTypeDefinition(objectTypeDef);
}
}
}
/**
* Create Relationship Definitions
*
* @param registry
* @param classQNames
*/
private void createAssocDefs(DictionaryRegistry registry, Collection<QName> classQNames)
{
// register base type
String typeId = cmisMapping.getCmisTypeId(BaseTypeId.CMIS_RELATIONSHIP, CMISMapping.RELATIONSHIP_QNAME);
RelationshipTypeDefintionWrapper objectTypeDef = new RelationshipTypeDefintionWrapper(cmisMapping,
serviceRegistry, typeId, dictionaryService.getClass(CMISMapping.RELATIONSHIP_QNAME));
registry.registerTypeDefinition(objectTypeDef);
// register all other relationships
for (QName classQName : classQNames)
{
if (!cmisMapping.isValidCmisRelationship(classQName))
continue;
// create appropriate kind of type definition
AssociationDefinition assocDef = dictionaryService.getAssociation(classQName);
typeId = cmisMapping.getCmisTypeId(BaseTypeId.CMIS_RELATIONSHIP, classQName);
objectTypeDef = new RelationshipTypeDefintionWrapper(cmisMapping, typeId, assocDef);
registry.registerTypeDefinition(objectTypeDef);
}
}
}

View File

@@ -1,85 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.opencmis.dictionary;
import org.alfresco.opencmis.CMISUtils;
import org.alfresco.opencmis.mapping.CMISMapping;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.namespace.QName;
import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
import org.apache.chemistry.opencmis.commons.enums.ContentStreamAllowed;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.DocumentTypeDefinitionImpl;
public class DocumentTypeDefinitionWrapper extends ShadowTypeDefinitionWrapper
{
private static final long serialVersionUID = 1L;
private DocumentTypeDefinitionImpl typeDef;
private DocumentTypeDefinitionImpl typeDefInclProperties;
public DocumentTypeDefinitionWrapper(CMISMapping cmisMapping, ServiceRegistry serviceRegistry, String typeId,
ClassDefinition cmisClassDef)
{
alfrescoName = cmisClassDef.getName();
alfrescoClass = cmisMapping.getAlfrescoClass(alfrescoName);
typeDef = new DocumentTypeDefinitionImpl();
typeDef.setBaseTypeId(BaseTypeId.CMIS_DOCUMENT);
typeDef.setId(typeId);
typeDef.setLocalName(alfrescoName.getLocalName());
typeDef.setLocalNamespace(alfrescoName.getNamespaceURI());
if (BaseTypeId.CMIS_DOCUMENT.value().equals(typeId))
{
typeDef.setQueryName(typeId);
typeDef.setParentTypeId(null);
} else
{
typeDef.setQueryName(cmisMapping.buildPrefixEncodedString(alfrescoName));
QName parentQName = cmisMapping.getCmisType(cmisClassDef.getParentName());
if (cmisMapping.isValidCmisDocument(parentQName))
{
typeDef.setParentTypeId(cmisMapping.getCmisTypeId(BaseTypeId.CMIS_DOCUMENT, parentQName));
}
}
typeDef.setDisplayName((cmisClassDef.getTitle() != null) ? cmisClassDef.getTitle() : typeId);
typeDef.setDescription(cmisClassDef.getDescription() != null ? cmisClassDef.getDescription() : typeDef
.getDisplayName());
typeDef.setIsCreatable(true);
typeDef.setIsQueryable(true);
typeDef.setIsFulltextIndexed(true);
typeDef.setIsControllablePolicy(false);
typeDef.setIsControllableAcl(true);
typeDef.setIsIncludedInSupertypeQuery(cmisClassDef.getIncludedInSuperTypeQuery());
typeDef.setIsFileable(true);
typeDef.setContentStreamAllowed(ContentStreamAllowed.ALLOWED);
typeDef.setIsVersionable(true);
typeDefInclProperties = CMISUtils.copy(typeDef);
setTypeDefinition(typeDef, typeDefInclProperties);
createOwningPropertyDefinitions(cmisMapping, serviceRegistry, cmisClassDef);
actionEvaluators = cmisMapping.getActionEvaluators(BaseTypeId.CMIS_DOCUMENT);
}
}

View File

@@ -1,90 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.opencmis.dictionary;
import org.alfresco.model.ContentModel;
import org.alfresco.opencmis.CMISUtils;
import org.alfresco.opencmis.mapping.CMISMapping;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.namespace.QName;
import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.FolderTypeDefinitionImpl;
public class FolderTypeDefintionWrapper extends ShadowTypeDefinitionWrapper
{
private static final long serialVersionUID = 1L;
private FolderTypeDefinitionImpl typeDef;
private FolderTypeDefinitionImpl typeDefInclProperties;
public FolderTypeDefintionWrapper(CMISMapping cmisMapping, ServiceRegistry serviceRegistry, String typeId,
ClassDefinition cmisClassDef)
{
alfrescoName = cmisClassDef.getName();
alfrescoClass = cmisMapping.getAlfrescoClass(alfrescoName);
typeDef = new FolderTypeDefinitionImpl();
typeDef.setBaseTypeId(BaseTypeId.CMIS_FOLDER);
typeDef.setId(typeId);
typeDef.setLocalName(alfrescoName.getLocalName());
typeDef.setLocalNamespace(alfrescoName.getNamespaceURI());
boolean isSystemFolder = false;
if (BaseTypeId.CMIS_FOLDER.value().equals(typeId))
{
typeDef.setQueryName(typeId);
typeDef.setParentTypeId(null);
} else
{
typeDef.setQueryName(cmisMapping.buildPrefixEncodedString(alfrescoName));
QName parentQName = cmisMapping.getCmisType(cmisClassDef.getParentName());
if (cmisMapping.isValidCmisFolder(parentQName))
{
typeDef.setParentTypeId(cmisMapping.getCmisTypeId(BaseTypeId.CMIS_FOLDER, parentQName));
}
if (alfrescoName.equals(ContentModel.TYPE_SYSTEM_FOLDER)
|| serviceRegistry.getDictionaryService().isSubClass(alfrescoName, ContentModel.TYPE_SYSTEM_FOLDER))
{
isSystemFolder = true;
}
}
typeDef.setDisplayName((cmisClassDef.getTitle() != null) ? cmisClassDef.getTitle() : typeId);
typeDef.setDescription(cmisClassDef.getDescription() != null ? cmisClassDef.getDescription() : typeDef
.getDisplayName());
typeDef.setIsCreatable(!isSystemFolder);
typeDef.setIsQueryable(true);
typeDef.setIsFulltextIndexed(true);
typeDef.setIsControllablePolicy(false);
typeDef.setIsControllableAcl(true);
typeDef.setIsIncludedInSupertypeQuery(cmisClassDef.getIncludedInSuperTypeQuery());
typeDef.setIsFileable(true);
typeDefInclProperties = CMISUtils.copy(typeDef);
setTypeDefinition(typeDef, typeDefInclProperties);
createOwningPropertyDefinitions(cmisMapping, serviceRegistry, cmisClassDef);
actionEvaluators = cmisMapping.getActionEvaluators(BaseTypeId.CMIS_FOLDER);
}
}

View File

@@ -1,195 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.opencmis.dictionary;
import java.util.ArrayList;
import java.util.Collection;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.opencmis.CMISUtils;
import org.alfresco.opencmis.dictionary.CMISAbstractDictionaryService.DictionaryRegistry;
import org.alfresco.opencmis.mapping.CMISMapping;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.namespace.QName;
import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.PolicyTypeDefinitionImpl;
public class PolicyTypeDefintionWrapper extends AbstractTypeDefinitionWrapper
{
private static final long serialVersionUID = 1L;
private PolicyTypeDefinitionImpl typeDef;
private PolicyTypeDefinitionImpl typeDefInclProperties;
public PolicyTypeDefintionWrapper(CMISMapping cmisMapping, ServiceRegistry serviceRegistry, String typeId,
ClassDefinition cmisClassDef)
{
alfrescoName = cmisClassDef.getName();
alfrescoClass = cmisMapping.getAlfrescoClass(alfrescoName);
typeDef = new PolicyTypeDefinitionImpl();
typeDef.setBaseTypeId(BaseTypeId.CMIS_POLICY);
typeDef.setId(typeId);
typeDef.setLocalName(alfrescoName.getLocalName());
typeDef.setLocalNamespace(alfrescoName.getNamespaceURI());
if (BaseTypeId.CMIS_POLICY.value().equals(typeId))
{
typeDef.setQueryName(typeId);
typeDef.setParentTypeId(null);
} else
{
typeDef.setQueryName(cmisMapping.buildPrefixEncodedString(alfrescoName));
QName parentQName = cmisMapping.getCmisType(cmisClassDef.getParentName());
if (parentQName == null)
{
typeDef.setParentTypeId(cmisMapping.getCmisTypeId(CMISMapping.ASPECTS_QNAME));
} else if (cmisMapping.isValidCmisPolicy(parentQName))
{
typeDef.setParentTypeId(cmisMapping.getCmisTypeId(BaseTypeId.CMIS_POLICY, parentQName));
}
}
typeDef.setDisplayName((cmisClassDef.getTitle() != null) ? cmisClassDef.getTitle() : typeId);
typeDef.setDescription(cmisClassDef.getDescription() != null ? cmisClassDef.getDescription() : typeDef
.getDisplayName());
typeDef.setIsCreatable(false);
typeDef.setIsQueryable(true);
typeDef.setIsFulltextIndexed(true);
typeDef.setIsControllablePolicy(false);
typeDef.setIsControllableAcl(false);
typeDef.setIsIncludedInSupertypeQuery(cmisClassDef.getIncludedInSuperTypeQuery());
typeDef.setIsFileable(true);
typeDefInclProperties = CMISUtils.copy(typeDef);
setTypeDefinition(typeDef, typeDefInclProperties);
createOwningPropertyDefinitions(cmisMapping, serviceRegistry, cmisClassDef);
actionEvaluators = cmisMapping.getActionEvaluators(BaseTypeId.CMIS_POLICY);
}
public void connectParentAndSubTypes(CMISMapping cmisMapping, DictionaryRegistry registry,
DictionaryService dictionaryService)
{
// find parent
if (typeDef.getParentTypeId() != null)
{
parent = registry.typeDefsByTypeId.get(typeDef.getParentTypeId());
} else
{
if (!isBaseType())
{
throw new AlfrescoRuntimeException("Type " + typeDef.getId() + " has no parent!");
}
parent = null;
}
// find children
children = new ArrayList<TypeDefinitionWrapper>();
Collection<QName> childrenNames = null;
if (isBaseType())
{
// add the "Aspects" type to the CMIS Policy type
childrenNames = new ArrayList<QName>();
childrenNames.add(CMISMapping.ASPECTS_QNAME);
} else if (getAlfrescoName().equals(CMISMapping.ASPECTS_QNAME))
{
// add all root aspects to the "Aspects" type
childrenNames = new ArrayList<QName>();
String aspectsTypeId = cmisMapping.getCmisTypeId(CMISMapping.ASPECTS_QNAME);
for (AbstractTypeDefinitionWrapper tdw : registry.typeDefsByTypeId.values())
{
String parentId = tdw.getTypeDefinition(false).getParentTypeId();
if ((parentId != null) && parentId.equals(aspectsTypeId))
{
childrenNames.add(tdw.getAlfrescoName());
}
}
} else
{
// add all non-root aspects to their parent
childrenNames = dictionaryService.getSubAspects(cmisMapping.getAlfrescoClass(getAlfrescoName()), false);
}
for (QName childName : childrenNames)
{
if (cmisMapping.isValidCmisPolicy(childName))
{
TypeDefinitionWrapper child = registry.typeDefsByQName.get(childName);
if (child == null)
{
throw new AlfrescoRuntimeException("Failed to retrieve sub type for type id " + childName
+ " for parent type " + getAlfrescoName() + "!");
}
children.add(child);
} else
{
System.out.println("Not a policy: " + childName);
}
}
}
public void resolveInheritance(CMISMapping cmisMapping, ServiceRegistry serviceRegistry,
DictionaryRegistry registry, DictionaryService dictionaryService)
{
PropertyDefinition<?> propertyDefintion;
if (parent != null)
{
for (PropertyDefintionWrapper propDef : parent.getProperties())
{
if (propertiesById.containsKey(propDef.getPropertyId()))
{
continue;
}
org.alfresco.service.cmr.dictionary.PropertyDefinition alfrescoPropDef = dictionaryService.getProperty(
propDef.getOwningType().getAlfrescoName(), propDef.getAlfrescoName());
propertyDefintion = createPropertyDefinition(cmisMapping, propDef.getPropertyId(),
alfrescoPropDef.getName(), alfrescoPropDef, true);
if (propertyDefintion != null)
{
registerProperty(new BasePropertyDefintionWrapper(propertyDefintion, alfrescoPropDef.getName(),
propDef.getOwningType(), propDef.getPropertyAccessor(), propDef.getPropertyLuceneBuilder()));
}
}
}
for (TypeDefinitionWrapper child : children)
{
if (child instanceof AbstractTypeDefinitionWrapper)
{
((AbstractTypeDefinitionWrapper) child).resolveInheritance(cmisMapping, serviceRegistry, registry,
dictionaryService);
}
}
}
}

View File

@@ -1,39 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.opencmis.dictionary;
import org.alfresco.cmis.CMISPropertyAccessor;
import org.alfresco.cmis.CMISPropertyLuceneBuilder;
import org.alfresco.service.namespace.QName;
import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
public interface PropertyDefintionWrapper
{
PropertyDefinition<?> getPropertyDefinition();
String getPropertyId();
QName getAlfrescoName();
TypeDefinitionWrapper getOwningType();
CMISPropertyAccessor getPropertyAccessor();
CMISPropertyLuceneBuilder getPropertyLuceneBuilder();
}

View File

@@ -1,193 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.opencmis.dictionary;
import java.util.ArrayList;
import java.util.Collections;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.opencmis.CMISUtils;
import org.alfresco.opencmis.dictionary.CMISAbstractDictionaryService.DictionaryRegistry;
import org.alfresco.opencmis.mapping.CMISMapping;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.RelationshipTypeDefinitionImpl;
public class RelationshipTypeDefintionWrapper extends AbstractTypeDefinitionWrapper
{
private static final long serialVersionUID = 1L;
private RelationshipTypeDefinitionImpl typeDef;
private RelationshipTypeDefinitionImpl typeDefInclProperties;
public RelationshipTypeDefintionWrapper(CMISMapping cmisMapping, ServiceRegistry serviceRegistry, String typeId,
ClassDefinition cmisClassDef)
{
alfrescoName = cmisClassDef.getName();
alfrescoClass = cmisMapping.getAlfrescoClass(alfrescoName);
typeDef = new RelationshipTypeDefinitionImpl();
typeDef.setBaseTypeId(BaseTypeId.CMIS_RELATIONSHIP);
typeDef.setId(typeId);
typeDef.setLocalName(alfrescoName.getLocalName());
typeDef.setLocalNamespace(alfrescoName.getNamespaceURI());
if (BaseTypeId.CMIS_RELATIONSHIP.value().equals(typeId))
{
typeDef.setQueryName(typeId);
typeDef.setParentTypeId(null);
} else
{
typeDef.setQueryName(cmisMapping.buildPrefixEncodedString(alfrescoName));
typeDef.setParentTypeId(BaseTypeId.CMIS_RELATIONSHIP.value());
}
typeDef.setDisplayName(cmisClassDef.getTitle() != null ? cmisClassDef.getTitle() : typeId);
typeDef.setDescription(cmisClassDef.getDescription() != null ? cmisClassDef.getDescription() : typeDef
.getDisplayName());
typeDef.setIsCreatable(true);
typeDef.setIsQueryable(false);
typeDef.setIsFulltextIndexed(false);
typeDef.setIsControllablePolicy(false);
typeDef.setIsControllableAcl(false);
typeDef.setIsIncludedInSupertypeQuery(true);
typeDef.setIsFileable(false);
typeDefInclProperties = CMISUtils.copy(typeDef);
setTypeDefinition(typeDef, typeDefInclProperties);
createOwningPropertyDefinitions(cmisMapping, serviceRegistry, cmisClassDef);
actionEvaluators = cmisMapping.getActionEvaluators(BaseTypeId.CMIS_RELATIONSHIP);
}
public RelationshipTypeDefintionWrapper(CMISMapping cmisMapping, String typeId, AssociationDefinition cmisAssocDef)
{
alfrescoName = cmisAssocDef.getName();
alfrescoClass = cmisMapping.getAlfrescoClass(alfrescoName);
typeDef = new RelationshipTypeDefinitionImpl();
typeDef.setBaseTypeId(BaseTypeId.CMIS_RELATIONSHIP);
typeDef.setId(typeId);
typeDef.setLocalName(alfrescoName.getLocalName());
typeDef.setLocalNamespace(alfrescoName.getNamespaceURI());
typeDef.setQueryName(cmisMapping.buildPrefixEncodedString(alfrescoName));
typeDef.setParentTypeId(BaseTypeId.CMIS_RELATIONSHIP.value());
typeDef.setDisplayName(cmisAssocDef.getTitle() != null ? cmisAssocDef.getTitle() : typeId);
typeDef.setDescription(cmisAssocDef.getDescription() != null ? cmisAssocDef.getDescription() : typeDef
.getDisplayName());
typeDef.setIsCreatable(true);
typeDef.setIsQueryable(false);
typeDef.setIsFulltextIndexed(false);
typeDef.setIsControllablePolicy(false);
typeDef.setIsControllableAcl(false);
typeDef.setIsIncludedInSupertypeQuery(true);
typeDef.setIsFileable(false);
String sourceTypeId = cmisMapping.getCmisTypeId(cmisMapping
.getCmisType(cmisAssocDef.getSourceClass().getName()));
if (sourceTypeId != null)
{
typeDef.setAllowedSourceTypes(Collections.singletonList(sourceTypeId));
}
String targetTypeId = cmisMapping.getCmisTypeId(cmisMapping
.getCmisType(cmisAssocDef.getTargetClass().getName()));
if (targetTypeId != null)
{
typeDef.setAllowedTargetTypes(Collections.singletonList(targetTypeId));
}
typeDefInclProperties = CMISUtils.copy(typeDef);
setTypeDefinition(typeDef, typeDefInclProperties);
actionEvaluators = cmisMapping.getActionEvaluators(BaseTypeId.CMIS_RELATIONSHIP);
}
public void connectParentAndSubTypes(CMISMapping cmisMapping, DictionaryRegistry registry,
DictionaryService dictionaryService)
{
// find parent
if (typeDef.getParentTypeId() != null)
{
parent = registry.typeDefsByTypeId.get(typeDef.getParentTypeId());
} else
{
if (!isBaseType())
{
throw new AlfrescoRuntimeException("Type " + typeDef.getId() + " has no parent!");
}
parent = null;
}
// find children
children = new ArrayList<TypeDefinitionWrapper>();
if (isBaseType())
{
for (TypeDefinitionWrapper child : registry.assocDefsByQName.values())
{
children.add(child);
}
}
}
public void resolveInheritance(CMISMapping cmisMapping, ServiceRegistry serviceRegistry,
DictionaryRegistry registry, DictionaryService dictionaryService)
{
PropertyDefinition<?> propertyDefintion;
if (parent != null)
{
for (PropertyDefintionWrapper propDef : parent.getProperties())
{
org.alfresco.service.cmr.dictionary.PropertyDefinition alfrescoPropDef = dictionaryService.getProperty(
propDef.getOwningType().getAlfrescoName(), propDef.getAlfrescoName());
propertyDefintion = createPropertyDefinition(cmisMapping, propDef.getPropertyId(),
alfrescoPropDef.getName(), alfrescoPropDef, true);
if (propertyDefintion != null)
{
registerProperty(new BasePropertyDefintionWrapper(propertyDefintion, alfrescoPropDef.getName(),
propDef.getOwningType(), propDef.getPropertyAccessor(), propDef.getPropertyLuceneBuilder()));
}
}
}
for (TypeDefinitionWrapper child : children)
{
if (child instanceof AbstractTypeDefinitionWrapper)
{
((AbstractTypeDefinitionWrapper) child).resolveInheritance(cmisMapping, serviceRegistry, registry,
dictionaryService);
}
}
}
}

View File

@@ -1,111 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.opencmis.dictionary;
import java.util.ArrayList;
import java.util.Collection;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.opencmis.dictionary.CMISAbstractDictionaryService.DictionaryRegistry;
import org.alfresco.opencmis.mapping.CMISMapping;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.namespace.QName;
import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
public abstract class ShadowTypeDefinitionWrapper extends AbstractTypeDefinitionWrapper
{
private static final long serialVersionUID = 1L;
public void connectParentAndSubTypes(CMISMapping cmisMapping, DictionaryRegistry registry,
DictionaryService dictionaryService)
{
// find parent
if (typeDef.getParentTypeId() != null)
{
parent = registry.typeDefsByTypeId.get(typeDef.getParentTypeId());
} else
{
if (!isBaseType())
{
throw new AlfrescoRuntimeException("Type " + typeDef.getId() + " has no parent!");
}
parent = null;
}
// find children
children = new ArrayList<TypeDefinitionWrapper>();
Collection<QName> childrenNames = dictionaryService.getSubTypes(cmisMapping.getAlfrescoClass(getAlfrescoName()),
false);
for (QName childName : childrenNames)
{
if (cmisMapping.isValidCmisObject(getBaseTypeId(), childName))
{
TypeDefinitionWrapper child = registry.typeDefsByQName.get(childName);
if (child == null)
{
throw new AlfrescoRuntimeException("Failed to retrieve sub type for type id " + childName
+ " for parent type " + getAlfrescoName() + "!");
}
children.add(child);
}
}
}
public void resolveInheritance(CMISMapping cmisMapping, ServiceRegistry serviceRegistry,
DictionaryRegistry registry, DictionaryService dictionaryService)
{
PropertyDefinition<?> propertyDefintion;
if (parent != null)
{
for (PropertyDefintionWrapper propDef : parent.getProperties())
{
if (propertiesById.containsKey(propDef.getPropertyId()))
{
continue;
}
org.alfresco.service.cmr.dictionary.PropertyDefinition alfrescoPropDef = dictionaryService.getProperty(
propDef.getOwningType().getAlfrescoName(), propDef.getAlfrescoName());
propertyDefintion = createPropertyDefinition(cmisMapping, propDef.getPropertyId(),
alfrescoPropDef.getName(), alfrescoPropDef, true);
if (propertyDefintion != null)
{
registerProperty(new BasePropertyDefintionWrapper(propertyDefintion, alfrescoPropDef.getName(),
propDef.getOwningType(), propDef.getPropertyAccessor(), propDef.getPropertyLuceneBuilder()));
}
}
}
for (TypeDefinitionWrapper child : children)
{
if (child instanceof AbstractTypeDefinitionWrapper)
{
((AbstractTypeDefinitionWrapper) child).resolveInheritance(cmisMapping, serviceRegistry, registry,
dictionaryService);
}
}
}
}

View File

@@ -1,58 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.opencmis.dictionary;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.alfresco.opencmis.CMISActionEvaluator;
import org.alfresco.service.namespace.QName;
import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
import org.apache.chemistry.opencmis.commons.enums.Action;
import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
public interface TypeDefinitionWrapper
{
TypeDefinition getTypeDefinition(boolean includePropertyDefinitions);
String getTypeId();
BaseTypeId getBaseTypeId();
boolean isBaseType();
QName getAlfrescoName();
QName getAlfrescoClass();
TypeDefinitionWrapper getParent();
List<TypeDefinitionWrapper> getChildren();
Collection<PropertyDefintionWrapper> getProperties();
PropertyDefintionWrapper getPropertyById(String propertyId);
PropertyDefintionWrapper getPropertyByQueryName(String queryName);
PropertyDefintionWrapper getPropertyByQName(QName name);
Map<Action, CMISActionEvaluator<? extends Object>> getActionEvaluators();
}

View File

@@ -18,7 +18,7 @@
*/
package org.alfresco.opencmis.mapping;
import org.alfresco.opencmis.CMISActionEvaluator;
import org.alfresco.opencmis.dictionary.CMISActionEvaluator;
import org.alfresco.service.ServiceRegistry;
import org.apache.chemistry.opencmis.commons.enums.Action;

View File

@@ -19,19 +19,12 @@
package org.alfresco.opencmis.mapping;
import java.io.Serializable;
import java.util.Collection;
import org.alfresco.cmis.CMISPropertyAccessor;
import org.alfresco.cmis.CMISPropertyLuceneBuilder;
import org.alfresco.repo.search.impl.lucene.LuceneFunction;
import org.alfresco.repo.search.impl.lucene.LuceneQueryParser;
import org.alfresco.repo.search.impl.querymodel.PredicateMode;
import org.alfresco.opencmis.dictionary.CMISPropertyAccessor;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.search.Query;
/**
* Base class for all property accessors
@@ -39,7 +32,7 @@ import org.apache.lucene.search.Query;
* @author andyh
*
*/
public abstract class AbstractProperty implements CMISPropertyAccessor, CMISPropertyLuceneBuilder
public abstract class AbstractProperty implements CMISPropertyAccessor
{
private ServiceRegistry serviceRegistry;
private String propertyName;
@@ -82,72 +75,19 @@ public abstract class AbstractProperty implements CMISPropertyAccessor, CMISProp
return null;
}
public Query buildLuceneEquality(LuceneQueryParser lqp, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
{
return null;
}
public Query buildLuceneExists(LuceneQueryParser lqp, Boolean not) throws ParseException
{
return null;
}
public Query buildLuceneGreaterThan(LuceneQueryParser lqp, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
{
return null;
}
public Query buildLuceneGreaterThanOrEquals(LuceneQueryParser lqp, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
{
return null;
}
public Query buildLuceneIn(LuceneQueryParser lqp, Collection<Serializable> values, Boolean not, PredicateMode mode) throws ParseException
{
return null;
}
public Query buildLuceneInequality(LuceneQueryParser lqp, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
{
return null;
}
public Query buildLuceneLessThan(LuceneQueryParser lqp, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
{
return null;
}
public Query buildLuceneLessThanOrEquals(LuceneQueryParser lqp, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
{
return null;
}
public Query buildLuceneLike(LuceneQueryParser lqp, Serializable value, Boolean not) throws ParseException
{
return null;
}
public String getLuceneFieldName()
{
throw new UnsupportedOperationException();
}
public String getLuceneSortField(LuceneQueryParser lqp)
{
throw new UnsupportedOperationException();
}
@Override
public Serializable getValue(NodeRef nodeRef)
{
throw new UnsupportedOperationException();
}
@Override
public void setValue(NodeRef nodeRef, Serializable value)
{
throw new UnsupportedOperationException();
}
@Override
public Serializable getValue(AssociationRef assocRef)
{
throw new UnsupportedOperationException();

View File

@@ -1,240 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.opencmis.mapping;
import java.io.Serializable;
import java.util.Collection;
import org.alfresco.repo.search.impl.lucene.AnalysisMode;
import org.alfresco.repo.search.impl.lucene.LuceneFunction;
import org.alfresco.repo.search.impl.lucene.LuceneQueryParser;
import org.alfresco.repo.search.impl.querymodel.PredicateMode;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.namespace.QName;
import org.apache.lucene.index.Term;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.BooleanClause.Occur;
/**
* Common support for lucene query building.
*
* @author andyh
*
*/
public abstract class AbstractSimpleProperty extends AbstractProperty
{
protected AbstractSimpleProperty(ServiceRegistry serviceRegistry, String propertyName)
{
super(serviceRegistry, propertyName);
}
protected abstract String getValueAsString(Serializable value);
protected String getRangeMax()
{
return "\uFFFF";
}
protected String getRangeMin()
{
return "\u0000";
}
protected abstract DataTypeDefinition getInDataType();
protected abstract QName getQNameForExists();
/*
* (non-Javadoc)
* @see org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneEquality(org.alfresco.repo.search.impl.lucene.LuceneQueryParser, java.io.Serializable, org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneEquality(LuceneQueryParser lqp, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
{
return lqp.getFieldQuery(getLuceneFieldName(), getValueAsString(value), AnalysisMode.IDENTIFIER, luceneFunction);
}
/*
* (non-Javadoc)
* @see org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneExists(org.alfresco.repo.search.impl.lucene.LuceneQueryParser, java.lang.Boolean)
*/
public Query buildLuceneExists(LuceneQueryParser lqp, Boolean not) throws ParseException
{
if (not)
{
return lqp.getFieldQuery("ISNULL", getQNameForExists().toString(), AnalysisMode.DEFAULT, LuceneFunction.FIELD);
}
else
{
return lqp.getFieldQuery("ISNOTNULL", getQNameForExists().toString(), AnalysisMode.DEFAULT, LuceneFunction.FIELD);
}
}
/*
* (non-Javadoc)
* @see org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneGreaterThan(org.alfresco.repo.search.impl.lucene.LuceneQueryParser, java.io.Serializable, org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneGreaterThan(LuceneQueryParser lqp, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
{
String field = getLuceneFieldName();
String stringValue = getValueAsString(value);
return lqp.getRangeQuery(field, stringValue, getRangeMax(), false, true, AnalysisMode.IDENTIFIER, luceneFunction);
}
/*
* (non-Javadoc)
* @see org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneGreaterThanOrEquals(org.alfresco.repo.search.impl.lucene.LuceneQueryParser, java.io.Serializable, org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneGreaterThanOrEquals(LuceneQueryParser lqp, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
{
String field = getLuceneFieldName();
String stringValue = getValueAsString(value);
return lqp.getRangeQuery(field, stringValue, getRangeMax(), true, true, AnalysisMode.IDENTIFIER, luceneFunction);
}
/*
* (non-Javadoc)
* @see org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneIn(org.alfresco.repo.search.impl.lucene.LuceneQueryParser, java.util.Collection, java.lang.Boolean, org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneIn(LuceneQueryParser lqp, Collection<Serializable> values, Boolean not, PredicateMode mode) throws ParseException
{
String field = getLuceneFieldName();
// Check type conversion
@SuppressWarnings("unused")
Object converted = DefaultTypeConverter.INSTANCE.convert(getInDataType(), values);
Collection<String> asStrings = DefaultTypeConverter.INSTANCE.convert(String.class, values);
if (asStrings.size() == 0)
{
if (not)
{
return new MatchAllDocsQuery();
}
else
{
return new TermQuery(new Term("NO_TOKENS", "__"));
}
}
else if (asStrings.size() == 1)
{
String value = asStrings.iterator().next();
if (not)
{
return lqp.getDoesNotMatchFieldQuery(field, value, AnalysisMode.IDENTIFIER, LuceneFunction.FIELD);
}
else
{
return lqp.getFieldQuery(field, value, AnalysisMode.IDENTIFIER, LuceneFunction.FIELD);
}
}
else
{
BooleanQuery booleanQuery = new BooleanQuery();
if (not)
{
booleanQuery.add(new MatchAllDocsQuery(), Occur.MUST);
}
for (String value : asStrings)
{
Query any = lqp.getFieldQuery(field, value, AnalysisMode.IDENTIFIER, LuceneFunction.FIELD);
if (not)
{
booleanQuery.add(any, Occur.MUST_NOT);
}
else
{
booleanQuery.add(any, Occur.SHOULD);
}
}
return booleanQuery;
}
}
/*
* (non-Javadoc)
* @see org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneInequality(org.alfresco.repo.search.impl.lucene.LuceneQueryParser, java.io.Serializable, org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneInequality(LuceneQueryParser lqp, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
{
String field = getLuceneFieldName();
String stringValue = getValueAsString(value);
return lqp.getDoesNotMatchFieldQuery(field, stringValue, AnalysisMode.IDENTIFIER, luceneFunction);
}
/*
* (non-Javadoc)
* @see org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneLessThan(org.alfresco.repo.search.impl.lucene.LuceneQueryParser, java.io.Serializable, org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneLessThan(LuceneQueryParser lqp, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
{
String field = getLuceneFieldName();
String stringValue = getValueAsString(value);
return lqp.getRangeQuery(field, getRangeMin(), stringValue, true, false, AnalysisMode.IDENTIFIER, luceneFunction);
}
/*
* (non-Javadoc)
* @see org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneLessThanOrEquals(org.alfresco.repo.search.impl.lucene.LuceneQueryParser, java.io.Serializable, org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneLessThanOrEquals(LuceneQueryParser lqp, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
{
String field = getLuceneFieldName();
String stringValue = getValueAsString(value);
return lqp.getRangeQuery(field, getRangeMin(), stringValue, true, true, AnalysisMode.IDENTIFIER, luceneFunction);
}
/*
* (non-Javadoc)
* @see org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneLike(org.alfresco.repo.search.impl.lucene.LuceneQueryParser, java.io.Serializable, java.lang.Boolean)
*/
public Query buildLuceneLike(LuceneQueryParser lqp, Serializable value, Boolean not) throws ParseException
{
String field = getLuceneFieldName();
String stringValue = getValueAsString(value);
if (not)
{
BooleanQuery booleanQuery = new BooleanQuery();
booleanQuery.add(new MatchAllDocsQuery(), Occur.MUST);
booleanQuery.add(lqp.getLikeQuery(field, stringValue, AnalysisMode.IDENTIFIER), Occur.MUST_NOT);
return booleanQuery;
}
else
{
return lqp.getLikeQuery(field, stringValue, AnalysisMode.IDENTIFIER);
}
}
/*
* (non-Javadoc)
* @see org.alfresco.cmis.property.PropertyLuceneBuilder#getLuceneSortField()
*/
public String getLuceneSortField(LuceneQueryParser lqp)
{
return getLuceneFieldName();
}
}

View File

@@ -19,28 +19,14 @@
package org.alfresco.opencmis.mapping;
import java.io.Serializable;
import java.util.Collection;
import org.alfresco.cmis.CMISQueryException;
import org.alfresco.cmis.CMISScope;
import org.alfresco.cmis.CMISTypeDefinition;
import org.alfresco.repo.search.impl.lucene.AnalysisMode;
import org.alfresco.repo.search.impl.lucene.LuceneFunction;
import org.alfresco.repo.search.impl.lucene.LuceneQueryParser;
import org.alfresco.repo.search.impl.querymodel.PredicateMode;
import org.alfresco.opencmis.dictionary.CMISDictionaryService;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.namespace.QName;
import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.lucene.index.Term;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.search.BooleanClause.Occur;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
/**
* Get the CMIS object type id property
@@ -49,14 +35,17 @@ import org.apache.lucene.search.TermQuery;
*/
public class BaseTypeIdProperty extends AbstractProperty
{
private CMISDictionaryService dictionaryService;
/**
* Construct
*
* @param serviceRegistry
*/
public BaseTypeIdProperty(ServiceRegistry serviceRegistry)
public BaseTypeIdProperty(ServiceRegistry serviceRegistry, CMISDictionaryService dictionaryService)
{
super(serviceRegistry, PropertyIds.BASE_TYPE_ID);
this.dictionaryService = dictionaryService;
}
/*
@@ -66,7 +55,7 @@ public class BaseTypeIdProperty extends AbstractProperty
public Serializable getValue(NodeRef nodeRef)
{
QName type = getServiceRegistry().getNodeService().getType(nodeRef);
return getServiceRegistry().getCMISDictionaryService().findTypeForClass(type).getBaseType().getTypeId().getId();
return dictionaryService.findTypeForClass(type).getBaseTypeId().value();
}
/*
@@ -75,113 +64,6 @@ public class BaseTypeIdProperty extends AbstractProperty
*/
public Serializable getValue(AssociationRef assocRef)
{
QName type = assocRef.getTypeQName();
return getServiceRegistry().getCMISDictionaryService().findTypeForClass(type, CMISScope.RELATIONSHIP).getBaseType().getTypeId().getId();
}
@Override
public Query buildLuceneEquality(LuceneQueryParser lqp, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
{
return lqp.getFieldQuery("TYPE", getBaseType(getValueAsString(value)), AnalysisMode.IDENTIFIER, luceneFunction);
}
@Override
public Query buildLuceneInequality(LuceneQueryParser lqp, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
{
return lqp.getDoesNotMatchFieldQuery("TYPE", getBaseType(getValueAsString(value)), AnalysisMode.IDENTIFIER, luceneFunction);
}
@Override
public Query buildLuceneIn(LuceneQueryParser lqp, Collection<Serializable> values, Boolean not, PredicateMode mode) throws ParseException
{
String field = "TYPE";
// Check type conversion
Collection<String> asStrings = DefaultTypeConverter.INSTANCE.convert(String.class, values);
if (asStrings.size() == 0)
{
if (not)
{
return new MatchAllDocsQuery();
}
else
{
return new TermQuery(new Term("NO_TOKENS", "__"));
}
}
else if (asStrings.size() == 1)
{
String value = asStrings.iterator().next();
if (not)
{
return lqp.getDoesNotMatchFieldQuery(field, getBaseType(value), AnalysisMode.IDENTIFIER, LuceneFunction.FIELD);
}
else
{
return lqp.getFieldQuery(field, getBaseType(value), AnalysisMode.IDENTIFIER, LuceneFunction.FIELD);
}
}
else
{
BooleanQuery booleanQuery = new BooleanQuery();
if (not)
{
booleanQuery.add(new MatchAllDocsQuery(), Occur.MUST);
}
for (String value : asStrings)
{
Query any = lqp.getFieldQuery(field, getBaseType(value), AnalysisMode.IDENTIFIER, LuceneFunction.FIELD);
if (not)
{
booleanQuery.add(any, Occur.MUST_NOT);
}
else
{
booleanQuery.add(any, Occur.SHOULD);
}
}
return booleanQuery;
}
}
@Override
public Query buildLuceneExists(LuceneQueryParser lqp, Boolean not) throws ParseException
{
if (not)
{
return new TermQuery(new Term("NO_TOKENS", "__"));
}
else
{
return new MatchAllDocsQuery();
}
}
private String getBaseType(String tableName)
{
CMISTypeDefinition typeDef = getServiceRegistry().getCMISDictionaryService().findTypeByQueryName(tableName);
if (typeDef == null)
{
throw new CMISQueryException("Unknwon base type: " + tableName);
}
if(!typeDef.getBaseType().equals(typeDef))
{
throw new CMISQueryException("Not a base type: " + tableName);
}
if(!typeDef.isQueryable())
{
throw new CMISQueryException("Base type is not queryable: " + tableName);
}
return typeDef.getTypeId().getQName().toString();
}
private String getValueAsString(Serializable value)
{
String asString = DefaultTypeConverter.INSTANCE.convert(String.class, value);
return asString;
return BaseTypeId.CMIS_RELATIONSHIP.value();
}
}

View File

@@ -1,871 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.opencmis.mapping;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import org.alfresco.cmis.CMISAccessControlFormatEnum;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.opencmis.CMISActionEvaluator;
import org.alfresco.opencmis.CMISConnector;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.AspectDefinition;
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.Pair;
import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.chemistry.opencmis.commons.enums.Action;
import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
import org.apache.chemistry.opencmis.commons.enums.PropertyType;
import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean;
/**
* CMIS <-> Alfresco mappings
*
* @author andyh
*/
public class CMISMapping implements InitializingBean
{
// Logger
protected static final Log logger = LogFactory.getLog(CMISMapping.class);
/**
* The Alfresco CMIS Namespace
*/
public static String CMIS_MODEL_NS = "cmis";
public static String CMIS_MODEL_URI = "http://www.alfresco.org/model/cmis/1.0/cs01";
public static String CMIS_EXT_NS = "cmisext";
public static String CMIS_EXT_URI = "http://www.alfresco.org/model/cmis/1.0/cs01ext";
/**
* The Alfresco CMIS Model name.
*/
public static String CMIS_MODEL_NAME = "cmismodel";
/**
* The QName for the Alfresco CMIS Model.
*/
public static QName CMIS_MODEL_QNAME = QName.createQName(CMIS_MODEL_URI, CMIS_MODEL_NAME);
// CMIS Data Types
public static QName CMIS_DATATYPE_ID = QName.createQName(CMIS_MODEL_URI, "id");
public static QName CMIS_DATATYPE_URI = QName.createQName(CMIS_MODEL_URI, "uri");
public static QName CMIS_DATATYPE_XML = QName.createQName(CMIS_MODEL_URI, "xml");
public static QName CMIS_DATATYPE_HTML = QName.createQName(CMIS_MODEL_URI, "html");
// CMIS Types
public static QName OBJECT_QNAME = QName.createQName(CMIS_EXT_URI, "object");
public static QName DOCUMENT_QNAME = QName.createQName(CMIS_MODEL_URI, "document");
public static QName FOLDER_QNAME = QName.createQName(CMIS_MODEL_URI, "folder");
public static QName RELATIONSHIP_QNAME = QName.createQName(CMIS_MODEL_URI, "relationship");
public static QName POLICY_QNAME = QName.createQName(CMIS_MODEL_URI, "policy");
public static QName ASPECTS_QNAME = QName.createQName(CMIS_EXT_URI, "aspects");
// CMIS Internal Type Ids
public static String OBJECT_TYPE_ID = "cmisext:object";
/**
* Basic permissions.
*/
public static final String CMIS_READ = "cmis:read";
public static final String CMIS_WRITE = "cmis:write";
public static final String CMIS_ALL = "cmis:all";
// Service Dependencies
private ServiceRegistry serviceRegistry;
private CMISConnector cmisConnector;
// Mappings
private Map<QName, String> mapAlfrescoQNameToTypeId = new HashMap<QName, String>();
private Map<QName, QName> mapCmisQNameToAlfrescoQName = new HashMap<QName, QName>();
private Map<QName, QName> mapAlfrescoQNameToCmisQName = new HashMap<QName, QName>();
private Map<QName, PropertyType> mapAlfrescoToCmisDataType = new HashMap<QName, PropertyType>();
private Map<PropertyType, QName> mapCmisDataTypeToAlfresco = new HashMap<PropertyType, QName>();
private Map<String, AbstractProperty> propertyAccessors = new HashMap<String, AbstractProperty>();
private Map<BaseTypeId, Map<Action, CMISActionEvaluator<? extends Object>>> actionEvaluators = new HashMap<BaseTypeId, Map<Action, CMISActionEvaluator<? extends Object>>>();
/*
* (non-Javadoc)
*
* @see
* org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/
public void afterPropertiesSet() throws Exception
{
//
// Type Mappings
//
mapAlfrescoQNameToTypeId.put(OBJECT_QNAME, OBJECT_TYPE_ID);
mapAlfrescoQNameToTypeId.put(DOCUMENT_QNAME, BaseTypeId.CMIS_DOCUMENT.value());
mapAlfrescoQNameToTypeId.put(FOLDER_QNAME, BaseTypeId.CMIS_FOLDER.value());
mapAlfrescoQNameToTypeId.put(RELATIONSHIP_QNAME, BaseTypeId.CMIS_RELATIONSHIP.value());
mapAlfrescoQNameToTypeId.put(POLICY_QNAME, BaseTypeId.CMIS_POLICY.value());
mapAlfrescoQNameToCmisQName.put(ContentModel.TYPE_CONTENT, DOCUMENT_QNAME);
mapAlfrescoQNameToCmisQName.put(ContentModel.TYPE_FOLDER, FOLDER_QNAME);
mapCmisQNameToAlfrescoQName.put(DOCUMENT_QNAME, ContentModel.TYPE_CONTENT);
mapCmisQNameToAlfrescoQName.put(FOLDER_QNAME, ContentModel.TYPE_FOLDER);
mapCmisQNameToAlfrescoQName.put(RELATIONSHIP_QNAME, null);
mapCmisQNameToAlfrescoQName.put(POLICY_QNAME, null);
//
// Data Type Mappings
//
mapAlfrescoToCmisDataType.put(DataTypeDefinition.ANY, null);
mapAlfrescoToCmisDataType.put(DataTypeDefinition.ASSOC_REF, null);
mapAlfrescoToCmisDataType.put(DataTypeDefinition.BOOLEAN, PropertyType.BOOLEAN);
mapAlfrescoToCmisDataType.put(DataTypeDefinition.CATEGORY, PropertyType.ID);
mapAlfrescoToCmisDataType.put(DataTypeDefinition.CHILD_ASSOC_REF, null);
mapAlfrescoToCmisDataType.put(DataTypeDefinition.CONTENT, null);
mapAlfrescoToCmisDataType.put(DataTypeDefinition.DATE, PropertyType.DATETIME);
mapAlfrescoToCmisDataType.put(DataTypeDefinition.DATETIME, PropertyType.DATETIME);
mapAlfrescoToCmisDataType.put(DataTypeDefinition.DOUBLE, PropertyType.DECIMAL);
mapAlfrescoToCmisDataType.put(DataTypeDefinition.FLOAT, PropertyType.DECIMAL);
mapAlfrescoToCmisDataType.put(DataTypeDefinition.INT, PropertyType.INTEGER);
mapAlfrescoToCmisDataType.put(DataTypeDefinition.LOCALE, null);
mapAlfrescoToCmisDataType.put(DataTypeDefinition.PERIOD, null);
mapAlfrescoToCmisDataType.put(DataTypeDefinition.LONG, PropertyType.INTEGER);
mapAlfrescoToCmisDataType.put(DataTypeDefinition.MLTEXT, PropertyType.STRING);
mapAlfrescoToCmisDataType.put(DataTypeDefinition.NODE_REF, PropertyType.ID);
mapAlfrescoToCmisDataType.put(DataTypeDefinition.PATH, null);
mapAlfrescoToCmisDataType.put(DataTypeDefinition.QNAME, null);
mapAlfrescoToCmisDataType.put(DataTypeDefinition.TEXT, PropertyType.STRING);
mapAlfrescoToCmisDataType.put(CMIS_DATATYPE_ID, PropertyType.ID);
mapAlfrescoToCmisDataType.put(CMIS_DATATYPE_URI, PropertyType.URI);
mapAlfrescoToCmisDataType.put(CMIS_DATATYPE_HTML, PropertyType.HTML);
mapCmisDataTypeToAlfresco.put(PropertyType.ID, DataTypeDefinition.TEXT);
mapCmisDataTypeToAlfresco.put(PropertyType.INTEGER, DataTypeDefinition.LONG);
mapCmisDataTypeToAlfresco.put(PropertyType.STRING, DataTypeDefinition.TEXT);
mapCmisDataTypeToAlfresco.put(PropertyType.DECIMAL, DataTypeDefinition.DOUBLE);
mapCmisDataTypeToAlfresco.put(PropertyType.BOOLEAN, DataTypeDefinition.BOOLEAN);
mapCmisDataTypeToAlfresco.put(PropertyType.DATETIME, DataTypeDefinition.DATETIME);
mapCmisDataTypeToAlfresco.put(PropertyType.URI, DataTypeDefinition.TEXT);
mapCmisDataTypeToAlfresco.put(PropertyType.HTML, DataTypeDefinition.TEXT);
//
// Property Mappings
//
registerPropertyAccessor(new ObjectIdProperty(serviceRegistry));
registerPropertyAccessor(new NodeRefProperty(serviceRegistry));
registerPropertyAccessor(new ObjectTypeIdProperty(serviceRegistry));
registerPropertyAccessor(new BaseTypeIdProperty(serviceRegistry));
registerPropertyAccessor(new DirectProperty(serviceRegistry, PropertyIds.CREATED_BY, ContentModel.PROP_CREATOR));
registerPropertyAccessor(new DirectProperty(serviceRegistry, PropertyIds.CREATION_DATE,
ContentModel.PROP_CREATED));
registerPropertyAccessor(new DirectProperty(serviceRegistry, PropertyIds.LAST_MODIFIED_BY,
ContentModel.PROP_MODIFIER));
registerPropertyAccessor(new DirectProperty(serviceRegistry, PropertyIds.LAST_MODIFICATION_DATE,
ContentModel.PROP_MODIFIED));
registerPropertyAccessor(new FixedValueProperty(serviceRegistry, PropertyIds.CHANGE_TOKEN, null));
registerPropertyAccessor(new DirectProperty(serviceRegistry, PropertyIds.NAME, ContentModel.PROP_NAME)
{
@Override
public Serializable getValue(AssociationRef assocRef)
{
// Let's use the association ref as the name
return assocRef.toString();
}
});
registerPropertyAccessor(new IsImmutableProperty(serviceRegistry));
registerPropertyAccessor(new IsLatestVersionProperty(serviceRegistry));
registerPropertyAccessor(new IsMajorVersionProperty(serviceRegistry));
registerPropertyAccessor(new IsLatestMajorVersionProperty(serviceRegistry));
registerPropertyAccessor(new VersionLabelProperty(serviceRegistry));
registerPropertyAccessor(new VersionSeriesIdProperty(serviceRegistry));
registerPropertyAccessor(new IsVersionSeriesCheckedOutProperty(serviceRegistry));
registerPropertyAccessor(new VersionSeriesCheckedOutByProperty(serviceRegistry));
registerPropertyAccessor(new VersionSeriesCheckedOutIdProperty(serviceRegistry));
registerPropertyAccessor(new CheckinCommentProperty(serviceRegistry));
registerPropertyAccessor(new ContentStreamLengthProperty(serviceRegistry));
registerPropertyAccessor(new ContentStreamMimetypeProperty(serviceRegistry));
registerPropertyAccessor(new ContentStreamIdProperty(serviceRegistry));
registerPropertyAccessor(new DirectProperty(serviceRegistry, PropertyIds.CONTENT_STREAM_FILE_NAME,
ContentModel.PROP_NAME));
registerPropertyAccessor(new ParentProperty(serviceRegistry));
registerPropertyAccessor(new PathProperty(serviceRegistry, cmisConnector));
registerPropertyAccessor(new AllowedChildObjectTypeIdsProperty(serviceRegistry, this));
registerPropertyAccessor(new SourceIdProperty(serviceRegistry));
registerPropertyAccessor(new TargetIdProperty(serviceRegistry));
//
// Action Evaluator Mappings
//
// NOTE: The order of evaluators is important - they must be in the
// order as specified in CMIS-Core.xsd
// so that schema validation passes
registerEvaluator(BaseTypeId.CMIS_DOCUMENT,
new CurrentVersionEvaluator(serviceRegistry, new PermissionActionEvaluator(serviceRegistry,
Action.CAN_DELETE_OBJECT, PermissionService.DELETE_NODE), false));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new CurrentVersionEvaluator(serviceRegistry,
new PermissionActionEvaluator(serviceRegistry, Action.CAN_UPDATE_PROPERTIES,
PermissionService.WRITE_PROPERTIES), false));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new PermissionActionEvaluator(serviceRegistry,
Action.CAN_GET_PROPERTIES, PermissionService.READ_PROPERTIES));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_GET_OBJECT_RELATIONSHIPS, true));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new ParentActionEvaluator(new PermissionActionEvaluator(
serviceRegistry, Action.CAN_GET_OBJECT_PARENTS, PermissionService.READ_PERMISSIONS)));
// Is CAN_MOVE correct mapping?
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new CurrentVersionEvaluator(serviceRegistry,
new PermissionActionEvaluator(serviceRegistry, Action.CAN_MOVE_OBJECT, PermissionService.DELETE_NODE),
false));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new CurrentVersionEvaluator(serviceRegistry,
new PermissionActionEvaluator(serviceRegistry, Action.CAN_DELETE_CONTENT_STREAM,
PermissionService.WRITE_PROPERTIES, PermissionService.WRITE_CONTENT), false));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new CurrentVersionEvaluator(serviceRegistry,
new CanCheckOutActionEvaluator(serviceRegistry), false));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new CurrentVersionEvaluator(serviceRegistry,
new PermissionActionEvaluator(serviceRegistry, Action.CAN_CANCEL_CHECK_OUT,
PermissionService.CANCEL_CHECK_OUT), false));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new PermissionActionEvaluator(serviceRegistry, Action.CAN_CHECK_IN,
PermissionService.CHECK_IN));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new CurrentVersionEvaluator(serviceRegistry,
new PermissionActionEvaluator(serviceRegistry, Action.CAN_SET_CONTENT_STREAM,
PermissionService.WRITE_CONTENT), false));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_GET_ALL_VERSIONS, true));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new CurrentVersionEvaluator(serviceRegistry,
new ParentActionEvaluator(new PermissionActionEvaluator(serviceRegistry,
Action.CAN_ADD_OBJECT_TO_FOLDER, PermissionService.LINK_CHILDREN)), false));
// Is CAN_REMOVE_FROM_FOLDER correct mapping?
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new CurrentVersionEvaluator(serviceRegistry,
new ParentActionEvaluator(new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_REMOVE_OBJECT_FROM_FOLDER, true)), false));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new PermissionActionEvaluator(serviceRegistry,
Action.CAN_GET_CONTENT_STREAM, PermissionService.READ_CONTENT));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_APPLY_POLICY, false));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_GET_APPLIED_POLICIES, true));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_REMOVE_POLICY, false));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new CurrentVersionEvaluator(serviceRegistry,
new FixedValueActionEvaluator<NodeRef>(serviceRegistry, Action.CAN_CREATE_RELATIONSHIP, true), false));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_GET_RENDITIONS, true));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new PermissionActionEvaluator(serviceRegistry, Action.CAN_GET_ACL,
PermissionService.READ_PERMISSIONS));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new CurrentVersionEvaluator(serviceRegistry,
new PermissionActionEvaluator(serviceRegistry, Action.CAN_APPLY_ACL,
PermissionService.CHANGE_PERMISSIONS), false));
registerEvaluator(BaseTypeId.CMIS_FOLDER,
new RootFolderEvaluator(serviceRegistry, cmisConnector, new PermissionActionEvaluator(serviceRegistry,
Action.CAN_DELETE_OBJECT, PermissionService.DELETE_NODE), false));
registerEvaluator(BaseTypeId.CMIS_FOLDER, new PermissionActionEvaluator(serviceRegistry,
Action.CAN_UPDATE_PROPERTIES, PermissionService.WRITE_PROPERTIES));
registerEvaluator(BaseTypeId.CMIS_FOLDER, new PermissionActionEvaluator(serviceRegistry,
Action.CAN_GET_FOLDER_TREE, PermissionService.READ_CHILDREN));
registerEvaluator(BaseTypeId.CMIS_FOLDER, new PermissionActionEvaluator(serviceRegistry,
Action.CAN_GET_PROPERTIES, PermissionService.READ_PROPERTIES));
registerEvaluator(BaseTypeId.CMIS_FOLDER, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_GET_OBJECT_RELATIONSHIPS, true));
registerEvaluator(BaseTypeId.CMIS_FOLDER, new ParentActionEvaluator(new PermissionActionEvaluator(
serviceRegistry, Action.CAN_GET_OBJECT_PARENTS, PermissionService.READ_PERMISSIONS)));
registerEvaluator(BaseTypeId.CMIS_FOLDER, new RootFolderEvaluator(serviceRegistry, cmisConnector,
new ParentActionEvaluator(new PermissionActionEvaluator(serviceRegistry, Action.CAN_GET_FOLDER_PARENT,
PermissionService.READ_PERMISSIONS)), false));
registerEvaluator(BaseTypeId.CMIS_FOLDER, new PermissionActionEvaluator(serviceRegistry,
Action.CAN_GET_DESCENDANTS, PermissionService.READ_CHILDREN));
// Is CAN_MOVE_OBJECT correct mapping?
registerEvaluator(BaseTypeId.CMIS_FOLDER, new RootFolderEvaluator(serviceRegistry, cmisConnector,
new PermissionActionEvaluator(serviceRegistry, Action.CAN_MOVE_OBJECT, PermissionService.DELETE_NODE),
false));
registerEvaluator(BaseTypeId.CMIS_FOLDER, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_APPLY_POLICY, false));
registerEvaluator(BaseTypeId.CMIS_FOLDER, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_GET_APPLIED_POLICIES, true));
registerEvaluator(BaseTypeId.CMIS_FOLDER, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_REMOVE_POLICY, false));
registerEvaluator(BaseTypeId.CMIS_FOLDER, new PermissionActionEvaluator(serviceRegistry,
Action.CAN_GET_CHILDREN, PermissionService.READ_CHILDREN));
registerEvaluator(BaseTypeId.CMIS_FOLDER, new PermissionActionEvaluator(serviceRegistry,
Action.CAN_CREATE_DOCUMENT, PermissionService.CREATE_CHILDREN));
registerEvaluator(BaseTypeId.CMIS_FOLDER, new PermissionActionEvaluator(serviceRegistry,
Action.CAN_CREATE_FOLDER, PermissionService.CREATE_CHILDREN));
registerEvaluator(BaseTypeId.CMIS_FOLDER, new PermissionActionEvaluator(serviceRegistry,
Action.CAN_CREATE_RELATIONSHIP, PermissionService.CREATE_ASSOCIATIONS));
registerEvaluator(BaseTypeId.CMIS_FOLDER, new RootFolderEvaluator(serviceRegistry, cmisConnector,
new PermissionActionEvaluator(serviceRegistry, Action.CAN_DELETE_TREE, PermissionService.DELETE_NODE),
false));
registerEvaluator(BaseTypeId.CMIS_FOLDER, new PermissionActionEvaluator(serviceRegistry, Action.CAN_GET_ACL,
PermissionService.READ_PERMISSIONS));
registerEvaluator(BaseTypeId.CMIS_FOLDER, new PermissionActionEvaluator(serviceRegistry, Action.CAN_APPLY_ACL,
PermissionService.CHANGE_PERMISSIONS));
registerEvaluator(BaseTypeId.CMIS_RELATIONSHIP, new FixedValueActionEvaluator<AssociationRef>(serviceRegistry,
Action.CAN_DELETE_OBJECT, true));
registerEvaluator(BaseTypeId.CMIS_RELATIONSHIP, new FixedValueActionEvaluator<AssociationRef>(serviceRegistry,
Action.CAN_UPDATE_PROPERTIES, false));
registerEvaluator(BaseTypeId.CMIS_RELATIONSHIP, new FixedValueActionEvaluator<AssociationRef>(serviceRegistry,
Action.CAN_GET_PROPERTIES, true));
registerEvaluator(BaseTypeId.CMIS_RELATIONSHIP, new FixedValueActionEvaluator<AssociationRef>(serviceRegistry,
Action.CAN_GET_ACL, false));
registerEvaluator(BaseTypeId.CMIS_RELATIONSHIP, new FixedValueActionEvaluator<AssociationRef>(serviceRegistry,
Action.CAN_APPLY_ACL, false));
registerEvaluator(BaseTypeId.CMIS_POLICY, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_DELETE_OBJECT, false));
registerEvaluator(BaseTypeId.CMIS_POLICY, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_UPDATE_PROPERTIES, false));
registerEvaluator(BaseTypeId.CMIS_POLICY, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_GET_PROPERTIES, false));
registerEvaluator(BaseTypeId.CMIS_POLICY, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_GET_OBJECT_PARENTS, false));
registerEvaluator(BaseTypeId.CMIS_POLICY, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_MOVE_OBJECT, false));
registerEvaluator(BaseTypeId.CMIS_POLICY, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_ADD_OBJECT_TO_FOLDER, false));
registerEvaluator(BaseTypeId.CMIS_POLICY, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_REMOVE_OBJECT_FROM_FOLDER, false));
registerEvaluator(BaseTypeId.CMIS_POLICY, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_GET_OBJECT_RELATIONSHIPS, false));
registerEvaluator(BaseTypeId.CMIS_POLICY, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_GET_ACL, false));
registerEvaluator(BaseTypeId.CMIS_POLICY, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_APPLY_ACL, false));
}
/**
* @param serviceRegistry
*/
public void setServiceRegistry(ServiceRegistry serviceRegistry)
{
this.serviceRegistry = serviceRegistry;
}
public void setCmisConnector(CMISConnector cmisConnector)
{
this.cmisConnector = cmisConnector;
}
/**
* @return namespaceService
*/
/* package */NamespaceService getNamespaceService()
{
return serviceRegistry.getNamespaceService();
}
/**
* Gets the CMIS Type Id given the Alfresco QName for the type in any
* Alfresco model
*
* @param typeQName
* @return
*/
public String getCmisTypeId(BaseTypeId scope, QName typeQName)
{
String typeId = mapAlfrescoQNameToTypeId.get(typeQName);
if (typeId == null)
{
String p = null;
switch (scope)
{
case CMIS_DOCUMENT:
p = "D";
break;
case CMIS_FOLDER:
p = "F";
break;
case CMIS_RELATIONSHIP:
p = "R";
break;
case CMIS_POLICY:
p = "P";
break;
default:
throw new CmisRuntimeException("Invalid base type!");
}
return p + ":" + typeQName.toPrefixString(serviceRegistry.getNamespaceService());
} else
{
return typeId;
}
}
public String getCmisTypeId(QName classQName)
{
if (classQName.equals(ContentModel.TYPE_CONTENT))
{
return getCmisTypeId(BaseTypeId.CMIS_DOCUMENT, classQName);
}
if (classQName.equals(ContentModel.TYPE_FOLDER))
{
return getCmisTypeId(BaseTypeId.CMIS_FOLDER, classQName);
}
if (classQName.equals(CMISMapping.RELATIONSHIP_QNAME))
{
return getCmisTypeId(BaseTypeId.CMIS_RELATIONSHIP, classQName);
}
if (classQName.equals(CMISMapping.POLICY_QNAME))
{
return getCmisTypeId(BaseTypeId.CMIS_POLICY, classQName);
}
if (classQName.equals(CMISMapping.ASPECTS_QNAME))
{
return getCmisTypeId(BaseTypeId.CMIS_POLICY, classQName);
}
if (isValidCmisDocument(classQName))
{
return getCmisTypeId(BaseTypeId.CMIS_DOCUMENT, classQName);
}
if (isValidCmisFolder(classQName))
{
return getCmisTypeId(BaseTypeId.CMIS_FOLDER, classQName);
}
if (isValidCmisRelationship(classQName))
{
return getCmisTypeId(BaseTypeId.CMIS_RELATIONSHIP, classQName);
}
if (isValidCmisPolicy(classQName))
{
return getCmisTypeId(BaseTypeId.CMIS_POLICY, classQName);
}
return null;
}
public String buildPrefixEncodedString(QName qname)
{
return qname.toPrefixString(serviceRegistry.getNamespaceService());
}
public QName getAlfrescoName(String typeId)
{
// Is it an Alfresco type id?
if (typeId.length() < 4 || typeId.charAt(1) != ':')
{
throw new CmisInvalidArgumentException("Malformed type id '" + typeId + "'");
}
return QName.createQName(typeId.substring(2), serviceRegistry.getNamespaceService());
}
/**
* Is this a valid cmis document or folder type (not a relationship)
*
* @param dictionaryService
* @param typeQName
* @return
*/
public boolean isValidCmisDocumentOrFolder(QName typeQName)
{
return isValidCmisFolder(typeQName) || isValidCmisDocument(typeQName);
}
public boolean isValidCmisObject(BaseTypeId scope, QName qname)
{
switch (scope)
{
case CMIS_DOCUMENT:
return isValidCmisDocument(qname);
case CMIS_FOLDER:
return isValidCmisFolder(qname);
case CMIS_POLICY:
return isValidCmisPolicy(qname);
case CMIS_RELATIONSHIP:
return isValidCmisRelationship(qname);
}
return false;
}
/**
* Is this a valid CMIS folder type?
*
* @param dictionaryService
* @param typeQName
* @return
*/
public boolean isValidCmisFolder(QName typeQName)
{
if (typeQName == null)
{
return false;
}
if (typeQName.equals(FOLDER_QNAME))
{
return true;
}
if (serviceRegistry.getDictionaryService().isSubClass(typeQName, ContentModel.TYPE_FOLDER))
{
if (typeQName.equals(ContentModel.TYPE_FOLDER))
{
return false;
} else
{
return true;
}
}
return false;
}
/**
* Is this a valid CMIS document type?
*
* @param dictionaryService
* @param typeQName
* @return
*/
public boolean isValidCmisDocument(QName typeQName)
{
if (typeQName == null)
{
return false;
}
if (typeQName.equals(DOCUMENT_QNAME))
{
return true;
}
if (serviceRegistry.getDictionaryService().isSubClass(typeQName, ContentModel.TYPE_CONTENT))
{
if (typeQName.equals(ContentModel.TYPE_CONTENT))
{
return false;
} else
{
return true;
}
}
return false;
}
/**
* Is this a valid CMIS policy type?
*
* @param dictionaryService
* @param typeQName
* @return
*/
public boolean isValidCmisPolicy(QName typeQName)
{
if (typeQName == null)
{
return false;
}
if (typeQName.equals(POLICY_QNAME))
{
return true;
}
if (typeQName.equals(ASPECTS_QNAME))
{
return true;
}
AspectDefinition aspectDef = serviceRegistry.getDictionaryService().getAspect(typeQName);
if (aspectDef == null)
{
return false;
}
if (aspectDef.getName().equals(ContentModel.ASPECT_VERSIONABLE)
|| aspectDef.getName().equals(ContentModel.ASPECT_AUDITABLE)
|| aspectDef.getName().equals(ContentModel.ASPECT_REFERENCEABLE))
{
return false;
}
return true;
}
/**
* Is an association valid in CMIS? It must be a non-child relationship and
* the source and target must both be valid CMIS types.
*
* @param dictionaryService
* @param associationQName
* @return
*/
public boolean isValidCmisRelationship(QName associationQName)
{
if (associationQName == null)
{
return false;
}
if (associationQName.equals(RELATIONSHIP_QNAME))
{
return true;
}
AssociationDefinition associationDefinition = serviceRegistry.getDictionaryService().getAssociation(
associationQName);
if (associationDefinition == null)
{
return false;
}
if (associationDefinition.isChild())
{
return false;
}
return true;
}
/**
* Given an Alfresco model type map it to the appropriate type. Maps
* cm:folder and cm:content to the CMIS definitions
*/
public QName getCmisType(QName typeQName)
{
QName mapped = mapAlfrescoQNameToCmisQName.get(typeQName);
if (mapped != null)
{
return mapped;
}
return typeQName;
}
/**
* Is Alfresco Type mapped to an alternative CMIS Type?
*/
public boolean isRemappedType(QName typeQName)
{
return mapAlfrescoQNameToCmisQName.containsKey(typeQName);
}
/**
* Given a CMIS model type map it to the appropriate Alfresco type.
*
* @param cmisTypeQName
* @return
*/
public QName getAlfrescoClass(QName cmisTypeQName)
{
QName mapped = mapCmisQNameToAlfrescoQName.get(cmisTypeQName);
if (mapped != null)
{
return mapped;
}
return cmisTypeQName;
}
/**
* Get the CMIS property type for a property
*
* @param dictionaryService
* @param propertyQName
* @return
*/
public PropertyType getDataType(DataTypeDefinition datatype)
{
return getDataType(datatype.getName());
}
public PropertyType getDataType(QName dataType)
{
return mapAlfrescoToCmisDataType.get(dataType);
}
public QName getAlfrescoDataType(PropertyType propertyType)
{
return mapCmisDataTypeToAlfresco.get(propertyType);
}
/**
* @param namespaceService
* @param propertyQName
* @return
*/
public String getCmisPropertyId(QName propertyQName)
{
return propertyQName.toPrefixString(serviceRegistry.getNamespaceService());
}
/**
* Get a Property Accessor
*/
public AbstractProperty getPropertyAccessor(String propertyId)
{
return propertyAccessors.get(propertyId);
}
/**
* Register pre-defined Property Accessor
*
* @param propertyAccessor
*/
private void registerPropertyAccessor(AbstractProperty propertyAccessor)
{
propertyAccessors.put(propertyAccessor.getName(), propertyAccessor);
}
/**
* Gets the Action Evaluators applicable for the given CMIS Scope
*/
public Map<Action, CMISActionEvaluator<? extends Object>> getActionEvaluators(BaseTypeId scope)
{
Map<Action, CMISActionEvaluator<? extends Object>> evaluators = actionEvaluators.get(scope);
if (evaluators == null)
{
evaluators = Collections.emptyMap();
}
return evaluators;
}
/**
* Register an Action Evaluator
*
* @param scope
* @param evaluator
*/
private void registerEvaluator(BaseTypeId scope, CMISActionEvaluator<? extends Object> evaluator)
{
Map<Action, CMISActionEvaluator<? extends Object>> evaluators = actionEvaluators.get(scope);
if (evaluators == null)
{
evaluators = new LinkedHashMap<Action, CMISActionEvaluator<? extends Object>>();
actionEvaluators.put(scope, evaluators);
}
if (evaluators.get(evaluator.getAction()) != null)
{
throw new AlfrescoRuntimeException("Already registered Action Evaluator " + evaluator.getAction()
+ " for scope " + scope);
}
evaluators.put(evaluator.getAction(), evaluator);
if (logger.isDebugEnabled())
logger.debug("Registered Action Evaluator: scope=" + scope + ", evaluator=" + evaluator);
}
public Collection<Pair<String, Boolean>> getReportedPermissions(String permission, Set<String> permissions,
boolean hasFull, boolean isDirect, CMISAccessControlFormatEnum format)
{
ArrayList<Pair<String, Boolean>> answer = new ArrayList<Pair<String, Boolean>>(20);
// indirect
if (hasFull)
{
answer.add(new Pair<String, Boolean>(CMIS_READ, false));
answer.add(new Pair<String, Boolean>(CMIS_WRITE, false));
answer.add(new Pair<String, Boolean>(CMIS_ALL, false));
}
for (String perm : permissions)
{
if (PermissionService.READ.equals(perm))
{
answer.add(new Pair<String, Boolean>(CMIS_READ, false));
} else if (PermissionService.WRITE.equals(perm))
{
answer.add(new Pair<String, Boolean>(CMIS_WRITE, false));
} else if (PermissionService.ALL_PERMISSIONS.equals(perm))
{
answer.add(new Pair<String, Boolean>(CMIS_READ, false));
answer.add(new Pair<String, Boolean>(CMIS_WRITE, false));
answer.add(new Pair<String, Boolean>(CMIS_ALL, false));
}
if (hasFull)
{
answer.add(new Pair<String, Boolean>(CMIS_READ, false));
answer.add(new Pair<String, Boolean>(CMIS_WRITE, false));
answer.add(new Pair<String, Boolean>(CMIS_ALL, false));
}
}
// permission
if (format == CMISAccessControlFormatEnum.REPOSITORY_SPECIFIC_PERMISSIONS)
{
if (PermissionService.READ.equals(permission))
{
answer.add(new Pair<String, Boolean>(CMIS_READ, false));
answer.add(new Pair<String, Boolean>(permission, isDirect));
} else if (PermissionService.WRITE.equals(permission))
{
answer.add(new Pair<String, Boolean>(CMIS_WRITE, false));
answer.add(new Pair<String, Boolean>(permission, isDirect));
} else if (PermissionService.ALL_PERMISSIONS.equals(permission))
{
answer.add(new Pair<String, Boolean>(CMIS_ALL, false));
answer.add(new Pair<String, Boolean>(permission, isDirect));
} else
{
answer.add(new Pair<String, Boolean>(permission, isDirect));
}
} else if (format == CMISAccessControlFormatEnum.CMIS_BASIC_PERMISSIONS)
{
if (PermissionService.READ.equals(permission))
{
answer.add(new Pair<String, Boolean>(CMIS_READ, isDirect));
} else if (PermissionService.WRITE.equals(permission))
{
answer.add(new Pair<String, Boolean>(CMIS_WRITE, isDirect));
} else if (PermissionService.ALL_PERMISSIONS.equals(permission))
{
answer.add(new Pair<String, Boolean>(CMIS_ALL, isDirect));
} else
{
// else nothing
}
}
return answer;
}
/**
* @param permission
* @return permission to set
*/
public String getSetPermission(String permission)
{
if (permission.equals(CMIS_READ))
{
return PermissionService.READ;
} else if (permission.equals(CMIS_WRITE))
{
return PermissionService.WRITE;
} else if (permission.equals(CMIS_ALL))
{
return PermissionService.ALL_PERMISSIONS;
} else
{
return permission;
}
}
}

View File

@@ -22,11 +22,9 @@ import java.io.Serializable;
import org.alfresco.model.ContentModel;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.namespace.QName;
import org.apache.chemistry.opencmis.commons.PropertyIds;
/**
@@ -34,7 +32,7 @@ import org.apache.chemistry.opencmis.commons.PropertyIds;
*
* @author andyh
*/
public class ContentStreamLengthProperty extends AbstractSimpleProperty
public class ContentStreamLengthProperty extends AbstractProperty
{
/**
* Construct
@@ -65,31 +63,4 @@ public class ContentStreamLengthProperty extends AbstractSimpleProperty
return 0L;
}
}
public String getLuceneFieldName()
{
StringBuilder field = new StringBuilder(128);
field.append("@");
field.append(ContentModel.PROP_CONTENT);
field.append(".size");
return field.toString();
}
protected String getValueAsString(Serializable value)
{
Object converted = DefaultTypeConverter.INSTANCE.convert(getServiceRegistry().getDictionaryService()
.getDataType(DataTypeDefinition.LONG), value);
String asString = DefaultTypeConverter.INSTANCE.convert(String.class, converted);
return asString;
}
protected QName getQNameForExists()
{
return ContentModel.PROP_CONTENT;
}
protected DataTypeDefinition getInDataType()
{
return getServiceRegistry().getDictionaryService().getDataType(DataTypeDefinition.LONG);
}
}

View File

@@ -34,7 +34,7 @@ import org.apache.chemistry.opencmis.commons.PropertyIds;
*
* @author andyh
*/
public class ContentStreamMimetypeProperty extends AbstractSimpleProperty
public class ContentStreamMimetypeProperty extends AbstractProperty
{
/**
* Construct

View File

@@ -21,7 +21,7 @@ package org.alfresco.opencmis.mapping;
import java.io.Serializable;
import org.alfresco.model.ContentModel;
import org.alfresco.opencmis.CMISActionEvaluator;
import org.alfresco.opencmis.dictionary.CMISActionEvaluator;
import org.alfresco.repo.version.VersionBaseModel;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;

View File

@@ -19,122 +19,19 @@
package org.alfresco.opencmis.mapping;
import java.io.Serializable;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import org.alfresco.repo.search.MLAnalysisMode;
import org.alfresco.repo.search.SearcherException;
import org.alfresco.repo.search.impl.lucene.LuceneQueryParser;
import org.alfresco.repo.search.impl.lucene.analysis.DateTimeAnalyser;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.namespace.QName;
import org.apache.lucene.index.IndexReader.FieldOption;
import org.springframework.extensions.surf.util.I18NUtil;
/**
* A simple 1-1 property mapping from a CMIS property name to an alfresco property
*
* @author andyh
*/
public class DirectProperty extends AbstractSimpleProperty
public class DirectProperty extends AbstractProperty
{
/*
* (non-Javadoc)
* @see org.alfresco.cmis.mapping.AbstractSimpleProperty#getLuceneSortField()
*/
@Override
public String getLuceneSortField(LuceneQueryParser lqp)
{
String field = getLuceneFieldName();
// need to find the real field to use
Locale sortLocale = null;
PropertyDefinition propertyDef = getServiceRegistry().getDictionaryService().getProperty(QName.createQName(field.substring(1)));
if (propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT))
{
throw new SearcherException("Order on content properties is not curently supported");
}
else if ((propertyDef.getDataType().getName().equals(DataTypeDefinition.MLTEXT)) || (propertyDef.getDataType().getName().equals(DataTypeDefinition.TEXT)))
{
List<Locale> locales = lqp.getSearchParameters().getLocales();
if (((locales == null) || (locales.size() == 0)))
{
locales = Collections.singletonList(I18NUtil.getLocale());
}
if (locales.size() > 1)
{
throw new SearcherException("Order on text/mltext properties with more than one locale is not curently supported");
}
sortLocale = locales.get(0);
// find best field match
HashSet<String> allowableLocales = new HashSet<String>();
MLAnalysisMode analysisMode = lqp.getDefaultSearchMLAnalysisMode();
for (Locale l : MLAnalysisMode.getLocales(analysisMode, sortLocale, false))
{
allowableLocales.add(l.toString());
}
String sortField = field;
for (Object current : lqp.getIndexReader().getFieldNames(FieldOption.INDEXED))
{
String currentString = (String) current;
if (currentString.startsWith(field) && currentString.endsWith(".sort"))
{
String fieldLocale = currentString.substring(field.length() + 1, currentString.length() - 5);
if (allowableLocales.contains(fieldLocale))
{
if (fieldLocale.equals(sortLocale.toString()))
{
sortField = currentString;
break;
}
else if (sortLocale.toString().startsWith(fieldLocale))
{
if (sortField.equals(field) || (currentString.length() < sortField.length()))
{
sortField = currentString;
}
}
else if (fieldLocale.startsWith(sortLocale.toString()))
{
if (sortField.equals(field) || (currentString.length() < sortField.length()))
{
sortField = currentString;
}
}
}
}
}
field = sortField;
}
else if (propertyDef.getDataType().getName().equals(DataTypeDefinition.DATETIME))
{
DataTypeDefinition dataType = propertyDef.getDataType();
String analyserClassName = dataType.getAnalyserClassName();
if (analyserClassName.equals(DateTimeAnalyser.class.getCanonicalName()))
{
field = field + ".sort";
}
}
return field;
}
private QName alfrescoName;
/**
@@ -176,32 +73,5 @@ public class DirectProperty extends AbstractSimpleProperty
{
return null;
}
public String getLuceneFieldName()
{
StringBuilder field = new StringBuilder(64);
field.append("@");
field.append(alfrescoName);
return field.toString();
}
protected String getValueAsString(Serializable value)
{
PropertyDefinition pd = getServiceRegistry().getDictionaryService().getProperty(alfrescoName);
Object converted = DefaultTypeConverter.INSTANCE.convert(pd.getDataType(), value);
String asString = DefaultTypeConverter.INSTANCE.convert(String.class, converted);
return asString;
}
protected QName getQNameForExists()
{
return alfrescoName;
}
protected DataTypeDefinition getInDataType()
{
PropertyDefinition pd = getServiceRegistry().getDictionaryService().getProperty(alfrescoName);
return pd.getDataType();
}
}

View File

@@ -19,24 +19,10 @@
package org.alfresco.opencmis.mapping;
import java.io.Serializable;
import java.util.Collection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.alfresco.repo.search.impl.lucene.LuceneFunction;
import org.alfresco.repo.search.impl.lucene.LuceneQueryParser;
import org.alfresco.repo.search.impl.querymodel.PredicateMode;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.util.EqualsHelper;
import org.alfresco.util.SearchLanguageConversion;
import org.apache.lucene.index.Term;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
/**
* Property accessor for fixed value mapping (eg to null, true, etc)
@@ -77,244 +63,4 @@ public class FixedValueProperty extends AbstractProperty
{
return value;
}
/*
* (non-Javadoc)
* @see org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneEquality(org.alfresco.repo.search.impl.lucene.LuceneQueryParser, java.io.Serializable, org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneEquality(LuceneQueryParser lqp, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
{
if (EqualsHelper.nullSafeEquals(value, value))
{
return new MatchAllDocsQuery();
}
else
{
return new TermQuery(new Term("NO_TOKENS", "__"));
}
}
/*
* (non-Javadoc)
* @see org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneExists(org.alfresco.repo.search.impl.lucene.LuceneQueryParser, java.lang.Boolean)
*/
public Query buildLuceneExists(LuceneQueryParser lqp, Boolean not) throws ParseException
{
if (not)
{
if (value == null)
{
return new MatchAllDocsQuery();
}
else
{
return new TermQuery(new Term("NO_TOKENS", "__"));
}
}
else
{
if (value == null)
{
return new TermQuery(new Term("NO_TOKENS", "__"));
}
else
{
return new MatchAllDocsQuery();
}
}
}
/*
* (non-Javadoc)
* @see org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneGreaterThan(org.alfresco.repo.search.impl.lucene.LuceneQueryParser, java.io.Serializable, org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
@SuppressWarnings("unchecked")
public Query buildLuceneGreaterThan(LuceneQueryParser lqp, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
{
if (value instanceof Comparable)
{
Comparable comparable = (Comparable) value;
if (comparable.compareTo(value) > 0)
{
return new MatchAllDocsQuery();
}
else
{
return new TermQuery(new Term("NO_TOKENS", "__"));
}
}
else
{
return new TermQuery(new Term("NO_TOKENS", "__"));
}
}
/*
* (non-Javadoc)
* @see org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneGreaterThanOrEquals(org.alfresco.repo.search.impl.lucene.LuceneQueryParser, java.io.Serializable, org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
@SuppressWarnings("unchecked")
public Query buildLuceneGreaterThanOrEquals(LuceneQueryParser lqp, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
{
if (value instanceof Comparable)
{
Comparable comparable = (Comparable) value;
if (comparable.compareTo(value) >= 0)
{
return new MatchAllDocsQuery();
}
else
{
return new TermQuery(new Term("NO_TOKENS", "__"));
}
}
else
{
return new TermQuery(new Term("NO_TOKENS", "__"));
}
}
/*
* (non-Javadoc)
* @see org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneIn(org.alfresco.repo.search.impl.lucene.LuceneQueryParser, java.util.Collection, java.lang.Boolean, org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneIn(LuceneQueryParser lqp, Collection<Serializable> values, Boolean not, PredicateMode mode) throws ParseException
{
boolean in = false;
for (Serializable value : values)
{
if (EqualsHelper.nullSafeEquals(value, value))
{
in = true;
break;
}
}
if (in == !not)
{
return new MatchAllDocsQuery();
}
else
{
return new TermQuery(new Term("NO_TOKENS", "__"));
}
}
/*
* (non-Javadoc)
* @see org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneInequality(org.alfresco.repo.search.impl.lucene.LuceneQueryParser, java.io.Serializable, org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneInequality(LuceneQueryParser lqp, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
{
if (!EqualsHelper.nullSafeEquals(value, value))
{
return new MatchAllDocsQuery();
}
else
{
return new TermQuery(new Term("NO_TOKENS", "__"));
}
}
/*
* (non-Javadoc)
* @see org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneLessThan(org.alfresco.repo.search.impl.lucene.LuceneQueryParser, java.io.Serializable, org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
@SuppressWarnings("unchecked")
public Query buildLuceneLessThan(LuceneQueryParser lqp, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
{
if (value instanceof Comparable)
{
Comparable comparable = (Comparable) value;
if (comparable.compareTo(value) < 0)
{
return new MatchAllDocsQuery();
}
else
{
return new TermQuery(new Term("NO_TOKENS", "__"));
}
}
else
{
return new TermQuery(new Term("NO_TOKENS", "__"));
}
}
/*
* (non-Javadoc)
* @see org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneLessThanOrEquals(org.alfresco.repo.search.impl.lucene.LuceneQueryParser, java.io.Serializable, org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
@SuppressWarnings("unchecked")
public Query buildLuceneLessThanOrEquals(LuceneQueryParser lqp, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
{
if (value instanceof Comparable)
{
Comparable comparable = (Comparable) value;
if (comparable.compareTo(value) <= 0)
{
return new MatchAllDocsQuery();
}
else
{
return new TermQuery(new Term("NO_TOKENS", "__"));
}
}
else
{
return new TermQuery(new Term("NO_TOKENS", "__"));
}
}
/*
* (non-Javadoc)
* @see org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneLike(org.alfresco.repo.search.impl.lucene.LuceneQueryParser, java.io.Serializable, java.lang.Boolean)
*/
public Query buildLuceneLike(LuceneQueryParser lqp, Serializable value, Boolean not) throws ParseException
{
if (value != null)
{
boolean matches = false;
Object converted = DefaultTypeConverter.INSTANCE.convert(value.getClass(), value);
String asString = DefaultTypeConverter.INSTANCE.convert(String.class, converted);
String regExpression = SearchLanguageConversion.convertSQLLikeToRegex(asString);
Pattern pattern = Pattern.compile(regExpression);
String target = DefaultTypeConverter.INSTANCE.convert(String.class, value);
Matcher matcher = pattern.matcher(target);
if (matcher.matches())
{
matches = true;
}
if (matches == !not)
{
return new MatchAllDocsQuery();
}
else
{
return new TermQuery(new Term("NO_TOKENS", "__"));
}
}
else
{
return new TermQuery(new Term("NO_TOKENS", "__"));
}
}
/*
* (non-Javadoc)
* @see org.alfresco.cmis.property.PropertyLuceneBuilder#getLuceneSortField()
*/
public String getLuceneSortField(LuceneQueryParser lqp)
{
throw new UnsupportedOperationException();
}
public String getLuceneFieldName()
{
throw new UnsupportedOperationException();
}
}

View File

@@ -29,7 +29,7 @@ import org.alfresco.service.cmr.repository.NodeRef;
*/
public class NodeRefProperty extends AbstractVersioningProperty
{
public static final String NodeRefPropertyId = "alf:nodeRef";
public static final String NodeRefPropertyId = "alfcmis:nodeRef";
/**
* Construct

View File

@@ -19,29 +19,14 @@
package org.alfresco.opencmis.mapping;
import java.io.Serializable;
import java.util.Collection;
import org.alfresco.cmis.CMISQueryException;
import org.alfresco.model.ContentModel;
import org.alfresco.opencmis.CMISConnector;
import org.alfresco.repo.search.impl.lucene.AnalysisMode;
import org.alfresco.repo.search.impl.lucene.LuceneFunction;
import org.alfresco.repo.search.impl.lucene.LuceneQueryParser;
import org.alfresco.repo.search.impl.querymodel.PredicateMode;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.namespace.QName;
import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.lucene.index.Term;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.search.BooleanClause.Occur;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
/**
* Get the CMIS object id property.
@@ -106,229 +91,4 @@ public class ObjectIdProperty extends AbstractVersioningProperty
return CMISConnector.ASSOC_ID_PREFIX + assocRef.getId();
}
public String getLuceneFieldName()
{
return "ID";
}
private String getValueAsString(Serializable value)
{
Object converted = DefaultTypeConverter.INSTANCE.convert(getServiceRegistry().getDictionaryService()
.getDataType(DataTypeDefinition.NODE_REF), value);
String asString = DefaultTypeConverter.INSTANCE.convert(String.class, converted);
return asString;
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneEquality(
* org.alfresco.repo.search.impl.lucene.LuceneQueryParser,
* java.io.Serializable,
* org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneEquality(LuceneQueryParser lqp, Serializable value, PredicateMode mode,
LuceneFunction luceneFunction) throws ParseException
{
String field = getLuceneFieldName();
String stringValue = getValueAsString(value);
return lqp.getFieldQuery(field, stringValue, AnalysisMode.IDENTIFIER, luceneFunction);
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneExists(org
* .alfresco.repo.search.impl.lucene.LuceneQueryParser, java.lang.Boolean)
*/
public Query buildLuceneExists(LuceneQueryParser lqp, Boolean not) throws ParseException
{
if (not)
{
return new TermQuery(new Term("NO_TOKENS", "__"));
} else
{
return new MatchAllDocsQuery();
}
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneGreaterThan
* (org.alfresco.repo.search.impl.lucene.LuceneQueryParser,
* java.io.Serializable,
* org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneGreaterThan(LuceneQueryParser lqp, Serializable value, PredicateMode mode,
LuceneFunction luceneFunction) throws ParseException
{
throw new CMISQueryException("Property " + getName() + " can not be used in a 'greater than' comparison");
}
/*
* (non-Javadoc)
*
* @see org.alfresco.cmis.property.PropertyLuceneBuilder#
* buildLuceneGreaterThanOrEquals
* (org.alfresco.repo.search.impl.lucene.LuceneQueryParser,
* java.io.Serializable,
* org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneGreaterThanOrEquals(LuceneQueryParser lqp, Serializable value, PredicateMode mode,
LuceneFunction luceneFunction) throws ParseException
{
throw new CMISQueryException("Property " + getName()
+ " can not be used in a 'greater than or equals' comparison");
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneIn(org.alfresco
* .repo.search.impl.lucene.LuceneQueryParser, java.util.Collection,
* java.lang.Boolean,
* org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneIn(LuceneQueryParser lqp, Collection<Serializable> values, Boolean not, PredicateMode mode)
throws ParseException
{
String field = getLuceneFieldName();
// Check type conversion
@SuppressWarnings("unused")
Object converted = DefaultTypeConverter.INSTANCE.convert(getServiceRegistry().getDictionaryService()
.getDataType(DataTypeDefinition.NODE_REF), values);
Collection<String> asStrings = DefaultTypeConverter.INSTANCE.convert(String.class, values);
if (asStrings.size() == 0)
{
if (not)
{
return new MatchAllDocsQuery();
} else
{
return new TermQuery(new Term("NO_TOKENS", "__"));
}
} else if (asStrings.size() == 1)
{
String value = asStrings.iterator().next();
if (not)
{
return lqp.getDoesNotMatchFieldQuery(field, value, AnalysisMode.IDENTIFIER, LuceneFunction.FIELD);
} else
{
return lqp.getFieldQuery(field, value, AnalysisMode.IDENTIFIER, LuceneFunction.FIELD);
}
} else
{
BooleanQuery booleanQuery = new BooleanQuery();
if (not)
{
booleanQuery.add(new MatchAllDocsQuery(), Occur.MUST);
}
for (String value : asStrings)
{
Query any = lqp.getFieldQuery(field, value, AnalysisMode.IDENTIFIER, LuceneFunction.FIELD);
if (not)
{
booleanQuery.add(any, Occur.MUST_NOT);
} else
{
booleanQuery.add(any, Occur.SHOULD);
}
}
return booleanQuery;
}
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneInequality
* (org.alfresco.repo.search.impl.lucene.LuceneQueryParser,
* java.io.Serializable,
* org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneInequality(LuceneQueryParser lqp, Serializable value, PredicateMode mode,
LuceneFunction luceneFunction) throws ParseException
{
String field = getLuceneFieldName();
String stringValue = getValueAsString(value);
return lqp.getDoesNotMatchFieldQuery(field, stringValue, AnalysisMode.IDENTIFIER, luceneFunction);
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneLessThan(
* org.alfresco.repo.search.impl.lucene.LuceneQueryParser,
* java.io.Serializable,
* org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneLessThan(LuceneQueryParser lqp, Serializable value, PredicateMode mode,
LuceneFunction luceneFunction) throws ParseException
{
throw new CMISQueryException("Property " + getName() + " can not be used in a 'less than' comparison");
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneLessThanOrEquals
* (org.alfresco.repo.search.impl.lucene.LuceneQueryParser,
* java.io.Serializable,
* org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneLessThanOrEquals(LuceneQueryParser lqp, Serializable value, PredicateMode mode,
LuceneFunction luceneFunction) throws ParseException
{
throw new CMISQueryException("Property " + getName() + " can not be used in a 'less than or equals' comparison");
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.NamedPropertyAccessor#buildLuceneLike(org.
* alfresco.repo.search.impl.lucene.LuceneQueryParser, java.lang.String,
* java.io.Serializable, java.lang.Boolean)
*/
public Query buildLuceneLike(LuceneQueryParser lqp, Serializable value, Boolean not) throws ParseException
{
String field = getLuceneFieldName();
String stringValue = getValueAsString(value);
if (not)
{
BooleanQuery booleanQuery = new BooleanQuery();
booleanQuery.add(new MatchAllDocsQuery(), Occur.MUST);
booleanQuery.add(lqp.getLikeQuery(field, stringValue, AnalysisMode.IDENTIFIER), Occur.MUST_NOT);
return booleanQuery;
} else
{
return lqp.getLikeQuery(field, stringValue, AnalysisMode.IDENTIFIER);
}
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.NamedPropertyAccessor#getLuceneSortField(java
* .lang.String)
*/
public String getLuceneSortField(LuceneQueryParser lqp)
{
return getLuceneFieldName();
}
}

View File

@@ -19,29 +19,14 @@
package org.alfresco.opencmis.mapping;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import org.alfresco.cmis.CMISQueryException;
import org.alfresco.cmis.CMISScope;
import org.alfresco.cmis.CMISTypeDefinition;
import org.alfresco.repo.search.impl.lucene.AnalysisMode;
import org.alfresco.repo.search.impl.lucene.LuceneFunction;
import org.alfresco.repo.search.impl.lucene.LuceneQueryParser;
import org.alfresco.repo.search.impl.querymodel.PredicateMode;
import org.alfresco.opencmis.dictionary.CMISDictionaryService;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.namespace.QName;
import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.lucene.index.Term;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.search.BooleanClause.Occur;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
/**
* Get the CMIS object type id property
@@ -50,14 +35,17 @@ import org.apache.lucene.search.TermQuery;
*/
public class ObjectTypeIdProperty extends AbstractProperty
{
private CMISDictionaryService dictionaryService;
/**
* Construct
*
* @param serviceRegistry
*/
public ObjectTypeIdProperty(ServiceRegistry serviceRegistry)
public ObjectTypeIdProperty(ServiceRegistry serviceRegistry, CMISDictionaryService dictionaryService)
{
super(serviceRegistry, PropertyIds.OBJECT_TYPE_ID);
this.dictionaryService = dictionaryService;
}
/*
@@ -70,7 +58,7 @@ public class ObjectTypeIdProperty extends AbstractProperty
public Serializable getValue(NodeRef nodeRef)
{
QName type = getServiceRegistry().getNodeService().getType(nodeRef);
return getServiceRegistry().getCMISDictionaryService().findTypeForClass(type).getTypeId().getId();
return dictionaryService.findTypeForClass(type).getTypeId();
}
/*
@@ -83,239 +71,6 @@ public class ObjectTypeIdProperty extends AbstractProperty
public Serializable getValue(AssociationRef assocRef)
{
QName type = assocRef.getTypeQName();
return getServiceRegistry().getCMISDictionaryService().findTypeForClass(type, CMISScope.RELATIONSHIP)
.getTypeId().getId();
}
public String getLuceneFieldName()
{
return "TYPE";
}
private String getValueAsString(Serializable value)
{
// Object converted =
// DefaultTypeConverter.INSTANCE.convert(getServiceRegistry().getDictionaryService().getDataType(DataTypeDefinition.QNAME),
// value);
String asString = DefaultTypeConverter.INSTANCE.convert(String.class, value);
return asString;
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneEquality(
* org.alfresco.repo.search.impl.lucene.LuceneQueryParser,
* java.io.Serializable,
* org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneEquality(LuceneQueryParser lqp, Serializable value, PredicateMode mode,
LuceneFunction luceneFunction) throws ParseException
{
String field = getLuceneFieldName();
String stringValue = getValueAsString(value);
CMISTypeDefinition type = getServiceRegistry().getCMISDictionaryService().findType(stringValue);
return lqp
.getFieldQuery(field, type.getTypeId().getQName().toString(), AnalysisMode.IDENTIFIER, luceneFunction);
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneExists(org
* .alfresco.repo.search.impl.lucene.LuceneQueryParser, java.lang.Boolean)
*/
public Query buildLuceneExists(LuceneQueryParser lqp, Boolean not) throws ParseException
{
if (not)
{
return new TermQuery(new Term("NO_TOKENS", "__"));
} else
{
return new MatchAllDocsQuery();
}
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneGreaterThan
* (org.alfresco.repo.search.impl.lucene.LuceneQueryParser,
* java.io.Serializable,
* org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneGreaterThan(LuceneQueryParser lqp, Serializable value, PredicateMode mode,
LuceneFunction luceneFunction) throws ParseException
{
throw new CMISQueryException("Property " + getName() + " can not be used in a 'greater than' comparison");
}
/*
* (non-Javadoc)
*
* @see org.alfresco.cmis.property.PropertyLuceneBuilder#
* buildLuceneGreaterThanOrEquals
* (org.alfresco.repo.search.impl.lucene.LuceneQueryParser,
* java.io.Serializable,
* org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneGreaterThanOrEquals(LuceneQueryParser lqp, Serializable value, PredicateMode mode,
LuceneFunction luceneFunction) throws ParseException
{
throw new CMISQueryException("Property " + getName()
+ " can not be used in a 'greater than or equals' comparison");
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneIn(org.alfresco
* .repo.search.impl.lucene.LuceneQueryParser, java.util.Collection,
* java.lang.Boolean,
* org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneIn(LuceneQueryParser lqp, Collection<Serializable> values, Boolean not, PredicateMode mode)
throws ParseException
{
String field = getLuceneFieldName();
Collection<String> asStrings = new ArrayList<String>(values.size());
for (Serializable value : values)
{
String stringValue = getValueAsString(value);
CMISTypeDefinition type = getServiceRegistry().getCMISDictionaryService().findType(stringValue);
asStrings.add(type.getTypeId().getQName().toString());
}
if (asStrings.size() == 0)
{
if (not)
{
return new MatchAllDocsQuery();
} else
{
return new TermQuery(new Term("NO_TOKENS", "__"));
}
} else if (asStrings.size() == 1)
{
String value = asStrings.iterator().next();
if (not)
{
return lqp.getDoesNotMatchFieldQuery(field, value, AnalysisMode.IDENTIFIER, LuceneFunction.FIELD);
} else
{
return lqp.getFieldQuery(field, value, AnalysisMode.IDENTIFIER, LuceneFunction.FIELD);
}
} else
{
BooleanQuery booleanQuery = new BooleanQuery();
if (not)
{
booleanQuery.add(new MatchAllDocsQuery(), Occur.MUST);
}
for (String value : asStrings)
{
Query any = lqp.getFieldQuery(field, value, AnalysisMode.IDENTIFIER, LuceneFunction.FIELD);
if (not)
{
booleanQuery.add(any, Occur.MUST_NOT);
} else
{
booleanQuery.add(any, Occur.SHOULD);
}
}
return booleanQuery;
}
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneInequality
* (org.alfresco.repo.search.impl.lucene.LuceneQueryParser,
* java.io.Serializable,
* org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneInequality(LuceneQueryParser lqp, Serializable value, PredicateMode mode,
LuceneFunction luceneFunction) throws ParseException
{
String field = getLuceneFieldName();
String stringValue = getValueAsString(value);
CMISTypeDefinition type = getServiceRegistry().getCMISDictionaryService().findType(stringValue);
return lqp.getDoesNotMatchFieldQuery(field, type.getTypeId().getQName().toString(), AnalysisMode.IDENTIFIER,
luceneFunction);
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneLessThan(
* org.alfresco.repo.search.impl.lucene.LuceneQueryParser,
* java.io.Serializable,
* org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneLessThan(LuceneQueryParser lqp, Serializable value, PredicateMode mode,
LuceneFunction luceneFunction) throws ParseException
{
throw new CMISQueryException("Property " + getName() + " can not be used in a 'less than' comparison");
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneLessThanOrEquals
* (org.alfresco.repo.search.impl.lucene.LuceneQueryParser,
* java.io.Serializable,
* org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneLessThanOrEquals(LuceneQueryParser lqp, Serializable value, PredicateMode mode,
LuceneFunction luceneFunction) throws ParseException
{
throw new CMISQueryException("Property " + getName() + " can not be used in a 'less than or equals' comparison");
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneLike(org.
* alfresco.repo.search.impl.lucene.LuceneQueryParser, java.io.Serializable,
* java.lang.Boolean)
*/
public Query buildLuceneLike(LuceneQueryParser lqp, Serializable value, Boolean not) throws ParseException
{
String field = getLuceneFieldName();
String stringValue = getValueAsString(value);
CMISTypeDefinition type = getServiceRegistry().getCMISDictionaryService().findType(stringValue);
String typeQName = type.getTypeId().getQName().toString();
if (not)
{
BooleanQuery booleanQuery = new BooleanQuery();
booleanQuery.add(new MatchAllDocsQuery(), Occur.MUST);
booleanQuery.add(lqp.getLikeQuery(field, typeQName, AnalysisMode.IDENTIFIER), Occur.MUST_NOT);
return booleanQuery;
} else
{
return lqp.getLikeQuery(field, typeQName, AnalysisMode.IDENTIFIER);
}
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.PropertyLuceneBuilder#getLuceneSortField()
*/
public String getLuceneSortField(LuceneQueryParser lqp)
{
return getLuceneFieldName();
return dictionaryService.findTypeForClass(type, BaseTypeId.CMIS_RELATIONSHIP).getTypeId();
}
}

View File

@@ -19,25 +19,11 @@
package org.alfresco.opencmis.mapping;
import java.io.Serializable;
import java.util.Collection;
import org.alfresco.repo.search.impl.lucene.AnalysisMode;
import org.alfresco.repo.search.impl.lucene.LuceneFunction;
import org.alfresco.repo.search.impl.lucene.LuceneQueryParser;
import org.alfresco.repo.search.impl.querymodel.PredicateMode;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.lucene.index.Term;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.search.BooleanClause.Occur;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
/**
* Get the CMIS parent property
@@ -80,167 +66,4 @@ public class ParentProperty extends AbstractProperty
return null;
}
}
public String getLuceneFieldName()
{
return "PARENT";
}
private String getValueAsString(Serializable value)
{
Object converted = DefaultTypeConverter.INSTANCE.convert(getServiceRegistry().getDictionaryService()
.getDataType(DataTypeDefinition.NODE_REF), value);
String asString = DefaultTypeConverter.INSTANCE.convert(String.class, converted);
return asString;
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneEquality(
* org.alfresco.repo.search.impl.lucene.LuceneQueryParser,
* java.io.Serializable,
* org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneEquality(LuceneQueryParser lqp, Serializable value, PredicateMode mode,
LuceneFunction luceneFunction) throws ParseException
{
String field = getLuceneFieldName();
String stringValue = getValueAsString(value);
return lqp.getFieldQuery(field, stringValue, AnalysisMode.IDENTIFIER, luceneFunction);
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneExists(org
* .alfresco.repo.search.impl.lucene.LuceneQueryParser, java.lang.Boolean)
*/
public Query buildLuceneExists(LuceneQueryParser lqp, Boolean not) throws ParseException
{
if (not)
{
return new TermQuery(new Term("ISROOT", "T"));
} else
{
return new MatchAllDocsQuery();
}
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneIn(org.alfresco
* .repo.search.impl.lucene.LuceneQueryParser, java.util.Collection,
* java.lang.Boolean,
* org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneIn(LuceneQueryParser lqp, Collection<Serializable> values, Boolean not, PredicateMode mode)
throws ParseException
{
String field = getLuceneFieldName();
// Check type conversion
@SuppressWarnings("unused")
Object converted = DefaultTypeConverter.INSTANCE.convert(getServiceRegistry().getDictionaryService()
.getDataType(DataTypeDefinition.NODE_REF), values);
Collection<String> asStrings = DefaultTypeConverter.INSTANCE.convert(String.class, values);
if (asStrings.size() == 0)
{
if (not)
{
return new MatchAllDocsQuery();
} else
{
return new TermQuery(new Term("NO_TOKENS", "__"));
}
} else if (asStrings.size() == 1)
{
String value = asStrings.iterator().next();
if (not)
{
return lqp.getDoesNotMatchFieldQuery(field, value, AnalysisMode.IDENTIFIER, LuceneFunction.FIELD);
} else
{
return lqp.getFieldQuery(field, value, AnalysisMode.IDENTIFIER, LuceneFunction.FIELD);
}
} else
{
BooleanQuery booleanQuery = new BooleanQuery();
if (not)
{
booleanQuery.add(new MatchAllDocsQuery(), Occur.MUST);
}
for (String value : asStrings)
{
Query any = lqp.getFieldQuery(field, value, AnalysisMode.IDENTIFIER, LuceneFunction.FIELD);
if (not)
{
booleanQuery.add(any, Occur.MUST_NOT);
} else
{
booleanQuery.add(any, Occur.SHOULD);
}
}
return booleanQuery;
}
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneInequality
* (org.alfresco.repo.search.impl.lucene.LuceneQueryParser,
* java.io.Serializable,
* org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneInequality(LuceneQueryParser lqp, Serializable value, PredicateMode mode,
LuceneFunction luceneFunction) throws ParseException
{
String field = getLuceneFieldName();
String stringValue = getValueAsString(value);
return lqp.getDoesNotMatchFieldQuery(field, stringValue, AnalysisMode.IDENTIFIER, luceneFunction);
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.PropertyLuceneBuilder#buildLuceneLike(org.
* alfresco.repo.search.impl.lucene.LuceneQueryParser, java.io.Serializable,
* java.lang.Boolean)
*/
public Query buildLuceneLike(LuceneQueryParser lqp, Serializable value, Boolean not) throws ParseException
{
String field = getLuceneFieldName();
String stringValue = getValueAsString(value);
if (not)
{
BooleanQuery booleanQuery = new BooleanQuery();
booleanQuery.add(new MatchAllDocsQuery(), Occur.MUST);
booleanQuery.add(lqp.getLikeQuery(field, stringValue, AnalysisMode.IDENTIFIER), Occur.MUST_NOT);
return booleanQuery;
} else
{
return lqp.getLikeQuery(field, stringValue, AnalysisMode.IDENTIFIER);
}
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.PropertyLuceneBuilder#getLuceneSortField()
*/
public String getLuceneSortField(LuceneQueryParser lqp)
{
return getLuceneFieldName();
}
}

View File

@@ -18,8 +18,8 @@
*/
package org.alfresco.opencmis.mapping;
import org.alfresco.opencmis.CMISActionEvaluator;
import org.alfresco.opencmis.CMISConnector;
import org.alfresco.opencmis.dictionary.CMISActionEvaluator;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;

View File

@@ -0,0 +1,363 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.opencmis.mapping;
import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.opencmis.CMISConnector;
import org.alfresco.opencmis.dictionary.CMISActionEvaluator;
import org.alfresco.opencmis.dictionary.CMISDictionaryService;
import org.alfresco.opencmis.dictionary.CMISPropertyAccessor;
import org.alfresco.opencmis.dictionary.PropertyAccessorMapping;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.namespace.QName;
import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.chemistry.opencmis.commons.enums.Action;
import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean;
/**
* Registry of property accessors which map the retrieval and setting of properties
* within Alfresco.
*
* @author davidc
*/
public class RuntimePropertyAccessorMapping implements PropertyAccessorMapping, InitializingBean
{
// Logger
protected static final Log logger = LogFactory.getLog(CMISMapping.class);
// Service dependencies
private ServiceRegistry serviceRegistry;
private CMISConnector cmisConnector;
private CMISMapping cmisMapping;
private CMISDictionaryService cmisDictionaryService;
private Map<String, AbstractProperty> propertyAccessors = new HashMap<String, AbstractProperty>();
private Map<BaseTypeId, Map<Action, CMISActionEvaluator<? extends Object>>> actionEvaluators = new HashMap<BaseTypeId, Map<Action, CMISActionEvaluator<? extends Object>>>();
/**
* @param service registry
*/
public void setServiceRegistry(ServiceRegistry serviceRegistry)
{
this.serviceRegistry = serviceRegistry;
}
/**
* @param cmis connector
*/
public void setCmisConnector(CMISConnector cmisConnector)
{
this.cmisConnector = cmisConnector;
}
/**
* @param cmis mapping
*/
public void setCmisMapping(CMISMapping cmisMapping)
{
this.cmisMapping = cmisMapping;
}
/**
* @param cmis mapping
*/
public void setCmisDictionaryService(CMISDictionaryService cmisDictionaryService)
{
this.cmisDictionaryService = cmisDictionaryService;
}
/*
* (non-Javadoc)
*
* @see
* org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/
public void afterPropertiesSet() throws Exception
{
//
// Property Mappings
//
registerPropertyAccessor(new ObjectIdProperty(serviceRegistry));
registerPropertyAccessor(new NodeRefProperty(serviceRegistry));
registerPropertyAccessor(new ObjectTypeIdProperty(serviceRegistry, cmisDictionaryService));
registerPropertyAccessor(new BaseTypeIdProperty(serviceRegistry, cmisDictionaryService));
registerPropertyAccessor(new DirectProperty(serviceRegistry, PropertyIds.CREATED_BY, ContentModel.PROP_CREATOR));
registerPropertyAccessor(new DirectProperty(serviceRegistry, PropertyIds.CREATION_DATE, ContentModel.PROP_CREATED));
registerPropertyAccessor(new DirectProperty(serviceRegistry, PropertyIds.LAST_MODIFIED_BY, ContentModel.PROP_MODIFIER));
registerPropertyAccessor(new DirectProperty(serviceRegistry, PropertyIds.LAST_MODIFICATION_DATE, ContentModel.PROP_MODIFIED));
registerPropertyAccessor(new FixedValueProperty(serviceRegistry, PropertyIds.CHANGE_TOKEN, null));
registerPropertyAccessor(new DirectProperty(serviceRegistry, PropertyIds.NAME, ContentModel.PROP_NAME)
{
@Override
public Serializable getValue(AssociationRef assocRef)
{
// Let's use the association ref as the name
return assocRef.toString();
}
});
registerPropertyAccessor(new IsImmutableProperty(serviceRegistry));
registerPropertyAccessor(new IsLatestVersionProperty(serviceRegistry));
registerPropertyAccessor(new IsMajorVersionProperty(serviceRegistry));
registerPropertyAccessor(new IsLatestMajorVersionProperty(serviceRegistry));
registerPropertyAccessor(new VersionLabelProperty(serviceRegistry));
registerPropertyAccessor(new VersionSeriesIdProperty(serviceRegistry));
registerPropertyAccessor(new IsVersionSeriesCheckedOutProperty(serviceRegistry));
registerPropertyAccessor(new VersionSeriesCheckedOutByProperty(serviceRegistry));
registerPropertyAccessor(new VersionSeriesCheckedOutIdProperty(serviceRegistry));
registerPropertyAccessor(new CheckinCommentProperty(serviceRegistry));
registerPropertyAccessor(new ContentStreamLengthProperty(serviceRegistry));
registerPropertyAccessor(new ContentStreamMimetypeProperty(serviceRegistry));
registerPropertyAccessor(new ContentStreamIdProperty(serviceRegistry));
registerPropertyAccessor(new DirectProperty(serviceRegistry, PropertyIds.CONTENT_STREAM_FILE_NAME, ContentModel.PROP_NAME));
registerPropertyAccessor(new ParentProperty(serviceRegistry));
registerPropertyAccessor(new PathProperty(serviceRegistry, cmisConnector));
registerPropertyAccessor(new AllowedChildObjectTypeIdsProperty(serviceRegistry, cmisMapping));
registerPropertyAccessor(new SourceIdProperty(serviceRegistry));
registerPropertyAccessor(new TargetIdProperty(serviceRegistry));
//
// Action Evaluator Mappings
//
// NOTE: The order of evaluators is important - they must be in the
// order as specified in CMIS-Core.xsd
// so that schema validation passes
registerEvaluator(BaseTypeId.CMIS_DOCUMENT,
new CurrentVersionEvaluator(serviceRegistry, new PermissionActionEvaluator(serviceRegistry,
Action.CAN_DELETE_OBJECT, PermissionService.DELETE_NODE), false));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new CurrentVersionEvaluator(serviceRegistry,
new PermissionActionEvaluator(serviceRegistry, Action.CAN_UPDATE_PROPERTIES,
PermissionService.WRITE_PROPERTIES), false));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new PermissionActionEvaluator(serviceRegistry,
Action.CAN_GET_PROPERTIES, PermissionService.READ_PROPERTIES));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_GET_OBJECT_RELATIONSHIPS, true));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new ParentActionEvaluator(new PermissionActionEvaluator(
serviceRegistry, Action.CAN_GET_OBJECT_PARENTS, PermissionService.READ_PERMISSIONS)));
// Is CAN_MOVE correct mapping?
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new CurrentVersionEvaluator(serviceRegistry,
new PermissionActionEvaluator(serviceRegistry, Action.CAN_MOVE_OBJECT, PermissionService.DELETE_NODE),
false));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new CurrentVersionEvaluator(serviceRegistry,
new PermissionActionEvaluator(serviceRegistry, Action.CAN_DELETE_CONTENT_STREAM,
PermissionService.WRITE_PROPERTIES, PermissionService.WRITE_CONTENT), false));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new CurrentVersionEvaluator(serviceRegistry,
new CanCheckOutActionEvaluator(serviceRegistry), false));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new CurrentVersionEvaluator(serviceRegistry,
new PermissionActionEvaluator(serviceRegistry, Action.CAN_CANCEL_CHECK_OUT,
PermissionService.CANCEL_CHECK_OUT), false));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new PermissionActionEvaluator(serviceRegistry, Action.CAN_CHECK_IN,
PermissionService.CHECK_IN));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new CurrentVersionEvaluator(serviceRegistry,
new PermissionActionEvaluator(serviceRegistry, Action.CAN_SET_CONTENT_STREAM,
PermissionService.WRITE_CONTENT), false));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_GET_ALL_VERSIONS, true));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new CurrentVersionEvaluator(serviceRegistry,
new ParentActionEvaluator(new PermissionActionEvaluator(serviceRegistry,
Action.CAN_ADD_OBJECT_TO_FOLDER, PermissionService.LINK_CHILDREN)), false));
// Is CAN_REMOVE_FROM_FOLDER correct mapping?
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new CurrentVersionEvaluator(serviceRegistry,
new ParentActionEvaluator(new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_REMOVE_OBJECT_FROM_FOLDER, true)), false));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new PermissionActionEvaluator(serviceRegistry,
Action.CAN_GET_CONTENT_STREAM, PermissionService.READ_CONTENT));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_APPLY_POLICY, false));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_GET_APPLIED_POLICIES, true));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_REMOVE_POLICY, false));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new CurrentVersionEvaluator(serviceRegistry,
new FixedValueActionEvaluator<NodeRef>(serviceRegistry, Action.CAN_CREATE_RELATIONSHIP, true), false));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_GET_RENDITIONS, true));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new PermissionActionEvaluator(serviceRegistry, Action.CAN_GET_ACL,
PermissionService.READ_PERMISSIONS));
registerEvaluator(BaseTypeId.CMIS_DOCUMENT, new CurrentVersionEvaluator(serviceRegistry,
new PermissionActionEvaluator(serviceRegistry, Action.CAN_APPLY_ACL,
PermissionService.CHANGE_PERMISSIONS), false));
registerEvaluator(BaseTypeId.CMIS_FOLDER,
new RootFolderEvaluator(serviceRegistry, cmisConnector, new PermissionActionEvaluator(serviceRegistry,
Action.CAN_DELETE_OBJECT, PermissionService.DELETE_NODE), false));
registerEvaluator(BaseTypeId.CMIS_FOLDER, new PermissionActionEvaluator(serviceRegistry,
Action.CAN_UPDATE_PROPERTIES, PermissionService.WRITE_PROPERTIES));
registerEvaluator(BaseTypeId.CMIS_FOLDER, new PermissionActionEvaluator(serviceRegistry,
Action.CAN_GET_FOLDER_TREE, PermissionService.READ_CHILDREN));
registerEvaluator(BaseTypeId.CMIS_FOLDER, new PermissionActionEvaluator(serviceRegistry,
Action.CAN_GET_PROPERTIES, PermissionService.READ_PROPERTIES));
registerEvaluator(BaseTypeId.CMIS_FOLDER, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_GET_OBJECT_RELATIONSHIPS, true));
registerEvaluator(BaseTypeId.CMIS_FOLDER, new ParentActionEvaluator(new PermissionActionEvaluator(
serviceRegistry, Action.CAN_GET_OBJECT_PARENTS, PermissionService.READ_PERMISSIONS)));
registerEvaluator(BaseTypeId.CMIS_FOLDER, new RootFolderEvaluator(serviceRegistry, cmisConnector,
new ParentActionEvaluator(new PermissionActionEvaluator(serviceRegistry, Action.CAN_GET_FOLDER_PARENT,
PermissionService.READ_PERMISSIONS)), false));
registerEvaluator(BaseTypeId.CMIS_FOLDER, new PermissionActionEvaluator(serviceRegistry,
Action.CAN_GET_DESCENDANTS, PermissionService.READ_CHILDREN));
// Is CAN_MOVE_OBJECT correct mapping?
registerEvaluator(BaseTypeId.CMIS_FOLDER, new RootFolderEvaluator(serviceRegistry, cmisConnector,
new PermissionActionEvaluator(serviceRegistry, Action.CAN_MOVE_OBJECT, PermissionService.DELETE_NODE),
false));
registerEvaluator(BaseTypeId.CMIS_FOLDER, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_APPLY_POLICY, false));
registerEvaluator(BaseTypeId.CMIS_FOLDER, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_GET_APPLIED_POLICIES, true));
registerEvaluator(BaseTypeId.CMIS_FOLDER, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_REMOVE_POLICY, false));
registerEvaluator(BaseTypeId.CMIS_FOLDER, new PermissionActionEvaluator(serviceRegistry,
Action.CAN_GET_CHILDREN, PermissionService.READ_CHILDREN));
registerEvaluator(BaseTypeId.CMIS_FOLDER, new PermissionActionEvaluator(serviceRegistry,
Action.CAN_CREATE_DOCUMENT, PermissionService.CREATE_CHILDREN));
registerEvaluator(BaseTypeId.CMIS_FOLDER, new PermissionActionEvaluator(serviceRegistry,
Action.CAN_CREATE_FOLDER, PermissionService.CREATE_CHILDREN));
registerEvaluator(BaseTypeId.CMIS_FOLDER, new PermissionActionEvaluator(serviceRegistry,
Action.CAN_CREATE_RELATIONSHIP, PermissionService.CREATE_ASSOCIATIONS));
registerEvaluator(BaseTypeId.CMIS_FOLDER, new RootFolderEvaluator(serviceRegistry, cmisConnector,
new PermissionActionEvaluator(serviceRegistry, Action.CAN_DELETE_TREE, PermissionService.DELETE_NODE),
false));
registerEvaluator(BaseTypeId.CMIS_FOLDER, new PermissionActionEvaluator(serviceRegistry, Action.CAN_GET_ACL,
PermissionService.READ_PERMISSIONS));
registerEvaluator(BaseTypeId.CMIS_FOLDER, new PermissionActionEvaluator(serviceRegistry, Action.CAN_APPLY_ACL,
PermissionService.CHANGE_PERMISSIONS));
registerEvaluator(BaseTypeId.CMIS_RELATIONSHIP, new FixedValueActionEvaluator<AssociationRef>(serviceRegistry,
Action.CAN_DELETE_OBJECT, true));
registerEvaluator(BaseTypeId.CMIS_RELATIONSHIP, new FixedValueActionEvaluator<AssociationRef>(serviceRegistry,
Action.CAN_UPDATE_PROPERTIES, false));
registerEvaluator(BaseTypeId.CMIS_RELATIONSHIP, new FixedValueActionEvaluator<AssociationRef>(serviceRegistry,
Action.CAN_GET_PROPERTIES, true));
registerEvaluator(BaseTypeId.CMIS_RELATIONSHIP, new FixedValueActionEvaluator<AssociationRef>(serviceRegistry,
Action.CAN_GET_ACL, false));
registerEvaluator(BaseTypeId.CMIS_RELATIONSHIP, new FixedValueActionEvaluator<AssociationRef>(serviceRegistry,
Action.CAN_APPLY_ACL, false));
registerEvaluator(BaseTypeId.CMIS_POLICY, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_DELETE_OBJECT, false));
registerEvaluator(BaseTypeId.CMIS_POLICY, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_UPDATE_PROPERTIES, false));
registerEvaluator(BaseTypeId.CMIS_POLICY, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_GET_PROPERTIES, false));
registerEvaluator(BaseTypeId.CMIS_POLICY, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_GET_OBJECT_PARENTS, false));
registerEvaluator(BaseTypeId.CMIS_POLICY, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_MOVE_OBJECT, false));
registerEvaluator(BaseTypeId.CMIS_POLICY, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_ADD_OBJECT_TO_FOLDER, false));
registerEvaluator(BaseTypeId.CMIS_POLICY, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_REMOVE_OBJECT_FROM_FOLDER, false));
registerEvaluator(BaseTypeId.CMIS_POLICY, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_GET_OBJECT_RELATIONSHIPS, false));
registerEvaluator(BaseTypeId.CMIS_POLICY, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_GET_ACL, false));
registerEvaluator(BaseTypeId.CMIS_POLICY, new FixedValueActionEvaluator<NodeRef>(serviceRegistry,
Action.CAN_APPLY_ACL, false));
}
/**
* Gets a property accessor
*
* @param propertyId property id
* @return property accessor
*/
public CMISPropertyAccessor getPropertyAccessor(String propertyId)
{
return propertyAccessors.get(propertyId);
}
/**
* Create a direct node property accessor
*
* @param propertyId property id
* @param propertyName node property name
* @return property accessor
*/
public CMISPropertyAccessor createDirectPropertyAccessor(String propertyId, QName propertyName)
{
return new DirectProperty(serviceRegistry, propertyId, propertyName);
}
/**
* Register pre-defined Property Accessor
*
* @param propertyAccessor
*/
private void registerPropertyAccessor(AbstractProperty propertyAccessor)
{
propertyAccessors.put(propertyAccessor.getName(), propertyAccessor);
}
/**
* Gets the Action Evaluators applicable for the given CMIS Scope
*
* @param scope
*/
public Map<Action, CMISActionEvaluator<? extends Object>> getActionEvaluators(BaseTypeId scope)
{
Map<Action, CMISActionEvaluator<? extends Object>> evaluators = actionEvaluators.get(scope);
if (evaluators == null)
{
evaluators = Collections.emptyMap();
}
return evaluators;
}
/**
* Register an Action Evaluator
*
* @param scope
* @param evaluator
*/
private void registerEvaluator(BaseTypeId scope, CMISActionEvaluator<? extends Object> evaluator)
{
Map<Action, CMISActionEvaluator<? extends Object>> evaluators = actionEvaluators.get(scope);
if (evaluators == null)
{
evaluators = new LinkedHashMap<Action, CMISActionEvaluator<? extends Object>>();
actionEvaluators.put(scope, evaluators);
}
if (evaluators.get(evaluator.getAction()) != null)
{
throw new AlfrescoRuntimeException("Already registered Action Evaluator " + evaluator.getAction()
+ " for scope " + scope);
}
evaluators.put(evaluator.getAction(), evaluator);
if (logger.isDebugEnabled())
logger.debug("Registered Action Evaluator: scope=" + scope + ", evaluator=" + evaluator);
}
}