Search in sources :

Example 1 with WorkingDirectory

use of net.sourceforge.processdash.tool.bridge.client.WorkingDirectory in project processdash by dtuma.

the class MobileSetupWizard method doPost.

@Override
protected void doPost() throws IOException {
    // make certain the request is coming from the local computer
    DashController.checkIP(env.get("REMOTE_ADDR"));
    // check for improper operating modes
    if (Settings.isReadOnly()) {
        printRedirect("mobileError.shtm?readOnly");
        return;
    } else if (CompressedInstanceLauncher.isRunningFromCompressedData()) {
        printRedirect("mobileError.shtm?quickLaunch");
        return;
    }
    // get the URL of our bridged working directory
    ProcessDashboard dash = (ProcessDashboard) getDashboardContext();
    WorkingDirectory workingDirectory = dash.getWorkingDirectory();
    String location = workingDirectory.getDescription();
    if (!location.startsWith("http")) {
        printRedirect("mobileError.shtm?notBridged");
        return;
    }
    // check for connectivity to the PDES
    try {
        URL u = new URL(location);
        FileUtils.slurpContents(u.openStream(), true);
    } catch (IOException ioe) {
        storePdesLocation(location);
        printRedirect("mobileError.shtm?noNetwork");
        return;
    }
    // ask the PDES for a data token for our directory
    String dataToken;
    try {
        dataToken = getDataToken(location);
    } catch (IOException ioe) {
        printRedirect("mobileError.shtm?upgradePdes");
        return;
    }
    // if we received the token "-", mobile support is disabled by the PDES
    if ("-".equals(dataToken)) {
        storePdesLocation(location);
        printRedirect("mobileError.shtm?pdesMobileDisabled");
        return;
    }
    // retrieve the username we are using for our data
    String username = HttpAuthenticator.getLastUsername();
    // prepare the dashboard for use with the mobile REST APIs
    try {
        DashController.assignHierarchyNodeIDs();
    } catch (IllegalStateException ise) {
        printRedirect("mobileError.shtm?hierEditor");
        return;
    }
    dash.flushWorkingData();
    // write information to the repository, and print a success page
    DataContext ctx = getDataRepository();
    ctx.putValue("/mobile//Data_Token", StringData.create(dataToken));
    if (username != null)
        ctx.putValue("/mobile//Username", StringData.create(username));
    printRedirect("mobileSuccess.shtm");
}
Also used : WorkingDirectory(net.sourceforge.processdash.tool.bridge.client.WorkingDirectory) DataContext(net.sourceforge.processdash.data.DataContext) ProcessDashboard(net.sourceforge.processdash.ProcessDashboard) IOException(java.io.IOException) URL(java.net.URL)

Example 2 with WorkingDirectory

use of net.sourceforge.processdash.tool.bridge.client.WorkingDirectory in project processdash by dtuma.

the class TeamProjectSetupWizard method writeFilesToWbsDir.

private void writeFilesToWbsDir(Collection<? extends WriteFileTask> files, String... wbsDirLocations) throws LockFailureException, IOException {
    if (files.isEmpty())
        return;
    WorkingDirectory dir = null;
    try {
        // obtain a working directory object for this WBS directory
        dir = WorkingDirectoryFactory.getInstance().get(WorkingDirectoryFactory.PURPOSE_WBS, wbsDirLocations);
        dir.acquireProcessLock("", null);
        dir.prepare();
        acquireWriteLock(dir);
        for (WriteFileTask task : files) task.write(dir.getDirectory());
        dir.flushData();
    } finally {
        if (dir != null)
            dir.releaseLocks();
    }
}
Also used : WorkingDirectory(net.sourceforge.processdash.tool.bridge.client.WorkingDirectory)

Example 3 with WorkingDirectory

use of net.sourceforge.processdash.tool.bridge.client.WorkingDirectory in project processdash by dtuma.

