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
|
* @param projectID
|
||||||
*/
|
*/
|
||||||
public void importProject(long projectID) {
|
public boolean importProject(long projectID) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
ProjectMetadata metadata = ProjectMetadata.load(getProjectDir(projectID));
|
ProjectMetadata metadata = ProjectMetadata.load(getProjectDir(projectID));
|
||||||
|
if (metadata != null) {
|
||||||
_projectsMetadata.put(projectID, metadata);
|
_projectsMetadata.put(projectID, metadata);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -313,13 +317,15 @@ public class ProjectManager {
|
|||||||
jsonWriter.key("projectIDs");
|
jsonWriter.key("projectIDs");
|
||||||
jsonWriter.array();
|
jsonWriter.array();
|
||||||
for (Long id : _projectsMetadata.keySet()) {
|
for (Long id : _projectsMetadata.keySet()) {
|
||||||
jsonWriter.value(id);
|
|
||||||
|
|
||||||
ProjectMetadata metadata = _projectsMetadata.get(id);
|
ProjectMetadata metadata = _projectsMetadata.get(id);
|
||||||
try {
|
if (metadata != null) {
|
||||||
metadata.save(getProjectDir(id));
|
jsonWriter.value(id);
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
try {
|
||||||
|
metadata.save(getProjectDir(id));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
jsonWriter.endArray();
|
jsonWriter.endArray();
|
||||||
|
@ -16,7 +16,9 @@ import javax.servlet.http.HttpServletResponse;
|
|||||||
import org.apache.tools.tar.TarEntry;
|
import org.apache.tools.tar.TarEntry;
|
||||||
import org.apache.tools.tar.TarInputStream;
|
import org.apache.tools.tar.TarInputStream;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.Gridworks;
|
||||||
import com.metaweb.gridworks.ProjectManager;
|
import com.metaweb.gridworks.ProjectManager;
|
||||||
|
import com.metaweb.gridworks.ProjectMetadata;
|
||||||
import com.metaweb.gridworks.commands.Command;
|
import com.metaweb.gridworks.commands.Command;
|
||||||
import com.metaweb.gridworks.model.Project;
|
import com.metaweb.gridworks.model.Project;
|
||||||
import com.metaweb.gridworks.util.ParsingUtilities;
|
import com.metaweb.gridworks.util.ParsingUtilities;
|
||||||
@ -33,19 +35,29 @@ public class ImportProjectCommand extends Command {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Properties options = ParsingUtilities.parseUrlParameters(request);
|
Properties options = ParsingUtilities.parseUrlParameters(request);
|
||||||
|
|
||||||
long projectID = Project.generateID();
|
long projectID = Project.generateID();
|
||||||
|
Gridworks.log("Importing existing project using new ID " + projectID);
|
||||||
|
|
||||||
internalImport(request, options, projectID);
|
internalImport(request, options, projectID);
|
||||||
|
|
||||||
ProjectManager.singleton.importProject(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) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -34,8 +34,11 @@ public class GetAllProjectMetadataCommand extends Command {
|
|||||||
writer.object();
|
writer.object();
|
||||||
Map<Long, ProjectMetadata> m = ProjectManager.singleton.getAllProjectMetadata();
|
Map<Long, ProjectMetadata> m = ProjectManager.singleton.getAllProjectMetadata();
|
||||||
for (Entry<Long,ProjectMetadata> e : m.entrySet()) {
|
for (Entry<Long,ProjectMetadata> e : m.entrySet()) {
|
||||||
writer.key(e.getKey().toString());
|
ProjectMetadata pm = e.getValue();
|
||||||
e.getValue().write(writer, options);
|
if (pm != null) {
|
||||||
|
writer.key(e.getKey().toString());
|
||||||
|
e.getValue().write(writer, options);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
writer.endObject();
|
writer.endObject();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user