From 894727b0cdb67aa9594afab02db84daba1f89f0d Mon Sep 17 00:00:00 2001 From: David Caruana Date: Thu, 12 Mar 2009 16:46:46 +0000 Subject: [PATCH] Part 1 of MOB-378 Support for sub-types (and properties). Supported for read cases. Property rendering driven from type model. Fixed support for ID, XML, HTML and URI type properties. Fixed ContentStreamUri property name. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@13607 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../org/alfresco/cmis/atomentry.lib.atom.ftl | 48 ++++--------- .../web-scripts-application-context.xml | 5 ++ .../repo/cmis/rest/CMISTypeIdMethod.java | 2 +- .../repo/cmis/rest/CMISTypeMethod.java | 71 +++++++++++++++++++ 4 files changed, 91 insertions(+), 35 deletions(-) create mode 100644 source/java/org/alfresco/repo/cmis/rest/CMISTypeMethod.java diff --git a/config/alfresco/templates/webscripts/org/alfresco/cmis/atomentry.lib.atom.ftl b/config/alfresco/templates/webscripts/org/alfresco/cmis/atomentry.lib.atom.ftl index 05cd855ee8..e0ee1461d9 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/cmis/atomentry.lib.atom.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/cmis/atomentry.lib.atom.ftl @@ -50,31 +50,13 @@ [#macro documentCMISProps node propfilter] - [@filter propfilter "ObjectId"][@prop "ObjectId" node "ID"/][/@filter] - [#-- TODO: Spec issue - add root type id to meta-model --] + [#-- TODO: Spec issue: BaseType not a property --] [@filter propfilter "BaseType"][@propvalue "BaseType" "document" "STRING"/][/@filter] - [@filter propfilter "ObjectTypeId"][@prop "ObjectTypeId" node "STRING"/][/@filter] - [@filter propfilter "CreatedBy"][@prop "CreatedBy" node "STRING"/][/@filter] - [@filter propfilter "CreationDate"][@prop "CreationDate" node "DATETIME"/][/@filter] - [@filter propfilter "LastModifiedBy"][@prop "LastModifiedBy" node "STRING"/][/@filter] - [@filter propfilter "LastModificationDate"][@prop "LastModificationDate" node "DATETIME"/][/@filter] - [#-- TODO: ChangeToken --] - [@filter propfilter "Name"][@prop "Name" node "STRING"/][/@filter] - [@filter propfilter "IsImmutable"][@prop "IsImmutable" node "BOOLEAN"/][/@filter] - [@filter propfilter "isLatestVersion"][@prop "IsLatestVersion" node "BOOLEAN"/][/@filter] - [@filter propfilter "IsMajorVersion"][@prop "IsMajorVersion" node "BOOLEAN"/][/@filter] - [@filter propfilter "isLatestMajorVersion"][@prop "IsLatestMajorVersion" node "BOOLEAN"/][/@filter] - [@filter propfilter "VersionLabel"][@prop "VersionLabel" node "STRING"/][/@filter] - [@filter propfilter "VersionSeriesId"][@prop "VersionSeriesId" node "ID"/][/@filter] - [@filter propfilter "IsVersionSeriesCheckedOut"][@prop "IsVersionSeriesCheckedOut" node "BOOLEAN"/][/@filter] - [@filter propfilter "VersionSeriesCheckedOutBy"][@prop "VersionSeriesCheckedOutBy" node "STRING"/][/@filter] - [@filter propfilter "VersionSeriesCheckedOutId"][@prop "VersionSeriesCheckedOutId" node "ID"/][/@filter] - [@filter propfilter "CheckinComment"][@prop "CheckinComment" node "STRING"/][/@filter] - [#-- TODO: ContentStreamAllowed --] - [@filter propfilter "ContentStreamLength"][@prop "ContentStreamLength" node "INTEGER"/][/@filter] - [@filter propfilter "ContentStreamMimeType"][@prop "ContentStreamMimeType" node "STRING"/][/@filter] - [@filter propfilter "ContentStreamFilename"][@prop "ContentStreamFilename" node "STRING"/][/@filter] - [@filter propfilter "ContentStreamURI"][@propvalue "ContentStreamURI" absurl(url.serviceContext) + "/api/node/" + node.nodeRef.storeRef.protocol + "/" + node.nodeRef.storeRef.identifier + "/" + node.nodeRef.id + "/content." + node.properties.name "STRING"/][/@filter] + + [#assign typedef = cmistype(node)] + [#list typedef.propertyDefinitions?values as propdef] + [@filter propfilter propdef.propertyName][@prop propdef.propertyName node propdef.propertyType/][/@filter] + [/#list] [/#macro] @@ -185,16 +167,13 @@ [#macro folderCMISProps node propfilter] - [@filter propfilter "ObjectId"][@prop "ObjectId" node "ID"/][/@filter] - [#-- TODO: Spec issue - add root type id to meta-model --] + [#-- TODO: Spec issue: BaseType not a property --] [@filter propfilter "BaseType"][@propvalue "BaseType" "folder" "STRING"/][/@filter] - [@filter propfilter "ObjectTypeId"][@prop "ObjectTypeId" node "STRING"/][/@filter] - [@filter propfilter "CreatedBy"][@prop "CreatedBy" node "STRING"/][/@filter] - [@filter propfilter "CreationDate"][@prop "CreationDate" node "DATETIME"/][/@filter] - [@filter propfilter "LastModifiedBy"][@prop "LastModifiedBy" node "STRING"/][/@filter] - [@filter propfilter "LastModificationDate"][@prop "LastModificationDate" node "DATETIME"/][/@filter] - [@filter propfilter "Name"][@prop "Name" node "STRING"/][/@filter] - [@filter propfilter "ParentId"][@prop "ParentId" node "ID"/][/@filter] + + [#assign typedef = cmistype(node)] + [#list typedef.propertyDefinitions?values as propdef] + [@filter propfilter propdef.propertyName][@prop propdef.propertyName node propdef.propertyType/][/@filter] + [/#list] [/#macro] @@ -279,7 +258,8 @@ [#elseif type == "DATETIME"] [@datetimevalue value/] [#elseif type == "URI"] -[@urivalue value/] +[#-- TODO: check validity of abs url prefix --] +[@urivalue absurl(url.serviceContext) + value/] [#elseif type == "ID"] [@idvalue value/] [#-- TODO: remaining property types --] diff --git a/config/alfresco/web-scripts-application-context.xml b/config/alfresco/web-scripts-application-context.xml index d7b118d31e..41dc9cb941 100644 --- a/config/alfresco/web-scripts-application-context.xml +++ b/config/alfresco/web-scripts-application-context.xml @@ -107,6 +107,11 @@ + + + + + diff --git a/source/java/org/alfresco/repo/cmis/rest/CMISTypeIdMethod.java b/source/java/org/alfresco/repo/cmis/rest/CMISTypeIdMethod.java index 39ef522bec..a82a992320 100644 --- a/source/java/org/alfresco/repo/cmis/rest/CMISTypeIdMethod.java +++ b/source/java/org/alfresco/repo/cmis/rest/CMISTypeIdMethod.java @@ -45,7 +45,7 @@ import freemarker.template.TemplateModelException; * * @author davidc */ -public final class CMISTypeIdMethod implements TemplateMethodModelEx +public class CMISTypeIdMethod implements TemplateMethodModelEx { private CMISMapping mappingService; diff --git a/source/java/org/alfresco/repo/cmis/rest/CMISTypeMethod.java b/source/java/org/alfresco/repo/cmis/rest/CMISTypeMethod.java new file mode 100644 index 0000000000..bb1b621f4b --- /dev/null +++ b/source/java/org/alfresco/repo/cmis/rest/CMISTypeMethod.java @@ -0,0 +1,71 @@ +/* + * 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.CMISDictionaryService; +import org.alfresco.cmis.dictionary.CMISTypeId; + +import freemarker.template.TemplateModelException; + +/** + * Custom FreeMarker Template language method. + *

+ * Retrieve the CMIS Type for an Alfresco node + *

+ * Usage: cmistype(TemplateNode node) + * cmistype(QName nodeType) + * + * @author davidc + */ +public class CMISTypeMethod extends CMISTypeIdMethod +{ + private CMISDictionaryService dictionaryService; + + /** + * Construct + */ + public CMISTypeMethod(CMISDictionaryService dictionaryService) + { + super(dictionaryService.getCMISMapping()); + this.dictionaryService = dictionaryService; + } + + /** + * @see freemarker.template.TemplateMethodModel#exec(java.util.List) + */ + @SuppressWarnings("unchecked") + public Object exec(List args) throws TemplateModelException + { + Object result = null; + Object typeId = super.exec(args); + if (typeId != null) + { + result = dictionaryService.getType((CMISTypeId)typeId); + } + return result; + } +}