mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
Merged 5.1.N (5.1.1) to HEAD (5.1)
120109 nsmintanca: Merged 5.0.N (5.0.4) to 5.1.N (5.1.1) 120046 abozianu: Merged DEV to 5.0.N (5.0.4) 117528 abozianu: MNT-14687 : Creating a document as checkedout and then cancelling the checkout should delete the document - added a new aspect for cmis checked out documents : ASPECT_CMIS_CHECKEDOUT 118441 abozianu: MNT-14687 : Creating a document as checkedout and then cancelling the checkout should delete the document - changed aspect name from ASPECT_CMIS_CHECKEDOUT to ASPECT_CMIS_CREATED_CHECKEDOUT 118775 abozianu: MNT-14687 : Creating a document as checkedout and then cancelling the checkout should delete the document - fixed commit error git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@123614 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1015,6 +1015,10 @@
|
|||||||
</mandatory-aspects>
|
</mandatory-aspects>
|
||||||
</aspect>
|
</aspect>
|
||||||
|
|
||||||
|
<aspect name="cm:cmisCreatedCheckedOut">
|
||||||
|
<title>CMIS Created Checked Out</title>
|
||||||
|
</aspect>
|
||||||
|
|
||||||
<aspect name="cm:versionable">
|
<aspect name="cm:versionable">
|
||||||
<title>Versionable</title>
|
<title>Versionable</title>
|
||||||
<properties>
|
<properties>
|
||||||
|
@@ -1447,9 +1447,8 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen
|
|||||||
nodeService.addAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE, null);
|
nodeService.addAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Serializable> versionProperties = new HashMap<String, Serializable>(5);
|
// MNT-14687 : Creating a document as checkedout and then cancelling the checkout should delete the document
|
||||||
versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MAJOR);
|
nodeService.addAspect(nodeRef, ContentModel.ASPECT_CMIS_CREATED_CHECKEDOUT, null);
|
||||||
versionProperties.put(VersionModel.PROP_DESCRIPTION, "Initial Version");
|
|
||||||
|
|
||||||
getCheckOutCheckInService().checkout(nodeRef);
|
getCheckOutCheckInService().checkout(nodeRef);
|
||||||
}
|
}
|
||||||
|
@@ -488,6 +488,7 @@ public class CheckOutCheckInServiceImpl implements CheckOutCheckInService,Extens
|
|||||||
nodeService.addAspect(workingCopy, ContentModel.ASPECT_LOCKABLE, null);
|
nodeService.addAspect(workingCopy, ContentModel.ASPECT_LOCKABLE, null);
|
||||||
nodeService.addAspect(nodeRef, ContentModel.ASPECT_CHECKED_OUT, null);
|
nodeService.addAspect(nodeRef, ContentModel.ASPECT_CHECKED_OUT, null);
|
||||||
nodeService.createAssociation(nodeRef, workingCopy, ContentModel.ASSOC_WORKING_COPY_LINK);
|
nodeService.createAssociation(nodeRef, workingCopy, ContentModel.ASSOC_WORKING_COPY_LINK);
|
||||||
|
nodeService.removeAspect(workingCopy, ContentModel.ASPECT_CMIS_CREATED_CHECKEDOUT);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -648,13 +649,17 @@ public class CheckOutCheckInServiceImpl implements CheckOutCheckInService,Extens
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (versionProperties != null && nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE))
|
if (versionProperties != null &&
|
||||||
|
nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE) &&
|
||||||
|
!nodeService.hasAspect(nodeRef, ContentModel.ASPECT_CMIS_CREATED_CHECKEDOUT))
|
||||||
{
|
{
|
||||||
// Create the new version
|
// Create the new version
|
||||||
this.versionService.createVersion(nodeRef, versionProperties);
|
this.versionService.createVersion(nodeRef, versionProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nodeService.removeAspect(nodeRef, ContentModel.ASPECT_CMIS_CREATED_CHECKEDOUT);
|
||||||
|
|
||||||
if (keepCheckedOut == false)
|
if (keepCheckedOut == false)
|
||||||
{
|
{
|
||||||
// Delete the working copy
|
// Delete the working copy
|
||||||
@@ -728,6 +733,11 @@ public class CheckOutCheckInServiceImpl implements CheckOutCheckInService,Extens
|
|||||||
|
|
||||||
// Invoke policy
|
// Invoke policy
|
||||||
invokeOnCancelCheckOut(nodeRef);
|
invokeOnCancelCheckOut(nodeRef);
|
||||||
|
|
||||||
|
if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_CMIS_CREATED_CHECKEDOUT))
|
||||||
|
{
|
||||||
|
nodeService.deleteNode(nodeRef);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (UnableToReleaseLockException exception)
|
catch (UnableToReleaseLockException exception)
|
||||||
{
|
{
|
||||||
@@ -740,7 +750,7 @@ public class CheckOutCheckInServiceImpl implements CheckOutCheckInService,Extens
|
|||||||
|
|
||||||
return nodeRef;
|
return nodeRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Extend(traitAPI=CheckOutCheckInServiceTrait.class,extensionAPI=CheckOutCheckInServiceExtension.class)
|
@Extend(traitAPI=CheckOutCheckInServiceTrait.class,extensionAPI=CheckOutCheckInServiceExtension.class)
|
||||||
public NodeRef getWorkingCopy(NodeRef nodeRef)
|
public NodeRef getWorkingCopy(NodeRef nodeRef)
|
||||||
|
@@ -140,6 +140,11 @@ public class WorkingCopyAspect implements CopyServicePolicies.OnCopyNodePolicy,
|
|||||||
{
|
{
|
||||||
lockService.unlock(checkedOutNodeRef, false, true);
|
lockService.unlock(checkedOutNodeRef, false, true);
|
||||||
nodeService.removeAspect(checkedOutNodeRef, ContentModel.ASPECT_CHECKED_OUT);
|
nodeService.removeAspect(checkedOutNodeRef, ContentModel.ASPECT_CHECKED_OUT);
|
||||||
|
|
||||||
|
if (nodeService.hasAspect(checkedOutNodeRef, ContentModel.ASPECT_CMIS_CREATED_CHECKEDOUT))
|
||||||
|
{
|
||||||
|
nodeService.deleteNode(checkedOutNodeRef);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@@ -37,9 +37,13 @@ import org.alfresco.events.types.ContentReadRangeEvent;
|
|||||||
import org.alfresco.repo.content.MimetypeMap;
|
import org.alfresco.repo.content.MimetypeMap;
|
||||||
import org.alfresco.repo.content.filestore.FileContentWriter;
|
import org.alfresco.repo.content.filestore.FileContentWriter;
|
||||||
import org.alfresco.repo.events.EventPublisherForTestingOnly;
|
import org.alfresco.repo.events.EventPublisherForTestingOnly;
|
||||||
|
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||||
|
import org.alfresco.service.ServiceRegistry;
|
||||||
|
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
|
||||||
import org.alfresco.service.cmr.repository.ContentReader;
|
import org.alfresco.service.cmr.repository.ContentReader;
|
||||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
import org.alfresco.test_category.OwnJVMTestsCategory;
|
import org.alfresco.test_category.OwnJVMTestsCategory;
|
||||||
import org.alfresco.util.ApplicationContextHelper;
|
import org.alfresco.util.ApplicationContextHelper;
|
||||||
import org.alfresco.util.FileFilterMode.Client;
|
import org.alfresco.util.FileFilterMode.Client;
|
||||||
@@ -56,6 +60,7 @@ import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
|
|||||||
import org.apache.chemistry.opencmis.commons.PropertyIds;
|
import org.apache.chemistry.opencmis.commons.PropertyIds;
|
||||||
import org.apache.chemistry.opencmis.commons.SessionParameter;
|
import org.apache.chemistry.opencmis.commons.SessionParameter;
|
||||||
import org.apache.chemistry.opencmis.commons.data.ContentStream;
|
import org.apache.chemistry.opencmis.commons.data.ContentStream;
|
||||||
|
import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
|
||||||
import org.apache.chemistry.opencmis.commons.enums.BindingType;
|
import org.apache.chemistry.opencmis.commons.enums.BindingType;
|
||||||
import org.apache.chemistry.opencmis.commons.enums.VersioningState;
|
import org.apache.chemistry.opencmis.commons.enums.VersioningState;
|
||||||
import org.apache.chemistry.opencmis.commons.exceptions.CmisStorageException;
|
import org.apache.chemistry.opencmis.commons.exceptions.CmisStorageException;
|
||||||
@@ -83,6 +88,8 @@ public class OpenCmisLocalTest extends TestCase
|
|||||||
"classpath:opencmis/opencmistest-context.xml"
|
"classpath:opencmis/opencmistest-context.xml"
|
||||||
};
|
};
|
||||||
private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext(CONFIG_LOCATIONS);
|
private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext(CONFIG_LOCATIONS);
|
||||||
|
private static final String BEAN_NAME_AUTHENTICATION_COMPONENT = "authenticationComponent";
|
||||||
|
private static final String MIME_PLAIN_TEXT = "text/plain";
|
||||||
private ThresholdOutputStreamFactory streamFactory;
|
private ThresholdOutputStreamFactory streamFactory;
|
||||||
private EventPublisherForTestingOnly eventPublisher;
|
private EventPublisherForTestingOnly eventPublisher;
|
||||||
|
|
||||||
@@ -436,4 +443,52 @@ public class OpenCmisLocalTest extends TestCase
|
|||||||
{
|
{
|
||||||
void methodA(ContentStream csa, String str, ContentStream csb, ContentStream csc, int i) throws Exception;
|
void methodA(ContentStream csa, String str, ContentStream csb, ContentStream csc, int i) throws Exception;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MNT-14687 - Creating a document as checkedout and then cancelling the
|
||||||
|
* checkout should delete the document.
|
||||||
|
*
|
||||||
|
* This test would have fit better within CheckOutCheckInServiceImplTest but
|
||||||
|
* was added here to make use of existing methods
|
||||||
|
*/
|
||||||
|
public void testCancelCheckoutWhileInCheckedOutState()
|
||||||
|
{
|
||||||
|
ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
|
||||||
|
CheckOutCheckInService cociService = serviceRegistry.getCheckOutCheckInService();
|
||||||
|
|
||||||
|
// Authenticate as system
|
||||||
|
AuthenticationComponent authenticationComponent = (AuthenticationComponent) ctx.getBean(BEAN_NAME_AUTHENTICATION_COMPONENT);
|
||||||
|
authenticationComponent.setSystemUserAsCurrentUser();
|
||||||
|
|
||||||
|
/* Create the document using openCmis services */
|
||||||
|
Repository repository = getRepository("admin", "admin");
|
||||||
|
Session session = repository.createSession();
|
||||||
|
Folder rootFolder = session.getRootFolder();
|
||||||
|
|
||||||
|
// Set file properties
|
||||||
|
String docname = "myDoc-" + GUID.generate() + ".txt";
|
||||||
|
Map<String, String> props = new HashMap<String, String>();
|
||||||
|
{
|
||||||
|
props.put(PropertyIds.OBJECT_TYPE_ID, BaseTypeId.CMIS_DOCUMENT.value());
|
||||||
|
props.put(PropertyIds.NAME, docname);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create some content
|
||||||
|
byte[] byteContent = "Some content".getBytes();
|
||||||
|
InputStream stream = new ByteArrayInputStream(byteContent);
|
||||||
|
ContentStream contentStream = new ContentStreamImpl(docname, BigInteger.valueOf(byteContent.length), MIME_PLAIN_TEXT, stream);
|
||||||
|
|
||||||
|
// Create the document
|
||||||
|
Document doc1 = rootFolder.createDocument(props, contentStream, VersioningState.CHECKEDOUT);
|
||||||
|
NodeRef doc1NodeRef = cmisIdToNodeRef(doc1.getId());
|
||||||
|
NodeRef doc1WorkingCopy = cociService.getWorkingCopy(doc1NodeRef);
|
||||||
|
|
||||||
|
/* Cancel Checkout */
|
||||||
|
cociService.cancelCheckout(doc1WorkingCopy);
|
||||||
|
|
||||||
|
/* Check if both the working copy and the document were deleted */
|
||||||
|
NodeService nodeService = serviceRegistry.getNodeService();
|
||||||
|
assertFalse(nodeService.exists(doc1NodeRef));
|
||||||
|
assertFalse(nodeService.exists(doc1WorkingCopy));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user