chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1221638 - in /chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util: pom.xml src/main/java/org/apache/chemistry/opencmis/util/specexamples/Main.java
Date Wed, 21 Dec 2011 07:55:51 GMT
Author: jens
Date: Wed Dec 21 07:55:51 2011
New Revision: 1221638

URL: http://svn.apache.org/viewvc?rev=1221638&view=rev
Log:
Improve generator for CMIS spec examples.

Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/pom.xml
    chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/specexamples/Main.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/pom.xml
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/pom.xml?rev=1221638&r1=1221637&r2=1221638&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/pom.xml
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/pom.xml
Wed Dec 21 07:55:51 2011
@@ -48,5 +48,10 @@
             <artifactId>chemistry-opencmis-client-bindings</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+            <version>2.0.1</version>
+        </dependency>     
     </dependencies>
 </project>

Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/specexamples/Main.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/specexamples/Main.java?rev=1221638&r1=1221637&r2=1221638&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/specexamples/Main.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/specexamples/Main.java
Wed Dec 21 07:55:51 2011
@@ -18,7 +18,11 @@
  */
 package org.apache.chemistry.opencmis.util.specexamples;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
+import java.io.FileFilter;
+import java.io.IOException;
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -27,40 +31,51 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.chemistry.opencmis.client.bindings.CmisBindingFactory;
+import org.apache.chemistry.opencmis.client.bindings.impl.CmisBindingImpl;
+import org.apache.chemistry.opencmis.commons.PropertyIds;
 import org.apache.chemistry.opencmis.commons.SessionParameter;
 import org.apache.chemistry.opencmis.commons.data.Ace;
 import org.apache.chemistry.opencmis.commons.data.Acl;
+import org.apache.chemistry.opencmis.commons.data.ContentStream;
+import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
 import org.apache.chemistry.opencmis.commons.data.ObjectInFolderData;
 import org.apache.chemistry.opencmis.commons.data.ObjectInFolderList;
+import org.apache.chemistry.opencmis.commons.data.Properties;
+import org.apache.chemistry.opencmis.commons.data.PropertyData;
 import org.apache.chemistry.opencmis.commons.data.RepositoryInfo;
-import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
-import org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionList;
 import org.apache.chemistry.opencmis.commons.enums.AclPropagation;
 import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
 import org.apache.chemistry.opencmis.commons.enums.BindingType;
 import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
+import org.apache.chemistry.opencmis.commons.enums.VersioningState;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.BindingsObjectFactoryImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl;
 import org.apache.chemistry.opencmis.commons.spi.AclService;
 import org.apache.chemistry.opencmis.commons.spi.BindingsObjectFactory;
 import org.apache.chemistry.opencmis.commons.spi.CmisBinding;
 import org.apache.chemistry.opencmis.commons.spi.DiscoveryService;
+import org.apache.chemistry.opencmis.commons.spi.Holder;
 import org.apache.chemistry.opencmis.commons.spi.MultiFilingService;
 import org.apache.chemistry.opencmis.commons.spi.NavigationService;
 import org.apache.chemistry.opencmis.commons.spi.ObjectService;
 import org.apache.chemistry.opencmis.commons.spi.RepositoryService;
 import org.apache.chemistry.opencmis.commons.spi.VersioningService;
