Skip to content

Commit

Permalink
GWT: Separate OwnerType into separate class. Unify HTTPService stubs …
Browse files Browse the repository at this point in the history
…getResults(), getUserResults() and getTeamResults().
  • Loading branch information
calin-iorgulescu committed Apr 23, 2015
1 parent 47a5a59 commit 1f87801
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 73 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package ro.pub.cs.vmchecker.client.model;

public enum AccountType {
USER,
TEAM
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@

public class ResultInfo {

public enum OwnerType {
USER,
TEAM
};

public OwnerType owner;
public String name;
public AccountType accountType;
public String accountName;
public HashMap<String, String> results;

public ResultInfo(OwnerType owner, String name, HashMap<String, String> results) {
this.owner = owner;
this.name = name;
public ResultInfo(AccountType accountType, String accountName, HashMap<String, String> results) {
this.accountType = accountType;
this.accountName = accountName;
this.results = results;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ro.pub.cs.vmchecker.client.event.ErrorDisplayEvent;
import ro.pub.cs.vmchecker.client.event.StatusChangedEvent;
import ro.pub.cs.vmchecker.client.model.Assignment;
import ro.pub.cs.vmchecker.client.model.AccountType;
import ro.pub.cs.vmchecker.client.model.ErrorResponse;
import ro.pub.cs.vmchecker.client.model.EvaluationResult;
import ro.pub.cs.vmchecker.client.service.HTTPService;
Expand Down Expand Up @@ -120,7 +121,7 @@ private void loadAndDisplayResults() {
eventBus.fireEvent(new StatusChangedEvent(StatusChangedEvent.StatusType.ACTION,
constants.loadResults()));

service.getResults(courseId, assignment.id, new AsyncCallback<EvaluationResult[]>() {
service.getResults(courseId, assignment.id, null, AccountType.USER, new AsyncCallback<EvaluationResult[]>() {

public void onFailure(Throwable caught) {
GWT.log("[AssignmentBoardPresenter]", caught);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ro.pub.cs.vmchecker.client.i18n.VmcheckerConstants;
import ro.pub.cs.vmchecker.client.event.StatusChangedEvent;
import ro.pub.cs.vmchecker.client.model.Assignment;
import ro.pub.cs.vmchecker.client.model.AccountType;
import ro.pub.cs.vmchecker.client.model.EvaluationResult;
import ro.pub.cs.vmchecker.client.model.ResultInfo;
import ro.pub.cs.vmchecker.client.model.User;
Expand Down Expand Up @@ -48,11 +49,7 @@ public void onClick(ClickEvent event) {
ResultInfo resultInfo = this.resultsInfo.get(cell.getRowIndex() - 1);
String assignmentId = assignments[cell.getCellIndex() - 1].id;
if (resultInfo.results.containsKey(assignmentId)) {
if (resultInfo.owner == ResultInfo.OwnerType.USER) {
loadAndShowUserResultDetails(assignmentId, resultInfo.name);
} else {
loadAndShowTeamResultDetails(assignmentId, resultInfo.name);
}
loadAndShowResultDetails(resultInfo, assignmentId);
}
}
}
Expand All @@ -62,7 +59,7 @@ private class ResultInfoComparator implements Comparator<ResultInfo> {
AlphanumComparator stringComparator = new AlphanumComparator();
@Override
public int compare(ResultInfo r1, ResultInfo r2) {
return stringComparator.compare(r1.name, r2.name);
return stringComparator.compare(r1.accountName, r2.accountName);
}
}

Expand Down Expand Up @@ -96,14 +93,15 @@ private void listenTableEvents() {
widget.getStudentTable().addClickHandler(new TableClickHandler(widget.getStudentTable(), studentResultsInfo));
}

private void loadAndShowTeamResultDetails(String assignmentId, String teamname) {
private void loadAndShowResultDetails(final ResultInfo resultInfo, final String assignment) {
eventBus.fireEvent(new StatusChangedEvent(StatusChangedEvent.StatusType.ACTION,
constants.loadResults()));
service.getTeamResults(courseId, assignmentId, teamname, new AsyncCallback<EvaluationResult[]> () {
constants.loadResults()));
service.getResults(courseId, assignment, resultInfo.accountName,
resultInfo.accountType, new AsyncCallback<EvaluationResult[]> () {

@Override
public void onFailure(Throwable caught) {
GWT.log("StatisticsPresenter.loadAndShowTeamResultDetails()", caught);
GWT.log("StatisticsPresenter.loadAndShowResultDetails()", caught);
}

@Override
Expand All @@ -119,24 +117,6 @@ public void onSuccess(EvaluationResult[] result) {
});
}

private void loadAndShowUserResultDetails(String assignmentId, String username) {
eventBus.fireEvent(new StatusChangedEvent(StatusChangedEvent.StatusType.ACTION,
constants.loadResults()));
service.getUserResults(courseId, assignmentId, username, new AsyncCallback<EvaluationResult[]> () {

@Override
public void onFailure(Throwable caught) {
GWT.log("StatisticsPresenter.loadAndShowUserResultDetails()", caught);
}

@Override
public void onSuccess(EvaluationResult[] result) {
eventBus.fireEvent(new StatusChangedEvent(StatusChangedEvent.StatusType.RESET, null));
String resultsHTML = "";
for (int i = 0; i < result.length; i++) {
resultsHTML += result[i].toHTML();
}
widget.displayResultDetails(resultsHTML);
}

});
Expand All @@ -155,11 +135,11 @@ private void processResults(ResultInfo[] resultsInfo) {
studentResultsInfo.clear();
teamResultsInfo.clear();
for (ResultInfo result : resultsInfo) {
if (result.owner == ResultInfo.OwnerType.USER) {
if (result.accountType == AccountType.USER) {
studentResultsInfo.add(result);
}

if (result.owner == ResultInfo.OwnerType.TEAM) {
if (result.accountType == AccountType.TEAM) {
teamResultsInfo.add(result);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.google.gwt.http.client.Request;

import ro.pub.cs.vmchecker.client.model.Assignment;
import ro.pub.cs.vmchecker.client.model.AccountType;
import ro.pub.cs.vmchecker.client.model.AuthenticationResponse;
import ro.pub.cs.vmchecker.client.model.Course;
import ro.pub.cs.vmchecker.client.model.EvaluationResult;
Expand Down Expand Up @@ -94,44 +95,28 @@ public void getStorageDirContents(String courseId, String assignmentId,
delegate.sendRequest(callback, new FileListDecoder(), params);
}

/*
* getResults() and getUserResults() call the same service: GET_USER_RESULTS.
* However, getResults() doesn't send the user as a parameter, thus getting information
* about the current user.
*/
public void getResults(String courseId, String assignmentId,
String account, AccountType accountType,
final AsyncCallback<EvaluationResult[]> callback) {
final String URL = accountType == AccountType.USER ? GET_USER_RESULTS_URL : GET_TEAM_RESULTS_URL;
Delegate<EvaluationResult[]> delegate =
new Delegate<EvaluationResult[]>(eventBus, GET_USER_RESULTS_URL, true, true, ongoingRequests);
HashMap<String, String> params = new HashMap<String, String>();
params.put("courseId", courseId);
params.put("assignmentId", assignmentId);
delegate.sendRequest(callback, new ResultDecoder(), params);
}

public void getUserResults(String courseId, String assignmentId, String username,
final AsyncCallback<EvaluationResult[]> callback) {
Delegate<EvaluationResult[]> delegate =
new Delegate<EvaluationResult[]>(eventBus, GET_USER_RESULTS_URL, true, true, ongoingRequests);
new Delegate<EvaluationResult[]>(eventBus, URL, true, true, ongoingRequests);
HashMap<String, String> params = new HashMap<String, String>();
params.put("courseId", courseId);
params.put("assignmentId", assignmentId);
params.put("username", username);
/*
* If no account is given, the current logged in account will be used implicitly.
*/
if (account != null) {
if (accountType == AccountType.USER) {
params.put("username", account);
} else {
params.put("teamname", account);
}
}
delegate.sendRequest(callback, new ResultDecoder(), params);
}

public void getTeamResults(String courseId, String assignmentId, String teamname,
final AsyncCallback<EvaluationResult[]> callback) {
Delegate<EvaluationResult[]> delegate =
new Delegate<EvaluationResult[]>(eventBus, GET_TEAM_RESULTS_URL, true, true, ongoingRequests);
HashMap<String, String> params = new HashMap<String, String>();
params.put("courseId", courseId);
params.put("assignmentId", assignmentId);
params.put("teamname", teamname);
delegate.sendRequest(callback, new ResultDecoder(), params);
}


public void getAllResults(String courseId, final AsyncCallback<ResultInfo[]> callback) {
Delegate<ResultInfo[]> delegate =
new Delegate<ResultInfo[]>(eventBus, GET_ALL_RESULTS_URL, true, false, ongoingRequests);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONValue;

import ro.pub.cs.vmchecker.client.model.AccountType;
import ro.pub.cs.vmchecker.client.model.ResultInfo;

public final class StatisticsDecoder extends JSONDecoder<ResultInfo[]> {
Expand All @@ -29,7 +30,7 @@ protected ResultInfo[] decode(String text) {
for (String assignmentId : resultsObj.keySet()) {
assignmentsResults.put(assignmentId, resultsObj.get(assignmentId).isString().stringValue());
}
results[i] = new ResultInfo(ResultInfo.OwnerType.valueOf(owner.toUpperCase()), name, assignmentsResults);
results[i] = new ResultInfo(AccountType.valueOf(owner.toUpperCase()), name, assignmentsResults);
}

return results;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ private void populateTable(FlexTable table, User user, Assignment assignments[],
/* the first column contains the student's name */
if (j == 0) {
table.getCellFormatter().addStyleName(i, j, style.name());
table.setText(i, j, result.name);
table.setText(i, j, result.accountName);
} else if (result.results.containsKey(assignments[j-1].id)) {
table.getCellFormatter().addStyleName(i, j, style.innercell());
table.setWidget(i, j, new Anchor(result.results.get(assignments[j-1].id)));
}
}

if (user.name.equals(result.name) || user.id.equals(result.name)) {
if (user.name.equals(result.accountName) || user.id.equals(result.accountName)) {
table.getRowFormatter().addStyleName(i, style.itself());
} else {
table.getRowFormatter().addStyleName(i, (i % 2 == 0) ? style.evenrow() : style.oddrow());
Expand Down

0 comments on commit 1f87801

Please sign in to comment.