Skip to content

Commit 47bdae1

Browse files
authored
Merge pull request #2 from JamaSoftware/oauth_upgrade
Added support for OAuth
2 parents 585f730 + 3ccc7e7 commit 47bdae1

14 files changed

Lines changed: 178 additions & 60 deletions

.DS_Store

6 KB
Binary file not shown.

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
target/
2+
*.iml
3+
import.cfg
4+
*.csv
5+
classes/
6+
*idea/

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,19 @@ Change these options as required (in step 2 above).
4242

4343
```delimiter = <single character> ``` -- A single character, usually a comma or semicolon. This character is what separates elements of the CSV file. It’s also used in the lists in the rest of this file.
4444

45+
-- CHOOSE 1 Authentication method, fill in the appropriate settings, Leave the other set empty, but do not delete the option entry--
46+
-- To Use Basic Auth Enter your Username and Password, Leave ClientID and ClientSecret set to the empty string. --
47+
-- To Enable OAuth Enter your ClientID an ClientSecret, Leave Username and Password set to the empty string.--
48+
4549
```username = <string> ``` -- Jama username.
4650

4751
```password = <string> ``` -- Jama password.
4852

49-
```baseURL = <string> ``` -- The base URL of the Jama instance. For hosted this is {base url}/rest/latest/ For on-prem it’s {base url}/contour/rest/latest/
53+
```clientID = <string>``` -- Jama Oauth Client ID
54+
55+
```clientSecret = <string>``` -- Jama Oauth Client Secret
56+
57+
```baseURL = <string> ``` -- The base URL of the Jama instance. For hosted this is {base url}/rest/ For on-prem it’s {base url}/contour/rest/
5058

5159
```csvFile = <string> ``` -- The name of a CSV file in the same directory as the JAR file.
5260

RelationshipCreator.iml

Lines changed: 0 additions & 22 deletions
This file was deleted.

pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@
4141
</configuration>
4242

4343
</plugin>
44+
<plugin>
45+
<groupId>org.apache.maven.plugins</groupId>
46+
<artifactId>maven-compiler-plugin</artifactId>
47+
<configuration>
48+
<source>8</source>
49+
<target>8</target>
50+
</configuration>
51+
</plugin>
4452
</plugins>
4553
</build>
4654

src/main/META-INF/MANIFEST.MF

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Manifest-Version: 1.0
2+
Main-Class: com.jamasoftware.relationshipCreator.Main
3+

src/main/java/com/jamasoftware/relationshipCreator/Config.java

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,30 @@
1414
public class Config {
1515

1616
private UsernamePasswordCredentials credentials;
17+
private String clientID;
18+
private String clientSecret;
19+
1720
private String baseURL;
1821
private String csvFile;
19-
2022
private int columnAItemType;
23+
2124
private String columnAFieldName;
2225
private int[] columnAProjects;
23-
2426
private int columnBItemType;
27+
2528
private String columnBFieldName;
2629
private int[] columnBProjects;
27-
2830
private String delimiter;
31+
2932
private int delay;
3033
private int retries;
3134
private String parseErrors = "";
3235
private String[] params = new String[] {
3336
"delimiter",
3437
"username",
3538
"password",
39+
"clientID",
40+
"clientSecret",
3641
"baseURL",
3742
"csvFile",
3843
"columnAItemTypeAPI-ID",
@@ -45,13 +50,20 @@ public class Config {
4550
"retries"
4651
};
4752
private ArrayList<String> configFile = new ArrayList<String>();
48-
4953
public Config() {
5054
HashMap<String, String[]> params = getParams();
51-
String username = params.get("username")[0];
52-
String password = params.get("password")[0];
55+
if(params.get("username").length < 1 || !"".equals(params.get("username")[0])){
56+
System.out.println("Connecting via basic auth.");
57+
String username = params.get("username")[0];
58+
String password = params.get("password")[0];
59+
credentials = new UsernamePasswordCredentials(username, password);
60+
}
61+
else if(params.get("clientID") != null){
62+
System.out.println("Connecting via OAuth.");
63+
clientID = params.get("clientID")[0];
64+
clientSecret = params.get("clientSecret")[0];
65+
}
5366

54-
credentials = new UsernamePasswordCredentials(username, password);
5567

5668
baseURL = params.get("baseURL")[0];
5769
csvFile = params.get("csvFile")[0];
@@ -129,6 +141,22 @@ public String getColumnBFieldName() {
129141
return columnBFieldName;
130142
}
131143

144+
public String getClientID() {
145+
return clientID;
146+
}
147+
148+
public void setClientID(String clientID) {
149+
this.clientID = clientID;
150+
}
151+
152+
public String getClientSecret() {
153+
return clientSecret;
154+
}
155+
156+
public void setClientSecret(String clientSecret) {
157+
this.clientSecret = clientSecret;
158+
}
159+
132160
public String getDelimiter() {
133161
return delimiter;
134162
}

src/main/java/com/jamasoftware/relationshipCreator/ItemMapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ public HashMap<String, ArrayList<Integer>> getMapping(String baseURL,
3939

4040
while (resultCount != 0) {
4141
ProgressRecord.startBatch();
42-
String url = baseURL + "abstractitems?itemType=" +
42+
String url = baseURL + "v1/" + "abstractitems?itemType=" +
4343
itemTypeId + "&maxResults=" +
4444
maxResults + "&project=" +
4545
projectId + "&startAt=" +
4646
startIndex;
47-
Response response = RestClient.get(url,
47+
Response response = RestClient.get(config, url,
4848
config.getCredentials(),
4949
config.getDelay());
5050
if(response.getStatusCode() >= 400) {

src/main/java/com/jamasoftware/relationshipCreator/RelationshipCreator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void createRelationships(LinkedList<String[]> csv, int attempts) {
3636
payload.append(row[2]);
3737
}
3838
payload.append("}");
39-
Response response = RestClient.post(config.getBaseURL() + "relationships/",
39+
Response response = RestClient.post(config, config.getBaseURL() +"v1/"+ "relationships/",
4040
payload.toString(),
4141
config.getCredentials(),
4242
config.getDelay());

src/main/java/com/jamasoftware/relationshipCreator/RelationshipCreatorThreaded.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void createRelationships(LinkedList<String[]> csv, int attempts) {
4242
payload.append(row[2]);
4343
}
4444
payload.append("}");
45-
Response response = RestClient.post(config.getBaseURL() + "relationships/",
45+
Response response = RestClient.post(config, config.getBaseURL() + "v1/" + "relationships/",
4646
payload.toString(),
4747
config.getCredentials(),
4848
config.getDelay());

0 commit comments

Comments
 (0)