How to create a subCategory in RAM using Java API
I have a method which is intended to create a subcategory .. but it fails with the following error:-
com.ibm.ram.common.data.exception.RAMRuntimeException
at com.ibm.ram.client.RAMSession.putCategorySchema(RAMSession.java:3776)
at com.ibm.ram.client.RAMSession.put(RAMSession.java:5041)
at com.cof.custom.policy.CustomPolicyUtility.categorizeSubCategoryAssets(CustomPolicyUtility.java:488)
at com.cof.custom.policy.CustomPolicyUtility.manageAssets(CustomPolicyUtility.java:425)
at com.cof.custom.policy.CustomPolicyUtility.main(CustomPolicyUtility.java:755)
Caused by: java.lang.NullPointerException
at com.ibm.ram.client.RAMSession.putCategorySchema(RAMSession.java:3666)
... 4 more
Exception in thread "main" com.ibm.ram.common.data.exception.RAMRuntimeException
at com.ibm.ram.client.RAMSession.putCategorySchema(RAMSession.java:3776)
at com.ibm.ram.client.RAMSession.put(RAMSession.java:5041)
My code goes like this :-
CategorySchema categorySchema = session.getCategorySchema(CustomPolicyConstants.BUSINESS_CAPABILITY_CATALOG);
RAMCategory bcCategory = (RAMCategory)categorySchema.getCategory(CustomPolicyConstants.BUSINESS_CAPABILITIES_ASSET_TYPE);
SubCategory subCategory = bcCategory.createSubCategory("NewSubCategory4");
getRAMSession().put(categorySchema, new RAMStatusMonitor());
Can anyone please shed light on this and let me know what am I doing wrong?
Thanks in advance for all your help.
com.ibm.ram.common.data.exception.RAMRuntimeException
at com.ibm.ram.client.RAMSession.putCategorySchema(RAMSession.java:3776)
at com.ibm.ram.client.RAMSession.put(RAMSession.java:5041)
at com.cof.custom.policy.CustomPolicyUtility.categorizeSubCategoryAssets(CustomPolicyUtility.java:488)
at com.cof.custom.policy.CustomPolicyUtility.manageAssets(CustomPolicyUtility.java:425)
at com.cof.custom.policy.CustomPolicyUtility.main(CustomPolicyUtility.java:755)
Caused by: java.lang.NullPointerException
at com.ibm.ram.client.RAMSession.putCategorySchema(RAMSession.java:3666)
... 4 more
Exception in thread "main" com.ibm.ram.common.data.exception.RAMRuntimeException
at com.ibm.ram.client.RAMSession.putCategorySchema(RAMSession.java:3776)
at com.ibm.ram.client.RAMSession.put(RAMSession.java:5041)
My code goes like this :-
CategorySchema categorySchema = session.getCategorySchema(CustomPolicyConstants.BUSINESS_CAPABILITY_CATALOG);
RAMCategory bcCategory = (RAMCategory)categorySchema.getCategory(CustomPolicyConstants.BUSINESS_CAPABILITIES_ASSET_TYPE);
SubCategory subCategory = bcCategory.createSubCategory("NewSubCategory4");
getRAMSession().put(categorySchema, new RAMStatusMonitor());
Can anyone please shed light on this and let me know what am I doing wrong?
Thanks in advance for all your help.
11 answers
I am working with RAM v7.5.1 and developing Java code to customize the RAM server. My objective is that when user creates/approves an asset of type "SubCategory" that subcategory should be visible in the left-hand catalog schema hierarchy. Please let me know if there are other approaches of resolution to the problem.
Yes, it is version 7.5.1 build RAM7511-I20120320_1046. It has the following test fixes.
Comments
a) The entire name of the jar that starts with the name com.ibm.ram.common?
Ans. The full name of the jar is com.ibm.ram.common_7.5.11.v20121127_0009
b) Are there any files in this directory labeled something like testfix12RamClient.xml? What are they named?
Ans. No.
c) Open the ramclient.jar and go to the META-INF\MANIFEST.MF file and tell me what the Created-By: entry in the manifest says?
Ans. IBM Rational CCB, build RAM7512-I20121126_1908
Ans. The full name of the jar is com.ibm.ram.common_7.5.11.v20121127_0009
b) Are there any files in this directory labeled something like testfix12RamClient.xml? What are they named?
Ans. No.
c) Open the ramclient.jar and go to the META-INF\MANIFEST.MF file and tell me what the Created-By: entry in the manifest says?
Ans. IBM Rational CCB, build RAM7512-I20121126_1908
Comments
This is the code that I am using
/**
*
*/
package com.cof.custom.policy;
import com.ibm.ram.client.RAMAsset;
import com.ibm.ram.client.RAMAssetQueryBuilder;
import com.ibm.ram.client.RAMCategory;
import com.ibm.ram.client.RAMCategorySchema;
import com.ibm.ram.client.RAMSession;
import com.ibm.ram.client.RAMSubCategory;
import com.ibm.ram.client.status.RAMStatusMonitor;
import com.ibm.ram.common.data.AssetSearchResult;
import com.ibm.ram.common.data.Relationship;
import com.ibm.ram.common.data.SearchResult;
/**
* @author fvz857
*
*/
public class TestCreateSubCategory {
public static RAMSession getRAMSession() {
RAMSession session = new RAMSession("https://10.42.102.20:11602/ram.ws","fvz857", "fvz857");
return session;
}
public static void categorizeSubCategoryAssets() {
RAMCategorySchema categorySchema = getRAMSession().getCategorySchema(CustomPolicyConstants.BUSINESS_CAPABILITY_CATALOG);
RAMCategory bcCategory = (RAMCategory)categorySchema.getCategory(CustomPolicyConstants.BUSINESS_CAPABILITIES_ASSET_TYPE);
RAMSubCategory sub = (RAMSubCategory) bcCategory.getSubCategory("Manage Delinquencies");
RAMSubCategory subCategory = sub.createSubCategory("New Delinquencies");
getRAMSession().put(categorySchema, new RAMStatusMonitor());
}
public static void main(String z[]){
categorizeSubCategoryAssets();
}
}
/**
*
*/
package com.cof.custom.policy;
import com.ibm.ram.client.RAMAsset;
import com.ibm.ram.client.RAMAssetQueryBuilder;
import com.ibm.ram.client.RAMCategory;
import com.ibm.ram.client.RAMCategorySchema;
import com.ibm.ram.client.RAMSession;
import com.ibm.ram.client.RAMSubCategory;
import com.ibm.ram.client.status.RAMStatusMonitor;
import com.ibm.ram.common.data.AssetSearchResult;
import com.ibm.ram.common.data.Relationship;
import com.ibm.ram.common.data.SearchResult;
/**
* @author fvz857
*
*/
public class TestCreateSubCategory {
public static RAMSession getRAMSession() {
RAMSession session = new RAMSession("https://10.42.102.20:11602/ram.ws","fvz857", "fvz857");
return session;
}
public static void categorizeSubCategoryAssets() {
RAMCategorySchema categorySchema = getRAMSession().getCategorySchema(CustomPolicyConstants.BUSINESS_CAPABILITY_CATALOG);
RAMCategory bcCategory = (RAMCategory)categorySchema.getCategory(CustomPolicyConstants.BUSINESS_CAPABILITIES_ASSET_TYPE);
RAMSubCategory sub = (RAMSubCategory) bcCategory.getSubCategory("Manage Delinquencies");
RAMSubCategory subCategory = sub.createSubCategory("New Delinquencies");
getRAMSession().put(categorySchema, new RAMStatusMonitor());
}
public static void main(String z[]){
categorizeSubCategoryAssets();
}
}
Comments
Thank you so much for your help. It works and I am not getting the NPE. But the newly-created sub-category does not show-up in the catalog hierarchy. What else do I need to do to achieve that?
It is the view that is available on RAM Web Client when searching for an asset. The left-side of the screen provides a "Visual Browse" view which can be used to browse to a particular asset.
The search can be filtered by either Category or Type or State or Community.
When the user clicks on "Category", the category hierarchy is displayed.
Category
Software Development
Kind
Process[1]
Schema[1]
Service[1]
Web Application[3]
I was referring the above structure as the "Category schema" hierarchy.
My requirement is that when the user creates a subcategory, that should show up on this hierarchy in the current location.i.e. under the correct category or subcategory.
The search can be filtered by either Category or Type or State or Community.
When the user clicks on "Category", the category hierarchy is displayed.
Category
Software Development
Kind
Process[1]
Schema[1]
Service[1]
Web Application[3]
I was referring the above structure as the "Category schema" hierarchy.
My requirement is that when the user creates a subcategory, that should show up on this hierarchy in the current location.i.e. under the correct category or subcategory.
Comments
Thanks for your help. Yes, I have checked the schema pages and verified that the category schema is updated but still not able to see the subcategory in the left view.
To do that I am going to Administration -> Category Schema to check the "update" column in the resulting view. Do you think that there are any filters that is set which is preventing the subcategory from getting displayed ?
However, when I try to create a new Asset, it shows up in the "Available categories" tree under the "Categories" tab.
After an asset is created under the newly created subCategory, then it shows up on the left side Category Schema view. Can there be any settings which determines that if there are no assets created under a sub-category, then that subCategory will not be displayed?
Please help.
To do that I am going to Administration -> Category Schema to check the "update" column in the resulting view. Do you think that there are any filters that is set which is preventing the subcategory from getting displayed ?
However, when I try to create a new Asset, it shows up in the "Available categories" tree under the "Categories" tab.
After an asset is created under the newly created subCategory, then it shows up on the left side Category Schema view. Can there be any settings which determines that if there are no assets created under a sub-category, then that subCategory will not be displayed?
Please help.
Comments
So, I am trying to categorize the subcategory asset object with the newly created sub-category to be compliant with the fact that "there must be at least one asset that has some child node of the category assigned to it."
But it fails with the following error :-
Exception in thread "main" com.ibm.ram.common.data.exception.RAMRuntimeException: Subcategory Business Capability Catalog/Business Capabilities/Move Money & Process Payments/My Buss Cap Asset5 was not found for the asset My Buss Cap Asset5[1.0].
at com.ibm.ram.client.RAMAsset.categorize(RAMAsset.java:2300)
at com.cof.custom.policy.CustomPolicyUtility.createUpdateSubCategory(CustomPolicyUtility.java:531)
at com.cof.custom.policy.CustomPolicyUtility.categorizeSubCategoryAssets(CustomPolicyUtility.java:493)
at com.cof.custom.policy.CustomPolicyUtility.manageAssets(CustomPolicyUtility.java:424)
at com.cof.custom.policy.CustomPolicyUtility.main(CustomPolicyUtility.java:849)
My program is as follows:-
public static void createUpdateSubCategory(RAMCategory category, RAMSubCategory subCategory, RAMAsset assetObj){
RAMSubCategory matchedCategory = null;
if(!isAssetExistsInCategory(subCategory, assetObj)){
matchedCategory= subCategory.createSubCategory(assetObj.getName());
try{
assetObj.categorize(category, subCategory.getName() + "/" + assetObj.getName());
}catch(Exception e){
assetObj.categorize(matchedCategory);
}
session.put(assetObj, new RAMStatusMonitor());
session.put(categorySchema, new RAMStatusMonitor());
}else{
matchedCategory = (RAMSubCategory)subCategory.getSubCategory(assetObj.getName());
assetObj.categorize(matchedCategory);
session.put(assetObj, new RAMStatusMonitor());
}
session.release();
}
Thanks in advance for your help.
But it fails with the following error :-
Exception in thread "main" com.ibm.ram.common.data.exception.RAMRuntimeException: Subcategory Business Capability Catalog/Business Capabilities/Move Money & Process Payments/My Buss Cap Asset5 was not found for the asset My Buss Cap Asset5[1.0].
at com.ibm.ram.client.RAMAsset.categorize(RAMAsset.java:2300)
at com.cof.custom.policy.CustomPolicyUtility.createUpdateSubCategory(CustomPolicyUtility.java:531)
at com.cof.custom.policy.CustomPolicyUtility.categorizeSubCategoryAssets(CustomPolicyUtility.java:493)
at com.cof.custom.policy.CustomPolicyUtility.manageAssets(CustomPolicyUtility.java:424)
at com.cof.custom.policy.CustomPolicyUtility.main(CustomPolicyUtility.java:849)
My program is as follows:-
public static void createUpdateSubCategory(RAMCategory category, RAMSubCategory subCategory, RAMAsset assetObj){
RAMSubCategory matchedCategory = null;
if(!isAssetExistsInCategory(subCategory, assetObj)){
matchedCategory= subCategory.createSubCategory(assetObj.getName());
try{
assetObj.categorize(category, subCategory.getName() + "/" + assetObj.getName());
}catch(Exception e){
assetObj.categorize(matchedCategory);
}
session.put(assetObj, new RAMStatusMonitor());
session.put(categorySchema, new RAMStatusMonitor());
}else{
matchedCategory = (RAMSubCategory)subCategory.getSubCategory(assetObj.getName());
assetObj.categorize(matchedCategory);
session.put(assetObj, new RAMStatusMonitor());
}
session.release();
}
Thanks in advance for your help.
page 1of 1 pagesof 2 pages
Comments
Rich Kulp
FORUM MODERATOR / JAZZ DEVELOPER Feb 07 '13, 1:12 p.m.