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.java976
1 files changed, 591 insertions, 385 deletions
diff --git a/dozentenmodulserver/src/main/java/server/ServerHandler.java b/dozentenmodulserver/src/main/java/server/ServerHandler.java
index 3156ff19..03e713b7 100644
--- a/dozentenmodulserver/src/main/java/server/ServerHandler.java
+++ b/dozentenmodulserver/src/main/java/server/ServerHandler.java
@@ -25,38 +25,81 @@ import server.generated.Lecture;
import server.generated.Person;
import server.generated.Server;
import server.generated.User;
+
+import org.openslx.imagemaster.thrift.iface.ImageServer.Client;
+import org.openslx.imagemaster.thrift.iface.InvalidTokenException;
+import thrift.MasterThriftConnection;
+import thrift.SessionData;
+
import sql.SQL;
//import util.XMLCreator;
-public class ServerHandler implements Server.Iface {
- static SQL sql = new SQL();
-
+public class ServerHandler implements Server.Iface
+{
+
private static Logger log = Logger.getLogger(ServerHandler.class);
+ static SQL sql = new SQL();
+ Client client = null;
- @Override
- public User getFtpUser() throws TException {
- log.info("returning FTPUser...");
- User user = new User();
- user.setUserName(UUID.randomUUID().toString().substring(0, 8));
- user.setPassword(getEncodedSha1Sum(UUID.randomUUID().toString()
- .substring(0, 8)));
- if (Configuration.config.getAbsolute_path().endsWith("/")) {
- user.setPath(Configuration.config.getAbsolute_path());
- } else {
- user.setPath(Configuration.config.getAbsolute_path() + "/");
+
+ public void setTokenForSession(String token)
+ {
+ SessionData.session.setAuthToken(token);
+ }
+
+
+
+ public boolean authenticated() throws InvalidTokenException
+ {
+ MasterThriftConnection thrift = new MasterThriftConnection();
+ client = thrift.getMasterThriftConnection();
+ try {
+ if(client.getUserFromToken(SessionData.session.getAuthToken()) != null)
+ {
+ return true;
+ }
+ } catch (TException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
}
+ return false;
+ }
- // check if folder temp and folder prod exist
- if (folderTempExists() == true && folderProdExists() == true) {
- sql.writeFTPUser(user.getUserName(), user.getPassword());
- return user;
- } else {
- log.info("Error: returning null user");
- return null;
+
+
+
+ @Override
+ public User getFtpUser() throws TException
+ {
+ if(authenticated())
+ {
+ log.info("returning FTPUser...");
+ User user = new User();
+ user.setUserName(UUID.randomUUID().toString().substring(0, 8));
+ user.setPassword(getEncodedSha1Sum(UUID.randomUUID().toString()
+ .substring(0, 8)));
+ if (Configuration.config.getAbsolute_path().endsWith("/")) {
+ user.setPath(Configuration.config.getAbsolute_path());
+ } 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());
+ return user;
+ } else {
+ log.info("Error: returning null user");
+ return null;
+ }
}
+ 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("/")) {
@@ -89,6 +132,7 @@ public class ServerHandler implements Server.Iface {
}
}// end folderTempExists()
+
public boolean folderProdExists() {
// check if folder temp exists, otherwise create it
@@ -125,6 +169,7 @@ public class ServerHandler implements Server.Iface {
}// end folderProdExists()
+
public String getEncodedSha1Sum(String key) {
try {
MessageDigest md = MessageDigest.getInstance("SHA1");
@@ -138,22 +183,35 @@ public class ServerHandler implements Server.Iface {
}
@Override
- public long DeleteFtpUser(String user) throws TException {
- return sql.DeleteUser(user);
+ 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 {
- log.info("successfully returned PathOfImage: "
- + sql.getPathOfImage(image_id, version));
- return 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) {
+ public String setInstitution(String university) throws InvalidTokenException
+ {
+ if(authenticated())
+ {
return sql.setInstitution(university);
+ }
+ return null;
}
@Override
@@ -161,82 +219,123 @@ 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 {
-
- String mode = null;
-
- if (shareMode == 0) {
- mode = "only_local";
- } else {
- mode = "to_be_published";
+ 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,
+ // new Date(), pk_institution);
+
+ // OS impl Select and write
+ // 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(" ", ""));
+
+ // 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);
+
+ log.info("written VLdata");
+ return true;
}
-
- // String pk_institution = sql.setInstitution(university);
- // 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
- // 32 bit"
- 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);
-
- log.info("written VLdata");
- return true;
+ return false;
}
+
@Override
- public List<Image> getImageListPermissionWrite(String userID)
- throws TException {
- return sql.getImageListPermissionWrite(userID);
+ 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 {
- return sql.getImageListPermissionRead(userID);
+ 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 {
- return sql.getImageListPermissionLink(userID);
+ 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 {
- return sql.getImageListPermissionAdmin(userID);
+ public List<Image> getImageListPermissionAdmin(String userID) throws TException
+ {
+ if(authenticated())
+ {
+ return sql.getImageListPermissionAdmin(userID);
+ }
+ return null;
}
@Override
- public List<Image> getImageListAllTemplates()
- throws TException {
- return sql.getImageListAllTemplates();
+ public List<Image> getImageListAllTemplates() throws TException
+ {
+ if(authenticated())
+ {
+ return sql.getImageListAllTemplates();
+ }
+ return null;
}
@Override
- public List<String> getAllOS() throws TException {
- return sql.getAllOS();
+ 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 {
- return sql.getPersonData(Vorname, Nachname);
+ 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) {
- 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
@@ -244,239 +343,279 @@ public class ServerHandler implements Server.Iface {
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 {
-
- //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");
- imageversion = Integer.parseInt(map.get("version"));
-
- sql.setLectureData(pk_person, imageID, imageversion, name, desc,
- shortdesc, startDate, endDate, isActive, lectureID);
-
+ throws TException
+ {
+ if(authenticated())
+ {
- /*
- XMLCreator xml = new XMLCreator(sql.getConnection(), name);
- try {
- xml.create(name);
- log.info("XML created.");
- } catch (SQLException e) {
- e.printStackTrace();
- } catch (ParserConfigurationException e) {
- e.printStackTrace();
- } catch (TransformerException e) {
- e.printStackTrace();
+ //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");
+ 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 {
- // 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));
- // int ret = sql.UpdateImagePath(filename);
- if (sql.UpdateImagePath(filename) == 0) {
- log.info("file moved and database updated.");
+ 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));
+ // 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();
}
-
- } catch (IOException e) {
- log.info("Failed to move file.");
- e.printStackTrace();
}
return true;
}
@Override
- public Map<String, String> getImageData(String imageid, String imageversion)
- throws TException {
- //log.info("returning ImageData: "+ sql.getImageData(imageid, imageversion).size() + "items.");
- return sql.getImageData(imageid, imageversion);
+ 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;
}
@Override
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 {
- String mode = null;
-
- if (shareMode == 0) {
- mode = "only_local";
- } else {
- mode = "to_be_published";
+ long filesize, long shareMode, String os) throws TException
+ {
+ if(authenticated())
+ {
+ 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(" ", ""));
- sql.UpdateImageData(name, newName, desc, image_path, license, internet,
- cpu, ram, id, version, isTemplate, filesize, mode, pk_os);
return false;
}
@Override
- public List<Lecture> getLectureList() throws TException {
-
- //log.info("returning LectureList");
- return sql.getLectureList();
-
+ public List<Lecture> getLectureList() throws TException
+ {
+ if(authenticated())
+ {
+ //log.info("returning LectureList");
+ return sql.getLectureList();
+ }
+ return null;
}
@Override
- public List<Lecture> getLectureListPermissionRead(String userID) {
- //log.info("returning LectureListRead");
- return sql.getLectureListPermissionRead(userID);
+ 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) {
- //log.info("returning LectureListWrite");
- return sql.getLectureListPermissionWrite(userID);
+ 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) {
- //log.info("returning LectureListAdmin");
- return sql.getLectureListPermissionAdmin(userID);
+ 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 {
- 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";
- File tmpFile = new File(path);
- try {
- FileUtils.forceDelete(tmpFile);
- } catch (IOException e1) {
- e1.printStackTrace();
- }
-
- /*
- XMLCreator xml = new XMLCreator(sql.getConnection(), newName);
- try {
- xml.create(newName);
- } catch (SQLException | ParserConfigurationException
- | TransformerException e) {
- e.printStackTrace();
+ 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";
+ File tmpFile = new File(path);
+ try {
+ FileUtils.forceDelete(tmpFile);
+ } catch (IOException e1) {
+ e1.printStackTrace();
+ }
}
-
- */
-
return false;
}
+
@Override
- public boolean deleteImageServer(String imageid, String imageversion)
- throws TException {
-
- 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();
-
+ 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 {
+ public boolean deleteImageData(String id, String version) throws TException
+ {
boolean success=false;
- if(sql.deleteImage(id, version)==true){
- success=true;
- log.info("Image '"+id+"' and permissions successfully deleted.");
+ 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 {
- return sql.connectedToLecture(id, version);
+ 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) {
+ public boolean deleteLecture(String id, String hs, String user) throws InvalidTokenException
+ {
boolean success = false;
- 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.");
+ 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){
+ success = true;
+ log.info("Lecture '"+id+"' and permissions successfully deleted.");
+ }
}
return success;
}
@Override
- public List<String> getAllUniversities() throws TException {
- return sql.getAllUniversities();
-
+ public List<String> getAllUniversities() throws TException
+ {
+ if(authenticated())
+ {
+ return sql.getAllUniversities();
+ }
+ return null;
}
@Override
- public Map<String, String> getLectureData(String lectureid)
- throws TException {
- //log.info("returning LectureData");
- return sql.getLectureData(lectureid);
+ 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;
@@ -486,210 +625,277 @@ public class ServerHandler implements Server.Iface {
}
@Override
- public boolean checkUser(String username) throws TException {
- return sql.checkUser(username);
+ public boolean checkUser(String username) throws TException
+ {
+ if(authenticated())
+ {
+ return sql.checkUser(username);
+ }
+ return false;
}
@Override
- public boolean createUser(String loginName, String lastName,
- String firstName, String mail, String university) throws TException {
- String pk_institution = sql.setInstitution(university);
- String pk_person = sql.setPerson(loginName, lastName, firstName, mail,
- new Date(), pk_institution);
- return true;
+ 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);
+ return true;
+ }
+ return false;
}
@Override
public boolean writeImageRights(String imageID, String username,
String lastName, String firstName, String mail, String university,
- String role) throws TException {
- 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);
-
- 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;
- // int changePermission=0;
- int admin = 1;
- int linkallowed = 1;
- int roleID = sql.getRoleID(role);
-
- sql.setImageRights(pk_person, pk_image, roleID, read, write, admin,
- linkallowed);
-
- } else if (role.equals("Admin")) {
- int read = 1;
- int write = 1;
- // int changePermission=1;
- int admin = 1;
- int linkallowed = 1;
- int roleID = sql.getRoleID(role);
-
- sql.setImageRights(pk_person, pk_image, roleID, read, write, admin,
- linkallowed);
- } else {
- int read = 1;
- int write = 0;
- // int changePermission=0;
- int admin = 0;
- int linkallowed = 0;
- int roleID = sql.getRoleID(role);
-
- sql.setImageRights(pk_person, pk_image, roleID, read, write, admin,
- linkallowed);
+ 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);
+
+ 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;
+ // int changePermission=0;
+ int admin = 1;
+ int linkallowed = 1;
+ int roleID = sql.getRoleID(role);
+
+ sql.setImageRights(pk_person, pk_image, roleID, read, write, admin,
+ linkallowed);
+
+ } else if (role.equals("Admin")) {
+ int read = 1;
+ int write = 1;
+ // int changePermission=1;
+ int admin = 1;
+ int linkallowed = 1;
+ int roleID = sql.getRoleID(role);
+
+ sql.setImageRights(pk_person, pk_image, roleID, read, write, admin,
+ linkallowed);
+ } else {
+ int read = 1;
+ int write = 0;
+ // int changePermission=0;
+ int admin = 0;
+ int linkallowed = 0;
+ int roleID = sql.getRoleID(role);
+
+ sql.setImageRights(pk_person, pk_image, roleID, read, write, admin,
+ linkallowed);
+ }
+
+ log.info("Written image rights");
+ return true;
}
-
- log.info("Written image rights");
- return true;
+ return false;
}
@Override
public boolean writeLectureRights(String lectureID, String username,
String lastName, String firstName, String mail, String university,
- String role) throws TException {
- //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);
-
- 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 {
- int read = 0;
- int write = 0;
- // int changePermission=0;
- int admin = 0;
- int roleID = sql.getRoleID(role);
-
- sql.setLectureRights(pk_person, lectureID, roleID, read, write,
- admin);
+ 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);
+
+ 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 {
+ int read = 0;
+ int write = 0;
+ // int changePermission=0;
+ int admin = 0;
+ int roleID = sql.getRoleID(role);
+
+ sql.setLectureRights(pk_person, lectureID, roleID, read, write,
+ admin);
+ }
+
+ return true;
}
-
- return true;
+ return false;
}
@Override
- public List<Person> getAllOtherSatelliteUsers(List<String> userID)
- throws TException {
- return sql.getAllOtherSatelliteUsers(userID);
- // return null;
+ 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
public boolean writeAdditionalImageRights(String imageID, String userID,
boolean isRead, boolean isWrite, boolean isLinkAllowed,
- boolean isAdmin) {
+ boolean isAdmin) throws InvalidTokenException
+ {
boolean success = false;
- Map<String, String> map = new HashMap<String, String>();
- map = sql.getImageIDandVersion(imageID);
- //String imageID = map.get("GUID");
+ if(authenticated())
+ {
- sql.writeAdditionalImageRights(imageID, userID, isRead, isWrite,
- isLinkAllowed, isAdmin);
- log.info("Written additional image rights for " + userID);
+ Map<String, String> map = new HashMap<String, String>();
+ map = sql.getImageIDandVersion(imageID);
+ //String imageID = map.get("GUID");
+
+ sql.writeAdditionalImageRights(imageID, userID, isRead, isWrite,
+ isLinkAllowed, isAdmin);
+ log.info("Written additional image rights for " + userID);
+ }
return success;
}
+
public boolean writeAdditionalLectureRights(String lectureID,
- String userID, boolean isRead, boolean isWrite, boolean isAdmin) {
-
- 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);
-
- return true;
+ 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);
+
+ return true;
+ }
+ return false;
}
@Override
public List<Person> getPermissionForUserAndImage(String userID,
- String imageID) throws TException {
- return sql.getPermissionForUserAndImage(userID, imageID);
+ String imageID) throws TException
+ {
+ if(authenticated())
+ {
+ return sql.getPermissionForUserAndImage(userID, imageID);
+ }
+ return null;
}
- public List<Person> getPermissionForUserAndLecture(String userID,
- String lectureID) {
- return sql.getPermissionForUserAndLecture(userID, lectureID);
+ 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 {
- sql.deleteAllAdditionalImagePermissions(imageID, userID);
+ 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 {
- sql.deleteAllAdditionalLecturePermissions(lectureID, userID);
+ 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 {
- return sql.getImageList(userID);
+ 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 {
-
- return sql.getAdditionalImageContacts(imageID);
+ public List<String> getAdditionalImageContacts(String imageID) throws TException
+ {
+ if(authenticated())
+ {
+ return sql.getAdditionalImageContacts(imageID);
+ }
+ return null;
}
@Override
- public String getOsNameForGuestOs(String guestOS) throws TException {
- return sql.getOsNameForGuestOs(guestOS);
+ public String getOsNameForGuestOs(String guestOS) throws TException
+ {
+ if(authenticated())
+ {
+ return sql.getOsNameForGuestOs(guestOS);
+ }
+ return null;
}
@Override
- public String createRandomUUID() throws TException {
- return sql.createRandomUUID();
+ public String createRandomUUID() throws TException
+ {
+ if(authenticated())
+ {
+ return sql.createRandomUUID();
+ }
+ return null;
}
- public Map<String, String> getItemOwner(String itemID) throws TException {
- return sql.getItemOwner(itemID);
+ public Map<String, String> getItemOwner(String itemID) throws TException
+ {
+ if(authenticated())
+ {
+ return sql.getItemOwner(itemID);
+ }
+ return null;
}
- @Override
- public void setTokenForSession(String token) throws TException {
- sql.setTokenForSession(token);
- }
}// end class