Kobr A 2 Web App Framework Web Service
Kobr. A 2 Web. App Framework
Web. Service. SOS. ocl context Service. Controller: : process(request: Request): Response post: let act = mvc. Action->any(e | e. name = request. get('action'). value) in result = act. do(request)
Web. Service. SOT. ocl context Response: : write(value: String) post: response. Body = response. Body@pre. concat(value) context String. Dictionary: : get(key: String): String post: result = attribute->any(e | e. key = key). value context String. Dictionary: : set(key: String, value: String): String post: result = attribute@pre->any(e | e. key = key). value and attribute->select(e | e. key = key)->size() > 0 and attribute->select(e | e. key = key). value = value context String. Dictionary: : remove(key: String): String post: result = attribute@pre->any(e | e. key = key). value and attribute->select(e | e. key = key)->size() = 0
Web. Service. ROS. ocl context Web. Service: : process(request: Resquest): Response post: result = service. Controller. process(request)
Service. Controller. SOS. ocl context Service. Controller: : process(request: Request): Response post: let act = mvc. Action->any(e | e. name = request. get('action'). value) in result = act. do(request)
MVCModel. SOT. ocl context Model. Entity: : all(): Sequence(Model. Entity) post: result = entity context Model. Entity: : put(): Model. Entity post: models->includes(self) context Model. Entity: : delete(): Model. Entity post: models->excludes(self) context Model. Entity: : get(eid : String): Model. Entity post: result = models->select(e | e. id = eid)
Kobr. A 2 Photo. Album as instance of Web. App Framework
Add. Comment. SOS -- do() simply calls add. Comment() method of Photo. Manager context Add. Comment: : do(request: Request): Response post: let id: Integer = K 2 Library. create. From. String(Integer, request. attribute>any( a: Attribute | a. key = 'photo. Id'). value), us: String = request. attribute->any(a: Attribute | a. key = 'user. Name'), text: String = request. attribute->any(a: Attribute | a. key = 'text'), date: Timestamp = K 2 Library. create. From. String(Timestamp, request. attribute->any( a: Attribute | a. key = 'date'). value) in Photo. Manager^add. Comment(id, us, date, text)
Add. Photo. SOS -- do() simply calls add. Photo() method of Photo. Manager context Add. Photos: : do(request: Request): Response post: let photo: Photo = Photo. create. From. String(request. attribute>any( a: Attribute | a. key = 'photo'). value) in Photo. Manager. add. Photo(photo)
List. Photos. SOS -- do() simply calls get. All. Photos() method of Photo. Manager context List. Photos: : do(request: Request): Response post: let photos: Sequence(Photo) = Photo. Manager. get. All. Photos() in result. ocl. As. Type(Response). write(K 2 Library. convert. To. Strin g(Sequence(Photo), photos)) and result. header. kind = Header. Kind: : content. Type and result. header. value = 'binary/octet-stream'
Photo. Manager. SOS (1/3) -- retrieve all photos context Photo. Manager: : get. All. Photos(): Sequence(Photo) post: result = photos -- add a photo context Photo. Manager: : add. Photo(photo: Photo) pre: not photos->includes( photo) post: photos = photos@pre->including(photo) -- updates a photo's informations (ex. name, description) context Photo. Manager: : update. Photo(photo: Photo) pre: self. photos->exists( e: Photo | e. id = photo. id) post: self. photos->any( e: Photo | e. name = photo. name). data = photo. data and self. photos->any( e: Photo | e. name = photo. name). description = photo. description
Photo. Manager. SOS (2/3) -- add a comment to a photo - Breno's version context Photo. Manager: : add. Comment(id: Integer, us: String, c: String, data: Timestamp) pre: self. photos->exists( e: Photo | e. id = photo. id) post: let comment: Comment and comment. ocl. Is. New() and comment. user. Name = us and comment. date = data and comment. text = s in self. photos->any( e: Photo | e. id = id). comment->includes(comment) -- add a comment to a photo - Ramon's version context Photo. Manager: : add. Comment(photo. Id: Integer, user. Name: String, date: Timestamp, text: String) pre: self. photos->exists( e: Photo | e. id = photo. id) post: let photo: Photo = self. photos->any( e: Photo | e. photo. Id = photo. Id), c: Comment in c. ocl. Is. New() and c. user. Name = user. Name and c. date = date and c. text = text and photo. comments->includes(c) and photo. comments->size() = photo. comments@pre->size() + 1
Photo. Manager. SOS (3/3) -- completely removes a photo context Photo. Manager: : remove. Photo(photo: Photo) pre: self. photos->exists( e: Photo | e. id = photo. id) post: self. photos->size() = self. photos@pre->size() - 1 and self. photos->excludes(photo)
Ok. Button. Action. Event. SOS context Ok. Button. Action. Event: : action. Performed() pre: source. name = 'bt. Ok' post: let window = self. get. Window() in window^close()
PAWindow. Event. SOS context Ph. View. Window. Event: : opened() pre: source. name = 'Photo. View' post: let elements = source. get. Nested. Elements(), cell = elements->select(ocl. Is. Kind. Of(Grid. Cell))->any(c | c. photo. Image. is. Selected), ind = cell. position. x * 2 + cell. position. y + 1 in rq: Request and rq. ocl. Is. New() and rq. set('action', 'Get. Photo') and rq. set('id', ind) and ph = Photo. create. From. String(Photo. Album. Web. Service^process(rq). response. Body) and ev. photo. Image = ph. data and ev. title = ph. description and ph->comment->for. All(c | ev. comments. text. concat(c. username). concat(‘: '). concat(c. text). concat('/n')) context PAWindow. Event: : closed() pre: source. name = 'Image. Chooser' post: source. confirm. Dialog implies ph: Photo and ph. ocl. Is. New() and ph. data = Image. from. File(source. file). content and ph. description = 'Enter your description here' and rq: Request and rq. ocl. Is. New() and rq. set('action', 'Add. Photo') and rq. set('photo', Photo. convert. To. String(ph)) and Photo. Album. Web. Service^process(rq)
Remove. Button. Action. SOS context Remove. Button. Action. Event: : action. Performed() pre: source. name = 'remove. Photo. Bt' post: let elements = source. get. Window(). get. Nested. Elements(), cell = elements->select(ocl. Is. Kind. Of(Grid. Cell))->any(c | c. photo. Image. is. Selected), ind = cell. position. x * 2 + cell. position. y + 1 in rq: Request and rq. ocl. Is. New() and rq. set('action', 'Delete. Photo') and rq. set('photo. Id', ind) and Photo. Album. Web. Service^process(rq)
Send. Button. Action. Event. SOS context Send. Button. Action. Event: : action. Performed() pre: source. name = 'send. Bt' post: let elements = source. get. Window(). get. Nested. Elements(), cell = elements->select(ocl. Is. Kind. Of(Grid. Cell))->any(c | c. photo. Image. is. Selected), ind = cell. position. x * 2 + cell. position. y + 1, nm = elements->select(ocl. Is. Kind. Of(Text. Field))->any(c | c. name = 'name. Field'). text, tx = elements->select(ocl. Is. Kind. Of(Text. Area)->any(c | c. name = 'message. Field'). text in rq: Request and rq. ocl. Is. New() and rq. set('action', 'Add. Comment') and rq. set('photo. Id', ind) and rq. set('user. Name', nm) and rq. set('text', tx) and rq. set('date', Date. now) and Photo. Album. Web. Service^process(rq)
Resources • Kobr. A 2 Specification - 2009 -03 -13 out-kobra-mm. pdf • Kobr. A 2 Models on Google Project Hosting http: //code. google. com/p/kobra 2/ • Kobra 2 MM (RSM)- http: //kobra 2. googlecode. com/svn/trunk/workspace/Kobr. A 2 MM • Web. App Model (RSM) – http: // kobra 2. googlecode. com/svn/trunk/workspace/Web. App • GUI-PIM-UF (RSM) – http: // kobra 2. googlecode. com/svn/trunk/workspace/GUI-PIM-UF
Resources • Kobr. A 2 Specification - 2009 -03 -13 out-kobra-mm. pdf • Kobr. A 2 Models on Google Project Hosting http: //code. google. com/p/kobra 2/ • Kobra 2 MM (RSM)- http: //kobra 2. googlecode. com/svn/trunk/workspace/Kobr. A 2 MM • Web. App Model (RSM) – http: // kobra 2. googlecode. com/svn/trunk/workspace/Web. App • Photo. Album Model (RSM) – http: // kobra 2. googlecode. com/svn/trunk/workspace/Photo. Album • GUI-PIM-UF (RSM) – http: // kobra 2. googlecode. com/svn/trunk/workspace/GUI-PIM-UF
- Slides: 69