diff options
author | unknown | 2014-02-25 11:04:51 +0100 |
---|---|---|
committer | unknown | 2014-02-25 11:04:51 +0100 |
commit | 2a3ec0fbda66ed07adcdc968a9365096ecd54f40 (patch) | |
tree | 187af202e5a404a15c31f0915e73cb23bf5b7900 /Dozentenmodulserver/src/server/ServerHandler.java | |
parent | Problem der herumspringenden Fenster entfernt (diff) | |
download | tutor-module-2a3ec0fbda66ed07adcdc968a9365096ecd54f40.tar.gz tutor-module-2a3ec0fbda66ed07adcdc968a9365096ecd54f40.tar.xz tutor-module-2a3ec0fbda66ed07adcdc968a9365096ecd54f40.zip |
Kommunikation von BwLehrpool Suite zu BwLehrpool Suite Server läuft nun über Thrift
Diffstat (limited to 'Dozentenmodulserver/src/server/ServerHandler.java')
-rw-r--r-- | Dozentenmodulserver/src/server/ServerHandler.java | 204 |
1 files changed, 204 insertions, 0 deletions
diff --git a/Dozentenmodulserver/src/server/ServerHandler.java b/Dozentenmodulserver/src/server/ServerHandler.java new file mode 100644 index 00000000..78e81464 --- /dev/null +++ b/Dozentenmodulserver/src/server/ServerHandler.java @@ -0,0 +1,204 @@ +package server; + +import java.math.BigInteger; +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; +import java.util.Map; +import java.util.UUID; + +import org.apache.thrift.TException; + +import sql.SQL; + + +public class ServerHandler implements Server.Iface { + + SQL sql=new SQL(); + Connection con=sql.getConnection(); + /** + * @param args + */ + /*public static void main(String[] args) { + // TODO Auto-generated method stub + + }*/ + + @Override + public User getFtpUser() throws TException { + User user=new User(); + user.setUserName(UUID.randomUUID().toString().substring(0, 8)); + user.setPassword(getEncodedSha1Sum(UUID.randomUUID().toString().substring(0, 8))); + user.setPath("/srv/openslx/nfs/temp"); + SQL sql=new SQL(); + Connection con=sql.getConnection(); + sql.writeFTPUser(con, user.getUserName(), user.getPassword()); + return user; + } + + + public String getEncodedSha1Sum(String key) { + try { + MessageDigest md = MessageDigest.getInstance( "SHA1" ); + md.update( key.getBytes() ); + return new BigInteger(1, md.digest()).toString(16); + } + catch (NoSuchAlgorithmException e) { + // handle error case to taste + } + return null; + } + + @Override + public long DeleteFtpUser(String user) throws TException { + int ret = sql.DeleteUser(con, user); + return ret; + } + + @Override + public List<String> getImages() throws TException { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getPathOfImage(String name) throws TException { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean writeVLdata(String imagename, String firstname, + String lastname, String university, String Mail, String Tel, + String Fak, boolean license, boolean internet, long ram, long cpu) + throws TException { + String login="tete"; + + int pk_institution=sql.setInstitution(con, university); + + int pk_person=sql.setPerson(con, login, lastname, firstname, Mail, new Date(), pk_institution); + + sql.setImageData(con, pk_person, license, internet, cpu, ram, imagename); + + // TODO Auto-generated method stub + return true; + } + + @Override + public List<Image> getImageList() throws TException { + ResultSet resWith=sql.getImageListWithLectures(con); + ResultSet resWithout=sql.getImageListWithoutLectures(con); + List<Image> listWith = new ArrayList<Image>(); + List<Image> listWithout = new ArrayList<Image>(); + try { + + while(resWith.next()) + { + + listWith.add(new Image(resWith.getString("image_name"),resWith.getString("cond_hasLicenseRestriction"),resWith.getString("name"),resWith.getString("lecture"),resWith.getString("image_update_time"),resWith.getString("user"))); + + } + + while(resWithout.next()) + { + listWithout.add(new Image(resWithout.getString("image_name"),resWithout.getString("cond_hasLicenseRestriction"),resWithout.getString("name"),"''",resWithout.getString("image_update_time"),resWithout.getString("user"))); + + } + + if(listWithout!=null) + { + listWith.addAll(listWith.size(), listWithout); + } + + return listWith; + } catch (SQLException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + 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; + } + + @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")); + map.put("tel", "009909"); + map.put("fak", "E+I"); + + } + return map; + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } + + @Override + public boolean writeLecturedata(String name, String shortdesc, String desc, + String startDate, String endDate, boolean isActive, + String imagename, String firstname, String lastname, + String university, String Mail, String Tel, String Fak) + throws TException { + int pk_image = 0; + String login="tete"; + int imageversion = 0; + int pk_institution=sql.setInstitution(con, university); + int pk_person=sql.setPerson(con, login, lastname, firstname, Mail, new Date(), pk_institution); + + ResultSet image=sql.getImageIDandVersion(con, imagename); + + try { + while(image.next()) + { + pk_image=image.getInt("GUID_imageID"); + imageversion=image.getInt("imageVersion"); + } + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + + System.out.println(startDate); + sql.setLectureData(con, pk_person, pk_image, imageversion, name, desc, shortdesc, startDate, endDate, isActive); + + return false; + } + +} |