Creating new repository using RepositoryManage!

ReemReem Member Posts: 20 Contributor I
edited November 2018 in Help
Hi,

To create new Repository I used the following way:
        
RepositoryAccessor repositoryAccessor = new RepositoryAccessorImplementation();
RepositoryManager repositoryManager = RepositoryManager.getInstance(repositoryAccessor);
File root = new File("Files/");
        if (!(new File("Files/Repository").exists())){
            System.out.println("*************************");
            LocalRepository localRepository = new LocalRepository("Repository", root);
            repositoryManager.addRepository(localRepository);
            File[] files = root.listFiles();
            for (File file : files){
                copyFile(file, new File("Files/Repository/"+file.getName()));//copy files from directory to another
            }
        }
        repositoryManager.save();
If I run the program twice and display the repositories, I got:

First run

Before creation:
[email protected]
[email protected]
LocalRepository
*************************
After creation:
[email protected]
[email protected]
LocalRepository
Repository
Second run (immediately after the first run)

Before creation:
[email protected]
[email protected]
LocalRepository
Repository
*************************
After creation:
[email protected]
[email protected]
LocalRepository
Repository
Repository
Even if the folder of repository exists, it keep creating the the repository and ignoring the condition,
So, I checked the path where the repository should exist, and I found NO folder called "Repository" after creating the repository. However, the strange thing is I got the new repository in the list returned by getRepositories() method! (shown in the output above)

If I restart Netbeans and RapidMiner, I found the new repositories exist in RapidMiner studio but not in my file system!!!

My question is: how can I save the changes of creating repository (or even delete repository) without closing Netbeans and RapidMiner?
I tried to use save() and load() mothods as they load and save xml configuration files, but it didn't make sense!
Tagged:

Answers

  • Marco_BoeckMarco_Boeck Team Lead Software Engineering Moderator, Employee, Member, University Professor Posts: 1,806   RM Engineering
    Hi,

    the existance of a repository is stored in the repositories.xml file in the user_home/.RapidMiner folder. Note that repositories only create folders when needed, e.g. after creating a new repository it is empty, thus needing no actual folders yet. I'd change the condition to asking the RepositoryManager directly if a repository with a given name already exists before creating one. Callling RepositoryManager.getInstance().shutdown() ensures your newly created repository is stored in the aforementioned xml file and exists the next time you start your program.

    Regards,
    Marco
  • ReemReem Member Posts: 20 Contributor I
    This is clear, thanks!

    Is there any way to get the absolute path of an exist repository?
    I tried to use the following:

    String path1 = repositoryManager.getRepository("Repository").getLocation().getAbsoluteLocation();
    String path2 = repositoryManager.getRepository("Repository").getLocation().toString();
    but it gave me:

    //Repository
  • Marco_BoeckMarco_Boeck Team Lead Software Engineering Moderator, Employee, Member, University Professor Posts: 1,806   RM Engineering
    Hi,

    you can check which Repository is of the type LocalRepository and then call getFile() on the LocalRepository instance.

    Regards,
    Marco
  • ReemReem Member Posts: 20 Contributor I
    Hi,

    I used this answer to integrate RapidMiner from FAQ:

    1) Question: I want to integrate RapidMiner into my application! What do I have to do?
    Answer: You need to either add the RapidMiner project as a library to your java project, or the RapidMiner library .jar files. RapidMiner sourcecode can be accessed via GIT here. For further sources (e.g. some extensions), check out our Scoureforge page here!
    I included all RapidMiner jar files into my application. however, the application still not running on a computer that doesn't have RapidMiner studio already installed!

    There are many errors appeared for me like:

    Exception in thread "main" com.rapidminer.repository.RepositoryException: Requested repository Local Repository does not exist.
        at com.rapidminer.repository.RepositoryManager.getRepository(RepositoryManager.java:202)
        at RapidMinerClassifier.RapidMinerTopicClassifier.<init>(RapidMinerTopicClassifier.java:47)
        at RapidMinerClassifier.RapidMinerTopicClassifier.main(RapidMinerTopicClassifier.java:138)
    However, I am creating the repository before setting up the process and run it as follows:

            RepositoryAccessor repositoryAccessor = null;
            RepositoryManager repositoryManager = RepositoryManager.getInstance(repositoryAccessor);
            if (repositoryManager.getRepository("Local Repository") != null) {
                String sourcePath = new File("Files/").getPath();
                LocalRepository localRepository = (LocalRepository) repositoryManager.getRepository("Local Repository");
                ManageFiles.copyFolderContent(sourcePath, repositoryPath);
                RepositoryManager.getInstance(repositoryAccessor).shutdown();
            }
    So, how can I guarantee that the repository is created in order to copy the processes (built using RapidMiner GUI) to it?

    Note: the same code is working in a computer that has RapidMiner already installed on it and the repository is created from RapidMiner GUI.

    Sorry for the asking a lot, but there is no detiled documentation to help.

    Thanks!
  • Marco_BoeckMarco_Boeck Team Lead Software Engineering Moderator, Employee, Member, University Professor Posts: 1,806   RM Engineering
    Hi,

    when you debug your code, are you actually entering the if block which requires a "Local Repository" to exist? I suspect not, so you need to first check if it exists, if it does not create it and only after that copy your files.

    Regards,
    Marco
Sign In or Register to comment.