refactoring the code the show the error message if there is any
@@ -44,6 +44,7 @@ import java.time.ZoneId;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.exception.ExceptionUtils;
import org.json.JSONException;
import org.json.JSONWriter;
import org.slf4j.Logger;
@@ -74,10 +75,6 @@ public class ProjectMetadataUtilities {
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 {
Writer writer = new OutputStreamWriter(new FileOutputStream(metadataFile));
try {
@@ -89,22 +86,34 @@ public class ProjectMetadataUtilities {
}
static public ProjectMetadata load(File projectDir) {
- try {
- return loadFromFile(new File(projectDir, ProjectMetadata.DEFAULT_FILE_NAME));
- } catch (Exception e) {
+ ProjectMetadata pm = null;
+
+ pm = loadMetaDataIfExist(projectDir, ProjectMetadata.DEFAULT_FILE_NAME);
+
+ if (pm == null) {
+ pm = loadMetaDataIfExist(projectDir, ProjectMetadata.TEMP_FILE_NAME);
}
- try {
- return loadFromFile(new File(projectDir, ProjectMetadata.TEMP_FILE_NAME));
- } catch (Exception e) {
+ if (pm == null) {
+ pm = loadMetaDataIfExist(projectDir, ProjectMetadata.OLD_FILE_NAME);
+ }
+
+ return pm;
}
+ private static ProjectMetadata loadMetaDataIfExist(File projectDir, String fileName) {
+ ProjectMetadata pm = null;
+ File file = new File(projectDir, fileName);
+ if (file.exists()) {
try {
- return loadFromFile(new File(projectDir, ProjectMetadata.OLD_FILE_NAME));
+ pm = loadFromFile(file);
} catch (Exception e) {
+ logger.warn("load metadata failed: " + file.getAbsolutePath());
+ logger.error(ExceptionUtils.getStackTrace(e));
+ }
}
- return null;
+ return pm;
}
/**
