05-04-2011 11:13 AM
function searchRootCategory(categoryName) {
logger.log("searchRootCategory, entrato");
var categoryToReturn = null;
var luceneQuery = "+TYPE:\"cm:category\" +@cm\\:name:\""+categoryName+"\"";
logger.log("searchRootCategory, eseguo la query ["+luceneQuery+"]");
var categories = search.luceneSearch(luceneQuery);
if (categories.length > 0) {
categoryToReturn = categories[0];
logger.log("searchRootCategory, category " + categoryName + " trovata");
} else {
logger.log("searchRootCategory, category " + categoryName + " NON trovata");
}
logger.log("searchRootCategory, uscito");
return categoryToReturn;
}
function searchSubCategory(rootCategoryName, subCategoryName) {
logger.log("searchSubCategory, entrato");
var subCategoryToReturn = null;
var rootCategoryNameToSearch = search.ISO9075Encode(rootCategoryName);
var luceneQuery = "+PATH:\"/cm:generalclassifiable/cm:"+rootCategoryNameToSearch+"/*\" +@cm\\:name:\""+subCategoryName+"\"";
logger.log("searchSubCategory, eseguo la query ["+luceneQuery+"]");
var subCategories = search.luceneSearch(luceneQuery);
if (subCategories.length > 0) {
subCategoryToReturn = subCategories[0];
logger.log("searchSubCategory, category " + subCategoryName + " trovata nella root category "+rootCategoryName);
} else {
logger.log("searchSubCategory, category " + subCategoryName + " NON trovata nella root category "+rootCategoryName);
}
logger.log("searchSubCategory, uscito");
return subCategoryToReturn;
}
function createSubCategory(rootCategoryName, subCategoryName) {
logger.log("createSubCategory, entrato");
var subCategoryToReturn = null;
var rootCategory = searchRootCategory(rootCategoryName);
if (rootCategory != null){
var subCategoryFound = searchSubCategory(subCategoryName, rootCategory);
if (subCategoryFound == null){
subCategoryToReturn = rootCategory.createSubCategory(subCategoryName);
} else {
subCategoryToReturn = subCategoryFound;
}
} else {
logger.log("createSubCategory, NON posso creare la subCategory ["+subCategoryName+"] perchè la root category ["+rootCategoryName+"] NON esiste");
}
logger.log("createSubCategory, uscito");
return subCategoryToReturn;
}
The lucene search query works fine ('ve tryed it in the node browser), but I can't execute the "rootCategory.createSubCategory" because the method is not set for a ScriptNode object, infact if I launch the:rootCategory.isCategory
it returned me false, and for me this is strange because the returned node has set the cm:category aspect.06-01-2011 12:48 PM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.