Google Docs:

- Documents that have been previously checked out to Google Docs can now be deleted
  - Test updated
  - More logging added to service implementation



git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@22675 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Roy Wetherall
2010-09-24 02:01:38 +00:00
parent d9744facca
commit 4cb3309a74
3 changed files with 56 additions and 18 deletions

View File

@@ -341,14 +341,12 @@ public class GoogleDocsServiceImpl extends TransactionListenerAdapter
{
// Get the entry
DocumentListEntry entry = getDocumentListEntry(nodeRef);
if (entry == null)
if (entry != null)
{
throw new AlfrescoRuntimeException("Unable to find google resource to delete for node " + nodeRef.toString());
// Mark the resource for deletion upon completion of the transaction
markResource(KEY_MARKED_DELETE, entry.getResourceId());
}
// Mark the resource for deletion upon completion of the transaction
markResource(KEY_MARKED_DELETE, entry.getResourceId());
// Remove the aspect from the node
nodeService.removeAspect(nodeRef, ASPECT_GOOGLERESOURCE);
}
@@ -644,9 +642,14 @@ public class GoogleDocsServiceImpl extends TransactionListenerAdapter
*/
private DocumentListEntry getDocumentListEntry(NodeRef docNodeRef)
{
DocumentListEntry result = null;
String docType = (String)nodeService.getProperty(docNodeRef, PROP_RESOURCE_TYPE);
String docId = (String)nodeService.getProperty(docNodeRef, PROP_RESOURCE_ID);
return getDocumentListEntry(docType + ":" + docId);
if (docType != null && docId != null)
{
result = getDocumentListEntry(docType + ":" + docId);
}
return result;
}
/**
@@ -708,12 +711,21 @@ public class GoogleDocsServiceImpl extends TransactionListenerAdapter
try
{
if (logger.isDebugEnabled() == true)
{
logger.debug("Creating media content object for mimetype " + mimetype);
}
// Create the media content object
MediaContent mediaContent = new MediaContent();
mediaContent.setMimeType(new ContentType(mimetype));
if (is != null)
{
if (logger.isDebugEnabled() == true)
{
logger.debug(" ... input stream has been set");
}
mediaContent.setMediaSource(new MediaStreamSource(is, mimetype));
}
@@ -722,6 +734,10 @@ public class GoogleDocsServiceImpl extends TransactionListenerAdapter
if (parentFolder != null)
{
parentFolderUrl = ((MediaContent)parentFolder.getContent()).getUri();
if (logger.isDebugEnabled() == true)
{
logger.debug(" ... parent folder URL is " + parentFolderUrl);
}
}
// Create the document entry object
@@ -730,19 +746,35 @@ public class GoogleDocsServiceImpl extends TransactionListenerAdapter
MediaType.XLSX.getMimeType().equals(mimetype) == true ||
MediaType.ODS.getMimeType().equals(mimetype) == true)
{
if (logger.isDebugEnabled() == true)
{
logger.debug("Creating SpreadsheetEntry for mimetype " + mimetype);
}
docEntry = new SpreadsheetEntry();
}
else if (MediaType.PPS.getMimeType().equals(mimetype) == true ||
MediaType.PPT.getMimeType().equals(mimetype) == true)
{
if (logger.isDebugEnabled() == true)
{
logger.debug("Creating PresentationEntry for mimetype " + mimetype);
}
docEntry = new PresentationEntry();
}
else if (MediaType.PDF.getMimeType().equals(mimetype) == true)
{
if (logger.isDebugEnabled() == true)
{
logger.debug("Creating PdfEntry for mimetype " + mimetype);
}
docEntry = new PdfEntry();
}
else
{
if (logger.isDebugEnabled() == true)
{
logger.debug("Creating DocumentEntry for mimetype " + mimetype);
}
docEntry = new DocumentEntry();
}

View File

@@ -84,8 +84,6 @@ public class GoogleDocumentServiceSystemTest extends TestCase implements GoogleD
private static final String USER_SIX = "GoogleDocUserSix";
private static final String USER_SEVEN = "GoogleDocUserSeven";
//private static final String EMAIL_DOMAIN = "@alfresco.com";
private NodeRef folder = null;
private NodeRef nodeRefDoc = null;
private NodeRef nodeRefSpread = null;
@@ -166,9 +164,6 @@ public class GoogleDocumentServiceSystemTest extends TestCase implements GoogleD
contentWriter.setEncoding("UTF-8");
contentWriter.setMimetype(MimetypeMap.MIMETYPE_EXCEL);
contentWriter.putContent("");
ContentData contentData = (ContentData)nodeService.getProperty(nodeRef2, ContentModel.PROP_CONTENT);
System.out.println(" ********** Content data = " + contentData.toString());
}
private NodeRef createTestDocument(String name, String contentPath, String mimetype)
@@ -271,9 +266,6 @@ public class GoogleDocumentServiceSystemTest extends TestCase implements GoogleD
{
if (isGoogleServiceAvailable() == true)
{
ContentReader contentReader = contentService.getReader(nodeRef2, ContentModel.PROP_CONTENT);
//assertNull(contentReader);
// Check out the empty google document
NodeRef workingCopy = checkOutCheckInService.checkout(nodeRef2);
@@ -288,9 +280,12 @@ public class GoogleDocumentServiceSystemTest extends TestCase implements GoogleD
checkOutCheckInService.checkin(workingCopy, null);
assertFalse(nodeService.hasAspect(nodeRefDoc, ASPECT_GOOGLERESOURCE));
contentReader = contentService.getReader(nodeRef2, ContentModel.PROP_CONTENT);
assertNotNull(contentReader);
assertFalse(nodeService.hasAspect(nodeRef2, ASPECT_GOOGLERESOURCE));
ContentReader contentReader = contentService.getReader(nodeRef2, ContentModel.PROP_CONTENT);
assertNotNull(contentReader);
// Lets try and delete the checked in node reference
nodeService.deleteNode(nodeRef2);
}
}

View File

@@ -27,6 +27,7 @@ import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.coci.CheckOutCheckInServicePolicies;
import org.alfresco.repo.coci.CheckOutCheckInServicePolicies.BeforeCheckIn;
import org.alfresco.repo.coci.CheckOutCheckInServicePolicies.OnCheckIn;
import org.alfresco.repo.coci.CheckOutCheckInServicePolicies.OnCheckOut;
import org.alfresco.repo.copy.CopyBehaviourCallback;
import org.alfresco.repo.copy.CopyDetails;
@@ -53,6 +54,7 @@ import org.alfresco.service.namespace.QName;
public class GoogleEditableAspect implements NodeServicePolicies.OnAddAspectPolicy,
CheckOutCheckInServicePolicies.OnCheckOut,
CheckOutCheckInServicePolicies.BeforeCheckIn,
CheckOutCheckInServicePolicies.OnCheckIn,
NodeServicePolicies.BeforeDeleteNodePolicy
{
/** Indicates whether behaviour is enabled or not */
@@ -140,6 +142,9 @@ public class GoogleEditableAspect implements NodeServicePolicies.OnAddAspectPoli
policyComponent.bindClassBehaviour(BeforeCheckIn.QNAME,
GoogleDocsModel.ASPECT_GOOGLERESOURCE,
new JavaBehaviour(this, "beforeCheckIn", NotificationFrequency.FIRST_EVENT));
policyComponent.bindClassBehaviour(OnCheckIn.QNAME,
GoogleDocsModel.ASPECT_GOOGLERESOURCE,
new JavaBehaviour(this, "onCheckIn", NotificationFrequency.FIRST_EVENT));
policyComponent.bindClassBehaviour(BeforeDeleteNodePolicy.QNAME,
GoogleDocsModel.ASPECT_GOOGLERESOURCE,
new JavaBehaviour(this, "beforeDeleteNode", NotificationFrequency.FIRST_EVENT));
@@ -213,7 +218,7 @@ public class GoogleEditableAspect implements NodeServicePolicies.OnAddAspectPoli
// Write the google content into the node
ContentWriter writer = contentService.getWriter(workingCopyNodeRef, ContentModel.PROP_CONTENT, true);
writer.putContent(is);
writer.putContent(is);
}
}
@@ -266,4 +271,10 @@ public class GoogleEditableAspect implements NodeServicePolicies.OnAddAspectPoli
return Collections.emptyMap();
}
}
@Override
public void onCheckIn(NodeRef nodeRef)
{
nodeService.removeAspect(nodeRef, GoogleDocsModel.ASPECT_GOOGLERESOURCE);
}
}