Package org.apache.chemistry.opencmis.inmemory.storedobj.api

Examples of org.apache.chemistry.opencmis.inmemory.storedobj.api.Folder


        String user = context.getUsername();
        validator.createFolder(context, repositoryId, folderId, extension);

        ObjectStore fs = fStoreManager.getObjectStore(repositoryId);
        StoredObject so = null;
        Folder parent = null;

        // get required properties
        PropertyData<?> pd = properties.getProperties().get(PropertyIds.NAME);
        String folderName = (String) pd.getFirstValue();
        if (null == folderName || folderName.length() == 0) {
            throw new CmisInvalidArgumentException("Cannot create a folder without a name.");
        }

        // check name syntax
        if (!NameValidator.isValidId(folderName)) {
            throw new CmisInvalidArgumentException(NameValidator.ERROR_ILLEGAL_NAME);
        }

        TypeValidator.validateRequiredSystemProperties(properties);

        TypeDefinition typeDef = getTypeDefinition(repositoryId, properties);

        // check if the given type is a folder type
        if (!typeDef.getBaseTypeId().equals(BaseTypeId.CMIS_FOLDER)) {
            throw new CmisInvalidArgumentException("Cannot create a folder, with a non-folder type: " + typeDef.getId());
        }

        Map<String, PropertyData<?>> propMap = properties.getProperties();
        Map<String, PropertyData<?>> propMapNew = setDefaultProperties(typeDef, propMap);
        if (propMapNew != propMap) {
            properties = new PropertiesImpl(propMapNew.values());
        }

        TypeValidator.validateProperties(typeDef, properties, true);

        // create folder
        try {
            LOG.debug("get folder for id: " + folderId);
            so = fs.getObjectById(folderId);
        } catch (Exception e) {
            throw new CmisObjectNotFoundException("Failed to retrieve folder.", e);
        }

        if (so instanceof Folder) {
            parent = (Folder) so;
        } else {
            throw new CmisInvalidArgumentException("Can't create folder, folderId does not refer to a folder: "
                    + folderId);
        }

        ObjectStore objStore = fStoreManager.getObjectStore(repositoryId);
        Folder newFolder = objStore.createFolder(folderName);
        // set default system attributes
        if (user == null) {
            user = "unknown";
        }
        newFolder.createSystemBasePropertiesWhenCreated(properties.getProperties(), user);
        newFolder.setCustomProperties(properties.getProperties());
        parent.addChildFolder(newFolder);
        LOG.debug("stop createFolder()");
        newFolder.persist();
        return newFolder;
    }
View Full Code Here


    }

    @Test
    public void testCreatAndGetFolders() {
        try {
            Folder childFolder = fStore.createFolder("Folder 1");
            fRoot.addChildFolder(childFolder);
            fail("Should throw exception if folder already exists.");
        } catch (Exception e) {
        }
        assertEquals(f1.getName(), "Folder 1");
View Full Code Here

    }

    @Test
    public void testMoveFolder() {
        String oldPath = f1.getPath();
        Folder f1Parent = f1.getParent();
        f1.move(f1Parent, f3);
        assertNull(fStore.getObjectByPath(oldPath));
        assertEquals(f1.getPath(), "/Folder 3/Folder 1");
        assertEquals(f1, fStore.getObjectByPath("/Folder 3/Folder 1"));

        f2.rename("Folder 1");
        try {
            Folder f2Parent = f2.getParent();
            f2.move(f2Parent, f3);
            fail("Should not be possible to move folder to a folder that has a child with same name");
        } catch (Exception e) {
        }
    }
View Full Code Here

        }
        StoredObject so = sos[0];
        StoredObject folder = sos[1];
        checkObjects(so, folder);

        Folder newParent = (Folder) folder;
        MultiFiling obj = (MultiFiling) so;
        obj.addParent(newParent);

        if (context.isObjectInfoRequired()) {
            ObjectInfoImpl objectInfo = new ObjectInfoImpl();
View Full Code Here

        ObjectStore objectStore = fStoreManager.getObjectStore(repositoryId);
        StoredObject folder = sos[1];

        checkObjects(so, folder);
        Folder parent = (Folder) folder;
        MultiFiling obj = (MultiFiling) so;
        obj.removeParent(parent);

        // To be able to provide all Atom links in the response we need
        // additional information:
View Full Code Here

        LOG.debug("start getFolderParent()");

        StoredObject so = validator.getFolderParent(context, repositoryId, folderId, extension);

        Folder folder = null;
        if (so instanceof Folder) {
            folder = (Folder) so;
        } else {
            throw new CmisInvalidArgumentException("Can't get folder parent, id does not refer to a folder: "
                    + folderId);
View Full Code Here

        ObjectInFolderListImpl result = new ObjectInFolderListImpl();
        List<ObjectInFolderData> folderList = new ArrayList<ObjectInFolderData>();
        ObjectStore fs = fStoreManager.getObjectStore(repositoryId);
        StoredObject so = fs.getObjectById(folderId);
        Folder folder = null;

        if (so == null) {
            throw new CmisObjectNotFoundException("Unknown object id: " + folderId);
        }

        if (so instanceof Folder) {
            folder = (Folder) so;
        }
        else {
            return null; // it is a document and has no children
        }

        List<? extends StoredObject> children = folderOnly ? folder.getFolderChildren(maxItems, skipCount) : folder
                .getChildren(maxItems, skipCount);

        List<String> requestedIds = FilterParser.getRequestedIdsFromFilter(filter);

        for (StoredObject spo : children) {
View Full Code Here

    private ObjectData getFolderParentIntern(String repositoryId, SingleFiling sop, String filter,
            ObjectInfoHandler objectInfos) {

        ObjectDataImpl parent = new ObjectDataImpl();

        Folder parentFolder = sop.getParent();

        if (null == parentFolder) {
            return null;
        }
View Full Code Here

        StringBuffer path = new StringBuffer(getName());
        if (null == getParent()) {
            path.replace(0, path.length(), PATH_SEPARATOR);
        } else {
            // root folder-->
            Folder f = getParent();
            while (f.getParent() != null) {
                path.insert(0, PATH_SEPARATOR);
                path.insert(0, f.getName());
                f = f.getParent();
            }
            path.insert(0, PATH_SEPARATOR);
        }
        // if (LOG.isDebugEnabled())
        // LOG.debug("getPath() returns: " + path.toString());
View Full Code Here

        doc.setName(name);
        return doc;
    }

    public Folder createFolder(String name) {
        Folder folder = new FolderImpl(this, name, null);
        folder.setRepositoryId(fRepositoryId);
        return folder;
    }
View Full Code Here

TOP

Related Classes of org.apache.chemistry.opencmis.inmemory.storedobj.api.Folder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.