掲示板

Using Content Targeting APIs

9年前 に Dmitry Nikeshkin によって更新されました。

Using Content Targeting APIs

New Member 投稿: 4 参加年月日: 12/11/12 最新の投稿
Hello,
I'm trying to use content targeting api from my hook plugin. Tried to add dependency as here Using content targeting, but when i deploy my plugin i receive
14:04:00,316 INFO  [localhost-startStop-10][ServiceComponentLocalServiceImpl:321] Running CT SQL scripts
14:04:03,718 ERROR [localhost-startStop-10][BaseDB:367] java.lang.NullPointerException
java.lang.NullPointerException
	at java.io.StringReader.<init>(StringReader.java:50)
	at org.apache.velocity.runtime.RuntimeInstance.evaluate(RuntimeInstance.java:1165)
	at org.apache.velocity.app.VelocityEngine.evaluate(VelocityEngine.java:219)
	at com.liferay.portal.velocity.VelocityUtil.evaluate(VelocityUtil.java:67)
	at com.liferay.portal.dao.db.BaseDB.evaluateVM(BaseDB.java:749)
	at com.liferay.portal.dao.db.BaseDB.runSQLTemplateString(BaseDB.java:364)
	at com.liferay.portal.service.impl.ServiceComponentLocalServiceImpl.doUpgradeDB(ServiceComponentLocalServiceImpl.java:324)
	at com.liferay.portal.service.impl.ServiceComponentLocalServiceImpl$DoUpgradeDBPrivilegedExceptionAction.run(ServiceComponentLocalServiceImpl.java:262)
	at com.liferay.portal.service.impl.ServiceComponentLocalServiceImpl$NoPACL.doUpgradeDB(ServiceComponentLocalServiceImpl.java:533)
	at com.liferay.portal.service.impl.ServiceComponentLocalServiceImpl.upgradeDB(ServiceComponentLocalServiceImpl.java:201)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:115)
	at com.liferay.portal.spring.transaction.DefaultTransactionExecutor.execute(DefaultTransactionExecutor.java:62)
	at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:51)
	at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:111)
	at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:175)
	at com.sun.proxy.$Proxy96.upgradeDB(Unknown Source)
	at com.liferay.portal.service.impl.ServiceComponentLocalServiceImpl.initServiceComponent(ServiceComponentLocalServiceImpl.java:179)
	at sun.reflect.GeneratedMethodAccessor335.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:115)
	at com.liferay.portal.spring.transaction.DefaultTransactionExecutor.execute(DefaultTransactionExecutor.java:62)
	at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:51)
	at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:111)
	at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:175)
	at com.sun.proxy.$Proxy96.initServiceComponent(Unknown Source)
	at com.liferay.portal.service.ServiceComponentLocalServiceUtil.initServiceComponent(ServiceComponentLocalServiceUtil.java:288)
	at com.liferay.portal.deploy.hot.PluginPackageHotDeployListener.initServiceComponent(PluginPackageHotDeployListener.java:247)
	at com.liferay.portal.deploy.hot.PluginPackageHotDeployListener.doInvokeDeploy(PluginPackageHotDeployListener.java:132)
	at com.liferay.portal.deploy.hot.PluginPackageHotDeployListener.invokeDeploy(PluginPackageHotDeployListener.java:61)
	at com.liferay.portal.deploy.hot.HotDeployImpl.doFireDeployEvent(HotDeployImpl.java:227)
	at com.liferay.portal.deploy.hot.HotDeployImpl.fireDeployEvent(HotDeployImpl.java:96)
	at com.liferay.portal.kernel.deploy.hot.HotDeployUtil.fireDeployEvent(HotDeployUtil.java:28)
	at com.liferay.portal.kernel.servlet.PluginContextListener.fireDeployEvent(PluginContextListener.java:164)
	at com.liferay.portal.kernel.servlet.PluginContextListener.doPortalInit(PluginContextListener.java:154)
	at com.liferay.portal.kernel.util.BasePortalLifecycle.portalInit(BasePortalLifecycle.java:44)
	at com.liferay.portal.kernel.util.PortalLifecycleUtil.register(PortalLifecycleUtil.java:74)
	at com.liferay.portal.kernel.util.PortalLifecycleUtil.register(PortalLifecycleUtil.java:58)
	at com.liferay.portal.kernel.util.BasePortalLifecycle.registerPortalLifecycle(BasePortalLifecycle.java:54)
	at com.liferay.portal.kernel.servlet.PluginContextListener.contextInitialized(PluginContextListener.java:116)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1113)
	at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1671)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)