the class DisplayConfig method loadConfigurationInformation.

private void loadConfigurationInformation() {
    dataDirectory = null;
    dataURL = null;
    configFile = new File(DashController.getSettingsFileName());
    WorkingDirectory workingDir = ((ProcessDashboard) getDashboardContext()).getWorkingDirectory();
    if (workingDir instanceof BridgedWorkingDirectory) {
        BridgedWorkingDirectory bwd = (BridgedWorkingDirectory) workingDir;
        dataURL = bwd.getDescription();
        dataDirectory = bwd.getTargetDirectory();
        if (dataDirectory == null)
            configFile = null;
        else
            configFile = new File(dataDirectory, configFile.getName());
    } else if (workingDir instanceof LocalWorkingDirectory) {
        LocalWorkingDirectory lwd = (LocalWorkingDirectory) workingDir;
        dataDirectory = lwd.getTargetDirectory();
    }
    DashPackage dash = TemplateLoader.getPackage(DASHBOARD_PACKAGE_ID);
    if (dash != null && StringUtils.hasValue(dash.filename)) {
        File dashJar = new File(dash.filename);
        installationDirectory = dashJar.getParentFile();
    }
    appTemplateDirectory = TemplateLoader.getApplicationTemplateDir();
    jvmInfo = System.getProperty("java.vendor") + " JRE " + System.getProperty("java.version") + "; " + System.getProperty("os.name");
}
Also used : BridgedWorkingDirectory(net.sourceforge.processdash.tool.bridge.client.BridgedWorkingDirectory) WorkingDirectory(net.sourceforge.processdash.tool.bridge.client.WorkingDirectory) LocalWorkingDirectory(net.sourceforge.processdash.tool.bridge.client.LocalWorkingDirectory) LocalWorkingDirectory(net.sourceforge.processdash.tool.bridge.client.LocalWorkingDirectory) ProcessDashboard(net.sourceforge.processdash.ProcessDashboard) BridgedWorkingDirectory(net.sourceforge.processdash.tool.bridge.client.BridgedWorkingDirectory) File(java.io.File) DashPackage(net.sourceforge.processdash.templates.DashPackage)

Example 4 with WorkingDirectory

use of net.sourceforge.processdash.tool.bridge.client.WorkingDirectory in project processdash by dtuma.

the class WBSEditor method createAndShowEditor.

