Search in sources :

Example 16 with ObjectId

use of org.apache.chemistry.opencmis.client.api.ObjectId in project copper-cms by PogeyanOSS.

the class AbstractSessionTest method createPolicy.

/**
 * Creates a policy.
 */
protected Policy createPolicy(Session session, Folder parent, String name, String policyText, String objectTypeId) {
    if (parent == null) {
        throw new IllegalArgumentException("Parent is not set!");
    }
    if (name == null) {
        throw new IllegalArgumentException("Name is not set!");
    }
    if (objectTypeId == null) {
        throw new IllegalArgumentException("Object Type ID is not set!");
    }
    // check type
    ObjectType type;
    try {
        type = session.getTypeDefinition(objectTypeId);
    } catch (CmisObjectNotFoundException e) {
        addResult(createResult(UNEXPECTED_EXCEPTION, "Policy type '" + objectTypeId + "' is not available: " + e.getMessage(), e, true));
        return null;
    }
    if (Boolean.FALSE.equals(type.isCreatable())) {
        addResult(createResult(SKIPPED, "Policy type '" + objectTypeId + "' is not creatable!", true));
        return null;
    }
    boolean isFilable = Boolean.TRUE.equals(type.isFileable());
    addResult(createResult(INFO, "Policy type '" + objectTypeId + "' is " + (isFilable ? "" : "not ") + "filable."));
    // create
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(PropertyIds.NAME, name);
    properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
    if (policyText != null) {
        properties.put(PropertyIds.POLICY_TEXT, policyText);
    }
    Policy result = null;
    try {
        // create the item
        if (isFilable) {
            result = parent.createPolicy(properties, null, null, null, SELECT_ALL_NO_CACHE_OC);
        } else {
            ObjectId policyId = session.createPolicy(properties, null, null, null, null);
            result = (Policy) session.getObject(policyId, SELECT_ALL_NO_CACHE_OC);
        }
    } catch (CmisBaseException e) {
        addResult(createResult(UNEXPECTED_EXCEPTION, "Policy could not be created! Exception: " + e.getMessage(), e, true));
        return null;
    }
    CmisTestResult f;
    try {
        // check item name
        f = createResult(FAILURE, "Policy name does not match!", false);
        addResult(assertEquals(name, result.getName(), null, f));
        addResult(checkObject(session, result, getAllProperties(result), "New policy object spec compliance"));
    } catch (CmisBaseException e) {
        addResult(createResult(UNEXPECTED_EXCEPTION, "Newly created policy is invalid! Exception: " + e.getMessage(), e, true));
    }
    // check parents
    List<Folder> parents = result.getParents(SELECT_ALL_NO_CACHE_OC);
    if (isFilable) {
        boolean found = false;
        for (Folder folder : parents) {
            if (parent.getId().equals(folder.getId())) {
                found = true;
                break;
            }
        }
        if (!found) {
            addResult(createResult(FAILURE, "The folder the item has been created in is not in the list of the item parents!"));
        }
    } else {
        f = createResult(FAILURE, "Policy is not filable but has a parent!", false);
        addResult(assertIsTrue(parents.isEmpty(), null, f));
    }
    return result;
}
Also used : Policy(org.apache.chemistry.opencmis.client.api.Policy) HashMap(java.util.HashMap) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) Folder(org.apache.chemistry.opencmis.client.api.Folder) ObjectType(org.apache.chemistry.opencmis.client.api.ObjectType) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CmisBaseException(org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) FileableCmisObject(org.apache.chemistry.opencmis.client.api.FileableCmisObject) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject)

Example 17 with ObjectId

use of org.apache.chemistry.opencmis.client.api.ObjectId in project copper-cms by PogeyanOSS.

the class UpdateSmokeTest method updateDocument.

