Skip to content

Commit 355cb39

Browse files
committed
1 parent 02a3e21 commit 355cb39

8 files changed

Lines changed: 160 additions & 24 deletions

File tree

src/main/java/de/rwth/idsg/steve/service/ChargePointService12_Client.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private ChangeAvailabilityRequest prepareChangeAvailability(ChangeAvailabilityPa
6868

6969
private ChangeConfigurationRequest prepareChangeConfiguration(ChangeConfigurationParams params) {
7070
return new ChangeConfigurationRequest()
71-
.withKey(params.getConfKey().value())
71+
.withKey(params.getKey())
7272
.withValue(params.getValue());
7373
}
7474

src/main/java/de/rwth/idsg/steve/service/ChargePointService15_Client.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private ChangeAvailabilityRequest prepareChangeAvailability(ChangeAvailabilityPa
9797

9898
private ChangeConfigurationRequest prepareChangeConfiguration(ChangeConfigurationParams params) {
9999
return new ChangeConfigurationRequest()
100-
.withKey(params.getConfKey().value())
100+
.withKey(params.getKey())
101101
.withValue(params.getValue());
102102
}
103103

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package de.rwth.idsg.steve.web.dto.common;
2+
3+
import com.google.common.base.Strings;
4+
import de.rwth.idsg.steve.SteveException;
5+
import lombok.Getter;
6+
import lombok.RequiredArgsConstructor;
7+
import lombok.Setter;
8+
9+
import javax.validation.constraints.AssertTrue;
10+
import javax.validation.constraints.NotNull;
11+
12+
/**
13+
* @author Sevket Goekay <goekay@dbis.rwth-aachen.de>
14+
* @since 22.03.2016
15+
*/
16+
@Getter
17+
@Setter
18+
public abstract class AbstractChangeConfigurationParams extends MultipleChargePointSelect {
19+
20+
private String customConfKey;
21+
22+
@NotNull(message = "Key type is required")
23+
private ConfigurationKeyType keyType = ConfigurationKeyType.PREDEFINED;
24+
25+
@AssertTrue(message = "Custom Configuration Key cannot be left blank")
26+
public boolean isValidCustom() {
27+
if (keyType == ConfigurationKeyType.CUSTOM) {
28+
return !Strings.isNullOrEmpty(customConfKey);
29+
} else {
30+
return true;
31+
}
32+
}
33+
34+
@AssertTrue(message = "Configuration Key is required")
35+
public boolean isValidPredefined() {
36+
if (keyType == ConfigurationKeyType.PREDEFINED) {
37+
return getPredefinedKey() != null;
38+
} else {
39+
return true;
40+
}
41+
}
42+
43+
public String getKey() {
44+
if (keyType == ConfigurationKeyType.PREDEFINED) {
45+
return getPredefinedKey();
46+
47+
} else if (keyType == ConfigurationKeyType.CUSTOM) {
48+
return customConfKey;
49+
}
50+
51+
// This should not happen
52+
throw new SteveException("Cannot determine key (KeyType in illegal state)");
53+
}
54+
55+
/**
56+
* To be implemented by version-specific subclasses
57+
*/
58+
protected abstract String getPredefinedKey();
59+
60+
// -------------------------------------------------------------------------
61+
// Enum
62+
// -------------------------------------------------------------------------
63+
64+
@RequiredArgsConstructor
65+
private enum ConfigurationKeyType {
66+
PREDEFINED("Predefined"),
67+
CUSTOM("Custom");
68+
69+
@Getter private final String value;
70+
71+
public static ConfigurationKeyType fromValue(String v) {
72+
for (ConfigurationKeyType c: ConfigurationKeyType.values()) {
73+
if (c.value.equals(v)) {
74+
return c;
75+
}
76+
}
77+
throw new IllegalArgumentException(v);
78+
}
79+
}
80+
81+
}
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package de.rwth.idsg.steve.web.dto.ocpp12;
22

3-
import de.rwth.idsg.steve.web.dto.common.MultipleChargePointSelect;
3+
import de.rwth.idsg.steve.web.dto.common.AbstractChangeConfigurationParams;
44
import lombok.Getter;
55
import lombok.Setter;
66
import org.hibernate.validator.constraints.NotBlank;
77

8-
import javax.validation.constraints.NotNull;
98
import javax.validation.constraints.Pattern;
109

1110
/**
@@ -14,13 +13,16 @@
1413
*/
1514
@Getter
1615
@Setter
17-
public class ChangeConfigurationParams extends MultipleChargePointSelect {
16+
public class ChangeConfigurationParams extends AbstractChangeConfigurationParams {
1817

19-
@NotNull(message = "Configuration Key is required")
2018
private ConfigurationKeyEnum confKey;
2119

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

24+
@Override
25+
protected String getPredefinedKey() {
26+
return confKey.value();
27+
}
2628
}
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package de.rwth.idsg.steve.web.dto.ocpp15;
22

3-
import de.rwth.idsg.steve.web.dto.common.MultipleChargePointSelect;
3+
import de.rwth.idsg.steve.web.dto.common.AbstractChangeConfigurationParams;
44
import lombok.Getter;
55
import lombok.Setter;
66
import org.hibernate.validator.constraints.NotBlank;
77

8-
import javax.validation.constraints.NotNull;
98
import javax.validation.constraints.Pattern;
109

1110
/**
@@ -14,12 +13,16 @@
1413
*/
1514
@Getter
1615
@Setter
17-
public class ChangeConfigurationParams extends MultipleChargePointSelect {
16+
public class ChangeConfigurationParams extends AbstractChangeConfigurationParams {
1817

19-
@NotNull(message = "Configuration key is required")
2018
private ConfigurationKeyEnum confKey;
2119

2220
@NotBlank(message = "Value is required")
2321
@Pattern(regexp = "\\S+", message = "Value cannot contain any whitespace")
2422
private String value;
23+
24+
@Override
25+
protected String getPredefinedKey() {
26+
return confKey.value();
27+
}
2528
}

src/main/resources/webapp/WEB-INF/views/op12/ChangeConfiguration.jsp

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
<%@ include file="../00-header.jsp" %>
22
<%@ include file="../00-op-bind-errors.jsp" %>
3+
<script type="text/javascript">
4+
$(document).ready(function() {
5+
<%@ include file="../snippets/confKeySelect.js" %>
6+
});
7+
</script>
38
<div class="content">
49
<div class="left-menu">
510
<ul>
@@ -20,15 +25,26 @@
2025
<%@ include file="../00-cp-multiple.jsp" %>
2126
<section><span>Parameters</span></section>
2227
<table class="userInput">
23-
<tr>
24-
<td>Configuration Key:</td>
25-
<td>
26-
<form:select path="confKey">
27-
<form:options items="${confKey}" itemLabel="text" />
28-
</form:select>
29-
</td>
30-
</tr>
31-
<tr><td>Value:</td><td><form:input path="value" /></td></tr>
28+
<tr>
29+
<td>Key Type:</td>
30+
<td><form:select path="keyType">
31+
<form:options items="${type}" itemLabel="value"/>
32+
</form:select>
33+
</td>
34+
</tr>
35+
<tr>
36+
<td>Configuration Key:</td>
37+
<td>
38+
<form:select path="confKey">
39+
<form:options items="${confKey}" itemLabel="text" />
40+
</form:select>
41+
</td>
42+
</tr>
43+
<tr>
44+
<td>Custom Configuration Key:</td>
45+
<td><form:input path="customConfKey"/></td>
46+
</tr>
47+
<tr><td>Value:</td><td><form:input path="value" /></td></tr>
3248
</table>
3349
<div class="submit-button"><input type="submit" value="Perform"></div>
3450
</form:form>

src/main/resources/webapp/WEB-INF/views/op15/ChangeConfiguration.jsp

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
<%@ include file="../00-header.jsp" %>
22
<%@ include file="../00-op-bind-errors.jsp" %>
3+
<script type="text/javascript">
4+
$(document).ready(function() {
5+
<%@ include file="../snippets/confKeySelect.js" %>
6+
});
7+
</script>
38
<div class="content">
49
<div class="left-menu">
510
<ul>
@@ -27,11 +32,25 @@
2732
<%@ include file="../00-cp-multiple.jsp" %>
2833
<section><span>Parameters</span></section>
2934
<table class="userInput">
30-
<tr><td>Configuration Key:</td><td>
31-
<form:select path="confKey">
32-
<form:options items="${confKeyList}" />
33-
</form:select>
34-
</td></tr>
35+
<tr>
36+
<td>Key Type:</td>
37+
<td><form:select path="keyType">
38+
<form:options items="${type}" itemLabel="value"/>
39+
</form:select>
40+
</td>
41+
</tr>
42+
<tr>
43+
<td>Configuration Key:</td>
44+
<td>
45+
<form:select path="confKey">
46+
<form:options items="${confKey}" itemLabel="text" />
47+
</form:select>
48+
</td>
49+
</tr>
50+
<tr>
51+
<td>Custom Configuration Key:</td>
52+
<td><form:input path="customConfKey"/></td>
53+
</tr>
3554
<tr><td>Value:</td><td><form:input path="value" /></td></tr>
3655
</table>
3756
<div class="submit-button"><input type="submit" value="Perform"></div>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var keyTypeSelect = $("#keyType");
2+
function togglePeriodType(keyTypeSelect) {
3+
if (keyTypeSelect.find("option:selected").text() == "Predefined") {
4+
$("#confKey").prop("disabled", false);
5+
$("#customConfKey").prop("disabled", true);
6+
} else {
7+
$("#confKey").prop("disabled", true);
8+
$("#customConfKey").prop("disabled", false);
9+
}
10+
}
11+
12+
togglePeriodType(keyTypeSelect);
13+
keyTypeSelect.change(function() {
14+
togglePeriodType(keyTypeSelect);
15+
});

0 commit comments

Comments
 (0)