Bug 4100: Swapped component path element order to simply allow using an

iterator instead of always removing the last entry and checking for
emptiness
This commit is contained in:
Steffen Schaefer committed 2017-06-26 13:37:26 +02:00
1 parent 8c2c82fa60
commit b583b4c8da
13 files changed
+65 -113

No files matched your search

@@ -1,8 +1,5 @@
package com.sap.sse.security.ui.settings;
import java.util.ArrayList;
import java.util.List;
import com.sap.sse.common.settings.Settings;
import com.sap.sse.common.settings.generic.GenericSerializableSettings;
import com.sap.sse.common.settings.generic.SettingsMap;
@@ -204,8 +201,8 @@ public class ComponentContextWithSettingsStorage<S extends Settings> extends Sim
@Override
public <CS extends Settings> void makeSettingsDefault(Component<CS> component, CS newDefaultSettings,
final OnSettingsStoredCallback onSettingsStoredCallback) {
List<String> path = component.getPath();
ComponentLifecycle<CS> targetLifecycle = ComponentUtils.determineLifecycle(new ArrayList<>(path),
Iterable<String> path = component.getPath();
ComponentLifecycle<CS> targetLifecycle = ComponentUtils.determineLifecycle(path,
rootLifecycle);
CS userSettings = targetLifecycle.extractUserSettings(newDefaultSettings);
updateUserSettings(path, userSettings, targetLifecycle.createDefaultSettings(), onSettingsStoredCallback);
@@ -226,8 +223,8 @@ public class ComponentContextWithSettingsStorage<S extends Settings> extends Sim
@Override
public <CS extends Settings> void storeSettingsForContext(Component<CS> component, CS newSettings,
OnSettingsStoredCallback onSettingsStoredCallback) {
List<String> path = component.getPath();
ComponentLifecycle<CS> targetLifecycle = ComponentUtils.determineLifecycle(new ArrayList<>(path),
Iterable<String> path = component.getPath();
ComponentLifecycle<CS> targetLifecycle = ComponentUtils.determineLifecycle(path,
rootLifecycle);
CS documentSettings = targetLifecycle.extractDocumentSettings(newSettings);
updateDocumentSettings(component.getPath(), documentSettings, targetLifecycle.createDefaultSettings(),
@@ -237,14 +234,14 @@ public class ComponentContextWithSettingsStorage<S extends Settings> extends Sim
@Override
public <CS extends Settings> void resetSettingsToDefault(Component<CS> component, CS newSettings,
OnSettingsLoadedCallback<CS> onSettingsStoredCallback) {
List<String> path = component.getPath();
ComponentLifecycle<CS> targetLifecycle = ComponentUtils.determineLifecycle(new ArrayList<>(path),
Iterable<String> path = component.getPath();
ComponentLifecycle<CS> targetLifecycle = ComponentUtils.determineLifecycle(path,
rootLifecycle);
removeGlobalAndContextSettings(path, targetLifecycle, new OnSettingsStoredCallback() {
@Override
public void onSuccess() {
getInitialSettingsForComponent(component, onSettingsStoredCallback);
getInitialSettingsForComponent(component, onSettingsStoredCallback);
}
@Override
@@ -255,7 +252,7 @@ public class ComponentContextWithSettingsStorage<S extends Settings> extends Sim
}
private void removeGlobalAndContextSettings(List<String> path, ComponentLifecycle<?> targetLifecycle,
private void removeGlobalAndContextSettings(Iterable<String> path, ComponentLifecycle<?> targetLifecycle,
OnSettingsStoredCallback onSettingsStoredCallback) {
settingsStorageManager.retrieveSettingsRepresentation(
new OnSettingsLoadedCallback<StorableRepresentationOfDocumentAndUserSettings>() {
@@ -270,11 +267,11 @@ public class ComponentContextWithSettingsStorage<S extends Settings> extends Sim
public void onSuccess(StorableRepresentationOfDocumentAndUserSettings settingsRepresentation) {
StorableSettingsRepresentation documentSettingsRepresentationRoot = StorableSettingsRepresentation
.patchSettingsRepresentation(settingsRepresentation.getDocumentSettingsRepresentation(),
new ArrayList<>(path), null);
path, null);
StorableSettingsRepresentation userSettingsRepresentationRoot = StorableSettingsRepresentation
.patchSettingsRepresentation(settingsRepresentation.getUserSettingsRepresentation(),
new ArrayList<>(path), null);
path, null);
StorableRepresentationOfDocumentAndUserSettings settingsRepresentationToStore = new StorableRepresentationOfDocumentAndUserSettings(
userSettingsRepresentationRoot, documentSettingsRepresentationRoot);
@@ -300,7 +297,7 @@ public class ComponentContextWithSettingsStorage<S extends Settings> extends Sim
* @param onSettingsStoredCallback
* The callback which is called when the settings storage process finishes
*/
private<CS extends Settings> void updateUserSettings(final List<String> path, final Settings newUserSettings, final CS newInstance,
private<CS extends Settings> void updateUserSettings(final Iterable<String> path, final Settings newUserSettings, final CS newInstance,
final OnSettingsStoredCallback onSettingsStoredCallback) {
settingsStorageManager.retrieveSettingsRepresentation(
new OnSettingsLoadedCallback<StorableRepresentationOfDocumentAndUserSettings>() {
@@ -315,7 +312,7 @@ public class ComponentContextWithSettingsStorage<S extends Settings> extends Sim
public void onSuccess(StorableRepresentationOfDocumentAndUserSettings settingsRepresentation) {
StorableSettingsRepresentation newUserSettingsRepresentationOfComponent = settingsBuildingPipeline.getStorableRepresentationOfUserSettings(newUserSettings, newInstance, path);
StorableSettingsRepresentation userSettingsRepresentationRoot = StorableSettingsRepresentation.patchSettingsRepresentation(
settingsRepresentation.getUserSettingsRepresentation(), new ArrayList<>(path),
settingsRepresentation.getUserSettingsRepresentation(), path,
newUserSettingsRepresentationOfComponent);
cachedSettingsRepresentation = new StorableRepresentationOfDocumentAndUserSettings(
@@ -346,7 +343,7 @@ public class ComponentContextWithSettingsStorage<S extends Settings> extends Sim
* @param onSettingsStoredCallback
* The callback which is called when the settings storage process finishes
*/
private<CS extends Settings> void updateDocumentSettings(final ArrayList<String> path, final CS newDocumentSettings, final CS newInstance,
private<CS extends Settings> void updateDocumentSettings(final Iterable<String> path, final CS newDocumentSettings, final CS newInstance,
final OnSettingsStoredCallback onSettingsStoredCallback) {
settingsStorageManager.retrieveSettingsRepresentation(
new OnSettingsLoadedCallback<StorableRepresentationOfDocumentAndUserSettings>() {
@@ -361,7 +358,7 @@ public class ComponentContextWithSettingsStorage<S extends Settings> extends Sim
public void onSuccess(StorableRepresentationOfDocumentAndUserSettings settingsRepresentation) {
StorableSettingsRepresentation newDocumentSettingsRepresentationOfComponent = settingsBuildingPipeline.getStorableRepresentationOfDocumentSettings(newDocumentSettings, newInstance, cachedSettingsRepresentation, path);
StorableSettingsRepresentation documentSettingsRepresentationRoot = StorableSettingsRepresentation.patchSettingsRepresentation(
settingsRepresentation.getDocumentSettingsRepresentation(), new ArrayList<>(path),
settingsRepresentation.getDocumentSettingsRepresentation(), path,
newDocumentSettingsRepresentationOfComponent);
cachedSettingsRepresentation = new StorableRepresentationOfDocumentAndUserSettings(
@@ -1,7 +1,5 @@
package com.sap.sse.security.ui.settings;
import java.util.ArrayList;
import com.sap.sse.common.settings.Settings;
import com.sap.sse.gwt.client.shared.components.Component;
import com.sap.sse.gwt.client.shared.components.ComponentLifecycle;
@@ -155,14 +153,14 @@ public class SimpleComponentContext<S extends Settings> implements ComponentCont
@Override
public void onError(Throwable caught, S fallbackDefaultSettings) {
CS componentFallbackSettings = ComponentUtils.determineComponentSettingsFromPerspectiveSettings(
new ArrayList<>(component.getPath()), fallbackDefaultSettings);
component.getPath(), fallbackDefaultSettings);
callback.onError(caught, componentFallbackSettings);
}
@Override
public void onSuccess(S settings) {
CS componentSettings = ComponentUtils.determineComponentSettingsFromPerspectiveSettings(
new ArrayList<>(component.getPath()), settings);
component.getPath(), settings);
callback.onSuccess(componentSettings);
}
};
@@ -1,7 +1,5 @@
package com.sap.sse.security.ui.settings;
import java.util.List;
import com.sap.sse.common.settings.Settings;
import com.sap.sse.gwt.client.shared.settings.ComponentContext;
import com.sap.sse.gwt.client.shared.settings.SettingsBuildingPipeline;
@@ -56,7 +54,7 @@ public class UrlSettingsBuildingPipeline implements SettingsBuildingPipeline {
* representation, because it is supposed to be used by read-only {@link ComponentContext} implementations.
*/
@Override
public <CS extends Settings> StorableSettingsRepresentation getStorableRepresentationOfUserSettings(CS newSettings, CS newInstance, List<String> path) {
public <CS extends Settings> StorableSettingsRepresentation getStorableRepresentationOfUserSettings(CS newSettings, CS newInstance, Iterable<String> path) {
throw new UnsupportedOperationException("This pipeline does not support JSON conversion");
}
@@ -65,7 +63,7 @@ public class UrlSettingsBuildingPipeline implements SettingsBuildingPipeline {
* representation, because it is supposed to be used by read-only {@link ComponentContext} implementations.
*/
@Override
public <CS extends Settings> StorableSettingsRepresentation getStorableRepresentationOfDocumentSettings(CS newSettings, CS newInstance, StorableRepresentationOfDocumentAndUserSettings previousSettingsRepresentation, List<String> path) {
public <CS extends Settings> StorableSettingsRepresentation getStorableRepresentationOfDocumentSettings(CS newSettings, CS newInstance, StorableRepresentationOfDocumentAndUserSettings previousSettingsRepresentation, Iterable<String> path) {
throw new UnsupportedOperationException("This pipeline does not support JSON conversion");
}
@@ -1,7 +1,5 @@
package com.sap.sse.security.ui.settings;
import java.util.List;
import com.sap.sse.common.settings.Settings;
import com.sap.sse.common.settings.generic.support.SettingsUtil;
import com.sap.sse.gwt.client.shared.settings.SettingsRepresentationTransformer;
@@ -86,7 +84,7 @@ public class UserSettingsBuildingPipeline extends UrlSettingsBuildingPipeline {
*/
@Override
public <CS extends Settings> StorableSettingsRepresentation getStorableRepresentationOfUserSettings(CS newSettings,
CS newInstance, List<String> path) {
CS newInstance, Iterable<String> path) {
return settingsRepresentationTransformer.convertToSettingsRepresentation(newSettings);
}
@@ -112,7 +110,7 @@ public class UserSettingsBuildingPipeline extends UrlSettingsBuildingPipeline {
@Override
public <CS extends Settings> StorableSettingsRepresentation getStorableRepresentationOfDocumentSettings(
CS newSettings, CS newInstance,
StorableRepresentationOfDocumentAndUserSettings previousSettingsRepresentation, List<String> path) {
StorableRepresentationOfDocumentAndUserSettings previousSettingsRepresentation, Iterable<String> path) {
CS documentSettingsWithUserSettingsDiff;
if (previousSettingsRepresentation.hasStoredUserSettings()) {
CS pipelinedSettings = SettingsUtil.copyDefaultsFromValues(newInstance, newInstance);
@@ -7,6 +7,7 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import com.sap.sse.common.Util;
import com.sap.sse.common.settings.Settings;
import com.sap.sse.common.settings.generic.GenericSerializableSettings;
import com.sap.sse.common.settings.generic.support.SettingsUtil;
@@ -84,16 +85,16 @@ public class UserSettingsBuildingPipelineWithAdditionalSettingsLayers extends Us
}
protected static <CS extends Settings> CS applyPatchesForPipelineLevel(CS currentSettings,
PipelineLevel pipelineLevel, List<String> absolutePathOfComponentWithSettings,
PipelineLevel pipelineLevel, Iterable<String> absolutePathOfComponentWithSettings,
SettingsPatches settingsPatchesToConsider) {
CS effectiveSettings = currentSettings;
for (Entry<List<String>, List<SettingsPatch<? extends Settings>>> entry : settingsPatchesToConsider
.getSettingsPatches(pipelineLevel).entrySet()) {
List<String> path = new ArrayList<>(entry.getKey());
if (path.size() >= absolutePathOfComponentWithSettings.size()
&& path.subList(path.size() - absolutePathOfComponentWithSettings.size(), path.size())
if (path.size() >= Util.size(absolutePathOfComponentWithSettings)
&& path.subList(path.size() - Util.size(absolutePathOfComponentWithSettings), path.size())
.equals(absolutePathOfComponentWithSettings)) {
path = path.subList(0, path.size() - absolutePathOfComponentWithSettings.size());
path = path.subList(0, path.size() - Util.size(absolutePathOfComponentWithSettings));
List<SettingsPatch<? extends Settings>> settingsPatches = entry.getValue();
if (!settingsPatches.isEmpty()) {
Settings patchedComponentSettings = ComponentUtils
@@ -136,7 +137,7 @@ public class UserSettingsBuildingPipelineWithAdditionalSettingsLayers extends Us
*/
@Override
public <CS extends Settings> StorableSettingsRepresentation getStorableRepresentationOfUserSettings(CS newSettings,
CS newInstance, List<String> path) {
CS newInstance, Iterable<String> path) {
CS pipelinedSettings = SettingsUtil.copyDefaultsFromValues(newInstance, newInstance);
pipelinedSettings = SettingsUtil.copyDefaults(newSettings, newInstance); // overrides values which are set to
// default values
@@ -173,7 +174,7 @@ public class UserSettingsBuildingPipelineWithAdditionalSettingsLayers extends Us
@Override
public <CS extends Settings> StorableSettingsRepresentation getStorableRepresentationOfDocumentSettings(
CS newSettings, CS newInstance,
StorableRepresentationOfDocumentAndUserSettings previousSettingsRepresentation, List<String> path) {
StorableRepresentationOfDocumentAndUserSettings previousSettingsRepresentation, Iterable<String> path) {
CS pipelinedSettings = SettingsUtil.copyDefaultsFromValues(newInstance, newInstance);
pipelinedSettings = SettingsUtil.copyDefaults(newSettings, newInstance); // overrides values which are set to
// default values
@@ -241,7 +242,7 @@ public class UserSettingsBuildingPipelineWithAdditionalSettingsLayers extends Us
private Map<PipelineLevel, Map<List<String>, List<SettingsPatch<? extends Settings>>>> patchesForSettings = new HashMap<>();
public void addSettingsPatch(List<String> path, SettingsPatch<? extends Settings> settingsPatch,
public void addSettingsPatch(Iterable<String> path, SettingsPatch<? extends Settings> settingsPatch,
PipelineLevel pipelineLevel) {
Map<List<String>, List<SettingsPatch<? extends Settings>>> pipelinePatches = patchesForSettings
.get(pipelineLevel);
@@ -252,7 +253,7 @@ public class UserSettingsBuildingPipelineWithAdditionalSettingsLayers extends Us
List<SettingsPatch<? extends Settings>> componentPatches = pipelinePatches.get(path);
if (componentPatches == null) {
componentPatches = new ArrayList<>();
pipelinePatches.put(path, componentPatches);
pipelinePatches.put(Util.asList(path), componentPatches);
}
componentPatches.add(settingsPatch);
}