javarhapsody

Rhapsody API reload project


I am creating a Rhapsody JavaAPI plugin that will clean the current project files and copy in a fresh model. This is to have a fresh working copy for developers so they do not have to close rhapsody and copy in the clean models manually.

My dilemma is when i close the active project, it removes it from the rhapsody view as expected. When I try reloading the new rpy file, the view does not change nor is the model reload.

How would I go about reloading the project?

Here is my plugin (note the class call works fine. Its in the method clean that I am having issues).

public class CMMCleaner {
  private Path rootDir;
  private Path rpyFile;
  private IRPApplication rpyApp;

  public CMMCleaner(final Path rootDir, final IRPApplication rpyApp) {
    this.rootDir = rootDir;
    if (!Files.exists(rootDir)) throw new IllegalArgumentException(rootDir + " does not exist");
    this.rpyApp = rpyApp;
    this.rpyFile = Paths.get(this.rpyApp.activeProject().getCurrentDirectory()).resolve(this.rpyApp.activeProject().getFilename());
  }

  public void clean() {
    try {
       rpyApp.activeProject.close();
       Path cleanDir = this.rootDir.resolve("CMM_starting_model");
       Path oldDir = this.rootDir.resolve("CMM_model");

       Files.walk(oldDir)
         .sorted(Comparator.reverseOrder())
         .map(Path::toFile)
         .forEach(File::delete);

      Files.walk(cleanDir)
        .filter(p -> Files.isRegularFile(p))
        .forEach(cleanFile -> {
          Path path = oldDir.resolve(cleanDir.relativize(cleanFile));
          try {
            Files.createDirectories(path.getParent());
            Files.copy(cleanFile, path, StandardCopyOption.REPLACE_EXISTING);
          } catch (Exception ex) {
            ex.printStackTrace();
          }
        });
      rpyApp.openProject(this.rpyFile.toAbsolutePath().toString());
      rpyApp.insertProject(this.rpyFile.toAbsolutePath().toString());
      rpyApp.activeProject();
      rpyApp.refreshAllViews();
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
}

No Exceptions are thrown, but as stated the project does close and I can visually see the files being deleted and copied in, but nothing happens in rhapsody after that.


Solution

  • I was able to solve the problem by removing the following lines:

    rpyApp.activeProject.close(); and rpyApp.insertProject(this.rpyFile.toAbsolutePath().toString());