diff options
| author | Simon Rettberg | 2015-05-27 19:43:45 +0200 |
|---|---|---|
| committer | Simon Rettberg | 2015-05-27 19:43:45 +0200 |
| commit | 8dc93364b1de3a6a96acf869298b3c3c44b10125 (patch) | |
| tree | b2fdb4730e55559064062d83d5fd0b994066992f /dozentenmodulserver/src/main/java | |
| parent | • removed link to OTRS from Suite (diff) | |
| download | tutor-module-8dc93364b1de3a6a96acf869298b3c3c44b10125.tar.gz tutor-module-8dc93364b1de3a6a96acf869298b3c3c44b10125.tar.xz tutor-module-8dc93364b1de3a6a96acf869298b3c3c44b10125.zip | |
[server] Applied Eclipse code format (with line width extended to 110)
Diffstat (limited to 'dozentenmodulserver/src/main/java')
4 files changed, 816 insertions, 1368 deletions
diff --git a/dozentenmodulserver/src/main/java/server/BinaryListener.java b/dozentenmodulserver/src/main/java/server/BinaryListener.java index 8f9dd622..7b1135b9 100644 --- a/dozentenmodulserver/src/main/java/server/BinaryListener.java +++ b/dozentenmodulserver/src/main/java/server/BinaryListener.java @@ -28,7 +28,7 @@ public class BinaryListener implements Runnable { true, true); try { transport = new TServerSocket(9090); - log.info(new Date() + " - Connected to Port 9090"); + log.info(new Date() + " - Listening on Port 9090"); } catch (TTransportException e) { log.fatal(new Date() + " - Could not listen on port 9090"); diff --git a/dozentenmodulserver/src/main/java/server/ServerHandler.java b/dozentenmodulserver/src/main/java/server/ServerHandler.java index 4c0f6d5e..837cc64a 100644 --- a/dozentenmodulserver/src/main/java/server/ServerHandler.java +++ b/dozentenmodulserver/src/main/java/server/ServerHandler.java @@ -24,88 +24,74 @@ import org.openslx.imagemaster.thrift.iface.UserInfo; import org.openslx.sat.thrift.iface.Image; import org.openslx.sat.thrift.iface.Lecture; import org.openslx.sat.thrift.iface.Person; -import org.openslx.sat.thrift.iface.User; import org.openslx.sat.thrift.iface.Server; +import org.openslx.sat.thrift.iface.User; import org.openslx.sat.thrift.version.Version; import sql.SQL; import thrift.MasterThriftConnection; -//import thrift.SessionData; - -//import util.XMLCreator; 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 + // saves the current tokens and the mapped userdata, returning from the server + private Map<String, UserInfo> tokenManager = new HashMap<>(); - public boolean authenticated(String token) throws TException - { - if(tokenManager.get(token) != null) - { - //user found in tokenManager, session was set to valid once before (cached session, no further action needed) + public boolean authenticated(String token) throws TException { + if (tokenManager.get(token) != null) { + // user found in tokenManager, session was set to valid once before + // (cached session, no further action needed) return true; - } - else - { + } else { MasterThriftConnection thrift = new MasterThriftConnection(); Client client = thrift.getMasterThriftConnection(); - //user not in tokenManager, check authentication, then add user to tokenManager - log.info("token is: "+token); + // user not in tokenManager, check authentication, then add user to tokenManager + log.info("token is: " + token); UserInfo ui = null; - if( (ui = client.getUserFromToken(token)) != null) //user authenticated by masterserver - { - //user was authenticated by the masterserver, cache the data + if ((ui = client.getUserFromToken(token)) != null) { + // user was authenticated by the masterserver, cache the data tokenManager.put(token, ui); return true; } } - + return false; } - - - private UserInfo getUserFromToken(String token) //local function, which gets userdata from the tokenmanager, not the masterserver - { //implemented, as there is no need for userdata in each function, so return type of authenticated should stay boolean + + /** + * local function, which gets userdata from the tokenmanager, not the + * masterserver implemented, as there is no need for userdata in each + * function, so return type of authenticated should stay boolean + */ + private UserInfo getUserFromToken(String token) { UserInfo ui = tokenManager.get(token); return ui; } - - - public boolean setSessionInvalid(String token) - { + + public boolean setSessionInvalid(String token) { log.info("token disabling.. round one"); log.info(tokenManager.get(token)); - - + tokenManager.remove(token); - + log.info("token disabling.. round two"); log.info(tokenManager.get(token)); - - if(tokenManager.get(token) == null) //check if deletion worked and token isn't stored anymore - { - return true; - } - return false; + // check if deletion worked and token isn't stored anymore + return tokenManager.get(token) == null; } @Override - public User getFtpUser(String token) throws TException - { - if(authenticated(token)) - { + 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)); - user.setPassword(getEncodedSha1Sum(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 { @@ -203,26 +189,18 @@ public class ServerHandler implements Server.Iface { return null; } - @Override - - public long DeleteFtpUser(String user, String token) throws TException - { - if(authenticated(token)) - { + public long DeleteFtpUser(String user, String token) throws TException { + if (authenticated(token)) { return sql.DeleteUser(user); } return -1; } - @Override - - public String getPathOfImage(String image_id, String version, String token) throws TException - { - if(authenticated(token)) - { + 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); @@ -231,10 +209,8 @@ public class ServerHandler implements Server.Iface { } @Override - public String setInstitution(String university, String token) throws TException - { - if(authenticated(token)) - { + public String setInstitution(String university, String token) throws TException { + if (authenticated(token)) { return sql.setInstitution(university); } @@ -242,43 +218,29 @@ public class ServerHandler implements Server.Iface { } @Override - public boolean writeVLdata(String imagename, String desc, - String Tel, String Fak, boolean license, boolean internet, - long ram, long cpu, String imagePath, boolean isTemplate, - long filesize, long shareMode, String os, String uid, String token, String userID) throws TException - { - - if(authenticated(token)) - { + public boolean writeVLdata(String imagename, String desc, String Tel, String Fak, boolean license, + boolean internet, long ram, long cpu, String imagePath, boolean isTemplate, long filesize, + long shareMode, String os, String uid, String token, String userID) throws TException { + + if (authenticated(token)) { 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" + // 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(" ", "")); + 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); - sql.setImageData(userID, license, internet, cpu, ram, imagename, desc, - imagePath, filesize, mode, pk_os, uid); - - log.info("userID in serverhandler was: "+userID); + log.info("userID in serverhandler was: " + userID); log.info("written VLdata"); return true; @@ -287,11 +249,9 @@ public class ServerHandler implements Server.Iface { } @Override - //@param: userID - deprecated, to be removed while setting up new suite-architecture - public List<Image> getImageListPermissionWrite(String userID, String token) throws TException - { - if(authenticated(token)) - { + // @param: userID - deprecated, to be removed while setting up new suite-architecture + public List<Image> getImageListPermissionWrite(String userID, String token) throws TException { + if (authenticated(token)) { UserInfo ui = getUserFromToken(token); return sql.getImageListPermissionWrite(ui.getUserId()); } @@ -299,11 +259,9 @@ public class ServerHandler implements Server.Iface { } @Override - //@param: userID - deprecated, to be removed while setting up new suite-architecture - public List<Image> getImageListPermissionRead(String userID, String token) throws TException - { - if(authenticated(token)) - { + // @param: userID - deprecated, to be removed while setting up new suite-architecture + public List<Image> getImageListPermissionRead(String userID, String token) throws TException { + if (authenticated(token)) { UserInfo ui = getUserFromToken(token); return sql.getImageListPermissionRead(ui.getUserId()); } @@ -311,11 +269,9 @@ public class ServerHandler implements Server.Iface { } @Override - //@param: userID - deprecated, to be removed while setting up new suite-architecture - public List<Image> getImageListPermissionLink(String userID, String token) throws TException - { - if(authenticated(token)) - { + // @param: userID - deprecated, to be removed while setting up new suite-architecture + public List<Image> getImageListPermissionLink(String userID, String token) throws TException { + if (authenticated(token)) { UserInfo ui = getUserFromToken(token); return sql.getImageListPermissionLink(ui.getUserId()); } @@ -323,11 +279,9 @@ public class ServerHandler implements Server.Iface { } @Override - //@param: userID - deprecated, to be removed while setting up new suite-architecture - public List<Image> getImageListPermissionAdmin(String userID, String token) throws TException - { - if(authenticated(token)) - { + // @param: userID - deprecated, to be removed while setting up new suite-architecture + public List<Image> getImageListPermissionAdmin(String userID, String token) throws TException { + if (authenticated(token)) { UserInfo ui = getUserFromToken(token); return sql.getImageListPermissionAdmin(ui.getUserId()); } @@ -335,110 +289,89 @@ public class ServerHandler implements Server.Iface { } @Override - public List<Image> getImageListAllTemplates(String token) throws TException - { - if(authenticated(token)) - { + public List<Image> getImageListAllTemplates(String token) throws TException { + if (authenticated(token)) { return sql.getImageListAllTemplates(); } return null; } @Override - public List<String> getAllOS(String token) throws TException - { - if(authenticated(token)) - { + public List<String> getAllOS(String token) throws TException { + if (authenticated(token)) { return sql.getAllOS(); } return null; } - //UserInfo does not return the institution, so in this case, the local method is prepared, but not yet executed, as the institution has to be added to UserInfo (or selected by institutionID) + // UserInfo does not return the institution, so in this case, the local + // method is prepared, but not yet executed, as the institution has to be + // added to UserInfo (or selected by institutionID) @Override - public Map<String, String> getPersonData(String Vorname, String Nachname, String token) throws TException - { - - if(authenticated(token)) - { - - Map<String, String> map = new HashMap<>(); - - UserInfo ui = getUserFromToken(token); - - map.put("mail", ui.getEMail()); - map.put("Nachname", ui.getLastName()); - map.put("Vorname", ui.getFirstName()); - - //map.put("Hochschule", sql.getInstitutionByID(ui.getOrganizationId())); //does not deliver the correct id - Map<String, String> tempMap = new HashMap<>(); - tempMap = sql.getPersonData(Vorname, Nachname); - map.put("Hochschule", tempMap.get("Hochschule")); - - return map; + public Map<String, String> getPersonData(String Vorname, String Nachname, String token) throws TException { + + if (authenticated(token)) { + + Map<String, String> map = new HashMap<>(); + + UserInfo ui = getUserFromToken(token); + + map.put("mail", ui.getEMail()); + map.put("Nachname", ui.getLastName()); + map.put("Vorname", ui.getFirstName()); + + Map<String, String> tempMap = new HashMap<>(); + tempMap = sql.getPersonData(Vorname, Nachname); + map.put("Hochschule", tempMap.get("Hochschule")); + + return map; } return null; } - - public void setPerson(String userID, String token, String institution) throws TException - { - if(authenticated(token)) - { + public void setPerson(String userID, String token, String institution) throws TException { + if (authenticated(token)) { UserInfo ui = getUserFromToken(token); - //String institution = sql.getInstitutionByID(ui.getOrganizationId()); sql.setPerson(userID, ui.getLastName(), ui.getFirstName(), ui.getEMail(), new Date(), institution); } } - - @Override - public boolean writeLecturedata(String name, String shortdesc, String desc, - String startDate, String endDate, boolean isActive, - String imageID, String token, String Tel, String Fak, String lectureID, String university) - throws TException - { - if(authenticated(token)) - { + public boolean writeLecturedata(String name, String shortdesc, String desc, String startDate, + String endDate, boolean isActive, String imageID, String token, String Tel, String Fak, + String lectureID, String university) throws TException { + if (authenticated(token)) { UserInfo ui = getUserFromToken(token); - - //String pk_image = imageID; + Map<String, String> map = new HashMap<String, String>(); int imageversion = 0; - //String university = sql.getInstitutionByID(ui.getOrganizationId()); String pk_institution = sql.setInstitution(university); - String pk_person = sql.setPerson(ui.getEMail(), ui.getLastName(), ui.getFirstName(), ui.getEMail(), - new Date(), pk_institution); + 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"); imageversion = Integer.parseInt(map.get("version")); - sql.setLectureData(pk_person, imageID, imageversion, name, desc, - shortdesc, startDate, endDate, isActive, lectureID); + sql.setLectureData(pk_person, imageID, imageversion, name, desc, shortdesc, startDate, endDate, + isActive, lectureID); } return false; } @Override - public boolean startFileCopy(String filename, String token) throws TException - { - if(authenticated(token)) - { + public boolean startFileCopy(String filename, String token) throws TException { + if (authenticated(token)) { // copy file from folder temp to folder prod - String file = Configuration.config.getAbsolute_path() + "temp/" - + filename; + 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() + "'"); + 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)); + 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."); @@ -453,31 +386,23 @@ public class ServerHandler implements Server.Iface { } @Override - public Map<String, String> getImageData(String imageid, String imageversion, String token) throws TException - { - if(authenticated(token)) - { - //log.info("returning ImageData: "+ sql.getImageData(imageid, imageversion).size() + "items."); + public Map<String, String> getImageData(String imageid, String imageversion, String token) + throws TException { + if (authenticated(token)) { 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, String token) throws TException - { - - if (authenticated(token)) - { - - //get old_image_path - String old_image_path = sql.getFile(id, version); - //log.debug("old file path has value:"+old_image_path.substring(5)); - //log.debug("new file path has value:"+image_path.substring(5)); + 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, String token) throws TException { + if (authenticated(token)) { + + // get old_image_path + String old_image_path = sql.getFile(id, version); String mode = null; @@ -487,112 +412,92 @@ public class ServerHandler implements Server.Iface { mode = "to_be_published"; } String pk_os = sql.getOSpk(os.substring(0, nthIndexOf(os, " ", 2)), - os.substring(nthIndexOf(os, " ", 2), os.lastIndexOf(" ")) - .replace(" ", "")); + 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); - - - - //check if new file has been uploaded by checking if the new file path equals the old file path - //if so, no new file was uploaded. Else delete old file - if (val == 0 && (!old_image_path.substring(5).matches(image_path.substring(5))) ) { + int val = sql.UpdateImageData(name, newName, desc, image_path, license, internet, cpu, ram, id, + version, isTemplate, filesize, mode, pk_os); + + // check if new file has been uploaded by checking if the new file + // path equals the old file path + // if so, no new file was uploaded. Else delete old file + if (val == 0 && (!old_image_path.substring(5).matches(image_path.substring(5)))) { // update was successful - delete old file - //log.debug("deleting file "+old_image_path); + // log.debug("deleting file "+old_image_path); deleteImageByPath(old_image_path); } else { // update was not successful - delete new file // TODO not yet implemented - //log.debug("doing nothing because no new file was uploaded.."); + // log.debug("doing nothing because no new file was uploaded.."); } } return false; } - @Override - public List<Lecture> getLectureList(String token) throws TException - { - if(authenticated(token)) - { - //log.info("returning LectureList"); + public List<Lecture> getLectureList(String token) throws TException { + if (authenticated(token)) { + // log.info("returning LectureList"); return sql.getLectureList(); } return null; } @Override - public List<Lecture> getLectureListPermissionRead(String token) throws TException - { - if(authenticated(token)) - { + public List<Lecture> getLectureListPermissionRead(String token) throws TException { + if (authenticated(token)) { UserInfo ui = getUserFromToken(token); - //log.info("returning LectureListRead"); + // log.info("returning LectureListRead"); return sql.getLectureListPermissionRead(ui.getUserId()); } return null; }// end getLectureListPermissionRead @Override - public List<Lecture> getLectureListPermissionWrite(String token) throws TException - { - if(authenticated(token)) - { + public List<Lecture> getLectureListPermissionWrite(String token) throws TException { + if (authenticated(token)) { UserInfo ui = getUserFromToken(token); - //log.info("returning LectureListWrite"); + // log.info("returning LectureListWrite"); return sql.getLectureListPermissionWrite(ui.getUserId()); } return null; }// end getLectureListPermissionRead @Override - - public List<Lecture> getLectureListPermissionAdmin(String token) throws TException - { - if(authenticated(token)) - { + public List<Lecture> getLectureListPermissionAdmin(String token) throws TException { + if (authenticated(token)) { UserInfo ui = getUserFromToken(token); - //log.info("returning LectureListAdmin"); + // log.info("returning LectureListAdmin"); return sql.getLectureListPermissionAdmin(ui.getUserId()); } 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 token, - String Tel, String Fak, String id, String university) throws TException - { - if(authenticated(token)) - { + public boolean updateLecturedata(String name, String newName, String shortdesc, String desc, + String startDate, String endDate, boolean isActive, String imageid, String imageversion, + String token, String Tel, String Fak, String id, String university) throws TException { + if (authenticated(token)) { UserInfo ui = getUserFromToken(token); - - sql.updateLectureData(imageid, imageversion, ui.getLastName(), newName, desc, - shortdesc, startDate, endDate, isActive, id); - + + sql.updateLectureData(imageid, imageversion, ui.getLastName(), newName, desc, shortdesc, + startDate, endDate, isActive, id); + } return false; } @Override - public boolean deleteImageServer(String imageid, String imageversion, String token) throws TException - { - if(authenticated(token)) - { + public boolean deleteImageServer(String imageid, String imageversion, String token) throws TException { + if (authenticated(token)) { String stringFile = sql.getFile(imageid, imageversion); log.info("File to Delete: " + stringFile); - File tmpFile = new File(Configuration.config.getAbsolute_path() - + stringFile); - - log.info("Absolute Path used for deletion: "+tmpFile); + File tmpFile = new File(Configuration.config.getAbsolute_path() + stringFile); + + log.info("Absolute Path used for deletion: " + tmpFile); try { // File wird von Server gelöscht @@ -607,76 +512,58 @@ public class ServerHandler implements Server.Iface { } return false; } - + @Override - public boolean deleteImageData(String id, String version, String token) throws TException - { - boolean success=false; - - if(authenticated(token)) - { - if(sql.deleteImage(id, version)==true) - { - success=true; - log.info("Image '"+id+"' and permissions successfully deleted."); + public boolean deleteImageData(String id, String version, String token) throws TException { + boolean success = false; + + if (authenticated(token)) { + if (sql.deleteImage(id, version) == true) { + success = true; + log.info("Image '" + id + "' and permissions successfully deleted."); } } return success; } -//TODO -public boolean deleteImageByPath(String image_path) throws TException{ - + // TODO + public boolean deleteImageByPath(String image_path) throws TException { + log.info("File to Delete: " + image_path); - //String stringFile = sql.getFile(imageid, imageversion); - log.info("File to Delete: " + image_path); + File tmpFile = new File(Configuration.config.getAbsolute_path() + image_path); - File tmpFile = new File(Configuration.config.getAbsolute_path() - + image_path); + try { + // File wird von Server gelöscht + FileUtils.forceDelete(tmpFile); + return true; - try { - // File wird von Server gelöscht - FileUtils.forceDelete(tmpFile); - return true; + } catch (IOException e) { + log.info("Failed to execute deleteImageServer."); + e.printStackTrace(); - } catch (IOException e) { - log.info("Failed to execute deleteImageServer."); - e.printStackTrace(); + } - } - + return false; - return false; - -} + } @Override - public boolean connectedToLecture(String id, String version, String token) throws TException - { - if(authenticated(token)) - { + public boolean connectedToLecture(String id, String version, String token) throws TException { + if (authenticated(token)) { return sql.connectedToLecture(id, version); } return true; } - public boolean deleteLecture(String id, String token, String university) throws TException - { + public boolean deleteLecture(String id, String token, String university) throws TException { boolean success = false; - - UserInfo ui = getUserFromToken(token); - - String user = ui.getEMail(); - - if(authenticated(token)) - { - if(sql.deleteLecture(id) == true) - { + + if (authenticated(token)) { + 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; @@ -684,31 +571,25 @@ public boolean deleteImageByPath(String image_path) throws TException{ } @Override - public List<String> getAllUniversities(String token) throws TException - { - if(authenticated(token)) - { + public List<String> getAllUniversities(String token) throws TException { + if (authenticated(token)) { return sql.getAllUniversities(); } return null; } @Override - public Map<String, String> getLectureData(String lectureid, String token) throws TException - { - if(authenticated(token)) - { + public Map<String, String> getLectureData(String lectureid, String token) throws TException { + if (authenticated(token)) { return sql.getLectureData(lectureid); } return null; } - public static int nthIndexOf(final String string, final String searchToken,final int index) - { + public static int nthIndexOf(final String string, final String searchToken, final int index) { int j = 0; - for (int i = 0; i < index; i++) - { + for (int i = 0; i < index; i++) { j = string.indexOf(searchToken, j + 1); if (j == -1) @@ -719,10 +600,8 @@ public boolean deleteImageByPath(String image_path) throws TException{ } @Override - public boolean checkUser(String username, String token) throws TException - { - if(authenticated(token)) - { + public boolean checkUser(String username, String token) throws TException { + if (authenticated(token)) { return sql.checkUser(username); } return false; @@ -730,32 +609,30 @@ public boolean deleteImageByPath(String image_path) throws TException{ } @Override - public boolean createUser(String token, String university) throws TException - { - if(authenticated(token)) - { + public boolean createUser(String token, String university) throws TException { + if (authenticated(token)) { UserInfo ui = getUserFromToken(token); String pk_institution = sql.setInstitution(university); - String pk_person = sql.setPerson(ui.getEMail(), ui.getLastName(), ui.getFirstName(), ui.getEMail(), new Date(), pk_institution); + sql.setPerson(ui.getEMail(), ui.getLastName(), ui.getFirstName(), ui.getEMail(), new Date(), + pk_institution); return true; } return false; } @Override - public boolean writeImageRights(String imageID, String token, - String role, String university, String userID) throws TException - { - if(authenticated(token)) - { + public boolean writeImageRights(String imageID, String token, String role, String university, + String userID) throws TException { + if (authenticated(token)) { UserInfo ui = getUserFromToken(token); String pk_image = null; 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); - + 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"); @@ -768,8 +645,7 @@ public boolean deleteImageByPath(String image_path) throws TException{ 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; @@ -779,8 +655,7 @@ public boolean deleteImageByPath(String image_path) throws TException{ 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; @@ -789,8 +664,7 @@ public boolean deleteImageByPath(String image_path) throws TException{ 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"); @@ -800,16 +674,16 @@ public boolean deleteImageByPath(String image_path) throws TException{ } @Override - public boolean writeLectureRights(String lectureID, String role, String token, String university, String userID) throws TException - { - if(authenticated(token)) - { - //String pk_lecture = null; + public boolean writeLectureRights(String lectureID, String role, String token, String university, + String userID) throws TException { + if (authenticated(token)) { + // String pk_lecture = null; UserInfo ui = getUserFromToken(token); String pk_institution = sql.setInstitution(university); - String pk_person = sql.setPerson(userID, ui.getLastName(), ui.getFirstName(), ui.getEMail(), new Date(), pk_institution); - //pk_lecture = sql.getLectureID(lectureID); - + String pk_person = sql.setPerson(userID, ui.getLastName(), ui.getFirstName(), ui.getEMail(), + new Date(), pk_institution); + // pk_lecture = sql.getLectureID(lectureID); + if (role.equals("Dozent")) { int read = 1; int write = 1; @@ -817,8 +691,7 @@ public boolean deleteImageByPath(String image_path) throws TException{ int admin = 1; int roleID = sql.getRoleID(role); - sql.setLectureRights(pk_person, lectureID, roleID, read, write, - admin); + sql.setLectureRights(pk_person, lectureID, roleID, read, write, admin); } else if (role.equals("Admin")) { int read = 1; @@ -827,8 +700,7 @@ public boolean deleteImageByPath(String image_path) throws TException{ int admin = 1; int roleID = sql.getRoleID(role); - sql.setLectureRights(pk_person, lectureID, roleID, read, write, - admin); + sql.setLectureRights(pk_person, lectureID, roleID, read, write, admin); } else { int read = 0; int write = 0; @@ -836,8 +708,7 @@ public boolean deleteImageByPath(String image_path) throws TException{ int admin = 0; int roleID = sql.getRoleID(role); - sql.setLectureRights(pk_person, lectureID, roleID, read, write, - admin); + sql.setLectureRights(pk_person, lectureID, roleID, read, write, admin); } return true; @@ -846,10 +717,8 @@ public boolean deleteImageByPath(String image_path) throws TException{ } @Override - public List<Person> getAllOtherSatelliteUsers(List<String> userID, String token) throws TException - { - if(authenticated(token)) - { + public List<Person> getAllOtherSatelliteUsers(List<String> userID, String token) throws TException { + if (authenticated(token)) { return sql.getAllOtherSatelliteUsers(userID); // return null; } @@ -857,34 +726,20 @@ public boolean deleteImageByPath(String image_path) throws TException{ } // 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 - { + public boolean writeAdditionalImageRights(String imageID, String userID, boolean isRead, boolean isWrite, + boolean isLinkAllowed, boolean isAdmin, String token) throws TException { boolean success = false; - if(authenticated(token)) - { - 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); + if (authenticated(token)) { + 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, 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); + public boolean writeAdditionalLectureRights(String lectureID, String userID, boolean isRead, + boolean isWrite, boolean isAdmin, String token) throws TException { + if (authenticated(token)) { + sql.writeAdditionalLectureRights(lectureID, userID, isRead, isWrite, isAdmin); log.info("Written additional lecture rights for " + userID); return true; @@ -893,95 +748,75 @@ public boolean deleteImageByPath(String image_path) throws TException{ } @Override - public List<Person> getPermissionForUserAndImage(String token, - String imageID, String userID) throws TException - { - if(authenticated(token)) - { + public List<Person> getPermissionForUserAndImage(String token, String imageID, String userID) + throws TException { + if (authenticated(token)) { return sql.getPermissionForUserAndImage(userID, imageID); } return null; } - - public List<Person> getPermissionForUserAndLecture(String token,String lectureID, String userID) throws TException - { - if(authenticated(token)) - { - UserInfo ui = getUserFromToken(token); + public List<Person> getPermissionForUserAndLecture(String token, String lectureID, String userID) + throws TException { + if (authenticated(token)) { return sql.getPermissionForUserAndLecture(userID, lectureID); } return null; } @Override - public void deleteAllAdditionalImagePermissions(String imageID, String token, String userID) throws TException - { - if(authenticated(token)) - { - UserInfo ui = getUserFromToken(token); + public void deleteAllAdditionalImagePermissions(String imageID, String token, String userID) + throws TException { + if (authenticated(token)) { sql.deleteAllAdditionalImagePermissions(imageID, userID); } return; } @Override - public void deleteAllAdditionalLecturePermissions(String lectureID,String token, String userID) throws TException - { - if(authenticated(token)) - { - UserInfo ui = getUserFromToken(token); + public void deleteAllAdditionalLecturePermissions(String lectureID, String token, String userID) + throws TException { + if (authenticated(token)) { sql.deleteAllAdditionalLecturePermissions(lectureID, userID); } return; } - - @Override - public List<Image> getImageList(String userID, String token) throws TException - { - if(authenticated(token)) - { + @Override + public List<Image> getImageList(String userID, String token) throws TException { + if (authenticated(token)) { return sql.getImageList(userID); } return null; } @Override - public List<String> getAdditionalImageContacts(String imageID, String token) throws TException - { - if(authenticated(token)) - { + public List<String> getAdditionalImageContacts(String imageID, String token) throws TException { + if (authenticated(token)) { return sql.getAdditionalImageContacts(imageID); } return null; } @Override - public String getOsNameForGuestOs(String guestOS, String token) throws TException - { - if(authenticated(token)) - { + public String getOsNameForGuestOs(String guestOS, String token) throws TException { + if (authenticated(token)) { return sql.getOsNameForGuestOs(guestOS); } return null; } @Override - public String createRandomUUID(String token) throws TException - { - if(authenticated(token)) - { + public String createRandomUUID(String token) throws TException { + if (authenticated(token)) { return sql.createRandomUUID(); } return null; } - public Map<String, String> getItemOwner(String itemID, String token) throws TException - { - if(authenticated(token)) - { + public Map<String, String> getItemOwner(String itemID, String token) throws TException { + if (authenticated(token)) { return sql.getItemOwner(itemID); } return null; @@ -989,43 +824,34 @@ public boolean deleteImageByPath(String image_path) throws TException{ } @Override - public boolean userIsImageAdmin(String imageID, String token, String userID) - throws TException { - - if(authenticated(token)) - { - UserInfo ui = getUserFromToken(token); - return sql.userIsImageAdmin(userID,imageID); + public boolean userIsImageAdmin(String imageID, String token, String userID) throws TException { + + if (authenticated(token)) { + return sql.userIsImageAdmin(userID, imageID); } return false; } @Override - public boolean userIsLectureAdmin(String userID, String lectureID, String token) - throws TException { + public boolean userIsLectureAdmin(String userID, String lectureID, String token) throws TException { - if(authenticated(token)) - { - return sql.userIsLectureAdmin(userID,lectureID); + if (authenticated(token)) { + return sql.userIsLectureAdmin(userID, lectureID); } return false; } - @Override public String getInstitutionByID(String institutionID) throws TException { // TODO Auto-generated method stub return null; } - @Override public long getVersion() throws TException { return Version.VERSION; } - - }// end class diff --git a/dozentenmodulserver/src/main/java/server/StartServer.java b/dozentenmodulserver/src/main/java/server/StartServer.java index cf141ae9..04314ee7 100644 --- a/dozentenmodulserver/src/main/java/server/StartServer.java +++ b/dozentenmodulserver/src/main/java/server/StartServer.java @@ -31,8 +31,6 @@ public class StartServer { log.info("*************************************************************************************************"); log.info("******************* " + new Date() + " - starting Application ***********************"); log.info("*************************************************************************************************"); - - // get Configuration try { @@ -68,7 +66,6 @@ public class StartServer { } } log.info(new Date() + " - all Servers shut down, exiting...\n"); - } } diff --git a/dozentenmodulserver/src/main/java/sql/SQL.java b/dozentenmodulserver/src/main/java/sql/SQL.java index 5f79f706..c953de34 100644 --- a/dozentenmodulserver/src/main/java/sql/SQL.java +++ b/dozentenmodulserver/src/main/java/sql/SQL.java @@ -14,7 +14,6 @@ import java.util.HashMap; import java.util.List;
import java.util.Map;
import java.util.UUID;
-//import server.generated.Server.Client;
import models.Configuration;
@@ -23,138 +22,107 @@ import org.openslx.sat.thrift.iface.Image; import org.openslx.sat.thrift.iface.Lecture;
import org.openslx.sat.thrift.iface.Person;
-
public class SQL {
-
- private static Logger log = Logger.getLogger(SQL.class);
-
-
+ private static final Logger log = Logger.getLogger(SQL.class);
+
public Connection getConnection() {
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
- } catch (InstantiationException | IllegalAccessException
- | ClassNotFoundException e) {
-
+ } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
+
e.printStackTrace();
- }
+ }
try {
Connection con = DriverManager.getConnection("jdbc:mysql://"
+ Configuration.config.getSql_connection() + "?user="
- + Configuration.config.getSql_user() + "&password="
- + Configuration.config.getSql_pass() + "");
+ + Configuration.config.getSql_user() + "&password=" + Configuration.config.getSql_pass()
+ + "");
con.setAutoCommit(false);
return con;
} catch (SQLException e) {
-
+
log.info("Failed to return connection to Client.");
e.printStackTrace();
}
-
+
return null;
}
-
-
-
public int writeFTPUser(String user, String pass) {
- Statement stm;
- try {
- Connection con = getConnection();
- stm = con.createStatement();
-
- int ret = stm
- .executeUpdate("INSERT INTO `bwLehrpool`.`FtpUsers`(`User`,`Password`,`Uid`,`Gid`,`Dir`)VALUES('"
- + user
- + "',SHA1('"
- + pass
- + "'),'10001','12345','"
- + Configuration.config.getAbsolute_path()
- + "temp/');");
- con.commit();
- con.close();
- log.info("Created FTPUser " + user + " : " + pass
- + ".");
- return ret;
- } catch (SQLException e) {
-
- log.info("Failed to writeFTPUser.");
- e.printStackTrace();
- }
- return -1;
- }
-
-
-
-
-
-
- public int DeleteUser(String user) {
- Statement stm = null;
+ Statement stm;
try {
Connection con = getConnection();
stm = con.createStatement();
+ int ret = stm
+ .executeUpdate("INSERT INTO `bwLehrpool`.`FtpUsers`(`User`,`Password`,`Uid`,`Gid`,`Dir`)VALUES('"
+ + user + "',SHA1('" + pass + "'),'10001','12345','"
+ + Configuration.config.getAbsolute_path() + "temp/');");
+ con.commit();
+ con.close();
+ log.info("Created FTPUser " + user + " : " + pass + ".");
+ return ret;
+ } catch (SQLException e) {
+
+ log.info("Failed to writeFTPUser.");
+ e.printStackTrace();
+ }
+ return -1;
+ }
+
+ public int DeleteUser(String user) {
+ try {
+ Connection con = getConnection();
+
String sql = "DELETE FROM `bwLehrpool`.`FtpUsers` where User like ?;";
PreparedStatement prest = con.prepareStatement(sql);
prest.setString(1, user);
-
+
int ret = prest.executeUpdate();
-
+
con.commit();
con.close();
log.info("FTPUser " + user + " deleted.");
return ret;
} catch (SQLException e) {
-
- log.info("Failed to DeleteUser "+user+".");
+
+ log.info("Failed to DeleteUser " + user + ".");
e.printStackTrace();
}
return -1;
}
-
-
-
-
-
- //no prepared statement to do here
+ // no prepared statement to do here
public ResultSet getImage() {
try {
Connection con = getConnection();
Statement stm = con.createStatement();
- ResultSet rs = stm
- .executeQuery("SELECT image_name FROM bwLehrpool.m_VLData_imageInfo;");
+ ResultSet rs = stm.executeQuery("SELECT image_name FROM bwLehrpool.m_VLData_imageInfo;");
con.close();
return rs;
} catch (SQLException e) {
-
+
log.info("Failed to getImage.");
e.printStackTrace();
}
return null;
}
-
-
-
public String getPathOfImage(String image_id, String version) {
try {
Connection con = getConnection();
-
- String sql = "SELECT image_path FROM bwLehrpool.m_VLData_imageInfo where GUID_imageID= "
- + "?"
- + " and imageVersion= "
- + "?"
- + ";";
-
+
+ String sql = "SELECT image_path FROM bwLehrpool.m_VLData_imageInfo where GUID_imageID= " + "?"
+ + " and imageVersion= " + "?" + ";";
+
PreparedStatement prest = con.prepareStatement(sql);
prest.setString(1, image_id);
prest.setString(2, version);
-
+
ResultSet rs = prest.executeQuery();
con.commit();
rs.first();
@@ -163,7 +131,7 @@ public class SQL { return path;
} catch (SQLException e) {
-
+
log.info("Failed to getPathOfImage.");
e.printStackTrace();
}
@@ -171,40 +139,34 @@ public class SQL { return null;
}
-
-
-
-
-
public String setInstitution(String university) {
try {
Connection con = getConnection();
-
+
String sql = "SELECT * FROM bwLehrpool.m_institution where name like ?;";
PreparedStatement prest = con.prepareStatement(sql);
prest.setString(1, university);
ResultSet ret = prest.executeQuery();
con.commit();
-
- if (ret.next() == false)
- {
+
+ if (ret.next() == false) {
String id = UUID.randomUUID().toString();
sql = "INSERT INTO `bwLehrpool`.`m_institution`(`institutionID`,`name`) VALUES" + "(?,?)";
-
+
prest = con.prepareStatement(sql);
prest.setString(1, id);
prest.setString(2, university);
prest.executeUpdate();
-
+
con.commit();
-
+
sql = "SELECT institutionID FROM bwLehrpool.m_institution WHERE name like ?;";
-
+
prest = con.prepareStatement(sql);
prest.setString(1, university);
-
+
ResultSet rs = prest.executeQuery();
con.commit();
rs.next();
@@ -219,45 +181,43 @@ public class SQL { }
} catch (SQLException e) {
-
+
log.info("Failed to setInstitution.");
e.printStackTrace();
}
return "-1";
}
-
-
-
-
-
-
-
- public String setPerson(String userID, String lastname, String firstname,
- String mail, Date lastlogin, String Institution) {
+ public String setPerson(String userID, String lastname, String firstname, String mail, Date lastlogin,
+ String Institution) {
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- try
- {
+ try {
Connection con = getConnection();
-
- String sql = "SELECT userID FROM bwLehrpool.m_user where Nachname like "
- + "?"
- + " and Vorname like "
- + "?"
- + ";";
-
+ String sql = "SELECT userID FROM bwLehrpool.m_user where Nachname like " + "?"
+ + " and Vorname like " + "?" + ";";
+
PreparedStatement prest = con.prepareStatement(sql);
prest.setString(1, lastname);
prest.setString(2, firstname);
-
+
ResultSet ret = prest.executeQuery();
con.commit();
- if (ret.next() == false)
- {
- log.info("create user statement values are: userID, loginname, lastname, firstname, mail, institution VALUES: "+userID+" "+userID+" "+lastname+" "+firstname+" "+mail+" "+Institution);
-
- sql = "INSERT INTO `bwLehrpool`.`m_user`(`userID`,`loginName`,`nachname`,`vorname`,`mail`,`lastLogin`,`institution`)VALUES("
+ if (ret.next() == false) {
+ log.info("create user statement values are: userID, loginname, lastname, firstname, mail, institution VALUES: "
+ + userID
+ + " "
+ + userID
+ + " "
+ + lastname
+ + " "
+ + firstname
+ + " "
+ + mail
+ + " "
+ + Institution);
+
+ sql = "INSERT INTO `bwLehrpool`.`m_user`(`userID`,`loginName`,`nachname`,`vorname`,`mail`,`lastLogin`,`institution`)VALUES("
+ "?"
+ ","
+ "?"
@@ -268,42 +228,34 @@ public class SQL { + ","
+ "?"
+ ",'"
- + formatter.format(new Date())
- + "',"
- + "?"
- + ");";
-
- prest = con.prepareStatement(sql);
- prest.setString(1, userID);
- prest.setString(2, userID);
- prest.setString(3, lastname);
- prest.setString(4, firstname);
- prest.setString(5, mail);
- prest.setString(6, Institution);
-
- prest.executeUpdate();
-
- con.commit();
-
- sql = "SELECT userID FROM bwLehrpool.m_user where Nachname like "
- + "?"
- + " and Vorname like "
- + "?"
- + ";";
-
- prest = con.prepareStatement(sql);
- prest.setString(1, lastname);
- prest.setString(2, firstname);
-
+ + formatter.format(new Date()) + "'," + "?" + ");";
+
+ prest = con.prepareStatement(sql);
+ prest.setString(1, userID);
+ prest.setString(2, userID);
+ prest.setString(3, lastname);
+ prest.setString(4, firstname);
+ prest.setString(5, mail);
+ prest.setString(6, Institution);
+
+ prest.executeUpdate();
+
+ con.commit();
+
+ sql = "SELECT userID FROM bwLehrpool.m_user where Nachname like " + "?"
+ + " and Vorname like " + "?" + ";";
+
+ prest = con.prepareStatement(sql);
+ prest.setString(1, lastname);
+ prest.setString(2, firstname);
+
ResultSet rs = prest.executeQuery();
con.commit();
rs.next();
String userid = rs.getString("userID");
con.close();
return userid;
- }
- else
- {
+ } else {
ret.first();
String userid = ret.getString("userID");
con.close();
@@ -311,27 +263,23 @@ public class SQL { }
} catch (SQLException e) {
-
+
log.info("Failed to setPerson.");
e.printStackTrace();
}
return "-1";
}
-
-
- public boolean setImageData(String pk_person, boolean license,
- boolean internet, long cpu, long ram, String imagename,
- String desc, String imagePath, long filesize, String shareMode,
- String pk_os, String uid)
- {
+ public boolean setImageData(String pk_person, boolean license, boolean internet, long cpu, long ram,
+ String imagename, String desc, String imagePath, long filesize, String shareMode, String pk_os,
+ String uid) {
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- log.info("userID came as pk_person to SQL as: "+pk_person);
- log.info("pk_os is: "+pk_os);
- log.info("uid is: "+uid);
-
+ log.info("userID came as pk_person to SQL as: " + pk_person);
+ log.info("pk_os is: " + pk_os);
+ log.info("uid is: " + uid);
+
int internet_bol = 0;
int license_bol = 0;
if (internet == true) {
@@ -352,7 +300,8 @@ public class SQL { + "?" // image_name
+ "," + "?" // image_description
+ "," + "?" // image_path
- + ",'" + formatter.format(new Date()) // image_lastCall
+ + ",'"
+ + formatter.format(new Date()) // image_lastCall
+ "','" + formatter.format(new Date()) // image_create_time
+ "','" + formatter.format(new Date()) // image_update_time
+ "'," + "?" // image_owner
@@ -377,7 +326,7 @@ public class SQL { + "," + "?" // image_filesize
+ "," + "?" // shareMode
+ ");";
-
+
PreparedStatement prest = con.prepareStatement(sql);
prest.setString(1, uid);
prest.setString(2, imagename);
@@ -394,13 +343,13 @@ public class SQL { prest.setLong(13, cpu);
prest.setLong(14, filesize);
prest.setString(15, shareMode);
-
+
prest.executeUpdate();
con.commit();
- //con.commit();
+ // con.commit();
con.close();
} catch (SQLException e) {
-
+
log.info("Failed to setImageData.");
e.printStackTrace();
}
@@ -408,13 +357,6 @@ public class SQL { }
-
-
-
-
-
-
-
public List<Image> getImageListPermissionWrite(String userID) {
Connection con = getConnection();
@@ -423,41 +365,30 @@ public class SQL { try {
String sql = "SELECT DISTINCT vl.GUID_imageID, vl.imageVersion, vl.image_name, vl.cond_hasLicenseRestriction, vl.image_filesize, os.name, os.architecture, '' as lecture, vl.image_update_time, Concat(u.Nachname,' ',u.Vorname) as user, vl.image_isTemplate, vl.image_description FROM bwLehrpool.pm_VLData_image pmi, bwLehrpool.m_VLData_imageInfo vl, bwLehrpool.m_operatingSystem os, bwLehrpool.m_user u WHERE u.userID = vl.image_owner AND vl.content_operatingSystem = os.operatingSystemID AND pmi.userID = "
- + "?"
- + " AND pmi.image_write = 1 AND pmi.GUID_imageID = vl.GUID_imageID ORDER BY vl.image_name;";
+ + "?"
+ + " AND pmi.image_write = 1 AND pmi.GUID_imageID = vl.GUID_imageID ORDER BY vl.image_name;";
PreparedStatement prest = con.prepareStatement(sql);
prest.setString(1, userID);
-
+
ResultSet res = prest.executeQuery();
con.commit();
while (res.next()) {
- list.add(new Image(res.getString("GUID_imageID"), res
- .getString("imageVersion"),
- res.getString("image_name"), res
- .getString("cond_hasLicenseRestriction"), res
- .getString("name")
- + " "
- + res.getString("architecture") + " bit", res
- .getString("lecture"), res
- .getString("image_update_time"), res
- .getString("user"), res
- .getString("image_isTemplate"),
- res.getString("image_description"),
- res.getString("image_filesize")));
+ list.add(new Image(res.getString("GUID_imageID"), res.getString("imageVersion"), res
+ .getString("image_name"), res.getString("cond_hasLicenseRestriction"), res
+ .getString("name") + " " + res.getString("architecture") + " bit", res
+ .getString("lecture"), res.getString("image_update_time"), res.getString("user"), res
+ .getString("image_isTemplate"), res.getString("image_description"), res
+ .getString("image_filesize")));
}
con.close();
} catch (SQLException e) {
-
+
e.printStackTrace();
}
return list;
}
-
-
-
-
public List<Image> getImageListPermissionRead(String userID) {
Connection con = getConnection();
@@ -465,46 +396,32 @@ public class SQL { List<Image> list = new ArrayList<Image>();
try {
-
String sql = "SELECT DISTINCT vl.GUID_imageID, vl.imageVersion, vl.image_name, vl.cond_hasLicenseRestriction, vl.image_filesize, os.name, os.architecture, '' as lecture, vl.image_update_time, Concat(u.Nachname,' ',u.Vorname) as user, vl.image_isTemplate, vl.image_description FROM bwLehrpool.pm_VLData_image pmi, bwLehrpool.m_VLData_imageInfo vl, bwLehrpool.m_operatingSystem os, bwLehrpool.m_user u WHERE u.userID = vl.image_owner AND vl.content_operatingSystem = os.operatingSystemID AND pmi.userID = "
- + "?"
- + " AND pmi.image_read = 1 AND pmi.GUID_imageID = vl.GUID_imageID ORDER BY vl.image_name;";
-
+ + "?"
+ + " AND pmi.image_read = 1 AND pmi.GUID_imageID = vl.GUID_imageID ORDER BY vl.image_name;";
+
PreparedStatement prest = con.prepareStatement(sql);
prest.setString(1, userID);
-
+
ResultSet res = prest.executeQuery();
con.commit();
- while (res.next())
- {
- list.add(new Image(res.getString("GUID_imageID"), res
- .getString("imageVersion"),
- res.getString("image_name"), res
- .getString("cond_hasLicenseRestriction"), res
- .getString("name")
- + " "
- + res.getString("architecture") + " bit", res
- .getString("lecture"), res
- .getString("image_update_time"), res
- .getString("user"), res
- .getString("image_isTemplate"),
- res.getString("image_description"),
- res.getString("image_filesize")));
+ while (res.next()) {
+ list.add(new Image(res.getString("GUID_imageID"), res.getString("imageVersion"), res
+ .getString("image_name"), res.getString("cond_hasLicenseRestriction"), res
+ .getString("name") + " " + res.getString("architecture") + " bit", res
+ .getString("lecture"), res.getString("image_update_time"), res.getString("user"), res
+ .getString("image_isTemplate"), res.getString("image_description"), res
+ .getString("image_filesize")));
}
con.close();
} catch (SQLException e) {
-
+
e.printStackTrace();
}
return list;
}
-
-
-
-
-
-
- //no prepared statement to do here
+
+ // no prepared statement to do here
public List<Image> getImageList(String userID) {
Connection con = getConnection();
@@ -517,33 +434,24 @@ public class SQL { // ResultSet
ResultSet res = stm
- .executeQuery("SELECT DISTINCT vl.GUID_imageID, vl.imageVersion, vl.image_name, vl.cond_hasLicenseRestriction, vl.image_filesize, os.name, os.architecture, '' as lecture, vl.image_update_time, Concat(u.Nachname,' ',u.Vorname) as user, vl.image_isTemplate, vl.image_description FROM bwLehrpool.pm_VLData_image pmi, bwLehrpool.m_VLData_imageInfo vl, bwLehrpool.m_operatingSystem os, bwLehrpool.m_user u WHERE u.userID = vl.image_owner AND vl.content_operatingSystem = os.operatingSystemID ORDER BY vl.image_name;");
+ .executeQuery("SELECT DISTINCT vl.GUID_imageID, vl.imageVersion, vl.image_name, vl.cond_hasLicenseRestriction, vl.image_filesize, os.name, os.architecture, '' as lecture, vl.image_update_time, Concat(u.Nachname,' ',u.Vorname) as user, vl.image_isTemplate, vl.image_description FROM bwLehrpool.pm_VLData_image pmi, bwLehrpool.m_VLData_imageInfo vl, bwLehrpool.m_operatingSystem os, bwLehrpool.m_user u WHERE u.userID = vl.image_owner AND vl.content_operatingSystem = os.operatingSystemID ORDER BY vl.image_name;");
while (res.next()) {
- list.add(new Image(res.getString("GUID_imageID"), res
- .getString("imageVersion"),
- res.getString("image_name"), res
- .getString("cond_hasLicenseRestriction"), res
- .getString("name")
- + " "
- + res.getString("architecture") + " bit", res
- .getString("lecture"), res
- .getString("image_update_time"), res
- .getString("user"), res
- .getString("image_isTemplate"),
- res.getString("image_description"),
- res.getString("image_filesize")));
+ list.add(new Image(res.getString("GUID_imageID"), res.getString("imageVersion"), res
+ .getString("image_name"), res.getString("cond_hasLicenseRestriction"), res
+ .getString("name") + " " + res.getString("architecture") + " bit", res
+ .getString("lecture"), res.getString("image_update_time"), res.getString("user"), res
+ .getString("image_isTemplate"), res.getString("image_description"), res
+ .getString("image_filesize")));
}
con.close();
} catch (SQLException e) {
-
+
e.printStackTrace();
}
return list;
}
-
-
public List<Image> getImageListPermissionLink(String userID) {
Connection con = getConnection();
@@ -552,85 +460,63 @@ public class SQL { try {
String sql = "SELECT DISTINCT vl.GUID_imageID, vl.imageVersion, vl.image_name, vl.cond_hasLicenseRestriction, vl.image_filesize, os.name, os.architecture, '' as lecture, vl.image_update_time, Concat(u.Nachname,' ',u.Vorname) as user, vl.image_isTemplate, vl.image_description FROM bwLehrpool.pm_VLData_image pmi, bwLehrpool.m_VLData_imageInfo vl, bwLehrpool.m_operatingSystem os, bwLehrpool.m_user u WHERE u.userID = vl.image_owner AND vl.content_operatingSystem = os.operatingSystemID AND pmi.userID = "
- + "?"
- + " AND pmi.link_allowed = 1 AND pmi.GUID_imageID = vl.GUID_imageID ORDER BY vl.image_name;";
-
+ + "?"
+ + " AND pmi.link_allowed = 1 AND pmi.GUID_imageID = vl.GUID_imageID ORDER BY vl.image_name;";
+
PreparedStatement prest = con.prepareStatement(sql);
prest.setString(1, userID);
-
+
ResultSet res = prest.executeQuery();
con.commit();
while (res.next()) {
- list.add(new Image(
- res.getString("GUID_imageID"),
- res.getString("imageVersion"),
- res.getString("image_name"),
- res.getString("cond_hasLicenseRestriction"),
- res.getString("name") + " " + res.getString("architecture") + " bit",
- res.getString("lecture"),
- res.getString("image_update_time"),
- res.getString("user"),
- res.getString("image_isTemplate"),
- res.getString("image_description"),
- res.getString("image_filesize")));
+ list.add(new Image(res.getString("GUID_imageID"), res.getString("imageVersion"), res
+ .getString("image_name"), res.getString("cond_hasLicenseRestriction"), res
+ .getString("name") + " " + res.getString("architecture") + " bit", res
+ .getString("lecture"), res.getString("image_update_time"), res.getString("user"), res
+ .getString("image_isTemplate"), res.getString("image_description"), res
+ .getString("image_filesize")));
}
con.close();
} catch (SQLException e) {
-
+
e.printStackTrace();
}
return list;
}
-
-
- public List<Image> getImageListPermissionAdmin(String userID){
+ public List<Image> getImageListPermissionAdmin(String userID) {
Connection con = getConnection();
List<Image> list = new ArrayList<Image>();
try {
String sql = "SELECT DISTINCT vl.GUID_imageID, vl.imageVersion, vl.image_name, vl.cond_hasLicenseRestriction, vl.image_filesize, os.name, os.architecture, '' as lecture, vl.image_update_time, Concat(u.Nachname,' ',u.Vorname) as user, vl.image_isTemplate, vl.image_description FROM bwLehrpool.pm_VLData_image pmi, bwLehrpool.m_VLData_imageInfo vl, bwLehrpool.m_operatingSystem os, bwLehrpool.m_user u WHERE u.userID = vl.image_owner AND vl.content_operatingSystem = os.operatingSystemID AND pmi.userID = "
- + "?"
- + " AND pmi.image_admin = 1 AND pmi.GUID_imageID = vl.GUID_imageID ORDER BY vl.image_name;";
-
+ + "?"
+ + " AND pmi.image_admin = 1 AND pmi.GUID_imageID = vl.GUID_imageID ORDER BY vl.image_name;";
+
PreparedStatement prest = con.prepareStatement(sql);
prest.setString(1, userID);
-
+
ResultSet res = prest.executeQuery();
con.commit();
- while (res.next())
- {
- list.add(new Image(
- res.getString("GUID_imageID"),
- res.getString("imageVersion"),
- res.getString("image_name"),
- res.getString("cond_hasLicenseRestriction"),
- res.getString("name") + " " + res.getString("architecture") + " bit",
- res.getString("lecture"),
- res.getString("image_update_time"),
- res.getString("user"),
- res.getString("image_isTemplate"),
- res.getString("image_description"),
- res.getString("image_filesize")
- )
- );
+ while (res.next()) {
+ list.add(new Image(res.getString("GUID_imageID"), res.getString("imageVersion"), res
+ .getString("image_name"), res.getString("cond_hasLicenseRestriction"), res
+ .getString("name") + " " + res.getString("architecture") + " bit", res
+ .getString("lecture"), res.getString("image_update_time"), res.getString("user"), res
+ .getString("image_isTemplate"), res.getString("image_description"), res
+ .getString("image_filesize")));
}
con.close();
} catch (SQLException e) {
-
+
e.printStackTrace();
}
return list;
- }//end getImageListPermissionAdmin
-
-
-
-
-
-
- //no prepared statement to do here
- public List<Image> getImageListAllTemplates(){
+ }// end getImageListPermissionAdmin
+
+ // no prepared statement to do here
+ public List<Image> getImageListAllTemplates() {
Connection con = getConnection();
Statement stm;
@@ -643,242 +529,193 @@ public class SQL { ResultSet res = stm
.executeQuery("SELECT DISTINCT vl.GUID_imageID, vl.imageVersion, vl.image_name, vl.image_description, vl.cond_hasLicenseRestriction, vl.image_filesize, os.name, os.architecture, '' as lecture, vl.image_update_time, Concat(u.Nachname,' ',u.Vorname) as user, vl.image_isTemplate FROM bwLehrpool.pm_VLData_image pmi, bwLehrpool.m_VLData_imageInfo vl, bwLehrpool.m_operatingSystem os, bwLehrpool.m_user u WHERE vl.image_isTemplate=1 AND vl.content_operatingSystem=os.operatingSystemID AND vl.image_owner=u.userID ORDER BY vl.image_name;");
-
- while (res.next())
- {
- list.add(new Image(
- res.getString("GUID_imageID"),
- res.getString("imageVersion"),
- res.getString("image_name"),
- res.getString("cond_hasLicenseRestriction"),
- res.getString("name") + " " + res.getString("architecture") + " bit",
- res.getString("lecture"),
- res.getString("image_update_time"),
- res.getString("user"),
- res.getString("image_isTemplate"),
- res.getString("image_description"),
- res.getString("image_filesize")
- )
- );
+ while (res.next()) {
+ list.add(new Image(res.getString("GUID_imageID"), res.getString("imageVersion"), res
+ .getString("image_name"), res.getString("cond_hasLicenseRestriction"), res
+ .getString("name") + " " + res.getString("architecture") + " bit", res
+ .getString("lecture"), res.getString("image_update_time"), res.getString("user"), res
+ .getString("image_isTemplate"), res.getString("image_description"), res
+ .getString("image_filesize")));
}
con.close();
} catch (SQLException e) {
-
+
e.printStackTrace();
}
return list;
- }//end getImageListAllTemplates
-
-
+ }// end getImageListAllTemplates
public List<Lecture> getLectureListPermissionRead(String userID) {
List<Lecture> list = new ArrayList<Lecture>();
try {
Connection con = getConnection();
-
+
String sql = "SELECT DISTINCT l.lectureID, l.name, l.isActive, l.startTime, l.endTime, l.lastUsed, l.description, i.image_name, concat(u.Nachname,' ',u.Vorname) as user "
- + "FROM bwLehrpool.m_VLData_lecture l, bwLehrpool.m_VLData_imageInfo i, bwLehrpool.pm_VLData_lecture pml, bwLehrpool.m_user u "
- + "WHERE u.userID = l.admin_owner AND pml.rec_read=1 AND i.GUID_imageID=l.imageID AND l.lectureID=pml.lectureID AND pml.userID = ? ORDER BY l.name;";
-
+ + "FROM bwLehrpool.m_VLData_lecture l, bwLehrpool.m_VLData_imageInfo i, bwLehrpool.pm_VLData_lecture pml, bwLehrpool.m_user u "
+ + "WHERE u.userID = l.admin_owner AND pml.rec_read=1 AND i.GUID_imageID=l.imageID AND l.lectureID=pml.lectureID AND pml.userID = ? ORDER BY l.name;";
+
PreparedStatement prest = con.prepareStatement(sql);
prest.setString(1, userID);
-
+
ResultSet res = prest.executeQuery();
con.commit();
- while (res.next())
- {
+ while (res.next()) {
- list.add(new Lecture(res.getString("lectureID"), res
- .getString("name"), res.getString("isActive"), res
- .getString("startTime"), res.getString("endTime"), res
- .getString("lastUsed"), res.getString("description"),
- res.getString("image_name"), res.getString("user")));
+ list.add(new Lecture(res.getString("lectureID"), res.getString("name"), res
+ .getString("isActive"), res.getString("startTime"), res.getString("endTime"), res
+ .getString("lastUsed"), res.getString("description"), res.getString("image_name"),
+ res.getString("user")));
}
con.close();
return list;
} catch (SQLException e) {
-
+
log.info("Failed to getLectureListPermissionRead.");
e.printStackTrace();
}
return list;
}// end getLectureListPermissionRead
-
-
public List<Lecture> getLectureListPermissionWrite(String userID) {
List<Lecture> list = new ArrayList<Lecture>();
try {
Connection con = getConnection();
-
+
String sql = "SELECT DISTINCT l.lectureID, l.name, l.isActive, l.startTime, l.endTime, l.lastUsed, l.description, i.image_name, concat(u.Nachname,' ',u.Vorname) as user "
- + "FROM bwLehrpool.m_VLData_lecture l, bwLehrpool.m_VLData_imageInfo i, bwLehrpool.pm_VLData_lecture pml, bwLehrpool.m_user u "
- + "WHERE pml.userID="
- + "?"
- + " AND u.userID = l.admin_owner AND pml.rec_write=1 AND i.GUID_imageID=l.imageID AND l.lectureID=pml.lectureID ORDER BY l.name;";
-
+ + "FROM bwLehrpool.m_VLData_lecture l, bwLehrpool.m_VLData_imageInfo i, bwLehrpool.pm_VLData_lecture pml, bwLehrpool.m_user u "
+ + "WHERE pml.userID="
+ + "?"
+ + " AND u.userID = l.admin_owner AND pml.rec_write=1 AND i.GUID_imageID=l.imageID AND l.lectureID=pml.lectureID ORDER BY l.name;";
+
PreparedStatement prest = con.prepareStatement(sql);
prest.setString(1, userID);
-
+
ResultSet res = prest.executeQuery();
con.commit();
- while (res.next())
- {
+ while (res.next()) {
- list.add(new Lecture(res.getString("lectureID"), res
- .getString("name"), res.getString("isActive"), res
- .getString("startTime"), res.getString("endTime"), res
- .getString("lastUsed"), res.getString("description"),
- res.getString("image_name"), res.getString("user")));
+ list.add(new Lecture(res.getString("lectureID"), res.getString("name"), res
+ .getString("isActive"), res.getString("startTime"), res.getString("endTime"), res
+ .getString("lastUsed"), res.getString("description"), res.getString("image_name"),
+ res.getString("user")));
}
con.close();
return list;
} catch (SQLException e) {
-
+
log.info("Failed to getLectureListPermissionWrite.");
e.printStackTrace();
}
return list;
}// end getLectureListPermissionWrite
-
-
-
-
-
- public List<Lecture> getLectureListPermissionAdmin(String userID)
- {
+ public List<Lecture> getLectureListPermissionAdmin(String userID) {
List<Lecture> list = new ArrayList<Lecture>();
try {
Connection con = getConnection();
String sql = "SELECT DISTINCT l.lectureID, l.name, l.isActive, l.startTime, l.endTime, l.lastUsed, l.description, i.image_name, concat(u.Nachname,' ',u.Vorname) as user "
- + "FROM bwLehrpool.m_VLData_lecture l, bwLehrpool.m_VLData_imageInfo i, bwLehrpool.pm_VLData_lecture pml, bwLehrpool.m_user u "
- + "WHERE u.userID = l.admin_owner AND pml.rec_admin=1 AND i.GUID_imageID=l.imageID AND l.lectureID=pml.lectureID AND pml.userID= ? ORDER BY l.name;";
-
+ + "FROM bwLehrpool.m_VLData_lecture l, bwLehrpool.m_VLData_imageInfo i, bwLehrpool.pm_VLData_lecture pml, bwLehrpool.m_user u "
+ + "WHERE u.userID = l.admin_owner AND pml.rec_admin=1 AND i.GUID_imageID=l.imageID AND l.lectureID=pml.lectureID AND pml.userID= ? ORDER BY l.name;";
+
PreparedStatement prest = con.prepareStatement(sql);
prest.setString(1, userID);
-
+
ResultSet res = prest.executeQuery();
con.commit();
- while (res.next())
- {
+ while (res.next()) {
- list.add(new Lecture(res.getString("lectureID"), res
- .getString("name"), res.getString("isActive"), res
- .getString("startTime"), res.getString("endTime"), res
- .getString("lastUsed"), res.getString("description"),
- res.getString("image_name"), res.getString("user")));
+ list.add(new Lecture(res.getString("lectureID"), res.getString("name"), res
+ .getString("isActive"), res.getString("startTime"), res.getString("endTime"), res
+ .getString("lastUsed"), res.getString("description"), res.getString("image_name"),
+ res.getString("user")));
}
con.close();
return list;
} catch (SQLException e) {
-
+
log.info("Failed to getLectureListPermissionAdmin.");
e.printStackTrace();
}
return list;
}// end getLectureListPermissionAdmin
-
-
-
-
-
- //No prepared statement to do here
+ // No prepared statement to do here
public List<Lecture> getLectureList() {
List<Lecture> list = new ArrayList<Lecture>();
- try
- {
+ try {
Connection con = getConnection();
Statement stm = con.createStatement();
ResultSet res = stm
.executeQuery("SELECT l.lectureID, l.name, l.isActive,l.startTime,l.endTime,l.lastUsed,l.description, i.image_name, concat(u.Nachname,' ',u.Vorname) as user FROM bwLehrpool.m_VLData_lecture l, bwLehrpool.m_VLData_imageInfo i, bwLehrpool.m_user u WHERE i.GUID_imageID=l.imageID and l.admin_owner=u.userID ORDER BY l.name;");
-
-
- while (res.next())
- {
- list.add(new Lecture(res.getString("lectureID"), res
- .getString("name"), res.getString("isActive"), res
- .getString("startTime"), res.getString("endTime"), res
- .getString("lastUsed"), res.getString("description"),
- res.getString("image_name"), res.getString("user")));
+ while (res.next()) {
+
+ list.add(new Lecture(res.getString("lectureID"), res.getString("name"), res
+ .getString("isActive"), res.getString("startTime"), res.getString("endTime"), res
+ .getString("lastUsed"), res.getString("description"), res.getString("image_name"),
+ res.getString("user")));
}
con.close();
return list;
} catch (SQLException e) {
-
+
log.info("Failed to getLectureList.");
e.printStackTrace();
}
return null;
}
-
-
-
- //No prepared statement to do here
- public List<String> getAllOS()
- {
-
- //if(authenticated())
- //{
- List<String> list = new ArrayList<>();
- try {
- Connection con = getConnection();
- Statement stm = con.createStatement();
- ResultSet rs = stm
- .executeQuery("SELECT name, architecture FROM bwLehrpool.m_operatingSystem ORDER BY name, architecture;");
- while (rs.next()) {
- list.add(rs.getString("name") + " "
- + rs.getString("architecture") + " bit");
- }
- return list;
-
- } catch (SQLException e) {
-
- log.info("Failed to getAllOS.");
- e.printStackTrace();
+ // No prepared statement to do here
+ public List<String> getAllOS() {
+
+ // if(authenticated())
+ // {
+ List<String> list = new ArrayList<>();
+ try {
+ Connection con = getConnection();
+ Statement stm = con.createStatement();
+ ResultSet rs = stm
+ .executeQuery("SELECT name, architecture FROM bwLehrpool.m_operatingSystem ORDER BY name, architecture;");
+ while (rs.next()) {
+ list.add(rs.getString("name") + " " + rs.getString("architecture") + " bit");
}
-
- return null;
+ return list;
+
+ } catch (SQLException e) {
+
+ log.info("Failed to getAllOS.");
+ e.printStackTrace();
+ }
+
+ return null;
- //}
- //return null;
+ // }
+ // return null;
}
-
-
-
-
-
public Map<String, String> getPersonData(String Vorname, String Nachname) {
Map<String, String> map = new HashMap<String, String>();
try {
Connection con = getConnection();
String sql = "SELECT u.Nachname, u.Vorname, u.mail, i.name FROM bwLehrpool.m_user u, bwLehrpool.m_institution i where u.Nachname like "
- + "?"
- + " and u.Vorname like "
- + "?"
- + " and u.institution=i.institutionID;";
-
+ + "?" + " and u.Vorname like " + "?" + " and u.institution=i.institutionID;";
+
PreparedStatement prest = con.prepareStatement(sql);
prest.setString(1, Vorname);
prest.setString(2, Nachname);
-
+
ResultSet rs = prest.executeQuery();
con.commit();
- while (rs.next())
- {
+ while (rs.next()) {
map.put("mail", rs.getString("mail"));
map.put("Nachname", rs.getString("Nachname"));
@@ -889,122 +726,110 @@ public class SQL { con.close();
return map;
} catch (SQLException e) {
-
+
log.info("Failed to getPersonData.");
e.printStackTrace();
}
return null;
- }//end getPersonData
-
-
-
-
+ }// end getPersonData
+
public Map<String, String> getPersonData(String userID) {
Map<String, String> map = new HashMap<String, String>();
try {
Connection con = getConnection();
String sql = "SELECT userID, loginName, Nachname, Vorname, mail, m_institution.name as institution FROM bwLehrpool.m_user, m_institution WHERE userID=? AND m_user.institution=m_institution.institutionID;";
-
+
PreparedStatement prest = con.prepareStatement(sql);
prest.setString(1, userID);
-
+
ResultSet rs = prest.executeQuery();
con.commit();
- while (rs.next())
- {
+ while (rs.next()) {
map.put("userID", rs.getString("userID"));
map.put("loginName", rs.getString("loginName"));
map.put("Nachname", rs.getString("Nachname"));
map.put("Vorname", rs.getString("Vorname"));
- map.put("mail", rs.getString("mail"));
+ map.put("mail", rs.getString("mail"));
map.put("institution", rs.getString("institution"));
}
con.close();
return map;
} catch (SQLException e) {
- log.info("Failed to getPersonData with userID='"+userID+"'.");
+ log.info("Failed to getPersonData with userID='" + userID + "'.");
e.printStackTrace();
}
return null;
- }//end getPersonData
-
-
+ }// end getPersonData
-
-
public Map<String, String> getItemOwner(String itemID) {
-
+
Map<String, String> map = new HashMap<String, String>();
Connection con = getConnection();
PreparedStatement prest;
String userID;
-
+
try {
- //find out if the itemID belongs to an image
+ // find out if the itemID belongs to an image
String sql = "SELECT image_owner FROM bwLehrpool.m_VLData_imageInfo WHERE GUID_imageID=?;";
prest = con.prepareStatement(sql);
prest.setString(1, itemID);
-
- ResultSet rs = prest.executeQuery();
- while (rs.next()){
- map.put("userID",rs.getString("image_owner"));
+
+ ResultSet rs = prest.executeQuery();
+ while (rs.next()) {
+ map.put("userID", rs.getString("image_owner"));
}
-
- //if map is empty, then itemID does not belong to an image -> must be a lecture
- if(map.isEmpty()==true){
- //check if itemID belongs to a lecture
+
+ // if map is empty, then itemID does not belong to an image -> must
+ // be a lecture
+ if (map.isEmpty() == true) {
+ // check if itemID belongs to a lecture
sql = "SELECT admin_owner FROM bwLehrpool.m_VLData_lecture WHERE lectureID=?;";
prest = con.prepareStatement(sql);
prest.setString(1, itemID);
-
+
rs = prest.executeQuery();
- while(rs.next()){
+ while (rs.next()) {
map.put("userID", rs.getString("admin_owner"));
}
}
-
- //if map is still empty, then the itemID could not be found
- if(map.isEmpty()==true){
- log.error("Failed to getItemOwner for item '"+itemID+"'.");
+
+ // if map is still empty, then the itemID could not be found
+ if (map.isEmpty() == true) {
+ log.error("Failed to getItemOwner for item '" + itemID + "'.");
} else {
-
- //now that we have the userID for this item, get the user information and put it in the map
- userID = map.get("userID"); //extract the userID
- map = getPersonData(userID); //get all the rest of his information
-
- //return this map with all the infos
+
+ // now that we have the userID for this item, get the user
+ // information and put it in the map
+ userID = map.get("userID"); // extract the userID
+ map = getPersonData(userID); // get all the rest of his
+ // information
+
+ // return this map with all the infos
return map;
-
+
}
-
+
} catch (SQLException e) {
e.printStackTrace();
}
-
- //something went horribly wrong...
+
+ // something went horribly wrong...
return null;
- }//end getItemOwner
-
-
-
-
- public int setLectureData(String pk_person, String pk_image,
- int imageversion, String name, String desc, String shortdesc,
- String start, String end, boolean isactive, String lectureID)
- {
+ }// end getItemOwner
+
+ public int setLectureData(String pk_person, String pk_image, int imageversion, String name, String desc,
+ String shortdesc, String start, String end, boolean isactive, String lectureID) {
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
int active_bol = 0;
- if (isactive == true)
- {
+ if (isactive == true) {
active_bol = 1;
}
-
- try
- {
+
+ try {
Connection con = getConnection();
String sql = "INSERT INTO `bwLehrpool`.`m_VLData_lecture`(`lectureID`,`name`,`isActive`,`startTime`,`endTime`,`lastUsed`,`shortDescription`,`description`,`imageID`,`imageVersion`,`admin_createTime`,`admin_changeTime`,`admin_owner`,`admin_change_by`)VALUES("
@@ -1035,7 +860,7 @@ public class SQL { + "?"
+ ","
+ "?" + ");";
-
+
PreparedStatement prest = con.prepareStatement(sql);
prest.setString(1, lectureID);
prest.setString(2, name);
@@ -1048,13 +873,13 @@ public class SQL { prest.setInt(9, imageversion);
prest.setString(10, pk_person);
prest.setString(11, pk_person);
-
+
prest.executeUpdate();
con.commit();
con.close();
} catch (SQLException e) {
-
+
log.info("Failed to setLectureData.");
e.printStackTrace();
}
@@ -1062,59 +887,49 @@ public class SQL { }
-
-
-
public Map<String, String> getImageIDandVersion(String id) {
Map<String, String> map = new HashMap<String, String>();
try {
Connection con = getConnection();
String sql = "SELECT GUID_imageID, imageVersion FROM bwLehrpool.m_VLData_imageInfo where GUID_imageID = ?";
-
+
PreparedStatement prest = con.prepareStatement(sql);
prest.setString(1, id);
-
+
ResultSet image = prest.executeQuery();
con.commit();
while (image.next()) {
map.put("GUID", image.getString("GUID_imageID"));
- map.put("version",
- String.valueOf(image.getString("imageVersion")));
+ map.put("version", String.valueOf(image.getString("imageVersion")));
}
con.close();
return map;
} catch (SQLException e) {
-
+
log.info("Failed to getImageIDandVersion.");
e.printStackTrace();
}
return null;
}
-
-
-
-
public Map<String, String> getImageData(String id, String version) {
Map<String, String> map = new HashMap<String, String>();
try {
Connection con = getConnection();
String sql = "SELECT u.mail, i.GUID_imageID, i.imageVersion, i.image_name,i.image_description,i.image_update_time,i.cond_hasInternetRestriction,i.cond_hasLicenseRestriction, i.cond_minCPUs,i.cond_minRAM, i.image_syncMode,i.image_filesize,i.image_path, i.image_isTemplate,os.GuestOS, concat(u.Nachname,' ',u.Vorname) as Owner FROM bwLehrpool.m_VLData_imageInfo i,bwLehrpool.m_user u,bwLehrpool.m_operatingSystem os where i.image_owner=u.userID and i.content_operatingSystem=os.operatingSystemID and GUID_imageID = ? and imageVersion = ? ;";
-
+
PreparedStatement prest = con.prepareStatement(sql);
prest.setString(1, id);
prest.setString(2, version);
-
+
ResultSet data = prest.executeQuery();
con.commit();
- while (data.next())
- {
+ while (data.next()) {
map.put("name", data.getString("image_name"));
- map.put("internet",
- data.getString("cond_hasInternetRestriction"));
+ map.put("internet", data.getString("cond_hasInternetRestriction"));
map.put("license", data.getString("cond_hasLicenseRestriction"));
map.put("cpu", data.getString("cond_minCPUs"));
map.put("ram", data.getString("cond_minRAM"));
@@ -1134,73 +949,35 @@ public class SQL { con.close();
return map;
} catch (SQLException e) {
-
+
log.info("Failed to getImageData.");
e.printStackTrace();
}
return null;
}
-
-
-
-
- public int UpdateImageData(String name, String newName, String desc,
- String image_path, boolean license, boolean internet, long cpu,
- long ram, String id, String version, boolean isTemplate,
- long filesize, String shareMode, String ospk)
-{
+
+ public int UpdateImageData(String name, String newName, String desc, String image_path, boolean license,
+ boolean internet, long cpu, long ram, String id, String version, boolean isTemplate,
+ long filesize, String shareMode, String ospk) {
try {
Connection con = getConnection();
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- //Statement stm = con.createStatement();
+ // Statement stm = con.createStatement();
int newVersion = Integer.parseInt(version) + 1;
int internet_bol = 0;
int license_bol = 0;
-
- if (internet == true)
- {
+
+ if (internet == true) {
internet_bol = 1;
}
-
- if (license == true)
- {
+
+ if (license == true) {
license_bol = 1;
}
- /*
- log.info("'image_name` = '" + newName
- + "\n length of name=" + newName.length());
-
- log.info("now in UpdateImageData()");
- log.info("UPDATE bwLehrpool.m_VLData_imageInfo SET imageVersion = "
- + newVersion + ",image_name = '" + newName
- + "',`image_description` = '" + desc + "',`image_path` = '"
- + image_path + "',`image_update_time` = '"
- + formatter.format(new Date()) + "',`rec_change_time` = '"
- + formatter.format(new Date())
- + "',`cond_hasLicenseRestriction` = '" + license_bol
- + "',`cond_hasInternetRestriction` = '" + internet_bol
- + "',`cond_minRAM` = '"
- + ram
- + "',`cond_minCPUs` = '"
- + cpu
- + "',`image_isTemplate` = '"
- // + isTemplate
- + "0'" + ",`content_operatingSystem` = " + ospk
- + ",`image_filesize` = " + filesize
- + ",`image_syncMode` = '" + shareMode
- + "' WHERE GUID_imageID = '" + id + "' AND imageVersion = "
- + version + ";");
- */
-
- String sql = "UPDATE bwLehrpool.m_VLData_imageInfo SET imageVersion = "
- + "?"
- + ",image_name = "
- + "?"
- + ",image_description = "
- + "?"
- + " ,image_path = "
- + "?"
+
+ String sql = "UPDATE bwLehrpool.m_VLData_imageInfo SET imageVersion = " + "?" + ",image_name = "
+ + "?" + ",image_description = " + "?" + " ,image_path = " + "?"
+ " ,image_update_time = '"
+ formatter.format(new Date())
+ "' ,rec_change_time = '"
@@ -1224,9 +1001,8 @@ public class SQL { + "?"
+ " WHERE GUID_imageID = "
+ "?"
- + " AND imageVersion = "
- + "?" + ";";
-
+ + " AND imageVersion = " + "?" + ";";
+
PreparedStatement prest = con.prepareStatement(sql);
prest.setInt(1, newVersion);
prest.setString(2, newName);
@@ -1241,51 +1017,46 @@ public class SQL { prest.setString(11, shareMode);
prest.setString(12, id);
prest.setString(13, version);
-
+
prest.executeUpdate();
-
- con.commit(); //needed, though executeUpdate()!
- //con.commit();
+ con.commit(); // needed, though executeUpdate()!
+
+ // con.commit();
con.close();
return 0;
} catch (SQLException e) {
-
+
log.info("Failed to UpdateImageData.");
e.printStackTrace();
}
return -1;
}
-
-
-
- public boolean deleteImage(String id, String version)
- {
+ public boolean deleteImage(String id, String version) {
try {
Connection con = getConnection();
- //delete the image record
+ // delete the image record
String sql = "DELETE FROM bwLehrpool.m_VLData_imageInfo WHERE GUID_imageID = ? AND imageVersion = ?;";
PreparedStatement prest = con.prepareStatement(sql);
prest.setString(1, id);
prest.setString(2, version);
prest.executeUpdate();
- //delete all permission records for this image
+ // delete all permission records for this image
sql = "DELETE FROM bwLehrpool.pm_VLData_image WHERE GUID_imageID = ?";
prest = con.prepareStatement(sql);
prest.setString(1, id);
prest.executeUpdate();
-
-
+
con.commit();
con.close();
return true;
} catch (SQLException e) {
-
+
log.info("Failed to deleteImage and permissions.");
e.printStackTrace();
}
@@ -1293,43 +1064,23 @@ public class SQL { return false;
}
-
-
-
-
- public int updateLectureData(String pk_image, String imageversion,
- String name, String newName, String desc, String shortdesc,
- String start, String end, boolean isactive, String id)
- {
+ public int updateLectureData(String pk_image, String imageversion, String name, String newName,
+ String desc, String shortdesc, String start, String end, boolean isactive, String id) {
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
int active_bol = 0;
- if (isactive == true)
- {
+ if (isactive == true) {
active_bol = 1;
}
try {
Connection con = getConnection();
- String sql = "UPDATE `bwLehrpool`.`m_VLData_lecture` SET `name` = "
- + "?"
- + ",isActive = "
- + "?"
- + ",startTime = "
- + "?"
- + ",endTime = "
- + "?"
- + ",description = "
- + "?"
- + ",imageID = "
- + "?"
- + ",imageVersion = "
- + "?"
- + ",admin_changeTime = '"
- + formatter.format(new Date())
+ String sql = "UPDATE `bwLehrpool`.`m_VLData_lecture` SET `name` = " + "?" + ",isActive = " + "?"
+ + ",startTime = " + "?" + ",endTime = " + "?" + ",description = " + "?" + ",imageID = "
+ + "?" + ",imageVersion = " + "?" + ",admin_changeTime = '" + formatter.format(new Date())
+ "'WHERE `lectureID` = ?;";
-
+
PreparedStatement prest = con.prepareStatement(sql);
prest.setString(1, newName);
prest.setInt(2, active_bol);
@@ -1339,14 +1090,14 @@ public class SQL { prest.setString(6, pk_image);
prest.setString(7, imageversion);
prest.setString(8, id);
-
+
prest.executeUpdate();
con.commit();
con.close();
- //log.info("Succeeded to updateLectureData.");
+ // log.info("Succeeded to updateLectureData.");
} catch (SQLException e) {
-
+
log.info("Failed to updateLectureData.");
e.printStackTrace();
}
@@ -1354,18 +1105,18 @@ public class SQL { return 0;
}
-
public boolean connectedToLecture(String id, String version) {
try {
Connection con = getConnection();
-
- String sql = "SELECT lectureID FROM "+ "bwLehrpool.m_VLData_lecture WHERE imageID = ? AND imageVersion = ?;";
+
+ String sql = "SELECT lectureID FROM "
+ + "bwLehrpool.m_VLData_lecture WHERE imageID = ? AND imageVersion = ?;";
PreparedStatement prest = con.prepareStatement(sql);
prest.setString(1, id);
prest.setString(2, version);
-
+
ResultSet rs = prest.executeQuery();
con.commit();
boolean ret = rs.first();
@@ -1373,7 +1124,7 @@ public class SQL { return ret;
} catch (SQLException e) {
-
+
log.info("Failed to execute method connectedToLecture.");
e.printStackTrace();
}
@@ -1381,35 +1132,31 @@ public class SQL { return false;
}
-
-
-
public boolean deleteLecture(String id) {
try {
Connection con = getConnection();
-
- //delete the lecture record
+
+ // delete the lecture record
String sql = "DELETE FROM bwLehrpool.m_VLData_lecture WHERE lectureID = ?;";
PreparedStatement prest = con.prepareStatement(sql);
- prest.setString(1, id);
-
+ prest.setString(1, id);
+
prest.executeUpdate();
-
- //delete all permission records for this lecture
+ // delete all permission records for this lecture
sql = "DELETE FROM bwLehrpool.pm_VLData_lecture WHERE lectureID = ?;";
prest = con.prepareStatement(sql);
- prest.setString(1, id);
-
+ prest.setString(1, id);
+
prest.executeUpdate();
-
+
con.commit();
con.close();
return true;
} catch (SQLException e) {
-
+
log.info("Failed to deleteLecture and permissions.");
e.printStackTrace();
}
@@ -1417,35 +1164,28 @@ public class SQL { return false;
}
-
-
public String getFile(String imageid, String imageversion) {
try {
Connection con = getConnection();
- Statement stm = con.createStatement();
- String sql = "SELECT image_path FROM bwLehrpool.m_VLData_imageInfo WHERE GUID_imageID = "
- + "?"
- + " AND imageVersion = "
- + "?"
- + ";";
-
+ String sql = "SELECT image_path FROM bwLehrpool.m_VLData_imageInfo WHERE GUID_imageID = " + "?"
+ + " AND imageVersion = " + "?" + ";";
+
PreparedStatement prest = con.prepareStatement(sql);
prest.setString(1, imageid);
prest.setString(2, imageversion);
-
+
ResultSet rs = prest.executeQuery();
con.commit();
-
-
+
rs.next();
String path = rs.getString("image_path");
con.close();
return path;
} catch (SQLException e) {
-
+
log.info("Failed to getFile.");
e.printStackTrace();
}
@@ -1453,89 +1193,75 @@ public class SQL { return null;
}
-
-
-
public Map<String, String> getDeleteXMLData(String id) {
Map<String, String> map = new HashMap<String, String>();
try {
Connection con = getConnection();
String sql = "SELECT name, admin_createTime FROM bwLehrpool.m_VLData_lecture where lectureID = ?;";
-
+
PreparedStatement prest = con.prepareStatement(sql);
prest.setString(1, id);
-
+
ResultSet rs = prest.executeQuery();
con.commit();
rs.next();
-
- map.put("date", rs.getString("admin_createTime").replace(" ", "")
- .replace("-", "").replace(":", ""));
+
+ map.put("date",
+ rs.getString("admin_createTime").replace(" ", "").replace("-", "").replace(":", ""));
map.put("name", rs.getString("name"));
con.close();
return map;
} catch (SQLException e) {
-
+
log.info("Failed to getDeleteXMLData.");
e.printStackTrace();
}
return null;
}
-
-
-
public int UpdateImagePath(String name) {
try {
Connection con = getConnection();
- Statement stm = con.createStatement();
-
- String sql = "UPDATE bwLehrpool.m_VLData_imageInfo SET image_path = "
- + "?" //prod/+name
- + " WHERE image_path = "
- + "?" //temp/+name
- + ";";
-
+ String sql = "UPDATE bwLehrpool.m_VLData_imageInfo SET image_path = " + "?" // prod/+name
+ + " WHERE image_path = " + "?" // temp/+name
+ + ";";
+
PreparedStatement prest = con.prepareStatement(sql);
- prest.setString(1, "prod/"+name);
- prest.setString(2, "temp/"+name);
-
+ prest.setString(1, "prod/" + name);
+ prest.setString(2, "temp/" + name);
+
prest.executeUpdate();
-
-
+
con.commit();
con.close();
- //log.info("Succesfully updated image path");
+ // log.info("Succesfully updated image path");
return 0;
} catch (SQLException e) {
-
+
log.info("Failed to UpdateImagePath.");
e.printStackTrace();
}
return -1;
}
-
-
public List<String> getAllUniversities() {
List<String> list = new ArrayList<>();
try {
Connection con = getConnection();
Statement stm = con.createStatement();
- ResultSet rs = stm
- .executeQuery("SELECT name FROM bwLehrpool.m_institution;");
+ ResultSet rs = stm.executeQuery("SELECT name FROM bwLehrpool.m_institution;");
while (rs.next()) {
list.add(rs.getString("name"));
}
return list;
} catch (SQLException e) {
-
+
log.info("Failed to getAllUniversities.");
e.printStackTrace();
}
@@ -1543,61 +1269,54 @@ public class SQL { return null;
}
-
-
+
public String getOSpk(String os, String architecture) {
try {
Connection con = getConnection();
- Statement stm = con.createStatement();
- //log.info("Getting PrimaryKey for OS: " + os + " architecture: " + architecture);
-
+ // log.info("Getting PrimaryKey for OS: " + os + " architecture: " +
+ // architecture);
+
String sql = "SELECT operatingSystemID FROM bwLehrpool.m_operatingSystem where name like ? and architecture like ?;";
PreparedStatement prest = con.prepareStatement(sql);
prest.setString(1, os);
prest.setString(2, architecture);
-
+
ResultSet rs = prest.executeQuery();
con.commit();
rs.first();
String pkos = rs.getString("operatingSystemID");
- //log.info(" - Key is " + pkos);
+ // log.info(" - Key is " + pkos);
con.close();
return pkos;
} catch (SQLException e) {
-
+
log.info("Failed to getOSpk.");
e.printStackTrace();
}
-
return null;
}
-
-
-
public String getOS(String pk) {
try {
Connection con = getConnection();
- Statement stm = con.createStatement();
// log.info(new Date() +
// " - OS: "+os+" architecture: "+architecture);
String sql = "SELECT name,architecture FROM bwLehrpool.m_operatingSystem where operatingSystemID = ?;";
-
+
PreparedStatement prest = con.prepareStatement(sql);
prest.setString(1, pk);
-
+
ResultSet rs = prest.executeQuery();
con.commit();
rs.first();
- String os = rs.getString("name") + " "
- + rs.getString("architecture");
+ String os = rs.getString("name") + " " + rs.getString("architecture");
con.close();
return os;
} catch (SQLException e) {
-
+
log.info("Failed to getOS.");
e.printStackTrace();
}
@@ -1605,17 +1324,15 @@ public class SQL { return null;
}
-
-
public Map<String, String> getLectureData(String id) {
Map<String, String> map = new HashMap<String, String>();
try {
Connection con = getConnection();
-
- String sql = "select l.name, l.isActive, l.startTime, l.endTime, l.lastUsed, l.description, i.image_path, l.imageVersion, concat(u.Nachname,' ',u.Vorname) as owner from m_VLData_lecture l, m_user u, m_VLData_imageInfo i where l.admin_owner=u.userID and l.imageID=i.GUID_imageID and lectureID= ?" ;
+
+ String sql = "select l.name, l.isActive, l.startTime, l.endTime, l.lastUsed, l.description, i.image_path, l.imageVersion, concat(u.Nachname,' ',u.Vorname) as owner from m_VLData_lecture l, m_user u, m_VLData_imageInfo i where l.admin_owner=u.userID and l.imageID=i.GUID_imageID and lectureID= ?";
PreparedStatement prest = con.prepareStatement(sql);
prest.setString(1, id);
-
+
ResultSet data = prest.executeQuery();
con.commit();
while (data.next()) {
@@ -1633,62 +1350,50 @@ public class SQL { con.close();
return map;
} catch (SQLException e) {
-
+
log.info("Failed to getLectureData.");
e.printStackTrace();
}
return null;
}
-
-
-
- public boolean checkUser(String username)
- {
-
+ public boolean checkUser(String username) {
+
boolean ret = false;
try {
Connection con = getConnection();
-
+
String sql = "Select * from m_user where loginName like ?";
PreparedStatement prest = con.prepareStatement(sql);
prest.setString(1, username);
-
+
ResultSet rs = prest.executeQuery();
con.commit();
- if (rs.next())
- {
+ if (rs.next()) {
ret = true;
- log.info("Checking user: " + rs.getString("loginName")
- + " exists.");
+ log.info("Checking user: " + rs.getString("loginName") + " exists.");
} else {
ret = false;
- log.info("Checking user: " + rs.getString("loginName")
- + " does not exist.");
+ log.info("Checking user: " + rs.getString("loginName") + " does not exist.");
}
con.close();
} catch (SQLException e) {
-
e.printStackTrace();
}
return ret;
}
-
-
-
public int getRoleID(String role) {
try {
Connection con = getConnection();
- Statement stm = con.createStatement();
-
+
String sql = "SELECT roleID FROM bwLehrpool.m_role where name like ?;";
PreparedStatement prest = con.prepareStatement(sql);
prest.setString(1, role);
-
+
ResultSet rs = prest.executeQuery();
con.commit();
rs.first();
@@ -1696,48 +1401,41 @@ public class SQL { return rs.getInt("roleID");
} catch (SQLException e) {
-
+
log.info("Failed to getRoleID.");
e.printStackTrace();
}
return -1;
}
-
-
-
public String getLectureID(String name) {
String id = null;
try {
Connection con = getConnection();
- Statement stm = con.createStatement();
String sql = "SELECT lectureID FROM bwLehrpool.m_VLData_lecture where name like ?;";
PreparedStatement prest = con.prepareStatement(sql);
prest.setString(1, name);
-
+
ResultSet lecture = prest.executeQuery();
con.commit();
- while (lecture.next())
- {
+ while (lecture.next()) {
id = lecture.getString("lectureID");
}
con.close();
return id;
} catch (SQLException e) {
-
+
log.info("Failed to getLectureID.");
e.printStackTrace();
}
return id;
}
-
-
// get all users from satellite -- temp, tb replaced by allUsers bwLehrpool
// does -NOT- return the user himself
- //TODO prepared statement
+ // TODO prepared statement
public List<Person> getAllOtherSatelliteUsers(List<String> userID) {
Connection con = getConnection();
Statement stm = null;
@@ -1748,7 +1446,7 @@ public class SQL { try {
stm = con.createStatement();
} catch (SQLException e) {
-
+
e.printStackTrace();
}
String query = "SELECT userID, Nachname, Vorname, mail FROM m_user WHERE userID NOT IN ('"
@@ -1758,75 +1456,58 @@ public class SQL { query = query + "','" + userID.get(i);
}
query = query + "') ORDER BY Nachname ASC;";
-
+
try {
res = stm.executeQuery(query);
} catch (SQLException e1) {
-
+
e1.printStackTrace();
}
-
+
try {
while (res.next()) {
// fill the list with users - permissions are all false because
// the image is new
- list.add(new Person(res.getString("userID"), res
- .getString("Nachname"), res.getString("Vorname"), res
- .getString("mail"), false, false, false, false, false,
+ list.add(new Person(res.getString("userID"), res.getString("Nachname"), res
+ .getString("Vorname"), res.getString("mail"), false, false, false, false, false,
false, false));
}
} catch (SQLException e) {
-
+
e.printStackTrace();
}
return list;
}// end getAllOtherSatelliteUsers()
-
-
-
-
-
-
-
// get the permissions of an image for all other registered users -EXCEPT-
// the logged on user
- public List<Person> getPermissionForUserAndImage(String userID,
- String imageID) {
-
+ public List<Person> getPermissionForUserAndImage(String userID, String imageID) {
+
Connection con = getConnection();
- Statement stm = null;
ResultSet res = null;
List<Person> list = new ArrayList<Person>();
try {
- stm = con.createStatement();
- } catch (SQLException e) {
-
- e.printStackTrace();
- }
- try {
-
-
+
String sql = "SELECT DISTINCT pmi.GUID_imageID, pmi.userID, u.userID, u.Nachname, u.Vorname, u.mail, pmi.image_read, pmi.image_write, pmi.image_admin, pmi.link_allowed FROM bwLehrpool.pm_VLData_image pmi, bwLehrpool.m_user u WHERE pmi.userID!= "
- + "?"
- + " AND pmi.GUID_imageID= "
- + "?"
- + " AND pmi.userID=u.userID ORDER BY u.Nachname ASC;";
-
+ + "?"
+ + " AND pmi.GUID_imageID= "
+ + "?"
+ + " AND pmi.userID=u.userID ORDER BY u.Nachname ASC;";
+
PreparedStatement prest = con.prepareStatement(sql);
prest.setString(1, userID);
prest.setString(2, imageID);
-
+
res = prest.executeQuery();
con.commit();
} catch (SQLException e) {
-
+
e.printStackTrace();
}
try {
- boolean image_read, image_write, link_allowed, image_admin, lecture_read, lecture_write, lecture_admin;
+ boolean image_read, image_write, link_allowed, image_admin;
while (res.next()) {
// reset old values and set the correct new values
@@ -1834,9 +1515,6 @@ public class SQL { image_write = false;
link_allowed = false;
image_admin = false;
- lecture_read = false;
- lecture_write = false;
- lecture_admin = false;
if (Integer.parseInt(res.getString("image_read")) != 0) {
image_read = true;
@@ -1853,64 +1531,51 @@ public class SQL { // fill the list with users - permissions are all false because
// the image is new
- list.add(new Person(res.getString("userID"), res
- .getString("Nachname"), res.getString("Vorname"), res
- .getString("mail"), image_read, image_write,
- link_allowed, image_admin, false, // lecture_read
+ list.add(new Person(res.getString("userID"), res.getString("Nachname"), res
+ .getString("Vorname"), res.getString("mail"), image_read, image_write, link_allowed,
+ image_admin, false, // lecture_read
false, // lecture_write
false) // lecture_admin
);
// System.out.println(res.getString("Nachname")+" "+Boolean.parseBoolean(res.getString("image_read"))+" "+Boolean.parseBoolean(res.getString("image_write"))+" "+Boolean.parseBoolean(res.getString("image_admin")));
}
} catch (SQLException e) {
-
+
e.printStackTrace();
}
return list;
}// end getPermissionFOrUserAndImage()
-
-
-
-
-
- // get the permissions of a lecture for all other registered users -EXCEPT- the logged on user
- public List<Person> getPermissionForUserAndLecture(String userID,
- String lectureID) {
-
+
+ // get the permissions of a lecture for all other registered users -EXCEPT-
+ // the logged on user
+ public List<Person> getPermissionForUserAndLecture(String userID, String lectureID) {
+
Connection con = getConnection();
- //Statement stm = null;
+ // Statement stm = null;
ResultSet res = null;
List<Person> list = new ArrayList<Person>();
-
-
-
try {
- String sql = "SELECT DISTINCT pml.lectureID, pml.userID, u.userID, u.Nachname, u.Vorname, u.mail, pml.rec_read, pml.rec_write, pml.rec_admin " +
- "FROM bwLehrpool.pm_VLData_lecture pml, bwLehrpool.m_user u WHERE pml.userID!= ? AND pml.lectureID= ? AND pml.userID=u.userID ORDER BY u.Nachname ASC;";
-
+ String sql = "SELECT DISTINCT pml.lectureID, pml.userID, u.userID, u.Nachname, u.Vorname, u.mail, pml.rec_read, pml.rec_write, pml.rec_admin "
+ + "FROM bwLehrpool.pm_VLData_lecture pml, bwLehrpool.m_user u WHERE pml.userID!= ? AND pml.lectureID= ? AND pml.userID=u.userID ORDER BY u.Nachname ASC;";
+
PreparedStatement prest = con.prepareStatement(sql);
prest.setString(1, userID);
prest.setString(2, lectureID);
-
+
res = prest.executeQuery();
con.commit();
-
+
} catch (SQLException e) {
-
+
e.printStackTrace();
}
try {
- boolean image_read, image_write, link_allowed, image_admin, lecture_read, lecture_write, lecture_admin;
+ boolean lecture_read, lecture_write, lecture_admin;
- while (res.next())
- {
+ while (res.next()) {
// reset old values and set the correct new values
- image_read = false;
- image_write = false;
- link_allowed = false;
- image_admin = false;
lecture_read = false;
lecture_write = false;
lecture_admin = false;
@@ -1927,15 +1592,11 @@ public class SQL { // fill the list with users - permissions are all false because
// the image is new
- list.add(new Person(
- res.getString("userID"),
- res.getString("Nachname"),
- res.getString("Vorname"),
- res.getString("mail"),
- false, //image read
- false, //image write
- false, //image link
- false, //image admin
+ list.add(new Person(res.getString("userID"), res.getString("Nachname"), res
+ .getString("Vorname"), res.getString("mail"), false, // image read
+ false, // image write
+ false, // image link
+ false, // image admin
lecture_read, // lecture_read
lecture_write, // lecture_write
lecture_admin) // lecture_admin
@@ -1943,29 +1604,26 @@ public class SQL { // System.out.println(res.getString("Nachname")+" "+Boolean.parseBoolean(res.getString("image_read"))+" "+Boolean.parseBoolean(res.getString("image_write"))+" "+Boolean.parseBoolean(res.getString("image_admin")));
}
} catch (SQLException e) {
-
+
e.printStackTrace();
}
return list;
}// end getPermissionForUserAndLecture
-
-
-
-
- public int setImageRights(String pk_person, String pk_image, int role,
- int read, int write, int linkallowed, int admin) {
+ public int setImageRights(String pk_person, String pk_image, int role, int read, int write,
+ int linkallowed, int admin) {
try {
Connection con = getConnection();
- //Statement stm = con.createStatement();
+ // Statement stm = con.createStatement();
String uid = UUID.randomUUID().toString();
- String sql = "INSERT INTO bwLehrpool.pm_VLData_image(GUID,GUID_imageID,roleID,userID,image_read,image_write,image_admin,link_allowed)VALUES" + "(?,?,?,?,?,?,?,?)";
-
+ String sql = "INSERT INTO bwLehrpool.pm_VLData_image(GUID,GUID_imageID,roleID,userID,image_read,image_write,image_admin,link_allowed)VALUES"
+ + "(?,?,?,?,?,?,?,?)";
+
PreparedStatement prest = con.prepareStatement(sql);
-
+
prest.setString(1, uid);
prest.setString(2, pk_image);
prest.setInt(3, role);
@@ -1974,37 +1632,36 @@ public class SQL { prest.setInt(6, write);
prest.setInt(7, admin);
prest.setInt(8, linkallowed);
-
+
prest.executeUpdate();
-
+
con.commit();
con.close();
-
+
} catch (SQLException e) {
-
+
log.info("Failed to setImageRights.");
e.printStackTrace();
}
return 0;
}// end setImageRights
- public boolean writeAdditionalImageRights(String imageID, String userID,boolean isRead, boolean isWrite, boolean isLinkAllowed,boolean isAdmin)
- {
+ public boolean writeAdditionalImageRights(String imageID, String userID, boolean isRead, boolean isWrite,
+ boolean isLinkAllowed, boolean isAdmin) {
boolean success = true;
String uid = UUID.randomUUID().toString();
-
+
Connection con = getConnection();
try {
-
- String sql = "INSERT INTO pm_VLData_image (" + "GUID, "
- + "GUID_imageID, " + "roleID, " + "userID, "
- + "image_read, " + "image_write, " + "link_allowed,"
- + "Image_admin)" + "VALUES" + "(?,?,?,?,?,?,?,?)";
-
+
+ String sql = "INSERT INTO pm_VLData_image (" + "GUID, " + "GUID_imageID, " + "roleID, "
+ + "userID, " + "image_read, " + "image_write, " + "link_allowed," + "Image_admin)"
+ + "VALUES" + "(?,?,?,?,?,?,?,?)";
+
PreparedStatement prest = con.prepareStatement(sql);
-
+
prest.setString(1, uid);
prest.setString(2, imageID);
prest.setInt(3, 1);
@@ -2013,60 +1670,56 @@ public class SQL { prest.setBoolean(6, isWrite);
prest.setBoolean(7, isLinkAllowed);
prest.setBoolean(8, isAdmin);
-
+
prest.executeUpdate();
con.commit();
con.close();
-
- //log.info("Written additional image rights.");
-
+
+ // log.info("Written additional image rights.");
+
} catch (SQLException e) {
-
+
e.printStackTrace();
log.info("Failed to write additional image rights.");
}
return success;
}// end writeAdditionalImageRights
-
-
- public int setLectureRights(String pk_person, String pk_lecture, int role,
- int read, int write, int admin) {
+ public int setLectureRights(String pk_person, String pk_lecture, int role, int read, int write, int admin) {
try {
Connection con = getConnection();
- //Statement stm = con.createStatement();
+ // Statement stm = con.createStatement();
String uid = UUID.randomUUID().toString();
- String sql = "INSERT INTO `bwLehrpool`.`pm_VLData_lecture`(`GUID`,`lectureID`,`userID`,`rec_read`,`rec_write`,`rec_admin`)VALUES" + "(?,?,?,?,?,?)";
-
+ String sql = "INSERT INTO `bwLehrpool`.`pm_VLData_lecture`(`GUID`,`lectureID`,`userID`,`rec_read`,`rec_write`,`rec_admin`)VALUES"
+ + "(?,?,?,?,?,?)";
+
PreparedStatement prest = con.prepareStatement(sql);
-
+
prest.setString(1, uid);
prest.setString(2, pk_lecture);
prest.setString(3, pk_person);
prest.setInt(4, read);
prest.setInt(5, write);
prest.setInt(6, admin);
-
+
prest.executeUpdate();
-
con.commit();
- log.info("Written lecture rights for lecture '" + pk_lecture+"'.");
+ log.info("Written lecture rights for lecture '" + pk_lecture + "'.");
con.close();
} catch (SQLException e) {
-
+
log.info("Failed to setLectureRights.");
e.printStackTrace();
}
return 0;
} // end setLectureRights
-
- public boolean writeAdditionalLectureRights(String lectureID,
- String userID, boolean isRead, boolean isWrite, boolean isAdmin) {
+ public boolean writeAdditionalLectureRights(String lectureID, String userID, boolean isRead,
+ boolean isWrite, boolean isAdmin) {
boolean success = true;
String uid = UUID.randomUUID().toString();
@@ -2074,51 +1727,50 @@ public class SQL { try {
- String sql = "INSERT INTO pm_VLData_lecture (GUID, lectureID, userID, rec_read, rec_write, rec_admin) VALUES"
+ String sql = "INSERT INTO pm_VLData_lecture (GUID, lectureID, userID, rec_read, rec_write, rec_admin) VALUES"
+ ("(?,?,?,?,?,?)");
-
+
PreparedStatement prest = con.prepareStatement(sql);
-
+
prest.setString(1, uid);
prest.setString(2, lectureID);
prest.setString(3, userID);
prest.setBoolean(4, isRead);
prest.setBoolean(5, isWrite);
prest.setBoolean(6, isAdmin);
-
- //log.info("userdata: "+uid+" "+lectureID + " " + userID + " " + isRead + isWrite + isAdmin);
-
+
+ // log.info("userdata: "+uid+" "+lectureID + " " + userID + " " +
+ // isRead + isWrite + isAdmin);
+
prest.executeUpdate();
-
+
con.commit();
con.close();
- //log.info("Written additional lecture rights for '"+ userID + "'.");
+ // log.info("Written additional lecture rights for '"+ userID +
+ // "'.");
} catch (SQLException e) {
-
+
e.printStackTrace();
log.info("Failed to write additional lecture rights.");
}
return success;
}// end writeAdditionalLectureRights
-
-
- public void deleteAllAdditionalImagePermissions(String imageID,
- String userID) {
+ public void deleteAllAdditionalImagePermissions(String imageID, String userID) {
Connection con = getConnection();
try {
-
- String sql = "DELETE FROM pm_VLData_image WHERE GUID_imageID = ? AND userID != ?;";
+
+ String sql = "DELETE FROM pm_VLData_image WHERE GUID_imageID = ? AND userID != ?;";
PreparedStatement prest = con.prepareStatement(sql);
-
+
prest.setString(1, imageID);
prest.setString(2, userID);
-
+
prest.executeUpdate();
-
+
} catch (SQLException e) {
-
+
e.printStackTrace();
}
@@ -2127,13 +1779,11 @@ public class SQL { con.commit();
} catch (SQLException e) {
-
+
e.printStackTrace();
}
}// end deleteAllAdditionalImagePermissions
-
-
-
+
public void deleteAllAdditionalLecturePermissions(String lectureID, String userID) {
Connection con = getConnection();
@@ -2141,10 +1791,10 @@ public class SQL { String sql = "DELETE FROM pm_VLData_lecture WHERE lectureID = ? AND userID != ?;";
PreparedStatement prest = con.prepareStatement(sql);
-
+
prest.setString(1, lectureID);
prest.setString(2, userID);
-
+
prest.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
@@ -2155,167 +1805,142 @@ public class SQL { con.commit();
} catch (SQLException e) {
-
+
e.printStackTrace();
}
}// end deleteAllAdditionalImagePermissions
-
-
- public List<String> getAdditionalImageContacts(String imageID)
- {
-
- List<String> list = new ArrayList<>();
-
- Connection con = getConnection();
- Statement stm;
- try
- {
-
- String sql = "select distinct u.Nachname, u.Vorname, u.mail from bwLehrpool.pm_VLData_image img, bwLehrpool.m_user u where GUID_imageID = ? and image_write = '1' and img.userID = u.userID;";
- PreparedStatement prest = con.prepareStatement(sql);
-
- prest.setString(1, imageID);
-
- ResultSet rs = prest.executeQuery();
- con.commit();
-
- while (rs.next())
- {
- list.add(rs.getString("Nachname") + "," + rs.getString("Vorname")+" ");
- }
-
- } catch (SQLException e) {
-
- e.printStackTrace();
+ public List<String> getAdditionalImageContacts(String imageID) {
+
+ List<String> list = new ArrayList<>();
+
+ Connection con = getConnection();
+ try {
+
+ String sql = "select distinct u.Nachname, u.Vorname, u.mail from bwLehrpool.pm_VLData_image img, bwLehrpool.m_user u where GUID_imageID = ? and image_write = '1' and img.userID = u.userID;";
+ PreparedStatement prest = con.prepareStatement(sql);
+
+ prest.setString(1, imageID);
+
+ ResultSet rs = prest.executeQuery();
+ con.commit();
+
+ while (rs.next()) {
+ list.add(rs.getString("Nachname") + "," + rs.getString("Vorname") + " ");
}
- return list;
-
- }
+ } catch (SQLException e) {
+
+ e.printStackTrace();
+ }
+ return list;
+
+ }
public String getOsNameForGuestOs(String guestOS) {
Connection con = getConnection();
ResultSet rs = null;
String sql = "Select name, architecture from bwLehrpool.m_operatingSystem where guestOS = ?";
-
- try
- {
-
+
+ try {
+
PreparedStatement prest = con.prepareStatement(sql);
prest.setString(1, guestOS);
rs = prest.executeQuery();
con.commit();
rs.next();
-
+
return rs.getString("name") + " " + rs.getString("architecture") + " bit";
-
+
} catch (SQLException e) {
-
+
e.printStackTrace();
}
-
+
return null;
-
- }
+ }
- - public String createRandomUUID()
- {
+ public String createRandomUUID() {
return UUID.randomUUID().toString();
}
-
- public boolean userIsImageAdmin(String userID, String imageID)
- {
+ public boolean userIsImageAdmin(String userID, String imageID) {
Connection con = getConnection();
ResultSet rs = null;
String sql = "SELECT image_admin FROM bwLehrpool.pm_VLData_image WHERE userID= ? AND GUID_imageID=?";
-
- log.info("stmt user is image admin: " + "SELECT image_admin FROM bwLehrpool.pm_VLData_image WHERE userID= '"+userID+"' AND GUID_imageID='"+imageID+"'");
-
- try
- {
+
+ log.info("stmt user is image admin: "
+ + "SELECT image_admin FROM bwLehrpool.pm_VLData_image WHERE userID= '" + userID
+ + "' AND GUID_imageID='" + imageID + "'");
+
+ try {
PreparedStatement prest = con.prepareStatement(sql);
prest.setString(1, userID);
prest.setString(2, imageID);
rs = prest.executeQuery();
con.commit();
rs.next();
-
+
return rs.getBoolean("image_admin");
-
+
} catch (SQLException e) {
-
+
e.printStackTrace();
}
return false;
}
-
-
-
public boolean userIsLectureAdmin(String userID, String lectureID) {
Connection con = getConnection();
ResultSet rs = null;
String sql = "SELECT rec_admin FROM bwLehrpool.pm_VLData_lecture WHERE userID= ? AND lectureID=?";
-
- try
- {
+
+ try {
PreparedStatement prest = con.prepareStatement(sql);
prest.setString(1, userID);
prest.setString(2, lectureID);
rs = prest.executeQuery();
con.commit();
rs.next();
-
+
return rs.getBoolean("rec_admin");
-
+
} catch (SQLException e) {
-
+
e.printStackTrace();
}
return false;
}
+ public String getInstitutionByID(String institutionID, String errorParam) {
-
-
- public String getInstitutionByID(String institutionID,String errorParam) {
-
Connection con = getConnection();
ResultSet rs = null;
String sql = "SELECT name FROM bwLehrpool.m_institution WHERE institutionID = ?";
-
- log.info("intitution ID is: "+institutionID);
-
+
+ log.info("intitution ID is: " + institutionID);
+
PreparedStatement prest;
try {
-
-
+
prest = con.prepareStatement(sql);
prest.setString(1, institutionID);
-
+
rs = prest.executeQuery();
- //con.commit();
+ // con.commit();
rs.next();
return rs.getString("name");
-
+
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
-
+
return null;
-
}
- -
- -
}// end class
|
