bug5241: added priority to DeviceConfiguration

This commit is contained in:
Axel Uhl committed 2020-12-10 14:30:32 +01:00
1 parent 6930e92d84
commit e40b457545
15 files changed
+126 -11

No files matched your search

@@ -0,0 +1,26 @@
package com.sap.sailing.domain.common.racelog;
/**
* Generally, any {@code AbstractLogEvent} has an author of type {@code AbstractLogEventAuthor} which has a numerical
* non-negative priority. Lesser numerical values represent higher priority/precedence. This enumeration captures
* the default priorities the Race Manager App is expected to handle.
*
* @author Axel Uhl (D043530)
*
*/
public enum AuthorPriority {
ADMIN(0),
OFFICER_ON_VESSEL(1),
SHORE_CONTROL(2),
DEMO_MODE(3);
private final int priority;
private AuthorPriority(int priority) {
this.priority = priority;
}
public int getPriority() {
return priority;
}
}
@@ -19,10 +19,9 @@ public interface AbstractLogEventAuthor extends Named, Comparable<AbstractLogEve
/**
* A lesser number represents a higher priority. Suggested priority levels:
* <ol>
* <li>Start Vessel</li>
* <li>Finish Vessel</li>
* <li>Race Officer on a Vessel</li>
* <li>Shore Control</li>
* <li>Compatibility priority for old events</li>
* <li>Demo Mode</li>
* </ol>
*/
int getPriority();
@@ -70,4 +70,19 @@ public interface DeviceConfiguration extends WithID, WithQualifiedObjectIdentifi
* @param courseAreaId if {@code null}, an {@link Optional#empty() empty} optional will result from {@link #getCourseAreaId()}.
*/
void setCourseAreaId(UUID courseAreaId);
/**
* During the Race Manager App's login process the user is asked to choose a "role" such as "Race Officer on the
* Water" or "Shore Control." These map to numeric priorities, with lesser numerical values taking higher
* precedence. "Race Officer on the Water" would map to the number 1, "Shore Control" to 2. An exceptional priority
* of 3 may be translated by the app into "Demo Mode" if that is permissible. The field may not be set, then
* returning an empty {@link Optional}, meaning that this device configuration leaves it up for the user to choose
* the priority during the login process.
*/
Optional<Integer> getPriority();
/**
* Sets the {@link #getPriority() priority}.
*/
void setPriority(Integer priority);
}
@@ -24,6 +24,7 @@ public class DeviceConfigurationImpl extends NamedImpl implements DeviceConfigur
private final UUID id;
private UUID eventId;
private UUID courseAreaId;
private Integer priority;
public DeviceConfigurationImpl(RegattaConfiguration regattaConfiguration, UUID id, String name) {
super(name);
@@ -59,6 +60,16 @@ public class DeviceConfigurationImpl extends NamedImpl implements DeviceConfigur
public void setCourseAreaId(UUID courseAreaId) {
this.courseAreaId = courseAreaId;
}
@Override
public Optional<Integer> getPriority() {
return Optional.ofNullable(priority);
}
@Override
public void setPriority(Integer priority) {
this.priority = priority;
}
/**
* May return {@code null}
@@ -0,0 +1,21 @@
package com.sap.sailing.gwt.ui.adminconsole;
import com.sap.sailing.domain.common.racelog.AuthorPriority;
import com.sap.sailing.gwt.ui.client.StringMessages;
public class AuthorPriorityFormatter {
public static String getDescription(AuthorPriority authorPriority, StringMessages stringMessages) {
switch (authorPriority) {
case ADMIN:
return stringMessages.administration();
case OFFICER_ON_VESSEL:
return stringMessages.raceOfficerOnVessel();
case SHORE_CONTROL:
return stringMessages.shoreControl();
case DEMO_MODE:
return stringMessages.demoMode();
}
throw new RuntimeException("Internal error: don't know author priority "+authorPriority.name());
}
}
@@ -29,6 +29,7 @@ import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.sap.sailing.domain.common.dto.CourseAreaDTO;
import com.sap.sailing.domain.common.racelog.AuthorPriority;
import com.sap.sailing.domain.common.security.SecuredDomainType;
import com.sap.sailing.gwt.ui.client.SailingServiceWriteAsync;
import com.sap.sailing.gwt.ui.client.StringMessages;
@@ -79,6 +80,12 @@ public class DeviceConfigurationDetailComposite extends Composite {
*/
private final ListBox courseAreaListBox;
/**
* Names are the internationalized descriptions of the roles, values are their corresponding integer values as
* String, or the empty string for the first empty "placeholder" record.
*/
private final ListBox priorityListBox;
private RegattaConfigurationDTO currentRegattaConfiguration;
private final UserService userService;
@@ -94,6 +101,7 @@ public class DeviceConfigurationDetailComposite extends Composite {
this.errorReporter = errorReporter;
this.stringMessages = stringMessages;
this.currentRegattaConfiguration = null;
priorityListBox = createPriorityListBox();
courseAreaListBox = new ListBox();
courseAreaListBox.addChangeHandler(e->markAsDirty(true));
eventListBox = new ListBox();
@@ -137,6 +145,15 @@ public class DeviceConfigurationDetailComposite extends Composite {
fillEventListBox();
}
private ListBox createPriorityListBox() {
final ListBox result = new ListBox();
result.addItem(stringMessages.selectARole(), "");
for (final AuthorPriority priority : AuthorPriority.values()) {
result.addItem(AuthorPriorityFormatter.getDescription(priority, stringMessages), Integer.toString(priority.getPriority()));
}
return result;
}
/**
* Obtains those events the user can UPDATE and presents them in the {@link #eventListBox} such that the visible string is
* the event's name and the
@@ -253,7 +270,7 @@ public class DeviceConfigurationDetailComposite extends Composite {
}
private void setupGeneral() {
Grid grid = new Grid(7, 2);
Grid grid = new Grid(8, 2);
int row = 0;
identifierBox = new TextBox();
identifierBox.setWidth("80%");
@@ -278,6 +295,8 @@ public class DeviceConfigurationDetailComposite extends Composite {
grid.setWidget(row++, 1, eventListBox);
grid.setWidget(row, 0, new Label(stringMessages.courseArea()));
grid.setWidget(row++, 1, courseAreaListBox);
grid.setWidget(row, 0, new Label(stringMessages.authorPriority()));
grid.setWidget(row++, 1, priorityListBox);
fillEventAndCourseAreaListBoxes();
contentPanel.add(grid);
}
@@ -368,6 +387,9 @@ public class DeviceConfigurationDetailComposite extends Composite {
if (!courseAreaListBox.getSelectedValue().isEmpty()) {
result.courseAreaId = UUID.fromString(courseAreaListBox.getSelectedValue());
}
if (!priorityListBox.getSelectedValue().isEmpty()) {
result.priority = Integer.decode(priorityListBox.getSelectedValue());
}
return result;
}
@@ -2400,4 +2400,8 @@ public interface StringMessages extends com.sap.sse.gwt.client.StringMessages,
String sharingLinkCopied();
String startOfTrackingMustNotBeAfterEndOfTracking();
String identifier();
String selectARole();
String raceOfficerOnVessel();
String shoreControl();
String demoMode();
}
@@ -2403,4 +2403,8 @@ insufficientPermissions=The current user has insufficient permissions for this a
manageEvents=Manage Events
sharingLinkCopied=Copied link to clipboard!
startOfTrackingMustNotBeAfterEndOfTracking=Start of tracking must not be after end of tracking
identifier=Identifier
identifier=Identifier
selectARole=Select a role
raceOfficerOnVessel=Officer on vessel
shoreControl=Shore control
demoMode=Demo mode
@@ -2411,4 +2411,8 @@ insufficientPermissions=Aktuelle Berechtigungen reichen nicht aus um die gewähl
manageEvents=Events Verwalten
sharingLinkCopied=Copied link to clipboard!
startOfTrackingMustNotBeAfterEndOfTracking=Startzeitpunkt des Trackings darf nicht nach dessen Endzeitpunkt liegen
identifier=Kennung
identifier=Kennung
selectARole=Rolle auswählen
raceOfficerOnVessel=Wettfahrtleiter auf dem Wasser
shoreControl=Team an Land
demoMode=Demomodus
@@ -4590,6 +4590,7 @@ public class SailingServiceImpl extends ResultCachingProxiedRemoteServiceServlet
dto.byNameDesignerCourseNames = configuration.getByNameCourseDesignerCourseNames();
configuration.getEventId().ifPresent(eventId->dto.eventId = eventId);
configuration.getCourseAreaId().ifPresent(courseAreaId->dto.courseAreaId = courseAreaId);
configuration.getPriority().ifPresent(priority->dto.priority = priority);
if (configuration.getRegattaConfiguration() != null) {
dto.regattaConfiguration = convertToRegattaConfigurationDTO(configuration.getRegattaConfiguration());
}
@@ -4603,11 +4604,9 @@ public class SailingServiceImpl extends ResultCachingProxiedRemoteServiceServlet
return null;
}
DeviceConfigurationDTO.RegattaConfigurationDTO dto = new DeviceConfigurationDTO.RegattaConfigurationDTO();
dto.defaultRacingProcedureType = configuration.getDefaultRacingProcedureType();
dto.defaultCourseDesignerMode = configuration.getDefaultCourseDesignerMode();
dto.defaultProtestTimeDuration = configuration.getDefaultProtestTimeDuration();
if (configuration.getRRS26Configuration() != null) {
dto.rrs26Configuration = new DeviceConfigurationDTO.RegattaConfigurationDTO.RRS26ConfigurationDTO();
copyBasicRacingProcedureProperties(configuration.getRRS26Configuration(), dto.rrs26Configuration);
@@ -5805,6 +5804,7 @@ public class SailingServiceImpl extends ResultCachingProxiedRemoteServiceServlet
return type;
}
@Override
public String openRegattaRegistrationQrCode(String url) {
String result = "";
try (DataInputStream imageIs = new DataInputStream(QRCodeGenerationUtil.create(url, 600, "H"))) {
@@ -3548,6 +3548,7 @@ public class SailingServiceWriteImpl extends SailingServiceImpl implements Saili
configuration.setByNameDesignerCourseNames(dto.byNameDesignerCourseNames);
configuration.setEventId(dto.eventId);
configuration.setCourseAreaId(dto.courseAreaId);
configuration.setPriority(dto.priority);
return configuration;
}
@@ -80,5 +80,8 @@ public class DeviceConfigurationDTO implements IsSerializable {
*/
public UUID courseAreaId;
public int priority;
/**
* The priority with which the user logs on (shore control, on water, ...).
*/
public Integer priority;
}
@@ -62,6 +62,9 @@ public class DeviceConfigurationJsonDeserializer implements JsonDeserializer<Dev
if (object.containsKey(DeviceConfigurationJsonSerializer.FIELD_COURSE_AREA_ID)) {
configuration.setCourseAreaId(UUID.fromString((String) object.get(DeviceConfigurationJsonSerializer.FIELD_COURSE_AREA_ID)));
}
if (object.containsKey(DeviceConfigurationJsonSerializer.FIELD_PRIORITY)) {
configuration.setPriority(((Number) object.get(DeviceConfigurationJsonSerializer.FIELD_PRIORITY)).intValue());
}
return configuration;
}
@@ -16,6 +16,7 @@ public class DeviceConfigurationJsonSerializer implements JsonSerializer<DeviceC
public static final String FIELD_REGATTA_CONFIGURATION = "procedures";
public static final String FIELD_EVENT_ID = "eventId";
public static final String FIELD_COURSE_AREA_ID = "courseAreaId";
public static final String FIELD_PRIORITY = "priority";
public static DeviceConfigurationJsonSerializer create() {
return new DeviceConfigurationJsonSerializer(RegattaConfigurationJsonSerializer.create());
@@ -51,6 +52,7 @@ public class DeviceConfigurationJsonSerializer implements JsonSerializer<DeviceC
}
object.getEventId().ifPresent(eventId->result.put(FIELD_EVENT_ID, eventId.toString()));
object.getCourseAreaId().ifPresent(courseAreaId->result.put(FIELD_COURSE_AREA_ID, courseAreaId.toString()));
object.getPriority().ifPresent(priority->result.put(FIELD_PRIORITY, priority));
return result;
}
@@ -48,9 +48,9 @@ public class PositionListFragment extends LoggableListFragment {
values.clear();
values.add(new LoginTypeItem(PRIORITY_OFFICER_VESSEL, getString(R.string.login_type_officer_on_vessel),
AppConstants.AUTHOR_TYPE_OFFICER_VESSEL, LoginType.OFFICER));
AppConstants.AUTHOR_TYPE_OFFICER_VESSEL /* TODO bug 5456: use user name instead */, LoginType.OFFICER));
values.add(new LoginTypeItem(PRIORITY_SHORE_CONTROL, getString(R.string.login_type_shore_control),
AppConstants.AUTHOR_TYPE_SHORE_CONTROL, LoginType.OFFICER));
AppConstants.AUTHOR_TYPE_SHORE_CONTROL /* TODO bug 5456: use user name instead */, LoginType.OFFICER));
// TODO define configuration to activate super user
// values.add(new LoginTypeItem(0, getString(R.string.login_type_superuser), AppConstants.AUTHOR_TYPE_SUPERUSER,
// LoginType.OFFICER));