use of com.google.refine.ProjectMetadata in project OpenRefine by OpenRefine.
the class GetAllProjectMetadataCommand method doGet.
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Type", "application/json");
JSONWriter writer = new JSONWriter(response.getWriter());
Properties options = new Properties();
writer.object();
writer.key("projects");
writer.object();
Map<Long, ProjectMetadata> m = ProjectManager.singleton.getAllProjectMetadata();
for (Entry<Long, ProjectMetadata> e : m.entrySet()) {
ProjectMetadata pm = e.getValue();
if (pm != null) {
writer.key(e.getKey().toString());
e.getValue().write(writer, options);
}
}
writer.endObject();
writer.endObject();
} catch (JSONException e) {
respondException(response, e);
}
}
use of com.google.refine.ProjectMetadata in project OpenRefine by OpenRefine.
the class ImportingUtilities method createProjectSynchronously.
private static void createProjectSynchronously(final ImportingJob job, final String format, final JSONObject optionObj, final List<Exception> exceptions, final Format record, final Project project) {
ProjectMetadata pm = new ProjectMetadata();
pm.setName(JSONUtilities.getString(optionObj, "projectName", "Untitled"));
String encoding = JSONUtilities.getString(optionObj, "encoding", "UTF-8");
if ("".equals(encoding)) {
// encoding can be present, but empty, which won't trigger JSONUtilities default processing
encoding = "UTF-8";
}
pm.setEncoding(encoding);
record.parser.parse(project, pm, job, job.getSelectedFileRecords(), format, -1, optionObj, exceptions);
if (!job.canceled) {
if (exceptions.size() == 0) {
// update all internal models, indexes, caches, etc.
project.update();
ProjectManager.singleton.registerProject(project, pm);
job.setProjectID(project.id);
job.setState("created-project");
} else {
job.setError(exceptions);
}
job.touch();
job.updating = false;
}
}
use of com.google.refine.ProjectMetadata in project OpenRefine by OpenRefine.
the class FileProjectManager method loadFromFile.
protected boolean loadFromFile(File file) {
logger.info("Loading workspace: {}", file.getAbsolutePath());
_projectsMetadata.clear();
boolean found = false;
if (file.exists() || file.canRead()) {
FileReader reader = null;
try {
reader = new FileReader(file);
JSONTokener tokener = new JSONTokener(reader);
JSONObject obj = (JSONObject) tokener.nextValue();
JSONArray a = obj.getJSONArray("projectIDs");
int count = a.length();
for (int i = 0; i < count; i++) {
long id = a.getLong(i);
File projectDir = getProjectDir(id);
ProjectMetadata metadata = ProjectMetadataUtilities.load(projectDir);
_projectsMetadata.put(id, metadata);
}
if (obj.has("preferences") && !obj.isNull("preferences")) {
_preferenceStore.load(obj.getJSONObject("preferences"));
}
if (obj.has("expressions") && !obj.isNull("expressions")) {
// backward compatibility
((TopList) _preferenceStore.get("scripting.expressions")).load(obj.getJSONArray("expressions"));
}
found = true;
} catch (JSONException e) {
logger.warn("Error reading file", e);
} catch (IOException e) {
logger.warn("Error reading file", e);
} finally {
try {
if (reader != null) {
reader.close();
}
} catch (IOException e) {
logger.warn("Exception closing file", e);
}
}
}
return found;
}
use of com.google.refine.ProjectMetadata in project OpenRefine by OpenRefine.
the class XlsExporterTests method SetUp.
@BeforeMethod
public void SetUp() {
SUT = new XlsExporter(false);
stream = new ByteArrayOutputStream();
ProjectManager.singleton = new ProjectManagerStub();
projectMetadata = new ProjectMetadata();
project = new Project();
projectMetadata.setName(TEST_PROJECT_NAME);
ProjectManager.singleton.registerProject(project, projectMetadata);
engine = new Engine(project);
options = mock(Properties.class);
}
use of com.google.refine.ProjectMetadata in project OpenRefine by OpenRefine.
the class BooleanTests method SetUp.
@BeforeMethod
public void SetUp() throws IOException, ModelException {
bindings = new Properties();
File dir = TestUtils.createTempDirectory("openrefine-test-workspace-dir");
FileProjectManager.initialize(dir);
project = new Project();
ProjectMetadata pm = new ProjectMetadata();
pm.setName("TNG Test Project");
ProjectManager.singleton.registerProject(project, pm);
int index = project.columnModel.allocateNewCellIndex();
Column column = new Column(index, "Column A");
project.columnModel.addColumn(index, column, true);
options = mock(Properties.class);
bindings.put("project", project);
// Five rows of a's and five of 1s
for (int i = 0; i < 10; i++) {
Row row = new Row(1);
row.setCell(0, new Cell(i < 5 ? "a" : new Integer(1), null));
project.rows.add(row);
}
}
Aggregations