|
@@ -620,7 +620,6 @@ end
|
|
|
|
|
|
class ListSearch < Riddl::Implementation
|
|
|
def response
|
|
|
-
|
|
|
ret = {
|
|
|
:imagesWIZAll => "/imagesWIZ?pattern=...",
|
|
|
:imagesWIZSingle => "/imagesWIZ/0..*/?pattern=...",
|
|
@@ -693,7 +692,6 @@ class SearchImagesSingle < Riddl::Implementation
|
|
|
if index != 0
|
|
|
uri += "&" + item.name.to_s + "=" + item.value.to_s
|
|
|
end
|
|
|
-
|
|
|
end
|
|
|
|
|
|
xml.variant(:lang => item3[2].to_s, :label => item3[3].to_s){
|
|
@@ -726,7 +724,6 @@ class SearchErrors < Riddl::Implementation
|
|
|
searchstring = searchstring + " AND " + pattern.map{ |key, val| key + ".type == '" + key + "' AND (" + key + ".value == '"+ val +"' or " + key + ".value == '*')"}.join(' AND ') + " ORDER BY ID ASC"
|
|
|
result = $db.execute searchstring;
|
|
|
|
|
|
-
|
|
|
ret = []
|
|
|
if result.length > 0
|
|
|
result.each do |item|
|
|
@@ -738,8 +735,6 @@ class SearchErrors < Riddl::Implementation
|
|
|
end
|
|
|
|
|
|
ret = ret.uniq
|
|
|
-
|
|
|
-
|
|
|
builder = Nokogiri::XML::Builder.new do |xml|
|
|
|
xml.reason{
|
|
|
if result.length > 0
|
|
@@ -756,6 +751,145 @@ class SearchErrors < Riddl::Implementation
|
|
|
end
|
|
|
end
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+class GetAssignments < Riddl::Implementation
|
|
|
+ def response
|
|
|
+ ret = {}
|
|
|
+ resultstation = $db.execute "SELECT * FROM assignments"
|
|
|
+ resultstation.each do |row|
|
|
|
+ ret[row[0]] = row[1]
|
|
|
+ end
|
|
|
+ Riddl::Parameter::Complex.new('list','application/json',JSON::pretty_generate(ret))
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+class SaveNewAssignment < Riddl::Implementation
|
|
|
+ def response
|
|
|
+ form = JSON.parse(@p[0].value.read);
|
|
|
+ result = $db.execute "SELECT MAX(ID) FROM assignments"
|
|
|
+ if(result[0][0] == nil)
|
|
|
+ id = 0
|
|
|
+ else
|
|
|
+ id = result[0][0] +1
|
|
|
+ end
|
|
|
+
|
|
|
+ checkimage = $db.execute "SELECT * FROM assignments WHERE image = '#{form["img"]}'"
|
|
|
+ #if image not stored create new assignment with pattern, otherwise only add pattern
|
|
|
+ if(checkimage[0] == nil)
|
|
|
+ $db.execute("INSERT INTO assignments (ID, image) VALUES (?,?)", [id, form["img"]])
|
|
|
+ form["parts"].each{ |key,val|
|
|
|
+ $db.execute("INSERT INTO patternassignments (ID, AssID, type, value) VALUES (?,?,?,?)", [id, 0, key, val])
|
|
|
+ }
|
|
|
+ $db.execute("INSERT INTO patternassignments (ID, AssID, type, value) VALUES (?,?,?,?)", [id, 0, "STATION", form["station"]])
|
|
|
+ $db.execute("INSERT INTO patternassignments (ID, AssID, type, value) VALUES (?,?,?,?)", [id, 0, "TEXT", form["assignmentText"]])
|
|
|
+ else
|
|
|
+ maxID = $db.execute "SELECT MAX(AssID) FROM patternassignments WHERE ID ='#{checkimage[0][0]}'"
|
|
|
+
|
|
|
+ if(maxID[0][0] == nil)
|
|
|
+ maxID = 0
|
|
|
+ else
|
|
|
+ maxID = maxID[0][0] +1
|
|
|
+ end
|
|
|
+
|
|
|
+ form["parts"].each{ |key,val|
|
|
|
+ $db.execute("INSERT INTO patternassignments (ID, AssID, type, value) VALUES (?,?,?,?)", [checkimage[0][0], maxID, key, val])
|
|
|
+ }
|
|
|
+ $db.execute("INSERT INTO patternassignments (ID, AssID, type, value) VALUES (?,?,?,?)", [checkimage[0][0], maxID, "STATION", form["station"]])
|
|
|
+ $db.execute("INSERT INTO patternassignments (ID, AssID, type, value) VALUES (?,?,?,?)", [checkimage[0][0], maxID, "TEXT", form["assignmentText"]])
|
|
|
+ end
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+class GetAssignment < Riddl::Implementation
|
|
|
+ def response
|
|
|
+ ret = {}
|
|
|
+ allAssIds = $db.execute "SELECT DISTINCT AssID FROM patternassignments WHERE ID = #{@r[1]}"
|
|
|
+
|
|
|
+ allAssIds.each do |row|
|
|
|
+
|
|
|
+
|
|
|
+ station = $db.execute "SELECT value FROM patternassignments WHERE ID = #{@r[1]} AND AssID = #{row[0]} AND type == 'STATION'"
|
|
|
+ stationvalue = Integer(station[0][0])
|
|
|
+
|
|
|
+ singleItem = $db.execute "SELECT value FROM patternassignments WHERE ID = #{@r[1]} AND AssID = #{row[0]} AND type != 'STATION'"
|
|
|
+
|
|
|
+ if(ret[stationvalue] == nil)
|
|
|
+ ret[stationvalue] = Hash.new()
|
|
|
+ end
|
|
|
+ ret[stationvalue][row[0]] = singleItem.join('.')
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ end
|
|
|
+ Riddl::Parameter::Complex.new('list','application/json',JSON::pretty_generate(ret))
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+class DeleteAssignment < Riddl::Implementation
|
|
|
+ def response
|
|
|
+ $db.execute("DELETE FROM assignments WHERE ID = ?", [@r[1]])
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+class DeleteSingleAssignment < Riddl::Implementation
|
|
|
+ def response
|
|
|
+ $db.execute("DELETE FROM patternassignments WHERE AssID = ? AND ID = ?", [@r[2], @r[1]])
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+class ListAssignmentSearch < Riddl::Implementation
|
|
|
+ def response
|
|
|
+
|
|
|
+ #https://centurio.work/customers/evva/was/ui/TransformProductCode.php?ProductCode=E.A.PZ.DZ-S.31.31.MP.SEP
|
|
|
+
|
|
|
+ pattern = JSON.parse(Net::HTTP.get URI("https://centurio.work/customers/evva/was/ui/TransformProductCode.php?ProductCode=" + @p[0].value))
|
|
|
+
|
|
|
+ puts @p[1].value + @p[2].value
|
|
|
+#$db.execute "CREATE TABLE IF NOT EXISTS patternassignments(ID INT, AssID INT, type CHARACTER(20), value CHARACTER(20), FOREIGN KEY(ID) REFERENCES assignments(ID) ON DELETE CASCADE)"
|
|
|
+
|
|
|
+ #Get first key dynamicly and then build sql query
|
|
|
+ searchstring = "SELECT " + pattern.keys[0] + ".ID AS ID"
|
|
|
+ searchstring = searchstring + " FROM " + pattern.map{ |key, val| "patternassignments " + key}.join(', ')
|
|
|
+ searchstring = searchstring + " , patternassignments STATION , patternassignments ValText"
|
|
|
+ searchstring = searchstring + " WHERE " + pattern.map{ |key, val| pattern.keys[0] + ".AssID == " + key + ".AssID"}.join(' AND ') + " AND ";
|
|
|
+ searchstring = searchstring + pattern.map{ |key, val| pattern.keys[0] + ".ID == " + key + ".ID"}.join(' AND ')
|
|
|
+
|
|
|
+ searchstring = searchstring + " AND " + pattern.keys[0] + ".AssID == STATION.AssID"
|
|
|
+ searchstring = searchstring + " AND " + pattern.keys[0] + ".AssID == ValText.AssID"
|
|
|
+ searchstring = searchstring + " AND " + pattern.keys[0] + ".ID == STATION.ID"
|
|
|
+ searchstring = searchstring + " AND " + pattern.keys[0] + ".ID == ValText.ID"
|
|
|
+
|
|
|
+
|
|
|
+ searchstring = searchstring + " AND STATION.type == 'STATION'" + " AND STATION.value == '" + @p[1].value + "'"
|
|
|
+ searchstring = searchstring + " AND ValText.type == 'TEXT'" + " AND ValText.value == '" + @p[2].value + "'"
|
|
|
+
|
|
|
+ searchstring = searchstring + " AND " + pattern.map{ |key, val| key + ".type == '" + key + "' AND (" + key + ".value == '"+ val +"' or " + key + ".value == '*')"}.join(' AND ') + " ORDER BY ID ASC"
|
|
|
+
|
|
|
+ #puts searchstring;
|
|
|
+
|
|
|
+ result = $db.execute searchstring;
|
|
|
+
|
|
|
+
|
|
|
+ #Search for images with one or multiple found patternIDs
|
|
|
+ ret = []
|
|
|
+ if result.length > 0
|
|
|
+ result.each do |item|
|
|
|
+ result2 = $db.execute "SELECT DISTINCT image FROM assignments WHERE ID = #{item[0]}"
|
|
|
+ result2.each do |item2|
|
|
|
+ ret << item2[0]
|
|
|
+ end
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ Riddl::Parameter::Complex.new('list','application/json',JSON::pretty_generate(ret))
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
def createDB(opts)
|
|
|
$db.execute("PRAGMA foreign_keys=ON");
|
|
|
|
|
@@ -767,17 +901,10 @@ def createDB(opts)
|
|
|
|
|
|
#vor DB struktur umstellung
|
|
|
#$db.execute "CREATE TABLE IF NOT EXISTS station(station INT, patternID INT, pattern CHARACTER(256), description TEXT, date TEXT, P0 VARCHAR(10), P1 VARCHAR(10), P2 VARCHAR(10), P3 VARCHAR(10), P4 VARCHAR(10), P5 VARCHAR(10), P6 VARCHAR(10), P7 VARCHAR(10), P8 VARCHAR(10), P9 VARCHAR(10), P10 VARCHAR(10), PRIMARY KEY(station,patternID), UNIQUE(station, patternID))"
|
|
|
-
|
|
|
-
|
|
|
#$db.execute "CREATE TABLE IF NOT EXISTS error(station INT, patternID INT, error TEXT, FOREIGN KEY(station, patternID) REFERENCES station(station, patternID) ON DELETE CASCADE)"
|
|
|
-
|
|
|
-
|
|
|
#$db.execute "CREATE TABLE IF NOT EXISTS replacements(station INT, patternID INT, abbreviation TEXT, url TEXT, ordering INT, FOREIGN KEY(station, patternID) REFERENCES station(station, patternID) ON DELETE CASCADE)"
|
|
|
-
|
|
|
#$db.execute "CREATE TABLE IF NOT EXISTS image(station INT, patternID INT, imageID INT, language CHARACTER(20), label TEXT, FOREIGN KEY(station, patternID) REFERENCES station(station, patternID) ON DELETE CASCADE,PRIMARY KEY(station,patternID,imageID,language))"
|
|
|
|
|
|
-
|
|
|
-
|
|
|
|
|
|
|
|
|
$db.execute "CREATE TABLE IF NOT EXISTS stationpattern(station INT, internalID INT, description TEXT, date TEXT, PRIMARY KEY(internalID), UNIQUE(internalID))"
|
|
@@ -786,6 +913,9 @@ def createDB(opts)
|
|
|
$db.execute "CREATE TABLE IF NOT EXISTS replacements(internalID INT, abbreviation TEXT, url TEXT, ordering INT, FOREIGN KEY(internalID) REFERENCES stationpattern(internalID) ON DELETE CASCADE)"
|
|
|
$db.execute "CREATE TABLE IF NOT EXISTS image(internalID INT, imageID INT, language CHARACTER(20), label TEXT, FOREIGN KEY(internalID) REFERENCES stationpattern(internalID) ON DELETE CASCADE)"
|
|
|
|
|
|
+ $db.execute "CREATE TABLE IF NOT EXISTS assignments(ID INT, image TEXT, PRIMARY KEY(ID) UNIQUE (ID))"
|
|
|
+ $db.execute "CREATE TABLE IF NOT EXISTS patternassignments(ID INT, AssID INT, type CHARACTER(20), value CHARACTER(20), FOREIGN KEY(ID) REFERENCES assignments(ID) ON DELETE CASCADE)"
|
|
|
+
|
|
|
end
|
|
|
|
|
|
server = Riddl::Server.new(File.join(__dir__,'/was.xml'), :host => 'localhost') do |opts|
|
|
@@ -866,5 +996,19 @@ server = Riddl::Server.new(File.join(__dir__,'/was.xml'), :host => 'localhost')
|
|
|
end
|
|
|
end
|
|
|
end
|
|
|
+ on resource 'assignments' do
|
|
|
+ run GetAssignments if get
|
|
|
+ run SaveNewAssignment if post 'list'
|
|
|
+ on resource 'search' do
|
|
|
+ run ListAssignmentSearch if get
|
|
|
+ end
|
|
|
+ on resource '\d+' do
|
|
|
+ run GetAssignment if get
|
|
|
+ run DeleteAssignment if delete
|
|
|
+ on resource '\d+' do
|
|
|
+ run DeleteSingleAssignment if delete
|
|
|
+ end
|
|
|
+ end
|
|
|
+ end
|
|
|
end
|
|
|
end.loop!
|