Merged DEV/SWIFT to HEAD

25458: added OpenCMIS server
   25555: Don't initialize servlet context if it is not present


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28000 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2011-05-24 02:23:57 +00:00
parent 0488757523
commit 00b8f4a002
76 changed files with 17777 additions and 32 deletions

View File

@@ -0,0 +1,65 @@
/*
* 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 org.alfresco.opencmis.CMISActionEvaluator;
import org.alfresco.service.ServiceRegistry;
import org.apache.chemistry.opencmis.commons.enums.Action;
/**
* Base class for all action evaluators
*
* @author davidc
*
*/
public abstract class AbstractActionEvaluator<T> implements CMISActionEvaluator<T>
{
private ServiceRegistry serviceRegistry;
private Action action;
/**
* Construct
*
* @param serviceRegistry
* @param action
*/
protected AbstractActionEvaluator(ServiceRegistry serviceRegistry, Action action)
{
this.serviceRegistry = serviceRegistry;
this.action = action;
}
/**
* @return service registry
*/
protected ServiceRegistry getServiceRegistry()
{
return serviceRegistry;
}
/*
* (non-Javadoc)
*
* @see org.alfresco.opencmis.CMISActionEvaluator#getAction()
*/
public Action getAction()
{
return action;
}
}

View File

@@ -0,0 +1,155 @@
/*
* 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.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.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
*
* @author andyh
*
*/
public abstract class AbstractProperty implements CMISPropertyAccessor, CMISPropertyLuceneBuilder
{
private ServiceRegistry serviceRegistry;
private String propertyName;
/**
* Construct
*
* @param serviceRegistry
* @param propertyName
*/
protected AbstractProperty(ServiceRegistry serviceRegistry, String propertyName)
{
this.serviceRegistry = serviceRegistry;
this.propertyName = propertyName;
}
/**
* @return service registry
*/
protected ServiceRegistry getServiceRegistry()
{
return serviceRegistry;
}
/*
* (non-Javadoc)
* @see org.alfresco.cmis.property.PropertyAccessor#getName()
*/
public String getName()
{
return propertyName;
}
/*
* (non-Javadoc)
* @see org.alfresco.cmis.property.PropertyAccessor#getMappedProperty()
*/
public QName getMappedProperty()
{
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();
}
public Serializable getValue(NodeRef nodeRef)
{
throw new UnsupportedOperationException();
}
public void setValue(NodeRef nodeRef, Serializable value)
{
throw new UnsupportedOperationException();
}
public Serializable getValue(AssociationRef assocRef)
{
throw new UnsupportedOperationException();
}
}

View File

@@ -0,0 +1,240 @@
/*
* 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

@@ -0,0 +1,125 @@
/*
* 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.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.version.VersionBaseModel;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.lock.LockType;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.version.Version;
import org.alfresco.service.cmr.version.VersionHistory;
import org.alfresco.service.namespace.QName;
/**
* Base class for versioning property accessors.
*
* @author dward
*
*/
public abstract class AbstractVersioningProperty extends AbstractProperty
{
/**
* Construct
*
* @param serviceRegistry
* @param propertyName
*/
protected AbstractVersioningProperty(ServiceRegistry serviceRegistry, String propertyName)
{
super(serviceRegistry, propertyName);
}
public NodeRef getVersionSeries(NodeRef nodeRef)
{
if (nodeRef.getStoreRef().getProtocol().equals(VersionBaseModel.STORE_PROTOCOL))
{
// Due to the remapping done for us by the versioned node services,
// we can simply look up the properties
// containing the component parts of the node ref to map back to the
// original node
Map<QName, Serializable> properties = getServiceRegistry().getNodeService().getProperties(nodeRef);
return new NodeRef((String) properties.get(ContentModel.PROP_STORE_PROTOCOL),
(String) properties.get(ContentModel.PROP_STORE_IDENTIFIER),
(String) properties.get(ContentModel.PROP_NODE_UUID));
} else if (isWorkingCopy(nodeRef))
{
return (NodeRef) getServiceRegistry().getNodeService().getProperty(nodeRef,
ContentModel.PROP_COPY_REFERENCE);
}
return nodeRef;
}
public boolean isWorkingCopy(NodeRef nodeRef)
{
return getServiceRegistry().getNodeService().hasAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY);
}
public boolean hasWorkingCopy(NodeRef nodeRef)
{
return getServiceRegistry().getLockService().getLockType(nodeRef) == LockType.READ_ONLY_LOCK;
}
public NodeRef getLiveNodeRef(NodeRef nodeRef)
{
if (nodeRef.getStoreRef().getProtocol().equals(VersionBaseModel.STORE_PROTOCOL))
{
VersionHistory versionHistory = getServiceRegistry().getVersionService().getVersionHistory(nodeRef);
if (versionHistory == null)
{
return nodeRef;
}
Version currentVersion = versionHistory.getHeadVersion();
Serializable versionLabel = getServiceRegistry().getNodeService().getProperty(nodeRef,
ContentModel.PROP_VERSION_LABEL);
if (currentVersion.getVersionLabel().equals(versionLabel))
{
return currentVersion.getVersionedNodeRef();
}
}
return nodeRef;
}
public boolean isCurrentVersion(NodeRef nodeRef)
{
if (nodeRef.getStoreRef().getProtocol().equals(VersionBaseModel.STORE_PROTOCOL))
{
VersionHistory versionHistory = getServiceRegistry().getVersionService().getVersionHistory(nodeRef);
if (versionHistory == null)
{
return true;
}
Version currentVersion = versionHistory.getHeadVersion();
Serializable versionLabel = getServiceRegistry().getNodeService().getProperty(nodeRef,
ContentModel.PROP_VERSION_LABEL);
return currentVersion.getVersionLabel().equals(versionLabel);
}
return true;
}
}

