Merge from SEAMIST3

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@10731 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
David Caruana
2008-09-04 11:09:45 +00:00
parent 3e303a86d5
commit fb231f88bc
26 changed files with 749 additions and 41 deletions

View File

@@ -24,8 +24,15 @@
*/
package org.alfresco.repo.cmis.rest;
import java.util.Collection;
import java.util.Iterator;
import org.alfresco.cmis.CMISService;
import org.alfresco.cmis.CMISService.TypesFilter;
import org.alfresco.cmis.dictionary.CMISDictionaryService;
import org.alfresco.cmis.dictionary.CMISTypeDefinition;
import org.alfresco.cmis.dictionary.CMISTypeId;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.jscript.BaseScopableProcessorExtension;
import org.alfresco.repo.jscript.ScriptNode;
import org.alfresco.repo.model.Repository;
@@ -49,6 +56,7 @@ public class CMISScript extends BaseScopableProcessorExtension
private ServiceRegistry services;
private Repository repository;
private CMISService cmisService;
private CMISDictionaryService cmisDictionaryService;
private Paging paging;
@@ -83,7 +91,7 @@ public class CMISScript extends BaseScopableProcessorExtension
}
/**
* Set the CMIS Navigation helper
* Set the CMIS Service
*
* @param cmisService
*/
@@ -91,7 +99,17 @@ public class CMISScript extends BaseScopableProcessorExtension
{
this.cmisService = cmisService;
}
/**
* Set the CMIS Dictionary Service
*
* @param cmisDictionaryService
*/
public void setCMISDictionaryService(CMISDictionaryService cmisDictionaryService)
{
this.cmisDictionaryService = cmisDictionaryService;
}
/**
* Gets the supported CMIS Version
*
@@ -273,6 +291,83 @@ public class CMISScript extends BaseScopableProcessorExtension
return results;
}
/**
* Query for all Type Definitions
*
* @param page
* @return paged result set of types
*/
public PagedResults queryTypes(Page page)
{
Collection<CMISTypeId> typeIds = cmisDictionaryService.getAllObjectTypeIds();
Cursor cursor = paging.createCursor(typeIds.size(), page);
// skip
Iterator<CMISTypeId> iterTypeIds = typeIds.iterator();
for (int i = 0; i < cursor.getStartRow(); i++)
{
iterTypeIds.next();
}
// get types for page
CMISTypeDefinition[] types = new CMISTypeDefinition[cursor.getRowCount()];
for (int i = cursor.getStartRow(); i <= cursor.getEndRow(); i++)
{
types[i - cursor.getStartRow()] = cmisDictionaryService.getType(iterTypeIds.next());
}
PagedResults results = paging.createPagedResults(types, cursor);
return results;
}
/**
* Query for all Type Definitions in a type hierarchy
*
* @param page
* @return paged result set of types
*/
public PagedResults queryTypeHierarchy(CMISTypeDefinition typedef, boolean descendants, Page page)
{
Collection<CMISTypeId> typeIds = cmisDictionaryService.getChildTypeIds(typedef.getObjectTypeId(), descendants);
Cursor cursor = paging.createCursor(typeIds.size(), page);
// skip
Iterator<CMISTypeId> iterTypeIds = typeIds.iterator();
for (int i = 0; i < cursor.getStartRow(); i++)
{
iterTypeIds.next();
}
// get types for page
CMISTypeDefinition[] types = new CMISTypeDefinition[cursor.getRowCount()];
for (int i = cursor.getStartRow(); i <= cursor.getEndRow(); i++)
{
types[i - cursor.getStartRow()] = cmisDictionaryService.getType(iterTypeIds.next());
}
PagedResults results = paging.createPagedResults(types, cursor);
return results;
}
/**
* Query for all Type Definitions
*
* @param page
* @return paged result set of types
*/
public CMISTypeDefinition queryType(String typeId)
{
try
{
CMISTypeId cmisTypeId = cmisDictionaryService.getCMISMapping().getCmisTypeId(typeId);
return cmisDictionaryService.getType(cmisTypeId);
}
catch(AlfrescoRuntimeException e)
{
return null;
}
}
/**
* Resolve to a Types Filter
*

View File

@@ -26,7 +26,9 @@ package org.alfresco.repo.cmis.rest;
import java.io.StringReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.alfresco.util.GUID;
import org.alfresco.web.scripts.Format;
@@ -132,6 +134,15 @@ public class CMISTest extends BaseCMISWebScriptTest
return rootHREF;
}
private IRI getTypesCollection(Service service)
{
Collection root = service.getCollection("Main Repository", "type collection");
assertNotNull(root);
IRI rootHREF = root.getHref();
assertNotNull(rootHREF);
return rootHREF;
}
private Entry createFolder(IRI parent, String name)
throws Exception
{
@@ -247,8 +258,7 @@ public class CMISTest extends BaseCMISWebScriptTest
public void testRepository()
throws Exception
{
Service service = getRepository();
IRI rootHREF = getRootCollection(service);
IRI rootHREF = getRootCollection(getRepository());
sendRequest(new GetRequest(rootHREF.toString()), 200, getAtomValidator());
}
@@ -331,7 +341,7 @@ public class CMISTest extends BaseCMISWebScriptTest
assertNotNull(documentRes);
String documentXML = documentRes.getContentAsString();
assertNotNull(documentXML);
IRI checkedoutHREF = getCheckedOutCollection(service);
IRI checkedoutHREF = getCheckedOutCollection(getRepository());
Response pwcRes = sendRequest(new PostRequest(checkedoutHREF.toString(), documentXML, Format.ATOMENTRY.mimetype()), 201, getAtomValidator());
assertNotNull(pwcRes);
Entry pwc = abdera.parseEntry(new StringReader(pwcRes.getContentAsString()), null);
@@ -344,10 +354,49 @@ public class CMISTest extends BaseCMISWebScriptTest
assertNotNull(children.getEntry(document2.getId().toString()));
assertNotNull(children.getEntry(document3.getId().toString()));
assertNull(children.getEntry(pwc.getId().toString()));
// TODO: paging
}
public void testChildrenPaging()
throws Exception
{
// create multiple children
Set<IRI> docIds = new HashSet<IRI>();
Entry testFolder = createTestFolder("testChildrenPaging");
Link childrenLink = testFolder.getLink(CMISConstants.REL_CHILDREN);
assertNotNull(childrenLink);
for (int i = 0; i < 15; i++)
{
Entry document = createDocument(childrenLink.getHref(), "testChildrenPaging" + i);
assertNotNull(document);
docIds.add(document.getId());
}
assertEquals(15, docIds.size());
// get children, ensure they exist (but not private working copy)
int nextCount = 0;
Map<String, String> args = new HashMap<String, String>();
args.put("maxItems", "4");
IRI childrenHREF = childrenLink.getHref();
while (childrenHREF != null)
{
nextCount++;
Feed types = getFeed(childrenHREF, args);
assertNotNull(types);
assertEquals(nextCount < 4 ? 4 : 3, types.getEntries().size());
for (Entry entry : types.getEntries())
{
docIds.remove(entry.getId());
}
// next page
Link nextLink = types.getLink("next");
childrenHREF = (nextLink != null) ? nextLink.getHref() : null;
args = null;
};
assertEquals(4, nextCount);
assertEquals(0, docIds.size());
}
public void testGetParent()
throws Exception
{
@@ -480,7 +529,7 @@ public class CMISTest extends BaseCMISWebScriptTest
// retrieve checkouts within scope of test checkout folder
Service repository = getRepository();
assertNotNull(repository);
IRI checkedoutHREF = getCheckedOutCollection(service);
IRI checkedoutHREF = getCheckedOutCollection(getRepository());
Map<String, String> args = new HashMap<String, String>();
args.put("folderId", scopeId);
Feed checkedout = getFeed(new IRI(checkedoutHREF.toString()), args);
@@ -503,7 +552,7 @@ public class CMISTest extends BaseCMISWebScriptTest
assertNotNull(documentXML);
// checkout
IRI checkedoutHREF = getCheckedOutCollection(service);
IRI checkedoutHREF = getCheckedOutCollection(getRepository());
Response pwcRes = sendRequest(new PostRequest(checkedoutHREF.toString(), documentXML, Format.ATOMENTRY.mimetype()), 201, getAtomValidator());
assertNotNull(pwcRes);
// TODO: test private working copy properties
@@ -533,7 +582,7 @@ public class CMISTest extends BaseCMISWebScriptTest
assertNotNull(xml);
// checkout
IRI checkedoutHREF = getCheckedOutCollection(service);
IRI checkedoutHREF = getCheckedOutCollection(getRepository());
Response pwcRes = sendRequest(new PostRequest(checkedoutHREF.toString(), xml, Format.ATOMENTRY.mimetype()), 201, getAtomValidator());
assertNotNull(pwcRes);
String pwcXml = pwcRes.getContentAsString();
@@ -578,7 +627,7 @@ public class CMISTest extends BaseCMISWebScriptTest
assertNotNull(xml);
// checkout
IRI checkedoutHREF = getCheckedOutCollection(service);
IRI checkedoutHREF = getCheckedOutCollection(getRepository());
Response pwcRes = sendRequest(new PostRequest(checkedoutHREF.toString(), xml, Format.ATOMENTRY.mimetype()), 201, getAtomValidator());
assertNotNull(pwcRes);
Entry pwc = abdera.parseEntry(new StringReader(pwcRes.getContentAsString()), null);
@@ -651,7 +700,7 @@ public class CMISTest extends BaseCMISWebScriptTest
assertNotNull(xml);
// checkout
IRI checkedoutHREF = getCheckedOutCollection(service);
IRI checkedoutHREF = getCheckedOutCollection(getRepository());
Response pwcRes = sendRequest(new PostRequest(checkedoutHREF.toString(), xml, Format.ATOMENTRY.mimetype()), 201, getAtomValidator());
assertNotNull(pwcRes);
Entry pwc = abdera.parseEntry(new StringReader(pwcRes.getContentAsString()), null);
@@ -712,7 +761,7 @@ public class CMISTest extends BaseCMISWebScriptTest
String xml = documentRes.getContentAsString();
assertNotNull(xml);
IRI checkedoutHREF = getCheckedOutCollection(service);
IRI checkedoutHREF = getCheckedOutCollection(getRepository());
for (int i = 0; i < NUMBER_OF_VERSIONS; i++)
{
// checkout
@@ -751,7 +800,52 @@ public class CMISTest extends BaseCMISWebScriptTest
}
}
public void testGetAllTypeDefinitions()
throws Exception
{
IRI typesHREF = getTypesCollection(getRepository());
Feed types = getFeed(typesHREF);
assertNotNull(types);
Feed typesWithProps = getFeed(typesHREF);
assertNotNull(typesWithProps);
// TODO: spec issue 40
for (Entry type : types.getEntries())
{
Entry retrievedType = getEntry(type.getSelfLink().getHref());
assertEquals(type.getId(), retrievedType.getId());
assertEquals(type.getTitle(), retrievedType.getTitle());
// TODO: type specific properties - extension to Abdera
}
}
public void testGetHierarchyTypeDefinitions()
throws Exception
{
IRI typesHREF = getTypesCollection(getRepository());
Map<String, String> args = new HashMap<String, String>();
args.put("type", "FOLDER_OBJECT_TYPE");
args.put("includePropertyDefinitions", "true");
args.put("maxItems", "5");
while (typesHREF != null)
{
Feed types = getFeed(typesHREF, args);
// TODO: spec issue 40
for (Entry type : types.getEntries())
{
Entry retrievedType = getEntry(type.getSelfLink().getHref());
assertEquals(type.getId(), retrievedType.getId());
assertEquals(type.getTitle(), retrievedType.getTitle());
// TODO: type specific properties - extension to Abdera
}
// next page
Link nextLink = types.getLink("next");
typesHREF = (nextLink != null) ? nextLink.getHref() : null;
args.remove("maxItems");
};
}
// public void testUnfiled()
// {
// }

View File

@@ -0,0 +1,98 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.cmis.rest;
import java.util.List;
import org.alfresco.cmis.dictionary.CMISMapping;
import org.alfresco.cmis.dictionary.CMISTypeId;
import org.alfresco.repo.jscript.ScriptNode;
import org.alfresco.repo.template.TemplateNode;
import org.alfresco.service.namespace.QName;
import freemarker.ext.beans.BeanModel;
import freemarker.template.TemplateMethodModelEx;
import freemarker.template.TemplateModelException;
/**
* Custom FreeMarker Template language method.
* <p>
* Retrieve the CMIS Type Id for an Alfresco node
* <p>
* Usage: cmisTypeId(ScriptNode node)
* cmisTypeId(QName nodeType)
*
* @author davidc
*/
public final class CMISTypeIdMethod implements TemplateMethodModelEx
{
private CMISMapping mappingService;
/**
* Construct
*/
public CMISTypeIdMethod(CMISMapping mappingService)
{
this.mappingService = mappingService;
}
/**
* @see freemarker.template.TemplateMethodModel#exec(java.util.List)
*/
public Object exec(List args) throws TemplateModelException
{
CMISTypeId result = null;
if (args.size() == 1)
{
Object arg0 = args.get(0);
if (arg0 instanceof BeanModel)
{
// extract node type qname
QName nodeType = null;
Object wrapped = ((BeanModel)arg0).getWrappedObject();
if (wrapped != null)
{
if (wrapped instanceof TemplateNode)
{
nodeType = ((TemplateNode)wrapped).getType();
}
else if (wrapped instanceof QName)
{
nodeType = (QName)wrapped;
}
}
// convert to CMIS type id
if (nodeType != null)
{
result = mappingService.getCmisTypeId(nodeType);
}
}
}
return result;
}
}

