This discussion is archived
2 Replies Latest reply: Sep 30, 2008 7:59 AM by Pedja RSS

How to update  category attribute value for a folder

user652534 Newbie
Currently Being Moderated
I have the code listed below to update category attribute value for a folder. I got an error:

Error Code: ORACLE.FDK.ParameterError
Detailed Error Code: ORACLE.FDK.InvalidAttribute
Trace Id:
info (NamedValue[]):
OPT.CATEGORY_DEFINITION (NamedValue[])=
OPT.CATEGORY_CLASS_ID=94610 (Long)
OPT.CATEGORY_DEFINITION_ATTRIBUTES (NamedValue[])=
CUSTOM_157066=1000 (String)

Below is my source code. Is there any one can help to look into it?

package oracle.ifs.examples.api.metadata;

import java.util.Map;
import oracle.ifs.examples.api.constants.AttributeRequests;
import oracle.ifs.examples.api.util.CategoryUtils;
import oracle.ifs.examples.api.util.CommonUtils;
import oracle.ifs.examples.api.util.Logger;
import oracle.ifs.examples.api.util.SamplesConfiguration;
import oracle.ifs.fdk.AttributeRequest;
import oracle.ifs.fdk.ClientUtils;
import oracle.ifs.fdk.CommonManager;
import oracle.ifs.fdk.FdkCredential;
import oracle.ifs.fdk.FileManager;
import oracle.ifs.fdk.Item;
import oracle.ifs.fdk.ManagersFactory;
import oracle.ifs.fdk.NamedValue;
import oracle.ifs.fdk.Options;
import oracle.ifs.fdk.SimpleFdkCredential;