private void updateDocument(Session session, Folder testFolder) {
    CmisTestResult f;
    // create document
    Document doc1 = createDocument(session, testFolder, DOC_NAME1, "rename me!");
    Document workDoc = doc1;
    f = createResult(FAILURE, "Document name doesn't match the given name!");
    addResult(assertEquals(DOC_NAME1, doc1.getName(), null, f));
    // test if check out is required
    boolean checkedout = false;
    DocumentTypeDefinition type = (DocumentTypeDefinition) doc1.getType();
    PropertyDefinition<?> namePropDef = type.getPropertyDefinitions().get(PropertyIds.NAME);
    if (namePropDef.getUpdatability() == Updatability.WHENCHECKEDOUT || (!doc1.getAllowableActions().getAllowableActions().contains(Action.CAN_UPDATE_PROPERTIES) && Boolean.TRUE.equals(type.isVersionable()))) {
        workDoc = (Document) session.getObject(doc1.checkOut(), SELECT_ALL_NO_CACHE_OC);
        checkedout = true;
    }
    // update
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(PropertyIds.NAME, DOC_NAME2);
    ObjectId newId = workDoc.updateProperties(properties, false);
    Document doc2 = (Document) session.getObject(newId, SELECT_ALL_NO_CACHE_OC);
    addResult(checkObject(session, doc2, getAllProperties(doc2), "Updated document compliance"));
    f = createResult(FAILURE, "Document name doesn't match updated value!");
    addResult(assertEquals(DOC_NAME2, doc2.getName(), null, f));
    // delete
    if (!workDoc.getId().equals(doc2.getId())) {
        deleteObject(doc2);
    }
    // cancel a possible check out
    if (checkedout) {
        workDoc.cancelCheckOut();
    }
    if (!doc1.getId().equals(doc2.getId())) {
        if (exists(doc1)) {
            deleteObject(doc1);
        }
    }
}
Also used : DocumentTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition) HashMap(java.util.HashMap) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) Document(org.apache.chemistry.opencmis.client.api.Document)

Example 18 with ObjectId

use of org.apache.chemistry.opencmis.client.api.ObjectId in project copper-cms by PogeyanOSS.

the class SecondaryTypesTest method createDocumentAndAttachSecondaryType.

private void createDocumentAndAttachSecondaryType(Session session, Folder testFolder, ObjectType secondaryTestType) {
    Document doc = createDocument(session, testFolder, "createandattach.txt", "Secondary Type Test");
    Document workDoc = doc;
    try {
        // test if check out is required
        boolean checkedout = false;
        if (needsCheckOut(doc)) {
            workDoc = (Document) session.getObject(doc.checkOut(), SELECT_ALL_NO_CACHE_OC);
            checkedout = true;
        }
        // -- attach secondary type
        List<String> secondaryTypes = new ArrayList<String>();
        // copy already attached secondary types, if there are any
        if (workDoc.getSecondaryTypes() != null) {
            for (SecondaryType secType : workDoc.getSecondaryTypes()) {
                secondaryTypes.add(secType.getId());
            }
        }
        // add the new secondary type
        secondaryTypes.add(secondaryTestType.getId());
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, secondaryTypes);
        // attach secondary type
        ObjectId newId = workDoc.updateProperties(properties);
        Document newDoc = (Document) session.getObject(newId, SELECT_ALL_NO_CACHE_OC);
        // check if the secondary type is there
        boolean found = checkSecondaryType(newDoc, secondaryTestType);
        // -- detach secondary type
        if (found) {
            detachSecondaryType(session, newDoc, secondaryTestType);
        }
        // cancel a possible check out
        if (checkedout) {
            workDoc.cancelCheckOut();
        }
    } finally {
        deleteObject(doc);
    }
}
Also used : SecondaryType(org.apache.chemistry.opencmis.client.api.SecondaryType) HashMap(java.util.HashMap) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) ArrayList(java.util.ArrayList) Document(org.apache.chemistry.opencmis.client.api.Document)

Example 19 with ObjectId

use of org.apache.chemistry.opencmis.client.api.ObjectId in project copper-cms by PogeyanOSS.

the class SecondaryTypesTest method detachSecondaryType.

private void detachSecondaryType(Session session, Document doc, ObjectType secondaryTestType) {
    CmisTestResult f;
    List<String> secondaryTypesId = new ArrayList<String>();
    for (SecondaryType secType : doc.getSecondaryTypes()) {
        if (!secondaryTestType.getId().equals(secType.getId())) {
            secondaryTypesId.add(secType.getId());
        }
    }
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, secondaryTypesId);
    // detach secondary type
    ObjectId newId = doc.updateProperties(properties);
    Document newDoc = (Document) session.getObject(newId, SELECT_ALL_NO_CACHE_OC);
    boolean found = false;
    if (newDoc.getSecondaryTypes() != null) {
        for (SecondaryType secType : newDoc.getSecondaryTypes()) {
            if (secondaryTestType.getId().equals(secType.getId())) {
                found = true;
                break;
            }
        }
    }
    f = createResult(FAILURE, "Document still has the detached secondary type!");
    addResult(assertIsFalse(found, null, f));
    // check properties
    ObjectType primaryType = newDoc.getType();
    List<SecondaryType> secondaryTypes = newDoc.getSecondaryTypes();
    for (Property<?> prop : doc.getProperties()) {
        if (!primaryType.getPropertyDefinitions().containsKey(prop.getId())) {
            f = createResult(FAILURE, "Property '" + prop.getId() + "' is neither defined by the primary type nor by a secondary type!");
            if (secondaryTypes == null) {
                addResult(f);
            } else {
                boolean foundProperty = false;
                for (SecondaryType secondaryType : secondaryTypes) {
                    if (secondaryType.getPropertyDefinitions() != null && secondaryType.getPropertyDefinitions().containsKey(prop.getId())) {
                        foundProperty = true;
                        break;
                    }
                }
                addResult(assertIsTrue(foundProperty, null, f));
            }
        }
    }
}
Also used : SecondaryType(org.apache.chemistry.opencmis.client.api.SecondaryType) HashMap(java.util.HashMap) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) ArrayList(java.util.ArrayList) Document(org.apache.chemistry.opencmis.client.api.Document) ObjectType(org.apache.chemistry.opencmis.client.api.ObjectType) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult)

