10 Replies Latest reply: Jan 30, 2012 10:58 AM by ClareR RSS

    How do I programatically determine RepositoryItem's super-type

    302517
      I have a bunch of item-descriptors that share a common super-type of "product" like below...

      <item-descriptor name="visualmedia" super-type="product" display-name="Visual Media" sub-type-value="visualmedia">
      <item-descriptor name="application" super-type="product" display-name="Application" sub-type-value="application">

      .

      In my code, it is easy enough to get a RepostitoryItem's Type like...

      String itemType = item.getItemDescriptor().getItemDescriptorName();
      // yields "visualmedia" or "application"

      ...but what I really need is the RepositoryItem's super-type value of "product". Does anyone know how to do this?

      Bob
        • 1. Re: How do I programatically determine RepositoryItem's super-type
          RajeshAkavaram
          You can look at the ItemDescriptor inheritance concept in the repository guide of atg manuals, it is clearly mentioned in there with examples, how to handle this...

          Thanks,
          Rajesh Akavaram
          • 2. Re: How do I programatically determine RepositoryItem's super-type
            302517
            Thanks for the reply and the direction to the Docs got me into the correct location, but even now the actual code to do this is not clear to me. The docs don't actually address how I can ask an arbitrary RepositoryItem if it has a parent of a particular type. If this was straight-up actual Java I'd be doing instanceof here. I don't see how the ATG API allows me to handle this.

            The docs seem to suggest that I know beforehand some property name whose presence would indicate that this RespositoryItem is on the inheritance chain I am interested in. The problem is that not ALL RepositoryItems have that property. Doesn't the API stacktrace if I ask a RepositoryItem for a property value of a property it doesn't have? My take-away from reading that section in the Repository Guide is that I can only do this is all the RepositoryItems that I am dealing with are on a common inhertiance chain. In my case, they aren't. Only some of them.

            Sigh.
            • 3. Re: How do I programatically determine RepositoryItem's super-type
              Praveer.Rai
              Hi ,

              You can use as below :

              GSAItemDescriptor itemDesc = (GSAItemDescriptor) item.getItemDescriptor();

              String superType= itemDesc.getSuperTypeDescriptor().getItemDescriptorName();



              cheers
              ~ Praveer
              • 4. Re: How do I programatically determine RepositoryItem's super-type
                Nick Glover-Oracle
                Hi,

                There is a way to do an "instanceof" like check with GSA. It can be found in the public API of GSAItemDescriptor at http://docs.oracle.com/cd/E22630_01/Platform.1002/apidoc/atg/adapter/gsa/GSAItemDescriptor.html .

                The method call is GSAItemDescriptor.isInstance( GSAItem ). The signature allows any object to be passed in, but it will work how you want if you pass in a GSAItem.

                You will get an IllegalArgumentException if you call GSAItem.getPropertyValue() for a property that doesn't exist for that item-type. But, you can use GSAItem.getItemDescriptor().hasProperty( String ) to check if a property exists for a particular item.

                Thanks.

                --
                Nick Glover
                Oracle Support for ATG Products
                • 5. Re: How do I programatically determine RepositoryItem's super-type
                  302517
                  Wow. This is probably correct, but I don't know how to get a GSAItemDescriptor from just a RepositoryItem. All I can get directly is a RepositoryItemDescriptor. Argh. Thanks so much for your help, but can you now give me a clue how to turn a RepositoryItemDescriptor into a GSAItemDescriptor so I can call through to the getSuperTypeDescriptor() method. Also, does that guy return null or something if the RepositoryItem does not have a super-type?

                  So many questions...so little time. As always, any help is greatly appreciated.

                  Bob
                  • 6. Re: How do I programatically determine RepositoryItem's super-type
                    ClareR
                    It's always better to write code using the Repository API, if possible, rather than diving into a particular repository implementation like the GSA. The atg.repository.RepositoryUtils class is your friend. It takes care of whatever instanceof checks and casts are necessary. It probably has the methods you need. Here are some options related to your question.

                    RepositoryItemDescriptor getBaseItemDescriptor(RepositoryItemDescriptor pItemDesc) - If pItemDesc is not a GSAItemDescriptor, it will be returned to you. If it is a GSAItemDescriptor, you'll get back GSAItemDescriptor.getBaseItemDescriptor. The base is the root of a multi-level inheritance tree. If the input parameter has no supertypes, it will be returned. In other words, you won't get a null back.

                    RepositoryItemDescriptor getParentItemDescriptor(RepositoryItemDescriptor pItemDesc) - This returns an immediate supertype or null if the input type has no supertype.

                    boolean isTypeOfItemDesc(RepositoryItem pItem, RepositoryItemDescriptor pSuper) - This returns true if pItem is a pSuper or has pSuper anywhere in its supertype tree. This is analogous to java's instanceof. There's an overloaded version of this method where you can pass in a RepositoryItemDescriptor for the first parameter if that happens to be more convenient for you. If you're starting with a RepositoryItem, there's no need for you to get its ItemDescriptor on your own.

                    The code in GSAItemDescriptor.getSuperTypeDescriptor isin't exactly the same as getParentItemDescriptor, and I'm not enough of a GSA expert to know if they'd give you different answers. I doubt it. My guess is that isTypeOfItemDesc is what you really want.
                    • 7. Re: How do I programatically determine RepositoryItem's super-type
                      Praveer.Rai
                      Hi ,

                      The way i have suggested works fine , i have tested it too ..all you have to do it Typecast .

                      eg : RepositoryItem item = ......... ;

                      GSAItemDescriptor itemDesc = (GSAItemDescriptor) item.getItemDescriptor();

                      String superType= itemDesc.getSuperTypeDescriptor().getItemDescriptorName();

                      just Import GSAItemDescriptor and typecast.



                      thanks
                      Praveer
                      • 8. Re: How do I programatically determine RepositoryItem's super-type
                        302517
                        "...atg.repository.RepositoryUtils class is your friend"...truer words have not been spoken. This seems to work...

                        <pre>
                        private boolean isAProduct( RepositoryItem item ) throws RepositoryException {
                        RepositoryItemDescriptor riDesc = item.getItemDescriptor();
                        RepositoryItemDescriptor baseRIDesc = RepositoryUtils.getBaseItemDescriptor( riDesc );
                        String itemType = baseRIDesc.getItemDescriptorName();
                        boolean itemIsAProduct = ITEM_DESC_PRODUCT.equals( itemType );
                        return itemIsAProduct;
                        }
                        </pre>
                        • 9. Re: How do I programatically determine RepositoryItem's super-type
                          Nick Glover-Oracle
                          There's an easier method to use:

                          <pre>
                          private boolean isAProduct( RepositoryItem item ) throws RepositoryException {
                          return RepositoryUtils.isTypeOfItemDesc( item, ITEM_DESC_PRODUCT);
                          }
                          </pre>

                          Thanks.

                          --
                          Nick Glover
                          Oracle Support for ATG Products
                          • 10. Re: How do I programatically determine RepositoryItem's super-type
                            ClareR
                            There's yet another choice if you're trying to check for one of ATG's ootb catalog repository item types. The /atg/commerce/catalog/CatalogTools component has an isProduct method that takes a repository item as input. I'm not sure what release isProduct was added, but it was in 2004. isCategory was added in 10.0, and isSku is coming in 10.1.