Skip to content

Commit

Permalink
SEBSP-116 added Client Group for alphabetical name
Browse files Browse the repository at this point in the history
  • Loading branch information
anhefti committed Oct 24, 2024
1 parent 0c06b70 commit 4fd9f07
Show file tree
Hide file tree
Showing 16 changed files with 313 additions and 192 deletions.
11 changes: 10 additions & 1 deletion src/main/java/ch/ethz/seb/sebserver/gbl/api/POSTMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ public String getString(final String name) {
return this.params.getFirst(name);
}

public Character getCharacter(final String name) {
final String result = getString(name);
if (result == null) {
return null;
}

return name.charAt(0);
}

public char[] getCharArray(final String name) {
final String value = getString(name);
if (value == null || value.length() <= 0) {
Expand Down Expand Up @@ -283,5 +292,5 @@ public String toString() {
builder.append("]");
return builder.toString();
}

}
112 changes: 56 additions & 56 deletions src/main/java/ch/ethz/seb/sebserver/gbl/model/exam/ClientGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ public class ClientGroup implements ClientGroupData, Comparable<ClientGroup> {
@JsonProperty(ATTR_CLIENT_OS)
public final ClientOS clientOS;

@JsonProperty(ATTR_NAME_RANGE_START_LETTER)
public final String nameRangeStartLetter;

@JsonProperty(ATTR_NAME_RANGE_END_LETTER)
public final String nameRangeEndLetter;

@JsonCreator
public ClientGroup(
@JsonProperty(CLIENT_GROUP.ATTR_ID) final Long id,
Expand All @@ -73,7 +79,9 @@ public ClientGroup(
@JsonProperty(CLIENT_GROUP.ATTR_ICON) final String icon,
@JsonProperty(ATTR_IP_RANGE_START) final String ipRangeStart,
@JsonProperty(ATTR_IP_RANGE_END) final String ipRangeEnd,
@JsonProperty(ATTR_CLIENT_OS) final ClientOS clientOS) {
@JsonProperty(ATTR_CLIENT_OS) final ClientOS clientOS,
@JsonProperty(ATTR_NAME_RANGE_START_LETTER) final String nameRangeStartLetter,
@JsonProperty(ATTR_NAME_RANGE_END_LETTER) final String nameRangeEndLetter) {

super();
this.id = id;
Expand All @@ -85,6 +93,8 @@ public ClientGroup(
this.ipRangeStart = ipRangeStart;
this.ipRangeEnd = ipRangeEnd;
this.clientOS = clientOS == null ? ClientOS.NONE : clientOS;
this.nameRangeStartLetter = nameRangeStartLetter;
this.nameRangeEndLetter = nameRangeEndLetter;
}

public ClientGroup(
Expand All @@ -110,18 +120,33 @@ public ClientGroup(
this.ipRangeStart = split[0];
this.ipRangeEnd = split[1];
this.clientOS = ClientOS.NONE;
this.nameRangeStartLetter = null;
this.nameRangeEndLetter = null;
break;
}
case CLIENT_OS: {
this.ipRangeStart = null;
this.ipRangeEnd = null;
this.clientOS = Utils.enumFromString(data, ClientOS.class, ClientOS.NONE);
this.nameRangeStartLetter = null;
this.nameRangeEndLetter = null;
break;
}
case NAME_ALPHABETICAL_RANGE: {
this.ipRangeStart = null;
this.ipRangeEnd = null;
this.clientOS = ClientOS.NONE;
final String[] split = StringUtils.split(data, Constants.EMBEDDED_LIST_SEPARATOR);
this.nameRangeStartLetter = split[0];
this.nameRangeEndLetter = split[1];
break;
}
default: {
this.ipRangeStart = null;
this.ipRangeEnd = null;
this.clientOS = ClientOS.NONE;
this.nameRangeStartLetter = null;
this.nameRangeEndLetter = null;
break;
}
}
Expand All @@ -137,14 +162,12 @@ public ClientGroup(final Long examId, final POSTMapper postParams) {
this.ipRangeStart = postParams.getString(ATTR_IP_RANGE_START);
this.ipRangeEnd = postParams.getString(ATTR_IP_RANGE_END);
this.clientOS = postParams.getEnum(ATTR_CLIENT_OS, ClientOS.class);
this.nameRangeStartLetter = postParams.getString(ATTR_NAME_RANGE_START_LETTER);
this.nameRangeEndLetter = postParams.getString(ATTR_NAME_RANGE_END_LETTER);
}

public static ClientGroup createNew(final String examId) {
try {
return new ClientGroup(null, Long.parseLong(examId), null, null, null, null, null, null, null);
} catch (final Exception e) {
return new ClientGroup(null, null, null, null, null, null, null, null, null);
}
return new ClientGroup(null, Long.parseLong(examId), null, null, null, null, null, null, null, null, null);
}

@Override
Expand Down Expand Up @@ -217,6 +240,16 @@ public ClientOS getClientOS() {
return this.clientOS;
}

@Override
public String getNameRangeStartLetter() {
return this.nameRangeStartLetter;
}

@Override
public String getNameRangeEndLetter() {
return this.nameRangeEndLetter;
}

@JsonIgnore
public String getData() {
switch (this.type) {
Expand All @@ -226,63 +259,30 @@ public String getData() {
case CLIENT_OS: {
return this.clientOS.name();
}
case NAME_ALPHABETICAL_RANGE: {
return this.nameRangeStartLetter + Constants.EMBEDDED_LIST_SEPARATOR + this.nameRangeEndLetter;
}
default: {
return StringUtils.EMPTY;
}
}
}

@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
builder.append("ClientGroup [id=");
builder.append(this.id);
builder.append(", examId=");
builder.append(this.examId);
builder.append(", name=");
builder.append(this.name);
builder.append(", type=");
builder.append(this.type);
builder.append(", color=");
builder.append(this.color);
builder.append(", icon=");
builder.append(this.icon);
builder.append(", ipRangeStart=");
builder.append(this.ipRangeStart);
builder.append(", ipRangeEnd=");
builder.append(this.ipRangeEnd);
builder.append(", clientOS=");
builder.append(this.clientOS);
builder.append("]");
return builder.toString();
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.id == null) ? 0 : this.id.hashCode());
result = prime * result + ((this.type == null) ? 0 : this.type.hashCode());
return result;
}

@Override
public boolean equals(final Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final ClientGroup other = (ClientGroup) obj;
if (this.id == null) {
if (other.id != null)
return false;
} else if (!this.id.equals(other.id))
return false;
if (this.type != other.type)
return false;
return true;
return "ClientGroup{" +
"id=" + id +
", examId=" + examId +
", name='" + name + '\'' +
", type=" + type +
", color='" + color + '\'' +
", icon='" + icon + '\'' +
", ipRangeStart='" + ipRangeStart + '\'' +
", ipRangeEnd='" + ipRangeEnd + '\'' +
", clientOS=" + clientOS +
", nameRangeStartLetter=" + nameRangeStartLetter +
", nameRangeEndLetter=" + nameRangeEndLetter +
'}';
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@
/** Overall interface for client group data used either for template or real client groups */
public interface ClientGroupData extends Entity {

public static final String ATTR_IP_RANGE_START = "ipRangeStart";
public static final String ATTR_IP_RANGE_END = "ipRangeEnd";
public static final String ATTR_CLIENT_OS = "clientOS";
String ATTR_IP_RANGE_START = "ipRangeStart";
String ATTR_IP_RANGE_END = "ipRangeEnd";
String ATTR_CLIENT_OS = "clientOS";
String ATTR_NAME_RANGE_START_LETTER = "nameRangeStartLetter";
String ATTR_NAME_RANGE_END_LETTER = "nameRangeEndLetter";

/** All known and implemented client group types */
public enum ClientGroupType {
enum ClientGroupType {
NONE,
IP_V4_RANGE,
CLIENT_OS
CLIENT_OS,
NAME_ALPHABETICAL_RANGE
}

/** All known and implemented SEB OS types */
public enum ClientOS {
enum ClientOS {
NONE(null),
WINDOWS("Windows"),
MAC_OS("macOS"),
Expand All @@ -36,16 +39,15 @@ public enum ClientOS {
public final String queryString1;
public final String queryString2;

private ClientOS(final String queryString1) {
ClientOS(final String queryString1) {
this.queryString1 = queryString1;
this.queryString2 = null;
}

private ClientOS(final String queryString1, final String queryString2) {
ClientOS(final String queryString1, final String queryString2) {
this.queryString1 = queryString1;
this.queryString2 = queryString2;
}

}

Long getId();
Expand All @@ -59,7 +61,11 @@ private ClientOS(final String queryString1, final String queryString2) {
String getIpRangeStart();

String getIpRangeEnd();

ClientOS getClientOS();

String getNameRangeStartLetter();

String getNameRangeEndLetter();

}
Loading

0 comments on commit 4fd9f07

Please sign in to comment.