Skip to content

Commit

Permalink
Fix variable override
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienlauer committed Sep 4, 2018
1 parent 0a9cd4c commit 4b542da
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 30 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Version 3.2.6 (2018-09-04)

* [fix] Make fragment variables from explicit `w20.app.json` configuration take precedence over default ones.

# Version 3.2.5 (2018-08-06)

* [nfo] w20: [2.5.1](https://github.com/w20-framework/w20/releases/tag/v2.5.1)
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<groupId>org.seedstack.addons.w20</groupId>
<artifactId>w20-bridge</artifactId>
<version>3.2.5-SNAPSHOT</version>
<version>3.2.6-SNAPSHOT</version>
<packaging>pom</packaging>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion rest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>org.seedstack.addons.w20</groupId>
<artifactId>w20-bridge</artifactId>
<version>3.2.5-SNAPSHOT</version>
<version>3.2.6-SNAPSHOT</version>
</parent>

<artifactId>w20-bridge-rest</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.seedstack.w20.internal.rest.application;

package org.seedstack.w20.internal.rest.application;

import com.google.inject.Inject;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletContext;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import org.seedstack.seed.web.WebResourceResolverFactory;
import org.seedstack.w20.AnonymousFragmentDeclaration;
import org.seedstack.w20.ConfiguredFragmentDeclaration;
Expand All @@ -19,16 +28,6 @@
import org.seedstack.w20.internal.PathUtils;
import org.seedstack.w20.internal.rest.EmptyObjectRepresentation;

import javax.servlet.ServletContext;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;

/**
* This REST resource generates the W20 application configuration.
*
Expand All @@ -55,7 +54,8 @@ public Map<String, Object> getConfiguration() {

for (FragmentDeclaration declaredFragment : fragmentManager.getDeclaredFragments()) {
if (declaredFragment instanceof AnonymousFragmentDeclaration) {
configuredFragmentRepresentations.put("", ((AnonymousFragmentDeclaration) declaredFragment).getContents());
configuredFragmentRepresentations.put("",
((AnonymousFragmentDeclaration) declaredFragment).getContents());
} else if (declaredFragment instanceof ConfiguredFragmentDeclaration) {
ConfiguredFragmentDeclaration configuredFragment = (ConfiguredFragmentDeclaration) declaredFragment;
ConfiguredFragmentRepresentation value = new ConfiguredFragmentRepresentation();
Expand All @@ -67,7 +67,8 @@ public Map<String, Object> getConfiguration() {
Map<String, Object> modules = new HashMap<>();
for (ConfiguredModule configuredModule : configuredFragment.getModules().values()) {
Object configuration = configuredModule.getConfiguration();
modules.put(configuredModule.getName(), configuration != null ? configuration : new EmptyObjectRepresentation());
modules.put(configuredModule.getName(),
configuration != null ? configuration : new EmptyObjectRepresentation());
}
value.setModules(modules);

Expand All @@ -77,19 +78,26 @@ public Map<String, Object> getConfiguration() {
value.setRoutes(routes);
}

Map<String, String> vars = configuredFragment.getVars() != null ? configuredFragment.getVars() : new HashMap<>();
// Add the default variables and copy explicit variables if any
Map<String, String> vars = new HashMap<>();
populateVars(vars);
Map<String, String> explicitVars = configuredFragment.getVars();
if (explicitVars != null) {
vars.putAll(explicitVars);
}
value.setVars(vars);

if (configuredFragment.getManifestLocation() != null) {
// Only includes scanned fragments if a resource resolver is available, otherwise they must be configured manually
// Only includes scanned fragments if a resource resolver is available, otherwise they must be
// configured manually
if (webResourceResolverFactory != null) {
URI resolvedUri = webResourceResolverFactory
.createWebResourceResolver(servletContext)
.resolveURI(configuredFragment.getManifestLocation());

if (resolvedUri == null) {
throw new IllegalArgumentException("Unable to resolve a web serving path for fragment " + configuredFragment.getName());
throw new IllegalArgumentException("Unable to resolve a web serving path for fragment " + configuredFragment
.getName());
}

configuredFragmentRepresentations.put(resolvedUri.toString(), value);
Expand All @@ -110,6 +118,7 @@ private void populateVars(Map<String, String> vars) {
vars.put("seed-rest-path", PathUtils.removeTrailingSlash(masterPageBuilder.getRestPath(contextPath)));
vars.put("seed-rest-path-slash", PathUtils.ensureTrailingSlash(masterPageBuilder.getRestPath(contextPath)));
vars.put("components-path", PathUtils.removeTrailingSlash(masterPageBuilder.getComponentsPath(contextPath)));
vars.put("components-path-slash", PathUtils.ensureTrailingSlash(masterPageBuilder.getComponentsPath(contextPath)));
vars.put("components-path-slash",
PathUtils.ensureTrailingSlash(masterPageBuilder.getComponentsPath(contextPath)));
}
}
2 changes: 1 addition & 1 deletion specs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.seedstack.addons.w20</groupId>
<artifactId>w20-bridge</artifactId>
<version>3.2.5-SNAPSHOT</version>
<version>3.2.6-SNAPSHOT</version>
</parent>

<artifactId>w20-bridge-specs</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion web-bootstrap-2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>org.seedstack.addons.w20</groupId>
<artifactId>w20-bridge</artifactId>
<version>3.2.5-SNAPSHOT</version>
<version>3.2.6-SNAPSHOT</version>
</parent>

<artifactId>w20-bridge-web-bootstrap-2</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion web-bootstrap-3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>org.seedstack.addons.w20</groupId>
<artifactId>w20-bridge</artifactId>
<version>3.2.5-SNAPSHOT</version>
<version>3.2.6-SNAPSHOT</version>
</parent>

<artifactId>w20-bridge-web-bootstrap-3</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion web-business-theme/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>org.seedstack.addons.w20</groupId>
<artifactId>w20-bridge</artifactId>
<version>3.2.5-SNAPSHOT</version>
<version>3.2.6-SNAPSHOT</version>
</parent>

<artifactId>w20-bridge-web-business-theme</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion web-components/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>org.seedstack.addons.w20</groupId>
<artifactId>w20-bridge</artifactId>
<version>3.2.5-SNAPSHOT</version>
<version>3.2.6-SNAPSHOT</version>
</parent>

<artifactId>w20-bridge-web-components</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion web-dataviz/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>org.seedstack.addons.w20</groupId>
<artifactId>w20-bridge</artifactId>
<version>3.2.5-SNAPSHOT</version>
<version>3.2.6-SNAPSHOT</version>
</parent>

<artifactId>w20-bridge-web-dataviz</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion web-extras/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>org.seedstack.addons.w20</groupId>
<artifactId>w20-bridge</artifactId>
<version>3.2.5-SNAPSHOT</version>
<version>3.2.6-SNAPSHOT</version>
</parent>

<artifactId>w20-bridge-web-extras</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion web-material-theme/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>org.seedstack.addons.w20</groupId>
<artifactId>w20-bridge</artifactId>
<version>3.2.5-SNAPSHOT</version>
<version>3.2.6-SNAPSHOT</version>
</parent>

<artifactId>w20-bridge-web-material-theme</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion web-material/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>org.seedstack.addons.w20</groupId>
<artifactId>w20-bridge</artifactId>
<version>3.2.5-SNAPSHOT</version>
<version>3.2.6-SNAPSHOT</version>
</parent>

<artifactId>w20-bridge-web-material</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion web-simple-theme/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>org.seedstack.addons.w20</groupId>
<artifactId>w20-bridge</artifactId>
<version>3.2.5-SNAPSHOT</version>
<version>3.2.6-SNAPSHOT</version>
</parent>

<artifactId>w20-bridge-web-simple-theme</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>org.seedstack.addons.w20</groupId>
<artifactId>w20-bridge</artifactId>
<version>3.2.5-SNAPSHOT</version>
<version>3.2.6-SNAPSHOT</version>
</parent>

<artifactId>w20-bridge-web</artifactId>
Expand Down

0 comments on commit 4b542da

Please sign in to comment.