diff --git a/config/alfresco/cmis-ws-context.xml b/config/alfresco/cmis-ws-context.xml index ffc416d965..19435d3d8d 100644 --- a/config/alfresco/cmis-ws-context.xml +++ b/config/alfresco/cmis-ws-context.xml @@ -291,7 +291,7 @@ - + diff --git a/config/alfresco/templates/webscripts/org/alfresco/cmis/lib/atomentry.lib.atom.ftl b/config/alfresco/templates/webscripts/org/alfresco/cmis/lib/atomentry.lib.atom.ftl index b022debdaf..3767b19245 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/cmis/lib/atomentry.lib.atom.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/cmis/lib/atomentry.lib.atom.ftl @@ -73,6 +73,7 @@ [#macro documentCMISLinks node renditionfilter="cmis:none"] [@linksLib.linkallowableactions node/] [@linksLib.linkrelationships node/] +[@linksLib.linkpolicies node/] [@linksLib.linkacl node/] [@linksLib.linkparents node/] [@linksLib.linkversions node/] @@ -149,6 +150,7 @@ [#macro folderCMISLinks node] [@linksLib.linkallowableactions node/] [@linksLib.linkrelationships node/] +[@linksLib.linkpolicies node/] [@linksLib.linkacl node/] [#if cmisproperty(node, cmisconstants.PROP_PARENT_ID)?is_string] [@linksLib.linkparent node/] diff --git a/config/alfresco/templates/webscripts/org/alfresco/cmis/lib/links.lib.atom.ftl b/config/alfresco/templates/webscripts/org/alfresco/cmis/lib/links.lib.atom.ftl index 083753525b..b18902ffc4 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/cmis/lib/links.lib.atom.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/cmis/lib/links.lib.atom.ftl @@ -24,6 +24,11 @@ [/#macro] +[#-- Link to node policies --] +[#macro linkpolicies node] + +[/#macro] + [#-- Link to node acl --] [#macro linkacl node] diff --git a/config/alfresco/templates/webscripts/org/alfresco/cmis/lib/modify.lib.js b/config/alfresco/templates/webscripts/org/alfresco/cmis/lib/modify.lib.js index 5bf94d84c5..a873bb8c39 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/cmis/lib/modify.lib.js +++ b/config/alfresco/templates/webscripts/org/alfresco/cmis/lib/modify.lib.js @@ -38,6 +38,10 @@ function createNode(parent, entry, slug, versioningState) { node = parent.createFolder(name); } + else if (baseType == POLICY_TYPE_ID) + { + node = cmis.createPolicy(typeId, parent); + } else { status.code = 400; @@ -314,6 +318,20 @@ function createAssociation(source, entry) return assoc; } +// +//Apply Policy from Atom Entry +// +//@param target target node +//@param entry atom entry +//@return created policy (or null, in case of error) +// +function applyPolicy(target, entry) +{ + var object = entry.getExtension(atom.names.cmisra_object); + cmis.applyPolicy(object.objectId, target); + return null; +} + // callback for validating property update for patch // return null => update not allowed, abort update diff --git a/config/alfresco/templates/webscripts/org/alfresco/cmis/policies.get.atomfeed.ftl b/config/alfresco/templates/webscripts/org/alfresco/cmis/policies.get.atomfeed.ftl new file mode 100644 index 0000000000..30e4d394d8 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/cmis/policies.get.atomfeed.ftl @@ -0,0 +1,24 @@ +[#ftl] +[#import "/org/alfresco/cmis/lib/ns.lib.atom.ftl" as nsLib/] +[#import "/org/alfresco/cmis/lib/links.lib.atom.ftl" as linksLib/] +[#import "/org/alfresco/cmis/lib/atomfeed.lib.atom.ftl" as feedLib/] +[#import "/org/alfresco/cmis/lib/atomentry.lib.atom.ftl" as entryLib/] +[#import "/org/alfresco/paging.lib.atom.ftl" as pagingLib/] +[#compress] + + + + +[@feedLib.node node "policies"] + [@linksLib.linkservice/] + [@linksLib.linkself/] + [#assign nodeuri][@linksLib.nodeuri node/][/#assign] + [@linksLib.linkvia href="${nodeuri}"/] + [@pagingLib.links cursor/] +[/@feedLib.node] +[@pagingLib.opensearch cursor/] +[@pagingLib.cmis cursor/] + + + +[/#compress] \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/cmis/policies.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/cmis/policies.get.desc.xml new file mode 100644 index 0000000000..bc7372aa31 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/cmis/policies.get.desc.xml @@ -0,0 +1,19 @@ + + Retrieve list of applied policies (getAppliedPolicies) + + + + + /cmis/i/{id}/pols?filter={filter?}&skipCount={skipCount?}&maxItems={maxItems?} + /cmis/s/{store}/i/{id}/pols?filter={filter?}&skipCount={skipCount?}&maxItems={maxItems?} + + /cmis/p{path}/pols?filter={filter?}&skipCount={skipCount?}&maxItems={maxItems?} + /cmis/s/{store}/p{path}/pols?filter={filter?}&skipCount={skipCount?}&maxItems={maxItems?} + + + /api/node/{store_type}/{store_id}/{id}/pols?filter={filter?}&skipCount={skipCount?}&maxItems={maxItems?} + /api/path/{store_type}/{store_id}/{id}/pols?filter={filter?}&skipCount={skipCount?}&maxItems={maxItems?} + guest + argument + CMIS + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/cmis/policies.get.js b/config/alfresco/templates/webscripts/org/alfresco/cmis/policies.get.js new file mode 100644 index 0000000000..11b3617cf2 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/cmis/policies.get.js @@ -0,0 +1,26 @@ + + + +script: +{ + // locate node + var object = getObjectFromUrl(); + if (object.node == null) + { + break script; + } + model.node = object.node; + + // property filter + var filter = args[cmis.ARG_FILTER]; + if (filter === null) + { + filter = "*"; + } + + // retrieve policies + var page = paging.createPageOrWindow(args); + var paged = cmis.getAppliedPolicies(model.node, filter, page); + model.results = paged.results; + model.cursor = paged.cursor; +} diff --git a/config/alfresco/templates/webscripts/org/alfresco/cmis/policies.post.atom.js b/config/alfresco/templates/webscripts/org/alfresco/cmis/policies.post.atom.js new file mode 100644 index 0000000000..d1865cfbbd --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/cmis/policies.post.atom.js @@ -0,0 +1,38 @@ + + + + +script: +{ + // ensure atom entry is posted + if (entry === null) + { + status.code = 400; + status.message = "Expected atom entry"; + status.redirect = true; + break script; + } + + // locate source node + var object = getObjectFromUrl(); + if (object.node == null) + { + break script; + } + model.target = object.node; + + // create + var policy = applyPolicy(model.target, entry); + if (policy == null) + { + break script; + } + + // success + model.policy = policy; + + // TODO: set Content-Location + status.code = 201; + status.location = url.server + url.serviceContext + "/cmis/pol/" + policy.id; + status.redirect = true; +} diff --git a/config/alfresco/templates/webscripts/org/alfresco/cmis/policies.post.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/cmis/policies.post.desc.xml new file mode 100644 index 0000000000..168b1c15c2 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/cmis/policies.post.desc.xml @@ -0,0 +1,20 @@ + + Create policy (createPolicy) + + + + + /cmis/i/{id}/pols + /cmis/s/{store}/i/{id}/pols + + /cmis/p{path}/pols + /cmis/s/{store}/p{path}/pols + + + /api/node/{store_type}/{store_id}/{id}/pols + /api/path/{store_type}/{store_id}/{id}/pols + + guest + argument + CMIS + \ No newline at end of file diff --git a/source/java/org/alfresco/repo/cmis/PropertyFilter.java b/source/java/org/alfresco/repo/cmis/PropertyFilter.java deleted file mode 100644 index 00743d2016..0000000000 --- a/source/java/org/alfresco/repo/cmis/PropertyFilter.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (C) 2005-2010 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - */ -package org.alfresco.repo.cmis; - -import java.util.HashSet; -import java.util.Set; -import java.util.regex.Pattern; - -import org.alfresco.repo.cmis.ws.CmisException; -import org.alfresco.repo.cmis.ws.EnumServiceException; -import org.alfresco.repo.cmis.ws.utils.ExceptionUtil; - -/** - * Property filter supporting CMIS filter expression - * - * @author Dmitry Lazurkin - * @author Dmitry Velichkevich - */ -public class PropertyFilter -{ - public static final String MATCH_ALL_FILTER = "*"; - public static final String PROPERTY_NAME_TOKENS_DELIMETER = ","; - - private static final int MINIMAL_ALLOWED_STRUCTURE_SIZE = 1; - private static final Pattern PROPERTY_FILTER_REGEX = Pattern.compile("^(\\*)|(((cmis\\:)?[\\p{Alpha}\\p{Digit}_]+)((,){1}( )*((cmis\\:)?[\\p{Alpha}\\p{Digit}_]+))*)$"); - - private Set properties; - - public PropertyFilter() - { - } - - /** - * @param filter filter value (case insensitive) - * @throws FilterNotValidException if filter string isn't valid - */ - public PropertyFilter(String filter) throws CmisException - { - if (filter == null || filter.length() < MINIMAL_ALLOWED_STRUCTURE_SIZE ? false : !PROPERTY_FILTER_REGEX.matcher(filter).matches()) - { - throw ExceptionUtil.createCmisException(("\"" + filter + "\" filter value is invalid"), EnumServiceException.FILTER_NOT_VALID); - } - - if (!filter.equals(MATCH_ALL_FILTER) && filter.length() >= MINIMAL_ALLOWED_STRUCTURE_SIZE) - { - splitFilterOnTokens(filter.split(PROPERTY_NAME_TOKENS_DELIMETER)); - } - } - - private void splitFilterOnTokens(String[] tokens) - { - properties = new HashSet(); - for (String token : tokens) - { - properties.add(token.trim().toLowerCase()); - } - } - - /** - * @param property property token name (e.g.: name (or Name), ObjectId (or: objectid, Objectid etc)) - * @return true returns if property is allowed by filter. In other case returns false - */ - public boolean allow(String property) - { - return properties == null || properties.contains(property.toLowerCase()); - } -} \ No newline at end of file diff --git a/source/java/org/alfresco/repo/cmis/PropertyFilterTest.java b/source/java/org/alfresco/repo/cmis/PropertyFilterTest.java deleted file mode 100644 index fb11062b60..0000000000 --- a/source/java/org/alfresco/repo/cmis/PropertyFilterTest.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (C) 2005-2010 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - */ -package org.alfresco.repo.cmis; - -import junit.framework.TestCase; - -import org.alfresco.repo.cmis.ws.CmisException; -import org.alfresco.repo.cmis.ws.EnumServiceException; - -/** - * @author Dmitry Velichkevich - */ -public class PropertyFilterTest extends TestCase -{ - private static final String NAME_TOKEN = "name"; - - private static final String[] FILTER_TOKENS = new String[] { "Name", NAME_TOKEN, "nAmE", "ObjectId", "ObjectID", "objectId" }; - private static final String[] TOKENS_THAT_ARE_NOT_ALLOWED = new String[] { "ParentId", "parentId", "ParEnTiD", "IsMajorVersion", "iSmAJORvERSION" }; - - private static final String VALID_MATCHE_ALL_FILTER = "*"; - private static final String VALID_MATCHE_ALL_EMPTY_FILTER = ""; - private static final String VALID_FILTER_WITH_NAME = NAME_TOKEN; - private static final String VALID_FILTER_WITH_SEVERAL_TOKENS = "name, ObjectId"; - private static final String LONG_VALID_FILTER_WITH_SEVERAL_TOKENS = "ObjectId, name, CreationDate, CreatedBy"; - private static final String VALID_FILTER_WITH_SEVERAL_TOKENS_WITHOUT_BREAKS = "name,Objectid,CreationDate"; - private static final String VALID_FILTER_WITH_SEVERAL_TOKENS_AND_WITH_BREAKS_IN_SOME_PLACES = "name, Objectid,CreationDate,CreatedBy, ModifiedBy, LastModifiedBy"; - private static final String VALID_FILTER_WITH_SEVERAL_TOKENS_AND_WITH_SEVERAL_BREAKS_IN_SOME_PLACES = "name, Objectid, CreationDate,CreatedBy, ModifiedBy, LastModifiedBy"; - - private static final String INVALID_MATCHE_ALL_FILTER = "*,"; - private static final String INVALID_FILTER_WITH_NAME = "*name,"; - private static final String INVALID_FILTER_WITH_SEVERAL_TOKENS = "name ,ObjectId"; - private static final String LONG_INVALID_FILTER_WITH_SEVERAL_TOKENS = "ObjectId, name CreationDate, CreatedBy*"; - private static final String INVALID_FILTER_WITH_SEVERAL_TOKENS_WITHOUT_BREAKS = ",name,Objectid,CreationDate"; - private static final String INVALID_FILTER_WITH_SEVERAL_TOKENS_AND_WITH_BREAKS_IN_SOME_PLACES = " name, Objectid,CreationDate CreatedBy ModifiedBy, LastModifiedBy"; - private static final String INVALID_FILTER_WITH_FIRST_BREAK_SYMBOL = " name, Objectid,CreationDate, CreatedBy, ModifiedBy, LastModifiedBy"; - private static final String INVALID_FILTER_WITH_DENIED_SYMBOL = "ObjectId; name"; - private static final String INVALID_FILTER_WITH_LAST_INVALID_SYMBOL = "ObjectId, name*"; - - public void testValidFilters() throws Exception - { - try - { - allTokensValidAssertion(new PropertyFilter()); - allTokensValidAssertion(new PropertyFilter(VALID_MATCHE_ALL_EMPTY_FILTER)); - allTokensValidAssertion(new PropertyFilter(VALID_MATCHE_ALL_FILTER)); - - onlyNameTokensAssertionValid(new PropertyFilter(VALID_FILTER_WITH_NAME)); - - nameAndObjectIdTokensAssertionValid(new PropertyFilter(VALID_FILTER_WITH_SEVERAL_TOKENS)); - nameAndObjectIdTokensAssertionValid(new PropertyFilter(LONG_VALID_FILTER_WITH_SEVERAL_TOKENS)); - nameAndObjectIdTokensAssertionValid(new PropertyFilter(VALID_FILTER_WITH_SEVERAL_TOKENS_WITHOUT_BREAKS)); - nameAndObjectIdTokensAssertionValid(new PropertyFilter(VALID_FILTER_WITH_SEVERAL_TOKENS_AND_WITH_BREAKS_IN_SOME_PLACES)); - nameAndObjectIdTokensAssertionValid(new PropertyFilter(VALID_FILTER_WITH_SEVERAL_TOKENS_AND_WITH_SEVERAL_BREAKS_IN_SOME_PLACES)); - } - catch (Throwable e) - { - fail(e.getMessage()); - } - } - - public void testInvalidFilters() throws Exception - { - invalidFilterAssertion(INVALID_MATCHE_ALL_FILTER); - invalidFilterAssertion(INVALID_FILTER_WITH_NAME); - invalidFilterAssertion(INVALID_FILTER_WITH_SEVERAL_TOKENS); - invalidFilterAssertion(LONG_INVALID_FILTER_WITH_SEVERAL_TOKENS); - invalidFilterAssertion(INVALID_FILTER_WITH_SEVERAL_TOKENS_WITHOUT_BREAKS); - invalidFilterAssertion(INVALID_FILTER_WITH_SEVERAL_TOKENS_AND_WITH_BREAKS_IN_SOME_PLACES); - invalidFilterAssertion(INVALID_FILTER_WITH_FIRST_BREAK_SYMBOL); - invalidFilterAssertion(INVALID_FILTER_WITH_DENIED_SYMBOL); - invalidFilterAssertion(INVALID_FILTER_WITH_LAST_INVALID_SYMBOL); - } - - private void nameAndObjectIdTokensAssertionValid(PropertyFilter propertyFilter) - { - for (String token : FILTER_TOKENS) - { - assertTrue(propertyFilter.allow(token)); - } - - for (String token : TOKENS_THAT_ARE_NOT_ALLOWED) - { - assertFalse(propertyFilter.allow(token)); - } - } - - private void onlyNameTokensAssertionValid(PropertyFilter propertyFilter) - { - for (String token : FILTER_TOKENS) - { - if (!token.equalsIgnoreCase(NAME_TOKEN)) - { - break; - } - - assertTrue(propertyFilter.allow(token)); - } - - for (String token : TOKENS_THAT_ARE_NOT_ALLOWED) - { - assertFalse(propertyFilter.allow(token)); - } - } - - private void allTokensValidAssertion(PropertyFilter propertyFilter) - { - for (String token : FILTER_TOKENS) - { - assertTrue(propertyFilter.allow(token)); - } - - for (String token : TOKENS_THAT_ARE_NOT_ALLOWED) - { - assertTrue(propertyFilter.allow(token)); - } - } - - private void invalidFilterAssertion(String filterValue) - { - try - { - new PropertyFilter(filterValue); - - fail("Invalid filter \"" + filterValue + "\" was interpreted as valid"); - } - catch (CmisException e) - { - assertEquals(("Unexpected exception type was thrown: " + e.getClass().getName()), EnumServiceException.FILTER_NOT_VALID, e.getFaultInfo().getType()); - } - } - -} diff --git a/source/java/org/alfresco/repo/cmis/rest/CMISScript.java b/source/java/org/alfresco/repo/cmis/rest/CMISScript.java index 98a9e7ccbf..85c8574439 100644 --- a/source/java/org/alfresco/repo/cmis/rest/CMISScript.java +++ b/source/java/org/alfresco/repo/cmis/rest/CMISScript.java @@ -21,6 +21,7 @@ package org.alfresco.repo.cmis.rest; import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -1166,4 +1167,106 @@ public class CMISScript extends BaseScopableProcessorExtension throw new WebScriptException(e.getStatusCode(), e.getMessage(), e); } } + + /** + * Creates a policy object of the specified type, and optionally adds the policy to a folder. Currently no policy + * types can be created in Alfresco. + * + * @param typeId + * the policy type + * @param parent + * parent folder for this new policy + * @return the created policy object + * @throws WebScriptException on error + */ + public ScriptNode createPolicy(String typeId, ScriptNode parent) + { + try + { + cmisService.createPolicy(Collections. singletonMap( + CMISDictionaryModel.PROP_OBJECT_TYPE_ID, typeId), (String) cmisService.getProperty(parent + .getNodeRef(), CMISDictionaryModel.PROP_OBJECT_ID), Collections. emptyList()); + return null; + } + catch (CMISServiceException e) + { + throw new WebScriptException(e.getStatusCode(), e.getMessage(), e); + } + } + + /** + * Applies a policy object to a target object. + * + * @param policyId + * policy Id + * @param target + * target node + * @throws WebScriptException on error + */ + public void applyPolicy(String policyId, ScriptNode target) + { + try + { + cmisService.applyPolicy(policyId, (String) cmisService.getProperty(target.getNodeRef(), + CMISDictionaryModel.PROP_OBJECT_ID)); + } + catch (CMISServiceException e) + { + throw new WebScriptException(e.getStatusCode(), e.getMessage(), e); + } + } + + /** + * Gets the list of policy objects currently applied to a target object. + * + * @param objectId + * the object id + * @param filter + * property filter + * @throws WebScriptException on error + */ + public PagedResults getAppliedPolicies(String objectId, String filter, Page page) + { + List policies; + try + { + policies = cmisService.getAppliedPolicies(objectId, filter); + } + catch (CMISServiceException e) + { + throw new WebScriptException(e.getStatusCode(), e.getMessage(), e); + } + Cursor cursor = paging.createCursor(policies.size(), page); + Object[] policyArr = new Object[cursor.getRowCount()]; + for (int i = cursor.getStartRow(); i <= cursor.getEndRow(); i++) + { + policyArr[i - cursor.getStartRow()] = Context.javaToJS(policies.get(i), getScope()); + } + + PagedResults results = paging.createPagedResults(policyArr, cursor); + return results; + } + + /** + * Removes a previously applied policy from a target object. The policy object is not deleted, and may still be + * applied to other objects. + * + * @param policyId + * policy Id + * @param objectId + * target object Id. + * @throws WebScriptException + * on error + */ + public void removePolicy(String policyId, String objectId) + { + try + { + cmisService.removePolicy(policyId, objectId); + } + catch (CMISServiceException e) + { + throw new WebScriptException(e.getStatusCode(), e.getMessage(), e); + } + } } diff --git a/source/java/org/alfresco/repo/cmis/ws/DMAbstractServicePort.java b/source/java/org/alfresco/repo/cmis/ws/DMAbstractServicePort.java index 6efb5543ed..6231ba3b91 100644 --- a/source/java/org/alfresco/repo/cmis/ws/DMAbstractServicePort.java +++ b/source/java/org/alfresco/repo/cmis/ws/DMAbstractServicePort.java @@ -40,18 +40,19 @@ import org.alfresco.cmis.CMISAclPropagationEnum; import org.alfresco.cmis.CMISActionEvaluator; import org.alfresco.cmis.CMISAllowedActionEnum; import org.alfresco.cmis.CMISChangeLogService; -import org.alfresco.cmis.CMISConstraintException; +import org.alfresco.cmis.CMISDictionaryModel; import org.alfresco.cmis.CMISFilterNotValidException; import org.alfresco.cmis.CMISInvalidArgumentException; import org.alfresco.cmis.CMISQueryService; import org.alfresco.cmis.CMISRelationshipDirectionEnum; import org.alfresco.cmis.CMISRendition; import org.alfresco.cmis.CMISRenditionService; +import org.alfresco.cmis.CMISServiceException; import org.alfresco.cmis.CMISServices; import org.alfresco.cmis.CMISTypeDefinition; +import org.alfresco.cmis.PropertyFilter; import org.alfresco.cmis.acl.CMISAccessControlEntryImpl; import org.alfresco.error.AlfrescoRuntimeException; -import org.alfresco.repo.cmis.PropertyFilter; import org.alfresco.repo.cmis.ws.utils.ExceptionUtil; import org.alfresco.repo.cmis.ws.utils.PropertyUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil; @@ -188,7 +189,14 @@ public class DMAbstractServicePort protected PropertyFilter createPropertyFilter(String filter) throws CmisException { - return (filter == null) ? (new PropertyFilter()) : (new PropertyFilter(filter)); + try + { + return new PropertyFilter(filter); + } + catch (CMISFilterNotValidException e) + { + throw ExceptionUtil.createCmisException(e); + } } protected PropertyFilter createPropertyFilter(JAXBElement element) throws CmisException @@ -383,7 +391,26 @@ public class DMAbstractServicePort object.setExactACL(aclReport.isExact()); } - protected CmisACLType applyAclCarefully(NodeRef object, CmisAccessControlListType addACEs, CmisAccessControlListType removeACEs, EnumACLPropagation aclPropagation) + protected void applyPolicies(String objectId, List policies) throws CmisException + { + // Process any provided policy IDs (they will be rejected!) + if (policies != null) + { + for (String policyId : policies) + { + try + { + cmisService.applyPolicy(policyId, objectId); + } + catch (CMISServiceException e) + { + throw ExceptionUtil.createCmisException(e); + } + } + } + } + + protected CmisACLType applyAclCarefully(NodeRef object, CmisAccessControlListType addACEs, CmisAccessControlListType removeACEs, EnumACLPropagation aclPropagation, List policies) throws CmisException { if (addACEs == null && removeACEs == null) @@ -397,10 +424,17 @@ public class DMAbstractServicePort List acesToRemove = (null == removeACEs) ? (null) : (convertToAlfrescoAceEntriesList(removeACEs.getPermission())); CMISAccessControlReport aclReport = null; aclReport = cmisAclService.applyAcl(object, acesToRemove, acesToAdd, propagation, CMISAccessControlFormatEnum.REPOSITORY_SPECIFIC_PERMISSIONS); + + // Process any provided policy IDs (they will be rejected!) + if (policies != null) + { + String objectId = (String) cmisService.getProperty(object, CMISDictionaryModel.PROP_OBJECT_ID); + applyPolicies(objectId, policies); + } CmisACLType result = convertAclReportToCmisAclType(aclReport); return result; } - catch (CMISConstraintException e) + catch (CMISServiceException e) { throw ExceptionUtil.createCmisException(e); } diff --git a/source/java/org/alfresco/repo/cmis/ws/DMAclServicePort.java b/source/java/org/alfresco/repo/cmis/ws/DMAclServicePort.java index 984f278a74..9e70f7f26d 100644 --- a/source/java/org/alfresco/repo/cmis/ws/DMAclServicePort.java +++ b/source/java/org/alfresco/repo/cmis/ws/DMAclServicePort.java @@ -46,7 +46,7 @@ public class DMAclServicePort extends DMAbstractServicePort implements ACLServic { throw ExceptionUtil.createCmisException(e); } - return applyAclCarefully(object, addACEs, removeACEs, aclPropagation); + return applyAclCarefully(object, addACEs, removeACEs, aclPropagation, null); } /** diff --git a/source/java/org/alfresco/repo/cmis/ws/DMDiscoveryServicePort.java b/source/java/org/alfresco/repo/cmis/ws/DMDiscoveryServicePort.java index 4046434f57..7f70d08d71 100644 --- a/source/java/org/alfresco/repo/cmis/ws/DMDiscoveryServicePort.java +++ b/source/java/org/alfresco/repo/cmis/ws/DMDiscoveryServicePort.java @@ -37,7 +37,7 @@ import org.alfresco.cmis.CMISResultSet; import org.alfresco.cmis.CMISResultSetColumn; import org.alfresco.cmis.CMISResultSetRow; import org.alfresco.cmis.CMISServiceException; -import org.alfresco.repo.cmis.PropertyFilter; +import org.alfresco.cmis.PropertyFilter; import org.alfresco.repo.cmis.ws.utils.ExceptionUtil; import org.alfresco.service.cmr.repository.NodeRef; @@ -171,7 +171,7 @@ public class DMDiscoveryServicePort extends DMAbstractServicePort implements Dis { if ((null != filter) && !"".equals(filter) && !PropertyFilter.MATCH_ALL_FILTER.equals(filter) && !filter.contains(CMISDictionaryModel.PROP_OBJECT_ID)) { - filter = CMISDictionaryModel.PROP_OBJECT_ID + PropertyFilter.PROPERTY_NAME_TOKENS_DELIMETER + filter; + filter = CMISDictionaryModel.PROP_OBJECT_ID + PropertyFilter.PROPERTY_NAME_TOKENS_DELIMITER + filter; } } else diff --git a/source/java/org/alfresco/repo/cmis/ws/DMNavigationServicePort.java b/source/java/org/alfresco/repo/cmis/ws/DMNavigationServicePort.java index 626e238c2e..2790923212 100644 --- a/source/java/org/alfresco/repo/cmis/ws/DMNavigationServicePort.java +++ b/source/java/org/alfresco/repo/cmis/ws/DMNavigationServicePort.java @@ -27,7 +27,7 @@ import java.util.Stack; import org.alfresco.cmis.CMISDictionaryModel; import org.alfresco.cmis.CMISServiceException; import org.alfresco.cmis.CMISTypesFilterEnum; -import org.alfresco.repo.cmis.PropertyFilter; +import org.alfresco.cmis.PropertyFilter; import org.alfresco.repo.cmis.ws.utils.ExceptionUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.web.util.paging.Cursor; diff --git a/source/java/org/alfresco/repo/cmis/ws/DMObjectServicePort.java b/source/java/org/alfresco/repo/cmis/ws/DMObjectServicePort.java index c748b9c38c..2d4d857485 100644 --- a/source/java/org/alfresco/repo/cmis/ws/DMObjectServicePort.java +++ b/source/java/org/alfresco/repo/cmis/ws/DMObjectServicePort.java @@ -20,6 +20,7 @@ package org.alfresco.repo.cmis.ws; import java.io.IOException; import java.io.InputStream; +import java.io.Serializable; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; @@ -37,10 +38,9 @@ import org.alfresco.cmis.CMISInvalidArgumentException; import org.alfresco.cmis.CMISRenditionKind; import org.alfresco.cmis.CMISScope; import org.alfresco.cmis.CMISServiceException; -import org.alfresco.cmis.CMISServices; import org.alfresco.cmis.CMISTypeDefinition; import org.alfresco.cmis.CMISVersioningStateEnum; -import org.alfresco.repo.cmis.PropertyFilter; +import org.alfresco.cmis.PropertyFilter; import org.alfresco.repo.cmis.ws.DeleteTreeResponse.FailedToDelete; import org.alfresco.repo.cmis.ws.utils.ExceptionUtil; import org.alfresco.repo.web.util.paging.Cursor; @@ -105,7 +105,7 @@ public class DMObjectServicePort extends DMAbstractServicePort implements Object try { NodeRef parentNodeRef = cmisService.getFolder(folderId); - Map propertiesMap = propertiesUtil.getPropertiesMap(properties); + Map propertiesMap = propertiesUtil.getPropertiesMap(properties); String typeId = extractAndAssertTypeId(propertiesMap); CMISTypeDefinition typeDef = cmisService.getTypeDefinition(typeId); String documentName = checkConstraintsAndGetName(typeId, typeDef, parentNodeRef, contentStream, propertiesMap, versioningState); @@ -209,13 +209,11 @@ public class DMObjectServicePort extends DMAbstractServicePort implements Object public void createFolder(String repositoryId, CmisPropertiesType properties, String folderId, List policies, CmisAccessControlListType addACEs, CmisAccessControlListType removeACEs, Holder extension, Holder objectId) throws CmisException { - // TODO: process Policies - checkRepositoryId(repositoryId); try { NodeRef folderNodeRef = cmisService.getFolder(folderId); - Map propertiesMap = propertiesUtil.getPropertiesMap(properties); + Map propertiesMap = propertiesUtil.getPropertiesMap(properties); String typeId = extractAndAssertTypeId(propertiesMap); CMISTypeDefinition type = cmisService.getTypeDefinition(typeId); if (type == null || type.getTypeId() == null || type.getTypeId().getScope() != CMISScope.FOLDER) @@ -234,7 +232,7 @@ public class DMObjectServicePort extends DMAbstractServicePort implements Object NodeRef newFolderNodeRef = fileFolderService.create(folderNodeRef, name, type.getTypeId().getQName()).getNodeRef(); propertiesUtil.setProperties(newFolderNodeRef, properties, createPropertyFilter(createIgnoringFilter(new String[] { CMISDictionaryModel.PROP_NAME, CMISDictionaryModel.PROP_OBJECT_TYPE_ID }))); - applyAclCarefully(newFolderNodeRef, addACEs, removeACEs, EnumACLPropagation.PROPAGATE); + applyAclCarefully(newFolderNodeRef, addACEs, removeACEs, EnumACLPropagation.PROPAGATE, policies); objectId.value = propertiesUtil.getProperty(newFolderNodeRef, CMISDictionaryModel.PROP_OBJECT_ID, null); } catch (FileExistsException e) @@ -260,7 +258,15 @@ public class DMObjectServicePort extends DMAbstractServicePort implements Object public void createPolicy(String repositoryId, CmisPropertiesType properties, String folderId, List policies, CmisAccessControlListType addACEs, CmisAccessControlListType removeACEs, Holder extension, Holder objectId) throws CmisException { - throw ExceptionUtil.createCmisException("Policy objects not supported", EnumServiceException.NOT_SUPPORTED); + checkRepositoryId(repositoryId); + try + { + objectId.value = cmisService.createPolicy(propertiesUtil.getPropertiesMap(properties), folderId, policies); + } + catch (CMISServiceException e) + { + throw ExceptionUtil.createCmisException(e); + } } /** @@ -279,7 +285,7 @@ public class DMObjectServicePort extends DMAbstractServicePort implements Object { // TODO: process Policies - Map propertiesMap = propertiesUtil.getPropertiesMap(properties); + Map propertiesMap = propertiesUtil.getPropertiesMap(properties); String sourceObjectId = (String) propertiesMap.get(CMISDictionaryModel.PROP_SOURCE_ID); String targetObjectId = (String) propertiesMap.get(CMISDictionaryModel.PROP_TARGET_ID); @@ -322,8 +328,20 @@ public class DMObjectServicePort extends DMAbstractServicePort implements Object { throw ExceptionUtil.createCmisException("Target object type isn't allowed as target type", EnumServiceException.CONSTRAINT); } + + // Check ACL arguments + if (addACEs != null && !addACEs.getPermission().isEmpty() || removeACEs != null && !removeACEs.getPermission().isEmpty()) + { + throw ExceptionUtil.createCmisException("ACLs are not supported for type: " + relationshipType.getDisplayName(), EnumServiceException.CONSTRAINT); + } + AssociationRef assocRef = nodeService.createAssociation(sourceNodeRef, targetNodeRef, relationshipTypeQName); - objectId.value = CMISServices.ASSOC_ID_PREFIX + assocRef.getId(); + String createdId = (String) cmisService.getProperty(assocRef, CMISDictionaryModel.PROP_OBJECT_ID); + + // Try applying policies + applyPolicies(createdId, policies); + + objectId.value = createdId; } else { @@ -435,9 +453,6 @@ public class DMObjectServicePort extends DMAbstractServicePort implements Object CmisObjectType cmisObject = createCmisObject(object, propertyFilter, includeRelationships, includeAllowableActions, renditionFilter); - // TODO: process relationships - // TODO: process policyIds - Object versionSeries = cmisService.getVersionSeries(objectId, Object.class, false); boolean includeAcl = (null != includeACL) ? (includeACL.booleanValue()) : (false); if (includeAcl && (versionSeries instanceof NodeRef)) @@ -727,12 +742,10 @@ public class DMObjectServicePort extends DMAbstractServicePort implements Object CmisAccessControlListType addACEs, CmisAccessControlListType removeACEs, Holder objectId, PropertyFilter propertyFilter) throws CMISConstraintException, CmisException, CMISInvalidArgumentException { - // TODO: process Policies - propertiesUtil.setProperties(targetDocumentNodeRef, properties, propertyFilter); // Apply the ACL before potentially creating a PWC - applyAclCarefully(targetDocumentNodeRef, addACEs, removeACEs, EnumACLPropagation.PROPAGATE); + applyAclCarefully(targetDocumentNodeRef, addACEs, removeACEs, EnumACLPropagation.PROPAGATE, policies); if (versioningState == null) { @@ -752,7 +765,7 @@ public class DMObjectServicePort extends DMAbstractServicePort implements Object if ((null != propertyName) && !propertyName.equals("")) { filter.append(propertyName); - filter.append(PropertyFilter.PROPERTY_NAME_TOKENS_DELIMETER); + filter.append(PropertyFilter.PROPERTY_NAME_TOKENS_DELIMITER); } } @@ -764,7 +777,7 @@ public class DMObjectServicePort extends DMAbstractServicePort implements Object return filter.toString(); } - private String extractAndAssertTypeId(Map propertiesMap) throws CmisException + private String extractAndAssertTypeId(Map propertiesMap) throws CmisException { String typeId = (String) propertiesMap.get(CMISDictionaryModel.PROP_OBJECT_TYPE_ID); if ((null == typeId) || "".equals(typeId)) @@ -775,7 +788,7 @@ public class DMObjectServicePort extends DMAbstractServicePort implements Object } private String checkConstraintsAndGetName(String documentTypeId, CMISTypeDefinition typeDef, NodeRef parentNodeRef, CmisContentStreamType contentStream, - Map propertiesMap, EnumVersioningState versioningState) throws CmisException + Map propertiesMap, EnumVersioningState versioningState) throws CmisException { if ((null == typeDef) || (null == typeDef.getTypeId())) { diff --git a/source/java/org/alfresco/repo/cmis/ws/DMPolicyServicePort.java b/source/java/org/alfresco/repo/cmis/ws/DMPolicyServicePort.java index 28ceb05b4e..e88978f0dc 100644 --- a/source/java/org/alfresco/repo/cmis/ws/DMPolicyServicePort.java +++ b/source/java/org/alfresco/repo/cmis/ws/DMPolicyServicePort.java @@ -18,17 +18,17 @@ */ package org.alfresco.repo.cmis.ws; +import java.util.Collections; import java.util.List; import javax.xml.ws.Holder; +import org.alfresco.cmis.CMISServiceException; import org.alfresco.repo.cmis.ws.utils.ExceptionUtil; @javax.jws.WebService(name = "PolicyServicePort", serviceName = "PolicyServicePort", portName = "PolicyServicePort", targetNamespace = "http://docs.oasis-open.org/ns/cmis/ws/200908/", endpointInterface = "org.alfresco.repo.cmis.ws.PolicyServicePort") public class DMPolicyServicePort extends DMAbstractServicePort implements PolicyServicePort { - private static final String POLICY_NOT_SUPPORTED_MESSAGE = "PolicyService not implemented"; - /** * Applies a policy object to a target object. * @@ -39,7 +39,15 @@ public class DMPolicyServicePort extends DMAbstractServicePort implements Policy */ public void applyPolicy(String repositoryId, String policyId, String objectId, Holder extension) throws CmisException { - throw ExceptionUtil.createCmisException(POLICY_NOT_SUPPORTED_MESSAGE, EnumServiceException.RUNTIME); + checkRepositoryId(repositoryId); + try + { + cmisService.applyPolicy(policyId, objectId); + } + catch (CMISServiceException e) + { + throw ExceptionUtil.createCmisException(e); + } } /** @@ -50,7 +58,16 @@ public class DMPolicyServicePort extends DMAbstractServicePort implements Policy */ public List getAppliedPolicies(String repositoryId, String objectId, String filter, CmisExtensionType extension) throws CmisException { - throw ExceptionUtil.createCmisException(POLICY_NOT_SUPPORTED_MESSAGE, EnumServiceException.RUNTIME); + checkRepositoryId(repositoryId); + try + { + cmisService.getAppliedPolicies(objectId, filter); + return Collections.emptyList(); + } + catch (CMISServiceException e) + { + throw ExceptionUtil.createCmisException(e); + } } /** @@ -63,6 +80,14 @@ public class DMPolicyServicePort extends DMAbstractServicePort implements Policy */ public void removePolicy(String repositoryId, String policyId, String objectId, Holder extension) throws CmisException { - throw ExceptionUtil.createCmisException(POLICY_NOT_SUPPORTED_MESSAGE, EnumServiceException.RUNTIME); + checkRepositoryId(repositoryId); + try + { + cmisService.removePolicy(policyId, objectId); + } + catch (CMISServiceException e) + { + throw ExceptionUtil.createCmisException(e); + } } } diff --git a/source/java/org/alfresco/repo/cmis/ws/DMRelationshipServicePort.java b/source/java/org/alfresco/repo/cmis/ws/DMRelationshipServicePort.java index 965c464222..41b53e00fe 100644 --- a/source/java/org/alfresco/repo/cmis/ws/DMRelationshipServicePort.java +++ b/source/java/org/alfresco/repo/cmis/ws/DMRelationshipServicePort.java @@ -25,7 +25,7 @@ import java.util.Map; import org.alfresco.cmis.CMISRelationshipDirectionEnum; import org.alfresco.cmis.CMISServiceException; import org.alfresco.cmis.CMISTypeDefinition; -import org.alfresco.repo.cmis.PropertyFilter; +import org.alfresco.cmis.PropertyFilter; import org.alfresco.repo.cmis.ws.utils.ExceptionUtil; import org.alfresco.repo.web.util.paging.Cursor; import org.alfresco.service.cmr.repository.AssociationRef; diff --git a/source/java/org/alfresco/repo/cmis/ws/DMRepositoryServicePort.java b/source/java/org/alfresco/repo/cmis/ws/DMRepositoryServicePort.java index cf63a7d17d..0a3273515a 100644 --- a/source/java/org/alfresco/repo/cmis/ws/DMRepositoryServicePort.java +++ b/source/java/org/alfresco/repo/cmis/ws/DMRepositoryServicePort.java @@ -380,39 +380,18 @@ public class DMRepositoryServicePort extends DMAbstractServicePort implements Re { case DOCUMENT: CmisTypeDocumentDefinitionType documentDefinitionType = new CmisTypeDocumentDefinitionType(); - setCmisTypeDefinitionProperties(documentDefinitionType, typeDef, includeProperties); - if ((null != typeDef.getParentType()) && (null != typeDef.getParentType().getTypeId())) - { - documentDefinitionType.setParentId(typeDef.getParentType().getTypeId().getId()); - } - documentDefinitionType.setVersionable(true); // FIXME: this attribute MUST be setted with typeDef.isVersionable() + documentDefinitionType.setVersionable(typeDef.isVersionable()); documentDefinitionType.setContentStreamAllowed(CONTENT_STREAM_ALLOWED_ENUM_MAPPING.get(typeDef.getContentStreamAllowed())); result = documentDefinitionType; break; case FOLDER: - CmisTypeFolderDefinitionType folderDefinitionType = new CmisTypeFolderDefinitionType(); - if ((null != typeDef.getParentType()) && (null != typeDef.getParentType().getTypeId())) - { - folderDefinitionType.setParentId(typeDef.getParentType().getTypeId().getId()); - } - setCmisTypeDefinitionProperties(folderDefinitionType, typeDef, includeProperties); - result = folderDefinitionType; + result = new CmisTypeFolderDefinitionType(); break; case POLICY: - CmisTypePolicyDefinitionType policyDefinitionType = new CmisTypePolicyDefinitionType(); - if ((null != typeDef.getParentType()) && (null != typeDef.getParentType().getTypeId())) - { - policyDefinitionType.setParentId(typeDef.getParentType().getTypeId().getId()); - } - setCmisTypeDefinitionProperties(policyDefinitionType, typeDef, includeProperties); - result = policyDefinitionType; + result = new CmisTypePolicyDefinitionType(); break; case RELATIONSHIP: CmisTypeRelationshipDefinitionType relationshipDefinitionType = new CmisTypeRelationshipDefinitionType(); - if ((null != typeDef.getParentType()) && (null != typeDef.getParentType().getTypeId())) - { - relationshipDefinitionType.setParentId(typeDef.getParentType().getTypeId().getId()); - } if (typeDef.getAllowedSourceTypes() != null) { for (CMISTypeDefinition definition : typeDef.getAllowedSourceTypes()) @@ -427,12 +406,16 @@ public class DMRepositoryServicePort extends DMAbstractServicePort implements Re relationshipDefinitionType.getAllowedTargetTypes().add(definition.getTypeId().getId()); } } - setCmisTypeDefinitionProperties(relationshipDefinitionType, typeDef, includeProperties); result = relationshipDefinitionType; break; case UNKNOWN: throw ExceptionUtil.createCmisException("Unknown CMIS Type", EnumServiceException.INVALID_ARGUMENT); } + if ((null != typeDef.getParentType()) && (null != typeDef.getParentType().getTypeId())) + { + result.setParentId(typeDef.getParentType().getTypeId().getId()); + } + setCmisTypeDefinitionProperties(result, typeDef, includeProperties); return result; } diff --git a/source/java/org/alfresco/repo/cmis/ws/DMTransactionWrappingInterceptor.java b/source/java/org/alfresco/repo/cmis/ws/DMTransactionWrappingInterceptor.java deleted file mode 100755 index 6e27805eaa..0000000000 --- a/source/java/org/alfresco/repo/cmis/ws/DMTransactionWrappingInterceptor.java +++ /dev/null @@ -1,89 +0,0 @@ -/* -* Copyright (C) 2005-2010 Alfresco Software Limited. -* -* This file is part of Alfresco -* -* Alfresco is free software: you can redistribute it and/or modify -* it under the terms of the GNU Lesser General 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 . -*/ -package org.alfresco.repo.cmis.ws; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import org.alfresco.error.AlfrescoRuntimeException; -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.transaction.TransactionService; -import org.aopalliance.intercept.MethodInterceptor; -import org.aopalliance.intercept.MethodInvocation; -import org.springframework.transaction.interceptor.TransactionAspectSupport; -import org.springframework.transaction.interceptor.TransactionAttribute; - -/** - * @author Dmitry Velichkevich - */ -public class DMTransactionWrappingInterceptor extends TransactionAspectSupport implements MethodInterceptor -{ - private TransactionService transactionService; - - public void setTransactionService(TransactionService transactionService) - { - this.transactionService = transactionService; - } - - public Object invoke(final MethodInvocation target) throws Throwable - { - if ((null != target) && (null != target.getThis()) && (null != target.getMethod())) - { - final Method method = target.getMethod(); - final TransactionAttribute transactionAttribute = getTransactionAttributeSource().getTransactionAttribute(method, target.getThis().getClass()); - if (null != transactionAttribute) - { - return AuthenticationUtil.runAs(new RunAsWork() - { - public Object doWork() throws Exception - { - return transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback() - { - public Object execute() throws Throwable - { - try - { - return method.invoke(target.getThis(), target.getArguments()); - } - catch (InvocationTargetException e) - { - if (null != e.getTargetException()) - { - throw e.getTargetException(); - } - else - { - throw new AlfrescoRuntimeException(e.getMessage(), e); - } - } - } - }, transactionAttribute.isReadOnly(), (TransactionAttribute.PROPAGATION_REQUIRES_NEW == transactionAttribute.getPropagationBehavior())); - } - }, AuthenticationUtil.getFullyAuthenticatedUser()); - } - else - { - return method.invoke(target.getThis(), target.getArguments()); - } - } - throw new AlfrescoRuntimeException("Invalid undefined MethodInvocation instance"); - } -} diff --git a/source/java/org/alfresco/repo/cmis/ws/DMVersioningServicePort.java b/source/java/org/alfresco/repo/cmis/ws/DMVersioningServicePort.java index 8295abe149..4c7c979890 100644 --- a/source/java/org/alfresco/repo/cmis/ws/DMVersioningServicePort.java +++ b/source/java/org/alfresco/repo/cmis/ws/DMVersioningServicePort.java @@ -27,7 +27,7 @@ import org.alfresco.cmis.CMISContentStreamAllowedEnum; import org.alfresco.cmis.CMISDictionaryModel; import org.alfresco.cmis.CMISServiceException; import org.alfresco.cmis.CMISTypeDefinition; -import org.alfresco.repo.cmis.PropertyFilter; +import org.alfresco.cmis.PropertyFilter; import org.alfresco.repo.cmis.ws.utils.ExceptionUtil; import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.NodeRef; @@ -108,8 +108,7 @@ public class DMVersioningServicePort extends DMAbstractServicePort implements Ve propertiesUtil.setProperties(workingCopyNodeRef, properties, null); NodeRef nodeRef = cmisService.checkIn(objectId.value, checkinComment, major == null || major); - // TODO: applyPolicies - applyAclCarefully(nodeRef, addACEs, removeACEs, EnumACLPropagation.PROPAGATE); + applyAclCarefully(nodeRef, addACEs, removeACEs, EnumACLPropagation.PROPAGATE, policies); objectId.value = propertiesUtil.getProperty(nodeRef, CMISDictionaryModel.PROP_OBJECT_ID, objectId.value); } catch (CMISServiceException e) diff --git a/source/java/org/alfresco/repo/cmis/ws/utils/PropertyUtil.java b/source/java/org/alfresco/repo/cmis/ws/utils/PropertyUtil.java index 519e48bd7d..750496f2d6 100644 --- a/source/java/org/alfresco/repo/cmis/ws/utils/PropertyUtil.java +++ b/source/java/org/alfresco/repo/cmis/ws/utils/PropertyUtil.java @@ -21,6 +21,7 @@ package org.alfresco.repo.cmis.ws.utils; import java.io.Serializable; import java.math.BigDecimal; import java.math.BigInteger; +import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.GregorianCalendar; @@ -33,15 +34,14 @@ import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.XMLGregorianCalendar; import org.alfresco.cmis.CMISDataTypeEnum; -import org.alfresco.cmis.CMISDictionaryModel; import org.alfresco.cmis.CMISDictionaryService; import org.alfresco.cmis.CMISInvalidArgumentException; import org.alfresco.cmis.CMISPropertyDefinition; -import org.alfresco.cmis.CMISScope; import org.alfresco.cmis.CMISServiceException; import org.alfresco.cmis.CMISServices; import org.alfresco.cmis.CMISTypeDefinition; -import org.alfresco.repo.cmis.PropertyFilter; +import org.alfresco.cmis.PropertyFilter; +import org.alfresco.repo.cmis.ws.Aspects; import org.alfresco.repo.cmis.ws.CmisException; import org.alfresco.repo.cmis.ws.CmisPropertiesType; import org.alfresco.repo.cmis.ws.CmisProperty; @@ -54,9 +54,7 @@ import org.alfresco.repo.cmis.ws.CmisPropertyInteger; import org.alfresco.repo.cmis.ws.CmisPropertyString; import org.alfresco.repo.cmis.ws.CmisPropertyUri; import org.alfresco.repo.cmis.ws.EnumServiceException; -import org.alfresco.repo.cmis.ws.Aspects; import org.alfresco.repo.cmis.ws.SetAspects; -import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.dictionary.PropertyDefinition; import org.alfresco.service.cmr.repository.AssociationRef; @@ -88,8 +86,6 @@ public class PropertyUtil private final static String NAMESPACE_BEGIN = "" + QName.NAMESPACE_BEGIN; - private static final String BASE_TYPE_PROPERTY_NAME = "BaseType"; - private DictionaryService dictionaryService; private NamespaceService namespaceService; private CMISServices cmisService; @@ -190,9 +186,9 @@ public class PropertyUtil } } - private Object getValue(CmisProperty cmisProperty) throws CmisException + private Serializable getValue(CmisProperty cmisProperty) throws CmisException { - Object value = null; + Serializable value = null; String propertyName = getPropertyName(cmisProperty); if ((null == cmisProperty) || (null == propertyName)) { @@ -239,11 +235,11 @@ public class PropertyUtil { if (isMultiValued(propertyName, multivaluedState, convertedValue)) { - value = (convertedValue.size() > 0) ? (convertedValue) : (null); + value = (convertedValue.size() > 0) ? new ArrayList((convertedValue)) : (null); } else { - value = convertedValue.iterator().next(); + value = (Serializable)convertedValue.iterator().next(); } } @@ -319,9 +315,9 @@ public class PropertyUtil * @return Map<String, Serializable> properties representation * @throws CmisException */ - public Map getPropertiesMap(CmisPropertiesType cmisProperties) throws CmisException + public Map getPropertiesMap(CmisPropertiesType cmisProperties) throws CmisException { - Map properties = new HashMap(); + Map properties = new HashMap(); if (null == cmisProperties) { @@ -471,14 +467,14 @@ public class PropertyUtil aspectProperties.putAll(cmisService.getProperties((NodeRef)object, typeDef)); } CmisPropertiesType aspectResult = new CmisPropertiesType(); - convertToCmisProperties(object, aspectProperties, filter, aspectResult); + convertToCmisProperties(aspectProperties, filter, aspectResult); extension.setProperties(aspectResult); } else { - properties = createBaseRelationshipProperties((AssociationRef) object); + properties = cmisService.getProperties((AssociationRef) object); } - convertToCmisProperties(object, properties, filter, result); + convertToCmisProperties( properties, filter, result); return result; } catch (CMISInvalidArgumentException e) @@ -487,54 +483,11 @@ public class PropertyUtil } } - private Map createBaseRelationshipProperties(AssociationRef association) + private void convertToCmisProperties(Map properties, PropertyFilter filter, CmisPropertiesType cmisProperties) throws CmisException { - Map result = new HashMap(); - result.put(CMISDictionaryModel.PROP_OBJECT_TYPE_ID, cmisDictionaryService.findTypeForClass(association.getTypeQName(), CMISScope.RELATIONSHIP).getTypeId()); - result.put(CMISDictionaryModel.PROP_OBJECT_ID, CMISServices.ASSOC_ID_PREFIX + association.getId()); - result.put(BASE_TYPE_PROPERTY_NAME, CMISDictionaryModel.RELATIONSHIP_TYPE_ID.getId()); - result.put(CMISDictionaryModel.PROP_CREATED_BY, AuthenticationUtil.getFullyAuthenticatedUser()); - result.put(CMISDictionaryModel.PROP_CREATION_DATE, new Date()); - result.put(CMISDictionaryModel.PROP_SOURCE_ID, association.getSourceRef()); - result.put(CMISDictionaryModel.PROP_TARGET_ID, association.getTargetRef()); - return result; - } - - private void convertToCmisProperties(Object object, Map properties, PropertyFilter filter, CmisPropertiesType cmisProperties) throws CmisException - { - CMISTypeDefinition type = null; - if (object instanceof NodeRef) - { - try - { - type = cmisService.getTypeDefinition((NodeRef) object); - } - catch (CMISInvalidArgumentException e) - { - throw ExceptionUtil.createCmisException(e.getMessage(), EnumServiceException.INVALID_ARGUMENT); - } - - } - else - { - try - { - type = cmisService.getTypeDefinition((AssociationRef) object); - } - catch (CMISInvalidArgumentException e) - { - throw ExceptionUtil.createCmisException(e.getMessage(), EnumServiceException.INVALID_ARGUMENT); - } - } - - if (null == type) - { - throw ExceptionUtil.createCmisException(("Type for object " + object + " was not found"), EnumServiceException.RUNTIME); - } - for (String propertyName : properties.keySet()) { - CMISPropertyDefinition propertyTypeDef = cmisDictionaryService.findProperty(propertyName, type); + CMISPropertyDefinition propertyTypeDef = cmisDictionaryService.findProperty(propertyName, null); if ((null != propertyTypeDef) && filter.allow(propertyName)) { CmisProperty property = createProperty(propertyName, propertyTypeDef.getDataType(), properties.get(propertyName));