Skip to content

Commit

Permalink
Add sonar scanner and build workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
hwbllmnn committed Aug 31, 2023
1 parent f085148 commit 702b6a2
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 19 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@
</snapshotRepository>
</distributionManagement>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<sonar.host.url>https://sq.terrestris.de</sonar.host.url>
<sonar.login>terrestris</sonar.login>
<sonar.sources>src/main/</sonar.sources>
</properties>

<profiles>
<profile>
<id>reporting</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer, Integer> 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")) {
Expand All @@ -38,12 +42,12 @@ public static byte[] migrateApplication(ObjectNode node, Map<Integer, Integer> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}
Expand Down Expand Up @@ -94,12 +97,12 @@ public static byte[] migrateApplication(JsonNode node, Map<Integer, Integer> 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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down Expand Up @@ -218,7 +221,7 @@ public Map<Integer, Integer> migrateLayers() {
try {
JsonNode node = fetch(source, "rest/projectlayers");
Map<Integer, Integer> layerIdMap = new HashMap<>();
int i = 0;
// int i = 0;
for (JsonNode layer : node) {
log.info("Migrating layer...");
byte[] bs = migrateLayer(layer);
Expand All @@ -243,7 +246,7 @@ public Map<Integer, Integer> migrateLayers() {
public void migrateApplications(Map<Integer, Integer> 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);
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/de/terrestris/shogun/migrator/MigratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));
Expand Down

0 comments on commit 702b6a2

Please sign in to comment.