Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

unsatisfied (reference) Error

Avatar

Level 2

Creating a Java file to convert the Crx data in to xml based on few condition for RSS so i have created a below java file. but i a m facing error ( unsatisfied (reference)). As i am new to AEM i am not able to find the fix for this..error message attached..http://

Error Msg.JPG

**************************

package com.hmi.aem.component;

import java.io.File;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import javax.annotation.Nonnull;

import javax.jcr.RepositoryException;

import javax.jcr.Session;

import javax.xml.parsers.DocumentBuilder;

import javax.xml.parsers.DocumentBuilderFactory;

import javax.xml.parsers.ParserConfigurationException;

import javax.xml.transform.OutputKeys;

import javax.xml.transform.Transformer;

import javax.xml.transform.TransformerException;

import javax.xml.transform.TransformerFactory;

import javax.xml.transform.dom.DOMSource;

import javax.xml.transform.stream.StreamResult;

import java.io.IOException;

import org.apache.felix.scr.annotations.Component;

import org.apache.felix.scr.annotations.Properties;

import org.apache.felix.scr.annotations.Property;

import org.apache.felix.scr.annotations.Reference;

import org.apache.felix.scr.annotations.Service;

import java.util.Dictionary;

import org.apache.sling.api.resource.ResourceResolver;

import org.apache.sling.api.resource.ValueMap;

import org.osgi.service.cm.Configuration;

import org.osgi.service.cm.ConfigurationAdmin;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

import org.w3c.dom.Document;

import org.w3c.dom.Element;

import com.day.cq.search.Query;

import com.day.cq.search.QueryBuilder;

import com.day.cq.search.result.Hit;

import com.day.cq.search.result.SearchResult;

import com.day.cq.wcm.api.NameConstants;

import com.hmi.constants.AppConstant;

import com.day.cq.replication.Replicator;

import com.day.cq.search.PredicateGroup;

@Component(metatype = true)

@Service(Runnable.class)

@Properties({ @Property(name = "enableService", boolValue = false, label = "Enable/Disable", description = "Tick to Enable Service"),

                @Property(name = "scheduler.expression", description = "CRON Expression for frequency of Execution", label = "Frequency")})

public class TopNewsService implements Runnable {

/** The Constant LOGGER. */

private static final Logger LOGGER = LoggerFactory.getLogger(TopNewsService.class);

public static final String TAG_ID = "tagid";

private static final String PROPERTIES = "jcr:path jcr:content/jcr:title jcr:content/jcr:description jcr:content/cq:lastReplicated jcr:content/ownername";

private static final String PATH = "/etc/insidedata/NewsFeed.xml";

/** The resource resolver. */

@Reference

private ResourceResolver resourceResolver;

@Reference

private QueryBuilder builder;

@Reference

private Session session;

@Reference

private Replicator replicator;

@Reference

