Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/socrata/datasync
Browse files Browse the repository at this point in the history
Conflicts:
	src/main/java/com/socrata/datasync/ui/IntegrationJobTab.java
  • Loading branch information
spaceballone committed Sep 3, 2015
2 parents 0860b0f + 0e95b33 commit 26db0e0
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ mvn clean compile -Dmaven.test.skip=true assembly:single
This puts the JAR file into the "target" directory inside the repo. So to open DataSync, simply:
```
cd target
java -jar DataSync-1.5.4-jar-with-dependencies.jar
java -jar DataSync-1.6-jar-with-dependencies.jar
```

### Java SDK
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/socrata/datasync/HttpUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ public class HttpUtility {
private boolean authRequired = false;
private static final String datasyncVersionHeader = "X-Socrata-DataSync-Version";
private static final String appHeader = "X-App-Token";
private static final String userAgent = "datasync";
private static String userAgent = "datasync";


public HttpUtility() { this(null, false); }

public HttpUtility(UserPreferences userPrefs, boolean useAuth, String usrAgent) {
this(userPrefs, useAuth);
userAgent = usrAgent;
}

public HttpUtility(UserPreferences userPrefs, boolean useAuth) {
HttpClientBuilder clientBuilder = HttpClients.custom();
if (useAuth) {
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/socrata/datasync/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,18 @@ public static String ordinal(int i) {
public static boolean nullOrEmpty(String s) {
return (s == null || s.equals(""));
}

public static String getUserAgentString(String agentName) {
try {
String osName = System.getProperty("os.name");
String osVersion = System.getProperty("os.version");
String javaVersion = System.getProperty("java.version");
String userLocale = System.getProperty("user.country") + "-" + System.getProperty("user.language");
return "DataSync/" + VersionProvider.getThisVersion() +
" (" + agentName + "; " + osName + " " + osVersion + "; Java " + javaVersion + "; " + userLocale + ")";
} catch (Exception e) {
return "DataSync/" + VersionProvider.getThisVersion() +
" (" + agentName + "; Error obtaining OS/Java/Locale info)";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class CommandLineOptions {

public static final String JOB_TYPE_FLAG = "jobType";
public static final String CONFIG_FLAG = "config";
public static final String USER_AGENT_FLAG = "userAgent";

public static final String DATASET_ID_FLAG = "datasetID";
public static final String FILE_TO_PUBLISH_FLAG = "fileToPublish";
public static final String PUBLISH_METHOD_FLAG = "publishMethod";
Expand Down Expand Up @@ -49,6 +51,7 @@ public class CommandLineOptions {
static {
options.addOption("t", JOB_TYPE_FLAG, true, "Type of job to run: " + Arrays.toString(Jobs.values()) + " (default: " + DEFAULT_JOBTYPE + ")");
options.addOption("c", CONFIG_FLAG, true, ".json file that stores global preferences (authentication details, etc) (optional)");
options.addOption("a", USER_AGENT_FLAG, true, "User-Agent string passed when making HTTPS calls (optional)");

// IntegrationJob params
options.addOption("i", DATASET_ID_FLAG, true, "Dataset ID to publish to [IntegrationJob]");
Expand Down
26 changes: 24 additions & 2 deletions src/main/java/com/socrata/datasync/job/IntegrationJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.socrata.datasync.config.controlfile.ControlFile;
import com.socrata.datasync.config.userpreferences.UserPreferences;
import com.socrata.datasync.config.userpreferences.UserPreferencesJava;
import com.socrata.datasync.config.userpreferences.UserPreferencesLib;
import com.socrata.datasync.publishers.DeltaImporter2Publisher;
import com.socrata.datasync.publishers.FTPDropbox2Publisher;
import com.socrata.datasync.publishers.Soda2Publisher;
Expand Down Expand Up @@ -67,6 +66,12 @@ public class IntegrationJob extends Job {
private boolean publishViaDi2Http = false;
private ControlFile controlFile = null;

private String userAgent = "datasync";

private String userAgentNameClient = "Client";
private String userAgentNameCli = "CLI";
private String userAgentNameSijFile = ".sij File";

private ObjectMapper controlFileMapper =
new ObjectMapper().enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY);

Expand All @@ -90,6 +95,7 @@ public IntegrationJob(UserPreferences userPrefs) {
*/
public IntegrationJob(String pathToFile) throws IOException, ControlDisagreementException {
this(pathToFile, false);
setUserAgentSijFile();
}

/**
Expand Down Expand Up @@ -207,6 +213,16 @@ public PublishMethod getPublishMethod() {

public String getDefaultJobName() { return defaultJobName; }

public void setUserAgent(String usrAgentName) {
userAgent = Utils.getUserAgentString(usrAgentName);
}
public void setUserAgentClient() {
userAgent = Utils.getUserAgentString(userAgentNameClient);
}
public void setUserAgentSijFile() {
userAgent = Utils.getUserAgentString(userAgentNameSijFile);
}

/**
* Checks that the command line arguments are sensible
* NB: it is expected that this is run before 'configure'.
Expand Down Expand Up @@ -238,6 +254,12 @@ public void configure(CommandLine cmd) {
if (controlFilePath == null)
controlFilePath = cmd.getOptionValue(options.PATH_TO_FTP_CONTROL_FILE_FLAG);
setPathToControlFile(controlFilePath);

String userAgentName = cmd.getOptionValue(options.USER_AGENT_FLAG);
if(Utils.nullOrEmpty(userAgentName)) {
userAgentName = userAgentNameCli;
}
setUserAgent(userAgentName);
}


Expand All @@ -264,7 +286,7 @@ public JobStatus run() {
try {
File fileToPublishFile = new File(fileToPublish);
if (publishViaDi2Http) {
try (DeltaImporter2Publisher publisher = new DeltaImporter2Publisher(userPrefs)) {
try (DeltaImporter2Publisher publisher = new DeltaImporter2Publisher(userPrefs, userAgent)) {
String action = controlFile.action == null ? publishMethod.name() : controlFile.action;
// "upsert" == "append" in di2
if ("upsert".equalsIgnoreCase(action))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ private static class CompletelyRestartJob extends Exception {}
private String pathToSignature = null;
CloseableHttpResponse signatureResponse = null;

public DeltaImporter2Publisher(UserPreferences userPrefs) {
http = new HttpUtility(userPrefs, true);
public DeltaImporter2Publisher(UserPreferences userPrefs, String userAgent) {
http = new HttpUtility(userPrefs, true, userAgent);
domain = userPrefs.getHost();
baseUri = new URIBuilder()
.setScheme("https")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ public JobStatus runJobNow() {
jobToRun.setControlFileContent(controlFileModel.getControlFileContents());

}
jobToRun.setUserAgentClient();
return jobToRun.run();
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/socrata/datasync/VersionProviderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void testVersionMajorNumbers() {

@Test
public void testGetLatestVersion() throws URISyntaxException {
TestCase.assertEquals("1.5.3", VersionProvider.getLatestVersion());
TestCase.assertEquals("1.5.4", VersionProvider.getLatestVersion());
}

@Test
Expand All @@ -48,6 +48,6 @@ public void testIsLatestVersion() throws URISyntaxException {

@Test
public void testGetThisVersion() {
TestCase.assertEquals("1.5.4", VersionProvider.getThisVersion());
TestCase.assertEquals("1.6", VersionProvider.getThisVersion());
}
}

0 comments on commit 26db0e0

Please sign in to comment.