Search in sources :

Example 6 with CmisInvalidArgumentException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException 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 7 with CmisInvalidArgumentException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException in project structr by structr.

the class CMISAclService method applyAce.

// ----- private methods -----
private void applyAce(final AccessControllable node, final Ace toAdd, final boolean revoke) throws FrameworkException {
    final String principalId = toAdd.getPrincipalId();
    final List<String> permissions = toAdd.getPermissions();
    final Principal principal = CMISObjectWrapper.translateUsernameToPrincipal(principalId);
    if (principal != null) {
        for (final String permissionString : permissions) {
            final Permission permission = Permissions.valueOf(permissionString);
            if (permission != null) {
                if (revoke) {
                    node.revoke(permission, principal);
                } else {
                    node.grant(permission, principal);
                }
            } else {
                throw new CmisInvalidArgumentException("Permission with ID " + permissionString + " does not exist");
            }
        }
    } else {
        throw new CmisObjectNotFoundException("Principal with ID " + principalId + " does not exist");
    }
}
Also used : CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) Permission(org.structr.common.Permission) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) Principal(org.structr.core.entity.Principal)

Example 8 with CmisInvalidArgumentException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException in project structr by structr.

the class CMISObjectService method moveObject.

@Override
public void moveObject(String repositoryId, final Holder<String> objectId, final String targetFolderId, final String sourceFolderId, final ExtensionsData extension) {
    if (sourceFolderId != null && targetFolderId != null) {
        if (sourceFolderId.equals(targetFolderId)) {
            return;
        }
        final App app = StructrApp.getInstance(securityContext);
        try (final Tx tx = app.tx()) {
            final File file = get(app, File.class, objectId.getValue());
            final Folder parent = file.getParent();
            // check if the file to be moved is filed in the root folder (=> null parent)
            if (CMISInfo.ROOT_FOLDER_ID.equals(sourceFolderId) && parent != null) {
                throw new CmisInvalidArgumentException("Object with ID " + objectId.getValue() + " is not filed in folder with ID " + sourceFolderId);
            }
            // check if the file to be moved is filed in the given source folder
            if (parent != null && !sourceFolderId.equals(parent.getUuid())) {
                throw new CmisInvalidArgumentException("Object with ID " + objectId.getValue() + " is not filed in folder with ID " + sourceFolderId);
            }
            // check if the target folder is the root folder
            if (CMISInfo.ROOT_FOLDER_ID.equals(targetFolderId)) {
                // root folder => null parent
                file.setParent(null);
            } else {
                // get will throw an exception if the folder doesn't exist
                file.setParent(get(app, Folder.class, targetFolderId));
            }
            tx.success();
        } catch (FrameworkException fex) {
            throw new CmisConstraintException(fex.getMessage(), fex);
        }
    } else {
        throw new CmisInvalidArgumentException("Source and target folder must be set");
    }
}
Also used : App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) Folder(org.structr.web.entity.Folder) AbstractFile(org.structr.web.entity.AbstractFile) File(org.structr.web.entity.File)

Example 9 with CmisInvalidArgumentException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException in project alfresco-remote-api by Alfresco.

the class TestCMIS method testMNT12956QueryingCMIS11UsesDictionary11.

