diff --git a/src/main/java/com/socrata/datasync/job/IntegrationJob.java b/src/main/java/com/socrata/datasync/job/IntegrationJob.java index 452948bc..6e43e08d 100644 --- a/src/main/java/com/socrata/datasync/job/IntegrationJob.java +++ b/src/main/java/com/socrata/datasync/job/IntegrationJob.java @@ -71,6 +71,28 @@ public class IntegrationJob extends Job { private boolean publishViaDi2Http = false; private ControlFile controlFile = null; + // Ok, so this is awful. What we're trying to do is change the + // eagerness of the way columns get fuzzy-matched going forward. + // But we don't want to change existing behavior. So: we put a + // flag in the .sij file indicating it. But that flag will take + // on its default value (which we want to be "true") when this + // object is default-constructed inside Jackson, whereupon it'll + // keep that value if there is no field saying to override it, + // which is exactly what we DON'T want to happen. + // + // So.. ugh. We'll set this threadlock to false while we're + // deserializing an .sij file, so when Jackson default-constructs + // the object it gets set to that, and can then be overridden to + // true if the flag is actually present in the file. Then, when + // it's saved, it'll be set to true over in the IntegrationJobTab, + // and the resolution will be frozen. + private static final ThreadLocal jacksonHack = new ThreadLocal() { + @Override public Boolean initialValue() { + return true; + } + }; + private boolean isPostNbeification = jacksonHack.get(); + private String userAgent = "datasync"; private String userAgentNameClient = "Client"; @@ -114,13 +136,19 @@ public IntegrationJob(String pathToFile, boolean ignoreControlInconsistencies) t // first try reading the 'current' format ObjectMapper mapper = new ObjectMapper(); IntegrationJob loadedJob; + + boolean oldHack = jacksonHack.get(); try { + jacksonHack.set(false); loadedJob = mapper.readValue(new File(pathToFile), IntegrationJob.class); } catch (IOException e) { // if reading new format fails...try reading old format into this object loadOldSijFile(pathToFile); return; + } finally { + jacksonHack.set(oldHack); } + loadedJob.setPathToSavedFile(pathToFile); String controlPath = loadedJob.getPathToControlFile(); String controlContent = loadedJob.getControlFileContent(); @@ -139,6 +167,7 @@ public IntegrationJob(String pathToFile, boolean ignoreControlInconsistencies) t setControlFileContent(loadedJob.getControlFileContent()); setPublishViaFTP(loadedJob.getPublishViaFTP()); setPublishViaDi2Http(loadedJob.getPublishViaDi2Http()); + setIsPostNbeification(loadedJob.getIsPostNbeification()); } @@ -217,6 +246,12 @@ public PublishMethod getPublishMethod() { @JsonProperty("publishViaDi2Http") public void setPublishViaDi2Http(boolean newPublishViaDi2Http) { publishViaDi2Http = newPublishViaDi2Http; } + @JsonProperty("isPostNbeification") + public boolean getIsPostNbeification() { return isPostNbeification; } + + @JsonProperty("isPostNbeification") + public void setIsPostNbeification(boolean newIsPostNbeification) { isPostNbeification = newIsPostNbeification; } + public String getDefaultJobName() { return defaultJobName; } public void setUserAgent(String usrAgentName) { @@ -629,6 +664,7 @@ private void loadOldSijFile(String pathToFile) throws IOException { setPublishViaFTP(false); setPathToControlFile(null); setControlFileContent(null); + setIsPostNbeification(false); } finally{ input.close(); diff --git a/src/main/java/com/socrata/datasync/model/ControlFileModel.java b/src/main/java/com/socrata/datasync/model/ControlFileModel.java index a996094c..cf3c719f 100644 --- a/src/main/java/com/socrata/datasync/model/ControlFileModel.java +++ b/src/main/java/com/socrata/datasync/model/ControlFileModel.java @@ -50,7 +50,7 @@ public class ControlFileModel extends Observable { private DatasetModel datasetModel; private String path; - public ControlFileModel (ControlFile file, DatasetModel dataset) throws IOException{ + public ControlFileModel (ControlFile file, DatasetModel dataset, boolean isPostNbeification) throws IOException{ controlFile = file; if (controlFile.getFileTypeControl().hasHeaderRow) controlFile.getFileTypeControl().skip = 1; @@ -63,10 +63,11 @@ public ControlFileModel (ControlFile file, DatasetModel dataset) throws IOExcept // could be duplicates, as well as empty strings. if (!file.getFileTypeControl().hasColumns()){ initializeColumns(); + // Now attempt to match those in the dataset to those in the CSV + matchColumns(); + } else if(!isPostNbeification) { + matchColumns(); } - - // Now attempt to match those in the dataset to those in the CSV - matchColumns(); } //This will be called anytime that we think the shape of the dataset has changed underneath us. diff --git a/src/main/java/com/socrata/datasync/ui/IntegrationJobTab.java b/src/main/java/com/socrata/datasync/ui/IntegrationJobTab.java index bcde3bbd..13c3ff73 100644 --- a/src/main/java/com/socrata/datasync/ui/IntegrationJobTab.java +++ b/src/main/java/com/socrata/datasync/ui/IntegrationJobTab.java @@ -120,6 +120,7 @@ public class IntegrationJobTab implements JobTab { private JTextField runCommandTextField; private boolean usingControlFile; + private boolean jobFromPostNbeification; private UserPreferences userPrefs; @@ -236,6 +237,7 @@ private void setReplaceRadioButtons(IntegrationJob job) { private void loadJobDataIntoUIFields(IntegrationJob job) { try { + jobFromPostNbeification = job.getIsPostNbeification(); if (job.getControlFileContent() != null) { ObjectMapper mapper = new ObjectMapper().enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY); ControlFile controlFile = mapper.readValue(job.getControlFileContent(), ControlFile.class); @@ -283,8 +285,8 @@ private void updateControlFileModel(ControlFile controlFile, String fourbyfour) datasetModel = new DatasetModel(userPrefs, fourbyfour); - controlFileModel = new ControlFileModel(controlFile, datasetModel); - + controlFileModel = new ControlFileModel(controlFile, datasetModel, jobFromPostNbeification); + jobFromPostNbeification = true; } private void updatePublishViaReplaceUIFields(boolean showFileInfo) { @@ -340,6 +342,7 @@ public void saveJob() { newIntegrationJob.setPathToControlFile(controlFileModel.getPath()); newIntegrationJob.setControlFileContent(controlFileModel.getControlFileContents()); newIntegrationJob.setPathToSavedFile(jobFileLocation); + newIntegrationJob.setIsPostNbeification(true); // TODO If an existing file was selected WARN user of overwriting // if first time saving this job: Open dialog box to select "Save as..." location