Example 20 with ObjectId

use of org.apache.chemistry.opencmis.client.api.ObjectId in project copper-cms by PogeyanOSS.

the class CheckedOutTest method run.

@Override
public void run(Session session) {
    CmisTestResult f;
    boolean supportsOrderByName = isOrderByNameSupported(session);
    OperationContext orderContext = (supportsOrderByName ? SELECT_ALL_NO_CACHE_OC_ORDER_BY_NAME : SELECT_ALL_NO_CACHE_OC);
    Document pwc = null;
    try {
        // create folder and a checked-out document
        Folder testFolder = createTestFolder(session);
        Document doc = createDocument(session, testFolder, "checkedouttest.txt", "checked out");
        DocumentTypeDefinition docType = (DocumentTypeDefinition) doc.getType();
        if (!docType.isVersionable()) {
            addResult(createResult(WARNING, "Test type is not versionable. Check out skipped!"));
        } else {
            ObjectId pwcId = doc.checkOut();
            pwc = (Document) session.getObject(pwcId, SELECT_ALL_NO_CACHE_OC);
        }
        // test all checked-out documents
        int sessionCheckedOut = checkPWCs(session, session.getCheckedOutDocs(orderContext), supportsOrderByName);
        addResult(createInfoResult(sessionCheckedOut + " checked out document(s) overall."));
        if (pwc != null) {
            f = createResult(FAILURE, "There should be at least one checked out document in the repository!");
            addResult(assertIsTrue(sessionCheckedOut >= 1, null, f));
        }
        // test checked-out documents in the test folder
        int testFolderCheckedOut = checkPWCs(session, testFolder.getCheckedOutDocs(orderContext), supportsOrderByName);
        addResult(createInfoResult(testFolderCheckedOut + " checked out document(s) in the test folder."));
        if (pwc != null) {
            f = createResult(FAILURE, "There should be at least one checked out document in the test folder!");
            addResult(assertIsTrue(testFolderCheckedOut >= 1, null, f));
        }
        // remove the PWC and document
        if (pwc != null) {
            pwc.cancelCheckOut();
            pwc = null;
        }
        deleteObject(doc);
    } finally {
        if (pwc != null) {
            pwc.cancelCheckOut();
        }
        deleteTestFolder();
    }
}
Also used : OperationContext(org.apache.chemistry.opencmis.client.api.OperationContext) DocumentTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) Document(org.apache.chemistry.opencmis.client.api.Document) Folder(org.apache.chemistry.opencmis.client.api.Folder)

Aggregations

ObjectId (org.apache.chemistry.opencmis.client.api.ObjectId)22 HashMap (java.util.HashMap)17 Document (org.apache.chemistry.opencmis.client.api.Document)17 Folder (org.apache.chemistry.opencmis.client.api.Folder)13 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)12 ContentStream (org.apache.chemistry.opencmis.commons.data.ContentStream)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 ContentStreamImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl)8 CmisObject (org.apache.chemistry.opencmis.client.api.CmisObject)7 DocumentTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition)7 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)7 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)6 ArrayList (java.util.ArrayList)5 FileableCmisObject (org.apache.chemistry.opencmis.client.api.FileableCmisObject)5 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)5 Map (java.util.Map)4 AlfrescoDocument (org.alfresco.cmis.client.AlfrescoDocument)4 AlfrescoFolder (org.alfresco.cmis.client.AlfrescoFolder)4 VersionableAspectTest (org.alfresco.repo.version.VersionableAspectTest)4 SiteInformation (org.alfresco.rest.api.tests.RepoService.SiteInformation)4