    private ConfigurationAdmin configurationAdmin;

private Boolean serviceEnabled;

public Document document;

public void run() {

LOGGER.info("STARTING THE DOCUMENT SERVICE...");

DocumentBuilderFactory documentbuilderfactory = DocumentBuilderFactory.newInstance();

DocumentBuilder documentbuilder;

try {

documentbuilder = documentbuilderfactory.newDocumentBuilder();

document = documentbuilder.newDocument();

Session session = initiliazeSession();

        List<Hit> resultHits = executeQueryAndReturnPageResults();

        for(Hit currentHit : resultHits){

        if (serviceEnabled && null != session && null != currentHit) {

            passingValue(session,resultHits);

        }

     

        }

LOGGER.info("PASS VALUE : PASSING VALUE...");

// output DOM XML to console

DOMSource source = new DOMSource(document);

StreamResult console = new StreamResult(new File(PATH));

Transformer transformer = TransformerFactory.newInstance().newTransformer();

transformer.setOutputProperty(OutputKeys.INDENT, "yes");

transformer.transform(source, console);

LOGGER.info("SOURCE FILE : PASSING VALUE..." + source);

// Output to console for testing

StreamResult consoleResult = new StreamResult(System.out);

transformer.transform(source, consoleResult);

} catch (TransformerException e) {

e.printStackTrace();

} catch (ParserConfigurationException e) {

e.printStackTrace();

}

}

void passingValue(@Nonnull Session session,@Nonnull List<Hit> resultHits) {

try {

resultHits = executeQueryAndReturnPageResults();

for (Hit currentPageResult : resultHits) {

ValueMap currentPageValues = currentPageResult.getProperties();

String pageTitle = currentPageValues.get("jcr:content/jcr:title", " ");

String pageDescription = currentPageValues.get("jcr:content/jcr:description", " ");

String publicationDate = currentPageValues.get("jcr:content/cq:lastReplicated"," ");

String ownerName = currentPageValues.get("jcr:content/ownername"," ");

appendtoXML(pageTitle, pageDescription, publicationDate, ownerName);

session.save();

session.logout();

}

} catch (Exception e) {

}

}

void appendtoXML(String pageTitle, String pageDescription, String publicationDate, String ownerName) {

try {

Element titleElement = document.createElement("Title_Feeds");

titleElement.appendChild(document.createTextNode(pageTitle));

Element pageElement = document.createElement("Page_Description");

pageElement.appendChild(document.createTextNode(pageDescription));

Element publicationElement = document.createElement("Publication_Date");

publicationElement.appendChild(document.createTextNode(publicationDate));

Element ownerNameElement = document.createElement("Owner_Name");

ownerNameElement.appendChild(document.createTextNode(ownerName));

} catch (Exception e) {

}

}

Session initiliazeSession(){

Dictionary<String, Object> propertyMap;

        try {

            Configuration configuration = configurationAdmin.getConfiguration(this.getClass().getCanonicalName());

            propertyMap = configuration.getProperties();

            if (!propertyMap.isEmpty()) {

                String serviceEnabledString = propertyMap.get("enableService").toString();

                if (("true").equalsIgnoreCase(serviceEnabledString)) {

                    setServiceEnabled(true);

                }

            }

        }catch (IOException e) {

        throw new InsideException(e);

}

        return null;

}

List<Hit> executeQueryAndReturnPageResults() {

Map<String, String> pageMap = new HashMap<>();

pageMap.put(AppConstant.TYPE_PROPERTY, NameConstants.NT_PAGE);

pageMap.put(TAG_ID, AppConstant.Global_TOP_NEWS_NODE);

pageMap.put("tagid.property", "jcr:content/cq:tags");

pageMap.put("p.hits", "selective");

pageMap.put("p.properties", PROPERTIES);

pageMap.put("p.limit", "-1");

Query query = getBuilder().createQuery(PredicateGroup.create(pageMap), getSession());

SearchResult searchResult = query.getResult();

return searchResult.getHits();

}

public Replicator getReplicator() {

return replicator;

}

public void setReplicator(Replicator replicator) {

this.replicator = replicator;

}

public ResourceResolver getResourceResolver() {

return resourceResolver;

}

public void setResourceResolver(ResourceResolver resourceResolver) {

this.resourceResolver = resourceResolver;

}

public QueryBuilder getBuilder() {

return builder;

}

public void setBuilder(QueryBuilder builder) {

this.builder = builder;

}

public Session getSession() {

return session;

}

public void setSession(Session session) {

this.session = session;

}

public ConfigurationAdmin getConfigurationAdmin() {

return configurationAdmin;

}

public void setConfigurationAdmin(ConfigurationAdmin configurationAdmin) {

this.configurationAdmin = configurationAdmin;

}

public Boolean getServiceEnabled() {

return serviceEnabled;

}

public void setServiceEnabled(Boolean serviceEnabled) {

this.serviceEnabled = serviceEnabled;

}

}

1 Accepted Solution

Avatar

Correct answer by
Level 10

I took your code and placed it into a Maven 10 Arch project as you are using felix SCR annotations. (Maven 10 still uses these annotations -- org.apache.felix.scr.annotations.Component).

Adobe Experience Manager Help | Creating your first Adobe Experience Manager 6.2 Project using Adobe...

I made a few code changes - like removed the @nonnull - AEM does not like that.

I updated the POM dependencies to run on 6.3 - as shown in this video

Here is my result....

View solution in original post

5 Replies

Avatar

Level 10

How did you create this code? Please explain your steps on how to created the OSGi bundle.

YOu should be using an Adobe Maven Archetype project and use the UBER JAR that corresponds to the version of AEM.

For example - see this artilce to learn how to use Maven Archetype 11 and UBER JAR for 6.3 -- Scott's Digital Community: Creating an Adobe Experience Manager 6.3 Project using Adobe Maven Archet...

Avatar

Level 10

See this AEM Artilce for 6.4. Its a similiar use case - we are querying the JCR and placing the data into XML to display it within a JQuery plug-in. It will help you -- Scott's Digital Community: Querying Adobe Experience Manager 6.4 JCR data

Avatar

Correct answer by
Level 10

I took your code and placed it into a Maven 10 Arch project as you are using felix SCR annotations. (Maven 10 still uses these annotations -- org.apache.felix.scr.annotations.Component).

Adobe Experience Manager Help | Creating your first Adobe Experience Manager 6.2 Project using Adobe...

I made a few code changes - like removed the @nonnull - AEM does not like that.

I updated the POM dependencies to run on 6.3 - as shown in this video

Here is my result....

Avatar

Level 2

Could you please suggest me in which i can proceed.

my requirement is to convert AEM data in to xml

Avatar

Level 10

To convert AEM JCR data - you need to QUery the JCR data, then use Java XML classes to convert the data to XML - this is all explained in this article -- Scott's Digital Community: Querying Adobe Experience Manager 6.4 JCR data