diff --git a/hsy-resources/pom.xml b/hsy-resources/pom.xml index 9f6f5d5..8eb475f 100644 --- a/hsy-resources/pom.xml +++ b/hsy-resources/pom.xml @@ -6,21 +6,15 @@ fi.hsy.oskari hsy-parent - 1.5.3 + 1.6.0 hsy-resources jar Resources for application - - fi.nls.oskari - content-resources - ${oskari.version} - org.oskari - service-capabilities-update - 1.55.1 + content-resources org.oskari diff --git a/hsy-resources/src/main/java/flyway/dev/V1_00_0__add_default_admin_user.java b/hsy-resources/src/main/java/flyway/dev/V1_00_0__add_default_admin_user.java index 201b5d1..787bddc 100755 --- a/hsy-resources/src/main/java/flyway/dev/V1_00_0__add_default_admin_user.java +++ b/hsy-resources/src/main/java/flyway/dev/V1_00_0__add_default_admin_user.java @@ -1,30 +1,29 @@ package flyway.dev; +import org.flywaydb.core.api.migration.BaseJavaMigration; +import org.flywaydb.core.api.migration.Context; + import fi.nls.oskari.log.LogFactory; import fi.nls.oskari.log.Logger; import fi.nls.oskari.service.ServiceException; import fi.nls.oskari.service.UserService; import fi.nls.oskari.user.DatabaseUserService; -import org.flywaydb.core.api.migration.jdbc.JdbcMigration; - -import java.sql.Connection; -public class V1_00_0__add_default_admin_user implements JdbcMigration { +public class V1_00_0__add_default_admin_user extends BaseJavaMigration { private Logger log = LogFactory.getLogger(V1_00_0__add_default_admin_user.class); - public void migrate(Connection connection) { - + public void migrate(Context context) { UserService dbService = null; try { dbService = DatabaseUserService.getInstance(); + try { + dbService.updateUserPassword("admin", "oskari"); + } catch (ServiceException se) { + log.error(se, "Cannot update password"); + } } catch (ServiceException se) { log.error(se, "Unable to initialize User service!"); } - try { - dbService.updateUserPassword("admin", "oskari"); - } catch (ServiceException se) { - log.error(se, "Cannot update password"); - } } } diff --git a/hsy-resources/src/main/java/flyway/hsy/V1_00_0__register_download_basket_bundle.java b/hsy-resources/src/main/java/flyway/hsy/V1_00_0__register_download_basket_bundle.java index 66f984f..95add19 100755 --- a/hsy-resources/src/main/java/flyway/hsy/V1_00_0__register_download_basket_bundle.java +++ b/hsy-resources/src/main/java/flyway/hsy/V1_00_0__register_download_basket_bundle.java @@ -1,24 +1,25 @@ package flyway.hsy; -import java.sql.Connection; +import java.sql.SQLException; -import org.flywaydb.core.api.migration.jdbc.JdbcMigration; +import org.flywaydb.core.api.migration.BaseJavaMigration; +import org.flywaydb.core.api.migration.Context; +import org.oskari.helpers.BundleHelper; -import fi.nls.oskari.db.BundleHelper; import fi.nls.oskari.domain.map.view.Bundle; -public class V1_00_0__register_download_basket_bundle implements JdbcMigration{ +public class V1_00_0__register_download_basket_bundle extends BaseJavaMigration { - private static final String NAMESPACE = "hsy"; private static final String DOWNLOAD_BASKET = "download-basket"; - public void migrate(Connection connection) { + public void migrate(Context context) throws SQLException { // BundleHelper checks if these bundles are already registered Bundle downloadBasket = new Bundle(); downloadBasket.setConfig("{}"); downloadBasket.setState("{}"); downloadBasket.setName(DOWNLOAD_BASKET); - downloadBasket.setStartup(BundleHelper.getDefaultBundleStartup(NAMESPACE, DOWNLOAD_BASKET, "Download basket")); - BundleHelper.registerBundle(downloadBasket); + //downloadBasket.setStartup(BundleHelper.getDefaultBundleStartup(NAMESPACE, DOWNLOAD_BASKET, "Download basket")); + BundleHelper.registerBundle(context.getConnection(), downloadBasket); } + } diff --git a/hsy-resources/src/main/java/flyway/hsy/V1_00_1__add_download_basket_to_views.java b/hsy-resources/src/main/java/flyway/hsy/V1_00_1__add_download_basket_to_views.java index e02d6e4..a14f0d3 100755 --- a/hsy-resources/src/main/java/flyway/hsy/V1_00_1__add_download_basket_to_views.java +++ b/hsy-resources/src/main/java/flyway/hsy/V1_00_1__add_download_basket_to_views.java @@ -1,49 +1,15 @@ package flyway.hsy; -import java.sql.Connection; -import java.sql.PreparedStatement; +import org.flywaydb.core.api.migration.BaseJavaMigration; +import org.flywaydb.core.api.migration.Context; +import org.oskari.helpers.AppSetupHelper; -import org.flywaydb.core.api.migration.jdbc.JdbcMigration; - -import fi.nls.oskari.map.view.ViewService; -import fi.nls.oskari.map.view.AppSetupServiceMybatisImpl; - -public class V1_00_1__add_download_basket_to_views implements JdbcMigration { +public class V1_00_1__add_download_basket_to_views extends BaseJavaMigration { - private static final ViewService VIEW_SERVICE = new AppSetupServiceMybatisImpl(); private static final String DOWNLOAD_BASKET = "download-basket"; - public void migrate(Connection connection) throws Exception { - long viewId = VIEW_SERVICE.getDefaultViewId(); - makeInsert(viewId,connection); - } - - private void makeInsert(long viewId, Connection connection) - throws Exception { - - final PreparedStatement statement = - connection.prepareStatement("INSERT INTO portti_view_bundle_seq" + - "(view_id, bundle_id, seqno, config, state, startup, bundleinstance) " + - "VALUES (" + - "?, " + - "(SELECT id FROM portti_bundle WHERE name=?), " + - "(SELECT max(seqno)+1 FROM portti_view_bundle_seq WHERE view_id=?), " + - "?, ?, " + - "(SELECT startup FROM portti_bundle WHERE name=?), " + - "?)"); - - statement.setLong(1, viewId); - statement.setString(2, DOWNLOAD_BASKET); - statement.setLong(3, viewId); - statement.setString(4, "{}"); - statement.setString(5, "{}"); - statement.setString(6, DOWNLOAD_BASKET); - statement.setString(7, DOWNLOAD_BASKET); - - try { - statement.execute(); - } finally { - statement.close(); - } + public void migrate(Context context) throws Exception { + AppSetupHelper.addBundleToApps(context.getConnection(), DOWNLOAD_BASKET); } + } diff --git a/hsy-resources/src/main/java/flyway/hsy/V1_00_2__register_link_panel_bundle.java b/hsy-resources/src/main/java/flyway/hsy/V1_00_2__register_link_panel_bundle.java index 8ea970e..52f9e50 100644 --- a/hsy-resources/src/main/java/flyway/hsy/V1_00_2__register_link_panel_bundle.java +++ b/hsy-resources/src/main/java/flyway/hsy/V1_00_2__register_link_panel_bundle.java @@ -1,24 +1,22 @@ package flyway.hsy; -import java.sql.Connection; +import java.sql.SQLException; -import org.flywaydb.core.api.migration.jdbc.JdbcMigration; +import org.flywaydb.core.api.migration.BaseJavaMigration; +import org.flywaydb.core.api.migration.Context; +import org.oskari.helpers.BundleHelper; -import fi.nls.oskari.db.BundleHelper; import fi.nls.oskari.domain.map.view.Bundle; -public class V1_00_2__register_link_panel_bundle implements JdbcMigration{ +public class V1_00_2__register_link_panel_bundle extends BaseJavaMigration { - private static final String NAMESPACE = "hsy"; private static final String LINK_PANEL = "link-panel"; - public void migrate(Connection connection) { - // BundleHelper checks if these bundles are already registered + public void migrate(Context context) throws SQLException { Bundle linkPanel = new Bundle(); linkPanel.setConfig("{}"); linkPanel.setState("{}"); linkPanel.setName(LINK_PANEL); - linkPanel.setStartup(BundleHelper.getDefaultBundleStartup(NAMESPACE, LINK_PANEL, "Link panel")); - BundleHelper.registerBundle(linkPanel); + BundleHelper.registerBundle(context.getConnection(), linkPanel); } } diff --git a/hsy-resources/src/main/java/flyway/hsy/V1_00_3__add_link_panel_to_views.java b/hsy-resources/src/main/java/flyway/hsy/V1_00_3__add_link_panel_to_views.java index 231199d..92c21f4 100755 --- a/hsy-resources/src/main/java/flyway/hsy/V1_00_3__add_link_panel_to_views.java +++ b/hsy-resources/src/main/java/flyway/hsy/V1_00_3__add_link_panel_to_views.java @@ -1,49 +1,15 @@ package flyway.hsy; -import java.sql.Connection; -import java.sql.PreparedStatement; +import org.flywaydb.core.api.migration.BaseJavaMigration; +import org.flywaydb.core.api.migration.Context; +import org.oskari.helpers.AppSetupHelper; -import org.flywaydb.core.api.migration.jdbc.JdbcMigration; - -import fi.nls.oskari.map.view.ViewService; -import fi.nls.oskari.map.view.AppSetupServiceMybatisImpl; - -public class V1_00_3__add_link_panel_to_views implements JdbcMigration{ +public class V1_00_3__add_link_panel_to_views extends BaseJavaMigration { - private static final ViewService VIEW_SERVICE = new AppSetupServiceMybatisImpl(); - private static final String LINK_PANEL = "link-panel"; + private static final String LINK_PANEL = "link-panel"; - public void migrate(Connection connection) throws Exception { - long viewId = VIEW_SERVICE.getDefaultViewId(); - makeInsert(viewId,connection); + public void migrate(Context context) throws Exception { + AppSetupHelper.addBundleToApps(context.getConnection(), LINK_PANEL); } - private void makeInsert(long viewId, Connection connection) - throws Exception { - - final PreparedStatement statement = - connection.prepareStatement("INSERT INTO portti_view_bundle_seq" + - "(view_id, bundle_id, seqno, config, state, startup, bundleinstance) " + - "VALUES (" + - "?, " + - "(SELECT id FROM portti_bundle WHERE name=?), " + - "(SELECT max(seqno)+1 FROM portti_view_bundle_seq WHERE view_id=?), " + - "?, ?, " + - "(SELECT startup FROM portti_bundle WHERE name=?), " + - "?)"); - - statement.setLong(1, viewId); - statement.setString(2, LINK_PANEL); - statement.setLong(3, viewId); - statement.setString(4, "{}"); - statement.setString(5, "{}"); - statement.setString(6, LINK_PANEL); - statement.setString(7, LINK_PANEL); - - try { - statement.execute(); - } finally { - statement.close(); - } - } } diff --git a/hsy-resources/src/main/java/flyway/hsy/V1_00_4__register_lang_override_bundle.java b/hsy-resources/src/main/java/flyway/hsy/V1_00_4__register_lang_override_bundle.java index 2ac4d93..25d4044 100644 --- a/hsy-resources/src/main/java/flyway/hsy/V1_00_4__register_lang_override_bundle.java +++ b/hsy-resources/src/main/java/flyway/hsy/V1_00_4__register_lang_override_bundle.java @@ -1,23 +1,22 @@ package flyway.hsy; -import java.sql.Connection; +import java.sql.SQLException; -import org.flywaydb.core.api.migration.jdbc.JdbcMigration; +import org.flywaydb.core.api.migration.BaseJavaMigration; +import org.flywaydb.core.api.migration.Context; +import org.oskari.helpers.BundleHelper; -import fi.nls.oskari.db.BundleHelper; import fi.nls.oskari.domain.map.view.Bundle; -public class V1_00_4__register_lang_override_bundle implements JdbcMigration{ - private static final String NAMESPACE = "hsy"; - private static final String LANG_OVERRIDES = "hsy-lang-overrides"; +public class V1_00_4__register_lang_override_bundle extends BaseJavaMigration { - public void migrate(Connection connection) { - // BundleHelper checks if these bundles are already registered + private static final String LANG_OVERRIDES = "hsy-lang-overrides"; + + public void migrate(Context context) throws SQLException { Bundle linkPanel = new Bundle(); linkPanel.setConfig("{}"); linkPanel.setState("{}"); linkPanel.setName(LANG_OVERRIDES); - linkPanel.setStartup(BundleHelper.getDefaultBundleStartup(NAMESPACE, LANG_OVERRIDES, "Lang overrides")); - BundleHelper.registerBundle(linkPanel); + BundleHelper.registerBundle(context.getConnection(), linkPanel); } } diff --git a/hsy-resources/src/main/java/flyway/hsy/V1_00_5__add_lang_override_to_views.java b/hsy-resources/src/main/java/flyway/hsy/V1_00_5__add_lang_override_to_views.java index e509347..6636147 100755 --- a/hsy-resources/src/main/java/flyway/hsy/V1_00_5__add_lang_override_to_views.java +++ b/hsy-resources/src/main/java/flyway/hsy/V1_00_5__add_lang_override_to_views.java @@ -1,48 +1,15 @@ package flyway.hsy; -import java.sql.Connection; -import java.sql.PreparedStatement; +import org.flywaydb.core.api.migration.BaseJavaMigration; +import org.flywaydb.core.api.migration.Context; +import org.oskari.helpers.AppSetupHelper; -import org.flywaydb.core.api.migration.jdbc.JdbcMigration; +public class V1_00_5__add_lang_override_to_views extends BaseJavaMigration { -import fi.nls.oskari.map.view.ViewService; -import fi.nls.oskari.map.view.AppSetupServiceMybatisImpl; + private static final String LANG_OVERRIDES = "hsy-lang-overrides"; -public class V1_00_5__add_lang_override_to_views implements JdbcMigration{ - private static final ViewService VIEW_SERVICE = new AppSetupServiceMybatisImpl(); - private static final String LANG_OVERRIDES = "hsy-lang-overrides"; - - public void migrate(Connection connection) throws Exception { - long viewId = VIEW_SERVICE.getDefaultViewId(); - makeInsert(viewId,connection); - } - - private void makeInsert(long viewId, Connection connection) - throws Exception { - - final PreparedStatement statement = - connection.prepareStatement("INSERT INTO portti_view_bundle_seq" + - "(view_id, bundle_id, seqno, config, state, startup, bundleinstance) " + - "VALUES (" + - "?, " + - "(SELECT id FROM portti_bundle WHERE name=?), " + - "(SELECT max(seqno)+1 FROM portti_view_bundle_seq WHERE view_id=?), " + - "?, ?, " + - "(SELECT startup FROM portti_bundle WHERE name=?), " + - "?)"); - - statement.setLong(1, viewId); - statement.setString(2, LANG_OVERRIDES); - statement.setLong(3, viewId); - statement.setString(4, "{}"); - statement.setString(5, "{}"); - statement.setString(6, LANG_OVERRIDES); - statement.setString(7, LANG_OVERRIDES); - - try { - statement.execute(); - } finally { - statement.close(); - } + public void migrate(Context context) throws Exception { + AppSetupHelper.addBundleToApps(context.getConnection(), LANG_OVERRIDES); } + } diff --git a/hsy-resources/src/main/java/flyway/hsy/V1_00_6__register_content_editor_bundle.java b/hsy-resources/src/main/java/flyway/hsy/V1_00_6__register_content_editor_bundle.java index 602d229..b395564 100644 --- a/hsy-resources/src/main/java/flyway/hsy/V1_00_6__register_content_editor_bundle.java +++ b/hsy-resources/src/main/java/flyway/hsy/V1_00_6__register_content_editor_bundle.java @@ -1,24 +1,22 @@ package flyway.hsy; -import java.sql.Connection; +import java.sql.SQLException; -import org.flywaydb.core.api.migration.jdbc.JdbcMigration; +import org.flywaydb.core.api.migration.BaseJavaMigration; +import org.flywaydb.core.api.migration.Context; +import org.oskari.helpers.BundleHelper; -import fi.nls.oskari.db.BundleHelper; import fi.nls.oskari.domain.map.view.Bundle; -public class V1_00_6__register_content_editor_bundle implements JdbcMigration{ +public class V1_00_6__register_content_editor_bundle extends BaseJavaMigration { - private static final String NAMESPACE = "tampere"; - private static final String CONTENT_EDITOR = "content-editor"; + private static final String CONTENT_EDITOR = "content-editor"; - public void migrate(Connection connection) { - // BundleHelper checks if these bundles are already registered - Bundle contenEditorTool = new Bundle(); - contenEditorTool.setConfig("{}"); - contenEditorTool.setState("{}"); - contenEditorTool.setName(CONTENT_EDITOR); - contenEditorTool.setStartup(BundleHelper.getDefaultBundleStartup(NAMESPACE, CONTENT_EDITOR, "content-editor")); - BundleHelper.registerBundle(contenEditorTool); - } + public void migrate(Context context) throws SQLException { + Bundle contenEditorTool = new Bundle(); + contenEditorTool.setConfig("{}"); + contenEditorTool.setState("{}"); + contenEditorTool.setName(CONTENT_EDITOR); + BundleHelper.registerBundle(context.getConnection(), contenEditorTool); + } } diff --git a/hsy-resources/src/main/java/flyway/hsy/V1_00_7__add_backgroundlayerselectionplugin_to_mapfull.java b/hsy-resources/src/main/java/flyway/hsy/V1_00_7__add_backgroundlayerselectionplugin_to_mapfull.java index 7b65913..1b15f6f 100755 --- a/hsy-resources/src/main/java/flyway/hsy/V1_00_7__add_backgroundlayerselectionplugin_to_mapfull.java +++ b/hsy-resources/src/main/java/flyway/hsy/V1_00_7__add_backgroundlayerselectionplugin_to_mapfull.java @@ -7,19 +7,20 @@ import fi.nls.oskari.map.layer.OskariLayerServiceMybatisImpl; import fi.nls.oskari.map.view.ViewService; import fi.nls.oskari.map.view.AppSetupServiceMybatisImpl; -import org.flywaydb.core.api.migration.jdbc.JdbcMigration; + +import org.flywaydb.core.api.migration.BaseJavaMigration; +import org.flywaydb.core.api.migration.Context; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import java.sql.Connection; import java.util.List; /** * Created by * @author Heikki Ylitalo */ -public class V1_00_7__add_backgroundlayerselectionplugin_to_mapfull implements JdbcMigration { +public class V1_00_7__add_backgroundlayerselectionplugin_to_mapfull extends BaseJavaMigration { private static final ViewService VIEW_SERVICE = new AppSetupServiceMybatisImpl(); private static final OskariLayerService LAYER_SERVICE = new OskariLayerServiceMybatisImpl(); private static final String PLUGIN_NAME = "Oskari.mapframework.bundle.mapmodule.plugin.BackgroundLayerSelectionPlugin"; @@ -27,8 +28,8 @@ public class V1_00_7__add_backgroundlayerselectionplugin_to_mapfull implements J private static final String OPASKARTTA_NAME = "Opaskartta_PKS"; private static final String ORTOILMAKUVA2015_NAME = "taustakartat_ja_aluejaot:ortoilmakuva2015"; private static final String OSM_NAME = "osm-finland"; - public void migrate(Connection connection) - throws Exception { + + public void migrate(Context context) throws Exception { List views = VIEW_SERVICE.getViewsForUser(-1); for(View v : views) { if(v.isDefault()) { diff --git a/hsy-resources/src/main/java/flyway/hsy/V1_00_8__register_selected_featuredata_bundle.java b/hsy-resources/src/main/java/flyway/hsy/V1_00_8__register_selected_featuredata_bundle.java index 8b8cd4c..7c617e3 100644 --- a/hsy-resources/src/main/java/flyway/hsy/V1_00_8__register_selected_featuredata_bundle.java +++ b/hsy-resources/src/main/java/flyway/hsy/V1_00_8__register_selected_featuredata_bundle.java @@ -1,24 +1,22 @@ package flyway.hsy; -import java.sql.Connection; +import java.sql.SQLException; -import org.flywaydb.core.api.migration.jdbc.JdbcMigration; +import org.flywaydb.core.api.migration.BaseJavaMigration; +import org.flywaydb.core.api.migration.Context; +import org.oskari.helpers.BundleHelper; -import fi.nls.oskari.db.BundleHelper; import fi.nls.oskari.domain.map.view.Bundle; -public class V1_00_8__register_selected_featuredata_bundle implements JdbcMigration{ +public class V1_00_8__register_selected_featuredata_bundle extends BaseJavaMigration { - private static final String NAMESPACE = "framework"; private static final String SELECTED_FEATUREDATA = "selected-featuredata"; - public void migrate(Connection connection) { - // BundleHelper checks if these bundles are already registered + public void migrate(Context context) throws SQLException { Bundle selectedFeatureData = new Bundle(); selectedFeatureData.setConfig("{}"); selectedFeatureData.setState("{}"); selectedFeatureData.setName(SELECTED_FEATUREDATA); - selectedFeatureData.setStartup(BundleHelper.getDefaultBundleStartup(NAMESPACE, SELECTED_FEATUREDATA, "Selected Featuredata")); - BundleHelper.registerBundle(selectedFeatureData); + BundleHelper.registerBundle(context.getConnection(), selectedFeatureData); } } diff --git a/hsy-resources/src/main/java/flyway/hsy/V1_00_9__add_selected_featuredata_to_views.java b/hsy-resources/src/main/java/flyway/hsy/V1_00_9__add_selected_featuredata_to_views.java index efda476..121a44c 100755 --- a/hsy-resources/src/main/java/flyway/hsy/V1_00_9__add_selected_featuredata_to_views.java +++ b/hsy-resources/src/main/java/flyway/hsy/V1_00_9__add_selected_featuredata_to_views.java @@ -1,50 +1,15 @@ package flyway.hsy; -import java.sql.Connection; -import java.sql.PreparedStatement; +import org.flywaydb.core.api.migration.BaseJavaMigration; +import org.flywaydb.core.api.migration.Context; +import org.oskari.helpers.AppSetupHelper; -import org.flywaydb.core.api.migration.jdbc.JdbcMigration; - -import fi.nls.oskari.map.view.ViewService; -import fi.nls.oskari.map.view.AppSetupServiceMybatisImpl; - -public class V1_00_9__add_selected_featuredata_to_views implements JdbcMigration { +public class V1_00_9__add_selected_featuredata_to_views extends BaseJavaMigration { - private static final ViewService VIEW_SERVICE = new AppSetupServiceMybatisImpl(); - private static final String SELECTED_FEATUREDATA = "selected-featuredata"; + private static final String SELECTED_FEATUREDATA = "selected-featuredata"; - public void migrate(Connection connection) throws Exception { - long viewId = VIEW_SERVICE.getDefaultViewId(); - makeInsert(viewId,connection); - makeInsert(1,connection); - } - - private void makeInsert(long viewId, Connection connection) - throws Exception { - - final PreparedStatement statement = - connection.prepareStatement("INSERT INTO portti_view_bundle_seq" + - "(view_id, bundle_id, seqno, config, state, startup, bundleinstance) " + - "VALUES (" + - "?, " + - "(SELECT id FROM portti_bundle WHERE name=?), " + - "(SELECT max(seqno)+1 FROM portti_view_bundle_seq WHERE view_id=?), " + - "?, ?, " + - "(SELECT startup FROM portti_bundle WHERE name=?), " + - "?)"); - - statement.setLong(1, viewId); - statement.setString(2, SELECTED_FEATUREDATA); - statement.setLong(3, viewId); - statement.setString(4, "{}"); - statement.setString(5, "{}"); - statement.setString(6, SELECTED_FEATUREDATA); - statement.setString(7, SELECTED_FEATUREDATA); - - try { - statement.execute(); - } finally { - statement.close(); - } + public void migrate(Context context) throws Exception { + AppSetupHelper.addBundleToApps(context.getConnection(), SELECTED_FEATUREDATA); } + } diff --git a/hsy-resources/src/main/java/flyway/hsy/V1_02_0__replace_layerselector2_bundle_to_hierarchical_layerlist.java b/hsy-resources/src/main/java/flyway/hsy/V1_02_0__replace_layerselector2_bundle_to_hierarchical_layerlist.java index b4dc649..7e5443c 100755 --- a/hsy-resources/src/main/java/flyway/hsy/V1_02_0__replace_layerselector2_bundle_to_hierarchical_layerlist.java +++ b/hsy-resources/src/main/java/flyway/hsy/V1_02_0__replace_layerselector2_bundle_to_hierarchical_layerlist.java @@ -7,35 +7,29 @@ import java.util.ArrayList; import java.util.List; -import fi.nls.oskari.db.BundleHelper; import fi.nls.oskari.domain.map.view.Bundle; import fi.nls.oskari.domain.map.view.View; import fi.nls.oskari.log.LogFactory; import fi.nls.oskari.log.Logger; -import fi.nls.oskari.util.FlywayHelper; -import org.flywaydb.core.api.migration.jdbc.JdbcMigration; -import fi.nls.oskari.map.view.ViewService; -import fi.nls.oskari.map.view.AppSetupServiceMybatisImpl; +import org.flywaydb.core.api.migration.BaseJavaMigration; +import org.flywaydb.core.api.migration.Context; +import org.oskari.helpers.BundleHelper; - -public class V1_02_0__replace_layerselector2_bundle_to_hierarchical_layerlist implements JdbcMigration { +public class V1_02_0__replace_layerselector2_bundle_to_hierarchical_layerlist extends BaseJavaMigration { private static final Logger LOG = LogFactory.getLogger(V1_02_0__replace_layerselector2_bundle_to_hierarchical_layerlist.class); private static final String BUNDLE_LAYERSELECTOR2 = "layerselector2"; private static final String BUNDLE_HIERARCHICAL_LAYERLIST = "hierarchical-layerlist"; private int updatedViewCount = 0; - private ViewService service = null; - public void migrate(Connection connection) throws Exception { - service = new AppSetupServiceMybatisImpl(); + public void migrate(Context context) throws Exception { try { - updateViews(connection); + updateViews(context.getConnection()); } finally { LOG.info("Updated views:", updatedViewCount); - service = null; } } @@ -52,11 +46,11 @@ private void updateViews(Connection conn) private List getOutdatedViews(Connection conn) throws SQLException { List list = new ArrayList<>(); - final String sql = "SELECT id FROM portti_view " + + final String sql = "SELECT id FROM oskari_appsetup " + "WHERE (type = 'USER' OR type = 'DEFAULT') AND " + "id IN (" + - "SELECT distinct view_id FROM portti_view_bundle_seq WHERE bundle_id IN (" + - "SELECT id FROM portti_bundle WHERE name='layerselection2' OR name='layerselector2'" + + "SELECT distinct appsetup_id FROM oskari_appsetup_bundles WHERE bundle_id IN (" + + "SELECT id FROM oskari_bundle WHERE name='layerselection2' OR name='layerselector2'" + "));"; try (PreparedStatement statement = conn.prepareStatement(sql)) { try (ResultSet rs = statement.executeQuery()) { @@ -72,12 +66,12 @@ private List getOutdatedViews(Connection conn) throws SQLException { public void addHierarchicalLayerListBundle(Connection conn, final long viewId) throws SQLException { - Bundle layerselectorBundle = BundleHelper.getRegisteredBundle(BUNDLE_LAYERSELECTOR2, conn); + Bundle layerselectorBundle = BundleHelper.getRegisteredBundle(conn, BUNDLE_LAYERSELECTOR2); if( layerselectorBundle == null) { // not even registered so migration not needed return; } - Bundle newBundle = BundleHelper.getRegisteredBundle(BUNDLE_HIERARCHICAL_LAYERLIST, conn); + Bundle newBundle = BundleHelper.getRegisteredBundle(conn, BUNDLE_HIERARCHICAL_LAYERLIST); if(newBundle == null) { throw new RuntimeException("Bundle not registered: " + BUNDLE_HIERARCHICAL_LAYERLIST); } @@ -88,12 +82,12 @@ public void addHierarchicalLayerListBundle(Connection conn, final long viewId) t } public void replaceLayerselectorBundleToHierarchicalLayerlist(Connection conn, final long viewId, final Bundle oldBundle, final Bundle newBundle) throws SQLException { - final String sql = "UPDATE portti_view_bundle_seq " + + final String sql = "UPDATE oskari_appsetup_bundles " + "SET " + " bundle_id=?, " + " startup=?, " + " bundleinstance=?" + - "WHERE bundle_id = ? and view_id=?"; + "WHERE bundle_id = ? and appsetup_id=?"; try (PreparedStatement statement = conn.prepareStatement(sql)){ diff --git a/hsy-resources/src/main/java/flyway/hsy/V1_02_1__remove_layerselection_bundle_from_default_views.java b/hsy-resources/src/main/java/flyway/hsy/V1_02_1__remove_layerselection_bundle_from_default_views.java index 16fc8d1..98eda27 100755 --- a/hsy-resources/src/main/java/flyway/hsy/V1_02_1__remove_layerselection_bundle_from_default_views.java +++ b/hsy-resources/src/main/java/flyway/hsy/V1_02_1__remove_layerselection_bundle_from_default_views.java @@ -1,13 +1,13 @@ package flyway.hsy; -import fi.nls.oskari.db.BundleHelper; import fi.nls.oskari.domain.map.view.Bundle; import fi.nls.oskari.domain.map.view.View; import fi.nls.oskari.log.LogFactory; import fi.nls.oskari.log.Logger; -import fi.nls.oskari.map.view.ViewService; -import fi.nls.oskari.map.view.AppSetupServiceMybatisImpl; -import org.flywaydb.core.api.migration.jdbc.JdbcMigration; + +import org.flywaydb.core.api.migration.BaseJavaMigration; +import org.flywaydb.core.api.migration.Context; +import org.oskari.helpers.BundleHelper; import java.sql.Connection; import java.sql.PreparedStatement; @@ -16,22 +16,19 @@ import java.util.ArrayList; import java.util.List; -public class V1_02_1__remove_layerselection_bundle_from_default_views implements JdbcMigration { +public class V1_02_1__remove_layerselection_bundle_from_default_views extends BaseJavaMigration { private static final Logger LOG = LogFactory.getLogger(V1_02_1__remove_layerselection_bundle_from_default_views.class); private static final String BUNDLE_LAYERSELECTION2 = "layerselection2"; private int updatedViewCount = 0; - private ViewService service = null; - public void migrate(Connection connection) throws Exception { - service = new AppSetupServiceMybatisImpl(); + public void migrate(Context context) throws Exception { try { - updateViews(connection); + updateViews(context.getConnection()); } finally { LOG.info("Updated views:", updatedViewCount); - service = null; } } @@ -48,11 +45,11 @@ private void updateViews(Connection conn) private List getOutdatedViews(Connection conn) throws SQLException { List list = new ArrayList<>(); - final String sql = "SELECT id FROM portti_view " + + final String sql = "SELECT id FROM oskari_appsetup " + "WHERE (type = 'USER' OR type = 'DEFAULT') AND " + "id IN (" + - "SELECT distinct view_id FROM portti_view_bundle_seq WHERE bundle_id IN (" + - "SELECT id FROM portti_bundle WHERE name='layerselection2'" + + "SELECT distinct appsetup_id FROM oskari_appsetup_bundles WHERE bundle_id IN (" + + "SELECT id FROM oskari_bundle WHERE name='layerselection2'" + "));"; try (PreparedStatement statement = conn.prepareStatement(sql)) { try (ResultSet rs = statement.executeQuery()) { @@ -68,15 +65,15 @@ private List getOutdatedViews(Connection conn) throws SQLException { public void removeLayerselectionBundle(Connection conn, final long viewId) throws SQLException { - Bundle layerselectionBundle = BundleHelper.getRegisteredBundle(BUNDLE_LAYERSELECTION2, conn); + Bundle layerselectionBundle = BundleHelper.getRegisteredBundle(conn, BUNDLE_LAYERSELECTION2); if(layerselectionBundle == null) { // not even registered so migration not needed return; } // remove layerselection2 bundle - final String sql = "DELETE FROM portti_view_bundle_seq " + - "WHERE bundle_id = ? AND view_id=?;"; + final String sql = "DELETE FROM oskari_appsetup_bundles " + + "WHERE bundle_id = ? AND appsetup_id=?;"; try (PreparedStatement statement = conn.prepareStatement(sql)){ diff --git a/hsy-resources/src/main/java/flyway/hsy/V1_02_2__update_background_selection_plugins_layers.java b/hsy-resources/src/main/java/flyway/hsy/V1_02_2__update_background_selection_plugins_layers.java index d6a1d85..899cf8b 100755 --- a/hsy-resources/src/main/java/flyway/hsy/V1_02_2__update_background_selection_plugins_layers.java +++ b/hsy-resources/src/main/java/flyway/hsy/V1_02_2__update_background_selection_plugins_layers.java @@ -1,21 +1,18 @@ package flyway.hsy; -import fi.nls.oskari.log.LogFactory; -import fi.nls.oskari.log.Logger; import fi.nls.oskari.util.PropertyUtil; import helpers.LayerHelper; -import org.flywaydb.core.api.migration.jdbc.JdbcMigration; -import java.sql.Connection; +import org.flywaydb.core.api.migration.BaseJavaMigration; +import org.flywaydb.core.api.migration.Context; -public class V1_02_2__update_background_selection_plugins_layers implements JdbcMigration { - private static final Logger LOG = LogFactory.getLogger(V1_02_2__update_background_selection_plugins_layers.class); +public class V1_02_2__update_background_selection_plugins_layers extends BaseJavaMigration { - public void migrate(Connection connection) throws Exception { + public void migrate(Context context) throws Exception { String[] layers = PropertyUtil.getCommaSeparatedList("flyway.hsy.V1_02_2.layers"); boolean skip = PropertyUtil.getOptional("flyway.hsy.V1_02_2.skip", false); if (!skip) { - LayerHelper.setBackgroundSelectionPluginLayers(connection, layers); + LayerHelper.setBackgroundSelectionPluginLayers(context.getConnection(), layers); } } } diff --git a/hsy-resources/src/main/java/flyway/hsy/V1_02_3__add_logoplugin_to_mapfull.java b/hsy-resources/src/main/java/flyway/hsy/V1_02_3__add_logoplugin_to_mapfull.java index a614af8..839655b 100755 --- a/hsy-resources/src/main/java/flyway/hsy/V1_02_3__add_logoplugin_to_mapfull.java +++ b/hsy-resources/src/main/java/flyway/hsy/V1_02_3__add_logoplugin_to_mapfull.java @@ -1,26 +1,23 @@ package flyway.hsy; -import fi.nls.oskari.domain.map.OskariLayer; import fi.nls.oskari.domain.map.view.Bundle; import fi.nls.oskari.domain.map.view.View; -import fi.nls.oskari.map.layer.OskariLayerService; -import fi.nls.oskari.map.layer.OskariLayerServiceMybatisImpl; import fi.nls.oskari.map.view.ViewService; import fi.nls.oskari.map.view.AppSetupServiceMybatisImpl; -import org.flywaydb.core.api.migration.jdbc.JdbcMigration; + +import org.flywaydb.core.api.migration.BaseJavaMigration; +import org.flywaydb.core.api.migration.Context; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import java.sql.Connection; import java.util.List; -public class V1_02_3__add_logoplugin_to_mapfull implements JdbcMigration { +public class V1_02_3__add_logoplugin_to_mapfull extends BaseJavaMigration { private static final ViewService VIEW_SERVICE = new AppSetupServiceMybatisImpl(); - private static final OskariLayerService LAYER_SERVICE = new OskariLayerServiceMybatisImpl(); private static final String PLUGIN_NAME = "Oskari.mapframework.bundle.mapmodule.plugin.LogoPlugin"; private static final String MAPFULL = "mapfull"; - public void migrate(Connection connection) + public void migrate(Context context) throws Exception { List views = VIEW_SERVICE.getViewsForUser(-1); for(View v : views) { diff --git a/hsy-resources/src/main/java/flyway/hsy/V1_02_4__add_selected_featuredata_to_views.java b/hsy-resources/src/main/java/flyway/hsy/V1_02_4__add_selected_featuredata_to_views.java index 08dd321..966eb22 100755 --- a/hsy-resources/src/main/java/flyway/hsy/V1_02_4__add_selected_featuredata_to_views.java +++ b/hsy-resources/src/main/java/flyway/hsy/V1_02_4__add_selected_featuredata_to_views.java @@ -1,27 +1,28 @@ package flyway.hsy; -import fi.nls.oskari.domain.map.view.Bundle; import fi.nls.oskari.domain.map.view.View; import fi.nls.oskari.map.view.ViewService; import fi.nls.oskari.map.view.AppSetupServiceMybatisImpl; -import fi.nls.oskari.util.FlywayHelper; -import org.flywaydb.core.api.migration.jdbc.JdbcMigration; + +import org.flywaydb.core.api.migration.BaseJavaMigration; +import org.flywaydb.core.api.migration.Context; +import org.oskari.helpers.AppSetupHelper; import java.sql.Connection; import java.util.List; -public class V1_02_4__add_selected_featuredata_to_views implements JdbcMigration { +public class V1_02_4__add_selected_featuredata_to_views extends BaseJavaMigration { private static final ViewService VIEW_SERVICE = new AppSetupServiceMybatisImpl(); private static final String BUNDLE_ID = "selected-featuredata"; - public void migrate(Connection connection) throws Exception { + public void migrate(Context context) throws Exception { + Connection connection = context.getConnection(); List views = VIEW_SERVICE.getViewsForUser(-1); for (View v : views) { if (v.isDefault()) { - if (FlywayHelper.viewContainsBundle(connection, BUNDLE_ID, v.getId())) { - continue; + if (!AppSetupHelper.appContainsBundle(connection, v.getId(), BUNDLE_ID)) { + AppSetupHelper.addBundleToApp(connection, v.getId(), BUNDLE_ID); } - FlywayHelper.addBundleWithDefaults(connection, v.getId(), BUNDLE_ID); } } } diff --git a/hsy-resources/src/main/java/flyway/hsy/V1_02_6__update_logoplugin_config.java b/hsy-resources/src/main/java/flyway/hsy/V1_02_6__update_logoplugin_config.java index ecb16c4..6d5e5e4 100644 --- a/hsy-resources/src/main/java/flyway/hsy/V1_02_6__update_logoplugin_config.java +++ b/hsy-resources/src/main/java/flyway/hsy/V1_02_6__update_logoplugin_config.java @@ -1,27 +1,24 @@ package flyway.hsy; -import fi.nls.oskari.domain.map.OskariLayer; import fi.nls.oskari.domain.map.view.Bundle; import fi.nls.oskari.domain.map.view.View; -import fi.nls.oskari.map.layer.OskariLayerService; -import fi.nls.oskari.map.layer.OskariLayerServiceMybatisImpl; import fi.nls.oskari.map.view.ViewService; import fi.nls.oskari.map.view.AppSetupServiceMybatisImpl; -import org.flywaydb.core.api.migration.jdbc.JdbcMigration; + +import org.flywaydb.core.api.migration.BaseJavaMigration; +import org.flywaydb.core.api.migration.Context; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import java.sql.Connection; import java.util.List; -public class V1_02_6__update_logoplugin_config implements JdbcMigration { +public class V1_02_6__update_logoplugin_config extends BaseJavaMigration { private static final ViewService VIEW_SERVICE = new AppSetupServiceMybatisImpl(); - private static final OskariLayerService LAYER_SERVICE = new OskariLayerServiceMybatisImpl(); private static final String PLUGIN_NAME = "Oskari.mapframework.bundle.mapmodule.plugin.LogoPlugin"; private static final String MAPFULL = "mapfull"; - public void migrate(Connection connection) + public void migrate(Context context) throws Exception { List views = VIEW_SERVICE.getViewsForUser(-1); for(View v : views) { diff --git a/hsy-resources/src/main/java/flyway/hsy/V1_03_0__change_hierarchical_layerlist_to_layerlist.java b/hsy-resources/src/main/java/flyway/hsy/V1_03_0__change_hierarchical_layerlist_to_layerlist.java new file mode 100644 index 0000000..e234978 --- /dev/null +++ b/hsy-resources/src/main/java/flyway/hsy/V1_03_0__change_hierarchical_layerlist_to_layerlist.java @@ -0,0 +1,46 @@ +package flyway.hsy; + +import java.sql.Connection; +import java.sql.SQLException; +import java.util.List; + +import org.flywaydb.core.api.migration.BaseJavaMigration; +import org.flywaydb.core.api.migration.Context; +import org.oskari.helpers.AppSetupHelper; +import org.oskari.helpers.BundleHelper; + +import fi.nls.oskari.domain.map.view.Bundle; + +public class V1_03_0__change_hierarchical_layerlist_to_layerlist extends BaseJavaMigration { + + public void migrate(Context context) throws Exception { + String bundleToAdd = "layerlist"; + String bundleToRemove = "hierarchical-layerlist"; + + Connection c = context.getConnection(); + + List appsetupIds = AppSetupHelper.getSetupsForUserAndDefaultType(c); + + BundleHelper.registerBundle(c, bundleToAdd); + for (long appsetupId : appsetupIds) { + swapBundle(c, appsetupId, bundleToAdd, bundleToRemove); + } + BundleHelper.unregisterBundle(c, bundleToRemove); + } + + private void swapBundle(Connection c, long appsetupId, String bundleToAdd, String bundleToRemove) throws SQLException { + Bundle bundle = AppSetupHelper.getAppBundle(c, appsetupId, bundleToRemove); + if (bundle == null) { + return; + } + + final int seqno = bundle.getSeqNo(); + AppSetupHelper.removeBundleFromApp(c, appsetupId, bundleToRemove); + + AppSetupHelper.addBundleToApp(c, appsetupId, bundleToAdd); + Bundle added = AppSetupHelper.getAppBundle(c, appsetupId, bundleToAdd); + added.setSeqNo(seqno); + AppSetupHelper.updateAppBundle(c, appsetupId, added); + } + +} diff --git a/hsy-resources/src/main/java/flyway/hsy/V1_03_2__update_mapfull_projectiondefs_gk25_axisorder.java b/hsy-resources/src/main/java/flyway/hsy/V1_03_2__update_mapfull_projectiondefs_gk25_axisorder.java new file mode 100644 index 0000000..f02cf87 --- /dev/null +++ b/hsy-resources/src/main/java/flyway/hsy/V1_03_2__update_mapfull_projectiondefs_gk25_axisorder.java @@ -0,0 +1,70 @@ +package flyway.hsy; + +import java.sql.Connection; +import java.sql.SQLException; +import java.util.List; + +import org.flywaydb.core.api.migration.BaseJavaMigration; +import org.flywaydb.core.api.migration.Context; +import org.json.JSONException; +import org.json.JSONObject; +import org.oskari.helpers.AppSetupHelper; + +import fi.nls.oskari.domain.map.view.Bundle; +import fi.nls.oskari.log.LogFactory; +import fi.nls.oskari.log.Logger; + +public class V1_03_2__update_mapfull_projectiondefs_gk25_axisorder extends BaseJavaMigration { + + private static final Logger LOG = LogFactory.getLogger(V1_03_2__update_mapfull_projectiondefs_gk25_axisorder.class); + + public void migrate(Context context) throws Exception { + Connection c = context.getConnection(); + List allAppsetupIds = AppSetupHelper.getSetupsForType(c); + for (long appsetupId : allAppsetupIds) { + setGK25ProjDefAxisOrder(c, appsetupId); + } + } + + private void setGK25ProjDefAxisOrder(Connection c, long appsetupId) + throws SQLException, JSONException { + Bundle mapfull = AppSetupHelper.getAppBundle(c, appsetupId, "mapfull"); + if (mapfull == null) { + LOG.debug("Skipping appsetup " + appsetupId + + " no mapfull bundle"); + return; + } + + JSONObject config = mapfull.getConfigJSON(); + if (config == null) { + LOG.debug("Skipping appsetup " + appsetupId + + " mapfull config is null"); + return; + } + + JSONObject projectionDefs = config.optJSONObject("projectionDefs"); + if (projectionDefs == null) { + LOG.debug("Skipping appsetup " + appsetupId + + " mapfull config does not contain value for key 'projectionDefs'"); + return; + } + + String projDef = projectionDefs.optString("EPSG:3879"); + if (projDef == null) { + LOG.debug("Skipping appsetup " + appsetupId + + " mapfull config projectionDefs does not contain value for key 'EPSG:3879'"); + return; + } + + if (projDef.contains("+axis=neu")) { + LOG.debug("Skipping appsetup " + appsetupId + + " +axis=neu already present in EPSG:3897 projDef"); + return; + } + + projectionDefs.put("EPSG:3879", projDef + " +axis=neu"); + AppSetupHelper.updateAppBundle(c, appsetupId, mapfull); + LOG.info("Updated " + appsetupId + " mapfull config to: " + mapfull.getConfig()); + } + +} diff --git a/hsy-resources/src/main/java/flyway/pipe/V1_00_0__register_water_pipe_tool_bundle.java b/hsy-resources/src/main/java/flyway/pipe/V1_00_0__register_water_pipe_tool_bundle.java index d3837e6..f9e0660 100755 --- a/hsy-resources/src/main/java/flyway/pipe/V1_00_0__register_water_pipe_tool_bundle.java +++ b/hsy-resources/src/main/java/flyway/pipe/V1_00_0__register_water_pipe_tool_bundle.java @@ -1,24 +1,23 @@ package flyway.pipe; -import java.sql.Connection; +import java.sql.SQLException; -import org.flywaydb.core.api.migration.jdbc.JdbcMigration; +import org.flywaydb.core.api.migration.BaseJavaMigration; +import org.flywaydb.core.api.migration.Context; +import org.oskari.helpers.BundleHelper; -import fi.nls.oskari.db.BundleHelper; import fi.nls.oskari.domain.map.view.Bundle; -public class V1_00_0__register_water_pipe_tool_bundle implements JdbcMigration{ +public class V1_00_0__register_water_pipe_tool_bundle extends BaseJavaMigration { - private static final String NAMESPACE = "hsy"; private static final String WATER_PIPE_TOOL = "water-pipe-tool"; - public void migrate(Connection connection) { + public void migrate(Context context) throws SQLException { // BundleHelper checks if these bundles are already registered Bundle waterPipeTool = new Bundle(); waterPipeTool.setConfig("{}"); waterPipeTool.setState("{}"); waterPipeTool.setName(WATER_PIPE_TOOL); - waterPipeTool.setStartup(BundleHelper.getDefaultBundleStartup(NAMESPACE, WATER_PIPE_TOOL, "Waterpipe tool")); - BundleHelper.registerBundle(waterPipeTool); + BundleHelper.registerBundle(context.getConnection(), waterPipeTool); } } diff --git a/hsy-resources/src/main/java/helpers/LayerHelper.java b/hsy-resources/src/main/java/helpers/LayerHelper.java index 498b4d7..f067db0 100644 --- a/hsy-resources/src/main/java/helpers/LayerHelper.java +++ b/hsy-resources/src/main/java/helpers/LayerHelper.java @@ -1,13 +1,12 @@ package helpers; -import fi.mml.map.mapwindow.service.db.OskariMapLayerGroupService; import fi.nls.oskari.control.ActionException; import fi.nls.oskari.control.ActionParamsException; import fi.nls.oskari.map.view.util.ViewHelper; import fi.nls.oskari.service.ServiceException; -import fi.nls.oskari.service.capabilities.CapabilitiesCacheService; + +import org.oskari.capabilities.CapabilitiesService; import org.oskari.capabilities.CapabilitiesUpdateResult; -import org.oskari.capabilities.CapabilitiesUpdateService; import org.oskari.permissions.PermissionService; import fi.nls.oskari.domain.Role; import fi.nls.oskari.domain.map.DataProvider; @@ -17,7 +16,6 @@ import fi.nls.oskari.domain.map.view.View; import fi.nls.oskari.log.LogFactory; import fi.nls.oskari.log.Logger; -import org.oskari.permissions.model.OskariLayerResource; import fi.nls.oskari.map.layer.DataProviderService; import fi.nls.oskari.map.layer.OskariLayerService; import fi.nls.oskari.map.layer.OskariLayerServiceMybatisImpl; @@ -25,12 +23,15 @@ import fi.nls.oskari.map.layer.group.link.OskariLayerGroupLinkService; import fi.nls.oskari.map.view.ViewException; import fi.nls.oskari.map.view.ViewService; + +import org.oskari.permissions.model.OskariLayerResource; import org.oskari.permissions.model.Permission; import org.oskari.permissions.model.Resource; import fi.nls.oskari.user.MybatisRoleService; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import org.oskari.service.maplayer.OskariMapLayerGroupService; import org.oskari.service.util.ServiceFactory; import java.sql.Connection; @@ -74,9 +75,6 @@ public class LayerHelper { private static final String BACKGROUND_LAYER_SELECTION_PLUGIN = "Oskari.mapframework.bundle.mapmodule.plugin.BackgroundLayerSelectionPlugin"; private static OskariLayerService LAYER_SERVICE = ServiceFactory.getMapLayerService(); - private static CapabilitiesCacheService CAPABILITIES_CACHE_SERVICE = ServiceFactory.getCapabilitiesCacheService(); - private static CapabilitiesUpdateService CAPABILITIES_SERVICE = new CapabilitiesUpdateService( - LAYER_SERVICE, CAPABILITIES_CACHE_SERVICE); /** @@ -554,7 +552,7 @@ public static boolean updateCapabilities(String layerId) throws ActionParamsExce Set systemCRSs = getSystemCRSs(); List result = - CAPABILITIES_SERVICE.updateCapabilities(layers, systemCRSs); + CapabilitiesService.updateCapabilities(layers, systemCRSs); return layers.size() == result.size(); } diff --git a/hsy-resources/src/main/java/flyway/ammassuo/V1_00_0__add_ammassyo_view_and_ammassyo_role.java b/hsy-resources/src/main/resources/ammassuo/V1_00_0__add_ammassyo_view_and_ammassyo_role.java similarity index 100% rename from hsy-resources/src/main/java/flyway/ammassuo/V1_00_0__add_ammassyo_view_and_ammassyo_role.java rename to hsy-resources/src/main/resources/ammassuo/V1_00_0__add_ammassyo_view_and_ammassyo_role.java diff --git a/hsy-resources/src/main/java/flyway/ammassuo/V1_00_1__add_backgroundlayersselectionplugin_to_ammassuo_mapfull.java b/hsy-resources/src/main/resources/ammassuo/V1_00_1__add_backgroundlayersselectionplugin_to_ammassuo_mapfull.java similarity index 100% rename from hsy-resources/src/main/java/flyway/ammassuo/V1_00_1__add_backgroundlayersselectionplugin_to_ammassuo_mapfull.java rename to hsy-resources/src/main/resources/ammassuo/V1_00_1__add_backgroundlayersselectionplugin_to_ammassuo_mapfull.java diff --git a/hsy-resources/src/main/java/flyway/ammassuo/V1_00_2__add_selected_featuredata_to_ammassuo_view.java b/hsy-resources/src/main/resources/ammassuo/V1_00_2__add_selected_featuredata_to_ammassuo_view.java similarity index 100% rename from hsy-resources/src/main/java/flyway/ammassuo/V1_00_2__add_selected_featuredata_to_ammassuo_view.java rename to hsy-resources/src/main/resources/ammassuo/V1_00_2__add_selected_featuredata_to_ammassuo_view.java diff --git a/hsy-resources/src/main/java/flyway/ammassuo/V1_00_3__set_selected_layers_ammassuo_view.java b/hsy-resources/src/main/resources/ammassuo/V1_00_3__set_selected_layers_ammassuo_view.java similarity index 100% rename from hsy-resources/src/main/java/flyway/ammassuo/V1_00_3__set_selected_layers_ammassuo_view.java rename to hsy-resources/src/main/resources/ammassuo/V1_00_3__set_selected_layers_ammassuo_view.java diff --git a/hsy-resources/src/main/java/flyway/ammassuo/V1_00_4__add_more_ammassuo_roles.java b/hsy-resources/src/main/resources/ammassuo/V1_00_4__add_more_ammassuo_roles.java similarity index 100% rename from hsy-resources/src/main/java/flyway/ammassuo/V1_00_4__add_more_ammassuo_roles.java rename to hsy-resources/src/main/resources/ammassuo/V1_00_4__add_more_ammassuo_roles.java diff --git a/hsy-resources/src/main/java/flyway/ammassuo/V1_01_0__add_download_basket_to_ammassuo_view.java b/hsy-resources/src/main/resources/ammassuo/V1_01_0__add_download_basket_to_ammassuo_view.java similarity index 100% rename from hsy-resources/src/main/java/flyway/ammassuo/V1_01_0__add_download_basket_to_ammassuo_view.java rename to hsy-resources/src/main/resources/ammassuo/V1_01_0__add_download_basket_to_ammassuo_view.java diff --git a/hsy-resources/src/main/java/flyway/ammassuo/V1_01_1__add_link_panel_to_ammassuo_view.java b/hsy-resources/src/main/resources/ammassuo/V1_01_1__add_link_panel_to_ammassuo_view.java similarity index 100% rename from hsy-resources/src/main/java/flyway/ammassuo/V1_01_1__add_link_panel_to_ammassuo_view.java rename to hsy-resources/src/main/resources/ammassuo/V1_01_1__add_link_panel_to_ammassuo_view.java diff --git a/hsy-resources/src/main/java/flyway/ammassuo/V1_01_2__add_lang_override_to_ammassuo_view.java b/hsy-resources/src/main/resources/ammassuo/V1_01_2__add_lang_override_to_ammassuo_view.java similarity index 100% rename from hsy-resources/src/main/java/flyway/ammassuo/V1_01_2__add_lang_override_to_ammassuo_view.java rename to hsy-resources/src/main/resources/ammassuo/V1_01_2__add_lang_override_to_ammassuo_view.java diff --git a/hsy-resources/src/main/java/flyway/ammassuo/V1_01_3__add_drawtools_to_ammassuo_view.java b/hsy-resources/src/main/resources/ammassuo/V1_01_3__add_drawtools_to_ammassuo_view.java similarity index 100% rename from hsy-resources/src/main/java/flyway/ammassuo/V1_01_3__add_drawtools_to_ammassuo_view.java rename to hsy-resources/src/main/resources/ammassuo/V1_01_3__add_drawtools_to_ammassuo_view.java diff --git a/hsy-resources/src/main/java/flyway/ammassuo/V1_01_4__add_logoplugin_to_mapfull.java b/hsy-resources/src/main/resources/ammassuo/V1_01_4__add_logoplugin_to_mapfull.java similarity index 100% rename from hsy-resources/src/main/java/flyway/ammassuo/V1_01_4__add_logoplugin_to_mapfull.java rename to hsy-resources/src/main/resources/ammassuo/V1_01_4__add_logoplugin_to_mapfull.java diff --git a/hsy-resources/src/main/java/flyway/ammassuo/V1_02_0__add_sijoituspaikat_maplayers.java b/hsy-resources/src/main/resources/ammassuo/V1_02_0__add_sijoituspaikat_maplayers.java similarity index 100% rename from hsy-resources/src/main/java/flyway/ammassuo/V1_02_0__add_sijoituspaikat_maplayers.java rename to hsy-resources/src/main/resources/ammassuo/V1_02_0__add_sijoituspaikat_maplayers.java diff --git a/hsy-resources/src/main/java/flyway/ammassuo/V1_03_0__update_maplayer_styles.java b/hsy-resources/src/main/resources/ammassuo/V1_03_0__update_maplayer_styles.java similarity index 100% rename from hsy-resources/src/main/java/flyway/ammassuo/V1_03_0__update_maplayer_styles.java rename to hsy-resources/src/main/resources/ammassuo/V1_03_0__update_maplayer_styles.java diff --git a/hsy-resources/src/main/java/flyway/ammassuo/V1_03_1__update_logoplugin_config.java b/hsy-resources/src/main/resources/ammassuo/V1_03_1__update_logoplugin_config.java similarity index 100% rename from hsy-resources/src/main/java/flyway/ammassuo/V1_03_1__update_logoplugin_config.java rename to hsy-resources/src/main/resources/ammassuo/V1_03_1__update_logoplugin_config.java diff --git a/hsy-resources/src/main/resources/flyway/hsy/V1_03_1__update_null_and_non_empty_layer_options.sql b/hsy-resources/src/main/resources/flyway/hsy/V1_03_1__update_null_and_non_empty_layer_options.sql new file mode 100644 index 0000000..632da7c --- /dev/null +++ b/hsy-resources/src/main/resources/flyway/hsy/V1_03_1__update_null_and_non_empty_layer_options.sql @@ -0,0 +1,3 @@ +UPDATE oskari_maplayer +SET options = '{}' +WHERE options IS NULL OR options = ''; diff --git a/hsy-resources/src/main/java/flyway/seutumaisa/V1_03_0__add_seutumaisa_view.java b/hsy-resources/src/main/resources/seutumaisa/V1_03_0__add_seutumaisa_view.java similarity index 100% rename from hsy-resources/src/main/java/flyway/seutumaisa/V1_03_0__add_seutumaisa_view.java rename to hsy-resources/src/main/resources/seutumaisa/V1_03_0__add_seutumaisa_view.java diff --git a/hsy-resources/src/main/java/flyway/seutumaisa/V1_03_10__add_logoplugin_to_mapfull.java b/hsy-resources/src/main/resources/seutumaisa/V1_03_10__add_logoplugin_to_mapfull.java similarity index 100% rename from hsy-resources/src/main/java/flyway/seutumaisa/V1_03_10__add_logoplugin_to_mapfull.java rename to hsy-resources/src/main/resources/seutumaisa/V1_03_10__add_logoplugin_to_mapfull.java diff --git a/hsy-resources/src/main/java/flyway/seutumaisa/V1_03_11__add_selected_featuredata_to_view.java b/hsy-resources/src/main/resources/seutumaisa/V1_03_11__add_selected_featuredata_to_view.java similarity index 100% rename from hsy-resources/src/main/java/flyway/seutumaisa/V1_03_11__add_selected_featuredata_to_view.java rename to hsy-resources/src/main/resources/seutumaisa/V1_03_11__add_selected_featuredata_to_view.java diff --git a/hsy-resources/src/main/java/flyway/seutumaisa/V1_03_12__fix_printout_config.java b/hsy-resources/src/main/resources/seutumaisa/V1_03_12__fix_printout_config.java similarity index 100% rename from hsy-resources/src/main/java/flyway/seutumaisa/V1_03_12__fix_printout_config.java rename to hsy-resources/src/main/resources/seutumaisa/V1_03_12__fix_printout_config.java diff --git a/hsy-resources/src/main/java/flyway/seutumaisa/V1_03_13__register_timeseries_bundle.java b/hsy-resources/src/main/resources/seutumaisa/V1_03_13__register_timeseries_bundle.java similarity index 100% rename from hsy-resources/src/main/java/flyway/seutumaisa/V1_03_13__register_timeseries_bundle.java rename to hsy-resources/src/main/resources/seutumaisa/V1_03_13__register_timeseries_bundle.java diff --git a/hsy-resources/src/main/java/flyway/seutumaisa/V1_03_14__add_timeseries_to_views.java b/hsy-resources/src/main/resources/seutumaisa/V1_03_14__add_timeseries_to_views.java similarity index 100% rename from hsy-resources/src/main/java/flyway/seutumaisa/V1_03_14__add_timeseries_to_views.java rename to hsy-resources/src/main/resources/seutumaisa/V1_03_14__add_timeseries_to_views.java diff --git a/hsy-resources/src/main/java/flyway/seutumaisa/V1_03_15__register_seutumaisa_search_bundle_and_add_it_to_views.java b/hsy-resources/src/main/resources/seutumaisa/V1_03_15__register_seutumaisa_search_bundle_and_add_it_to_views.java similarity index 100% rename from hsy-resources/src/main/java/flyway/seutumaisa/V1_03_15__register_seutumaisa_search_bundle_and_add_it_to_views.java rename to hsy-resources/src/main/resources/seutumaisa/V1_03_15__register_seutumaisa_search_bundle_and_add_it_to_views.java diff --git a/hsy-resources/src/main/java/flyway/seutumaisa/V1_03_16__reorder_seutumaisa_view_bundle_startsequences.java b/hsy-resources/src/main/resources/seutumaisa/V1_03_16__reorder_seutumaisa_view_bundle_startsequences.java similarity index 100% rename from hsy-resources/src/main/java/flyway/seutumaisa/V1_03_16__reorder_seutumaisa_view_bundle_startsequences.java rename to hsy-resources/src/main/resources/seutumaisa/V1_03_16__reorder_seutumaisa_view_bundle_startsequences.java diff --git a/hsy-resources/src/main/java/flyway/seutumaisa/V1_03_17__fix_userguide_configuration.java b/hsy-resources/src/main/resources/seutumaisa/V1_03_17__fix_userguide_configuration.java similarity index 100% rename from hsy-resources/src/main/java/flyway/seutumaisa/V1_03_17__fix_userguide_configuration.java rename to hsy-resources/src/main/resources/seutumaisa/V1_03_17__fix_userguide_configuration.java diff --git a/hsy-resources/src/main/java/flyway/seutumaisa/V1_03_18__add_drawtools_to_views.java b/hsy-resources/src/main/resources/seutumaisa/V1_03_18__add_drawtools_to_views.java similarity index 100% rename from hsy-resources/src/main/java/flyway/seutumaisa/V1_03_18__add_drawtools_to_views.java rename to hsy-resources/src/main/resources/seutumaisa/V1_03_18__add_drawtools_to_views.java diff --git a/hsy-resources/src/main/java/flyway/seutumaisa/V1_03_1__add_backgroundlayersselectionplugin_to_seutumaisa_mapfull.java b/hsy-resources/src/main/resources/seutumaisa/V1_03_1__add_backgroundlayersselectionplugin_to_seutumaisa_mapfull.java similarity index 100% rename from hsy-resources/src/main/java/flyway/seutumaisa/V1_03_1__add_backgroundlayersselectionplugin_to_seutumaisa_mapfull.java rename to hsy-resources/src/main/resources/seutumaisa/V1_03_1__add_backgroundlayersselectionplugin_to_seutumaisa_mapfull.java diff --git a/hsy-resources/src/main/java/flyway/seutumaisa/V1_03_2__set_map_center_and_zoom_to_hsy_area.java b/hsy-resources/src/main/resources/seutumaisa/V1_03_2__set_map_center_and_zoom_to_hsy_area.java similarity index 100% rename from hsy-resources/src/main/java/flyway/seutumaisa/V1_03_2__set_map_center_and_zoom_to_hsy_area.java rename to hsy-resources/src/main/resources/seutumaisa/V1_03_2__set_map_center_and_zoom_to_hsy_area.java diff --git a/hsy-resources/src/main/java/flyway/seutumaisa/V1_03_3__register_map_location_bundle.java b/hsy-resources/src/main/resources/seutumaisa/V1_03_3__register_map_location_bundle.java similarity index 100% rename from hsy-resources/src/main/java/flyway/seutumaisa/V1_03_3__register_map_location_bundle.java rename to hsy-resources/src/main/resources/seutumaisa/V1_03_3__register_map_location_bundle.java diff --git a/hsy-resources/src/main/java/flyway/seutumaisa/V1_03_4__add_map_location_to_seutumaisa_view.java b/hsy-resources/src/main/resources/seutumaisa/V1_03_4__add_map_location_to_seutumaisa_view.java similarity index 100% rename from hsy-resources/src/main/java/flyway/seutumaisa/V1_03_4__add_map_location_to_seutumaisa_view.java rename to hsy-resources/src/main/resources/seutumaisa/V1_03_4__add_map_location_to_seutumaisa_view.java diff --git a/hsy-resources/src/main/java/flyway/seutumaisa/V1_03_5__add_backgroundlayerselectionplugin_to_mapfull.java b/hsy-resources/src/main/resources/seutumaisa/V1_03_5__add_backgroundlayerselectionplugin_to_mapfull.java similarity index 100% rename from hsy-resources/src/main/java/flyway/seutumaisa/V1_03_5__add_backgroundlayerselectionplugin_to_mapfull.java rename to hsy-resources/src/main/resources/seutumaisa/V1_03_5__add_backgroundlayerselectionplugin_to_mapfull.java diff --git a/hsy-resources/src/main/java/flyway/seutumaisa/V1_03_6__mappfull_add_selected_layers.java b/hsy-resources/src/main/resources/seutumaisa/V1_03_6__mappfull_add_selected_layers.java similarity index 100% rename from hsy-resources/src/main/java/flyway/seutumaisa/V1_03_6__mappfull_add_selected_layers.java rename to hsy-resources/src/main/resources/seutumaisa/V1_03_6__mappfull_add_selected_layers.java diff --git a/hsy-resources/src/main/java/flyway/seutumaisa/V1_03_7__update_userguide_configuration.java b/hsy-resources/src/main/resources/seutumaisa/V1_03_7__update_userguide_configuration.java similarity index 100% rename from hsy-resources/src/main/java/flyway/seutumaisa/V1_03_7__update_userguide_configuration.java rename to hsy-resources/src/main/resources/seutumaisa/V1_03_7__update_userguide_configuration.java diff --git a/hsy-resources/src/main/java/flyway/seutumaisa/V1_03_9__add_layers.java b/hsy-resources/src/main/resources/seutumaisa/V1_03_9__add_layers.java similarity index 100% rename from hsy-resources/src/main/java/flyway/seutumaisa/V1_03_9__add_layers.java rename to hsy-resources/src/main/resources/seutumaisa/V1_03_9__add_layers.java diff --git a/hsy-resources/src/main/java/flyway/seutumaisa/V1_04_00__register_seutumaisa_history_search_bundle_and_add_it_to_views.java b/hsy-resources/src/main/resources/seutumaisa/V1_04_00__register_seutumaisa_history_search_bundle_and_add_it_to_views.java similarity index 100% rename from hsy-resources/src/main/java/flyway/seutumaisa/V1_04_00__register_seutumaisa_history_search_bundle_and_add_it_to_views.java rename to hsy-resources/src/main/resources/seutumaisa/V1_04_00__register_seutumaisa_history_search_bundle_and_add_it_to_views.java diff --git a/hsy-resources/src/main/java/flyway/seutumaisa/V1_04_01__update_logoplugin_config.java b/hsy-resources/src/main/resources/seutumaisa/V1_04_01__update_logoplugin_config.java similarity index 100% rename from hsy-resources/src/main/java/flyway/seutumaisa/V1_04_01__update_logoplugin_config.java rename to hsy-resources/src/main/resources/seutumaisa/V1_04_01__update_logoplugin_config.java diff --git a/pom.xml b/pom.xml index c9b2087..725c9d6 100755 --- a/pom.xml +++ b/pom.xml @@ -5,12 +5,12 @@ 4.0.0 fi.hsy.oskari hsy-parent - 1.5.3 + 1.6.0 pom HSY applications - 1.56.0 + 2.9.0-1 UTF-8 1.8 @@ -39,8 +39,8 @@ - fi.nls.oskari - oskari-parent + org.oskari + oskari-server ${oskari.version} import pom diff --git a/server-extension/pom.xml b/server-extension/pom.xml index 03cff77..726ca68 100755 --- a/server-extension/pom.xml +++ b/server-extension/pom.xml @@ -3,7 +3,7 @@ fi.hsy.oskari hsy-parent - 1.5.3 + 1.6.0 server-extension @@ -11,8 +11,8 @@ - fi.nls.oskari.service - oskari-control-base + org.oskari + control-base diff --git a/server-extension/src/main/java/hsy/general/actions/SaveMultipleFeaturesHandler.java b/server-extension/src/main/java/hsy/general/actions/SaveMultipleFeaturesHandler.java index 81a84e7..5037638 100755 --- a/server-extension/src/main/java/hsy/general/actions/SaveMultipleFeaturesHandler.java +++ b/server-extension/src/main/java/hsy/general/actions/SaveMultipleFeaturesHandler.java @@ -59,7 +59,6 @@ public void handlePost(ActionParameters params) throws ActionException { requestData.append(""); String responseString = postPayload(layer.getUsername(), layer.getPassword(), requestData.toString(), getURLForNamespace(layer.getName(),layer.getUrl())); - flushLayerTilesCache(layer.getId()); if (responseString.indexOf("Exception") > -1) { ResponseHelper.writeResponse(params, "Exception"); diff --git a/server-extension/src/main/java/hsy/pipe/GetPipesWithParamsHandler.java b/server-extension/src/main/java/hsy/pipe/GetPipesWithParamsHandler.java new file mode 100755 index 0000000..3c4cfb1 --- /dev/null +++ b/server-extension/src/main/java/hsy/pipe/GetPipesWithParamsHandler.java @@ -0,0 +1,69 @@ +package hsy.pipe; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.net.URLConnection; + +import fi.nls.oskari.annotation.OskariActionRoute; +import fi.nls.oskari.control.ActionException; +import fi.nls.oskari.control.ActionHandler; +import fi.nls.oskari.control.ActionParameters; +import fi.nls.oskari.util.IOHelper; +import fi.nls.oskari.util.ResponseHelper; + +@OskariActionRoute("GetPipesWithParams") +public class GetPipesWithParamsHandler extends ActionHandler { + + private static final int MAX_FEATURE_COUNT = 50; + + private static final String PARAM_LAYERS = "layers"; + private static final String PARAM_X = "x"; + private static final String PARAM_Y = "y"; + private static final String PARAM_BBOX = "bbox"; + private static final String PARAM_WIDTH = "width"; + private static final String PARAM_HEIGHT = "height"; + private static final String PARAM_SRS = "srs"; + private static final String PARAM_URL = "url"; + + @Override + public void handleAction(final ActionParameters params) throws ActionException { + String wmsUrl = getGetFeatureInfoUrlForProxy(params.getHttpParam(PARAM_URL).toString(), params.getHttpParam(PARAM_SRS).toString(), + params.getHttpParam(PARAM_BBOX).toString(), params.getHttpParam(PARAM_WIDTH).toString(), params.getHttpParam(PARAM_HEIGHT).toString(), + params.getHttpParam(PARAM_X).toString(), params.getHttpParam(PARAM_Y).toString(), params.getHttpParam(PARAM_LAYERS).toString()); + try { + URL wms = new URL(wmsUrl); + URLConnection wmsConn = wms.openConnection(); + wmsConn.setRequestProperty("Accept-Charset", "UTF-8"); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (InputStream in = wmsConn.getInputStream()) { + IOHelper.copy(in, baos); + } + ResponseHelper.writeResponse(params, 200, ResponseHelper.CONTENT_TYPE_JSON_UTF8, baos); + } catch (IOException e) { + throw new ActionException("Could not populate Response", e); + } + } + + private static String getGetFeatureInfoUrlForProxy(String url, String projection, String bbox, String width, String height, String x, String y, String layerName) { + String wmsUrl = url+"?SERVICE=WMS" + +"&VERSION=1.1.1&" + +"REQUEST=GetFeatureInfo" + +"&SRS="+projection + +"&BBOX="+bbox + +"&WIDTH="+width + +"&HEIGHT="+height + +"&QUERY_LAYERS="+layerName + +"&X="+Math.round(Float.parseFloat(x)) + +"&Y="+Math.round(Float.parseFloat(y)) + +"&LAYERS="+layerName + +"&FEATURE_COUNT="+MAX_FEATURE_COUNT + +"&INFO_FORMAT=application/json" + +"&EXCEPTIONS=application/vnd.ogc.se_xml" + +"&BUFFER=10"; + return wmsUrl; + } + +} \ No newline at end of file diff --git a/server-extension/src/main/java/hsy/pipe/SearchTagPipeHandler.java b/server-extension/src/main/java/hsy/pipe/SearchTagPipeHandler.java new file mode 100755 index 0000000..1178bfd --- /dev/null +++ b/server-extension/src/main/java/hsy/pipe/SearchTagPipeHandler.java @@ -0,0 +1,146 @@ +package hsy.pipe; + +import java.util.List; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import fi.nls.oskari.annotation.OskariActionRoute; +import fi.nls.oskari.control.ActionException; +import fi.nls.oskari.control.ActionParameters; +import fi.nls.oskari.control.ActionParamsException; +import fi.nls.oskari.control.RestActionHandler; +import fi.nls.oskari.log.LogFactory; +import fi.nls.oskari.log.Logger; +import fi.nls.oskari.service.OskariComponentManager; +import fi.nls.oskari.util.ResponseHelper; + +@OskariActionRoute("SearchTagPipe") +public class SearchTagPipeHandler extends RestActionHandler { + + private static final Logger log = LogFactory.getLogger(SearchTagPipeHandler.class); + + private final TagPipeConfigurationService tagpipeService = OskariComponentManager.getComponentOfType(TagPipeConfigurationService.class); + + @Override + public void handleGet(ActionParameters params) throws ActionException { + try { + ResponseHelper.writeResponse(params, getTagPipes()); + } catch (Exception ex){ + log.error(org.apache.commons.lang.exception.ExceptionUtils.getStackTrace(ex)); + throw new ActionParamsException("Couldn't get tagpipes"); + } + } + + @Override + public void handleDelete(ActionParameters params) throws ActionException { + // Only admin user + params.requireAdminUser(); + + int tagPipeId = params.getRequiredParamInt(TagPipeConfiguration.PARAM_TAG_ID); + + try { + if(tagPipeId>0) { + ResponseHelper.writeResponse(params, delete(tagPipeId)); + } else { + throw new ActionParamsException("Couldn't delete tagpipe"); + } + } catch (Exception ex){ + log.error(org.apache.commons.lang.exception.ExceptionUtils.getStackTrace(ex)); + throw new ActionParamsException("Couldn't delete tagpipe"); + } + } + + @Override + public void handlePost(ActionParameters params) throws ActionException { + // Only admin user + params.requireAdminUser(); + + try { + TagPipeConfiguration conf = new TagPipeConfiguration(params); + // tag_type required on POST / INSERT -- can't be changed with PUT / UPDATE + conf.setTagType(params.getRequiredParam(TagPipeConfiguration.PARAM_TAG_TYPE)); + JSONObject response = insert(conf); + ResponseHelper.writeResponse(params, response); + } catch (Exception ex){ + log.error(org.apache.commons.lang.exception.ExceptionUtils.getStackTrace(ex)); + throw new ActionParamsException("Couldn't insert tagpipe"); + } + } + + @Override + public void handlePut(ActionParameters params) throws ActionException { + // Only admin user + params.requireAdminUser(); + + try { + TagPipeConfiguration conf = new TagPipeConfiguration(params); + // tag_id (server created) is required on PUT / UPDATE -- can't be set on POST / INSERT + conf.setTagId(params.getRequiredParamInt(TagPipeConfiguration.PARAM_TAG_ID)); + JSONObject response = update(conf); + ResponseHelper.writeResponse(params, response); + } catch (Exception ex){ + log.error(org.apache.commons.lang.exception.ExceptionUtils.getStackTrace(ex)); + throw new ActionParamsException("Couldn't update tagpipe"); + } + } + + private JSONObject getTagPipes() throws JSONException { + JSONObject job = new JSONObject(); + List tagpipes = tagpipeService.findTagPipes(); + JSONArray tagpipesJSONArray = new JSONArray(); + + for(int i=0;i 0); + } catch (Exception e) { + log.error(org.apache.commons.lang.exception.ExceptionUtils.getStackTrace(e)); + try{ + job.put("success", false); + } catch (Exception ex) {} + } + return job; + } + + private JSONObject update(final TagPipeConfiguration tagpipe) { + JSONObject job = new JSONObject(); + try{ + tagpipeService.update(tagpipe); + job.put("success", true); + } catch (Exception e) { + log.error(org.apache.commons.lang.exception.ExceptionUtils.getStackTrace(e)); + try{ + job.put("success", false); + } catch (Exception ex) {} + } + return job; + } + +} diff --git a/server-extension/src/main/java/hsy/pipe/domain/TagPipeConfiguration.java b/server-extension/src/main/java/hsy/pipe/TagPipeConfiguration.java similarity index 75% rename from server-extension/src/main/java/hsy/pipe/domain/TagPipeConfiguration.java rename to server-extension/src/main/java/hsy/pipe/TagPipeConfiguration.java index 18b0076..a3d4e1a 100755 --- a/server-extension/src/main/java/hsy/pipe/domain/TagPipeConfiguration.java +++ b/server-extension/src/main/java/hsy/pipe/TagPipeConfiguration.java @@ -1,15 +1,13 @@ -package hsy.pipe.domain; +package hsy.pipe; import org.json.JSONObject; -import fi.nls.oskari.log.LogFactory; -import fi.nls.oskari.log.Logger; +import fi.nls.oskari.control.ActionParameters; +import fi.nls.oskari.util.ConversionHelper; import fi.nls.oskari.util.JSONHelper; public class TagPipeConfiguration { - private static final Logger log = LogFactory.getLogger(TagPipeConfiguration.class); - protected final static String PARAM_TAG_ID = "tag_id"; protected final static String PARAM_TAG_TYPE = "tag_type"; protected final static String PARAM_TAG_ADDRESS = "tag_address"; @@ -49,7 +47,31 @@ public class TagPipeConfiguration { private String tagBlock; private String tagPlot; - public JSONObject getAsJSONObject() { + /** + * Constructor from action parameters + * NOTE: Doesn't set tagType or tagId! + * This is because insert/update logic might differ + */ + public TagPipeConfiguration(ActionParameters params) throws Exception { + setTagAddress(ConversionHelper.getString(params.getRequiredParam(PARAM_TAG_ADDRESS),"")); + setTagPipeSize(ConversionHelper.getDouble(params.getHttpParam(PARAM_TAG_PIPE_SIZE), 0)); + setTagLowPressureLevel(ConversionHelper.getDouble(params.getHttpParam(PARAM_TAG_LOW_PRESSURE_LEVEL), 0)); + setTagMaxPressureLevel(ConversionHelper.getDouble(params.getHttpParam(PARAM_TAG_MAX_PRESSURE_LEVEL), 0)); + setTagMaxWaterTake(ConversionHelper.getDouble(params.getHttpParam(PARAM_TAG_MAX_WATER_TAKE), 0)); + setTagMinPressureLevel(ConversionHelper.getDouble(params.getHttpParam(PARAM_TAG_MIN_PRESSURE_LEVEL), 0)); + setTagBottomHeight(ConversionHelper.getDouble(params.getHttpParam(PARAM_TAG_BOTTOM_HEIGHT), 0)); + setTagLowTagHeight(ConversionHelper.getDouble(params.getHttpParam(PARAM_TAG_LOW_TAG_HEIGHT), 0)); + setTagBarrageHeight(ConversionHelper.getDouble(params.getHttpParam(PARAM_TAG_BARRAGE_HEIGHT), 0)); + setTagGroundHeight(ConversionHelper.getDouble(params.getHttpParam(PARAM_TAG_GROUND_HEIGHT), 0)); + setTagOtherIssue(ConversionHelper.getString(params.getHttpParam(PARAM_TAG_OTHER_ISSUE),"")); + setTagGeoJson(new JSONObject(ConversionHelper.getString(params.getHttpParam(PARAM_TAG_GEOJSON),""))); + setTagMunicipality(ConversionHelper.getString(params.getRequiredParam(PARAM_TAG_MUNICIPALITY),"")); + setTagNeighborhood(ConversionHelper.getString(params.getRequiredParam(PARAM_TAG_NEIGHBORHOOD),"")); + setTagBlock(ConversionHelper.getString(params.getRequiredParam(PARAM_TAG_BLOCK),"")); + setTagPlot(ConversionHelper.getString(params.getRequiredParam(PARAM_TAG_PLOT),"")); + } + + public JSONObject getAsJSONObject() { final JSONObject root = new JSONObject(); JSONHelper.putValue(root, PARAM_TAG_ID, this.getTagId()); JSONHelper.putValue(root, PARAM_TAG_TYPE, this.getTagType()); diff --git a/server-extension/src/main/java/hsy/pipe/TagPipeConfigurationMapper.java b/server-extension/src/main/java/hsy/pipe/TagPipeConfigurationMapper.java new file mode 100644 index 0000000..53b99d9 --- /dev/null +++ b/server-extension/src/main/java/hsy/pipe/TagPipeConfigurationMapper.java @@ -0,0 +1,126 @@ +package hsy.pipe; + +import java.util.List; + +import org.apache.ibatis.annotations.Delete; +import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.Options; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Result; +import org.apache.ibatis.annotations.Results; +import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.Update; +import org.apache.ibatis.type.JdbcType; +import org.json.JSONObject; + +import fi.nls.oskari.mybatis.JSONObjectMybatisTypeHandler; + +public interface TagPipeConfigurationMapper { + + @Results(id = "TagPipeResult", value = { + @Result(property="tagId", column="tag_id"), + @Result(property="tagType", column="tag_type"), + @Result(property="tagAddress", column="tag_address"), + @Result(property="tagPipeSize", column="tag_pipe_size"), + @Result(property="tagLowPressureLevel", column="tag_low_pressure_level"), + @Result(property="tagMaxPressureLevel", column="tag_max_pressure_level"), + @Result(property="tagMaxWaterTake", column="tag_max_water_take"), + @Result(property="tagMinPressureLevel", column="tag_min_pressure_level"), + @Result(property="tagBottomHeight", column="tag_bottom_height"), + @Result(property="tagLowTagHeight", column="tag_low_tag_height"), + @Result(property="tagBarrageHeight", column="tag_barrage_height"), + @Result(property="tagGroundHeight", column="tag_ground_height"), + @Result(property="tagOtherIssue", column="tag_other_issue"), + @Result(property="tagGeoJson", column="tag_geojson", jdbcType = JdbcType.VARCHAR, javaType = JSONObject.class, typeHandler = JSONObjectMybatisTypeHandler.class), + @Result(property="tagMunicipality", column="tag_municipality"), + @Result(property="tagNeighborhood", column="tag_neighborhood"), + @Result(property="tagBlock", column="tag_block"), + @Result(property="tagPlot", column="tag_plot"), + }) + @Select("SELECT " + + "tag_id," + + "tag_type," + + "tag_address," + + "tag_pipe_size," + + "tag_low_pressure_level," + + "tag_max_pressure_level," + + "tag_max_water_take," + + "tag_min_pressure_level," + + "tag_bottom_height," + + "tag_low_tag_height," + + "tag_barrage_height," + + "tag_ground_height," + + "tag_other_issue," + + "tag_geojson," + + "tag_municipality," + + "tag_neighborhood," + + "tag_block," + + "tag_plot" + + " FROM oskari_tagpipes") + List findAll(); + + @Insert("INSERT INTO oskari_tagpipes (" + + "tag_type," + + "tag_address," + + "tag_pipe_size," + + "tag_low_pressure_level," + + "tag_max_pressure_level," + + "tag_max_water_take," + + "tag_min_pressure_level," + + "tag_bottom_height," + + "tag_low_tag_height," + + "tag_barrage_height," + + "tag_ground_height," + + "tag_other_issue," + + "tag_geojson," + + "tag_municipality," + + "tag_neighborhood," + + "tag_block," + + "tag_plot" + + ") VALUES (" + + "${tagType}," + + "${tagAddress}," + + "${tagPipeSize}," + + "${tagLowPressureLevel}," + + "${tagMaxPressureLevel}," + + "${tagMaxWaterTake}," + + "${tagMinPressureLevel}," + + "${tagBottomHeight}," + + "${tagLowTagHeight}," + + "${tagBarrageHeight}," + + "${tagGroundHeight}," + + "${tagOtherIssue}," + + "${tagGeoJson}," + + "${tagMunicipality}," + + "${tagNeighborhood}," + + "${tagBlock}," + + "${tagPlot}" + + ")") + @Options(useGeneratedKeys=true, keyColumn="tag_id", keyProperty="tagId") + int insert(TagPipeConfiguration tagpipe); + + @Update("UPDATE oskari_tagpipes SET " + + "tag_type = ${tagType}," + + "tag_address = ${tagAddress}," + + "tag_pipe_size = ${tagPipeSize}," + + "tag_low_pressure_level = ${tagLowPressureLevel}," + + "tag_max_pressure_level = ${tagMaxPressureLevel}," + + "tag_max_water_take = ${tagMaxWaterTake}," + + "tag_min_pressure_level = ${tagMinPressureLevel}," + + "tag_bottom_height = ${tagBottomHeight}," + + "tag_low_tag_height = ${tagLowTagHeight}," + + "tag_barrage_height = ${tagBarrageHeight}," + + "tag_ground_height = ${tagGroundHeight}," + + "tag_other_issue = ${tagOtherIssue}," + + "tag_geojson = ${tagGeoJson}," + + "tag_municipality = ${tagMunicipality}," + + "tag_neighborhood = ${tagNeighborhood}," + + "tag_block = ${tagBlock}," + + "tag_plot = ${tagPlot}" + + " WHERE tag_id = ${tagId}") + void update(TagPipeConfiguration tagpipe); + + @Delete("DELETE FROM oskari_tagpipes WHERE tag_id=#{id}") + void delete(@Param("id") int tagPipeId); + +} diff --git a/server-extension/src/main/java/hsy/pipe/TagPipeConfigurationService.java b/server-extension/src/main/java/hsy/pipe/TagPipeConfigurationService.java new file mode 100755 index 0000000..e618c1a --- /dev/null +++ b/server-extension/src/main/java/hsy/pipe/TagPipeConfigurationService.java @@ -0,0 +1,14 @@ +package hsy.pipe; + +import java.util.List; + +import fi.nls.oskari.service.OskariComponent; + +public abstract class TagPipeConfigurationService extends OskariComponent { + + public abstract List findTagPipes(); + public abstract void delete(final int tagPipeId); + public abstract int insert(final TagPipeConfiguration tagpipe); + public abstract void update(final TagPipeConfiguration tagpipe); + +} diff --git a/server-extension/src/main/java/hsy/pipe/TagPipeConfigurationServiceMyBatisImpl.java b/server-extension/src/main/java/hsy/pipe/TagPipeConfigurationServiceMyBatisImpl.java new file mode 100644 index 0000000..292f85f --- /dev/null +++ b/server-extension/src/main/java/hsy/pipe/TagPipeConfigurationServiceMyBatisImpl.java @@ -0,0 +1,64 @@ +package hsy.pipe; + +import java.util.List; + +import javax.sql.DataSource; + +import org.apache.ibatis.session.SqlSession; +import org.apache.ibatis.session.SqlSessionFactory; + +import fi.nls.oskari.annotation.Oskari; +import fi.nls.oskari.db.DatasourceHelper; +import fi.nls.oskari.log.LogFactory; +import fi.nls.oskari.log.Logger; +import fi.nls.oskari.mybatis.MyBatisHelper; + +@Oskari +public class TagPipeConfigurationServiceMyBatisImpl extends TagPipeConfigurationService { + + private static final Logger LOG = LogFactory.getLogger(TagPipeConfigurationServiceMyBatisImpl.class); + private static final Class MAPPER = TagPipeConfigurationMapper.class; + + private final SqlSessionFactory factory; + + public TagPipeConfigurationServiceMyBatisImpl() { + this(DatasourceHelper.getInstance().getDataSource()); + } + + public TagPipeConfigurationServiceMyBatisImpl(DataSource ds) { + super(); + if (ds == null) { + LOG.warn("DataSource was null, all future calls will throw NPEs!"); + factory = null; + } else { + factory = MyBatisHelper.initMyBatis(ds, MAPPER); + } + + } + + public List findTagPipes() { + try (SqlSession session = factory.openSession()) { + return session.getMapper(MAPPER).findAll(); + } + } + + public void delete(final int tagPipeId) { + try (SqlSession session = factory.openSession()) { + session.getMapper(MAPPER).delete(tagPipeId); + } + } + + public int insert(final TagPipeConfiguration tagpipe) { + try (SqlSession session = factory.openSession()) { + session.getMapper(MAPPER).insert(tagpipe); + return tagpipe.getTagId(); + } + } + + public void update(final TagPipeConfiguration tagpipe) { + try (SqlSession session = factory.openSession()) { + session.getMapper(MAPPER).update(tagpipe); + } + } + +} diff --git a/server-extension/src/main/java/hsy/pipe/actions/GetPipesWithParams.java b/server-extension/src/main/java/hsy/pipe/actions/GetPipesWithParams.java deleted file mode 100755 index bd0c9af..0000000 --- a/server-extension/src/main/java/hsy/pipe/actions/GetPipesWithParams.java +++ /dev/null @@ -1,74 +0,0 @@ -package hsy.pipe.actions; - -import hsy.pipe.helpers.Helpers; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLConnection; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import fi.nls.oskari.annotation.OskariActionRoute; -import fi.nls.oskari.control.ActionException; -import fi.nls.oskari.control.ActionHandler; -import fi.nls.oskari.control.ActionParameters; -import fi.nls.oskari.log.LogFactory; -import fi.nls.oskari.log.Logger; -import fi.nls.oskari.util.ResponseHelper; - -@OskariActionRoute("GetPipesWithParams") -public class GetPipesWithParams extends ActionHandler { - - private final Logger LOGGER = LogFactory.getLogger(GetPipesWithParams.class); - - private static final String PARAM_LAYERS = "layers"; - private static final String PARAM_X = "x"; - private static final String PARAM_Y = "y"; - private static final String PARAM_BBOX = "bbox"; - private static final String PARAM_WIDTH = "width"; - private static final String PARAM_HEIGHT = "height"; - private static final String PARAM_SRS = "srs"; - private static final String PARAM_URL = "url"; - - @Override - public void handleAction(final ActionParameters params) throws ActionException { - - final JSONArray data = new JSONArray(); - - String wmsUrl = Helpers.getGetFeatureInfoUrlForProxy(params.getHttpParam(PARAM_URL).toString(), params.getHttpParam(PARAM_SRS).toString(), - params.getHttpParam(PARAM_BBOX).toString(), params.getHttpParam(PARAM_WIDTH).toString(), params.getHttpParam(PARAM_HEIGHT).toString(), - params.getHttpParam(PARAM_X).toString(), params.getHttpParam(PARAM_Y).toString(), params.getHttpParam(PARAM_LAYERS).toString()); - - URL wms; - try { - wms = new URL(wmsUrl); - URLConnection wmsConn = wms.openConnection(); - wmsConn.setRequestProperty("Accept-Charset", "UTF-8"); - BufferedReader in = new BufferedReader( new InputStreamReader( wmsConn.getInputStream(), "UTF-8" ) ); - - String inputLine; - String html = ""; - - while ((inputLine = in.readLine()) != null) { - html += inputLine; - } - in.close(); - - JSONObject jsoni = new JSONObject(html); - - ResponseHelper.writeResponse(params, jsoni); - - } catch (JSONException e) { - throw new ActionException("Could not populate Response JSON: " + LOGGER.getAsString(data), e); - } catch (MalformedURLException e) { - throw new ActionException("Could not populate Response JSON: " + LOGGER.getAsString(data), e); - } catch (IOException e) { - throw new ActionException("Could not populate Response JSON: " + LOGGER.getAsString(data), e); - } - } -} \ No newline at end of file diff --git a/server-extension/src/main/java/hsy/pipe/actions/TagPipeActionHandler.java b/server-extension/src/main/java/hsy/pipe/actions/TagPipeActionHandler.java deleted file mode 100755 index ca93fd9..0000000 --- a/server-extension/src/main/java/hsy/pipe/actions/TagPipeActionHandler.java +++ /dev/null @@ -1,140 +0,0 @@ -package hsy.pipe.actions; - -import org.json.JSONObject; - -import hsy.pipe.domain.TagPipeConfiguration; -import hsy.pipe.helpers.TagPipeHelper; -import fi.nls.oskari.annotation.OskariActionRoute; -import fi.nls.oskari.control.ActionException; -import fi.nls.oskari.control.ActionParameters; -import fi.nls.oskari.control.ActionParamsException; -import fi.nls.oskari.control.RestActionHandler; -import fi.nls.oskari.log.LogFactory; -import fi.nls.oskari.log.Logger; -import fi.nls.oskari.util.ConversionHelper; -import fi.nls.oskari.util.ResponseHelper; - -@OskariActionRoute("SearchTagPipe") -public class TagPipeActionHandler extends RestActionHandler { - - private static final Logger log = LogFactory.getLogger(TagPipeActionHandler.class); - - protected final static String PARAM_TAG_ID = "tag_id"; - protected final static String PARAM_TAG_TYPE = "tag_type"; - protected final static String PARAM_TAG_ADDRESS = "tag_address"; - protected final static String PARAM_TAG_PIPE_SIZE = "tag_pipe_size"; - protected final static String PARAM_TAG_LOW_PRESSURE_LEVEL = "tag_low_pressure_level"; - protected final static String PARAM_TAG_MAX_PRESSURE_LEVEL = "tag_max_pressure_level"; - protected final static String PARAM_TAG_MAX_WATER_TAKE = "tag_max_water_take"; - protected final static String PARAM_TAG_MIN_PRESSURE_LEVEL = "tag_min_pressure_level"; - protected final static String PARAM_TAG_BOTTOM_HEIGHT = "tag_bottom_height"; - protected final static String PARAM_TAG_LOW_TAG_HEIGHT = "tag_low_tag_height"; - protected final static String PARAM_TAG_BARRAGE_HEIGHT = "tag_barrage_height"; - protected final static String PARAM_TAG_GROUND_HEIGHT = "tag_ground_height"; - protected final static String PARAM_TAG_OTHER_ISSUE = "tag_other_issue"; - protected final static String PARAM_TAG_GEOJSON = "tag_geojson"; - //Separate Finnish kiinteistötunnus (real estate ID) into 4 different fields - protected final static String PARAM_TAG_MUNICIPALITY = "tag_municipality"; - protected final static String PARAM_TAG_NEIGHBORHOOD = "tag_neighborhood"; - protected final static String PARAM_TAG_BLOCK = "tag_block"; - protected final static String PARAM_TAG_PLOT = "tag_plot"; - - @Override - public void handleGet(ActionParameters params) throws ActionException { - try { - ResponseHelper.writeResponse(params, TagPipeHelper.getTagPipes(params.getUser(), params.getLocale().getLanguage())); - } catch (Exception ex){ - log.error(org.apache.commons.lang.exception.ExceptionUtils.getStackTrace(ex)); - throw new ActionParamsException("Couldn't get tagpipes"); - } - } - - @Override - public void handleDelete(ActionParameters params) throws ActionException { - // Only admin user - params.requireAdminUser(); - - int tagPipeId = ConversionHelper.getInt(params.getRequiredParam(PARAM_TAG_ID), -1); - - try { - if(tagPipeId>0) { - ResponseHelper.writeResponse(params, TagPipeHelper.delete(tagPipeId)); - } else { - throw new ActionParamsException("Couldn't delete tagpipe"); - } - } catch (Exception ex){ - log.error(org.apache.commons.lang.exception.ExceptionUtils.getStackTrace(ex)); - throw new ActionParamsException("Couldn't delete tagpipe"); - } - } - - @Override - public void handlePost(ActionParameters params) throws ActionException { - - // Only admin user - params.requireAdminUser(); - - try { - - TagPipeConfiguration conf = new TagPipeConfiguration(); - - conf.setTagType(ConversionHelper.getString(params.getRequiredParam(PARAM_TAG_TYPE),"")); - conf.setTagAddress(ConversionHelper.getString(params.getRequiredParam(PARAM_TAG_ADDRESS),"")); - conf.setTagPipeSize(ConversionHelper.getDouble(params.getHttpParam(PARAM_TAG_PIPE_SIZE), 0)); - conf.setTagLowPressureLevel(ConversionHelper.getDouble(params.getHttpParam(PARAM_TAG_LOW_PRESSURE_LEVEL), 0)); - conf.setTagMaxPressureLevel(ConversionHelper.getDouble(params.getHttpParam(PARAM_TAG_MAX_PRESSURE_LEVEL), 0)); - conf.setTagMaxWaterTake(ConversionHelper.getDouble(params.getHttpParam(PARAM_TAG_MAX_WATER_TAKE), 0)); - conf.setTagMinPressureLevel(ConversionHelper.getDouble(params.getHttpParam(PARAM_TAG_MIN_PRESSURE_LEVEL), 0)); - conf.setTagBottomHeight(ConversionHelper.getDouble(params.getHttpParam(PARAM_TAG_BOTTOM_HEIGHT), 0)); - conf.setTagLowTagHeight(ConversionHelper.getDouble(params.getHttpParam(PARAM_TAG_LOW_TAG_HEIGHT), 0)); - conf.setTagBarrageHeight(ConversionHelper.getDouble(params.getHttpParam(PARAM_TAG_BARRAGE_HEIGHT), 0)); - conf.setTagGroundHeight(ConversionHelper.getDouble(params.getHttpParam(PARAM_TAG_GROUND_HEIGHT), 0)); - conf.setTagOtherIssue(ConversionHelper.getString(params.getHttpParam(PARAM_TAG_OTHER_ISSUE),"")); - conf.setTagGeoJson(new JSONObject(ConversionHelper.getString(params.getHttpParam(PARAM_TAG_GEOJSON),""))); - conf.setTagMunicipality(ConversionHelper.getString(params.getRequiredParam(PARAM_TAG_MUNICIPALITY),"")); - conf.setTagNeighborhood(ConversionHelper.getString(params.getRequiredParam(PARAM_TAG_NEIGHBORHOOD),"")); - conf.setTagBlock(ConversionHelper.getString(params.getRequiredParam(PARAM_TAG_BLOCK),"")); - conf.setTagPlot(ConversionHelper.getString(params.getRequiredParam(PARAM_TAG_PLOT),"")); - - ResponseHelper.writeResponse(params, TagPipeHelper.insert(conf)); - } catch (Exception ex){ - log.error(org.apache.commons.lang.exception.ExceptionUtils.getStackTrace(ex)); - throw new ActionParamsException("Couldn't insert tagpipe"); - } - } - - @Override - public void handlePut(ActionParameters params) throws ActionException { - // Only admin user - params.requireAdminUser(); - - try { - TagPipeConfiguration conf = new TagPipeConfiguration(); - //conf.setTagType(ConversionHelper.getString(params.getRequiredParam(PARAM_TAG_TYPE),"")); - conf.setTagAddress(ConversionHelper.getString(params.getRequiredParam(PARAM_TAG_ADDRESS),"")); - conf.setTagPipeSize(ConversionHelper.getDouble(params.getHttpParam(PARAM_TAG_PIPE_SIZE), 0)); - conf.setTagLowPressureLevel(ConversionHelper.getDouble(params.getHttpParam(PARAM_TAG_LOW_PRESSURE_LEVEL), 0)); - conf.setTagMaxPressureLevel(ConversionHelper.getDouble(params.getHttpParam(PARAM_TAG_MAX_PRESSURE_LEVEL), 0)); - conf.setTagMaxWaterTake(ConversionHelper.getDouble(params.getHttpParam(PARAM_TAG_MAX_WATER_TAKE), 0)); - conf.setTagMinPressureLevel(ConversionHelper.getDouble(params.getHttpParam(PARAM_TAG_MIN_PRESSURE_LEVEL), 0)); - conf.setTagBottomHeight(ConversionHelper.getDouble(params.getHttpParam(PARAM_TAG_BOTTOM_HEIGHT), 0)); - conf.setTagLowTagHeight(ConversionHelper.getDouble(params.getHttpParam(PARAM_TAG_LOW_TAG_HEIGHT), 0)); - conf.setTagBarrageHeight(ConversionHelper.getDouble(params.getHttpParam(PARAM_TAG_BARRAGE_HEIGHT), 0)); - conf.setTagGroundHeight(ConversionHelper.getDouble(params.getHttpParam(PARAM_TAG_GROUND_HEIGHT), 0)); - conf.setTagOtherIssue(ConversionHelper.getString(params.getHttpParam(PARAM_TAG_OTHER_ISSUE),"")); - conf.setTagGeoJson(new JSONObject(ConversionHelper.getString(params.getHttpParam(PARAM_TAG_GEOJSON),""))); - conf.setTagId(ConversionHelper.getInt(params.getRequiredParam(PARAM_TAG_ID), -1)); - conf.setTagMunicipality(ConversionHelper.getString(params.getRequiredParam(PARAM_TAG_MUNICIPALITY),"")); - conf.setTagNeighborhood(ConversionHelper.getString(params.getRequiredParam(PARAM_TAG_NEIGHBORHOOD),"")); - conf.setTagBlock(ConversionHelper.getString(params.getRequiredParam(PARAM_TAG_BLOCK),"")); - conf.setTagPlot(ConversionHelper.getString(params.getRequiredParam(PARAM_TAG_PLOT),"")); - - ResponseHelper.writeResponse(params, TagPipeHelper.update(conf)); - } catch (Exception ex){ - log.error(org.apache.commons.lang.exception.ExceptionUtils.getStackTrace(ex)); - throw new ActionParamsException("Couldn't update tagpipe"); - } - - } - -} diff --git a/server-extension/src/main/java/hsy/pipe/domain/utils/JSONArrayTypeHandler.java b/server-extension/src/main/java/hsy/pipe/domain/utils/JSONArrayTypeHandler.java deleted file mode 100755 index 57c7f7f..0000000 --- a/server-extension/src/main/java/hsy/pipe/domain/utils/JSONArrayTypeHandler.java +++ /dev/null @@ -1,45 +0,0 @@ -package hsy.pipe.domain.utils; - -import java.sql.SQLException; -import java.sql.Types; - -import org.json.JSONArray; -import org.json.JSONException; - -import com.ibatis.sqlmap.client.extensions.ParameterSetter; -import com.ibatis.sqlmap.client.extensions.ResultGetter; -import com.ibatis.sqlmap.client.extensions.TypeHandlerCallback; - -import fi.nls.oskari.log.LogFactory; -import fi.nls.oskari.log.Logger; - -public class JSONArrayTypeHandler implements TypeHandlerCallback { - private final static Logger log = LogFactory.getLogger(JSONArrayTypeHandler.class); - - public void setParameter(ParameterSetter parameterSetter, Object parameter) throws SQLException { - if (parameter == null) { - parameterSetter.setNull(Types.VARCHAR); - } else { - parameterSetter.setString(((JSONArray)parameter).toString()); - } - } - - public Object getResult(ResultGetter resultGetter) throws SQLException { - String value = resultGetter.getString(); - if (resultGetter.wasNull()) { - return null; - } - return valueOf(value); - } - - public Object valueOf(String s) { - JSONArray jsonArray = null; - try { - jsonArray = new JSONArray(s); - } catch (JSONException e) { - log.error("Couldn't parse DB string to JSONArray:", s, e); - return new JSONArray(); - } - return jsonArray; - } -} diff --git a/server-extension/src/main/java/hsy/pipe/helpers/Helpers.java b/server-extension/src/main/java/hsy/pipe/helpers/Helpers.java deleted file mode 100755 index 795ca8a..0000000 --- a/server-extension/src/main/java/hsy/pipe/helpers/Helpers.java +++ /dev/null @@ -1,51 +0,0 @@ -package hsy.pipe.helpers; - -import fi.nls.oskari.log.LogFactory; -import fi.nls.oskari.log.Logger; - -public class Helpers { - - private static final Logger log = LogFactory.getLogger(Helpers.class); - private static final int MAX_FEATURE_COUNT = 50; - /** - * Get GetFeatureInfoUrl for proxy - * @param url a url - * @param projection a projection - * @param bbox a bbox - * @param width a width - * @param height a heigth - * @param x a x - * @param y a y - * @param layerName a layer name - * @return getFeatureInfoUrl - */ - public static String getGetFeatureInfoUrlForProxy(String url, String projection, String bbox, String width, String height, String x, String y, String layerName) { - String wmsUrl = url+"?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetFeatureInfo&SRS="+projection - +"&BBOX="+bbox - +"&WIDTH="+width - +"&HEIGHT="+height - +"&QUERY_LAYERS="+layerName - +"&X="+Math.round(Float.parseFloat(x)) - +"&Y="+Math.round(Float.parseFloat(y)) - +"&LAYERS="+layerName - +"&FEATURE_COUNT="+MAX_FEATURE_COUNT - +"&INFO_FORMAT=application/json" - +"&EXCEPTIONS=application/vnd.ogc.se_xml" - +"&BUFFER=10"; - return wmsUrl; - } - - /** - * Get layer name without namespace. - * @param layerName layer name - * @return layer name without namespace - */ - public static String getLayerNameWithoutNameSpace(String layerName) { - String[] temp = layerName.split(":"); - String layerNameWithoutNameSpace = layerName; - if(temp.length==2){ - layerNameWithoutNameSpace = temp[1]; - } - return layerNameWithoutNameSpace; - } -} diff --git a/server-extension/src/main/java/hsy/pipe/helpers/TagPipeHelper.java b/server-extension/src/main/java/hsy/pipe/helpers/TagPipeHelper.java deleted file mode 100755 index 9947f78..0000000 --- a/server-extension/src/main/java/hsy/pipe/helpers/TagPipeHelper.java +++ /dev/null @@ -1,113 +0,0 @@ -package hsy.pipe.helpers; - -import hsy.pipe.tagpipe.TagPipeConfigurationService; -import hsy.pipe.tagpipe.TagPipeConfigurationServiceIbatisImpl; - -import java.util.ArrayList; -import java.util.List; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import hsy.pipe.domain.TagPipeConfiguration; -import fi.nls.oskari.domain.User; -import fi.nls.oskari.log.LogFactory; -import fi.nls.oskari.log.Logger; - -public class TagPipeHelper { - - private static final Logger log = LogFactory.getLogger(TagPipeHelper.class); - private static TagPipeConfigurationService tagpipeService = new TagPipeConfigurationServiceIbatisImpl(); - - /** - * Get tagpipes - * @param string - * @param user - * @return - */ - public static JSONObject getTagPipes(User user, String lang) throws JSONException{ - JSONObject job = new JSONObject(); - List tagpipes = tagpipeService.findTagPipes(); - JSONArray tagpipesJSONArray = new JSONArray(); - - for(int i=0;i getTagPipeById(JSONArray tagPipeIds) throws JSONException{ - - List tagpipes = new ArrayList(); - for (int i = 0; i < tagPipeIds.length(); i++) { - tagpipes.add(tagpipeService.findTagPipeById(tagPipeIds.getInt(i))); - } - - return tagpipes; - } - - /** - * Delete selected tagpipe - * @param tagpipeId - */ - public static JSONObject delete(final int tagPipeId) { - JSONObject job = new JSONObject(); - try{ - tagpipeService.delete(tagPipeId); - job.put("success", true); - } catch (Exception e) { - try{ - job.put("success", false); - } catch (Exception ex) {} - } - return job; - } - - /** - * Add tagpipe - * @param tagpipe - */ - public static JSONObject insert(final TagPipeConfiguration tagpipe) { - JSONObject job = new JSONObject(); - try{ - int newId = tagpipeService.insert(tagpipe); - job.put("success", newId > 0); - } catch (Exception e) { - log.error(org.apache.commons.lang.exception.ExceptionUtils.getStackTrace(e)); - try{ - job.put("success", false); - } catch (Exception ex) {} - } - return job; - } - - /** - * Update tagpipe - * @param tagpipe - */ - public static JSONObject update(final TagPipeConfiguration tagpipe) { - JSONObject job = new JSONObject(); - try{ - tagpipeService.update(tagpipe); - job.put("success", true); - } catch (Exception e) { - log.error(org.apache.commons.lang.exception.ExceptionUtils.getStackTrace(e)); - try{ - job.put("success", false); - } catch (Exception ex) {} - } - return job; - } -} diff --git a/server-extension/src/main/java/hsy/pipe/tagpipe/TagPipeConfigurationService.java b/server-extension/src/main/java/hsy/pipe/tagpipe/TagPipeConfigurationService.java deleted file mode 100755 index 3069a86..0000000 --- a/server-extension/src/main/java/hsy/pipe/tagpipe/TagPipeConfigurationService.java +++ /dev/null @@ -1,14 +0,0 @@ -package hsy.pipe.tagpipe; - -import java.util.List; - -import hsy.pipe.domain.TagPipeConfiguration; -import fi.nls.oskari.service.db.BaseService; - -public interface TagPipeConfigurationService extends BaseService{ - public List findTagPipes(); - public TagPipeConfiguration findTagPipeById(final int tagPipeId); - public void delete(final int tagPipeId); - public int insert(final TagPipeConfiguration tagpipe); - public void update(final TagPipeConfiguration tagpipe); -} diff --git a/server-extension/src/main/java/hsy/pipe/tagpipe/TagPipeConfigurationServiceIbatisImpl.java b/server-extension/src/main/java/hsy/pipe/tagpipe/TagPipeConfigurationServiceIbatisImpl.java deleted file mode 100755 index cb7f442..0000000 --- a/server-extension/src/main/java/hsy/pipe/tagpipe/TagPipeConfigurationServiceIbatisImpl.java +++ /dev/null @@ -1,122 +0,0 @@ -package hsy.pipe.tagpipe; - -import java.io.Reader; -import java.sql.SQLException; -import java.util.List; - -import com.ibatis.common.resources.Resources; -import com.ibatis.sqlmap.client.SqlMapClient; -import com.ibatis.sqlmap.client.SqlMapClientBuilder; -import com.ibatis.sqlmap.client.SqlMapSession; - -import fi.nls.oskari.log.LogFactory; -import fi.nls.oskari.log.Logger; -import fi.nls.oskari.service.db.BaseIbatisService; -import hsy.pipe.domain.TagPipeConfiguration; - -public class TagPipeConfigurationServiceIbatisImpl extends BaseIbatisService implements TagPipeConfigurationService{ - private final static Logger log = LogFactory.getLogger(TagPipeConfigurationServiceIbatisImpl.class); - private SqlMapClient client = null; - - @Override - protected String getNameSpace() { - return "TagPipeConfiguration"; - } - - public List findTagPipes() { - List tagpipes = queryForList(getNameSpace() + ".findTagPipes"); - return tagpipes; - } - - public TagPipeConfiguration findTagPipeById(final int tagPipeId) { - long tagpipe_id = Long.valueOf(tagPipeId); - TagPipeConfiguration tagpipe = queryForObject(getNameSpace() + ".findTagPipeById", tagpipe_id); - return tagpipe; - } - - - /* - * The purpose of this method is to allow many SqlMapConfig.xml files in a - * single portlet - */ - protected String getSqlMapLocation() { - return "META-INF/SqlMapConfig-tagpipe-configuration.xml"; - } - - /** - * Returns SQLmap - * - * @return - */ - @Override - protected SqlMapClient getSqlMapClient() { - if (client != null) { - return client; - } - - Reader reader = null; - try { - String sqlMapLocation = getSqlMapLocation(); - reader = Resources.getResourceAsReader(sqlMapLocation); - client = SqlMapClientBuilder.buildSqlMapClient(reader); - return client; - } catch (Exception e) { - log.error(org.apache.commons.lang.exception.ExceptionUtils.getStackTrace(e)); - throw new RuntimeException("Failed to retrieve SQL client", e); - } finally { - if (reader != null) { - try { - reader.close(); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - } - } - - public void delete(final int tagPipeId) { - long tagpipe_id = Long.valueOf(tagPipeId); - final SqlMapSession session = openSession(); - try { - session.startTransaction(); - // remove tagpipe - session.delete(getNameSpace() + ".delete", tagpipe_id); - session.commitTransaction(); - } catch (Exception e) { - log.error(org.apache.commons.lang.exception.ExceptionUtils.getStackTrace(e)); - new RuntimeException("Error deleting tagpipe with id:" + Long.toString(tagpipe_id), e); - } finally { - endSession(session); - } - }; - - public synchronized int insert(final TagPipeConfiguration tagpipe) { - SqlMapClient client = null; - try { - client = getSqlMapClient(); - client.startTransaction(); - client.insert(getNameSpace() + ".insert", tagpipe); - Integer id = (Integer) client.queryForObject(getNameSpace() + ".maxId"); - client.commitTransaction(); - return id; - } catch (Exception e) { - log.error(org.apache.commons.lang.exception.ExceptionUtils.getStackTrace(e)); - throw new RuntimeException("Failed to insert tagpipe", e); - } finally { - if (client != null) { - try { - client.endTransaction(); - } catch (SQLException ignored) { } - } - } - } - - public void update(final TagPipeConfiguration tagpipe) { - try { - getSqlMapClient().update(getNameSpace() + ".update", tagpipe); - } catch (Exception e) { - log.error(org.apache.commons.lang.exception.ExceptionUtils.getStackTrace(e)); - throw new RuntimeException("Failed to update tagpipe", e); - } - }; -} diff --git a/server-extension/src/main/java/hsy/seutumaisa/actions/GetSeutumaisaHistorySearchFieldsHandler.java b/server-extension/src/main/java/hsy/seutumaisa/actions/GetSeutumaisaHistorySearchFieldsHandler.java index a598447..ec54be4 100644 --- a/server-extension/src/main/java/hsy/seutumaisa/actions/GetSeutumaisaHistorySearchFieldsHandler.java +++ b/server-extension/src/main/java/hsy/seutumaisa/actions/GetSeutumaisaHistorySearchFieldsHandler.java @@ -18,8 +18,6 @@ public class GetSeutumaisaHistorySearchFieldsHandler extends SeutumaisaRestActio @Override public void handleGet(ActionParameters params) throws ActionException { - requireSeutumaisaConfigured(); - try { JSONArray fields = SeutumaisaHistoryDBHelper.getHistorySearchFields(); ResponseHelper.writeResponse(params, fields); diff --git a/server-extension/src/main/java/hsy/seutumaisa/actions/GetSeutumaisaSearchFieldsHandler.java b/server-extension/src/main/java/hsy/seutumaisa/actions/GetSeutumaisaSearchFieldsHandler.java index b888199..6b3480a 100755 --- a/server-extension/src/main/java/hsy/seutumaisa/actions/GetSeutumaisaSearchFieldsHandler.java +++ b/server-extension/src/main/java/hsy/seutumaisa/actions/GetSeutumaisaSearchFieldsHandler.java @@ -17,8 +17,6 @@ public class GetSeutumaisaSearchFieldsHandler extends SeutumaisaRestActionHandle @Override public void handleGet(ActionParameters params) throws ActionException { - requireSeutumaisaConfigured(); - try { JSONArray fields = SeutumaisaDBHelper.getSearchFields(); ResponseHelper.writeResponse(params, fields); diff --git a/server-extension/src/main/java/hsy/seutumaisa/actions/SeutumaisaHistorySearch.java b/server-extension/src/main/java/hsy/seutumaisa/actions/SeutumaisaHistorySearch.java index b3f3ead..ff1b5c7 100644 --- a/server-extension/src/main/java/hsy/seutumaisa/actions/SeutumaisaHistorySearch.java +++ b/server-extension/src/main/java/hsy/seutumaisa/actions/SeutumaisaHistorySearch.java @@ -17,12 +17,7 @@ public class SeutumaisaHistorySearch extends SeutumaisaRestActionHandler { @Override public void handlePost(ActionParameters params) throws ActionException { - requireSeutumaisaConfigured(); - try { - System.out.println("=======================PARAMS============================="); - System.out.println(params); - System.out.println("===================================================="); JSONObject result = SeutumaisaHistoryDBHelper.search(params); ResponseHelper.writeResponse(params, result); } catch (JSONException e) { diff --git a/server-extension/src/main/java/hsy/seutumaisa/actions/SeutumaisaRestActionHandler.java b/server-extension/src/main/java/hsy/seutumaisa/actions/SeutumaisaRestActionHandler.java index 3801a7b..46fd6b7 100755 --- a/server-extension/src/main/java/hsy/seutumaisa/actions/SeutumaisaRestActionHandler.java +++ b/server-extension/src/main/java/hsy/seutumaisa/actions/SeutumaisaRestActionHandler.java @@ -2,17 +2,16 @@ import fi.nls.oskari.control.ActionDeniedException; import fi.nls.oskari.control.ActionException; +import fi.nls.oskari.control.ActionParameters; import fi.nls.oskari.control.RestActionHandler; import fi.nls.oskari.util.PropertyUtil; public class SeutumaisaRestActionHandler extends RestActionHandler { - private final static String PROPERTY_MODULES = "db.additional.modules"; + private final static String PROPERTY_ENABLED = "seutumassa.enabled"; - public void requireSeutumaisaConfigured() throws ActionException { - String modules = PropertyUtil.get(PROPERTY_MODULES, ""); - if(!modules.contains("seutumaisa")) { + public void preProcess(ActionParameters params) throws ActionException { + if (!PropertyUtil.getOptional(PROPERTY_ENABLED, false)) { throw new ActionDeniedException("Not seutumaisa configured"); } - } } diff --git a/server-extension/src/main/java/hsy/seutumaisa/actions/SeutumaisaSearch.java b/server-extension/src/main/java/hsy/seutumaisa/actions/SeutumaisaSearch.java index 1374981..dc723e0 100755 --- a/server-extension/src/main/java/hsy/seutumaisa/actions/SeutumaisaSearch.java +++ b/server-extension/src/main/java/hsy/seutumaisa/actions/SeutumaisaSearch.java @@ -16,8 +16,6 @@ public class SeutumaisaSearch extends SeutumaisaRestActionHandler { @Override public void handlePost(ActionParameters params) throws ActionException { - requireSeutumaisaConfigured(); - try { JSONObject result = SeutumaisaDBHelper.search(params); ResponseHelper.writeResponse(params, result); diff --git a/server-extension/src/main/resources/META-INF/SqlMapConfig-tagpipe-configuration.xml b/server-extension/src/main/resources/META-INF/SqlMapConfig-tagpipe-configuration.xml deleted file mode 100755 index 4e84a81..0000000 --- a/server-extension/src/main/resources/META-INF/SqlMapConfig-tagpipe-configuration.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/server-extension/src/main/resources/META-INF/TagPipeConfiguration.xml b/server-extension/src/main/resources/META-INF/TagPipeConfiguration.xml deleted file mode 100755 index 3e2bf12..0000000 --- a/server-extension/src/main/resources/META-INF/TagPipeConfiguration.xml +++ /dev/null @@ -1,142 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SELECT - * - FROM oskari_tagpipes - ORDER BY tag_id ASC; - - - - SELECT - * - FROM oskari_tagpipes - WHERE tag_id=#tagpipe_id#; - - - - DELETE FROM oskari_tagpipes WHERE tag_id=#tagpipe_id#; - - - - INSERT INTO oskari_tagpipes ( - tag_type, - tag_address, - tag_pipe_size, - tag_low_pressure_level, - tag_max_pressure_level, - tag_max_water_take, - tag_min_pressure_level, - tag_bottom_height, - tag_low_tag_height, - tag_barrage_height, - tag_ground_height, - tag_other_issue, - tag_geojson, - tag_municipality, - tag_neighborhood, - tag_block, - tag_plot) - values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) - - - - UPDATE oskari_tagpipes - SET - tag_address=?, - tag_pipe_size=?, - tag_low_pressure_level=?, - tag_max_pressure_level=?, - tag_max_water_take=?, - tag_min_pressure_level=?, - tag_bottom_height=?, - tag_low_tag_height=?, - tag_barrage_height=?, - tag_ground_height=?, - tag_other_issue=?, - tag_geojson=?, - tag_municipality=?, - tag_neighborhood=?, - tag_block=?, - tag_plot=? - WHERE tag_id = ? - - \ No newline at end of file diff --git a/webapp-map/pom.xml b/webapp-map/pom.xml index acc1d36..50e2fa2 100755 --- a/webapp-map/pom.xml +++ b/webapp-map/pom.xml @@ -5,7 +5,7 @@ hsy-parent fi.hsy.oskari - 1.5.3 + 1.6.0 4.0.0 @@ -41,14 +41,14 @@ - fi.nls.oskari.service - oskari-control-example + org.oskari + control-example - - fi.nls.oskari.service - oskari-control-admin - + + org.oskari + control-admin + org.oskari @@ -56,12 +56,12 @@ - fi.nls.oskari.service - oskari-control-myplaces + org.oskari + control-myplaces - fi.nls.oskari + org.oskari servlet-map @@ -72,22 +72,24 @@ - fi.nls.oskari.extras - oskari-search-nls - 2.1 - - - - fi.nls.oskari + org.oskari service-logging - fi.nls.oskari + org.oskari download-basket + + + fi.nls.oskari.extras + oskari-search-nls + 3.7.0 + + + org.slf4j slf4j-api @@ -122,4 +124,4 @@ ${appName} - \ No newline at end of file +