Skip to content

Commit 4275c99

Browse files
committed
Unifying logging format
Also removed unused imports and addressed a couple other Sonar warnings.
1 parent 9fbd009 commit 4275c99

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+139
-166
lines changed

src/main/java/edu/ksu/canvas/CanvasApiFactory.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class CanvasApiFactory {
3737
* @param canvasBaseUrl The base URL used to access your Canvas instance
3838
*/
3939
public CanvasApiFactory(String canvasBaseUrl) {
40-
LOG.debug("Creating Canvas API factory with base URL: " + canvasBaseUrl);
40+
LOG.debug("Creating Canvas API factory with base URL: {}", canvasBaseUrl);
4141
this.canvasBaseUrl = canvasBaseUrl;
4242
this.connectTimeout = DEFAULT_CONNECT_TIMEOUT_MS;
4343
this.readTimeout = DEFAULT_READ_TIMEOUT_MS;
@@ -51,6 +51,7 @@ public CanvasApiFactory(String canvasBaseUrl) {
5151
* @param readTimeout Read timeout in milliseconds. If this is too low, longer API queries could time out prematurely
5252
*/
5353
public CanvasApiFactory(String canvasBaseUrl, int connectTimeout, int readTimeout) {
54+
LOG.debug("Creating Canvas API factory with base URL: {}, connect timeout: {}, read timeout: {}", canvasBaseUrl, connectTimeout, readTimeout);
5455
this.canvasBaseUrl = canvasBaseUrl;
5556
this.connectTimeout = connectTimeout;
5657
this.readTimeout = readTimeout;
@@ -81,7 +82,7 @@ public <T extends CanvasReader> T getReader(Class<T> type, OauthToken oauthToken
8182
* @return An instance of the requested reader class
8283
*/
8384
public <T extends CanvasReader> T getReader(Class<T> type, OauthToken oauthToken, Integer paginationPageSize) {
84-
LOG.debug("Factory call to instantiate class: " + type.getName());
85+
LOG.debug("Factory call to instantiate reader class: {}", type.getName());
8586
RestClient restClient = new RefreshingRestClient();
8687

8788
@SuppressWarnings("unchecked")
@@ -91,7 +92,7 @@ public <T extends CanvasReader> T getReader(Class<T> type, OauthToken oauthToken
9192
throw new UnsupportedOperationException("No implementation for requested interface found: " + type.getName());
9293
}
9394

94-
LOG.debug("got class: " + concreteClass);
95+
LOG.debug("got class: {}", concreteClass);
9596
try {
9697
Constructor<T> constructor = concreteClass.getConstructor(String.class, Integer.class,
9798
OauthToken.class, RestClient.class, Integer.TYPE, Integer.TYPE, Integer.class, Boolean.class);
@@ -124,7 +125,7 @@ public <T extends CanvasWriter> T getWriter(Class<T> type, OauthToken oauthToken
124125
* @return An instantiated instance of the requested writer type
125126
*/
126127
public <T extends CanvasWriter> T getWriter(Class<T> type, OauthToken oauthToken, Boolean serializeNulls) {
127-
LOG.debug("Factory call to instantiate class: " + type.getName());
128+
LOG.debug("Factory call to instantiate writer class: {}", type.getName());
128129
RestClient restClient = new RefreshingRestClient();
129130

130131
@SuppressWarnings("unchecked")
@@ -134,7 +135,7 @@ public <T extends CanvasWriter> T getWriter(Class<T> type, OauthToken oauthToken
134135
throw new UnsupportedOperationException("No implementation for requested interface found: " + type.getName());
135136
}
136137

137-
LOG.debug("got writer class: " + concreteClass);
138+
LOG.debug("got writer class: {}", concreteClass);
138139
try {
139140
Constructor<T> constructor = concreteClass.getConstructor(String.class, Integer.class, OauthToken.class,
140141
RestClient.class, Integer.TYPE, Integer.TYPE, Integer.class, Boolean.class);

src/main/java/edu/ksu/canvas/TestLauncher.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,16 @@ public void getRootAccount() throws IOException {
6969
CanvasApiFactory apiFactory = new CanvasApiFactory(canvasUrl);
7070
AccountReader acctReader = apiFactory.getReader(AccountReader.class, oauthToken);
7171
Account rootAccount = acctReader.getSingleAccount("1").get();
72-
LOG.info("Got account from Canvas: " + rootAccount.getName());
72+
LOG.info("Got account from Canvas: {}", rootAccount.getName());
7373
}
7474

7575
public void getOwnCourses() throws IOException {
7676
CanvasApiFactory apiFactory = new CanvasApiFactory(canvasUrl);
7777
CourseReader courseReader = apiFactory.getReader(CourseReader.class, oauthToken);
7878
List<Course> myCourses = courseReader.listCurrentUserCourses(new ListCurrentUserCoursesOptions());
79-
LOG.info("Got " + myCourses.size() + " courses back from Canvas: ");
79+
LOG.info("Got {} courses back from Canvas: ", myCourses.size());
8080
for(Course course : myCourses) {
81-
LOG.info(" " + course.getName());
81+
LOG.info(" course {}, name: {}", course.getId(), course.getName());
8282
}
8383
}
8484
}

src/main/java/edu/ksu/canvas/constants/CanvasConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
public class CanvasConstants {
44

5+
private CanvasConstants(){}
6+
57
public static final String ACCOUNT_ID="1";
68
public static final String MASQUERADE_SIS_USER="sis_user_id";
79
public static final String MASQUERADE_CANVAS_USER="canvas_user_id";

src/main/java/edu/ksu/canvas/errors/ErrorDetails.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package edu.ksu.canvas.errors;
22

3-
import java.util.List;
4-
53
/**
64
* This allows you to retrieve more information about what was wrong with your request.
75
*/

src/main/java/edu/ksu/canvas/impl/AccountImpl.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public AccountImpl(String canvasBaseUrl, Integer apiVersion, OauthToken oauthTok
2929

3030
@Override
3131
public Optional<Account> getSingleAccount(String accountId) throws IOException {
32-
LOG.debug("getting account " + accountId);
32+
LOG.debug("getting account {}", accountId);
3333
String url = buildCanvasUrl("accounts/" + accountId, Collections.emptyMap());
3434

3535
Response response = canvasMessenger.getSingleResponseFromCanvas(oauthToken, url);
@@ -48,7 +48,7 @@ public List<Account> listAccounts(ListAccountOptions options) throws IOException
4848

4949
@Override
5050
public List<Account> getSubAccounts(GetSubAccountsOptions options) throws IOException {
51-
LOG.debug("Getting list of sub-accounts for account " + options.getAccountId());
51+
LOG.debug("Getting list of sub-accounts for account {}", options.getAccountId());
5252
String url = buildCanvasUrl("accounts/" + options.getAccountId() + "/sub_accounts", options.getOptionsMap());
5353
return getListFromCanvas(url);
5454
}
@@ -91,9 +91,8 @@ public Boolean deleteAccount(String parentAccountId, String accountId) throws IO
9191
Map<String, List<String>> postParams = new HashMap<>();
9292
String deleteUrl = buildCanvasUrl("accounts/" + parentAccountId+ "/sub_accounts/"+ accountId, Collections.emptyMap());
9393
Response response = canvasMessenger.deleteFromCanvas(oauthToken, deleteUrl, postParams);
94-
LOG.debug("response "+ response.toString());
9594
if (response.getErrorHappened() || response.getResponseCode() != 200) {
96-
LOG.debug("Failed to delete course, error message: " + response.toString());
95+
LOG.debug("Failed to delete course, error message: {}", response.toString());
9796
return false;
9897
}
9998
Optional<Delete> responseParsed = responseParser.parseToObject(Delete.class, response);

src/main/java/edu/ksu/canvas/impl/AccountReportImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,31 @@ public List<AccountReport> listReports(String accountId, String report) throws I
3232
if(StringUtils.isBlank(report)) {
3333
throw new IllegalArgumentException("You must specify the report you want to run.");
3434
}
35-
LOG.debug("Retrieving information about all " + report + " reports for account " + accountId);
35+
LOG.debug("Retrieving information about all {} reports for account {}", report, accountId);
3636
String url = buildCanvasUrl("accounts/" + accountId + "/reports/" + report, Collections.emptyMap());
3737

3838
return getListFromCanvas(url);
3939
}
4040

4141
@Override
4242
public Optional<AccountReport> reportStatus(String accountId, String report, Long id) throws IOException {
43-
LOG.debug("Retrieving information about report ID " + id + " of report " + report + " for account " + accountId);
43+
LOG.debug("Retrieving information about report ID {} of report {} for account {}", id, report, accountId);
4444
String url = buildCanvasUrl("accounts/" + accountId + "/reports/" + report + "/" + id, Collections.emptyMap());
4545

4646
return getFromCanvas(url);
4747
}
4848

4949
@Override
5050
public Optional<AccountReport> startReport(AccountReportOptions options) throws IOException {
51-
LOG.debug("Starting new report of type " + options.getReportType() + " for account " + options.getAccountId());
51+
LOG.debug("Starting new report of type {} for account {}", options.getReportType(), options.getAccountId());
5252
String url = buildCanvasUrl("accounts/" + options.getAccountId() + "/reports/" + options.getReportType(), Collections.emptyMap());
5353
Response response = canvasMessenger.sendToCanvas(oauthToken, url, options.getOptionsMap());
5454
return responseParser.parseToObject(objectType(), response);
5555
}
5656

5757
@Override
5858
public Optional<AccountReport> deleteReport(String accountId, String report, Long reportId) throws IOException {
59-
LOG.debug("Deleting report ID " + reportId + " for report " + report + " on behalf of account " + accountId);
59+
LOG.debug("Deleting report ID {} for report {} on behalf of account {}", reportId, report, accountId);
6060
String url = buildCanvasUrl("accounts/" + accountId + "/reports/" + report + "/" + reportId, Collections.emptyMap());
6161
Response response = canvasMessenger.deleteFromCanvas(oauthToken, url, Collections.emptyMap());
6262
return responseParser.parseToObject(objectType(), response);

src/main/java/edu/ksu/canvas/impl/AccountReportSummaryImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public AccountReportSummaryImpl(String canvasBaseUrl, Integer apiVersion, OauthT
2525

2626
@Override
2727
public List<AccountReportSummary> listAvailableReports(String accountId) throws IOException {
28-
LOG.debug("Retrieving available reports for account " + accountId);
28+
LOG.debug("Retrieving available reports for account {}", accountId);
2929
String url = buildCanvasUrl("accounts/" + accountId + "/reports", Collections.emptyMap());
3030

3131
return getListFromCanvas(url);

src/main/java/edu/ksu/canvas/impl/AssignmentGroupImpl.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ public AssignmentGroupImpl(String canvasBaseUrl, Integer apiVersion, OauthToken
4444

4545
@Override
4646
public Optional<AssignmentGroup> getAssignmentGroup(GetAssignmentGroupOptions options) throws IOException {
47-
LOG.debug("Fetching assignment group " + options.getAssignmentGroupId() + " from course " + options.getCourseId());
47+
LOG.debug("Fetching assignment group {} from course {}", options.getAssignmentGroupId(), options.getCourseId());
4848
String url = buildCanvasUrl("courses/" + options.getCourseId() + "/assignment_groups/" + options.getAssignmentGroupId(), options.getOptionsMap());
4949
return getFromCanvas(url);
5050
}
5151

5252
@Override
5353
public List<AssignmentGroup> listAssignmentGroup(ListAssignmentGroupOptions options) throws IOException {
54-
LOG.debug("Listing assignment groups in course " + options.getCourseId());
54+
LOG.debug("Listing assignment groups in course {}", options.getCourseId());
5555
String url = buildCanvasUrl("courses/" + options.getCourseId() + "/assignment_groups", options.getOptionsMap());
5656
return getListFromCanvas(url);
5757
}
@@ -61,7 +61,7 @@ public Optional<AssignmentGroup> createAssignmentGroup(String courseId, Assignme
6161
if(StringUtils.isBlank(courseId)) {
6262
throw new IllegalArgumentException("Must supply a course ID when creating an assignment group");
6363
}
64-
LOG.debug("Creating new assignment group in course " + courseId + ", group name: " + assignmentGroup.getName());
64+
LOG.debug("Creating new assignment group in course {}, group name: {}", courseId, assignmentGroup.getName());
6565
String url = buildCanvasUrl("courses/" + courseId + "/assignment_groups", Collections.emptyMap());
6666
Response response = canvasMessenger.sendToCanvas(oauthToken, url, assignmentGroup.toPostMap(serializeNulls));
6767
return responseParser.parseToObject(AssignmentGroup.class, response);
@@ -72,15 +72,15 @@ public Optional<AssignmentGroup> editAssignmentGroup(String courseId, Assignment
7272
if(StringUtils.isBlank(courseId) || assignmentGroup == null || assignmentGroup.getId() == null || assignmentGroup.getId() == 0l) {
7373
throw new IllegalArgumentException("Course ID and assignment group ID must be provided");
7474
}
75-
LOG.debug("Modifying assignment group " + assignmentGroup.getId() + " in course " + courseId);
75+
LOG.debug("Modifying assignment group {} in course {}", assignmentGroup.getId(), courseId);
7676
String url = buildCanvasUrl("courses/" + courseId + "/assignment_groups/" + assignmentGroup.getId(), Collections.emptyMap());
7777
Response response = canvasMessenger.putToCanvas(oauthToken, url, assignmentGroup.toPostMap(serializeNulls));
7878
return responseParser.parseToObject(AssignmentGroup.class, response);
7979
}
8080

8181
@Override
8282
public Optional<AssignmentGroup> deleteAssignmentGroup(DeleteAssignmentGroupOptions options) throws IOException {
83-
LOG.debug("Deleting assignment group " + options.getAssignmentGroupId() + " from course " + options.getCourseId());
83+
LOG.debug("Deleting assignment group {} from course", options.getAssignmentGroupId(), options.getCourseId());
8484
String url = buildCanvasUrl("courses/" + options.getCourseId() + "/assignment_groups/" + options.getAssignmentGroupId(), options.getOptionsMap());
8585
Response response = canvasMessenger.deleteFromCanvas(oauthToken, url, Collections.emptyMap());
8686
return responseParser.parseToObject(AssignmentGroup.class, response);

src/main/java/edu/ksu/canvas/impl/AssignmentImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public Optional<Assignment> deleteAssignment(String courseId, Long assignmentId)
6767
postParams.put("event", Collections.singletonList("delete"));
6868
String createdUrl = buildCanvasUrl("courses/" + courseId + "/assignments/" + assignmentId, Collections.emptyMap());
6969
Response response = canvasMessenger.deleteFromCanvas(oauthToken, createdUrl, postParams);
70-
LOG.debug("response " + response.toString());
70+
LOG.debug("response {}", response.toString());
7171
if(response.getErrorHappened() || response.getResponseCode() != 200){
7272
LOG.debug("Failed to delete assignment, error message: " + response.toString());
7373
return Optional.empty();

src/main/java/edu/ksu/canvas/impl/AssignmentOverrideImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ public AssignmentOverrideImpl(String canvasBaseUrl, Integer apiVersion, OauthTok
3030

3131
@Override
3232
public List<AssignmentOverride> listAssignmentOverrides(String courseId, Long assignmentId) throws IOException {
33-
LOG.debug("Retrieving a list of assignment overrides in course " + courseId + " for assignment " + assignmentId);
33+
LOG.debug("Retrieving a list of assignment overrides in course {} for assignment {}", courseId, assignmentId);
3434
String url = buildCanvasUrl("courses/" + courseId + "/assignments/" + assignmentId + "/overrides", Collections.emptyMap());
3535
return getListFromCanvas(url);
3636
}
3737

3838
@Override
3939
public Optional<AssignmentOverride> getAssignmentOverride(String courseId, Long assignmentId, Long overrideId) throws IOException {
40-
LOG.debug("Retrieving an assignment override in course " + courseId + " for assignment " + assignmentId);
40+
LOG.debug("Retrieving an assignment override in course {} for assignment {}", courseId, assignmentId);
4141
String url = buildCanvasUrl("courses/" + courseId + "/assignments/" + assignmentId + "/overrides/" + overrideId, Collections.emptyMap());
4242
Response response = canvasMessenger.getSingleResponseFromCanvas(oauthToken, url);
4343
return responseParser.parseToObject(AssignmentOverride.class, response);
@@ -48,7 +48,7 @@ public Optional<AssignmentOverride> createAssignmentOverride(String courseId, As
4848
if(assignmentOverride.getAssignmentId() == null) {
4949
throw new IllegalArgumentException("Assignment override must have an assignment ID");
5050
}
51-
LOG.debug("Creating an assignment override in course " + courseId + " for assignment " + assignmentOverride.getAssignmentId());
51+
LOG.debug("Creating an assignment override in course {} for assignment {}", courseId, assignmentOverride.getAssignmentId());
5252
String url = buildCanvasUrl("courses/" + courseId + "/assignments/" + assignmentOverride.getAssignmentId() + "/overrides", Collections.emptyMap());
5353
Response response = canvasMessenger.sendJsonPostToCanvas(oauthToken, url, assignmentOverride.toJsonObject(serializeNulls));
5454
return responseParser.parseToObject(AssignmentOverride.class, response);

0 commit comments

Comments
 (0)