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

refactoring: switching to dependency injection and fixing tests

parent d46f0ea2
No related branches found
No related tags found
No related merge requests found
Showing
with 44 additions and 42 deletions
......@@ -27,12 +27,23 @@ public class ProjectDAO {
connect.connect();
String mysqlRequest =
"INSERT INTO projects (`name`, `password`, `active`, `timecreated`, `author`, "
+ "`adminPassword`, `phase`) values (?,?,?,?,?,?,?)";
"INSERT INTO projects (`name`, `password`, `active`, `timecreated`, `author`, " + "`adminPassword`, `phase`) values (?,?,?,?,?,?,?)";
connect.issueInsertOrDeleteStatement(mysqlRequest, project.getName(), project.getPassword(), project.isActive(),
project.getTimecreated(), project.getAuthorEmail(), project.getAdminPassword(), project.getPhase()
== null ? ProjectPhase.CourseCreation : project.getPhase());
project.getTimecreated(), project.getAuthorEmail(), project.getAdminPassword(),
project.getPhase() == null ? ProjectPhase.CourseCreation : project.getPhase());
connect.close();
connect.connect();
String[] tags = project.getTags();
for (String tag : tags) {
connect.issueInsertOrDeleteStatement(
"INSERT INTO tags (`projectName`, `tag`) values (?,?)", project.getName(), tag);
}
connect.close();
}
public void delete(Project project) {
......@@ -58,8 +69,7 @@ public class ProjectDAO {
public Project getProjectByName(String name) {
connect.connect();
String mysqlRequest = "SELECT * FROM projects where name = ?";
VereinfachtesResultSet vereinfachtesResultSet =
connect.issueSelectStatement(mysqlRequest, name);
VereinfachtesResultSet vereinfachtesResultSet = connect.issueSelectStatement(mysqlRequest, name);
boolean next = vereinfachtesResultSet.next();
Project result = getProject(vereinfachtesResultSet, next);
List<String> tags = getTags(result);
......@@ -94,8 +104,7 @@ public class ProjectDAO {
public java.util.List<String> getTags(Project project) {
connect.connect();
String mysqlRequest =
"SELECT t.tag from tags t where t.projectName = ?";
String mysqlRequest = "SELECT t.tag from tags t where t.projectName = ?";
VereinfachtesResultSet vereinfachtesResultSet = connect.issueSelectStatement(mysqlRequest, project.getName());
java.util.List<String> result = new ArrayList<>();
......@@ -104,6 +113,6 @@ public class ProjectDAO {
result.add(vereinfachtesResultSet.getString("tag"));
}
connect.close();
return result;
return result;
}
}
......@@ -48,23 +48,21 @@ public class ProjectView {
}
@GET
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.APPLICATION_JSON)
@Path("/all/author/{userEmail}")
public java.util.List<String> getProjects(
public String[] getProjects(
@PathParam("userEmail") String authorToken) {
java.util.List<String> projects = iManagement.getProjects(authorToken);
return projects;
return projects.toArray(new String[0]);
}
@GET
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.APPLICATION_JSON)
@Path("/all/student/{studentEmail}")
public java.util.List<String> getProjectsStudent(
public String[] getProjectsStudent(
@PathParam("studentEmail") String studentEmail) {
return iManagement.getProjectsStudent(studentEmail);
return iManagement.getProjectsStudent(studentEmail).toArray(new String[0]);
}
@GET
......
......@@ -19,6 +19,7 @@
<div class="sk-cube3 sk-cube"></div>
</div>
<div id="wrapper" class="wrapper">
<menu:menu hierarchy="1"></menu:menu>
<div class="page-content-wrapper">
<div class="container-fluid"><a class="btn btn-link" role="button" href="#menu-toggle" id="menu-toggle"></a>
<div class="row">
......
......@@ -2,14 +2,11 @@
* Created by fides-WHK on 15.03.2018.
*/
$(document).ready(function () {
printTags();
$("#competencies0").focus();
$("#studentFormSubmit").on("click", function () {
getContextData(takesPartInProject);
takesPartInProject();
});
$("#addCompetenceButton").on("click", function () {
addInput("competencies"); //creates a new input-Field with the ID 'competenciesX' where X is number of elements with 'competencies' as ID
......@@ -29,13 +26,13 @@ $(document).ready(function () {
function addInput(name) { //creates a new input-Field with the ID 'nameX' where X is number of elements with 'name' as ID
var i = document.getElementsByName(name).length;
let div = document.getElementById(name);
var newInput = document.createElement("span");
newInput.innerHTML = "<input class='form-control' " +
"type='text' " +
"name='" + name + "' " +
"id='" + name + i + "' " +
"style='max-width:417px;margin-left:14px;padding-top:10px;margin-top:2px;margin-bottom:13px;'>";
var div = document.getElementById(name);
div.appendChild(newInput);
}
......@@ -119,8 +116,8 @@ function takesPartInProject(context) {
};
var userEmail = context.user.email;
var projectName = context.project.id;
var userEmail = getUserEmail();
var projectName = getProjectName();
var dataString = JSON.stringify(data); //to send correctly, data needs to be stringified
var url = compbaseUrl + "/api2/user/" + userEmail + "/projects/" + projectName + "/preferences";
$.ajax({
......@@ -133,7 +130,7 @@ function takesPartInProject(context) {
console.log(response);
document.getElementById('loader').className = "loader-inactive";
document.getElementById('wrapper').className = "wrapper";
location.href = "../overview-student.jsp" + getUserEmail();
location.href = "../project/overview-student.jsp";
},
error: function (a, b, c) {
console.log(a);
......
/**
* Created by fides-WHK on 09.01.2018.
*/
var projectName = "";
$(document).ready(function () {
$("#projectWrongPassword").hide();
$("#projectIsMissing").hide();
......@@ -16,11 +19,12 @@ $(document).ready(function () {
}
});
$("#loginProject").on('click', function () {
loginProject($('#projectName').val());
projectName = $('#projectName').val();
loginProject();
});
});
function loginProject(projectName) {
function loginProject() {
var password = $('#projectPassword').val();
var url = "../../gemeinsamforschen/rest/project/login/"+projectName+"?password="+password;
if (projectName === "") {
......@@ -37,7 +41,7 @@ function loginProject(projectName) {
} else {
if (response !== "wrong password") { //if response !== project missing and not wrong password, its the projectName
var projectToken = response;
document.location.href = "../groupfinding/enter-preferences.jsp"+"&projectName="+projectToken;
document.location.href = "../groupfinding/enter-preferences.jsp?projectName="+projectName;
} else {
$("#projectIsMissing").hide();
$('#projectWrongPassword').show();
......
......@@ -8,7 +8,7 @@ $(document).ready(function(){
function updateStatus(projectName){
$.ajax({
url: 'rest/phases/projects/'+projectName,
url: '../rest/phases/projects/'+projectName,
headers: {
"Content-Type": "application/json",
"Cache-Control": "no-cache"
......@@ -49,7 +49,7 @@ function updateStatus(projectName){
function getGrade(projectName){
let userName = $('#userEmail').html().trim();
$.ajax({
url: 'rest/assessments/get/project/'+projectName+'/student/'+userName,
url: '../rest/assessments/get/project/'+projectName+'/student/'+userName,
headers: {
"Content-Type": "application/json",
"Cache-Control": "no-cache"
......@@ -65,7 +65,7 @@ function getGrade(projectName){
function getProjects(userName){
$.ajax({
url: 'rest/project/all/student/' + userName,
url: '../rest/project/all/student/' + userName,
headers: {
"Content-Type": "text/plain",
"Cache-Control": "no-cache"
......
......@@ -7,13 +7,13 @@
<html>
<head>
<omniDependencies:omniDependencies hierarchy="0"/>
<omniDependencies:omniDependencies hierarchy="1"/>
<script src="js/overview-student.js"></script>
</head>
<body>
<div id="wrapper">
<menu:menu hierarchy="0"/>
<menu:menu hierarchy="1"/>
<div class="page-content-wrapper">
<headLine:headLine/>
<div>
......
......@@ -18,8 +18,7 @@
<menu:menu hierarchy="1"/>
<div class="page-content-wrapper">
<headLine:headLine/>
<button
class="btn btn-default" type="button">Exportiere Zwischenstand
<button class="btn btn-default" type="button">Exportiere Zwischenstand
</button>
<button class="btn btn-default" type="button">Quizfrage erstellen</button>
<div>
......
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%--suppress XmlDuplicatedId --%>
<%@ taglib uri="../taglibs/gemeinsamForschen.tld" prefix="menu" %>
<%@ taglib uri="../taglibs/gemeinsamForschen.tld" prefix="headLine" %>
<%@ taglib uri="../taglibs/gemeinsamForschen.tld" prefix="omniDependencies" %>
<%@ taglib uri="../taglibs/gemeinsamForschen.tld" prefix="footer" %>
<!--todo: E-mail an Studenten als Notifikation für Phasenwechsel -->
<!DOCTYPE html>
<html>
<head>
<omniDependencies:omniDependencies hierarchy="0"/>
<omniDependencies:omniDependencies hierarchy="1"/>
<script src="js/project-student.js"></script>
</head>
<body>
<div id="wrapper">
<menu:menu hierarchy="0"/>
<menu:menu hierarchy="1"/>
<div class="page-content-wrapper">
<headLine:headLine/>
......
......@@ -65,7 +65,7 @@ function getUserEmail() {
function getProjectName() {
return $('#projectName').html().trim();
return getQueryVariable("projectName");
}
function getQueryVariable(variable) {
......
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