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

@@ -70,6 +70,9 @@ public class CMISMapping implements InitializingBean
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.
*/
@@ -87,7 +90,7 @@ public class CMISMapping implements InitializingBean
public static QName CMIS_DATATYPE_HTML = QName.createQName(CMIS_MODEL_URI, "html");
// CMIS Types
public static QName OBJECT_QNAME = QName.createQName(CMIS_MODEL_URI, "object");
public static QName OBJECT_QNAME = QName.createQName(CMIS_EXT_URI, "object");
public static QName FILESYSTEM_OBJECT_QNAME = QName.createQName(CMIS_MODEL_URI, "filesystemobject");
public static QName DOCUMENT_QNAME = QName.createQName(CMIS_MODEL_URI, "document");
public static QName FOLDER_QNAME = QName.createQName(CMIS_MODEL_URI, "folder");

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,74 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.opencmis;
import java.util.Map;
import org.apache.chemistry.opencmis.commons.impl.server.AbstractServiceFactory;
import org.apache.chemistry.opencmis.commons.server.CallContext;
import org.apache.chemistry.opencmis.commons.server.CmisService;
import org.apache.chemistry.opencmis.server.support.CmisServiceWrapper;
/**
* Factory for OpenCMIS service objects.
*
* @author florian.mueller
*/
public class AlfrescoCmisServiceFactory extends AbstractServiceFactory
{
private ThreadLocal<CmisServiceWrapper<AlfrescoCmisService>> threadLocalService = new ThreadLocal<CmisServiceWrapper<AlfrescoCmisService>>();
private CMISConnector connector;
@Override
public void init(Map<String, String> parameters)
{
}
/**
* Sets the CMIS connector.
*/
public void setCmisConnector(CMISConnector connector)
{
this.connector = connector;
}
@Override
public void destroy()
{
threadLocalService = null;
}
@Override
public CmisService getService(CallContext context)
{
CmisServiceWrapper<AlfrescoCmisService> wrapperService = threadLocalService.get();
if (wrapperService == null)
{
wrapperService = new CmisServiceWrapper<AlfrescoCmisService>(new AlfrescoCmisService(connector),
connector.getTypesDefaultMaxItems(), connector.getTypesDefaultDepth(),
connector.getObjectsDefaultMaxItems(), connector.getObjectsDefaultDepth());
threadLocalService.set(wrapperService);
}
wrapperService.getWrappedService().beginCall(context);
return wrapperService;
}
}

View File

@@ -0,0 +1,39 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.opencmis;
import org.apache.chemistry.opencmis.commons.enums.Action;
public interface CMISActionEvaluator<T>
{
/**
* Gets the CMIS Allowed Action
*
* @return
*/
public Action getAction();
/**
* Determines if an action is allowed on an object
*
* @param object
* @return
*/
public boolean isAllowed(T object);
}

View File

