Search in sources :

Example 1 with Relationship

use of org.apache.chemistry.opencmis.client.api.Relationship in project iaf by ibissource.

the class CmisSender method sendMessageForActionFetch.

private String sendMessageForActionFetch(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
    Element queryElement = null;
    try {
        if (XmlUtils.isWellFormed(message, "cmis")) {
            queryElement = XmlUtils.buildElement(message);
        } else {
            queryElement = XmlUtils.buildElement("<cmis/>");
        }
    } catch (DomBuilderException e) {
        throw new SenderException(e);
    }
    String objectIdstr = XmlUtils.getChildTagAsString(queryElement, "objectId");
    String filter = XmlUtils.getChildTagAsString(queryElement, "filter");
    boolean includeAllowableActions = XmlUtils.getChildTagAsBoolean(queryElement, "includeAllowableActions");
    boolean includePolicies = XmlUtils.getChildTagAsBoolean(queryElement, "includePolicies");
    boolean includeAcl = XmlUtils.getChildTagAsBoolean(queryElement, "includeAcl");
    OperationContext operationContext = session.createOperationContext();
    if (StringUtils.isNotEmpty(filter))
        operationContext.setFilterString(filter);
    operationContext.setIncludeAllowableActions(includeAllowableActions);
    operationContext.setIncludePolicies(includePolicies);
    operationContext.setIncludeAcls(includeAcl);
    CmisObject object = null;
    try {
        object = session.getObject(session.createObjectId(objectIdstr), operationContext);
    } catch (CmisObjectNotFoundException e) {
        if (StringUtils.isNotEmpty(getResultOnNotFound())) {
            log.info(getLogPrefix() + "document with id [" + message + "] not found", e);
            return getResultOnNotFound();
        } else {
            throw new SenderException(e);
        }
    }
    XmlBuilder cmisXml = new XmlBuilder("cmis");
    XmlBuilder propertiesXml = new XmlBuilder("properties");
    for (Iterator it = object.getProperties().iterator(); it.hasNext(); ) {
        Property property = (Property) it.next();
        propertiesXml.addSubElement(getPropertyXml(property));
    }
    cmisXml.addSubElement(propertiesXml);
    XmlBuilder allowableActionsXml = new XmlBuilder("allowableActions");
    Set<Action> actions = object.getAllowableActions().getAllowableActions();
    for (Action action : actions) {
        XmlBuilder actionXml = new XmlBuilder("action");
        actionXml.setValue(action.value());
        allowableActionsXml.addSubElement(actionXml);
    }
    cmisXml.addSubElement(allowableActionsXml);
    XmlBuilder isExactAclXml = new XmlBuilder("isExactAcl");
    if (object.getAcl() != null)
        isExactAclXml.setValue(object.getAcl().isExact().toString());
    cmisXml.addSubElement(isExactAclXml);
    XmlBuilder policiesXml = new XmlBuilder("policyIds");
    List<ObjectId> policies = object.getPolicyIds();
    if (policies != null) {
        for (ObjectId objectId : policies) {
            XmlBuilder policyXml = new XmlBuilder("policyId");
            policyXml.setValue(objectId.getId());
            policiesXml.addSubElement(policyXml);
        }
    }
    cmisXml.addSubElement(policiesXml);
    XmlBuilder relationshipsXml = new XmlBuilder("relationships");
    List<Relationship> relationships = object.getRelationships();
    if (relationships != null) {
        for (Relationship relation : relationships) {
            XmlBuilder policyXml = new XmlBuilder("relation");
            policyXml.setValue(relation.getId());
            relationshipsXml.addSubElement(policyXml);
        }
    }
    cmisXml.addSubElement(relationshipsXml);
    return cmisXml.toXML();
}
Also used : OperationContext(org.apache.chemistry.opencmis.client.api.OperationContext) Action(org.apache.chemistry.opencmis.commons.enums.Action) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) Element(org.w3c.dom.Element) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) Relationship(org.apache.chemistry.opencmis.client.api.Relationship) Iterator(java.util.Iterator) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) SenderException(nl.nn.adapterframework.core.SenderException) Property(org.apache.chemistry.opencmis.client.api.Property)

Example 2 with Relationship

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

the class AbstractSessionTest method createRelationship.

/**
 * Creates a relationship.
 */
