It's all about the answers!

Ask a question

RAM Java API Query Builder


Chamal Panditharatne (112) | asked Aug 13 '20, 1:22 p.m.
edited Aug 13 '20, 1:27 p.m.

 Hello,


I am trying to use the RAM Java API to run queries, but I have an issue with the RAMAssetQueryBuilder.  The addSearchFilter(subCategory) method returns a null pointer exception when I try and add the sub category as a search term.  I can't seem to work out why this is happenning.

The code is compiled under JDK1.8 
RAM Version 7.5.4.1

NB the server is returning a SubCategory

EDIT: this is the output

id_60526
Integration
Exception in thread "main" java.lang.NullPointerException
        at com.ibm.ram.client.RAMAssetQueryBuilder.isQueryTerms(RAMAssetQueryBuilder.java:494)
        at com.ibm.ram.client.RAMAssetQueryBuilder.parseQueryCriteria4OSLCv1(RAMAssetQueryBuilder.java:695)
        at com.ibm.ram.client.RAMAssetQueryBuilder.addSearchFilter(RAMAssetQueryBuilder.java:974)
        at com.ibm.ram.client.RAMAssetQueryBuilder.addSearchFilter(RAMAssetQueryBuilder.java:1031)
        at com.ibm.ram.client.RAMAssetQueryBuilder.addSearchFilter(RAMAssetQueryBuilder.java:1093)
        at com.bt.intcoe.App.main(App.java:46)
ackage com.bt.intcoe;

import com.ibm.ram.client.RAMSession;
import com.ibm.ram.client.RAMAssetType;
import com.ibm.ram.client.RAMAssetQueryBuilder;
import com.ibm.ram.client.RAMAssetSearchResult;

import com.ibm.ram.common.data.Asset;
import com.ibm.ram.common.data.exception.RAMRuntimeException;
import com.ibm.ram.common.data.SearchResult;
import com.ibm.ram.common.data.SubCategory;


/
  Hello world!
 /
public final class App {
    private App() {
    }

    /
      Says hello to the world.
      @param args The arguments of the program.
     /
    public static void main(String[] args) {

        RAMSession session = new RAMSession(URL,USER,PASS);

        try {

            RAMAssetQueryBuilder queryBuilder = new RAMAssetQueryBuilder(session);

            RAMAssetType appAssetType = (RAMAssetTypesession.getAssetType("Software Service Instance");
            
            SubCategory subCategory = session.getCategorySchema("Common").getCategory("Platform").getSubCategory("Integration");
            
            System.out.println(subCategory.getId());
            System.out.println(subCategory.getName());
            
            queryBuilder.addSearchFilter(subCategory);
            queryBuilder.addSearchFilter(appAssetType);
            
            SearchResult searchResult = session.getAssets(queryBuilder);

            RAMAssetSearchResult[] results = (RAMAssetSearchResult[]) searchResult.getAssetSearchResults();
            
            int totalNumberOfAssets = searchResult.getTotalResultsCount();
            
            // Initialise counter in preparation of paging through search results
            int assetRunningCount = 0;
            
            /
              Loops through assets in search result.  
             /
            while(assetRunningCount < totalNumberOfAssets) {
                
                for(RAMAssetSearchResult result : results) {
                
                    assetRunningCount++;
                    
                    Asset asset = (Assetresult.getAsset();
                    
                    String assetId = asset.getIdentification().getGUID() + ":" + asset.getIdentification().getVersion();
                    
                    System.out.println(assetId);
                                        
                }
                
                // get the next page of assets, if there are more assets to get...
                if(assetRunningCount < totalNumberOfAssets) { 
                    
                    queryBuilder.setResultsStartIndex(assetRunningCount);
                    
                    searchResult = session.getAssets(queryBuilder);
                    
                    results = (RAMAssetSearchResult[]) searchResult.getAssetSearchResults();
                        
                    // if all the assets have been processed then exit the while loop
                    if(results == null || results.length == 0) { break; }
                    
                }
                
            }


        } catch(RAMRuntimeException e) {

            session.release();

        } finally {

            session.release();

        }

    }
}

Be the first one to answer this question!


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.