Fórum

Get Image From Image Gallery From A Tag

thumbnail
Chris Whittle, modificado 14 Anos atrás.

Get Image From Image Gallery From A Tag

Expert Postagens: 462 Data de Entrada: 17/09/08 Postagens Recentes
I am trying to find an Image(s) from the Image Gallery by supplying a tag and coming up with nothing.... Can anyone help?
Code I found and tried to use... in my log all I get is "looking for images" so nothing is ever found.... I have added an image with the same tag as what I am passing and I can see the tag in the Tag Admin so it's showing up correctly.... Any ideas?
private void getCustomerLogoByTag(HttpServletRequest req, String companyName) throws Exception{
		long currentGroupId = PortalUtil.getScopeGroupId(req);
		long classNameId = PortalUtil.getClassNameId(IGImage.class.getName());
                //Tried this and it just errors and says there is no tag entry with my tagname even though there is so I commented out
		//TagsEntry entry = TagsEntryLocalServiceUtil.getEntry(currentGroupId, companyName);
		//if(entry != null){
		//	_log.error("Found " + companyName);
		//}else{
		//	_log.error("Did Not Find " + companyName);
		//}
		long[] entryIds = TagsEntryLocalServiceUtil.getEntryIds(currentGroupId, new String[] {companyName});
		long[] notEntryIds = new long[0];
		_log.error("looking for images");
		if(entryIds.length>0) {
			ThemeDisplay themeDisplay = (ThemeDisplay) req
			.getAttribute(WebKeys.THEME_DISPLAY);
			_log.error("found " + entryIds.length);
			        List<tagsasset> assets = TagsAssetLocalServiceUtil.getAssets(currentGroupId, new long[] {classNameId}, entryIds, notEntryIds, false, false,-1,-1);
			        for (TagsAsset asset : assets) {
			                IGImage image = IGImageLocalServiceUtil.getIGImage(asset.getClassPK());
			                _log.error(themeDisplay.getPathImage()+ "/image_gallery?img_id="+ image.getLargeImageId() + "&amp;t=" + ImageServletTokenUtil.getToken(image.getLargeImageId()));
			        }
			 }
		}</tagsasset>
thumbnail
Amos Fong, modificado 14 Anos atrás.

RE: Get Image From Image Gallery From A Tag

Liferay Legend Postagens: 2047 Data de Entrada: 07/10/08 Postagens Recentes
Did you make sure your tag exists in the group you are calling this from?

Are there any strange characters in your tagname?
thumbnail
Chris Whittle, modificado 14 Anos atrás.

RE: Get Image From Image Gallery From A Tag

Expert Postagens: 462 Data de Entrada: 17/09/08 Postagens Recentes
Thanks Amos, it ended up being my company ID... I changed it to
ThemeDisplay themeDisplay = (ThemeDisplay) req
		.getAttribute(WebKeys.THEME_DISPLAY);
		long currentGroupId = themeDisplay.getCompanyId();

and it got past that part... now I'm having issues here
 List<tagsasset> assets = TagsAssetLocalServiceUtil.getAssets(currentGroupId, new long[] {classNameId}, entryIds, notEntryIds, false, false,0,0);
			        for (TagsAsset asset : assets) {
			                IGImage image = IGImageLocalServiceUtil.getIGImage(asset.getClassPK());
			                _log.error(themeDisplay.getPathImage()+ "/image_gallery?img_id="+ image.getLargeImageId() + "&amp;t=" + ImageServletTokenUtil.getToken(image.getLargeImageId()));
			        }</tagsasset>

I think it's the start and end "0,0)" that from the original example was from a search container... But this isn't coming from a portlet so I haven't found a way to create a search container... In the past I have passed -1 or 0 as the start and end to signify everything and they worked but I'm getting nothing back... Any ideas?
thumbnail
Amos Fong, modificado 14 Anos atrás.

RE: Get Image From Image Gallery From A Tag

Liferay Legend Postagens: 2047 Data de Entrada: 07/10/08 Postagens Recentes
It works when you pass in your companyId when it's supposed to groupId?

I'm confused =\

For start and end, if you want everything you can use the constant QueryUtil.ALL_POS which is really -1.
thumbnail
Chris Whittle, modificado 14 Anos atrás.

RE: Get Image From Image Gallery From A Tag

Expert Postagens: 462 Data de Entrada: 17/09/08 Postagens Recentes
I can see how that could be confusing dang missnamed variables.... here is the current code... I am getting a tag back now but I'm not getting any images.... am i using the wrong ClassnameId?
private void getCustomerLogoByTag(HttpServletRequest req, String companyName) throws Exception{
		ThemeDisplay themeDisplay = (ThemeDisplay) req
		.getAttribute(WebKeys.THEME_DISPLAY);
		long currentGroupId = PortalUtil.getScopeGroupId(req);
		long companyId = themeDisplay.getCompanyId();
		long classNameId = PortalUtil.getClassNameId(IGImage.class.getName());
		//long classNameId = PortalUtil.getClassNameId(Image.class.getName()); tried this too..
		TagsEntry entry = TagsEntryLocalServiceUtil.getEntry(companyId, companyName);
		if(entry != null){
			_log.error("Found " + companyName);
		}else{
			_log.error("Did Not Find " + companyName);
		}
		long[] entryIds = TagsEntryLocalServiceUtil.getEntryIds(companyId, new String[] {companyName});
		long[] notEntryIds = new long[0];
		_log.error("looking for images");
		if(entryIds.length&gt;0) {
			
			_log.error("found " + entryIds.length);
			        List<tagsasset> assets = TagsAssetLocalServiceUtil.getAssets(currentGroupId, new long[]{classNameId}, entryIds, notEntryIds, false, false,-1,-1);
			        for (TagsAsset asset : assets) {
			        	//Not Getting Here
			                IGImage image = IGImageLocalServiceUtil.getIGImage(asset.getClassPK());
			                _log.error(themeDisplay.getPathImage()+ "/image_gallery?img_id="+ image.getLargeImageId() + "&amp;t=" + ImageServletTokenUtil.getToken(image.getLargeImageId()));
			        }
			 }
		}</tagsasset>
