Skip to content

Commit

Permalink
Fix geosolutions-it#271 AutoResourceUpdate implementation & geosoluti…
Browse files Browse the repository at this point in the history
…ons-it#274 remove widget (geosolutions-it#275)

* Fix geosolutions-it#271 AutoResourceUpdate implementation

* Update context as well and others

* updating epics logic for ignoring execution based on options

* Update pr with changes to plugin config

* update revision including fix for geosolutions-it#10622
  • Loading branch information
MV88 authored Nov 6, 2024
1 parent e0ebe93 commit d797b8a
Show file tree
Hide file tree
Showing 17 changed files with 434 additions and 28 deletions.
45 changes: 44 additions & 1 deletion configs/localConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"path": "print.capabilities"
},
{
"name": "usergroups",
"name": "usergroups",
"path": "security.user.groups.group"
}
],
Expand Down Expand Up @@ -246,8 +246,32 @@
}
}
},
"AutoResourceUpdateOptions": {
"urlsToReplace": {
"http://datigis.comune.fi.it/img": "https://datigis.comune.fi.it/img",
"http://geonetwork.comune.intranet/geonetwork": "https://geonetwork.comune.fi.it/geonetwork",
"http://geostories.comune.intranet/": "https://mapstore2.comune.fi.it",
"http://mappe.cittametropolitana.fi.it:443/geoserver": "https://mappe.cittametropolitana.fi.it/geoserver",
"http://opendata.comune.fi.it": "https://opendata.comune.fi.it",
"http://sr-vm378-sitgfn.comune.intranet:9080/geonetwork": "https://geonetwork.comune.fi.it/geonetwork",
"http://datigis.comune.fi.it/geonetwork": "https://geonetwork.comune.fi.it/geonetwork",
"http://geoserver.comune.intranet/geoserver": "https://datigis.comune.fi.it/geoserver",
"http://datigis.comune.intranet/geoserver": "https://datigis.comune.fi.it/geoserver",
"http://sr-vm380-sitgs1.comune.intranet:8080/geoserver": "https://datigis.comune.fi.it/geoserver",
"http://sr-vm380-sitgs1:8080/geoserver": "https://datigis.comune.fi.it/geoserver",
"http://datigis2.comune.intranet/geoserver": "https://datigis2.comune.fi.it/geoserver",
"http://tms.comune.fi.it/geowebcache": "https://tms.comune.fi.it/geowebcache",
"http://tms.comune.fi.it/tiles": "https://tms.comune.fi.it/tiles",
"http://tms.comune.intranet/geoserver": "https://datigis.comune.fi.it/geoserver/gwc/service",
"http://tms.comune.intranet/geowebcache_internal": "https://datigis.comune.fi.it/geoserver/gwc/service",
"http://3dtiles-cloud-cofi.comune.intranet": "https://3dtiles-cloud-cofi.comune.fi.it"
}
},
"plugins": {
"mobile": [
{
"name": "AutoResourceUpdate"
},
{
"name": "Map",
"cfg": {
Expand Down Expand Up @@ -442,6 +466,9 @@
}
},
"AutoMapUpdate",
{
"name": "AutoResourceUpdate"
},
"DrawerMenu",
"Notifications",
"BackgroundSelector",
Expand Down Expand Up @@ -720,6 +747,9 @@
}
],
"embedded": [
{
"name": "AutoResourceUpdate"
},
"Details",
{
"name": "Map",
Expand Down Expand Up @@ -933,6 +963,10 @@
"FeedbackMask"
],
"dashboard": [

{
"name": "AutoResourceUpdate"
},
"Details",
"AddWidgetDashboard",
"MapConnectionDashboard",
Expand Down Expand Up @@ -1078,6 +1112,9 @@
}
],
"geostory-embedded": [
{
"name": "AutoResourceUpdate"
},
"GeoStory",
{
"name": "GeoStoryNavigation",
Expand All @@ -1093,6 +1130,9 @@
}
],
"dashboard-embedded": [
{
"name": "AutoResourceUpdate"
},
{
"name": "Dashboard",
"cfg": {
Expand All @@ -1104,6 +1144,9 @@
}
],
"geostory": [
{
"name": "AutoResourceUpdate"
},
{
"name": "OmniBar",
"cfg": {
Expand Down
16 changes: 16 additions & 0 deletions js/actions/autoResourceUpdate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright 2024, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

export const START_UPDATING_RESOURCE = "AUTO_RESOURCE_UPDATE:START_UPDATING_RESOURCE";

export const startUpdatingResource = (options) => {
return {
type: START_UPDATING_RESOURCE,
options
};
};
14 changes: 14 additions & 0 deletions js/apiPlugins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

import AutoResourceUpdate from './plugins/AutoResourceUpdate';
import pluginsDef from '../MapStore2/web/client/product/apiPlugins';
const { plugins, requires } = pluginsDef;

export default {
plugins: {
...plugins,
AutoResourceUpdatePlugin: AutoResourceUpdate
},
requires: {
...requires
}
};
7 changes: 6 additions & 1 deletion js/apps/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import { checkForMissingPlugins } from '@mapstore/utils/DebugUtils';
import main from '@mapstore/product/main';
import {setConfigProp, setLocalConfigurationFile} from '@mapstore/utils/ConfigUtils';
import appConfig from '@mapstore/product/appConfig';
import plugins from '@mapstore/product/plugins';
import plugins from '@js/plugins';
import '../../assets/css/mapstore2.css';
import { manageAutoContextUpdateEpic } from '@js/epics/autoResourceUpdateContext';

/**
* Add custom (overriding) translations with:
Expand Down Expand Up @@ -52,6 +53,10 @@ setLocalConfigurationFile('configs/localConfig.json');

checkForMissingPlugins(plugins.plugins);

appConfig.appEpics = {
manageAutoContextUpdateEpic
};

main({
...appConfig,
themeCfg: {
Expand Down
2 changes: 1 addition & 1 deletion js/apps/dashboardEmbedded.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { loadVersion } from '@mapstore/actions/version';
import { triggerShowConnections } from '@mapstore/actions/dashboard';
import appConfigDashboardEmbedded from '@mapstore/product/appConfigDashboardEmbedded';
import pluginsDashboardEmbedded from '@mapstore/product/pluginsDashboardEmbedded';
import pluginsDashboardEmbedded from '@js/pluginsDashboardEmbedded';
import main from '@mapstore/product/main';
import url from 'url';
import '../../assets/css/mapstore2.css';
Expand Down
2 changes: 1 addition & 1 deletion js/apps/embedded.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import {
setLocalConfigurationFile
} from '@mapstore/utils/ConfigUtils';
import appConfigEmbedded from '@mapstore/product/appConfigEmbedded';
import apiPlugins from '@mapstore/product/apiPlugins';
import { loadVersion } from '@mapstore/actions/version';
import main from '@mapstore/product/main';
import '../../assets/css/mapstore2.css';

import apiPlugins from '@js/apiPlugins';
/**
* Add custom (overriding) translations with:
*
Expand Down
2 changes: 1 addition & 1 deletion js/apps/geostoryEmbedded.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
setLocalConfigurationFile
} from '@mapstore/utils/ConfigUtils';
import appConfigGeostoryEmbedded from '@mapstore/product/appConfigGeostoryEmbedded';
import pluginsEmbedded from '@mapstore/product/pluginsGeostoryEmbedded';
import pluginsEmbedded from '@js/pluginsGeostoryEmbedded';
import main from '@mapstore/product/main';
import { loadVersion } from '@mapstore/actions/version';
import '../../assets/css/mapstore2.css';
Expand Down
145 changes: 145 additions & 0 deletions js/epics/autoResourceUpdate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*
* Copyright 2024, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
import Rx from 'rxjs';
import { isEmpty } from 'lodash';

import { MAP_CONFIG_LOADED, MAP_INFO_LOADED } from '../../MapStore2/web/client/actions/config';
import { warning } from '../../MapStore2/web/client/actions/notifications';
import { updateCatalogServices } from '../../MapStore2/web/client/actions/catalog';
import { replaceLayers } from '../../MapStore2/web/client/actions/layers';
import { isUserAllowedSelectorCreator } from '../../MapStore2/web/client/selectors/security';
import { DASHBOARD_LOADED, dashboardLoaded } from '../../MapStore2/web/client/actions/dashboard';
import { SET_CURRENT_STORY, setCurrentStory } from '../../MapStore2/web/client/actions/geostory';

import { START_UPDATING_RESOURCE } from '@js/actions/autoResourceUpdate';
import { getConfigProp } from '../../MapStore2/web/client/utils/ConfigUtils';
import { migrateAllUrls } from '../utils/AutoResourceUpdateUtils';

/**
* Epics for update old map
* @name epics.autoresourceupdate
* @type {Object}
*/


/**
* When map has been loaded, it sends a notification if the version is less than 2 and users has write permission.
* @param {external:Observable} action$ manages `MAP_CONFIG_LOADED` and `MAP_INFO_LOADED`.
* @memberof epics.autoresourceupdate
* @return {external:Observable}
*/
export const manageAutoMapUpdateEpic = (action$, store) =>
action$.ofType(START_UPDATING_RESOURCE)
.switchMap(() =>
action$.ofType(MAP_CONFIG_LOADED)
.switchMap((mapConfigLoaded) =>
action$.ofType(MAP_INFO_LOADED)
.take(1)
.switchMap(() => {
const state = store.getState();
const options = getConfigProp('AutoResourceUpdateOptions');
const showNotification = options?.showNotificationForRoles?.length && isUserAllowedSelectorCreator({
allowedRoles: options.showNotificationForRoles
})(state);
const layers = mapConfigLoaded?.config?.map?.layers || [];
const newLayers = migrateAllUrls(layers, options.urlsToReplace);
const services = mapConfigLoaded?.config?.catalogServices?.services;
const newServices = migrateAllUrls(services, options.urlsToReplace);
let actions = [];
if (showNotification) {
// show only for allowed roles, do not show it by default
actions.push(warning({
title: "notification.warning",
message: "notification.updateOldResource",
autoDismiss: options.autoDismiss,
position: "tc"
}));
}
actions.push(updateCatalogServices(newServices));
actions.push(replaceLayers(newLayers));
if (isEmpty(options)) {
return Rx.Observable.empty();
}
return Rx.Observable.from(actions);
})
));

/**
* When map has been loaded, it sends a notification if the version is less than 2 and users has write permission.
* @param {external:Observable} action$ manages `MAP_CONFIG_LOADED` and `MAP_INFO_LOADED`.
* @memberof epics.autoresourceupdate
* @return {external:Observable}
*/
export const manageAutoDashboardUpdateEpic = (action$, store) =>
action$.ofType(START_UPDATING_RESOURCE)
.switchMap(() =>
action$.ofType(DASHBOARD_LOADED)
.take(1)
.switchMap(({resource, data}) => {
const state = store.getState();
const options = getConfigProp('AutoResourceUpdateOptions');
const showNotification = options?.showNotificationForRoles?.length && isUserAllowedSelectorCreator({
allowedRoles: options.showNotificationForRoles
})(state);

const newData = migrateAllUrls(data, options.urlsToReplace);
let actions = [];
if (showNotification) {
// show only for allowed roles, do not show it by default
actions.push(warning({
title: "notification.warning",
message: "notification.updateOldResource",
autoDismiss: options.autoDismiss,
position: "tc"
}));
}
actions.push(dashboardLoaded(resource, newData));
if (isEmpty(options)) {
return Rx.Observable.empty();
}
return Rx.Observable.from(actions);
})
);


/**
* when a story is loaded a check is done and all urls are replaced
* @param {external:Observable} action$ manages `START_UPDATING_RESOURCE` and `SET_CURRENT_STORY`.
* @memberof epics.autoresourceupdate
* @return {external:Observable}
*/
export const manageAutoGeostoryUpdateEpic = (action$, store) =>
action$.ofType(START_UPDATING_RESOURCE)
.switchMap(() =>
action$.ofType(SET_CURRENT_STORY)
.filter(({story}) => !isEmpty(story))
.switchMap(({story}) => {
const state = store.getState();
const options = getConfigProp('AutoResourceUpdateOptions');
const showNotification = options?.showNotificationForRoles?.length && isUserAllowedSelectorCreator({
allowedRoles: options.showNotificationForRoles
})(state);

const newStory = migrateAllUrls(story, options.urlsToReplace);
let actions = [];
if (showNotification) {
// show only for allowed roles, do not show it by default
actions.push(warning({
title: "notification.warning",
message: "notification.updateOldResource",
autoDismiss: options.autoDismiss,
position: "tc"
}));
}
actions.push(setCurrentStory(newStory));
if (isEmpty(options)) {
return Rx.Observable.empty();
}
return Rx.Observable.from(actions);
})
);
59 changes: 59 additions & 0 deletions js/epics/autoResourceUpdateContext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2024, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
import Rx from 'rxjs';
import {isEmpty} from 'lodash';

import { LOAD_MAP_CONFIG, MAP_CONFIG_LOADED } from '../../MapStore2/web/client/actions/config';
import { warning } from '../../MapStore2/web/client/actions/notifications';
import { updateCatalogServices } from '../../MapStore2/web/client/actions/catalog';
import { isUserAllowedSelectorCreator } from '../../MapStore2/web/client/selectors/security';
import { replaceLayers } from '../../MapStore2/web/client/actions/layers';

import { getConfigProp } from '../../MapStore2/web/client/utils/ConfigUtils';
import { migrateAllUrls } from '../utils/AutoResourceUpdateUtils';


/**
* When map has been loaded, it sends a notification if the version is less than 2 and users has write permission.
* @param {external:Observable} action$ manages `MAP_CONFIG_LOADED` and `MAP_INFO_LOADED`.
* @memberof epics.autoresourceupdate
* @return {external:Observable}
*/
export const manageAutoContextUpdateEpic = (action$, store) =>
action$.ofType(LOAD_MAP_CONFIG)
.switchMap(() =>
action$.ofType(MAP_CONFIG_LOADED)
.take(1)
.switchMap((mapConfigLoaded) => {
const state = store.getState();
const options = getConfigProp('AutoResourceUpdateOptions');
const showNotification = options?.showNotificationForRoles?.length && isUserAllowedSelectorCreator({
allowedRoles: options.showNotificationForRoles
})(state);
const layers = mapConfigLoaded?.config?.map?.layers || [];
const newLayers = migrateAllUrls(layers, options.urlsToReplace);
const services = mapConfigLoaded?.config?.catalogServices?.services;
const newServices = migrateAllUrls(services, options.urlsToReplace);
let actions = [];
if (showNotification) {
// show only for allowed roles, do not show it by default
actions.push(warning({
title: "notification.warning",
message: "notification.updateOldResource",
autoDismiss: options.autoDismiss,
position: "tc"
}));
}
actions.push(updateCatalogServices(newServices));
actions.push(replaceLayers(newLayers));
if (isEmpty(options)) {
return Rx.Observable.empty();
}
return Rx.Observable.from(actions);
})
);
Loading

0 comments on commit d797b8a

Please sign in to comment.