Merged HEAD-QA to HEAD (4.2) (including moving test classes into separate folders)

51903 to 54309 


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@54310 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Samuel Langlois
2013-08-20 17:17:31 +00:00
parent 0a36e2af67
commit ab4ca7177f
1576 changed files with 36419 additions and 8603 deletions

View File

@@ -0,0 +1,104 @@
/*
* Copyright (C) 2005-2012 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.cmis.mapping;
import org.alfresco.cmis.CMISAllowedActionEnum;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
import org.apache.chemistry.abdera.ext.CMISAllowableActions;
/**
* This evaluator determines an action availability in accordance with collection of aspects and rules of checking application of the aspects. The rules are:<br />
* - is it expected that aspect(s) had been applied;<br />
* - should all aspects in the collection satisfying to the specified condition or at least 1 aspect is enough<br />
* <br />
* This evaluator is generic, because it is used in the scope of {@link CompositeActionEvaluator}
*
* @author Dmitry Velichkevich
*/
public class AspectActionEvaluator<ObjectType> extends AbstractActionEvaluator<ObjectType>
{
private NodeService nodeService;
private boolean expected;
private boolean allAspectsMustConcur;
private boolean defaultAllowing;
private QName[] aspects;
/**
* Constructor
*
* @param serviceRegistry - {@link ServiceRegistry} instance
* @param action - {@link CMISAllowableActions} enumeration value, which determines the action to check
* @param expected - {@link Boolean} value, which determines: <code>true</code> - aspects application is expected, <code>false</code> - aspects absence is expected
* @param allAspectsMustConcur - {@link Boolean} value, which determines: <code>true</code> - all aspects should satisfy <code>expected</code> condition, <code>false</code> -
* at least 1 aspect should satisfy the <code>expected</code> condition
* @param defaultAllowing - {@link Boolean} value, which determines availability of action for several special cases (invalid object id, empty collection of the aspects etc.)
* @param aspects {@link QName}... collection, which specifies all aspects, required for validation
*/
public AspectActionEvaluator(ServiceRegistry serviceRegistry, CMISAllowedActionEnum action, boolean expected, boolean allAspectsMustConcur, boolean defaultAllowing,
QName... aspects)
{
super(serviceRegistry, action);
this.expected = expected;
this.allAspectsMustConcur = allAspectsMustConcur;
this.aspects = aspects;
nodeService = serviceRegistry.getNodeService();
}
public boolean isAllowed(ObjectType id)
{
NodeRef nodeRef = (id instanceof NodeRef) ? ((NodeRef) id) : (null);
if ((null != nodeRef) && (null != aspects))
{
for (QName aspectId : aspects)
{
boolean aspect = nodeService.hasAspect(nodeRef, aspectId);
if (!expected)
{
aspect = !aspect;
}
if (!allAspectsMustConcur && aspect)
{
return true;
}
else
{
if (allAspectsMustConcur && !aspect)
{
return false;
}
}
}
return allAspectsMustConcur;
}
return defaultAllowing;
}
}

View File