View File

@@ -180,7 +180,6 @@ public class RepositoryContainer extends AbstractRuntimeContainer implements Ten
Map<String, Object> params = new HashMap<String, Object>();
params.putAll(super.getTemplateParameters());
params.put(TemplateService.KEY_IMAGE_RESOLVER, imageResolver.getImageResolver());
params.put("cropContent", new CropContentMethod());
addRepoParameters(params);
return params;
}

View File

@@ -156,5 +156,5 @@ public class TestWebScriptRepoServer extends TestWebScriptServer
}
}, username);
}
}

View File

@@ -24,6 +24,8 @@
*/
package org.alfresco.repo.web.util.paging;
import java.util.Map;
/**
* Paging. A utility for maintaining paged indexes for a collection of N items.
*
@@ -134,6 +136,90 @@ public class Paging
{
return zeroBasedRow;
}
/**
* Create a Page or Window from standardised request arguments / headers
*
* For Paged based index (take precedence over window based index, if both are specified):
*
* - request args
* pageNo => page number index
* pageSize => size of page
*
* For Window based index (as defined by CMIS):
*
* - request args (take precedence over header values if both are specified)
* skipCount => row number start index
* maxItems => size of page
*
* - header values
* CMIS-skipCount => row number start index
* CMIS-maxItems => size of page
*
* @param args request args
* @param headers request headers
* @return page (if pageNumber driven) or window (if skipCount driven)
*/
public Page createPageOrWindow(Map<String, String> args, Map<String, String> headers)
{
// page number
String strPageNo = args.get("pageNo");
Integer pageNo = null;
if (strPageNo != null)
{
try
{
pageNo = new Integer(strPageNo);
}
catch(NumberFormatException e) {};
}
// page size
String strPageSize = args.get("pageSize");
Integer pageSize = null;
if (strPageSize != null)
{
try
{
pageSize = new Integer(strPageSize);
}
catch(NumberFormatException e) {};
}
// skip count
String strSkipCount = args.get("skipCount");
if (strSkipCount == null)
{
strSkipCount = (headers == null) ? null : headers.get("CMIS-skipCount");
}
Integer skipCount = null;
if (strSkipCount != null)
{
try
{
skipCount = new Integer(strSkipCount);
}
catch(NumberFormatException e) {};
}
// max items
String strMaxItems = args.get("maxItems");
if (strMaxItems == null)
{
strMaxItems = (headers == null) ? null : headers.get("CMIS-maxItems");
}
Integer maxItems = null;
if (strMaxItems != null)
{
try
{
maxItems = new Integer(strMaxItems);
}
catch(NumberFormatException e) {};
}
return createPageOrWindow(pageNo, pageSize, skipCount, maxItems);
}
/**
* Create a Page or Window
@@ -146,13 +232,13 @@ public class Paging
*/
public Page createPageOrWindow(Integer pageNumber, Integer pageSize, Integer skipCount, Integer maxItems)
{
if (pageNumber != null)
if (pageNumber != null || pageSize != null)
{
return createPage(pageNumber, pageSize == null ? 0 : pageSize);
return createPage(pageNumber == null ? isZeroBasedPage() ? 0 : 1 : pageNumber, pageSize == null ? 0 : pageSize);
}
else if (skipCount != null)
else if (skipCount != null || maxItems != null)
{
return createWindow(skipCount, maxItems == null ? 0 : maxItems);
return createWindow(skipCount == null ? isZeroBasedRow() ? 0 : 1 : skipCount, maxItems == null ? 0 : maxItems);
}
return createUnlimitedPage();
}