Merge pull request #1551 from OpenRefine/issue/1542

refactoring the code to show the error message if there is any
This commit is contained in:
Antonin Delpeuch 2018-03-26 10:02:01 +01:00 committed by GitHub
commit 220b884fc6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,6 +44,7 @@ import java.time.ZoneId;
import java.util.List; import java.util.List;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONWriter; import org.json.JSONWriter;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -74,10 +75,6 @@ public class ProjectMetadataUtilities {
tempFile.renameTo(file); tempFile.renameTo(file);
} }
public static void saveTableSchema(Project project, File projectDir) throws JSONException, IOException {
}
protected static void saveToFile(IMetadata projectMeta, File metadataFile) throws JSONException, IOException { protected static void saveToFile(IMetadata projectMeta, File metadataFile) throws JSONException, IOException {
Writer writer = new OutputStreamWriter(new FileOutputStream(metadataFile)); Writer writer = new OutputStreamWriter(new FileOutputStream(metadataFile));
try { try {
@ -89,22 +86,34 @@ public class ProjectMetadataUtilities {
} }
static public ProjectMetadata load(File projectDir) { static public ProjectMetadata load(File projectDir) {
try { ProjectMetadata pm = null;
return loadFromFile(new File(projectDir, ProjectMetadata.DEFAULT_FILE_NAME));
} catch (Exception e) { pm = loadMetaDataIfExist(projectDir, ProjectMetadata.DEFAULT_FILE_NAME);
if (pm == null) {
pm = loadMetaDataIfExist(projectDir, ProjectMetadata.TEMP_FILE_NAME);
} }
try { if (pm == null) {
return loadFromFile(new File(projectDir, ProjectMetadata.TEMP_FILE_NAME)); pm = loadMetaDataIfExist(projectDir, ProjectMetadata.OLD_FILE_NAME);
} catch (Exception e) {
} }
try { return pm;
return loadFromFile(new File(projectDir, ProjectMetadata.OLD_FILE_NAME)); }
} catch (Exception e) {
private static ProjectMetadata loadMetaDataIfExist(File projectDir, String fileName) {
ProjectMetadata pm = null;
File file = new File(projectDir, fileName);
if (file.exists()) {
try {
pm = loadFromFile(file);
} catch (Exception e) {
logger.warn("load metadata failed: " + file.getAbsolutePath());
logger.error(ExceptionUtils.getStackTrace(e));
}
} }
return null; return pm;
} }
/** /**