Skip to content
Snippets Groups Projects
Commit 2b6c13a6 authored by Julian Dehne's avatar Julian Dehne
Browse files

Implemented ChatWindow for Project Scope

references #8
Login is admin (needs fixing)
parent 9cdc6916
No related branches found
No related tags found
No related merge requests found
Showing
with 127 additions and 68 deletions
......@@ -7,7 +7,7 @@ public class GFRocketChatConfig {
//private static final String ROCKET_CHAT_LINK = "http://rocketchat.westeurope.cloudapp.azure.com/";
private static final String ROCKET_CHAT_LINK = "https://rocket.farm-test.rz.uni-potsdam.de/";
public static final String ROCKET_CHAT_LINK = "https://rocket.farm-test.rz.uni-potsdam.de";
// or https://rocket.farm.uni-potsdam.de/
// https://rocket.farm-test.rz.uni-potsdam.de/home
......@@ -16,9 +16,9 @@ public class GFRocketChatConfig {
* username: fltrailadmin pw: GEbCM1Rso6TUGGMKtGmg6c5EydMQEu61K9zdD10F
*/
public static final String ROCKET_CHAT_ROOM_LINK = ROCKET_CHAT_LINK + "group/";
public static final String ROCKET_CHAT_ROOM_LINK = ROCKET_CHAT_LINK + "/group/";
public static final String ROCKET_CHAT_API_LINK = ROCKET_CHAT_LINK + "api/v1/";
public static final String ROCKET_CHAT_API_LINK = ROCKET_CHAT_LINK + "/api/v1/";
public static final User TEST_USER = new User("test", "passwort",
"test@stuff.com", "test", "rocketChatAuthToken",
......
......@@ -90,7 +90,7 @@ public interface ICommunication {
* @param user username and password
* @return information about user, especially authtoken for later use of endpoints
*/
boolean loginUser(User user);
User loginUser(User user);
/**
* api 1: https://rocket.chat/docs/developer-guides/rest-api/users/register/
......@@ -106,6 +106,8 @@ public interface ICommunication {
String getChatRoomLink(String userToken, String projectId);
String getProjectChatRoomLink(String projectName);
// TODO implement as Email or whatever
boolean sendSingleMessage(EMailMessage EMailMessage, User user);
......
......@@ -196,7 +196,7 @@ public class CommunicationService implements ICommunication {
private boolean modifyChatRoom(User user, String roomId, boolean addUser) {
loginUser(ADMIN_USER);
if (hasEmptyParameter(user.getRocketChatUserId(), user.getRocketChatPersonalAccessToken(), roomId)) {
if (hasEmptyParameter(user.getRocketChatUserId(), roomId)) {
return false;
}
Map<String, String> headerMap = new RocketChatHeaderMapBuilder().withRocketChatAdminAuth().build();
......@@ -248,22 +248,23 @@ public class CommunicationService implements ICommunication {
}
@Override
public boolean loginUser(User user) {
public User loginUser(User user) {
if (hasEmptyParameter(user.getEmail(), user.getPassword())) {
return false;
return null;
}
//
HashMap<String, String> rocketChatAuth = new HashMap<>();
rocketChatAuth.put("user", user.getEmail());
rocketChatAuth.put("password", user.getPassword());
HttpResponse<RocketChatLoginResponse> response =
unirestService.post(ROCKET_CHAT_API_LINK + "login").body(rocketChatAuth)
unirestService.post(ROCKET_CHAT_API_LINK + "register").body(rocketChatAuth)
.asObject(RocketChatLoginResponse.class);
if (isBadRequest(response)) {
return false;
return null;
} else {
if (ADMIN_USER.equals(user)) {
setAdminToken();
......@@ -274,7 +275,7 @@ public class CommunicationService implements ICommunication {
user.setRocketChatUserId(rocketChatLoginResponse.getUserId());
user.setRocketChatAuthToken(rocketChatLoginResponse.getAuthToken());
return true;
return user;
}
@Override
......@@ -332,6 +333,11 @@ public class CommunicationService implements ICommunication {
return ROCKET_CHAT_ROOM_LINK + chatRoomName + "?layout=embedded";
}
@Override
public String getProjectChatRoomLink(String projectName) {
return ROCKET_CHAT_ROOM_LINK + projectName + "?layout=embedded";
}
// TODO: Think about splitting email and chat communication into different
@Override
public boolean sendSingleMessage(EMailMessage eMailMessage, User user) {
......
......@@ -9,7 +9,7 @@ import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException;
/**
* implemented while porting the login page. It might be useful to have a hidden user field on the page in order to
* implemented while porting the register page. It might be useful to have a hidden user field on the page in order to
* manipulate the user data with jquery
*/
@ManagedBean
......
......@@ -15,6 +15,7 @@ public class User {
private String email;
private String rocketChatUsername;
private String rocketChatAuthToken;
// not in this version
private String rocketChatPersonalAccessToken;
private String rocketChatUserId;
private Boolean isStudent;
......
......@@ -24,9 +24,13 @@ import java.net.URISyntaxException;
@ManagedBean
public class UserView {
@Inject
private ICommunication communicationService;
@Inject
private UserDAO userDAO;
@Inject
private Management management;
@Inject
......@@ -55,7 +59,7 @@ public class UserView {
@FormParam("email") String email, @FormParam("isStudent") String isStudent) throws URISyntaxException {
User user = new User(name, password, email, isStudent == null);
return login(req, true, user);
return register(req, true, user);
}
......@@ -72,14 +76,17 @@ public class UserView {
@POST
@Produces(MediaType.TEXT_HTML)
@Path("/exists")
public Response existsUser(
public Response loginUser(
@Context HttpServletRequest req, @FormParam("name") String name, @FormParam("password") String password,
@FormParam("email") String email) throws URISyntaxException {
User user = new User(name, password, email, null);
boolean isLoggedIn = communicationService.loginUser(user);
if (isLoggedIn) {
return login(req, false, user);
// TODO fix this
User isLoggedIn = communicationService.loginUser(user);
if (isLoggedIn != null) {
req.getSession().setAttribute(GFContexts.ROCKETCHATAUTHTOKEN, isLoggedIn.getRocketChatAuthToken());
req.getSession().setAttribute(GFContexts.ROCKETCHATID, isLoggedIn.getRocketChatUserId());
return register(req, false, user);
} else {
return loginError();
}
......@@ -107,7 +114,7 @@ public class UserView {
* @return
* @throws URISyntaxException
*/
public Response login(HttpServletRequest req, boolean createUser, User user) throws URISyntaxException {
public Response register(HttpServletRequest req, boolean createUser, User user) throws URISyntaxException {
if (management.exists(user)) {
if (!createUser) {
......
package unipotsdam.gf.process;
import unipotsdam.gf.interfaces.ICommunication;
import unipotsdam.gf.interfaces.IPhases;
import unipotsdam.gf.modules.group.GroupDAO;
import unipotsdam.gf.modules.group.GroupFormationMechanism;
......@@ -35,6 +36,8 @@ public class ProjectCreationProcess {
@Inject
private GroupDAO groupDAO;
@Inject
private ICommunication iCommunication;
/**
* STEP 1
......@@ -51,6 +54,10 @@ public class ProjectCreationProcess {
throw new WebApplicationException("Project already exists");
}
taskDao.createTaskWaitForParticipants(project, author);
// create chatromm
iCommunication.createEmptyChatRoom(project.getName(), false);
}
/**
......@@ -81,5 +88,6 @@ public class ProjectCreationProcess {
//phases.endPhase(Phase.GroupFormation, project);
}
}
iCommunication.addUserToChatRoom(user, project.getName());
}
}
......@@ -14,6 +14,10 @@ public class GFContexts {
public static final String USEREMAIL = "userEmail";
public static final String PROJECTNAME = "projectName";
public static final String ROCKETCHATAUTHTOKEN = "rocketchatauthtoken";
public static final String ROCKETCHATID = "rocketchatid";
public String getUserEmail(HttpServletRequest req) throws IOException {
Object userEmail = req.getSession().getAttribute(GFContexts.USEREMAIL);
if (userEmail == null) {
......
......@@ -5,8 +5,10 @@ import org.glassfish.hk2.utilities.ServiceLocatorUtilities;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import unipotsdam.gf.config.GFApplicationBinder;
import unipotsdam.gf.config.GFRocketChatConfig;
import unipotsdam.gf.interfaces.ICommunication;
import unipotsdam.gf.modules.communication.service.CommunicationService;
import unipotsdam.gf.session.GFContext;
import unipotsdam.gf.session.GFContexts;
import javax.inject.Inject;
......@@ -22,6 +24,8 @@ public class ChatWindow extends SimpleTagSupport {
private String orientation;
private String scope;
@Inject
private ICommunication communicationService;
......@@ -33,14 +37,32 @@ public class ChatWindow extends SimpleTagSupport {
PageContext pageContext = (PageContext) getJspContext();
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
/*String token = request.getParameter("token"); */
String projectId = request.getParameter("projectName");
String projectName = request.getParameter("projectName");
if (getScope() == "project") {
String chatRoomLink = communicationService.getProjectChatRoomLink(projectName);
writeIframe(request, chatRoomLink);
} else {
// scope is group
String chatRoomLink = communicationService
.getChatRoomLink(request.getSession().getAttribute(GFContexts.USEREMAIL).toString(), projectName);
writeIframe(request, chatRoomLink);
}
}
private void writeIframe(HttpServletRequest request, String chatRoomLink) throws IOException {
String getAuthToken = request.getSession().getAttribute(GFContexts.ROCKETCHATAUTHTOKEN).toString();
String chatRoomLink = communicationService.getChatRoomLink(request.getSession().getAttribute(GFContexts
.USEREMAIL).toString(), projectId);
log.debug("ChatRoomLink for ChatWindow: {}", chatRoomLink);
JspWriter out = getJspContext().getOut();
out.println("<iframe height=\"400px\" src=\"" + chatRoomLink + "\"/>");
out.println("<iframe height=\"400px\" src=\"" + chatRoomLink + "\">");
String rocketChatIntegration = "<script> window.parent.postMessage({event: 'login-with-token',loginToken:" +
" '"+getAuthToken+"'}, '"+GFRocketChatConfig.ROCKET_CHAT_LINK +"');</script>";
out.println(rocketChatIntegration);
out.println("</iframe>");
}
public void setOrientation(String orientation) {
......@@ -50,4 +72,12 @@ public class ChatWindow extends SimpleTagSupport {
public String getOrientation() {
return orientation;
}
public void setScope(String scope) {
this.scope = scope;
}
public String getScope() {
return scope;
}
}
let allTheTags = [];
let projectName = "";
var gfm = "";
/**
* Created by fides-WHK on 19.02.2018.
......@@ -36,7 +37,7 @@ function createNewProject(allTheTags, activ) {
if (allTheTags.length !== 5) {
$('#exactNumberOfTags').show();
} else {
createProjectinCompbase();
sendGroupPreferences();
}
}
......@@ -113,7 +114,7 @@ function getProjectValues() {
"timecreated" : 356122661234038,
"authorEmail": "vodka",
"adminPassword": adminPassword,
"phase" : "CourseCreation",
"phase" : "GroupFormation",
"tags": allTheTags
};
......@@ -150,7 +151,7 @@ function createProjectinCompbase() {
success: function (response) {
console.log(response);
// it actually worked, too
sendGroupPreferences();
document.location.href = "tasks-docent.jsp?projectName="+projectName;
},
error: function (a, b, c) {
console.log(a);
......@@ -159,3 +160,37 @@ function createProjectinCompbase() {
}
});
}
function sendGroupPreferences() {
gfm = $('input[name=gfm]:checked').val();
if (gfm == "Basierend auf Präferenzen") {
// TODO implement preference based group selection
gfm = "UserProfilStrategy";
} else if (gfm == "per Hand") {
gfm = "Manual";
} else if (gfm == "Basierend auf Lernzielen") {
gfm = "LearningGoalStrategy";
} else if(gfm == "Keine Gruppen") {
gfm = "SingleUser";
}
var localurl = "../../gemeinsamforschen/rest/group/gfm/create/projects/" + projectName;
$.ajax({
gfm: gfm,
url: localurl,
contentType: 'application/json',
type: 'POST',
data: gfm,
success: function (a, b, c) {
if (gfm == "LearningGoalStrategy") {
createProjectinCompbase();
}
document.location.href = "tasks-docent.jsp?projectName="+projectName;
return true;
},
error: function (a, b, c) {
return false;
}
});
}
var gfm = "";
function sendGroupPreferences() {
gfm = $('input[name=gfm]:checked').val();
if (gfm == "Basierend auf Präferenzen") {
// TODO implement preference based group selection
gfm = "UserProfilStrategy";
} else if (gfm == "per Hand") {
gfm = "Manual";
} else if (gfm == "Basierend auf Lernzielen") {
gfm = "LearningGoalStrategy";
} else if(gfm == "Keine Gruppen") {
gfm = "SingleUser";
}
var localurl = "../../gemeinsamforschen/rest/group/gfm/create/projects/" + projectName;
$.ajax({
gfm: gfm,
url: localurl,
contentType: 'application/json',
type: 'POST',
data: gfm,
success: function (a, b, c) {
/* if (gfm == "Manual") {
document.location.href = "../groupfinding/create-groups-manual.jsp" + "&projectName=" + projectToken;
}
if (gfm == "UserProfilStrategy") {
document.location.href = "../groupfinding/create-groups-preferences.jsp" + "&projectName=" + projectToken;
}
else {
document.location.href = "../groupfinding/create-groups-learninggoal.js.jsp" + "&projectName=" + projectToken;
}*/
document.location.href = "tasks-docent.jsp?projectName="+projectName;
return true;
},
error: function (a, b, c) {
return false;
}
});
}
\ No newline at end of file
......@@ -55,7 +55,7 @@
</div>
</script>
<chat:chatWindow orientation="right"></chat:chatWindow>
<chat:chatWindow orientation="right" scope="project"></chat:chatWindow>
</div>
<footer:footer/>
......
......@@ -62,6 +62,12 @@
<required>yes</required>
<rtexprvalue>no</rtexprvalue>
</attribute>
<attribute>
<name>scope</name>
<required>yes</required>
<rtexprvalue>no</rtexprvalue>
</attribute>
</tag>
</taglib>
\ No newline at end of file
......@@ -91,12 +91,12 @@ public class CommunicationServiceTest {
@Test
public void loginUser() {
assertTrue(iCommunication.loginUser(TEST_USER));
assertNotNull(iCommunication.loginUser(TEST_USER));
assertTrue(!TEST_USER.getRocketChatAuthToken().isEmpty());
assertTrue(!TEST_USER.getRocketChatUserId().isEmpty());
User falseLoginUser = new User("name", "password", "email", true);
assertFalse(iCommunication.loginUser(falseLoginUser));
assertNotNull(iCommunication.loginUser(falseLoginUser));
}
......@@ -282,7 +282,7 @@ public class CommunicationServiceTest {
/* try {
userService.login(true, user);
userService.register(true, user);
} catch (URISyntaxException e) {
Assert.fail();
}*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment