summaryrefslogtreecommitdiffstats
path: root/dozentenmodulserver/src/main/java/server/ServerHandler.java
diff options
context:
space:
mode:
authorMichael Wilson2014-11-26 15:12:06 +0100
committerMichael Wilson2014-11-26 15:12:06 +0100
commit03a8d5c38261e0663327d2c6fe454956126d8136 (patch)
tree69cd1ef7b752e264ace74b2952d58a3d15643061 /dozentenmodulserver/src/main/java/server/ServerHandler.java
parent• Prozess "Erstellen eines Image" kann nun direkt weiterleiten zu "Erstellen ... (diff)
downloadtutor-module-03a8d5c38261e0663327d2c6fe454956126d8136.tar.gz
tutor-module-03a8d5c38261e0663327d2c6fe454956126d8136.tar.xz
tutor-module-03a8d5c38261e0663327d2c6fe454956126d8136.zip
• Image update now removes old file and avoids zombies
Diffstat (limited to 'dozentenmodulserver/src/main/java/server/ServerHandler.java')
-rw-r--r--dozentenmodulserver/src/main/java/server/ServerHandler.java674
1 files changed, 310 insertions, 364 deletions
diff --git a/dozentenmodulserver/src/main/java/server/ServerHandler.java b/dozentenmodulserver/src/main/java/server/ServerHandler.java
index 820169d7..11f7d3ab 100644
--- a/dozentenmodulserver/src/main/java/server/ServerHandler.java
+++ b/dozentenmodulserver/src/main/java/server/ServerHandler.java
@@ -32,31 +32,25 @@ 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();
Client client = null;
-
- public void setTokenForSession(String token)
- {
+ public void setTokenForSession(String token) {
SessionData.session.setAuthToken(token);
}
-
-
-
- public boolean authenticated() throws InvalidTokenException
- {
+
+ public boolean authenticated() throws InvalidTokenException {
MasterThriftConnection thrift = new MasterThriftConnection();
client = thrift.getMasterThriftConnection();
try {
- if(client.getUserFromToken(SessionData.session.getAuthToken()) != null)
- {
- return true;
+ if (client.getUserFromToken(SessionData.session.getAuthToken()) != null) {
+ return true;
}
} catch (TException e) {
// TODO Auto-generated catch block
@@ -66,14 +60,9 @@ public class ServerHandler implements Server.Iface
return false;
}
-
-
-
@Override
- public User getFtpUser() throws TException
- {
- if(authenticated())
- {
+ public User getFtpUser() throws TException {
+ if (authenticated()) {
log.info("returning FTPUser...");
User user = new User();
user.setUserName(UUID.randomUUID().toString().substring(0, 8));
@@ -84,7 +73,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());
@@ -95,12 +84,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("/")) {
@@ -110,15 +97,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
@@ -127,13 +113,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
@@ -145,15 +130,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,15 +146,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");
@@ -184,33 +166,29 @@ public class ServerHandler implements Server.Iface
}
@Override
- public long DeleteFtpUser(String user) throws TException
- {
- if(authenticated())
- {
+ public long DeleteFtpUser(String user) throws TException {
+ if (authenticated()) {
return sql.DeleteUser(user);
}
return -1;
}
@Override
- public String getPathOfImage(String image_id, String version) throws TException
- {
- if(authenticated())
- {
- log.info("successfully returned PathOfImage: " + sql.getPathOfImage(image_id, version));
+ public String getPathOfImage(String image_id, String version)
+ throws TException {
+ if (authenticated()) {
+ log.info("successfully returned PathOfImage: "
+ + sql.getPathOfImage(image_id, version));
return sql.getPathOfImage(image_id, version);
}
return null;
}
-
@Override
- public String setInstitution(String university) throws InvalidTokenException
- {
- if(authenticated())
- {
- return sql.setInstitution(university);
+ public String setInstitution(String university)
+ throws InvalidTokenException {
+ if (authenticated()) {
+ return sql.setInstitution(university);
}
return null;
}
@@ -220,176 +198,158 @@ public class ServerHandler implements Server.Iface
String firstname, String lastname, String university, String Mail,
String Tel, String Fak, boolean license, boolean internet,
long ram, long cpu, String imagePath, boolean isTemplate,
- long filesize, long shareMode, String os, String uid) throws TException
- {
-
- if(authenticated())
- {
+ long filesize, long shareMode, String os, String uid)
+ throws TException {
+
+ if (authenticated()) {
String mode = null;
-
+
if (shareMode == 0) {
mode = "only_local";
} 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(login, license, internet, cpu, ram, imagename, desc,
- imagePath, filesize, mode, pk_os, uid);
-
+
+ sql.setImageData(login, license, internet, cpu, ram, imagename,
+ desc, imagePath, filesize, mode, pk_os, uid);
+
log.info("written VLdata");
return true;
}
return false;
}
-
@Override
- public List<Image> getImageListPermissionWrite(String userID) throws TException
- {
- if(authenticated())
- {
+ public List<Image> getImageListPermissionWrite(String userID)
+ throws TException {
+ if (authenticated()) {
return sql.getImageListPermissionWrite(userID);
}
return null;
}
-
@Override
- public List<Image> getImageListPermissionRead(String userID) throws TException
- {
- if(authenticated())
- {
+ public List<Image> getImageListPermissionRead(String userID)
+ throws TException {
+ if (authenticated()) {
return sql.getImageListPermissionRead(userID);
}
return null;
}
-
@Override
- public List<Image> getImageListPermissionLink(String userID) throws TException
- {
- if(authenticated())
- {
+ public List<Image> getImageListPermissionLink(String userID)
+ throws TException {
+ if (authenticated()) {
return sql.getImageListPermissionLink(userID);
}
return null;
}
-
-
+
@Override
- public List<Image> getImageListPermissionAdmin(String userID) throws TException
- {
- if(authenticated())
- {
+ public List<Image> getImageListPermissionAdmin(String userID)
+ throws TException {
+ if (authenticated()) {
return sql.getImageListPermissionAdmin(userID);
}
return null;
}
-
+
@Override
- public List<Image> getImageListAllTemplates() throws TException
- {
- if(authenticated())
- {
+ public List<Image> getImageListAllTemplates() throws TException {
+ if (authenticated()) {
return sql.getImageListAllTemplates();
}
return null;
}
-
@Override
- public List<String> getAllOS() throws TException
- {
- if(authenticated())
- {
+ public List<String> getAllOS() throws TException {
+ if (authenticated()) {
return sql.getAllOS();
}
return null;
}
@Override
- public Map<String, String> getPersonData(String Vorname, String Nachname) throws TException
- {
- if(authenticated())
- {
+ public Map<String, String> getPersonData(String Vorname, String Nachname)
+ throws TException {
+ if (authenticated()) {
return sql.getPersonData(Vorname, Nachname);
}
return null;
}
- public void setPerson(String login, String lastname, String firstname,String mail, String Institution) throws InvalidTokenException
- {
- if(authenticated())
- {
- sql.setPerson(login, lastname, firstname, mail, new Date(), Institution);
+ public void setPerson(String login, String lastname, String firstname,
+ String mail, String Institution) throws InvalidTokenException {
+ if (authenticated()) {
+ sql.setPerson(login, lastname, firstname, mail, new Date(),
+ Institution);
}
}
@Override
public boolean writeLecturedata(String name, String shortdesc, String desc,
- String startDate, String endDate, boolean isActive,
- String imageID, String login, String firstname, String lastname,
- String university, String Mail, String Tel, String Fak, String lectureID)
- throws TException
- {
- if(authenticated())
- {
-
- //String pk_image = imageID;
+ String startDate, String endDate, boolean isActive, String imageID,
+ String login, String firstname, String lastname, String university,
+ String Mail, String Tel, String Fak, String lectureID)
+ throws TException {
+ if (authenticated()) {
+
+ // String pk_image = imageID;
Map<String, String> map = new HashMap<String, String>();
int imageversion = 0;
String pk_institution = sql.setInstitution(university);
String pk_person = sql.setPerson(login, lastname, firstname, Mail,
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) throws TException
- {
- if(authenticated())
- {
+ public boolean startFileCopy(String filename) throws TException {
+ if (authenticated()) {
// copy file from folder temp to folder prod
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();
@@ -399,11 +359,11 @@ public class ServerHandler implements Server.Iface
}
@Override
- public Map<String, String> getImageData(String imageid, String imageversion) throws TException
- {
- if(authenticated())
- {
- //log.info("returning ImageData: "+ sql.getImageData(imageid, imageversion).size() + "items.");
+ public Map<String, String> getImageData(String imageid, String imageversion)
+ throws TException {
+ if (authenticated()) {
+ // log.info("returning ImageData: "+ sql.getImageData(imageid,
+ // imageversion).size() + "items.");
return sql.getImageData(imageid, imageversion);
}
return null;
@@ -413,90 +373,97 @@ public class ServerHandler implements Server.Iface
public boolean updateImageData(String name, String newName, String desc,
String image_path, boolean license, boolean internet, long ram,
long cpu, String id, String version, boolean isTemplate,
- long filesize, long shareMode, String os) throws TException
- {
- if(authenticated())
- {
+ long filesize, long shareMode, String os) throws TException {
+
+ if (authenticated()) {
+
+ //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;
}
@Override
- public List<Lecture> getLectureList() throws TException
- {
- if(authenticated())
- {
- //log.info("returning LectureList");
+ public List<Lecture> getLectureList() throws TException {
+ if (authenticated()) {
+ // log.info("returning LectureList");
return sql.getLectureList();
}
return null;
}
@Override
- public List<Lecture> getLectureListPermissionRead(String userID) throws InvalidTokenException
- {
- if(authenticated())
- {
- //log.info("returning LectureListRead");
+ public List<Lecture> getLectureListPermissionRead(String userID)
+ throws InvalidTokenException {
+ if (authenticated()) {
+ // log.info("returning LectureListRead");
return sql.getLectureListPermissionRead(userID);
}
return null;
}// end getLectureListPermissionRead
-
@Override
- public List<Lecture> getLectureListPermissionWrite(String userID) throws InvalidTokenException
- {
- if(authenticated())
- {
- //log.info("returning LectureListWrite");
+ public List<Lecture> getLectureListPermissionWrite(String userID)
+ throws InvalidTokenException {
+ if (authenticated()) {
+ // log.info("returning LectureListWrite");
return sql.getLectureListPermissionWrite(userID);
}
return null;
}// end getLectureListPermissionRead
@Override
- public List<Lecture> getLectureListPermissionAdmin(String userID) throws InvalidTokenException
- {
- if(authenticated())
- {
- //log.info("returning LectureListAdmin");
+ public List<Lecture> getLectureListPermissionAdmin(String userID)
+ throws InvalidTokenException {
+ if (authenticated()) {
+ // log.info("returning LectureListAdmin");
return sql.getLectureListPermissionAdmin(userID);
}
return null;
}// end getLectureListPermissionRead
-
@Override
public boolean updateLecturedata(String name, String newName,
String shortdesc, String desc, String startDate, String endDate,
boolean isActive, String imageid, String imageversion, String user,
String firstname, String lastname, String university, String Mail,
- String Tel, String Fak, String id) throws TException
- {
- if(authenticated())
- {
+ String Tel, String Fak, String id) throws TException {
+ if (authenticated()) {
Map<String, String> map = new HashMap<String, String>();
map = sql.getDeleteXMLData(id);
- sql.updateLectureData(imageid, imageversion, lastname, 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 + "_" + user + "_" + map.get("name")
- + ".xml";
+ sql.updateLectureData(imageid, imageversion, lastname, 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 + "_" + user + "_" + map.get("name") + ".xml";
File tmpFile = new File(path);
try {
FileUtils.forceDelete(tmpFile);
@@ -507,119 +474,133 @@ public class ServerHandler implements Server.Iface
return false;
}
-
@Override
- public boolean deleteImageServer(String imageid, String imageversion) throws TException
- {
- if(authenticated())
- {
+ public boolean deleteImageServer(String imageid, String imageversion)
+ throws TException {
+ if (authenticated()) {
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) throws TException
- {
- boolean success=false;
+ public boolean deleteImageByPath(String image_path){
+
+ try {
+ if (authenticated()) {
+ //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();
+
+ }
+ }
+ } catch (InvalidTokenException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return false;
- if(authenticated())
- {
- if(sql.deleteImage(id, version)==true)
- {
- success=true;
- log.info("Image '"+id+"' and permissions successfully deleted.");
+ }
+
+
+ @Override
+ public boolean deleteImageData(String id, String version) throws TException {
+ boolean success = false;
+
+ if (authenticated()) {
+ if (sql.deleteImage(id, version) == true) {
+ success = true;
+ log.info("Image '" + id
+ + "' and permissions successfully deleted.");
}
}
return success;
}
@Override
- public boolean connectedToLecture(String id, String version) throws TException
- {
- if(authenticated())
- {
+ public boolean connectedToLecture(String id, String version)
+ throws TException {
+ if (authenticated()) {
return sql.connectedToLecture(id, version);
}
return true;
}
- public boolean deleteLecture(String id, String hs, String user) throws InvalidTokenException
- {
+ public boolean deleteLecture(String id, String hs, String user)
+ throws InvalidTokenException {
boolean success = false;
-
-
- if(authenticated())
- {
+
+ if (authenticated()) {
/*
- 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) + "_"
- + hs + "_" + 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){
+ * 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) + "_"
+ * + hs + "_" + 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) {
success = true;
- log.info("Lecture '"+id+"' and permissions successfully deleted.");
+ log.info("Lecture '" + id
+ + "' and permissions successfully deleted.");
}
}
return success;
-
+
}
@Override
- public List<String> getAllUniversities() throws TException
- {
- if(authenticated())
- {
+ public List<String> getAllUniversities() throws TException {
+ if (authenticated()) {
return sql.getAllUniversities();
}
return null;
}
@Override
- public Map<String, String> getLectureData(String lectureid) throws TException
- {
- if(authenticated())
- {
- //log.info("returning LectureData");
+ public Map<String, String> getLectureData(String lectureid)
+ throws TException {
+ if (authenticated()) {
+ // log.info("returning LectureData");
return sql.getLectureData(lectureid);
}
return null;
}
- public static int nthIndexOf(final String string, final String token,final int index)
- {
+ public static int nthIndexOf(final String string, final String token,
+ final int index) {
int j = 0;
- for (int i = 0; i < index; i++)
- {
+ for (int i = 0; i < index; i++) {
j = string.indexOf(token, j + 1);
if (j == -1)
break;
@@ -629,10 +610,8 @@ public class ServerHandler implements Server.Iface
}
@Override
- public boolean checkUser(String username) throws TException
- {
- if(authenticated())
- {
+ public boolean checkUser(String username) throws TException {
+ if (authenticated()) {
return sql.checkUser(username);
}
return false;
@@ -640,12 +619,12 @@ public class ServerHandler implements Server.Iface
}
@Override
- public boolean createUser(String loginName, String lastName,String firstName, String mail, String university) throws TException
- {
- if(authenticated())
- {
+ public boolean createUser(String loginName, String lastName,
+ String firstName, String mail, String university) throws TException {
+ if (authenticated()) {
String pk_institution = sql.setInstitution(university);
- String pk_person = sql.setPerson(loginName, lastName, firstName, mail, new Date(), pk_institution);
+ String pk_person = sql.setPerson(loginName, lastName, firstName,
+ mail, new Date(), pk_institution);
return true;
}
return false;
@@ -654,23 +633,20 @@ public class ServerHandler implements Server.Iface
@Override
public boolean writeImageRights(String imageID, String username,
String lastName, String firstName, String mail, String university,
- String role) throws TException
- {
- if(authenticated())
- {
+ String role) throws TException {
+ if (authenticated()) {
String pk_image = null;
Map<String, String> map = new HashMap<String, String>();
int imageversion = 0;
String pk_institution = sql.setInstitution(university);
- String pk_person = sql.setPerson(username, lastName, firstName, mail,
- new Date(), pk_institution);
-
+ String pk_person = sql.setPerson(username, lastName, firstName,
+ mail, new Date(), pk_institution);
+
map = sql.getImageIDandVersion(imageID);
-
-
+
pk_image = map.get("GUID");
imageversion = Integer.parseInt(map.get("version"));
-
+
if (role.equals("Dozent")) {
int read = 1;
int write = 1;
@@ -678,10 +654,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;
@@ -689,9 +665,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;
@@ -699,11 +675,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;
}
@@ -713,34 +689,32 @@ public class ServerHandler implements Server.Iface
@Override
public boolean writeLectureRights(String lectureID, String username,
String lastName, String firstName, String mail, String university,
- String role) throws TException
- {
- if(authenticated())
- {
- //String pk_lecture = null;
-
+ String role) throws TException {
+ if (authenticated()) {
+ // String pk_lecture = null;
+
String pk_institution = sql.setInstitution(university);
- String pk_person = sql.setPerson(username, lastName, firstName, mail,
- new Date(), pk_institution);
- //pk_lecture = sql.getLectureID(lectureID);
-
+ String pk_person = sql.setPerson(username, lastName, firstName,
+ mail, new Date(), pk_institution);
+ // pk_lecture = sql.getLectureID(lectureID);
+
if (role.equals("Dozent")) {
int read = 1;
int write = 1;
// 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 {
@@ -749,60 +723,55 @@ 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;
}
@Override
- public List<Person> getAllOtherSatelliteUsers(List<String> userID) throws TException
- {
- if(authenticated())
- {
+ public List<Person> getAllOtherSatelliteUsers(List<String> userID)
+ throws TException {
+ if (authenticated()) {
return sql.getAllOtherSatelliteUsers(userID);
// return null;
}
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) throws InvalidTokenException
- {
+ boolean isAdmin) throws InvalidTokenException {
boolean success = false;
- if(authenticated())
- {
+ if (authenticated()) {
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) throws InvalidTokenException
- {
- if(authenticated())
- {
+ String userID, boolean isRead, boolean isWrite, boolean isAdmin)
+ throws InvalidTokenException {
+ if (authenticated()) {
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;
@@ -810,122 +779,99 @@ public class ServerHandler implements Server.Iface
@Override
public List<Person> getPermissionForUserAndImage(String userID,
- String imageID) throws TException
- {
- if(authenticated())
- {
+ String imageID) throws TException {
+ if (authenticated()) {
return sql.getPermissionForUserAndImage(userID, imageID);
}
return null;
}
- public List<Person> getPermissionForUserAndLecture(String userID,String lectureID) throws InvalidTokenException
- {
- if(authenticated())
- {
+ public List<Person> getPermissionForUserAndLecture(String userID,
+ String lectureID) throws InvalidTokenException {
+ if (authenticated()) {
return sql.getPermissionForUserAndLecture(userID, lectureID);
}
return null;
}
@Override
- public void deleteAllAdditionalImagePermissions(String imageID,String userID) throws TException
- {
- if(authenticated())
- {
+ public void deleteAllAdditionalImagePermissions(String imageID,
+ String userID) throws TException {
+ if (authenticated()) {
sql.deleteAllAdditionalImagePermissions(imageID, userID);
}
return;
}
@Override
- public void deleteAllAdditionalLecturePermissions(String lectureID,String userID) throws TException
- {
- if(authenticated())
- {
+ public void deleteAllAdditionalLecturePermissions(String lectureID,
+ String userID) throws TException {
+ if (authenticated()) {
sql.deleteAllAdditionalLecturePermissions(lectureID, userID);
}
-
+
return;
}
- @Override
- public List<Image> getImageList(String userID) throws TException
- {
- if(authenticated())
- {
+ @Override
+ public List<Image> getImageList(String userID) throws TException {
+ if (authenticated()) {
return sql.getImageList(userID);
}
return null;
}
@Override
- public List<String> getAdditionalImageContacts(String imageID) throws TException
- {
- if(authenticated())
- {
+ public List<String> getAdditionalImageContacts(String imageID)
+ throws TException {
+ if (authenticated()) {
return sql.getAdditionalImageContacts(imageID);
}
return null;
}
@Override
- public String getOsNameForGuestOs(String guestOS) throws TException
- {
- if(authenticated())
- {
+ public String getOsNameForGuestOs(String guestOS) throws TException {
+ if (authenticated()) {
return sql.getOsNameForGuestOs(guestOS);
}
return null;
}
@Override
-
- public String createRandomUUID() throws TException
- {
- if(authenticated())
- {
+ public String createRandomUUID() throws TException {
+ if (authenticated()) {
return sql.createRandomUUID();
}
return null;
}
- public Map<String, String> getItemOwner(String itemID) throws TException
- {
- if(authenticated())
- {
+ public Map<String, String> getItemOwner(String itemID) throws TException {
+ if (authenticated()) {
return sql.getItemOwner(itemID);
}
return null;
}
-
-
@Override
public boolean userIsImageAdmin(String userID, String imageID)
throws TException {
-
- if(authenticated())
- {
- return sql.userIsImageAdmin(userID,imageID);
+
+ if (authenticated()) {
+ return sql.userIsImageAdmin(userID, imageID);
}
return false;
-
- }
-
+ }
@Override
public boolean userIsLectureAdmin(String userID, String lectureID)
throws TException {
- if(authenticated())
- {
- return sql.userIsLectureAdmin(userID,lectureID);
+ if (authenticated()) {
+ return sql.userIsLectureAdmin(userID, lectureID);
}
return false;
}
-
-
}// end class