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

Add CIF to AEM Archetype #388

Merged
merged 24 commits into from
May 28, 2020
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
db32952
Add CIF option and dependencies
mhaack Apr 27, 2020
66a853b
Add CIF option and dependencies
mhaack Apr 28, 2020
933b21b
Add missing cloudconfigs folder
mhaack Apr 28, 2020
90b0754
Add CIF test definitions
mhaack Apr 28, 2020
ab908b3
Add placeholder .scss for CIF components
mhaack Apr 29, 2020
cf1537b
Add CIF option and dependencies
mhaack Apr 27, 2020
d2c46c9
Add CIF option and dependencies
mhaack Apr 28, 2020
bab0291
Add missing cloudconfigs folder
mhaack Apr 28, 2020
32bacfe
Add CIF test definitions
mhaack Apr 28, 2020
71bce13
Add placeholder .scss for CIF components
mhaack Apr 29, 2020
45ec14d
Fix component & pom.xml
mhaack May 4, 2020
46894fe
Fix clientlib
mhaack May 4, 2020
751ae52
Merge branch 'issues/CIF-1212' of https://github.com/mhaack/aem-proje…
mhaack May 4, 2020
625426f
Add tests & default OSGI configs
mhaack May 5, 2020
3afd202
Fix CIF client lib, correct cleanup for ui.frontend module
mhaack May 5, 2020
db5cba4
Add default config for GraphQl client
mhaack May 8, 2020
3dcf7ee
Update README.md
mhaack May 8, 2020
019183e
Only add GraphQL client for non AEM cloud projects
mhaack May 8, 2020
a6ce85f
CIF-1264 - Add CIF usage section to README of generated project
mhaack May 11, 2020
e470604
CIF-1213: Improve Venia test coverage to meet CM goals
hbacila May 14, 2020
22c2555
CIF-1213: Improve Venia test coverage to meet CM goals
hbacila May 14, 2020
c7f4492
CIF-1264 - Update CIF dependencies to last released versions
mhaack May 20, 2020
239ff4f
Fix readme.md
mhaack May 25, 2020
819e424
Add missing mapping policies for product drag & drop
mhaack May 25, 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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.formatOnSave": false
}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Maven template that creates a minimal, best-practices-based Adobe Experience Man
* **Style System:** Avoid building custom components by allowing authors to [apply different styles](https://docs.adobe.com/content/help/en/experience-manager-learn/getting-started-wknd-tutorial-develop/style-system.html) to them.
* **Front-End Build:** Front-end devs can [mock AEM pages](https://docs.adobe.com/content/help/en/experience-manager-core-components/using/developing/archetype/uifrontend.html#webpack-dev-server) and [build client libraries](https://docs.adobe.com/content/help/en/experience-manager-core-components/using/developing/archetype/uifrontend.html) with Webpack, TypeScript, and SASS.
* **WebApp-Ready:** For sites using [React](https://docs.adobe.com/content/help/en/experience-manager-core-components/using/developing/archetype/uifrontend-react.html) or [Angular](https://docs.adobe.com/content/help/en/experience-manager-core-components/using/developing/archetype/uifrontend-angular.html), use the [SPA SDK](https://docs.adobe.com/content/help/en/experience-manager-64/developing/headless/spas/spa-architecture.html) to retain [in-context authoring of the app](https://docs.adobe.com/content/help/en/experience-manager-learn/sites/spa-editor/spa-editor-framework-feature-video-use.html).
* **Commerce Enabled** For projects that want to use Commerce Integration Framework ([CIF](https://github.com/adobe/aem-core-cif-components)) to integrated with commerce solutions like Magento.
* **Example Code:** Checkout the HelloWorld component, and the sample models, servelets, filters, and schedulers.
* **Open Sourced:** If something is not as it should, [contribute](https://github.com/adobe/aem-core-wcm-components/blob/master/CONTRIBUTING.md) your improvements!

Expand Down Expand Up @@ -72,6 +73,8 @@ Name | Default | Description
`singleCountry` | `y` | Includes a language-master content structure (can be `y`, or `n`).
`includeExamples` | `y` | Includes a [Component Library](https://www.aemcomponents.dev/) example site (can be `y`, or `n`).
`includeErrorHandler` | `n` | Includes a custom 404 response page that will be global to the entire instance (can be `y` or `n`).
`includeCommerce` | `n` | Included [CIF Core Components](https://github.com/adobe/aem-core-cif-components) dependecies and generates corresponding artifacts.
`commerceEndpoint` | | Requiered for CIF only. Optional endpoint of the commerce system GraphQL service to be used (e.g. `https://hostname.com/grapql`).

## System Requirements

Expand Down
12 changes: 12 additions & 0 deletions src/main/archetype/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ The main parts of the template are:
* ui.tests: Java bundle containing JUnit tests that are executed server-side. This bundle is not to be deployed onto production.
* ui.launcher: contains glue code that deploys the ui.tests bundle (and dependent bundles) to the server and triggers the remote JUnit execution
* ui.frontend: an optional dedicated front-end build mechanism (Angular, React or general Webpack project)
#if ( $includeCommerce == "y" )

## Commerce usage

This project template includes dependencies to [CIF Core Components](https://github.com/adobe/aem-core-cif-components) and best-practice how they can be used for creating your own AEM commerce project.

The CIF Core Components connect to a Magento (or alternative commerce system) via GraphQL. This connection has to be configured in the `com.adobe.cq.commerce.graphql.client.impl.GraphqlClientImpl-default.config` config. A reference is included in the project template. Consult [documatetion](https://github.com/adobe/aem-core-cif-components/wiki/configuration) for detailed configuation steps.

The project depends on the CIF Authoring tooling. The CIF Connector is not included in the generated project and must be installed separately. See [CIF Connector](https://github.com/adobe/commerce-cif-connector) project for instructions.

Sample code demonstrating how [CIF core components can be customized](https://github.com/adobe/aem-core-cif-components/wiki/Customizing-CIF-Core-Components) and extended is included in the `core` bundle module. The Sling modules package contains an example `MyProductTeaser` model.
#end

## How to build

Expand Down
16 changes: 16 additions & 0 deletions src/main/archetype/all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@
<type>zip</type>
<target>/apps/${appId}-vendor-packages/content/install</target>
</embedded>
#end
#if ( $includeCommerce == "y" )
<embedded>
<groupId>com.adobe.commerce.cif</groupId>
<artifactId>core-cif-components-apps</artifactId>
<type>zip</type>
<target>/apps/${appId}-vendor-packages/application/install</target>
</embedded>
#end
</embeddeds>
<subPackages>
Expand Down Expand Up @@ -234,6 +242,14 @@
<type>zip</type>
</dependency>
#end
#if ( $includeCommerce == "y" )
<!-- Adobe CIF Dependencies -->
<dependency>
<groupId>com.adobe.commerce.cif</groupId>
<artifactId>core-cif-components-apps</artifactId>
<type>zip</type>
</dependency>
#end
#if ( $includeExamples == "y" )
<dependency>
<groupId>com.adobe.cq</groupId>
Expand Down
2 changes: 2 additions & 0 deletions src/main/archetype/archetype.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ includeErrorHandler=${includeErrorHandler}
frontendModule=${frontendModule}
singleCountry=${singleCountry}
includeDispatcherConfig=${includeDispatcherConfig}
includeCommerce=${includeCommerce}
commerceEndpoint=${commerceEndpoint}
37 changes: 37 additions & 0 deletions src/main/archetype/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ Import-Package: javax.annotation;version=0.0.0,*
<groupId>org.osgi</groupId>
<artifactId>org.osgi.resource</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.util.tracker</artifactId>
</dependency>
<!-- Other Dependencies -->
<dependency>
<groupId>org.slf4j</groupId>
Expand Down Expand Up @@ -168,6 +172,22 @@ Import-Package: javax.annotation;version=0.0.0,*
<artifactId>aem-sdk-api</artifactId>
</dependency>
#end

#if ( $includeCommerce == "y" )
<!-- Adobe CIF Dependencies -->
<dependency>
<groupId>com.adobe.commerce.cif</groupId>
<artifactId>core-cif-components-core</artifactId>
</dependency>
<dependency>
<groupId>com.adobe.commerce.cif</groupId>
<artifactId>graphql-client</artifactId>
</dependency>
<dependency>
<groupId>com.adobe.commerce.cif</groupId>
<artifactId>magento-graphql</artifactId>
</dependency>
#end
<!-- Testing -->
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand All @@ -192,6 +212,23 @@ Import-Package: javax.annotation;version=0.0.0,*
<dependency>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.junit5</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.models.impl</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</exclusion>
</exclusions>
<scope>test</scope>
</dependency>
<!-- Required to be able to support injection with @Self and @Via -->
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.models.impl</artifactId>
<version>1.4.4</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*******************************************************************************
*
* Copyright 2019 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*
******************************************************************************/
package ${package}.core.models.commerce;

import com.adobe.cq.commerce.core.components.models.productteaser.ProductTeaser;

import org.osgi.annotation.versioning.ProviderType;

@ProviderType
public interface MyProductTeaser extends ProductTeaser {
// Extend the existing interface with the additional properties which you
// want to expose to the HTL template.
public Boolean isShowBadge();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*******************************************************************************
*
* Copyright 2019 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*
******************************************************************************/
package ${package}.core.models.commerce;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.time.format.DateTimeFormatter;

import javax.annotation.PostConstruct;

import com.adobe.cq.commerce.core.components.models.common.Price;
import com.adobe.cq.commerce.core.components.models.productteaser.ProductTeaser;
import com.adobe.cq.commerce.core.components.models.retriever.AbstractProductRetriever;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.Via;
import org.apache.sling.models.annotations.injectorspecific.ScriptVariable;
import org.apache.sling.models.annotations.injectorspecific.Self;
import org.apache.sling.models.annotations.via.ResourceSuperType;

@Model(adaptables = SlingHttpServletRequest.class, adapters = MyProductTeaser.class, resourceType = MyProductTeaserImpl.RESOURCE_TYPE)
public class MyProductTeaserImpl implements MyProductTeaser {

protected static final String RESOURCE_TYPE = "${appId}/components/commerce/productteaser";

private static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

@Self
@Via(type = ResourceSuperType.class)
private ProductTeaser productTeaser;

@ScriptVariable
private ValueMap properties;

private AbstractProductRetriever productRetriever;

@PostConstruct
public void initModel() {
productRetriever = productTeaser.getProductRetriever();

if (productRetriever != null) {
// Pass your custom partial query to the ProductRetriever. This class will
// automatically take care of executing your query as soon
// as you try to access any product property.
productRetriever.extendProductQueryWith(p -> p.createdAt());
}
}

@Override
public Boolean isShowBadge() {
final boolean showBadge = properties.get("badge", false);
if (showBadge) {
final int maxAgeProp = properties.get("age", 0);

// Custom code to calc the date difference of the product creation
// compared to today
final LocalDate createdAt = LocalDate.parse(productRetriever.fetchProduct().getCreatedAt(), formatter);
if (createdAt != null) {
final long age = ChronoUnit.DAYS.between(createdAt, LocalDate.now());
if (age < maxAgeProp) {
return true;
}
}
}
return false;
}

@Override
public String getFormattedPrice() {
return productTeaser.getPriceRange().getFormattedFinalPrice();
}

@Override
public Price getPriceRange() { return productTeaser.getPriceRange(); }

@Override
public String getImage() {
return productTeaser.getImage();
}

@Override
public String getName() {
return productTeaser.getName();
}

@Override
public String getUrl() {
return productTeaser.getUrl();
}

@Override
public String getSku() {
return productTeaser.getSku();
}

@Override
public String getCallToAction() {
return productTeaser.getCallToAction();
}

@Override
public Boolean isVirtualProduct() { return productTeaser.isVirtualProduct(); }

@Override
public AbstractProductRetriever getProductRetriever() {
return productRetriever;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2015 Adobe Systems Incorporated
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@Version("1.0")
package ${package}.core.models.commerce;

import org.osgi.annotation.versioning.Version;
Loading