protected Relationship createRelationship(Session session, String name, ObjectId source, ObjectId target, String objectTypeId) {
    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, "Relationship type '" + objectTypeId + "' is not available: " + e.getMessage(), e, true));
        return null;
    }
    if (Boolean.FALSE.equals(type.isCreatable())) {
        addResult(createResult(SKIPPED, "Relationship type '" + objectTypeId + "' is not creatable!", true));
        return null;
    }
    // create
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(PropertyIds.NAME, name);
    properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
    properties.put(PropertyIds.SOURCE_ID, source.getId());
    properties.put(PropertyIds.TARGET_ID, target.getId());
    ObjectId relId;
    Relationship result = null;
    try {
        relId = session.createRelationship(properties);
        result = (Relationship) session.getObject(relId, SELECT_ALL_NO_CACHE_OC);
    } catch (Exception e) {
        addResult(createResult(UNEXPECTED_EXCEPTION, "Relationship could not be created! Exception: " + e.getMessage(), e, true));
    }
    if (result != null) {
        try {
            // check the new relationship
            addResult(checkObject(session, result, getAllProperties(result), "New document object spec compliance"));
        } catch (CmisBaseException e) {
            addResult(createResult(UNEXPECTED_EXCEPTION, "Newly created document is invalid! Exception: " + e.getMessage(), e, true));
        }
    }
    return result;
}
Also used : ObjectType(org.apache.chemistry.opencmis.client.api.ObjectType) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) HashMap(java.util.HashMap) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) CmisBaseException(org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException) Relationship(org.apache.chemistry.opencmis.client.api.Relationship) FileableCmisObject(org.apache.chemistry.opencmis.client.api.FileableCmisObject) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CmisBaseException(org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException) CmisNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException) IOException(java.io.IOException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)

Example 3 with Relationship

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

the class AbstractSessionTest method checkRelationships.

private void checkRelationships(Session session, List<CmisTestResult> results, CmisObject object) {
    if (object instanceof Relationship) {
        if (isNotEmpty(object.getRelationships())) {
            addResult(results, createResult(FAILURE, "A relationship has relationships!"));
            return;
        }
    }
    if (object.getRelationships() != null) {
        for (Relationship relationship : object.getRelationships()) {
            if (relationship == null) {
                addResult(results, createResult(FAILURE, "A relationship in the relationship list is null!"));
                continue;
            }
            CmisObject fullRelationshipObject = session.getObject(relationship, SELECT_ALL_NO_CACHE_OC);
            addResult(results, checkObject(session, fullRelationshipObject, getAllProperties(fullRelationshipObject), "Relationship check: " + fullRelationshipObject.getId()));
        }
    }
}
Also used : Relationship(org.apache.chemistry.opencmis.client.api.Relationship) FileableCmisObject(org.apache.chemistry.opencmis.client.api.FileableCmisObject) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject)

Example 4 with Relationship

use of org.apache.chemistry.opencmis.client.api.Relationship in project alfresco-remote-api by Alfresco.

the class TestCMIS method testPublicApi110.