@@ -0,0 +1,120 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.opencmis;
import java.io.Serializable;
import java.util.HashMap;
import org.alfresco.opencmis.dictionary.CMISDictionaryService;
import org.alfresco.opencmis.dictionary.TypeDefinitionWrapper;
import org.alfresco.repo.audit.extractor.AbstractDataExtractor;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
/**
* An extractor that allows to filter data using the following rule: Audit
* records should only be created for items in the CMIS domain model.
*
* @author Stas Sokolovsky
*/
public class CMISChangeLogDataExtractor extends AbstractDataExtractor
{
public static final String KEY_NODE_REF = "nodeRef";
public static final String KEY_OBJECT_ID = "objectId";
private NodeService nodeService;
private CMISDictionaryService cmisDictionaryService;
/**
* Extracts relevant node refs and Ids from auditing data
*
* @see org.alfresco.repo.audit.extractor.DataExtractor.extractData(java.io.
* Serializable)
*/
public Serializable extractData(Serializable value) throws Throwable
{
NodeRef nodeRef = getNodeRef(value);
QName typeQName = nodeService.getType(nodeRef);
TypeDefinitionWrapper type = cmisDictionaryService.findNodeType(typeQName);
HashMap<String, Serializable> result = new HashMap<String, Serializable>(5);
result.put(KEY_NODE_REF, nodeRef);
// Support version nodes by recording the object ID
result.put(KEY_OBJECT_ID, type.getPropertyById(PropertyIds.OBJECT_ID).getPropertyAccessor().getValue(nodeRef));
return result;
}
/**
* @return Returns <tt>true</tt> if items in the CMIS domain model
* @see org.alfresco.repo.audit.extractor.DataExtractor.isSupported(java.io.
* Serializable)
*/
public boolean isSupported(Serializable data)
{
if (data != null)
{
NodeRef nodeRef = getNodeRef(data);
if (nodeRef != null)
{
QName typeQName = nodeService.getType(nodeRef);
TypeDefinitionWrapper type = cmisDictionaryService.findNodeType(typeQName);
return (type != null)
&& (type.getBaseTypeId() == BaseTypeId.CMIS_DOCUMENT || type.getBaseTypeId() == BaseTypeId.CMIS_FOLDER);
}
}
return false;
}
/**
* Gets the NodeRef from auditing data
*
* @param data
* audit data
* @return Node Reference
*/
private NodeRef getNodeRef(Serializable data)
{
NodeRef nodeRef = null;
if (data instanceof FileInfo)
{
nodeRef = ((FileInfo) data).getNodeRef();
} else if (data instanceof NodeRef)
{
nodeRef = (NodeRef) data;
}
return nodeRef;
}
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
public void setOpenCMISDictionaryService(CMISDictionaryService cmisDictionaryService)
{
this.cmisDictionaryService = cmisDictionaryService;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,70 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.opencmis;
import java.util.HashMap;
import javax.servlet.ServletContext;
import org.apache.chemistry.opencmis.commons.server.CmisServiceFactory;
import org.apache.chemistry.opencmis.server.impl.CmisRepositoryContextListener;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.web.context.ServletContextAware;
/**
* This bean controls the lifecycle of the CMIS factory.
*
* @author florian.mueller
*/
public class CMISLifecycleBean implements ServletContextAware, InitializingBean, DisposableBean
{
private ServletContext servletContext;
private CmisServiceFactory factory;
@Override
public void setServletContext(ServletContext servletContext)
{
this.servletContext = servletContext;
}
public void setCmisServiceFactory(CmisServiceFactory factory)
{
this.factory = factory;
}
@Override
public void afterPropertiesSet() throws Exception
{
if (factory != null && servletContext != null)
{
factory.init(new HashMap<String, String>());
servletContext.setAttribute(CmisRepositoryContextListener.SERVICES_FACTORY, factory);
}
}
@Override
public void destroy() throws Exception
{
if (factory != null)
{
factory.destroy();
}
}
}

View File

@@ -0,0 +1,304 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.opencmis;
import java.io.Serializable;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.rendition.executer.ImageRenderingEngine;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.cmr.rendition.RenditionDefinition;
import org.alfresco.service.cmr.rendition.RenditionService;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.apache.chemistry.opencmis.commons.data.RenditionData;
import org.apache.chemistry.opencmis.commons.exceptions.CmisFilterNotValidException;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.RenditionDataImpl;
public class CMISRenditionMapping
{
private NodeService nodeService;
private ContentService contentService;
private RenditionService renditionService;
private TransactionService transactionService;
private Map<String, List<String>> kindToRenditionNames;
private Map<String, String> renditionNamesToKind;
private Map<String, BigInteger[]> renditionNameToSize;
public CMISRenditionMapping(NodeService nodeService, ContentService contentService,
RenditionService renditionService, TransactionService transactionService,
Map<String, List<String>> renditionKinds)
{
this.nodeService = nodeService;
this.contentService = contentService;
this.renditionService = renditionService;
this.transactionService = transactionService;
if (renditionKinds == null)
{
this.kindToRenditionNames = new HashMap<String, List<String>>();
} else
{
this.kindToRenditionNames = renditionKinds;
}
renditionNamesToKind = new HashMap<String, String>();
for (Entry<String, List<String>> entry : renditionKinds.entrySet())
{
for (String renditionName : entry.getValue())
{
renditionNamesToKind.put(renditionName, entry.getKey());
}
}
cacheRenditionSizes();
}
private void cacheRenditionSizes()
{
renditionNameToSize = AuthenticationUtil.runAs(new RunAsWork<Map<String, BigInteger[]>>()
{
public Map<String, BigInteger[]> doWork() throws Exception
{
return transactionService.getRetryingTransactionHelper().doInTransaction(
new RetryingTransactionCallback<Map<String, BigInteger[]>>()
{
public Map<String, BigInteger[]> execute() throws Exception
{
Map<String, BigInteger[]> rn2s = new HashMap<String, BigInteger[]>();
List<RenditionDefinition> allRenditionDefs = renditionService
.loadRenditionDefinitions();
for (RenditionDefinition rd : allRenditionDefs)
{
QName renditionDefinitionName = rd.getRenditionName();
Number width = (Number) rd
.getParameterValue(ImageRenderingEngine.PARAM_RESIZE_WIDTH);
Number height = (Number) rd
.getParameterValue(ImageRenderingEngine.PARAM_RESIZE_HEIGHT);
if ((width != null) || (height != null))
{
BigInteger[] size = new BigInteger[2];
size[0] = (width == null ? null : BigInteger.valueOf(width.longValue()));
size[1] = (height == null ? null : BigInteger.valueOf(height.longValue()));
rn2s.put(renditionDefinitionName.getLocalName(), size);
}
}
return rn2s;
};
}, true);
}
}, AuthenticationUtil.getSystemUserName());
}
public List<RenditionData> getRenditions(NodeRef nodeRef, String renditionFilter, BigInteger maxItems,
BigInteger skipCount)
{
List<RenditionData> result = new ArrayList<RenditionData>();
// split the filter
Set<String> filterSet = splitRenditionFilter(renditionFilter);
if ((filterSet != null) && (filterSet.contains(CMISConnector.RENDITION_NONE)))
{
// "cmis:none" found -> no renditions
return result;
}
// convert BigIntegers to int
int max = (maxItems == null ? Integer.MAX_VALUE : maxItems.intValue());
int skip = (skipCount == null || skipCount.intValue() < 0 ? 0 : skipCount.intValue());
if (max > 0)
{
// find all renditions and filter them
List<ChildAssociationRef> renditionList = renditionService.getRenditions(nodeRef);
int lastIndex = (max + skip > renditionList.size() ? renditionList.size() : max + skip) - 1;
for (int i = skip; i <= lastIndex; i++)
{
ChildAssociationRef rendition = renditionList.get(i);
NodeRef rendNodeRef = rendition.getChildRef();
String rendName = rendition.getQName().getLocalName();
// get and check content
QName contentProperty = ContentModel.PROP_CONTENT;
Serializable contentPropertyName = nodeService.getProperty(rendNodeRef,
ContentModel.PROP_CONTENT_PROPERTY_NAME);
if (contentPropertyName != null)
{
contentProperty = (QName) contentPropertyName;
}
ContentReader reader = contentService.getReader(rendNodeRef, contentProperty);
if ((reader == null) || (reader.exists()))
{
// no content -> no rendition
continue;
}
// get and clean MIME type
String mimeType = reader.getMimetype();
if (mimeType.indexOf(';') > 3)
{
mimeType = mimeType.substring(0, mimeType.indexOf(';')).trim();
}
// if a filter is set, check it
if (filterSet != null)
{
boolean include = false;
for (String f : filterSet)
{
if (f.indexOf('/') == -1)
{
// found a kind, not a MIME type
List<String> renditionNames = kindToRenditionNames.get(f);
if (renditionNames.contains(rendName))
{
include = true;
break;
}
} else if (f.endsWith("*"))
{
// found MIME type with wildcard
if (mimeType.startsWith(f.substring(0, f.length() - 2)))
{
include = true;
break;
}
} else
{
// found complete MIME type
if (mimeType.equals(f))
{
include = true;
break;
}
}
}
// if no filter matches, skip this rendition
if (!include)
{
continue;
}
}
// gather rendition data
String title = rendName;
String kind = (renditionNamesToKind.containsKey(rendName) ? renditionNamesToKind.get(rendName)
: rendName);
BigInteger length = BigInteger.valueOf(reader.getSize());
BigInteger width = null;
BigInteger height = null;
if (renditionNameToSize.containsKey(rendName))
{
BigInteger[] size = renditionNameToSize.get(rendName);
width = size[0];
height = size[1];
}
// finally add this rendition
result.add(createRenditionData(rendNodeRef, mimeType, title, kind, length, width, height));
}
}
return result;
}
private Set<String> splitRenditionFilter(String filter)
{
if (filter == null)
{
return null;
}
if (filter.trim().length() == 0)
{
return null;
}
Set<String> result = new HashSet<String>();
for (String s : filter.split(","))
{
s = s.trim();
if (s.equals("*"))
{
return null;
} else if (s.indexOf('*') > -1)
{
if (!s.endsWith("*"))
{
throw new CmisFilterNotValidException("Rendition filter is invalid: " + s);
}
result.add(s);
} else if (s.equalsIgnoreCase(CMISConnector.RENDITION_NONE))
{
result.clear();
result.add(CMISConnector.RENDITION_NONE);
break;
} else if (s.length() > 0)
{
result.add(s);
}
}
return result;
}
private RenditionData createRenditionData(NodeRef rendNodeRef, String mimeType, String title, String kind,
BigInteger length, BigInteger width, BigInteger height)
{
RenditionDataImpl result = new RenditionDataImpl();
result.setStreamId(rendNodeRef.toString());
result.setMimeType(mimeType);
result.setTitle(title);
result.setKind(kind);
result.setBigLength(length);
result.setBigWidth(width);
result.setBigHeight(height);
result.setRenditionDocumentId(rendNodeRef.toString());
return result;
}
}

View File

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

View File

@@ -0,0 +1,31 @@
/*
* 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;
public enum ObjectVariantEnum
{
INVALID_ID, // not a valid object id
NOT_EXISTING, // valid id but object doesn't exist
NODE, // object is a node
VERSION, // object is a version (not updatable)
PWC, // object is a PWC
ASSOC, // object is a relationship
PERMISSION_DENIED
// user has no permissions
}

View File

@@ -0,0 +1,102 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.opencmis;
import java.io.IOException;
import java.io.InputStream;
public class RangeInputStream extends InputStream
{
private InputStream inputStream;
private long bytesRead;
private long length;
public RangeInputStream(InputStream inputStream, long offset, long length) throws IOException
{
super();
this.inputStream = inputStream;
this.length = length;
this.bytesRead = 0;
long l = this.inputStream.skip(offset);
if (l < offset)
{
this.inputStream.skip(offset);
}
}
@Override
public int read() throws IOException
{
if (bytesRead < length)
{
bytesRead++;
return inputStream.read();
} else
{
return -1;
}
}
@Override
public int read(byte[] b) throws IOException
{
return read(b, 0, b.length);
}
@Override
public int read(byte[] b, int off, int len) throws IOException
{
if (len > length - bytesRead)
{
len = (int) (length - bytesRead);
}
int readed = inputStream.read(b, off, len);
bytesRead += readed;
return readed;
}
@Override
public int available() throws IOException
{
return (int) (length - bytesRead + 1);
}
@Override
public void close() throws IOException
{
inputStream.close();
}
@Override
public long skip(long n) throws IOException
{
if (bytesRead + n > length)
{
n = (length - n) > 0 ? (length - n) : length - bytesRead;
}
n = inputStream.skip(n);
bytesRead += n;
return n;
}
}

View File

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

View File

@@ -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.dictionary;
import java.io.Serializable;
import org.alfresco.cmis.CMISPropertyAccessor;
import org.alfresco.cmis.CMISPropertyLuceneBuilder;
import org.alfresco.service.namespace.QName;
import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
public class BasePropertyDefintionWrapper implements PropertyDefintionWrapper, Serializable
{
private static final long serialVersionUID = 1L;
private PropertyDefinition<?> propDef;
private QName alfrescoName;
private TypeDefinitionWrapper owningType;
private CMISPropertyAccessor accessor;
private CMISPropertyLuceneBuilder luceneBuilder;
public BasePropertyDefintionWrapper(PropertyDefinition<?> propDef, QName alfrescoName,
TypeDefinitionWrapper owningType, CMISPropertyAccessor accessor, CMISPropertyLuceneBuilder luceneBuilder)
{
this.propDef = propDef;
this.alfrescoName = alfrescoName;
this.owningType = owningType;
this.accessor = accessor;
this.luceneBuilder = luceneBuilder;
}
@Override
public PropertyDefinition<?> getPropertyDefinition()
{
return propDef;
}
@Override
public String getPropertyId()
{
return propDef.getId();
}
@Override
public QName getAlfrescoName()
{
return alfrescoName;
}
@Override
public TypeDefinitionWrapper getOwningType()
{
return owningType;
}
@Override
public CMISPropertyAccessor getPropertyAccessor()
{
return accessor;
}
@Override
public CMISPropertyLuceneBuilder getPropertyLuceneBuilder()
{
return luceneBuilder;
}
}

View File

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

View File

@@ -0,0 +1,117 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.opencmis.dictionary;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.chemistry.opencmis.commons.BasicPermissions;
/**
* CMIS Allowed Action Enum
*
* @author davidc
*/
public enum CMISAllowedActionEnum
{
// navigation services
CAN_GET_DESCENDANTS("canGetDescendants", "canGetDescendents.Folder", BasicPermissions.READ, "canGetDescendents.Folder", "{http://www.alfresco.org/model/system/1.0}base.ReadChildren"),
//CAN_GET_FOLDER_TREE("canGetFolderTree", "canGetFolderTree.Folder", BasicPermissions.READ, "canGetFolderTree.Folder", "{http://www.alfresco.org/model/system/1.0}base.ReadChildren"),
CAN_GET_CHILDREN("canGetChildren", "canGetChildren.Folder", BasicPermissions.READ, "canGetChildren.Folder", "{http://www.alfresco.org/model/system/1.0}base.ReadChildren"),
CAN_GET_FOLDER_PARENT("canGetFolderParent", "canGetParents.Folder", BasicPermissions.READ, "canGetParents.Folder", "{http://www.alfresco.org/model/system/1.0}base.ReadProperties"),
CAN_GET_OBJECT_PARENTS("canGetObjectParents", "canGetFolderParent.Object", BasicPermissions.READ, "canGetFolderParent.Object", "{http://www.alfresco.org/model/system/1.0}base.ReadProperties"),
// object services
CAN_CREATE_DOCUMENT("canCreateDocument", "canCreateDocument.Folder", BasicPermissions.ALL, "canCreateDocument.Folder", "{http://www.alfresco.org/model/system/1.0}base.CreateChildren"),
CAN_CREATE_FOLDER("canCreateFolder", "canCreateFolder.Folder", BasicPermissions.ALL, "canCreateFolder.Folder", "{http://www.alfresco.org/model/system/1.0}base.CreateChildren"),
CAN_CREATE_RELATIONSHIP("canCreateRelationship"),
CAN_GET_PROPERTIES("canGetProperties", "canGetProperties.Object", BasicPermissions.READ, "canGetProperties.Object", "{http://www.alfresco.org/model/system/1.0}base.ReadProperties"),
CAN_GET_RENDITIONS("canGetRenditions"/*, "canGetRenditions.Object", BasicPermissions.READ, "canGetRenditions.Object", "{http://www.alfresco.org/model/system/1.0}base.ReadProperties"*/),
CAN_GET_CONTENT_STREAM("canGetContentStream", "canViewContent.Object", BasicPermissions.READ, "canViewContent.Object", "{http://www.alfresco.org/model/system/1.0}base.ReadContent"),
CAN_UPDATE_PROPERTIES("canUpdateProperties", "canUpdateProperties.Object", BasicPermissions.WRITE, "canUpdateProperties.Object", "{http://www.alfresco.org/model/system/1.0}base.WriteProperties"),
CAN_MOVE_OBJECT("canMoveObject", "canMove.Object", BasicPermissions.ALL, "canMove.Target", BasicPermissions.ALL, "canMove.Object", "{http://www.alfresco.org/model/system/1.0}base.DeleteNode", "canMove.Target", "{http://www.alfresco.org/model/system/1.0}base.CreateChildren"),
CAN_DELETE_OBJECT("canDeleteObject", "canDelete.Object", BasicPermissions.ALL, "canDelete.Object", "{http://www.alfresco.org/model/system/1.0}base.DeleteNode"),
CAN_SET_CONTENT_STREAM("canSetContentStream", "canSetContent.Document", BasicPermissions.WRITE, "canSetContent.Document", "{http://www.alfresco.org/model/system/1.0}base.WriteContent"),
CAN_DELETE_CONTENT_STREAM("canDeleteContentStream", "canDeleteContent.Document", BasicPermissions.WRITE, "canDeleteContent.Document", "{http://www.alfresco.org/model/system/1.0}base.WriteContent"),
CAN_DELETE_TREE("canDeleteTree", "canDeleteTree.Folder", BasicPermissions.ALL, "canDeleteTree.Folder", "{http://www.alfresco.org/model/system/1.0}base.DeleteNode"),
// multi-filing services
CAN_ADD_OBJECT_TO_FOLDER("canAddObjectToFolder", "canAddToFolder.Object", BasicPermissions.READ, "canAddToFolder.Folder", BasicPermissions.ALL, "canAddToFolder.Object", "{http://www.alfresco.org/model/system/1.0}base.ReadProperties", "canAddToFolder.Folder", "{http://www.alfresco.org/model/system/1.0}base.CreateChildren"),
CAN_REMOVE_OBJECT_FROM_FOLDER("canRemoveObjectFromFolder", "canRemoveFromFolder.Object", BasicPermissions.ALL, "canRemoveFromFolder.Object", "{http://www.alfresco.org/model/system/1.0}base.DeleteNode"),
// versioning services
CAN_CHECKOUT("canCheckOut", "canCheckout.Document", BasicPermissions.ALL, "canCheckout.Document", "{http://www.alfresco.org/model/content/1.0}lockable.CheckOut"),
CAN_CANCEL_CHECKOUT("canCancelCheckOut", "canCancelCheckout.Document", BasicPermissions.ALL, "canCancelCheckout.Document", "{http://www.alfresco.org/model/content/1.0}lockable.CancelCheckOut"),
CAN_CHECKIN("canCheckIn", "canCheckin.Document", BasicPermissions.ALL, "canCheckin.Document", "{http://www.alfresco.org/model/content/1.0}lockable.CheckIn"),
CAN_GET_ALL_VERSIONS("canGetAllVersions", "canGetAllVersions.VersionSeries", BasicPermissions.READ, "canGetAllVersions.VersionSeries", "{http://www.alfresco.org/model/system/1.0}base.Read"),
// relationship services
CAN_GET_OBJECT_RELATIONSHIPS("canGetObjectRelationships"),
// policy services
CAN_APPLY_POLICY("canApplyPolicy", "canAddPolicy.Object", BasicPermissions.WRITE, "canAddPolicy.Policy", BasicPermissions.READ, "canAddPolicy.Object", "{http://www.alfresco.org/model/system/1.0}base.Write"),
CAN_REMOVE_POLICY("canRemovePolicy", "canRemovePolicy.Object", BasicPermissions.WRITE, "canRemovePolicy.Policy", BasicPermissions.READ, "canRemovePolicy.Object", "{http://www.alfresco.org/model/system/1.0}base.Write"),
CAN_GET_APPLIED_POLICIES("canGetAppliedPolicies", "canGetAppliedPolicies.Object", BasicPermissions.READ, "canGetAppliedPolicies.Object", "{http://www.alfresco.org/model/system/1.0}base.ReadProperties"),
// acl services
CAN_GET_ACL("canGetACL", "canGetACL.Object", BasicPermissions.ALL, "canGetACL.Object", "{http://www.alfresco.org/model/system/1.0}base.ReadPermissions"),
CAN_APPLY_ACL("canApplyACL", "canApplyACL.Object", BasicPermissions.ALL, "canApplyACL.Object", "{http://www.alfresco.org/model/system/1.0}base.ChangePermissions");
private String label;
private Map<String, List<String>> mapping = new HashMap<String, List<String>>();
/**
* Construct
*
* @param label
*/
CMISAllowedActionEnum(String label, String ... keysAndPermissions)
{
this.label = label;
assert(keysAndPermissions.length % 2 == 0);
for(int i = 0; i < keysAndPermissions.length; i++)
{
String key = keysAndPermissions[i];
String permission = keysAndPermissions[++i];
List<String> permissions = mapping.get(key);
if(permissions == null)
{
permissions = new ArrayList<String>(1);
mapping.put(key, permissions);
}
permissions.add(permission);
}
}
public String getLabel()
{
return label;
}
public Map<String, List<String>> getPermissionMapping()
{
return mapping;
}
}

View File

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

View File

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

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.dictionary;
import org.alfresco.opencmis.CMISUtils;
import org.alfresco.opencmis.mapping.CMISMapping;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.namespace.QName;
import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
import org.apache.chemistry.opencmis.commons.enums.ContentStreamAllowed;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.DocumentTypeDefinitionImpl;
public class DocumentTypeDefinitionWrapper extends ShadowTypeDefinitionWrapper
{
private static final long serialVersionUID = 1L;
private DocumentTypeDefinitionImpl typeDef;
private DocumentTypeDefinitionImpl typeDefInclProperties;
public DocumentTypeDefinitionWrapper(CMISMapping cmisMapping, ServiceRegistry serviceRegistry, String typeId,
ClassDefinition cmisClassDef)
{
alfrescoName = cmisClassDef.getName();
alfrescoClass = cmisMapping.getAlfrescoClass(alfrescoName);
typeDef = new DocumentTypeDefinitionImpl();
typeDef.setBaseTypeId(BaseTypeId.CMIS_DOCUMENT);
typeDef.setId(typeId);
typeDef.setLocalName(alfrescoName.getLocalName());
typeDef.setLocalNamespace(alfrescoName.getNamespaceURI());
if (BaseTypeId.CMIS_DOCUMENT.value().equals(typeId))
{
typeDef.setQueryName(typeId);
typeDef.setParentTypeId(null);
} else
{
typeDef.setQueryName(cmisMapping.buildPrefixEncodedString(alfrescoName));
QName parentQName = cmisMapping.getCmisType(cmisClassDef.getParentName());
if (cmisMapping.isValidCmisDocument(parentQName))
{
typeDef.setParentTypeId(cmisMapping.getCmisTypeId(BaseTypeId.CMIS_DOCUMENT, parentQName));
}
}
typeDef.setDisplayName((cmisClassDef.getTitle() != null) ? cmisClassDef.getTitle() : typeId);
typeDef.setDescription(cmisClassDef.getDescription() != null ? cmisClassDef.getDescription() : typeDef
.getDisplayName());
typeDef.setIsCreatable(true);
typeDef.setIsQueryable(true);
typeDef.setIsFulltextIndexed(true);
typeDef.setIsControllablePolicy(false);
typeDef.setIsControllableAcl(true);
typeDef.setIsIncludedInSupertypeQuery(cmisClassDef.getIncludedInSuperTypeQuery());
typeDef.setIsFileable(true);
typeDef.setContentStreamAllowed(ContentStreamAllowed.ALLOWED);
typeDef.setIsVersionable(true);
typeDefInclProperties = CMISUtils.copy(typeDef);
setTypeDefinition(typeDef, typeDefInclProperties);
createOwningPropertyDefinitions(cmisMapping, serviceRegistry, cmisClassDef);
actionEvaluators = cmisMapping.getActionEvaluators(BaseTypeId.CMIS_DOCUMENT);
}
}

View File

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

View File

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

View File

@@ -0,0 +1,39 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.opencmis.dictionary;
import org.alfresco.cmis.CMISPropertyAccessor;
import org.alfresco.cmis.CMISPropertyLuceneBuilder;
import org.alfresco.service.namespace.QName;
import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
public interface PropertyDefintionWrapper
{
PropertyDefinition<?> getPropertyDefinition();
String getPropertyId();
QName getAlfrescoName();
TypeDefinitionWrapper getOwningType();
CMISPropertyAccessor getPropertyAccessor();
CMISPropertyLuceneBuilder getPropertyLuceneBuilder();
}

View File

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

View File

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

View File

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

View File

@@ -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();
}
}
}

