Search in sources :

Example 11 with ObjectType

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

the class AbstractSessionTest method deleteType.

/**
 * Deletes a type.
 */
protected void deleteType(Session session, String typeId) {
    ObjectType type = session.getTypeDefinition(typeId);
    if (type == null) {
        addResult(createResult(FAILURE, "Type does not exist and therefore cannot be deleted! ID: " + typeId));
        return;
    }
    // check if type can be deleted
    if (type.getTypeMutability() == null) {
        addResult(createResult(FAILURE, "Type does not provide type mutability data! ID: " + typeId));
    } else {
        if (!Boolean.TRUE.equals(type.getTypeMutability().canDelete())) {
            addResult(createResult(WARNING, "Type indicates that it cannot be deleted. Trying it anyway. ID: " + typeId));
        }
    }
    // delete it
    try {
        session.deleteType(typeId);
    } catch (CmisBaseException e) {
        addResult(createResult(FAILURE, "Deleting type '" + typeId + "' failed: " + e.getMessage(), e, false));
        return;
    }
    // check if the type still exists
    try {
        session.getTypeDefinition(typeId);
        addResult(createResult(FAILURE, "Type should not exist anymore but it is still there! ID: " + typeId, true));
    } catch (CmisObjectNotFoundException e) {
    // expected result
    }
}
Also used : ObjectType(org.apache.chemistry.opencmis.client.api.ObjectType) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CmisBaseException(org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException)

Example 12 with ObjectType

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

the class BaseTypesTest method runTypeChecks.

private int runTypeChecks(Session session, List<Tree<ObjectType>> types) {
    if (types == null) {
        return 0;
    }
    int numOfTypes = 0;
    CmisTestResult failure;
    for (Tree<ObjectType> tree : types) {
        failure = createResult(FAILURE, "Types tree contains null leaf!");
        addResult(assertNotNull(tree, null, failure));
        if (tree != null) {
            numOfTypes++;
            addResult(checkTypeDefinition(session, tree.getItem(), "Type spec compliance: " + tree.getItem().getId()));
            // clear the cache to ensure that the type definition is
            // reloaded from the repository
            session.clear();
            try {
                TypeDefinition reloadedType = session.getTypeDefinition(tree.getItem().getId());
                addResult(checkTypeDefinition(session, reloadedType, "Type spec compliance: " + (reloadedType == null ? "?" : reloadedType.getId())));
                failure = createResult(FAILURE, "Type fetched via getTypeDescendants() is does not macth type fetched via getTypeDefinition(): " + tree.getItem().getId());
                addResult(assertEquals(tree.getItem(), reloadedType, null, failure));
            } catch (CmisObjectNotFoundException e) {
                addResult(createResult(FAILURE, "Type fetched via getTypeDescendants() is not available via getTypeDefinition(): " + tree.getItem().getId(), e, false));
            }
            // clear the cache again to ensure that the type definition
            // children are reloaded from the repository
            session.clear();
            try {
                ItemIterable<ObjectType> reloadedTypeChildren = session.getTypeChildren(tree.getItem().getId(), true);
                // check type children
                Map<String, ObjectType> typeChilden = new HashMap<String, ObjectType>();
                for (ObjectType childType : reloadedTypeChildren) {
                    if (childType == null) {
                        addResult(createResult(FAILURE, "The list of types contains a null entry!"));
                        continue;
                    }
                    addResult(checkTypeDefinition(session, childType, "Type spec compliance: " + childType.getId()));
                    typeChilden.put(childType.getId(), childType);
                }
                // compare type children and type descendants
                if (tree.getChildren() == null) {
                    failure = createResult(FAILURE, "Type children fetched via getTypeDescendants() don't match type children fetched via getTypeChildren(): " + tree.getItem().getId());
                    addResult(assertEquals(0, typeChilden.size(), null, failure));
                } else {
                    // collect the children
                    Map<String, ObjectType> typeDescendants = new HashMap<String, ObjectType>();
                    for (Tree<ObjectType> childType : tree.getChildren()) {
                        if ((childType != null) && (childType.getItem() != null)) {
                            typeDescendants.put(childType.getItem().getId(), childType.getItem());
                        }
                    }
                    failure = createResult(FAILURE, "Type children fetched via getTypeDescendants() don't match type children fetched via getTypeChildren(): " + tree.getItem().getId());
                    addResult(assertEquals(typeDescendants.size(), typeChilden.size(), null, failure));
                    for (ObjectType compareType : typeDescendants.values()) {
                        failure = createResult(FAILURE, "Type fetched via getTypeDescendants() doesn't match type fetched via getTypeChildren(): " + tree.getItem().getId());
                        addResult(assertEquals(compareType, typeChilden.get(compareType.getId()), null, failure));
                    }
                }
            } catch (CmisObjectNotFoundException e) {
                addResult(createResult(FAILURE, "Type children fetched via getTypeDescendants() are not available via getTypeChildren(): " + tree.getItem().getId(), e, false));
            }
            numOfTypes += runTypeChecks(session, tree.getChildren());
        }
    }
    return numOfTypes;
}
Also used : ObjectType(org.apache.chemistry.opencmis.client.api.ObjectType) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) HashMap(java.util.HashMap) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) TypeDefinition(org.apache.chemistry.opencmis.commons.definitions.TypeDefinition)