@@ -1,179 +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.cmis.mapping;
import java.util.Date;
import javax.transaction.Status;
import javax.transaction.UserTransaction;
import junit.framework.TestCase;
import org.alfresco.cmis.CMISAccessControlService;
import org.alfresco.cmis.CMISDictionaryService;
import org.alfresco.cmis.CMISQueryService;
import org.alfresco.cmis.CMISRenditionService;
import org.alfresco.cmis.CMISServices;
import org.alfresco.repo.dictionary.DictionaryDAO;
import org.alfresco.repo.dictionary.NamespaceDAOImpl;
import org.alfresco.repo.model.Repository;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.MutableAuthenticationDao;
import org.alfresco.repo.security.permissions.impl.ModelDAO;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.action.ActionService;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.rule.RuleService;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.cmr.security.MutableAuthenticationService;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.thumbnail.ThumbnailService;
import org.alfresco.service.cmr.version.VersionService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.ApplicationContextHelper;
import org.springframework.context.ApplicationContext;
/**
* Base CMIS test
* Basic TX control and authentication
*
* @author andyh
*/
public abstract class BaseCMISTest extends TestCase
{
private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
protected CMISMapping cmisMapping;
protected CMISServices cmisService;
protected CMISDictionaryService cmisDictionaryService;
protected CMISRenditionService cmisRenditionService;
protected CMISAccessControlService cmisAccessControlService;
protected DictionaryService dictionaryService;
protected TransactionService transactionService;
protected AuthenticationComponent authenticationComponent;
protected UserTransaction testTX;
protected NodeService nodeService;
protected NodeRef rootNodeRef;
protected FileFolderService fileFolderService;
protected ServiceRegistry serviceRegistry;
protected NamespaceService namespaceService;
protected CMISQueryService cmisQueryService;
private MutableAuthenticationService authenticationService;
private MutableAuthenticationDao authenticationDAO;
protected SearchService searchService;
protected ContentService contentService;
protected PermissionService permissionService;
protected ThumbnailService thumbnailService;
protected ModelDAO permissionModelDao;
protected DictionaryDAO dictionaryDAO;
protected NamespaceDAOImpl namespaceDao;
protected VersionService versionService;
protected ActionService actionService;
protected RuleService ruleService;
protected Repository repositoryHelper;
public void setUp() throws Exception
{
serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
cmisDictionaryService = (CMISDictionaryService) ctx.getBean("CMISDictionaryService");
cmisMapping = (CMISMapping) ctx.getBean("CMISMapping");
cmisQueryService = (CMISQueryService) ctx.getBean("CMISQueryService");
cmisService = (CMISServices) ctx.getBean("CMISService");
cmisRenditionService = (CMISRenditionService) ctx.getBean("CMISRenditionService");
cmisAccessControlService = (CMISAccessControlService) ctx.getBean("CMISAccessControlService");
dictionaryService = (DictionaryService) ctx.getBean("dictionaryService");
nodeService = (NodeService) ctx.getBean("nodeService");
fileFolderService = (FileFolderService) ctx.getBean("fileFolderService");
namespaceService = (NamespaceService) ctx.getBean("namespaceService");
transactionService = (TransactionService) ctx.getBean("transactionComponent");
authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
searchService = (SearchService) ctx.getBean("searchService");
contentService = (ContentService) ctx.getBean("contentService");
permissionService = (PermissionService) ctx.getBean("permissionService");
versionService = (VersionService) ctx.getBean("versionService");
actionService = (ActionService)ctx.getBean("actionService");
ruleService = (RuleService)ctx.getBean("ruleService");
repositoryHelper = (Repository)ctx.getBean("repositoryHelper");
authenticationService = (MutableAuthenticationService) ctx.getBean("authenticationService");
authenticationDAO = (MutableAuthenticationDao) ctx.getBean("authenticationDao");
thumbnailService = (ThumbnailService) ctx.getBean("thumbnailService");
permissionModelDao = (ModelDAO) ctx.getBean("permissionsModelDAO");
dictionaryDAO = (DictionaryDAO) ctx.getBean("dictionaryDAO");
namespaceDao = (NamespaceDAOImpl) ctx.getBean("namespaceDAO");
testTX = transactionService.getUserTransaction();
testTX.begin();
this.authenticationComponent.setSystemUserAsCurrentUser();
String storeName = "CMISTest-" + getStoreName() + "-" + (new Date().getTime());
StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, storeName);
rootNodeRef = nodeService.getRootNode(storeRef);
if(authenticationDAO.userExists("cmis"))
{
authenticationService.deleteAuthentication("cmis");
}
authenticationService.createAuthentication("cmis", "cmis".toCharArray());
}
private String getStoreName()
{
String testName = getName();
testName = testName.replace("_", "-");
testName = testName.replace("%", "-");
return testName;
}
protected void runAs(String userName)
{
authenticationService.authenticate(userName, userName.toCharArray());
assertNotNull(authenticationService.getCurrentUserName());
}
@Override
protected void tearDown() throws Exception
{
if (testTX.getStatus() == Status.STATUS_ACTIVE)
{
testTX.rollback();
}
AuthenticationUtil.clearCurrentSecurityContext();
super.tearDown();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
* Copyright (C) 2005-2012 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -30,6 +30,7 @@ import java.util.Set;
import org.alfresco.cmis.CMISAccessControlService;
import org.alfresco.cmis.CMISActionEvaluator;
import org.alfresco.cmis.CMISAllowedActionEnum;
import org.alfresco.cmis.CMISContentStreamAllowedEnum;
import org.alfresco.cmis.CMISDataTypeEnum;
import org.alfresco.cmis.CMISDictionaryModel;
import org.alfresco.cmis.CMISPropertyId;
@@ -39,10 +40,12 @@ import org.alfresco.cmis.CMISTypeId;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.opencmis.CMISAccessControlFormatEnum;
import org.alfresco.repo.version.Version2Model;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.AspectDefinition;
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.lock.LockType;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.PermissionService;
@@ -52,6 +55,9 @@ import org.alfresco.util.Pair;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean;
import org.alfresco.cmis.mapping.ParentTypeActionEvaluator.ParentTypeEnum;
import org.alfresco.cmis.mapping.PropertyActionEvaluator.PropertyDescriptor;
import org.alfresco.cmis.mapping.TypeAttributeActionEvaluator.TypeDefinitionAttributeEnum;
/**
@@ -61,6 +67,22 @@ import org.springframework.beans.factory.InitializingBean;
*/
public class CMISMapping implements InitializingBean
{
private static final Comparable<Object> CONTENT_STREAM_SUPPORTED_COMPARATOR = new Comparable<Object>()
{
@Override
public int compareTo(Object another)
{
CMISContentStreamAllowedEnum converted = (CMISContentStreamAllowedEnum) another;
return (CMISContentStreamAllowedEnum.NOT_ALLOWED != converted) ? (0) : (-1);
}
};
private static final PropertyDescriptor PROPERTY_STREAM_ID = new PropertyDescriptor(CMISDictionaryModel.PROP_CONTENT_STREAM_ID, null, false);
private static final boolean DEFAULT_ALLOWING = false;
private static final PropertyDescriptor PROPERTY_MUTABLE = new PropertyDescriptor(CMISDictionaryModel.PROP_IS_IMMUTABLE, false, true);
// Logger
protected static final Log logger = LogFactory.getLog(CMISMapping.class);
@@ -216,51 +238,113 @@ public class CMISMapping implements InitializingBean
// NOTE: The order of evaluators is important - they must be in the order as specified in CMIS-Core.xsd
// so that schema validation passes
registerEvaluator(CMISScope.DOCUMENT, new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_DELETE_OBJECT, PermissionService.DELETE_NODE));
registerEvaluator(CMISScope.DOCUMENT, new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_UPDATE_PROPERTIES, PermissionService.WRITE_PROPERTIES));
registerEvaluator(CMISScope.DOCUMENT, new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_GET_PROPERTIES, PermissionService.READ_PROPERTIES));
registerEvaluator(CMISScope.DOCUMENT, new FixedValueActionEvaluator<NodeRef>(serviceRegistry, CMISAllowedActionEnum.CAN_GET_OBJECT_RELATIONSHIPS, true));
registerEvaluator(CMISScope.DOCUMENT, new ParentActionEvaluator(new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_GET_OBJECT_PARENTS, PermissionService.READ_PERMISSIONS)));
// Depends on cmis:immutable
registerEvaluator(CMISScope.DOCUMENT, new CompositeActionEvaluator<NodeRef>(DEFAULT_ALLOWING, serviceRegistry, CMISAllowedActionEnum.CAN_DELETE_OBJECT).addPermissionCondition(
PermissionService.DELETE_NODE).addPropertyCondition(PROPERTY_MUTABLE));
// Depends on cmis:immutable
registerEvaluator(CMISScope.DOCUMENT, new CompositeActionEvaluator<NodeRef>(DEFAULT_ALLOWING, serviceRegistry, CMISAllowedActionEnum.CAN_UPDATE_PROPERTIES).addPermissionCondition(
PermissionService.WRITE_PROPERTIES).addAspectCondition(false, Version2Model.ASPECT_VERSION).addPropertyCondition(PROPERTY_MUTABLE));
registerEvaluator(CMISScope.DOCUMENT, new PermissionActionEvaluator<NodeRef>(serviceRegistry, CMISAllowedActionEnum.CAN_GET_PROPERTIES, DEFAULT_ALLOWING,
PermissionService.READ_PROPERTIES));
registerEvaluator(CMISScope.DOCUMENT, new PermissionActionEvaluator<NodeRef>(serviceRegistry, CMISAllowedActionEnum.CAN_GET_OBJECT_RELATIONSHIPS, DEFAULT_ALLOWING,
PermissionService.READ_ASSOCIATIONS));
registerEvaluator(CMISScope.DOCUMENT, new ParentActionEvaluator(new PermissionActionEvaluator<NodeRef>(serviceRegistry, CMISAllowedActionEnum.CAN_GET_OBJECT_PARENTS,
DEFAULT_ALLOWING, PermissionService.READ_PERMISSIONS)));
// Is CAN_MOVE correct mapping?
registerEvaluator(CMISScope.DOCUMENT, new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_MOVE_OBJECT, PermissionService.DELETE_NODE));
registerEvaluator(CMISScope.DOCUMENT, new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_DELETE_CONTENT_STREAM, PermissionService.WRITE_PROPERTIES, PermissionService.WRITE_CONTENT));
registerEvaluator(CMISScope.DOCUMENT, new CanCheckOutActionEvaluator(serviceRegistry));
registerEvaluator(CMISScope.DOCUMENT, new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_CANCEL_CHECKOUT, PermissionService.CANCEL_CHECK_OUT));
registerEvaluator(CMISScope.DOCUMENT, new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_CHECKIN, PermissionService.CHECK_IN));
registerEvaluator(CMISScope.DOCUMENT, new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_SET_CONTENT_STREAM, PermissionService.WRITE_CONTENT));
// Depends on cmis:immutable
registerEvaluator(CMISScope.DOCUMENT, new CompositeActionEvaluator<NodeRef>(DEFAULT_ALLOWING, serviceRegistry, CMISAllowedActionEnum.CAN_MOVE_OBJECT).addPermissionCondition(
PermissionService.DELETE_NODE).addAspectCondition(false, Version2Model.ASPECT_VERSION).addPropertyCondition(PROPERTY_MUTABLE));
// Depends on cmis:immutable
// Also depends on content stream appearance definition in the model and whether stream is set...
registerEvaluator(CMISScope.DOCUMENT, new CompositeActionEvaluator<NodeRef>(DEFAULT_ALLOWING, serviceRegistry, CMISAllowedActionEnum.CAN_DELETE_CONTENT_STREAM)
.addPermissionCondition(PermissionService.WRITE_CONTENT).addPropertyCondition(PROPERTY_MUTABLE, PROPERTY_STREAM_ID).addAspectCondition(false,
Version2Model.ASPECT_VERSION).addTypeAttributeCondition(TypeDefinitionAttributeEnum.CONTENT_STREAM_ALLOWED, new Comparable<Object>()
{
@Override
public int compareTo(Object another)
{
return CMISContentStreamAllowedEnum.ALLOWED.compareTo((CMISContentStreamAllowedEnum) another);
}
}));
// Also depends on cmis:immutable
registerEvaluator(CMISScope.DOCUMENT, new CompositeActionEvaluator<NodeRef>(DEFAULT_ALLOWING, serviceRegistry, CMISAllowedActionEnum.CAN_CHECKOUT).addPermissionCondition(
PermissionService.CHECK_OUT).addPropertyCondition(PROPERTY_MUTABLE).addLockCondition(LockType.READ_ONLY_LOCK).addPwcCondition(false));
// Same as check-in. It requires check if specified object is a PWC
registerEvaluator(CMISScope.DOCUMENT, new CompositeActionEvaluator<NodeRef>(DEFAULT_ALLOWING, serviceRegistry, CMISAllowedActionEnum.CAN_CANCEL_CHECKOUT).addPermissionCondition(
PermissionService.CANCEL_CHECK_OUT).addPwcCondition(true));
registerEvaluator(CMISScope.DOCUMENT, new CompositeActionEvaluator<NodeRef>(DEFAULT_ALLOWING, serviceRegistry, CMISAllowedActionEnum.CAN_CHECKIN).addPermissionCondition(
PermissionService.CHECK_IN).addPwcCondition(true));
// Also depends on model definition... also depends on cmis:immutable
registerEvaluator(CMISScope.DOCUMENT, new CompositeActionEvaluator<NodeRef>(DEFAULT_ALLOWING, serviceRegistry, CMISAllowedActionEnum.CAN_SET_CONTENT_STREAM)
.addPermissionCondition(PermissionService.WRITE_CONTENT).addAspectCondition(false, Version2Model.ASPECT_VERSION).addPropertyCondition(PROPERTY_MUTABLE)
.addTypeAttributeCondition(TypeDefinitionAttributeEnum.CONTENT_STREAM_ALLOWED, CONTENT_STREAM_SUPPORTED_COMPARATOR));
registerEvaluator(CMISScope.DOCUMENT, new FixedValueActionEvaluator<NodeRef>(serviceRegistry, CMISAllowedActionEnum.CAN_GET_ALL_VERSIONS, true));
registerEvaluator(CMISScope.DOCUMENT, new ParentActionEvaluator(new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_ADD_OBJECT_TO_FOLDER, PermissionService.LINK_CHILDREN)));
// Depends on cmis:immutable
registerEvaluator(CMISScope.DOCUMENT, new CompositeActionEvaluator<NodeRef>(DEFAULT_ALLOWING, serviceRegistry, CMISAllowedActionEnum.CAN_ADD_OBJECT_TO_FOLDER)
.addPropertyCondition(PROPERTY_MUTABLE).addPermissionCondition(PermissionService.CREATE_ASSOCIATIONS));
// Is CAN_REMOVE_FROM_FOLDER correct mapping?
registerEvaluator(CMISScope.DOCUMENT, new ParentActionEvaluator(new FixedValueActionEvaluator<NodeRef>(serviceRegistry, CMISAllowedActionEnum.CAN_REMOVE_OBJECT_FROM_FOLDER, true)));
registerEvaluator(CMISScope.DOCUMENT, new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_GET_CONTENT_STREAM, PermissionService.READ_CONTENT));
// Should be aware about amount of parents. It is not allowed for PRIMARY parent!
registerEvaluator(CMISScope.DOCUMENT, new CompositeActionEvaluator<NodeRef>(DEFAULT_ALLOWING, serviceRegistry, CMISAllowedActionEnum.CAN_REMOVE_OBJECT_FROM_FOLDER)
.addPermissionCondition(PermissionService.DELETE_ASSOCIATIONS).addPropertyCondition(PROPERTY_MUTABLE).addParentTypeCondition(ParentTypeEnum.MULTI_FILED));
// Depends on availability of the stream (including streams of renditions)
registerEvaluator(CMISScope.DOCUMENT, new CompositeActionEvaluator<NodeRef>(DEFAULT_ALLOWING, serviceRegistry, CMISAllowedActionEnum.CAN_GET_CONTENT_STREAM)
.addPermissionCondition(PermissionService.READ_CONTENT).addPropertyCondition(PROPERTY_STREAM_ID).addTypeAttributeCondition(
TypeDefinitionAttributeEnum.CONTENT_STREAM_ALLOWED, CONTENT_STREAM_SUPPORTED_COMPARATOR));
registerEvaluator(CMISScope.DOCUMENT, new FixedValueActionEvaluator<NodeRef>(serviceRegistry, CMISAllowedActionEnum.CAN_APPLY_POLICY, false));
registerEvaluator(CMISScope.DOCUMENT, new FixedValueActionEvaluator<NodeRef>(serviceRegistry, CMISAllowedActionEnum.CAN_GET_APPLIED_POLICIES, true));
registerEvaluator(CMISScope.DOCUMENT, new FixedValueActionEvaluator<NodeRef>(serviceRegistry, CMISAllowedActionEnum.CAN_REMOVE_POLICY, false));
registerEvaluator(CMISScope.DOCUMENT, new FixedValueActionEvaluator<NodeRef>(serviceRegistry, CMISAllowedActionEnum.CAN_CREATE_RELATIONSHIP, true));
// Depends on cmis:immutable
registerEvaluator(CMISScope.DOCUMENT, new CompositeActionEvaluator<NodeRef>(DEFAULT_ALLOWING, serviceRegistry, CMISAllowedActionEnum.CAN_CREATE_RELATIONSHIP)
.addPermissionCondition(PermissionService.CREATE_ASSOCIATIONS).addPropertyCondition(PROPERTY_MUTABLE));
registerEvaluator(CMISScope.DOCUMENT, new FixedValueActionEvaluator<NodeRef>(serviceRegistry, CMISAllowedActionEnum.CAN_GET_RENDITIONS, true));
registerEvaluator(CMISScope.DOCUMENT, new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_GET_ACL, PermissionService.READ_PERMISSIONS));
registerEvaluator(CMISScope.DOCUMENT, new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_APPLY_ACL, PermissionService.CHANGE_PERMISSIONS));
registerEvaluator(CMISScope.FOLDER, new RootActionEvaluator(new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_DELETE_OBJECT, PermissionService.DELETE_NODE), false));
registerEvaluator(CMISScope.FOLDER, new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_UPDATE_PROPERTIES, PermissionService.WRITE_PROPERTIES));
registerEvaluator(CMISScope.FOLDER, new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_GET_FOLDER_TREE, PermissionService.READ_CHILDREN));
registerEvaluator(CMISScope.FOLDER, new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_GET_PROPERTIES, PermissionService.READ_PROPERTIES));
registerEvaluator(CMISScope.FOLDER, new FixedValueActionEvaluator<NodeRef>(serviceRegistry, CMISAllowedActionEnum.CAN_GET_OBJECT_RELATIONSHIPS, true));
registerEvaluator(CMISScope.FOLDER, new ParentActionEvaluator(new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_GET_OBJECT_PARENTS, PermissionService.READ_PERMISSIONS)));
registerEvaluator(CMISScope.FOLDER, new ParentActionEvaluator(new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_GET_FOLDER_PARENT, PermissionService.READ_PERMISSIONS)));
registerEvaluator(CMISScope.FOLDER, new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_GET_DESCENDANTS, PermissionService.READ_CHILDREN));
registerEvaluator(CMISScope.DOCUMENT, new PermissionActionEvaluator<NodeRef>(serviceRegistry, CMISAllowedActionEnum.CAN_GET_ACL, DEFAULT_ALLOWING,
PermissionService.READ_PERMISSIONS));
// Depends on cmis:immutable
registerEvaluator(CMISScope.DOCUMENT, new CompositeActionEvaluator<NodeRef>(DEFAULT_ALLOWING, serviceRegistry, CMISAllowedActionEnum.CAN_APPLY_ACL).addPermissionCondition(
PermissionService.CHANGE_PERMISSIONS).addPropertyCondition(PROPERTY_MUTABLE));
registerEvaluator(CMISScope.FOLDER, new RootActionEvaluator<NodeRef>(new PermissionActionEvaluator<NodeRef>(serviceRegistry, CMISAllowedActionEnum.CAN_DELETE_OBJECT,
DEFAULT_ALLOWING, PermissionService.DELETE_NODE), false));
registerEvaluator(CMISScope.FOLDER, new CompositeActionEvaluator<NodeRef>(DEFAULT_ALLOWING, serviceRegistry, CMISAllowedActionEnum.CAN_UPDATE_PROPERTIES)
.addPermissionCondition(PermissionService.WRITE_PROPERTIES));
registerEvaluator(CMISScope.FOLDER, new PermissionActionEvaluator<NodeRef>(serviceRegistry, CMISAllowedActionEnum.CAN_GET_FOLDER_TREE, DEFAULT_ALLOWING, PermissionService.READ_CHILDREN));
registerEvaluator(CMISScope.FOLDER, new PermissionActionEvaluator<NodeRef>(serviceRegistry, CMISAllowedActionEnum.CAN_GET_PROPERTIES, DEFAULT_ALLOWING, PermissionService.READ_PROPERTIES));
registerEvaluator(CMISScope.FOLDER, new PermissionActionEvaluator<NodeRef>(serviceRegistry, CMISAllowedActionEnum.CAN_GET_OBJECT_RELATIONSHIPS, DEFAULT_ALLOWING,
PermissionService.READ_ASSOCIATIONS));
registerEvaluator(CMISScope.FOLDER, new ParentActionEvaluator(new PermissionActionEvaluator<NodeRef>(serviceRegistry,
CMISAllowedActionEnum.CAN_GET_OBJECT_PARENTS, DEFAULT_ALLOWING, PermissionService.READ_PERMISSIONS)));
registerEvaluator(CMISScope.FOLDER, new ParentActionEvaluator(new PermissionActionEvaluator<NodeRef>(serviceRegistry, CMISAllowedActionEnum.CAN_GET_FOLDER_PARENT,
DEFAULT_ALLOWING, PermissionService.READ_PERMISSIONS)));
registerEvaluator(CMISScope.FOLDER, new PermissionActionEvaluator<NodeRef>(serviceRegistry, CMISAllowedActionEnum.CAN_GET_DESCENDANTS, DEFAULT_ALLOWING,
PermissionService.READ_CHILDREN));
// Is CAN_MOVE_OBJECT correct mapping?
registerEvaluator(CMISScope.FOLDER, new RootActionEvaluator(new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_MOVE_OBJECT, PermissionService.DELETE_NODE), false));
registerEvaluator(CMISScope.FOLDER, new RootActionEvaluator<NodeRef>(new PermissionActionEvaluator<NodeRef>(serviceRegistry, CMISAllowedActionEnum.CAN_MOVE_OBJECT,
DEFAULT_ALLOWING, PermissionService.DELETE_NODE), false));
registerEvaluator(CMISScope.FOLDER, new FixedValueActionEvaluator<NodeRef>(serviceRegistry, CMISAllowedActionEnum.CAN_APPLY_POLICY, false));
registerEvaluator(CMISScope.FOLDER, new FixedValueActionEvaluator<NodeRef>(serviceRegistry, CMISAllowedActionEnum.CAN_GET_APPLIED_POLICIES, true));
registerEvaluator(CMISScope.FOLDER, new FixedValueActionEvaluator<NodeRef>(serviceRegistry, CMISAllowedActionEnum.CAN_REMOVE_POLICY, false));
registerEvaluator(CMISScope.FOLDER, new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_GET_CHILDREN, PermissionService.READ_CHILDREN));
registerEvaluator(CMISScope.FOLDER, new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_CREATE_DOCUMENT, PermissionService.CREATE_CHILDREN));
registerEvaluator(CMISScope.FOLDER, new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_CREATE_FOLDER, PermissionService.CREATE_CHILDREN));
registerEvaluator(CMISScope.FOLDER, new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_CREATE_RELATIONSHIP, PermissionService.CREATE_ASSOCIATIONS));
registerEvaluator(CMISScope.FOLDER, new RootActionEvaluator(new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_DELETE_TREE, PermissionService.DELETE_NODE), false));
registerEvaluator(CMISScope.FOLDER, new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_GET_ACL, PermissionService.READ_PERMISSIONS));
registerEvaluator(CMISScope.FOLDER, new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_APPLY_ACL, PermissionService.CHANGE_PERMISSIONS));
registerEvaluator(CMISScope.FOLDER, new PermissionActionEvaluator<NodeRef>(serviceRegistry, CMISAllowedActionEnum.CAN_GET_CHILDREN, DEFAULT_ALLOWING,
PermissionService.READ_CHILDREN));
registerEvaluator(CMISScope.FOLDER, new PermissionActionEvaluator<NodeRef>(serviceRegistry, CMISAllowedActionEnum.CAN_CREATE_DOCUMENT, DEFAULT_ALLOWING,
PermissionService.CREATE_CHILDREN));
registerEvaluator(CMISScope.FOLDER, new PermissionActionEvaluator<NodeRef>(serviceRegistry, CMISAllowedActionEnum.CAN_CREATE_FOLDER, DEFAULT_ALLOWING,
PermissionService.CREATE_CHILDREN));
registerEvaluator(CMISScope.FOLDER, new PermissionActionEvaluator<NodeRef>(serviceRegistry, CMISAllowedActionEnum.CAN_CREATE_RELATIONSHIP, DEFAULT_ALLOWING,
PermissionService.CREATE_ASSOCIATIONS));
registerEvaluator(CMISScope.FOLDER, new RootActionEvaluator<NodeRef>(new PermissionActionEvaluator<NodeRef>(serviceRegistry, CMISAllowedActionEnum.CAN_DELETE_TREE,
DEFAULT_ALLOWING, PermissionService.DELETE_NODE), false));
registerEvaluator(CMISScope.FOLDER, new PermissionActionEvaluator<NodeRef>(serviceRegistry, CMISAllowedActionEnum.CAN_GET_ACL, DEFAULT_ALLOWING,
PermissionService.READ_PERMISSIONS));
registerEvaluator(CMISScope.FOLDER, new PermissionActionEvaluator<Object>(serviceRegistry, CMISAllowedActionEnum.CAN_APPLY_ACL, DEFAULT_ALLOWING,
PermissionService.CHANGE_PERMISSIONS));
registerEvaluator(CMISScope.RELATIONSHIP, new FixedValueActionEvaluator<AssociationRef>(serviceRegistry, CMISAllowedActionEnum.CAN_DELETE_OBJECT, true));
registerEvaluator(CMISScope.RELATIONSHIP, new FixedValueActionEvaluator<AssociationRef>(serviceRegistry, CMISAllowedActionEnum.CAN_UPDATE_PROPERTIES, false));

