Showing posts with label ATG. Show all posts
Showing posts with label ATG. Show all posts

Friday, September 18, 2015

ATG QueryBuilder: How to create nested queries / subqueries

I had to deal a good amount of time finding a way to query repositoy items that would match some relationships among different item descriptors. I was trying to look for a way to perform a join over different item descriptors, but at the end was able to solved it in a nested queries fashion. You know,

the typical thing in SQL where you filter by matching a column from the result of another query:

SELECT column_name [, column_name ]
FROM   table1 [, table2 ]
WHERE  column_name OPERATOR
      (SELECT column_name [, column_name ]
      FROM table1 [, table2 ]
      [WHERE])

This in ATG can be done using a query builder operation called: createIncludesItemQuery. You can pass as parameter another query and the colum matching expression.


// Get guide items where tabs in the guide matches some other tabs query
RepositoryItemDescriptor guideRepositoryItemDescriptor = 
                        getProductRepository().getItemDescriptor("guide");
RepositoryView guidesRepositoryView = guideRepositoryItemDescriptor.getRepositoryView();               

QueryBuilder guidesQueryBuilder = guidesRepositoryView.getQueryBuilder();
QueryExpression tabsPropertyExpression =     
        guidesQueryBuilder.createPropertyQueryExpression("tabs");                    
// productTabsQuery is another query built
Query productGuidesQuery = 
      guidesQueryBuilder.createIncludesItemQuery(tabsPropertyExpression, productTabsQuery);
RepositoryItem[] guides = guidesRepositoryView.executeQuery(productGuidesQuery);

Wednesday, October 15, 2014

Ant: adding additional JARs to classpath

I was working in a custom ATG module in which I required to extend a core ATG class. When I ran the build ant command I got compile errors because of "cannot find symbol", in other words, my dear reference class was not being recognized. It was missing! In my Eclipse project I got no errors because I had the right library included in the project's classpath.

I started looking on how to add additional JAR files to the classpath, but after digging a little bit more in the compile target referenced in the build.xml:

<target name="build" depends="echo-build-message,clean,compile,jar-classes,jar-configs,copy-to-install" />

I saw how could I add additional classpath entries using the reference id "classpath.additions". In the included common.xml file we had this:


 
<target name="compile">
     <mkdir dir="${java.output.dir}"/>
        <mkdir dir="${java.src.dir}"/>
        <copy todir="${java.output.dir}">
            <fileset dir="${java.src.dir}">
                <include name="**/*.properties" />
                <include name="**/*.xml" />
            </fileset>
        </copy>
     <if>
      <isreference refid="classpath.additions" />
      <then>
       <path id="fullClasspath">
        <path refid="classpath" />
        <path refid="classpath.additions" />
       </path>
      </then>
      <else>
       <path id="fullClasspath">
        <path refid="classpath" />
       </path>
       </else>
     </if>
        
     <echo message="java.src.dir: ${java.src.dir}, java.output.dir: ${java.output.dir}" />
     <javac srcdir="${java.src.dir}" destdir="${java.output.dir}" classpathref="fullClasspath" debug="on" includeAntRuntime="false" />
</target>

So I just added this in the build.xml:
<path id="classpath.additions"> 
  <fileset dir="${dynamo.home}/../REST/lib"><include name="**/*.jar" /></fileset>  
</path> 
This seems like an elegant generic way for configuring classpaths in a multi module environment like ATG.

Tuesday, October 14, 2014

ATG: Nucleus tips

Get current request URI

import atg.servlet.ServletUtil;
//...
ServletUtil.getCurrentRequest().getRequestURI();

Define a collection of components

Java:
    
protected Component [] componentes;

public void setComponents(Component [] components) {
   this.components = components;
}
    
public Component [] getComponents() {
   return components;
}

Properties:
components=\
 /path/to/some/Component,\
        /path/to/another/Component


Tuesday, May 6, 2014

ATG RQL Tips

Query any item but limit results to only one.

<query-items item-descriptor="category">ALL RANGE +1</query-items>

Remove an item.

<remove-item item-descriptor="<item-descriptor>" id="<ID>"/>

Query item where property is null/not defined


<query-items item-descriptor="product">seoTags IS NULL</query-items>


Query date ranges


<query-items item-descriptor="project"><![CDATA[checkinDate > date("2016-11-18") and checkinDate < date("2016-11-21")]]></query-items>


Get where a property is set (not null)


<query-items item-descriptor="promotion">(NOT closenessQualifiers IS NULL) RANGE+1</query-items>

Thursday, January 23, 2014

ATG Which version

This tool is very useful in ATG to find the version and location (JAR file path) of any particular class:

http://<domain>:8080/dyn/dyn/whichversion.jhtml


Wednesday, November 6, 2013

ATG Colorizer: libstdc++.so.6: cannot open shared object file: No such file or directory

I was in the middle of my ATG local dev environment setup and started to see an error with small application ATG Colorizer:

libstdc++.so.6: cannot open shared object file: No such file or directory




I tried installing the library as I have done in the past, but somehow my new Ubuntu stopped liking the old install recipe. After checking the web for a while I found a way she liked: 
apt-get install lib32stdc++6

Tuesday, September 10, 2013

ATG: Template Error: category error 2

I started getting this error after a merge of code. No clue why this happened but it was impeding my work.

The CategoryLookup droplet (/atg/commerce/catalog/CategoryLookup) was the one failing . So I turned on debug mode to have more information. I got this:


14:01:43,960 INFO  [CategoryLookup] DEBUG Find item: id=BRAND_OPTIMUM; type=category
14:01:43,961 INFO  [CategoryLookup] DEBUG Item Found:category:BRAND_OPTIMUM
14:01:43,961 INFO  [CategoryLookup] DEBUG Is item in catalog catalog:masterCatalog
14:01:43,961 INFO  [CategoryLookup] DEBUG This item is not in the correct catalog.

A more expert person  on ATG told me there is a catalog maintenance page that is used to solve this kind of issues:

Basic Catalog Maintenance

http://localhost:8080/dyn/admin/atg/commerce/admin/en/maintenance/startService.jhtml?process=BasicMaintProcess


Basically, I just ran the process and issues were solved.