public class TestFolderCat
{
private static SamplesConfiguration s_Config =
SamplesConfiguration.getInstance();

private static Logger s_Logger = new Logger();

public static void main(String[] args)
{   
s_Logger.log("ApplyingCategories: starting");

FdkCredential credential = new SimpleFdkCredential(
"bpeladmin", "Password1");

ManagersFactory session = null;
try
{
session = ManagersFactory.login(credential, "http://ldbdocsl01.bcliquor.com:7777/content/ws");

FileManager fileM = session.getFileManager();

CommonManager commonmanager = session.getCommonManager();

AttributeRequest[] requestedAttributes = null;

if (session != null){
Item doc = null;
s_Logger.log("Session is created");
String docId = "188675";
//String docId = "188706";

AttributeRequest[] requestedAttribute =
AttributeRequests.ITEM_CATEGORY_CONFIGURATION;

try {           
doc = commonmanager.getItem(Long.parseLong(docId), requestedAttribute);
s_Logger.log(doc);
} catch (Exception s)
{
doc = null;
s_Logger.log("Can't get folder Item");
s_Logger.log(s);
}
requestedAttributes = AttributeRequests.CATEGORY_CLASS_ATTRIBUTES;
Item catClass = CategoryUtils.getCategoryClass(
session, null, "RM_File Plan", requestedAttributes);
if (catClass == null)
{
s_Logger.log(
"Category class not found");
throw new RuntimeException(
"Required category missing");
}
s_Logger.log("Class details");
s_Logger.log(catClass);

Map attributeMap = CategoryUtils.getCategoryAttrInternalNames(
session, catClass.getId(),
new String[]{"File Plan" ,"Records Series", "Record Category", "Retention Period", "Make Records After"});


String attribute5Name = (String) attributeMap.get("Make Records After");

s_Logger.log("Creating category instance definition ...");
NamedValue[] categoryInstanceAttributes = new NamedValue[] {

// ClientUtils.newNamedValue(attribute1Name, "0"),
// ClientUtils.newNamedValue(attribute2Name, "0"),
// ClientUtils.newNamedValue(attribute3Name, "0"),
// ClientUtils.newNamedValue(attribute4Name, "0"),
ClientUtils.newNamedValue(attribute5Name,"1000")
};

NamedValue[] categoryDef = new NamedValue[] {

ClientUtils.newNamedValue(
Options.CATEGORY_CLASS_ID, new Long(catClass.getId())),

ClientUtils.newNamedValue(
Options.CATEGORY_DEFINITION_ATTRIBUTES, categoryInstanceAttributes)
};

NamedValue[] floderDef = new NamedValue[] {
ClientUtils.newNamedValue(Options.CATEGORY_DEFINITION, categoryDef)
};

s_Logger.log("Updating folder with new category instance ...");
requestedAttributes = AttributeRequests.DOCUMENT_CATEGORY_ATTRIBUTES;
// requestedAttributes = AttributeRequests.ITEM_CATEGORY_CONFIGURATION;

try {
doc = fileM.updateFolder(doc.getId(), floderDef, requestedAttributes);
} catch (Exception s)
{
s_Logger.log("Can't update folder Item");
s_Logger.log(s);
};
s_Logger.log(doc);

} else {
s_Logger.log("can't create session");
}
}
catch (Throwable t)
{
s_Logger.log(t);
}
finally
{
CommonUtils.bestEffortLogout(session);
s_Logger.log("ApplyingCategories: done");
}
}
}
  • 1. Re: How to update  category attribute value for a folder
    560578 Newbie
    Currently Being Moderated
    Last time I inquired about this on this forum. I got told that category on folder arent updateable.
    And a workaround would be to keep a file IN the folder that act as a category values holder for the folder.

    Hope this helps!
  • 2. Re: How to update  category attribute value for a folder
    Pedja Expert
    Currently Being Moderated
    Hi,

    Here is my code that works for me, I hope you'll find it usefull:
        public  void setCategoryOnFolder(String folderPath, String categoryDisplayName, NamedValue[] attrNamesAndValues, StringBuffer s) throws FdkException, RemoteException, Exception {
            
            try{
                
                AttributeRequest[] attributeRequest = new AttributeRequest[]{
                    new AttributeRequest(Attributes.DISPLAY_NAME, null), 
                    new AttributeRequest(Attributes.CLASS_NAME, null), 
                    new AttributeRequest(Attributes.METADATA_ATTRIBUTES, new AttributeRequest[]{
                    new AttributeRequest(Attributes.ATTRIBUTE_NAME, null), 
                    new AttributeRequest(Attributes.DISPLAY_NAME, null)
                    })
                };
                Item folder = m_FileManager.resolvePath(folderPath, null);
                Item category = CustomFdkUtils.getCategoryObject(m_DomainManager, m_CommonManager, null, categoryDisplayName, attributeRequest);
                Item[] attributes = (Item[])CustomFdkUtils.getAttribute(category, Attributes.METADATA_ATTRIBUTES);
                long[] atrID = new long[attributes.length];
                for(int i=0; i<attributes.length; i++) atrID[i] = attributes.getId(); 

    Object[] attributeOverrides = new Object[attributes.length];
    for(int i=0; i<attributes.length; i++){
    NamedValue[] attributeOverride = new NamedValue[] {
    new NamedValue(Attributes.ATTRIBUTE_OVERRIDE_ATTRIBUTE, new Long(atrID[i])),
    new NamedValue(Attributes.ATTRIBUTE_OVERRIDE_CATEGORY_CLASS, new Long(category.getId())),
    new NamedValue(Attributes.ATTRIBUTE_OVERRIDE_DEFAULT, attrNamesAndValues[i].getValue()),
    new NamedValue(Attributes.ATTRIBUTE_OVERRIDE_REQUIRED, Boolean.TRUE),
    new NamedValue(Attributes.ATTRIBUTE_OVERRIDE_SETTABLE, Boolean.TRUE),
    new NamedValue(Attributes.ATTRIBUTE_OVERRIDE_PROMPT, Boolean.FALSE),
    };
    attributeOverrides[i] = attributeOverride;

    }

    long[] catID = {category.getId()};
    NamedValue[] categoryConfigurationAttributes = new NamedValue[attributes.length+4];
    categoryConfigurationAttributes[0] = new NamedValue(Attributes.REQUIRED_CATEGORIES, catID);
    categoryConfigurationAttributes[1] = new NamedValue(Attributes.ALLOWED_CATEGORIES, catID);
    categoryConfigurationAttributes[2] = new NamedValue(Attributes.CONFIGURATION_ENABLED, new Boolean(true));
    categoryConfigurationAttributes[3] = new NamedValue(Attributes.CONFIGURATION_FINAL, new Boolean(false));
    for(int i=4; i<categoryConfigurationAttributes.length; i++) categoryConfigurationAttributes[i] = new NamedValue(Attributes.ATTRIBUTE_OVERRIDE, (NamedValue[])attributeOverrides[i-4]);

    m_CategoryManager.setCategoryConfiguration(folder.getId(), categoryConfigurationAttributes);
    }
    catch(FdkException fe) {  s_Logger.log(Level.SEVERE, "Error setting category on folder."); throw fe; }
    catch(RemoteException re){  s_Logger.log(Level.SEVERE, "Error setting category on folder."); throw re; }
    catch(Exception e){  s_Logger.log(Level.SEVERE, "Error setting category on folder."); throw e; }

    }
    Pedja