View File

@@ -1,919 +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.cmis.mapping;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.alfresco.cmis.CMISConstraintException;
import org.alfresco.cmis.CMISDictionaryModel;
import org.alfresco.cmis.CMISInvalidArgumentException;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.evaluator.ComparePropertyValueEvaluator;
import org.alfresco.repo.action.executer.AddFeaturesActionExecuter;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.repo.version.VersionModel;
import org.alfresco.service.cmr.action.ActionCondition;
import org.alfresco.service.cmr.lock.LockType;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.rule.Rule;
import org.alfresco.service.cmr.rule.RuleType;
import org.alfresco.service.cmr.version.Version;
import org.alfresco.service.cmr.version.VersionType;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl;
import org.springframework.extensions.webscripts.GUID;
public class CMISPropertyServiceTest extends BaseCMISTest
{
public void testBasicFolder() throws Exception
{
NodeRef folder = fileFolderService.create(cmisService.getDefaultRootNodeRef(), "BaseFolder", ContentModel.TYPE_FOLDER).getNodeRef();
Map<String, Serializable> properties = cmisService.getProperties(folder);
assertEquals(folder.toString(), properties.get(CMISDictionaryModel.PROP_OBJECT_ID));
assertEquals(CMISDictionaryModel.FOLDER_TYPE_ID.getId(), properties.get(CMISDictionaryModel.PROP_OBJECT_TYPE_ID));
assertEquals(CMISDictionaryModel.FOLDER_TYPE_ID.getId(), properties.get(CMISDictionaryModel.PROP_BASE_TYPE_ID));
assertEquals(authenticationComponent.getCurrentUserName(), properties.get(CMISDictionaryModel.PROP_CREATED_BY));
assertNotNull(properties.get(CMISDictionaryModel.PROP_CREATION_DATE));
assertEquals(authenticationComponent.getCurrentUserName(), properties.get(CMISDictionaryModel.PROP_LAST_MODIFIED_BY));
assertNotNull(properties.get(CMISDictionaryModel.PROP_LAST_MODIFICATION_DATE));
assertNull(properties.get(CMISDictionaryModel.PROP_CHANGE_TOKEN));
assertEquals("BaseFolder", properties.get(CMISDictionaryModel.PROP_NAME));
assertNull(properties.get(CMISDictionaryModel.PROP_IS_IMMUTABLE));
assertNull(properties.get(CMISDictionaryModel.PROP_IS_LATEST_VERSION));
assertNull(properties.get(CMISDictionaryModel.PROP_IS_MAJOR_VERSION));
assertNull(properties.get(CMISDictionaryModel.PROP_IS_LATEST_MAJOR_VERSION));
assertNull(properties.get(CMISDictionaryModel.PROP_VERSION_LABEL));
assertNull(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_ID));
assertNull(properties.get(CMISDictionaryModel.PROP_IS_VERSION_SERIES_CHECKED_OUT));
assertNull(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_BY));
assertNull(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_ID));
assertNull(properties.get(CMISDictionaryModel.PROP_CHECKIN_COMMENT));
assertNull(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_LENGTH));
assertNull(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_MIME_TYPE));
assertNull(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_FILENAME));
assertNull(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_ID));
assertEquals(cmisService.getDefaultRootNodeRef().toString(), properties.get(CMISDictionaryModel.PROP_PARENT_ID));
assertNull(properties.get(CMISDictionaryModel.PROP_ALLOWED_CHILD_OBJECT_TYPE_IDS));
}
public void testBasicDocument() throws Exception
{
NodeRef content = fileFolderService.create(rootNodeRef, "BaseContent", ContentModel.TYPE_CONTENT).getNodeRef();
Map<String, Serializable> properties = cmisService.getProperties(content);
assertEquals(properties.get(CMISDictionaryModel.PROP_OBJECT_ID), content.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_OBJECT_TYPE_ID), CMISDictionaryModel.DOCUMENT_TYPE_ID.getId());
assertEquals(properties.get(CMISDictionaryModel.PROP_BASE_TYPE_ID), CMISDictionaryModel.DOCUMENT_TYPE_ID.getId());
assertEquals(properties.get(CMISDictionaryModel.PROP_CREATED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(properties.get(CMISDictionaryModel.PROP_CREATION_DATE));
assertEquals(properties.get(CMISDictionaryModel.PROP_LAST_MODIFIED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(properties.get(CMISDictionaryModel.PROP_LAST_MODIFICATION_DATE));
assertNull(properties.get(CMISDictionaryModel.PROP_CHANGE_TOKEN));
assertEquals(properties.get(CMISDictionaryModel.PROP_NAME), "BaseContent");
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_IMMUTABLE), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_VERSION), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_MAJOR_VERSION), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_MAJOR_VERSION), false);
assertNotNull(properties.get(CMISDictionaryModel.PROP_VERSION_LABEL));
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_ID), content.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_VERSION_SERIES_CHECKED_OUT), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_BY), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_ID), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_CHECKIN_COMMENT), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_LENGTH), 0L);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_MIME_TYPE), ""); // we don't unnecessarily guess/store (see FileFolderService.createImpl)
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_FILENAME), "BaseContent");
assertNull(properties.get(CMISDictionaryModel.PROP_PARENT_ID));
assertNull(properties.get(CMISDictionaryModel.PROP_ALLOWED_CHILD_OBJECT_TYPE_IDS));
}
public void testContentProperties() throws Exception
{
NodeRef content = fileFolderService.create(rootNodeRef, "BaseContent", ContentModel.TYPE_CONTENT).getNodeRef();
Map<String, Serializable> properties = cmisService.getProperties(content);
assertEquals(properties.get(CMISDictionaryModel.PROP_OBJECT_ID), content.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_OBJECT_TYPE_ID), CMISDictionaryModel.DOCUMENT_TYPE_ID.getId());
assertEquals(properties.get(CMISDictionaryModel.PROP_BASE_TYPE_ID), CMISDictionaryModel.DOCUMENT_TYPE_ID.getId());
assertEquals(properties.get(CMISDictionaryModel.PROP_CREATED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(properties.get(CMISDictionaryModel.PROP_CREATION_DATE));
assertEquals(properties.get(CMISDictionaryModel.PROP_LAST_MODIFIED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(properties.get(CMISDictionaryModel.PROP_LAST_MODIFICATION_DATE));
assertNull(properties.get(CMISDictionaryModel.PROP_CHANGE_TOKEN));
assertEquals(properties.get(CMISDictionaryModel.PROP_NAME), "BaseContent");
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_IMMUTABLE), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_VERSION), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_MAJOR_VERSION), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_MAJOR_VERSION), false);
assertNotNull(properties.get(CMISDictionaryModel.PROP_VERSION_LABEL));
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_ID), content.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_VERSION_SERIES_CHECKED_OUT), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_BY), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_ID), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_CHECKIN_COMMENT), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_LENGTH), 0L);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_MIME_TYPE), "");
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_FILENAME), "BaseContent");
assertNull(properties.get(CMISDictionaryModel.PROP_PARENT_ID));
assertNull(properties.get(CMISDictionaryModel.PROP_ALLOWED_CHILD_OBJECT_TYPE_IDS));
ContentData contentData = new ContentData(null, "text/plain", 0L, "UTF-8", Locale.UK);
nodeService.setProperty(content, ContentModel.PROP_CONTENT, contentData);
ContentWriter writer = serviceRegistry.getContentService().getWriter(content, ContentModel.PROP_CONTENT, true);
writer.setEncoding("UTF-8");
writer.putContent("The quick brown fox jumped over the lazy dog and ate the Alfresco Tutorial, in pdf format, along with the following stop words; a an and are"
+ " as at be but by for if in into is it no not of on or such that the their then there these they this to was will with: "
+ " and random charcters \u00E0\u00EA\u00EE\u00F0\u00F1\u00F6\u00FB\u00FF");
long size = writer.getSize();
properties = cmisService.getProperties(content);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_LENGTH), size);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_MIME_TYPE), "text/plain");
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_FILENAME), "BaseContent");
assertNotNull(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_ID));
}
public void testLock() throws Exception
{
NodeRef content = fileFolderService.create(rootNodeRef, "BaseContent", ContentModel.TYPE_CONTENT).getNodeRef();
Map<String, Serializable> properties = cmisService.getProperties(content);
assertEquals(properties.get(CMISDictionaryModel.PROP_OBJECT_ID), content.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_OBJECT_TYPE_ID), CMISDictionaryModel.DOCUMENT_TYPE_ID.getId());
assertEquals(properties.get(CMISDictionaryModel.PROP_BASE_TYPE_ID), CMISDictionaryModel.DOCUMENT_TYPE_ID.getId());
assertEquals(properties.get(CMISDictionaryModel.PROP_CREATED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(properties.get(CMISDictionaryModel.PROP_CREATION_DATE));
assertEquals(properties.get(CMISDictionaryModel.PROP_LAST_MODIFIED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(properties.get(CMISDictionaryModel.PROP_LAST_MODIFICATION_DATE));
assertNull(properties.get(CMISDictionaryModel.PROP_CHANGE_TOKEN));
assertEquals(properties.get(CMISDictionaryModel.PROP_NAME), "BaseContent");
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_IMMUTABLE), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_VERSION), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_MAJOR_VERSION), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_MAJOR_VERSION), false);
assertNotNull(properties.get(CMISDictionaryModel.PROP_VERSION_LABEL));
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_ID), content.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_VERSION_SERIES_CHECKED_OUT), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_BY), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_ID), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_CHECKIN_COMMENT), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_LENGTH), 0L);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_MIME_TYPE), "");
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_FILENAME), "BaseContent");
assertNull(properties.get(CMISDictionaryModel.PROP_PARENT_ID));
assertNull(properties.get(CMISDictionaryModel.PROP_ALLOWED_CHILD_OBJECT_TYPE_IDS));
serviceRegistry.getLockService().lock(content, LockType.READ_ONLY_LOCK);
properties = cmisService.getProperties(content);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_IMMUTABLE), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_VERSION), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_MAJOR_VERSION), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_MAJOR_VERSION), false);
assertNotNull(properties.get(CMISDictionaryModel.PROP_VERSION_LABEL));
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_ID), content.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_VERSION_SERIES_CHECKED_OUT), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_BY), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_ID), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_CHECKIN_COMMENT), null);
serviceRegistry.getLockService().unlock(content);
properties = cmisService.getProperties(content);
assertEquals(properties.get(CMISDictionaryModel.PROP_OBJECT_ID), content.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_OBJECT_TYPE_ID), CMISDictionaryModel.DOCUMENT_TYPE_ID.getId());
assertEquals(properties.get(CMISDictionaryModel.PROP_BASE_TYPE_ID), CMISDictionaryModel.DOCUMENT_TYPE_ID.getId());
assertEquals(properties.get(CMISDictionaryModel.PROP_CREATED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(properties.get(CMISDictionaryModel.PROP_CREATION_DATE));
assertEquals(properties.get(CMISDictionaryModel.PROP_LAST_MODIFIED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(properties.get(CMISDictionaryModel.PROP_LAST_MODIFICATION_DATE));
assertNull(properties.get(CMISDictionaryModel.PROP_CHANGE_TOKEN));
assertEquals(properties.get(CMISDictionaryModel.PROP_NAME), "BaseContent");
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_IMMUTABLE), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_VERSION), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_MAJOR_VERSION), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_MAJOR_VERSION), false);
assertNotNull(properties.get(CMISDictionaryModel.PROP_VERSION_LABEL));
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_ID), content.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_VERSION_SERIES_CHECKED_OUT), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_BY), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_ID), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_CHECKIN_COMMENT), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_LENGTH), 0L);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_MIME_TYPE), ""); // we don't unnecessarily guess/store (see FileFolderService.createImpl)
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_FILENAME), "BaseContent");
assertNull(properties.get(CMISDictionaryModel.PROP_PARENT_ID));
assertNull(properties.get(CMISDictionaryModel.PROP_ALLOWED_CHILD_OBJECT_TYPE_IDS));
}
public void testCheckOut() throws Exception
{
NodeRef content = fileFolderService.create(rootNodeRef, "BaseContent", ContentModel.TYPE_CONTENT).getNodeRef();
Map<String, Serializable> properties = cmisService.getProperties(content);
assertEquals(properties.get(CMISDictionaryModel.PROP_OBJECT_ID), content.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_OBJECT_TYPE_ID), CMISDictionaryModel.DOCUMENT_TYPE_ID.getId());
assertEquals(properties.get(CMISDictionaryModel.PROP_BASE_TYPE_ID), CMISDictionaryModel.DOCUMENT_TYPE_ID.getId());
assertEquals(properties.get(CMISDictionaryModel.PROP_CREATED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(properties.get(CMISDictionaryModel.PROP_CREATION_DATE));
assertEquals(properties.get(CMISDictionaryModel.PROP_LAST_MODIFIED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(properties.get(CMISDictionaryModel.PROP_LAST_MODIFICATION_DATE));
assertNull(properties.get(CMISDictionaryModel.PROP_CHANGE_TOKEN));
assertEquals(properties.get(CMISDictionaryModel.PROP_NAME), "BaseContent");
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_IMMUTABLE), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_VERSION), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_MAJOR_VERSION), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_MAJOR_VERSION), false);
assertNotNull(properties.get(CMISDictionaryModel.PROP_VERSION_LABEL));
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_ID), content.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_VERSION_SERIES_CHECKED_OUT), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_BY), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_ID), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_CHECKIN_COMMENT), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_LENGTH), 0L);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_MIME_TYPE), "");
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_FILENAME), "BaseContent");
assertNull(properties.get(CMISDictionaryModel.PROP_PARENT_ID));
assertNull(properties.get(CMISDictionaryModel.PROP_ALLOWED_CHILD_OBJECT_TYPE_IDS));
NodeRef pwc = serviceRegistry.getCheckOutCheckInService().checkout(content);
properties = cmisService.getProperties(content);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_IMMUTABLE), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_VERSION), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_MAJOR_VERSION), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_MAJOR_VERSION), false);
assertNotNull(properties.get(CMISDictionaryModel.PROP_VERSION_LABEL));
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_ID), content.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_VERSION_SERIES_CHECKED_OUT), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_BY), authenticationComponent.getCurrentUserName());
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_ID), pwc.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_CHECKIN_COMMENT), null);
properties = cmisService.getProperties(pwc);
assertEquals(properties.get(CMISDictionaryModel.PROP_OBJECT_ID), pwc.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_OBJECT_TYPE_ID), CMISDictionaryModel.DOCUMENT_TYPE_ID.getId());
assertEquals(properties.get(CMISDictionaryModel.PROP_BASE_TYPE_ID), CMISDictionaryModel.DOCUMENT_TYPE_ID.getId());
assertEquals(properties.get(CMISDictionaryModel.PROP_CREATED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(properties.get(CMISDictionaryModel.PROP_CREATION_DATE));
assertEquals(properties.get(CMISDictionaryModel.PROP_LAST_MODIFIED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(properties.get(CMISDictionaryModel.PROP_LAST_MODIFICATION_DATE));
assertNull(properties.get(CMISDictionaryModel.PROP_CHANGE_TOKEN));
assertEquals(properties.get(CMISDictionaryModel.PROP_NAME), "BaseContent (Working Copy)");
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_IMMUTABLE), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_VERSION), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_MAJOR_VERSION), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_MAJOR_VERSION), false);
assertNotNull(properties.get(CMISDictionaryModel.PROP_VERSION_LABEL));
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_ID), content.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_VERSION_SERIES_CHECKED_OUT), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_BY), authenticationComponent.getCurrentUserName());
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_ID), pwc.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_CHECKIN_COMMENT), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_LENGTH), 0L);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_MIME_TYPE), "");
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_FILENAME), "BaseContent (Working Copy)");
assertNull(properties.get(CMISDictionaryModel.PROP_PARENT_ID));
assertNull(properties.get(CMISDictionaryModel.PROP_ALLOWED_CHILD_OBJECT_TYPE_IDS));
serviceRegistry.getCheckOutCheckInService().cancelCheckout(pwc);
properties = cmisService.getProperties(content);
assertEquals(properties.get(CMISDictionaryModel.PROP_OBJECT_ID), content.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_OBJECT_TYPE_ID), CMISDictionaryModel.DOCUMENT_TYPE_ID.getId());
assertEquals(properties.get(CMISDictionaryModel.PROP_BASE_TYPE_ID), CMISDictionaryModel.DOCUMENT_TYPE_ID.getId());
assertEquals(properties.get(CMISDictionaryModel.PROP_CREATED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(properties.get(CMISDictionaryModel.PROP_CREATION_DATE));
assertEquals(properties.get(CMISDictionaryModel.PROP_LAST_MODIFIED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(properties.get(CMISDictionaryModel.PROP_LAST_MODIFICATION_DATE));
assertNull(properties.get(CMISDictionaryModel.PROP_CHANGE_TOKEN));
assertEquals(properties.get(CMISDictionaryModel.PROP_NAME), "BaseContent");
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_IMMUTABLE), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_VERSION), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_MAJOR_VERSION), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_MAJOR_VERSION), false);
assertNotNull(properties.get(CMISDictionaryModel.PROP_VERSION_LABEL));
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_ID), content.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_VERSION_SERIES_CHECKED_OUT), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_BY), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_ID), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_CHECKIN_COMMENT), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_LENGTH), 0L);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_MIME_TYPE), "");
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_FILENAME), "BaseContent");
assertNull(properties.get(CMISDictionaryModel.PROP_PARENT_ID));
assertNull(properties.get(CMISDictionaryModel.PROP_ALLOWED_CHILD_OBJECT_TYPE_IDS));
pwc = serviceRegistry.getCheckOutCheckInService().checkout(content);
properties = cmisService.getProperties(content);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_IMMUTABLE), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_VERSION), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_MAJOR_VERSION), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_MAJOR_VERSION), false);
assertNotNull(properties.get(CMISDictionaryModel.PROP_VERSION_LABEL));
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_ID), content.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_VERSION_SERIES_CHECKED_OUT), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_BY), authenticationComponent.getCurrentUserName());
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_ID), pwc.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_CHECKIN_COMMENT), null);
properties = cmisService.getProperties(pwc);
assertEquals(properties.get(CMISDictionaryModel.PROP_OBJECT_ID), pwc.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_OBJECT_TYPE_ID), CMISDictionaryModel.DOCUMENT_TYPE_ID.getId());
assertEquals(properties.get(CMISDictionaryModel.PROP_BASE_TYPE_ID), CMISDictionaryModel.DOCUMENT_TYPE_ID.getId());
assertEquals(properties.get(CMISDictionaryModel.PROP_CREATED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(properties.get(CMISDictionaryModel.PROP_CREATION_DATE));
assertEquals(properties.get(CMISDictionaryModel.PROP_LAST_MODIFIED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(properties.get(CMISDictionaryModel.PROP_LAST_MODIFICATION_DATE));
assertNull(properties.get(CMISDictionaryModel.PROP_CHANGE_TOKEN));
assertEquals(properties.get(CMISDictionaryModel.PROP_NAME), "BaseContent (Working Copy)");
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_IMMUTABLE), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_VERSION), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_MAJOR_VERSION), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_MAJOR_VERSION), false);
assertNotNull(properties.get(CMISDictionaryModel.PROP_VERSION_LABEL));
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_ID), content.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_VERSION_SERIES_CHECKED_OUT), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_BY), authenticationComponent.getCurrentUserName());
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_ID), pwc.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_CHECKIN_COMMENT), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_LENGTH), 0L);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_MIME_TYPE), "");
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_FILENAME), "BaseContent (Working Copy)");
assertNull(properties.get(CMISDictionaryModel.PROP_PARENT_ID));
assertNull(properties.get(CMISDictionaryModel.PROP_ALLOWED_CHILD_OBJECT_TYPE_IDS));
serviceRegistry.getCheckOutCheckInService().checkin(pwc, null);
properties = cmisService.getProperties(content);
assertEquals(properties.get(CMISDictionaryModel.PROP_OBJECT_ID), content.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_OBJECT_TYPE_ID), CMISDictionaryModel.DOCUMENT_TYPE_ID.getId());
assertEquals(properties.get(CMISDictionaryModel.PROP_BASE_TYPE_ID), CMISDictionaryModel.DOCUMENT_TYPE_ID.getId());
assertEquals(properties.get(CMISDictionaryModel.PROP_CREATED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(properties.get(CMISDictionaryModel.PROP_CREATION_DATE));
assertEquals(properties.get(CMISDictionaryModel.PROP_LAST_MODIFIED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(properties.get(CMISDictionaryModel.PROP_LAST_MODIFICATION_DATE));
assertNull(properties.get(CMISDictionaryModel.PROP_CHANGE_TOKEN));
assertEquals(properties.get(CMISDictionaryModel.PROP_NAME), "BaseContent");
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_IMMUTABLE), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_VERSION), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_MAJOR_VERSION), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_MAJOR_VERSION), false);
assertNotNull(properties.get(CMISDictionaryModel.PROP_VERSION_LABEL));
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_ID), content.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_VERSION_SERIES_CHECKED_OUT), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_BY), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_ID), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_CHECKIN_COMMENT), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_LENGTH), 0L);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_MIME_TYPE), "");
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_FILENAME), "BaseContent");
assertNull(properties.get(CMISDictionaryModel.PROP_PARENT_ID));
assertNull(properties.get(CMISDictionaryModel.PROP_ALLOWED_CHILD_OBJECT_TYPE_IDS));
}
public void testVersioning() throws Exception
{
NodeRef content = fileFolderService.create(rootNodeRef, "BaseContent", ContentModel.TYPE_CONTENT).getNodeRef();
Map<String, Serializable> properties = cmisService.getProperties(content);
assertEquals(properties.get(CMISDictionaryModel.PROP_OBJECT_ID), content.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_OBJECT_TYPE_ID), CMISDictionaryModel.DOCUMENT_TYPE_ID.getId());
assertEquals(properties.get(CMISDictionaryModel.PROP_BASE_TYPE_ID), CMISDictionaryModel.DOCUMENT_TYPE_ID.getId());
assertEquals(properties.get(CMISDictionaryModel.PROP_CREATED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(properties.get(CMISDictionaryModel.PROP_CREATION_DATE));
assertEquals(properties.get(CMISDictionaryModel.PROP_LAST_MODIFIED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(properties.get(CMISDictionaryModel.PROP_LAST_MODIFICATION_DATE));
assertNull(properties.get(CMISDictionaryModel.PROP_CHANGE_TOKEN));
assertEquals(properties.get(CMISDictionaryModel.PROP_NAME), "BaseContent");
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_IMMUTABLE), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_VERSION), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_MAJOR_VERSION), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_MAJOR_VERSION), false);
assertNotNull(properties.get(CMISDictionaryModel.PROP_VERSION_LABEL));
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_ID), content.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_VERSION_SERIES_CHECKED_OUT), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_BY), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_ID), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_CHECKIN_COMMENT), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_LENGTH), 0L);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_MIME_TYPE), "");
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_FILENAME), "BaseContent");
assertNull(properties.get(CMISDictionaryModel.PROP_PARENT_ID));
assertNull(properties.get(CMISDictionaryModel.PROP_ALLOWED_CHILD_OBJECT_TYPE_IDS));
nodeService.addAspect(content, ContentModel.ASPECT_VERSIONABLE, null);
properties = cmisService.getProperties(content);
assertEquals(properties.get(CMISDictionaryModel.PROP_OBJECT_ID), content.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_OBJECT_TYPE_ID), CMISDictionaryModel.DOCUMENT_TYPE_ID.getId());
assertEquals(properties.get(CMISDictionaryModel.PROP_BASE_TYPE_ID), CMISDictionaryModel.DOCUMENT_TYPE_ID.getId());
assertEquals(properties.get(CMISDictionaryModel.PROP_CREATED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(properties.get(CMISDictionaryModel.PROP_CREATION_DATE));
assertEquals(properties.get(CMISDictionaryModel.PROP_LAST_MODIFIED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(properties.get(CMISDictionaryModel.PROP_LAST_MODIFICATION_DATE));
assertNull(properties.get(CMISDictionaryModel.PROP_CHANGE_TOKEN));
assertEquals(properties.get(CMISDictionaryModel.PROP_NAME), "BaseContent");
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_IMMUTABLE), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_VERSION), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_MAJOR_VERSION), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_MAJOR_VERSION), false);
assertNotNull(properties.get(CMISDictionaryModel.PROP_VERSION_LABEL));
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_ID), content.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_VERSION_SERIES_CHECKED_OUT), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_BY), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_ID), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_CHECKIN_COMMENT), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_LENGTH), 0L);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_MIME_TYPE), "");
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_FILENAME), "BaseContent");
assertNull(properties.get(CMISDictionaryModel.PROP_PARENT_ID));
assertNull(properties.get(CMISDictionaryModel.PROP_ALLOWED_CHILD_OBJECT_TYPE_IDS));
NodeRef pwc = serviceRegistry.getCheckOutCheckInService().checkout(content);
properties = cmisService.getProperties(content);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_IMMUTABLE), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_VERSION), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_MAJOR_VERSION), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_MAJOR_VERSION), false);
assertNotNull(properties.get(CMISDictionaryModel.PROP_VERSION_LABEL));
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_ID), content.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_VERSION_SERIES_CHECKED_OUT), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_BY), authenticationComponent.getCurrentUserName());
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_ID), pwc.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_CHECKIN_COMMENT), null);
properties = cmisService.getProperties(pwc);
assertEquals(properties.get(CMISDictionaryModel.PROP_OBJECT_ID), pwc.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_OBJECT_TYPE_ID), CMISDictionaryModel.DOCUMENT_TYPE_ID.getId());
assertEquals(properties.get(CMISDictionaryModel.PROP_BASE_TYPE_ID), CMISDictionaryModel.DOCUMENT_TYPE_ID.getId());
assertEquals(properties.get(CMISDictionaryModel.PROP_CREATED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(properties.get(CMISDictionaryModel.PROP_CREATION_DATE));
assertEquals(properties.get(CMISDictionaryModel.PROP_LAST_MODIFIED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(properties.get(CMISDictionaryModel.PROP_LAST_MODIFICATION_DATE));
assertNull(properties.get(CMISDictionaryModel.PROP_CHANGE_TOKEN));
assertEquals(properties.get(CMISDictionaryModel.PROP_NAME), "BaseContent (Working Copy)");
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_IMMUTABLE), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_VERSION), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_MAJOR_VERSION), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_MAJOR_VERSION), false);
assertNotNull(properties.get(CMISDictionaryModel.PROP_VERSION_LABEL));
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_ID), content.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_VERSION_SERIES_CHECKED_OUT), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_BY), authenticationComponent.getCurrentUserName());
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_ID), pwc.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_CHECKIN_COMMENT), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_LENGTH), 0L);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_MIME_TYPE), "");
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_FILENAME), "BaseContent (Working Copy)");
assertNull(properties.get(CMISDictionaryModel.PROP_PARENT_ID));
assertNull(properties.get(CMISDictionaryModel.PROP_ALLOWED_CHILD_OBJECT_TYPE_IDS));
serviceRegistry.getCheckOutCheckInService().cancelCheckout(pwc);
properties = cmisService.getProperties(content);
assertEquals(properties.get(CMISDictionaryModel.PROP_OBJECT_ID), content.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_OBJECT_TYPE_ID), CMISDictionaryModel.DOCUMENT_TYPE_ID.getId());
assertEquals(properties.get(CMISDictionaryModel.PROP_BASE_TYPE_ID), CMISDictionaryModel.DOCUMENT_TYPE_ID.getId());
assertEquals(properties.get(CMISDictionaryModel.PROP_CREATED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(properties.get(CMISDictionaryModel.PROP_CREATION_DATE));
assertEquals(properties.get(CMISDictionaryModel.PROP_LAST_MODIFIED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(properties.get(CMISDictionaryModel.PROP_LAST_MODIFICATION_DATE));
assertNull(properties.get(CMISDictionaryModel.PROP_CHANGE_TOKEN));
assertEquals(properties.get(CMISDictionaryModel.PROP_NAME), "BaseContent");
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_IMMUTABLE), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_VERSION), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_MAJOR_VERSION), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_MAJOR_VERSION), false);
assertNotNull(properties.get(CMISDictionaryModel.PROP_VERSION_LABEL));
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_ID), content.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_VERSION_SERIES_CHECKED_OUT), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_BY), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_ID), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_CHECKIN_COMMENT), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_LENGTH), 0L);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_MIME_TYPE), "");
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_FILENAME), "BaseContent");
assertNull(properties.get(CMISDictionaryModel.PROP_PARENT_ID));
assertNull(properties.get(CMISDictionaryModel.PROP_ALLOWED_CHILD_OBJECT_TYPE_IDS));
pwc = serviceRegistry.getCheckOutCheckInService().checkout(content);
properties = cmisService.getProperties(content);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_IMMUTABLE), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_VERSION), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_MAJOR_VERSION), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_MAJOR_VERSION), false);
assertNotNull(properties.get(CMISDictionaryModel.PROP_VERSION_LABEL));
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_ID), content.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_VERSION_SERIES_CHECKED_OUT), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_BY), authenticationComponent.getCurrentUserName());
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_ID), pwc.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_CHECKIN_COMMENT), null);
properties = cmisService.getProperties(pwc);
assertEquals(properties.get(CMISDictionaryModel.PROP_OBJECT_ID), pwc.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_OBJECT_TYPE_ID), CMISDictionaryModel.DOCUMENT_TYPE_ID.getId());
assertEquals(properties.get(CMISDictionaryModel.PROP_BASE_TYPE_ID), CMISDictionaryModel.DOCUMENT_TYPE_ID.getId());
assertEquals(properties.get(CMISDictionaryModel.PROP_CREATED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(properties.get(CMISDictionaryModel.PROP_CREATION_DATE));
assertEquals(properties.get(CMISDictionaryModel.PROP_LAST_MODIFIED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(properties.get(CMISDictionaryModel.PROP_LAST_MODIFICATION_DATE));
assertNull(properties.get(CMISDictionaryModel.PROP_CHANGE_TOKEN));
assertEquals(properties.get(CMISDictionaryModel.PROP_NAME), "BaseContent (Working Copy)");
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_IMMUTABLE), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_VERSION), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_MAJOR_VERSION), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_MAJOR_VERSION), false);
assertNotNull(properties.get(CMISDictionaryModel.PROP_VERSION_LABEL));
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_ID), content.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_VERSION_SERIES_CHECKED_OUT), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_BY), authenticationComponent.getCurrentUserName());
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_ID), pwc.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_CHECKIN_COMMENT), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_LENGTH), 0L);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_MIME_TYPE), "");
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_FILENAME), "BaseContent (Working Copy)");
assertNull(properties.get(CMISDictionaryModel.PROP_PARENT_ID));
assertNull(properties.get(CMISDictionaryModel.PROP_ALLOWED_CHILD_OBJECT_TYPE_IDS));
Map<String, Serializable> versionProperties = new HashMap<String, Serializable>();
versionProperties.put(Version.PROP_DESCRIPTION, "Meep");
versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MAJOR);
serviceRegistry.getCheckOutCheckInService().checkin(pwc, versionProperties);
properties = cmisService.getProperties(content);
assertEquals(properties.get(CMISDictionaryModel.PROP_OBJECT_TYPE_ID), CMISDictionaryModel.DOCUMENT_TYPE_ID.getId());
assertEquals(properties.get(CMISDictionaryModel.PROP_BASE_TYPE_ID), CMISDictionaryModel.DOCUMENT_TYPE_ID.getId());
assertEquals(properties.get(CMISDictionaryModel.PROP_CREATED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(properties.get(CMISDictionaryModel.PROP_CREATION_DATE));
assertEquals(properties.get(CMISDictionaryModel.PROP_LAST_MODIFIED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(properties.get(CMISDictionaryModel.PROP_LAST_MODIFICATION_DATE));
assertNull(properties.get(CMISDictionaryModel.PROP_CHANGE_TOKEN));
assertEquals(properties.get(CMISDictionaryModel.PROP_NAME), "BaseContent");
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_IMMUTABLE), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_VERSION), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_MAJOR_VERSION), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_MAJOR_VERSION), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_LABEL), "1.0");
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_ID), content.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_VERSION_SERIES_CHECKED_OUT), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_BY), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_ID), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_LENGTH), 0L);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_MIME_TYPE), "");
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_FILENAME), "BaseContent");
assertNull(properties.get(CMISDictionaryModel.PROP_PARENT_ID));
assertNull(properties.get(CMISDictionaryModel.PROP_ALLOWED_CHILD_OBJECT_TYPE_IDS));
pwc = serviceRegistry.getCheckOutCheckInService().checkout(content);
properties = cmisService.getProperties(content);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_IMMUTABLE), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_VERSION), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_MAJOR_VERSION), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_MAJOR_VERSION), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_LABEL), "1.0");
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_ID), content.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_VERSION_SERIES_CHECKED_OUT), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_BY), authenticationComponent.getCurrentUserName());
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_ID), pwc.toString());
properties = cmisService.getProperties(pwc);
assertEquals(properties.get(CMISDictionaryModel.PROP_OBJECT_ID), pwc.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_OBJECT_TYPE_ID), CMISDictionaryModel.DOCUMENT_TYPE_ID.getId());
assertEquals(properties.get(CMISDictionaryModel.PROP_BASE_TYPE_ID), CMISDictionaryModel.DOCUMENT_TYPE_ID.getId());
assertEquals(properties.get(CMISDictionaryModel.PROP_CREATED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(properties.get(CMISDictionaryModel.PROP_CREATION_DATE));
assertEquals(properties.get(CMISDictionaryModel.PROP_LAST_MODIFIED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(properties.get(CMISDictionaryModel.PROP_LAST_MODIFICATION_DATE));
assertNull(properties.get(CMISDictionaryModel.PROP_CHANGE_TOKEN));
assertEquals(properties.get(CMISDictionaryModel.PROP_NAME), "BaseContent (Working Copy)");
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_IMMUTABLE), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_VERSION), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_MAJOR_VERSION), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_MAJOR_VERSION), false);
assertNotNull(properties.get(CMISDictionaryModel.PROP_VERSION_LABEL));
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_ID), content.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_VERSION_SERIES_CHECKED_OUT), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_BY), authenticationComponent.getCurrentUserName());
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_ID), pwc.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_CHECKIN_COMMENT), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_LENGTH), 0L);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_MIME_TYPE), "");
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_FILENAME), "BaseContent (Working Copy)");
assertNull(properties.get(CMISDictionaryModel.PROP_PARENT_ID));
assertNull(properties.get(CMISDictionaryModel.PROP_ALLOWED_CHILD_OBJECT_TYPE_IDS));
versionProperties = new HashMap<String, Serializable>();
versionProperties.put(Version.PROP_DESCRIPTION, "Woof");
versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MINOR);
serviceRegistry.getCheckOutCheckInService().checkin(pwc, versionProperties);
properties = cmisService.getProperties(content);
assertEquals(properties.get(CMISDictionaryModel.PROP_OBJECT_TYPE_ID), CMISDictionaryModel.DOCUMENT_TYPE_ID.getId());
assertEquals(properties.get(CMISDictionaryModel.PROP_BASE_TYPE_ID), CMISDictionaryModel.DOCUMENT_TYPE_ID.getId());
assertEquals(properties.get(CMISDictionaryModel.PROP_CREATED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(properties.get(CMISDictionaryModel.PROP_CREATION_DATE));
assertEquals(properties.get(CMISDictionaryModel.PROP_LAST_MODIFIED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(properties.get(CMISDictionaryModel.PROP_LAST_MODIFICATION_DATE));
assertNull(properties.get(CMISDictionaryModel.PROP_CHANGE_TOKEN));
assertEquals(properties.get(CMISDictionaryModel.PROP_NAME), "BaseContent");
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_IMMUTABLE), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_VERSION), true);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_MAJOR_VERSION), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_LATEST_MAJOR_VERSION), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_LABEL), "1.1");
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_ID), content.toString());
assertEquals(properties.get(CMISDictionaryModel.PROP_IS_VERSION_SERIES_CHECKED_OUT), false);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_BY), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_ID), null);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_LENGTH), 0L);
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_MIME_TYPE), "");
assertEquals(properties.get(CMISDictionaryModel.PROP_CONTENT_STREAM_FILENAME), "BaseContent");
assertNull(properties.get(CMISDictionaryModel.PROP_PARENT_ID));
assertNull(properties.get(CMISDictionaryModel.PROP_ALLOWED_CHILD_OBJECT_TYPE_IDS));
}
public void testSinglePropertyFolderAccess() throws Exception
{
NodeRef folder = fileFolderService.create(rootNodeRef, "BaseFolder", ContentModel.TYPE_FOLDER).getNodeRef();
assertEquals(cmisService.getProperty(folder, CMISDictionaryModel.PROP_OBJECT_ID), folder.toString());
assertEquals(cmisService.getProperty(folder, CMISDictionaryModel.PROP_OBJECT_TYPE_ID), CMISDictionaryModel.FOLDER_TYPE_ID.getId());
assertEquals(cmisService.getProperty(folder, CMISDictionaryModel.PROP_BASE_TYPE_ID), CMISDictionaryModel.FOLDER_TYPE_ID.getId());
assertEquals(cmisService.getProperty(folder, CMISDictionaryModel.PROP_CREATED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(cmisService.getProperty(folder, CMISDictionaryModel.PROP_CREATION_DATE));
assertEquals(cmisService.getProperty(folder, CMISDictionaryModel.PROP_LAST_MODIFIED_BY), authenticationComponent.getCurrentUserName());
assertNotNull(cmisService.getProperty(folder, CMISDictionaryModel.PROP_LAST_MODIFICATION_DATE));
assertNull(cmisService.getProperty(folder, CMISDictionaryModel.PROP_CHANGE_TOKEN));
assertEquals(cmisService.getProperty(folder, CMISDictionaryModel.PROP_NAME), "BaseFolder");
try
{
cmisService.getProperty(folder, CMISDictionaryModel.PROP_IS_IMMUTABLE);
cmisService.getProperty(folder, CMISDictionaryModel.PROP_IS_LATEST_VERSION);
cmisService.getProperty(folder, CMISDictionaryModel.PROP_IS_MAJOR_VERSION);
cmisService.getProperty(folder, CMISDictionaryModel.PROP_IS_LATEST_MAJOR_VERSION);
cmisService.getProperty(folder, CMISDictionaryModel.PROP_VERSION_LABEL);
cmisService.getProperty(folder, CMISDictionaryModel.PROP_VERSION_SERIES_ID);
cmisService.getProperty(folder, CMISDictionaryModel.PROP_IS_VERSION_SERIES_CHECKED_OUT);
cmisService.getProperty(folder, CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_BY);
cmisService.getProperty(folder, CMISDictionaryModel.PROP_VERSION_SERIES_CHECKED_OUT_ID);
cmisService.getProperty(folder, CMISDictionaryModel.PROP_CHECKIN_COMMENT);
cmisService.getProperty(folder, CMISDictionaryModel.PROP_CONTENT_STREAM_LENGTH);
cmisService.getProperty(folder, CMISDictionaryModel.PROP_CONTENT_STREAM_MIME_TYPE);
cmisService.getProperty(folder, CMISDictionaryModel.PROP_CONTENT_STREAM_FILENAME);
cmisService.getProperty(folder, CMISDictionaryModel.PROP_CONTENT_STREAM_ID);
fail("Failed to catch invalid property on type folder");
}
catch(CMISInvalidArgumentException e)
{
// NOTE: Invalid property
}
assertEquals(cmisService.getProperty(folder, CMISDictionaryModel.PROP_PARENT_ID), rootNodeRef.toString());
assertNull(cmisService.getProperty(folder, CMISDictionaryModel.PROP_ALLOWED_CHILD_OBJECT_TYPE_IDS));
assertEquals(cmisService.getProperty(folder, CMISDictionaryModel.PROP_NAME.toUpperCase()), "BaseFolder");
assertEquals(cmisService.getProperty(folder, CMISDictionaryModel.PROP_NAME.toLowerCase()), "BaseFolder");
}
public void testContentMimeTypeDetection() throws Exception
{
// create simple text plain content
NodeRef content = fileFolderService.create(rootNodeRef, "textFile" + GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef();
ContentWriter writer = serviceRegistry.getContentService().getWriter(content, ContentModel.PROP_CONTENT, true);
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
writer.setEncoding("UTF-8");
writer.putContent("Simple text plain document");
// create content stream with undefined mimetype and file name
ContentStreamImpl contentStreamHTML = new ContentStreamImpl(null, null, "<html><head><title> Hello </title></head><body><p> Test html</p></body></html></body></html>");
String objectId = (String) cmisService.getProperty(content, CMISDictionaryModel.PROP_OBJECT_ID);
cmisService.setContentStream(objectId, null, true, contentStreamHTML.getStream(), null);
// check mimetype
String mimetype = (String) cmisService.getProperty(content, CMISDictionaryModel.PROP_CONTENT_STREAM_MIME_TYPE);
assertTrue("Mimetype is not defined correctly.", mimetype.equals(MimetypeMap.MIMETYPE_HTML));
}
/**
* Test for ALF-18151.
*/
public void testDeleteFolder() throws Exception
{
Map<FileInfo, Boolean> testFolderMap = new HashMap<FileInfo, Boolean>(4);
try
{
// create folder with file
String folderName = "cmistestfolder" + GUID.generate();
String docName = "cmistestdoc.txt" + GUID.generate();
FileInfo folder = createContent(folderName, docName, false);
testFolderMap.put(folder, Boolean.FALSE);
// create empty folder
String folderNameEmpty = "cmistestfolder_empty1" + GUID.generate();
FileInfo folderEmpty = createContent(folderNameEmpty, null, false);
testFolderMap.put(folderEmpty, Boolean.TRUE);
// create folder with file
String folderNameRule = "cmistestfolde_rule" + GUID.generate();
String docNameRule = "cmistestdoc_rule.txt" + GUID.generate();
FileInfo folderWithRule = createContent(folderNameRule, docNameRule, true);
testFolderMap.put(folderWithRule, Boolean.FALSE);
// create empty folder
String folderNameEmptyRule = "cmistestfolde_empty_rule1" + GUID.generate();
FileInfo folderEmptyWithRule = createContent(folderNameEmptyRule, null, true);
testFolderMap.put(folderEmptyWithRule, Boolean.TRUE);
for (Map.Entry<FileInfo, Boolean> entry : testFolderMap.entrySet())
{
try
{
// delete folder
cmisService.deleteObject((String) cmisService.getProperty(entry.getKey().getNodeRef(), CMISDictionaryModel.PROP_OBJECT_ID), Boolean.TRUE);
}
catch (CMISConstraintException ex)
{
assertTrue(!entry.getValue());
continue;
}
assertTrue(entry.getValue());
}
}
finally
{
for (Map.Entry<FileInfo, Boolean> entry : testFolderMap.entrySet())
{
if (fileFolderService.exists(entry.getKey().getNodeRef()))
{
fileFolderService.delete(entry.getKey().getNodeRef());
}
}
}
}
private FileInfo createContent(final String folderName, final String docName, final boolean isRule)
{
final FileInfo folderInfo = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<FileInfo>()
{
@Override
public FileInfo execute() throws Throwable
{
NodeRef companyHomeNodeRef = repositoryHelper.getCompanyHome();
FileInfo folderInfo = fileFolderService.create(companyHomeNodeRef, folderName, ContentModel.TYPE_FOLDER);
nodeService.setProperty(folderInfo.getNodeRef(), ContentModel.PROP_NAME, folderName);
assertNotNull(folderInfo);
FileInfo fileInfo;
if (docName != null)
{
fileInfo = fileFolderService.create(folderInfo.getNodeRef(), docName, ContentModel.TYPE_CONTENT);
nodeService.setProperty(fileInfo.getNodeRef(), ContentModel.PROP_NAME, docName);
assertNotNull(fileInfo);
}
if (isRule)
{
Rule rule = addRule(true, folderName);
assertNotNull(rule);
// Attach the rule to the node
ruleService.saveRule(folderInfo.getNodeRef(), rule);
assertTrue(ruleService.getRules(folderInfo.getNodeRef()).size() > 0);
}
return folderInfo;
}
});
return folderInfo;
}
private Rule addRule(boolean isAppliedToChildren, String title)
{
// Rule properties
Map<String, Serializable> conditionProps = new HashMap<String, Serializable>();
conditionProps.put(ComparePropertyValueEvaluator.PARAM_VALUE, ".txt");
Map<String, Serializable> actionProps = new HashMap<String, Serializable>();
actionProps.put(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_VERSIONABLE);
List<String> ruleTypes = new ArrayList<String>(1);
ruleTypes.add(RuleType.INBOUND);
// Create the action
org.alfresco.service.cmr.action.Action action = actionService.createAction(title);
action.setParameterValues(conditionProps);
ActionCondition actionCondition = actionService.createActionCondition(ComparePropertyValueEvaluator.NAME);
actionCondition.setParameterValues(conditionProps);
action.addActionCondition(actionCondition);
// Create the rule
Rule rule = new Rule();
rule.setRuleTypes(ruleTypes);
rule.setTitle(title);
rule.setDescription("description");
rule.applyToChildren(isAppliedToChildren);
rule.setAction(action);
return rule;
}
}

View File

@@ -1625,7 +1625,7 @@ public class CMISServicesImpl implements CMISServices, ApplicationContextAware,
if (nodeService.getChildAssocs(
nodeRef,
ContentModel.ASSOC_CONTAINS,
RegexQNamePattern.MATCH_ALL).size() > 0)
RegexQNamePattern.MATCH_ALL, 1, false).size() > 0)
{
throw new CMISConstraintException("Could not delete folder with at least one Child");
}

