Search in sources :

Example 1 with TypeDefinitionList

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

the class BaseTypesTest method run.

@Override
public void run(Session session) {
    CmisTestResult failure;
    // check base types
    Set<String> cmisTypes = new HashSet<String>();
    cmisTypes.add(BaseTypeId.CMIS_DOCUMENT.value());
    cmisTypes.add(BaseTypeId.CMIS_FOLDER.value());
    cmisTypes.add(BaseTypeId.CMIS_RELATIONSHIP.value());
    cmisTypes.add(BaseTypeId.CMIS_POLICY.value());
    if (session.getRepositoryInfo().getCmisVersion() != CmisVersion.CMIS_1_0) {
        cmisTypes.add(BaseTypeId.CMIS_ITEM.value());
        cmisTypes.add(BaseTypeId.CMIS_SECONDARY.value());
    }
    for (TypeDefinition typeDef : session.getTypeChildren(null, false)) {
        String typeId = typeDef.getId();
        if (typeId == null || !cmisTypes.contains(typeId)) {
            addResult(createResult(FAILURE, "Base type has an invalid ID: " + typeId));
        }
        if (typeDef.getPropertyDefinitions() != null && !typeDef.getPropertyDefinitions().isEmpty()) {
            addResult(createResult(WARNING, "Property type definitions were not requested but delivered. Type ID: " + typeId));
        }
    }
    // document
    try {
        TypeDefinition documentType = session.getTypeDefinition(BaseTypeId.CMIS_DOCUMENT.value());
        addResult(checkTypeDefinition(session, documentType, "Document type spec compliance: " + documentType.getId()));
        failure = createResult(FAILURE, "Document type has the wrong base type: " + documentType.getBaseTypeId());
        addResult(assertEquals(BaseTypeId.CMIS_DOCUMENT, documentType.getBaseTypeId(), null, failure));
    } catch (CmisObjectNotFoundException e) {
        addResult(createResult(FAILURE, "Document type not available!", e, false));
    }
    // folder
    try {
        TypeDefinition folderType = session.getTypeDefinition(BaseTypeId.CMIS_FOLDER.value());
        addResult(checkTypeDefinition(session, folderType, "Folder type spec compliance: " + folderType.getId()));
        failure = createResult(FAILURE, "Folder type has the wrong base type: " + folderType.getBaseTypeId());
        addResult(assertEquals(BaseTypeId.CMIS_FOLDER, folderType.getBaseTypeId(), null, failure));
    } catch (CmisObjectNotFoundException e) {
        addResult(createResult(FAILURE, "Folder type not available!", e, false));
    }
    // relationship
    try {
        TypeDefinition relationshipType = session.getTypeDefinition(BaseTypeId.CMIS_RELATIONSHIP.value());
        addResult(checkTypeDefinition(session, relationshipType, "Relationship type spec compliance: " + relationshipType.getId()));
        failure = createResult(FAILURE, "Relationship type has the wrong base type: " + relationshipType.getBaseTypeId());
        addResult(assertEquals(BaseTypeId.CMIS_RELATIONSHIP, relationshipType.getBaseTypeId(), null, failure));
    } catch (CmisObjectNotFoundException e) {
        addResult(createResult(WARNING, "Relationship type not available!", e, false));
    }
    // policy
    try {
        TypeDefinition policyType = session.getTypeDefinition(BaseTypeId.CMIS_POLICY.value());
        addResult(checkTypeDefinition(session, policyType, "Policy type spec compliance: " + policyType.getId()));
        failure = createResult(FAILURE, "Policy type has the wrong base type: " + policyType.getBaseTypeId());
        addResult(assertEquals(BaseTypeId.CMIS_POLICY, policyType.getBaseTypeId(), null, failure));
    } catch (CmisInvalidArgumentException e) {
        addResult(createResult(WARNING, "Policy type not available!", e, false));
    } catch (CmisObjectNotFoundException e) {
        addResult(createResult(WARNING, "Policy type not available!", e, false));
    }
    // CMIS 1.1 types
    if (session.getRepositoryInfo().getCmisVersion() == CmisVersion.CMIS_1_1) {
        // item
        try {
            TypeDefinition itemType = session.getTypeDefinition(BaseTypeId.CMIS_ITEM.value());
            addResult(checkTypeDefinition(session, itemType, "Item type spec compliance: " + itemType.getId()));
            failure = createResult(FAILURE, "Item type has the wrong base type: " + itemType.getBaseTypeId());
            addResult(assertEquals(BaseTypeId.CMIS_ITEM, itemType.getBaseTypeId(), null, failure));
        } catch (CmisInvalidArgumentException e) {
            addResult(createResult(WARNING, "Item type not available!", e, false));
        } catch (CmisObjectNotFoundException e) {
            addResult(createResult(WARNING, "Item type not available!", e, false));
        }
        // secondary type
        try {
            TypeDefinition secondaryType = session.getTypeDefinition(BaseTypeId.CMIS_SECONDARY.value());
            addResult(checkTypeDefinition(session, secondaryType, "Secondary type spec compliance: " + secondaryType.getId()));
            failure = createResult(FAILURE, "Secondary type has the wrong base type: " + secondaryType.getBaseTypeId());
            addResult(assertEquals(BaseTypeId.CMIS_SECONDARY, secondaryType.getBaseTypeId(), null, failure));
        } catch (CmisInvalidArgumentException e) {
            addResult(createResult(WARNING, "Secondary type not available!", e, false));
        } catch (CmisObjectNotFoundException e) {
            addResult(createResult(WARNING, "Secondary type not available!", e, false));
        }
    } else {
        try {
            session.getTypeDefinition(BaseTypeId.CMIS_ITEM.value());
            addResult(createResult(FAILURE, "CMIS 1.0 repository returns cmis:item type definition!"));
        } catch (CmisBaseException e) {
        // expected
        }
        try {
            session.getTypeDefinition(BaseTypeId.CMIS_SECONDARY.value());
            addResult(createResult(FAILURE, "CMIS 1.0 repository returns cmis:secondary type definition!"));
        } catch (CmisBaseException e) {
        // expected
        }
    }
    // simple getTypeChildren paging test - skipping over all base types mut
    // return an empty list
    TypeDefinitionList typeDefinitionList = session.getBinding().getRepositoryService().getTypeChildren(session.getRepositoryInfo().getId(), null, false, BigInteger.valueOf(100), BigInteger.valueOf(6), null);
    if (typeDefinitionList == null) {
        addResult(createResult(FAILURE, "getTypeChildren() returned nothing!"));
    } else {
        if (typeDefinitionList.getList() != null && !typeDefinitionList.getList().isEmpty()) {
            addResult(createResult(FAILURE, "A getTypeChildren() call on the base types must retrun an empty list if skipCount is >= 6! The repository returned a list of " + typeDefinitionList.getList().size() + " elements."));
        }
        if (Boolean.TRUE.equals(typeDefinitionList.hasMoreItems())) {
            addResult(createResult(FAILURE, "A getTypeChildren() call on the base types must retrun an empty list if skipCount is >= 6! The repository returned hasMoreItems == true."));
        }
    }
    // test getTypeDescendants()
    int numOfTypes = runTypeChecks(session, session.getTypeDescendants(null, -1, true));
    addResult(createInfoResult("Checked " + numOfTypes + " type definitions."));
}
Also used : CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CmisBaseException(org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException) TypeDefinitionList(org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionList) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) HashSet(java.util.HashSet) TypeDefinition(org.apache.chemistry.opencmis.commons.definitions.TypeDefinition)

