Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/main/java/de/doubleslash/usb_led_matrix/graph/Graph.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -44,15 +45,14 @@ public class Graph {
private HttpClient client = HttpClient.newHttpClient();

public Graph() {
try {
final InputStream input = new FileInputStream(refreshFile);
try (FileInputStream input = new FileInputStream(refreshFile)) {
properties.load(input);
final String tenantID = properties.getProperty(TENANT_ID_PROPERTY);
if (tenantID != null) {
tokenURI = String.format("https://login.microsoftonline.com/%s/oauth2/v2.0/token", tenantID);
}
} catch (IOException e) {
LOG.error("Could not load properties from file '{}'", refreshFile.getAbsolutePath(), e);
LOG.error("Error loading properties from file '{}'", refreshFile.getAbsolutePath(), e);
}
}

Expand Down Expand Up @@ -143,8 +143,9 @@ private HttpRequest.BodyPublisher ofFormData(final Map<Object, Object> data) {
}

private void getNewAccessToken() throws IOException, InterruptedException {
final InputStream input = new FileInputStream(refreshFile);
properties.load(input);
try (InputStream input = new FileInputStream(refreshFile)) {
properties.load(input);
}

final Map<Object, Object> values = new HashMap<>();

Expand Down Expand Up @@ -213,6 +214,10 @@ public Color getStatusColorFromTeams() throws IOException, InterruptedException
} catch (final IllegalArgumentException e) {
LOG.warn("Unknown availability '{}'.", teamsStatus, e);
}
return availabilityStatus.getColor();
if (availabilityStatus != null) {
return availabilityStatus.getColor();
} else {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ public void customInitialize() {
CommandLineOptions.Dark(scene);
}
final String fileName = "refreshToken.txt";
try {
final InputStream input = new FileInputStream(new File(fileName));
try (InputStream input = new FileInputStream(new File(fileName))) {
final Properties properties = new Properties();
properties.load(input);
final String tenantID = properties.getProperty("tenant_id");
Expand Down Expand Up @@ -136,9 +135,7 @@ public void setScene(final Scene scene) {

@FXML
void setTeamsID(ActionEvent event) {
final FileWriter fw;
try {
fw = new FileWriter("refreshToken.txt");
try (FileWriter fw = new FileWriter("refreshToken.txt")) {
final Properties p = new Properties();
p.setProperty("tenant_id", tenantIDTextField.getText());
p.setProperty("client_id", clientIDTextField.getText());
Expand Down Expand Up @@ -183,8 +180,11 @@ public void setWebsiteCode() {
initializeCopyButton();

this.deviceCode.set(deviceCode);
} catch (IOException | InterruptedException e) {
} catch (IOException e) {
LOG.error("Could not retrieve device code: ", e);
} catch (InterruptedException e) {
LOG.error("CurrentThread was interrupt", e);
Thread.currentThread().interrupt();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

guess we should only interrupt, if interrupt exception was thrown. not also in case of IOException.
(same comment as was already resolved at another place)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is now only interrupted in the event of an interruption exception

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • extra ; present
  • logging is different than in the other locations where u changed it. please do it consistently

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import java.util.Optional;

public class ConfigurationView {
private static final int POLLING_INTERVALL_SECONDS = 10;
private static final long POLLING_INTERVALL_SECONDS = 10;

private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

Expand Down Expand Up @@ -94,6 +94,7 @@ public class ConfigurationView {
Thread.sleep(POLLING_INTERVALL_SECONDS * 1000);
} catch (final InterruptedException e) {
LOG.debug("Manual mode was interrupted.", e);
Thread.currentThread().interrupt();
return;
}
}
Expand All @@ -111,6 +112,7 @@ public class ConfigurationView {
Thread.sleep(POLLING_INTERVALL_SECONDS * 1000);
} catch (final InterruptedException ie) {
LOG.debug("MS Teams status polling was interrupted.", ie);
Thread.currentThread().interrupt();
return;
}
}
Expand All @@ -124,6 +126,7 @@ public class ConfigurationView {
Thread.sleep(POLLING_INTERVALL_SECONDS * 1000);
} catch (final InterruptedException e) {
LOG.debug("Connection check was interrupted.", e);
Thread.currentThread().interrupt();
return;
}
turnOffAutomaticallyIfNeeded(LocalTime.now());
Expand All @@ -137,6 +140,8 @@ public class ConfigurationView {
Thread.sleep(POLLING_INTERVALL_SECONDS * 1000);
} catch (final InterruptedException e) {
LOG.debug("Reconnection check was interrupted.", e);
Thread.currentThread().interrupt();

return;
}
turnOffAutomaticallyIfNeeded(LocalTime.now());
Expand All @@ -154,8 +159,11 @@ protected Void call() {
answerBody = graph.pollingForToken(model.getDeviceCode());
LOG.debug("Polling for token. Answer was: '{}'.", answerBody);
Thread.sleep(POLLING_INTERVALL_SECONDS * 500);
} catch (IOException | InterruptedException e) {
} catch (IOException e) {
LOG.error("Could not get answer from server.", e);
} catch (InterruptedException e) {
LOG.error("Could not get answer from server.", e);
Thread.currentThread().interrupt();
}
}
if (answerBody.contains("access_token")) {
Expand Down