Skip to content

Instantly share code, notes, and snippets.

@sreeni-b
Last active August 27, 2022 10:59
Show Gist options
  • Save sreeni-b/6f95860ba7419511dbab0880b8433871 to your computer and use it in GitHub Desktop.
Save sreeni-b/6f95860ba7419511dbab0880b8433871 to your computer and use it in GitHub Desktop.
package com.aemks.core.workflow;
import com.adobe.cq.dam.cfm.ContentFragment;
import com.adobe.granite.workflow.WorkflowException;
import com.adobe.granite.workflow.WorkflowSession;
import com.adobe.granite.workflow.exec.WorkItem;
import com.adobe.granite.workflow.exec.WorkflowData;
import com.adobe.granite.workflow.exec.WorkflowProcess;
import com.adobe.granite.workflow.metadata.MetaDataMap;
import com.day.cq.commons.jcr.JcrConstants;
import com.day.cq.dam.api.Asset;
import com.day.cq.dam.commons.util.DamUtil;
import com.day.cq.dam.core.process.ProcessingProfileApplier;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.osgi.service.component.annotations.Component;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
/**
* By default, the metadata processing profile does not work for content fragments.
* Hence this custom process is required to apply processing profile on create
* of any Content Fragment.
*/
@Component(property = { "process.label = Content Fragment Metadata Processor" })
public class ContentFragmentMetadataProcessor implements WorkflowProcess {
private ProcessingProfileApplier processingProfileApplier = new ProcessingProfileApplier();
@Override public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap)
throws WorkflowException {
Session session = workflowSession.adaptTo(Session.class);
WorkflowData data = workItem.getWorkflowData();
String payloadPath = data.getPayload().toString();
if(payloadPath.endsWith("/jcr:content")){
payloadPath=payloadPath.replace("/jcr:content","");
}
ResourceResolver resourceResolver = workflowSession.adaptTo(ResourceResolver.class);
if(resourceResolver==null){
throw new WorkflowException("Resource Resolver is null");
}
Resource assetResource = resourceResolver.getResource(payloadPath);
if(assetResource==null){
throw new WorkflowException("Asset resource is null");
}
ContentFragment contentFragment = assetResource.adaptTo(ContentFragment.class);
if(contentFragment==null){
throw new WorkflowException("Asset resource is not a content fragment");
}
Asset asset = DamUtil.resolveToAsset(assetResource);
try {
processingProfileApplier.applyProcessingProfile(session,asset);
} catch (RepositoryException e) {
throw new WorkflowException("Error occurred while applying processing profile to Content Fragment",e);
}
}
}
@siddharth21dimri98
Copy link

Hi
I am facing an issue ( com.adobe.aem.guides:aem-guides-wknd.core:2.0.1-SNAPSHOT: Bundle aem-guides-wknd.core:2.0.1-SNAPSHOT is importing package(s) com.day.cq.dam.core.process in start level 20 but no bundle is exporting these for that start level. (com.adobe.aem.guides:aem-guides-wknd.all:2.0.1-SNAPSHOT))

4.0.0 com.adobe.aem.guides aem-guides-wknd pom 2.0.1-SNAPSHOT WKND Sites Project - Reactor Project WKND Sites Project https://github.com/adobe/aem-guides-wknd 2019
<licenses>
	<license>
		<name>MIT License</name>
		<url>http://www.opensource.org/licenses/mit-license.php</url>
	</license>
</licenses>

<modules>
    <module>all</module>
    <module>core</module>
    <module>ui.frontend</module>
    <module>ui.apps</module>
    <module>ui.apps.structure</module>
    <module>ui.config</module>
    <module>ui.content</module>
    <module>ui.content.sample</module>
    <module>it.tests</module>
    <module>dispatcher</module>
    <module>ui.tests</module>
</modules>

<properties>
    <aem.host>localhost</aem.host>
    <aem.port>4506</aem.port>
    <aem.publish.host>localhost</aem.publish.host>
    <aem.publish.port>4503</aem.publish.port>
    <sling.user>admin</sling.user>
    <sling.password>admin</sling.password>
    <vault.user>admin</vault.user>
    <vault.password>admin</vault.password>
    <bnd.version>5.1.2</bnd.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <aem.sdk.api>2022.7.8085.20220725T140323Z-220600</aem.sdk.api>
    <componentGroupName>WKND Site</componentGroupName>
    <core.wcm.components.version>2.19.2</core.wcm.components.version>
    <uber.jar.version>6.5.12</uber.jar.version>
    <wknd-shared.version>2.0.0</wknd-shared.version>
    <aemanalyser.version>1.4.14</aemanalyser.version>
</properties>