@Test
public void testPublicApi110() throws Exception {
    Iterator<TestNetwork> networksIt = getTestFixture().networksIterator();
    final TestNetwork network1 = networksIt.next();
    Iterator<String> personIt = network1.getPersonIds().iterator();
    final String person1Id = personIt.next();
    final String person2Id = personIt.next();
    final List<NodeRef> nodes = new ArrayList<NodeRef>(5);
    // Create some favourite targets, sites, files and folders
    TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            String siteName1 = "site" + GUID.generate();
            SiteInformation siteInfo1 = new SiteInformation(siteName1, siteName1, siteName1, SiteVisibility.PUBLIC);
            TestSite site1 = network1.createSite(siteInfo1);
            String siteName2 = "site" + GUID.generate();
            SiteInformation siteInfo2 = new SiteInformation(siteName2, siteName2, siteName2, SiteVisibility.PRIVATE);
            TestSite site2 = network1.createSite(siteInfo2);
            NodeRef nodeRef1 = repoService.createDocument(site1.getContainerNodeRef(DOCUMENT_LIBRARY_CONTAINER_NAME), "Test Doc1", "Test Doc1 Title", "Test Doc1 Description", "Test Content");
            nodes.add(nodeRef1);
            NodeRef nodeRef2 = repoService.createDocument(site1.getContainerNodeRef(DOCUMENT_LIBRARY_CONTAINER_NAME), "Test Doc2", "Test Doc2 Title", "Test Doc2 Description", "Test Content");
            nodes.add(nodeRef2);
            NodeRef nodeRef3 = repoService.createDocument(site2.getContainerNodeRef(DOCUMENT_LIBRARY_CONTAINER_NAME), "Test Doc2", "Test Doc2 Title", "Test Doc2 Description", "Test Content");
            nodes.add(nodeRef3);
            repoService.createAssociation(nodeRef2, nodeRef1, ASSOC_ORIGINAL);
            repoService.createAssociation(nodeRef3, nodeRef1, ASSOC_ORIGINAL);
            site1.inviteToSite(person2Id, SiteRole.SiteCollaborator);
            return null;
        }
    }, person1Id, network1.getId());
    {
        OperationContext cmisOperationCtxOverride = new OperationContextImpl();
        cmisOperationCtxOverride.setIncludeRelationships(IncludeRelationships.BOTH);
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2Id, cmisOperationCtxOverride));
        CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_10, AlfrescoObjectFactoryImpl.class.getName());
        CmisObject o1 = cmisSession.getObject(nodes.get(0).getId());
        List<Relationship> relationships = o1.getRelationships();
        assertEquals(1, relationships.size());
        Relationship r = relationships.get(0);
        CmisObject source = r.getSource();
        CmisObject target = r.getTarget();
        String sourceVersionSeriesId = (String) source.getProperty(PropertyIds.VERSION_SERIES_ID).getFirstValue();
        String targetVersionSeriesId = (String) target.getProperty(PropertyIds.VERSION_SERIES_ID).getFirstValue();
        assertEquals(nodes.get(1).getId(), sourceVersionSeriesId);
        assertEquals(nodes.get(0).getId(), targetVersionSeriesId);
    }
}
Also used : OperationContext(org.apache.chemistry.opencmis.client.api.OperationContext) CmisSession(org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) ArrayList(java.util.ArrayList) OperationContextImpl(org.apache.chemistry.opencmis.client.runtime.OperationContextImpl) CmisUpdateConflictException(org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisPermissionDeniedException(org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SiteInformation(org.alfresco.rest.api.tests.RepoService.SiteInformation) Relationship(org.apache.chemistry.opencmis.client.api.Relationship) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) FileableCmisObject(org.apache.chemistry.opencmis.client.api.FileableCmisObject) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) ArrayList(java.util.ArrayList) AbstractList(java.util.AbstractList) List(java.util.List) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Example 5 with Relationship

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

the class AbstractSessionTest method checkObject.