Example 13 with ObjectType

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

the class CreateAndDeleteTypeTest method createTypeWithoutProperties.

private void createTypeWithoutProperties(Session session, ObjectType parentType) {
    CmisTestResult failure = null;
    // define the type
    DocumentTypeDefinitionImpl newTypeDef = createDocumentTypeDefinition(session, "tck:testid_without_properties", parentType);
    // create the type
    ObjectType newType = createType(session, newTypeDef);
    if (newType == null) {
        return;
    }
    // get the type
    ObjectType newType2 = null;
    try {
        newType2 = session.getTypeDefinition(newType.getId());
        // assert type definitions
        failure = createResult(FAILURE, "The type definition returned by createType() doesn't match the type definition returned by getTypeDefinition()!");
        addResult(assertEquals(newType, newType2, null, failure));
    } catch (CmisObjectNotFoundException e) {
        addResult(createResult(FAILURE, "Newly created type can not be fetched. Id: " + newType.getId(), e, false));
    }
    // delete the type
    deleteType(session, newType.getId());
}
Also used : ObjectType(org.apache.chemistry.opencmis.client.api.ObjectType) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) DocumentTypeDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.DocumentTypeDefinitionImpl)

Example 14 with ObjectType

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

the class SecondaryTypesTest method run.

@Override
public void run(Session session) {
    if (session.getRepositoryInfo().getCmisVersion() == CmisVersion.CMIS_1_0) {
        addResult(createResult(SKIPPED, "Secondary types are not supported by CMIS 1.0. Test skipped!"));
        return;
    }
    if (!hasSecondaries(session)) {
        addResult(createResult(SKIPPED, "Repository doesn't support secondary types. Test skipped!"));
        return;
    }
    // check cmis:secondaryObjectTypeIds property definition
    ObjectType docType = session.getTypeDefinition(getDocumentTestTypeId());
    PropertyDefinition<?> secTypesPropDef = docType.getPropertyDefinitions().get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS);
    if (secTypesPropDef == null) {
        addResult(createResult(FAILURE, "Test document type has no " + PropertyIds.SECONDARY_OBJECT_TYPE_IDS + " property!"));
        return;
    } else if (secTypesPropDef.getUpdatability() != Updatability.READWRITE) {
        addResult(createResult(SKIPPED, "Test document type does not allow attaching secondary types. Test skipped!"));
        return;
    }
    // create a test folder
    Folder testFolder = createTestFolder(session);
    try {
        String secondaryTestTypeId = getSecondaryTestTypeId();
        ObjectType secondaryTestType = session.getTypeDefinition(secondaryTestTypeId);
        createDocumentAndAttachSecondaryType(session, testFolder, secondaryTestType);
        createDocumentWithSecondaryType(session, testFolder, secondaryTestType);
    } finally {
        // delete the test folder
        deleteTestFolder();
    }
}
Also used : ObjectType(org.apache.chemistry.opencmis.client.api.ObjectType) Folder(org.apache.chemistry.opencmis.client.api.Folder)

Example 15 with ObjectType

use of org.apache.chemistry.opencmis.client.api.ObjectType 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)

Aggregations

ObjectType (org.apache.chemistry.opencmis.client.api.ObjectType)15 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)9 HashMap (java.util.HashMap)8 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)8 CmisBaseException (org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException)7 CmisObject (org.apache.chemistry.opencmis.client.api.CmisObject)5 FileableCmisObject (org.apache.chemistry.opencmis.client.api.FileableCmisObject)5 Folder (org.apache.chemistry.opencmis.client.api.Folder)5 ObjectId (org.apache.chemistry.opencmis.client.api.ObjectId)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 CmisSession (org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession)2 Document (org.apache.chemistry.opencmis.client.api.Document)2 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)2 CmisNotSupportedException (org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException)2 DocumentTypeDefinitionImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.DocumentTypeDefinitionImpl)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Map (java.util.Map)1 AlfrescoObjectFactoryImpl (org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl)1 AlfrescoType (org.alfresco.cmis.client.type.AlfrescoType)1