public void findLocationForInstance(ArchDescriptionInstances newInstance) {
   if (newInstance instanceof ArchDescriptionAnalogInstances) {
     final Resources parentResource = (Resources) editorField.getModel();
     final ArchDescriptionAnalogInstances analogInstance =
         (ArchDescriptionAnalogInstances) newInstance;
     Thread performer =
         new Thread(
             new Runnable() {
               public void run() {
                 InfiniteProgressPanel monitor =
                     ATProgressUtil.createModalProgressMonitor(
                         ApplicationFrame.getInstance(), 1000);
                 monitor.start("Gathering Containers...");
                 try {
                   analogInstance.setLocation(
                       parentResource.findLocationForContainer(
                           analogInstance.getTopLevelLabel(), monitor));
                 } finally {
                   monitor.close();
                 }
               }
             },
             "Performer");
     performer.start();
   }
 }
Example #2
0
  /** Method to start the a thread that actually copied ASpace records */
  private void startASpaceCopyProcess(final XSSFWorkbook workBook) {
    Thread performer =
        new Thread(
            new Runnable() {
              public void run() {
                // first disable/enable the relevant buttons
                copyToASpaceButton.setEnabled(false);
                // errorLogButton.setEnabled(false);
                stopButton.setEnabled(true);

                // clear text area and show progress bar
                consoleTextArea.setText("");
                copyProgressBar.setStringPainted(true);
                copyProgressBar.setString("Copying Records ...");
                copyProgressBar.setIndeterminate(true);

                try {
                  // print the connection message
                  consoleTextArea.append("Excel File Opened ...\n");

                  String host = hostTextField.getText().trim();
                  String admin = adminTextField.getText();
                  String adminPassword = adminPasswordTextField.getText();

                  boolean simulateRESTCalls = simulateCheckBox.isSelected();
                  boolean developerMode = developerModeCheckBox.isSelected();

                  ascopy = new ASpaceCopy(host, admin, adminPassword);

                  ascopy.setPreProcessing(supportsPreProcessing);

                  ascopy.setMapperScriptType(getMapperScriptType());

                  if (mapperScript.isEmpty()) {
                    ascopy.setMapperScript(defaultMapperScript);
                    indicateSupportedRecords(defaultMapperScript);
                    mapperScriptTextField.setText("Default mapper script loaded ...");
                  } else {
                    ascopy.setMapperScript(mapperScript);
                  }

                  ascopy.setWorkbook(workBook);

                  ascopy.setSimulateRESTCalls(simulateRESTCalls);
                  ascopy.setDeveloperMode(developerMode);

                  // set the reset password, and output console and progress bar
                  ascopy.setOutputConsole(consoleTextArea);
                  ascopy.setProgressIndicators(copyProgressBar, errorCountLabel);
                  ascopy.setCopying(true);

                  // try getting the session and only continue if a valid session is return;
                  if (!simulateRESTCalls && !ascopy.getSession()) {
                    consoleTextArea.append(
                        "\nNo Archives Space backend session, nothing to do ...\n");
                    reEnableCopyButtons();
                    return;
                  } else {
                    consoleTextArea.append("\nAdministrator authenticated ...\n");
                  }

                  boolean globalRecordsExists = false;
                  if (developerMode && ascopy.uriMapFileExist()) {
                    globalRecordsExists = ascopy.loadURIMaps();
                  }

                  // load the subjects and agent location records
                  // that are already in the ASpace backend if they haven't been
                  // loaded locally
                  if (!globalRecordsExists) {
                    globalRecordsExists = ascopy.loadGlobalRecords();
                  }

                  // set the progress bar from doing it's thing since the ascopy class is going to
                  // take over
                  copyProgressBar.setIndeterminate(false);

                  // see whether to create a repository record or use the one entered by user
                  String repositoryURI = repositoryURITextField.getText();

                  if (supportsRepository) {
                    repositoryURI = ascopy.createRepository();
                    repositoryURITextField.setText(repositoryURI);
                  } else if (createRepositoryCheckBox.isSelected()) {
                    JSONObject repository = createRepositoryRecord();
                    repositoryURI = ascopy.copyRepositoryRecord(repository);
                    repositoryURITextField.setText(repositoryURI);
                  }

                  if (repositoryURI.isEmpty()) {
                    consoleTextArea.append("No target repository, unable to copy ...\n");
                    reEnableCopyButtons();
                    return;
                  } else {
                    ascopy.setRepositoryURI(repositoryURI);
                  }

                  int locationsSheet = Integer.parseInt(locationsTextField.getText()) - 1;
                  int subjectsSheet = Integer.parseInt(subjectsTextField.getText()) - 1;
                  int namesSheet = Integer.parseInt(namesTextField.getText()) - 1;
                  int accessionSheet = Integer.parseInt(accessionsTextField.getText()) - 1;
                  int digitalObjectSheet = Integer.parseInt(digitalObjectsTextField.getText()) - 1;

                  // now check if we in developer mode, in which case we not going to save
                  // the locations, subjects, names records since they should already be in the
                  // database
                  if (!developerMode || !globalRecordsExists) {
                    if (!copyStopped && locationsSheet >= 0 && supportsLocations)
                      ascopy.copyLocationRecords(locationsSheet);
                    if (!copyStopped && subjectsSheet >= 0 && supportsSubjects)
                      ascopy.copySubjectRecords(subjectsSheet);
                    if (!copyStopped && namesSheet >= 0 && supportsNames)
                      ascopy.copyNameRecords(namesSheet);
                  }

                  if (!copyStopped && accessionSheet >= 0 && supportsAccessions)
                    ascopy.copyAccessionRecords(accessionSheet);

                  if (!copyStopped && digitalObjectSheet >= 0 && supportsDigitalObjects)
                    ascopy.copyDigitalObjectRecords(digitalObjectSheet);

                  // save the record maps for possible future use
                  ascopy.saveURIMaps();

                  String resourcesSheets = resourcesTextField.getText().trim();
                  if (!copyStopped && !resourcesSheets.isEmpty() && supportsResources) {
                    ascopy.copyResourceRecords(resourcesSheets);
                  }

                  ascopy.cleanUp();

                  // set the number of errors and message now
                  String errorCount = "" + ascopy.getSaveErrorCount();
                  errorCountLabel.setText(errorCount);
                  migrationErrors =
                      ascopy.getSaveErrorMessages() + "\n\nTotal errors: " + errorCount;
                } catch (Exception e) {
                  consoleTextArea.setText("Unrecoverable exception, migration stopped ...\n\n");
                  consoleTextArea.append(ascopy.getCurrentRecordInfo() + "\n\n");
                  consoleTextArea.append(getStackTrace(e));
                  // e.printStackTrace();
                }

                reEnableCopyButtons();
              }
            });

    performer.start();
  }