1

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...

Monali
  • 270
  • 1
  • 5
  • 16
Deepak Talape
  • 997
  • 1
  • 9
  • 35
  • 2
    is it in the same server i mean it is only moving content from repository to an other – Yagami Light Apr 10 '17 at 09:32
  • @Yagami Light No, Servers are Different – Deepak Talape Apr 10 '17 at 09:42
  • 1
    I can give an answer about it (using CMIS) but i am sure you can find a better answer are you interested ?!? (it is like download and reupload this files included folder) – Yagami Light Apr 10 '17 at 09:56
  • @YagamiLight please provide your answer if possible, actually i don't want existing folder structure. I just want all the contents with its metadata. And in my new repository different logic is there for creating internal folder structure. so i just want to send these contents in one particular place of new repository – Deepak Talape Apr 10 '17 at 09:59
  • 1
    The point is yes i can provide a solution but you will lost a lot of informations example let say you have Server A and Server B you want to move a folder X from A to B, with my method you will lost the real date of creation that you had in your server A actually it will be to day do you understand my problem ?!? – Yagami Light Apr 10 '17 at 10:02
  • @YagamiLight That thing is ok with me, If creation Date changed then also no problem. In my Scenario my previous repo content are there in the file system, and i want to migrate it to S3 Bucket of amazon cloud. The requirement is i just want to validate it in between. – Deepak Talape Apr 10 '17 at 10:42
  • Can anyone please help me, i am a bit new in alfresco. And its really on high priority. – Deepak Talape Apr 10 '17 at 12:45
  • @YagamiLight Can you please provide your solution, as no one is replying for the question. so i will go with your solution. Thanks in Advance.... – Deepak Talape Apr 10 '17 at 13:24
  • did you try something with CMIS like getting session (i will provide a solution don't worry ) – Yagami Light Apr 10 '17 at 13:41
  • @YagamiLight Yes, i used CMIS for basic functionalities like uploading documents and versioning etc. – Deepak Talape Apr 10 '17 at 13:48
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/141377/discussion-between-yagami-light-and-deepak-talape). – Yagami Light Apr 10 '17 at 16:57
  • @YagamiLight while migration i also want to get all aspects and its properties in CMIS. is it possible? as i am not able to find any usefull code for this, can you please help.. – Deepak Talape Apr 21 '17 at 07:24
  • @YagamiLight Can you please help me to fetch aspect and its properties from old repository. I also created new question. but not getting any help. – Deepak Talape Apr 21 '17 at 09:08
  • Sorry for the late comment (i was seek) i will see your question – Yagami Light Apr 21 '17 at 09:20
  • @YagamiLight Thanks, please Take care.. – Deepak Talape Apr 21 '17 at 09:39

1 Answers1

1

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.

Community
  • 1
  • 1
Yagami Light
  • 1,756
  • 4
  • 19
  • 39
  • please understand that we will work step by step – Yagami Light Apr 10 '17 at 14:05
  • Try it with a file that you know exactly the path – Yagami Light Apr 10 '17 at 14:06
  • Guys i have edited my question, and please don't provide negative voting for the solution. Its helpful for me.. Thanks........... – Deepak Talape Apr 10 '17 at 14:31
  • Don't worry we will continue in the chat (it's 15:34 i will be available for working with you in 17:30) i hope to find you – Yagami Light Apr 10 '17 at 14:35
  • Can you please provide the further steps that i can follow next?? – Deepak Talape Apr 10 '17 at 15:38
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/141394/discussion-between-deepak-talape-and-yagami-light). – Deepak Talape Apr 11 '17 at 03:14
  • Does it work ( does it transfert file from A to B ) – Yagami Light Apr 11 '17 at 06:21
  • Its working, Thanks.. But Do you think InputStream will not cause any data lose, means if i will execute it on production and some network issue will occurred. then can we trace where is it failde? – Deepak Talape Apr 13 '17 at 12:31
  • why not check if any files proprieties are lost with a lot of system.out... , please look to my post [File proprity](http://stackoverflow.com/questions/39363131/how-to-update-document-properties-using-cmis/39363368#39363368) it's your own question please make it as an answer (and why not upvoting my answers ;) ) – Yagami Light Apr 13 '17 at 12:46
  • we can optimize the solution if you want to make it automatic are you interested ?!? – Yagami Light Apr 13 '17 at 14:13
  • Yes, i am intrested – Deepak Talape Apr 13 '17 at 14:26
  • Thank you so much. Your solution is working fine for migrating single document in between 2 repository's. Now i have to traverse all repository content excluding folders. can you please update the answer if possible. – Deepak Talape Apr 16 '17 at 14:23
  • I am sorry for forgeting updating my answer i will this afternoon, Can you please post an other question of how retrieving all document content i will answer it – Yagami Light Apr 16 '17 at 14:39
  • Why an other question because it's something that can be usufull for other and it's something different from your actual question – Yagami Light Apr 16 '17 at 14:48
  • I have created different question. Can you please answer for the question. Thanks.......... – Deepak Talape Apr 17 '17 at 10:31
  • when we are creating new document in new repository i also want to apply one aspect to that document and have to apply some properties to it. so can you please modify the answer a bit if possible. – Deepak Talape Apr 19 '17 at 15:55