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
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ subprojects {
apply plugin: 'maven-publish'
apply plugin: "com.github.sherter.google-java-format"

compileJava {
options.compilerArgs << '-Xlint:all'
}

compileTestJava {
options.compilerArgs << '-Xlint:all'
}

repositories {
mavenLocal()
maven {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ of this software and associated documentation files (the "Software"), to deal

/** Exception returned to an outgoing request if an error is reported from the other end. */
public class CallErrorException extends Exception {
private static final long serialVersionUID = 2491636769263746241L;

private String errorCode;
private String errorDescription;
Expand Down
21 changes: 14 additions & 7 deletions ocpp-common/src/main/java/eu/chargetime/ocpp/Communicator.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ of this software and associated documentation files (the "Software"), to deal
SOFTWARE.
*/

import eu.chargetime.ocpp.feature.Feature;
import eu.chargetime.ocpp.model.*;
import java.util.ArrayDeque;
import org.slf4j.Logger;
Expand Down Expand Up @@ -54,6 +55,7 @@ public abstract class Communicator {
* @param payload the raw formatted payload.
* @param type the expected return type.
* @return the unpacked payload.
* @param <T> the type of the unpacked payload.
* @throws Exception error occurred while converting.
*/
public abstract <T> T unpackPayload(Object payload, Class<T> type) throws Exception;
Expand All @@ -70,7 +72,7 @@ public abstract class Communicator {
* Create a call result envelope to transmit.
*
* @param uniqueId the id the receiver expects.
* @param action action name of the feature.
* @param action action name of the {@link Feature}.
* @param payload packed payload.
* @return a fully packed message ready to send.
*/
Expand All @@ -80,7 +82,7 @@ public abstract class Communicator {
* Create a call envelope to transmit to the server.
*
* @param uniqueId the id the receiver must reply with.
* @param action action name of the feature.
* @param action action name of the {@link Feature}.
* @param payload packed payload.
* @return a fully packed message ready to send.
*/
Expand All @@ -90,6 +92,7 @@ public abstract class Communicator {
* Create a call error envelope to transmit.
*
* @param uniqueId the id the receiver expects.
* @param action action name of the {@link Feature}.
* @param errorCode an OCPP error code.
* @param errorDescription an associated error description.
* @return a fully packed message ready to send.
Expand All @@ -101,6 +104,7 @@ protected abstract Object makeCallError(
* Create a call result error envelope to transmit.
*
* @param uniqueId the id the receiver expects.
* @param action action name of the {@link Feature}.
* @param errorCode an OCPP error code.
* @param errorDescription an associated error description.
* @return a fully packed message ready to send.
Expand All @@ -112,7 +116,7 @@ protected abstract Object makeCallResultError(
* Create a send envelope to transmit to the server.
*
* @param uniqueId the id of the message.
* @param action action name of the feature.
* @param action action name of the {@link Feature}.
* @param payload packed payload.
* @return a fully packed message ready to send.
*/
Expand Down Expand Up @@ -177,7 +181,7 @@ public void accept(CommunicatorEvents events) {
* Request}s.
*
* @param uniqueId the id the receiver should use to reply.
* @param action action name of the {@link eu.chargetime.ocpp.feature.Feature}.
* @param action action name of the {@link Feature}.
* @param request the outgoing {@link Request}
*/
public synchronized void sendCall(String uniqueId, String action, Request request) {
Expand Down Expand Up @@ -222,6 +226,7 @@ public synchronized void sendCall(String uniqueId, String action, Request reques
* Send a {@link Confirmation} reply to a {@link Request}.
*
* @param uniqueId the id the receiver expects.
* @param action action name of the {@link Feature}.
* @param confirmation the outgoing {@link Confirmation}
*/
public void sendCallResult(String uniqueId, String action, Confirmation confirmation) {
Expand Down Expand Up @@ -255,7 +260,8 @@ public void sendCallResult(String uniqueId, String action, Confirmation confirma
* Send an error. If offline, the message is thrown away.
*
* @param uniqueId the id the receiver expects a response to.
* @param errorCode an OCPP error Code
* @param action action name of the {@link Feature}.
* @param errorCode an OCPP error Code.
* @param errorDescription a associated error description.
*/
public void sendCallError(
Expand All @@ -282,7 +288,8 @@ public void sendCallError(
* Send a call result error. If offline, the message is thrown away.
*
* @param uniqueId the id the receiver expects a response to.
* @param errorCode an OCPP error Code
* @param action action name of the {@link Feature}.
* @param errorCode an OCPP error Code.
* @param errorDescription a associated error description.
*/
public void sendCallResultError(
Expand Down Expand Up @@ -310,7 +317,7 @@ public void sendCallResultError(
* Send a {@link Request} which has no confirmation.
*
* @param uniqueId the id of the {@link Request}.
* @param action action name of the {@link eu.chargetime.ocpp.feature.Feature}.
* @param action action name of the {@link Feature}.
* @param request the outgoing {@link Request}
*/
public synchronized void send(String uniqueId, String action, Request request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ of this software and associated documentation files (the "Software"), to deal
SOFTWARE.
*/

public class NotConnectedException extends Exception {}
public class NotConnectedException extends Exception {
private static final long serialVersionUID = -2192470845608175121L;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ of this software and associated documentation files (the "Software"), to deal
*/

/** Exception thrown when trying to send a request that isn't valid. */
public class OccurenceConstraintException extends Exception {}
public class OccurenceConstraintException extends Exception {
private static final long serialVersionUID = -8870111792165582976L;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ of this software and associated documentation files (the "Software"), to deal

/** Exception used when validating fields. */
public class PropertyConstraintException extends IllegalArgumentException {

private static final long serialVersionUID = 7561578774874709893L;
private static final String EXCEPTION_MESSAGE_TEMPLATE =
"Validation failed: [%s]. Current Value: [%s]";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ of this software and associated documentation files (the "Software"), to deal

/** A security issue occurred */
public class SecurityErrorException extends IllegalStateException {
private static final long serialVersionUID = 630599636179474207L;

public SecurityErrorException(String s) {
super(s);
}
Expand Down
4 changes: 4 additions & 0 deletions ocpp-common/src/main/java/eu/chargetime/ocpp/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ public void close() {
* @throws UnsupportedFeatureException Thrown if the feature isn't among the list of supported
* features.
* @throws OccurenceConstraintException Thrown if the request isn't valid.
* @throws NotConnectedException Thrown if session with passed sessionIndex is not found
*/
public CompletableFuture<Confirmation> send(UUID sessionIndex, Request request)
throws UnsupportedFeatureException, OccurenceConstraintException, NotConnectedException {
Expand Down Expand Up @@ -275,6 +276,9 @@ public CompletableFuture<Confirmation> send(UUID sessionIndex, Request request)
* @param confirmation the {@link Confirmation} to the original {@link Request}.
* @return a boolean indicating if pending request was found.
* @throws NotConnectedException Thrown if session with passed sessionIndex is not found
* @throws UnsupportedFeatureException Thrown if the feature isn't among the list of supported
* features.
* @throws OccurenceConstraintException Thrown if the request isn't valid.
*/
public boolean asyncCompleteRequest(UUID sessionIndex, String uniqueId, Confirmation confirmation)
throws NotConnectedException, UnsupportedFeatureException, OccurenceConstraintException {
Expand Down
3 changes: 3 additions & 0 deletions ocpp-common/src/main/java/eu/chargetime/ocpp/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public class Session implements ISession {
*
* @param communicator send and receive messages.
* @param queue store and restore requests based on unique ids.
* @param fulfiller the {@link PromiseFulfiller} to use
* @param featureRepository the {@link IFeatureRepository} to use
*/
public Session(
Communicator communicator,
Expand Down Expand Up @@ -150,6 +152,7 @@ public void removeRequest(String ticket) {
* Send a {@link Confirmation} to a {@link Request}
*
* @param uniqueId the unique identification the receiver expects.
* @param action action name to identify the feature.
* @param confirmation the {@link Confirmation} payload to send.
*/
public void sendConfirmation(String uniqueId, String action, Confirmation confirmation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public interface SessionEvents {
*
* @param request the {@link Request}.
* @return a {@link Confirmation} to send as a response or {@code null} if none to send.
* @throws UnsupportedFeatureException Thrown if the feature isn't among the list of supported
* features.
*/
@Nullable
Confirmation handleRequest(Request request) throws UnsupportedFeatureException;
Expand All @@ -57,6 +59,9 @@ public interface SessionEvents {
* @param uniqueId the unique id used for the {@link Request}.
* @param confirmation the {@link Confirmation} to the {@link Request}.
* @return a boolean indicating if pending request was found.
* @throws UnsupportedFeatureException Thrown if the feature isn't among the list of supported
* features.
* @throws OccurenceConstraintException Thrown if the request isn't valid.
*/
boolean asyncCompleteRequest(String uniqueId, Confirmation confirmation)
throws UnsupportedFeatureException, OccurenceConstraintException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ of this software and associated documentation files (the "Software"), to deal

public class OptionalDecorator extends Validator<String> {

private final Validator validator;
private final Validator<String> validator;

public OptionalDecorator(Validator validator) {
public OptionalDecorator(Validator<String> validator) {
this.validator = validator;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ of this software and associated documentation files (the "Software"), to deal

import eu.chargetime.ocpp.PropertyConstraintException;

public class RequiredDecorator extends Validator<Object> {
public class RequiredDecorator<T> extends Validator<T> {

private final Validator requiredValidator = new RequiredValidator();
private final Validator decoratee;
private final Validator<T> requiredValidator = new RequiredValidator<>();
private final Validator<T> decoratee;

public RequiredDecorator(Validator validator) {
public RequiredDecorator(Validator<T> validator) {
this.decoratee = validator;
}

@Override
public void validate(Object value) throws PropertyConstraintException {
public void validate(T value) throws PropertyConstraintException {
requiredValidator.validate(value);
decoratee.validate(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ of this software and associated documentation files (the "Software"), to deal

import eu.chargetime.ocpp.PropertyConstraintException;

public class RequiredValidator extends Validator<Object> {
private final String ERROR_MESSAGE = "Field is required and must not be Null.";
public class RequiredValidator<T> extends Validator<T> {
private static final String ERROR_MESSAGE = "Field is required and must not be Null.";

@Override
public void validate(Object value) throws PropertyConstraintException {
public void validate(T value) throws PropertyConstraintException {
if (value == null) {
throw new PropertyConstraintException(ERROR_MESSAGE, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ of this software and associated documentation files (the "Software"), to deal

public class ValidatorBuilder {

private final ArrayList<IValidationRule> rules;
private boolean required = false;
private ArrayList<IValidationRule> rules;

public ValidatorBuilder() {
rules = new ArrayList<>();
Expand All @@ -46,10 +46,10 @@ public ValidatorBuilder setRequired(boolean isRequired) {
return this;
}

public Validator build() {
Validator validator = new StringValidator(rules.toArray(new IValidationRule[0]));
public Validator<String> build() {
Validator<String> validator = new StringValidator(rules.toArray(new IValidationRule[0]));

if (required) validator = new RequiredDecorator(validator);
if (required) validator = new RequiredDecorator<>(validator);
else validator = new OptionalDecorator(validator);

return validator;
Expand Down
Loading
Loading