Added "Date:" helper feature in EWF_HEADER
Added license.lic to restbuck example, and mainly copyright to Javier Use HTTP_STATUS_CODES Minor improvements using object tests Cosmetic (indentation, ..)
This commit is contained in:
@@ -84,4 +84,7 @@ invariant
|
||||
valid_coffe : is_valid_coffee_type (name)
|
||||
valid_customization : is_valid_milk_type (option)
|
||||
valid_quantity : quantity > 0
|
||||
note
|
||||
copyright: "2011-2011, Javier Velilla and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
|
||||
@@ -48,4 +48,7 @@ feature -- Access
|
||||
once
|
||||
Result := <<"small","mediumn", "large">>
|
||||
end
|
||||
note
|
||||
copyright: "2011-2011, Javier Velilla and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
|
||||
@@ -6,64 +6,73 @@
|
||||
|
||||
class
|
||||
JSON_ORDER_CONVERTER
|
||||
|
||||
inherit
|
||||
JSON_CONVERTER
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Initialization
|
||||
|
||||
make
|
||||
do
|
||||
create object.make ("","","")
|
||||
create object.make ("", "", "")
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
object : ORDER
|
||||
|
||||
object: ORDER
|
||||
|
||||
value: detachable JSON_OBJECT
|
||||
|
||||
value : detachable JSON_OBJECT
|
||||
feature -- Conversion
|
||||
|
||||
from_json (j: attached like value): detachable like object
|
||||
from_json (j: attached like value): detachable like object
|
||||
-- Convert from JSON value. Returns Void if unable to convert
|
||||
local
|
||||
lstr1, lstr2, lstr3 : detachable STRING_32
|
||||
q: detachable INTEGER_8
|
||||
s_name, s_key, s_option: detachable STRING_32
|
||||
q: INTEGER_8
|
||||
o: ORDER
|
||||
i : ITEM
|
||||
l_val : detachable JSON_ARRAY
|
||||
l_array : detachable ARRAYED_LIST[JSON_VALUE]
|
||||
jv : detachable JSON_OBJECT
|
||||
l_array : detachable LIST [JSON_VALUE]
|
||||
is_valid_from_json : BOOLEAN
|
||||
do
|
||||
is_valid_from_json := True
|
||||
lstr1 ?= json.object (j.item (id_key), Void)
|
||||
lstr2 ?= json.object (j.item (location_key), Void)
|
||||
lstr3 ?= json.object (j.item (status_key), Void)
|
||||
l_val ?= j.item (items_key)
|
||||
|
||||
create o.make (lstr1, lstr2, lstr3)
|
||||
s_name ?= json.object (j.item (id_key), Void)
|
||||
s_key ?= json.object (j.item (location_key), Void)
|
||||
s_option ?= json.object (j.item (status_key), Void)
|
||||
|
||||
if l_val /= void then
|
||||
create o.make (s_name, s_key, s_option)
|
||||
|
||||
if attached {JSON_ARRAY} j.item (items_key) as l_val then
|
||||
l_array := l_val.array_representation
|
||||
from
|
||||
l_array.start
|
||||
until
|
||||
l_array.after
|
||||
loop
|
||||
jv ?= l_array.item_for_iteration
|
||||
if jv /= Void then
|
||||
lstr1 ?= json.object (jv.item (name_key), Void)
|
||||
lstr2 ?= json.object (jv.item (size_key), Void)
|
||||
lstr3 ?= json.object (jv.item (option_key), Void)
|
||||
q ?= json.object (jv.item (quantity_key),Void)
|
||||
if lstr1/= Void and then lstr2 /= Void and then lstr3 /= Void then
|
||||
if is_valid_item_customization(lstr1,lstr2,lstr3,q) then
|
||||
create i.make (lstr1, lstr2,lstr3, q)
|
||||
if attached {JSON_OBJECT} l_array.item_for_iteration as jv then
|
||||
if attached {INTEGER_8} json.object (jv.item (quantity_key), Void) as l_integer then
|
||||
q := l_integer
|
||||
else
|
||||
q := 0
|
||||
end
|
||||
|
||||
s_name ?= json.object (jv.item (id_key), Void)
|
||||
s_key ?= json.object (jv.item (location_key), Void)
|
||||
s_option ?= json.object (jv.item (status_key), Void)
|
||||
|
||||
if s_name /= Void and s_key /= Void and s_option /= Void then
|
||||
if is_valid_item_customization (s_name, s_key, s_option,q) then
|
||||
create i.make (s_name, s_key, s_option, q)
|
||||
o.add_item (i)
|
||||
else
|
||||
is_valid_from_json := false
|
||||
is_valid_from_json := False
|
||||
end
|
||||
else
|
||||
is_valid_from_json := false
|
||||
is_valid_from_json := False
|
||||
end
|
||||
end
|
||||
|
||||
@@ -75,7 +84,6 @@ feature -- Conversion
|
||||
else
|
||||
Result := o
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
to_json (o: like object): like value
|
||||
@@ -98,7 +106,7 @@ feature -- Conversion
|
||||
i := o.items.item_for_iteration
|
||||
create jv.make
|
||||
jv.put (json.value (i.name), name_key)
|
||||
jv.put (json.value (i.size),size_key)
|
||||
jv.put (json.value (i.size), size_key)
|
||||
jv.put (json.value (i.quantity), quantity_key)
|
||||
jv.put (json.value (i.option), option_key)
|
||||
ja.add (jv)
|
||||
@@ -108,6 +116,7 @@ feature -- Conversion
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
id_key: JSON_STRING
|
||||
once
|
||||
create Result.make_json ("id")
|
||||
@@ -147,12 +156,12 @@ feature -- Conversion
|
||||
create Result.make_json ("quantity")
|
||||
end
|
||||
|
||||
|
||||
option_key : JSON_STRING
|
||||
|
||||
once
|
||||
create Result.make_json ("option")
|
||||
end
|
||||
|
||||
feature -- Validation
|
||||
|
||||
is_valid_item_customization ( name : STRING_32; size: STRING_32; option : STRING_32; quantity : INTEGER_8 ) : BOOLEAN
|
||||
@@ -163,4 +172,7 @@ feature -- Validation
|
||||
Result := ic.is_valid_coffee_type (name) and ic.is_valid_milk_type (option) and ic.is_valid_size_option (size) and quantity > 0
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2011, Javier Velilla and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
|
||||
@@ -12,14 +12,14 @@ feature -- Initialization
|
||||
|
||||
make ( an_id : detachable STRING_32; a_location: detachable STRING_32; a_status: detachable STRING_32)
|
||||
do
|
||||
create {ARRAYED_LIST[ITEM]}items.make (10)
|
||||
create {ARRAYED_LIST [ITEM]} items.make (10)
|
||||
if an_id /= Void then
|
||||
set_id(an_id)
|
||||
set_id (an_id)
|
||||
else
|
||||
set_id ("")
|
||||
end
|
||||
if a_location /= Void then
|
||||
set_location(a_location)
|
||||
set_location (a_location)
|
||||
else
|
||||
set_location ("")
|
||||
end
|
||||
@@ -40,6 +40,7 @@ feature -- Access
|
||||
revision : INTEGER
|
||||
|
||||
feature -- element change
|
||||
|
||||
set_id (an_id : STRING_32)
|
||||
do
|
||||
id := an_id
|
||||
@@ -61,7 +62,6 @@ feature -- element change
|
||||
status_asigned : status.same_string (a_status)
|
||||
end
|
||||
|
||||
|
||||
add_item (a_item : ITEM)
|
||||
require
|
||||
valid_item: a_item /= Void
|
||||
@@ -71,7 +71,6 @@ feature -- element change
|
||||
has_item : items.has (a_item)
|
||||
end
|
||||
|
||||
|
||||
add_revision
|
||||
do
|
||||
revision := revision + 1
|
||||
@@ -82,7 +81,7 @@ feature -- element change
|
||||
feature -- Etag
|
||||
|
||||
etag : STRING_32
|
||||
-- Etag generation for Order objects
|
||||
-- Etag generation for Order objects
|
||||
do
|
||||
Result := hash_code.out + revision.out
|
||||
end
|
||||
@@ -106,4 +105,7 @@ feature -- Report
|
||||
end
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2011, Javier Velilla and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
|
||||
@@ -51,4 +51,7 @@ feature -- Access
|
||||
end
|
||||
|
||||
|
||||
note
|
||||
copyright: "2011-2011, Javier Velilla and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
|
||||
@@ -13,4 +13,7 @@ feature
|
||||
create Result
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2011, Javier Velilla and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user