Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
dave ch
Web Content - Tags Issue
January 31, 2013 7:50 AM
Answer

dave ch

Rank: Regular Member

Posts: 164

Join Date: February 6, 2012

Recent Posts

Hi all,

I am publishing my content using Web Content portlet from Control Panel. While publishing I am also adding Tags from Categorization Option which is on the right hand side(Web content --> Select a web content --> Categorization Option on right hand side). Now when I am adding Tags, Tags should keep as is they entered. I want to Prevent them converted into lowercase.
When the Tags are displaying in the Asset Publisher portlet they are in Lower Case. I want to Prevent them converted into lowercase. How should I achieve this?
Any help will be appreciated.

Thanks

Dave
Samuel Kong
RE: Web Content - Tags Issue
January 31, 2013 11:33 PM
Answer

Samuel Kong

LIFERAY STAFF

Rank: Liferay Master

Posts: 979

Join Date: March 10, 2008

Recent Posts

Take a look at the Overriding a Portal Service section of the Development Guide. You'll need to create a hook to override AssetTagLocalService since the all lowercase version is stored in the database. (disclaimer: this might cause some things to break. I'm not sure)
dave ch
RE: Web Content - Tags Issue
February 1, 2013 12:50 AM
Answer

dave ch

Rank: Regular Member

Posts: 164

Join Date: February 6, 2012

Recent Posts

Hi Samuel ,

Thanks for the quick reply.
I just want to know what are all the methods i need to override to keep the tags, as is they entered. I want to Prevent them converted into lowercase.

Any help will be appriciated.

Thanks

dave
Hitoshi Ozawa
RE: Web Content - Tags Issue
February 1, 2013 2:21 AM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7990

Join Date: March 23, 2010

Recent Posts

Look at
\portal-impl\src\com\liferay\portlet\asset\service\impl\AssetTagLocalServiceImpl.java

There are two rows with the following statement:
name = name.toLowerCase();
dave ch
RE: Web Content - Tags Issue
February 1, 2013 4:01 AM
Answer

dave ch

Rank: Regular Member

Posts: 164

Join Date: February 6, 2012

Recent Posts

Hi Hitoshi,

So I need to use Ext instead of Hook to override AssetTagLocalServiceImpl.java. , if i am not wrong.

Thanks,

dave
Samuel Kong
RE: Web Content - Tags Issue
February 3, 2013 7:05 PM
Answer

Samuel Kong

LIFERAY STAFF

Rank: Liferay Master

Posts: 979

Join Date: March 10, 2008

Recent Posts

No, Use a hook instead. You should generally avoid using an ext-plugin unless you have no other choices.
dave ch
RE: Web Content - Tags Issue
February 5, 2013 1:33 AM
Answer

dave ch

Rank: Regular Member

Posts: 164

Join Date: February 6, 2012

Recent Posts

Samuel Kong]No, Use a hook instead. You should generally avoid using an ext-plugin unless you have no other choices.


Hi Samuel,

I tried to override AssetTagLocalServiceImpl.java class using hook, but i was unsuccessful.
I have created a Test-hook and tried to override this by writting the below code in liferay-hook.xml

<service>
<service-type>com.liferay.portlet.asset.service.AssetTagLocalService</service-type>
<service-impl>com.liferay.sample.hook.MyAssetTagLocalServiceImpl</service-impl>
</service>

and end with getting some exceptions. Seems to be it is not possible to override this class using hook.

Regards

Dave
dave ch
RE: Web Content - Tags Issue
February 5, 2013 2:35 AM
Answer

dave ch

Rank: Regular Member

Posts: 164

Join Date: February 6, 2012

Recent Posts

The exception i am getting is:

 110:10:50,728 ERROR [pool-2-thread-4][HotDeployImpl:191] com.liferay.portal.kernel.deploy.hot.HotDeployException: Error registering hook for servicehook-hook
 2com.liferay.portal.kernel.deploy.hot.HotDeployException: Error registering hook for servicehook-hook
 3    at com.liferay.portal.kernel.deploy.hot.BaseHotDeployListener.throwHotDeployException(BaseHotDeployListener.java:46)
 4    at com.liferay.portal.deploy.hot.HookHotDeployListener.invokeDeploy(HookHotDeployListener.java:276)
 5    at com.liferay.portal.deploy.hot.HotDeployImpl.doFireDeployEvent(HotDeployImpl.java:188)
 6    at com.liferay.portal.deploy.hot.HotDeployImpl.fireDeployEvent(HotDeployImpl.java:96)
 7    at com.liferay.portal.kernel.deploy.hot.HotDeployUtil.fireDeployEvent(HotDeployUtil.java:27)
 8    at com.liferay.portal.kernel.servlet.PluginContextListener.fireDeployEvent(PluginContextListener.java:151)
 9    at com.liferay.portal.kernel.servlet.PluginContextListener.doPortalInit(PluginContextListener.java:141)
10    at com.liferay.portal.kernel.util.BasePortalLifecycle.portalInit(BasePortalLifecycle.java:42)
11    at com.liferay.portal.kernel.util.PortalLifecycleUtil.register(PortalLifecycleUtil.java:64)
12    at com.liferay.portal.kernel.util.PortalLifecycleUtil.register(PortalLifecycleUtil.java:56)
13    at com.liferay.portal.kernel.util.BasePortalLifecycle.registerPortalLifecycle(BasePortalLifecycle.java:52)
14    at com.liferay.portal.kernel.servlet.PluginContextListener.contextInitialized(PluginContextListener.java:103)
15    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)
16    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)
17    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
18    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895)
19    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:871
20    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
21    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1099)
22    at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1621)
23    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
24    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
25    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
26    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
27    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
28    at java.lang.Thread.run(Thread.java:619)
29Caused by: java.lang.ClassNotFoundException: com.liferay.portlet.asset.service.impl.AssetTagLocalServiceImpl
30    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
31    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
32    at com.liferay.portal.deploy.hot.HookHotDeployListener.doInvokeDeploy(HookHotDeployListener.java:601)
33    at com.liferay.portal.deploy.hot.HookHotDeployListener.invokeDeploy(HookHotDeployListener.java:273)
34    ... 24 more
Samuel Kong
RE: Web Content - Tags Issue
February 6, 2013 8:08 PM
Answer

Samuel Kong

LIFERAY STAFF

Rank: Liferay Master

Posts: 979

Join Date: March 10, 2008

Recent Posts

I just tested using 6.1.1 and a hook will work. You probably have something not configured correctly in your hook. Check out https://github.com/liferay/liferay-plugins/tree/6.1.x/portlets/test-hook-portlet for a working example.
dave ch
RE: Web Content - Tags Issue
February 7, 2013 3:39 AM
Answer

dave ch

Rank: Regular Member

Posts: 164

Join Date: February 6, 2012

Recent Posts

Hi Samuel,

This is the method i want to override using hook of AssetTagLocalServiceImpl :

 1public AssetTag addTag(
 2            long userId, String name, String[] tagProperties,
 3            ServiceContext serviceContext)
 4        throws PortalException, SystemException {
 5
 6        // Tag
 7
 8        User user = userPersistence.findByPrimaryKey(userId);
 9        long groupId = serviceContext.getScopeGroupId();
10
11        if (tagProperties == null) {
12            tagProperties = new String[0];
13        }
14
15        Date now = new Date();
16
17        long tagId = counterLocalService.increment();
18
19        AssetTag tag = assetTagPersistence.create(tagId);
20
21        tag.setGroupId(groupId);
22        tag.setCompanyId(user.getCompanyId());
23        tag.setUserId(user.getUserId());
24        tag.setUserName(user.getFullName());
25        tag.setCreateDate(now);
26        tag.setModifiedDate(now);
27
28        name = name.trim();
29        name = name.toLowerCase();
30
31        if (hasTag(groupId, name)) {
32            throw new DuplicateTagException(
33                "A tag with the name " + name + " already exists");
34        }
35
36        validate(name);
37
38        tag.setName(name);
39
40        assetTagPersistence.update(tag, false);
41
42        // Resources
43
44        if (serviceContext.isAddGroupPermissions() ||
45            serviceContext.isAddGuestPermissions()) {
46
47            addTagResources(
48                tag, serviceContext.isAddGroupPermissions(),
49                serviceContext.isAddGuestPermissions());
50        }
51        else {
52            addTagResources(
53                tag, serviceContext.getGroupPermissions(),
54                serviceContext.getGuestPermissions());
55        }
56
57        // Properties
58
59        for (int i = 0; i < tagProperties.length; i++) {
60            String[] tagProperty = StringUtil.split(
61                tagProperties[i], CharPool.COLON);
62
63            String key = StringPool.BLANK;
64
65            if (tagProperty.length > 0) {
66                key = GetterUtil.getString(tagProperty[0]);
67            }
68
69            String value = StringPool.BLANK;
70
71            if (tagProperty.length > 1) {
72                value = GetterUtil.getString(tagProperty[1]);
73            }
74
75            if (Validator.isNotNull(key)) {
76                assetTagPropertyLocalService.addTagProperty(
77                    userId, tagId, key, value);
78            }
79        }
80
81        return tag;
82    }


But, then from where do i get the instance variables like: userPersistence, counterLocalService, assetTagPersistence, assetTagPersistence.

Kindly suggest.

Thanks,

Dave
dave ch
RE: Web Content - Tags Issue
February 8, 2013 2:13 AM
Answer

dave ch

Rank: Regular Member

Posts: 164

Join Date: February 6, 2012

Recent Posts

Hi,

Finally got the solution by changing these injected variables:

userPersistence---to--- UserLocalServiceUtil
counterLocalService---to--- CounterLocalServiceUtil
assetTagPersistence---to--- AssetTagLocalServiceUtil
assetTagPropertyLocalService---to---AssetTagPropertyLocalServiceUtil
assetEntryLocalService---to---AssetEntryLocalServiceUtil

Regards

Dave