This discussion is archived
1 2 Previous Next 23 Replies Latest reply: Jan 16, 2008 10:28 PM by 617460 RSS

Updating a document with category metadata using updateDocument(): error!

478333 Newbie
Currently Being Moderated
I have studied the sample code and the API docs, and I feel pretty sure I am coding it according to the docs, but I cannot successfully update a document with category metadata. I always get a MetaDataSchemaInvalid exception.

My process goes like this:
1. Upload a new file, creating a new document publicobject.
2. Create a CATEGORY_DEFINITION with all the metadata name/value pairs I wish to write.
3. Call FileManager.updateDocument() with this CATEGORY_DEFINITION.

My process differs from the docs in that I am first uploading the document, and then adding the metadata as a second step. I want to get it working this way to make my system more modular. I do not want to make my upload method dependent upon metadata attributes, and vice versa.

Step 1 is working fine. The document is being uploaded to the right folder. Good to go.

Step 3 is where I get the error. If the error is my fault, then it must be a result of what I do in step 2. The structure of my CATEGORY_DEFINITION must be messed up.

Here is my code for creating the CATEGORY_DEFINITION. The Document class is my own entity that encapsulates the binary data for a document, as well as the metadata attributes that are to be assigned to the document once it is uploaded into Content Services. We don't need to worry about where the data comes from. Just assume the raw data is correct.



public NamedValue[] newCategoryAttributeDefinition(Document document, String categoryDisplayName) throws WebserviceClientException {
/* Get the category attribute name-value pairs as a 2-D array. */
Map metadataMap = document.getMetadataParser().getAttributeNameMapping();
List categoryDefinitionAttributeList = new ArrayList();
for(Iterator i = metadataMap.entrySet().iterator(); i.hasNext();) {
Map.Entry entry = (Map.Entry)i.next();
String name = "CUSTOM_" + (String)entry.getKey();
Object value = entry.getValue();
if(value != null) {
categoryDefinitionAttributeList.add(new Object[] { name, value });
}
}
Object[][] categoryDefinitionAttributeArray = new Object[categoryDefinitionAttributeList.size()][];
int index = 0;
for(Iterator i = categoryDefinitionAttributeList.iterator(); i.hasNext();) {
Object[] value = (Object[])i.next();
categoryDefinitionAttributeArray[index++] = value;
}
/* Create the NamedValue tree that describes this category's attribute values. */
Long categoryId = new Long(getCategoryClassId(categoryDisplayName));
NamedValue[] categoryAttributeDefinition = WebserviceUtils.newNamedValueArray(new Object[][] {
{ Options.CATEGORY_ID, categoryId },
{ Options.CATEGORY_DEFINITION_ATTRIBUTES, WebserviceUtils.newNamedValueArray(categoryDefinitionAttributeArray) }
});
NamedValue[] categoryDefinition = WebserviceUtils.newNamedValueArray(Options.CATEGORY_DEFINITION, categoryAttributeDefinition);
return categoryDefinition;
}



And below is the resulting CATEGORY_DEFINITION, as seen in a jdb debugger.

-- The OPT.CATEGORY_ID value is equal to the ID column in ODMV_SCHEMACATEGORY, otherwise known as the category class id.

-- My OPT.CATEGORY_DEFINITION_ATTRIBUTES tree for this document has the 4 attributes that I want to set. The category has more than these 4 attributes; I am not populating every attribute. None of the attributes are required, and all are editable. I don't need to include every attribute in my CATEGORY_DEFINITION, even if the values are null, do I? Also, all the attribute names start with "CUSTOM_", which I believe is necessary - right?

-- I am setting only the OPT.CATEGORY_ID and OPT.CATEGORY_DEFINITION_ATTRIBUTES. Am I missing some other required attribute?



http-8888-Processor5[1] http-8888-Processor5[1] dump categoryDefinition
categoryDefinition = {
instance of oracle.ifs.fdk.NamedValue(id=2562)
}
http-8888-Processor5[1] dump categoryDefinition[0]
categoryDefinition[0] = {
name: "OPT.CATEGORY_DEFINITION"
value: instance of oracle.ifs.fdk.NamedValue[2] (id=2559)
__equalsCalc: null
__hashCodeCalc: false
typeDesc: instance of org.apache.axis.description.TypeDesc(id=2564)
class$oracle$ifs$fdk$NamedValue: instance of java.lang.Class(reflected class=oracle.ifs.fdk.NamedValue, id=1975)
}
http-8888-Processor5[1] dump categoryDefinition[0].value[0]
categoryDefinition[0].value[0] = {
name: "OPT.CATEGORY_ID"
value: instance of java.lang.Long(id=2558)
__equalsCalc: null
__hashCodeCalc: false
typeDesc: instance of org.apache.axis.description.TypeDesc(id=2564)
class$oracle$ifs$fdk$NamedValue: instance of java.lang.Class(reflected class=oracle.ifs.fdk.NamedValue, id=1975)
}
http-8888-Processor5[1] dump categoryDefinition[0].value[0].value.toString()
categoryDefinition[0].value[0].value.toString() = "60068"
http-8888-Processor5[1] dump categoryDefinition[0].value[1]
categoryDefinition[0].value[1] = {
name: "OPT.CATEGORY_DEFINITION_ATTRIBUTES"
value: instance of oracle.ifs.fdk.NamedValue[4] (id=2570)
__equalsCalc: null
__hashCodeCalc: false
typeDesc: instance of org.apache.axis.description.TypeDesc(id=2564)
class$oracle$ifs$fdk$NamedValue: instance of java.lang.Class(reflected class=oracle.ifs.fdk.NamedValue, id=1975)
}
http-8888-Processor5[1] dump categoryDefinition[0].value[1].value[0]
categoryDefinition[0].value[1].value[0] = {
name: "CUSTOM_From"
value: "SA"
__equalsCalc: null
__hashCodeCalc: false
typeDesc: instance of org.apache.axis.description.TypeDesc(id=2564)
class$oracle$ifs$fdk$NamedValue: instance of java.lang.Class(reflected class=oracle.ifs.fdk.NamedValue, id=1975)
}
http-8888-Processor5[1] dump categoryDefinition[0].value[1].value[1]
categoryDefinition[0].value[1].value[1] = {
name: "CUSTOM_Footer Number"
value: "PRM 34-318"
__equalsCalc: null
__hashCodeCalc: false
typeDesc: instance of org.apache.axis.description.TypeDesc(id=2564)
class$oracle$ifs$fdk$NamedValue: instance of java.lang.Class(reflected class=oracle.ifs.fdk.NamedValue, id=1975)
}
http-8888-Processor5[1] dump categoryDefinition[0].value[1].value[2]
categoryDefinition[0].value[1].value[2] = {
name: "CUSTOM_To"
value: "PROJECT TEAM"
__equalsCalc: null
__hashCodeCalc: false
typeDesc: instance of org.apache.axis.description.TypeDesc(id=2564)
class$oracle$ifs$fdk$NamedValue: instance of java.lang.Class(reflected class=oracle.ifs.fdk.NamedValue, id=1975)
}
http-8888-Processor5[1] dump categoryDefinition[0].value[1].value[3]
categoryDefinition[0].value[1].value[3] = {
name: "CUSTOM_Subject"
value: "Riverside Energy Resource Center Meeting Minutes-Internal"
__equalsCalc: null
__hashCodeCalc: false
typeDesc: instance of org.apache.axis.description.TypeDesc(id=2564)
class$oracle$ifs$fdk$NamedValue: instance of java.lang.Class(reflected class=oracle.ifs.fdk.NamedValue, id=1975)
}



After building this CATEGORY_DEFINITION, I go on to attempt an update to the document with this information. Here is the method I call. I always fall into the catch(), and the error dump follows the code snippet. Unfortunately, the error doesn't tell me a lot about what's wrong. That's why I am asking for help in spotting any conspicuous errors in my CATEGORY_DEFINITION.



public Item addCategoryToDocument(Item documentItem,
NamedValue[] categoryDefinition)
throws WebserviceClientException {
FileManager fileManager = getWebserviceClient().getFileManager();
Item documentItemWithCategory = null;
try {
documentItemWithCategory = fileManager.updateDocument(documentItem.getId(), categoryDefinition, null);
} catch(Exception e) {
throw new WebserviceClientException("Could not update document with category definition.", e);
}
return documentItemWithCategory;
}



