690 likes | 854 Vues
KobrA2. WebApp Framework. WebService.SOS.ocl. context ServiceController::process(request: Request): Response post: let act = mvcAction->any(e | e.name = request.get('action').value) in result = act.do(request). WebService.SOT.ocl. context Response :: write ( value : String)
E N D
KobrA2 WebApp Framework
WebService.SOS.ocl context ServiceController::process(request: Request): Response post: let act = mvcAction->any(e | e.name = request.get('action').value) in result = act.do(request)
WebService.SOT.ocl contextResponse::write(value: String) post: responseBody = responseBody@pre.concat(value) context StringDictionary::get(key: String):String post: result = attribute->any(e | e.key = key).value context StringDictionary::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 StringDictionary::remove(key: String):String post: result = attribute@pre->any(e | e.key = key).value and attribute->select(e | e.key = key)->size() = 0
WebService.ROS.ocl context WebService::process(request: Resquest):Response post: result = serviceController.process(request)
ServiceController.SOS.ocl context ServiceController::process(request: Request): Response post: let act = mvcAction->any(e | e.name = request.get('action').value) in result = act.do(request)
MVCModel.SOT.ocl contextModelEntity::all():Sequence(ModelEntity) post: result = entity contextModelEntity::put():ModelEntity post: models->includes(self) contextModelEntity::delete():ModelEntity post: models->excludes(self) context ModelEntity::get(eid : String):ModelEntity post: result = models->select(e | e.id = eid)
KobrA2 PhotoAlbum as instanceofWebApp Framework
AddComment.SOS -- do() simply calls addComment() method of PhotoManager contextAddComment::do(request:Request):Response post: let id:Integer = K2Library.createFromString(Integer, request.attribute->any( a:Attribute | a.key = 'photoId').value), us: String = request.attribute->any(a:Attribute | a.key = 'userName'), text:String = request.attribute->any(a:Attribute | a.key = 'text'), date: Timestamp = K2Library.createFromString(Timestamp, request.attribute->any( a:Attribute | a.key = 'date').value) in PhotoManager^addComment(id,us,date,text)
AddPhoto.SOS -- do() simply calls addPhoto() method of PhotoManager context AddPhotos::do(request:Request):Response post: let photo:Photo = Photo.createFromString(request.attribute->any( a:Attribute | a.key = 'photo').value) in PhotoManager.addPhoto(photo)
ListPhotos.SOS -- do() simply calls getAllPhotos() method of PhotoManager context ListPhotos::do(request:Request):Response post: let photos:Sequence(Photo) = PhotoManager.getAllPhotos() in result.oclAsType(Response).write(K2Library.convertToString(Sequence(Photo), photos)) and result.header.kind = HeaderKind::contentType and result.header.value = 'binary/octet-stream'
PhotoManager.SOS (1/3) -- retrieveallphotos contextPhotoManager::getAllPhotos():Sequence(Photo) post: result = photos -- add a photo contextPhotoManager::addPhoto(photo:Photo) pre: notphotos->includes( photo) post: photos = photos@pre->including(photo) -- updates a photo's informations (ex. name, description) contextPhotoManager::updatePhoto(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
PhotoManager.SOS (2/3) -- add a comment to a photo - Breno's version context PhotoManager::addComment(id:Integer, us:String, c:String, data:Timestamp) pre: self.photos->exists( e:Photo | e.id = photo.id) post: let comment:Comment and comment.oclIsNew() and comment.userName = 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 PhotoManager::addComment(photoId:Integer, userName: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.photoId = photoId), c:Comment in c.oclIsNew() and c.userName = userName and c.date = date and c.text = text and photo.comments->includes(c) and photo.comments->size() = photo.comments@pre->size() + 1
PhotoManager.SOS (3/3) -- completely removes a photo context PhotoManager::removePhoto(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)