1 17 package org.alfresco.webservice.sample; 18 19 import org.alfresco.webservice.authoring.AuthoringServiceSoapBindingStub; 20 import org.alfresco.webservice.authoring.CheckoutResult; 21 import org.alfresco.webservice.content.Content; 22 import org.alfresco.webservice.content.ContentServiceSoapBindingStub; 23 import org.alfresco.webservice.repository.RepositoryServiceSoapBindingStub; 24 import org.alfresco.webservice.types.CML; 25 import org.alfresco.webservice.types.CMLAddAspect; 26 import org.alfresco.webservice.types.ContentFormat; 27 import org.alfresco.webservice.types.NamedValue; 28 import org.alfresco.webservice.types.Predicate; 29 import org.alfresco.webservice.types.Reference; 30 import org.alfresco.webservice.types.Store; 31 import org.alfresco.webservice.types.StoreEnum; 32 import org.alfresco.webservice.types.Version; 33 import org.alfresco.webservice.types.VersionHistory; 34 import org.alfresco.webservice.util.AuthenticationUtils; 35 import org.alfresco.webservice.util.Constants; 36 import org.alfresco.webservice.util.ContentUtils; 37 import org.alfresco.webservice.util.WebServiceFactory; 38 39 47 public class WebServiceSample5 extends WebServiceSampleBase 48 { 49 private final static String INITIAL_CONTENT = "This is the content pror to checkout"; 50 private final static String UPDATED_CONTENT = "This is the updated content"; 51 52 55 public static void main(String [] args) 56 throws Exception  57 { 58 AuthenticationUtils.startSession(USERNAME, PASSWORD); 59 try 60 { 61 createSampleData(); 63 64 RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService(); 66 ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService(); 67 AuthoringServiceSoapBindingStub authoringService = WebServiceFactory.getAuthoringService(); 68 69 Reference contentReference = WebServiceSample3.createNewContent(contentService, "SampleFiveFileOne.txt", INITIAL_CONTENT); 71 72 makeVersionable(repositoryService, contentReference); 74 75 Predicate itemsToCheckOut = new Predicate(new Reference[]{contentReference}, null, null); 77 CheckoutResult checkOutResult = authoringService.checkout(itemsToCheckOut, null); 78 79 Reference workingCopyReference = checkOutResult.getWorkingCopies()[0]; 81 82 ContentFormat format = new ContentFormat(Constants.MIMETYPE_TEXT_PLAIN, "UTF-8"); 84 contentService.write(workingCopyReference, Constants.PROP_CONTENT, UPDATED_CONTENT.getBytes(), format); 85 86 Predicate predicate = new Predicate(new Reference[]{workingCopyReference}, null, null); 88 NamedValue[] comments = new NamedValue[]{new NamedValue("description", "The content has been updated")}; 89 authoringService.checkin(predicate, comments, false); 90 91 Store store = new Store(StoreEnum.workspace, "SpacesStore"); 93 Content[] readResult = contentService.read( 94 new Predicate(new Reference[]{contentReference}, store, null), 95 Constants.PROP_CONTENT); 96 Content content = readResult[0]; 97 System.out.println("This is the checked-in content:"); 98 System.out.println(ContentUtils.getContentAsString(content)); 99 100 System.out.println("The version history:"); 102 VersionHistory versionHistory = authoringService.getVersionHistory(contentReference); 103 for (Version version : versionHistory.getVersions()) 104 { 105 outputVersion(version); 107 } 108 } 109 finally 110 { 111 AuthenticationUtils.endSession(); 113 } 114 } 115 116 125 public static void makeVersionable(RepositoryServiceSoapBindingStub respositoryService, Reference reference) 126 throws Exception  127 { 128 Predicate predicate = new Predicate(new Reference[]{reference}, null, null); 130 CMLAddAspect addAspect = new CMLAddAspect(Constants.ASPECT_VERSIONABLE, null, predicate, null); 131 132 CML cml = new CML(); 134 cml.setAddAspect(new CMLAddAspect[]{addAspect}); 135 136 respositoryService.update(cml); 138 } 139 140 145 private static void outputVersion(Version version) 146 { 147 String description = "none"; 148 for (NamedValue namedValue : version.getCommentaries()) 149 { 150 if (namedValue.getName().equals("description") == true) 151 { 152 description = namedValue.getValue(); 153 } 154 } 155 System.out.println("Version label = " + version.getLabel() + "; Version description = " + description); 156 } 157 } 158
| Popular Tags
|