Search in sources :

Example 1 with RelationshipTypeDefinition

use of org.apache.chemistry.opencmis.commons.definitions.RelationshipTypeDefinition in project copper-cms by PogeyanOSS.

the class AbstractSessionTest method checkTypeDefinition.

protected CmisTestResult checkTypeDefinition(Session session, TypeDefinition type, String message) {
    List<CmisTestResult> results = new ArrayList<CmisTestResult>();
    CmisTestResult f;
    f = createResult(FAILURE, "Type is null!");
    addResult(results, assertNotNull(type, null, f));
    if (type != null) {
        f = createResult(FAILURE, "Type ID is not set!");
        addResult(results, assertStringNotEmpty(type.getId(), null, f));
        f = createResult(FAILURE, "Base type ID is not set!");
        addResult(results, assertNotNull(type.getBaseTypeId(), null, f));
        f = createResult(FAILURE, "Local name is not set!");
        addResult(results, assertStringNotEmpty(type.getLocalName(), null, f));
        // f = createResult(FAILURE, "Local namespace is not set!");
        // addResult(results, assertStringNotEmpty(type.(), null, f));
        boolean isQueryNameRequired = Boolean.TRUE.equals(type.isQueryable());
        addResult(results, checkQueryName(type.getQueryName(), isQueryNameRequired, "Type Query Name: " + type.getQueryName()));
        if ((type.getId() != null) && (type.getBaseTypeId() != null)) {
            if (type.getBaseTypeId().value().equals(type.getId())) {
                f = createResult(FAILURE, "Base type has parent type!");
                addResult(results, assertStringNullOrEmpty(type.getParentTypeId(), null, f));
                f = createResult(FAILURE, "Query name of base type is wrong!");
                addResult(results, assertEquals(type.getId(), type.getQueryName(), null, f));
            } else {
                f = createResult(FAILURE, "Parent type is not set!");
                addResult(results, assertStringNotEmpty(type.getParentTypeId(), null, f));
            }
        }
        f = createResult(FAILURE, "Creatable flag is not set!");
        addResult(results, assertNotNull(type.isCreatable(), null, f));
        f = createResult(FAILURE, "Fileable flag is not set!");
        addResult(results, assertNotNull(type.isFileable(), null, f));
        f = createResult(FAILURE, "Controllable ACL flag is not set!");
        addResult(results, assertNotNull(type.isControllableAcl(), null, f));
        f = createResult(FAILURE, "Controllable Policy flag is not set!");
        addResult(results, assertNotNull(type.isControllablePolicy(), null, f));
        f = createResult(FAILURE, "Fulltext indexed flag is not set!");
        addResult(results, assertNotNull(type.isFulltextIndexed(), null, f));
        f = createResult(FAILURE, "Included in super type flag is not set!");
        addResult(results, assertNotNull(type.isIncludedInSupertypeQuery(), null, f));
        f = createResult(FAILURE, "Queryable flag is not set!");
        addResult(results, assertNotNull(type.isQueryable(), null, f));
        f = createResult(WARNING, "Type display name is not set!");
        addResult(results, assertStringNotEmpty(type.getDisplayName(), null, f));
        f = createResult(WARNING, "Type description is not set!");
        addResult(results, assertStringNotEmpty(type.getDescription(), null, f));
        if (BaseTypeId.CMIS_DOCUMENT.equals(type.getBaseTypeId())) {
            DocumentTypeDefinition docType = (DocumentTypeDefinition) type;
            f = createResult(FAILURE, "Versionable flag is not set!");
            addResult(results, assertNotNull(docType.isVersionable(), null, f));
            f = createResult(FAILURE, "Content stream allowed flag is not set!");
            addResult(results, assertNotNull(docType.getContentStreamAllowed(), null, f));
        } else if (BaseTypeId.CMIS_FOLDER.equals(type.getBaseTypeId())) {
            if (type.isFileable() != null) {
                f = createResult(FAILURE, "Folder types must be fileable!");
                addResult(results, assertIsTrue(type.isFileable(), null, f));
            }
        } else if (BaseTypeId.CMIS_RELATIONSHIP.equals(type.getBaseTypeId())) {
            RelationshipTypeDefinition relType = (RelationshipTypeDefinition) type;
            f = createResult(FAILURE, "Allowed Source Type IDs are not set!");
            addResult(results, assertNotNull(relType.getAllowedSourceTypeIds(), null, f));
            if (relType.getAllowedSourceTypeIds() != null) {
                for (String typeId : relType.getAllowedSourceTypeIds()) {
                    try {
                        session.getTypeDefinition(typeId);
                    } catch (CmisInvalidArgumentException e) {
                        addResult(results, createResult(WARNING, "Allowed Source Type IDs contain a type ID that doesn't exist: " + typeId));
                    } catch (CmisObjectNotFoundException e) {
                        addResult(results, createResult(WARNING, "Allowed Source Type IDs contain a type ID that doesn't exist: " + typeId));
                    }
                }
            }
            f = createResult(FAILURE, "Allowed Target Type IDs are not set!");
            addResult(results, assertNotNull(relType.getAllowedTargetTypeIds(), null, f));
            if (relType.getAllowedTargetTypeIds() != null) {
                for (String typeId : relType.getAllowedTargetTypeIds()) {
                    try {
                        session.getTypeDefinition(typeId);
                    } catch (CmisInvalidArgumentException e) {
                        addResult(results, createResult(WARNING, "Allowed Target Type IDs contain a type ID that doesn't exist: " + typeId));
                    } catch (CmisObjectNotFoundException e) {
                        addResult(results, createResult(WARNING, "Allowed Target Type IDs contain a type ID that doesn't exist: " + typeId));
                    }
                }
            }
            if (type.isFileable() != null) {
                f = createResult(FAILURE, "Relationship types must not be fileable!");
                addResult(results, assertIsFalse(type.isFileable(), null, f));
            }
        } else if (BaseTypeId.CMIS_POLICY.equals(type.getBaseTypeId())) {
        // nothing to do
        } else if (BaseTypeId.CMIS_SECONDARY.equals(type.getBaseTypeId())) {
            if (type.isCreatable() != null) {
                f = createResult(FAILURE, "Secondary types must not be creatable!");
                addResult(results, assertIsFalse(type.isCreatable(), null, f));
            }
            if (type.isFileable() != null) {
                f = createResult(FAILURE, "Secondary types must not be fileable!");
                addResult(results, assertIsFalse(type.isFileable(), null, f));
            }
            if (type.isControllableAcl() != null) {
                f = createResult(FAILURE, "The controllable ACL flag must be false for secondary types!");
                addResult(results, assertIsFalse(type.isControllableAcl(), null, f));
            }
            if (type.isControllablePolicy() != null) {
                f = createResult(FAILURE, "The controllable policy flag must be false for secondary types!");
                addResult(results, assertIsFalse(type.isControllablePolicy(), null, f));
            }
        }
        // check properties
        if (!BaseTypeId.CMIS_SECONDARY.equals(type.getBaseTypeId())) {
            f = createResult(FAILURE, "Type has no property definitions!");
            addResult(results, assertNotNull(type.getPropertyDefinitions(), null, f));
            if (type.getPropertyDefinitions() != null) {
                for (PropertyDefinition<?> propDef : type.getPropertyDefinitions().values()) {
                    if (propDef == null) {
                        addResult(results, createResult(FAILURE, "A property definition is null!"));
                    } else if (propDef.getId() == null) {
                        addResult(results, createResult(FAILURE, "A property definition ID is null!"));
                    } else {
                        addResult(results, checkPropertyDefinition(propDef, "Property definition: " + propDef.getId()));
                    }
                }
            }
            CmisPropertyDefintion cpd;
            // cmis:name
            cpd = new CmisPropertyDefintion(PropertyIds.NAME, null, PropertyType.STRING, Cardinality.SINGLE, null, null, null);
            addResult(results, cpd.check(type));
            // cmis:objectId
            cpd = new CmisPropertyDefintion(PropertyIds.OBJECT_ID, false, PropertyType.ID, Cardinality.SINGLE, Updatability.ONCREATE, null, null);
            addResult(results, cpd.check(type));
            // cmis:baseTypeId
            cpd = new CmisPropertyDefintion(PropertyIds.BASE_TYPE_ID, false, PropertyType.ID, Cardinality.SINGLE, Updatability.READONLY, null, null);
            addResult(results, cpd.check(type));
            // cmis:objectTypeId
            cpd = new CmisPropertyDefintion(PropertyIds.OBJECT_TYPE_ID, true, PropertyType.ID, Cardinality.SINGLE, Updatability.ONCREATE, null, null);
            addResult(results, cpd.check(type));
            // cmis:createdBy
            cpd = new CmisPropertyDefintion(PropertyIds.CREATED_BY, false, PropertyType.STRING, Cardinality.SINGLE, Updatability.READONLY, true, true);
            addResult(results, cpd.check(type));
            // cmis:creationDate
            cpd = new CmisPropertyDefintion(PropertyIds.CREATION_DATE, false, PropertyType.DATETIME, Cardinality.SINGLE, Updatability.READONLY, true, true);
            addResult(results, cpd.check(type));
            // cmis:lastModifiedBy
            cpd = new CmisPropertyDefintion(PropertyIds.LAST_MODIFIED_BY, false, PropertyType.STRING, Cardinality.SINGLE, Updatability.READONLY, true, true);
            addResult(results, cpd.check(type));
            // cmis:lastModificationDate
            cpd = new CmisPropertyDefintion(PropertyIds.LAST_MODIFICATION_DATE, false, PropertyType.DATETIME, Cardinality.SINGLE, Updatability.READONLY, true, true);
            addResult(results, cpd.check(type));
            // cmis:changeToken
            cpd = new CmisPropertyDefintion(PropertyIds.CHANGE_TOKEN, false, PropertyType.STRING, Cardinality.SINGLE, Updatability.READONLY, null, null);
            addResult(results, cpd.check(type));
            // CMIS 1.1 properties
            if (session.getRepositoryInfo().getCmisVersion() == CmisVersion.CMIS_1_1) {
                // cmis:description
                cpd = new CmisPropertyDefintion(PropertyIds.DESCRIPTION, null, PropertyType.STRING, Cardinality.SINGLE, null, null, null);
                addResult(results, cpd.check(type));
                // cmis:secondaryObjectTypeIds
                cpd = new CmisPropertyDefintion(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, false, PropertyType.ID, Cardinality.MULTI, null, null, false);
                addResult(results, cpd.check(type));
                if (BaseTypeId.CMIS_DOCUMENT.equals(type.getBaseTypeId())) {
                    // cmis:isPrivateWorkingCopy
                    cpd = new CmisPropertyDefintion(PropertyIds.IS_PRIVATE_WORKING_COPY, null, PropertyType.BOOLEAN, Cardinality.SINGLE, Updatability.READONLY, null, null);
                    addResult(results, cpd.check(type));
                }
            }
            if (BaseTypeId.CMIS_DOCUMENT.equals(type.getBaseTypeId())) {
                // cmis:isImmutable
                cpd = new CmisPropertyDefintion(PropertyIds.IS_IMMUTABLE, false, PropertyType.BOOLEAN, Cardinality.SINGLE, Updatability.READONLY, null, null);
                addResult(results, cpd.check(type));
                // cmis:isLatestVersion
                cpd = new CmisPropertyDefintion(PropertyIds.IS_LATEST_VERSION, false, PropertyType.BOOLEAN, Cardinality.SINGLE, Updatability.READONLY, null, null);
                addResult(results, cpd.check(type));
                // cmis:isMajorVersion
                cpd = new CmisPropertyDefintion(PropertyIds.IS_MAJOR_VERSION, false, PropertyType.BOOLEAN, Cardinality.SINGLE, Updatability.READONLY, null, null);
                addResult(results, cpd.check(type));
                // cmis:isLatestMajorVersion
                cpd = new CmisPropertyDefintion(PropertyIds.IS_LATEST_MAJOR_VERSION, false, PropertyType.BOOLEAN, Cardinality.SINGLE, Updatability.READONLY, null, null);
                addResult(results, cpd.check(type));
                // cmis:versionLabel
                cpd = new CmisPropertyDefintion(PropertyIds.VERSION_LABEL, false, PropertyType.STRING, Cardinality.SINGLE, Updatability.READONLY, null, null);
                addResult(results, cpd.check(type));
                // cmis:versionSeriesId
                cpd = new CmisPropertyDefintion(PropertyIds.VERSION_SERIES_ID, false, PropertyType.ID, Cardinality.SINGLE, Updatability.READONLY, null, null);
                addResult(results, cpd.check(type));
                // cmis:isVersionSeriesCheckedOut
                cpd = new CmisPropertyDefintion(PropertyIds.IS_VERSION_SERIES_CHECKED_OUT, false, PropertyType.BOOLEAN, Cardinality.SINGLE, Updatability.READONLY, null, null);
                addResult(results, cpd.check(type));
                // cmis:versionSeriesCheckedOutBy
                cpd = new CmisPropertyDefintion(PropertyIds.VERSION_SERIES_CHECKED_OUT_BY, false, PropertyType.STRING, Cardinality.SINGLE, Updatability.READONLY, null, null);
                addResult(results, cpd.check(type));
                // cmis:versionSeriesCheckedOutId
                cpd = new CmisPropertyDefintion(PropertyIds.VERSION_SERIES_CHECKED_OUT_ID, false, PropertyType.ID, Cardinality.SINGLE, Updatability.READONLY, null, null);
                addResult(results, cpd.check(type));
                // cmis:checkinComment
                cpd = new CmisPropertyDefintion(PropertyIds.CHECKIN_COMMENT, false, PropertyType.STRING, Cardinality.SINGLE, Updatability.READONLY, null, null);
                addResult(results, cpd.check(type));
                // cmis:contentStreamLength
                cpd = new CmisPropertyDefintion(PropertyIds.CONTENT_STREAM_LENGTH, false, PropertyType.INTEGER, Cardinality.SINGLE, Updatability.READONLY, null, null);
                addResult(results, cpd.check(type));
                // cmis:contentStreamMimeType
                cpd = new CmisPropertyDefintion(PropertyIds.CONTENT_STREAM_MIME_TYPE, false, PropertyType.STRING, Cardinality.SINGLE, Updatability.READONLY, null, null);
                addResult(results, cpd.check(type));
                // cmis:contentStreamFileName
                cpd = new CmisPropertyDefintion(PropertyIds.CONTENT_STREAM_FILE_NAME, false, PropertyType.STRING, Cardinality.SINGLE, Updatability.READONLY, null, null);
                addResult(results, cpd.check(type));
                // cmis:contentStreamId
                cpd = new CmisPropertyDefintion(PropertyIds.CONTENT_STREAM_ID, false, PropertyType.ID, Cardinality.SINGLE, Updatability.READONLY, null, null);
                addResult(results, cpd.check(type));
            } else if (BaseTypeId.CMIS_FOLDER.equals(type.getBaseTypeId())) {
                // cmis:parentId
                cpd = new CmisPropertyDefintion(PropertyIds.PARENT_ID, false, PropertyType.ID, Cardinality.SINGLE, Updatability.READONLY, null, null);
                addResult(results, cpd.check(type));
                // cmis:path
                cpd = new CmisPropertyDefintion(PropertyIds.PATH, false, PropertyType.STRING, Cardinality.SINGLE, Updatability.READONLY, null, null);
                addResult(results, cpd.check(type));
                // cmis:allowedChildObjectTypeIds
                cpd = new CmisPropertyDefintion(PropertyIds.ALLOWED_CHILD_OBJECT_TYPE_IDS, false, PropertyType.ID, Cardinality.MULTI, Updatability.READONLY, null, false);
                addResult(results, cpd.check(type));
            } else if (BaseTypeId.CMIS_RELATIONSHIP.equals(type.getBaseTypeId())) {
                // cmis:sourceId
                cpd = new CmisPropertyDefintion(PropertyIds.SOURCE_ID, true, PropertyType.ID, Cardinality.SINGLE, null, null, null);
                addResult(results, cpd.check(type));
                // cmis:targetId
                cpd = new CmisPropertyDefintion(PropertyIds.TARGET_ID, true, PropertyType.ID, Cardinality.SINGLE, null, null, null);
                addResult(results, cpd.check(type));
            } else if (BaseTypeId.CMIS_POLICY.equals(type.getBaseTypeId())) {
                // cmis:policyText
                cpd = new CmisPropertyDefintion(PropertyIds.POLICY_TEXT, null, PropertyType.STRING, Cardinality.SINGLE, null, null, null);
                addResult(results, cpd.check(type));
            }
        }
    }
    CmisTestResultImpl result = createResult(getWorst(results), message);
    result.getChildren().addAll(results);
    return result.getStatus().getLevel() <= OK.getLevel() ? null : result;
}
Also used : RelationshipTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.RelationshipTypeDefinition) DocumentTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) ArrayList(java.util.ArrayList) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)

Aggregations

ArrayList (java.util.ArrayList)1 DocumentTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition)1 RelationshipTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.RelationshipTypeDefinition)1 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)1 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)1 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)1