Skip to content

Commit

Permalink
Merge pull request #204 from socrata/rjm/aaugh
Browse files Browse the repository at this point in the history
EN-49082: rework column-matching
  • Loading branch information
rjmac authored Nov 5, 2021
2 parents ad89225 + 1c4754f commit ab8c922
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
36 changes: 36 additions & 0 deletions src/main/java/com/socrata/datasync/job/IntegrationJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Boolean> jacksonHack = new ThreadLocal<Boolean>() {
@Override public Boolean initialValue() {
return true;
}
};
private boolean isPostNbeification = jacksonHack.get();

private String userAgent = "datasync";

private String userAgentNameClient = "Client";
Expand Down Expand Up @@ -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();
Expand All @@ -139,6 +167,7 @@ public IntegrationJob(String pathToFile, boolean ignoreControlInconsistencies) t
setControlFileContent(loadedJob.getControlFileContent());
setPublishViaFTP(loadedJob.getPublishViaFTP());
setPublishViaDi2Http(loadedJob.getPublishViaDi2Http());
setIsPostNbeification(loadedJob.getIsPostNbeification());
}


Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -629,6 +664,7 @@ private void loadOldSijFile(String pathToFile) throws IOException {
setPublishViaFTP(false);
setPathToControlFile(null);
setControlFileContent(null);
setIsPostNbeification(false);
}
finally{
input.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/socrata/datasync/ui/IntegrationJobTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public class IntegrationJobTab implements JobTab {
private JTextField runCommandTextField;

private boolean usingControlFile;
private boolean jobFromPostNbeification;

private UserPreferences userPrefs;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ab8c922

Please sign in to comment.