Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/target
/.idea
target
.idea
*.iml
.DS_Store
.DS_Store
22 changes: 22 additions & 0 deletions ocpp-custom/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>de.rwth.idsg</groupId>
<artifactId>ocpp-parent</artifactId>
<version>0.0.14-SNAPSHOT</version>
</parent>

<artifactId>ocpp-custom</artifactId>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-core</artifactId>
<version>${jsonschema2pojo.version}</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package de.rwth.idsg.ocpp.jaxb;

import com.fasterxml.jackson.databind.JsonNode;
import com.sun.codemodel.JDefinedClass;
import com.sun.codemodel.JFieldVar;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.joda.time.DateTime;
import org.jsonschema2pojo.AbstractAnnotator;
import tools.jackson.databind.annotation.JsonDeserialize;
import tools.jackson.databind.annotation.JsonSerialize;

public class CustomAnnotator extends AbstractAnnotator {

@Override
public void typeInfo(JDefinedClass clazz, JsonNode schema) {
super.typeInfo(clazz, schema);

clazz.annotate(ToString.class);
clazz.annotate(Getter.class);
clazz.annotate(Setter.class);
clazz.annotate(EqualsAndHashCode.class);
}

@Override
public void propertyField(JFieldVar field, JDefinedClass clazz,
String propertyName,
JsonNode propertyNode) {
super.propertyField(field, clazz, propertyName, propertyNode);

// Add custom converter annotations to all DateTime fields
if (field.type().fullName().equals(DateTime.class.getName())) {
// Add @JsonSerialize annotation
field.annotate(JsonSerialize.class)
.param("using", clazz.owner().ref("de.rwth.idsg.ocpp.jaxb.JodaDateTimeSerializer").dotclass());

// Add @JsonDeserialize annotation
field.annotate(JsonDeserialize.class)
.param("using", clazz.owner().ref("de.rwth.idsg.ocpp.jaxb.JodaDateTimeDeserializer").dotclass());
}
}
}
228 changes: 228 additions & 0 deletions ocpp-jaxb/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>de.rwth.idsg</groupId>
<artifactId>ocpp-parent</artifactId>
<version>0.0.14-SNAPSHOT</version>
</parent>

<artifactId>ocpp-jaxb</artifactId>
<packaging>jar</packaging>

<properties>
<ocpp-1.6-security-schemas-dir>OCPP-1.6_Security_3rd_Edition_schemas</ocpp-1.6-security-schemas-dir>
<ocpp-2.0.1-schemas-dir>OCPP-2.0.1_part3_JSON_schemas</ocpp-2.0.1-schemas-dir>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<configuration>
<sourceRoot>${project.build.directory}/generated-sources</sourceRoot>
<wsdlRoot>${basedir}/src/main/resources/wsdl</wsdlRoot>
<defaultOptions>
<bindingFiles>
<bindingFile>${basedir}/src/main/resources/wsdl-binding/ocpp_binding.xml</bindingFile>
<bindingFile>${basedir}/src/main/resources/wsdl-binding/async_binding.xml</bindingFile>
<bindingFile>${basedir}/src/main/resources/wsdl-binding/add_interface.xml</bindingFile>
</bindingFiles>
<extraargs>
<extraarg>-xjc-Xfluent-api</extraarg>
<extraarg>-xjc-Xinheritance</extraarg>
<extraarg>-xjc-Xannotate</extraarg>
<!--<extraarg>-verbose</extraarg>-->
<extraarg>-exsh</extraarg>
<extraarg>true</extraarg>
</extraargs>
</defaultOptions>
</configuration>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
<dependency>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-plugins</artifactId>
<version>4.0.8</version>
</dependency>
<dependency>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-plugin-annotate</artifactId>
<version>4.0.8</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>

<!-- Unlike Ocpp 2 schema files, Ocpp 1.6 Security schema files do not use "Request" postfix in name
for request messages, i.e. they are like InstallCertificate.json instead of InstallCertificateRequest.json.
This creates a minor problem when selecting/filtering the files to add the interface RequestType.