View File

@@ -0,0 +1,414 @@
/*
* 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.search;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.repo.search.impl.lucene.AnalysisMode;
import org.alfresco.repo.search.impl.parsers.CMIS_FTSLexer;
import org.alfresco.repo.search.impl.parsers.CMIS_FTSParser;
import org.alfresco.repo.search.impl.parsers.FTSQueryException;
import org.alfresco.repo.search.impl.querymodel.Argument;
import org.alfresco.repo.search.impl.querymodel.Column;
import org.alfresco.repo.search.impl.querymodel.Constraint;
import org.alfresco.repo.search.impl.querymodel.Function;
import org.alfresco.repo.search.impl.querymodel.FunctionEvaluationContext;
import org.alfresco.repo.search.impl.querymodel.LiteralArgument;
import org.alfresco.repo.search.impl.querymodel.QueryModelFactory;
import org.alfresco.repo.search.impl.querymodel.Selector;
import org.alfresco.repo.search.impl.querymodel.Constraint.Occur;
import org.alfresco.repo.search.impl.querymodel.QueryOptions.Connective;
import org.alfresco.repo.search.impl.querymodel.impl.functions.FTSPhrase;
import org.alfresco.repo.search.impl.querymodel.impl.functions.FTSTerm;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.antlr.runtime.ANTLRStringStream;
import org.antlr.runtime.CharStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.Token;
import org.antlr.runtime.tree.CommonTree;
import org.antlr.runtime.tree.Tree;
public class CMISFTSQueryParser
{
static public Constraint buildFTS(String ftsExpression, QueryModelFactory factory, FunctionEvaluationContext functionEvaluationContext, Selector selector,
Map<String, Column> columnMap, String defaultField)
{
// TODO: Decode sql escape for '' should do in CMIS layer
// parse templates to trees ...
CMIS_FTSParser parser = null;
try
{
CharStream cs = new ANTLRStringStream(ftsExpression);
CMIS_FTSLexer lexer = new CMIS_FTSLexer(cs);
CommonTokenStream tokens = new CommonTokenStream(lexer);
parser = new CMIS_FTSParser(tokens);
CommonTree ftsNode = (CommonTree) parser.cmisFtsQuery().getTree();
return buildFTSConnective(ftsNode, factory, functionEvaluationContext, selector, columnMap, defaultField);
}
catch (RecognitionException e)
{
if (parser != null)
{
String[] tokenNames = parser.getTokenNames();
String hdr = parser.getErrorHeader(e);
String msg = parser.getErrorMessage(e, tokenNames);
throw new FTSQueryException(hdr + "\n" + msg, e);
}
return null;
}
}
static private Constraint buildFTSConnective(CommonTree node, QueryModelFactory factory, FunctionEvaluationContext functionEvaluationContext,
Selector selector, Map<String, Column> columnMap, String defaultField)
{
Connective connective;
switch (node.getType())
{
case CMIS_FTSParser.DISJUNCTION:
connective = Connective.OR;
break;
case CMIS_FTSParser.CONJUNCTION:
connective = Connective.AND;
break;
default:
throw new FTSQueryException("Invalid connective ..." + node.getText());
}
List<Constraint> constraints = new ArrayList<Constraint>(node.getChildCount());
CommonTree testNode;
for (int i = 0; i < node.getChildCount(); i++)
{
CommonTree subNode = (CommonTree) node.getChild(i);
Constraint constraint;
switch (subNode.getType())
{
case CMIS_FTSParser.DISJUNCTION:
case CMIS_FTSParser.CONJUNCTION:
constraint = buildFTSConnective(subNode, factory, functionEvaluationContext, selector, columnMap, defaultField);
break;
case CMIS_FTSParser.DEFAULT:
testNode = (CommonTree) subNode.getChild(0);
constraint = buildFTSTest(testNode, factory, functionEvaluationContext, selector, columnMap, defaultField);
constraint.setOccur(Occur.DEFAULT);
break;
case CMIS_FTSParser.EXCLUDE:
testNode = (CommonTree) subNode.getChild(0);
constraint = buildFTSTest(testNode, factory, functionEvaluationContext, selector, columnMap, defaultField);
constraint.setOccur(Occur.EXCLUDE);
break;
default:
throw new FTSQueryException("Unsupported FTS option " + subNode.getText());
}
constraints.add(constraint);
}
if (constraints.size() == 1)
{
return constraints.get(0);
}
else
{
if (connective == Connective.OR)
{
return factory.createDisjunction(constraints);
}
else
{
return factory.createConjunction(constraints);
}
}
}
static private Constraint buildFTSTest(CommonTree argNode, QueryModelFactory factory, FunctionEvaluationContext functionEvaluationContext,
Selector selector, Map<String, Column> columnMap, String defaultField)
{
CommonTree testNode = argNode;
switch (testNode.getType())
{
case CMIS_FTSParser.DISJUNCTION:
case CMIS_FTSParser.CONJUNCTION:
return buildFTSConnective(testNode, factory, functionEvaluationContext, selector, columnMap, defaultField);
case CMIS_FTSParser.TERM:
return buildTerm(testNode, factory, functionEvaluationContext, selector, columnMap);
case CMIS_FTSParser.PHRASE:
return buildPhrase(testNode, factory, functionEvaluationContext, selector, columnMap);
default:
throw new FTSQueryException("Unsupported FTS option " + testNode.getText());
}
}
static private Constraint buildPhrase(CommonTree testNode, QueryModelFactory factory,
FunctionEvaluationContext functionEvaluationContext, Selector selector, Map<String, Column> columnMap)
{
String functionName = FTSPhrase.NAME;
Function function = factory.getFunction(functionName);
Map<String, Argument> functionArguments = new LinkedHashMap<String, Argument>();
LiteralArgument larg = factory.createLiteralArgument(FTSPhrase.ARG_PHRASE, DataTypeDefinition.TEXT, getText(testNode.getChild(0)));
functionArguments.put(larg.getName(), larg);
return factory.createFunctionalConstraint(function, functionArguments);
}
static private Constraint buildTerm(CommonTree testNode, QueryModelFactory factory, FunctionEvaluationContext functionEvaluationContext,
Selector selector, Map<String, Column> columnMap)
{
String functionName = FTSTerm.NAME;
Function function = factory.getFunction(functionName);
Map<String, Argument> functionArguments = new LinkedHashMap<String, Argument>();
LiteralArgument larg = factory.createLiteralArgument(FTSTerm.ARG_TERM, DataTypeDefinition.TEXT, getText(testNode.getChild(0)));
functionArguments.put(larg.getName(), larg);
larg = factory.createLiteralArgument(FTSTerm.ARG_TOKENISATION_MODE, DataTypeDefinition.ANY, AnalysisMode.DEFAULT);
functionArguments.put(larg.getName(), larg);
return factory.createFunctionalConstraint(function, functionArguments);
}
static class DisjunctionToken implements Token
{
public int getChannel()
{
return 0;
}
public int getCharPositionInLine()
{
return 0;
}
public CharStream getInputStream()
{
return null;
}
public int getLine()
{
return 0;
}
public String getText()
{
return null;
}
public int getTokenIndex()
{
return 0;
}
public int getType()
{
return CMIS_FTSParser.DISJUNCTION;
}
public void setChannel(int arg0)
{
}
public void setCharPositionInLine(int arg0)
{
}
public void setInputStream(CharStream arg0)
{
}
public void setLine(int arg0)
{
}
public void setText(String arg0)
{
}
public void setTokenIndex(int arg0)
{
}
public void setType(int arg0)
{
}
}
static class DefaultToken implements Token
{
public int getChannel()
{
return 0;
}
public int getCharPositionInLine()
{
return 0;
}
public CharStream getInputStream()
{
return null;
}
public int getLine()
{
return 0;
}
public String getText()
{
return null;
}
public int getTokenIndex()
{
return 0;
}
public int getType()
{
return CMIS_FTSParser.DEFAULT;
}
public void setChannel(int arg0)
{
}
public void setCharPositionInLine(int arg0)
{
}
public void setInputStream(CharStream arg0)
{
}
public void setLine(int arg0)
{
}
public void setText(String arg0)
{
}
public void setTokenIndex(int arg0)
{
}
public void setType(int arg0)
{
}
}
static private String getText(Tree node)
{
String text = node.getText();
int index;
switch (node.getType())
{
case CMIS_FTSParser.FTSWORD:
index = text.indexOf('\\');
if (index == -1)
{
return text;
}
else
{
return unescape(text);
}
case CMIS_FTSParser.FTSPHRASE:
String phrase = text.substring(1, text.length() - 1);
index = phrase.indexOf('\\');
if (index == -1)
{
return phrase;
}
else
{
return unescape(phrase);
}
default:
return text;
}
}
static private String unescape(String string)
{
StringBuilder builder = new StringBuilder(string.length());
boolean lastWasEscape = false;
for (int i = 0; i < string.length(); i++)
{
char c = string.charAt(i);
if (lastWasEscape)
{
if (c == 'u')
{
throw new UnsupportedOperationException(string);
}
else
{
builder.append(c);
}
lastWasEscape = false;
}
else
{
if (c == '\\')
{
lastWasEscape = true;
}
else
{
builder.append(c);
}
}
}
if (lastWasEscape)
{
throw new FTSQueryException("Escape character at end of string " + string);
}
return builder.toString();
}
}

View File

@@ -0,0 +1,90 @@
/*
* 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.search;
import java.util.Locale;
import org.springframework.extensions.surf.util.I18NUtil;
import org.alfresco.repo.search.impl.querymodel.QueryOptions;
import org.alfresco.service.cmr.repository.StoreRef;
/**
* The options for a CMIS query
*
* @author andyh
*/
public class CMISQueryOptions extends QueryOptions
{
public enum CMISQueryMode
{
CMS_STRICT, CMS_WITH_ALFRESCO_EXTENSIONS;
}
private CMISQueryMode queryMode = CMISQueryMode.CMS_STRICT;
/**
* Create a CMISQueryOptions instance with the default options other than
* the query and store ref. The query will be run using the locale returned
* by I18NUtil.getLocale()
*
* @param query
* - the query to run
* @param storeRef
* - the store against which to run the query
*/
public CMISQueryOptions(String query, StoreRef storeRef)
{
this(query, storeRef, I18NUtil.getLocale());
}
/**
* Create a CMISQueryOptions instance with the default options other than
* the query, store ref and locale.
*
* @param query
* - the query to run
* @param storeRef
* - the store against which to run the query
*/
public CMISQueryOptions(String query, StoreRef storeRef, Locale locale)
{
super(query, storeRef, locale);
}
/**
* Get the query mode.
*
* @return the queryMode
*/
public CMISQueryMode getQueryMode()
{
return queryMode;
}
/**
* Set the query mode.
*
* @param queryMode
* the queryMode to set
*/
public void setQueryMode(CMISQueryMode queryMode)
{
this.queryMode = queryMode;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,20 @@
package org.alfresco.opencmis.search;
import org.alfresco.service.cmr.repository.StoreRef;
import org.apache.chemistry.opencmis.commons.enums.CapabilityJoin;
import org.apache.chemistry.opencmis.commons.enums.CapabilityQuery;
public interface CMISQueryService
{
CMISResultSet query(CMISQueryOptions options);
CMISResultSet query(String query, StoreRef storeRef);
boolean getPwcSearchable();
boolean getAllVersionsSearchable();
CapabilityQuery getQuerySupport();
CapabilityJoin getJoinSupport();
}

View File

@@ -0,0 +1,152 @@
/*
* 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.search;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.alfresco.opencmis.dictionary.CMISDictionaryService;
import org.alfresco.opencmis.search.CMISQueryOptions.CMISQueryMode;
import org.alfresco.repo.search.impl.querymodel.Query;
import org.alfresco.repo.search.impl.querymodel.QueryEngine;
import org.alfresco.repo.search.impl.querymodel.QueryEngineResults;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.LimitBy;
import org.alfresco.service.cmr.search.ResultSet;
import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
import org.apache.chemistry.opencmis.commons.enums.CapabilityJoin;
import org.apache.chemistry.opencmis.commons.enums.CapabilityQuery;
/**
* @author andyh
*/
public class CMISQueryServiceImpl implements CMISQueryService
{
private CMISDictionaryService cmisDictionaryService;
private QueryEngine queryEngine;
private NodeService nodeService;
private DictionaryService alfrescoDictionaryService;
public void setOpenCMISDictionaryService(CMISDictionaryService cmisDictionaryService)
{
this.cmisDictionaryService = cmisDictionaryService;
}
/**
* @param queryEngine
* the queryEngine to set
*/
public void setQueryEngine(QueryEngine queryEngine)
{
this.queryEngine = queryEngine;
}
/**
* @param nodeService
* the nodeService to set
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* @param alfrescoDictionaryService
* the Alfresco Dictionary Service to set
*/
public void setAlfrescoDictionaryService(DictionaryService alfrescoDictionaryService)
{
this.alfrescoDictionaryService = alfrescoDictionaryService;
}
public CMISResultSet query(CMISQueryOptions options)
{
CapabilityJoin joinSupport = getJoinSupport();
if (options.getQueryMode() == CMISQueryOptions.CMISQueryMode.CMS_WITH_ALFRESCO_EXTENSIONS)
{
joinSupport = CapabilityJoin.INNERONLY;
}
// TODO: Refactor to avoid duplication of valid scopes here and in
// CMISQueryParser
BaseTypeId[] validScopes = (options.getQueryMode() == CMISQueryMode.CMS_STRICT) ? CmisFunctionEvaluationContext.STRICT_SCOPES
: CmisFunctionEvaluationContext.ALFRESCO_SCOPES;
CmisFunctionEvaluationContext functionContext = new CmisFunctionEvaluationContext();
functionContext.setCmisDictionaryService(cmisDictionaryService);
functionContext.setNodeService(nodeService);
functionContext.setValidScopes(validScopes);
CMISQueryParser parser = new CMISQueryParser(options, cmisDictionaryService, joinSupport);
Query query = parser.parse(queryEngine.getQueryModelFactory(), functionContext);
QueryEngineResults results = queryEngine.executeQuery(query, options, functionContext);
Map<String, ResultSet> wrapped = new HashMap<String, ResultSet>();
Map<Set<String>, ResultSet> map = results.getResults();
for (Set<String> group : map.keySet())
{
ResultSet current = map.get(group);
for (String selector : group)
{
wrapped.put(selector, current);
}
}
LimitBy limitBy = null;
if ((null != results.getResults()) && !results.getResults().isEmpty()
&& (null != results.getResults().values()) && !results.getResults().values().isEmpty())
{
limitBy = results.getResults().values().iterator().next().getResultSetMetaData().getLimitedBy();
}
CMISResultSet cmis = new CMISResultSet(wrapped, options, limitBy, nodeService, query, cmisDictionaryService,
alfrescoDictionaryService);
return cmis;
}
public CMISResultSet query(String query, StoreRef storeRef)
{
CMISQueryOptions options = new CMISQueryOptions(query, storeRef);
return query(options);
}
public boolean getPwcSearchable()
{
return true;
}
public boolean getAllVersionsSearchable()
{
return false;
}
public CapabilityQuery getQuerySupport()
{
return CapabilityQuery.BOTHCOMBINED;
}
public CapabilityJoin getJoinSupport()
{
return CapabilityJoin.NONE;
}
}

View File

@@ -0,0 +1,331 @@
/*
* 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.search;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.opencmis.dictionary.CMISDictionaryService;
import org.alfresco.repo.search.impl.querymodel.Query;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.search.LimitBy;
import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.cmr.search.ResultSetRow;
import org.alfresco.service.cmr.search.ResultSetSPI;
/**
* @author andyh
*/
public class CMISResultSet implements ResultSetSPI<CMISResultSetRow, CMISResultSetMetaData>, Serializable
{
private static final long serialVersionUID = 2014688399588268994L;
private Map<String, ResultSet> wrapped;
private LimitBy limitBy;
CMISQueryOptions options;
NodeService nodeService;
Query query;
CMISDictionaryService cmisDictionaryService;
DictionaryService alfrescoDictionaryService;
public CMISResultSet(Map<String, ResultSet> wrapped, CMISQueryOptions options, LimitBy limitBy,
NodeService nodeService, Query query, CMISDictionaryService cmisDictionaryService,
DictionaryService alfrescoDictionaryService)
{
this.wrapped = wrapped;
this.options = options;
this.limitBy = limitBy;
this.nodeService = nodeService;
this.query = query;
this.cmisDictionaryService = cmisDictionaryService;
this.alfrescoDictionaryService = alfrescoDictionaryService;
}
/*
* (non-Javadoc)
*
* @see org.alfresco.cmis.search.CMISResultSet#close()
*/
public void close()
{
// results sets can be used for more than one selector so we need to
// keep track of what we have closed
Set<ResultSet> closed = new HashSet<ResultSet>();
for (ResultSet resultSet : wrapped.values())
{
if (!closed.contains(resultSet))
{
resultSet.close();
closed.add(resultSet);
}
}
}
/*
* (non-Javadoc)
*
* @see org.alfresco.cmis.search.CMISResultSet#getMetaData()
*/
public CMISResultSetMetaData getMetaData()
{
return new CMISResultSetMetaData(options, query, limitBy, cmisDictionaryService, alfrescoDictionaryService);
}
/*
* (non-Javadoc)
*
* @see org.alfresco.cmis.search.CMISResultSet#getRow(int)
*/
public CMISResultSetRow getRow(int i)
{
return new CMISResultSetRow(this, i, getScores(i), nodeService, getNodeRefs(i), query, cmisDictionaryService);
}
/*
* (non-Javadoc)
*
* @see org.alfresco.cmis.search.CMISResultSet#hasMore()
*/
public boolean hasMore()
{
for (ResultSet resultSet : wrapped.values())
{
if (resultSet.hasMore())
{
return true;
}
}
return false;
}
/*
* (non-Javadoc)
*
* @see org.alfresco.cmis.search.CMISResultSet#length()
*/
public int getLength()
{
for (ResultSet resultSet : wrapped.values())
{
return resultSet.length();
}
throw new IllegalStateException();
}
/*
* (non-Javadoc)
*
* @see org.alfresco.cmis.search.CMISResultSet#start()
*/
public int getStart()
{
return options.getSkipCount();
}
/*
* (non-Javadoc)
*
* @see java.lang.Iterable#iterator()
*/
public Iterator<CMISResultSetRow> iterator()
{
return new CMISResultSetRowIterator(this);
}
private Map<String, NodeRef> getNodeRefs(int i)
{
HashMap<String, NodeRef> refs = new HashMap<String, NodeRef>();
for (String selector : wrapped.keySet())
{
ResultSet rs = wrapped.get(selector);
refs.put(selector, rs.getNodeRef(i));
}
return refs;
}
private Map<String, Float> getScores(int i)
{
HashMap<String, Float> scores = new HashMap<String, Float>();
for (String selector : wrapped.keySet())
{
ResultSet rs = wrapped.get(selector);
scores.put(selector, Float.valueOf(rs.getScore(i)));
}
return scores;
}
public ChildAssociationRef getChildAssocRef(int n)
{
NodeRef nodeRef = getNodeRef(n);
return nodeService.getPrimaryParent(nodeRef);
}
public List<ChildAssociationRef> getChildAssocRefs()
{
ArrayList<ChildAssociationRef> cars = new ArrayList<ChildAssociationRef>(length());
for (ResultSetRow row : this)
{
cars.add(row.getChildAssocRef());
}
return cars;
}
public NodeRef getNodeRef(int n)
{
Map<String, NodeRef> refs = getNodeRefs(n);
if (refs.size() == 1)
{
return refs.values().iterator().next();
} else if (allNodeRefsEqual(refs))
{
return refs.values().iterator().next();
} else
{
throw new IllegalStateException("Ambiguous selector");
}
}
private boolean allNodeRefsEqual(Map<String, NodeRef> selected)
{
NodeRef last = null;
for (NodeRef current : selected.values())
{
if (last == null)
{
last = current;
} else
{
if (!last.equals(current))
{
return false;
}
}
}
return true;
}
public List<NodeRef> getNodeRefs()
{
ArrayList<NodeRef> nodeRefs = new ArrayList<NodeRef>(length());
for (ResultSetRow row : this)
{
nodeRefs.add(row.getNodeRef());
}
return nodeRefs;
}
public CMISResultSetMetaData getResultSetMetaData()
{
return getMetaData();
}
public float getScore(int n)
{
Map<String, Float> scores = getScores(n);
if (scores.size() == 1)
{
return scores.values().iterator().next();
} else if (allScoresEqual(scores))
{
return scores.values().iterator().next();
} else
{
throw new IllegalStateException("Ambiguous selector");
}
}
private boolean allScoresEqual(Map<String, Float> scores)
{
Float last = null;
for (Float current : scores.values())
{
if (last == null)
{
last = current;
} else
{
if (!last.equals(current))
{
return false;
}
}
}
return true;
}
public int length()
{
return getLength();
}
/**
* Bulk fetch results in the cache - not supported here
*
* @param bulkFetch
*/
public boolean setBulkFetch(boolean bulkFetch)
{
return false;
}
/**
* Do we bulk fetch - not supported here
*
* @return - true if we do
*/
public boolean getBulkFetch()
{
return false;
}
/**
* Set the bulk fetch size
*
* @param bulkFetchSize
*/
public int setBulkFetchSize(int bulkFetchSize)
{
return 0;
}
/**
* Get the bulk fetch size.
*
* @return the fetch size
*/
public int getBulkFetchSize()
{
return 0;
}
}

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.search;
import org.alfresco.opencmis.dictionary.PropertyDefintionWrapper;
import org.alfresco.service.cmr.search.ResultSetColumn;
import org.alfresco.service.namespace.QName;
import org.apache.chemistry.opencmis.commons.enums.PropertyType;
/**
* @author andyh
*
*/
public class CMISResultSetColumn implements ResultSetColumn
{
private String name;
private PropertyDefintionWrapper propertyDefinition;
private PropertyType dataType;
private QName alfrescoPropertyQName;
private QName alfrescoDataTypeQName;
CMISResultSetColumn(String name, PropertyDefintionWrapper propertyDefinition, PropertyType dataType,
QName alfrescoPropertyQName, QName alfrescoDataTypeQName)
{
this.name = name;
this.propertyDefinition = propertyDefinition;
this.dataType = dataType;
this.alfrescoPropertyQName = alfrescoPropertyQName;
this.alfrescoDataTypeQName = alfrescoDataTypeQName;
}
public String getName()
{
return name;
}
public PropertyDefintionWrapper getCMISPropertyDefinition()
{
return propertyDefinition;
}
public PropertyType getCMISDataType()
{
return dataType;
}
public QName getDataType()
{
return alfrescoDataTypeQName;
}
public QName getPropertyType()
{
return alfrescoPropertyQName;
}
}

View File

@@ -0,0 +1,201 @@
/*
* 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.search;
import java.util.LinkedHashMap;
import java.util.Map;
import org.alfresco.opencmis.dictionary.CMISDictionaryService;
import org.alfresco.opencmis.dictionary.PropertyDefintionWrapper;
import org.alfresco.opencmis.dictionary.TypeDefinitionWrapper;
import org.alfresco.repo.search.impl.querymodel.Column;
import org.alfresco.repo.search.impl.querymodel.PropertyArgument;
import org.alfresco.repo.search.impl.querymodel.Query;
import org.alfresco.repo.search.impl.querymodel.Selector;
import org.alfresco.repo.search.impl.querymodel.impl.functions.PropertyAccessor;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.search.LimitBy;
import org.alfresco.service.cmr.search.PermissionEvaluationMode;
import org.alfresco.service.cmr.search.ResultSetMetaData;
import org.alfresco.service.cmr.search.ResultSetType;
import org.alfresco.service.cmr.search.SearchParameters;
import org.alfresco.service.namespace.QName;
import org.apache.chemistry.opencmis.commons.enums.PropertyType;
/**
* @author andyh
*/
public class CMISResultSetMetaData implements ResultSetMetaData
{
private CMISQueryOptions options;
private SearchParameters searchParams;
private LimitBy limitBy;
private Map<String, CMISResultSetColumn> columnMetaData;
private Map<String, CMISResultSetSelector> selectorMetaData;
public CMISResultSetMetaData(CMISQueryOptions options, Query query, LimitBy limitBy,
CMISDictionaryService cmisDictionaryService, DictionaryService alfrescoDictionaryService)
{
this.options = options;
this.searchParams = new SearchParameters(options);
this.limitBy = limitBy;
Map<String, Selector> selectors = query.getSource().getSelectors();
selectorMetaData = new LinkedHashMap<String, CMISResultSetSelector>();
for (Selector selector : selectors.values())
{
TypeDefinitionWrapper type = cmisDictionaryService.findTypeForClass(selector.getType());
CMISResultSetSelector smd = new CMISResultSetSelector(selector.getAlias(), type);
selectorMetaData.put(smd.getName(), smd);
}
columnMetaData = new LinkedHashMap<String, CMISResultSetColumn>();
for (Column column : query.getColumns())
{
PropertyDefintionWrapper propertyDefinition = null;
PropertyType type = null;
QName alfrescoPropertyQName = null;
QName alfrescoDataTypeQName = null;
if (column.getFunction().getName().equals(PropertyAccessor.NAME))
{
PropertyArgument arg = (PropertyArgument) column.getFunctionArguments().get(
PropertyAccessor.ARG_PROPERTY);
String propertyName = arg.getPropertyName();
alfrescoPropertyQName = QName.createQName(propertyName);
PropertyDefinition alfPropDef = alfrescoDictionaryService.getProperty(alfrescoPropertyQName);
if (alfPropDef == null)
{
alfrescoPropertyQName = null;
} else
{
alfrescoDataTypeQName = alfPropDef.getDataType().getName();
}
propertyDefinition = cmisDictionaryService.findProperty(propertyName);
type = propertyDefinition.getPropertyDefinition().getPropertyType();
}
if (type == null)
{
type = cmisDictionaryService.findDataType(column.getFunction().getReturnType());
}
if (alfrescoDataTypeQName == null)
{
alfrescoDataTypeQName = cmisDictionaryService.findAlfrescoDataType(type);
}
CMISResultSetColumn cmd = new CMISResultSetColumn(column.getAlias(), propertyDefinition, type,
alfrescoPropertyQName, alfrescoDataTypeQName);
columnMetaData.put(cmd.getName(), cmd);
}
}
/*
* (non-Javadoc)
*
* @see org.alfresco.cmis.search.CMISResultSetMetaData#getColumnNames()
*/
public String[] getColumnNames()
{
return columnMetaData.keySet().toArray(new String[0]);
}
/*
* (non-Javadoc)
*
* @see org.alfresco.cmis.search.CMISResultSetMetaData#getColumns()
*/
public CMISResultSetColumn[] getColumns()
{
return columnMetaData.values().toArray(new CMISResultSetColumn[0]);
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.search.CMISResultSetMetaData#getCoumn(java.lang.String)
*/
public CMISResultSetColumn getColumn(String name)
{
return columnMetaData.get(name);
}
/*
* (non-Javadoc)
*
* @see org.alfresco.cmis.search.CMISResultSetMetaData#getQueryOptions()
*/
public CMISQueryOptions getQueryOptions()
{
return options;
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.cmis.search.CMISResultSetMetaData#getSelector(java.lang.
* String)
*/
public CMISResultSetSelector getSelector(String name)
{
return selectorMetaData.get(name);
}
/*
* (non-Javadoc)
*
* @see org.alfresco.cmis.search.CMISResultSetMetaData#getSelectorNames()
*/
public String[] getSelectorNames()
{
return selectorMetaData.keySet().toArray(new String[0]);
}
/*
* (non-Javadoc)
*
* @see org.alfresco.cmis.search.CMISResultSetMetaData#getSelectors()
*/
public CMISResultSetSelector[] getSelectors()
{
return selectorMetaData.values().toArray(new CMISResultSetSelector[0]);
}
public LimitBy getLimitedBy()
{
return limitBy;
}
public PermissionEvaluationMode getPermissionEvaluationMode()
{
throw new UnsupportedOperationException();
}
public ResultSetType getResultSetType()
{
return ResultSetType.COLUMN_AND_NODE_REF;
}
public SearchParameters getSearchParameters()
{
return searchParams;
}
}

View File

@@ -0,0 +1,279 @@
/*
* 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.search;
import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.Map;
import org.alfresco.opencmis.dictionary.CMISDictionaryService;
import org.alfresco.repo.search.impl.querymodel.Column;
import org.alfresco.repo.search.impl.querymodel.PropertyArgument;
import org.alfresco.repo.search.impl.querymodel.Query;
import org.alfresco.repo.search.impl.querymodel.impl.functions.PropertyAccessor;
import org.alfresco.repo.search.results.ResultSetSPIWrapper;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.cmr.search.ResultSetRow;
import org.alfresco.service.namespace.QName;
/**
* @author andyh
*/
public class CMISResultSetRow implements ResultSetRow
{
/**
* The containing result set
*/
private CMISResultSet resultSet;
/**
* The current position in the containing result set
*/
private int index;
private Map<String, Float> scores;
private NodeService nodeService;
private Map<String, NodeRef> nodeRefs;
private Query query;
private CMISDictionaryService cmisDictionaryService;
public CMISResultSetRow(CMISResultSet resultSet, int index, Map<String, Float> scores, NodeService nodeService,
Map<String, NodeRef> nodeRefs, Query query, CMISDictionaryService cmisDictionaryService)
{
this.resultSet = resultSet;
this.index = index;
this.scores = scores;
this.nodeService = nodeService;
this.nodeRefs = nodeRefs;
this.query = query;
this.cmisDictionaryService = cmisDictionaryService;
}
/*
* (non-Javadoc)
*
* @see org.alfresco.cmis.search.CMISResultSetRow#getIndex()
*/
public int getIndex()
{
return index;
}
/*
* (non-Javadoc)
*
* @see org.alfresco.cmis.search.CMISResultSetRow#getResultSet()
*/
public ResultSet getResultSet()
{
return new ResultSetSPIWrapper<CMISResultSetRow, CMISResultSetMetaData>(resultSet);
}
/*
* (non-Javadoc)
*
* @see org.alfresco.cmis.search.CMISResultSetRow#getScore()
*/
public float getScore()
{
float count = 0;
float overall = 0;
for (Float score : scores.values())
{
overall = (overall * (count / (count + 1.0f))) + (score / (count + 1.0f));
}
return overall;
}
/*
* (non-Javadoc)
*
* @see org.alfresco.cmis.search.CMISResultSetRow#getScore(java.lang.String)
*/
public float getScore(String selectorName)
{
return scores.get(selectorName);
}
/*
* (non-Javadoc)
*
* @see org.alfresco.cmis.search.CMISResultSetRow#getScores()
*/
public Map<String, Float> getScores()
{
return scores;
}
/*
* (non-Javadoc)
*
* @see org.alfresco.cmis.search.CMISResultSetRow#getScore(java.lang.String)
*/
public NodeRef getNodeRef(String selectorName)
{
return nodeRefs.get(selectorName);
}
/*
* (non-Javadoc)
*
* @see org.alfresco.cmis.search.CMISResultSetRow#getScores()
*/
public Map<String, NodeRef> getNodeRefs()
{
return nodeRefs;
}
/*
* (non-Javadoc)
*
* @see org.alfresco.cmis.search.CMISResultSetRow#getValue(java.lang.String)
*/
public Serializable getValue(String columnName)
{
CmisFunctionEvaluationContext context = new CmisFunctionEvaluationContext();
context.setCmisDictionaryService(cmisDictionaryService);
context.setNodeRefs(nodeRefs);
context.setNodeService(nodeService);
context.setScores(scores);
context.setScore(getScore());
for (Column column : query.getColumns())
{
if (column.getAlias().equals(columnName))
{
return column.getFunction().getValue(column.getFunctionArguments(), context);
}
// Special case for one selector - ignore any table aliases
// also allows look up direct and not by alias
// Perhaps we should add the duplicates instead
// TODO: check SQL 92 for single alias table behaviour for selectors
if (nodeRefs.size() == 1)
{
if (column.getFunction().getName().equals(PropertyAccessor.NAME))
{
PropertyArgument arg = (PropertyArgument) column.getFunctionArguments().get(
PropertyAccessor.ARG_PROPERTY);
String propertyName = arg.getPropertyName();
if (propertyName.equals(columnName))
{
return column.getFunction().getValue(column.getFunctionArguments(), context);
}
StringBuilder builder = new StringBuilder();
builder.append(arg.getSelector()).append(".").append(propertyName);
propertyName = builder.toString();
if (propertyName.equals(columnName))
{
return column.getFunction().getValue(column.getFunctionArguments(), context);
}
}
} else
{
if (column.getFunction().getName().equals(PropertyAccessor.NAME))
{
PropertyArgument arg = (PropertyArgument) column.getFunctionArguments().get(
PropertyAccessor.ARG_PROPERTY);
StringBuilder builder = new StringBuilder();
builder.append(arg.getSelector()).append(".").append(arg.getPropertyName());
String propertyName = builder.toString();
if (propertyName.equals(columnName))
{
return column.getFunction().getValue(column.getFunctionArguments(), context);
}
}
}
}
return null;
}
/*
* (non-Javadoc)
*
* @see org.alfresco.cmis.search.CMISResultSetRow#getValues()
*/
public Map<String, Serializable> getValues()
{
LinkedHashMap<String, Serializable> answer = new LinkedHashMap<String, Serializable>();
for (String column : resultSet.getMetaData().getColumnNames())
{
answer.put(column, getValue(column));
}
return answer;
}
public CMISResultSet getCMISResultSet()
{
return resultSet;
}
public ChildAssociationRef getChildAssocRef()
{
NodeRef nodeRef = getNodeRef();
return nodeService.getPrimaryParent(nodeRef);
}
public NodeRef getNodeRef()
{
if (nodeRefs.size() == 1)
{
return nodeRefs.values().iterator().next();
} else if (allNodeRefsEqual(nodeRefs))
{
return nodeRefs.values().iterator().next();
}
throw new UnsupportedOperationException("Ambiguous selector");
}
private boolean allNodeRefsEqual(Map<String, NodeRef> selected)
{
NodeRef last = null;
for (NodeRef current : selected.values())
{
if (last == null)
{
last = current;
} else
{
if (!last.equals(current))
{
return false;
}
}
}
return true;
}
public QName getQName()
{
return getChildAssocRef().getQName();
}
public Serializable getValue(QName qname)
{
throw new UnsupportedOperationException();
}
}

View File

@@ -0,0 +1,130 @@
/*
* 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.search;
import java.util.ListIterator;
/**
* @author andyh
*/
public class CMISResultSetRowIterator implements ListIterator<CMISResultSetRow>
{
/**
* The result set
*/
private CMISResultSet resultSet;
/**
* The current position
*/
private int position = -1;
/**
* The maximum position
*/
private int max;
/**
* Create an iterator over the result set. Follows stadard ListIterator
* conventions
*
* @param resultSet
*/
public CMISResultSetRowIterator(CMISResultSet resultSet)
{
this.resultSet = resultSet;
this.max = resultSet.getLength();
}
public CMISResultSet getResultSet()
{
return resultSet;
}
/*
* ListIterator implementation
*/
public boolean hasNext()
{
return position < (max - 1);
}
public boolean allowsReverse()
{
return true;
}
public boolean hasPrevious()
{
return position > 0;
}
public CMISResultSetRow next()
{
return resultSet.getRow(moveToNextPosition());
}
protected int moveToNextPosition()
{
return ++position;
}
public CMISResultSetRow previous()
{
return resultSet.getRow(moveToPreviousPosition());
}
protected int moveToPreviousPosition()
{
return --position;
}
public int nextIndex()
{
return position + 1;
}
public int previousIndex()
{
return position - 1;
}
/*
* Mutation is not supported
*/
public void remove()
{
// TODO Auto-generated method stub
throw new UnsupportedOperationException();
}
public void set(CMISResultSetRow o)
{
// TODO Auto-generated method stub
throw new UnsupportedOperationException();
}
public void add(CMISResultSetRow o)
{
// TODO Auto-generated method stub
throw new UnsupportedOperationException();
}
}

View File

@@ -0,0 +1,56 @@
/*
* 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.search;
import org.alfresco.opencmis.dictionary.TypeDefinitionWrapper;
import org.alfresco.service.cmr.search.ResultSetSelector;
import org.alfresco.service.namespace.QName;
/**
* @author andyh
*
*/
public class CMISResultSetSelector implements ResultSetSelector
{
private String name;
private TypeDefinitionWrapper typeDefinition;
public CMISResultSetSelector(String name, TypeDefinitionWrapper typeDefinition)
{
this.name = name;
this.typeDefinition = typeDefinition;
}
public String getName()
{
return name;
}
public TypeDefinitionWrapper getTypeDefinition()
{
return typeDefinition;
}
public QName getType()
{
return typeDefinition.getAlfrescoName();
}
}

View File

@@ -0,0 +1,429 @@
/*
* 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.search;
import java.io.Serializable;
import java.util.Collection;
import java.util.Map;
import org.alfresco.cmis.CMISDictionaryModel;
import org.alfresco.opencmis.dictionary.CMISDictionaryService;
import org.alfresco.opencmis.dictionary.PropertyDefintionWrapper;
import org.alfresco.opencmis.dictionary.TypeDefinitionWrapper;
import org.alfresco.repo.search.impl.lucene.LuceneFunction;
import org.alfresco.repo.search.impl.lucene.LuceneQueryParser;
import org.alfresco.repo.search.impl.querymodel.FunctionArgument;
import org.alfresco.repo.search.impl.querymodel.FunctionEvaluationContext;
import org.alfresco.repo.search.impl.querymodel.PredicateMode;
import org.alfresco.repo.search.impl.querymodel.QueryModelException;
import org.alfresco.repo.search.impl.querymodel.Selector;
import org.alfresco.repo.search.impl.querymodel.impl.functions.Lower;
import org.alfresco.repo.search.impl.querymodel.impl.functions.Upper;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
import org.apache.chemistry.opencmis.commons.enums.Cardinality;
import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.search.Query;
/**
* @author andyh
*/
public class CmisFunctionEvaluationContext implements FunctionEvaluationContext
{
public static BaseTypeId[] STRICT_SCOPES = new BaseTypeId[] { BaseTypeId.CMIS_DOCUMENT, BaseTypeId.CMIS_FOLDER };
public static BaseTypeId[] ALFRESCO_SCOPES = new BaseTypeId[] { BaseTypeId.CMIS_DOCUMENT, BaseTypeId.CMIS_FOLDER,
BaseTypeId.CMIS_POLICY };
private Map<String, NodeRef> nodeRefs;
private Map<String, Float> scores;
private NodeService nodeService;
private CMISDictionaryService cmisDictionaryService;
private BaseTypeId[] validScopes;
private Float score;
/**
* @param nodeRefs
* the nodeRefs to set
*/
public void setNodeRefs(Map<String, NodeRef> nodeRefs)
{
this.nodeRefs = nodeRefs;
}
/**
* @param scores
* the scores to set
*/
public void setScores(Map<String, Float> scores)
{
this.scores = scores;
}
/**
* @param nodeService
* the nodeService to set
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* @param cmisDictionaryService
* the cmisDictionaryService to set
*/
public void setCmisDictionaryService(CMISDictionaryService cmisDictionaryService)
{
this.cmisDictionaryService = cmisDictionaryService;
}
/**
* @param validScopes
* the valid scopes to set
*/
public void setValidScopes(BaseTypeId[] validScopes)
{
this.validScopes = validScopes;
}
/*
* (non-Javadoc)
*
* @see org.alfresco.repo.search.impl.querymodel.FunctionEvaluationContext#
* getNodeRefs()
*/
public Map<String, NodeRef> getNodeRefs()
{
return nodeRefs;
}
/*
* (non-Javadoc)
*
* @see org.alfresco.repo.search.impl.querymodel.FunctionEvaluationContext#
* getNodeService()
*/
public NodeService getNodeService()
{
return nodeService;
}
/*
* (non-Javadoc)
*
* @see org.alfresco.repo.search.impl.querymodel.FunctionEvaluationContext#
* getProperty(org.alfresco.service.cmr.repository.NodeRef,
* org.alfresco.service.namespace.QName)
*/
public Serializable getProperty(NodeRef nodeRef, String propertyName)
{
PropertyDefintionWrapper propertyDef = cmisDictionaryService.findProperty(propertyName);
return propertyDef.getPropertyAccessor().getValue(nodeRef);
}
/*
* (non-Javadoc)
*
* @see
* org.alfresco.repo.search.impl.querymodel.FunctionEvaluationContext#getScores
* ()
*/
public Map<String, Float> getScores()
{
return scores;
}
/**
* @return the score
*/
public Float getScore()
{
return score;
}
/**
* @param score
* the score to set
*/
public void setScore(Float score)
{
this.score = score;
}
public Query buildLuceneEquality(LuceneQueryParser lqp, String propertyName, Serializable value,
PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
{
PropertyDefintionWrapper propertyDef = cmisDictionaryService.findProperty(propertyName);
return propertyDef.getPropertyLuceneBuilder().buildLuceneEquality(lqp, value, mode, luceneFunction);
}
/*
* (non-Javadoc)
*
* @see org.alfresco.repo.search.impl.querymodel.FunctionEvaluationContext#
* buildLuceneExists(org.alfresco.repo.search.impl.lucene.LuceneQueryParser,
* org.alfresco.service.namespace.QName, java.lang.Boolean)
*/
public Query buildLuceneExists(LuceneQueryParser lqp, String propertyName, Boolean not) throws ParseException
{
PropertyDefintionWrapper propertyDef = cmisDictionaryService.findProperty(propertyName);
return propertyDef.getPropertyLuceneBuilder().buildLuceneExists(lqp, not);
}
/*
* (non-Javadoc)
*
* @see org.alfresco.repo.search.impl.querymodel.FunctionEvaluationContext#
* buildLuceneGreaterThan
* (org.alfresco.repo.search.impl.lucene.LuceneQueryParser,
* org.alfresco.service.namespace.QName, java.io.Serializable,
* org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneGreaterThan(LuceneQueryParser lqp, String propertyName, Serializable value,
PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
{
PropertyDefintionWrapper propertyDef = cmisDictionaryService.findProperty(propertyName);
return propertyDef.getPropertyLuceneBuilder().buildLuceneGreaterThan(lqp, value, mode, luceneFunction);
}
/*
* (non-Javadoc)
*
* @see org.alfresco.repo.search.impl.querymodel.FunctionEvaluationContext#
* buildLuceneGreaterThanOrEquals
* (org.alfresco.repo.search.impl.lucene.LuceneQueryParser,
* org.alfresco.service.namespace.QName, java.io.Serializable,
* org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneGreaterThanOrEquals(LuceneQueryParser lqp, String propertyName, Serializable value,
PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
{
PropertyDefintionWrapper propertyDef = cmisDictionaryService.findProperty(propertyName);
return propertyDef.getPropertyLuceneBuilder().buildLuceneGreaterThanOrEquals(lqp, value, mode, luceneFunction);
}
/*
* (non-Javadoc)
*
* @see org.alfresco.repo.search.impl.querymodel.FunctionEvaluationContext#
* buildLuceneIn(org.alfresco.repo.search.impl.lucene.LuceneQueryParser,
* org.alfresco.service.namespace.QName, java.util.Collection,
* java.lang.Boolean,
* org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneIn(LuceneQueryParser lqp, String propertyName, Collection<Serializable> values,
Boolean not, PredicateMode mode) throws ParseException
{
PropertyDefintionWrapper propertyDef = cmisDictionaryService.findProperty(propertyName);
return propertyDef.getPropertyLuceneBuilder().buildLuceneIn(lqp, values, not, mode);
}
/*
* (non-Javadoc)
*
* @see org.alfresco.repo.search.impl.querymodel.FunctionEvaluationContext#
* buildLuceneInequality
* (org.alfresco.repo.search.impl.lucene.LuceneQueryParser,
* org.alfresco.service.namespace.QName, java.io.Serializable,
* org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneInequality(LuceneQueryParser lqp, String propertyName, Serializable value,
PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
{
PropertyDefintionWrapper propertyDef = cmisDictionaryService.findProperty(propertyName);
return propertyDef.getPropertyLuceneBuilder().buildLuceneInequality(lqp, value, mode, luceneFunction);
}
/*
* (non-Javadoc)
*
* @see org.alfresco.repo.search.impl.querymodel.FunctionEvaluationContext#
* buildLuceneLessThan
* (org.alfresco.repo.search.impl.lucene.LuceneQueryParser,
* org.alfresco.service.namespace.QName, java.io.Serializable,
* org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneLessThan(LuceneQueryParser lqp, String propertyName, Serializable value,
PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
{
PropertyDefintionWrapper propertyDef = cmisDictionaryService.findProperty(propertyName);
return propertyDef.getPropertyLuceneBuilder().buildLuceneLessThan(lqp, value, mode, luceneFunction);
}
/*
* (non-Javadoc)
*
* @see org.alfresco.repo.search.impl.querymodel.FunctionEvaluationContext#
* buildLuceneLessThanOrEquals
* (org.alfresco.repo.search.impl.lucene.LuceneQueryParser,
* org.alfresco.service.namespace.QName, java.io.Serializable,
* org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneLessThanOrEquals(LuceneQueryParser lqp, String propertyName, Serializable value,
PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
{
PropertyDefintionWrapper propertyDef = cmisDictionaryService.findProperty(propertyName);
return propertyDef.getPropertyLuceneBuilder().buildLuceneLessThanOrEquals(lqp, value, mode, luceneFunction);
}
/*
* (non-Javadoc)
*
* @see org.alfresco.repo.search.impl.querymodel.FunctionEvaluationContext#
* buildLuceneLike(org.alfresco.repo.search.impl.lucene.LuceneQueryParser,
* org.alfresco.service.namespace.QName, java.io.Serializable,
* java.lang.Boolean)
*/
public Query buildLuceneLike(LuceneQueryParser lqp, String propertyName, Serializable value, Boolean not)
throws ParseException
{
PropertyDefintionWrapper propertyDef = cmisDictionaryService.findProperty(propertyName);
return propertyDef.getPropertyLuceneBuilder().buildLuceneLike(lqp, value, not);
}
/*
* (non-Javadoc)
*
* @see org.alfresco.repo.search.impl.querymodel.FunctionEvaluationContext#
* getLuceneSortField(org.alfresco.service.namespace.QName)
*/
public String getLuceneSortField(LuceneQueryParser lqp, String propertyName)
{
PropertyDefintionWrapper propertyDef = cmisDictionaryService.findProperty(propertyName);
return propertyDef.getPropertyLuceneBuilder().getLuceneSortField(lqp);
}
public boolean isObjectId(String propertyName)
{
return CMISDictionaryModel.PROP_OBJECT_ID.equalsIgnoreCase(propertyName);
}
public boolean isOrderable(String fieldName)
{
PropertyDefintionWrapper propertyDef = cmisDictionaryService.findProperty(fieldName);
if (propertyDef == null)
{
return false;
} else
{
return propertyDef.getPropertyDefinition().isOrderable();
}
}
public boolean isQueryable(String fieldName)
{
PropertyDefintionWrapper propertyDef = cmisDictionaryService.findProperty(fieldName);
if (propertyDef == null)
{
return true;
} else
{
return propertyDef.getPropertyDefinition().isQueryable();
}
}
public String getLuceneFieldName(String propertyName)
{
PropertyDefintionWrapper propertyDef = cmisDictionaryService.findProperty(propertyName);
if (propertyDef != null)
{
return propertyDef.getPropertyLuceneBuilder().getLuceneFieldName();
} else
{
// TODO: restrict to supported "special" fields
return propertyName;
}
}
public LuceneFunction getLuceneFunction(FunctionArgument functionArgument)
{
if (functionArgument == null)
{
return LuceneFunction.FIELD;
} else
{
String functionName = functionArgument.getFunction().getName();
if (functionName.equals(Upper.NAME))
{
return LuceneFunction.UPPER;
} else if (functionName.equals(Lower.NAME))
{
return LuceneFunction.LOWER;
} else
{
throw new QueryModelException("Unsupported function: " + functionName);
}
}
}
/*
* (non-Javadoc)
*
* @see org.alfresco.repo.search.impl.querymodel.FunctionEvaluationContext#
* checkFieldApplies(org.alfresco.service.namespace.QName, java.lang.String)
*/
public void checkFieldApplies(Selector selector, String propertyName)
{
PropertyDefintionWrapper propDef = cmisDictionaryService.findPropertyByQueryName(propertyName);
if (propDef == null)
{
throw new CmisInvalidArgumentException("Unknown column/property " + propertyName);
}
TypeDefinitionWrapper typeDef = cmisDictionaryService.findTypeForClass(selector.getType(), validScopes);
if (typeDef == null)
{
throw new CmisInvalidArgumentException("Type unsupported in CMIS queries: " + selector.getAlias());
}
// Check column/property applies to selector/type
if (typeDef.getPropertyById(propDef.getPropertyId()) == null)
{
throw new CmisInvalidArgumentException("Invalid column for "
+ typeDef.getTypeDefinition(false).getQueryName() + "." + propertyName);
}
}
/*
* (non-Javadoc)
*
* @see org.alfresco.repo.search.impl.querymodel.FunctionEvaluationContext#
* isMultiValued(java.lang.String)
*/
public boolean isMultiValued(String propertyName)
{
PropertyDefintionWrapper propDef = cmisDictionaryService.findPropertyByQueryName(propertyName);
if (propDef == null)
{
throw new CmisInvalidArgumentException("Unknown column/property " + propertyName);
}
return propDef.getPropertyDefinition().getCardinality() == Cardinality.MULTI;
}
}

View File

@@ -0,0 +1,98 @@
/*
* 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.repo.search.impl.lucene;
import java.util.List;
import org.alfresco.opencmis.search.CMISQueryOptions;
import org.alfresco.opencmis.search.CMISQueryOptions.CMISQueryMode;
import org.alfresco.opencmis.search.CMISQueryService;
import org.alfresco.opencmis.search.CMISResultSetMetaData;
import org.alfresco.opencmis.search.CMISResultSetRow;
import org.alfresco.repo.search.impl.querymodel.QueryOptions.Connective;
import org.alfresco.repo.search.results.ResultSetSPIWrapper;
import org.alfresco.service.cmr.search.LimitBy;
import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.cmr.search.SearchParameters;
import org.alfresco.service.cmr.search.SearchService;
/**
* Support for sql-cmis-strict in the search service
*
* @author andyh
*
*/
public class LuceneOpenCMISAlfrescoSqlQueryLanguage implements LuceneQueryLanguageSPI
{
private CMISQueryService cmisQueryService;
/**
* Set the search service
*
* @param cmisQueryService
*/
public void setCmisQueryService(CMISQueryService cmisQueryService)
{
this.cmisQueryService = cmisQueryService;
}
public ResultSet executeQuery(SearchParameters searchParameters, ADMLuceneSearcherImpl admLuceneSearcher)
{
String sql = searchParameters.getQuery();
CMISQueryOptions options = new CMISQueryOptions(sql, searchParameters.getStores().get(0));
options.setIncludeInTransactionData(!searchParameters.excludeDataInTheCurrentTransaction());
options.setDefaultFTSConnective(searchParameters.getDefaultOperator() == SearchParameters.Operator.OR ? Connective.OR
: Connective.AND);
options.setDefaultFTSFieldConnective(searchParameters.getDefaultOperator() == SearchParameters.Operator.OR ? Connective.OR
: Connective.AND);
options.setSkipCount(searchParameters.getSkipCount());
options.setMaxPermissionChecks(searchParameters.getMaxPermissionChecks());
options.setMaxPermissionCheckTimeMillis(searchParameters.getMaxPermissionCheckTimeMillis());
options.setDefaultFieldName(searchParameters.getDefaultFieldName());
if (searchParameters.getLimitBy() == LimitBy.FINAL_SIZE)
{
options.setMaxItems(searchParameters.getLimit());
} else
{
options.setMaxItems(searchParameters.getMaxItems());
}
options.setMlAnalaysisMode(searchParameters.getMlAnalaysisMode());
options.setLocales(searchParameters.getLocales());
options.setStores(searchParameters.getStores());
options.setQueryMode(CMISQueryMode.CMS_WITH_ALFRESCO_EXTENSIONS);
return new ResultSetSPIWrapper<CMISResultSetRow, CMISResultSetMetaData>(cmisQueryService.query(options));
}
public String getName()
{
return SearchService.LANGUAGE_CMIS_ALFRESCO;
}
public void setFactories(List<AbstractLuceneIndexerAndSearcherFactory> factories)
{
for (AbstractLuceneIndexerAndSearcherFactory factory : factories)
{
factory.registerQueryLanguage(this);
}
}
}

View File

@@ -0,0 +1,97 @@
/*
* 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.repo.search.impl.lucene;
import java.util.List;
import org.alfresco.opencmis.search.CMISQueryOptions;
import org.alfresco.opencmis.search.CMISQueryOptions.CMISQueryMode;
import org.alfresco.opencmis.search.CMISQueryService;
import org.alfresco.opencmis.search.CMISResultSetMetaData;
import org.alfresco.opencmis.search.CMISResultSetRow;
import org.alfresco.repo.search.impl.querymodel.QueryOptions.Connective;
import org.alfresco.repo.search.results.ResultSetSPIWrapper;
import org.alfresco.service.cmr.search.LimitBy;
import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.cmr.search.SearchParameters;
import org.alfresco.service.cmr.search.SearchService;
/**
* Support for Alfresco SQL in the search service
*
* @author andyh
*
*/
public class LuceneOpenCMISStrictSqlQueryLanguage implements LuceneQueryLanguageSPI
{
private CMISQueryService cmisQueryService;
/**
* Set the search service
*
* @param cmisQueryService
*/
public void setCmisQueryService(CMISQueryService cmisQueryService)
{
this.cmisQueryService = cmisQueryService;
}
public ResultSet executeQuery(SearchParameters searchParameters, ADMLuceneSearcherImpl admLuceneSearcher)
{
String sql = searchParameters.getQuery();
CMISQueryOptions options = new CMISQueryOptions(sql, searchParameters.getStores().get(0));
options.setIncludeInTransactionData(!searchParameters.excludeDataInTheCurrentTransaction());
options.setDefaultFTSConnective(searchParameters.getDefaultOperator() == SearchParameters.Operator.OR ? Connective.OR
: Connective.AND);
options.setDefaultFTSFieldConnective(searchParameters.getDefaultOperator() == SearchParameters.Operator.OR ? Connective.OR
: Connective.AND);
options.setSkipCount(searchParameters.getSkipCount());
options.setMaxPermissionChecks(searchParameters.getMaxPermissionChecks());
options.setMaxPermissionCheckTimeMillis(searchParameters.getMaxPermissionCheckTimeMillis());
if (searchParameters.getLimitBy() == LimitBy.FINAL_SIZE)
{
options.setMaxItems(searchParameters.getLimit());
} else
{
options.setMaxItems(searchParameters.getMaxItems());
}
options.setMlAnalaysisMode(searchParameters.getMlAnalaysisMode());
options.setLocales(searchParameters.getLocales());
options.setStores(searchParameters.getStores());
options.setQueryMode(CMISQueryMode.CMS_STRICT);
return new ResultSetSPIWrapper<CMISResultSetRow, CMISResultSetMetaData>(cmisQueryService.query(options));
}
public String getName()
{
return SearchService.LANGUAGE_CMIS_STRICT;
}
public void setFactories(List<AbstractLuceneIndexerAndSearcherFactory> factories)
{
for (AbstractLuceneIndexerAndSearcherFactory factory : factories)
{
factory.registerQueryLanguage(this);
}
}
}