thumbnail
Amos Fong, modificado 14 Anos atrás.

RE: Get Image From Image Gallery From A Tag

Liferay Legend Postagens: 2047 Data de Entrada: 07/10/08 Postagens Recentes
Hm...that is the correct classNameId for Image gallery images.

Try this method:

	public List<tagsasset> getAssets(
			long[] entryIds, long[] notEntryIds, boolean andOperator,
			boolean excludeZeroViewCount, int start, int end)</tagsasset>


That should find anything with your tag. Then you can check if the groupId and classNameIds match up to what you think they are.
thumbnail
Chris Whittle, modificado 14 Anos atrás.

RE: Get Image From Image Gallery From A Tag

Expert Postagens: 462 Data de Entrada: 17/09/08 Postagens Recentes
Weirdest thing it started working... Here is my full code for prosperity... If anyone wants to know what this is for we are using it to display a company logo for a user inside a community that has a generic logo for other users...

private String getCustomerLogoByTag(HttpServletRequest req,
			String companyName) throws Exception {
		companyName = companyName.toLowerCase() + " logo";
		ThemeDisplay themeDisplay = (ThemeDisplay) req
				.getAttribute(WebKeys.THEME_DISPLAY);
		long currentGroupId = PortalUtil.getScopeGroupId(req);
		long companyId = themeDisplay.getCompanyId();
		long classNameId = PortalUtil.getClassNameId(IGImage.class.getName());
		
		long[] entryIds = TagsEntryLocalServiceUtil.getEntryIds(companyId,
				new String[] { companyName });
		long[] notEntryIds = new long[0];
		if (entryIds.length &gt; 0) {
			List<tagsasset> assets = TagsAssetLocalServiceUtil.getAssets(
					currentGroupId, new long[] { classNameId }, entryIds,
					notEntryIds, false, false, -1, -1);
			if (assets.size() &gt; 1) {
				_log.error("There were more than one(" + assets.size()
						+ ") images with the tag '" + companyName
						+ "' returning null");
			} else if (assets.size() == 1) {
				IGImage image = IGImageLocalServiceUtil.getIGImage(assets
						.get(0).getClassPK());
				return themeDisplay.getPathImage()
						+ "/image_gallery?img_id="
						+ image.getLargeImageId()
						+ "&amp;t="
						+ ImageServletTokenUtil.getToken(image
								.getLargeImageId());
			}
		}
		return "";
	}
</tagsasset>
thumbnail
delang j, modificado 13 Anos atrás.

RE: Get Image From Image Gallery From A Tag

Expert Postagens: 252 Data de Entrada: 14/07/08 Postagens Recentes
hi chris,

thanks for your code, im done with my own use to get image by tag too. here my code.
		&lt;%
		long groupId = themeDisplay.getScopeGroupId();
		long classNameId = PortalUtil.getClassNameId(IGImage.class.getName());
		String[] titletag = {map.getTitle().toLowerCase()};
		long[] entryIds = TagsEntryLocalServiceUtil.getEntryIds(groupId, titletag);
		long[] notEntryIds = new long[0];
		
		out.println(entryIds.length);
		if (entryIds.length &gt; 0) {
			
			List<tagsasset> assets = TagsAssetLocalServiceUtil.getAssets(groupId, new long[] { classNameId }, 
				entryIds, notEntryIds, false, false, -1, -1);
			
			for (TagsAsset tagsAss : assets) {
				IGImage imageTags = IGImageLocalServiceUtil.getIGImage(tagsAss.getClassPK());
				out.print("IG name" + imageTags.getName());
			}
		
		}
		%&gt;</tagsasset>
Phoenix Zerin, modificado 12 Anos atrás.

RE: Get Image From Image Gallery From A Tag

Junior Member Postagens: 60 Data de Entrada: 28/06/11 Postagens Recentes
Is the TagsAssetLocalServiceUtil service available in Liferay 6? It doesn't appear to be coming up when I go to Navigate → Open Type... in Liferay Developer Studio.
thumbnail
Parag Negi, modificado 12 Anos atrás.

RE: Get Image From Image Gallery From A Tag

Junior Member Postagens: 69 Data de Entrada: 31/08/11 Postagens Recentes
Hi Pheonix,

I face same issue.

When i try to run code on server using TagsAssetLocalServiceUtil, i get message as

15:15:38,336 ERROR [jsp:154] java.lang.NoClassDefFoundError: com/liferay/portlet/tags/service/TagsEntryLocalServiceUtil
at com.ba.breakingnews.portlet.BreakingnewsView.handleRenderRequestInternal(BreakingnewsView.java:77)
at javax.portlet.GenericPortlet.render(GenericPortlet.java:233)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:101)
at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:64)
at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:92)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:630)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:535)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:472)
at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:638)
at com.liferay.portlet.InvokerPortletImpl.invokeRender(InvokerPortletImpl.java:723)
at com.liferay.portlet.InvokerPortletImpl.render(InvokerPortletImpl.java:425)
at org.apache.jsp.html.portal.render_005fportlet_jsp._jspService(render_005fportlet_jsp.java:1442)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)


Can you please advise, if you managed resolve this mystery...

Thanks
Eric Bartos, modificado 10 Anos atrás.

RE: Get Image From Image Gallery From A Tag

New Member Mensagem: 1 Data de Entrada: 09/08/11 Postagens Recentes
Was anyone able to make this work in Liferay 6?