private static void migrateDB() { if (PropertyUtil.getOptional("db.flyway", true) == false) { log.warn( "Skipping flyway migration! Remove 'db.flyway' property or set it to 'true' to enable migration"); return; } // upgrade database structure with http://flywaydb.org/ log.info("Oskari-map checking DB status"); try { FlywaydbMigrator.migrate(DS_HELPER.getDataSource()); log.info("Oskari core DB migrated successfully"); } catch (Exception e) { log.error(e, "DB migration for Oskari core failed!"); } final String[] additionalPools = PropertyUtil.getCommaSeparatedList(KEY_MODULE_LIST); for (String module : additionalPools) { final String poolName = DS_HELPER.getOskariDataSourceName(module); try { FlywaydbMigrator.migrate(DS_HELPER.getDataSource(poolName), module); log.info(module + " DB migrated successfully"); } catch (Exception e) { log.error(e, "DB migration for module " + module + " failed!", e); e.printStackTrace(); } } }
@Override public void handleGet(ActionParameters params) throws ActionException { log.info("handleGet"); final JSONObject response; long id = getId(params); try { if (id > -1) { log.info("handleGet: has id"); User user = userService.getUser(id); response = user2Json(user); } else { log.info("handleGet: no id"); List<User> users = userService.getUsers(); log.info("found: " + users.size() + "users"); response = new JSONObject(); JSONArray arr = new JSONArray(); response.put("users", arr); List<User> newUsers = userService.getUsersWithRoles(); for (User user : newUsers) { arr.put(user2Json(user)); } } } catch (ServiceException se) { throw new ActionException(se.getMessage(), se); } catch (JSONException je) { throw new ActionException(je.getMessage(), je); } log.info(response); ResponseHelper.writeResponse(params, response); }
/** * Creates SLD style * * @param layer * @param styleName * @return style */ private Style getSLDStyle(WFSLayerStore layer, String styleName) { Style style = null; log.debug("Trying to get style with name:", styleName); if (layer.getStyles().containsKey(styleName)) { style = createSLDStyle(layer.getStyles().get(styleName).getSLDStyle()); } else if (STYLE_HIGHLIGHT.equals(styleName)) { style = createSLDStyle(layer.getSelectionSLDStyle()); } else if (layer.getStyles().containsKey(STYLE_DEFAULT)) { style = createSLDStyle(layer.getStyles().get(STYLE_DEFAULT).getSLDStyle()); } // if styles couldn't be parsed, use defaults if (style == null) { log.info("Layer style not customized or parsing failed. Using defaults."); if (STYLE_HIGHLIGHT.equals(styleName)) { // style = createDefaultHighlightSLDStyle(layer.getGMLGeometryProperty()); // TODO: check if we really always want to use without namespace style = createDefaultHighlightSLDStyle(layer.getGMLGeometryPropertyNoNamespace()); } else { style = createSLDStyle( WFSImage.class.getResourceAsStream(DEFAULT_SLD)); // getClass() (non-static) } } if (style == null) { // something is seriously wrong, even default styles can't be parsed log.error("Failed to get SLD style (even default failed)!!"); } return style; }
public void notifyCompleted(final boolean success) { log.info("Completed - layer:", layerId, "type:", type, "success:", success); Map<String, Object> output = createCommonResponse("completed"); output.put("success", success); output.put("type", type.toString()); this.service.addResults(session.getClient(), ResultProcessor.CHANNEL_STATUS, output); }
/** Main initialization method */ public static void initializeOskariContext() { log.info("- checking default DataSource"); final Context ctx = DS_HELPER.getContext(); if (!DS_HELPER.checkDataSource(ctx)) { log.error("Couldn't initialize default DataSource"); } // loop "db.additional.pools" to see if we need any more pools configured log.info("- checking additional DataSources"); final String[] additionalPools = PropertyUtil.getCommaSeparatedList(KEY_MODULE_LIST); for (String pool : additionalPools) { if (!DS_HELPER.checkDataSource(ctx, pool)) { log.error("Couldn't initialize DataSource for module:", pool); } } }
/** * Parses SLD style from a String (XML) * * @param xml * @return sld */ private Style createSLDStyle(String xml) { if (xml == null) { log.info("Trying to create style from <null> String!"); return null; } final Style style = createSLDStyle(new ByteArrayInputStream(xml.getBytes())); if (style == null) { log.warn("Couldn't create style from XML:", xml); } return style; }
private String transformResponse(final String xslt, final String response) { if (xslt == null || "".equals(xslt)) { // if not found, return as is return response; } ByteArrayInputStream respInStream = null; ByteArrayInputStream xsltInStream = null; Writer outWriter = null; try { final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); factory.setNamespaceAware(true); final DocumentBuilder builder = factory.newDocumentBuilder(); respInStream = new ByteArrayInputStream(response.getBytes("UTF-8")); final Document document = builder.parse(respInStream); xsltInStream = new ByteArrayInputStream(xslt.getBytes()); final StreamSource stylesource = new StreamSource(xsltInStream); final String transformedResponse = getFormatedJSONString(document, stylesource); if (transformedResponse == null || transformedResponse.isEmpty()) { log.info("got empty result from transform with:", xslt, " - Response:", response); return response; } return transformedResponse; } catch (Exception e) { log.error(e, "Error transforming GFI response: ", response, "- with XSLT:", xslt); } finally { if (respInStream != null) { try { respInStream.close(); } catch (Exception ignored) { } } if (xsltInStream != null) { try { xsltInStream.close(); } catch (Exception ignored) { } } if (outWriter != null) { try { outWriter.close(); } catch (Exception ignored) { } } } // Sanitize response return Jsoup.clean(response, Whitelist.relaxed()); }
public static void teardown() { if (schedulerService != null) { try { schedulerService.shutdownScheduler(); } catch (final SchedulerException e) { log.error(e, "Failed to shut down the Oskari scheduler"); } } DS_HELPER.teardown(); JedisManager.shutdown(); log.info("Context destroy"); }
private Bundle addBundle(final View view, final String bundleid) { Bundle bundle = view.getBundleByName(bundleid); if (bundle == null) { log.info("Bundle with id:", bundleid, "not found in currentView - adding"); if (!bundleCache.containsKey(bundleid)) { log.warn("Trying to add bundle that isn't loaded:", bundleid, "- Skipping it!"); return null; } bundle = bundleCache.get(bundleid).clone(); view.addBundle(bundle); } return bundle; }
public void migrate(Connection connection) { List<OskariLayer> layers = LAYER_SERVICE.findAll(); LOG.info("Start populating capabilities for layers - count:", layers.size()); Set<String> keys = new HashSet<>(); int progress = 0; for (OskariLayer layer : layers) { try { final String layerKey = (layer.getSimplifiedUrl(true) + "----" + layer.getType()).toLowerCase(); if (keys.contains(layerKey)) { progress++; continue; } keys.add(layerKey); CAPABILITIES_SERVICE.getCapabilities(layer); progress++; LOG.info("Capabilities populated:", progress, "/", layers.size()); } catch (ServiceException e) { LOG.error(e, "Error getting capabilities for layer", layer); } } }
private void setupBundle(final View view, final JSONObject publisherData, final String bundleid) { final JSONObject bundleData = publisherData.optJSONObject(bundleid); if (bundleData != null && bundleData.names().length() > 0) { log.info("config found for", bundleid); final Bundle bundle = addBundle(view, bundleid); mergeBundleConfiguration(bundle, bundleData, null); } else { log.warn("config not found for", bundleid, "- removing bundle."); // We have to remove the bundle... // TODO: check if we really want to remove the bundle from view since it could be template // view??? view.removeBundle(bundleid); } }
public void init() { // setup service if it hasn't been initialized if (viewService == null) { setViewService(new ViewServiceIbatisImpl()); } if (myPlaceService == null) { setMyPlacesService(new MyPlacesServiceIbatisImpl()); } if (permissionsService == null) { setPermissionsService(new PermissionsServiceIbatisImpl()); } if (bundleService == null) { setBundleService(new BundleServiceIbatisImpl()); } final String publishTemplateIdProperty = PropertyUtil.getOptional("view.template.publish"); PUBLISHED_VIEW_TEMPLATE_ID = ConversionHelper.getLong(publishTemplateIdProperty, PUBLISHED_VIEW_TEMPLATE_ID); if (publishTemplateIdProperty == null) { log.warn("Publish template id not configured (property: view.template.publish)!"); } else { log.info("Using publish template id: ", PUBLISHED_VIEW_TEMPLATE_ID); } // setup roles authorized to enable drawing tools on published map drawToolsEnabledRoles = PropertyUtil.getCommaSeparatedList(PROPERTY_DRAW_TOOLS_ENABLED); for (String bundleid : CACHED_BUNDLE_IDS) { final Bundle bundle = bundleService.getBundleTemplateByName(bundleid); if (bundle == null) { log.warn("Couldn't get", bundleid, "bundle template from DB!"); continue; } bundleCache.put(bundleid, bundle); } }
public static void init() { try { if (!propsLoaded) { loadProperties(); } // catch all so we don't get mysterious listener start errors log.info(STR_LOG_LINE); log.info("Oskari-map context is being initialized"); initializeOskariContext(); // create initial content if properties tells us to if ("true".equals(PropertyUtil.getOptional("oskari.init.db"))) { log.info("- checking for initial db content"); DBHandler.createContentIfNotCreated(DS_HELPER.getDataSource()); } migrateDB(); // init jedis log.info("Initializing Redis connections"); JedisManager.connect( ConversionHelper.getInt(PropertyUtil.get(KEY_REDIS_POOL_SIZE), 30), PropertyUtil.get(KEY_REDIS_HOSTNAME, "localhost"), ConversionHelper.getInt(PropertyUtil.get(KEY_REDIS_PORT), 6379)); log.info("Oskari-map context initialization done"); log.info(STR_LOG_LINE); } catch (Exception ex) { log.error(ex, "!!! Error initializing context for Oskari !!!"); } schedulerService = new SchedulerService(); try { schedulerService.initializeScheduler(); } catch (final SchedulerException e) { log.error(e, "Failed to start up the Oskari scheduler"); } }
public void notifyStart() { log.info("On start - layer:", layerId, "type:", type); this.service.addResults( session.getClient(), ResultProcessor.CHANNEL_STATUS, createCommonResponse("started")); }