Commit f95ca9ff authored by Matthias Betz's avatar Matthias Betz
Browse files

fixed error adapter

fixed tests
added service meta inf
fixed various other issues
parent af713a75
......@@ -33,7 +33,7 @@ public class CityObjectPropertiesAdapter implements ObjectBuilder<CityObjectProp
return;
}
switch (name.getLocalPart()) {
case "validationResult" -> object.setValidationResult(reader.getObjectUsingBuilder(ValidationResultPropertyAdapter.class));
case "ValidationResult" -> object.setValidationResult(reader.getObjectUsingBuilder(ValidationResultPropertyAdapter.class));
default -> throw new IllegalStateException("Cannot handle name " + name + " when building CityObjectProperties element");
}
}
......
package de.hft.stuttgart.quality.adapter.types;
import de.hft.stuttgart.quality.model.enums.ErrorId;
import de.hft.stuttgart.quality.model.types.Error;
import javax.xml.namespace.QName;
import de.hft.stuttgart.quality.QualityADEModule;
import org.xmlobjects.annotation.XMLElement;
import org.xmlobjects.builder.ObjectBuildException;
import org.xmlobjects.builder.ObjectBuilder;
import org.xmlobjects.serializer.ObjectSerializeException;
......@@ -16,8 +15,11 @@ import org.xmlobjects.xml.Attributes;
import org.xmlobjects.xml.Element;
import org.xmlobjects.xml.Namespaces;
import javax.xml.namespace.QName;
import de.hft.stuttgart.quality.QualityADEModule;
import de.hft.stuttgart.quality.model.enums.ErrorId;
import de.hft.stuttgart.quality.model.types.Error;
@XMLElement(name = "Error", namespaceURI = QualityADEModule.NAMESPACE_URI)
public class ErrorAdapter implements ObjectBuilder<Error>, ObjectSerializer<Error> {
@Override
......@@ -38,6 +40,11 @@ public class ErrorAdapter implements ObjectBuilder<Error>, ObjectSerializer<Erro
}
}
@Override
public Element createElement(Error object, Namespaces namespaces) throws ObjectSerializeException {
return Element.of(QualityADEModule.NAMESPACE_URI, "Error");
}
@Override
public void writeChildElements(Error object, Namespaces namespaces, XMLWriter writer)
throws ObjectSerializeException, XMLWriteException {
......
......@@ -16,7 +16,9 @@ import org.xmlobjects.xml.Element;
import org.xmlobjects.xml.Namespaces;
import de.hft.stuttgart.quality.QualityADEModule;
import de.hft.stuttgart.quality.adapter.properties.ErrorPropertyAdapter;
import de.hft.stuttgart.quality.adapter.properties.FeatureStatisticsPropertyAdapter;
import de.hft.stuttgart.quality.model.properties.ErrorProperty;
import de.hft.stuttgart.quality.model.types.Statistics;
@XMLElement(name = "Statistics", namespaceURI = QualityADEModule.NAMESPACE_URI)
......@@ -46,6 +48,7 @@ public class StatisticsAdapter implements ObjectBuilder<Statistics>, ObjectSeria
.setNumErrorWaterObjects(reader.getObjectUsingBuilder(FeatureStatisticsPropertyAdapter.class));
case "numErrorTransportation" -> object
.setNumErrorTransportation(reader.getObjectUsingBuilder(FeatureStatisticsPropertyAdapter.class));
case "error" -> object.getErrors().add(reader.getObjectUsingBuilder(ErrorPropertyAdapter.class));
default -> throw new IllegalStateException("Cannot handle name " + name + " when building Statistics element");
}
}
......@@ -82,5 +85,9 @@ public class StatisticsAdapter implements ObjectBuilder<Statistics>, ObjectSeria
writer.writeElementUsingSerializer(Element.of(QualityADEModule.NAMESPACE_URI, "numErrorTransportation"),
object.getNumErrorTransportation(), FeatureStatisticsPropertyAdapter.class, namespaces);
}
for (ErrorProperty errorProp : object.getErrors()) {
writer.writeElementUsingSerializer(Element.of(QualityADEModule.NAMESPACE_URI, "error"), errorProp,
ErrorPropertyAdapter.class, namespaces);
}
}
}
......@@ -28,6 +28,15 @@ public class FeatureStatistics extends GMLObject implements ADEObject {
private int numChecked;
private int numErrors;
public FeatureStatistics() {
// constructor for serialization
}
public FeatureStatistics(int numChecked, int numErrors) {
this.numChecked = numChecked;
this.numErrors = numErrors;
}
public int getNumChecked() {
return numChecked;
}
......
de.hft.stuttgart.quality.QualityADEContext
\ No newline at end of file
......@@ -15,6 +15,7 @@
*/
package de.hft.stuttgart.quality;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayInputStream;
......@@ -22,10 +23,15 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import javax.xml.XMLConstants;
import javax.xml.namespace.QName;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
......@@ -37,11 +43,17 @@ import org.citygml4j.core.ade.ADERegistry;
import org.citygml4j.core.model.CityGMLVersion;
import org.citygml4j.core.model.building.Building;
import org.citygml4j.core.model.core.AbstractCityObjectProperty;
import org.citygml4j.core.model.core.AbstractFeature;
import org.citygml4j.core.model.core.AbstractFeatureProperty;
import org.citygml4j.core.model.core.CityModel;
import org.citygml4j.core.util.CityGMLConstants;
import org.citygml4j.xml.CityGMLContext;
import org.citygml4j.xml.CityGMLContextException;
import org.citygml4j.xml.module.citygml.CoreModule;
import org.citygml4j.xml.reader.ChunkOptions;
import org.citygml4j.xml.reader.CityGMLInputFactory;
import org.citygml4j.xml.reader.CityGMLReadException;
import org.citygml4j.xml.reader.CityGMLReader;
import org.citygml4j.xml.schema.CityGMLSchemaHandler;
import org.citygml4j.xml.writer.CityGMLOutputFactory;
import org.citygml4j.xml.writer.CityGMLWriteException;
......@@ -57,6 +69,7 @@ import org.xmlobjects.gml.model.measures.Angle;
import org.xmlobjects.gml.model.measures.Length;
import org.xmlobjects.schema.SchemaHandlerException;
import de.hft.stuttgart.quality.model.enums.ErrorId;
import de.hft.stuttgart.quality.model.enums.RequirementId;
import de.hft.stuttgart.quality.model.enums.ResultType;
import de.hft.stuttgart.quality.model.enums.RingSelfIntType;
......@@ -65,6 +78,7 @@ import de.hft.stuttgart.quality.model.properties.AbstractErrorProperty;
import de.hft.stuttgart.quality.model.properties.CheckingProperty;
import de.hft.stuttgart.quality.model.properties.EdgeListProperty;
import de.hft.stuttgart.quality.model.properties.EdgeProperty;
import de.hft.stuttgart.quality.model.properties.ErrorProperty;
import de.hft.stuttgart.quality.model.properties.FeatureStatisticsProperty;
import de.hft.stuttgart.quality.model.properties.FilterProperty;
import de.hft.stuttgart.quality.model.properties.GlobalParametersProperty;
......@@ -112,15 +126,44 @@ import de.hft.stuttgart.quality.model.types.ValidationResult;
class QualityAdeTests {
private static final String CITY_OBJECT_MEMBER = "cityObjectMember";
private static List<QName> chunkProperties = new ArrayList<>();
static {
chunkProperties.add(new QName(CityGMLConstants.CITYGML_1_0_CORE_NAMESPACE, CITY_OBJECT_MEMBER));
chunkProperties.add(new QName(CityGMLConstants.CITYGML_2_0_CORE_NAMESPACE, CITY_OBJECT_MEMBER));
chunkProperties.add(new QName(CityGMLConstants.CITYGML_3_0_CORE_NAMESPACE, CITY_OBJECT_MEMBER));
}
@BeforeAll
static void setUsLocale() throws ADEException {
Locale.setDefault(Locale.US);
ADERegistry.getInstance().loadADE(new QualityADEContext());
}
@Test
void testReadingModel() throws CityGMLContextException, CityGMLReadException {
CityGMLContext context = CityGMLContext.newInstance();
CityGMLInputFactory in = context.createCityGMLInputFactory()
.withChunking(ChunkOptions.chunkByProperties(chunkProperties).skipCityModel(false));
Path file = Paths.get("src/test/resources/SimpleSolid_Error_QualityADE.gml");
try (CityGMLReader reader = in.createCityGMLReader(file)) {
while (reader.hasNext()) {
AbstractFeature feature = reader.next();
if (feature instanceof Building) {
List<CityObjectProperties> adeProperties = feature.getADEProperties(CityObjectProperties.class);
assertEquals(1, adeProperties.size());
}
}
}
}
@Test
void testAllPolygonsOrientedWrong() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException {
void testAllPolygonsOrientedWrong() throws ADEException, CityGMLContextException, CityGMLWriteException,
SAXException, IOException, SchemaHandlerException {
CityModel model = new CityModel();
ValidationResult res = fillCityModel(model);
......@@ -133,7 +176,8 @@ class QualityAdeTests {
}
@Test
void testConsecutivePointsSameError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException {
void testConsecutivePointsSameError() throws ADEException, CityGMLContextException, CityGMLWriteException,
SAXException, IOException, SchemaHandlerException {
CityModel model = new CityModel();
ValidationResult res = fillCityModel(model);
......@@ -148,7 +192,8 @@ class QualityAdeTests {
}
@Test
void testHoleOutsideError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException {
void testHoleOutsideError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException,
IOException, SchemaHandlerException {
CityModel model = new CityModel();
ValidationResult res = fillCityModel(model);
......@@ -162,7 +207,8 @@ class QualityAdeTests {
}
@Test
void testInnerRingsNestedError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException {
void testInnerRingsNestedError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException,
IOException, SchemaHandlerException {
CityModel model = new CityModel();
ValidationResult res = fillCityModel(model);
......@@ -177,7 +223,8 @@ class QualityAdeTests {
}
@Test
void testInteriorDisconnectedError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException {
void testInteriorDisconnectedError() throws ADEException, CityGMLContextException, CityGMLWriteException,
SAXException, IOException, SchemaHandlerException {
CityModel model = new CityModel();
ValidationResult res = fillCityModel(model);
......@@ -190,7 +237,8 @@ class QualityAdeTests {
}
@Test
void testIntersectingRingsError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException {
void testIntersectingRingsError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException,
IOException, SchemaHandlerException {
CityModel model = new CityModel();
ValidationResult res = fillCityModel(model);
......@@ -205,7 +253,8 @@ class QualityAdeTests {
}
@Test
void testMultipleComponentsError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException {
void testMultipleComponentsError() throws ADEException, CityGMLContextException, CityGMLWriteException,
SAXException, IOException, SchemaHandlerException {
CityModel model = new CityModel();
ValidationResult res = fillCityModel(model);
......@@ -222,7 +271,8 @@ class QualityAdeTests {
}
@Test
void testNonManifoldEdgeError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException {
void testNonManifoldEdgeError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException,
IOException, SchemaHandlerException {
CityModel model = new CityModel();
ValidationResult res = fillCityModel(model);
......@@ -242,7 +292,8 @@ class QualityAdeTests {
}
@Test
void testNonManifoldVertexError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException {
void testNonManifoldVertexError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException,
IOException, SchemaHandlerException {
CityModel model = new CityModel();
ValidationResult res = fillCityModel(model);
......@@ -256,7 +307,8 @@ class QualityAdeTests {
}
@Test
void testOrientationRingsSameError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException {
void testOrientationRingsSameError() throws ADEException, CityGMLContextException, CityGMLWriteException,
SAXException, IOException, SchemaHandlerException {
CityModel model = new CityModel();
ValidationResult res = fillCityModel(model);
......@@ -270,7 +322,8 @@ class QualityAdeTests {
}
@Test
void testPlanarDistancePlaneError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException {
void testPlanarDistancePlaneError() throws ADEException, CityGMLContextException, CityGMLWriteException,
SAXException, IOException, SchemaHandlerException {
CityModel model = new CityModel();
ValidationResult res = fillCityModel(model);
......@@ -285,7 +338,8 @@ class QualityAdeTests {
}
@Test
void testPlanarNormalsDeviationError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException {
void testPlanarNormalsDeviationError() throws ADEException, CityGMLContextException, CityGMLWriteException,
SAXException, IOException, SchemaHandlerException {
CityModel model = new CityModel();
ValidationResult res = fillCityModel(model);
......@@ -299,7 +353,8 @@ class QualityAdeTests {
}
@Test
void testPolygonWrongOrientationError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException {
void testPolygonWrongOrientationError() throws ADEException, CityGMLContextException, CityGMLWriteException,
SAXException, IOException, SchemaHandlerException {
CityModel model = new CityModel();
ValidationResult res = fillCityModel(model);
......@@ -318,7 +373,8 @@ class QualityAdeTests {
}
@Test
void testRingNotClosedError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException {
void testRingNotClosedError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException,
IOException, SchemaHandlerException {
CityModel model = new CityModel();
ValidationResult res = fillCityModel(model);
......@@ -331,7 +387,8 @@ class QualityAdeTests {
}
@Test
void testRingSelfIntersectionError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException {
void testRingSelfIntersectionError() throws ADEException, CityGMLContextException, CityGMLWriteException,
SAXException, IOException, SchemaHandlerException {
CityModel model = new CityModel();
ValidationResult res = fillCityModel(model);
......@@ -351,7 +408,8 @@ class QualityAdeTests {
}
@Test
void testRingTooFewPointsError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException {
void testRingTooFewPointsError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException,
IOException, SchemaHandlerException {
CityModel model = new CityModel();
ValidationResult res = fillCityModel(model);
......@@ -364,7 +422,8 @@ class QualityAdeTests {
}
@Test
void testSemanticAttributeMissingError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException {
void testSemanticAttributeMissingError() throws ADEException, CityGMLContextException, CityGMLWriteException,
SAXException, IOException, SchemaHandlerException {
CityModel model = new CityModel();
ValidationResult res = fillCityModel(model);
......@@ -379,7 +438,8 @@ class QualityAdeTests {
}
@Test
void testSemanticAttributeWrongValueError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException {
void testSemanticAttributeWrongValueError() throws ADEException, CityGMLContextException, CityGMLWriteException,
SAXException, IOException, SchemaHandlerException {
CityModel model = new CityModel();
ValidationResult res = fillCityModel(model);
......@@ -394,7 +454,8 @@ class QualityAdeTests {
}
@Test
void testSolidNotClosedError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException {
void testSolidNotClosedError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException,
IOException, SchemaHandlerException {
CityModel model = new CityModel();
ValidationResult res = fillCityModel(model);
......@@ -413,7 +474,8 @@ class QualityAdeTests {
}
@Test
void testSolidSelfIntersectionError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException {
void testSolidSelfIntersectionError() throws ADEException, CityGMLContextException, CityGMLWriteException,
SAXException, IOException, SchemaHandlerException {
CityModel model = new CityModel();
ValidationResult res = fillCityModel(model);
......@@ -428,7 +490,8 @@ class QualityAdeTests {
}
@Test
void testSolidTooFewPolygonsError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException {
void testSolidTooFewPolygonsError() throws ADEException, CityGMLContextException, CityGMLWriteException,
SAXException, IOException, SchemaHandlerException {
CityModel model = new CityModel();
ValidationResult res = fillCityModel(model);
......@@ -440,9 +503,8 @@ class QualityAdeTests {
assertTrue(validate(new ByteArrayInputStream(buf)));
}
private boolean validate(InputStream stream) throws SAXException, IOException, CityGMLContextException, SchemaHandlerException {
private boolean validate(InputStream stream)
throws SAXException, IOException, CityGMLContextException, SchemaHandlerException {
CityGMLContext context = CityGMLContext.newInstance();
......@@ -476,12 +538,10 @@ class QualityAdeTests {
}
});
validator.validate(new StreamSource(stream));
return !foundErrors[0];
}
private byte[] writeModel(CityModel model) throws ADEException, CityGMLContextException, CityGMLWriteException {
CityGMLContext context = CityGMLContext.newInstance();
......@@ -490,10 +550,9 @@ class QualityAdeTests {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
try (CityGMLWriter writer = out.createCityGMLWriter(outStream, StandardCharsets.UTF_8.name())) {
writer.withIndent(" ")
.withSchemaLocation(QualityADEModule.NAMESPACE_URI, getClass().getResource("/qualityAde.xsd").toString())
.withDefaultPrefixes()
.withDefaultNamespace(CoreModule.of(version).getNamespaceURI())
.write(model);
.withSchemaLocation(QualityADEModule.NAMESPACE_URI,
getClass().getResource("/qualityAde.xsd").toString())
.withDefaultPrefixes().withDefaultNamespace(CoreModule.of(version).getNamespaceURI()).write(model);
}
return outStream.toByteArray();
}
......@@ -513,6 +572,11 @@ class QualityAdeTests {
stats.setNumErrorBridgeObjects(new FeatureStatisticsProperty(fStats));
v.setStatistics(new StatisticsProperty(stats));
de.hft.stuttgart.quality.model.types.Error err = new de.hft.stuttgart.quality.model.types.Error();
err.setName(ErrorId.GE_P_HOLE_OUTSIDE);
err.setOccurrences(1);
stats.getErrors().add(new ErrorProperty(err));
Requirement req = new Requirement();
req.setEnabled(true);
req.setRequirementType(RequirementId.R_GE_P_HOLE_OUTSIDE);
......@@ -535,7 +599,6 @@ class QualityAdeTests {
v.setValidationPlan(new ValidationPlanProperty(plan));
Building b = new Building();
b.setId("testId");
model.getCityObjectMembers().add(new AbstractCityObjectProperty(b));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment