I'm using MapFish Print to generate PDFs of maps, creating the map images in the pdf when I only use a WMS layer for base tiles is completely fine. Works as expected.
However, when I add a vector layer and a geoJSON object within it, mapfish print throws the following error:
Exception in thread "tilesReader3" java.lang.NullPointerException
at org.mapfish.print.map.renderers.vector.PointRenderer.renderImpl(PointRenderer.java:113)
at org.mapfish.print.map.renderers.vector.PointRenderer.renderImpl(PointRenderer.java:49)
at org.mapfish.print.map.renderers.vector.GeometriesRenderer.render(GeometriesRenderer.java:69)
at org.mapfish.print.map.renderers.vector.FeaturesRenderer$FeatureRenderer.renderImpl(FeaturesRenderer.java:62)
at org.mapfish.print.map.renderers.vector.FeaturesRenderer$FeatureRenderer.renderImpl(FeaturesRenderer.java:58)
at org.mapfish.print.map.renderers.vector.FeaturesRenderer.render(FeaturesRenderer.java:53)
at org.mapfish.print.map.renderers.vector.FeaturesRenderer$FeatureCollectionRenderer.renderImpl(FeaturesRenderer.java:70)
at org.mapfish.print.map.renderers.vector.FeaturesRenderer$FeatureCollectionRenderer.renderImpl(FeaturesRenderer.java:67)
at org.mapfish.print.map.renderers.vector.FeaturesRenderer.render(FeaturesRenderer.java:53)
at org.mapfish.print.map.readers.VectorMapReader$1.renderOnPdf(VectorMapReader.java:85)
at org.mapfish.print.map.ParallelMapTileLoader.handle(ParallelMapTileLoader.java:97)
at org.mapfish.print.map.ParallelMapTileLoader.handle(ParallelMapTileLoader.java:41)
at org.pvalsecc.concurrent.OrderedResultsExecutor.addOutput(OrderedResultsExecutor.java:148)
at org.pvalsecc.concurrent.OrderedResultsExecutor.access$600(OrderedResultsExecutor.java:23)
at org.pvalsecc.concurrent.OrderedResultsExecutor$Runner.run(OrderedResultsExecutor.java:181)
at java.lang.Thread.run(Unknown Source)
My query that I am sending to Mapfish print is a slightly modified version of the default sample (to use a different WMS as the default for the example is down), with the Vector layer added in, as follows:
{
layout: 'A4 portrait',
title: 'A simple example',
srs: 'EPSG:4326',
units: 'dd',
outputFilename: 'mapfish-print',
outputFormat: 'pdf',
layers: [
{
type: 'WMS',
format: 'image/png',
layers: ['OSM-GB:__all__'],
baseURL: 'http://www.osmgb.org.uk/ogc/wms'
},
{
type: 'Vector',
geoJson: {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-0.0996621,
51.5059247
]
},
"properties": {
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-0.099332,
51.5072000
]
},
"properties": {
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-0.0945508,
51.50240484
]
},
"properties": {
}
}
]
}
}
],
pages: [
{
center: [0.09, 51.50],
scale: 4000000,
dpi: 190,
mapTitle: "First map",
comment: "The \"routes\" layer is not shown (the scale is too small)",
data: [
{id:1, name: 'blah', icon: 'icon_pan'},
{id:2, name: 'blip', icon: 'icon_zoomin'}
]
},
{
center: [0.09, 51.50],
scale: 500000,
dpi: 190,
mapTitle: "Second map",
comment: "This is a zoomed in version of the first map. Since the scale is more appropriate, we show the \"routes\" layer.",
data: [
{id:1, name: 'blah', icon: 'icon_pan'},
{id:2, name: 'blip', icon: 'icon_zoomin'}
]
}
]
}
The GeoJSON validates and displays on geojsonlint.com, just fine. Having looked through the source for mapfish print I cannot figure out why exactly this is occurring. Though it seems to be something to do with styles, I have had no luck adding one into the request to fix this issue.
-- Update:
If anybody else ever comes across this issue, the problem was that (undocumented), you have to define within the vector layer, a set of styles, and make sure each feature in the geoJSON uses a style.
The problem was that (undocumented), you have to define within the vector layer, a set of styles and a styleproperty, and make sure each feature in the geoJSON uses a style.
The styles themselves are SVG styles, although many of the tags are renamed, so rather than being fill-color, they will be fillColor.
See here for a bit more detail: http://www.mapfish.org/doc/print/protocol.html#layers-params
The SVG styles which need to be defined are in the form of OpenLayers.Feature.Vector.style
Related
I have a graph which should have the following json structure
{
"models": [
{
"name": "Model1",
"id": 19,
"diagram": [
{
"name": "Diagram1",
"id": "34"
},
{
"name": "Diagram2",
"id": "36"
}
]
},
{
"name": "Model2",
"id": 14,
"diagram": [
{
"name": "Diagram2",
"id": "32"
}
]
}
]
}
Here is my sample graph:
g.addV('org').property('name', 'Org_seppmed').as('org1').addV('org').property('name', 'Org_siemens').as('org2').addV('user').property('name', 'U_Sebastian').as('user1').addV('user').property('name', 'U_Jaroslaw').as('user2').addV('user').property('name', 'U_Jürgen').as('user3').addV('user').property('name', 'U_Carsten').as('user4').addV('user').property('name', 'U_DevUser').as('user5').addE('administratedBy').from('org1').to('user1').addE('hasEmployee').from('org1').to('user2').addE('hasEmployee').from('org1').to('user3').addE('hasEmployee').from('org2').to('user4').addE('hasEmployee').from('org1').to('user5').addE('hasGuest').from('org1').to('user4').addV('project').property('name', 'P_Bremsen').as('projectmbt1').addV('project').property('name', 'P_Blinker').as('projectmbt2').addE('owns').from('user1').to('projectmbt1').addE('owns').from('user2').to('projectmbt2').addE('writes').from('user2').to('projectmbt1').addE('writes').from('user3').to('projectmbt1').addE('reads').from('user4').to('projectmbt1').addE('writes').from('user1').to('projectmbt2').addE('writes').from('user3').to('projectmbt2').addV('model').property('name', 'M_Bremse').as('modelmbt1').addV('model').property('name', 'M_Blinker').as('modelmbt2').addV('model').property('name', 'M_Bremse2').as('modelmbt3').addE('has').from('projectmbt1').to('modelmbt1').addE('has').from('projectmbt1').to('modelmbt3').addE('has').from('projectmbt2').to('modelmbt2').addV('diagram').property('name', 'D_D1').as('diagramd1').addV('diagram').property('name', 'D_D2').as('diagramd2').addV('diagram').property('name', 'D_D3').as('diagramd3').addV('diagram').property('name', 'D_D1').as('diagramd4').addV('testsuite').property('name', 'T_TestD1').as('testsuited1').addE('has').from('modelmbt1').to('diagramd1').addE('has').from('modelmbt1').to('diagramd2').addE('has').from('modelmbt2').to('diagramd3').addE('has').from('modelmbt3').to('diagramd4').addE('has').from('modelmbt1').to('testsuited1').addV('initial').as('initMBT1D1').addV('precondition').as('preMBT1D1').addV('teststep').property('name', 'N_Blinking left').as('node1MBT1D1').addV('teststep').property('name', 'N_Blinking right').as('node2MBT1D1').addV('teststep').property('name', 'N_Hazard flashers').as('node3MBT1D1').addV('teststep').property('name', 'N_Emergency flashers').as('node4MBT1D1').addV('teststep').property('name', 'N_Blinking off').as('node5MBT1D1').addV('node').as('connodeMBT1D1').addV('postcondition').as('postMBT1D1').addV('final').as('finalMBT1D1').addE('has').from('diagramd1').to('initMBT1D1').addE('has').from('diagramd1').to('preMBT1D1').addE('has').from('diagramd1').to('node1MBT1D1').addE('has').from('diagramd1').to('node2MBT1D1').addE('has').from('diagramd1').to('node3MBT1D1').addE('has').from('diagramd1').to('node4MBT1D1').addE('has').from('diagramd1').to('node5MBT1D1').addE('has').from('diagramd1').to('connodeMBT1D1').addE('has').from('diagramd1').to('postMBT1D1').addE('has').from('diagramd1').to('finalMBT1D1').addE('pointsTo').from('initMBT1D1').to('preMBT1D1').addE('pointsTo').from('preMBT1D1').to('node1MBT1D1').addE('pointsTo').from('preMBT1D1').to('node2MBT1D1').addE('pointsTo').from('preMBT1D1').to('node3MBT1D1').addE('pointsTo').from('preMBT1D1').to('node4MBT1D1').addE('pointsTo').from('preMBT1D1').to('node5MBT1D1').addE('pointsTo').from('node1MBT1D1').to('postMBT1D1').addE('pointsTo').from('postMBT1D1').to('node1MBT1D1').addE('pointsTo').from('node2MBT1D1').to('postMBT1D1').addE('pointsTo').from('node3MBT1D1').to('postMBT1D1').addE('pointsTo').from('node4MBT1D1').to('postMBT1D1').addE('pointsTo').from('node5MBT1D1').to('postMBT1D1').addE('pointsTo').from('postMBT1D1').to('connodeMBT1D1').addE('linksTo').from('connodeMBT1D1').to('diagramd2').addE('pointsTo').from('connodeMBT1D1').to('finalMBT1D1').addV('initial').as('initMBT1D2').addV('teststep').property('name', 'N_Trigger left').as('node1MBT1D2').addV('teststep').property('name', 'N_Trigger right').as('node2MBT1D2').addV('verificationpoint').property('name', 'N_Triggercheck').as('node3MBT1D2').addV('final').as('finalMBT1D2').addE('has').from('diagramd2').to('initMBT1D2').addE('has').from('diagramd2').to('node1MBT1D2').addE('has').from('diagramd2').to('node2MBT1D2').addE('has').from('diagramd2').to('node3MBT1D2').addE('has').from('diagramd2').to('finalMBT1D2').addE('pointsTo').from('initMBT1D2').to('node1MBT1D2').addE('pointsTo').from('initMBT1D2').to('node2MBT1D2').addE('pointsTo').from('node1MBT1D2').to('node3MBT1D2').addE('pointsTo').from('node2MBT1D2').to('node3MBT1D2').addE('pointsTo').from('node3MBT1D2').to('finalMBT1D2')
Now I am trying to find a query to get above structure:
g.V().hasLabel("model").out().hasLabel("diagram").path().by(elementMap())
The result is like:
==>path[{id=12384, label=model, name=Model2}, {id=28904, label=diagram, name=Diagram2}]
==>path[{id=37056, label=model, name=Model1}, {id=16448, label=diagram, name=Diagram1}]
==>path[{id=37056, label=model, name=Model1}, {id=24808, label=diagram, name=Diagram1}]
My expectation was to get a Map<Model, List<Diagram>>. But i get for each diagram of a model a complete new entry, instead of adding all related diagrams to a model.
How can I solve my problem?
If you want to generate a Map you will need to group using the model as the key. Something like shown below. Obviously, you will not really want to use the label but something that identifies the class of the model, if you have such a property, such as name.
g.V().hasLabel("model").
group().
by('name').
by(out().hasLabel("diagram").path().by(elementMap()).fold())
EDITED after discussion in comments:
If you do not want the whole path in the result but just the unique diagram nodes and their properties, the query can be amended to as shown below. This version also adds all of the properties from the label node as the group (map) key.
g.V().hasLabel("model").
group().
by(elementMap()).
by(out().hasLabel("diagram").elementMap().fold())
I am getting the below Json Response by hitting a RestAPI.
**
[
{
"index": 0,
"object": {
"attributes": {
"ID": [
{
"type": "configuration/entityTypes/Customer/attributes/ID",
"ov": true,
"value": "5",
"uri": "entities/attributes/ID/2Cqf5xG2"
},
{
"type": "configuration/entityTypes/Customer/attributes/ID",
"ov": true,
"value": "3028",
"uri": "entities/attributes/ID/fto38ZRR"
}
],
"IgpId": [
{
"type": "configuration/entityTypes/Customer/attributes/IgpId",
"ov": true,
"value": "1911",
"uri": "entities/attributes/IgpId/20ft8omYM"
}
],
"IgpName": [
{
"type": "configuration/entityTypes/Customer/attributes/IgpName",
"ov": true,
"value": "Dr. heath",
"uri": "entities/attributes/IgpName/20ft8oe1q"
}
],
"IgpID": [
{
"type": "configuration/entityTypes/Customer/attributes/IgpID",
"ov": true,
"value": "1872",
"uri": "entities/attributes/IgpID/20ft8oiI6"
}
],
"IgpNAME": [
{
"type": "configuration/entityTypes/Customer/attributes/IgpNAME",
"ov": true,
"value": "Dr Jc crook",
"uri": "entities/attributes/IgpNAME/20ft8oqoc"
}
]
}
},
"successful": true
}
]
**
I am trying to save the values for CoachID (3028), IgpID(1872), IgpId(1911), IgpName(Dr. heath), IgpNAME(Dr Jc crook) in String variables in APex class.
I have used a map to do so but unable to get the proper values. I wanted to get the above values in a List & return that list from function.
Can anyone help me on this? I am not supposed to do this using wrapper.
Regards,
Mohit
It can't be done as straight "JSON.deserialize" call because some fields are reserved keywords in Apex. How strict the wrapper ban is? I wouldn't want to type this stuff freehand but you can go to https://json2apex.herokuapp.com/, tick checkbox about explicit parser (again, since you have reserved keywords it'd happen anyway) and well, you have a ready class & cool stab at unit test / example how to use the code. It's battle-tested, if you can't use that then your project has bigger problems ;)
If you really really have to do it alone and with maps it'll be something like https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_System_Json.htm, example for deserializeUntyped
Am a new bee to vaadin. I have to show the data from a JSON file (which is fetching from MySQL db) in Grid/Table(vaadin). I am able show the data in table if JSON in the below format.
[
{
"id": "ex-wardrobe",
"productId": "ex-wardrobe",
"name": "exWardrobe",
"desc": "Some description",
"dimension": "WxDxH 148\" X 24\" X 112\" ",
"category": "Bedroom",
"subcategory": "Wardrobe",
"categoryId": "bedroom",
"subcategoryId": "wardrobe",
"tags": "all, Space Design Bedroom, Space Details Wardrobe",
"designer": "hb",
"curr": "INR",
"popularity": "1",
"relevance": "1",
"shortlisted": "1",
"likes": "1",
"createDt": "",
"pageId": "ex-wardrobe",
"styleName": "Fresh",
"styleId": "cfresh",
"priceRange": "Premium",
"priceId": "premium",
"defaultPrice": "123",
"defaultMaterial": "MDF ",
"defaultFinish": "LAMINATE"
}
]
But, if i get JSON(data is related to same product) in the below format am unable to add data in table.
[
{
"id": "ex-wardrobe",
"productId": "ex-wardrobe",
"name": "exWardrobe",
"desc": "Some description",
"dimension": "WxDxH 148\" X 24\" X 112\" ",
"category": "Bedroom",
"subcategory": "Wardrobe",
"categoryId": "bedroom",
"subcategoryId": "wardrobe",
"tags": "all, Space Design Bedroom, Space Details Wardrobe",
"designer": "hb",
"curr": "INR",
"popularity": "1",
"relevance": "1",
"shortlisted": "1",
"likes": "1",
"createDt": "",
"pageId": "ex-wardrobe",
"styleName": "Fresh",
"styleId": "cfresh",
"priceRange": "Premium",
"priceId": "premium",
"defaultPrice": "123",
"defaultMaterial": "MDF ",
"defaultFinish": "LAMINATE",
"mf": [
{
"basePrice": "123",
"material": "MDF ",
"finish": "LAMINATE"
}
],
"images": [
"066___ex_WARDROBE_Dim.jpg",
"067___ex_WARDROBE_close_door.jpg",
"068___ex_DOVE_dim.jpg"
],
"components": [],
"accessories": []
}
]
This is the code which am using to show JSON data in table,
Table grid = new Table();
root.addComponent(grid);
grid.setStyleName("iso3166");
grid.setPageLength(6);
grid.setSizeFull();
grid.setSelectable(true);
grid.setMultiSelect(false);
grid.setImmediate(true);
grid.setColumnReorderingAllowed(true);
grid.setColumnCollapsingAllowed(true);
try {
JSONArray products = productsDataProvider.getCatalogs();
JsonContainer dataSource =
JsonContainer.Factory.newInstance(products.toString());
grid.setContainerDataSource(dataSource);
grid.setColumnReorderingAllowed(true);
grid.setWidth("98%");
grid.addStyleName(ChameleonTheme.TABLE_STRIPED);
} catch (IllegalArgumentException ignored) {
}
grid.setWidth("100%");
grid.setHeight("100%");
root.addComponent(grid);
Am stuck on this and i have sleepless night on this. Million tons of thanks in advance. I hope you GURU's can help me in this :)
Sorry not vaadin expert. See it first time and like it. I guess your problem are the arrays inside your object. I mean this:
"mf": [
{
"basePrice": "173881",
"material": "MDF ",
"finish": "LAMINATE"
}
],
"images": [
"066___ex_WARDROBE_Dim.jpg",
"067___ex_WARDROBE_close_door.jpg",
"068___ex_DOVE_dim.jpg"
],
"components": [],
"accessories": []
No idea how the component should display this. Have you tried it without mf, images, components and accessories?
You are using a very simple JSONContainer. As can be seen in the source code, this implementation does not support nested / compound elements and arrays.
First you have to ask yourself how these complex objects need to be displayed (UX), especially the "mf" field.
UPDATE
Simple compound objects (like "simpleCompound": {"name": "foo", number: 123}) can be shown in a table column (not supported by the JSONContainer you use, but similar functionality is available by the BeanItemContainer, so look there for how to implement this functionality).
The array fields are more problematic from a UX standpoint. Mostly this information is only shown on demand or in separate panels. The Vaadin Grid component offers the possibility to show a details view, see the wiki. Maybe that will fit your requirements.
Currently nested json data is not supported unless you create your own advance template for that. There is currently an online json container application demo that is used to test if the data is really json or json array but not nested. Then it displays that data in grid table. So you can use this to verify your data.
You can also get the application template with source code on github
Am new to rest assured
I have a json response like this
{
"queryPath": "/api/",
"nId": "f084f5ad24fcfaa9e9faea0",
"statusCode": 707
"statusMessage": "Success",
"results": {
"data": [
{
"id": "10248522500798",
"capabilities": [
"men",
"women"
],
"name": "errt2"
},
{
"id": "418143778",
"capabilities": [
"dog",
"cat"
],
"name": "Livin"
}
]
}
}
String type = "men"
Using rest assured i need to check the type value men with capabilities array values
[
"men",
"women"
]
and
"capabilities": [
"dog",
"cat"
]
If the type value `men` not contains in any of the capabilities i need to raise error..how it is possible?
i used following code .But it is not working.any other way??
body("results.data.capabilities", hasItems(type));
Am getting error
Expected: (a collection containing "men")
Actual: [[ men,women
], [dog, cat]]
The problem is that your jsonPath
results.data.capabilities
points to both "capabilities" arrays since they are nested at the same level of your JSON. If you can reliably expect the first "capabilities" array to contain "men" then you can specify the first "capabilities" in your jsonPath like so:
results.data.capabilities[0]
Say I have a JSON array similar to the following:
[
{
"title": "This is a title",
"year": 2013,
"images": {
"image": "http://........jpg",
},
"ratings": {
"thumbsup": 1053,
"thumbsdown": 256
}
},
{
"title": "This is a title",
"year": 2013,
"images": {
"image": "http://........jpg",
},
"ratings": {
"thumbsup": 1053,
"thumbsdown": 256
}
}
]
And the required output is a JSON array like this:
[
{
"title": "This is a title",
"images": {
"image": "http://........jpg",
},
"ratings": {
"thumbsup": 1053,
}
},
{
"title": "This is a title",
"images": {
"image": "http://........jpg",
},
"ratings": {
"thumbsup": 1053,
}
}
]
Iv'e been researching and it's suggested that the most efficient way would be to parse it using the Jackson streaming API. This is for use on a PaaS with limited memory, so I wish to keep the memory usage to the bare minimum.
Is the best way to parse the JSON with Jackson Streaming API, and construct a new JSON array at the same time or simply remove the elements somehow?
I did something similiar with XML once. You can have the requestor tell you what fields you want to get back, and have it only emit those. In my case I had no control over the 3rd party axis xml view, but once I had the view, when I asked for things from it if it was already there I could give back just the pieces I was interested in. As a bonus, if you are marshalling or unmarshalling real java objects from the JSON after getting the json or XML you don't need to build the part of the object graph you don't care about.