public static WBSEditor createAndShowEditor(String[] locations, boolean bottomUp, boolean indivMode, String initials, boolean showTeamList, String syncURL, boolean exitOnClose, boolean forceReadOnly, String itemHref, String owner) {
    LargeFontsHelper.maybeInitialize();
    try {
        HttpAuthenticator.maybeInitialize("WBS Editor");
    } catch (Exception e) {
    }
    TamperDeterrent.init();
    String message = (showTeamList ? "Opening Team Member List..." : "Opening Work Breakdown Structure...");
    JFrame waitFrame = null;
    if (!isDumpAndExitMode()) {
        waitFrame = createWaitFrame(message);
        waitFrame.setVisible(true);
    }
    LockMessageDispatcher dispatch;
    WorkingDirectory workingDirectory;
    File dir;
    TeamProject proj;
    if (bottomUp) {
        proj = new TeamProjectBottomUp(locations, "Team Project");
        dir = proj.getStorageDirectory();
        if (!dir.isDirectory()) {
            waitFrame.dispose();
            showCannotOpenError(locations[locations.length - 1]);
            return null;
        }
        workingDirectory = null;
        dispatch = null;
    } else // if not bottom up
    {
        String intent;
        if (showTeamList)
            intent = INTENT_TEAM_EDITOR;
        else if (StringUtils.hasValue(itemHref))
            intent = INTENT_SHOW_ITEM + itemHref;
        else
            intent = INTENT_WBS_EDITOR;
        dispatch = new LockMessageDispatcher();
        workingDirectory = configureWorkingDirectory(locations, intent, dispatch);
        if (workingDirectory == null) {
            waitFrame.dispose();
            return null;
        }
        dir = workingDirectory.getDirectory();
        proj = new TeamProject(dir, "Team Project");
        if (workingDirectory instanceof CompressedWorkingDirectory) {
            if (!((CompressedWorkingDirectory) workingDirectory).getTargetZipFile().canWrite())
                forceReadOnly = true;
        }
    }
    try {
        if (!isDumpAndExitMode()) {
            UserGroupManagerWBS.init(proj);
            WBSPermissionManager.init(workingDirectory, proj);
        }
    } catch (HttpException.Unauthorized he) {
        displayStartupPermissionError("Unauthorized");
        waitFrame.dispose();
        return null;
    }
    if (indivMode && proj.getBoolUserSetting(MEMBERS_CANNOT_EDIT_SETTING))
        forceReadOnly = true;
    if (forceReadOnly)
        proj.setReadOnly(true);
    else
        owner = getOwnerName(owner, true);
    if (!indivMode)
        initials = null;
    try {
        WBSEditor w = new WBSEditor(workingDirectory, proj, owner, initials);
        w.setExitOnClose(exitOnClose);
        w.setSyncURL(syncURL);
        w.setIndivMode(indivMode);
        if (showTeamList) {
            w.showTeamListEditorWithSaveButton();
        } else {
            w.show();
            w.showApplicableStartupMessages();
            if (itemHref != null)
                w.showHyperlinkedItem(itemHref);
        }
        HttpAuthenticator.setParentComponent(w.tabPanel);
        if (dispatch != null)
            dispatch.setEditor(w);
        waitFrame.dispose();
        return w;
    } catch (LockFailureException e) {
        workingDirectory.releaseLocks();
        if (exitOnClose)
            System.exit(0);
        waitFrame.dispose();
        return null;
    }
}
Also used : BridgedWorkingDirectory(net.sourceforge.processdash.tool.bridge.client.BridgedWorkingDirectory) CompressedWorkingDirectory(net.sourceforge.processdash.tool.bridge.client.CompressedWorkingDirectory) WorkingDirectory(net.sourceforge.processdash.tool.bridge.client.WorkingDirectory) CompressedWorkingDirectory(net.sourceforge.processdash.tool.bridge.client.CompressedWorkingDirectory) LockFailureException(net.sourceforge.processdash.util.lock.LockFailureException) LockUncertainException(net.sourceforge.processdash.util.lock.LockUncertainException) CannotCreateLockException(net.sourceforge.processdash.util.lock.CannotCreateLockException) IOException(java.io.IOException) SentLockMessageException(net.sourceforge.processdash.util.lock.SentLockMessageException) HeadlessException(java.awt.HeadlessException) ReadOnlyLockFailureException(net.sourceforge.processdash.util.lock.ReadOnlyLockFailureException) LoadTabsException(teamdash.wbs.WBSTabPanel.LoadTabsException) HttpException(net.sourceforge.processdash.util.HttpException) AlreadyLockedException(net.sourceforge.processdash.util.lock.AlreadyLockedException) LockFailureException(net.sourceforge.processdash.util.lock.LockFailureException) ReadOnlyLockFailureException(net.sourceforge.processdash.util.lock.ReadOnlyLockFailureException) JFrame(javax.swing.JFrame) HttpException(net.sourceforge.processdash.util.HttpException) File(java.io.File)

Example 5 with WorkingDirectory

use of net.sourceforge.processdash.tool.bridge.client.WorkingDirectory in project processdash by dtuma.

the class WBSEditor method configureWorkingDirectory.