14:04:03,720 ERROR [localhost-startStop-10][HotDeployImpl:230] com.liferay.portal.kernel.deploy.hot.HotDeployException: Error registering plugins for page-config-segment-1.0-SNAPSHOTpage-config-segment-1.0-SNAPSHOT
com.liferay.portal.kernel.deploy.hot.HotDeployException: Error registering plugins for page-config-segment-1.0-SNAPSHOTpage-config-segment-1.0-SNAPSHOT
	at com.liferay.portal.kernel.deploy.hot.BaseHotDeployListener.throwHotDeployException(BaseHotDeployListener.java:46)
	at com.liferay.portal.deploy.hot.PluginPackageHotDeployListener.invokeDeploy(PluginPackageHotDeployListener.java:64)
	at com.liferay.portal.deploy.hot.HotDeployImpl.doFireDeployEvent(HotDeployImpl.java:227)
	at com.liferay.portal.deploy.hot.HotDeployImpl.fireDeployEvent(HotDeployImpl.java:96)
	at com.liferay.portal.kernel.deploy.hot.HotDeployUtil.fireDeployEvent(HotDeployUtil.java:28)
	at com.liferay.portal.kernel.servlet.PluginContextListener.fireDeployEvent(PluginContextListener.java:164)
	at com.liferay.portal.kernel.servlet.PluginContextListener.doPortalInit(PluginContextListener.java:154)
	at com.liferay.portal.kernel.util.BasePortalLifecycle.portalInit(BasePortalLifecycle.java:44)
	at com.liferay.portal.kernel.util.PortalLifecycleUtil.register(PortalLifecycleUtil.java:74)
	at com.liferay.portal.kernel.util.PortalLifecycleUtil.register(PortalLifecycleUtil.java:58)
	at com.liferay.portal.kernel.util.BasePortalLifecycle.registerPortalLifecycle(BasePortalLifecycle.java:54)
	at com.liferay.portal.kernel.servlet.PluginContextListener.contextInitialized(PluginContextListener.java:116)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1113)
	at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1671)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)
Caused by: com.liferay.portal.kernel.exception.SystemException: java.lang.NullPointerException
	at com.liferay.portal.service.impl.ServiceComponentLocalServiceImpl.initServiceComponent(ServiceComponentLocalServiceImpl.java:188)
	at sun.reflect.GeneratedMethodAccessor335.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:115)
	at com.liferay.portal.spring.transaction.DefaultTransactionExecutor.execute(DefaultTransactionExecutor.java:62)
	at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:51)
	at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:111)
	at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:175)
	at com.sun.proxy.$Proxy96.initServiceComponent(Unknown Source)
	at com.liferay.portal.service.ServiceComponentLocalServiceUtil.initServiceComponent(ServiceComponentLocalServiceUtil.java:288)
	at com.liferay.portal.deploy.hot.PluginPackageHotDeployListener.initServiceComponent(PluginPackageHotDeployListener.java:247)
	at com.liferay.portal.deploy.hot.PluginPackageHotDeployListener.doInvokeDeploy(PluginPackageHotDeployListener.java:132)
	at com.liferay.portal.deploy.hot.PluginPackageHotDeployListener.invokeDeploy(PluginPackageHotDeployListener.java:61)
	... 23 more
Caused by: java.lang.NullPointerException
	at com.liferay.portal.kernel.io.unsync.UnsyncStringReader.<init>(UnsyncStringReader.java:34)
	at com.liferay.portal.dao.db.BaseDB.runSQLTemplateString(BaseDB.java:374)
	at com.liferay.portal.service.impl.ServiceComponentLocalServiceImpl.doUpgradeDB(ServiceComponentLocalServiceImpl.java:324)
	at com.liferay.portal.service.impl.ServiceComponentLocalServiceImpl$DoUpgradeDBPrivilegedExceptionAction.run(ServiceComponentLocalServiceImpl.java:262)
	at com.liferay.portal.service.impl.ServiceComponentLocalServiceImpl$NoPACL.doUpgradeDB(ServiceComponentLocalServiceImpl.java:533)
	at com.liferay.portal.service.impl.ServiceComponentLocalServiceImpl.upgradeDB(ServiceComponentLocalServiceImpl.java:201)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:115)
	at com.liferay.portal.spring.transaction.DefaultTransactionExecutor.execute(DefaultTransactionExecutor.java:62)
	at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:51)
	at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:111)
	at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:175)
	at com.sun.proxy.$Proxy96.upgradeDB(Unknown Source)
	at com.liferay.portal.service.impl.ServiceComponentLocalServiceImpl.initServiceComponent(ServiceComponentLocalServiceImpl.java:179)
	... 36 more
Apr 20, 2015 2:04:03 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Loading file:/home/formoza/projects/bundle/liferay-portal-6.2-ce-ga3/tomcat-7.0.42/work/Catalina/localhost/page-config-segment-1.0-SNAPSHOT/loader/service.properties</init></init>

Further i'm trying to get all segments
List<usersegment> segments = UserSegmentLocalServiceUtil.getUserSegments(-1, -1);</usersegment>
and ofc receive
14:04:12,840 ERROR [http-bio-8080-exec-60][PortletBeanLocatorUtil:42] BeanLocator is null for servlet context com.liferay.content.targeting.api
.

