From 702b6a29b23909e970ad1c9c52b8dc2a5f82f756 Mon Sep 17 00:00:00 2001 From: Andreas Schmitz Date: Thu, 31 Aug 2023 11:52:29 +0200 Subject: [PATCH] Add sonar scanner and build workflow --- .github/workflows/build.yml | 22 ++++++++++++++++ pom.xml | 7 ++++++ .../shogun/migrator/shogun2/BootMigrator.java | 14 +++++++---- .../migrator/shogun2/Shogun2Migrator.java | 25 +++++++++++-------- .../shogun/migrator/MigratorTest.java | 6 ++--- 5 files changed, 55 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..7c10be4 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,22 @@ +name: build and analyse + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + + strategy: + matrix: + java-version: [ 11, 17 ] + + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: ${{ matrix.java-version }} + cache: 'maven' + - run: mvn -B install --no-transfer-progress + - name: Analyse code and publish to SonarQube 📊 + run: mvn -B -Dsonar.password=${{ secrets.SONAR_PASSWORD }} sonar:sonar diff --git a/pom.xml b/pom.xml index 292508f..a603ece 100644 --- a/pom.xml +++ b/pom.xml @@ -42,6 +42,13 @@ + + UTF-8 + https://sq.terrestris.de + terrestris + src/main/ + + reporting diff --git a/src/main/java/de/terrestris/shogun/migrator/shogun2/BootMigrator.java b/src/main/java/de/terrestris/shogun/migrator/shogun2/BootMigrator.java index 914cec9..fba663f 100644 --- a/src/main/java/de/terrestris/shogun/migrator/shogun2/BootMigrator.java +++ b/src/main/java/de/terrestris/shogun/migrator/shogun2/BootMigrator.java @@ -17,13 +17,17 @@ @Log4j2 public class BootMigrator implements ShogunMigrator { + public static final String LAYER_ID = "layerId"; + + public static final String BACKGROUND_LAYERS = "backgroundLayers"; + private HostDto source; private HostDto target; private static void migrateLayerTree(ObjectNode node, Map idMap) { - if (node.has("layerId")) { - node.put("layerId", idMap.get(node.get("layerId").intValue())); + if (node.has(LAYER_ID)) { + node.put(LAYER_ID, idMap.get(node.get(LAYER_ID).intValue())); } if (node.has("children")) { for (JsonNode jsonNode : node.get("children")) { @@ -38,12 +42,12 @@ public static byte[] migrateApplication(ObjectNode node, Map i log.info("Migrating application {}", node.get("name").asText()); JsonNode clientConfig = node.get("clientConfig"); - if (clientConfig.has("backgroundLayers")) { + if (clientConfig.has(BACKGROUND_LAYERS)) { ArrayNode backgroundLayers = mapper.createArrayNode(); - for (JsonNode jsonNode : clientConfig.get("backgroundLayers")) { + for (JsonNode jsonNode : clientConfig.get(BACKGROUND_LAYERS)) { backgroundLayers.add(idMap.get(jsonNode.asInt())); } - ((ObjectNode) clientConfig).set("backgroundLayers", backgroundLayers); + ((ObjectNode) clientConfig).set(BACKGROUND_LAYERS, backgroundLayers); } JsonNode layerTree = node.get("layerTree"); migrateLayerTree((ObjectNode) layerTree, idMap); diff --git a/src/main/java/de/terrestris/shogun/migrator/shogun2/Shogun2Migrator.java b/src/main/java/de/terrestris/shogun/migrator/shogun2/Shogun2Migrator.java index cd18c8d..5226174 100644 --- a/src/main/java/de/terrestris/shogun/migrator/shogun2/Shogun2Migrator.java +++ b/src/main/java/de/terrestris/shogun/migrator/shogun2/Shogun2Migrator.java @@ -19,6 +19,9 @@ @Log4j2 public class Shogun2Migrator implements ShogunMigrator { + public static final String CHILDREN = "children"; + public static final String RESOLUTIONS = "resolutions"; + public static final String SEARCHABLE = "searchable"; private HostDto source; private HostDto target; @@ -55,10 +58,10 @@ private static JsonNode migrateLayerTree(JsonNode node, ObjectMapper mapper, Map } folder.put("layerId", idMap.get(id)); } - if (node.has("children")) { + if (node.has(CHILDREN)) { ArrayNode children = mapper.createArrayNode(); - folder.set("children", children); - for (JsonNode child : node.get("children")) { + folder.set(CHILDREN, children); + for (JsonNode child : node.get(CHILDREN)) { children.add(migrateLayerTree(child, mapper, idMap)); } } @@ -94,12 +97,12 @@ public static byte[] migrateApplication(JsonNode node, Map idM mapView.set("mapExtent", extent); String oldProjection = mapConfig.get("projection").asText(); mapView.put("projection", oldProjection.startsWith("EPSG:") ? oldProjection : ("EPSG:" + oldProjection)); - JsonNode resolutions = mapConfig.get("resolutions"); + JsonNode resolutions = mapConfig.get(RESOLUTIONS); ArrayNode newResolutions = mapper.createArrayNode(); for (JsonNode res : resolutions) { newResolutions.add(res.asDouble()); } - mapView.set("resolutions", newResolutions); + mapView.set(RESOLUTIONS, newResolutions); clientConfig.set("mapView", mapView); } JsonNode layerTree = migrateLayerTree(node.get("layerTree"), mapper, idMap); @@ -137,9 +140,9 @@ private static void migrateClientConfig(JsonNode node, ObjectNode config) { JsonNode appearance = node.get("appearance"); config.put("minResolution", appearance.get("minResolution").textValue()); config.put("maxResolution", appearance.get("maxResolution").textValue()); - JsonNode searchable = node.get("searchable"); + JsonNode searchable = node.get(SEARCHABLE); if (searchable != null && searchable.booleanValue()) { - config.put("searchable", searchable.booleanValue()); + config.put(SEARCHABLE, searchable.booleanValue()); JsonNode oldConfig = node.get("searchConfig"); ObjectNode searchConfig = mapper.createObjectNode(); config.set("searchConfig", searchConfig); @@ -152,7 +155,7 @@ private static void migrateClientConfig(JsonNode node, ObjectNode config) { oldConfig.get("attributes").forEach(attribute -> attributes.add(attribute.textValue())); searchConfig.set("attributes", attributes); } else { - config.put("searchable", false); + config.put(SEARCHABLE, false); } } @@ -172,7 +175,7 @@ private static void migrateSourceConfig(JsonNode node, ObjectNode config) { JsonNode oldResolutions = tileGrid.get("tileGridResolutions"); ArrayNode resolutions = mapper.createArrayNode(); oldResolutions.forEach(resolution -> resolutions.add(resolution.doubleValue())); - config.set("resolutions", resolutions); + config.set(RESOLUTIONS, resolutions); } } @@ -218,7 +221,7 @@ public Map migrateLayers() { try { JsonNode node = fetch(source, "rest/projectlayers"); Map layerIdMap = new HashMap<>(); - int i = 0; +// int i = 0; for (JsonNode layer : node) { log.info("Migrating layer..."); byte[] bs = migrateLayer(layer); @@ -243,7 +246,7 @@ public Map migrateLayers() { public void migrateApplications(Map idMap) { try { JsonNode node = fetch(source, "rest/projectapps"); - int i = 0; +// int i = 0; for (JsonNode app : node) { log.info("Migrating application..."); byte[] bs = migrateApplication(app, idMap); diff --git a/src/test/java/de/terrestris/shogun/migrator/MigratorTest.java b/src/test/java/de/terrestris/shogun/migrator/MigratorTest.java index b220ed7..9db5c8d 100644 --- a/src/test/java/de/terrestris/shogun/migrator/MigratorTest.java +++ b/src/test/java/de/terrestris/shogun/migrator/MigratorTest.java @@ -11,13 +11,13 @@ import java.io.IOException; import java.util.HashMap; -public class MigratorTest { +class MigratorTest { private final ObjectMapper mapper = new ObjectMapper(); @ParameterizedTest @ValueSource(strings = {"/1.json", "/2.json", "/3.json"}) - public void testMigration(String file) throws IOException { + void testMigration(String file) throws IOException { JsonNode node = mapper.readTree(MigratorTest.class.getResource(file)); byte[] bs = Shogun2Migrator.migrateApplication(node, new HashMap<>()); byte[] expected = IOUtils.toByteArray(MigratorTest.class.getResource("/migrated" + file)); @@ -26,7 +26,7 @@ public void testMigration(String file) throws IOException { @ParameterizedTest @ValueSource(strings = {"/layer1.json", "/layer2.json", "/layer3.json", "/layer4.json", "/layer5.json", "/layer6.json", "/layer7.json", "/layer8.json"}) - public void testLayerMigration(String file) throws IOException { + void testLayerMigration(String file) throws IOException { JsonNode node = mapper.readTree(MigratorTest.class.getResource(file)); byte[] bs = Shogun2Migrator.migrateLayer(node); byte[] expected = IOUtils.toByteArray(MigratorTest.class.getResource("/migratedlayer" + file));