Skip to content

Commit

Permalink
Localize urls.
Browse files Browse the repository at this point in the history
Refactor model so that urls for testlocations can be localized. Refactor TestLocationHelper to use message source.
  • Loading branch information
martinalig committed Dec 18, 2020
1 parent 0815d44 commit dfee8e0
Show file tree
Hide file tree
Showing 19 changed files with 1,033 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,12 @@ public class GaenConfigController {

private static final Logger logger = LoggerFactory.getLogger(GaenConfigController.class);

private Messages messages;
private final Messages messages;
private final TestLocationHelper testLocationHelper;

public GaenConfigController(Messages messages) {
this.messages = messages;
this.testLocationHelper = new TestLocationHelper(messages);
}

@Documentation(description = "Echo endpoint", responses = { "200 => Hello from DP3T Config WS" })
Expand All @@ -119,7 +121,7 @@ public GaenConfigController(Messages messages) {
@Documentation(description = "Build number of the app", example = "ios-200619.2333.175") @RequestParam String buildnr) {
ConfigResponse config = new ConfigResponse();
config.setWhatToDoPositiveTestTexts(whatToDoPositiveTestTexts(messages));
config.setTestLocations(TestLocationHelper.getTestLocations());
config.setTestLocations(testLocationHelper.getTestLocations());

// For iOS 13.6 users show information about weekly notification
if (osversion.startsWith(IOS_VERSION_DE_WEEKLY_NOTIFCATION_INFO)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package org.dpppt.switzerland.backend.sdk.config.ws.helper;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import org.dpppt.switzerland.backend.sdk.config.ws.model.TestLocation;
import org.dpppt.switzerland.backend.sdk.config.ws.model.TestLocationCollection;
import org.dpppt.switzerland.backend.sdk.config.ws.poeditor.Messages;

/**
* Holds the url for test locations for each canton.
Expand All @@ -11,53 +16,46 @@
*/
public class TestLocationHelper {

// make sure its ordered
private static final Map<String, String> TEST_LOCATIONS = new LinkedHashMap<>();

static {
TEST_LOCATIONS.put("canton_aargau", "https://www.ag.ch/de/themen_1/coronavirus_2/coronavirus.jsp");
TEST_LOCATIONS.put("canton_appenzell_ausserrhoden",
"https://www.ar.ch/verwaltung/departement-gesundheit-und-soziales/amt-fuer-gesundheit/informationsseite-coronavirus/");
TEST_LOCATIONS.put("canton_appenzell_innerrhoden",
"https://www.ai.ch/themen/gesundheit-alter-und-soziales/gesundheitsfoerderung-und-praevention/uebertragbare-krankheiten/coronavirus");
TEST_LOCATIONS.put("canton_basel_country",
"https://www.baselland.ch/politik-und-behorden/direktionen/volkswirtschafts-und-gesundheitsdirektion/amt-fur-gesundheit/medizinische-dienste/kantonsarztlicher-dienst/aktuelles");
TEST_LOCATIONS.put("canton_basel_city", "https://www.coronavirus.bs.ch/");
TEST_LOCATIONS.put("canton_berne", "http://www.be.ch/corona");
TEST_LOCATIONS.put("canton_fribourg",
"https://www.fr.ch/de/gesundheit/covid-19/coronavirus-aktuelle-informationen");
TEST_LOCATIONS.put("canton_geneva", "https://www.ge.ch/covid-19-se-proteger-prevenir-nouvelle-vague");
TEST_LOCATIONS.put("canton_glarus",
"https://www.gl.ch/verwaltung/finanzen-und-gesundheit/gesundheit/coronavirus.html/4817");
TEST_LOCATIONS.put("canton_graubuenden",
"https://www.gr.ch/DE/institutionen/verwaltung/djsg/ga/coronavirus/info/Seiten/Start.aspx");
TEST_LOCATIONS.put("canton_jura",
"https://www.jura.ch/fr/Autorites/Coronavirus/Accueil/Coronavirus-Informations-officielles-a-la-population-jurassienne.html");
TEST_LOCATIONS.put("canton_lucerne",
"https://gesundheit.lu.ch/themen/Humanmedizin/Infektionskrankheiten/Coronavirus");
TEST_LOCATIONS.put("canton_neuchatel",
"https://www.ne.ch/autorites/DFS/SCSP/medecin-cantonal/maladies-vaccinations/Pages/Coronavirus.aspx");
TEST_LOCATIONS.put("canton_nidwalden", "https://www.nw.ch/gesundheitsamtdienste/6044");
TEST_LOCATIONS.put("canton_obwalden", "https://www.ow.ch/de/verwaltung/dienstleistungen/?dienst_id=5962");
TEST_LOCATIONS.put("canton_st_gallen", "https://www.sg.ch/tools/informationen-coronavirus.html");
TEST_LOCATIONS.put("canton_schaffhausen",
"https://sh.ch/CMS/Webseite/Kanton-Schaffhausen/Beh-rde/Verwaltung/Departement-des-Innern/Gesundheitsamt-2954701-DE.html");
TEST_LOCATIONS.put("canton_schwyz",
"https://www.sz.ch/behoerden/information-medien/medienmitteilungen/coronavirus.html/72-416-412-1379-6948");
TEST_LOCATIONS.put("canton_solothurn", "https://corona.so.ch/");
TEST_LOCATIONS.put("canton_thurgovia", "https://www.tg.ch/news/fachdossier-coronavirus.html/10552");
TEST_LOCATIONS.put("canton_ticino", "https://www4.ti.ch/dss/dsp/covid19/home/");
TEST_LOCATIONS.put("canton_uri", "https://www.ur.ch/themen/2962");
TEST_LOCATIONS.put("canton_valais", "https://www.vs.ch/de/web/coronavirus");
TEST_LOCATIONS.put("canton_vaud",
"https://www.vd.ch/toutes-les-actualites/hotline-et-informations-sur-le-coronavirus/");
TEST_LOCATIONS.put("canton_zug", "https://www.zg.ch/behoerden/gesundheitsdirektion/amt-fuer-gesundheit/corona");
TEST_LOCATIONS.put("canton_zurich", "https://www.zh.ch/de/gesundheit/coronavirus.html");
TEST_LOCATIONS.put("country_liechtenstein", "https://www.llv.li/inhalt/118724/amtsstellen/coronavirus");
private final Messages messages;
private final TestLocationCollection testLocationCollection;

private static final List<String> ALL_CANTONS_AND_LIECHTENSTEIN = List.of("canton_aargau",
"canton_appenzell_ausserrhoden", "canton_appenzell_innerrhoden", "canton_basel_country",
"canton_basel_city", "canton_berne", "canton_fribourg", "canton_geneva", "canton_glarus",
"canton_graubuenden", "canton_jura", "canton_lucerne", "canton_neuchatel", "canton_nidwalden",
"canton_obwalden", "canton_st_gallen", "canton_schaffhausen", "canton_schwyz", "canton_solothurn",
"canton_thurgovia", "canton_ticino", "canton_uri", "canton_valais", "canton_vaud", "canton_zug",
"canton_zurich", "country_liechtenstein");

public TestLocationHelper(Messages messages) {
this.messages = messages;
this.testLocationCollection = new TestLocationCollection();

testLocationCollection.setBs(getTestLocationsForLanguage(Locale.forLanguageTag("bs")));
testLocationCollection.setDe(getTestLocationsForLanguage(Locale.forLanguageTag("de")));
testLocationCollection.setEn(getTestLocationsForLanguage(Locale.forLanguageTag("en")));
testLocationCollection.setEs(getTestLocationsForLanguage(Locale.forLanguageTag("es")));
testLocationCollection.setFr(getTestLocationsForLanguage(Locale.forLanguageTag("fr")));
testLocationCollection.setHr(getTestLocationsForLanguage(Locale.forLanguageTag("hr")));
testLocationCollection.setIt(getTestLocationsForLanguage(Locale.forLanguageTag("it")));
testLocationCollection.setPt(getTestLocationsForLanguage(Locale.forLanguageTag("pt")));
testLocationCollection.setRm(getTestLocationsForLanguage(Locale.forLanguageTag("rm")));
testLocationCollection.setSq(getTestLocationsForLanguage(Locale.forLanguageTag("sq")));
testLocationCollection.setSr(getTestLocationsForLanguage(Locale.forLanguageTag("sr")));
testLocationCollection.setTi(getTestLocationsForLanguage(Locale.forLanguageTag("ti")));
testLocationCollection.setTr(getTestLocationsForLanguage(Locale.forLanguageTag("tr")));
}

private List<TestLocation> getTestLocationsForLanguage(Locale language) {
List<TestLocation> testLocations = new ArrayList<>();
for (String region : ALL_CANTONS_AND_LIECHTENSTEIN) {
testLocations.add(new TestLocation(region, messages.getMessage("testlocation_url_" + region, language)));
}
return testLocations;
}

public static Map<String, String> getTestLocations() {
return TEST_LOCATIONS;
public TestLocationCollection getTestLocations() {
return this.testLocationCollection;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class ConfigResponse {
private WhatToDoPositiveTestTextsCollection whatToDoPositiveTestTexts;

@Documentation(description = "Holds a url for test locations for each canton and Liechtenstein")
private Map<String, String> testLocations;
private TestLocationCollection testLocations;

@Documentation(description = "GAEN epidemiological parameters for iOS")
private GAENSDKConfig iOSGaenSdkConfig = new GAENSDKConfig();
Expand Down Expand Up @@ -76,11 +76,11 @@ public void setAndroidGaenSdkConfig(GAENSDKConfig androidGaenSdkConfig) {
this.androidGaenSdkConfig = androidGaenSdkConfig;
}

public Map<String, String> getTestLocations() {
public TestLocationCollection getTestLocations() {
return testLocations;
}

public void setTestLocations(Map<String, String> testLocations) {
public void setTestLocations(TestLocationCollection testLocations) {
this.testLocations = testLocations;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2020 Ubique Innovation AG <https://www.ubique.ch>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* SPDX-License-Identifier: MPL-2.0
*/

package org.dpppt.switzerland.backend.sdk.config.ws.model;

public class TestLocation {

private String region;
private String url;

public TestLocation() {
}

public TestLocation(String region, String url) {
super();
this.region = region;
this.url = url;
}

public String getRegion() {
return region;
}

public void setRegion(String region) {
this.region = region;
}

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* Copyright (c) 2020 Ubique Innovation AG <https://www.ubique.ch>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* SPDX-License-Identifier: MPL-2.0
*/

package org.dpppt.switzerland.backend.sdk.config.ws.model;

import java.util.List;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

@JsonInclude(value = Include.NON_NULL)
public class TestLocationCollection {

private List<TestLocation> de;
private List<TestLocation> fr;
private List<TestLocation> it;
private List<TestLocation> en;
private List<TestLocation> pt;
private List<TestLocation> es;
private List<TestLocation> sq;
private List<TestLocation> bs;
private List<TestLocation> hr;
private List<TestLocation> sr;
private List<TestLocation> rm;
private List<TestLocation> tr;
private List<TestLocation> ti;

public List<TestLocation> getDe() {
return de;
}

public void setDe(List<TestLocation> de) {
this.de = de;
}

public List<TestLocation> getFr() {
return fr;
}

public void setFr(List<TestLocation> fr) {
this.fr = fr;
}

public List<TestLocation> getIt() {
return it;
}

public void setIt(List<TestLocation> it) {
this.it = it;
}

public List<TestLocation> getEn() {
return en;
}

public void setEn(List<TestLocation> en) {
this.en = en;
}

public List<TestLocation> getPt() {
return pt;
}

public void setPt(List<TestLocation> pt) {
this.pt = pt;
}

public List<TestLocation> getEs() {
return es;
}

public void setEs(List<TestLocation> es) {
this.es = es;
}

public List<TestLocation> getSq() {
return sq;
}

public void setSq(List<TestLocation> sq) {
this.sq = sq;
}

public List<TestLocation> getBs() {
return bs;
}

public void setBs(List<TestLocation> bs) {
this.bs = bs;
}

public List<TestLocation> getHr() {
return hr;
}

public void setHr(List<TestLocation> hr) {
this.hr = hr;
}

public List<TestLocation> getSr() {
return sr;
}

public void setSr(List<TestLocation> sr) {
this.sr = sr;
}

public List<TestLocation> getRm() {
return rm;
}

public void setRm(List<TestLocation> rm) {
this.rm = rm;
}

public List<TestLocation> getTr() {
return tr;
}

public void setTr(List<TestLocation> tr) {
this.tr = tr;
}

public List<TestLocation> getTi() {
return ti;
}

public void setTi(List<TestLocation> ti) {
this.ti = ti;
}

}
Loading

0 comments on commit dfee8e0

Please sign in to comment.