Maven dependency:
<dependency>
            <groupid>com.liferay.content-targeting</groupid>
            <artifactid>com.liferay.content.targeting.api</artifactid>
            <version>2.0.0</version>
        </dependency>

May be problem in maven? Also I don't understand why it starts to do upgradeDb?
thumbnail
9年前 に Julio Camarero によって更新されました。

RE: Using Content Targeting APIs

Liferay Legend 投稿: 1668 参加年月日: 08/07/15 最新の投稿
Hi Dmitry,

you can use these APIs from other portlets but you probably can't do that from a hook. Keep in mind that hooks don't usually have a web application, they share the classloader of the portal for the JSPs, for example.

what kind of hook are you creating? where are you calling these APIs from your hook? a JSP? a Java class implementing Event or Action?
9年前 に Dmitry Nikeshkin によって更新されました。

RE: Using Content Targeting APIs

New Member 投稿: 4 参加年月日: 12/11/12 最新の投稿
Hi,
Thank you for answer. I created hook for site administration page (new jsp tab for editing layouts). Also I implemented hook for "/group_pages/edit_layouts" action (Java class) and there tried to receive e.g. all segments.

Btw I looked to osgi plugins and this is not suitable for creating jsp hook, because when we create osgi bundle, we can not use jsp, only template technologies, e.g. freemarker templates.
thumbnail
9年前 に Julio Camarero によって更新されました。

RE: Using Content Targeting APIs (回答)

Liferay Legend 投稿: 1668 参加年月日: 08/07/15 最新の投稿
Hi Dmitry,

in that situation, you are in the classloader of the portal, which doesn't have the JAR files of the modules.

You have 2 different options:
- Since we create one category per user segment in a vocabulary called "User Segment", you could use those categories (see how we do this in our module)
- You could copy the jar file of Audience Targeting to the lib folder of your app server and restart the server so that you can access the library from the portal classloader.

cheers!
9年前 に Dmitry Nikeshkin によって更新されました。

RE: Using Content Targeting APIs

New Member 投稿: 4 参加年月日: 12/11/12 最新の投稿
Julio Camarero:

- You could copy the jar file of Audience Targeting to the lib folder of your app server and restart the server so that you can access the library from the portal classloader.


So, i left dependency in my pom.xml, further I moved jar to tomcat lib folder and now I can receive segments. BUT what can I do with
14:04:00,316 INFO  [localhost-startStop-10][ServiceComponentLocalServiceImpl:321] Running CT SQL scripts
  214:04:03,718 ERROR [localhost-startStop-10][BaseDB:367] java.lang.NullPointerException
exception?
thumbnail
9年前 に Alexey Kakunin によって更新されました。

RE: Using Content Targeting APIs

Liferay Master 投稿: 621 参加年月日: 08/07/07 最新の投稿
Julio, thank you for answer.

I do not think it is good idea to copy whole jar (included both - API and Implementation) into some other place. It may produce really unexpected behavior.
In our case we need *-service.jar - actually jar with only API of plugin (just like in Plugins SDK or Maven it was used to separate API of plugin into special service.jar and keep implementation only in plugin itself).

Is it possible with OSGI? If there are no such separation of classes into two modules (API and Implementation) what is a proper way to use some API provided by some module in OSGI ?

For example - as Dmitry wrote in another message - if we are doing like this - during deployment of our hook run's CT SQL scripts - I'm pretty sure it is because during deploy it is loaded audience targeting jar included IMPL-classes (as well as sql and other staff) just instead of loading jar file with only API. I'm not sure it is good to run these SQL during deploying our hook - since it should be loaded only during eploying of Audience Targeting itself.

TO be more concrete - our target is to extend functionality of Audience Targeting - we like to add ne tabs into page configuration (it is why we need implement it as hook) to allow to do some configuration on page, specific from user sergments.

Using categories is not enough for us - since after completing configuraiton, we will need another hook - there we will decide, epending from current user segments and page configuration which portlets to show or not to show to the user - in this case categories will not help us.
thumbnail
9年前 に Julio Camarero によって更新されました。

RE: Using Content Targeting APIs

Liferay Legend 投稿: 1668 参加年月日: 08/07/15 最新の投稿
Hi Alexey,

we did want to separate the API and Implementation for the services, but unfortunately, service builder in 6.2 was not ready for it and the whole thing goes together. We will have this separation for 7.0 (as we are doing with the rest of modules migrated to osgi).

If you are trying to use this module from other osgi module it would be really simple, you would just need to list your dependencies in your bnd files and add the libraries to your dependencies ivy file. However, in 6.2, the portal itself is not an OSGI module and therefore it is not as easy to use dependencies from other modules.

If you want to customize the pages configuration using User Segments, in 6.2 the best option you have is to create a new portlet (even better if you use osgi for your portlet, but it's not mandatory, you can easily use the content targeting API from another traditional portlet). Then, you could open that portlet in a popup, or embed it inside the other portlet.

Cheers!