mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-06-30 18:15:39 +00:00
47256: Merged DEV to V4.1-BUG-FIX 47145: ALF-17877 : CLONE - The deleted via Sharepoint document is not removed from Alfresco but hidden aspect is added for it Setting webdav client for all webdav requests in SPP module. 47257: ALF-17816 (Incorrect tooltip 'Locked by' icon for other user) 47285: ALF-17635: Incorrect behavior of Move action in Update rule and Outbound rule in Share - Altered MoveActionExcecuter so that it doesn't fire on a working copy and will hence wait for checkin 47287: Fixes ALF-2590: Calendar doesn't handle 401 errors properly: - callUtils now pass on non 200 status codes (rather than swallowing errors) - updates create-event template to handle missing data. 47288: ALF-17057: SPP: Extra version is created when add new document via Document Connection on MacOS X Lion - Now we ignore empty content when we create the initial version 47290: ALF-16931: Bootstrapped users with Uppercase name cannot see site they have been invited to - Changed the code to be conditional on association type 47296: ALF-4565: Incorrect behaviour of Edit Online action if document's name contains wildcards - URLs were incorrectly being double decoded in DefaultAuthenticationHandler 47308: Merged DEV to V4.1-BUG-FIX 47298: ALF-17907 : specified index does not exist during upgrade to 4.1.2 The droppping of alf_node.store_id index was marked as optional to support the upgrades from originally Alfresco 2.2 for Oracle DB. 47314: Fixed ALF-13679 "Cannot play a movie file in Preview, which has double byte characters in the file name" 47322: ALL LANGS: Translation updates based on EN r47138 47325: ALL LANGS: Translation updates based on EN r47138 47327: Removes unused TinyMCE files (as part of ALF-17451 ) 47329: FR, IT, NL: Fixes ALF-17413 47331: Implements fix suggested in ALF-17451, updates fixes for ALF-8486, ALF-10690 and ALF-11000. 47334: ALF-16991: Editing Rich Text files in TinyMCE loses some formatting. 47340: Merged DEV to V4.1-BUG-FIX 47306: ALF-17907 : specified index does not exist during upgrade to 4.1.2 The droppping of alf_node.store_id index was marked as optional to support the upgrades from originally Alfresco 2.2 for MS SQL Server. 47353: Merged V4.1-BUG-FIX-2012_11_26 to V4.1-BUG-FIX 44182: ALF-15970: OpenOffice form not found Show error message if form definition could not be found 47383: ALF-17222: "Protected attribute not take into account for target of associations" 47392: Merged BRANCHES/DEV/BELARUS/V4.1-BUG-FIX-2013_02_26 to BRANCHES/DEV/V4.1-BUG-FIX: 47313: ALF-18006 : Sending a PUT request without a Content-Type header resets the contents mimetype to application/octet-stream 47402: ALF-18212: SOLR OOTB cache sizes are too big and require >20GB heap space - Reduced default cache sizes from 512 to 64 47405: Fixes: ALF-14412 - Tag filtering in blogs 47407: Fix failing unit tests - use public services where transactions are required 47410: Merged V3.4-BUG-FIX to V4.1-BUG-FIX 47293: (RECORD ONLY) Merged DEV to V3.4-BUG-FIX 43417: ALF-14710 JUnit test for WebServiceSuiteSystemTest project fails - testPropertySetGet() method was updated in RepositoryServiceSystemTest class 47311: ALF-18213 / ALF-18005: webscript guestDownload does not set Content-Dispositon HTTP header - Follow on from ALF-9817 - Now it does it properly 47414: Merged V3.4-BUG-FIX to V4.1-BUG-FIX (RECORD ONLY) 47332: ALF-17640: Merged V4.1-BUG-FIX to V3.4-BUG-FIX 45828: Additional fix for ALF-17153 FTS query parser FTSQueryParser is not debuggable 47385: ALF-17935: Merged PATCHES/V4.0.2 to V3.4-BUG-FIX 42969: Merged DEV to PATCHES/V4.0.2 42967: MNT-158: SharePoint Protocol Opening Documents in Read-Only for Site Consumer with Collaborator Privileges Remove manual throwing of AccessDeniedException is user has "consumer" or "contributor" role. Create "links" container from system user. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@47419 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
364 lines
12 KiB
Java
364 lines
12 KiB
Java
package org.alfresco.opencmis;
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
import static org.junit.Assert.assertFalse;
|
|
import static org.junit.Assert.assertNotNull;
|
|
import static org.junit.Assert.assertTrue;
|
|
import static org.junit.Assert.fail;
|
|
|
|
import java.io.File;
|
|
import java.math.BigInteger;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import org.alfresco.model.ContentModel;
|
|
import org.alfresco.model.WCMModel;
|
|
import org.alfresco.repo.content.MimetypeMap;
|
|
import org.alfresco.repo.model.Repository;
|
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
|
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
|
import org.alfresco.service.cmr.model.FileFolderService;
|
|
import org.alfresco.service.cmr.model.FileInfo;
|
|
import org.alfresco.service.cmr.repository.NodeRef;
|
|
import org.alfresco.service.cmr.repository.NodeService;
|
|
import org.alfresco.service.namespace.NamespaceService;
|
|
import org.alfresco.service.namespace.QName;
|
|
import org.alfresco.service.transaction.TransactionService;
|
|
import org.alfresco.util.ApplicationContextHelper;
|
|
import org.apache.chemistry.opencmis.commons.PropertyIds;
|
|
import org.apache.chemistry.opencmis.commons.data.AllowableActions;
|
|
import org.apache.chemistry.opencmis.commons.data.ObjectData;
|
|
import org.apache.chemistry.opencmis.commons.data.PropertyData;
|
|
import org.apache.chemistry.opencmis.commons.data.RepositoryInfo;
|
|
import org.apache.chemistry.opencmis.commons.enums.Action;
|
|
import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
|
|
import org.apache.chemistry.opencmis.commons.enums.VersioningState;
|
|
import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException;
|
|
import org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl;
|
|
import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl;
|
|
import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIdImpl;
|
|
import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringImpl;
|
|
import org.apache.chemistry.opencmis.commons.impl.server.AbstractServiceFactory;
|
|
import org.apache.chemistry.opencmis.commons.server.CallContext;
|
|
import org.apache.chemistry.opencmis.commons.server.CmisService;
|
|
import org.apache.chemistry.opencmis.commons.spi.Holder;
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
import org.springframework.context.ApplicationContext;
|
|
import org.springframework.extensions.webscripts.GUID;
|
|
|
|
/**
|
|
* OpenCMIS tests.
|
|
*
|
|
* @author steveglover
|
|
*
|
|
*/
|
|
public class CMISTest
|
|
{
|
|
private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
|
|
|
|
private FileFolderService fileFolderService;
|
|
private TransactionService transactionService;
|
|
private NodeService nodeService;
|
|
private Repository repositoryHelper;
|
|
|
|
private AlfrescoCmisServiceFactory factory;
|
|
private SimpleCallContext context;
|
|
|
|
/**
|
|
* Test class to provide the service factory
|
|
*
|
|
* @author Derek Hulley
|
|
* @since 4.0
|
|
*/
|
|
public static class TestCmisServiceFactory extends AbstractServiceFactory
|
|
{
|
|
private static AlfrescoCmisServiceFactory serviceFactory = (AlfrescoCmisServiceFactory) ctx.getBean("CMISServiceFactory");
|
|
@Override
|
|
public void init(Map<String, String> parameters)
|
|
{
|
|
serviceFactory.init(parameters);
|
|
}
|
|
|
|
@Override
|
|
public void destroy()
|
|
{
|
|
}
|
|
|
|
@Override
|
|
public CmisService getService(CallContext context)
|
|
{
|
|
return serviceFactory.getService(context);
|
|
}
|
|
}
|
|
|
|
private static class SimpleCallContext implements CallContext
|
|
{
|
|
private final Map<String, Object> contextMap = new HashMap<String, Object>();
|
|
|
|
public SimpleCallContext(String user, String password)
|
|
{
|
|
contextMap.put(USERNAME, user);
|
|
contextMap.put(PASSWORD, password);
|
|
}
|
|
|
|
public String getBinding()
|
|
{
|
|
return BINDING_LOCAL;
|
|
}
|
|
|
|
public Object get(String key)
|
|
{
|
|
return contextMap.get(key);
|
|
}
|
|
|
|
public String getRepositoryId()
|
|
{
|
|
return (String) get(REPOSITORY_ID);
|
|
}
|
|
|
|
public String getUsername()
|
|
{
|
|
return (String) get(USERNAME);
|
|
}
|
|
|
|
public String getPassword()
|
|
{
|
|
return (String) get(PASSWORD);
|
|
}
|
|
|
|
public String getLocale()
|
|
{
|
|
return null;
|
|
}
|
|
|
|
public BigInteger getOffset()
|
|
{
|
|
return (BigInteger) get(OFFSET);
|
|
}
|
|
|
|
public BigInteger getLength()
|
|
{
|
|
return (BigInteger) get(LENGTH);
|
|
}
|
|
|
|
public boolean isObjectInfoRequired()
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public File getTempDirectory()
|
|
{
|
|
return null;
|
|
}
|
|
|
|
public int getMemoryThreshold()
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
public long getMaxContentSize()
|
|
{
|
|
return Long.MAX_VALUE;
|
|
}
|
|
}
|
|
|
|
@Before
|
|
public void before()
|
|
{
|
|
this.fileFolderService = (FileFolderService)ctx.getBean("FileFolderService");
|
|
this.transactionService = (TransactionService)ctx.getBean("transactionService");
|
|
this.nodeService = (NodeService)ctx.getBean("NodeService");
|
|
this.repositoryHelper = (Repository)ctx.getBean("repositoryHelper");
|
|
this.factory = (AlfrescoCmisServiceFactory)ctx.getBean("CMISServiceFactory");
|
|
this.context = new SimpleCallContext("admin", "admin");
|
|
}
|
|
|
|
/**
|
|
* ALF-18006 Test content mimetype auto-detection into CmisStreamInterceptor when "Content-Type" is not defined.
|
|
*/
|
|
@Test
|
|
public void testContentMimeTypeDetection()
|
|
{
|
|
String repositoryId = null;
|
|
|
|
CmisService cmisService = factory.getService(context);
|
|
try
|
|
{
|
|
// get repository id
|
|
List<RepositoryInfo> repositories = cmisService.getRepositoryInfos(null);
|
|
assertTrue(repositories.size() > 0);
|
|
RepositoryInfo repo = repositories.get(0);
|
|
repositoryId = repo.getId();
|
|
|
|
// create content properties
|
|
PropertiesImpl properties = new PropertiesImpl();
|
|
String objectTypeId = "cmis:document";
|
|
properties.addProperty(new PropertyIdImpl(PropertyIds.OBJECT_TYPE_ID, objectTypeId));
|
|
String fileName = "textFile" + GUID.generate();
|
|
properties.addProperty(new PropertyStringImpl(PropertyIds.NAME, fileName));
|
|
|
|
// create content stream
|
|
ContentStreamImpl contentStream = new ContentStreamImpl(fileName, MimetypeMap.MIMETYPE_TEXT_PLAIN, "Simple text plain document");
|
|
|
|
// create simple text plain content
|
|
String objectId = cmisService.create(repositoryId, properties, repositoryHelper.getCompanyHome().toString(), contentStream, VersioningState.MAJOR, null, null);
|
|
|
|
Holder<String> objectIdHolder = new Holder<String>(objectId);
|
|
|
|
// 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>");
|
|
cmisService.setContentStream(repositoryId, objectIdHolder, true, null, contentStreamHTML, null);
|
|
|
|
// check mimetype
|
|
boolean mimetypeHTML = cmisService.getObjectInfo(repositoryId, objectId).getContentType().equals(MimetypeMap.MIMETYPE_HTML);
|
|
assertTrue("Mimetype is not defined correctly.", mimetypeHTML);
|
|
}
|
|
finally
|
|
{
|
|
cmisService.close();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Test for ALF-16310.
|
|
*
|
|
* Check that, for AtomPub binding, cancel checkout on the originating checked out document i.e. not the working
|
|
* copy throws an exception and does not delete the document.
|
|
*/
|
|
@SuppressWarnings("unchecked")
|
|
@Test
|
|
public void testCancelCheckout()
|
|
{
|
|
String repositoryId = null;
|
|
ObjectData objectData = null;
|
|
Holder<String> objectId = null;
|
|
|
|
final String folderName = "testfolder." + GUID.generate();
|
|
final String docName = "testdoc.txt." + GUID.generate();
|
|
|
|
AuthenticationUtil.pushAuthentication();
|
|
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
|
|
try
|
|
{
|
|
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);
|
|
|
|
FileInfo fileInfo = fileFolderService.create(folderInfo.getNodeRef(), docName, ContentModel.TYPE_CONTENT);
|
|
nodeService.setProperty(fileInfo.getNodeRef(), ContentModel.PROP_NAME, docName);
|
|
|
|
return folderInfo;
|
|
}
|
|
});
|
|
|
|
CmisService service = factory.getService(context);
|
|
try
|
|
{
|
|
List<RepositoryInfo> repositories = service.getRepositoryInfos(null);
|
|
assertTrue(repositories.size() > 0);
|
|
RepositoryInfo repo = repositories.get(0);
|
|
repositoryId = repo.getId();
|
|
objectData = service.getObjectByPath(repositoryId, "/" + folderName + "/" + docName, null, true,
|
|
IncludeRelationships.NONE, null, false, true, null);
|
|
|
|
// checkout
|
|
objectId = new Holder<String>(objectData.getId());
|
|
service.checkOut(repositoryId, objectId, null, new Holder<Boolean>(true));
|
|
}
|
|
finally
|
|
{
|
|
service.close();
|
|
}
|
|
|
|
// AtomPub cancel checkout
|
|
try
|
|
{
|
|
service = factory.getService(context);
|
|
|
|
// check allowable actions
|
|
ObjectData originalDoc = service.getObject(repositoryId, objectData.getId(), null, true, IncludeRelationships.NONE, null, false, true, null);
|
|
AllowableActions allowableActions = originalDoc.getAllowableActions();
|
|
assertNotNull(allowableActions);
|
|
assertFalse(allowableActions.getAllowableActions().contains(Action.CAN_DELETE_OBJECT));
|
|
|
|
// try to cancel the checkout
|
|
service.deleteObjectOrCancelCheckOut(repositoryId, objectData.getId(), Boolean.TRUE, null);
|
|
fail();
|
|
}
|
|
catch(CmisConstraintException e)
|
|
{
|
|
// expected
|
|
}
|
|
finally
|
|
{
|
|
service.close();
|
|
}
|
|
|
|
try
|
|
{
|
|
service = factory.getService(context);
|
|
|
|
// cancel checkout on pwc
|
|
service.deleteObjectOrCancelCheckOut(repositoryId, objectId.getValue(), Boolean.TRUE, null);
|
|
}
|
|
finally
|
|
{
|
|
service.close();
|
|
}
|
|
|
|
try
|
|
{
|
|
service = factory.getService(context);
|
|
|
|
// get original document
|
|
ObjectData originalDoc = service.getObject(repositoryId, objectData.getId(), null, true, IncludeRelationships.NONE, null, false, true, null);
|
|
Map<String, PropertyData<?>> properties = originalDoc.getProperties().getProperties();
|
|
PropertyData<Boolean> isVersionSeriesCheckedOutProp = (PropertyData<Boolean>)properties.get(PropertyIds.IS_VERSION_SERIES_CHECKED_OUT);
|
|
assertNotNull(isVersionSeriesCheckedOutProp);
|
|
Boolean isVersionSeriesCheckedOut = isVersionSeriesCheckedOutProp.getFirstValue();
|
|
assertNotNull(isVersionSeriesCheckedOut);
|
|
assertEquals(Boolean.FALSE, isVersionSeriesCheckedOut);
|
|
}
|
|
finally
|
|
{
|
|
service.close();
|
|
}
|
|
|
|
try
|
|
{
|
|
service = factory.getService(context);
|
|
|
|
// delete original document
|
|
service.deleteObject(repositoryId, objectData.getId(), true, null);
|
|
}
|
|
finally
|
|
{
|
|
service.close();
|
|
}
|
|
|
|
List<FileInfo> children = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<List<FileInfo>>()
|
|
{
|
|
@Override
|
|
public List<FileInfo> execute() throws Throwable
|
|
{
|
|
List<FileInfo> children = fileFolderService.list(folderInfo.getNodeRef());
|
|
return children;
|
|
}
|
|
});
|
|
assertEquals(0, children.size());
|
|
}
|
|
finally
|
|
{
|
|
AuthenticationUtil.popAuthentication();
|
|
}
|
|
}
|
|
}
|