View File

@@ -1,69 +1,58 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.cmis.mapping;
import org.alfresco.cmis.CMISAllowedActionEnum;
import org.alfresco.model.ContentModel;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.lock.LockService;
import org.alfresco.service.cmr.lock.LockType;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.security.PermissionService;
/**
* Alfresco Permission based Action Evaluator
*
* @author davidc
*/
public class CanCheckOutActionEvaluator extends AbstractActionEvaluator<NodeRef>
{
private PermissionActionEvaluator permissionEvaluator;
private NodeService nodeService;
private LockService lockService;
/**
* Construct
*
* @param serviceRegistry
* @param permission
*/
protected CanCheckOutActionEvaluator(ServiceRegistry serviceRegistry)
{
super(serviceRegistry, CMISAllowedActionEnum.CAN_CHECKOUT);
permissionEvaluator = new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_CHECKOUT, PermissionService.CHECK_OUT);
nodeService = serviceRegistry.getNodeService();
lockService = serviceRegistry.getLockService();
}
/*
* (non-Javadoc)
* @see org.alfresco.cmis.CMISActionEvaluator#isAllowed(org.alfresco.service.cmr.repository.NodeRef)
*/
public boolean isAllowed(NodeRef nodeRef)
{
if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY) ||
lockService.getLockType(nodeRef) == LockType.READ_ONLY_LOCK)
{
return false;
}
return permissionEvaluator.isAllowed(nodeRef);
}
}
/*
* Copyright (C) 2005-2012 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.cmis.mapping;
import org.alfresco.cmis.CMISAllowedActionEnum;
import org.alfresco.model.ContentModel;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.security.PermissionService;
/**
* Check-in operation is only allowed for PWC object per CMIS specification
*
* @author Dmitry Velichkevich
*/
public class CanCheckInActionEvaluator extends AbstractActionEvaluator<NodeRef>
{
private NodeService nodeService;
private PermissionActionEvaluator permissionEvaluator;
protected CanCheckInActionEvaluator(ServiceRegistry serviceRegistry)
{
super(serviceRegistry, CMISAllowedActionEnum.CAN_CHECKIN);
permissionEvaluator = new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_CHECKIN, false, PermissionService.CHECK_IN);
nodeService = serviceRegistry.getNodeService();
}
@Override
public boolean isAllowed(NodeRef object)
{
if ((null != object) && nodeService.exists(object))
{
return permissionEvaluator.isAllowed(object) && nodeService.hasAspect(object, ContentModel.ASPECT_WORKING_COPY);
}
return false;
}
}