private static WorkingDirectory configureWorkingDirectory(String[] locations, String intent, LockMessageHandler handler) {
    DashboardBackupFactory.setKeepBackupsNumDays(30);
    WorkingDirectory workingDirectory = WorkingDirectoryFactory.getInstance().get(WorkingDirectoryFactory.PURPOSE_WBS, locations);
    try {
        workingDirectory.acquireProcessLock(intent, handler);
    } catch (SentLockMessageException s) {
        // another WBS Editor is running, and it handled the request for us.
        maybeDumpStartupError("Process Conflict", new Object[] { //
        "Another process on this computer has already locked", "the WBS Editor for this team project." });
        return null;
    } catch (LockFailureException e) {
        e.printStackTrace();
        showLockFailureError();
        return null;
    }
    boolean workingDirIsGood = false;
    try {
        workingDirectory.prepare();
        File dir = workingDirectory.getDirectory();
        if (workingDirectory instanceof CompressedWorkingDirectory) {
            workingDirIsGood = new File(dir, WBS_FILENAME).isFile();
        } else {
            workingDirIsGood = dir.isDirectory();
        }
    } catch (HttpException.Unauthorized e) {
        displayStartupPermissionError("Unauthorized");
        return null;
    } catch (HttpException.Forbidden e) {
        displayStartupPermissionError("Forbidden");
        return null;
    } catch (IOException e) {
    // do nothing.  An exception means that "workingDirIsGood" will
    // remain false, so we will display an error message below.
    }
    if (workingDirIsGood) {
        return workingDirectory;
    } else {
        showCannotOpenError(workingDirectory);
        return null;
    }
}
Also used : SentLockMessageException(net.sourceforge.processdash.util.lock.SentLockMessageException) BridgedWorkingDirectory(net.sourceforge.processdash.tool.bridge.client.BridgedWorkingDirectory) CompressedWorkingDirectory(net.sourceforge.processdash.tool.bridge.client.CompressedWorkingDirectory) WorkingDirectory(net.sourceforge.processdash.tool.bridge.client.WorkingDirectory) CompressedWorkingDirectory(net.sourceforge.processdash.tool.bridge.client.CompressedWorkingDirectory) HttpException(net.sourceforge.processdash.util.HttpException) IOException(java.io.IOException) File(java.io.File) LockFailureException(net.sourceforge.processdash.util.lock.LockFailureException) ReadOnlyLockFailureException(net.sourceforge.processdash.util.lock.ReadOnlyLockFailureException)

Aggregations

WorkingDirectory (net.sourceforge.processdash.tool.bridge.client.WorkingDirectory)5 File (java.io.File)3 IOException (java.io.IOException)3 BridgedWorkingDirectory (net.sourceforge.processdash.tool.bridge.client.BridgedWorkingDirectory)3 ProcessDashboard (net.sourceforge.processdash.ProcessDashboard)2 CompressedWorkingDirectory (net.sourceforge.processdash.tool.bridge.client.CompressedWorkingDirectory)2 HttpException (net.sourceforge.processdash.util.HttpException)2 LockFailureException (net.sourceforge.processdash.util.lock.LockFailureException)2 ReadOnlyLockFailureException (net.sourceforge.processdash.util.lock.ReadOnlyLockFailureException)2 SentLockMessageException (net.sourceforge.processdash.util.lock.SentLockMessageException)2 HeadlessException (java.awt.HeadlessException)1 URL (java.net.URL)1 JFrame (javax.swing.JFrame)1 DataContext (net.sourceforge.processdash.data.DataContext)1 DashPackage (net.sourceforge.processdash.templates.DashPackage)1 LocalWorkingDirectory (net.sourceforge.processdash.tool.bridge.client.LocalWorkingDirectory)1 AlreadyLockedException (net.sourceforge.processdash.util.lock.AlreadyLockedException)1 CannotCreateLockException (net.sourceforge.processdash.util.lock.CannotCreateLockException)1 LockUncertainException (net.sourceforge.processdash.util.lock.LockUncertainException)1 LoadTabsException (teamdash.wbs.WBSTabPanel.LoadTabsException)1