Do a bit more checking when retrieving project metadata just in case project metadata is null.
git-svn-id: http://google-refine.googlecode.com/svn/trunk@435 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
4a139842d4
commit
a0d8c385f9
@ -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();
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -34,8 +34,11 @@ public class GetAllProjectMetadataCommand extends Command {
|
||||
writer.object();
|
||||
Map<Long, ProjectMetadata> m = ProjectManager.singleton.getAllProjectMetadata();
|
||||
for (Entry<Long,ProjectMetadata> 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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user