View File

@@ -0,0 +1,205 @@
/*
* Copyright (C) 2005-2012 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.cmis.mapping;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.alfresco.cmis.CMISAllowedActionEnum;
import org.alfresco.cmis.mapping.ParentTypeActionEvaluator.ParentTypeEnum;
import org.alfresco.cmis.mapping.PropertyActionEvaluator.PropertyDescriptor;
import org.alfresco.cmis.mapping.TypeAttributeActionEvaluator.TypeDefinitionAttributeEnum;
import org.alfresco.model.ContentModel;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.lock.LockType;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.Pair;
import org.apache.chemistry.abdera.ext.CMISAllowableActions;
/**
* This action evaluator introduces simplified interface to construct set of conditions to determine, if an action is available for a specified object. It is generic evaluator,
* which doesn't limit validation for any type of the objects. Also it introduces a possibility to build chain of the conditions.<br />
* <br />
* Evaluator allows specifying logical operation to calculate the final result, using the specified conditions: conjunction (AND operation; <b>DEFAULT</b> value) or disjunction (OR
* operation).<br />
* <br />
* <b>N.B.:</b> each {@link CompositeActionEvaluator} may include other {@link CompositeActionEvaluator} conditions!
*
* @author Dmitry Velichkevich
*/
public class CompositeActionEvaluator<ObjectType> extends AbstractActionEvaluator<ObjectType>
{
private List<AbstractActionEvaluator<ObjectType>> conditions = new LinkedList<AbstractActionEvaluator<ObjectType>>();
private boolean defaultAllowing;
private boolean requiresDisjunction;
/**
* Constructor
*
* @param defaultAllowing - {@link Boolean} value, which determines availability of action for several special cases (invalid object id, empty collection of the aspects etc.)
* @param serviceRegistry - {@link ServiceRegistry} instance
* @param action - {@link CMISAllowableActions} enumeration value, which determines the action to check
*/
public CompositeActionEvaluator(boolean defaultAllowing, ServiceRegistry serviceRegistry, CMISAllowedActionEnum action)
{
super(serviceRegistry, action);
this.defaultAllowing = defaultAllowing;
}
@Override
public boolean isAllowed(ObjectType object)
{
boolean result = defaultAllowing;
for (AbstractActionEvaluator<ObjectType> evaluator : conditions)
{
result = evaluator.isAllowed(object);
if ((requiresDisjunction && result) || (!requiresDisjunction && !result))
{
break;
}
}
return result;
}
/**
* Adds {@link PermissionActionEvaluator} condition to the list
*
* @param permissions - {@link String}... collection, which specifies all the permissions, which should be checked
* @return {@link CompositeActionEvaluator} - self-instance, which allows making chain of conditions
*/
public CompositeActionEvaluator<ObjectType> addPermissionCondition(String... permissions)
{
if (null != permissions)
{
conditions.add(new PermissionActionEvaluator<ObjectType>(getServiceRegistry(), getAction(), defaultAllowing, permissions));
}
return this;
}
/**
* Add {@link PropertyActionEvaluator} condition to the list. This method implies, that each property from the <code>propertyIdsAndExpectedValues</code> collection must satisfy
* conditions, which are specified in each {@link PropertyDescriptor} instance
*
* @param propertyIdsAndExpectedValues - {@link PropertyDescriptor} collection, which specifies property ids and expected values or if value should not be <code>null</code>
* @return {@link CompositeActionEvaluator} - self-instance, which allows making chain of conditions
*/
public CompositeActionEvaluator<ObjectType> addPropertyCondition(PropertyDescriptor... propertyIdsAndExpectedValues)
{
if (null != propertyIdsAndExpectedValues)
{
conditions.add(new PropertyActionEvaluator<ObjectType>(getServiceRegistry(), getAction(), true, defaultAllowing, propertyIdsAndExpectedValues));
}
return this;
}
/**
* Adds {@link TypeAttributeActionEvaluator} condition to the list. This method implies, that <code>attribute</code> value may be null and it is not {@link Map} or
* {@link Collection}
*
* @param attribute - {@link TypeDefinitionAttributeEnum} enumeration value, which determines attribute of object type definition, which should be validated
* @param comparator - {@link Comparable} instance, which encapsulates the logic of checking a value, received from the object type definition in accordance with
* <code>attribute</code> parameter
* @return {@link CompositeActionEvaluator} - self-instance, which allows making chain of conditions
*/
public CompositeActionEvaluator<ObjectType> addTypeAttributeCondition(TypeDefinitionAttributeEnum attribute, Comparable<Object> comparator)
{
if ((null != attribute) && (null != comparator))
{
conditions.add(new TypeAttributeActionEvaluator<ObjectType>(attribute, new Pair<Object, Comparable<Object>>(null, comparator), true, defaultAllowing,
getServiceRegistry(), getAction()));
}
return this;
}
/**
* Adds {@link ObjectLockedActionEvaluator} condition to the list. This method implies, that object should not have <code>lockType</code> lock
*
* @param lockType - {@link LockType} enumeration value, which determines lock, required to check
* @return {@link CompositeActionEvaluator} - self-instance, which allows making chain of conditions
*/
public CompositeActionEvaluator<ObjectType> addLockCondition(LockType lockType)
{
conditions.add(new ObjectLockedActionEvaluator<ObjectType>(lockType, false, getServiceRegistry(), getAction()));
return this;
}
/**
* Adds {@link AspectActionEvaluator} condition to the list. This method sets only 1 {@link ContentModel#ASPECT_WORKING_COPY} aspect id and it implies
*
* @param pwcExpected - {@link Boolean} value, which determines: <code>true</code> - object should be PWC, <code>false</code> - object should not be PWC
* @return {@link CompositeActionEvaluator} - self-instance, which allows making chain of conditions
*/
public CompositeActionEvaluator<ObjectType> addPwcCondition(boolean pwcExpected)
{
conditions.add(new AspectActionEvaluator<ObjectType>(getServiceRegistry(), getAction(), pwcExpected, true, defaultAllowing, ContentModel.ASPECT_WORKING_COPY));
return this;
}
/**
* Adds {@link AspectActionEvaluator} condition to the list. This method implies, that all aspects should satisfy to the <code>expected</code> condition
*
* @param expected - {@link Boolean} value, which determines: <code>true</code> - aspects appliance is expected, <code>false</code> - aspects absence is expected
* @param aspects - {@link QName}... collection, which specifies all the aspects, which should be validated
* @return {@link CompositeActionEvaluator} - self-instance, which allows making chain of conditions
*/
public CompositeActionEvaluator<ObjectType> addAspectCondition(boolean expected, QName... aspects)
{
conditions.add(new AspectActionEvaluator<ObjectType>(getServiceRegistry(), getAction(), expected, true, defaultAllowing, aspects));
return this;
}
/**
* Adds {@link ParentTypeActionEvaluator} condition to the list. This method implies, that parent of the <code>parentType</code> type is expected
*
* @param parentType - {@link ParentTypeEnum} enumeration value, which determines, validation for which parent is required: for {@link ParentTypeEnum#MULTI_FILED}, for
* {@link ParentTypeEnum#REPOSITORY_ROOT} or for {@link ParentTypeEnum#PRIMARY_REPOSITORY_ROOT}
* @return {@link CompositeActionEvaluator} - self-instance, which allows making chain of conditions
*/
public CompositeActionEvaluator<ObjectType> addParentTypeCondition(ParentTypeEnum parentType)
{
conditions.add(new ParentTypeActionEvaluator<ObjectType>(getServiceRegistry(), getAction(), parentType, true));
return this;
}
/**
* Adds any condition to the list, if it is not a <code>null</code>
*
* @param condition - {@link AbstractActionEvaluator} instance, which determines some condition
* @return {@link CompositeActionEvaluator} - self-instance, which allows making chain of conditions
*/
public CompositeActionEvaluator<ObjectType> addCondition(AbstractActionEvaluator<ObjectType> condition)
{
if (null != condition)
{
conditions.add(condition);
}
return this;
}
}

