How to create a subCategory in RAM using Java API
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
Comments
Just an FYI:
7.5.1 and 7.5.1.1 are not the same in RAM. Also just the testfix number would be sufficient. We don't need the list of actual defects. So you can say simply RAM 7.5.1.1 testfix 7d.
We need to know this information on any RAM question. This is because there are many different levels of RAM out there and they all have many differences from the previous ones.
I'll go see if I can see any problems with testfix 7 that would cause this.
Thanks.
OK, we have another problem. The version of RAM you gave us was naturally the server version. The problem is that your error is occurring in the ramclient and not the server. Your ramclient does not appear to be from 7511. The line numbers don't quite match up.
So can you please do the following, look in the directory where you are storing your ramclient.zip jars and tell me:
a) The entire name of the jar that starts with the name com.ibm.ram.common?
b) Are there any files in this directory labeled something like testfix12RamClient.xml? What are they named?
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?
These three together will tell me the version of the ramclient being used.
Thanks
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
Ah, you are using an internal build that has never been published. I'm not sure why it is failing.
Did you do a session.release() somewhere between the
session.getCategorySchema(CustomPolicyConstants.BUSINESS_CAPABILITY_CATALOG);
and the
getRAMSession().put(categorySchema, new RAMStatusMonitor());
That is the only way I could see an NPE at the given location.
/**
*
*/
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
public static RAMSession getRAMSession() {
RAMSession session = new RAMSession("https://10.42.102.20:11602/ram.ws","fvz857", "fvz857");
return session;
}
Every time you call getRAMSession() you are getting a brand new one. So the
getRAMSession().getCategorySchema() is a different ram session than the one retrieved via getRAMSession().put(...). You can't get a schema from one session and try to put it into a different session.
Not only that but you are leaking RAMSession's. You are required to do a session.release() on every RAMSession created. If you don't then session will leak and not logout.
Thanks,
Rich
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
That is a cached view. It is refreshed approximately once every ten minutes.
You need to first verify that the update actually worked on the host. Go to the Admin pages and verify that the schema has been updated. That view always shows the live current view. If that worked, then it will eventually show up on the search page.
My understanding is that the category is missing from the visual browse. Does it show up on the search page when you drill down to it?
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
For Visual Browse top category to show up there must be at least one asset that has some child node of the category assigned to it. Until then nothing shows. But once there is at least one then it will show them all. BUT you need to close the visual browser after making the change. The categories for the visualbrowse are only retrieved once, when the browser is started. You need to close and reopen it to see the new sub-category.
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.
Comments
Rich Kulp
FORUM MODERATOR / JAZZ DEVELOPER Feb 07 '13, 1:12 p.m.What is the exact version of the RAM client that you are using? I can't find out which version that the line numbers shown match up with.