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

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


        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

    public String createFolder(CallContext context, String repositoryId, Properties properties, String folderId,
            List<String> policies, Acl addAces, Acl removeAces, ExtensionsData extension) {
        LOG.debug("start createFolder()");

        Folder folder = createFolderIntern(context, repositoryId, properties, folderId, policies, addAces, removeAces,
                extension);
        LOG.debug("stop createFolder()");
        return folder.getId();
    }
View Full Code Here

            String targetFolderId, String sourceFolderId, ExtensionsData extension, ObjectInfoHandler objectInfos) {

        LOG.debug("start moveObject()");
        StoredObject[] sos = validator.moveObject(context, repositoryId, objectId, targetFolderId, sourceFolderId, extension);
        StoredObject so = sos[0];
        Folder targetFolder = null;
        Folder sourceFolder = null;
        ObjectStore objectStore = fStoreManager.getObjectStore(repositoryId);
        Filing spo = null;

        if (null == so)
            throw new CmisObjectNotFoundException("Unknown object: " + objectId.getValue());
View Full Code Here

        // Validation stuff
        TypeValidator.validateRequiredSystemProperties(properties);
        TypeDefinition typeDef = getTypeDefinition(repositoryId, properties);

        Folder folder = null;
        if (null != folderId) {
            StoredObject so = objectStore.getObjectById(folderId);

            if (null == so)
                throw new CmisInvalidArgumentException(" Cannot create document, folderId: " + folderId + " is invalid");

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

            TypeValidator.validateAllowedChildObjectTypes(typeDef, folder.getAllowedChildObjectTypeIds());
        }

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

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

        TypeValidator.validateVersionStateForCreate((DocumentTypeDefinition) typeDef, versioningState);

        // set properties that are not set but have a default:
        Map<String, PropertyData<?>> propMapNew = setDefaultProperties(typeDef, propMap);
        if (propMapNew != propMap) {
            properties = new PropertiesImpl(propMapNew.values());
            propMap = propMapNew;
        }

        TypeValidator.validateProperties(typeDef, properties, true);

        // set user, creation date, etc.
        if (user == null)
            user = "unknown";

        StoredObject so = null;

        // check if content stream parameters are set and if not set some defaults
        if (null != contentStream && (contentStream.getFileName() == null || contentStream.getFileName().length() == 0 ||
            contentStream.getMimeType() == null || contentStream.getMimeType().length() == 0)) {
            ContentStreamImpl cs = new ContentStreamImpl();
            cs.setStream(contentStream.getStream());
            if (contentStream.getFileName() == null || contentStream.getFileName().length() == 0)
                cs.setFileName(name);
            else
                cs.setFileName(contentStream.getFileName());
            cs.setLength(contentStream.getBigLength());
            if (contentStream.getMimeType() == null || contentStream.getMimeType().length() == 0)
                cs.setMimeType("application/octet-stream");
            else
                cs.setMimeType(contentStream.getMimeType());
            cs.setExtensions(contentStream.getExtensions());
            contentStream = cs;
        }

        // Now we are sure to have document type definition:
        if (((DocumentTypeDefinition) typeDef).isVersionable()) {
            VersionedDocument verDoc = fStoreManager.getObjectStore(repositoryId).createVersionedDocument(name);
            verDoc.createSystemBasePropertiesWhenCreated(properties.getProperties(), user);
            verDoc.setCustomProperties(properties.getProperties());
            DocumentVersion version = verDoc.addVersion(contentStream, versioningState, user);
            if (null != folder)
                folder.addChildDocument(verDoc); // add document to folder and
            // set parent in doc
            else
                verDoc.persist();
            version.createSystemBasePropertiesWhenCreated(propMap, user);
            version.setCustomProperties(propMap);
            version.persist();
            so = version; // return the version and not the version series to
            // caller
        } else {
            Document doc = fStoreManager.getObjectStore(repositoryId).createDocument(name);
            doc.setContent(contentStream, false);
            // add document to folder
            doc.createSystemBasePropertiesWhenCreated(propMap, user);
            doc.setCustomProperties(propMap);
            if (null != folder)
                folder.addChildDocument(doc); // add document to folder and set
            // parent in doc
            else
                doc.persist();
            so = doc;
        }
View Full Code Here

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

        StringBuffer path = new StringBuffer(getName());
        if (null == getParent())
            path.replace(0, path.length(), PATH_SEPARATOR); // root folder-->
        // set /
        else {
            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

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.