diff --git a/src/main/java/com/metaweb/gridworks/ProjectManager.java b/src/main/java/com/metaweb/gridworks/ProjectManager.java index 9e58a90fd..8ff26d56c 100644 --- a/src/main/java/com/metaweb/gridworks/ProjectManager.java +++ b/src/main/java/com/metaweb/gridworks/ProjectManager.java @@ -176,11 +176,15 @@ public class ProjectManager { * * @param projectID */ - public void importProject(long projectID) { + public boolean importProject(long projectID) { synchronized (this) { ProjectMetadata metadata = ProjectMetadata.load(getProjectDir(projectID)); - - _projectsMetadata.put(projectID, metadata); + if (metadata != null) { + _projectsMetadata.put(projectID, metadata); + return true; + } else { + return false; + } } } @@ -313,13 +317,15 @@ public class ProjectManager { jsonWriter.key("projectIDs"); jsonWriter.array(); for (Long id : _projectsMetadata.keySet()) { - jsonWriter.value(id); - ProjectMetadata metadata = _projectsMetadata.get(id); - try { - metadata.save(getProjectDir(id)); - } catch (Exception e) { - e.printStackTrace(); + if (metadata != null) { + jsonWriter.value(id); + + try { + metadata.save(getProjectDir(id)); + } catch (Exception e) { + e.printStackTrace(); + } } } jsonWriter.endArray(); diff --git a/src/main/java/com/metaweb/gridworks/commands/edit/ImportProjectCommand.java b/src/main/java/com/metaweb/gridworks/commands/edit/ImportProjectCommand.java index 518ed1781..caed2e0be 100644 --- a/src/main/java/com/metaweb/gridworks/commands/edit/ImportProjectCommand.java +++ b/src/main/java/com/metaweb/gridworks/commands/edit/ImportProjectCommand.java @@ -16,7 +16,9 @@ import javax.servlet.http.HttpServletResponse; import org.apache.tools.tar.TarEntry; import org.apache.tools.tar.TarInputStream; +import com.metaweb.gridworks.Gridworks; import com.metaweb.gridworks.ProjectManager; +import com.metaweb.gridworks.ProjectMetadata; import com.metaweb.gridworks.commands.Command; import com.metaweb.gridworks.model.Project; import com.metaweb.gridworks.util.ParsingUtilities; @@ -33,19 +35,29 @@ public class ImportProjectCommand extends Command { try { Properties options = ParsingUtilities.parseUrlParameters(request); + long projectID = Project.generateID(); + Gridworks.log("Importing existing project using new ID " + projectID); internalImport(request, options, projectID); ProjectManager.singleton.importProject(projectID); - if (options.containsKey("project-name")) { - String projectName = options.getProperty("project-name"); - if (projectName != null && projectName.length() > 0) { - ProjectManager.singleton.getProjectMetadata(projectID).setName(projectName); - } - } - redirect(response, "/project.html?project=" + projectID); + ProjectMetadata pm = ProjectManager.singleton.getProjectMetadata(projectID); + if (pm != null) { + if (options.containsKey("project-name")) { + String projectName = options.getProperty("project-name"); + if (projectName != null && projectName.length() > 0) { + pm.setName(projectName); + } + } + + redirect(response, "/project.html?project=" + projectID); + } else { + redirect(response, "/error.html?redirect=index.html&msg=" + + ParsingUtilities.encode("Failed to import project") + ); + } } catch (Exception e) { e.printStackTrace(); } diff --git a/src/main/java/com/metaweb/gridworks/commands/info/GetAllProjectMetadataCommand.java b/src/main/java/com/metaweb/gridworks/commands/info/GetAllProjectMetadataCommand.java index 9afbacca2..4550c7ffa 100644 --- a/src/main/java/com/metaweb/gridworks/commands/info/GetAllProjectMetadataCommand.java +++ b/src/main/java/com/metaweb/gridworks/commands/info/GetAllProjectMetadataCommand.java @@ -34,8 +34,11 @@ public class GetAllProjectMetadataCommand extends Command { writer.object(); Map m = ProjectManager.singleton.getAllProjectMetadata(); for (Entry e : m.entrySet()) { - writer.key(e.getKey().toString()); - e.getValue().write(writer, options); + ProjectMetadata pm = e.getValue(); + if (pm != null) { + writer.key(e.getKey().toString()); + e.getValue().write(writer, options); + } } writer.endObject();