1 17 package org.alfresco.webservice.sample; 18 19 import org.alfresco.webservice.repository.UpdateResult; 20 import org.alfresco.webservice.types.CML; 21 import org.alfresco.webservice.types.CMLCreate; 22 import org.alfresco.webservice.types.ContentFormat; 23 import org.alfresco.webservice.types.NamedValue; 24 import org.alfresco.webservice.types.ParentReference; 25 import org.alfresco.webservice.types.Predicate; 26 import org.alfresco.webservice.types.Reference; 27 import org.alfresco.webservice.types.Store; 28 import org.alfresco.webservice.types.StoreEnum; 29 import org.alfresco.webservice.util.Constants; 30 import org.alfresco.webservice.util.WebServiceFactory; 31 32 35 public class WebServiceSampleBase 36 { 37 38 protected static final String USERNAME = "admin"; 39 protected static final String PASSWORD = "admin"; 40 41 42 protected static final Store STORE = new Store(StoreEnum.workspace, "SpacesStore"); 43 44 protected static final Reference SAMPLE_FOLDER = new Reference(STORE, null, "/app:company_home/cm:sample_folder"); 45 46 protected static void createSampleData() throws Exception  47 { 48 try 49 { 50 WebServiceFactory.getRepositoryService().get(new Predicate(new Reference[]{SAMPLE_FOLDER}, STORE, null)); 52 } 53 catch (Exception exception) 54 { 55 ParentReference parentReference = new ParentReference( 57 STORE, 58 null, 59 "/app:company_home", 60 Constants.ASSOC_CONTAINS, 61 Constants.createQNameString(Constants.NAMESPACE_CONTENT_MODEL, "sample_folder")); 62 63 NamedValue[] properties = new NamedValue[]{new NamedValue(Constants.PROP_NAME, "Web Service Sample Folder")}; 65 CMLCreate create = new CMLCreate("1", parentReference, Constants.TYPE_FOLDER, properties); 66 CML cml = new CML(); 67 cml.setCreate(new CMLCreate[]{create}); 68 UpdateResult[] results = WebServiceFactory.getRepositoryService().update(cml); 69 70 Reference sampleFolder = results[0].getDestination(); 72 ParentReference parentReference2 = new ParentReference( 73 STORE, 74 sampleFolder.getUuid(), 75 null, 76 Constants.ASSOC_CONTAINS, 77 Constants.createQNameString(Constants.NAMESPACE_CONTENT_MODEL, "sample_content")); 78 79 NamedValue[] properties2 = new NamedValue[]{new NamedValue(Constants.PROP_NAME, "SampleContent.txt")}; 81 CMLCreate create2 = new CMLCreate("1", parentReference2, Constants.TYPE_CONTENT, properties2); 82 CML cml2 = new CML(); 83 cml2.setCreate(new CMLCreate[]{create2}); 84 UpdateResult[] results2 = WebServiceFactory.getRepositoryService().update(cml2); 85 86 ContentFormat format = new ContentFormat(Constants.MIMETYPE_TEXT_PLAIN, "UTF-8"); 88 byte[] content = "This is some test content provided by the Alfresco development team!".getBytes(); 89 WebServiceFactory.getContentService().write(results2[0].getDestination(), Constants.PROP_CONTENT, content, format); 90 91 } 92 } 93 } 94
| Popular Tags
|