diff options
| author | unknown | 2014-05-25 17:49:07 +0200 |
|---|---|---|
| committer | unknown | 2014-05-25 17:49:07 +0200 |
| commit | b0b65eca6b6600a57d71c5f63f8e5a066e6accd7 (patch) | |
| tree | 21b55c6f7ff2c60401ede9f369738b2ae2d5f77f /Dozentenmodulserver/src/server/ServerHandler.java | |
| parent | links + encoding (diff) | |
| parent | Freigabe Mechanismus implementiert, nun sollte die notwendige Grundlage für d... (diff) | |
| download | tutor-module-b0b65eca6b6600a57d71c5f63f8e5a066e6accd7.tar.gz tutor-module-b0b65eca6b6600a57d71c5f63f8e5a066e6accd7.tar.xz tutor-module-b0b65eca6b6600a57d71c5f63f8e5a066e6accd7.zip | |
Merge branch 'master' of ssh://git.openslx.org/openslx-ng/tutor-module
Conflicts:
ffffDozentenmodul/bin/gui/image/CreateImageTechnisch_GUI.class
Dozentenmodul/bin/gui/image/DeleteImage_GUI.class
Dozentenmodul/bin/gui/image/EditImageAllgemein_GUI.class
Dozentenmodul/bin/gui/image/FTPCreateUploader_GUI$8.class
Dozentenmodul/bin/gui/image/FTPCreateUploader_GUI.class
Dozentenmodul/bin/gui/image/FTPDownloader_GUI.class
Dozentenmodul/bin/gui/image/FTPEditUploader_GUI.class
Dozentenmodul/bin/gui/image/SearchEditImage_GUI.class
Dozentenmodul/bin/gui/image/SearchImage_GUI.class
Dozentenmodul/bin/gui/intro/VmWareLink_GUI.class
Dozentenmodul/bin/gui/lecture/CreateLectureAllgemein_GUI.class
Dozentenmodul/bin/gui/lecture/EditLectureAllgemein_GUI.class
Dozentenmodul/bin/gui/lecture/ExtendedSearchForImages_GUI.class
Dozentenmodul/src/gui/lecture/EditLectureLink_GUI.java
Dozentenmodul/src/models/Links.java
Diffstat (limited to 'Dozentenmodulserver/src/server/ServerHandler.java')
| -rw-r--r-- | Dozentenmodulserver/src/server/ServerHandler.java | 293 |
1 files changed, 90 insertions, 203 deletions
diff --git a/Dozentenmodulserver/src/server/ServerHandler.java b/Dozentenmodulserver/src/server/ServerHandler.java index 5744003a..5ce72615 100644 --- a/Dozentenmodulserver/src/server/ServerHandler.java +++ b/Dozentenmodulserver/src/server/ServerHandler.java @@ -8,10 +8,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -import java.sql.Connection; -import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -26,9 +23,11 @@ import org.apache.thrift.TException; import sql.SQL; import util.XMLCreator; + + public class ServerHandler implements Server.Iface { static SQL sql = new SQL(); - static Connection con = sql.getConnection(); + private static Logger log = Logger.getLogger(ServerHandler.class); @Override @@ -38,18 +37,15 @@ public class ServerHandler implements Server.Iface { user.setUserName(UUID.randomUUID().toString().substring(0, 8)); user.setPassword(getEncodedSha1Sum(UUID.randomUUID().toString() .substring(0, 8))); - if(Configuration.config.getAbsolute_path().endsWith("/")) - { + if (Configuration.config.getAbsolute_path().endsWith("/")) { user.setPath(Configuration.config.getAbsolute_path()); + } else { + user.setPath(Configuration.config.getAbsolute_path() + "/"); } - else{ - user.setPath(Configuration.config.getAbsolute_path()+"/"); - } - SQL sql = new SQL(); - Connection con = sql.getConnection(); + // check if folder temp exists if (folderTempExists() == true) { - sql.writeFTPUser(con, user.getUserName(), user.getPassword()); + sql.writeFTPUser(user.getUserName(), user.getPassword()); return user; } else { log.info(new Date() + " - returning null user"); @@ -59,15 +55,11 @@ public class ServerHandler implements Server.Iface { public boolean folderTempExists() { // check if folder temp exists, otherwise create it - Path path=null; - if(Configuration.config.getAbsolute_path().endsWith("/")) - { - path = Paths - .get(Configuration.config.getAbsolute_path() + "temp"); - } - else{ - path = Paths - .get(Configuration.config.getAbsolute_path() + "/temp"); + Path path = null; + if (Configuration.config.getAbsolute_path().endsWith("/")) { + path = Paths.get(Configuration.config.getAbsolute_path() + "temp"); + } else { + path = Paths.get(Configuration.config.getAbsolute_path() + "/temp"); } if (Files.exists(path) == true) { @@ -83,9 +75,9 @@ public class ServerHandler implements Server.Iface { + "'"); return false; } else { - //set permissions + // set permissions try { - Runtime.getRuntime().exec("chmod 777 "+path); + Runtime.getRuntime().exec("chmod 777 " + path); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -112,26 +104,16 @@ public class ServerHandler implements Server.Iface { @Override public long DeleteFtpUser(String user) throws TException { - int ret = sql.DeleteUser(con, user); - return ret; + return sql.DeleteUser(user); } @Override public String getPathOfImage(String image_id, String version) throws TException { + log.info(new Date() + " - successfully returned PathOfImage: " + + sql.getPathOfImage(image_id, version)); + return sql.getPathOfImage(image_id, version); - try { - ResultSet rs = sql.getPathOfImage(con, image_id, version); - rs.next(); - log.info(new Date() + " - successfully returned PathOfImage: " - + rs.getString("image_path")); - return rs.getString("image_path"); - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - log.info(new Date() + " - returning PathOfImage: null"); - return null; } @Override @@ -139,15 +121,25 @@ public class ServerHandler implements Server.Iface { String firstname, String lastname, String university, String Mail, String Tel, String Fak, boolean license, boolean internet, long ram, long cpu, String imagePath, boolean isTemplate, - long filesize) throws TException { + long filesize, long shareMode) throws TException { + + String mode=null; + + if(shareMode==0) + { + mode="only_local"; + } + else{ + mode="to_be_published"; + } - String pk_institution = sql.setInstitution(con, university); + String pk_institution = sql.setInstitution(university); - String pk_person = sql.setPerson(con, login, lastname, firstname, Mail, + String pk_person = sql.setPerson(login, lastname, firstname, Mail, new Date(), pk_institution); - - sql.setImageData(con, pk_person, license, internet, cpu, ram, - imagename, imagePath, isTemplate, filesize); + + sql.setImageData(pk_person, license, internet, cpu, ram, imagename, + imagePath, isTemplate, filesize,mode); log.info(new Date() + " - written VLdata"); // TODO Auto-generated method stub @@ -156,73 +148,21 @@ public class ServerHandler implements Server.Iface { @Override public List<Image> getImageList() throws TException { - ResultSet res = sql.getImageList(con); - - List<Image> list = new ArrayList<Image>(); + return sql.getImageList(); - try { - - 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("lecture"), - res.getString("image_update_time"), res - .getString("user"))); - - } - - return list; - } catch (SQLException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - log.info(new Date() + " - returning ImageList: " + list.size() - + " items."); - return null; } @Override public List<String> getAllOS() throws TException { - List<String> list = new ArrayList<>(); - ResultSet rs = sql.getAllOS(con); - try { - while (rs.next()) { - list.add(rs.getString("name")); - } - return list; - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return null; + return sql.getAllOS(); + } @Override public Map<String, String> getPersonData(String Vorname, String Nachname) throws TException { - Map<String, String> map = new HashMap<String, String>(); - - ResultSet rs = sql.getPersonData(con, Vorname, Nachname); - try { - while (rs.next()) { - - map.put("mail", rs.getString("mail")); - map.put("Nachname", rs.getString("Nachname")); - map.put("Vorname", rs.getString("Vorname")); - map.put("Hochschule", rs.getString("name")); + return sql.getPersonData(Vorname, Nachname); - } - return map; - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - log.info(new Date() + " - returning PersonData: " + map.size() - + " items."); - return null; } @Override @@ -232,27 +172,19 @@ public class ServerHandler implements Server.Iface { String university, String Mail, String Tel, String Fak) throws TException { String pk_image = null; - + Map<String, String> map = new HashMap<String, String>(); int imageversion = 0; - String pk_institution = sql.setInstitution(con, university); - String pk_person = sql.setPerson(con, login, lastname, firstname, Mail, + String pk_institution = sql.setInstitution(university); + String pk_person = sql.setPerson(login, lastname, firstname, Mail, new Date(), pk_institution); - ResultSet image = sql.getImageIDandVersion(con, imagename); - - try { - while (image.next()) { - pk_image = image.getString("GUID_imageID"); - imageversion = image.getInt("imageVersion"); - } - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + map = sql.getImageIDandVersion(imagename); - sql.setLectureData(con, pk_person, pk_image, imageversion, name, desc, + pk_image = map.get("GUID"); + imageversion = Integer.parseInt(map.get("version")); + sql.setLectureData(pk_person, pk_image, imageversion, name, desc, shortdesc, startDate, endDate, isActive); - XMLCreator xml = new XMLCreator(con, name); + XMLCreator xml = new XMLCreator(sql.getConnection(), name); try { xml.create(name); log.info(new Date() + " - XML created."); @@ -271,6 +203,7 @@ public class ServerHandler implements Server.Iface { @Override public boolean startFileCopy(String filename) throws TException { + //copy file from folder temp to folder prod String file = Configuration.config.getAbsolute_path() + "temp/" + filename; File tmpFile = new File(file); @@ -279,17 +212,13 @@ public class ServerHandler implements Server.Iface { + " - Trying to move file to '/srv/openslx/nfs/prod/" + tmpFile.getName() + "'"); try { - - // der übergebene Filename ist falsch - hier muss der generierte - // name geholt werden, nicht der ursprüngliche name. wo wird dieser - // eingelesen? - FileUtils.moveFile(tmpFile, new File(Configuration.config.getAbsolute_path() + "prod/" + filename)); - int ret = sql.UpdateImagePath(con, filename); - log.info(new Date() + " - update " + ret); - log.info(new Date() + " - file moved"); + // int ret = sql.UpdateImagePath(filename); + if (sql.UpdateImagePath(filename) == 0) { + log.info(new Date() + " - file moved and database updated."); + } } catch (IOException e) { // TODO Auto-generated catch block @@ -302,43 +231,27 @@ public class ServerHandler implements Server.Iface { @Override public Map<String, String> getImageData(String imageid, String imageversion) throws TException { - - ResultSet data = sql.getImageData(con, imageid, imageversion); - - Map<String, String> map = new HashMap<String, String>(); - try { - while (data.next()) { - System.out.println(data - .getString("cond_hasInternetRestriction") - + data.getString("cond_hasLicenseRestriction") - + data.getString("cond_minCPUs") - + data.getString("cond_minRAM")); - map.put("name", data.getString("image_name")); - 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")); - - } - return map; - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - log.info(new Date() + " - returning ImageData: " + map.size() - + "items."); - return null; - + log.info(new Date() + " - returning ImageData: " + + sql.getImageData(imageid, imageversion).size() + "items."); + return sql.getImageData(imageid, imageversion); } @Override public boolean updateImageData(String name, String newName, String image_path, boolean license, boolean internet, long ram, long cpu, String id, String version, boolean isTemplate, - long filesize) throws TException { - sql.UpdateImageData(con, name, newName, image_path, license, internet, - cpu, ram, id, version, isTemplate, filesize); + long filesize, long shareMode) throws TException { + String mode=null; + + if(shareMode==0) + { + mode="only_local"; + } + else{ + mode="to_be_published"; + } + sql.UpdateImageData(name, newName, image_path, license, internet, cpu, + ram, id, version, isTemplate, filesize,mode); return false; } @@ -351,29 +264,13 @@ public class ServerHandler implements Server.Iface { @Override public List<Lecture> getLectureList() throws TException { - ResultSet res = sql.getLectureList(con); - List<Lecture> list = new ArrayList<Lecture>(); - try { - - 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"))); + log.info(new Date().toString() + " - returning LectureList: " + + sql.getLectureList().size() + " items."); + return sql.getLectureList(); + - } - return list; - } catch (SQLException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - log.info(new Date() + " - returning LectureList: " + list.size() - + " items."); - return null; } @Override @@ -384,21 +281,14 @@ public class ServerHandler implements Server.Iface { String Fak, String id) throws TException { String pk_image = ""; int imageversion = 0; - ResultSet image = sql.getImageIDandVersion(con, imagename); + Map<String, String> image = sql.getImageIDandVersion(imagename); - try { - while (image.next()) { - pk_image = image.getString("GUID_imageID"); - imageversion = image.getInt("imageVersion"); - } - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - sql.updateLectureData(con, pk_image, imageversion, lastname, newName, - desc, shortdesc, startDate, endDate, isActive, id); + pk_image = image.get("GUID"); + imageversion = Integer.parseInt(image.get("version")); + sql.updateLectureData(pk_image, imageversion, lastname, newName, desc, + shortdesc, startDate, endDate, isActive, id); - XMLCreator xml = new XMLCreator(con, newName); + XMLCreator xml = new XMLCreator(sql.getConnection(), newName); try { xml.create(newName); } catch (SQLException | ParserConfigurationException @@ -416,14 +306,14 @@ public class ServerHandler implements Server.Iface { public boolean deleteImageServer(String imageid, String imageversion) throws TException { - String stringFile = sql.getFile(con, imageid, imageversion); + String stringFile = sql.getFile(imageid, imageversion); log.info(new Date() + " - File to Delete: " + stringFile); File tmpFile = new File(Configuration.config.getAbsolute_path() + stringFile); try { - // File wird von Server gelöscht + // File wird von Server gel�scht FileUtils.forceDelete(tmpFile); return true; @@ -439,36 +329,33 @@ public class ServerHandler implements Server.Iface { @Override public boolean deleteImageData(String id, String version) throws TException { - return sql.deleteImage(con, id, version); + return sql.deleteImage(id, version); } @Override public boolean connectedToLecture(String id, String version) throws TException { // TODO Auto-generated method stub - return sql.connectedToLecture(con, id, version); + return sql.connectedToLecture(id, version); } public boolean deleteLecture(String id, String hs, String user) { - ResultSet rs = sql.getDeleteXMLData(con, id); + Map<String, String> map = new HashMap<String, String>(); + map = sql.getDeleteXMLData(id); try { - rs.next(); - String date = rs.getString("admin_createTime").replace(" ", "") - .replace("-", "").replace(":", ""); - String name = rs.getString("name"); - String path = Configuration.config.getAbsolute_path() + "temp/" - + date.substring(0, date.length() - 2) + "_" + hs + "_" - + user + "_" + name + ".xml"; + + String path = Configuration.config.getAbsolute_path() + + "temp/" + + map.get("date") + .substring(0, map.get("date").length() - 2) + "_" + + hs + "_" + user + "_" + map.get("name") + ".xml"; File xmlFile = new File(path); FileUtils.forceDelete(xmlFile); - } catch (SQLException e) { - log.info(new Date() + " - Failed to execute deleteLecture"); - e.printStackTrace(); } catch (IOException e) { log.info(new Date() + " - Failed to execute deleteLecture"); e.printStackTrace(); } - return sql.deleteLecture(con, id); + return sql.deleteLecture(id); } |
