Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CIF-1202 - Update the CIF Core Components to use configurations from /conf #184

Merged
merged 32 commits into from
Mar 12, 2020
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
7db229b
CIF-1134 - Unified configuration of site settings
dplaton Jan 17, 2020
901ea0e
Merged local changes with remote
dplaton Jan 28, 2020
c2bda74
CIF-1134 - Unified configuration of site settings
dplaton Jan 28, 2020
e0261af
(WIP) Update unit tests to use the ConfigurationBuilder as well
dplaton Jan 28, 2020
b7f64ed
CIF-1202 - Update the CIF Core Components to use configurations from …
dplaton Jan 29, 2020
4d33336
Merge branch 'master' into issue/CIF-1134
dplaton Jan 29, 2020
22cd4c4
@trivial Fix formatting
dplaton Jan 29, 2020
03a7344
Follow-up on the review:
dplaton Jan 29, 2020
51d1234
@trivial Fix formatting
dplaton Jan 29, 2020
9f4f498
CIF-1201 - Implement the configuration wizard
dplaton Feb 3, 2020
707467c
CIF-1201 - Implement the configuration wizard
dplaton Feb 4, 2020
1fcaf3b
@trivial Fix formatting
dplaton Feb 4, 2020
de8789b
Merge branch 'master' into issue/CIF-1134
dplaton Feb 6, 2020
3245d99
Read the configuration from "cloudconfigs/commerce" instead of "comme…
dplaton Feb 6, 2020
7c26ef7
Update test content to work in the testing environment.
dplaton Feb 7, 2020
85b7b02
Merge branch 'master' into issue/CIF-1134
dplaton Feb 12, 2020
aa75508
Merge branch 'master' into issue/CIF-1134
dplaton Feb 17, 2020
51433cf
Fix the test content after a faulty merge.
dplaton Feb 17, 2020
de1dd15
@trivial Remove extra line
dplaton Feb 17, 2020
998d3ac
Merge branch 'master' into issue/CIF-1134
dplaton Feb 18, 2020
6bc0acc
Merge branch 'master' into issue/CIF-1134
cjelger Feb 26, 2020
603eaf9
CIF-1134 - Unified configuration of site settings
cjelger Feb 26, 2020
c1b2cf5
Merge branch 'master' into issue/CIF-1134
dplaton Feb 26, 2020
ceff093
Fix the navigation to use the context-aware configurations.
dplaton Feb 26, 2020
bfbd3b2
Update the navigation to fall back to reading the configuration from …
dplaton Feb 26, 2020
0169770
Update the navigation to fall back to reading the configuration from …
dplaton Feb 27, 2020
c82b513
Merge branch 'master' into issue/CIF-1134
dplaton Feb 28, 2020
a90a120
Merge branch 'issue/CIF-1134' of github.com:adobe/aem-core-cif-compon…
dplaton Mar 10, 2020
84cb204
Merge branch 'master' into issue/CIF-1134
LSantha Mar 11, 2020
3deb9d8
Merge branch 'issue/CIF-1134' of github.com:adobe/aem-core-cif-compon…
dplaton Mar 12, 2020
4077e9e
Update the unit test to improve the converage of the `NavigationImpl`…
dplaton Mar 12, 2020
5860454
@trivial Fix formatting
dplaton Mar 12, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions bundles/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,12 @@
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.jcr</groupId>
<artifactId>jcr</artifactId>
Expand Down Expand Up @@ -490,6 +496,13 @@
<version>${core.wcm.components.version}</version>
</dependency>

<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.testing.caconfig-mock-plugin</artifactId>
<version>1.3.2</version>
<scope>test</scope>
</dependency>

<!-- CIF Dependencies -->
<dependency>
<groupId>com.adobe.commerce.cif</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@