http-8888-Processor4[1] http-8888-Processor4[1] dump e
e = {
detailedErrorCode: "ORACLE.FDK.AggregateError"
errorCode: "ORACLE.FDK.AggregateError"
exceptionEntries: instance of oracle.ifs.fdk.FdkExceptionEntry[1] (id=2691)
info: null
serverStackTraceId: ""
__equalsCalc: null
__hashCodeCalc: false
typeDesc: instance of org.apache.axis.description.TypeDesc(id=2694)
class$oracle$ifs$fdk$FdkException: instance of java.lang.Class(reflected class=oracle.ifs.fdk.FdkException, id=1972)
org.apache.axis.AxisFault.log: instance of org.apache.commons.logging.impl.Log4JLogger(id=2695)
org.apache.axis.AxisFault.faultCode: instance of javax.xml.namespace.QName(id=2696)
org.apache.axis.AxisFault.faultSubCode: null
org.apache.axis.AxisFault.faultString: "ORACLE.FDK.AggregateError:ORACLE.FDK.AggregateError"
org.apache.axis.AxisFault.faultActor: null
org.apache.axis.AxisFault.faultDetails: instance of java.util.Vector(id=2698)
org.apache.axis.AxisFault.faultNode: null
org.apache.axis.AxisFault.faultHeaders: null
org.apache.axis.AxisFault.class$org$apache$axis$AxisFault: instance of java.lang.Class(reflected class=org.apache.axis.AxisFault, id=1928)
java.rmi.RemoteException.serialVersionUID: -5148567311918794206
java.rmi.RemoteException.detail: null
java.lang.Exception.serialVersionUID: -3387516993124229948
java.lang.Throwable.serialVersionUID: -3042686055658047285
java.lang.Throwable.detailMessage: null
java.lang.Throwable.cause: null
java.lang.Throwable.stackTrace: instance of java.lang.StackTraceElement[76] (id=2699)
}
http-8888-Processor4[1] dump e.exceptionEntries[0]
e.exceptionEntries[0] = {
detailedErrorCode: "ORACLE.FDK.MetadataSchemaInvalid"
errorCode: "ORACLE.FDK.MetaDataError"
id: 348018
info: null
serverStackTraceId: ""
__equalsCalc: null
__hashCodeCalc: false
typeDesc: instance of org.apache.axis.description.TypeDesc(id=2705)
class$oracle$ifs$fdk$FdkExceptionEntry: instance of java.lang.Class(reflected class=oracle.ifs.fdk.FdkExceptionEntry, id=1973)
}
  • 1. Re: Updating a document with category metadata using updateDocument(): erro
    478333 Newbie
    Currently Being Moderated
    Here's a more narrow, direct question: when building the CATEGORY_DEFINITION for use in the FileManager.updateDocument() method call, should I use the category class ID (the ID from the ODMV_SCHEMACATEGORY view) or the category instance ID (the ID from the ODMV_PUBLICOBJECT view where the CLASSOBJECT is ADHOCCONFIGURATION and the SECURINGPUBLICOBJECT is the uploaded document)?
  • 2. Re: Updating a document with category metadata using updateDocument(): erro
    102972 Newbie
    Currently Being Moderated
    You need to use the category class id.

    regards,
    -sancho
  • 3. Re: Updating a document with category metadata using updateDocument(): erro
    478333 Newbie
    Currently Being Moderated
    Hmmm... when I use the ID from the odmv_schemacategory view (60068 in my case), I get the MetaDataSchemaInvalid error. When I use the ASSOCIATEDSCHEMAOBJECT value from the odmv_schemacategory view (60050 in my case), I get an UnexpectedError. When you say "category class ID", I guess you must mean the ID from the odmv_schemacategory view, since the error looks a little less bad.

    I guess my problem must be in the construction of the CATEGORY_CONFIGURATION then. This is one of the few areas of the oracle.ifs.fdk API that is adequately documented (see FileManager.updateDocument() in the javdoc, and then follow the link to CATEGORY_DEFINITION). I cannot see where my CATEGORY_DEFINITION deviates from this documentation, yet it must or I would not be getting the error (assuming the API works as claimed). Reading other peoples' posts leads me to believe that others are able to get this to work.

    If anybody can spot an error in my CATEGORY_CONFIGURATION, I would be grateful to gear about it. If the format of the jdb dump provided is too hard to read, I can reformat the information in a more user-friendly format.

    Is my methodology of performing the upload first and adding the metadata later a bad plan? Should I do both at once?
  • 4. Re: Updating a document with category metadata using updateDocument(): erro
    478333 Newbie
    Currently Being Moderated
    In oracle forum post Re: How to fill attributes for a given Category when uploading a new file? , the user experienced an issue whenever a date appeared in the metadata attributes. I have a date in mine as well. I will try to omit it for testing. The guy with the date problem does not appear to have found a solution (at least he didn't say so). He did not say what his exception was, which is too bad.
  • 5. Re: Updating a document with category metadata using updateDocument(): erro
    478333 Newbie
    Currently Being Moderated
    I made a bit of headway. My category was set to required, but the individual attributes were not. Just for the fun of it, I set all the attributes to required. Voila! my error changed to "ORACLE.FDK.MetadataAttributeRequired". This is an improvement, for it implies that the API was able to resolve my category and inspect its attributes. It threw the error because I did not supply name/value pairs for all required attributes.

    My next step is to provide all required data. If that works, then I will need to attack the issue of needing to set the attributes to required. Why is it necessary? Why wouldn't the API allow me to set an attribute, even if it's optional? Is this a feature or a bug?
  • 6. Re: Updating a document with category metadata using updateDocument(): erro
    478333 Newbie
    Currently Being Moderated
    Setting the metadata attributes to required did nothing. Still get the MetaDataSchemaInvalid error.

    I moved the category setting code into the upload code. I now set the CATEGORY_DEFINITION right away when creating the document. Once again, the error still occurs. The "document" object in this code snippet is my own entity. It contains the folder ID and CATEGORY_DEFINITION:

    document.setFolderId(folder.getId());
    NamedValue[] documentDefinition = WebserviceUtils.newNamedValueArray(new Object[][] {
    { Options.DESTFOLDER, new Long(document.getFolderId()) },
    { Options.CATEGORY_DEFINITION, document.getCategoryDefinition() },
    { Options.USE_SAVED_DEFINITION, new Long(documentDefinitionItem.getId()) }
    });
    Item documentItem = null;
    try {
    documentItem = fileManager.createDocument(documentDefinition, null, null);
    } catch(Exception e) {
    throw new WebserviceClientException("Could not create document. Check for missing required metadata fields, etc.", e);
    }

    A close inspection of the CATEGORY_DEFINITION shows that it looks just like the one in oracle.ifs.examples.ws.CategoryOperations.createDocumentWithCategory(). It is a simple configuration, easily verifiable, little opportunity for error. Still stumped on this one.

    There was a prevoius post regarding a problem setting a Date attribute. I have a Date attribute in my category. I will try removing it and see if that helps. Naturally, this is not a long-term solution, only a debugging measure. Any helpful hints for setting Date values?
  • 7. Re: Updating a document with category metadata using updateDocument(): erro
    478333 Newbie
    Currently Being Moderated
    I have found information stating that I need to use the internal metadata attribute names rather than the human-friendly ones. For instance, my attribute names need to look like "CUSTOM_12345" rather than "CUSTOM_Vendor". Is this true? I am working toward this implementation, but I am finding that it is a somewhat convoluted procedure to get a mapping of human-readable attribute names to internal attribute names. It would help if I could get each individual metadata attribute as an Item rather than as a NamedValue. This would allow me to use CommonManager.getItem() to fetch the DISPLAY_NAME.

    I am using the following code at the moment to query the document for all its category info. How can I modify this to get each metadata attribute to include its DISPLAY_NAME?

    public Item getItemWithCategoryInfo(Item documentItem) throws WebserviceClientException {
    /* Build the request for all category information on the document. */
    AttributeRequest[] displayNameRequest = new AttributeRequest[] {
    new AttributeRequest(Attributes.DISPLAY_NAME, null)
    };
    AttributeRequest[] metadataRequest = new AttributeRequest[] {
    new AttributeRequest(Attributes.CUSTOM_ALL, null),
    new AttributeRequest(Attributes.CATEGORY_CLASS_OBJECT, displayNameRequest)
    };
    AttributeRequest[] categoryRequest = new AttributeRequest[] {
    new AttributeRequest(Attributes.CATEGORIES, metadataRequest)
    };
    /* Get all category information on the document. */
    try {
    documentItem = getCommonManager().getItem(documentItem.getId(), categoryRequest);
    } catch(RemoteException e) {
    throw new WebserviceClientException(e.getMessage().replaceAll("\n", " "), e);
    }
    return documentItem;
    }
  • 8. Re: Updating a document with category metadata using updateDocument(): erro
    102972 Newbie
    Currently Being Moderated
    You need to specify the date as a java.util.Calendar

    regards,
    -sancho
  • 9. Re: Updating a document with category metadata using updateDocument(): erro
    102972 Newbie
    Currently Being Moderated
    Yes you must use the internal name when creating the category configuration. You can maintain a map of display-name to attribute-name (that is populated on startup) and then use code like the following to generate your category definition:

    public static NamedValue[] createCategoryDefinition(FdkSession markupSession, Long docId, Long markupId,
    String markupName, Long userId, boolean privateMarkup)
    throws MarkupException
    {
    Map catAttributes = getMarkupCategoryAttributeMap(markupSession);
    NamedValue[] attrs = new NamedValue[5];
    attrs[0] = new NamedValue();
    attrs[0].setName((String)catAttributes.get(MarkupConstants.MARKUP_ID));
    attrs[0].setValue(markupId);
    attrs[1] = new NamedValue();
    attrs[1].setName((String)catAttributes.get(MarkupConstants.MARKUP_AUTHOR));
    attrs[1].setValue(userId);
    attrs[2] = new NamedValue();
    attrs[2].setName((String)catAttributes.get(MarkupConstants.MARKUP_PRIVATE));
    attrs[2].setValue(privateMarkup ? Boolean.TRUE : Boolean.FALSE);
    attrs[3] = new NamedValue();
    attrs[3].setName((String)catAttributes.get(MarkupConstants.MARKUP_DOCID));
    attrs[3].setValue(docId);
    attrs[4] = new NamedValue();
    attrs[4].setName((String)catAttributes.get(MarkupConstants.MARKUP_NAME));
    attrs[4].setValue((markupName != null) ? markupName : "");

    NamedValue[] catDefn = new NamedValue[2];
    catDefn[0] = new NamedValue();
    catDefn[0].setName(Options.CATEGORY_CLASS_ID);
    catDefn[0].setValue(new Long(getMarkupCategory(markupSession).getId()));
    catDefn[1] = new NamedValue();
    catDefn[1].setName(Options.CATEGORY_DEFINITION_ATTRIBUTES);
    catDefn[1].setValue(attrs);

    return catDefn;
    }

    To populate the category attribute map try something like:

    public static Item getMarkupCategory(FdkSession markupSession)
    throws MarkupException
    {
    Item category = Cache.getInstance().getCategory();
    if (category != null)
    {
    return category;
    }

    // category not found so lets look it up
    String categoryName = MarkupProperties.getInstance().getMarkupCategoryName();

    System.out.println("Looking up category: "+categoryName);
    try
    {
    AttributeRequest[] attAr = new AttributeRequest[2];
    attAr[0] = new AttributeRequest();
    attAr[0].setAttributeName(Attributes.DISPLAY_NAME);
    attAr[1] = new AttributeRequest();
    attAr[1].setAttributeName(Attributes.ATTRIBUTE_NAME);

    AttributeRequest[] catAr = new AttributeRequest[1];
    catAr[0] = new AttributeRequest();
    catAr[0].setAttributeName(Attributes.METADATA_ATTRIBUTES);
    catAr[0].setRequestedAttributes(attAr);

    category = FdkUtils.getCategoryObject(markupSession, null,
    categoryName, catAr);
    }
    catch (Exception e)
    {
    throw new MarkupException(MarkupException.INSTANCE_NOT_INITIALIZED, e);
    }

    if (category == null)
    {
    throw new MarkupException(MarkupException.INSTANCE_NOT_INITIALIZED);
    }
    else
    {
    Cache.getInstance().setCategory(category);

    // since we found the category lets also init the attribute map
    Map attrMap = new HashMap();
    Item[] attrs = (Item[])FdkUtils.getAttribute(category, Attributes.METADATA_ATTRIBUTES);
    for (int ii=0; ii< attrs.length; ii++)
    {       
    attrMap.put(FdkUtils.getAttribute(attrs[ii], Attributes.DISPLAY_NAME),
    FdkUtils.getAttribute(attrs[ii], Attributes.ATTRIBUTE_NAME));
    }
    Cache.getInstance().setCategoryAttributeMap(attrMap);
    }

    return category;
    }

    regards,
    -sancho
  • 10. Re: Updating a document with category metadata using updateDocument(): erro
    478333 Newbie
    Currently Being Moderated
    This code helped a lot. I was able to achieve partial success. I can write the attribute values now (including dates - thanks for the GregorianCalendar tip), but I get a new, duplicate category as well. The original category instance is left unpopulated, while the new, dupe category gets all the attribute values.

    I'm sure this has at least something to do with the ID I'm putting in CATEGORY_CLASS_ID. By the way, CATEGORY_CLASS_ID doesn't exist in class Attributes, at least not in my version of the oracle.ifs.fdk jar file. Another bit of documentation I found calls it UPDATE_CATEGORY_ID, which doesn't exist either.

    I used Options.CATEGORY_ID, but with the class object ID as the value. If I try to use a category instance ID, I get an oracle.ifs.fdk.ServerError. This is all the information I can find on the error - not very helpful. From this error, I cannot tell if the error is due to bad AttributeRequest structure, bad category instance (or no category instance), or something completely different, like I'm using the wrong category ID or something. I know that changing the category ID is all I need to do to make it work or fail (if you call sprouting a dupe category "working").

    Also, I had to add a top-level wrapper to the AttributeRequest. Without this, I could not get the code to work:

    NamedValue[] categoryAttributeDefinition = WebserviceUtils.newNamedValueArray(new Object[][] {
    { Options.CATEGORY_ID, categoryId },
    { Options.CATEGORY_DEFINITION_ATTRIBUTES, WebserviceUtils.newNamedValueArray(categoryDefinitionAttributeArray) }
    });
    NamedValue[] categoryDefinition = new NamedValue[] {
    new NamedValue(Options.CATEGORY_DEFINITION, categoryAttributeDefinition)
    };

    There is still much confusion over the meaning of "category ID" in this context. Your sample code sets the category ID using a method that I do not have the source code for. Without this implementation, I cannot know exactly what the mehod call returns:

    category = FdkUtils.getCategoryObject(markupSession, null, categoryName, catAr);

    Time for direct questions:

    - Should there be such a thing as Options.CATEGORY_CLASS_ID? Am I using the wrong jar file? Mine is called content-ws-1011.jar.

    - There are lots of different IDs that can be called "category ID". There is the category class object ID, the category class ID ("<domain-id>_AHC_<ID>), the instance ID on the parent folder (ADHOCCONFIGURATION), and the instance ID on the document itself. No docs I've seen have clearly specified which to use. Which to use?

    - Was it bad to wrap the AttributeRequest in a CATEGORY_DEFINITION?
  • 11. Re: Updating a document with category metadata using updateDocument(): erro
    514432 Newbie
    Currently Being Moderated
    see >>> Java & C# Content Services 10.1.2.3 Accelerator kits posted to OTN <<<
    Here you can find CATEGORY_CLASS_ID and UPDATE_CATEGORY_ID in the newer versions.

    I also have this problem, only when I use UPDATE_CATEGORY_ID I get:

    AxisFault
    faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
    faultSubcode:
    faultString: ORACLE.FDK.UnexpectedError:ORACLE.FDK.ServerError

    but when I use CATEGORY_CLASS_ID, it works but I also have the same category twice on a document, the old one and the new with the right values.

    who can help us?

    regards CJ
  • 12. Re: Updating a document with category metadata using updateDocument(): erro
    mshannon Newbie
    Currently Being Moderated
    1 – For an existing document, how do I determine what category instances have been applied to it and their attribute values
    FdkSession session = …;
    // Consider we have an existing item myDoc of type document
    Item myDoc = …;

    CommonManager cm = Managers.getCommonManager(session);

    AttributeRequest[] requestedAttributes = new AttributeRequest[]
    {
      // The Categories associated with this Document, if any
    new AttributeRequest(Attributes.CATEGORIES,
      // sub attributerequest
      new AttributeRequest[] {
        // the actual attributes name/values for the category instance – returns a namedvalue array
        new AttributeRequest(Attributes.CUSTOM_ALL,null),
        // the actual category class for the category instance – returns an item
        new AttributeRequest(Attributes.CATEGORY_CLASS_OBJECT,null)
      }
    )
    };

    myDoc = cm.getItem(myDoc.getId(), requestedAttributes);
    log(myDoc);
    /* output could look like:

    (Item) 14385 DOCUMENT sample3.doc
    requested attributes ...
    CATEGORIES (Item[])=
    (Item) 14387 CATEGORY
    requested attributes ...
    CUSTOM_ALL (NamedValue[])=
    CUSTOM_14352=true (Boolean)
    CUSTOM_14353=Internal Only Pending Review (String)
    CATEGORY_CLASS_OBJECT (Item)=
    (Item) 14354 CATEGORY_CLASS 5044-14351

    This means, that for document sample3.doc, we have 1 instance of a category object applied to it.
    The category object instance has id 14387. The instance is of a category class object type 14354. The instance has two attributes with internal names CUSTOM_14352, and CUSTOM_15353. The values of these attributes are of type Boolean and String respectively.

    */

    2 - How do I update an attribute value of an existing category instance applied to an item
    FdkSession session = …;
    // Consider we have an existing item myDoc of type document
    Item myDoc = …;

    .. perform code along the lines of that shown in step1 above to determine existing category instance info on the document ..

    FileManager fm = Managers.getFileManager(session);

    NamedValue[] categoryInstanceAttributes = new NamedValue[] {
      // use the internal attribute name for all attributes
      new NamedValue("CUSTOM_14352", Boolean.FALSE),
      new NamedValue("CUSTOM_14352", "Company Confidential")
    };
    NamedValue[] categoryDef = new NamedValue[] {
      // the category instance that we are updating
    new NamedValue(Options.UPDATE_CATEGORY_ID,new Long(14387)),
    // the updated values of the category instance
      new NamedValue(Options.CATEGORY_DEFINITION_ATTRIBUTES, categoryInstanceAttributes)
    };

    NamedValue[] documentDef = new NamedValue[] {
    new NamedValue(Options.CATEGORY_DEFINITION, categoryDef)
    };

    requestedAttributes = ...
    myDoc = fm.updateDocument(myDoc.getId(),documentDef,requestedAttributes) ;
    3 – For a document item X, what is the associated category configuration which could include
    a) what are the category objects I can apply on it (either explicitly restricted by way of ALLOWED_CATEGORIES on the folder configuration, or any site/domain category by way of ALLOW_ALL_CATEGORIES)
    b) is there any attribute overrides
    c) is there any enforced categories
    FdkSession session = …;
    // Consider we have an existing item myDoc of type document
    Item myDoc = …;

    CommonManager cm = Managers.getCommonManager(session);

    AttributeRequest[] categoryObjectAttributes = new AttributeRequest[]
    {
    // What is the category object class name
    new AttributeRequest(Attributes.CLASS_NAME,null),
      // What is the category classobject display name
    new AttributeRequest(Attributes.DISPLAY_NAME,null),
    // get attributes inherited and introduced by category object
    new AttributeRequest(Attributes.METADATA_ATTRIBUTES,
      new AttributeRequest[]
      {
        // Attribute internal name
        new AttributeRequest(Attributes.ATTRIBUTE_NAME,null),
        // Attribute display name
        new AttributeRequest(Attributes.DISPLAY_NAME,null),
        new AttributeRequest(Attributes.ATTRIBUTE_TYPE,null),
        new AttributeRequest(Attributes.ATTRIBUTE_DEFAULT,null),
        new AttributeRequest(Attributes.ATTRIBUTE_ENUMERATION,null),
        new AttributeRequest(Attributes.ATTRIBUTE_REQUIRED,null),
        new AttributeRequest(Attributes.ATTRIBUTE_SETTABLE,null),
        new AttributeRequest(Attributes.ATTRIBUTE_UPDATEABLE,null),
        new AttributeRequest(Attributes.ATTRIBUTE_HIDDEN,null),
        new AttributeRequest(Attributes.ATTRIBUTE_PROMPTED,null),
        new AttributeRequest(Attributes.ATTRIBUTE_OVERRIDEABLE,null),
      }
    )
    };

    AttributeRequest[] overrideAttributes = new AttributeRequest[]
    {
    // id of the attribute to be overridden
    new AttributeRequest(Attributes.ATTRIBUTE_OVERRIDE_ATTRIBUTE,null),
    // id of the category class object to which this attribute override applies
    new AttributeRequest(Attributes.ATTRIBUTE_OVERRIDE_CATEGORY_CLASS,null),
    // new default value
    new AttributeRequest(Attributes.ATTRIBUTE_OVERRIDE_DEFAULT,null),
    // should attribute now be prompted
    new AttributeRequest(Attributes.ATTRIBUTE_OVERRIDE_PROMPT,null),
    // is the attribute now required
    new AttributeRequest(Attributes.ATTRIBUTE_OVERRIDE_REQUIRED,null),
    // can instances of this attribute have there value updated
    new AttributeRequest(Attributes.ATTRIBUTE_OVERRIDE_SETTABLE,null),
    };

    AttributeRequest[] requestedAttributes = new AttributeRequest[]
    {
    // what is the category configuration for the item
    new AttributeRequest(Attributes.CATEGORY_CONFIGURATION,
      new AttributeRequest[]
      {
        // Is the category configuration enabled
         new AttributeRequest(Attributes.CONFIGURATION_ENABLED,null),
         // Can the category configuration be overridden or is it final
        new AttributeRequest(Attributes.CONFIGURATION_FINAL,null),
        // What are the required categories for the category configuration and associated attribute information
        new AttributeRequest(Attributes.REQUIRED_CATEGORIES,categoryObjectAttributes),
        // Can any categories in the site be utilized
        new AttributeRequest(Attributes.ALLOW_ALL_CATEGORIES,null),
        // or .. are we restricting the categories to only the following
        new AttributeRequest(Attributes.ALLOWED_CATEGORIES,categoryObjectAttributes),
        // are there any attribute overrides on category object attributes for this category config?
        new AttributeRequest(Attributes.ATTRIBUTE_OVERRIDES,overrideAttributes)
      }
    )
    };

    log(cm.getItem(myDoc.getId(), requestedAttributes);
    /*
    If ALLOW_ALL_CATEGORIES is set to true, any category in the domain can be utilized that is not abstract. To determine these, the domain item has a property CATEGORY_CLASSES that returns all category objects in the domain. It also has a property ROOT_CATEGORY_CLASSES which returns just the top level categories (those that have no custom category superclass). You would create a sub AttributeRequest[] checking for CLASS_ABSTRACT when requesting the appropriate categories attribute from the domain.

    If ALLOW_ALL_CATEGORIES is set to false, the applicable categories objects that can be utilized on items contained in the folder is determined by the items contained in the ALLOWED_CATEGORIES attribute of the category configuration.

    Finally, the REQUIRED_CATEGORIES attribute list the category items that must be applied to all new items added to the folder.
    */

    4 – How do I manually apply an instance of a category to an existing item
    FdkSession session = …;
    // Consider we have an existing item myDoc of type document
    Item myDoc = …;

    .. use techniques in step3 above to determine what category objects that you planning to apply to the document ..
    .. if the category configuration on the item has ALLOW_ALL_CATEGORIES set to true, you can use any category in the system
    .. otherwise, you must use a category defined in the allowed categories list

    .. the code here is essentially the same as step2 above
    .. you must utilize internal attribute names, and specify the id of the category class object

    FileManager fm = Managers.getFileManager(session);

    NamedValue[] categoryInstanceAttributes = new NamedValue[] {
      // use the internal attribute name for all attributes
      new NamedValue("CUSTOM_14352", Boolean.FALSE),
      new NamedValue("CUSTOM_14352", "Company Confidential")
    };
    NamedValue[] categoryDef = new NamedValue[] {
      // the id of the category object class for which this new category will be an instance of
    new NamedValue(Options.CATEGORY_CLASS_ID,new Long(14354)),
    // the updated values of the category instance
      new NamedValue(Options.CATEGORY_DEFINITION_ATTRIBUTES, categoryInstanceAttributes)
    };

    NamedValue[] documentDef = new NamedValue[] {
    new NamedValue(Options.CATEGORY_DEFINITION, categoryDef)
    };

    requestedAttributes = ...
    myDoc = fm.updateDocument(myDoc.getId(),documentDef,requestedAttributes);

    // Note – it is possible for one to peform creation, updating, and deletion of various category instances for an existing item in the fileManager updateDocument call!
    // you simply supply multiple Options.CATEGORY_DEFINITIONs to the fm.updateDocument call along with any Options.REMOVE_CATEGORY_IDs
    5 – How do I specify a category instance when creating a new item
    FdkSession session = …;

    .. use techniques in step3 above to determine what category objects that you planning to apply to the new document ..
    .. you get the category configuration information from the destination folder!!!

    Item destinationFolder = …;
    CommonManager cm = Managers.getCommonManager(session);

    AttributeRequest[] requestedAttributes = new AttributeRequest[]
    {
    // what is the category configuration for the item
    new AttributeRequest(Attributes.CATEGORY_CONFIGURATION,
    . . .
    };

    destinationFolder = cm.getItem(destinationFolder.getId(),requestedAttributes);
    .. if the category configuration on the folder item has ALLOW_ALL_CATEGORIES set to true, you can use any category in the system
    .. otherwise, you must use a category defined in the allowed categories list

    .. the code here is essentially the same as step2 above, just we are using createDocument and document definitions now
    .. you must utilize internal attribute names, and specify the id of the category class object
     
    FileManager fm = Managers.getFileManager(session);

    NamedValue[] categoryInstanceAttributes = new NamedValue[] {
      // use the internal attribute name for all attributes
      new NamedValue("CUSTOM_14352", Boolean.FALSE),
      new NamedValue("CUSTOM_14352", "Company Confidential")
    };
    NamedValue[] categoryDef = new NamedValue[] {
      // the id of the category object class for which this new category will be an instance of
    new NamedValue(Options.CATEGORY_CLASS_ID,new Long(14354)),
    // the attribute values for this new category instance
      new NamedValue(Options.CATEGORY_DEFINITION_ATTRIBUTES, categoryInstanceAttributes)
    };

    String destinationFile = "sample.doc";
    requestedAttributes = new AttributeRequest[]
    {
      new AttributeRequest(Attributes.URL,null)
    };

    Item docDef = fm.createDocumentDefinition(new NamedValue[]
    {
      new NamedValue(Attributes.NAME, destinationFile),
    },requestedAttributes);

    String defURL = ...  // get URL from document definition

    doFileUpload(...)  // upload file using http put to defURL


    NamedValue[] documentDef = new NamedValue[] {
      new NamedValue(Options.USE_SAVED_DEFINITION,new Long(docDef.getId())),
    new NamedValue(Options.DESTFOLDER, new Long(destinationFolder.getId())),
    // specify character set if appropriate
      new NamedValue(Attributes.DOCUMENT_CHARACTER_SET,"ISO-8859-1"),
      // specify language if appropriate
    new NamedValue(Attributes.DOCUMENT_LANGUAGE,"ENGLISH"),
    // apply category instance information
    new NamedValue(Options.CATEGORY_DEFINITION, categoryDef),
    };

    requestedAttributes = ...
    Item doc = fm.createDocument(documentDef,null, requestedAttributes);


    // Note – it is possible for one to peform creation of multiple category instances on a document at the same time
    // you simply supply multiple Options.CATEGORY_DEFINITIONs to the fm.createDocument call
    // Note – that if a folder has a category configuration containing required categories, and you do not specify
    // all applicable category definitions on createDocument, you will receive an FdkException along the lines of
    // missing metadata. You can catch this exception, and retry the createDocument call supplying the valid category definition(s).
  • 13. Re: Updating a document with category metadata using updateDocument(): erro
    mshannon Newbie
    Currently Being Moderated
    To update a category instance you need to supply
    Options.UPDATE_CATEGORY_ID - which is the id of the category instance that you are trying to update.

    To add a new category instance to a doc you need to supply
    Options.CATEGORY_CLASS_ID which is the id of the category object class for which this new category will be an instance of
  • 14. Re: Updating a document with category metadata using updateDocument(): erro
    514432 Newbie
    Currently Being Moderated
    ok when I'm not mistaking it goes like this:
    Item categoryConfig = (Item) returnedAttrs.get(Attributes.CATEGORY_CONFIGURATION);
    returnedAttrs = getAttributesMap(categoryConfig);


    // what are the required categories for this category configuration
    logger.debug("\nRequired categories ...");
    Item[] reqCategories = (Item[]) returnedAttrs.get(Attributes.REQUIRED_CATEGORIES);
    WSUtility.log("", reqCategories);

    Object[] reponseRequiredCategories = null;
    if(reqCategories != null)
    {
    reponseRequiredCategories= new Object[reqCategories.length];

    Item tmpCatClass = null;
    Item[] tmpMetadataAttributes = null;

    for(int cat= 0; cat < reqCategories.length; cat++)
    {

    tmpCatClass = reqCategories[cat];
    }
    .........
    NamedValue[] categoryDef =
    WSUtility.newNamedValueArray(new Object[][] {
    { Options.UPDATE_CATEGORY_ID, new Long(tmpCatClass.getId())},
    { Options.CATEGORY_DEFINITION_ATTRIBUTES, categoryInstanceAttributes}
    });
    }
    NamedValue[] documentDef =
    new NamedValue(Options.CATEGORY_DEFINITION, categoryDef );

    fm.updateDocument( doc.getId(),
    documentDef,
    null);

    ///
    but stille get the error?

    CJ
1 2 Previous Next