Search in sources :

Example 1 with NetworkDriveList

use of net.sourceforge.processdash.util.NetworkDriveList in project processdash by dtuma.

the class TeamProjectSetupWizard method resolveTeamDataDirectoryImpl.

private URL resolveTeamDataDirectoryImpl() throws IOException {
    Map<String, String> joinInfo = getTeamProjectJoinInformation();
    String teamDirectory = joinInfo.get(TEAM_DIRECTORY);
    String teamDirectoryUNC = joinInfo.get(TEAM_DIRECTORY_UNC);
    String teamDataDirectoryURL = joinInfo.get(TEAM_DATA_DIRECTORY_URL);
    String indivOverrideDirectory = getValue(IND_DIR_OVERRIDE);
    String dataSubdir = "data/" + joinInfo.get(PROJECT_ID);
    File f = null;
    if (StringUtils.hasValue(indivOverrideDirectory)) {
        // If the user has specified a manual directory override, try that
        // directory only.
        f = new File(indivOverrideDirectory, dataSubdir);
        if (f.isDirectory()) {
            joinInfo.put(TEAM_DIRECTORY, indivOverrideDirectory);
            joinInfo.put(TEAM_DIRECTORY_UNC, "");
            return f.toURI().toURL();
        }
    } else if (StringUtils.hasValue(teamDirectory)) {
        // Otherwise, try the directory specified by the team project.
        f = new File(teamDirectory, dataSubdir);
        if (f.isDirectory())
            return f.toURI().toURL();
        // Try to find the data directory using the UNC path.
        if (StringUtils.hasValue(teamDirectoryUNC)) {
            NetworkDriveList networkDriveList = new NetworkDriveList();
            String altTeamDirectory = networkDriveList.fromUNCName(teamDirectoryUNC);
            if (altTeamDirectory != null) {
                File f2 = new File(altTeamDirectory, dataSubdir);
                if (f2.isDirectory()) {
                    joinInfo.put(TEAM_DIRECTORY, altTeamDirectory);
                    return f2.toURI().toURL();
                }
            }
        }
    }
    // if a URL has been provided, try it to see if it is valid.
    if (TeamServerSelector.testServerURL(teamDataDirectoryURL) != null) {
        joinInfo.put(TEAM_DIRECTORY, "");
        joinInfo.put(TEAM_DIRECTORY_UNC, "");
        return new URL(teamDataDirectoryURL + "/");
    }
    putValue(DATA_DIR, f == null ? null : f.getPath());
    putValue(DATA_DIR_URL, teamDataDirectoryURL);
    throw new WizardError(IND_DATADIR_ERR_URL);
}
Also used : NetworkDriveList(net.sourceforge.processdash.util.NetworkDriveList) ZipFile(java.util.zip.ZipFile) File(java.io.File) URL(java.net.URL)

Example 2 with NetworkDriveList

use of net.sourceforge.processdash.util.NetworkDriveList in project processdash by dtuma.

the class TeamStartBootstrap method resolveTemplateLocation.

private File resolveTemplateLocation(String templatePath, String templatePathUNC) {
    if (templatePath == null || templatePath.trim().length() == 0)
        return null;
    File f = new File(templatePath);
    if (!f.exists()) {
        if (templatePathUNC != null && templatePathUNC.length() > 0) {
            // Try to find the template file using the UNC path.
            NetworkDriveList networkDriveList = new NetworkDriveList();
            String altTemplatePath = networkDriveList.fromUNCName(templatePathUNC);
            if (altTemplatePath != null)
                f = new File(altTemplatePath);
            else
                f = new File(templatePathUNC);
        }
    }
    try {
        f = f.getCanonicalFile();
    } catch (Exception e) {
        logger.log(Level.WARNING, "Caught exception getting canonical file", e);
    }
    logger.finer("resolveTemplateLocation('" + templatePath + "', '" + templatePathUNC + "') = '" + f + "'");
    return f;
}
Also used : NetworkDriveList(net.sourceforge.processdash.util.NetworkDriveList) File(java.io.File) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 3 with NetworkDriveList

use of net.sourceforge.processdash.util.NetworkDriveList in project processdash by dtuma.

the class MoveTeamDirMessageHandler method handle.

public void handle(MessageEvent message) {
    Element xml = message.getMessageXml();
    String projectId = getString(xml, PROJECT_ID_ATTR);
    if (!StringUtils.hasValue(projectId))
        return;
    String path = findProject(PropertyKey.ROOT, projectId);
    if (path == null)
        return;
    String directory = getString(xml, DIR_ATTR);
    String directoryUNC = getString(xml, DIR_UNC_ATTR);
    String url = getString(xml, URL_ATTR);
    NetworkDriveList dl = new NetworkDriveList();
    if (dl.wasSuccessful()) {
        if (StringUtils.hasValue(directoryUNC)) {
            if (directory == null || !directory.startsWith("\\\\")) {
                String newDir = dl.fromUNCName(directoryUNC);
                if (StringUtils.hasValue(newDir))
                    directory = newDir;
            }
        } else if (StringUtils.hasValue(directory)) {
            String newUNC = dl.toUNCName(directory);
            if (StringUtils.hasValue(newUNC))
                directoryUNC = newUNC;
        }
    }
    logger.info("Moving team data directory for project '" + path + "' to:\n" + "\tdirectory=" + directory + "\n" + "\tdirectoryUNC=" + directoryUNC + "\n" + "\turl=" + url);
    DataContext data = ctx.getData().getSubcontext(path);
    saveString(data, TeamDataConstants.TEAM_DIRECTORY, directory);
    saveString(data, TeamDataConstants.TEAM_DIRECTORY_UNC, directoryUNC);
    saveString(data, TeamDataConstants.TEAM_DATA_DIRECTORY_URL, url);
    RepairImportInstruction.maybeRepairForIndividual(data);
}
Also used : NetworkDriveList(net.sourceforge.processdash.util.NetworkDriveList) DataContext(net.sourceforge.processdash.data.DataContext) Element(org.w3c.dom.Element)

Aggregations

NetworkDriveList (net.sourceforge.processdash.util.NetworkDriveList)3 File (java.io.File)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ZipFile (java.util.zip.ZipFile)1 DataContext (net.sourceforge.processdash.data.DataContext)1 Element (org.w3c.dom.Element)1