Skip to content

Commit

Permalink
gwt: Record both the full user name and the user id. Fix row highligh…
Browse files Browse the repository at this point in the history
…ting that was broken due to LDAP canonical names.
  • Loading branch information
calin-iorgulescu committed Jan 20, 2015
1 parent f329ff1 commit 338cd10
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private void listenAuthenticationEvents() {
public void onAuthenticationChange(AuthenticationEvent event) {
GWT.log("Authentication event received", null);
if (event.getType() == AuthenticationEvent.EventType.SUCCESS) {
CookieManager.saveUsername(event.getUsername());
CookieManager.saveUser(event.getUser());
displayContent();
} else if (event.getType() == AuthenticationEvent.EventType.ERROR) {
/*
Expand Down Expand Up @@ -139,7 +139,7 @@ public void onSuccess(Course[] result) {

/* initialize header presenter */
headerPresenter = new HeaderPresenter(eventBus, service,
new HeaderWidget(CookieManager.getUsername()));
new HeaderWidget(CookieManager.getUser()));
headerPresenter.setCourses(courses);

headerPresenter.go(container);
Expand Down Expand Up @@ -172,7 +172,7 @@ public void onHistoryChanged(String token) {
if (mainPresenter != null) {
mainPresenter.clearEventHandlers();
}
mainPresenter = new AssignmentPresenter(eventBus, service, idToCourse.get(token).id, CookieManager.getUsername(), new AssignmentWidget());
mainPresenter = new AssignmentPresenter(eventBus, service, idToCourse.get(token).id, CookieManager.getUser(), new AssignmentWidget());
headerPresenter.selectCourse(idToCourse.get(token).id);
} else {
token = courses.get(0).id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import com.google.gwt.user.client.Cookies;

import ro.pub.cs.vmchecker.client.model.User;

/**
* @author claudiugh
*
Expand All @@ -12,20 +14,34 @@
*/
public class CookieManager {
public static final String COURSE_COOKIE = "VMCHK-COURSE";
public static final String USERNAME_COOKIE = "VMCHK-USER";
public static final String USERNAME_COOKIE = "VMCHK-USER-NAME";
public static final String USERID_COOKIE = "VMCHK-USER-ID";

/**
* the username is stored as cookie because it is obtained only
* the user name and id are stored as cookie because it is obtained only
* when login is successfully performed
* @param username
*/
public static void saveUsername(String username) {
public static void saveUser(User user) {
Date now = new Date();
Cookies.setCookie(USERNAME_COOKIE, username, new Date(now.getYear() + 1, now.getMonth(), now.getDay()));
Cookies.setCookie(USERNAME_COOKIE, user.name, new Date(now.getYear() + 1, now.getMonth(), now.getDay()));
Cookies.setCookie(USERID_COOKIE, user.id, new Date(now.getYear() + 1, now.getMonth(), now.getDay()));
}

public static String getUsername() {
return Cookies.getCookie(USERNAME_COOKIE);
public static User getUser() {
String userId = Cookies.getCookie(USERID_COOKIE);
String userName = Cookies.getCookie(USERNAME_COOKIE);

/*
* A user must have a valid id.
*/
if (userId == null)
return null;

if (userName == null)
userName = "";

return new User(userId, userName);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.google.gwt.event.shared.GwtEvent;

import ro.pub.cs.vmchecker.client.model.User;

public class AuthenticationEvent extends GwtEvent<AuthenticationEventHandler> {

public static final GwtEvent.Type<AuthenticationEventHandler> TYPE
Expand All @@ -11,24 +13,24 @@ public enum EventType {
SUCCESS, ERROR
}

private String username;
private User user;
private EventType type;

public AuthenticationEvent(EventType type) {
this.type = type;
}

public AuthenticationEvent(String username) {
public AuthenticationEvent(User user) {
this.type = EventType.SUCCESS;
this.username = username;
this.user = user;
}

public EventType getType() {
return type;
}

public String getUsername() {
return username;
public User getUser() {
return user;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
public class AuthenticationResponse {

public boolean status;
public String username;
public User user;
public String info;

public AuthenticationResponse(boolean status, String username, String info) {
public AuthenticationResponse(boolean status, User user, String info) {
this.status = status;
this.username = username;
this.user = user;
this.info = info;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package ro.pub.cs.vmchecker.client.model;

public class User {
public String id;
public String name;

public User(String name) {
public User(String id, String name) {
this.id = id;
this.name = name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import ro.pub.cs.vmchecker.client.ui.AssignmentBoardWidget;
import ro.pub.cs.vmchecker.client.ui.NumberedMenu;
import ro.pub.cs.vmchecker.client.ui.StatisticsWidget;
import ro.pub.cs.vmchecker.client.model.User;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
Expand All @@ -27,7 +28,7 @@ public class AssignmentPresenter implements Presenter {

private Assignment[] assignments;
private String courseId;
private String username;
private User user;

private MenuPresenter menuPresenter = null;
private AssignmentBoardPresenter boardPresenter = null;
Expand All @@ -42,12 +43,12 @@ public interface AssignmentWidget {
}

public AssignmentPresenter(HandlerManager eventBus, HTTPService service, String courseId,
String username, AssignmentWidget widget) {
User user, AssignmentWidget widget) {
this.eventBus = eventBus;
this.service = service;
this.courseId = courseId;
this.widget = widget;
this.username = username;
this.user = user;
}

private void bindWidget(final AssignmentWidget widget) {
Expand Down Expand Up @@ -99,7 +100,7 @@ public void onSuccess(Assignment[] result) {

menuPresenter = new MenuPresenter(eventBus, new NumberedMenu(titles));
boardPresenter = new AssignmentBoardPresenter(eventBus, service, courseId, new AssignmentBoardWidget());
statsPresenter = new StatisticsPresenter(eventBus, service, courseId, username, result, new StatisticsWidget());
statsPresenter = new StatisticsPresenter(eventBus, service, courseId, user, result, new StatisticsWidget());

bindWidget(widget);
widget.getMenuPanel().clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void onFailure(Throwable caught) {
public void onSuccess(AuthenticationResponse result) {
if (result.status) {
/* send authentication event */
AuthenticationEvent authEvent = new AuthenticationEvent(result.username);
AuthenticationEvent authEvent = new AuthenticationEvent(result.user);
eventBus.fireEvent(authEvent);
} else {
widget.getLoginCommentLabel().setText(result.info);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import ro.pub.cs.vmchecker.client.model.Assignment;
import ro.pub.cs.vmchecker.client.model.EvaluationResult;
import ro.pub.cs.vmchecker.client.model.StudentInfo;
import ro.pub.cs.vmchecker.client.model.User;
import ro.pub.cs.vmchecker.client.service.HTTPService;

import com.google.gwt.core.client.GWT;
Expand All @@ -19,7 +20,7 @@ public class StatisticsPresenter implements Presenter {

public interface Widget {
HTMLTable getTable();
void displayInfo(String username, Assignment[] assignments, StudentInfo[] studentInfo);
void displayInfo(User user, Assignment[] assignments, StudentInfo[] studentInfo);
void displayResultDetails(String htmlDetails);
}

Expand All @@ -31,17 +32,17 @@ public interface Widget {
private StatisticsPresenter.Widget widget;

private String courseId;
private String username;
private User user;
private Assignment[] assignments;
private StudentInfo[] studentsInfo;

public StatisticsPresenter(HandlerManager eventBus, HTTPService service,
String courseId, String username, Assignment[] assignments, StatisticsPresenter.Widget widget) {
String courseId, User user, Assignment[] assignments, StatisticsPresenter.Widget widget) {
this.eventBus = eventBus;
this.service = service;
this.courseId = courseId;
this.assignments = assignments;
this.username = username;
this.user = user;
bindWidget(widget);
listenTableEvents();
}
Expand Down Expand Up @@ -112,7 +113,7 @@ public void onFailure(Throwable caught) {
public void onSuccess(StudentInfo[] result) {
container.clear();
studentsInfo = result;
widget.displayInfo(username, assignments, result);
widget.displayInfo(user, assignments, result);
container.add((com.google.gwt.user.client.ui.Widget) widget);
eventBus.fireEvent(new StatusChangedEvent(StatusChangedEvent.StatusType.RESET, null));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ro.pub.cs.vmchecker.client.service.json;

import ro.pub.cs.vmchecker.client.model.AuthenticationResponse;
import ro.pub.cs.vmchecker.client.model.User;

import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONParser;
Expand All @@ -10,6 +11,7 @@ public class AuthenticationResponseDecoder implements JSONDecoder<Authentication

public static final String statusKey = "status";
public static final String usernameKey = "username";
public static final String useridKey = "userid";
public static final String infoKey = "info";

@Override
Expand All @@ -19,8 +21,9 @@ public AuthenticationResponse decode(String text) throws Exception {

boolean status = jsonObj.get(statusKey).isBoolean().booleanValue();
String username = jsonObj.get(usernameKey).isString().stringValue();
String userid = jsonObj.get(useridKey).isString().stringValue();
String info = jsonObj.get(infoKey).isString().stringValue();
return new AuthenticationResponse(status, username, info);
return new AuthenticationResponse(status, new User(userid, username), info);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import ro.pub.cs.vmchecker.client.i18n.VmcheckerConstants;
import ro.pub.cs.vmchecker.client.event.StatusChangedEvent.StatusType;
import ro.pub.cs.vmchecker.client.presenter.HeaderPresenter;
import ro.pub.cs.vmchecker.client.model.User;

public class HeaderWidget extends Composite
implements HeaderPresenter.HeaderWidget {
Expand All @@ -39,11 +40,11 @@ interface HeaderUiBinder extends UiBinder<Widget, HeaderWidget> {}
private static VmcheckerConstants constants = GWT
.create(VmcheckerConstants.class);

public HeaderWidget(String username) {
public HeaderWidget(User user) {
initWidget(uiBinder.createAndBindUi(this));
courseSelection.setText(constants.courseSelection());
logoutButton.setText(constants.logoutButton());
usernameLabel.setText(username);
usernameLabel.setText(user.name + " (" + user.id + ")");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import ro.pub.cs.vmchecker.client.i18n.VmcheckerConstants;
import ro.pub.cs.vmchecker.client.model.Assignment;
import ro.pub.cs.vmchecker.client.model.StudentInfo;
import ro.pub.cs.vmchecker.client.model.User;
import ro.pub.cs.vmchecker.client.presenter.StatisticsPresenter;

public class StatisticsWidget extends Composite implements StatisticsPresenter.Widget {
Expand Down Expand Up @@ -72,7 +73,7 @@ public HTMLTable getTable() {
}

@Override
public void displayInfo(String username, Assignment[] assignments, StudentInfo[] studentInfo) {
public void displayInfo(User user, Assignment[] assignments, StudentInfo[] studentInfo) {
tablePanel.clear();
table.resize(studentInfo.length + 1, assignments.length + 1);
table.setCellPadding(5);
Expand Down Expand Up @@ -104,7 +105,7 @@ public void displayInfo(String username, Assignment[] assignments, StudentInfo[]
}
}

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

0 comments on commit 338cd10

Please sign in to comment.