import java.util.Collections;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.Header;
import org.apache.http.message.BasicHeader;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.caconfig.ConfigurationBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -48,13 +51,16 @@ public class MagentoGraphqlClient {

public static final String STORE_CODE_PROPERTY = "magentoStore";

public static final String CONFIGURATION_NAME = "cloudconfigs/commerce";

private GraphqlClient graphqlClient;

private RequestOptions requestOptions;

/**
* Instantiates and returns a new MagentoGraphqlClient.
* This method returns <code>null</code> if the client cannot be instantiated.
*
*
* @param resource The JCR resource to use to adapt to the lower-level {@link GraphqlClient}.
* @return A new MagentoGraphqlClient instance.
*/
Expand All @@ -75,24 +81,20 @@ private MagentoGraphqlClient(Resource resource) {

requestOptions = new RequestOptions().withGson(QueryDeserializer.getGson());

InheritanceValueMap properties;
Page page = resource.getResourceResolver().adaptTo(PageManager.class).getContainingPage(resource);
if (page != null) {
properties = new HierarchyNodeInheritanceValueMap(page.getContentResource());
} else {
properties = new ComponentInheritanceValueMap(resource);
}
String storeCode;
ConfigurationBuilder configBuilder = resource.adaptTo(ConfigurationBuilder.class);

// get Magento store code
String storeCode = properties.getInherited(STORE_CODE_PROPERTY, String.class);
// for backward compatibility also check of the old cq:magentoStore property
if (storeCode == null) {
storeCode = properties.getInherited("cq:" + STORE_CODE_PROPERTY, String.class);
if (storeCode != null) {
LOGGER.warn("Deprecated 'cq:magentoStore' still in use for {}. Please update to 'magentoStore'.", resource.getPath());
if (configBuilder != null) {
ValueMap properties = configBuilder.name(CONFIGURATION_NAME).asValueMap();
storeCode = properties.get(STORE_CODE_PROPERTY, String.class);
if (storeCode == null) {
storeCode = readFallBackConfiguration(resource, STORE_CODE_PROPERTY);
}
;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this line

} else {
storeCode = readFallBackConfiguration(resource, STORE_CODE_PROPERTY);
}
if (storeCode != null) {
if (StringUtils.isNotEmpty(storeCode)) {
Header storeHeader = new BasicHeader("Store", storeCode);
requestOptions.withHeaders(Collections.singletonList(storeHeader));
}
Expand All @@ -102,7 +104,7 @@ private MagentoGraphqlClient(Resource resource) {
* Executes the given Magento query and returns the response. This method will use
* the default HTTP method defined in the OSGi configuration of the underlying {@link GraphqlClient}.
* Use {@link #execute(String, HttpMethod)} if you want to specify the HTTP method yourself.
*
*
* @param query The GraphQL query.
* @return The GraphQL response.
*/
Expand All @@ -113,19 +115,41 @@ public GraphqlResponse<Query, Error> execute(String query) {
/**
* Executes the given Magento query and returns the response. This method
* uses the given <code>httpMethod</code> to fetch the data.
*
*
* @param query The GraphQL query.
* @param httpMethod The HTTP method that will be used to fetch the data.
* @return The GraphQL response.
*/
public GraphqlResponse<Query, Error> execute(String query, HttpMethod httpMethod) {

// We do not set the HTTP method in 'this.requestOptions' to avoid setting it as the new default
RequestOptions options = new RequestOptions()
.withGson(requestOptions.getGson())
RequestOptions options = new RequestOptions().withGson(requestOptions.getGson())
.withHeaders(requestOptions.getHeaders())
.withHttpMethod(httpMethod);

return graphqlClient.execute(new GraphqlRequest(query), Query.class, Error.class, options);
}

private String readFallBackConfiguration(Resource resource, String propertyName) {

InheritanceValueMap properties;
String storeCode;

Page page = resource.getResourceResolver()
.adaptTo(PageManager.class)
.getContainingPage(resource);
if (page != null) {
properties = new HierarchyNodeInheritanceValueMap(page.getContentResource());
} else {
properties = new ComponentInheritanceValueMap(resource);
}
storeCode = properties.getInherited(propertyName, String.class);
if (storeCode == null) {
storeCode = properties.getInherited("cq:" + propertyName, String.class);
if (storeCode != null) {
LOGGER.warn("Deprecated 'cq:magentoStore' still in use for {}. Please update to 'magentoStore'.", resource.getPath());
}
}
return storeCode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
import org.osgi.service.component.annotations.ReferencePolicy;

import com.adobe.cq.commerce.graphql.client.GraphqlClient;
import com.adobe.granite.ui.components.Config;
import com.adobe.granite.ui.components.ExpressionHelper;
import com.adobe.granite.ui.components.ExpressionResolver;
import com.adobe.granite.ui.components.ds.DataSource;
import com.adobe.granite.ui.components.ds.SimpleDataSource;
import com.day.cq.i18n.I18n;
Expand All @@ -58,6 +61,9 @@ public class GraphqlClientDataSourceServlet extends SlingSafeMethodsServlet {

private Set<String> identifiers = new ConcurrentHashSet<>();

@Reference
private ExpressionResolver expressionResolver;

@Reference(
service = GraphqlClient.class,
bind = "bindGraphqlClient",
Expand All @@ -83,9 +89,16 @@ List<Resource> getGraphqlClients(@Nonnull SlingHttpServletRequest request) {
ResourceResolver resolver = request.getResourceResolver();
List<Resource> graphqlClients = new ArrayList<>();

final Config cfg = new Config(request.getResource().getChild(Config.DATASOURCE));
boolean showEmptyOption = false;
if (cfg != null) {
ExpressionHelper expressionHelper = new ExpressionHelper(expressionResolver, request);
showEmptyOption = expressionHelper.getBoolean(cfg.get("showEmptyOption"));
}
// Add empty option
graphqlClients.add(new GraphqlClientResource(i18n.get("Inherit", "Inherit property"), StringUtils.EMPTY, resolver));

if (showEmptyOption) {
graphqlClients.add(new GraphqlClientResource(i18n.get("Inherit", "Inherit property"), StringUtils.EMPTY, resolver));
}
// Add other configurations
for (String identifier : identifiers) {
graphqlClients.add(new GraphqlClientResource(identifier, identifier, resolver));
Expand Down
Loading