Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add myplaces GFI-formatter definition #602

Merged
merged 4 commits into from Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -149,25 +149,94 @@ public static JSONObject addMyplacesAttributes(JSONObject attributes) {

JSONObject filter = new JSONObject();
JSONHelper.putValue(data, "filter", filter);
Set<String> fields = ConversionHelper.asSet("name", "place_desc", "link", "image_url");
Set<String> fields = ConversionHelper.asSet("name", "place_desc", "image_url", "link");
JSONHelper.putValue(filter, "default", new JSONArray(fields));
JSONHelper.putValue(filter, "fi", new JSONArray(fields));

JSONObject locale = new JSONObject();
JSONHelper.putValue(data, "locale", locale);
JSONObject en = new JSONObject();
JSONHelper.putValue(locale, "en", en);
JSONHelper.putValue(en, "name", "name");
JSONHelper.putValue(en, "place_desc", "description");
JSONHelper.putValue(en, "link", "link");
JSONHelper.putValue(en, "image_url", "image");
JSONHelper.putValue(en, "name", "Name");
JSONHelper.putValue(en, "place_desc", "Description");
JSONHelper.putValue(en, "link", "URL");
JSONHelper.putValue(en, "image_url", "Image URL");
JSONHelper.putValue(en, "attention_text", "Text on map");

JSONObject fi = new JSONObject();
JSONHelper.putValue(locale, "fi", fi);
JSONHelper.putValue(fi, "name", "nimi");
JSONHelper.putValue(fi, "place_desc", "kuvaus");
JSONHelper.putValue(fi, "link", "linkki");
JSONHelper.putValue(fi, "image_url", "kuva-linkki");
JSONHelper.putValue(fi, "name", "Nimi");
JSONHelper.putValue(fi, "place_desc", "Kuvaus");
JSONHelper.putValue(fi, "link", "Linkki");
JSONHelper.putValue(fi, "image_url", "Kuvalinkki");
JSONHelper.putValue(fi, "attention_text", "Teksti kartalla");

JSONObject sv = new JSONObject();
JSONHelper.putValue(locale, "sv", sv);
JSONHelper.putValue(sv, "name", "Namn");
JSONHelper.putValue(sv, "place_desc", "Beskrivelse");
JSONHelper.putValue(sv, "link", "Webbaddress");
JSONHelper.putValue(sv, "image_url", "Bild-URL");
JSONHelper.putValue(sv, "attention_text", "Placera text på kartan");

/*
Format is:
"name": {
"type": "h3",
"noLabel": true
},
"place_desc": {
"type": "p",
"noLabel": true,
"skipEmpty": true
},
"attention_text": {
"type": "hidden"
},
"image_url": {
"type": "image",
"noLabel": true,
"params": {
"link": true
},
"skipEmpty": true
},
"link": {
"type": "link",
"skipEmpty": true
}
*/
JSONObject format = new JSONObject();
JSONHelper.putValue(data, "format", format);

JSONObject name = new JSONObject();
JSONHelper.putValue(format, "name", name);
JSONHelper.putValue(name, "type", "h3");
JSONHelper.putValue(name, "noLabel", true);

JSONObject place_desc = new JSONObject();
JSONHelper.putValue(format, "place_desc", place_desc);
JSONHelper.putValue(place_desc, "type", "p");
JSONHelper.putValue(place_desc, "noLabel", true);
JSONHelper.putValue(place_desc, "skipEmpty", true);

JSONObject attention_text = new JSONObject();
JSONHelper.putValue(format, "attention_text", attention_text);
JSONHelper.putValue(attention_text, "type", "hidden");

JSONObject image_url = new JSONObject();
JSONHelper.putValue(format, "image_url", image_url);
JSONHelper.putValue(image_url, "type", "image");
JSONHelper.putValue(image_url, "noLabel", true);
JSONHelper.putValue(image_url, "skipEmpty", true);
JSONObject image_params = new JSONObject();
JSONHelper.putValue(image_params, "link", true);
JSONHelper.putValue(image_url, "params", image_params);

JSONObject link = new JSONObject();
JSONHelper.putValue(format, "link", link);
JSONHelper.putValue(link, "type", "link");
JSONHelper.putValue(link, "skipEmpty", true);

return attributes;
}
Expand Down
@@ -0,0 +1,31 @@
package flyway.myplaces;

import fi.nls.oskari.db.DatasourceHelper;
import fi.nls.oskari.geoserver.GeoserverPopulator;
import org.flywaydb.core.api.migration.jdbc.JdbcMigration;
import org.json.JSONObject;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;

public class V1_0_13__add_formatting_metadata implements JdbcMigration {

public void migrate(Connection ignored) throws Exception {
// myplaces _can_ use other db than the default one
// -> Use connection to default db for this migration
DataSource ds = DatasourceHelper.getInstance().getDataSource();
if (ds == null) {
ds = DatasourceHelper.getInstance().createDataSource();
}
Connection conn = ds.getConnection();
JSONObject attributes = GeoserverPopulator.addMyplacesAttributes(GeoserverPopulator.createUserContentAttributes());
final String sql = "update oskari_maplayer set attributes =? where name = 'oskari:my_places';";

try (final PreparedStatement statement = conn.prepareStatement(sql)) {
statement.setString(1, attributes.toString());
statement.execute();
}
}

}
12 changes: 6 additions & 6 deletions service-base/src/main/java/fi/nls/oskari/util/JSONHelper.java
Expand Up @@ -49,15 +49,15 @@ public static final JSONObject createJSONObject(final String content) {
try {
return new JSONObject(content);
} catch (Exception e) {
log.info("Error generating JSONObject from ", content);
log.debug("Error generating JSONObject from ", content);
}
return null;
}
public static final JSONObject createJSONObject4Tokener(final JSONTokener content) {
try {
return new JSONObject(content);
} catch (Exception e) {
log.info("Error generating JSONObject from JSONTokener ", content);
log.debug("Error generating JSONObject from JSONTokener ", content);
}
return null;
}
Expand All @@ -68,7 +68,7 @@ public static final JSONObject getJSONObject(final JSONObject content, String ke
try {
return content.getJSONObject(key);
} catch (Exception e) {
log.info("Couldn't get JSONObject from ", content, " with key =", key);
log.debug("Couldn't get JSONObject from ", content, " with key =", key);
return null;
}
}
Expand All @@ -79,7 +79,7 @@ public static final Object get(final JSONObject content, String key) {
try {
return content.get(key);
} catch (Exception e) {
log.info("Couldn't get Object from ", content, " with key =", key);
log.debug("Couldn't get Object from ", content, " with key =", key);
return null;
}
}
Expand All @@ -90,7 +90,7 @@ public static final JSONObject getJSONObject(final JSONArray content, int key) {
try {
return content.getJSONObject(key);
} catch (Exception e) {
log.warn("Couldn't get JSONObject from ", content, " with key =", key, " - error: ", e);
log.debug("Couldn't get JSONObject from ", content, " with key =", key, " - error: ", e);
return null;
}
}
Expand All @@ -101,7 +101,7 @@ public static final JSONArray getJSONArray(final JSONObject content, String key)
try {
return content.getJSONArray(key);
} catch (JSONException e) {
log.info("Couldn't get JSONArray from " + content + " with key = " + key);
log.debug("Couldn't get JSONArray from " + content + " with key = " + key);
return null;
}
}
Expand Down