diff options
author | unknown | 2014-05-15 09:31:06 +0200 |
---|---|---|
committer | unknown | 2014-05-15 09:31:06 +0200 |
commit | a3622fa7a5bf9437994707468834638bdb3176da (patch) | |
tree | f29a89c33cd68946d795834b360f4fe6e9460567 /Dozentenmodulserver | |
parent | t (diff) | |
parent | Check ob Ordner /temp vorhanden ist (diff) | |
download | tutor-module-a3622fa7a5bf9437994707468834638bdb3176da.tar.gz tutor-module-a3622fa7a5bf9437994707468834638bdb3176da.tar.xz tutor-module-a3622fa7a5bf9437994707468834638bdb3176da.zip |
Merge branch 'master' of git.openslx.org:openslx-ng/tutor-module
Conflicts:
Dozentenmodulserver/bin/server/ServerHandler.class
Diffstat (limited to 'Dozentenmodulserver')
-rw-r--r-- | Dozentenmodulserver/bin/server/ServerHandler.class | bin | 15199 -> 16590 bytes | |||
-rw-r--r-- | Dozentenmodulserver/src/server/ServerHandler.java | 115 |
2 files changed, 85 insertions, 30 deletions
diff --git a/Dozentenmodulserver/bin/server/ServerHandler.class b/Dozentenmodulserver/bin/server/ServerHandler.class Binary files differindex f0c8e2a5..cf70402f 100644 --- a/Dozentenmodulserver/bin/server/ServerHandler.class +++ b/Dozentenmodulserver/bin/server/ServerHandler.class diff --git a/Dozentenmodulserver/src/server/ServerHandler.java b/Dozentenmodulserver/src/server/ServerHandler.java index 57d6ed49..5744003a 100644 --- a/Dozentenmodulserver/src/server/ServerHandler.java +++ b/Dozentenmodulserver/src/server/ServerHandler.java @@ -3,6 +3,9 @@ package server; import java.io.File; import java.io.IOException; import java.math.BigInteger; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.sql.Connection; @@ -14,17 +17,12 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; - import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.TransformerException; - import models.Configuration; - import org.apache.commons.io.FileUtils; import org.apache.log4j.Logger; import org.apache.thrift.TException; -import org.ini4j.Wini; - import sql.SQL; import util.XMLCreator; @@ -32,24 +30,74 @@ 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 public User getFtpUser() throws TException { - log.info(new Date() + " - returing FTPUser..."); + log.info(new Date() + " - returning FTPUser..."); User user = new User(); user.setUserName(UUID.randomUUID().toString().substring(0, 8)); user.setPassword(getEncodedSha1Sum(UUID.randomUUID().toString() .substring(0, 8))); - - user.setPath(Configuration.config.getAbsolute_path()); + if(Configuration.config.getAbsolute_path().endsWith("/")) + { + user.setPath(Configuration.config.getAbsolute_path()); + } + else{ + user.setPath(Configuration.config.getAbsolute_path()+"/"); + } SQL sql = new SQL(); Connection con = sql.getConnection(); - sql.writeFTPUser(con, user.getUserName(), user.getPassword()); - return user; + // check if folder temp exists + if (folderTempExists() == true) { + sql.writeFTPUser(con, user.getUserName(), user.getPassword()); + return user; + } else { + log.info(new Date() + " - returning null user"); + return null; + } } + 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"); + } + + if (Files.exists(path) == true) { + log.info(new Date() + " - folder '" + path + + "' exists, no further action"); + return true; + } else { + // create directory and set permissions + boolean success = (new File(path + "")).mkdirs(); + + if (!success) { + log.info(new Date() + " - failed to create folder '" + path + + "'"); + return false; + } else { + //set permissions + try { + Runtime.getRuntime().exec("chmod 777 "+path); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + log.info(new Date() + " - folder '" + path + + "' successfully created"); + return true; + } + } + + }// end folderTempExists() + public String getEncodedSha1Sum(String key) { try { MessageDigest md = MessageDigest.getInstance("SHA1"); @@ -90,7 +138,8 @@ public class ServerHandler implements Server.Iface { public boolean writeVLdata(String imagename, String login, 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 ram, long cpu, String imagePath, boolean isTemplate, + long filesize) throws TException { String pk_institution = sql.setInstitution(con, university); @@ -98,7 +147,7 @@ public class ServerHandler implements Server.Iface { new Date(), pk_institution); sql.setImageData(con, pk_person, license, internet, cpu, ram, - imagename, imagePath,isTemplate ,filesize); + imagename, imagePath, isTemplate, filesize); log.info(new Date() + " - written VLdata"); // TODO Auto-generated method stub @@ -222,19 +271,24 @@ public class ServerHandler implements Server.Iface { @Override public boolean startFileCopy(String filename) throws TException { - String file=Configuration.config.getAbsolute_path()+"temp/"+filename; + String file = Configuration.config.getAbsolute_path() + "temp/" + + filename; File tmpFile = new File(file); - - log.info(new Date() + " - Trying to move file to '/srv/openslx/nfs/prod/"+tmpFile.getName() +"'"); + + log.info(new Date() + + " - 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); + 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"); } catch (IOException e) { @@ -279,11 +333,12 @@ public class ServerHandler implements Server.Iface { } @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); + 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); return false; } @@ -352,8 +407,8 @@ public class ServerHandler implements Server.Iface { e.printStackTrace(); } - //sql.updateLectureData(con, pk_image, imageversion, lastname, newName, - // desc, shortdesc, startDate, endDate, isActive, id); + // sql.updateLectureData(con, pk_image, imageversion, lastname, newName, + // desc, shortdesc, startDate, endDate, isActive, id); return false; } @@ -364,7 +419,8 @@ public class ServerHandler implements Server.Iface { String stringFile = sql.getFile(con, imageid, imageversion); log.info(new Date() + " - File to Delete: " + stringFile); - File tmpFile = new File(Configuration.config.getAbsolute_path()+stringFile); + File tmpFile = new File(Configuration.config.getAbsolute_path() + + stringFile); try { // File wird von Server gelöscht @@ -400,7 +456,7 @@ public class ServerHandler implements Server.Iface { String date = rs.getString("admin_createTime").replace(" ", "") .replace("-", "").replace(":", ""); String name = rs.getString("name"); - String path = Configuration.config.getAbsolute_path()+"temp/" + String path = Configuration.config.getAbsolute_path() + "temp/" + date.substring(0, date.length() - 2) + "_" + hs + "_" + user + "_" + name + ".xml"; File xmlFile = new File(path); @@ -416,5 +472,4 @@ public class ServerHandler implements Server.Iface { } - } |