mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-21 18:09:20 +00:00
SAIL-160: CMIS Policy no-op implementations
- SOAP and REST binding create/update methods throw exceptions allowed by spec and read method returns empty set - Moved transaction interceptor into org.alfresco.repo.transaction package and removed redundant runAs call - PropertyFilter parsing corrected and made a shared service - Removed replicated code from webservice getTypeDefinition implementation - Moved association property getting into CMISServices git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@19239 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -291,7 +291,7 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="dmTransactionWrappingInterceptor" class="org.alfresco.repo.cmis.ws.DMTransactionWrappingInterceptor">
|
||||
<bean id="dmTransactionWrappingInterceptor" class="org.alfresco.repo.transaction.RetryingTransactionInterceptor">
|
||||
<property name="transactionService" ref="TransactionService" />
|
||||
<property name="transactionManager">
|
||||
<ref bean="transactionManager" />
|
||||
|
@@ -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/]
|
||||
|
@@ -24,6 +24,11 @@
|
||||
<link rel="${cmisconstants.REL_RELATIONSHIPS}" href="${absurl(url.serviceContext)}[@nodeuri node/]/rels"/>
|
||||
[/#macro]
|
||||
|
||||
[#-- Link to node policies --]
|
||||
[#macro linkpolicies node]
|
||||
<link rel="${cmisconstants.REL_POLICIES}" href="${absurl(url.serviceContext)}[@nodeuri node/]/pols"/>
|
||||
[/#macro]
|
||||
|
||||
[#-- Link to node acl --]
|
||||
[#macro linkacl node]
|
||||
<link rel="${cmisconstants.REL_ACL}" href="${absurl(url.serviceContext)}[@nodeuri node/]/acl"/>
|
||||
|
@@ -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
|
||||
|
@@ -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]
|
||||
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<feed [@nsLib.feedNS/]>
|
||||
|
||||
[@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/]
|
||||
|
||||
</feed>
|
||||
|
||||
[/#compress]
|
@@ -0,0 +1,19 @@
|
||||
<webscript>
|
||||
<shortname>Retrieve list of applied policies (getAppliedPolicies)</shortname>
|
||||
<description>
|
||||
</description>
|
||||
|
||||
<!-- by object id -->
|
||||
<url>/cmis/i/{id}/pols?filter={filter?}&skipCount={skipCount?}&maxItems={maxItems?}</url>
|
||||
<url>/cmis/s/{store}/i/{id}/pols?filter={filter?}&skipCount={skipCount?}&maxItems={maxItems?}</url>
|
||||
<!-- by path -->
|
||||
<url>/cmis/p{path}/pols?filter={filter?}&skipCount={skipCount?}&maxItems={maxItems?}</url>
|
||||
<url>/cmis/s/{store}/p{path}/pols?filter={filter?}&skipCount={skipCount?}&maxItems={maxItems?}</url>
|
||||
|
||||
<!-- alfresco style -->
|
||||
<url>/api/node/{store_type}/{store_id}/{id}/pols?filter={filter?}&skipCount={skipCount?}&maxItems={maxItems?}</url>
|
||||
<url>/api/path/{store_type}/{store_id}/{id}/pols?filter={filter?}&skipCount={skipCount?}&maxItems={maxItems?}</url>
|
||||
<authentication>guest</authentication>
|
||||
<format default="atomfeed">argument</format>
|
||||
<family>CMIS</family>
|
||||
</webscript>
|
@@ -0,0 +1,26 @@
|
||||
<import resource="classpath:alfresco/templates/webscripts/org/alfresco/cmis/lib/read.lib.js">
|
||||
<import resource="classpath:alfresco/templates/webscripts/org/alfresco/cmis/lib/constants.lib.js">
|
||||
|
||||
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;
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
<import resource="classpath:alfresco/templates/webscripts/org/alfresco/cmis/lib/constants.lib.js">
|
||||
<import resource="classpath:alfresco/templates/webscripts/org/alfresco/cmis/lib/read.lib.js">
|
||||
<import resource="classpath:alfresco/templates/webscripts/org/alfresco/cmis/lib/modify.lib.js">
|
||||
|
||||
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;
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
<webscript>
|
||||
<shortname>Create policy (createPolicy)</shortname>
|
||||
<description>
|
||||
</description>
|
||||
|
||||
<!-- by object id -->
|
||||
<url>/cmis/i/{id}/pols</url>
|
||||
<url>/cmis/s/{store}/i/{id}/pols</url>
|
||||
<!-- by path -->
|
||||
<url>/cmis/p{path}/pols</url>
|
||||
<url>/cmis/s/{store}/p{path}/pols</url>
|
||||
|
||||
<!-- alfresco style -->
|
||||
<url>/api/node/{store_type}/{store_id}/{id}/pols</url>
|
||||
<url>/api/path/{store_type}/{store_id}/{id}/pols</url>
|
||||
|
||||
<authentication>guest</authentication>
|
||||
<format default="atomentry">argument</format>
|
||||
<family>CMIS</family>
|
||||
</webscript>
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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<String> 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<String>();
|
||||
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 <b>true</b> returns if property is allowed by filter. In other case returns <b>false</b>
|
||||
*/
|
||||
public boolean allow(String property)
|
||||
{
|
||||
return properties == null || properties.contains(property.toLowerCase());
|
||||
}
|
||||
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -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.<String, Serializable> singletonMap(
|
||||
CMISDictionaryModel.PROP_OBJECT_TYPE_ID, typeId), (String) cmisService.getProperty(parent
|
||||
.getNodeRef(), CMISDictionaryModel.PROP_OBJECT_ID), Collections.<String> 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<CMISTypeDefinition> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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<String> 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<String> 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<String> policies)
|
||||
throws CmisException
|
||||
{
|
||||
if (addACEs == null && removeACEs == null)
|
||||
@@ -397,10 +424,17 @@ public class DMAbstractServicePort
|
||||
List<CMISAccessControlEntry> 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);
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -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
|
||||
|
@@ -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;
|
||||
|
@@ -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<String, Object> propertiesMap = propertiesUtil.getPropertiesMap(properties);
|
||||
Map<String, Serializable> 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<String> policies, CmisAccessControlListType addACEs,
|
||||
CmisAccessControlListType removeACEs, Holder<CmisExtensionType> extension, Holder<String> objectId) throws CmisException
|
||||
{
|
||||
// TODO: process Policies
|
||||
|
||||
checkRepositoryId(repositoryId);
|
||||
try
|
||||
{
|
||||
NodeRef folderNodeRef = cmisService.getFolder(folderId);
|
||||
Map<String, Object> propertiesMap = propertiesUtil.getPropertiesMap(properties);
|
||||
Map<String, Serializable> 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<String> policies, CmisAccessControlListType addACEs,
|
||||
CmisAccessControlListType removeACEs, Holder<CmisExtensionType> extension, Holder<String> 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<String, Object> propertiesMap = propertiesUtil.getPropertiesMap(properties);
|
||||
Map<String, Serializable> 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<String> 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<String, Object> propertiesMap) throws CmisException
|
||||
private String extractAndAssertTypeId(Map<String, Serializable> 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<String, Object> propertiesMap, EnumVersioningState versioningState) throws CmisException
|
||||
Map<String, Serializable> propertiesMap, EnumVersioningState versioningState) throws CmisException
|
||||
{
|
||||
if ((null == typeDef) || (null == typeDef.getTypeId()))
|
||||
{
|
||||
|
@@ -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<CmisExtensionType> 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<CmisObjectType> 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<CmisExtensionType> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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<Object>()
|
||||
{
|
||||
public Object doWork() throws Exception
|
||||
{
|
||||
return transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Object>()
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
@@ -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)
|
||||
|
@@ -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<Object>((convertedValue)) : (null);
|
||||
}
|
||||
else
|
||||
{
|
||||
value = convertedValue.iterator().next();
|
||||
value = (Serializable)convertedValue.iterator().next();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,9 +315,9 @@ public class PropertyUtil
|
||||
* @return <b>Map</b><<b>String</b>, <b>Serializable</b>> properties representation
|
||||
* @throws <b>CmisException</b>
|
||||
*/
|
||||
public Map<String, Object> getPropertiesMap(CmisPropertiesType cmisProperties) throws CmisException
|
||||
public Map<String, Serializable> getPropertiesMap(CmisPropertiesType cmisProperties) throws CmisException
|
||||
{
|
||||
Map<String, Object> properties = new HashMap<String, Object>();
|
||||
Map<String, Serializable> properties = new HashMap<String, Serializable>();
|
||||
|
||||
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<String, Serializable> createBaseRelationshipProperties(AssociationRef association)
|
||||
private void convertToCmisProperties(Map<String, Serializable> properties, PropertyFilter filter, CmisPropertiesType cmisProperties) throws CmisException
|
||||
{
|
||||
Map<String, Serializable> result = new HashMap<String, Serializable>();
|
||||
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<String, Serializable> 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));
|
||||
|
Reference in New Issue
Block a user