alfrescoalfresco-sharealfresco-webscriptsopencmiscontent-repository

How to migrate content from one alfresco repository to other using Open CMIS


I want to migrate all alfresco repository contents from one repository to other. but i don't want the existing folder structure. while migrating i have to validate the content according to some business requirement, and based on content type i have to create different folder structure in new repository.

Does any one did this previously. Please help.

Thanks in Advance...


Solution

  • Ok, the solution that i give is not the best one, but i think it will work, we will start with a simple document and see if it's working (we will modifie the answer)

    Getting the inputStram of a document

    I think it's the most important part

    public InputStream getTheInputStream () {    
    Document newDocument = (Document) getSession(serverURL, userName, password).getObject(path);
    ContentStream cs = newDocument.getContentStream(null);
    return cs.getStream();
    }
    

    Moving the inputStram from Server A to Server B

    public void transfert() throws FileNotFoundException, IOException {
        Session sessionB = getSession(serverUrlB, usernameB, passwordB);
    
        ////////////////////////////  GET THE FOLDER THAT YOU WILL WORK WITH
        Folder root = sessionB.getRootFolder();
        ////////////////////////////  GET THE FOLDER THAT YOU WILL WORK WITH
        File newfile = new File(fileName);
        String nom = fileName;
        Map<String, Object> properties = new HashMap<>();
        properties.put(PropertyIds.OBJECT_TYPE_ID, BaseTypeId.CMIS_DOCUMENT.value());
        properties.put(PropertyIds.NAME, nom);
        List<Ace> addAces = new LinkedList<>();
        List<Ace> removeAces = new LinkedList<>();
        List<Policy> policies = new LinkedList<>();
        String extension = FilenameUtils.getExtension(nom);
        ContentStream contentStream = new ContentStreamImpl("content." + extension, BigInteger.valueOf(nom).length()),
                new MimetypesFileTypeMap().getContentType(newfile), (theInputStream);
        Document dc = root.createDocument(properties, contentStream, VersioningState.MAJOR, policies, addAces, removeAces, sessionB.getDefaultContext());        
    
    }
    

    Try this method and tell me if it's working, if you don't have the getSession method just look to this post get session method.