cancel
Showing results for 
Search instead for 
Did you mean: 

How to validate RID

Former Member
0 Kudos

Hi,

Is it possible to check whether an RID is valid or nor, ie, the corresponding folder actually exists or not?

I am using th following code to get the RID:

String path = "/KM/"+"SAP IMPLEMENTATION PROJECTS/"+project+rs_prop.getString("folder");
RID rid=RID.getRID(path);

In the next line I want to check whether the RID path actually exists before proceeding further. How can this be done? I tried if(rid!=null). But it didnt work.

Please Help.

Thanks,

Das.

Accepted Solutions (1)

Accepted Solutions (1)

former_member188556
Active Contributor
0 Kudos

Hi Krishna

U can validate like this

ICollection folder = null;
folder =(ICollection) resourceFactory.getResource(
		RID.getRID(properties.getProperty("Folder")),
			resourceContext);
if(folder!=null){

}

Regards

BP

Former Member
0 Kudos

Hi Bobu,

I have already tried this. But in our case since there are more than 30 folders which doesnt have a valid path, it is taking a lot of time to execute the line:

folder =(ICollection) resourceFactory.getResource(

RID.getRID(properties.getProperty("Folder")),

resourceContext);

Seems it is time consuming to try to get a resource which does not exist. Is there anything that can be done to validate the RID other than trying to access the resource and then checking its value?

Thanks,

Das.

Former Member
0 Kudos

A RID is valid independantly of whether the resource exists or not (just pointing out terminology).

I think the ResourceFactory also has a checkExistance method, but I doubt it makes a difference performance-wise.

Best regards, Julian

former_member188556
Active Contributor
0 Kudos

Hi Krishna

Why dont u use resource iterator?

It will give u only valid resources.

and also u can use isCollection() method to validate whether its folder or file


IResourceFactory resourceFactory;
IResourceContext resourceContext;
IUser cmAdminUser = null;
try {
	cmAdminUser =
		WPUMFactory.getServiceUserFactory().getServiceUser(
			"cmadmin_service");
} catch (UserManagementException e) {
	// TODO Auto-generated catch block
		e.printStackTrace();
}
resourceFactory = ResourceFactory.getInstance();
resourceContext = new ResourceContext(cmAdminUser);
ICollection folder = null;
folder = (ICollection) resourceFactory.getResource(
		RID.getRID(properties.getProperty("/documents/Folder/")),
			resourceContext);
IResourceList resList = null;
try {
	resList = folder.getChildren();
} catch (AccessDeniedException e1) {
	// TODO Auto-generated catch block
		response.write(
			"You dont have enough permission!!!<br>"
				+ e1.getLocalizedMessage());
	e1.printStackTrace();
} catch (ResourceException e1) {
	// TODO Auto-generated catch block
		response.write(e1.getLocalizedMessage());
		e1.printStackTrace();
}

IResourceListIterator iter = resourceList.listIterator();
while (iter.hasNext()) {
	IResource tempres = iter.next();
		if (!tempres.isCollection()) {
        }
}

This may help u

Regards

BP

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

you have to check by getting the Collection under the RID:


bolean exists = false;
try  {
IResourceContext rContext = new ResourceContext(curUser);
IResource res = ResourceFactory.getInstance().getResource(rid, rContext);
if(res!=null) {
exists = true;
}
} catch (Exception e)  {
//...
}

Romano