View File

@@ -0,0 +1,80 @@
/*
* Copyright (C) 2005-2012 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.cmis.mapping;
import org.alfresco.cmis.CMISAllowedActionEnum;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.lock.LockService;
import org.alfresco.service.cmr.lock.LockType;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.apache.chemistry.abdera.ext.CMISAllowableActions;
/**
* This evaluator determines an action availability in accordance with {@link LockType} lock parameter and in accordance with rules of checking application of the lock. The rules
* are:<br />
* - is it expected that object had been locked
* <br />
* This evaluator is generic, because it is used in the scope of {@link CompositeActionEvaluator}
*
* @author Dmitry Velichkevich
*/
public class ObjectLockedActionEvaluator<ObjectType> extends AbstractActionEvaluator<ObjectType>
{
private NodeService nodeService;
private LockService lockService;
private LockType lockType;
private boolean lockExpected;
/**
* Constructor
*
* @param lockType - {@link LockType} enumeration value, which determines type of the lock, which should be validated
* @param lockExpected - {@link Boolean} value, which determines: <code>true</code> - object should be locked and lock should satisfy to the <code>lockType</code>,
* <code>false</code> - object should not have the <code>lockType</code> lock
* @param serviceRegistry - {@link ServiceRegistry} instance
* @param action - {@link CMISAllowableActions} enumeration value, which determines the action to check
*/
protected ObjectLockedActionEvaluator(LockType lockType, boolean lockExpected, ServiceRegistry serviceRegistry, CMISAllowedActionEnum action)
{
super(serviceRegistry, action);
this.lockType = lockType;
this.lockExpected = lockExpected;
nodeService = serviceRegistry.getNodeService();
lockService = serviceRegistry.getLockService();
}
@Override
public boolean isAllowed(ObjectType object)
{
NodeRef nodeRef = (object instanceof NodeRef) ? ((NodeRef) object) : (null);
if ((null != lockType) && nodeService.exists(nodeRef))
{
boolean locked = lockType == lockService.getLockType(nodeRef);
return (lockExpected && locked) || (!lockExpected && !locked);
}
return false;
}
}

