On Wed, 13 Mar 2019 at 02:10, Roelof Wobben <r.wobben@home.nl> wrote:
Op 12-3-2019 om 18:46 schreef Ben Coman:
Then in Playground do... collectionUrl := ' https://www.rijksmuseum.nl/api/nl/collection?key=14OGzuak&format=json&type=s... '. json := NeoJSONReader fromString: (ZnEasy get: collectionUrl) contents. paintings := Paintings fromJSON: json. paintings inspect.
and then debug trace through that whole thing. Is that what you were trying to do? Or have I got the wrong end of the stick?
cheers -ben
There is a one to one relationship between the objectNumber and a Painting
I do not use the imageUrl found on this url because it's to big .
okay. So I presume you want "artObject/webImage/url" ? { "artObject": { "webImage": { "url": " http://lh6.ggpht.com/wwx2vAS9DzFmmyeZefPjMtmCNOdjD80gvkXJcylloy40SiZOhdLHVdd... "
So what I try now is first put all the objectNumber in a collection and use that collection on a second url to fetch a image of the right size
Okay. I understand, but I am *still* coaching you to *not* do that. Rather than gathering a collection of dumb numbers and then creating new Painting objects from those, (which is awkward for joining the new data with the previous data) work with the Painting objects you already have. Add a new instance variables "webImageUrl" and "webImage" Then either Painting >> getMoreData |entity| ... webImageUrl := (artObjectJson at: 'webImage') at: 'url'. entity := (ZnEasy get: webImageUrl) entity. webImage := ImageReadWriter formFromStream: entity readStream. which may lock the UI for a moment downloading them all, or download lazily (slight variation on my previous imageEntity which doubles up on storage)... Painting >> getMoreData ... webImageUrl := (artObjectJson at: 'webImage') at: 'url'. Painting >> webImage |entity| webImageUrl ifNil: [^nil]. webImage ifNil: [ entity := (ZnEasy get: webImageUrl) entity. webImage := ImageReadWriter formFromStream: entity readStream]. ^ webImage Painting >> gtInspectorJpegIn: composite <gtInspectorPresentationOrder: 0> composite morph title: 'Painting'; display: [ self webImage ]
I hope im clear what I try to do in this step
yes it is. Please take my coaching and kill your collection of numbers. Keeping them keeps you stuck in old ways of thinking. So just kill it :) Once you've done that, alternatives will open up for you and you'll be on the path to a new way of thinking about programming. :) :)
so numbers should be a collection of objectNumbers
no.
and paintings a collection of painting with the info I need
yes, and objectNumber is part of the info of a painting.
so to recap
this one must give me a collection of objectNumbers : ' https://www.rijksmuseum.nl/api/nl/collection?key=14OGzuak&format=json&type=s... '.
no. it gives you a collection of paintings, of which objectNumber is one attribute.
and the objectNumbers I can use for this url :
https://www.rijksmuseum.nl/api/nl/collection/<one objectNumber/tiles?key=14OGzuak&format=json
and I do not store the objectNumber in Paintings because I do not use it to display it in a seaside project.
Regardless of whether you display it or not, objectNumber is supplied by the server "as an attribute belonging to painting" so store it inside your Painting objects. Then rather than Seaside asking a collection of dumb numbers for each JPEG to display it asks a collection of smart Painting objects for their JPEG to display (since they know their own objectNumber, they can get the JPEG themselves). cheers -ben On Wed, 13 Mar 2019 at 02:10, Roelof Wobben <r.wobben@home.nl> wrote:
Op 12-3-2019 om 18:46 schreef Ben Coman:
On Wed, 13 Mar 2019 at 00:43, Roelof Wobben <r.wobben@home.nl> wrote:
I did try to make this idea work but now im complete lost.
Right now the collection that should contain the objectNumbers is total empty anyone who can see where I went wrong.
I included my code so far.
A few things... !Paintings class methodsFor: 'instance creation' stamp: 'RoelofWobben 3/12/2019 17:26'! getImagesDataFromJSON: json | instance | instance := Painting new. (json at: #values) do: [ :artObjectJson | | painting | painting := Painting new. painting imageUrl: (json at: #name). instance addPainting: painting ]. ^ instance! !
You are adding a painting to a painting, which semantically makes no sense. i.e. where #addPainting: is sent to "instance" , that is holding a Painting.
I would not expect your Painting class to have a method addPainting: Paintings should have that method.
btw, Stop using "instance" as a variable name. Its as bad as variables named "a", "i", "t", "z" - it provides no semantic context.
-------------------- Object subclass: #Paintings instanceVariableNames: 'paintings numbers'
Paintings class instanceVariableNames: 'numbers paintings'!
You've defined these variables on both the instance-side and class-side. I'll hazard a guess that you should delete the class-side definition.
----------------------------------
TBApplicationRootComponent initialize!Object subclass: #Painting instanceVariableNames: 'imageUrl'
Why are you *not* storing objectNumber inside each Painting? What is the relationship between paintings and objectNumbers? Is it one-to-many or one-to-one?
------------------- !Paintings methodsFor: 'instance creation' stamp: 'RoelofWobben 3/11/2019 08:05'! initialize super initialize. numbers := OrderedCollection new! !
Why do you *not* initialize variable "paintings" to "OrderedCollection new" ? Aren't you dealing with a collection of paintings?
---------------- There is lots more confusing me here, so before going further, in a fresh new image, can you load NeoJSON and the attached fileout.
Then in Playground do... collectionUrl := ' https://www.rijksmuseum.nl/api/nl/collection?key=14OGzuak&format=json&type=s... '. json := NeoJSONReader fromString: (ZnEasy get: collectionUrl) contents. paintings := Paintings fromJSON: json. paintings inspect.
and then debug trace through that whole thing. Is that what you were trying to do? Or have I got the wrong end of the stick?
cheers -ben
Oke, I try to tell what I want
Right now I only want to fetch the objectNumber is a collection.
so I can use that in a later step.
There is a one to one relationship between the objectNumber and a Painting
I do not use the imageUrl found on this url because it's to big .
So what I try now is first put all the objectNumber in a collection and use that collection on a second url to fetch a image of the right size
I hope im clear what I try to do in this step
so numbers should be a collection of objectNumbers and paintings a collection of painting with the info I need
so to recap
this one must give me a collection of objectNumbers : ' https://www.rijksmuseum.nl/api/nl/collection?key=14OGzuak&format=json&type=s... '.
and the objectNumbers I can use for this url :
https://www.rijksmuseum.nl/api/nl/collection/<one objectNumber/tiles?key=14OGzuak&format=json
and I do not store the objectNumber in Paintings because I do not use it to display it in a seaside project.
Roelof