Skip to content

Commit

Permalink
Try to merge (still wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfuchss committed Jan 12, 2024
1 parent d576147 commit 1c849ec
Show file tree
Hide file tree
Showing 33 changed files with 236 additions and 168 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Licensed under MIT 2023. */
/* Licensed under MIT 2023-2024. */
package edu.kit.kastel.mcse.ardoco.core.api.diagramconsistency.common;

import java.util.List;
Expand Down Expand Up @@ -108,7 +108,7 @@ public static List<Box> getContainedBoxes(Box box, SortedMap<String, Box> boxes)
*/
public static Box addBox(Diagram diagram, String text) {
TextBox textBox = new TextBox(0, 0, 0, 0, 1.0, text, null);
Box box = new Box(String.valueOf(diagram.getBoxes().size()), new int[] { 0, 0, 0, 0 }, 1.0, null, List.of(textBox), null);
Box box = new Box(diagram, String.valueOf(diagram.getBoxes().size()), new int[] { 0, 0, 0, 0 }, 1.0, null, List.of(textBox), null);

diagram.addBox(box);
return box;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ public class Box extends DiagramElement implements Serializable {
private List<TextBox> textBoxes = new ArrayList<>();
@JsonProperty("contained")
private List<String> containedBoxes = new ArrayList<>();
private transient Color dominatingColor = null;
@JsonProperty("dominatingColor")
private Color dominatingColor = null;
@JsonIgnore
private SortedSet<String> references = new TreeSet<>();

private static String calculateUUID(int[] coordinates) {
protected static String calculateUUID(int[] coordinates) {
return String.format("Box [%s]", getBoundingBoxConcat(coordinates));
}

Expand All @@ -49,6 +50,26 @@ public static String getBoundingBoxConcat(int[] coordinates) {
return Arrays.stream(coordinates).mapToObj((Integer::toString)).reduce((l, r) -> l + "-" + r).orElseThrow();
}

/**
* Create a new box that is detected on the image.
*
* @param diagram the diagram the box belongs to
* @param uuid the unique identifier of the box
* @param coordinates the coordinates of two corners of the box in pixel. (x1,y1,x2,y2)
* @param confidence a confidence value
* @param classification the classification (e.g., "LABEL"), see {@link Classification} for further details
* @param textBoxes the text boxes that are attached to this box
* @param dominatingColor a dominating color in the box (iff present)
*/
public Box(Diagram diagram, String uuid, int[] coordinates, double confidence, String classification, List<TextBox> textBoxes, Color dominatingColor) {
super(diagram, uuid);
this.coordinates = coordinates;
this.confidence = confidence;
this.classification = classification;
this.textBoxes = textBoxes;
this.dominatingColor = dominatingColor;
}

/**
* Create a new box that is detected on the image.
*
Expand All @@ -71,18 +92,22 @@ public Box(Diagram diagram, int[] coordinates, double confidence, String classif
/**
* Create a new box that is detected on the image.
*
* @param diagram the diagram this box belongs to
* @param coordinates the coordinates of two corners of the box in pixel. (x1,y1,x2,y2)
* @param confidence a confidence value
* @param classification the classification (e.g., "LABEL"), see {@link Classification} for further details
* @param diagram the diagram this box belongs to
* @param uuid the unique identifier of the box
* @param coordinates the coordinates of two corners of the box in pixel. (x1,y1,x2,y2)
* @param confidence a confidence value
* @param classification the classification (e.g., "LABEL"), see {@link Classification} for further details
* @param dominatingColor a dominating color in the box (iff present)
*/
@JsonCreator
public Box(@JacksonInject Diagram diagram, @JsonProperty("box") int[] coordinates, @JsonProperty("confidence") double confidence,
@JsonProperty("class") String classification) {
super(diagram, calculateUUID(coordinates));
public Box(@JacksonInject Diagram diagram, @JsonProperty("uuid") String uuid, @JsonProperty("box") int[] coordinates,
@JsonProperty("confidence") double confidence, @JsonProperty("class") String classification,
@JsonProperty("dominatingColor") Color dominatingColor) {
super(diagram, uuid == null ? calculateUUID(coordinates) : uuid);
this.coordinates = coordinates;
this.confidence = confidence;
this.classification = classification;
this.dominatingColor = dominatingColor;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* Licensed under MIT 2024. */
package edu.kit.kastel.mcse.ardoco.core.common;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

public final class JsonHandling {
private JsonHandling() {
throw new IllegalAccessError("Utility class");
}

public static ObjectMapper createObjectMapper() {
var objectMapper = new ObjectMapper();
objectMapper.configure(SerializationFeature.INDENT_OUTPUT, false);
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.setVisibility(objectMapper.getSerializationConfig()
.getDefaultVisibilityChecker() //
.withFieldVisibility(JsonAutoDetect.Visibility.ANY) //
.withGetterVisibility(JsonAutoDetect.Visibility.NONE) //
.withSetterVisibility(JsonAutoDetect.Visibility.NONE) //
.withIsGetterVisibility(JsonAutoDetect.Visibility.NONE));
return objectMapper;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* Licensed under MIT 2023-2024. */
package edu.kit.kastel.mcse.ardoco.core.common.util;

import static edu.kit.kastel.mcse.ardoco.core.common.JsonHandling.createObjectMapper;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
Expand All @@ -13,8 +15,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.databind.ObjectMapper;

import edu.kit.kastel.mcse.ardoco.core.api.Disambiguation;

/**
Expand Down Expand Up @@ -212,7 +212,7 @@ static SortedSet<String> crawlAcronymFinderCom(String abbreviation) {
protected SortedMap<String, Disambiguation> read() throws CacheException {
try {
logger.info("Reading abbreviations file");
var read = toMap(new ObjectMapper().readValue(getFile(), Disambiguation[].class));
var read = toMap(createObjectMapper().readValue(getFile(), Disambiguation[].class));
logger.info("Found {} cached abbreviation", read.size());
return read;
} catch (IOException e) {
Expand All @@ -230,7 +230,7 @@ protected void write(SortedMap<String, Disambiguation> content) {
Collection<Disambiguation> values = content.values();
try (PrintWriter out = new PrintWriter(getFile())) {
//Parse before writing to the file, so we don't mess up the entire file due to a parsing error
String json = new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(values);
String json = createObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(values);
out.print(json);
logger.info("Saved abbreviations file");
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* Licensed under MIT 2023-2024. */
package edu.kit.kastel.mcse.ardoco.core.common.util;

import static edu.kit.kastel.mcse.ardoco.core.common.JsonHandling.createObjectMapper;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
Expand All @@ -13,7 +15,6 @@
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
* This class provides lists of computer- and software-related terminology. It retrieves the terminology from the DBPedia ontology using SPARQL queries. The
Expand Down Expand Up @@ -151,7 +152,7 @@ private List<String> runQuery(ParameterizedSparqlString query) {
protected void write(DbPediaData r) {
try (PrintWriter out = new PrintWriter(getFile())) {
//Parse before writing to the file, so we don't mess up the entire file due to a parsing error
String json = new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(r);
String json = createObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(r);
out.print(json);
logger.info("Saved {} file", getIdentifier());
} catch (IOException e) {
Expand All @@ -168,7 +169,7 @@ protected DbPediaData getDefault() {
protected DbPediaData read() throws CacheException {
try {
logger.info("Reading {} file", getIdentifier());
return new ObjectMapper().readValue(getFile(), new TypeReference<>() {
return createObjectMapper().readValue(getFile(), new TypeReference<>() {
});
} catch (IOException e) {
logger.error("Error reading {} file", getIdentifier());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Licensed under MIT 2022-2023. */
/* Licensed under MIT 2022-2024. */
package edu.kit.kastel.mcse.ardoco.core.data;

import java.io.Serializable;
Expand All @@ -7,10 +7,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import edu.kit.kastel.mcse.ardoco.core.common.JsonHandling;

/**
* This abstract class defines data that is used for the pipeline steps.
Expand All @@ -36,7 +33,7 @@ default <T extends PipelineStepData> Optional<T> asPipelineStepData(Class<T> cla
}

default String serialize() {
var oom = createObjectMapper();
var oom = JsonHandling.createObjectMapper();
try {
return oom.writeValueAsString(this);
} catch (Exception e) {
Expand All @@ -46,25 +43,12 @@ default String serialize() {
}

default PipelineStepData deserialize(String data) {
var oom = createObjectMapper();
var oom = JsonHandling.createObjectMapper();
try {
return oom.readValue(data, this.getClass());
} catch (Exception e) {
logger.error(e.getMessage(), e);
return null;
}
}

private static ObjectMapper createObjectMapper() {
var objectMapper = new ObjectMapper();
objectMapper.configure(SerializationFeature.INDENT_OUTPUT, false);
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.setVisibility(objectMapper.getSerializationConfig()
.getDefaultVisibilityChecker() //
.withFieldVisibility(JsonAutoDetect.Visibility.ANY) //
.withGetterVisibility(JsonAutoDetect.Visibility.NONE) //
.withSetterVisibility(JsonAutoDetect.Visibility.NONE) //
.withIsGetterVisibility(JsonAutoDetect.Visibility.NONE));
return objectMapper;
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* Licensed under MIT 2023-2024. */
package edu.kit.kastel.mcse.ardoco.core.common.util;

import static edu.kit.kastel.mcse.ardoco.core.common.JsonHandling.createObjectMapper;
import static org.junit.jupiter.api.Assertions.*;

import java.util.List;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import edu.kit.kastel.mcse.ardoco.core.api.Disambiguation;

Expand All @@ -31,7 +31,7 @@ void get() {

@Test
void deserialize() throws JsonProcessingException {
var abbr = new ObjectMapper().readValue(dbJSON, Disambiguation.class);
var abbr = createObjectMapper().readValue(dbJSON, Disambiguation.class);
assertEquals("DB", abbr.getAbbreviation());
assertTrue(abbr.getMeanings().containsAll(List.of("Database", "Decibel")));
assertEquals(2, abbr.getMeanings().size());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* Licensed under MIT 2023. */
/* Licensed under MIT 2023-2024. */
package edu.kit.kastel.mcse.ardoco.core.textproviderjson.converter;

import static edu.kit.kastel.mcse.ardoco.core.common.JsonHandling.createObjectMapper;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
Expand Down Expand Up @@ -40,7 +42,7 @@ private JsonConverter() {
* @return whether the json string matches the text schema
*/
public static boolean validateJson(String json) throws IOException {
ObjectMapper mapper = new ObjectMapper();
ObjectMapper mapper = createObjectMapper();
JsonSchemaFactory schemaFactory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V4);

InputStream inputSchema = JsonConverter.class.getClassLoader().getResourceAsStream(SCHEMA_PATH);
Expand Down Expand Up @@ -69,7 +71,7 @@ public static TextDto fromJsonString(String json) throws IOException, InvalidJso
if (!validateJson(json)) {
throw new InvalidJsonException("The json string is no valid text DTO.");
}
ObjectMapper objectMapper = new ObjectMapper();
ObjectMapper objectMapper = createObjectMapper();
return objectMapper.readValue(json, TextDto.class);
}

Expand All @@ -80,7 +82,7 @@ public static TextDto fromJsonString(String json) throws IOException, InvalidJso
* @return the JSON string or null
*/
public static String toJsonString(TextDto obj) throws IOException, InvalidJsonException {
ObjectMapper objectMapper = new ObjectMapper();
ObjectMapper objectMapper = createObjectMapper();
String jsonString = objectMapper.writeValueAsString(obj);
if (!validateJson(jsonString)) {
throw new InvalidJsonException("The text DTO could not be converted into a json string. No valid text Dto");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Licensed under MIT 2021-2023. */
/* Licensed under MIT 2021-2024. */
package edu.kit.kastel.mcse.ardoco.core.common.util;

import static edu.kit.kastel.mcse.ardoco.core.common.util.DataRepositoryHelper.getConnectionStates;
Expand Down Expand Up @@ -392,6 +392,7 @@ public static void writeToFile(String filename, String text) {
* @param text the text to write
*/
public static void writeToFile(Path file, String text) {
file.getParent().toFile().mkdirs();
try (BufferedWriter writer = Files.newBufferedWriter(file, UTF_8)) {
writer.write(text);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Licensed under MIT 2023. */
/* Licensed under MIT 2023-2024. */
package edu.kit.kastel.mcse.ardoco.core.diagramconsistency;

import java.io.File;
Expand All @@ -19,7 +19,7 @@
import edu.kit.kastel.mcse.ardoco.core.diagramconsistency.agents.DiagramProviderAgent;
import edu.kit.kastel.mcse.ardoco.core.execution.ArDoCo;
import edu.kit.kastel.mcse.ardoco.core.execution.runner.ArDoCoRunner;
import edu.kit.kastel.mcse.ardoco.core.models.ArCoTLModelProviderAgent;
import edu.kit.kastel.mcse.ardoco.core.models.agents.ArCoTLModelProviderAgent;

/**
* A runner that checks the consistency of a diagram and the represented architecture/code model.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Licensed under MIT 2023. */
/* Licensed under MIT 2023-2024. */
package edu.kit.kastel.mcse.ardoco.core.diagramconsistency.informants;

import java.util.Set;
Expand Down Expand Up @@ -72,7 +72,7 @@ public DiagramElementOccurrenceFinderInformant(DataRepository dataRepository) {
}

@Override
public void run() {
public void process() {
if (this.skip) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Licensed under MIT 2023. */
/* Licensed under MIT 2023-2024. */
package edu.kit.kastel.mcse.ardoco.core.diagramconsistency.informants;

import java.util.ArrayList;
Expand Down Expand Up @@ -107,7 +107,7 @@ private static void checkRulesForLooseEntities(Map<String, Entity> entities, Con
}

@Override
public void run() {
public void process() {
DataRepository data = this.getDataRepository();

ModelStates models = data.getData(ModelStates.ID, ModelStates.class).orElse(null);
Expand Down
Loading

0 comments on commit 1c849ec

Please sign in to comment.