Skip to content

refactor: delete AbstractChangeConfigurationParams #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 28, 2018
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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,20 +1,83 @@
package de.rwth.idsg.steve.web.dto.ocpp;

import com.google.common.base.Strings;
import de.rwth.idsg.steve.SteveException;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.hibernate.validator.constraints.NotBlank;

import javax.validation.constraints.AssertTrue;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

/**
* @author Sevket Goekay <goekay@dbis.rwth-aachen.de>
* @since 08.03.2018
*/
@Getter
@Setter
public class ChangeConfigurationParams extends AbstractChangeConfigurationParams {
public class ChangeConfigurationParams extends MultipleChargePointSelect {

private String confKey;

@Override
protected String getPredefinedKey() {
return confKey;
private String customConfKey;

@NotNull(message = "Key type is required")
private ConfigurationKeyType keyType = ConfigurationKeyType.PREDEFINED;

@NotBlank(message = "Value is required")
@Pattern(regexp = "\\S+", message = "Value cannot contain any whitespace")
private String value;

@AssertTrue(message = "Custom Configuration Key cannot be left blank")
public boolean isValidCustom() {
if (keyType == ConfigurationKeyType.CUSTOM) {
return !Strings.isNullOrEmpty(customConfKey);
} else {
return true;
}
}

@AssertTrue(message = "Configuration Key is required")
public boolean isValidPredefined() {
if (keyType == ConfigurationKeyType.PREDEFINED) {
return confKey != null;
} else {
return true;
}
}

public String getKey() {
if (keyType == ConfigurationKeyType.PREDEFINED) {
return confKey;
} else if (keyType == ConfigurationKeyType.CUSTOM) {
return customConfKey;
}

// This should not happen
throw new SteveException("Cannot determine key (KeyType in illegal state)");
}

// -------------------------------------------------------------------------
// Enum
// -------------------------------------------------------------------------

@RequiredArgsConstructor
private enum ConfigurationKeyType {
PREDEFINED("Predefined"),
CUSTOM("Custom");

@Getter private final String value;

public static ConfigurationKeyType fromValue(String v) {
for (ConfigurationKeyType c: ConfigurationKeyType.values()) {
if (c.value.equals(v)) {
return c;
}
}
throw new IllegalArgumentException(v);
}
}

}