Example 2 with TypeDefinitionList

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

the class RepositoryActor method getTypeChildren.

private JSONObject getTypeChildren(QueryGetRequest request) throws IllegalArgumentException, CmisRuntimeException {
    String permission = request.getUserObject().getPermission();
    if (!Helpers.checkingUserPremission(permission, "get")) {
        throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
    }
    String typeId = request.getParameter(QueryGetRequest.PARAM_TYPE_ID);
    DateTimeFormat dateTimeFormat = request.getDateTimeFormatParameter();
    boolean includePropertyDefinitions = request.getBooleanParameter(QueryGetRequest.PARAM_PROPERTY_DEFINITIONS, false);
    BigInteger maxItems = request.getBigIntegerParameter(QueryGetRequest.PARAM_MAX_ITEMS);
    BigInteger skipCount = request.getBigIntegerParameter(QueryGetRequest.PARAM_SKIP_COUNT);
    TypeDefinitionList typeList = CmisTypeServices.Impl.getTypeChildren(request.getRepositoryId(), typeId, includePropertyDefinitions, maxItems, skipCount, null);
    JSONObject jsonTypeList = JSONConverter.convert(typeList, dateTimeFormat);
    return jsonTypeList;
}
Also used : CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) TypeDefinitionList(org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionList) BigInteger(java.math.BigInteger) DateTimeFormat(org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)

Aggregations

TypeDefinitionList (org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionList)2 BigInteger (java.math.BigInteger)1 HashSet (java.util.HashSet)1 TypeDefinition (org.apache.chemistry.opencmis.commons.definitions.TypeDefinition)1 DateTimeFormat (org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)1 CmisBaseException (org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException)1 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)1 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)1 CmisRuntimeException (org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException)1 JSONObject (org.apache.chemistry.opencmis.commons.impl.json.JSONObject)1 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)1