View File

@@ -0,0 +1,75 @@
/*
* 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.Collections;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.ChildAssociationDefinition;
import org.alfresco.service.cmr.dictionary.TypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.apache.chemistry.opencmis.commons.PropertyIds;
/**
* Get the CMIS allowedChildObjectTypeIds property.
*
* @author florian.mueller
*/
public class AllowedChildObjectTypeIdsProperty extends AbstractProperty
{
private CMISMapping cmisMapping;
/**
* Construct
*
* @param serviceRegistry
*/
public AllowedChildObjectTypeIdsProperty(ServiceRegistry serviceRegistry, CMISMapping cmisMapping)
{
super(serviceRegistry, PropertyIds.ALLOWED_CHILD_OBJECT_TYPE_IDS);
this.cmisMapping = cmisMapping;
}
@Override
public Serializable getValue(NodeRef nodeRef)
{
QName typeQName = getServiceRegistry().getNodeService().getType(nodeRef);
TypeDefinition type = getServiceRegistry().getDictionaryService().getType(typeQName);
if ((type != null) && (type.getChildAssociations() != null) && (!type.getChildAssociations().isEmpty()))
{
ArrayList<String> result = new ArrayList<String>();
for (ChildAssociationDefinition cad : type.getChildAssociations().values())
{
String typeId = cmisMapping.getCmisTypeId(cad.getTargetClass().getName());
if (typeId != null)
{
result.add(typeId);
}
}
return result;
}
return (Serializable) Collections.emptyList();
}
}

View File

@@ -0,0 +1,187 @@
/*
* 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.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.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;
/**
* Get the CMIS object type id property
*
* @author andyh
*/
public class BaseTypeIdProperty extends AbstractProperty
{
/**
* Construct
*
* @param serviceRegistry
*/
public BaseTypeIdProperty(ServiceRegistry serviceRegistry)
{
super(serviceRegistry, PropertyIds.BASE_TYPE_ID);
}
/*
* (non-Javadoc)
* @see org.alfresco.cmis.mapping.AbstractProperty#getValue(org.alfresco.service.cmr.repository.NodeRef)
*/
public Serializable getValue(NodeRef nodeRef)
{
QName type = getServiceRegistry().getNodeService().getType(nodeRef);
return getServiceRegistry().getCMISDictionaryService().findTypeForClass(type).getBaseType().getTypeId().getId();
}
/*
* (non-Javadoc)
* @see org.alfresco.cmis.mapping.AbstractProperty#getValue(org.alfresco.service.cmr.repository.AssociationRef)
*/
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;
}
}

View File

@@ -0,0 +1,879 @@
/*
* 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;
}
if (!isValidCmisDocumentOrFolder(getCmisType(associationDefinition.getSourceClass().getName())))
{
return false;
}
if (!isValidCmisDocumentOrFolder(getCmisType(associationDefinition.getTargetClass().getName())))
{
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

@@ -0,0 +1,66 @@
/*
* 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 org.alfresco.model.ContentModel;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.lock.LockService;
import org.alfresco.service.cmr.lock.LockType;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.security.PermissionService;
import org.apache.chemistry.opencmis.commons.enums.Action;
/**
* Alfresco Permission based Action Evaluator
*
* @author davidc
*/
public class CanCheckOutActionEvaluator extends AbstractActionEvaluator<NodeRef>
{
private PermissionActionEvaluator permissionEvaluator;
private NodeService nodeService;
private LockService lockService;
/**
* Construct
*
* @param serviceRegistry
* @param permission
*/
protected CanCheckOutActionEvaluator(ServiceRegistry serviceRegistry)
{
super(serviceRegistry, Action.CAN_CHECK_OUT);
permissionEvaluator = new PermissionActionEvaluator(serviceRegistry, Action.CAN_CHECK_OUT,
PermissionService.CHECK_OUT);
nodeService = serviceRegistry.getNodeService();
lockService = serviceRegistry.getLockService();
}
public boolean isAllowed(NodeRef nodeRef)
{
if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY)
|| lockService.getLockType(nodeRef) == LockType.READ_ONLY_LOCK)
{
return false;
}
return permissionEvaluator.isAllowed(nodeRef);
}
}

View File

@@ -0,0 +1,76 @@
/*
* 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 org.alfresco.cmis.CMISDictionaryModel;
import org.alfresco.model.ContentModel;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.version.Version;
import org.alfresco.service.cmr.version.VersionHistory;
/**
* Accessor for the CMIS Checkin Comment
*
* @author dward
*/
public class CheckinCommentProperty extends AbstractVersioningProperty
{
/**
* Construct
*
* @param serviceRegistry
*/
public CheckinCommentProperty(ServiceRegistry serviceRegistry)
{
super(serviceRegistry, CMISDictionaryModel.PROP_CHECKIN_COMMENT);
}
/*
* (non-Javadoc)
* @see org.alfresco.cmis.property.PropertyAccessor#getValue(org.alfresco.service.cmr.repository.NodeRef)
*/
public Serializable getValue(NodeRef nodeRef)
{
if (isWorkingCopy(nodeRef))
{
return null;
}
ServiceRegistry serviceRegistry = getServiceRegistry();
String versionLabel = (String)serviceRegistry.getNodeService().getProperty(nodeRef, ContentModel.PROP_VERSION_LABEL);
if (versionLabel == null)
{
return null;
}
NodeRef versionSeries = getVersionSeries(nodeRef);
VersionHistory versionHistory = serviceRegistry.getVersionService().getVersionHistory(versionSeries);
if (versionHistory == null)
{
return null;
}
Version version = versionHistory.getVersion(versionLabel);
if (version == null)
{
return null;
}
return version.getDescription();
}
}