Solution: Apply RequestType to all files first. The next execution 'add-response-interface-ocpp-1.6-security'
will select the Response files only and override the RequestType with the proper ResponseType.
-->
<execution>
<id>add-request-interface-ocpp-1.6j-security</id>
<phase>generate-resources</phase>
<goals>
<goal>replace</goal>
</goals>
<configuration>
<filesToInclude>${basedir}/src/main/resources/${ocpp-1.6-security-schemas-dir}/*.json</filesToInclude>
<preserveDir>false</preserveDir>
<outputDir>${project.build.directory}/generated-resources/${ocpp-1.6-security-schemas-dir}</outputDir>
<replacements>
<replacement>
<token>"\$schema"</token>
<!-- &#10; is html code for line break -->
<value>"javaInterfaces" : ["de.rwth.idsg.ocpp.jaxb.RequestType"],
"\$schema"</value>
</replacement>
</replacements>
</configuration>
</execution>
<execution>
<id>add-response-interface-ocpp-1.6j-security</id>
<phase>generate-resources</phase>
<goals>
<goal>replace</goal>
</goals>
<configuration>
<filesToInclude>${basedir}/src/main/resources/${ocpp-1.6-security-schemas-dir}/*Response.json</filesToInclude>
<preserveDir>false</preserveDir>
<outputDir>${project.build.directory}/generated-resources/${ocpp-1.6-security-schemas-dir}</outputDir>
<replacements>
<replacement>
<token>"\$schema"</token>
<!-- &#10; is html code for line break -->
<value>"javaInterfaces" : ["de.rwth.idsg.ocpp.jaxb.ResponseType"],
"\$schema"</value>
</replacement>
</replacements>
</configuration>
</execution>

<execution>
<id>add-request-interface-ocpp-2.0.1</id>
<phase>generate-resources</phase>
<goals>
<goal>replace</goal>
</goals>
<configuration>
<filesToInclude>${basedir}/src/main/resources/${ocpp-2.0.1-schemas-dir}/*Request.json</filesToInclude>
<preserveDir>false</preserveDir>
<outputDir>${project.build.directory}/generated-resources/${ocpp-2.0.1-schemas-dir}</outputDir>
<replacements>
<replacement>
<token>"\$schema"</token>
<!-- &#10; is html code for line break -->
<value>"javaInterfaces" : ["de.rwth.idsg.ocpp.jaxb.RequestType"],
"\$schema"</value>
</replacement>
</replacements>
</configuration>
</execution>
<execution>
<id>add-response-interface-ocpp-2.0.1</id>
<phase>generate-resources</phase>
<goals>
<goal>replace</goal>
</goals>
<configuration>
<filesToInclude>${basedir}/src/main/resources/${ocpp-2.0.1-schemas-dir}/*Response.json</filesToInclude>
<preserveDir>false</preserveDir>
<outputDir>${project.build.directory}/generated-resources/${ocpp-2.0.1-schemas-dir}</outputDir>
<replacements>
<replacement>
<token>"\$schema"</token>
<!-- &#10; is html code for line break -->
<value>"javaInterfaces" : ["de.rwth.idsg.ocpp.jaxb.ResponseType"],
"\$schema"</value>
</replacement>
</replacements>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
<version>${jsonschema2pojo.version}</version>
<configuration>
<outputDirectory>${project.build.directory}/generated-sources</outputDirectory>
<generateBuilders>true</generateBuilders>
<includeJsr303Annotations>true</includeJsr303Annotations>
<includeGeneratedAnnotation>false</includeGeneratedAnnotation>
<useJakartaValidation>true</useJakartaValidation>
<useJodaDates>true</useJodaDates>
<useJodaLocalDates>true</useJodaLocalDates>
<useJodaLocalTimes>true</useJodaLocalTimes>
<customAnnotator>de.rwth.idsg.ocpp.jaxb.CustomAnnotator</customAnnotator>

<includeToString>false</includeToString>
<includeGetters>false</includeGetters>
<includeSetters>false</includeSetters>
<includeHashcodeAndEquals>false</includeHashcodeAndEquals>
</configuration>
<executions>
<execution>
<id>generate-ocpp-1.6j-security</id>
<phase>process-resources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<sourceDirectory>${project.build.directory}/generated-resources/${ocpp-1.6-security-schemas-dir}</sourceDirectory>
<!-- using the date of "OCPP 1.6 security whitepaper edition 3" as package-->
<targetPackage>ocpp._2022._02.security</targetPackage>
</configuration>
</execution>
<execution>
<id>generate-ocpp-2.0.1</id>
<phase>process-resources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<sourceDirectory>${project.build.directory}/generated-resources/${ocpp-2.0.1-schemas-dir}</sourceDirectory>
<targetPackage>ocpp._2020._03</targetPackage>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>ocpp-custom</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>tools.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package de.rwth.idsg.ocpp.jaxb;

import org.joda.time.DateTime;

import jakarta.xml.bind.annotation.adapters.XmlAdapter;

import static de.rwth.idsg.ocpp.jaxb.Utils.FORMATTER;
import static de.rwth.idsg.ocpp.jaxb.Utils.isNullOrEmpty;

/**
* Joda-Time and XSD represent data and time information according to ISO 8601.
*
* @author Sevket Goekay <goekay@dbis.rwth-aachen.de>
* @since 20.10.2014
*/
public class JodaDateTimeConverter extends XmlAdapter<String, DateTime> {

@Override
public DateTime unmarshal(String v) throws Exception {
if (isNullOrEmpty(v)) {
return null;
} else {
return FORMATTER.parseDateTime(v);
}
}

@Override
public String marshal(DateTime v) throws Exception {
if (v == null) {
return null;
} else {
return v.toString();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package de.rwth.idsg.ocpp.jaxb;

import org.joda.time.DateTime;
import tools.jackson.core.JacksonException;
import tools.jackson.core.JsonParser;
import tools.jackson.databind.DeserializationContext;
import tools.jackson.databind.ValueDeserializer;

import static de.rwth.idsg.ocpp.jaxb.Utils.FORMATTER;
import static de.rwth.idsg.ocpp.jaxb.Utils.isNullOrEmpty;

public class JodaDateTimeDeserializer extends ValueDeserializer<DateTime> {

@Override
public DateTime deserialize(JsonParser p, DeserializationContext ctxt) throws JacksonException {
String value = p.getString();
if (isNullOrEmpty(value)) {
return null;
}
return FORMATTER.parseDateTime(value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package de.rwth.idsg.ocpp.jaxb;

import org.joda.time.DateTime;
import tools.jackson.core.JacksonException;
import tools.jackson.core.JsonGenerator;
import tools.jackson.databind.SerializationContext;
import tools.jackson.databind.ValueSerializer;

public class JodaDateTimeSerializer extends ValueSerializer<DateTime> {

@Override
public void serialize(DateTime value, JsonGenerator gen, SerializationContext serializers) throws JacksonException {
if (value == null) {
gen.writeNull();
} else {
gen.writeString(value.toString());
}
}
}
Loading