summaryrefslogtreecommitdiffstats
path: root/dozentenmodulserver/src/main/java/server/ServerHandler.java
diff options
context:
space:
mode:
Diffstat (limited to 'dozentenmodulserver/src/main/java/server/ServerHandler.java')
-rw-r--r--dozentenmodulserver/src/main/java/server/ServerHandler.java308
1 files changed, 155 insertions, 153 deletions
diff --git a/dozentenmodulserver/src/main/java/server/ServerHandler.java b/dozentenmodulserver/src/main/java/server/ServerHandler.java
index d9a663c4..0deb1037 100644
--- a/dozentenmodulserver/src/main/java/server/ServerHandler.java
+++ b/dozentenmodulserver/src/main/java/server/ServerHandler.java
@@ -34,19 +34,17 @@ import thrift.MasterThriftConnection;
//import thrift.SessionData;
import sql.SQL;
+
//import util.XMLCreator;
-public class ServerHandler implements Server.Iface
-{
-
+public class ServerHandler implements Server.Iface {
+
private static Logger log = Logger.getLogger(ServerHandler.class);
static SQL sql = new SQL();
private Map<String,UserInfo> tokenManager = new HashMap<>(); //saves the current tokens and the mapped userdata, returning from the server
-
-
-
+
public boolean authenticated(String token) throws TException
{
if(tokenManager.get(token) != null)
@@ -97,18 +95,15 @@ public class ServerHandler implements Server.Iface
return true;
}
return false;
- }
-
-
-
-
+ }
@Override
public User getFtpUser(String token) throws TException
{
if(authenticated(token))
{
+
log.info("returning FTPUser...");
User user = new User();
user.setUserName(UUID.randomUUID().toString().substring(0, 8));
@@ -119,7 +114,7 @@ public class ServerHandler implements Server.Iface
} else {
user.setPath(Configuration.config.getAbsolute_path() + "/");
}
-
+
// check if folder temp and folder prod exist
if (folderTempExists() == true && folderProdExists() == true) {
sql.writeFTPUser(user.getUserName(), user.getPassword());
@@ -130,12 +125,10 @@ public class ServerHandler implements Server.Iface
}
}
return null;
-
+
}
-
- public boolean folderTempExists()
- {
+ public boolean folderTempExists() {
// check if folder temp exists, otherwise create it
Path path = null;
if (Configuration.config.getAbsolute_path().endsWith("/")) {
@@ -145,15 +138,14 @@ public class ServerHandler implements Server.Iface
}
if (Files.exists(path) == true) {
- log.info("folder '" + path + "' exists, no further action");
+ log.info("folder '" + path + "' exists, no further action");
return true;
} else {
// create directory and set permissions
boolean success = (new File(path + "")).mkdirs();
if (!success) {
- log.info("failed to create folder '" + path
- + "'");
+ log.info("failed to create folder '" + path + "'");
return false;
} else {
// set permissions
@@ -162,13 +154,12 @@ public class ServerHandler implements Server.Iface
} catch (IOException e) {
e.printStackTrace();
}
- log.info("folder '" + path + "' successfully created");
+ log.info("folder '" + path + "' successfully created");
return true;
}
}
}// end folderTempExists()
-
public boolean folderProdExists() {
// check if folder temp exists, otherwise create it
@@ -180,15 +171,14 @@ public class ServerHandler implements Server.Iface
}
if (Files.exists(path) == true) {
- log.info("folder '" + path + "' exists, no further action");
+ log.info("folder '" + path + "' exists, no further action");
return true;
} else {
// create directory and set permissions
boolean success = (new File(path + "")).mkdirs();
if (!success) {
- log.info("failed to create folder '" + path
- + "'");
+ log.info("failed to create folder '" + path + "'");
return false;
} else {
// set permissions
@@ -197,15 +187,13 @@ public class ServerHandler implements Server.Iface
} catch (IOException e) {
e.printStackTrace();
}
- log.info("folder '" + path
- + "' successfully created");
+ log.info("folder '" + path + "' successfully created");
return true;
}
}
}// end folderProdExists()
-
public String getEncodedSha1Sum(String key) {
try {
MessageDigest md = MessageDigest.getInstance("SHA1");
@@ -220,10 +208,12 @@ public class ServerHandler implements Server.Iface
@Override
+
public long DeleteFtpUser(String user, String token) throws TException
{
if(authenticated(token))
{
+
return sql.DeleteUser(user);
}
return -1;
@@ -231,22 +221,24 @@ public class ServerHandler implements Server.Iface
@Override
+
public String getPathOfImage(String image_id, String version, String token) throws TException
{
if(authenticated(token))
{
log.info("successfully returned PathOfImage: " + sql.getPathOfImage(image_id, version));
+
return sql.getPathOfImage(image_id, version);
}
return null;
}
-
@Override
public String setInstitution(String university, String token) throws TException
{
if(authenticated(token))
{
+
return sql.setInstitution(university);
}
return null;
@@ -269,77 +261,79 @@ public class ServerHandler implements Server.Iface
} else {
mode = "to_be_published";
}
-
+
// String pk_institution = sql.setInstitution(university);
- // String pk_person = sql.setPerson(login, lastname, firstname, Mail,
+ // String pk_person = sql.setPerson(login, lastname, firstname,
+ // Mail,
// new Date(), pk_institution);
-
+
// OS impl Select and write
- // ACHTUNG: Anzahl der Leerzeichen muss eingehalten werden: 'Windows 7
+ // ACHTUNG: Anzahl der Leerzeichen muss eingehalten werden: 'Windows
+ // 7
// 32 bit"
- String pk_os = sql.getOSpk(os.substring(0, nthIndexOf(os, " ", 2)), os
- .substring(nthIndexOf(os, " ", 2), os.lastIndexOf(" "))
- .replace(" ", ""));
-
+ String pk_os = sql.getOSpk(os.substring(0, nthIndexOf(os, " ", 2)),
+ os.substring(nthIndexOf(os, " ", 2), os.lastIndexOf(" "))
+ .replace(" ", ""));
+
// sql.setImageData(pk_person, license, internet, cpu, ram,
// imagename,desc, imagePath, filesize,mode,pk_os);
-
-
-
+
sql.setImageData(userID, license, internet, cpu, ram, imagename, desc,
imagePath, filesize, mode, pk_os, uid);
log.info("userID in serverhandler was: "+userID);
+
log.info("written VLdata");
return true;
}
return false;
}
-
@Override
+
public List<Image> getImageListPermissionWrite(String userID, String token) throws TException
{
if(authenticated(token))
{
+
return sql.getImageListPermissionWrite(userID);
}
return null;
}
-
@Override
public List<Image> getImageListPermissionRead(String userID, String token) throws TException
{
if(authenticated(token))
{
+
return sql.getImageListPermissionRead(userID);
}
return null;
}
-
@Override
public List<Image> getImageListPermissionLink(String userID, String token) throws TException
{
if(authenticated(token))
{
+
return sql.getImageListPermissionLink(userID);
}
return null;
}
-
-
+
@Override
public List<Image> getImageListPermissionAdmin(String userID, String token) throws TException
{
if(authenticated(token))
{
+
return sql.getImageListPermissionAdmin(userID);
}
return null;
}
-
+
@Override
public List<Image> getImageListAllTemplates(String token) throws TException
{
@@ -349,7 +343,6 @@ public class ServerHandler implements Server.Iface
}
return null;
}
-
@Override
public List<String> getAllOS(String token) throws TException
@@ -365,14 +358,10 @@ public class ServerHandler implements Server.Iface
@Override
public Map<String, String> getPersonData(String Vorname, String Nachname, String token) throws TException
{
- /*
+
if(authenticated(token))
{
- return sql.getPersonData(Vorname, Nachname);
- }
- return null;
- */
-
+
Map<String, String> map = new HashMap<>();
UserInfo ui = getUserFromToken(token);
@@ -387,8 +376,10 @@ public class ServerHandler implements Server.Iface
map.put("Hochschule", tempMap.get("Hochschule"));
return map;
-
+ }
+ return null;
}
+
public void setPerson(String userID, String token, String institution) throws TException
{
@@ -419,19 +410,18 @@ public class ServerHandler implements Server.Iface
String pk_institution = sql.setInstitution(university);
String pk_person = sql.setPerson(ui.getEMail(), ui.getLastName(), ui.getFirstName(), ui.getEMail(),
new Date(), pk_institution);
-
+
map = sql.getImageIDandVersion(imageID);
-
- //pk_image = map.get("GUID");
+
+ // pk_image = map.get("GUID");
imageversion = Integer.parseInt(map.get("version"));
-
+
sql.setLectureData(pk_person, imageID, imageversion, name, desc,
shortdesc, startDate, endDate, isActive, lectureID);
}
- return false;
-
+ return false;
+
}
-
@Override
public boolean startFileCopy(String filename, String token) throws TException
@@ -442,18 +432,18 @@ public class ServerHandler implements Server.Iface
String file = Configuration.config.getAbsolute_path() + "temp/"
+ filename;
File tmpFile = new File(file);
-
+
log.info("Trying to move file to '/srv/openslx/nfs/prod/"
+ tmpFile.getName() + "'");
try {
FileUtils.moveFile(tmpFile,
- new File(Configuration.config.getAbsolute_path() + "prod/"
- + filename));
+ new File(Configuration.config.getAbsolute_path()
+ + "prod/" + filename));
// int ret = sql.UpdateImagePath(filename);
if (sql.UpdateImagePath(filename) == 0) {
log.info("file moved and database updated.");
}
-
+
} catch (IOException e) {
log.info("Failed to move file.");
e.printStackTrace();
@@ -479,20 +469,38 @@ public class ServerHandler implements Server.Iface
long cpu, String id, String version, boolean isTemplate,
long filesize, long shareMode, String os, String token) throws TException
{
- if(authenticated(token))
+
+ if (authenticated(token))
{
+
+ //get old_image_path
+ String old_image_path = sql.getFile(id, version);
+
String mode = null;
-
+
if (shareMode == 0) {
mode = "only_local";
} else {
mode = "to_be_published";
}
- String pk_os = sql.getOSpk(os.substring(0, nthIndexOf(os, " ", 2)), os
- .substring(nthIndexOf(os, " ", 2), os.lastIndexOf(" "))
- .replace(" ", ""));
- sql.UpdateImageData(name, newName, desc, image_path, license, internet,
- cpu, ram, id, version, isTemplate, filesize, mode, pk_os);
+ String pk_os = sql.getOSpk(os.substring(0, nthIndexOf(os, " ", 2)),
+ os.substring(nthIndexOf(os, " ", 2), os.lastIndexOf(" "))
+ .replace(" ", ""));
+
+ // do database update - if successful then delete old file from
+ // drive
+ int val = sql.UpdateImageData(name, newName, desc, image_path,
+ license, internet, cpu, ram, id, version, isTemplate,
+ filesize, mode, pk_os);
+
+ if (val == 0) {
+ // update was successful - delete old file
+ deleteImageByPath(old_image_path);
+ } else {
+ // update was not successful - delete new file
+ // TODO not yet implemented
+
+ }
}
return false;
}
@@ -521,7 +529,6 @@ public class ServerHandler implements Server.Iface
return null;
}// end getLectureListPermissionRead
-
@Override
public List<Lecture> getLectureListPermissionWrite(String token) throws TException
{
@@ -535,6 +542,7 @@ public class ServerHandler implements Server.Iface
}// end getLectureListPermissionRead
@Override
+
public List<Lecture> getLectureListPermissionAdmin(String token) throws TException
{
if(authenticated(token))
@@ -557,27 +565,13 @@ public class ServerHandler implements Server.Iface
{
UserInfo ui = getUserFromToken(token);
- Map<String, String> map = new HashMap<String, String>();
- map = sql.getDeleteXMLData(id);
sql.updateLectureData(imageid, imageversion, ui.getLastName(), newName, desc,
shortdesc, startDate, endDate, isActive, id);
-
- String path = Configuration.config.getAbsolute_path() + "prod/"
- + map.get("date").substring(0, map.get("date").length() - 2)
- + "_" + university + "_" + ui.getEMail() + "_" + map.get("name")
- + ".xml";
- File tmpFile = new File(path);
- try {
- FileUtils.forceDelete(tmpFile);
- } catch (IOException e1) {
- e1.printStackTrace();
- }
}
return false;
}
-
@Override
public boolean deleteImageServer(String imageid, String imageversion, String token) throws TException
{
@@ -585,24 +579,23 @@ public class ServerHandler implements Server.Iface
{
String stringFile = sql.getFile(imageid, imageversion);
log.info("File to Delete: " + stringFile);
-
+
File tmpFile = new File(Configuration.config.getAbsolute_path()
+ stringFile);
-
+
try {
// File wird von Server gelöscht
FileUtils.forceDelete(tmpFile);
return true;
-
+
} catch (IOException e) {
log.info("Failed to execute deleteImageServer.");
e.printStackTrace();
-
+
}
}
return false;
}
-
@Override
public boolean deleteImageData(String id, String version, String token) throws TException
@@ -620,6 +613,33 @@ public class ServerHandler implements Server.Iface
return success;
}
+//TODO
+public boolean deleteImageByPath(String image_path) throws TException{
+
+
+
+ //String stringFile = sql.getFile(imageid, imageversion);
+ log.info("File to Delete: " + image_path);
+
+ File tmpFile = new File(Configuration.config.getAbsolute_path()
+ + image_path);
+
+ try {
+ // File wird von Server gelöscht
+ FileUtils.forceDelete(tmpFile);
+ return true;
+
+ } catch (IOException e) {
+ log.info("Failed to execute deleteImageServer.");
+ e.printStackTrace();
+
+ }
+
+
+ return false;
+
+}
+
@Override
public boolean connectedToLecture(String id, String version, String token) throws TException
{
@@ -640,28 +660,16 @@ public class ServerHandler implements Server.Iface
if(authenticated(token))
{
- Map<String, String> map = new HashMap<String, String>();
- map = sql.getDeleteXMLData(id);
- try {
-
- String path = Configuration.config.getAbsolute_path()
- + "prod/"
- + map.get("date")
- .substring(0, map.get("date").length() - 2) + "_"
- + university + "_" + user + "_" + map.get("name") + ".xml";
- File xmlFile = new File(path);
- FileUtils.forceDelete(xmlFile);
- } catch (IOException e) {
- log.info("Failed to execute deleteLecture.");
- e.printStackTrace();
- }
-
- if(sql.deleteLecture(id) == true){
+ if(sql.deleteLecture(id) == true)
+ {
+
success = true;
- log.info("Lecture '"+id+"' and permissions successfully deleted.");
+ log.info("Lecture '" + id
+ + "' and permissions successfully deleted.");
}
}
return success;
+
}
@Override
@@ -679,7 +687,6 @@ public class ServerHandler implements Server.Iface
{
if(authenticated(token))
{
- //log.info("returning LectureData");
return sql.getLectureData(lectureid);
}
return null;
@@ -692,6 +699,7 @@ public class ServerHandler implements Server.Iface
for (int i = 0; i < index; i++)
{
j = string.indexOf(searchToken, j + 1);
+
if (j == -1)
break;
}
@@ -734,13 +742,13 @@ public class ServerHandler implements Server.Iface
Map<String, String> map = new HashMap<String, String>();
String pk_institution = sql.setInstitution(university);
+
String pk_person = sql.setPerson(userID, ui.getLastName(), ui.getFirstName(), ui.getEMail(), new Date(), pk_institution);
map = sql.getImageIDandVersion(imageID);
-
-
+
pk_image = map.get("GUID");
-
+
if (role.equals("Dozent")) {
int read = 1;
int write = 1;
@@ -748,10 +756,10 @@ public class ServerHandler implements Server.Iface
int admin = 1;
int linkallowed = 1;
int roleID = sql.getRoleID(role);
-
- sql.setImageRights(pk_person, pk_image, roleID, read, write, admin,
- linkallowed);
-
+
+ sql.setImageRights(pk_person, pk_image, roleID, read, write,
+ admin, linkallowed);
+
} else if (role.equals("Admin")) {
int read = 1;
int write = 1;
@@ -759,9 +767,9 @@ public class ServerHandler implements Server.Iface
int admin = 1;
int linkallowed = 1;
int roleID = sql.getRoleID(role);
-
- sql.setImageRights(pk_person, pk_image, roleID, read, write, admin,
- linkallowed);
+
+ sql.setImageRights(pk_person, pk_image, roleID, read, write,
+ admin, linkallowed);
} else {
int read = 1;
int write = 0;
@@ -769,11 +777,11 @@ public class ServerHandler implements Server.Iface
int admin = 0;
int linkallowed = 0;
int roleID = sql.getRoleID(role);
-
- sql.setImageRights(pk_person, pk_image, roleID, read, write, admin,
- linkallowed);
+
+ sql.setImageRights(pk_person, pk_image, roleID, read, write,
+ admin, linkallowed);
}
-
+
log.info("Written image rights");
return true;
}
@@ -797,17 +805,17 @@ public class ServerHandler implements Server.Iface
// int changePermission=0;
int admin = 1;
int roleID = sql.getRoleID(role);
-
+
sql.setLectureRights(pk_person, lectureID, roleID, read, write,
admin);
-
+
} else if (role.equals("Admin")) {
int read = 1;
int write = 1;
// int changePermission=1;
int admin = 1;
int roleID = sql.getRoleID(role);
-
+
sql.setLectureRights(pk_person, lectureID, roleID, read, write,
admin);
} else {
@@ -816,11 +824,11 @@ public class ServerHandler implements Server.Iface
// int changePermission=0;
int admin = 0;
int roleID = sql.getRoleID(role);
-
+
sql.setLectureRights(pk_person, lectureID, roleID, read, write,
admin);
}
-
+
return true;
}
return false;
@@ -837,7 +845,7 @@ public class ServerHandler implements Server.Iface
return null;
}
- //set permissions for users which are !=userID
+ // set permissions for users which are !=userID
public boolean writeAdditionalImageRights(String imageID, String userID,
boolean isRead, boolean isWrite, boolean isLinkAllowed,
boolean isAdmin, String token) throws TException
@@ -845,31 +853,29 @@ public class ServerHandler implements Server.Iface
boolean success = false;
if(authenticated(token))
{
-
Map<String, String> map = new HashMap<String, String>();
map = sql.getImageIDandVersion(imageID);
- //String imageID = map.get("GUID");
-
+ // String imageID = map.get("GUID");
+
sql.writeAdditionalImageRights(imageID, userID, isRead, isWrite,
isLinkAllowed, isAdmin);
- log.info("Written additional image rights for " + userID);
+ log.info("Written additional image rights for " + userID);
}
return success;
}
-
public boolean writeAdditionalLectureRights(String lectureID,
String userID, boolean isRead, boolean isWrite, boolean isAdmin, String token) throws TException
{
if(authenticated(token))
{
Map<String, String> map = new HashMap<String, String>();
- //String lectureID = sql.getLectureID(lectureID);
-
- sql.writeAdditionalLectureRights(lectureID, userID, isRead, isWrite,
- isAdmin);
- log.info("Written additional lecture rights for "+ userID);
-
+ // String lectureID = sql.getLectureID(lectureID);
+
+ sql.writeAdditionalLectureRights(lectureID, userID, isRead,
+ isWrite, isAdmin);
+ log.info("Written additional lecture rights for " + userID);
+
return true;
}
return false;
@@ -886,6 +892,7 @@ public class ServerHandler implements Server.Iface
return null;
}
+
public List<Person> getPermissionForUserAndLecture(String token,String lectureID, String userID) throws TException
{
if(authenticated(token))
@@ -915,17 +922,17 @@ public class ServerHandler implements Server.Iface
UserInfo ui = getUserFromToken(token);
sql.deleteAllAdditionalLecturePermissions(lectureID, userID);
}
-
+
return;
}
+
@Override
- public List<Image> getImageList(String token) throws TException
+ public List<Image> getImageList(String userID, String token) throws TException
{
- UserInfo ui = getUserFromToken(token);
if(authenticated(token))
{
- return sql.getImageList(ui.getEMail());
+ return sql.getImageList(userID);
}
return null;
}
@@ -951,7 +958,6 @@ public class ServerHandler implements Server.Iface
}
@Override
-
public String createRandomUUID(String token) throws TException
{
if(authenticated(token))
@@ -971,8 +977,6 @@ public class ServerHandler implements Server.Iface
}
-
-
@Override
public boolean userIsImageAdmin(String imageID, String token, String userID)
throws TException {
@@ -983,17 +987,17 @@ public class ServerHandler implements Server.Iface
return sql.userIsImageAdmin(userID,imageID);
}
return false;
-
- }
-
+ }
@Override
public boolean userIsLectureAdmin(String userID, String lectureID, String token)
throws TException {
+
if(authenticated(token))
{
return sql.userIsLectureAdmin(userID,lectureID);
+
}
return false;
}
@@ -1007,6 +1011,4 @@ public class ServerHandler implements Server.Iface
-
-
}// end class