View File

@@ -0,0 +1,65 @@
/*
* 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 org.alfresco.model.ContentModel;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.apache.chemistry.opencmis.commons.PropertyIds;
/**
* Accessor for CMIS content stream property id
*
* @author andyh
*/
public class ContentStreamIdProperty extends AbstractProperty
{
/**
* Construct
*
* @param serviceRegistry
*/
public ContentStreamIdProperty(ServiceRegistry serviceRegistry)
{
super(serviceRegistry, PropertyIds.CONTENT_STREAM_ID);
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.PropertyAccessor#getValue(org.alfresco.service
* .cmr.repository.NodeRef)
*/
public Serializable getValue(NodeRef nodeRef)
{
Serializable sValue = getServiceRegistry().getNodeService().getProperty(nodeRef, ContentModel.PROP_CONTENT);
if (sValue != null)
{
ContentData contentData = DefaultTypeConverter.INSTANCE.convert(ContentData.class, sValue);
return contentData.getContentUrl();
}
return null;
}
}

View File

@@ -0,0 +1,95 @@
/*
* 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 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;
/**
* Accessor for CMIS content stream length property
*
* @author andyh
*/
public class ContentStreamLengthProperty extends AbstractSimpleProperty
{
/**
* Construct
*
* @param serviceRegistry
*/
public ContentStreamLengthProperty(ServiceRegistry serviceRegistry)
{
super(serviceRegistry, PropertyIds.CONTENT_STREAM_LENGTH);
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.PropertyAccessor#getValue(org.alfresco.service
* .cmr.repository.NodeRef)
*/
public Serializable getValue(NodeRef nodeRef)
{
Serializable value = getServiceRegistry().getNodeService().getProperty(nodeRef, ContentModel.PROP_CONTENT);
if (value != null)
{
ContentData contentData = DefaultTypeConverter.INSTANCE.convert(ContentData.class, value);
return contentData.getSize();
} else
{
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

@@ -0,0 +1,95 @@
/*
* 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 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;
/**
* Accessor for CMIS content stream mimetype property
*
* @author andyh
*/
public class ContentStreamMimetypeProperty extends AbstractSimpleProperty
{
/**
* Construct
*
* @param serviceRegistry
*/
public ContentStreamMimetypeProperty(ServiceRegistry serviceRegistry)
{
super(serviceRegistry, PropertyIds.CONTENT_STREAM_MIME_TYPE);
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.PropertyAccessor#getValue(org.alfresco.service
* .cmr.repository.NodeRef)
*/
public Serializable getValue(NodeRef nodeRef)
{
Serializable value = getServiceRegistry().getNodeService().getProperty(nodeRef, ContentModel.PROP_CONTENT);
if (value != null)
{
ContentData contentData = DefaultTypeConverter.INSTANCE.convert(ContentData.class, value);
return contentData.getMimetype();
} else
{
return "";
}
}
public String getLuceneFieldName()
{
StringBuilder field = new StringBuilder(128);
field.append("@");
field.append(ContentModel.PROP_CONTENT);
field.append(".mimetype");
return field.toString();
}
protected String getValueAsString(Serializable value)
{
Object converted = DefaultTypeConverter.INSTANCE.convert(getServiceRegistry().getDictionaryService()
.getDataType(DataTypeDefinition.TEXT), 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.TEXT);
}
}

View File

@@ -0,0 +1,84 @@
/*
* 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 org.alfresco.model.ContentModel;
import org.alfresco.opencmis.CMISActionEvaluator;
import org.alfresco.repo.version.VersionBaseModel;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.version.Version;
import org.alfresco.service.cmr.version.VersionHistory;
import org.apache.chemistry.opencmis.commons.enums.Action;
public class CurrentVersionEvaluator extends AbstractActionEvaluator<NodeRef>
{
private CMISActionEvaluator<NodeRef> currentVersionEvaluator;
private boolean currentVersionValue;
private boolean nonCurrentVersionValue;
/**
* Construct
*
* @param serviceRegistry
*/
protected CurrentVersionEvaluator(ServiceRegistry serviceRegistry, Action action, boolean currentVersionValue,
boolean nonCurrentVersionValue)
{
super(serviceRegistry, action);
this.currentVersionValue = currentVersionValue;
this.nonCurrentVersionValue = nonCurrentVersionValue;
}
/**
* Construct
*
* @param serviceRegistry
*/
protected CurrentVersionEvaluator(ServiceRegistry serviceRegistry,
CMISActionEvaluator<NodeRef> currentVersionEvaluator, boolean nonCurrentVersionValue)
{
super(serviceRegistry, currentVersionEvaluator.getAction());
this.currentVersionEvaluator = currentVersionEvaluator;
this.nonCurrentVersionValue = nonCurrentVersionValue;
}
public boolean isAllowed(NodeRef nodeRef)
{
if (nodeRef.getStoreRef().getProtocol().equals(VersionBaseModel.STORE_PROTOCOL))
{
VersionHistory versionHistory = getServiceRegistry().getVersionService().getVersionHistory(nodeRef);
if (versionHistory != null)
{
Version currentVersion = versionHistory.getHeadVersion();
Serializable versionLabel = getServiceRegistry().getNodeService().getProperty(nodeRef,
ContentModel.PROP_VERSION_LABEL);
if (!currentVersion.getVersionLabel().equals(versionLabel))
{
return nonCurrentVersionValue;
}
}
}
return currentVersionEvaluator == null ? currentVersionValue : currentVersionEvaluator.isAllowed(nodeRef);
}
}

View File

@@ -0,0 +1,207 @@
/*
* 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.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
{
/*
* (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;
/**
* Construct
*
* @param serviceRegistry
* @param propertyName
* @param alfrescoName
*/
public DirectProperty(ServiceRegistry serviceRegistry, String propertyName, QName alfrescoName)
{
super(serviceRegistry, propertyName);
this.alfrescoName = alfrescoName;
}
/*
* (non-Javadoc)
* @see org.alfresco.cmis.property.AbstractPropertyAccessor#getMappedProperty()
*/
public QName getMappedProperty()
{
return alfrescoName;
}
/*
* (non-Javadoc)
* @see org.alfresco.cmis.property.PropertyAccessor#getValue(org.alfresco.service.cmr.repository.NodeRef)
*/
public Serializable getValue(NodeRef nodeRef)
{
return getServiceRegistry().getNodeService().getProperty(nodeRef, alfrescoName);
}
/*
* (non-Javadoc)
* @see org.alfresco.cmis.mapping.AbstractProperty#getValue(org.alfresco.service.cmr.repository.AssociationRef)
*/
public Serializable getValue(AssociationRef assocRef)
{
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

@@ -0,0 +1,59 @@
/*
* 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 org.alfresco.service.ServiceRegistry;
import org.apache.chemistry.opencmis.commons.enums.Action;
/**
* Action Evaluator whose evaluation is fixed
*
* @author davidc
*
*/
public class FixedValueActionEvaluator<T> extends AbstractActionEvaluator<T>
{
private boolean allowed;
/**
* Construct
*
* @param serviceRegistry
* @param action
*/
protected FixedValueActionEvaluator(ServiceRegistry serviceRegistry, Action action, boolean allowed)
{
super(serviceRegistry, action);
this.allowed = allowed;
}
public boolean isAllowed(T object)
{
return allowed;
}
@Override
public String toString()
{
StringBuilder builder = new StringBuilder();
builder.append("FixedValueActionEvaluator[action=").append(getAction());
builder.append(", allowed=").append(allowed).append("]");
return builder.toString();
}
}

View File

@@ -0,0 +1,320 @@
/*
* 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 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)
*
* @author andyh
*/
public class FixedValueProperty extends AbstractProperty
{
private Serializable value;
/**
* Construct
*
* @param serviceRegistry
* @param propertyName
* @param value
*/
public FixedValueProperty(ServiceRegistry serviceRegistry, String propertyName, Serializable value)
{
super(serviceRegistry, propertyName);
this.value = value;
}
/*
* (non-Javadoc)
* @see org.alfresco.cmis.property.PropertyAccessor#getValue(org.alfresco.service.cmr.repository.NodeRef)
*/
public Serializable getValue(NodeRef nodeRef)
{
return value;
}
/*
* (non-Javadoc)
* @see org.alfresco.cmis.mapping.AbstractProperty#getValue(org.alfresco.service.cmr.repository.AssociationRef)
*/
public Serializable getValue(AssociationRef assocRef)
{
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

@@ -0,0 +1,67 @@
/*
* 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 org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.apache.chemistry.opencmis.commons.PropertyIds;
/**
* Property accessor for CMIS is immutable property
*
* @author dward
*/
public class IsImmutableProperty extends AbstractVersioningProperty
{
/**
* Construct
*
* @param serviceRegistry
*/
public IsImmutableProperty(ServiceRegistry serviceRegistry)
{
super(serviceRegistry, PropertyIds.IS_IMMUTABLE);
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.PropertyAccessor#getValue(org.alfresco.service
* .cmr.repository.NodeRef)
*/
public Serializable getValue(NodeRef nodeRef)
{
if (!isCurrentVersion(nodeRef))
{
return true;
}
if (isWorkingCopy(nodeRef))
{
return false;
}
if (getVersionSeries(nodeRef).equals(nodeRef))
{
return hasWorkingCopy(nodeRef);
}
return true;
}
}

View File

@@ -0,0 +1,106 @@
/*
* 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 org.alfresco.model.ContentModel;
import org.alfresco.repo.version.VersionBaseModel;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.version.Version;
import org.alfresco.service.cmr.version.VersionHistory;
import org.alfresco.service.cmr.version.VersionService;
import org.alfresco.service.cmr.version.VersionType;
import org.apache.chemistry.opencmis.commons.PropertyIds;
/**
* Accessor for CMIS is latest major version property
*
* @author dward
*/
public class IsLatestMajorVersionProperty extends AbstractVersioningProperty
{
/**
* Construct
*
* @param serviceRegistry
*/
public IsLatestMajorVersionProperty(ServiceRegistry serviceRegistry)
{
super(serviceRegistry, PropertyIds.IS_LATEST_MAJOR_VERSION);
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.PropertyAccessor#getValue(org.alfresco.service
* .cmr.repository.NodeRef)
*/
public Serializable getValue(NodeRef nodeRef)
{
if (isWorkingCopy(nodeRef))
{
return false;
}
NodeRef versionSeries = getVersionSeries(nodeRef);
ServiceRegistry serviceRegistry = getServiceRegistry();
VersionService versionService = serviceRegistry.getVersionService();
VersionHistory versionHistory = versionService.getVersionHistory(versionSeries);
if (versionHistory == null)
{
return false;
}
NodeRef versionNodeRef = nodeRef;
if (!nodeRef.getStoreRef().getProtocol().equals(VersionBaseModel.STORE_PROTOCOL))
{
String versionLabel = (String) serviceRegistry.getNodeService().getProperty(nodeRef,
ContentModel.PROP_VERSION_LABEL);
if (versionLabel == null)
{
return false;
}
Version version = versionHistory.getVersion(versionLabel);
if (version == null)
{
return false;
}
versionNodeRef = version.getFrozenStateNodeRef();
}
// Go back in time to the last major version
Version currentVersion = versionService.getCurrentVersion(versionSeries);
while (currentVersion != null)
{
if (currentVersion.getVersionType() == VersionType.MAJOR)
{
return currentVersion.getFrozenStateNodeRef().equals(versionNodeRef);
}
// We got to the current node and its not major. We failed!
else if (currentVersion.getFrozenStateNodeRef().equals(versionNodeRef))
{
return false;
}
currentVersion = versionHistory.getPredecessor(currentVersion);
}
return false;
}
}

View File

@@ -0,0 +1,85 @@
/*
* 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 org.alfresco.model.ContentModel;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.version.Version;
import org.alfresco.service.cmr.version.VersionHistory;
import org.apache.chemistry.opencmis.commons.PropertyIds;
/**
* Accesser for CMIS is latest version property
*
* @author dward
*/
public class IsLatestVersionProperty extends AbstractVersioningProperty
{
/**
* Construct
*
* @param serviceRegistry
*/
public IsLatestVersionProperty(ServiceRegistry serviceRegistry)
{
super(serviceRegistry, PropertyIds.IS_LATEST_VERSION);
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.PropertyAccessor#getValue(org.alfresco.service
* .cmr.repository.NodeRef)
*/
public Serializable getValue(NodeRef nodeRef)
{
if (isWorkingCopy(nodeRef) || getVersionSeries(nodeRef).equals(nodeRef) && !hasWorkingCopy(nodeRef))
{
return true;
}
NodeRef versionSeries = getVersionSeries(nodeRef);
if (hasWorkingCopy(versionSeries))
{
return false;
}
ServiceRegistry serviceRegistry = getServiceRegistry();
String versionLabel = (String) serviceRegistry.getNodeService().getProperty(nodeRef,
ContentModel.PROP_VERSION_LABEL);
if (versionLabel == null)
{
return false;
}
VersionHistory versionHistory = serviceRegistry.getVersionService().getVersionHistory(versionSeries);
if (versionHistory == null)
{
return false;
}
Version version = versionHistory.getVersion(versionLabel);
if (version == null)
{
return false;
}
return versionHistory.getHeadVersion().getFrozenStateNodeRef().equals(version.getFrozenStateNodeRef());
}
}

View File

@@ -0,0 +1,75 @@
/*
* 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 org.alfresco.model.ContentModel;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.version.VersionHistory;
import org.alfresco.service.cmr.version.VersionType;
import org.apache.chemistry.opencmis.commons.PropertyIds;
/**
* Accessor for CMIS is major version property
*
* @author dward
*/
public class IsMajorVersionProperty extends AbstractVersioningProperty
{
/**
* Construct
*
* @param serviceRegistry
*/
public IsMajorVersionProperty(ServiceRegistry serviceRegistry)
{
super(serviceRegistry, PropertyIds.IS_MAJOR_VERSION);
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.PropertyAccessor#getValue(org.alfresco.service
* .cmr.repository.NodeRef)
*/
public Serializable getValue(NodeRef nodeRef)
{
if (isWorkingCopy(nodeRef))
{
return false;
}
ServiceRegistry serviceRegistry = getServiceRegistry();
String versionLabel = (String) serviceRegistry.getNodeService().getProperty(nodeRef,
ContentModel.PROP_VERSION_LABEL);
if (versionLabel == null)
{
return false;
}
NodeRef versionSeries = getVersionSeries(nodeRef);
VersionHistory versionHistory = serviceRegistry.getVersionService().getVersionHistory(versionSeries);
if (versionHistory == null)
{
return false;
}
return versionHistory.getVersion(versionLabel).getVersionType() == VersionType.MAJOR;
}
}

View File

@@ -0,0 +1,55 @@
/*
* 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 org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.apache.chemistry.opencmis.commons.PropertyIds;
/**
* Get the CMIS version series checked out property
*
* @author dward
*/
public class IsVersionSeriesCheckedOutProperty extends AbstractVersioningProperty
{
/**
* Construct
*
* @param serviceRegistry
*/
public IsVersionSeriesCheckedOutProperty(ServiceRegistry serviceRegistry)
{
super(serviceRegistry, PropertyIds.IS_VERSION_SERIES_CHECKED_OUT);
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.PropertyAccessor#getValue(org.alfresco.service
* .cmr.repository.NodeRef)
*/
public Serializable getValue(NodeRef nodeRef)
{
return isWorkingCopy(nodeRef) || hasWorkingCopy(getVersionSeries(nodeRef));
}
}

View File

@@ -0,0 +1,54 @@
/*
* Copyright (C) 2005-2011 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 org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* Get the CMIS object id property.
*/
public class NodeRefProperty extends AbstractVersioningProperty
{
public static final String NodeRefPropertyId = "alf:nodeRef";
/**
* Construct
*
* @param serviceRegistry
*/
public NodeRefProperty(ServiceRegistry serviceRegistry)
{
super(serviceRegistry, NodeRefPropertyId);
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.mapping.AbstractProperty#getValue(org.alfresco.service
* .cmr.repository.NodeRef)
*/
public Serializable getValue(NodeRef nodeRef)
{
return getLiveNodeRef(nodeRef);
}
}

View File

@@ -0,0 +1,334 @@
/*
* 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.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.
*
* @author andyh
* @author dward
*/
public class ObjectIdProperty extends AbstractVersioningProperty
{
/**
* Construct
*
* @param serviceRegistry
*/
public ObjectIdProperty(ServiceRegistry serviceRegistry)
{
super(serviceRegistry, PropertyIds.OBJECT_ID);
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.mapping.AbstractProperty#getValue(org.alfresco.service
* .cmr.repository.NodeRef)
*/
public Serializable getValue(NodeRef nodeRef)
{
if (isWorkingCopy(nodeRef))
{
return nodeRef.toString();
}
QName typeQName = getServiceRegistry().getNodeService().getType(nodeRef);
if (typeQName.equals(CMISMapping.DOCUMENT_QNAME)
|| getServiceRegistry().getDictionaryService().isSubClass(typeQName, ContentModel.TYPE_CONTENT))
{
Serializable versionLabel = getServiceRegistry().getNodeService().getProperty(nodeRef,
ContentModel.PROP_VERSION_LABEL);
if (versionLabel == null)
{
versionLabel = CMISConnector.UNVERSIONED_VERSION_LABEL;
}
NodeRef versionSeries = getVersionSeries(nodeRef);
return new StringBuilder(1024).append(versionSeries.toString()).append(CMISConnector.ID_SEPERATOR)
.append(versionLabel).toString();
}
return nodeRef.toString();
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.mapping.AbstractProperty#getValue(org.alfresco.service
* .cmr.repository.AssociationRef)
*/
public Serializable getValue(AssociationRef assocRef)
{
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

@@ -0,0 +1,321 @@
/*
* 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 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.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;
/**
* Get the CMIS object type id property
*
* @author andyh
*/
public class ObjectTypeIdProperty extends AbstractProperty
{
/**
* Construct
*
* @param serviceRegistry
*/
public ObjectTypeIdProperty(ServiceRegistry serviceRegistry)
{
super(serviceRegistry, PropertyIds.OBJECT_TYPE_ID);
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.mapping.AbstractProperty#getValue(org.alfresco.service
* .cmr.repository.NodeRef)
*/
public Serializable getValue(NodeRef nodeRef)
{
QName type = getServiceRegistry().getNodeService().getType(nodeRef);
return getServiceRegistry().getCMISDictionaryService().findTypeForClass(type).getTypeId().getId();
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.mapping.AbstractProperty#getValue(org.alfresco.service
* .cmr.repository.AssociationRef)
*/
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();
}
}

View File

@@ -0,0 +1,77 @@
/*
* 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 org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* Action Evaluator whose evaluation takes place on parent
*
* @author davidc
*/
public class ParentActionEvaluator extends AbstractActionEvaluator<NodeRef>
{
private AbstractActionEvaluator<NodeRef> evaluator;
/**
* Construct
*
* @param serviceRegistry
* @param action
*/
protected ParentActionEvaluator(AbstractActionEvaluator<NodeRef> evaluator)
{
super(evaluator.getServiceRegistry(), evaluator.getAction());
this.evaluator = evaluator;
}
/*
* (non-Javadoc)
* @see org.alfresco.cmis.CMISActionEvaluator#isAllowed(org.alfresco.service.cmr.repository.NodeRef)
*/
public boolean isAllowed(NodeRef nodeRef)
{
if (nodeRef.equals(getServiceRegistry().getCMISService().getDefaultRootNodeRef()))
{
return false;
}
ChildAssociationRef car = getServiceRegistry().getNodeService().getPrimaryParent(nodeRef);
if ((car != null) && (car.getParentRef() != null))
{
return evaluator.isAllowed(car.getParentRef());
}
return false;
}
/*
* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
StringBuilder builder = new StringBuilder();
builder.append("ParentActionEvaluator[evaluator=").append(evaluator).append("]");
return builder.toString();
}
}

View File

@@ -0,0 +1,246 @@
/*
* 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.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
*
* @author andyh
*
*/
public class ParentProperty extends AbstractProperty
{
/**
* Construct
*
* @param serviceRegistry
*/
public ParentProperty(ServiceRegistry serviceRegistry)
{
super(serviceRegistry, PropertyIds.PARENT_ID);
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.PropertyAccessor#getValue(org.alfresco.service
* .cmr.repository.NodeRef)
*/
public Serializable getValue(NodeRef nodeRef)
{
if (nodeRef.equals(getServiceRegistry().getCMISService().getDefaultRootNodeRef()))
{
return null;
}
ChildAssociationRef car = getServiceRegistry().getNodeService().getPrimaryParent(nodeRef);
if ((car != null) && (car.getParentRef() != null))
{
return car.getParentRef().toString();
} else
{
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

@@ -0,0 +1,119 @@
/*
* 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 org.alfresco.model.ContentModel;
import org.alfresco.opencmis.CMISConnector;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.Path;
import org.alfresco.service.cmr.repository.Path.ChildAssocElement;
import org.apache.chemistry.opencmis.commons.PropertyIds;
/**
* Get the CMIS path property.
*
* @author davidc
*/
public class PathProperty extends AbstractProperty
{
private CMISConnector cmisConnector;
/**
* Construct
*
* @param serviceRegistry
*/
public PathProperty(ServiceRegistry serviceRegistry, CMISConnector cmisConnector)
{
super(serviceRegistry, PropertyIds.PATH);
this.cmisConnector = cmisConnector;
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.mapping.AbstractProperty#getValue(org.alfresco.service
* .cmr.repository.NodeRef)
*/
public Serializable getValue(NodeRef nodeRef)
{
Path path = getServiceRegistry().getNodeService().getPath(nodeRef);
return toDisplayPath(path);
}
private String toDisplayPath(Path path)
{
StringBuilder displayPath = new StringBuilder(64);
// skip to CMIS root path
NodeRef rootNode = cmisConnector.getRootNodeRef();
int i = 0;
while (i < path.size())
{
Path.Element element = path.get(i);
if (element instanceof ChildAssocElement)
{
ChildAssociationRef assocRef = ((ChildAssocElement) element).getRef();
NodeRef node = assocRef.getChildRef();
if (node.equals(rootNode))
{
break;
}
}
i++;
}
if (i == path.size())
{
// TODO:
// throw new AlfrescoRuntimeException("Path " + path +
// " not in CMIS root node scope");
}
if (path.size() - i == 1)
{
// render root path
displayPath.append("/");
} else
{
// render CMIS scoped path
i++;
while (i < path.size())
{
Path.Element element = path.get(i);
if (element instanceof ChildAssocElement)
{
ChildAssociationRef assocRef = ((ChildAssocElement) element).getRef();
NodeRef node = assocRef.getChildRef();
displayPath.append("/");
displayPath.append(getServiceRegistry().getNodeService().getProperty(node, ContentModel.PROP_NAME));
}
i++;
}
}
return displayPath.toString();
}
}

View File

@@ -0,0 +1,81 @@
/*
* 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 org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.cmr.security.PermissionService;
import org.apache.chemistry.opencmis.commons.enums.Action;
/**
* Alfresco Permission based Action Evaluator
*
* @author davidc
*/
public class PermissionActionEvaluator extends AbstractActionEvaluator<NodeRef>
{
private String[] permissions;
private PermissionService permissionService;
/**
* Construct
*
* @param serviceRegistry
* @param permission
*/
protected PermissionActionEvaluator(ServiceRegistry serviceRegistry, Action action, String... permission)
{
super(serviceRegistry, action);
this.permissions = permission;
this.permissionService = serviceRegistry.getPermissionService();
}
/*
* (non-Javadoc)
* @see org.alfresco.cmis.CMISActionEvaluator#isAllowed(org.alfresco.service.cmr.repository.NodeRef)
*/
public boolean isAllowed(NodeRef nodeRef)
{
for (String permission : permissions)
{
if (permissionService.hasPermission(nodeRef, permission) == AccessStatus.DENIED)
{
return false;
}
}
return true;
}
@Override
public String toString()
{
StringBuilder builder = new StringBuilder();
builder.append("PermissionActionEvaluator[action=").append(getAction());
builder.append(", permissions=");
for (String permission : permissions)
{
builder.append(permission).append(",");
}
builder.append("]");
return builder.toString();
}
}

View File

@@ -0,0 +1,50 @@
/*
* 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 org.alfresco.opencmis.CMISActionEvaluator;
import org.alfresco.opencmis.CMISConnector;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
public class RootFolderEvaluator extends AbstractActionEvaluator<NodeRef>
{
private CMISConnector cmisConnector;
private CMISActionEvaluator<NodeRef> folderEvaluator;
private boolean rootFolderValue;
protected RootFolderEvaluator(ServiceRegistry serviceRegistry, CMISConnector cmisConnector,
CMISActionEvaluator<NodeRef> folderEvaluator, boolean rootFolderValue)
{
super(serviceRegistry, folderEvaluator.getAction());
this.cmisConnector = cmisConnector;
this.folderEvaluator = folderEvaluator;
this.rootFolderValue = rootFolderValue;
}
public boolean isAllowed(NodeRef nodeRef)
{
if (cmisConnector.getRootNodeRef().equals(nodeRef))
{
return rootFolderValue;
}
return folderEvaluator.isAllowed(nodeRef);
}
}

View File

@@ -0,0 +1,55 @@
/*
* 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 org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.apache.chemistry.opencmis.commons.PropertyIds;
/**
* Accessor for the Source Id (relationship)
*
* @author davidc
*/
public class SourceIdProperty extends AbstractProperty
{
/**
* Construct
*
* @param serviceRegistry
*/
public SourceIdProperty(ServiceRegistry serviceRegistry)
{
super(serviceRegistry, PropertyIds.SOURCE_ID);
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.mapping.AbstractProperty#getValue(org.alfresco.service
* .cmr.repository.AssociationRef)
*/
public Serializable getValue(AssociationRef assocRef)
{
return assocRef.getSourceRef().toString();
}
}

View File

@@ -0,0 +1,55 @@
/*
* 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 org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.apache.chemistry.opencmis.commons.PropertyIds;
/**
* Accessor for the Target Id (relationship)
*
* @author davidc
*/
public class TargetIdProperty extends AbstractProperty
{
/**
* Construct
*
* @param serviceRegistry
*/
public TargetIdProperty(ServiceRegistry serviceRegistry)
{
super(serviceRegistry, PropertyIds.TARGET_ID);
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.mapping.AbstractProperty#getValue(org.alfresco.service
* .cmr.repository.AssociationRef)
*/
public Serializable getValue(AssociationRef assocRef)
{
return assocRef.getTargetRef().toString();
}
}

View File

@@ -0,0 +1,65 @@
/*
* 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 org.alfresco.model.ContentModel;
import org.alfresco.opencmis.CMISConnector;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.apache.chemistry.opencmis.commons.PropertyIds;
/**
* @author dward
*/
public class VersionLabelProperty extends AbstractVersioningProperty
{
/**
* Construct
*
* @param serviceRegistry
*/
public VersionLabelProperty(ServiceRegistry serviceRegistry)
{
super(serviceRegistry, PropertyIds.VERSION_LABEL);
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.PropertyAccessor#getValue(org.alfresco.service
* .cmr.repository.NodeRef)
*/
public Serializable getValue(NodeRef nodeRef)
{
if (isWorkingCopy(nodeRef))
{
return CMISConnector.PWC_VERSION_LABEL;
}
Serializable versionLabel = getServiceRegistry().getNodeService().getProperty(nodeRef,
ContentModel.PROP_VERSION_LABEL);
if (versionLabel == null)
{
return CMISConnector.UNVERSIONED_VERSION_LABEL;
}
return versionLabel;
}
}

View File

@@ -0,0 +1,64 @@
/*
* 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 org.alfresco.model.ContentModel;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.apache.chemistry.opencmis.commons.PropertyIds;
/**
* Get the CMIS version series checked out by property
*
* @author dward
*/
public class VersionSeriesCheckedOutByProperty extends AbstractVersioningProperty
{
/**
* Construct
*
* @param serviceRegistry
*/
public VersionSeriesCheckedOutByProperty(ServiceRegistry serviceRegistry)
{
super(serviceRegistry, PropertyIds.VERSION_SERIES_CHECKED_OUT_BY);
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.PropertyAccessor#getValue(org.alfresco.service
* .cmr.repository.NodeRef)
*/
public Serializable getValue(NodeRef nodeRef)
{
NodeRef versionSeries;
if (isWorkingCopy(nodeRef))
{
return getServiceRegistry().getNodeService().getProperty(nodeRef, ContentModel.PROP_WORKING_COPY_OWNER);
} else if (hasWorkingCopy((versionSeries = getVersionSeries(nodeRef))))
{
return getServiceRegistry().getNodeService().getProperty(versionSeries, ContentModel.PROP_LOCK_OWNER);
}
return null;
}
}

View File

@@ -0,0 +1,67 @@
/*
* 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 org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.apache.chemistry.opencmis.commons.PropertyIds;
/**
* Get the CMIS version series checked out id property
*
* @author dward
*/
public class VersionSeriesCheckedOutIdProperty extends AbstractVersioningProperty
{
/**
* Construct
*
* @param serviceRegistry
*/
public VersionSeriesCheckedOutIdProperty(ServiceRegistry serviceRegistry)
{
super(serviceRegistry, PropertyIds.VERSION_SERIES_CHECKED_OUT_ID);
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.PropertyAccessor#getValue(org.alfresco.service
* .cmr.repository.NodeRef)
*/
public Serializable getValue(NodeRef nodeRef)
{
NodeRef versionSeries;
if (isWorkingCopy(nodeRef))
{
return nodeRef.toString();
} else if (hasWorkingCopy((versionSeries = getVersionSeries(nodeRef))))
{
NodeRef pwc = getServiceRegistry().getCheckOutCheckInService().getWorkingCopy(versionSeries);
if (pwc != null)
{
return pwc.toString();
}
}
return null;
}
}

View File

@@ -0,0 +1,62 @@
/*
* 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 org.alfresco.model.ContentModel;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.apache.chemistry.opencmis.commons.PropertyIds;
/**
* @author dward
*/
public class VersionSeriesIdProperty extends AbstractVersioningProperty
{
/**
* Construct
*
* @param serviceRegistry
*/
public VersionSeriesIdProperty(ServiceRegistry serviceRegistry)
{
super(serviceRegistry, PropertyIds.VERSION_SERIES_ID);
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.property.PropertyAccessor#getValue(org.alfresco.service
* .cmr.repository.NodeRef)
*/
public Serializable getValue(NodeRef nodeRef)
{
NodeService nodeService = getServiceRegistry().getNodeService();
if (isWorkingCopy(nodeRef))
{
return nodeService.getProperty(nodeRef, ContentModel.PROP_COPY_REFERENCE).toString();
} else
{
return getVersionSeries(nodeRef).toString();
}
}
}