Skip to content

Commit

Permalink
Update core version
Browse files Browse the repository at this point in the history
  • Loading branch information
nygrenh committed Mar 18, 2019
1 parent 524f26e commit 94cc4ff
Show file tree
Hide file tree
Showing 27 changed files with 116 additions and 209 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>fi.helsinki.cs.tmc.cli</groupId>
<artifactId>tmc-cli</artifactId>
<version>0.9.1</version>
<version>0.9.2</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -36,7 +36,7 @@
<dependency>
<groupId>fi.helsinki.cs.tmc</groupId>
<artifactId>core</artifactId>
<version>0.10.3-SNAPSHOT</version>
<version>0.10.12-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/fi/helsinki/cs/tmc/cli/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import fi.helsinki.cs.tmc.core.utilities.TmcRequestProcessor;
import fi.helsinki.cs.tmc.langs.util.TaskExecutor;
import fi.helsinki.cs.tmc.langs.util.TaskExecutorImpl;
import fi.helsinki.cs.tmc.spyware.EventSendBuffer;
import fi.helsinki.cs.tmc.spyware.EventStore;
import fi.helsinki.cs.tmc.snapshots.EventSendBuffer;
import fi.helsinki.cs.tmc.snapshots.EventStore;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.GnuParser;
import org.apache.commons.cli.Option;
Expand Down Expand Up @@ -219,8 +219,8 @@ public static void main(String[] args) {
Settings settings = new Settings();
TaskExecutor tmcLangs = new TaskExecutorImpl();
TmcCore core = new TmcCore(settings, tmcLangs);
EventSendBuffer eventSendBuffer = new EventSendBuffer(settings, new EventStore());
AnalyticsFacade analyticsFacade = new AnalyticsFacade(settings, eventSendBuffer);
EventSendBuffer eventSendBuffer = new EventSendBuffer(new EventStore());
AnalyticsFacade analyticsFacade = new AnalyticsFacade(eventSendBuffer);
Application app = new Application(new CliContext(null, core, new WorkDir(), settings, analyticsFacade));
app.run(args);
// Because of EventSendBuffer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,41 @@

import fi.helsinki.cs.tmc.core.domain.Course;
import fi.helsinki.cs.tmc.core.domain.Exercise;
import fi.helsinki.cs.tmc.spyware.EventSendBuffer;
import fi.helsinki.cs.tmc.spyware.LoggableEvent;
import fi.helsinki.cs.tmc.spyware.SpywareSettings;
import fi.helsinki.cs.tmc.snapshots.EventSendBuffer;
import fi.helsinki.cs.tmc.snapshots.LoggableEvent;
import org.slf4j.LoggerFactory;
import java.util.Optional;

public class AnalyticsFacade {
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(AnalyticsFacade.class);

private EventSendBuffer eventSendBuffer;
private SpywareSettings settings;

public AnalyticsFacade(SpywareSettings settings, EventSendBuffer eventSendBuffer) {
this.settings = settings;
public AnalyticsFacade(EventSendBuffer eventSendBuffer) {
this.eventSendBuffer = eventSendBuffer;
}

public void saveAnalytics(String command) {
if (!settings.isSpywareEnabled()) {
return;
}
LoggableEvent event = LoggableEventCreator.createEvent(command);
saveEvent(event);
}

public void saveAnalytics(String courseName, String command) {
if (!settings.isSpywareEnabled()) {
return;
}
LoggableEvent event = LoggableEventCreator.createEvent(courseName, command);
saveEvent(event);
}

public void saveAnalytics(Course course, String command) {
if (!settings.isSpywareEnabled()) {
return;
}
LoggableEvent event = LoggableEventCreator.createEvent(course, command);
saveEvent(event);
}

public void saveAnalytics(Exercise exercise, String command) {
if (!settings.isSpywareEnabled()) {
return;
}
LoggableEvent event = LoggableEventCreator.createEvent(exercise, command);
saveEvent(event);
}

public Optional<Thread> sendAnalytics() {
if (!settings.isSpywareEnabled()) {
return Optional.empty();
}
Thread t = new Thread(() -> this.eventSendBuffer.sendNow());
t.run();
return Optional.of(t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.google.gson.Gson;
import fi.helsinki.cs.tmc.core.domain.Course;
import fi.helsinki.cs.tmc.core.domain.Exercise;
import fi.helsinki.cs.tmc.spyware.LoggableEvent;
import fi.helsinki.cs.tmc.snapshots.LoggableEvent;

import java.nio.charset.Charset;
import java.util.Collections;
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/fi/helsinki/cs/tmc/cli/backend/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class Account {
private OauthCredentials oauthCredentials;
private Course currentCourse;
private String token;
private Integer id;
private Organization organization;
private boolean sendDiagnostics;
private boolean sendAnalytics;
Expand Down Expand Up @@ -153,6 +154,14 @@ public void setServerAddressToDefault() {
this.serverAddress = DEFAULT_SERVER;
}

public void setId(Integer id) {
this.id = id;
}

public Integer getId() {
return this.id;
}

@Override
public String toString() {
return "Account{" +
Expand Down
46 changes: 26 additions & 20 deletions src/main/java/fi/helsinki/cs/tmc/cli/backend/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@
import fi.helsinki.cs.tmc.core.domain.Organization;
import fi.helsinki.cs.tmc.core.domain.ProgressObserver;
import fi.helsinki.cs.tmc.core.utilities.TmcServerAddressNormalizer;
import fi.helsinki.cs.tmc.spyware.SpywareSettings;
import org.apache.http.impl.conn.SystemDefaultRoutePlanner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.swing.text.html.Option;
import java.nio.file.Path;
import java.util.Locale;
import java.util.concurrent.Callable;

public class Settings implements TmcSettings, SpywareSettings {
public class Settings implements TmcSettings {

private static final Logger logger = LoggerFactory.getLogger(Settings.class);
private WorkDir workDir;
Expand Down Expand Up @@ -127,11 +125,36 @@ public void setPassword(Optional<String> password) {
account.setPassword(password);
}

@Override
public Optional<Integer> getId() {
return Optional.fromNullable(account.getId());
}

@Override
public void setId(int i) {
account.setId(i);
}

@Override
public Optional<String> getUsername() {
return account.getUsername();
}

@Override
public void setUsername(String s) {

}

@Override
public Optional<String> getEmail() {
return null;
}

@Override
public void setEmail(String s) {

}

@Override
public boolean userDataExists() {
return getUsername().isPresent() && getPassword().isPresent();
Expand Down Expand Up @@ -227,21 +250,4 @@ public void setOrganization(Optional<Organization> organization) {
account.setOrganization(organization);
}

@Override
public boolean isSpywareEnabled() {
return account.getSendAnalytics();
}

public void setSpywareEnabled(boolean spywareEnabled) {
account.setSendAnalytics(spywareEnabled);
}

@Override
public boolean isDetailedSpywareEnabled() {
return account.getSendDetailedAnalytics();
}

public void setDetailedSpywareEnabled(boolean detailedSpywareEnabled) {
account.setSendDetailedAnalytics(detailedSpywareEnabled);
}
}
13 changes: 0 additions & 13 deletions src/main/java/fi/helsinki/cs/tmc/cli/command/ConfigCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public class ConfigCommand extends AbstractCommand {
private Io io;
private static final Map<String, PropertyFunctions> ALLOWED_KEYS = new HashMap<>();
private static final Set<String> PROGRESS_BAR_COLORS = new HashSet<>(Arrays.asList("black", "red", "green", "blue", "yellow", "blue", "purple", "cyan", "white", "none"));
private static final String sendAnalyticsKey = "send-analytics";
private static final String serverAddressKey = "server-address";
private static final String testResultRightKey = "testresults-right";
private static final String testResultLeftKey = "testresults-left";
Expand Down Expand Up @@ -57,19 +56,7 @@ public void setter(String value) throws BadValueTypeException {
SettingsIo.saveCurrentSettingsToAccountList(context.getSettings());
}
});
ALLOWED_KEYS.put(sendAnalyticsKey, new PropertyFunctions() {
@Override
public String getter() {
return Boolean.toString(context.getSettings().isSpywareEnabled());
}

@Override
public void setter(String value) throws BadValueTypeException {
boolean send = getBooleanSendValue(value);
context.getSettings().setSpywareEnabled(send);
SettingsIo.saveCurrentSettingsToAccountList(context.getSettings());
}
});
ALLOWED_KEYS.put(serverAddressKey, new PropertyFunctions() {
@Override
public String getter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ public boolean login(CliContext ctx, CommandLine args, Optional<String> serverAd
"Do you want to send crash reports for client development?",
ctx.getSettings().getSendDiagnostics(), io);
account.setSendDiagnostics(sendDiagnostics);
boolean sendAnalytics = getBooleanAnswerFromUser(Optional.fromNullable(username),
"Do you want to send analytics data for research?",
ctx.getSettings().isSpywareEnabled(), io);
account.setSendAnalytics(sendAnalytics);

AccountList list = SettingsIo.loadAccountList();
list.addAccount(account);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/log4j.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Root logger option
log4j.rootLogger=INFO, file
log4j.category.fi.helsinki.cs.tmc.core=DEBUG, file
log4j.category.fi.helsinki.cs.tmc.spyware=DEBUG, file
log4j.category.fi.helsinki.cs.tmc.snapshots=DEBUG, file

# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
Expand Down
10 changes: 4 additions & 6 deletions src/test/java/fi/helsinki/cs/tmc/cli/ApplicationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
import fi.helsinki.cs.tmc.core.TmcCore;
import fi.helsinki.cs.tmc.langs.util.TaskExecutor;
import fi.helsinki.cs.tmc.langs.util.TaskExecutorImpl;
import fi.helsinki.cs.tmc.spyware.EventSendBuffer;
import fi.helsinki.cs.tmc.spyware.EventStore;
import fi.helsinki.cs.tmc.spyware.SpywareSettings;
import fi.helsinki.cs.tmc.snapshots.EventSendBuffer;
import fi.helsinki.cs.tmc.snapshots.EventStore;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -46,9 +45,8 @@ public void setUp() {
Settings settings = new Settings();
TaskExecutor tmcLangs = new TaskExecutorImpl();
TmcCore core = new TmcCore(settings, tmcLangs);
SpywareSettings analyticsSettings = new Settings();
EventSendBuffer eventSendBuffer = new EventSendBuffer(analyticsSettings, new EventStore());
AnalyticsFacade analyticsFacade = new AnalyticsFacade(analyticsSettings, eventSendBuffer);
EventSendBuffer eventSendBuffer = new EventSendBuffer(new EventStore());
AnalyticsFacade analyticsFacade = new AnalyticsFacade(eventSendBuffer);
app = new Application(new CliContext(io, core, new WorkDir(), settings, analyticsFacade));
mockStatic(AutoUpdater.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import fi.helsinki.cs.tmc.core.TmcCore;
import fi.helsinki.cs.tmc.langs.util.TaskExecutor;
import fi.helsinki.cs.tmc.langs.util.TaskExecutorImpl;
import fi.helsinki.cs.tmc.spyware.EventSendBuffer;
import fi.helsinki.cs.tmc.spyware.LoggableEvent;
import fi.helsinki.cs.tmc.snapshots.EventSendBuffer;
import fi.helsinki.cs.tmc.snapshots.LoggableEvent;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
Expand All @@ -33,7 +33,6 @@
@RunWith(PowerMockRunner.class)
@PrepareForTest({SettingsIo.class, TmcUtil.class})
public class AnalyticsFacadeTest {
private Settings analyticsSettings;
private AnalyticsFacade analyticsFacade;
private EventSendBuffer eventSendBuffer;
private Application app;
Expand All @@ -59,9 +58,8 @@ public void setUp() {
Settings settings = new Settings();
TaskExecutor tmcLangs = new TaskExecutorImpl();
TmcCore core = new TmcCore(settings, tmcLangs);
analyticsSettings = mock(Settings.class);
eventSendBuffer = mock(EventSendBuffer.class);
analyticsFacade = new AnalyticsFacade(analyticsSettings, eventSendBuffer);
analyticsFacade = new AnalyticsFacade(eventSendBuffer);
CliContext ctx = new CliContext(io, core, new WorkDir(), settings, analyticsFacade);
app = new Application(ctx);
workDir = ctx.getWorkDir();
Expand All @@ -75,33 +73,17 @@ public void setUp() {

}

@Test
public void analyticsNotSentIfSpywareIsNotEnabled() {
workDir.setWorkdir(pathToDummyCourse);
when(analyticsSettings.isSpywareEnabled()).thenReturn(false);
app.run(new String[] {"submit", "Module_1-02_intro"});
verify(eventSendBuffer, never()).sendNow();
}

@Test
public void analyticsisSentOnSubmitIfSpywareIsEnabled() {
workDir.setWorkdir(pathToDummyCourse);
when(analyticsSettings.isSpywareEnabled()).thenReturn(true);
app.run(new String[] {"submit", "Module_1-02_intro"});
verify(eventSendBuffer).sendNow();
}

@Test
public void analyticsIsSavedIfSpywareIsEnabled() {
when(analyticsSettings.isSpywareEnabled()).thenReturn(true);
app.run(new String[] {"courses"});
verify(eventSendBuffer, times(1)).receiveEvent(any(LoggableEvent.class));
}

@Test
public void analyticsIsNotSavedIfSpywareIsNotEnabled() {
when(analyticsSettings.isSpywareEnabled()).thenReturn(false);
app.run(new String[] {"courses"});
verify(eventSendBuffer, never()).receiveEvent(any(LoggableEvent.class));
}
}
10 changes: 4 additions & 6 deletions src/test/java/fi/helsinki/cs/tmc/cli/backend/SettingsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
import fi.helsinki.cs.tmc.core.domain.ProgressObserver;
import fi.helsinki.cs.tmc.core.holders.TmcSettingsHolder;
import fi.helsinki.cs.tmc.langs.util.TaskExecutorImpl;
import fi.helsinki.cs.tmc.spyware.EventSendBuffer;
import fi.helsinki.cs.tmc.spyware.EventStore;
import fi.helsinki.cs.tmc.spyware.SpywareSettings;
import fi.helsinki.cs.tmc.snapshots.EventSendBuffer;
import fi.helsinki.cs.tmc.snapshots.EventStore;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -46,9 +45,8 @@ public void setUp() {
testOrganization = new Organization("test", "test", "hy", "test", false);
settings = new Settings("testuser", "testpassword", testOrganization);
core = spy(new TmcCore(settings, new TaskExecutorImpl()));
SpywareSettings analyticsSettings = settings;
EventSendBuffer eventSendBuffer = new EventSendBuffer(analyticsSettings, new EventStore());
AnalyticsFacade analyticsFacade = new AnalyticsFacade(analyticsSettings, eventSendBuffer);
EventSendBuffer eventSendBuffer = new EventSendBuffer(new EventStore());
AnalyticsFacade analyticsFacade = new AnalyticsFacade(eventSendBuffer);
io = new TestIo();
context = new CliContext(io, core, new WorkDir(), settings, analyticsFacade);
}
Expand Down
Loading

0 comments on commit 94cc4ff

Please sign in to comment.