5

I've been working with the Core Service recently, mainly to provide editors with lists of items (Components / Pages / Structure Groups) that have specific fields set or absent.

I can do all of this just fine, but the way I seem to be having to do this is a little clunky and the filters seem a little "hit and miss". What I'm trying to do in this example is to find all components that have a field "owner" set:

OrganizationalItemItemsFilterData filter = new OrganizationalItemItemsFilterData
{
    ItemTypes = new [] {
        ItemType.Component
    },
    ComponentTypes = new[] {
        ComponentType.Normal
    },
    Recursive = true
};
XElement componentsXml = service.GetListXml(folder, filter);

The first issue is that what's returned from the service does contain Multimedia components, which is an issue when coming to read their metadata later on.

Am I using the wrong type of filter? I would have preferred to to have retrieved an Object rather than XML, but the GetList() method again complained about the type of filter and the only one I could find that worked did not have the necessary fields to populate (though I seem to remember reading that this was a known issue in 2011).

Then, later, I'm reading each individual Component after converting to an XmlDocument (I have a front end history, so my Linq-fu is pretty non-existent).

foreach (XmlNode node in nodes)
{
    Console.Write("\rReading component: " + i + "/" + nodes.Count + " (" + (Math.Round((100D * i / nodes.Count)).ToString()) + "%): " + node.Attributes["ID"].Value + " " + node.Attributes["Title"].Value + "                                  ");
    try
    {
        components.Add((ComponentData)service.Read(node.Attributes["ID"].Value, new ReadOptions()));
    }
    catch
    {
        Console.WriteLine("Could not read Component" + node.Attributes["ID"].Value + "(" + node.Attributes["Title"].Value + ") - no longer exists?");
    }
    i++;
}

...and then running through the metadata to output values to a file:

Again, this all works, but it seems a quite inefficient.

Is there a method I haven't yet found that does most of the above in one hit, i.e. I give it a list of TCM URIs and it grabs be back data, rather than having to read them all individually?

1
  • AFAIK, you need to get a list of all components in the form of Component object using the GetList method or in the form of XMLs using GetListXml method, and once you have this, you may need to filter out for Multimedia components - by checking for the Multimedia field in the component as well as for the field value. Commented Feb 4, 2015 at 13:58

2 Answers 2

6

To my knowledge there are no bulk read/write operation APIs in the coreservice so what you are trying to do specifically isn't possible other than reading one item at a time.

I'm however not convinced that you're using the right API for the job; finding items that meet certain criteria is something that the search API is designed to handle; you might want to look at the

IEnumerable<IdentifiableObjectData> GetSearchResults(SearchQueryData filter)

method of the core service.

1
  • I tried this but the search results were very sporadic, but some further investigation revealed that certain MM Components contained PDFs encrypted with AES, which caused them not to be indexed. We had to update pdfbox.jar on the server (Tridion\solr-home\lib) and its dependencies, i.e. fontbox.jar and jempbox.jar to v1.8.1 and now it's working beautifully. Thanks very much. Commented Feb 17, 2015 at 12:23
0

Regarding your second point.

Is there a method I haven't yet found that does most of the above in one hit, i.e. I give it a list of TCM URIs and it grabs be back data, rather than having to read them all individually?

I'm seeing that the GetList() method in the CoreService API returns 'A list of (partially loaded) Data Objects..' so it might be that you need to check that out and see if it returns the data of the object you need. I typically use the read() method on items individually and have no issues with it.

1
  • 1
    I think his first point was that MM Component are being included when he doesn't want that, and specifically asked for them not to be included (only 'normal' Components). Commented Feb 5, 2015 at 11:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.