It's all about the answers!

Ask a question

Adding a category to an asset in a custom policy


Allen Earnest (6212437) | asked Nov 15 '13, 9:20 a.m.
edited Nov 15 '13, 9:25 a.m.
 Hello

I need to create a custom policy that will add a category to an asset.  I've been digging through the Java API and think I have a good approach, but it is not working.  My code looks like this...

CategorySchema newCategorySchema = myAsset.getAvailableCategorySchema("Service Usage Indicator");
Category newCategory = newCategorySchema.getCategory("Service Usage");
SubCategory newSubCategory = newCategory.getSubCategory("First Use");
SubCategory[] subCategories1  = {newSubCategory};
newCategory.setSubCategories(subCategories1);
Category[] categories1  = {newCategory};
newCategorySchema.setCategories(categories1);
CategorySchema[] schemas1 = {newCategorySchema};
myAsset.setCategorySchemas(schemas1);
However, this gives me an exception...

exception java.lang.NullPointerException stack trace=[com.ibm.ram.client.RAMCategorySchema.setDirty(RAMCategorySchema.java:411), com.ibm.ram.client.RAMCategory.setDirty(RAMCategory.java:415), com.ibm.ram.client.RAMSubCategory.setDirty(RAMSubCategory.java:432), com.ibm.ram.client.RAMSubCategory.setSubCategories(RAMSubCategory.java:706), com.ibm.ram.client.RAMCategory.setSubCategories(RAMCategory.java:474), ......

What is the correct way to categorize an asset via a custom policy?  I've tried many variations of the above, but keep hitting exceptions of one kind or another.

Thanks for any help!
  

Accepted answer


permanent link
Allen Earnest (6212437) | answered Nov 18 '13, 9:58 a.m.
Well, I was making this harder than it needed to be.  Plus i skipped over the part of the documentation that actually answered by question!

From the IBM documentation found here >
Extending Product Function > Extending Rational Asset Manager > Using Rational Asset Manager Java API > Work with assets > Create, modify, or delete assets > Categorize an asset


//Categorize using the category schema fetched from the session
CategorySchema automobilesSchema = 
        session.getCategorySchema("Automobiles");

Category priceCategory = automobilesSchema.getCategory("Price");
newAsset.categorize(priceCategory, "25000");

//Categorize using a category fetched through the asset
automobilesSchema = newAsset.getAvailableCategorySchema("Automobiles");

Category colorCategory = automobilesSchema.getCategory("Color");
newAsset.categorize(colorCategory, "Red");

//Categorize using sub category objects
Category modelCategory = automobilesSchema.getCategory("Model");
SubCategory domestic = modelCategory.getSubCategory("Domestic");
SubCategory foreign = modelCategory.getSubCategory("Foreign");
SubCategory honda = foreign.getSubCategory("Honda");
SubCategory camry = foreign.getSubCategory("Toyota/Camry");
newAsset.categorize(domestic);
newAsset.categorize(honda);
newAsset.categorize(camry);

session.put(newAsset, new NullProgressMonitor());



Rich Kulp selected this answer as the correct answer

Comments
Pramod Chavan commented Dec 20 '13, 2:07 a.m.

getSubCategory("SubCategory-Name"); this method does not work when the input argument "sub-category-name" has backslash(/).


E.g: getSubCategory("sub/category") --> returns null

Please let me know if there is any workaround for this. I tried to eescape it by placing \ before /, but did not work. 

Your answer


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.