/** * Validates that and object's ID is the one provided, in case both are not null or blank. */ private static void validateRedundantIdentifier(CmisObject object, String objectId) { if (object != null && StringUtils.isNotBlank(objectId) && !object.getId().equals(objectId)) { throw new IllegalArgumentException("The id provided does not match the object's ID"); } }
/** * Deletes an object by path or id (string identifier). * * @param pathOrIdOfObject * the id or path of the object * @param session * the session * * @throws CmisBaseException * if something go wrong, for example the object doesn't exist */ public static void delete(String pathOrIdOfObject, Session session) { CmisObject object = getObject(pathOrIdOfObject, session); if (object instanceof Folder) { ((Folder) object).deleteTree(true, UnfileObject.DELETE, true); } else { object.delete(true); } }
/** * Converts CMIS folder children to JCR node children * * @param folder CMIS folder * @param writer JCR node representation */ private void cmisChildren( Folder folder, DocumentWriter writer ) { ItemIterable<CmisObject> it = folder.getChildren(); for (CmisObject obj : it) { writer.addChild(obj.getId(), obj.getName()); } }
if (object.getId() == null) { return; try { CacheItem<Map<String, CmisObject>> cacheKeyMap = objectMap.get(object.getId()); if (cacheKeyMap == null) { cacheKeyMap = new CacheItem<Map<String, CmisObject>>(new HashMap<String, CmisObject>(), cacheTtl); objectMap.put(object.getId(), cacheKeyMap); String path = object.getPropertyValue(PropertyIds.PATH); if (path != null) { pathToIdMap.put(path, new CacheItem<String>(object.getId(), pathToIdTtl));
.add(new BulkUpdateObjectIdAndChangeTokenImpl(object.getId(), object.getChangeToken())); objectType = object.getType(); if (object.getSecondaryTypes() != null) { for (SecondaryType secondaryType : object.getSecondaryTypes()) { secondaryTypes.put(secondaryType.getId(), secondaryType);
if (child.getId().equals(testDocument.getId())) { for (Property<?> prop : child.getProperties()) { if (!properties.contains(prop.getDefinition().getQueryName())) { addResult(createResult(CmisTestResultStatus.WARNING, "getChildren() delivered the property '" addResult(assertNull(child.getAcl(), null, f)); addResult(assertNull(child.getAllowableActions(), null, f)); addResult(assertListNullOrEmpty(child.getPolicies(), null, f)); addResult(assertListNullOrEmpty(child.getRelationships(), null, f)); addResult(assertListNullOrEmpty(child.getRenditions(), null, f));
addResult(results, assertStringNotEmpty(object.getId(), null, f)); Property<?> prop = object.getProperty(propId); if ((object.getAllowableActions() == null) || (object.getAllowableActions().getAllowableActions() == null)) { addResult(results, createResult(FAILURE, "Object has no allowable actions!")); } else { Set<Action> actions = object.getAllowableActions().getAllowableActions(); addResult(results, assertIsTrue(object.hasAllowableAction(Action.CAN_GET_PROPERTIES), null, f)); "Document is checked out and but the property cmis:versionSeriesCheckedOutId is not set!")); } else { if (doc.getVersionSeriesCheckedOutId().equals(object.getId())) { .getAllowableActions(session.getRepositoryInfo().getId(), object.getId(), null); 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)); if (object.getAcl() != null && object.getAcl().getAces() != null) { addResult(results, checkACL(session, object.getAcl(), true, "ACL")); try { List<ObjectData> appliedPolicies = session.getBinding().getPolicyService() .getAppliedPolicies(session.getRepositoryInfo().getId(), object.getId(), "*", null);
addResult(results, assertEquals(expected.getId(), actual.getId(), null, f)); addResult(results, assertEquals(expected.getBaseTypeId(), actual.getBaseTypeId(), null, f)); addResult(results, assertEquals(expected.getType().getId(), actual.getType().getId(), null, f));
if (expected.getProperties().size() != actual.getProperties().size()) { f = createResult(FAILURE, "Number of properties don't match"); addResult(results, assertEquals(expected.getProperties().size(), actual.getProperties().size(), null, f)); } else { for (Property<?> expectedProperty : expected.getProperties()) { Property<?> actualProperty = actual.getProperty(expectedProperty.getId()); addResult(results, assertEquals(expected.getAllowableActions(), actual.getAllowableActions(), null, f)); addResult(results, assertEquals(expected.getAcl(), actual.getAcl(), null, f)); addResult(results, assertEqualObjectList(expected.getPolicies(), actual.getPolicies(), null, f)); addResult(results, assertEqualObjectList(expected.getRelationships(), actual.getRelationships(), null, f)); addResult(results, assertEqualRenditionLists(expected.getRenditions(), actual.getRenditions(), null, f));
addResult(results, createResult(FAILURE, "Folder contains a null child!")); } else { String[] propertiesToCheck = new String[child.getType().getPropertyDefinitions().size()]; for (String propId : child.getType().getPropertyDefinitions().keySet()) { propertiesToCheck[i++] = propId; addResult(results, checkObject(session, child, propertiesToCheck, "Child check: " + child.getId())); addResult(results, checkVersionHistory(session, child, propertiesToCheck, "Child version history check: " + child.getId())); "Child is not fileable! ID: " + child.getId() + " / Type: " + child.getType().getId()); addResult(results, assertIsTrue(child instanceof FileableCmisObject, null, f)); f = createResult(FAILURE, "Child has no parents! ID: " + child.getId()); addResult(results, assertListNotEmpty(parents, null, f)); "Child is a folder and has more than one parent! ID: " + child.getId()); addResult(results, assertIsFalse(parents.size() > 1, null, f)); createResult(FAILURE, "getFolderParent() returns null for a non-root folder object! ID: " + child.getId())); } else { f = createResult(FAILURE, "getFolderParent() returns wrong parent object! ID: " + child.getId()); addResult(results, assertEquals(folder.getId(), folderParent.getId(), null, f)); f = createResult(FAILURE,
if (o.getName() == null || o.getName().length() == 0) { addResult(createResult( FAILURE, "Documents without name should not be returned by this query! Document ID: " + o.getId())); } else { f = createResult(FAILURE, "Document name should start with '" + c + "' but the name is '" + o.getName() + "'."); addResult(assertEquals(c, Character.toLowerCase(o.getName().charAt(0)), null, f)); if (o.getCreationDate() == null) { addResult(createResult(FAILURE, "Found document without creation date! Document ID: " + o.getId())); } else { f = createResult(FAILURE, "Query results should be ordered by cmis:creationDate but they are not!"); addResult(assertIsTrue(timestamp <= o.getCreationDate().getTimeInMillis(), null, f)); timestamp = o.getCreationDate().getTimeInMillis(); if (o.getName() == null || o.getName().length() == 0) { addResult(createResult(FAILURE, "Folder without name should not be returned by this query! Folder ID: " + o.getId())); } else { f = createResult(FAILURE, "Folder name should start with '" + c + "' but the name is '" + o.getName() + "'."); addResult(assertEquals(c, Character.toLowerCase(o.getName().charAt(0)), null, f)); if (o.getCreationDate() == null) {
/** * Deletes an object and checks if it is deleted. */ protected void deleteObject(CmisObject object) { if (object != null) { if (object instanceof Folder) { try { ((Folder) object).deleteTree(true, null, true); } catch (CmisBaseException e) { addResult(createResult(UNEXPECTED_EXCEPTION, "Folder could not be deleted! Exception: " + e.getMessage(), e, true)); } } else { try { object.delete(true); } catch (CmisBaseException e) { addResult(createResult(UNEXPECTED_EXCEPTION, "Object could not be deleted! Exception: " + e.getMessage(), e, true)); } } CmisTestResult f = createResult(FAILURE, "Object should not exist anymore but it is still there! ID: " + object.getId(), true); addResult(assertIsFalse(exists(object), null, f)); } }
// For how to get a Session see: // http://chemistry.apache.org/java/opencmis-client-api.html#sessions Session session = getSession(); CmisObject object = session.getObjectByPath("/path/to/object"); ObjectType type = object.getType(); Boolean isVersionable = type instanceOf DocumentType && ((DocumentType)type).isVersionable();
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())); } } }
Map<String, PropertyDefinition<?>> propDefs = cmisObject.getBaseType().getPropertyDefinitions(); cmisObject.updateProperties(updateProperties); before = object.getName(); after = renamed.get(key).getLocalName(); if (after.equals(before)) continue;
@Override public ObjectId createDocumentFromSource(ObjectId source, Map<String, ?> properties, ObjectId folderId, VersioningState versioningState, List<Policy> policies, List<Ace> addAces, List<Ace> removeAces) { if (source == null || source.getId() == null) { throw new IllegalArgumentException("Source must be set!"); } // get the type of the source document ObjectType type = null; List<SecondaryType> secondaryTypes = null; if (source instanceof CmisObject) { type = ((CmisObject) source).getType(); secondaryTypes = ((CmisObject) source).getSecondaryTypes(); } else { CmisObject sourceObj = getObject(source); type = sourceObj.getType(); secondaryTypes = sourceObj.getSecondaryTypes(); } if (type.getBaseTypeId() != BaseTypeId.CMIS_DOCUMENT) { throw new IllegalArgumentException("Source object must be a document!"); } String newId = getBinding().getObjectService().createDocumentFromSource(getRepositoryId(), source.getId(), objectFactory.convertProperties(properties, type, secondaryTypes, CREATE_AND_CHECKOUT_UPDATABILITY), (folderId == null ? null : folderId.getId()), versioningState, objectFactory.convertPolicies(policies), objectFactory.convertAces(addAces), objectFactory.convertAces(removeAces), null); if (newId == null) { return null; } return createObjectId(newId); }
if (co instanceof Document) { hasAnyDocuments = true; String name = co.getName(); boolean popup = false; Map<String, Object> map = new HashMap<String, Object>(); map.put(PropertyIds.NAME, name); co.updateProperties(map, true); } else if (name.contains("__POPUP_ALWAYS__")) { popup = true;
/** * look for a child folder of the parent folder, if not found, create it and return it. */ private static Folder getOrCreateFolder(final Folder parentFolder, final String folderName) throws IOException { Folder childFolder = null; // get existing if any ItemIterable<CmisObject> children = parentFolder.getChildren(); if (children.iterator().hasNext()) { for (CmisObject cmisObject : children) { if (cmisObject instanceof Folder && cmisObject.getName().equals(folderName)) { log.debug("Found '{}' folder.", folderName); return childFolder = (Folder)cmisObject; } } } // Create new folder (requires at least type id and name of the folder) log.debug("'{}' folder not found, about to create...", folderName); Map<String, String> folderProps = new HashMap<String, String>(); folderProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder"); folderProps.put(PropertyIds.NAME, folderName); childFolder = parentFolder.createFolder(folderProps); log.info("'{}' folder created!", folderName); return childFolder; }
/** * Utility method for renaming CMIS object * @param object CMIS object to rename * @param name new name */ private void rename(CmisObject object, String name){ Map<String, Object> newName = new HashMap<String, Object>(); newName.put("cmis:name", name); object.updateProperties(newName); }