Search in sources :

Example 31 with ObjectData

use of org.apache.chemistry.opencmis.commons.data.ObjectData in project copper-cms by PogeyanOSS.

the class CreateAndDeletePolicyTest method run.

@Override
public void run(Session session) {
    if (hasPolicies(session)) {
        CmisTestResult f;
        // create a test folder
        Folder testFolder = createTestFolder(session);
        try {
            // create policy object
            Policy policy = createPolicy(session, testFolder, "testPolicy", "TCK Test Policy");
            // create document and apply policy
            Document doc = createDocument(session, testFolder, "testDocument", "Policy Test");
            if (Boolean.TRUE.equals(doc.getType().isControllablePolicy())) {
                doc.applyPolicy(policy);
                // check if policy has been applied
                List<Policy> policies1 = doc.getPolicies();
                boolean found1 = false;
                for (Policy p : policies1) {
                    if (p.getId().equals(policy.getId())) {
                        found1 = true;
                        break;
                    }
                }
                f = createResult(FAILURE, "Policy has not been applied to document! Policy Id: " + policy.getId() + ", Doc Id: " + doc.getId());
                addResult(assertIsTrue(found1, null, f));
                // get the policies
                List<ObjectData> policiesData2 = session.getBinding().getPolicyService().getAppliedPolicies(session.getRepositoryInfo().getId(), doc.getId(), "*", null);
                boolean found2 = false;
                if (policiesData2 != null && !policiesData2.isEmpty()) {
                    for (ObjectData p : policiesData2) {
                        if (p.getId().equals(policy.getId())) {
                            found2 = true;
                            break;
                        }
                    }
                }
                f = createResult(FAILURE, "Applied policy is not returned by the repository! Policy Id: " + policy.getId() + ", Doc Id: " + doc.getId());
                addResult(assertIsTrue(found2, null, f));
                // remove policy
                doc.removePolicy(policy);
                // check if policy has been applied
                List<Policy> policies3 = doc.getPolicies();
                if (policies3 != null) {
                    boolean found3 = false;
                    for (Policy p : policies3) {
                        if (p.getId().equals(policy.getId())) {
                            found3 = true;
                            break;
                        }
                    }
                    f = createResult(FAILURE, "Policy has not been removed from document! Policy Id: " + policy.getId() + ", Doc Id: " + doc.getId());
                    addResult(assertIsFalse(found3, null, f));
                }
            } else {
                addResult(createResult(INFO, "Document type " + doc.getType().getId() + " does not allow applying and removing policies. Choose a different document type for this test."));
            }
            // delete document
            deleteObject(doc);
            // delete policy object
            deleteObject(policy);
        } finally {
            // delete the test folder
            deleteTestFolder();
        }
    } else {
        addResult(createResult(SKIPPED, "Policies not supported. Test skipped!"));
    }
}
Also used : Policy(org.apache.chemistry.opencmis.client.api.Policy) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document)

Example 32 with ObjectData

use of org.apache.chemistry.opencmis.commons.data.ObjectData in project structr by structr.

the class CMISNavigationService method getFolderParent.

@Override
public ObjectData getFolderParent(final String repositoryId, final String folderId, final String propertyFilter, final ExtensionsData extension) {
    final App app = StructrApp.getInstance();
    ObjectData result = null;
    try (final Tx tx = app.tx()) {
        final AbstractFile graphObject = app.get(AbstractFile.class, folderId);
        if (graphObject != null) {
            final Folder parent = graphObject.getParent();
            if (parent != null) {
                result = CMISObjectWrapper.wrap(parent, propertyFilter, false);
            }
        }
        tx.success();
    } catch (Throwable t) {
        logger.warn("", t);
    }
    if (result != null) {
        return result;
    }
    return null;
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) AbstractFile(org.structr.web.entity.AbstractFile) Tx(org.structr.core.graph.Tx) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) CMISRootFolder(org.structr.files.cmis.repository.CMISRootFolder) Folder(org.structr.web.entity.Folder)

Aggregations

ObjectData (org.apache.chemistry.opencmis.commons.data.ObjectData)32 CmisRuntimeException (org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException)23 DateTimeFormat (org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)22 JSONObject (org.apache.chemistry.opencmis.commons.impl.json.JSONObject)20 Properties (org.apache.chemistry.opencmis.commons.data.Properties)8 Holder (org.apache.chemistry.opencmis.commons.spi.Holder)7 IUserGroupObject (com.pogeyan.cmis.api.auth.IUserGroupObject)6 Acl (org.apache.chemistry.opencmis.commons.data.Acl)6 CmisNotSupportedException (org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException)3 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)3 App (org.structr.core.app.App)3 StructrApp (org.structr.core.app.StructrApp)3 Tx (org.structr.core.graph.Tx)3 BaseMessage (com.pogeyan.cmis.api.BaseMessage)2 IBaseObject (com.pogeyan.cmis.api.data.IBaseObject)2 ArrayList (java.util.ArrayList)2 Document (org.apache.chemistry.opencmis.client.api.Document)2 Folder (org.apache.chemistry.opencmis.client.api.Folder)2 Policy (org.apache.chemistry.opencmis.client.api.Policy)2 ObjectParentData (org.apache.chemistry.opencmis.commons.data.ObjectParentData)2