2017-01-16 23:32:28 +01:00
|
|
|
# coding: utf-8
|
|
|
|
|
|
|
|
import json
|
|
|
|
|
|
|
|
import cherrypy
|
|
|
|
from .database import ProjektDatabase_cl, KomponenteDatabase_cl
|
|
|
|
# Method-Dispatching!
|
|
|
|
|
|
|
|
# Übersicht Anforderungen / Methoden
|
|
|
|
# (beachte: / relativ zu /navigation, siehe Konfiguration Server!)
|
|
|
|
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def adjustId_p(id_spl, data_opl):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
if id_spl == None:
|
|
|
|
data_opl['id'] = ''
|
|
|
|
elif id_spl == '':
|
|
|
|
data_opl['id'] = ''
|
|
|
|
elif id_spl == '0':
|
|
|
|
data_opl['id'] = ''
|
|
|
|
else:
|
|
|
|
data_opl['id'] = id_spl
|
|
|
|
return data_opl
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
Anforderung GET PUT POST DELETE
|
|
|
|
-----------------------------------------------------------------------------------------
|
|
|
|
/projekt/ alle Projekte
|
|
|
|
(Liste) anfordern
|
|
|
|
/projekt/:projekt-id einzelnes Projekt Projekt löschen
|
|
|
|
anfordern
|
|
|
|
/projekt/+Daten neues speichern
|
|
|
|
Projekt-Id Rückgabe
|
|
|
|
/projekt/:projekt-id+Daten Projekt ändern
|
|
|
|
"""
|
|
|
|
|
|
|
|
#----------------------------------------------------------
|
|
|
|
class Projekt_cl(object):
|
|
|
|
#----------------------------------------------------------
|
|
|
|
|
|
|
|
exposed = True # gilt für alle Methoden
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def __init__(self):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
self.db_o = ProjektDatabase_cl()
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def GET(self, id = None):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
retVal_o = {
|
|
|
|
'data': None
|
|
|
|
}
|
|
|
|
if id == None:
|
|
|
|
# Anforderung der Liste
|
|
|
|
retVal_o['data'] = self.db_o.read_px()
|
|
|
|
else:
|
|
|
|
# Anforderung eines Dokuments
|
|
|
|
data_o = self.db_o.read_px(id)
|
|
|
|
if data_o != None:
|
|
|
|
retVal_o['data'] = adjustId_p(id, data_o)
|
|
|
|
|
|
|
|
return retVal_o
|
|
|
|
#return json.dumps(retVal_o)
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
2017-01-17 14:23:08 +01:00
|
|
|
def PUT(self, data_opl):
|
2017-01-16 23:32:28 +01:00
|
|
|
#-------------------------------------------------------
|
2017-01-17 14:23:08 +01:00
|
|
|
# Sichern der Daten: jetzt wird keine vollständige Seite
|
|
|
|
# zurückgeliefert, sondern nur noch die Information, ob das
|
|
|
|
# Speichern erfolgreich war
|
|
|
|
|
|
|
|
retVal_o = {
|
|
|
|
'id': None
|
|
|
|
}
|
|
|
|
|
|
|
|
# data_opl: Dictionary mit den gelieferten key-value-Paaren
|
|
|
|
# hier müsste man prüfen, ob die Daten korrekt vorliegen!
|
|
|
|
|
|
|
|
id_s = data_opl["id_s"]
|
|
|
|
data_o = {
|
|
|
|
'name': data_opl["name_s"],
|
|
|
|
'id': data_opl["id_s"]
|
|
|
|
}
|
|
|
|
# Update-Operation
|
|
|
|
retVal_o['id'] = id_s
|
|
|
|
if self.db_o.update_px(id_s, data_o):
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
retVal_o['id'] = None
|
|
|
|
|
|
|
|
return retVal_o
|
2017-01-16 23:32:28 +01:00
|
|
|
|
|
|
|
#-------------------------------------------------------
|
2017-01-17 14:23:08 +01:00
|
|
|
def POST(self, data_opl):
|
2017-01-16 23:32:28 +01:00
|
|
|
#-------------------------------------------------------
|
2017-01-17 14:23:08 +01:00
|
|
|
retVal_o = {
|
|
|
|
'id': None
|
|
|
|
}
|
|
|
|
|
|
|
|
# data_opl: Dictionary mit den gelieferten key-value-Paaren
|
|
|
|
|
|
|
|
# hier müsste man prüfen, ob die Daten korrekt vorliegen!
|
|
|
|
|
|
|
|
data_o = {
|
|
|
|
'name': data_opl["name_s"]
|
|
|
|
}
|
|
|
|
# Create-Operation
|
|
|
|
id_s = self.db_o.create_px(data_o)
|
|
|
|
retVal_o['id'] = id_s
|
|
|
|
|
|
|
|
return retVal_o
|
2017-01-16 23:32:28 +01:00
|
|
|
|
|
|
|
#-------------------------------------------------------
|
2017-01-17 14:23:08 +01:00
|
|
|
def DELETE(self, id):
|
2017-01-16 23:32:28 +01:00
|
|
|
#-------------------------------------------------------
|
2017-01-17 14:23:08 +01:00
|
|
|
# Eintrag löschen, nur noch Rückmeldung liefern
|
|
|
|
retVal_o = {
|
|
|
|
'id': id
|
|
|
|
}
|
|
|
|
|
|
|
|
if self.db_o.delete_px(id):
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
retVal_o['id'] = None
|
|
|
|
|
|
|
|
return retVal_o
|
2017-01-16 23:32:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
Anforderung GET PUT POST DELETE
|
|
|
|
-----------------------------------------------------------------------------------------
|
|
|
|
/projektkomponenten/:projekt-id
|
|
|
|
Komponenten liefern
|
|
|
|
"""
|
|
|
|
|
|
|
|
#----------------------------------------------------------
|
|
|
|
class ProjektKomponenten_cl(object):
|
|
|
|
#----------------------------------------------------------
|
|
|
|
|
|
|
|
exposed = True # gilt für alle Methoden
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def __init__(self):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
self.db_o = KomponenteDatabase_cl()
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def GET(self):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
retVal_o = {
|
|
|
|
'data': None
|
|
|
|
}
|
|
|
|
if id == None:
|
|
|
|
# Anforderung der Liste
|
|
|
|
retVal_o['data'] = self.db_o.read_px()
|
|
|
|
else:
|
|
|
|
# Anforderung eines Dokuments
|
|
|
|
data_o = self.db_o.read_px(id)
|
|
|
|
if data_o != None:
|
|
|
|
retVal_o['data'] = adjustId_p(id, data_o)
|
|
|
|
|
|
|
|
return retVal_o
|
|
|
|
#return json.dumps(retVal_o)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
Anforderung GET PUT POST DELETE
|
|
|
|
-----------------------------------------------------------------------------------------
|
|
|
|
/komponente/ alle Komponenten
|
|
|
|
/komponente/:komponente-id
|
|
|
|
einzelne Komponente Komponente löschen
|
|
|
|
/komponente/:projekt-id+Daten neue Komponente speichern
|
|
|
|
Id Rückgabe
|
|
|
|
/komponente/:komponente-id+Daten Komponente ändern
|
|
|
|
"""
|
|
|
|
|
|
|
|
#----------------------------------------------------------
|
|
|
|
class Komponente_cl(object):
|
|
|
|
#----------------------------------------------------------
|
|
|
|
|
|
|
|
exposed = True # gilt für alle Methoden
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def __init__(self):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
self.db_o = KomponenteDatabase_cl()
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def GET(self):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
retVal_o = {
|
|
|
|
'data': None
|
|
|
|
}
|
|
|
|
if id == None:
|
|
|
|
# Anforderung der Liste
|
|
|
|
retVal_o['data'] = self.db_o.read_px()
|
|
|
|
else:
|
|
|
|
# Anforderung eines Dokuments
|
|
|
|
data_o = self.db_o.read_px(id)
|
|
|
|
if data_o != None:
|
|
|
|
retVal_o['data'] = adjustId_p(id, data_o)
|
|
|
|
|
|
|
|
return retVal_o
|
|
|
|
#return json.dumps(retVal_o)
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def PUT(self):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
return json.dumps(retVal_o)
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def POST(self):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
return json.dumps(retVal_o)
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def DELETE(self):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
return json.dumps(retVal_o)
|
|
|
|
|
|
|
|
|
|
|
|
# EOF
|
|
|
|
|