Dear All,
When I am trying to call my service in my HTL like below then I am getting below error
org/apache/sling/scripting/sightly/apps/page/body_html.java:
Line 79, column 4095 : ai.core.service.OneTrustService cannot be resolved to a type
My Code is Below
************** SERVICE CLASS ***************
package ai.core.service;
public interface OneTrustService {
/**
*/
public String getOneTrustId();
/**
*
* @Return Google Tag Manager (gtm) Id */
String getGtmId();
}
************** SERVICE IMPL CLASS ***************
package ai.core.service;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Modified;
import org.osgi.service.metatype.annotations.Designate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ai.core.config.OneTrustConfig;
@component(service = OneTrustService.class, immediate = true)
@Designate(ocd = OneTrustConfig.class)
public class OneTrustServiceImpl implements OneTrustService {
private String oneTrustId;
private String gtmId;
private static final Logger LOGGER = LoggerFactory.getLogger(OneTrustServiceImpl.class);
/**
* Method used to init the service when activated
*
* @Param OneTrustConfig serverConfiguration The parameters activated for the component */
protected void activate(final OneTrustConfig serverConfiguration) {
this.init(serverConfiguration);
}
/**
* Method used to init the service when updated
*
* @Param OneTrustConfig serverConfiguration The parameters activated for the component */
protected void update(final OneTrustConfig serverConfiguration) {
this.init(serverConfiguration);
}
/**
* This method assigns the configuration when the component is activated and updated.
*
* @Param OneTrustConfig serverConfiguration The configuration set for the component */
private void init(final OneTrustConfig serverConfiguration) {
this.oneTrustId = serverConfiguration.getOneTrustId();
LOGGER.info("oneTrustId value ==== "+ oneTrustId);
this.gtmId = serverConfiguration.getGtmId();
LOGGER.info("gtmId value ==== "+ gtmId);
}
public String getOneTrustId() {
LOGGER.info("oneTrustId value INSIDE getOneTrustId ==== "+ oneTrustId);
return oneTrustId;
}
public String getGtmId() {
LOGGER.info("oneTrustId value INSIDE getGtmId ==== "+ gtmId);
return gtmId;
}
}
************** CONFIG CLASS ***************
package ai.core.models;
import org.osgi.service.metatype.annotations.AttributeDefinition;
import org.osgi.service.metatype.annotations.ObjectClassDefinition;
/**
*
* This interface represents the configuration for OneTrust
*
*/
@ObjectClassDefinition(name = "Talent Marketing OneTrust Config", description = "Talent Marketing OneTrust Config")
/**
*/
@AttributeDefinition(name = "OneTrust ID", description = "OneTrust ID for Cookie Banner")
String getOneTrustId();
/**
*
* @Return The Google Tag Manager (GTM) Id */
@AttributeDefinition(name = "GTM ID", description = "GTM ID For Cookie Banner")
String getGtmId();
}
***************** HTL CODE *******************
<sly data-sly-use.templatedContainer="com.day.cq.wcm.foundation.TemplatedContainer"
data-sly-repeat.child="${templatedContainer.structureResources}"
data-sly-resource="${child.path @ resourceType=child.resourceType, decorationTagName='div'}"></sly>
<!--<p data-sly-use.gtmonetrustid="ai.marcel.contentadmin.core.service.OneTrustService">
${gtmonetrustid.gtmId}
</p> -->
<!-- Google Tag Manager (noscript) -->
<noscript>
style="display:none;visibility:hidden" title="Google tag manager">
</iframe>
</noscript>
<!-- End Google Tag Manager (noscript) -->
*******************************
My server config file value is below
![subnaik_0-1724764882979.png subnaik_0-1724764882979.png](https://experienceleaguecommunities.adobe.com/t5/image/serverpage/image-id/79285i34755E0216EB51EB/image-size/medium?v=v2&px=400)
Can anyone please help me here that why I am not getting the osgi config value in my HTL ?
Thanks
Lakhman