/** * 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"); } }
@Override public String getDocumentId( String path ) { // establish relation between path and object identifier return session.getObjectByPath(path).getId(); }
public void addAspect(ObjectType[] type, Map<String, ?> properties) { if (type == null || type.length == 0) { throw new IllegalArgumentException("Type must be set!"); } AlfrescoAspectsUtils.updateAspects(session, object.getId(), type, null, properties); }
public void save() { if (addAspectTypes.isEmpty() && removeAspectTypes.isEmpty()) { return; } AlfrescoAspectsUtils.updateAspects(session, object.getId(), addAspectTypes.values().toArray(new ObjectType[0]), removeAspectTypes.values().toArray(new ObjectType[0]), null); } }
public void addAspect(ObjectType... type) { if (type == null || type.length == 0) { throw new IllegalArgumentException("Type must be set!"); } AlfrescoAspectsUtils.updateAspects(session, object.getId(), type, null, null); }
public void removeAspect(ObjectType... type) { if (type == null || type.length == 0) { throw new IllegalArgumentException("Type must be set!"); } AlfrescoAspectsUtils.updateAspects(session, object.getId(), null, type, null); } }
@Override public void putPath(String path, CmisObject object, String cacheKey) { if (path == null) { return; } lock.writeLock().lock(); try { put(object, cacheKey); if ((object != null) && (object.getId() != null) && (cacheKey != null)) { pathToIdMap.put(path, new CacheItem<String>(object.getId(), pathToIdTtl)); } } finally { lock.writeLock().unlock(); } }
@Override public void putPath(String path, CmisObject object, String cacheKey) { if (path == null) { return; } lock.writeLock().lock(); try { put(object, cacheKey); if ((object != null) && (object.getId() != null) && (cacheKey != null)) { pathToIdMap.put(path, new CacheItem<String>(object.getId(), pathToIdTtl)); } } finally { lock.writeLock().unlock(); } }
for(CmisObject obj: folder.getChildren()) { System.out.println("Name: " + obj.getName()); System.out.println("Id: " + obj.getId()); System.out.println("Type: " + getType(obj.getType())); System.out.println(); }
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); pathToIdMap.put(path, new CacheItem<String>(object.getId(), pathToIdTtl));
/** * For each folder in the given folder path, creates it if necessary. Notice: this implementation checks that the folder exists, and if not creates it. This is not efficient, * it would be better to try to just try to create it and catch {@link CmisContentAlreadyExistsException}, but currently that exception is not being thrown - it seems like a * server's bug */ private CmisObject createFolderStructure(String folderPath) { String[] folderNames = StringUtils.split(folderPath, "/"); String currentObjectId = getObjectByPath("/").getId(); String currentPath = "/"; for (String folder : folderNames) { currentPath = currentPath + folder + "/"; CmisObject currentObject = null; try { currentObject = getObjectByPath(currentPath); } catch (CmisObjectNotFoundException ex) { logger.debug("Path not found: " + currentPath, ex); } currentObjectId = currentObject != null ? currentObject.getId() : createFolder(folder, currentObjectId).getId(); } return getObjectById(currentObjectId); }
/** * 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()); } }
/** * create a document */ protected ObjectId createDocument(@NotNull(value = "No folder was specified in the request.") CmisObject folder, @NotNull(value = "No filename was specified in the request.") String filename, @NotNull(value = "No document content was specified in the payload.") Object content, @NotNull(value = "No file mime type was specified in the request.") String mimeType, @NotNull(value = "No versioning state was specified in the request.") org.mule.modules.cmis.model.VersioningState versioningState, String objectType, Map<String, Object> extraProperties) { ObjectId returnId = null; Session session = this.getSession(this.connectionParameters); if (session != null) { VersioningState vs; try { vs = VersioningState.valueOf(versioningState.name()); } catch (IllegalArgumentException e) { throw new IllegalArgumentException(String.format("Illegal value for versioningState. Given `%s' could be: %s", versioningState, Arrays.toString(VersioningState.values())), e); } Map<String, Object> properties = new HashMap<String, Object>(); properties.put(PropertyIds.OBJECT_TYPE_ID, objectType); properties.put(PropertyIds.NAME, filename); if (extraProperties != null) { properties.putAll(extraProperties); } returnId = session.createDocument(properties, session.createObjectId(folder.getId()), createContentStream(filename, mimeType, content), vs); } return returnId; // End createDocument }
private void testDeepHierarchy(Session session, Folder testFolder, int depth) { String folderName = "depth"; StringBuilder path = new StringBuilder(testFolder.getPath()); for (int i = 0; i < depth; i++) { path.append('/'); path.append(folderName + i); } session.createPath(testFolder, path.toString(), getFolderTestTypeId()); for (int i = 0; i < depth; i++) { CmisObject folderObj = session.getObjectByPath(path.toString(), SELECT_ALL_NO_CACHE_OC); if (folderObj instanceof Folder) { session.deleteByPath(((Folder) folderObj).getPath()); } else { addResult(createResult(FAILURE, "Just created folder is not a folder! Id: " + folderObj.getId())); } path.delete(path.lastIndexOf("/"), path.length()); } addResult(createInfoResult("Tested the creation of a folder hierarchy with a depth of " + (depth + 1) + " below the test folder.")); } }
public ObjectId createFolder(String folderName, String parentObjectId) { ObjectId returnId = null; Session session = this.getSession(this.connectionParameters); if (session != null) { if (StringUtils.isEmpty(parentObjectId)) { parentObjectId = session.getRootFolder().getId(); } Map<String, Object> properties = new HashMap<String, Object>(); properties.put(PropertyIds.NAME, folderName); properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder"); try { returnId = session.createFolder(properties, session.getObject(session.createObjectId(parentObjectId))); } catch (CmisContentAlreadyExistsException e) { logger.debug("CMIS Content Already Exists ", e); CmisObject object = session.getObject(session.createObjectId(parentObjectId)); if (!(object instanceof Folder)) { throw new IllegalArgumentException(parentObjectId + " is not a folder"); } Folder folder = (Folder) object; for (CmisObject o : folder.getChildren()) { if (o.getName().equals(folderName)) { return session.createObjectId(o.getId()); } } } } return returnId; // End createFolder }
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())); } } }
/** * 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)); } }
writer.addChild(ObjectId.toString(ObjectId.Type.ACL, cmisObject.getId()), "mode:acl");