mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-11 05:12:43 +00:00
Bug 4211 added SaveSailorProfileAction and associated preferences and
settings objects (SailorProfilePreference, SailorProfilePreferences, SailorProfileSettings) + SailorProfile and SailorProfileImpl classes. TODO: implement fromStringValue-method in SailorProfileSetting.Converter to ensure correct deserialization
This commit is contained in:
1 parent
e50b85f953
commit
6a52fb8b8b
6 files changed
+260
No files matched your search
+12
@@ -0,0 +1,12 @@
|
||||
package com.sap.sailing.domain.base;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import com.sap.sse.common.IsManagedByCache;
|
||||
import com.sap.sse.common.NamedWithID;
|
||||
|
||||
public interface SailorProfile extends NamedWithID, IsManagedByCache<SharedDomainFactory> {
|
||||
String getName();
|
||||
|
||||
UUID getUuid();
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package com.sap.sailing.domain.base.impl;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.sap.sailing.domain.base.SailorProfile;
|
||||
import com.sap.sailing.domain.base.SharedDomainFactory;
|
||||
import com.sap.sse.common.IsManagedByCache;
|
||||
import com.sap.sse.common.impl.NamedImpl;
|
||||
|
||||
public class SailorProfileImpl extends NamedImpl implements SailorProfile {
|
||||
private static final long serialVersionUID = -2714015903187029053L;
|
||||
|
||||
private UUID uuid;
|
||||
|
||||
public SailorProfileImpl(String name, UUID uuid) {
|
||||
this(name);
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public SailorProfileImpl(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Serializable getId() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IsManagedByCache<SharedDomainFactory> resolve(SharedDomainFactory domainFactory) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package com.sap.sailing.gwt.home.communication.user.profile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gwt.core.shared.GwtIncompatible;
|
||||
import com.sap.sailing.domain.base.DomainFactory;
|
||||
import com.sap.sailing.domain.base.SailorProfile;
|
||||
import com.sap.sailing.domain.base.impl.SailorProfileImpl;
|
||||
import com.sap.sailing.gwt.home.communication.SailingAction;
|
||||
import com.sap.sailing.gwt.home.communication.SailingDispatchContext;
|
||||
import com.sap.sailing.gwt.home.communication.user.profile.domain.SailorProfileEntry;
|
||||
import com.sap.sailing.server.impl.preferences.model.SailorProfilePreference;
|
||||
import com.sap.sailing.server.impl.preferences.model.SailorProfilePreferences;
|
||||
import com.sap.sse.gwt.dispatch.shared.commands.VoidResult;
|
||||
import com.sap.sse.gwt.dispatch.shared.exceptions.DispatchException;
|
||||
|
||||
/**
|
||||
* {@link SailingAction} implementation to save favorite boat classes for the currently logged in user as selected on
|
||||
* the preferences page.
|
||||
*/
|
||||
public class SaveSailorProfileAction implements SailingAction<VoidResult> {
|
||||
|
||||
private SailorProfileEntry sailorProfileEntry;
|
||||
|
||||
protected SaveSailorProfileAction() {}
|
||||
|
||||
public SaveSailorProfileAction(SailorProfileEntry sailorProfileEntry) {
|
||||
this.sailorProfileEntry = sailorProfileEntry;
|
||||
}
|
||||
|
||||
@Override
|
||||
@GwtIncompatible
|
||||
public VoidResult execute(SailingDispatchContext ctx) throws DispatchException {
|
||||
DomainFactory domainFactory = ctx.getRacingEventService().getBaseDomainFactory();
|
||||
|
||||
List<SailorProfilePreference> sailorProfilePreferences = new ArrayList<>();
|
||||
SailorProfilePreferences prefs = ctx.getPreferenceForCurrentUser(SailorProfilePreferences.PREF_NAME);
|
||||
if (prefs == null) {
|
||||
prefs = new SailorProfilePreferences(domainFactory);
|
||||
}
|
||||
|
||||
prefs.updateOrInsert(new SailorProfilePreference(domainFactory, convert(sailorProfileEntry)));
|
||||
|
||||
prefs.setSailorProfiles(sailorProfilePreferences);
|
||||
ctx.setPreferenceForCurrentUser(SailorProfilePreferences.PREF_NAME, prefs);
|
||||
return new VoidResult();
|
||||
}
|
||||
|
||||
@GwtIncompatible
|
||||
private SailorProfile convert(SailorProfileEntry entr) {
|
||||
return new SailorProfileImpl(entr.getName(), entr.getKey());
|
||||
}
|
||||
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package com.sap.sailing.server.impl.preferences.model;
|
||||
|
||||
import com.sap.sailing.domain.base.DomainFactory;
|
||||
import com.sap.sailing.domain.base.SailorProfile;
|
||||
import com.sap.sse.common.settings.generic.AbstractGenericSerializableSettings;
|
||||
|
||||
public class SailorProfilePreference extends AbstractGenericSerializableSettings {
|
||||
private static final long serialVersionUID = 8324742146089597693L;
|
||||
private transient SailorProfileSetting sailorProfile;
|
||||
|
||||
public SailorProfilePreference(DomainFactory domainFactory) {
|
||||
sailorProfile = new SailorProfileSetting("sailorProfile", this, domainFactory);
|
||||
}
|
||||
|
||||
public SailorProfilePreference(DomainFactory domainFactory, SailorProfile sailorProfile) {
|
||||
this(domainFactory);
|
||||
this.sailorProfile.setValue(sailorProfile);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addChildSettings() {
|
||||
// We do not create the Setting instances here, because access to the RacingEventService would not be given.
|
||||
// Doing this, Java/GWT Serialization isn't working anymore. Because the preferences are only serialized as JSON
|
||||
// in the backend an transferred as DTO to the frontend, this isn't a problem. Due to usage of BoatClass and
|
||||
// Competitor domain objects, it wouldn't be GWT compatible anyway.
|
||||
// The usage of Java Serialization isn't planned by now, either.
|
||||
}
|
||||
|
||||
public SailorProfile getSailorProfile() {
|
||||
return sailorProfile.getValue();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
package com.sap.sailing.server.impl.preferences.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.sap.sailing.domain.base.DomainFactory;
|
||||
import com.sap.sse.common.settings.generic.AbstractGenericSerializableSettings;
|
||||
import com.sap.sse.common.settings.generic.SettingsList;
|
||||
|
||||
public class SailorProfilePreferences extends AbstractGenericSerializableSettings {
|
||||
private static final long serialVersionUID = -3773945485974367205L;
|
||||
|
||||
// TODO: setting preference title
|
||||
public static final String PREF_NAME = "sailorProfiles";
|
||||
|
||||
private transient SettingsList<SailorProfilePreference> sailorProfiles;
|
||||
|
||||
public SailorProfilePreferences(DomainFactory domainFactory) {
|
||||
sailorProfiles = new SettingsList<>("sailorProfiles", this, () -> new SailorProfilePreference(domainFactory));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addChildSettings() {
|
||||
}
|
||||
|
||||
public Iterable<SailorProfilePreference> getSailorProfiles() {
|
||||
return sailorProfiles.getValues();
|
||||
}
|
||||
|
||||
public void setSailorProfiles(Iterable<SailorProfilePreference> sailorProfiles) {
|
||||
this.sailorProfiles.setValues(sailorProfiles);
|
||||
}
|
||||
|
||||
public void updateOrInsert(final SailorProfilePreference sailorProfilePreference) {
|
||||
|
||||
boolean noElementChanged = true;
|
||||
// copy to list
|
||||
List<SailorProfilePreference> list = new ArrayList<>();
|
||||
for (SailorProfilePreference p : sailorProfiles.getValues()) {
|
||||
noElementChanged = p.getSailorProfile().equals(sailorProfilePreference.getSailorProfile());
|
||||
list.add(p);
|
||||
}
|
||||
|
||||
if (!noElementChanged) {
|
||||
// replace if necessary
|
||||
Iterator<SailorProfilePreference> it = list.iterator();
|
||||
SailorProfilePreference pref;
|
||||
while ((pref = it.next()) != null) {
|
||||
if (pref.getSailorProfile().equals(sailorProfilePreference.getSailorProfile())) {
|
||||
it.remove();
|
||||
list.add(sailorProfilePreference);
|
||||
}
|
||||
|
||||
}
|
||||
sailorProfiles.setValues(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
package com.sap.sailing.server.impl.preferences.model;
|
||||
|
||||
import com.sap.sailing.domain.base.BoatClass;
|
||||
import com.sap.sailing.domain.base.DomainFactory;
|
||||
import com.sap.sailing.domain.base.SailorProfile;
|
||||
import com.sap.sse.common.settings.generic.AbstractGenericSerializableSettings;
|
||||
import com.sap.sse.common.settings.generic.ValueConverter;
|
||||
import com.sap.sse.common.settings.generic.base.AbstractValueSetting;
|
||||
import com.sap.sse.common.settings.value.StringValue;
|
||||
import com.sap.sse.common.settings.value.Value;
|
||||
|
||||
/**
|
||||
* Specific setting to hold a {@link BoatClass} instance. The competitor is being serialized using the boat classes'
|
||||
* name and deserialized using the given {@link DomainFactory}.
|
||||
*/
|
||||
public class SailorProfileSetting extends AbstractValueSetting<SailorProfile> {
|
||||
|
||||
protected SailorProfileSetting(String name, AbstractGenericSerializableSettings settings, DomainFactory domainFactory) {
|
||||
super(name, settings, null, new Converter());
|
||||
}
|
||||
|
||||
public static class Converter implements ValueConverter<SailorProfile> {
|
||||
|
||||
|
||||
public Converter() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object toJSONValue(SailorProfile value) {
|
||||
return toStringValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SailorProfile fromJSONValue(Object jsonValue) {
|
||||
return fromStringValue((String) jsonValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toStringValue(SailorProfile value) {
|
||||
return value == null ? null : value.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SailorProfile fromStringValue(String stringValue) {
|
||||
// TODO implement to return correct sailor profile
|
||||
return stringValue == null ? null : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SailorProfile fromValue(Value value) {
|
||||
return fromStringValue(((StringValue) value).getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value toValue(SailorProfile value) {
|
||||
return new StringValue(toStringValue(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user