Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit 47c681d

Browse files
author
Irene
committed
Fix bugs, remove admin command, improve messages
Bugs were related to analytics
1 parent 696e42f commit 47c681d

14 files changed

Lines changed: 83 additions & 89 deletions

File tree

src/main/java/fi/helsinki/cs/tmc/cli/Application.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,6 @@ public static void main(String[] args) {
221221
app.run(args);
222222
// Because of EventSendBuffer
223223
TmcRequestProcessor.instance.shutdown();
224-
try {
225-
eventSendBuffer.saveNow(1000);
226-
} catch (Exception e) {
227-
logger.warn("Failed to save events: ", e.getStackTrace());
228-
}
229224
}
230225

231226
private boolean versionCheck() {

src/main/java/fi/helsinki/cs/tmc/cli/analytics/AnalyticsFacade.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import fi.helsinki.cs.tmc.spyware.EventStore;
99
import fi.helsinki.cs.tmc.spyware.LoggableEvent;
1010
import fi.helsinki.cs.tmc.spyware.SpywareSettings;
11+
import org.slf4j.LoggerFactory;
1112

1213
import java.awt.*;
1314
import java.security.spec.ECField;
@@ -17,6 +18,8 @@
1718
import java.util.logging.Logger;
1819

1920
public class AnalyticsFacade {
21+
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(AnalyticsFacade.class);
22+
2023
private EventSendBuffer eventSendBuffer;
2124
private SpywareSettings settings;
2225

@@ -30,31 +33,40 @@ public void saveAnalytics(String command) {
3033
return;
3134
}
3235
LoggableEvent event = LoggableEventCreator.createEvent(command);
33-
this.eventSendBuffer.receiveEvent(event);
36+
saveEvent(event);
3437
}
3538

3639
public void saveAnalytics(String courseName, String command) {
3740
if (!settings.isSpywareEnabled()) {
3841
return;
3942
}
4043
LoggableEvent event = LoggableEventCreator.createEvent(courseName, command);
41-
this.eventSendBuffer.receiveEvent(event);
44+
saveEvent(event);
4245
}
4346

4447
public void saveAnalytics(Course course, String command) {
4548
if (!settings.isSpywareEnabled()) {
4649
return;
4750
}
4851
LoggableEvent event = LoggableEventCreator.createEvent(course, command);
49-
this.eventSendBuffer.receiveEvent(event);
52+
saveEvent(event);
5053
}
5154

5255
public void saveAnalytics(Exercise exercise, String command) {
5356
if (!settings.isSpywareEnabled()) {
5457
return;
5558
}
5659
LoggableEvent event = LoggableEventCreator.createEvent(exercise, command);
60+
saveEvent(event);
61+
}
62+
63+
private void saveEvent(LoggableEvent event) {
5764
this.eventSendBuffer.receiveEvent(event);
65+
try {
66+
eventSendBuffer.saveNow(1000);
67+
} catch (Exception e) {
68+
logger.warn("Failed to save events: ", e.getStackTrace());
69+
}
5870
}
5971

6072
public Optional<Thread> sendAnalytics() {

src/main/java/fi/helsinki/cs/tmc/cli/command/ConfigCommand.java

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void setter(String value) throws BadValueTypeException {
5757
SettingsIo.saveCurrentSettingsToAccountList(context.getSettings());
5858
}
5959
});
60-
ALLOWED_KEYS.put("send-analytics", new PropertyFunctions() {
60+
ALLOWED_KEYS.put(sendAnalyticsKey, new PropertyFunctions() {
6161
@Override
6262
public String getter() {
6363
return Boolean.toString(context.getSettings().isSpywareEnabled());
@@ -70,7 +70,7 @@ public void setter(String value) throws BadValueTypeException {
7070
SettingsIo.saveCurrentSettingsToAccountList(context.getSettings());
7171
}
7272
});
73-
ALLOWED_KEYS.put("server-address", new PropertyFunctions() {
73+
ALLOWED_KEYS.put(serverAddressKey, new PropertyFunctions() {
7474
@Override
7575
public String getter() {
7676
return context.getSettings().getServerAddress();
@@ -90,62 +90,62 @@ public void setter(String value) throws BadValueTypeException {
9090
SettingsIo.saveCurrentSettingsToAccountList(context.getSettings());
9191
}
9292
});
93-
ALLOWED_KEYS.put("update-date", new PropertyFunctions() {
93+
ALLOWED_KEYS.put(updateDateKey, new PropertyFunctions() {
9494
@Override
9595
public String getter() {
96-
return context.getProperties().get("update-date");
96+
return context.getProperties().get(updateDateKey);
9797
}
9898

9999
@Override
100100
public void setter(String date) throws BadValueTypeException {
101101
if (!date.matches("[0-9]+")) {
102102
throw new BadValueTypeException("Please insert the date as a number");
103103
}
104-
properties.put("update-date", date);
104+
properties.put(updateDateKey, date);
105105
}
106106
});
107-
ALLOWED_KEYS.put("testresults-right", new PropertyFunctions() {
107+
ALLOWED_KEYS.put(testResultRightKey, new PropertyFunctions() {
108108
@Override
109109
public String getter() {
110-
return context.getProperties().get("testresults-right");
110+
return context.getProperties().get(testResultRightKey);
111111
}
112112

113113
@Override
114114
public void setter(String value) throws BadValueTypeException {
115-
addBarColorToProperties("testresults-right", value);
115+
addBarColorToProperties(testResultRightKey, value);
116116
}
117117
});
118-
ALLOWED_KEYS.put("testresults-left", new PropertyFunctions() {
118+
ALLOWED_KEYS.put(testResultLeftKey, new PropertyFunctions() {
119119
@Override
120120
public String getter() {
121-
return context.getProperties().get("testresults-left");
121+
return context.getProperties().get(testResultLeftKey);
122122
}
123123

124124
@Override
125125
public void setter(String value) throws BadValueTypeException {
126-
addBarColorToProperties("testresults-left", value);
126+
addBarColorToProperties(testResultLeftKey, value);
127127
}
128128
});
129-
ALLOWED_KEYS.put("progressbar-left", new PropertyFunctions() {
129+
ALLOWED_KEYS.put(progressBarLeftKey, new PropertyFunctions() {
130130
@Override
131131
public String getter() {
132-
return context.getProperties().get("progressbar-left");
132+
return context.getProperties().get(progressBarLeftKey);
133133
}
134134

135135
@Override
136136
public void setter(String value) throws BadValueTypeException {
137-
addBarColorToProperties("progressbar-left", value);
137+
addBarColorToProperties(progressBarLeftKey, value);
138138
}
139139
});
140-
ALLOWED_KEYS.put("progressbar-right", new PropertyFunctions() {
140+
ALLOWED_KEYS.put(progressBarRightKey, new PropertyFunctions() {
141141
@Override
142142
public String getter() {
143-
return context.getProperties().get("progressbar-right");
143+
return context.getProperties().get(progressBarRightKey);
144144
}
145145

146146
@Override
147147
public void setter(String value) throws BadValueTypeException {
148-
addBarColorToProperties("progressbar-right", value);
148+
addBarColorToProperties(progressBarRightKey, value);
149149
}
150150
});
151151
}
@@ -196,8 +196,7 @@ public void run(CliContext context, CommandLine args) {
196196
return;
197197
}
198198

199-
Optional<String> username = this.context.getSettings().getUsername();
200-
this.context.getAnalyticsFacade().saveAnalytics(username.isPresent() ? username.get() : "", "config");
199+
this.context.getAnalyticsFacade().saveAnalytics("config");
201200

202201
if ((get ? 1 : 0) + (listing ? 1 : 0) + (delete ? 1 : 0) > 1) {
203202
io.errorln("Only one of the --get or --list or --delete options can "

src/main/java/fi/helsinki/cs/tmc/cli/command/HelpCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public void run(CliContext context, CommandLine args) {
3434
this.context = context;
3535
this.io = context.getIo();
3636

37-
if (this.context.checkIsLoggedIn(false)) {
38-
this.context.getAnalyticsFacade().saveAnalytics(this.context.getSettings().getUsername().get(), "help");
37+
if (this.context.checkIsLoggedIn(true)) {
38+
this.context.getAnalyticsFacade().saveAnalytics("help");
3939
}
4040

4141
String category = handleArgs(args);

src/main/java/fi/helsinki/cs/tmc/cli/command/InfoCommand.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ public void run(CliContext context, CommandLine args) {
6565
} else {
6666
printLocalInfo(args.getArgs());
6767
}
68-
this.ctx.getAnalyticsFacade().saveAnalytics(courseName, "info");
68+
if (this.ctx.checkIsLoggedIn(true)) {
69+
this.ctx.getAnalyticsFacade().saveAnalytics(courseName, "info");
70+
}
6971
}
7072

7173
private void printInfoFromInternet(String courseName) {

src/main/java/fi/helsinki/cs/tmc/cli/command/ListCoursesCommand.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ public void run(CliContext context, CommandLine args) {
3737

3838
this.ctx.loadUserInformation();
3939

40-
this.ctx.getAnalyticsFacade().saveAnalytics("list_courses");
40+
if (this.ctx.checkIsLoggedIn(true)) {
41+
this.ctx.getAnalyticsFacade().saveAnalytics("list_courses");
42+
}
4143

4244
if (!TmcUtil.hasConnection(ctx)) {
4345
io.errorln("You don't have internet connection currently.");

src/main/java/fi/helsinki/cs/tmc/cli/command/LoginCommand.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void run(CliContext context, CommandLine args) {
5454
" and your current organization is " + this.ctx.getSettings().getOrganization().get().getName() :
5555
""));
5656
io.println("Change your organization with the command organization.");
57-
io.println("Run tmc config -l to see your current settings.");
57+
io.println("Inspect and change your current settings with the command config.");
5858
return;
5959
}
6060

@@ -106,6 +106,8 @@ public void run(CliContext context, CommandLine args) {
106106
this.ctx.getAnalyticsFacade().saveAnalytics("login");
107107

108108
io.println("Login successful.");
109+
io.println("You can change your organization with the command organization, " +
110+
"and inspect and change other settings with the command config.");
109111
}
110112

111113
private String getLoginInfo(CommandLine line, String oldValue, String option, String prompt) {

src/main/java/fi/helsinki/cs/tmc/cli/command/OrganizationCommand.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ public void run(CliContext ctx, CommandLine args) {
3535
return;
3636
}
3737

38-
Optional<String> username = this.ctx.getSettings().getUsername();
39-
this.ctx.getAnalyticsFacade().saveAnalytics(username.isPresent() ? username.get() : "", "config");
38+
this.ctx.getAnalyticsFacade().saveAnalytics("organization");
4039

4140
Optional<Organization> organization = chooseOrganization(ctx, args);
4241
this.ctx.getSettings().setOrganization(organization);

src/main/java/fi/helsinki/cs/tmc/cli/command/SubmitCommand.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,17 @@ public void run(CliContext context, CommandLine args) {
5757
if (exercisesFromArgs == null) {
5858
return;
5959
}
60-
if (exercisesFromArgs.length == 0) {
61-
io.println("Please give exercise to submit as argument");
62-
return;
63-
}
6460

6561
if (!ctx.checkIsLoggedIn(false)) {
6662
return;
6763
}
6864

6965
WorkDir workDir = ctx.getWorkDir();
66+
if (exercisesFromArgs.length == 0 && workDir.getExercises().size() != 1) {
67+
io.println("Please give exercise to submit as argument");
68+
return;
69+
}
70+
7071
for (String exercise : exercisesFromArgs) {
7172
if (!workDir.addPath(exercise)) {
7273
io.println("Error: " + exercise + " is not a valid exercise.");

src/main/java/fi/helsinki/cs/tmc/cli/command/admin/TestAdminCommand.java

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

0 commit comments

Comments
 (0)