@Test
public void testMNT12956QueryingCMIS11UsesDictionary11() throws Exception {
    final TestNetwork network1 = getTestFixture().getRandomNetwork();
    String username = "user" + System.currentTimeMillis();
    PersonInfo personInfo = new PersonInfo(username, username, username, TEST_PASSWORD, null, null, null, null, null, null, null);
    TestPerson person = network1.createUser(personInfo);
    String personId = person.getId();
    final List<NodeRef> documents = new ArrayList<NodeRef>();
    final String filename = GUID.generate();
    TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            String siteName = "site" + System.currentTimeMillis();
            SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE);
            TestSite site = repoService.createSite(null, siteInfo);
            NodeRef docNodeRef = repoService.createDocument(site.getContainerNodeRef(DOCUMENT_LIBRARY_CONTAINER_NAME), filename, "test content");
            documents.add(docNodeRef);
            return null;
        }
    }, personId, network1.getId());
    NodeRef docNodeRef = documents.get(0);
    publicApiClient.setRequestContext(new RequestContext(network1.getId(), personId));
    CmisSession atomCmisSession10 = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_10, AlfrescoObjectFactoryImpl.class.getName());
    CmisSession atomCmisSession11 = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_11);
    // query
    {
        // searching by NodeRef, expect result objectIds to be objectId
        Set<String> expectedObjectIds = new HashSet<String>();
        expectedObjectIds.add(docNodeRef.getId());
        int numMatchingDocs = 0;
        // NodeRef input
        List<CMISNode> results = atomCmisSession11.query("SELECT cmis:objectId,cmis:name,cmis:secondaryObjectTypeIds FROM cmis:document WHERE cmis:name LIKE '" + filename + "'", false, 0, Integer.MAX_VALUE);
        assertEquals(expectedObjectIds.size(), results.size());
        for (CMISNode node : results) {
            String objectId = stripCMISSuffix((String) node.getProperties().get(PropertyIds.OBJECT_ID));
            if (expectedObjectIds.contains(objectId)) {
                numMatchingDocs++;
            }
        }
        assertEquals(expectedObjectIds.size(), numMatchingDocs);
        try {
            results = atomCmisSession10.query("SELECT cmis:objectId,cmis:name,cmis:secondaryObjectTypeIds FROM cmis:document WHERE cmis:name LIKE '" + filename + "'", false, 0, Integer.MAX_VALUE);
            fail("OpenCMIS 1.0 knows nothing about cmis:secondaryObjectTypeIds");
        } catch (CmisInvalidArgumentException expectedException) {
        // ok
        }
    }
}
Also used : CMISNode(org.alfresco.rest.api.tests.client.data.CMISNode) AlfrescoObjectFactoryImpl(org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl) CmisSession(org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession) Set(java.util.Set) HashSet(java.util.HashSet) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) ArrayList(java.util.ArrayList) 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) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) ArrayList(java.util.ArrayList) AbstractList(java.util.AbstractList) List(java.util.List) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Example 10 with CmisInvalidArgumentException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException in project alfresco-repository by Alfresco.

the class CMISConnector method removeSecondaryTypes.

public void removeSecondaryTypes(NodeRef nodeRef, List<String> secondaryTypes) {
    if (secondaryTypes != null && secondaryTypes.size() > 0) {
        for (String secondaryType : secondaryTypes) {
            TypeDefinitionWrapper type = getType(secondaryType);
            if (type == null) {
                throw new CmisInvalidArgumentException("Invalid secondaryType: " + secondaryType);
            }
            nodeService.removeAspect(nodeRef, type.getAlfrescoName());
        }
    }
}
Also used : ItemTypeDefinitionWrapper(org.alfresco.opencmis.dictionary.ItemTypeDefinitionWrapper) TypeDefinitionWrapper(org.alfresco.opencmis.dictionary.TypeDefinitionWrapper) DocumentTypeDefinitionWrapper(org.alfresco.opencmis.dictionary.DocumentTypeDefinitionWrapper) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) PropertyString(org.apache.chemistry.opencmis.commons.data.PropertyString)

Aggregations

CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)42 CMISNodeInfo (org.alfresco.opencmis.dictionary.CMISNodeInfo)14 NodeRef (org.alfresco.service.cmr.repository.NodeRef)13 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)12 ArrayList (java.util.ArrayList)11 CmisRuntimeException (org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException)10 TypeDefinitionWrapper (org.alfresco.opencmis.dictionary.TypeDefinitionWrapper)9 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)8 PropertyString (org.apache.chemistry.opencmis.commons.data.PropertyString)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 DocumentTypeDefinitionWrapper (org.alfresco.opencmis.dictionary.DocumentTypeDefinitionWrapper)6 ItemTypeDefinitionWrapper (org.alfresco.opencmis.dictionary.ItemTypeDefinitionWrapper)6 CmisStreamNotSupportedException (org.apache.chemistry.opencmis.commons.exceptions.CmisStreamNotSupportedException)6 List (java.util.List)5 ObjectData (org.apache.chemistry.opencmis.commons.data.ObjectData)5 CmisContentAlreadyExistsException (org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException)5 IOException (java.io.IOException)4 QName (org.alfresco.service.namespace.QName)4 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)4