protected CmisTestResult checkObject(Session session, CmisObject object, String[] properties, String message) {
    List<CmisTestResult> results = new ArrayList<CmisTestResult>();
    CmisTestResult f;
    f = createResult(FAILURE, "Object is null!", true);
    addResult(results, assertNotNull(object, null, f));
    if (object != null) {
        f = createResult(FAILURE, "Object ID is not set!");
        addResult(results, assertStringNotEmpty(object.getId(), null, f));
        GregorianCalendar creationDate = null;
        GregorianCalendar lastModificationDate = null;
        // properties
        for (String propId : properties) {
            Property<?> prop = object.getProperty(propId);
            // values of non-spec properties are not checked here
            PropertyCheckEnum propertyCheck = PropertyCheckEnum.NO_VALUE_CHECK;
            // known properties that are strings and must be set
            if (PropertyIds.OBJECT_ID.equals(propId) || PropertyIds.BASE_TYPE_ID.equals(propId) || PropertyIds.OBJECT_TYPE_ID.equals(propId) || PropertyIds.PATH.equals(propId) || PropertyIds.SOURCE_ID.equals(propId) || PropertyIds.TARGET_ID.equals(propId)) {
                propertyCheck = PropertyCheckEnum.STRING_MUST_NOT_BE_EMPTY;
            }
            if (!(object instanceof Relationship)) {
                if (PropertyIds.CREATED_BY.equals(propId) || PropertyIds.LAST_MODIFIED_BY.equals(propId)) {
                    propertyCheck = PropertyCheckEnum.STRING_MUST_NOT_BE_EMPTY;
                }
            }
            // known properties that are strings and should be set
            if (PropertyIds.NAME.equals(propId) || PropertyIds.POLICY_TEXT.equals(propId)) {
                propertyCheck = PropertyCheckEnum.STRING_SHOULD_NOT_BE_EMPTY;
            }
            // known properties that are not strings and must be set
            if (PropertyIds.IS_IMMUTABLE.equals(propId)) {
                propertyCheck = PropertyCheckEnum.MUST_BE_SET;
            }
            if (!(object instanceof Relationship)) {
                if (PropertyIds.CREATION_DATE.equals(propId) || PropertyIds.LAST_MODIFICATION_DATE.equals(propId)) {
                    propertyCheck = PropertyCheckEnum.MUST_BE_SET;
                }
            }
            // special case: parent
            if (PropertyIds.PARENT_ID.equals(propId)) {
                if (object instanceof Folder) {
                    if (((Folder) object).isRootFolder()) {
                        propertyCheck = PropertyCheckEnum.MUST_NOT_BE_SET;
                    } else {
                        propertyCheck = PropertyCheckEnum.STRING_MUST_NOT_BE_EMPTY;
                    }
                } else {
                    addResult(results, createResult(FAILURE, "Property " + PropertyIds.PARENT_ID + " is only defined for folders!"));
                }
            }
            // special case: path
            if (PropertyIds.PATH.equals(propId) && prop.getFirstValue() != null) {
                Object path = prop.getFirstValue();
                if (path instanceof String) {
                    f = createResult(FAILURE, "Path does not start with '/': " + path);
                    addResult(results, assertIsTrue(((String) path).length() > 0 && ((String) path).charAt(0) == '/', null, f));
                } else {
                    addResult(results, createResult(FAILURE, "Property " + PropertyIds.PATH + " is not a string!"));
                }
            }
            // check property
            addResult(results, checkProperty(prop, "Property " + propId, propertyCheck));
            // catch creationDate and lastModificationDate
            if (PropertyIds.CREATION_DATE.equals(propId)) {
                if (prop != null) {
                    creationDate = (GregorianCalendar) prop.getFirstValue();
                }
            } else if (PropertyIds.LAST_MODIFICATION_DATE.equals(propId)) {
                if (prop != null) {
                    lastModificationDate = (GregorianCalendar) prop.getFirstValue();
                }
            }
        }
        // check creationDate <= lastModificationDate
        if (creationDate != null && lastModificationDate != null) {
            f = createResult(FAILURE, "Last modification date precedes creation date!");
            addResult(results, assertIsTrue(creationDate.getTimeInMillis() <= lastModificationDate.getTimeInMillis(), null, f));
            f = createResult(WARNING, "Creation date and last modification date have different timezones.");
            addResult(assertIsTrue(creationDate.getTimeZone().hasSameRules(lastModificationDate.getTimeZone()), null, f));
        }
        // allowable actions
        if ((object.getAllowableActions() == null) || (object.getAllowableActions().getAllowableActions() == null)) {
            addResult(results, createResult(FAILURE, "Object has no allowable actions!"));
        } else {
            Set<Action> actions = object.getAllowableActions().getAllowableActions();
            f = createResult(FAILURE, "Object has no CAN_GET_PROPERTIES allowable action!");
            addResult(results, assertAllowableAction(object, Action.CAN_GET_PROPERTIES, null, f));
            addResult(results, assertIsTrue(object.hasAllowableAction(Action.CAN_GET_PROPERTIES), null, f));
            if (object instanceof Document) {
                if (actions.contains(Action.CAN_CHECK_OUT) && actions.contains(Action.CAN_CHECK_IN)) {
                    addResult(results, createResult(FAILURE, "Document object has CAN_CHECK_OUT and CAN_CHECK_IN allowable actions!"));
                }
                if (actions.contains(Action.CAN_CHECK_OUT) && actions.contains(Action.CAN_CANCEL_CHECK_OUT)) {
                    addResult(results, createResult(FAILURE, "Document object has CAN_CHECK_OUT and CAN_CANCEL_CHECK_OUT allowable actions!"));
                }
                Document doc = (Document) object;
                DocumentTypeDefinition docType = (DocumentTypeDefinition) doc.getType();
                if (doc.isVersionSeriesCheckedOut() != null) {
                    if (doc.isVersionSeriesCheckedOut()) {
                        f = createResult(WARNING, "Document is checked out and has CAN_CHECK_OUT allowable action!");
                        addResult(results, assertNotAllowableAction(object, Action.CAN_CHECK_OUT, null, f));
                        if (doc.getVersionSeriesCheckedOutId() == null) {
                            addResult(results, createResult(WARNING, "Document is checked out and but the property cmis:versionSeriesCheckedOutId is not set!"));
                        } else {
                            if (doc.getVersionSeriesCheckedOutId().equals(object.getId())) {
                                // object is PWC
                                f = createResult(FAILURE, "PWC doesn't have CAN_CHECK_IN allowable action!");
                                addResult(results, assertAllowableAction(object, Action.CAN_CHECK_IN, null, f));
                                f = createResult(FAILURE, "PWC doesn't have CAN_CANCEL_CHECK_OUT allowable action!");
                                addResult(results, assertAllowableAction(object, Action.CAN_CANCEL_CHECK_OUT, null, f));
                            } else {
                                // object is not PWC
                                f = createResult(WARNING, "Non-PWC has CAN_CHECK_IN allowable action!");
                                addResult(results, assertNotAllowableAction(object, Action.CAN_CHECK_IN, null, f));
                                f = createResult(WARNING, "Non-PWC has CAN_CANCEL_CHECK_OUT allowable action!");
                                addResult(results, assertNotAllowableAction(object, Action.CAN_CANCEL_CHECK_OUT, null, f));
                            }
                        }
                    } else {
                        f = createResult(FAILURE, "Document is not checked out and has CAN_CHECK_IN allowable action!");
                        addResult(results, assertNotAllowableAction(object, Action.CAN_CHECK_IN, null, f));
                        f = createResult(FAILURE, "Document is not checked out and has CAN_CANCEL_CHECK_OUT allowable action!");
                        addResult(results, assertNotAllowableAction(object, Action.CAN_CANCEL_CHECK_OUT, null, f));
                        // versionable check
                        if (docType.isVersionable()) {
                            // 
                            if (Boolean.TRUE.equals(doc.isLatestVersion())) {
                                f = createResult(WARNING, "Document is versionable and not checked but has no CAN_CHECK_OUT allowable action!");
                                addResult(results, assertAllowableAction(object, Action.CAN_CHECK_OUT, null, f));
                            }
                        } else {
                            f = createResult(FAILURE, "Document is not versionable but has CAN_CHECK_OUT allowable action!");
                            addResult(results, assertNotAllowableAction(object, Action.CAN_CHECK_OUT, null, f));
                        }
                    }
                } else {
                    addResult(results, createResult(WARNING, "Property cmis:isVersionSeriesCheckedOut is not set!"));
                }
                // immutable check
                if (Boolean.TRUE.equals(doc.isImmutable())) {
                    f = createResult(FAILURE, "Document is immutable and has CAN_UPDATE_PROPERTIES allowable action!");
                    addResult(results, assertNotAllowableAction(object, Action.CAN_UPDATE_PROPERTIES, null, f));
                    f = createResult(FAILURE, "Document is immutable and has CAN_DELETE_OBJECT allowable action!");
                    addResult(results, assertNotAllowableAction(object, Action.CAN_DELETE_OBJECT, null, f));
                }
            } else {
                f = createResult(FAILURE, "Non-Document object has CAN_CHECK_IN allowable action!");
                addResult(results, assertNotAllowableAction(object, Action.CAN_CHECK_IN, null, f));
                f = createResult(FAILURE, "Non-Document object has CAN_CHECK_OUT allowable action!");
                addResult(results, assertNotAllowableAction(object, Action.CAN_CHECK_OUT, null, f));
                f = createResult(FAILURE, "Non-Document object has CAN_CANCEL_CHECK_OUT allowable action!");
                addResult(results, assertNotAllowableAction(object, Action.CAN_CANCEL_CHECK_OUT, null, f));
                f = createResult(FAILURE, "Non-Document object has CAN_GET_CONTENT_STREAM allowable action!");
                addResult(results, assertNotAllowableAction(object, Action.CAN_GET_CONTENT_STREAM, null, f));
                f = createResult(FAILURE, "Non-Document object has CAN_DELETE_CONTENT_STREAM allowable action!");
                addResult(results, assertNotAllowableAction(object, Action.CAN_DELETE_CONTENT_STREAM, null, f));
                f = createResult(FAILURE, "Non-Document object has CAN_GET_ALL_VERSIONS allowable action!");
                addResult(results, assertNotAllowableAction(object, Action.CAN_GET_ALL_VERSIONS, null, f));
            }
            if (object instanceof Folder) {
                Folder folder = (Folder) object;
                if (folder.isRootFolder()) {
                    f = createResult(FAILURE, "Root folder has CAN_DELETE_OBJECT allowable action!");
                    addResult(results, assertNotAllowableAction(object, Action.CAN_DELETE_OBJECT, null, f));
                    f = createResult(FAILURE, "Root folder has CAN_GET_FOLDER_PARENT allowable action!");
                    addResult(results, assertNotAllowableAction(object, Action.CAN_GET_FOLDER_PARENT, null, f));
                    f = createResult(FAILURE, "Root folder has CAN_MOVE_OBJECT allowable action!");
                    addResult(results, assertNotAllowableAction(object, Action.CAN_MOVE_OBJECT, null, f));
                }
            } else {
                f = createResult(FAILURE, "Non-Folder object has CAN_GET_DESCENDANTS allowable action!");
                addResult(results, assertNotAllowableAction(object, Action.CAN_GET_DESCENDANTS, null, f));
                f = createResult(FAILURE, "Non-Folder object has CAN_GET_FOLDER_PARENT allowable action!");
                addResult(results, assertNotAllowableAction(object, Action.CAN_GET_FOLDER_PARENT, null, f));
                f = createResult(FAILURE, "Non-Folder object has CAN_GET_CHILDREN allowable action!");
                addResult(results, assertNotAllowableAction(object, Action.CAN_GET_CHILDREN, null, f));
                f = createResult(FAILURE, "Non-Folder object has CAN_DELETE_TREE allowable action!");
                addResult(results, assertNotAllowableAction(object, Action.CAN_DELETE_TREE, null, f));
                f = createResult(FAILURE, "Non-Folder object has CAN_GET_FOLDER_PARENT allowable action!");
                addResult(results, assertNotAllowableAction(object, Action.CAN_GET_FOLDER_PARENT, null, f));
                f = createResult(FAILURE, "Non-Folder object has CAN_CREATE_DOCUMENT allowable action!");
                addResult(results, assertNotAllowableAction(object, Action.CAN_CREATE_DOCUMENT, null, f));
                f = createResult(FAILURE, "Non-Folder object has CAN_CREATE_FOLDER allowable action!");
                addResult(results, assertNotAllowableAction(object, Action.CAN_CREATE_FOLDER, null, f));
            }
            if (!(object instanceof FileableCmisObject) || (object instanceof Folder)) {
                f = createResult(FAILURE, "Non-Filable object or folder has CAN_ADD_OBJECT_TO_FOLDER allowable action!");
                addResult(results, assertNotAllowableAction(object, Action.CAN_ADD_OBJECT_TO_FOLDER, null, f));
                f = createResult(FAILURE, "Non-Filable object or folder has CAN_REMOVE_OBJECT_FROM_FOLDER allowable action!");
                addResult(results, assertNotAllowableAction(object, Action.CAN_REMOVE_OBJECT_FROM_FOLDER, null, f));
            }
            if (!(object instanceof FileableCmisObject)) {
                f = createResult(FAILURE, "Non-Fileable object has CAN_MOVE_OBJECT allowable action!");
                addResult(results, assertNotAllowableAction(object, Action.CAN_MOVE_OBJECT, null, f));
            }
            // get allowable actions again
            AllowableActions allowableActions = session.getBinding().getObjectService().getAllowableActions(session.getRepositoryInfo().getId(), object.getId(), null);
            if (allowableActions.getAllowableActions() == null) {
                addResult(results, createResult(FAILURE, "getAllowableActions() didn't returned allowable actions!"));
            } else {
                f = createResult(FAILURE, "Object allowable actions don't match the allowable actions returned by getAllowableActions()!");
                addResult(results, assertEqualSet(object.getAllowableActions().getAllowableActions(), allowableActions.getAllowableActions(), null, f));
            }
        }
        // check ACL
        if (object.getAcl() != null && object.getAcl().getAces() != null) {
            addResult(results, checkACL(session, object.getAcl(), true, "ACL"));
        }
        // check policies
        if (hasPolicies(session)) {
            try {
                List<ObjectData> appliedPolicies = session.getBinding().getPolicyService().getAppliedPolicies(session.getRepositoryInfo().getId(), object.getId(), "*", null);
                if (appliedPolicies == null) {
                    appliedPolicies = Collections.emptyList();
                }
                List<Policy> objectPolicies = object.getPolicies();
                if (objectPolicies == null) {
                    objectPolicies = Collections.emptyList();
                }
                f = createResult(FAILURE, "The number of policies returned by getAppliedPolicies() and the number of object policies don't match!");
                addResult(results, assertEquals(appliedPolicies.size(), objectPolicies.size(), null, f));
            } catch (CmisNotSupportedException e) {
                addResult(results, createResult(WARNING, "getAppliedPolicies() not supported for object: " + object.getId()));
            }
        }
        // check relationships
        checkRelationships(session, results, object);
        // check document content
        checkDocumentContent(session, results, object);
        // check renditions
        if (object.getRenditions() != null) {
            addResult(results, checkRenditions(session, object, "Rendition check"));
        }
        // check allowed child object type ids
        if (object instanceof Folder) {
            List<String> otids = object.getPropertyValue(PropertyIds.ALLOWED_CHILD_OBJECT_TYPE_IDS);
            if (otids != null) {
                for (String otid : otids) {
                    try {
                        session.getTypeDefinition(otid);
                    } catch (CmisBaseException e) {
                        addResult(results, createResult(FAILURE, "The cmis:allowedChildObjectTypeIds property contains the type ID '" + otid + "' but the type doesn't exists. Folder ID: " + object.getId()));
                    }
                }
            }
        }
        // check path
        if (object instanceof FileableCmisObject) {
            List<String> paths = ((FileableCmisObject) object).getPaths();
            if (object instanceof Folder) {
                f = createResult(FAILURE, "Folder does not have excatly one path! This is an OpenCMIS bug!");
                addResult(results, assertEquals(1, paths.size(), null, f));
            } else {
                if (Boolean.FALSE.equals(session.getRepositoryInfo().getCapabilities().isMultifilingSupported())) {
                    f = createResult(FAILURE, "Repository does not support multi-filing, but the object has more than one parent!");
                    addResult(results, assertIsTrue(paths.size() < 2, null, f));
                }
            }
        }
    }
    CmisTestResultImpl result = createResult(getWorst(results), message);
    result.getChildren().addAll(results);
    return result.getStatus().getLevel() <= OK.getLevel() ? null : result;
}
Also used : Policy(org.apache.chemistry.opencmis.client.api.Policy) CmisNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException) Action(org.apache.chemistry.opencmis.commons.enums.Action) DocumentTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition) ArrayList(java.util.ArrayList) GregorianCalendar(java.util.GregorianCalendar) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document) CmisBaseException(org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) Relationship(org.apache.chemistry.opencmis.client.api.Relationship) AllowableActions(org.apache.chemistry.opencmis.commons.data.AllowableActions) FileableCmisObject(org.apache.chemistry.opencmis.client.api.FileableCmisObject) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) FileableCmisObject(org.apache.chemistry.opencmis.client.api.FileableCmisObject)

Aggregations

Relationship (org.apache.chemistry.opencmis.client.api.Relationship)6 CmisObject (org.apache.chemistry.opencmis.client.api.CmisObject)5 FileableCmisObject (org.apache.chemistry.opencmis.client.api.FileableCmisObject)4 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)3 ArrayList (java.util.ArrayList)2 Document (org.apache.chemistry.opencmis.client.api.Document)2 Folder (org.apache.chemistry.opencmis.client.api.Folder)2 ObjectId (org.apache.chemistry.opencmis.client.api.ObjectId)2 OperationContext (org.apache.chemistry.opencmis.client.api.OperationContext)2 Action (org.apache.chemistry.opencmis.commons.enums.Action)2 CmisBaseException (org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException)2 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)2 CmisNotSupportedException (org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException)2 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)2 IOException (java.io.IOException)1 AbstractList (java.util.AbstractList)1 GregorianCalendar (java.util.GregorianCalendar)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1