+import org.apache.commons.io.filefilter.WildcardFileFilter;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 public class Main {
 
     private static final Log LOG = LogFactory.getLog(Main.class.getName());
-    private BigInteger MAX_ITEMS = BigInteger.valueOf(-1);
-    private BigInteger SKIP_COUNT = BigInteger.valueOf(0);
-    private static final String COMPLEX_TYPE = "ComplexType";
+    private static final BigInteger MAX_ITEMS = BigInteger.valueOf(-1);
+    private static final BigInteger SKIP_COUNT = BigInteger.valueOf(0);
+    // private static final String COMPLEX_TYPE = "ComplexType";
     private static final String TOPLEVEL_TYPE = "DocumentTopLevel";
-    
+    private static final String VERSIONED_TYPE = "VersionableType";
+    private static String LOGDIR = System.getProperty("java.io.tmpdir");// + File.separator;
+
     private BindingsObjectFactory objFactory = new BindingsObjectFactoryImpl();
+    private BindingType bindingType;
     private String rootFolderId;
     private String repositoryId;
     private ObjectService objSvc;
@@ -71,51 +86,50 @@ public class Main {
     private DiscoveryService discSvc;
     private AclService aclSvc;
 
-
-    private int requestCounter = 0;
-    private String logDir = System.getProperty("java.io.tmpdir") + File.separator;
-    
     public Main() {
-        init("A1");        
+        bindingType = BindingType.ATOMPUB;
+        init("http://localhost:8080/inmemory/atom", bindingType);
     }
-    
+
     public void run() {
-        
+        // Repository Service:
+        repositoryId = "A1";
         getRepositoryInfo();
+        getRepositories();
         String docId = getTestDocId();
-        requestCounter++;
         String folderId = getTestFolderId();
+
+        getTypeChildren(TOPLEVEL_TYPE);
+
+        // Navigation Service:
+        getChildren(folderId);
+        getDescendants(folderId);
+
+        // Object Service:
+        getObject(docId);
         getAcl(docId);
-        getAllowableActions(docId);
-        // getChangeLog();
-        getDocumentEntry(docId);
-        getFolderChildren(folderId);
-        getFolderDescendants(folderId);
-        getFolderEntry(folderId);
-        //getPolicyEntry(id);
-        //getRelationshipyEntry(id);
+        String id = createDocument("SampleDocument", TOPLEVEL_TYPE, rootFolderId, VersioningState.NONE);
+        updateProperties(id, PropertyIds.NAME, "RenamedDocument");
+        deleteObject(id);
+
+        // Discovery Service:
         doQuery();
-        getTypeChildren(TOPLEVEL_TYPE);
-        //getTypeDescendants();        
-        getTypeDocumentWith(COMPLEX_TYPE);
-//        getTypeDocumentWithout(COMPLEX_TYPE);
-        getTypeFolderWith("cmis:folder");
-//        getTypeFolderWithout("cmis:folder");
-        //getTypePolicyWith("cmis:policy");
-        //getTypePolicyWithout("cmis:policy");
-        //getTypeRelationshipWith("cmis:relationship");
-        //getTypeRelationshipWithout("cmis:relationship");
-        
+
+        // Versioning Service
+        id = prepareVersionSeries("VersionedDocument", VERSIONED_TYPE, rootFolderId);
+        checkOut(id);
+        checkIn(id, true, "final version in series");
+        getAllVersions(id);        
     }
-    
-    private void init(String repositoryId) {
+
+    private void init(String url, BindingType bindingType) {
         LOG.debug("Initializing connection to InMemory server: ");
         Map<String, String> parameters = new HashMap<String, String>();
         parameters.put(SessionParameter.USER, "admin");
         parameters.put(SessionParameter.PASSWORD, "admin");
 
-        parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());     
  
-        parameters.put(SessionParameter.ATOMPUB_URL, "http://localhost:8080/inmemory/atom");
+        parameters.put(SessionParameter.BINDING_TYPE, bindingType.value());
+        parameters.put(SessionParameter.ATOMPUB_URL, url);
 
         // get factory and create binding
         CmisBindingFactory factory = CmisBindingFactory.newInstance();
@@ -129,216 +143,154 @@ public class Main {
         multiSvc = binding.getMultiFilingService();
         discSvc = binding.getDiscoveryService();
         aclSvc = binding.getAclService();
-        
-        this.repositoryId = repositoryId;
-        LOG.debug("Initializing done. ");               
+        LOG.debug("Initializing done. ");
     }
-    
+
+    private void getRepositories() {
+        LOG.debug("getRepositories()");
+        List<RepositoryInfo> repositories = repSvc.getRepositoryInfos(null);
+        this.repositoryId = repositories.get(0).getId();
+        renameFiles("getRepositoryInfos");
+        LOG.debug("getRepositoryInfo() done.");
+    }
+
     private void getRepositoryInfo() {
         LOG.debug("getting repository info for repository " + repositoryId);
         RepositoryInfo repoInfo = repSvc.getRepositoryInfo(repositoryId, null);
         LOG.debug("root folder id is: " + repoInfo.getId());
-        rootFolderId =  repoInfo.getRootFolderId();        
+        rootFolderId = repoInfo.getRootFolderId();
         renameFiles("getRepositoryInfo");
-        requestCounter++;
         LOG.debug("getRepositoryInfo() done.");
     }
-    
-    private void getAcl(String objectId) {
-        LOG.debug("getting Acl() " + objectId);
-        // apply an ACL to the test doc
-        List<Ace> aces = new ArrayList<Ace>();
-        aces.add (objFactory.createAccessControlEntry("Alice", Collections.singletonList("cmis:read")));
-        aces.add (objFactory.createAccessControlEntry("Bob", Collections.singletonList("cmis:write")));
-        aces.add (objFactory.createAccessControlEntry("admin", Collections.singletonList("cmis:all")));
-        Acl acl = objFactory.createAccessControlList(aces);
-        aclSvc.applyAcl(repositoryId, objectId, acl, null, AclPropagation.OBJECTONLY, null);
-        requestCounter +=2; // note one internal in bindings layer
-        aclSvc.getAcl(repositoryId, objectId, true, null);
-        renameFiles("getAcl");
-        requestCounter++;
-        LOG.debug("getting Acl() done.");
-    }
 
-    private void getAllowableActions(String objectId) {
-        LOG.debug("getAllowableActions " + objectId);
-        objSvc.getAllowableActions(repositoryId, objectId, null);
-        renameFiles("getAllowableActions");
-        requestCounter++;
-        LOG.debug("getAllowableActions() done.");
+    private void getObject(String objectId) {
+        LOG.debug("getObject " + objectId);
+        objSvc.getObject(repositoryId, objectId, "*", false /* includeAllowableActions */,
+                IncludeRelationships.NONE /* includeRelationships */, null /* renditionFilter
*/,
+                false /* includePolicyIds */, false /* includeAcl */, null);
+        renameFiles("getObject");
+        LOG.debug("getObject() done.");
     }
 
-    private void getChangeLog() {
-        LOG.debug("getChangeLog " + repositoryId);
-        LOG.debug("Not implemented.");
-        // renameFiles("getChangeLog");
-        // requestCounter++;
-        LOG.debug("getChangeLog() done.");
-    }
-
-    private void getDocumentEntry(String objectId) {
-        LOG.debug("getDocumentEntry " + objectId);
-        objSvc.getObject(repositoryId, objectId, "*", false /*includeAllowableActions*/,
IncludeRelationships.NONE /*includeRelationships*/,
-                null /*renditionFilter*/, false /*includePolicyIds*/, false /*includeAcl*/,
null);
-        renameFiles("getDocumentEntry");
-        requestCounter++;
-        LOG.debug("getDocumentEntry() done.");
-    }
-
-    private void getFolderChildren(String folderId) {
-        LOG.debug("getFolderChildren " + folderId);
-        navSvc.getChildren(repositoryId, folderId, "*", null /*orderBy*/, false /*includeAllowableActions*/,
-                IncludeRelationships.NONE, null /*renditionFilter*/, true /*includePathSegment*/,
MAX_ITEMS, 
+    private void getChildren(String folderId) {
+        LOG.debug("getChildren " + folderId);
+        navSvc.getChildren(repositoryId, folderId, "*", null /* orderBy */, false /* includeAllowableActions
*/,
+                IncludeRelationships.NONE, null /* renditionFilter */, true /* includePathSegment
*/, MAX_ITEMS,
                 SKIP_COUNT, null);
-        renameFiles("getFolderChildren");
-        requestCounter++;
-        LOG.debug("getFolderChildren() done.");
+        renameFiles("getChildren");
+        LOG.debug("getChildren() done.");
     }
 
-    private void getFolderDescendants(String folderId) {
+    private void getDescendants(String folderId) {
         final BigInteger DEPTH = BigInteger.valueOf(3);
-        LOG.debug("getFolderDescendants " + folderId);
-        navSvc.getDescendants(repositoryId, folderId, DEPTH, "*", false /*includeAllowableActions*/,
IncludeRelationships.NONE,
-                null /*renditionFilter*/, true /*includePathSegment*/, null);
-        renameFiles("getFolderDescendants");
-        requestCounter++;
-        LOG.debug("getFolderDescendants() done.");
-    }
-
-    private void getFolderEntry(String folderId) {
-        LOG.debug("getFolderEntry " + folderId);
-        objSvc.getObject(repositoryId, folderId, "*", false /*includeAllowableActions*/,
IncludeRelationships.NONE /*includeRelationships*/,
-                null /*renditionFilter*/, false /*includePolicyIds*/, false /*includeAcl*/,
null);
-        renameFiles("getFolderEntry");
-        requestCounter++;
-        LOG.debug("getFolderEntry() done.");
-    }
-
-    private void getPolicyEntry(String policyId) {
-        LOG.debug("getPolicyEntry " + policyId);
-        objSvc.getObject(repositoryId, policyId, "*", false /*includeAllowableActions*/,
IncludeRelationships.NONE /*includeRelationships*/,
-                null /*renditionFilter*/, false /*includePolicyIds*/, false /*includeAcl*/,
null);
-        renameFiles("getPolicyEntry");
-        requestCounter++;
-        LOG.debug("getPolicyEntry() done.");
-    }
-
-    private void getRelationshipyEntry(String relId) {
-        LOG.debug("getRelationshipyEntry " + relId);
-        objSvc.getObject(repositoryId, relId, "*", false /*includeAllowableActions*/, IncludeRelationships.NONE
/*includeRelationships*/,
-                null /*renditionFilter*/, false /*includePolicyIds*/, false /*includeAcl*/,
null);
-        renameFiles("getRelationshipyEntry");
-        requestCounter++;
-        LOG.debug("getRelationshipyEntry() done.");
+        LOG.debug("getDescendants " + folderId);
+        navSvc.getDescendants(repositoryId, folderId, DEPTH, "*", false /* includeAllowableActions
*/,
+                IncludeRelationships.NONE, null /* renditionFilter */, true /* includePathSegment
*/, null);
+        renameFiles("getDescendants");
+        LOG.debug("getDescendants() done.");
     }
 
     private void doQuery() {
         LOG.debug("doQuery ");
         String statement = "SELECT * from cmis:document WHERE IN_FOLDER('" + rootFolderId
+ "')";
-        discSvc.query(repositoryId, statement, false /*searchAllVersions*/, false /*includeAllowableActions*/,
+        discSvc.query(repositoryId, statement, false /* searchAllVersions */, false /* includeAllowableActions
*/,
                 IncludeRelationships.NONE, null, MAX_ITEMS, SKIP_COUNT, null);
         renameFiles("doQuery");
-        requestCounter++;
         LOG.debug("doQuery() done.");
     }
 
     private void getTypeChildren(String typeId) {
         LOG.debug("getTypeChildren " + typeId);
-        requestCounter++;
-        repSvc.getTypeChildren(repositoryId, typeId, true /*includePropertyDefinitions*/,
MAX_ITEMS, 
-                SKIP_COUNT, null);
+        repSvc.getTypeChildren(repositoryId, typeId, true /* includePropertyDefinitions */,
MAX_ITEMS, SKIP_COUNT, null);
         renameFiles("getTypeChildren");
-        requestCounter++;
         LOG.debug("getTypeChildren() done.");
     }
 
-    /*
-    private void getTypeDescendants(String typeId) {
-        final BigInteger DEPTH = BigInteger.valueOf(-1);
-        LOG.debug("getTypeDescendants " + typeId);
-        repSvc.getTypeDescendants(repositoryId, typeId, DEPTH, true /*includePropertyDefinitions*
/,null);
-        renameFiles("getTypeDescendants");
-        LOG.debug("getTypeDescendants() done.");
-    }
-    */
-    
-    private void getTypeDocumentWith(String typeId) {
-        LOG.debug("getTypeDocumentWith " + typeId);
-        LOG.debug("Not implemented.");
-        getType(typeId, true);
-        renameFiles("getTypeDocumentWith");
-        requestCounter++;
-        LOG.debug("getTypeDocumentWith() done.");
-    }
-
-    private void getTypeDocumentWithout(String typeId) {
-        LOG.debug("getTypeDocumentWithout " + typeId);
-        getType(typeId, false);
-        renameFiles("getTypeDocumentWithout");
-        requestCounter++;
-        LOG.debug("getTypeDocumentWithout() done.");
-    }
-
-    private void getTypeFolderWith(String typeId) {
-        LOG.debug("getTypeFolderWith " + typeId);
-        getType(typeId, true);
-        renameFiles("getTypeFolderWith");
-        requestCounter++;
-        LOG.debug("getTypeFolderWith() done.");
-    }
-
-    private void getTypeFolderWithout(String typeId) {
-        LOG.debug("getTypeFolderWithout " + typeId);
-        getType(typeId, false);
-        renameFiles("getTypeFolderWithout");
-        requestCounter++;
-        LOG.debug("getTypeFolderWithout() done.");
-    }
-
-    private void getTypePolicyWith(String typeId) {
-        LOG.debug("getTypePolicyWith " + typeId);
-        getType(typeId, true);
-        renameFiles("getTypePolicyWith");
-        requestCounter++;
-        LOG.debug("getTypePolicyWith() done.");
-    }
-
-    private void getTypePolicyWithout(String typeId) {
-        LOG.debug("getTypePolicyWithout " + typeId);
-        getType(typeId, false);
-        renameFiles("getTypePolicyWithout");
-        requestCounter++;
-        LOG.debug("getTypePolicyWithout() done.");
-    }
-
-    private void getTypeRelationshipWith(String typeId) {
-        LOG.debug("getTypeRelationshipWith " + typeId);
-        getType(typeId, true);
-        renameFiles("getTypeRelationshipWith");
-        requestCounter++;
-        LOG.debug("getTypeRelationshipWith() done.");
-    }
-
-    private void getTypeRelationshipWithout(String typeId) {
-        LOG.debug("getTypeRelationshipyWithout " + typeId);
-        getType(typeId, false);
-        renameFiles("getTypeRelationshipyWithout");
-        requestCounter++;
-        LOG.debug("getTypeRelationshipyWithout() done.");
+    private String createDocument(String name, String typeId, String folderId, VersioningState
versioningState) {
+        LOG.debug("createDocument " + typeId);
+
+        String id = createDocumentIntern(name, typeId, folderId, versioningState);
+        renameFiles("createDocument");
+        LOG.debug("createDocument() done.");
+
+        return id;
+    }
+
+    private String createDocumentIntern(String name, String typeId, String folderId, VersioningState
versioningState) {
+        ContentStream contentStream = null;
+        List<String> policies = null;
+        Acl addACEs = null;
+        Acl removeACEs = null;
+        ExtensionsData extension = null;
+
+        List<PropertyData<?>> properties = new ArrayList<PropertyData<?>>();
+        properties.add(objFactory.createPropertyIdData(PropertyIds.NAME, name));
+        properties.add(objFactory.createPropertyIdData(PropertyIds.OBJECT_TYPE_ID, typeId));
+        Properties props = objFactory.createPropertiesData(properties);
+
+        contentStream = createContent();
+
+        String id = null;
+        id = objSvc.createDocument(repositoryId, props, folderId, contentStream, versioningState,
policies, addACEs,
+                removeACEs, extension);
+        return id;
+    }
+
+    private ContentStream createContent() {
+        ContentStreamImpl content = new ContentStreamImpl();
+        content.setFileName("data.txt");
+        content.setMimeType("text/plain");
+        int len = 32 * 1024;
+        byte[] b = { 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c,
0x6d, 0x6e, 0x0c, 0x0a,
+                0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d,
0x6e, 0x0c, 0x0a }; // 32
+        // Bytes
+        ByteArrayOutputStream ba = new ByteArrayOutputStream(len);
+        try {
+            for (int i = 0; i < 1024; i++) {
+                ba.write(b);
+            }
+        } catch (IOException e) {
+            throw new RuntimeException("Failed to fill content stream with data", e);
+        }
+        content.setStream(new ByteArrayInputStream(ba.toByteArray()));
+        content.setLength(BigInteger.valueOf(len));
+        return content;
+    }
+
+    private void updateProperties(String id, String propertyId, String propertyValue) {
+        LOG.debug("updateProperties " + id);
+        List<PropertyData<?>> properties = new ArrayList<PropertyData<?>>();
+        properties.add(objFactory.createPropertyStringData(propertyId, propertyValue));
+        Properties newProps = objFactory.createPropertiesData(properties);
+
+        Holder<String> idHolder = new Holder<String>(id);
+        Holder<String> changeTokenHolder = new Holder<String>();
+        objSvc.updateProperties(repositoryId, idHolder, changeTokenHolder, newProps, null);
+        renameFiles("updateProperties");
+        LOG.debug("updateProperties() done.");
+    }
+
+    private void deleteObject(String id) {
+        LOG.debug("deleteObject " + id);
+        objSvc.deleteObject(repositoryId, id, true, null);
+        renameFiles("deleteObject");
+        LOG.debug("deleteObject() done.");
     }
-    
+
     /**
-     * enumerate the children of the root folder and return the id
-     * of the first document
+     * enumerate the children of the root folder and return the id of the first
+     * document
+     * 
      * @return id of first doc in root folder
      */
     private String getTestDocId() {
         return getTestId(BaseTypeId.CMIS_DOCUMENT);
     }
-    
+
     /**
-     * enumerate the children of the root folder and return the id
-     * of the first sub-folder
+     * enumerate the children of the root folder and return the id of the first
+     * sub-folder
+     * 
      * @return id of first doc in root folder
      */
     private String getTestFolderId() {
@@ -349,26 +301,107 @@ public class Main {
         LOG.debug("getTestDocId()");
         ObjectInFolderList result = navSvc.getChildren(repositoryId, rootFolderId, "*", null,
false,
                 IncludeRelationships.NONE, null, true, MAX_ITEMS, SKIP_COUNT, null);
-        requestCounter++;
 
         List<ObjectInFolderData> children = result.getObjects();
         LOG.debug(" found " + children.size() + " folders in getChildren()");
         for (ObjectInFolderData child : children) {
-            if (baseTypeId.equals(child.getObject().getBaseTypeId())) 
+            if (baseTypeId.equals(child.getObject().getBaseTypeId()))
                 return child.getObject().getId();
         }
         return null;
     }
+
+    private String prepareVersionSeries(String name, String typeId, String folderId) {
+        String id = createDocumentIntern(name, typeId, folderId, VersioningState.MAJOR);
+        Holder<Boolean> contentCopied = new Holder<Boolean>(true);
+        Holder<String> idHolder = new Holder<String>(id);
+
+        verSvc.checkOut(repositoryId, idHolder, null, contentCopied);
+        String checkinComment = "Checkin V2.0";
+        verSvc.checkIn(repositoryId, idHolder, true /*major*/, null /*properties*/, null
/*content*/,
+                checkinComment, null/*policies*/, null/*addAcl*/, null /*removeAcl*/, null
/*extension*/);
+
+        verSvc.checkOut(repositoryId, idHolder, null, contentCopied);
+        checkinComment = "Checkin V2.1";
+        verSvc.checkIn(repositoryId, idHolder, false /*major*/, null /*properties*/, null
/*content*/,
+                checkinComment, null/*policies*/, null/*addAcl*/, null /*removeAcl*/, null
/*extension*/);
         
-    private TypeDefinition getType(String typeId, boolean withPropDefs) {
-        return repSvc.getTypeDefinition(repositoryId, typeId, null);
+        return idHolder.getValue();
+    }
+    
+    private void checkOut(String id) {
+        LOG.debug("checkOut()");        
+        Holder<String> idHolder = new Holder<String>(id);
+        Holder<Boolean> contentCopied = new Holder<Boolean>(true);
+        verSvc.checkOut(repositoryId, idHolder, null, contentCopied);
+        renameFiles("checkOut");
+        LOG.debug("checkOut done.");
+    }
+
+    private void checkIn(String id, boolean major, String checkinComment) {
+        LOG.debug("checkIn()");        
+        Holder<String> idHolder = new Holder<String>(id);
+        verSvc.checkIn(repositoryId, idHolder, major /*major*/, null /*properties*/, null
/*content*/,
+                checkinComment, null/*policies*/, null/*addAcl*/, null /*removeAcl*/, null
/*extension*/);
+        renameFiles("checkIn");
+        LOG.debug("checkIn done.");
+    }
+
+    private void getAllVersions(String id) {
+        LOG.debug("getAllVersions()");     
+        verSvc.getAllVersions(repositoryId, id/* object id */, id/* series id */, "*"/* filter
*/,
+                false /* includeAllowableActions */, null /* extension */);
+        renameFiles("getAllVersions");
+        LOG.debug("getAllVersions done.");
     }
     
+    private void getAcl(String objectId) {
+        LOG.debug("getting Acl() " + objectId);
+        // apply an ACL to the test doc
+        List<Ace> aces = new ArrayList<Ace>();
+        aces.add(objFactory.createAccessControlEntry("Alice", Collections.singletonList("cmis:read")));
+        aces.add(objFactory.createAccessControlEntry("Bob", Collections.singletonList("cmis:write")));
+        aces.add(objFactory.createAccessControlEntry("admin", Collections.singletonList("cmis:all")));
+        Acl acl = objFactory.createAccessControlList(aces);
+
+        if (bindingType == BindingType.ATOMPUB)
+            ;// TODO: aclSvc.applyAcl(repositoryId, objectId, acl, AclPropagation.OBJECTONLY,
null);
+        else
+            aclSvc.applyAcl(repositoryId, objectId, acl, null, AclPropagation.OBJECTONLY,
null);
+            
+        aclSvc.getAcl(repositoryId, objectId, true, null);
+        renameFiles("getAcl");
+        LOG.debug("getting Acl() done.");
+    }
+
+    private void getTypeDescendants(String typeId) {
+        final BigInteger DEPTH = BigInteger.valueOf(-1);
+        LOG.debug("getTypeDescendants " + typeId);
+        repSvc.getTypeDescendants(repositoryId, typeId, DEPTH, true /* includePropertyDefinitions
*/, null);
+        renameFiles("getTypeDescendants");
+        LOG.debug("getTypeDescendants() done.");
+    }
+
+    private void getAllowableActions(String objectId) {
+        LOG.debug("getAllowableActions " + objectId);
+        objSvc.getAllowableActions(repositoryId, objectId, null);
+        renameFiles("getAllowableActions");
+        LOG.debug("getAllowableActions() done.");
+    }
+
     private void renameFiles(String name) {
-        String fileNameInReq = String.format("%05d-request.log", requestCounter);
-        String fileNameInResp = String.format("%05d-response.log", requestCounter);
-        File in = new File(logDir + fileNameInReq);
-        File out = new File(name + "-request.xml");
+        String fileNameInReq = findLastFile(LOGDIR, "*-request.log");
+        String fileNameInResp = findLastFile(LOGDIR, "*-response.log");
+        if (null == fileNameInReq) {
+            LOG.error("Failed to find captured request file for " + name);
+            return;
+        }
+        if (null == fileNameInResp) {
+            LOG.error("Failed to find captured response file for " + name);
+            return;
+        }
+        File in = new File(fileNameInReq);
+        File out = new File(name + "-request.log");
         if (out.exists())
             out.delete();
         boolean ok = in.renameTo(out);
@@ -377,21 +410,56 @@ public class Main {
         else
             LOG.warn("Renaming file " + in.getAbsolutePath() + " to " + out.getAbsolutePath()
+ " failed.");
 
-        in = new File(logDir + fileNameInResp);
-        out = new File(name + "-response.xml");
+        in = new File(fileNameInResp);
+        out = new File(name + "-response.log");
         if (out.exists())
             out.delete();
         ok = in.renameTo(out);
         if (ok)
-            LOG.debug("Renaming file " + in.getAbsolutePath() +  "to " + out.getAbsolutePath()
+ " succeeded.");
+            LOG.debug("Renaming file " + in.getAbsolutePath() + "to " + out.getAbsolutePath()
+ " succeeded.");
         else
             LOG.warn("Renaming file " + in.getAbsolutePath() + " to " + out.getAbsolutePath()
+ " failed.");
     }
     
+    public static void clean() {
+        LOG.debug("Cleaning generated and captured request and response logs...");
+        
+        cleanFilesWithFilter(LOGDIR, "*-request.log");
+        cleanFilesWithFilter(LOGDIR, "*-response.log");
+        cleanFilesWithFilter(".", "*-request.log");
+        cleanFilesWithFilter(".", "*-response.log");
+
+        LOG.debug("...cleaning done.");        
+    }
+    
+    private static void cleanFilesWithFilter(String directoryPath, String wildcardFilter)
{
+        File dir = new File(directoryPath);
+        FileFilter fileFilter = new WildcardFileFilter(wildcardFilter);
+        File[] files = dir.listFiles(fileFilter);
+        for (int i = 0; i < files.length; i++) {
+           boolean ok = files[i].delete();
+           LOG.debug("Deleting file: " + files[i] + ", success: " + ok);
+        }        
+    }
+    
+    private static String findLastFile(String directoryPath, String wildcardFilter) {
+        File dir = new File(directoryPath);
+        FileFilter fileFilter = new WildcardFileFilter(wildcardFilter);
+        File[] files = dir.listFiles(fileFilter);
+        if (files.length == 0)
+            return null;
+        else
+            return files[files.length-1].getAbsolutePath();
+    }
+
     public static void main(String[] args) {
         LOG.debug("Starting generating spec examples...");
-        Main main = new Main();
-        main.run();
+        if (args.length > 0 && args[0].equals("-clean"))
+            Main.clean();
+        else {
+            Main main = new Main();
+            main.run();
+        }
         LOG.debug("... finsihed generating spec examples.");
     }
 }



Mime
View raw message