summaryrefslogtreecommitdiffstats
path: root/Dozentenmodulserver
diff options
context:
space:
mode:
authorunknown2014-05-15 09:07:58 +0200
committerunknown2014-05-15 09:07:58 +0200
commitfd0287db425350886a384b6c3ea15dcdbacbdc6e (patch)
tree5d4054fa6dfa55da095c3cb85756af389cdf6ca8 /Dozentenmodulserver
parentFTP-Server nicht mehr hard-coded sondern ausgelesen + diverse Kleinigkeiten (diff)
downloadtutor-module-fd0287db425350886a384b6c3ea15dcdbacbdc6e.tar.gz
tutor-module-fd0287db425350886a384b6c3ea15dcdbacbdc6e.tar.xz
tutor-module-fd0287db425350886a384b6c3ea15dcdbacbdc6e.zip
Check ob Ordner /temp vorhanden ist
Diffstat (limited to 'Dozentenmodulserver')
-rw-r--r--Dozentenmodulserver/bin/server/ServerHandler.classbin15199 -> 16278 bytes
-rw-r--r--Dozentenmodulserver/src/server/ServerHandler.java99
2 files changed, 72 insertions, 27 deletions
diff --git a/Dozentenmodulserver/bin/server/ServerHandler.class b/Dozentenmodulserver/bin/server/ServerHandler.class
index 052ffd4a..6ad23978 100644
--- a/Dozentenmodulserver/bin/server/ServerHandler.class
+++ b/Dozentenmodulserver/bin/server/ServerHandler.class
Binary files differ
diff --git a/Dozentenmodulserver/src/server/ServerHandler.java b/Dozentenmodulserver/src/server/ServerHandler.java
index e9bf43a7..568ea714 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,9 +30,7 @@ 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...");
@@ -45,10 +41,52 @@ public class ServerHandler implements Server.Iface {
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 = 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();
+ //File dir = new File(path + "");
+ //dir.setExecutable(true);
+ //dir.setReadable(true);
+ //dir.setWritable(true);
+
+ 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");
@@ -89,7 +127,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);
@@ -97,7 +136,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
@@ -221,19 +260,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) {
@@ -278,11 +322,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;
}
@@ -351,8 +396,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;
}
@@ -363,7 +408,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
@@ -399,7 +445,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);
@@ -415,5 +461,4 @@ public class ServerHandler implements Server.Iface {
}
-
}