@@ -76,13 +76,14 @@ const updateOrDeleteLinkedResource = (id, attributeName, linkedResource = {}, re
7676
7777/**
7878 * Creates a resource on GeoStore and link it to the current resource. Can be used for thumbnails, details and so on
79+ * If the data for the resource is "NODATA", it won't be created.
7980 * @param {number } id the id of the resource
8081 * @param {string } attributeName the name of the attribute to link
8182 * @param {object } linkedResource the resource object of the resource to link. This resource have a tail option that can be used to add options URL of the link
8283 * @param {object } API the API to use (default GeoStoreDAO)
8384 */
8485const createLinkedResource = ( id , attributeName , linkedResource , permission , API = GeoStoreDAO ) =>
85- Observable . defer ( ( ) =>
86+ linkedResource . data !== 'NODATA' ? Observable . defer ( ( ) =>
8687 API . createResource ( {
8788 name : `${ id } -${ attributeName } -${ uuid ( ) } `
8889 } ,
@@ -98,7 +99,7 @@ const createLinkedResource = (id, attributeName, linkedResource, permission, API
9899 ...( permission ? [ updateResourcePermissions ( linkedResourceId , permission , API ) ] : [ ] )
99100
100101 ] ) . map ( ( ) => linkedResourceId )
101- ) ;
102+ ) : Observable . of ( - 1 ) ;
102103
103104/**
104105 * Updates a linked resource. Check if the resource already exists as attribute.
@@ -121,15 +122,17 @@ const updateLinkedResource = (id, attributeName, linkedResource, permission, API
121122 : createLinkedResource ( id , attributeName , linkedResource , permission , API )
122123 ) . catch (
123124 /* if the attribute doesn't exists or if the linked resource update gave an error
124- * you have to create a new resource for the linked resource.
125+ * you have to create a new resource for the linked resource, provided it has valid data .
125126 * This error can occur if:
126127 * - The resource is new
127128 * - The resource URL is present as attribute of the main resource but the linked resource doesn't exist anymore.
128129 * ( for instance it may happen if the creation procedure gives an error )
129130 * - The resource is not writable by the user. It happens when a user changes the permission of a resource and doesn't update
130131 * the resource permission.
131132 */
132- ( e ) => createLinkedResource ( id , attributeName , linkedResource , permission , API , e )
133+ ( e ) => linkedResource && linkedResource . data && linkedResource . data !== 'NODATA' ?
134+ createLinkedResource ( id , attributeName , linkedResource , permission , API , e ) :
135+ Observable . of ( - 1 )
133136 ) ;
134137/**
135138 * Updates the permission of the linkedResources that are not modified.
@@ -291,9 +294,11 @@ export const createCategory = (category, API = GeoStoreDAO) =>
291294 * @return an observable that emits the id of the updated resource
292295 */
293296
294- export const updateResource = ( { id, data, permission, metadata, linkedResources = { } } = { } , API = GeoStoreDAO ) =>
295- // update metadata
296- Observable . forkJoin ( [
297+ export const updateResource = ( { id, data, permission, metadata, linkedResources = { } } = { } , API = GeoStoreDAO ) => {
298+ const linkedResourcesKeys = Object . keys ( linkedResources ) ;
299+
300+ // update metadata
301+ return Observable . forkJoin ( [
297302 // update data and permissions after data updated
298303 Observable . defer (
299304 ( ) => API . putResourceMetadataAndAttributes ( id , metadata )
@@ -304,17 +309,18 @@ export const updateResource = ({ id, data, permission, metadata, linkedResources
304309 ( ) => API . putResource ( id , data )
305310 )
306311 : Observable . of ( res ) )
307- . switchMap ( ( res ) => permission ? Observable . defer ( ( ) => updateResourcePermissions ( id , permission , API ) ) : Observable . of ( res ) ) ,
312+ . switchMap ( ( res ) => permission ? Observable . defer ( ( ) => updateResourcePermissions ( id , permission , API ) ) : Observable . of ( res ) ) ,
308313 // update linkedResources and permissions after linkedResources updated
309- ... (
310- Object . keys ( linkedResources ) . map (
314+ ( linkedResourcesKeys . length > 0 ? Observable . forkJoin (
315+ ... linkedResourcesKeys . map (
311316 attributeName => updateLinkedResource ( id , attributeName , linkedResources [ attributeName ] , permission , API )
312- . switchMap ( ( res ) => permission ?
313- Observable . defer ( ( ) => updateOtherLinkedResourcesPermissions ( id , linkedResources , permission , API ) )
314- : Observable . of ( res ) )
315317 )
316- )
318+ ) : Observable . of ( [ ] ) )
319+ . switchMap ( ( ) => permission ?
320+ Observable . defer ( ( ) => updateOtherLinkedResourcesPermissions ( id , linkedResources , permission , API ) ) :
321+ Observable . of ( - 1 ) )
317322 ] ) . map ( ( ) => id ) ;
323+ } ;
318324
319325/**
320326 * Deletes a resource and Its linked attributes
0 commit comments