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."));
}
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");
}
}
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");
}
}
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
}
}
}
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());
}
}
}
Aggregations