Skip to content

Commit

Permalink
Fix #10805 JAXBException while updating an existing dashboard (#10813)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Lorenzo Natali <[email protected]>
  • Loading branch information
allyoucanmap and offtherailz authored Feb 21, 2025
1 parent 1e493c5 commit 2db004d
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 52 deletions.
2 changes: 1 addition & 1 deletion web/client/api/GeoStoreDAO.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const createAttributeList = (metadata = {}) => {
const attributes = metadata.attributes || omit(metadata, ["name", "description", "id", "advertised"]);

const xmlAttrs = Object.keys(attributes).map((key) => {
return "<attribute><name>" + key + "</name><value>" + attributes[key] + "</value><type>STRING</type></attribute>";
return "<attribute><name>" + key + "</name><value><![CDATA[" + attributes[key] + "]]></value><type>STRING</type></attribute>";
});
let attributesSection = "";
if (xmlAttrs.length > 0) {
Expand Down
6 changes: 3 additions & 3 deletions web/client/api/__tests__/GeoStoreDAO-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ describe('Test correctness of the GeoStore APIs', () => {
metadata = API.createAttributeList(metadata);
expect(metadata).toEqual(
"<Attributes>" +
"<attribute><name>nina</name><value>nina</value><type>STRING</type></attribute>" +
"<attribute><name>eating</name><value>eating</value><type>STRING</type></attribute>" +
"<attribute><name>plastic</name><value>plastic</value><type>STRING</type></attribute>" +
"<attribute><name>nina</name><value><![CDATA[nina]]></value><type>STRING</type></attribute>" +
"<attribute><name>eating</name><value><![CDATA[eating]]></value><type>STRING</type></attribute>" +
"<attribute><name>plastic</name><value><![CDATA[plastic]]></value><type>STRING</type></attribute>" +
"</Attributes>"
);
});
Expand Down
10 changes: 7 additions & 3 deletions web/client/api/usersession/__tests__/server-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ describe('usersession API server implementation', () => {
}
});
server.writeSession(null, "myname", "myuser", {myprop: "myvalue"}).subscribe((id) => {
expect(id).toBe(1);
expect(mockAxios.history.post[0].data).toContain("<name><![CDATA[myname]]></name>");
expect(mockAxios.history.post[0].data).toContain("<value>myuser</value>");
try {
expect(id).toBe(1);
expect(mockAxios.history.post[0].data).toContain("<name><![CDATA[myname]]></name>");
expect(mockAxios.history.post[0].data).toContain("<value><![CDATA[myuser]]></value>");
} catch (e) {
done(e);
}
done();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,10 @@ describe('resources api', () => {
"category": { "id": 5, "name": "MAP" },
"id": 1,
"name": "Map",
"attributes": { "context": 2 },
"attributes": {
"context": 2,
"detailsSettings": {}
},
"@extras": {
"context": {
"category": { "id": 3, "name": "CONTEXT" },
Expand Down
27 changes: 16 additions & 11 deletions web/client/plugins/ResourcesCatalog/api/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,17 @@ const getFilter = ({
};
};

const parseDetailsSettings = (detailsSettings) => {
if (isString(detailsSettings)) {
try {
return JSON.parse(detailsSettings);
} catch (e) {
return {};
}
}
return detailsSettings || {};
};

export const requestResources = ({
params,
config
Expand Down Expand Up @@ -201,8 +212,13 @@ export const requestResources = ({
isNextPageAvailable: page < (response?.totalCount / pageSize),
resources: resources
.map(({ tags, ...resource }) => {
const detailsSettings = parseDetailsSettings(resource?.attributes?.detailsSettings);
return {
...resource,
attributes: {
...resource?.attributes,
detailsSettings
},
...(tags && { tags: castArray(tags) })
};
})
Expand All @@ -223,17 +239,6 @@ export const requestResources = ({
});
};

const parseDetailsSettings = (detailsSettings) => {
if (isString(detailsSettings)) {
try {
return JSON.parse(detailsSettings);
} catch (e) {
return {};
}
}
return detailsSettings || {};
};

export const requestResource = ({ resource, user }) => {
return getResource(resource.id, { includeAttributes: true, withData: false, withPermissions: !!user })
.toPromise()
Expand Down
4 changes: 3 additions & 1 deletion web/client/plugins/ResourcesCatalog/utils/ResourcesUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { isEmpty, isEqual, omit, isArray, isObject } from 'lodash';
import merge from 'lodash/fp/merge';
import uuid from 'uuid/v1';

const NODATA = 'NODATA';

Expand Down Expand Up @@ -104,7 +105,8 @@ export const computePendingChanges = (initialResource, resource, resourceData) =
];
const categoryOptions = {
'thumbnail': {
tail: '/raw?decode=datauri',
// this forces the reload the thumbnail image when updated
tail: `/raw?decode=datauri&v=${uuid()}`,
category: 'THUMBNAIL'
},
'details': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,38 +127,6 @@ describe('ResourcesUtils', () => {
}
);

expect(computePendingChanges(
{ id: 1, name: 'Title', attributes: { thumbnail: '/thumb' }, category: { name: 'MAP' } },
{ id: 1, name: 'Title', attributes: { thumbnail: '' }, category: { name: 'MAP' } })).toEqual(
{
initialResource: { id: 1, name: 'Title', attributes: { thumbnail: '/thumb' }, category: { name: 'MAP' } },
resource: { id: 1, name: 'Title', attributes: { thumbnail: '' }, category: { name: 'MAP' } },
saveResource: {
id: 1,
permission: undefined,
category: 'MAP',
metadata: { id: 1, name: 'Title', attributes: { thumbnail: '/thumb' } },
linkedResources: { thumbnail: { tail: '/raw?decode=datauri', category: 'THUMBNAIL', value: '/thumb', data: 'NODATA' } }
},
changes: { linkedResources: { thumbnail: { tail: '/raw?decode=datauri', category: 'THUMBNAIL', value: '/thumb', data: 'NODATA' } } } }
);

expect(computePendingChanges(
{ id: 1, name: 'Title', attributes: {}, category: { name: 'MAP' } },
{ id: 1, name: 'Title', attributes: { thumbnail: '/thumb' }, category: { name: 'MAP' } })).toEqual(
{
initialResource: { id: 1, name: 'Title', attributes: { }, category: { name: 'MAP' } },
resource: { id: 1, name: 'Title', attributes: { thumbnail: '/thumb' }, category: { name: 'MAP' } },
saveResource: {
id: 1,
permission: undefined,
category: 'MAP',
metadata: { id: 1, name: 'Title', attributes: {} },
linkedResources: { thumbnail: { tail: '/raw?decode=datauri', category: 'THUMBNAIL', value: 'NODATA', data: '/thumb' } }
},
changes: { linkedResources: { thumbnail: { tail: '/raw?decode=datauri', category: 'THUMBNAIL', value: 'NODATA', data: '/thumb' } } } }
);

expect(computePendingChanges(
{ id: 1, name: 'Title', attributes: {}, category: { name: 'MAP' } },
{ id: 1, name: 'Title', attributes: { details: '/details' }, category: { name: 'MAP' } })).toEqual(
Expand All @@ -184,6 +152,26 @@ describe('ResourcesUtils', () => {
}
);
});
it('computePendingChanges with thumbnail', () => {
let computedChanges = computePendingChanges(
{ id: 1, name: 'Title', attributes: { thumbnail: '/thumb' }, category: { name: 'MAP' } },
{ id: 1, name: 'Title', attributes: { thumbnail: '' }, category: { name: 'MAP' } });
expect(computedChanges.initialResource).toEqual({ id: 1, name: 'Title', attributes: { thumbnail: '/thumb' }, category: { name: 'MAP' } });
expect(computedChanges.resource).toEqual({ id: 1, name: 'Title', attributes: { thumbnail: '' }, category: { name: 'MAP' } });
expect(computedChanges.changes.linkedResources.thumbnail.value).toBe('/thumb');
expect(computedChanges.changes.linkedResources.thumbnail.data).toBe('NODATA');

computedChanges = computePendingChanges(
{ id: 1, name: 'Title', attributes: {}, category: { name: 'MAP' } },
{ id: 1, name: 'Title', attributes: { thumbnail: '/thumb' }, category: { name: 'MAP' } });
expect(computedChanges.initialResource).toEqual({ id: 1, name: 'Title', attributes: { }, category: { name: 'MAP' } });
expect(computedChanges.resource).toEqual({ id: 1, name: 'Title', attributes: { thumbnail: '/thumb' }, category: { name: 'MAP' } });
expect(computedChanges.changes.linkedResources.thumbnail.value).toBe('NODATA');
expect(computedChanges.changes.linkedResources.thumbnail.data).toBe('/thumb');
const tailsParts = computedChanges.changes.linkedResources.thumbnail.tail.split('&');
expect(tailsParts[0]).toBe('/raw?decode=datauri');
expect(tailsParts[1].includes('v=')).toBe(true);
});
it('computePendingChanges with tags', () => {
const computed = computePendingChanges(
{ id: 1, name: 'Title', category: { name: 'MAP' }, tags: [{ id: '01' }, { id: '02' }] },
Expand Down

0 comments on commit 2db004d

Please sign in to comment.