<organization>
    <name>Adobe</name>
    <url>http://www.adobe.com/</url>
</organization>

 <developers>
    <developer>
        <id>aem-guides-wknd</id>
        <organization>Adobe</organization>
        <organizationUrl>https://www.adobe.com</organizationUrl>
        <url>https://docs.adobe.com/content/help/en/experience-manager-learn/getting-started-wknd-tutorial-develop/overview.html</url>
    </developer>
</developers>

 <scm>
    <connection>scm:git:https://github.com/adobe/aem-guides-wknd.git</connection>
    <developerConnection>scm:git:https://github.com/adobe/aem-guides-wknd.git</developerConnection>
    <url>https://github.com/adobe/aem-guides-wknd/tree/main</url>
    <tag>HEAD</tag>
</scm>

<build>
    <plugins>
        <!-- Maven Release Plugin -->
        <plugin>
            <artifactId>maven-release-plugin</artifactId>
            <version>3.0.0-M5</version>
            <configuration>
                <scmCommentPrefix>[maven-scm] :</scmCommentPrefix>
                <preparationGoals>clean install</preparationGoals>
                <goals>deploy</goals>
                <releaseProfiles>release</releaseProfiles>
                <autoVersionSubmodules>true</autoVersionSubmodules>
                <projectVersionPolicyId>OddEvenVersionPolicy</projectVersionPolicyId>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.apache.maven.release</groupId>
                    <artifactId>maven-release-oddeven-policy</artifactId>
                    <version>3.0.0-M5</version>
                </dependency>
            </dependencies>
        </plugin>
        <!-- Maven Source Plugin -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <version>3.0.1</version>
            <inherited>true</inherited>
        </plugin>
        <!-- Maven Javadocs Plugin -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>2.9.1</version>
            <configuration>
                <source>8</source>
            </configuration>
            <executions>
                <execution>
                <id>attach-javadocs</id>
                <goals>
                    <goal>jar</goal>
                </goals>
                </execution>
            </executions>
        </plugin>
        <!-- Maven Enforcer Plugin -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-enforcer-plugin</artifactId>
            <executions>
                <execution>
                    <id>enforce-maven</id>
                    <goals>
                        <goal>enforce</goal>
                    </goals>
                    <configuration>
                        <rules>
                            <requireMavenVersion>
                                <version>[3.3.9,)</version>
                            </requireMavenVersion>
                            <requireJavaVersion>
                                <message>Maven must be executed with a Java 8 JRE or higher.</message>
                                <version>1.8.0</version>
                            </requireJavaVersion>
                        </rules>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <!-- Maven Compiler Plugin -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>com.github.eirslett</groupId>
                <artifactId>frontend-maven-plugin</artifactId>
                <version>1.11.3</version>
                <configuration>
                    <nodeVersion>v12.22.7</nodeVersion>
                    <npmVersion>6.14.0</npmVersion>
                </configuration>
                <executions>
                    <execution>
                        <id>install node and npm</id>
                        <goals>
                            <goal>install-node-and-npm</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>npm install</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- Maven Jar Plugin -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.1.2</version>
            </plugin>
            <!-- Maven Clean Plugin -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <version>3.0.0</version>
            </plugin>
            <!-- BND Maven Plugin -->
            <plugin>
                <groupId>biz.aQute.bnd</groupId>
                <artifactId>bnd-maven-plugin</artifactId>
                <version>${bnd.version}</version>
                <executions>
                    <execution>
                        <id>bnd-process</id>
                        <goals>
                            <goal>bnd-process</goal>
                        </goals>
                        <configuration>
                            <bnd><![CDATA[

Bundle-Category: ${componentGroupName}

export all versioned packages except for conditional ones (bndtools/bnd#3721 (comment))

-exportcontents: ${removeall;${packages;VERSIONED};${packages;CONDITIONAL}}

reproducible builds (bndtools/bnd#3521)

-noextraheaders: true
-snapshot: SNAPSHOT

Bundle-DocURL:
-plugin org.apache.sling.caconfig.bndplugin.ConfigurationClassScannerPlugin
-plugin org.apache.sling.bnd.models.ModelsScannerPlugin
]]>





org.apache.sling
org.apache.sling.caconfig.bnd-plugin
1.0.2


org.apache.sling
org.apache.sling.bnd.models
1.0.0




biz.aQute.bnd
bnd-baseline-maven-plugin
${bnd.version}



org.apache.maven.plugins
maven-resources-plugin
3.0.2



org.apache.maven.plugins
maven-compiler-plugin
3.8.1



org.apache.maven.plugins
maven-install-plugin
2.5.2



org.apache.maven.plugins
maven-surefire-plugin
2.22.1

false




org.apache.maven.plugins
maven-failsafe-plugin
2.22.1



org.apache.maven.plugins
maven-deploy-plugin
2.8.2



org.apache.sling
sling-maven-plugin
2.4.0

http://${aem.host}:${aem.port}/system/console
WebConsole




org.apache.sling
htl-maven-plugin
1.3.4-1.4.0

true




org.apache.jackrabbit
filevault-package-maven-plugin
true
1.1.4

src/main/content/META-INF/vault/filter.xml

none





tccl:aem.cnd






biz.netcentric.aem
aem-nodetypes
6.5.5.0





com.adobe.aem
aemanalyser-maven-plugin
${aemanalyser.version}
true



com.day.jcr.vault
content-package-maven-plugin
1.0.2

http://${aem.host}:${aem.port}/crx/packmgr/service.jsp
true
${vault.user}
${vault.password}




org.apache.maven.plugins
maven-enforcer-plugin
3.0.0



org.apache.maven.plugins
maven-dependency-plugin
3.0.0



org.codehaus.mojo
build-helper-maven-plugin
3.0.0



org.eclipse.m2e
lifecycle-mapping
1.0.0





org.apache.maven.plugins
maven-enforcer-plugin
[1.0.0,)

enforce









org.apache.maven.plugins


maven-dependency-plugin


[2.2,)


copy-dependencies
unpack









org.codehaus.mojo


build-helper-maven-plugin


[1.5,)



reserve-network-port












org.apache.maven.plugins
maven-javadoc-plugin
${maven-javadoc-plugin.version}


attach-javadocs

jar


-Xdoclint:none




${java.home}/bin/javadoc
com.vu.poc.test.objects





<profiles>
    <!-- ====================================================== -->
    <!-- A D O B E P U B L I C P R O F I L E -->
    <!-- ====================================================== -->
    <profile>
        <id>adobe-public</id>

        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>

        <properties>
            <releaseRepository-Id>adobe-public-releases</releaseRepository-Id>
            <releaseRepository-Name>Adobe Public Releases</releaseRepository-Name>
            <releaseRepository-URL>https://repo.adobe.com/nexus/content/groups/public</releaseRepository-URL>
        </properties>

        <repositories>
            <repository>
                <id>adobe-public-releases</id>
                <name>Adobe Public Repository</name>
                <url>https://repo.adobe.com/nexus/content/groups/public</url>
                <releases>
                    <enabled>true</enabled>
                    <updatePolicy>never</updatePolicy>
                </releases>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
            </repository>
        </repositories>

        <pluginRepositories>
            <pluginRepository>
                <id>adobe-public-releases</id>
                <name>Adobe Public Repository</name>
                <url>https://repo.adobe.com/nexus/content/groups/public</url>
                <releases>
                    <enabled>true</enabled>
                    <updatePolicy>never</updatePolicy>
                </releases>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
            </pluginRepository>
        </pluginRepositories>
    </profile>

    <!-- Development profile: install only the bundle -->
    <profile>
        <id>autoInstallBundle</id>
        <!--
            To enable this feature for a bundle, the sling-maven-plugin
            (without configuration) needs to be included:

            <plugin>
                <groupId>org.apache.sling</groupId>
                <artifactId>sling-maven-plugin</artifactId>
             </plugin>
        -->
        <activation>
            <activeByDefault>false</activeByDefault>
        </activation>
        <build>
            <pluginManagement>
                <plugins>
                    <plugin>
                        <groupId>org.apache.sling</groupId>
                        <artifactId>sling-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>install-bundle</id>
                                <goals>
                                    <goal>install</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </pluginManagement>
        </build>
    </profile>

    <profile>
        <id>autoInstallPackage</id>
        <activation>
            <activeByDefault>false</activeByDefault>
        </activation>
        <build>
            <pluginManagement>
                <plugins>
                    <plugin>
                        <groupId>org.apache.jackrabbit</groupId>
                        <artifactId>filevault-package-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>create-package</id>
                                <goals>
                                    <goal>package</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>com.day.jcr.vault</groupId>
                        <artifactId>content-package-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>install-package</id>
                                <goals>
                                    <goal>install</goal>
                                </goals>
                                <configuration>
                                    <targetURL>http://${aem.host}:${aem.port}/crx/packmgr/service.jsp</targetURL>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </pluginManagement>
        </build>
    </profile>

    <profile>
        <id>autoInstallPackagePublish</id>
        <activation>
            <activeByDefault>false</activeByDefault>
        </activation>
        <build>
            <pluginManagement>
                <plugins>
                    <plugin>
                        <groupId>org.apache.jackrabbit</groupId>
                        <artifactId>filevault-package-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>create-package</id>
                                <goals>
                                    <goal>package</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>com.day.jcr.vault</groupId>
                        <artifactId>content-package-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>install-package-publish</id>
                                <goals>
                                    <goal>install</goal>
                                </goals>
                                <configuration>
                                    <targetURL>http://${aem.publish.host}:${aem.publish.port}/crx/packmgr/service.jsp</targetURL>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </pluginManagement>
        </build>
    </profile>
    <profile>
        <id>release</id>
        <activation>
            <property>
                <name>performRelease</name>
            </property>
        </activation>
        <build>
            <!-- https://central.sonatype.org/pages/requirements.html -->
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-source-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>attach-sources</id>
                            <goals>
                                <goal>jar-no-fork</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>attach-javadocs</id>
                            <goals>
                                <goal>jar</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>gpg-maven-plugin</artifactId>
                    <version>3.0.1</version>
                    <executions>
                        <execution>
                            <id>sign-artifacts</id>
                            <phase>verify</phase>
                            <goals>
                                <goal>sign</goal>
                            </goals>
                            <configuration>
                                <gpgArguments>
                                    <arg>--pinentry-mode</arg>
                                    <arg>loopback</arg>
                                </gpgArguments>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.sonatype.plugins</groupId>
                    <artifactId>nexus-staging-maven-plugin</artifactId>
                    <version>1.6.8</version>
                    <extensions>true</extensions>
                    <configuration>
                        <serverId>ossrh</serverId>
                        <nexusUrl>https://oss.sonatype.org/</nexusUrl>
                        <!-- manually release in https://oss.sonatype.org/#stagingRepositories after the Maven release build -->
                        <autoReleaseAfterClose>false</autoReleaseAfterClose>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
    <profile>
        <id>cm-java-11</id>
        <activation>
              <property>
                    <name>env.CM_BUILD</name>
              </property>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-toolchains-plugin</artifactId>
                    <version>1.1</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>toolchain</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <toolchains>
                            <jdk>
                                <version>1.11</version>
                                <vendor>oracle</vendor>
                            </jdk>
                        </toolchains>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>


<!-- ====================================================================== -->
<!-- D E P E N D E N C I E S -->
<!-- ====================================================================== -->
<dependencyManagement>
    <dependencies>

        <!-- Adobe AEM Dependencies -->
        <dependency>
            <groupId>com.adobe.aem</groupId>
            <artifactId>uber-jar</artifactId>
            <version>${uber.jar.version}</version>
            <scope>provided</scope>
        </dependency>
    <!-- AEM as a Cloud Service SDK -->
        <dependency>
            <groupId>com.adobe.aem</groupId>
            <artifactId>aem-sdk-api</artifactId>
            <version>${aem.sdk.api}</version>
            <scope>provided</scope>
        </dependency>

         <!-- AEM Core Components -->
        <dependency>
            <groupId>com.adobe.cq</groupId>
            <artifactId>core.wcm.components.core</artifactId>
            <version>${core.wcm.components.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.adobe.cq</groupId>
            <artifactId>core.wcm.components.content</artifactId>
            <type>zip</type>
            <version>${core.wcm.components.version}</version>
        </dependency>
        <dependency>
            <groupId>com.adobe.cq</groupId>
            <artifactId>core.wcm.components.config</artifactId>
            <type>zip</type>
            <version>${core.wcm.components.version}</version>
        </dependency>

        <!-- WKND Shared -->
        <dependency>
            <groupId>com.adobe.aem.guides</groupId>
            <artifactId>aem-guides-wknd-shared.ui.content</artifactId>
            <version>${wknd-shared.version}</version>
            <type>zip</type>
        </dependency>

        <!-- Testing -->
        <dependency>
            <groupId>org.junit</groupId>
            <artifactId>junit-bom</artifactId>
            <version>5.6.2</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>3.3.3</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-junit-jupiter</artifactId>
            <version>3.3.3</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit-addons</groupId>
            <artifactId>junit-addons</artifactId>
            <version>1.4</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>io.wcm</groupId>
            <artifactId>io.wcm.testing.aem-mock.junit5</artifactId>
            <version>3.0.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>uk.org.lidalia</groupId>
            <artifactId>slf4j-test</artifactId>
            <version>1.0.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-imaging</artifactId>
            <version>1.0-alpha2</version>
        </dependency>
    </dependencies>
</dependencyManagement>
this is my main pom file. 6.5.12(uber jar version) import com.day.cq.dam.core.process.ProcessingProfileApplier;(this import package was also giving errors)

@r-malav
Copy link

r-malav commented Aug 27, 2022

Hi can share project create command

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment