Esempio n. 1
0
  public void doStartupAction(
      final GraphicManager gm,
      final long projectId,
      final String[] projectUrls,
      final boolean welcome,
      boolean readOnly,
      final Map<String, String> args) {
    this.args = args;
    log.debug("Start up action: " + projectId);
    if (Environment.isClientSide() && !Environment.isTesting()) {
      log.debug("Start up action: A");
      if (projectId > 0) {
        log.debug("Start up action: B");

        Boolean writable = null;
        if (readOnly) writable = Boolean.FALSE;
        else writable = verifyOpenWritable(projectId);
        if (writable == null) return;
        AssignmentService.getInstance().setSubstituting(args.get("oldResourceId") != null);
        log.info("Load document: " + projectUrls);
        gm.loadDocument(
            projectId,
            true,
            !writable,
            new Closure() {
              public void execute(Object arg0) {
                log.debug("Start up action: D");
                Project project = (Project) arg0;
                DocumentFrame frame = gm.getCurrentFrame();
                if (frame != null && frame.getProject().getUniqueId() != projectId) {
                  log.debug("Start up action: E");

                  gm.switchToProject(projectId);
                }
                log.debug("Start up action: F");
                if (args.get("oldResourceId") != null) { // see if need to substitute
                  // JGao 6/3/2009 Need to set initial ids to make sure before doing resource
                  // substitution
                  if (project.getInitialTaskIds() == null) project.setInitialIds();
                  final long oldResourceId = Long.parseLong(args.get("oldResourceId"));
                  final long newResourceId = Long.parseLong(args.get("newResourceId"));
                  final Date startingFrom = DateTime.parseZulu(args.get("startingFrom"));
                  final int[] taskIds =
                      StringList.parseAsIntArray(args.get("commaSeparatedTaskIds"));
                  AssignmentService.getInstance()
                      .replaceResource(
                          projectId, oldResourceId, newResourceId, startingFrom, taskIds);
                  if (GraphicManager.getInstance() != null)
                    GraphicManager.getInstance().setEnabledDocumentMenuActions(true);
                  args.put("oldResourceId", null); // avoid doing again
                  AssignmentService.getInstance().setSubstituting(false);
                  log.debug("Start up action: G");
                }
              }
            });
      } else if (projectUrls != null && projectUrls.length > 0) {
        log.info("Load document: " + projectUrls[0]);
        gm.loadLocalDocument(projectUrls[0], !Environment.getStandAlone(), true);
      }
    }
    if (serverUrl != null) {
      if (opts.get("auth") != null) {
        String username = (String) ((LinkedList) opts.get("auth")).get(1);
        String password = (String) ((LinkedList) opts.get("auth")).get(2);
        TracImporter importer = new TracImporter(serverUrl, username, password);
        String msg = importer.checkConnection();
        if (msg != null) {}

        try {
          importer.importByQuery("status!=close");
        } catch (XmlRpcException e) {
          e.printStackTrace();
        }
        Project project = importer.getProject();
        String HTTP_PREFIX = "http://";

        project.setFileName(
            HTTP_PREFIX
                + username
                + ":"
                + password
                + "@"
                + serverUrl.substring(HTTP_PREFIX.length()));

        project.initialize(false, false);
        project.setBoundsAfterReadProject();

        Environment.setImporting(false);
        project.setWasImported(true);

        final Session session = SessionFactory.getInstance().getSession(true);
        session.refreshMetadata(project);
        session.readCurrencyData(project);
        return;

      } else {
        SwingUtilities.invokeLater(
            new Runnable() {
              public void run() {
                if (Environment.isOpenProj() && !Environment.isPlugin()) {
                  //							LicenseDialog.showDialog(gm.getFrame(),false);
                  UserInfoDialog.showDialog(gm.getFrame(), false);
                  //							TryPODDialog.maybeShow(gm.getFrame(),false);
                  //							UpdateChecker.checkForUpdateInBackground();
                }
                if (welcome && !Environment.isPlugin()) {
                  if (Environment.isOpenProj()) {
                    // LicenseDialog.showDialog(gm.getFrame(),false);
                    // TipOfTheDay.showDialog(gm.getFrame(), false);
                  } else {
                    if (Environment.isNeedToRestart()) return;
                    if (!LafManagerImpl
                        .isLafOk()) // for startup glitch - we don't want people to work until
                                    // restarting.
                    return;

                    //
                    //								String lastVersion =
                    // Preferences.userNodeForPackage(StartupFactory.class).get("lastVersion","0");
                    //								String thisVersion = VersionUtils.getVersion();
                    //								System.out.println("last version " + lastVersion + " this version " +
                    // thisVersion);
                    //								if (!lastVersion.equals(thisVersion)) {
                    //
                    //	Preferences.userNodeForPackage(StartupFactory.class).put("lastVersion",thisVersion);
                    //									String javaVersion = System.getProperty("java.version");
                    //									if (javaVersion.equals("1.6.0_04") || javaVersion.equals("1.6.0_05"))
                    //										Alert.warn("Project-ON-Demand has been updated.  Please close your
                    // browser completely and restart it to complete the upgrade process.");
                    //									return;
                    //								}

                  }
                  gm.doWelcomeDialog();
                }
                if (Environment.isPlugin()) gm.doNewProjectNoDialog(opts);
              }
            });
      }
    }
  }