View File

@@ -0,0 +1,130 @@
/*
* Copyright (C) 2005-2012 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.cmis.mapping;
import java.util.List;
import org.alfresco.cmis.CMISAllowedActionEnum;
import org.alfresco.cmis.CMISServices;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.apache.chemistry.abdera.ext.CMISAllowableActions;
/**
* This evaluator determines an action availability in accordance with parent(s) of object. The rules are:<br />
* - is it expected that object has parent of {@link ParentTypeEnum} or not.<br />
* <br />
* This evaluator is generic, because it is used in the scope of {@link CompositeActionEvaluator}
*
* @author Dmitry Velichkevich
*/
public class ParentTypeActionEvaluator<ObjectType> extends AbstractActionEvaluator<ObjectType>
{
private CMISServices cmisServices;
private NodeService nodeService;
private ParentTypeEnum parentType;
private boolean expected;
/**
* Constructor
*
* @param serviceRegistry - {@link ServiceRegistry} instance
* @param action - {@link CMISAllowableActions} enumeration value, which determines the action to check
* @param parentType - {@link ParentTypeEnum} enumeration value, which determines type of parent, which should be validated
* @param expected - {@link Boolean} value, which determines: <code>true</code> - object should have <code>parentType</code> parent, <code>false</code> - object should NOT have
* <code>parentType</code> parent
*/
protected ParentTypeActionEvaluator(ServiceRegistry serviceRegistry, CMISAllowedActionEnum action, ParentTypeEnum parentType, boolean expected)
{
super(serviceRegistry, action);
this.parentType = parentType;
this.expected = expected;
cmisServices = serviceRegistry.getCMISService();
nodeService = serviceRegistry.getNodeService();
}
/* (non-Javadoc)
* @see org.alfresco.cmis.CMISActionEvaluator#isAllowed(java.lang.Object)
*/
@Override
public boolean isAllowed(ObjectType object)
{
NodeRef nodeRef = (object instanceof NodeRef) ? ((NodeRef) object) : (null);
NodeRef rootNodeRef = cmisServices.getDefaultRootNodeRef();
if ((null == nodeRef) || rootNodeRef.equals(nodeRef))
{
return false;
}
List<ChildAssociationRef> parentAssocs = nodeService.getParentAssocs(nodeRef);
if ((ParentTypeEnum.REPOSITORY_ROOT == parentType) || (ParentTypeEnum.PRIMARY_REPOSITORY_ROOT == parentType))
{
ChildAssociationRef root = null;
for (ChildAssociationRef ref : parentAssocs)
{
root = (rootNodeRef.equals(ref.getParentRef())) ? (ref) : (null);
if (null != root)
{
if ((ParentTypeEnum.PRIMARY_REPOSITORY_ROOT == parentType) && !ref.isPrimary())
{
root = null;
}
break;
}
}
return (expected) ? (null != root) : (null == root);
}
return (expected) ? (parentAssocs.size() > 1) : (1 == parentAssocs.size());
}
/**
* Enumeration of type of parents, which may be required to check availability of some action for an object
*
* @author Dmitry Velichkevich
* @see MultiFilingServicePort
*/
public static enum ParentTypeEnum
{
/**
* One or more parents, which are not primary (see {@link MultiFilingServicePort#addObjectToFolder(String, String, String, Boolean, javax.xml.ws.Holder)} and
* {@link MultiFilingServicePort#removeObjectFromFolder(String, String, String, javax.xml.ws.Holder)})
*/
MULTI_FILED,
/**
* Default repository root as a primary or one of the multi filed parents
*/
REPOSITORY_ROOT,
/**
* Default repository root only as primary parent
*/
PRIMARY_REPOSITORY_ROOT;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
* Copyright (C) 2005-2012 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -29,9 +29,12 @@ import org.alfresco.service.cmr.security.PermissionService;
*
* @author davidc
*/
public class PermissionActionEvaluator extends AbstractActionEvaluator<NodeRef>
public class PermissionActionEvaluator<ObjectType> extends AbstractActionEvaluator<ObjectType>
{
private String[] permissions;
private boolean defaultAllowing;
private PermissionService permissionService;
/**
@@ -40,10 +43,11 @@ public class PermissionActionEvaluator extends AbstractActionEvaluator<NodeRef>
* @param serviceRegistry
* @param permission
*/
protected PermissionActionEvaluator(ServiceRegistry serviceRegistry, CMISAllowedActionEnum action, String... permission)
protected PermissionActionEvaluator(ServiceRegistry serviceRegistry, CMISAllowedActionEnum action, boolean defaultAllowing, String... permission)
{
super(serviceRegistry, action);
this.permissions = permission;
this.defaultAllowing = defaultAllowing;
this.permissionService = serviceRegistry.getPermissionService();
}
@@ -51,8 +55,14 @@ public class PermissionActionEvaluator extends AbstractActionEvaluator<NodeRef>
* (non-Javadoc)
* @see org.alfresco.cmis.CMISActionEvaluator#isAllowed(org.alfresco.service.cmr.repository.NodeRef)
*/
public boolean isAllowed(NodeRef nodeRef)
public boolean isAllowed(ObjectType object)
{
if (!(object instanceof NodeRef))
{
return defaultAllowing;
}
NodeRef nodeRef = (NodeRef) object;
for (String permission : permissions)
{
if (permissionService.hasPermission(nodeRef, permission) == AccessStatus.DENIED)
@@ -60,9 +70,10 @@ public class PermissionActionEvaluator extends AbstractActionEvaluator<NodeRef>
return false;
}
}
return true;
}
@Override
public String toString()
{
@@ -76,5 +87,5 @@ public class PermissionActionEvaluator extends AbstractActionEvaluator<NodeRef>
builder.append("]");
return builder.toString();
}
}

View File

@@ -0,0 +1,200 @@
/*
* Copyright (C) 2005-2012 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.cmis.mapping;
import java.io.Serializable;
import org.alfresco.cmis.CMISAllowedActionEnum;
import org.alfresco.cmis.CMISDictionaryModel;
import org.alfresco.cmis.CMISInvalidArgumentException;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.apache.chemistry.abdera.ext.CMISAllowableActions;
/**
* This evaluator determines an action availability in accordance with collection of {@link PropertyDescriptor} and in accordance with rules of checking of the object properties.
* The rules are:<br />
* - should each specific property in the list satisfy all the conditions, which are specified in appropriate {@link PropertyDescriptor} instance or at least 1 property
* satisfaction is enough.<br />
* <br />
* This evaluator is generic, because it is used in the scope of {@link CompositeActionEvaluator}
*
* @author Dmitry Velichkevich
* @see PropertyDescriptor
*/
public class PropertyActionEvaluator<ValidatingObjectType> extends AbstractActionEvaluator<ValidatingObjectType>
{
private PropertyDescriptor[] propertyIdsAndExpectedValues;
private boolean allPropertiesConcur;
private boolean defaultAllowing;
/**
* Constructor
*
* @param serviceRegistry - {@link ServiceRegistry} instance
* @param action - {@link CMISAllowableActions} enumeration value, which determines the action to check
* @param allPropertiesConcur - {@link Boolean} value, which determines: <code>true</code> - each specific object property should satisfy all the conditions of appropriate
* {@link PropertyDescriptor}, <code>false</code> - at least 1 object property satisfaction is enough
* @param defaultAllowing - {@link Boolean} value, which determines availability of action for several special cases (invalid object id, empty collection of the aspects etc.)
* @param propertyIdsAndExpectedValues - {@link PropertyDescriptor}... collection, which specifies all the properties, which should be validated on an object
*/
public PropertyActionEvaluator(ServiceRegistry serviceRegistry, CMISAllowedActionEnum action, boolean allPropertiesConcur, boolean defaultAllowing,
PropertyDescriptor... propertyIdsAndExpectedValues)
{
super(serviceRegistry, action);
this.propertyIdsAndExpectedValues = propertyIdsAndExpectedValues;
this.allPropertiesConcur = allPropertiesConcur;
}
@Override
public boolean isAllowed(ValidatingObjectType object)
{
boolean result = defaultAllowing;
if (null != propertyIdsAndExpectedValues)
{
for (PropertyDescriptor descriptor : propertyIdsAndExpectedValues)
{
if ((null != descriptor) && (null != descriptor.getPropertyId()))
{
Serializable left = null;
try
{
if (object instanceof NodeRef)
{
left = getServiceRegistry().getCMISService().getProperty((NodeRef) object, descriptor.getPropertyId());
}
else
{
if (object instanceof AssociationRef)
{
left = getServiceRegistry().getCMISService().getProperty((AssociationRef) object, descriptor.getPropertyId());
}
else
{
return false;
}
}
}
catch (CMISInvalidArgumentException e)
{
throw new RuntimeException(e.toString(), e);
}
result = descriptor.satisfies(left);
if ((allPropertiesConcur && !result) || (!allPropertiesConcur && result))
{
break;
}
}
}
}
return result;
}
/**
* This class encapsulates description of object property to validate some actual object property against defined condition. This, in turn, allows determine, if some action is
* allowable for an object in accordance with value or values of the property or properties.<br />
* <br />
* <b>N.B.:</b><code>null</code> expected value is supported! <br />
* The class introduces the following fields:<br />
* - property definition id (subject to reference is {@link CMISDictionaryModel}; {@link PropertyDescriptor#getPropertyId()}); - expected property value
* {@link PropertyDescriptor#getPropertyValue()}; - may property be equal to <code>null</code> {@link PropertyDescriptor#isNullExpected()}
*
* @author Dmitry Velichkevich
* @see CMISDictionaryModel
*/
public static class PropertyDescriptor
{
private String propertyId;
private Serializable propertyValue;
private boolean nullExpected;
/**
* Constructor
*
* @param propertyId - {@link String} value, which determines property definition id (subject to reference is {@link CMISDictionaryModel})
* @param propertyValue - {@link Serializable} instance, which specifies expected property value
* @param nullExpected - {@link Boolean} value, which determines: <code>true</code> - property may be <code>null</code>, <code>false</code> - property can't be equal to
* <code>null</code> (this leads to ignoring {@link PropertyDescriptor#getPropertyValue()} value)
*/
public PropertyDescriptor(String propertyId, Serializable propertyValue, boolean nullExpected)
{
this.propertyId = propertyId;
this.propertyValue = propertyValue;
this.nullExpected = nullExpected;
}
/**
* Getter
*
* @return {@link String} value, which represents one of the {@link CMISDictionaryModel} property definition ids
*/
public String getPropertyId()
{
return propertyId;
}
/**
* Getter
*
* @return {@link Serializable} instance, which specifies expected property value
*/
public Serializable getPropertyValue()
{
return propertyValue;
}
/**
* Getter
*
* @return {@link Boolean} value, which determines: <code>true</code> - property may be <code>null</code>, <code>false</code> - property can't be equal to <code>null</code>
* (this leads to ignoring {@link PropertyDescriptor#getPropertyValue()} value)
*/
public boolean isNullExpected()
{
return nullExpected;
}
/**
* This method checks whether specified <code>value</code> satisfies to all the defined conditions in current instance of {@link PropertyDescriptor}
*
* @param value - {@link Serializable} instance, which represents actual value of some object property
* @return {@link Boolean} value, which determines: <code>true</code> - specified <code>value</code> satisfies to all the defined conditions, <code>false</code> - specified
* <code>value</code> doesn't satisfy to all the defined conditions
*/
public boolean satisfies(Serializable value)
{
if (!nullExpected)
{
return null != value;
}
return (null != value) ? (value.equals(propertyValue)) : (null == propertyValue);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
* Copyright (C) 2005-2012 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -25,9 +25,9 @@ import org.alfresco.service.cmr.repository.NodeRef;
*
* @author davidc
*/
public class RootActionEvaluator extends AbstractActionEvaluator<NodeRef>
public class RootActionEvaluator<ObjectType> extends AbstractActionEvaluator<ObjectType>
{
private AbstractActionEvaluator<NodeRef> evaluator;
private AbstractActionEvaluator<ObjectType> evaluator;
private boolean allow;
/**
@@ -36,7 +36,7 @@ public class RootActionEvaluator extends AbstractActionEvaluator<NodeRef>
* @param serviceRegistry
* @param action
*/
protected RootActionEvaluator(AbstractActionEvaluator<NodeRef> evaluator, boolean allow)
protected RootActionEvaluator(AbstractActionEvaluator<ObjectType> evaluator, boolean allow)
{
super(evaluator.getServiceRegistry(), evaluator.getAction());
this.evaluator = evaluator;
@@ -47,13 +47,14 @@ public class RootActionEvaluator extends AbstractActionEvaluator<NodeRef>
* (non-Javadoc)
* @see org.alfresco.cmis.CMISActionEvaluator#isAllowed(org.alfresco.service.cmr.repository.NodeRef)
*/
public boolean isAllowed(NodeRef nodeRef)
public boolean isAllowed(ObjectType id)
{
if (nodeRef.equals(getServiceRegistry().getCMISService().getDefaultRootNodeRef()))
if ((id instanceof NodeRef) && id.equals(getServiceRegistry().getCMISService().getDefaultRootNodeRef()))
{
return allow;
}
return evaluator.isAllowed(nodeRef);
return evaluator.isAllowed(id);
}
/*
@@ -68,4 +69,3 @@ public class RootActionEvaluator extends AbstractActionEvaluator<NodeRef>
return builder.toString();
}
}

View File

@@ -0,0 +1,303 @@
/*
* Copyright (C) 2005-2012 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.cmis.mapping;
import java.io.Serializable;
import java.util.Collection;
import java.util.Map;
import org.alfresco.cmis.CMISAllowedActionEnum;
import org.alfresco.cmis.CMISInvalidArgumentException;
import org.alfresco.cmis.CMISTypeDefinition;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.util.Pair;
import org.apache.chemistry.abdera.ext.CMISAllowableActions;
/**
* This evaluator determines an action availability in accordance with value of object type definition attribute and in accordance with rules of checking of the object type
* definition attribute value. The rules are:<br />
* - attribute value may be <code>null</code> or it cannot. <code>getSecond()</code> of the {@link TypeAttributeActionEvaluator#comparator} field is ignored, if it cannot be equal
* to <code>null</code> <br />
* <br />
* This evaluator is generic, because it is used in the scope of {@link CompositeActionEvaluator}. <br />
* <br />
*
* @author Dmitry Velichkevich
* @see TypeAttributeActionEvaluator#comparator
*/
public class TypeAttributeActionEvaluator<ObjectType> extends AbstractActionEvaluator<ObjectType>
{
private TypeDefinitionAttributeEnum attribute;
/**
* This field contains descriptor to extract and compare desired attribute value from object type definition. The following attribute value data types are supported:<br />
* - descendants of {@link Serializable} interface;<br />
* - descendants of {@link Collection} interface;<br />
* - descendatns of {@link Map} interface.<br />
* <br />
* Result of the <code>getFirst()</code> method of the <code>comparator</code> field must contain the following value:<br />
* - this value is completely ignored, if attribute data type is descendant of {@link Serializable};<br />
* - {@link Integer} number, which determines index of element in collection. Element will be received, using {@link Collection#toArray()}[({@link Integer})
* <code>comparator.getFirst()</code>];<br />
* - an appropriate object, which may be used as a key to receive attribute value, if attribute data type is descendant of the {@link Map}<br />
* <br />
* Result of <code>getSecond()</code> method of the <code>comparator</code> field MUST NOT be <code>null</code>! This {@link Comparable} instance MUST encapsulate the logic of
* additional processing of extracted actual attribute value (for example, if extracted value has some custom data type), if necessary. And it should encapsulate the logic of
* comparing an actual value of the attribute with the expected. Expected value is also a subject of encapsulation of the {@link Comparable}
*/
private Pair<Object, Comparable<Object>> comparator;
private boolean nullExpected;
private boolean defaultAllowing;
/**
* Constructor
*
* @param attribute - {@link TypeDefinitionAttributeEnum} enumeration value, which specifies method of {@link CMISTypeDefinition} to receive attribute, which should be
* validated
* @param comparator - {@link Pair}&lt;{@link Object}, {@link Comparable}&lt;{@link Object}&gt;&gt; instance. See {@link TypeAttributeActionEvaluator#comparator} for more
* details
* @param nullExpected - {@link Boolean} value, which determines: <code>true</code> - attribute value may be <code>null</code>, <code>false</code> - attribute value can't be
* equal to <code>null</code> (this leads to ignoring <code>getSecond()</code> of the {@link TypeAttributeActionEvaluator#comparator} field)
* @param defaultAllowing - {@link Boolean} value, which determines availability of action for several special cases (invalid object id, empty collection of the aspects etc.)
* @param serviceRegistry - {@link ServiceRegistry} instance
* @param action - {@link CMISAllowableActions} enumeration value, which determines the action to check
*/
public TypeAttributeActionEvaluator(TypeDefinitionAttributeEnum attribute, Pair<Object, Comparable<Object>> comparator, boolean nullExpected, boolean defaultAllowing,
ServiceRegistry serviceRegistry, CMISAllowedActionEnum action)
{
super(serviceRegistry, action);
this.attribute = attribute;
this.comparator = comparator;
this.nullExpected = nullExpected;
this.defaultAllowing = defaultAllowing;
}
@Override
public boolean isAllowed(ObjectType object)
{
boolean result = defaultAllowing;
if ((null != object) && (null != attribute) && (null != comparator) && (null != comparator.getSecond()))
{
CMISTypeDefinition typeDefinition = null;
try
{
typeDefinition = getServiceRegistry().getCMISService().getTypeDefinition(object);
}
catch (CMISInvalidArgumentException e)
{
throw new RuntimeException(e.toString(), e);
}
result = attribute.satisfies(typeDefinition, comparator, nullExpected, defaultAllowing);
}
return result;
}
/**
* This enumeration encapsulates the logic of object type definition attributes comparing. It uses Java Reflection mechanism to get actual attribute value, which should be
* validated
*
* @author Dmitry Velichkevich
*/
public static enum TypeDefinitionAttributeEnum
{
/**
* {@link CMISTypeDefinition#isPublic()}
*/
PUBLIC("isPublic", true),
/**
* {@link CMISTypeDefinition#getTypeId()}
*/
TYPE_ID("getTypeId", true),
/**
* {@link CMISTypeDefinition#getQueryName()}
*/
QUERY_NAME("getQueryName", true),
/**
* {@link CMISTypeDefinition#getDisplayName()}
*/
DISPLAY_NAME("getDisplayName", true),
/**
* {@link CMISTypeDefinition#getParentType()}
*/
PARENT_TYPE("getParentType", false),
/**
* {@link CMISTypeDefinition#getSubTypes(boolean)}
*/
SUB_TYPES("getSubTypes", false),
/**
* {@link CMISTypeDefinition#getBaseType()}
*/
BASE_TYPE("getBaseType", false),
/**
* {@link CMISTypeDefinition#getDescription()}
*/
DESCRIPTION("getDescription", true),
/**
* {@link CMISTypeDefinition#isCreatable()}
*/
CREATABLE("isCreatable", true),
/**
* {@link CMISTypeDefinition#isFileable()}
*/
FILEABLE("isFileable", true),
/**
* {@link CMISTypeDefinition#isQueryable()}
*/
QUERYABLE("isQueryable", true),
/**
* {@link CMISTypeDefinition#isFullTextIndexed()}
*/
FULL_TEXT_INDEXED("isFullTextIndexed", true),
/**
* {@link CMISTypeDefinition#isControllablePolicy()}
*/
CONTROLLABLE_POLICY("isControllablePolicy", true),
/**
* {@link CMISTypeDefinition#isControllableACL()}
*/
CONTROLLABLE_ACL("isControllableACL", true),
/**
* {@link CMISTypeDefinition#isIncludedInSuperTypeQuery()}
*/
INCLUDED_IN_SUPER_TYPE_QUERY("isIncludedInSuperTypeQuery", true),
/**
* {@link CMISTypeDefinition#isVersionable()}
*/
VERSIONABLE("isVersionable", true),
/**
* {@link CMISTypeDefinition#getContentStreamAllowed()}
*/
CONTENT_STREAM_ALLOWED("getContentStreamAllowed", true),
/**
* {@link CMISTypeDefinition#getAllowedSourceTypes()}
*/
ALLOWED_SOURCE_TYPES("getAllowedSourceTypes", false),
/**
* {@link CMISTypeDefinition#getAllowedTargetTypes()}
*/
ALLOWED_TARGET_TYPES("getAllowedTargetTypes", false),
/**
* {@link CMISTypeDefinition#getPropertyDefinitions()}
*/
PROPERTY_DEFINITIONS("getPropertyDefinitions", false),
/**
* {@link CMISTypeDefinition#getOwnedPropertyDefinitions()}
*/
OWNED_PROPERTY_DEFINITIONS("getOwnedPropertyDefinitions", false);
private String methodName;
private boolean primitiveType;
/**
* Constructor
*
* @param methodName - {@link String} value, which specifies name of the method, which returns desired attribute value
* @param primitiveType - {@link Boolean} value, which determines: <code>true</code> - attribute value data type IS NOT descendant of {@link Collection} or {@link Map},
* <code>false</code> - attribute value data type IS descendant of {@link Collection} or {@link Map}
*/
private TypeDefinitionAttributeEnum(String methodName, boolean primitiveType)
{
this.methodName = methodName;
this.primitiveType = primitiveType;
}
/**
* This method determines, if object data type definition contains attribute, which satisfies to condition to allow some action
*
* @param typeDefinition - {@link CMISTypeDefinition} instance of the object, which should be checked
* @param comparator - {@link Pair}&lt;{@link Object}, {@link Comparable}&lt;{@link Object}&gt;&gt; instance. See {@link TypeAttributeActionEvaluator#comparator} for more
* details
* @param nullExpected - {@link Boolean} value, which determines: <code>true</code> - attribute value may be <code>null</code>, <code>false</code> - attribute value can't
* be equal to <code>null</code> (this leads to ignoring <code>getSecond()</code> of the <code>comparator</code> attribute)
* @param defaultAllowing - {@link Boolean} value, which determines availability of action for several special cases (invalid object id, empty collection of the aspects
* etc.)
* @return - {@link Boolean} value, which determines: <code>true</code> - actual attribute value satisfies all the conditions of the <code>comparator</code> parameter,
* <code>false</code> - actual attribute value doesn't satisfy conditions of the <code>comparator</code> parameter
*/
@SuppressWarnings("unchecked")
public boolean satisfies(CMISTypeDefinition typeDefinition, Pair<Object, Comparable<Object>> comparator, boolean nullExpected, boolean defaultAllowing)
{
if (null == typeDefinition)
{
return defaultAllowing;
}
Object actualValue = null;
try
{
actualValue = typeDefinition.getClass().getMethod(methodName).invoke(typeDefinition);
}
catch (Exception e)
{
throw new RuntimeException("Interface of '" + CMISTypeDefinition.class.getName() + "' has been modified!");
}
if ((null == actualValue) && !primitiveType)
{
return defaultAllowing;
}
if (actualValue instanceof Map)
{
actualValue = ((Map) actualValue).get(comparator.getFirst());
}
else
{
if (actualValue instanceof Collection)
{
actualValue = ((Collection) actualValue).toArray()[(Integer) comparator.getFirst()];
}
}
if (!nullExpected)
{
return null != actualValue;
}
return 0 == comparator.getSecond().compareTo(actualValue);
}
}
}