4

I'm creating an ECL provider, and in my provider, I want to store some metadata from the external content in the stub component. While I could use the event system, using the example that can be found here : http://www.tridiondeveloper.com/ecl-event-handlers, one of the comments on this post mentions to use the StubComponentCreated.

This method is called when Tridion creates a component stub for your ECL component. What i'm trying to do is to open the created stub component using Core Services, set some metadata values, and save it.

my code is pretty straightforward

public void StubComponentCreated(IEclUri eclUri, string tcmUri)
{
    try
    {
        var coreserviceclient = GetNewClient("http://[url]", "user", "password");
        var stubComponent = coreserviceclient.CheckOut(tcmUri, false, new ReadOptions()) as ComponentData;
        StubComponent.Metadata = [metadata value];
        coreserviceclient.Save(StubComponent, new ReadOptions());
    }
    catch(Exception ex)
    {
        //do some logging & error handling here
    }
}

Unfortunately, when I try to open, or read the component with the specific tcmUri, I get an error that the object does not exist. It looks like the stub component is only available after the ECL StubComponentCreated.

Note that my coreservice client and my ECL session are using the same user credentials.

Is it normal that I can't open the stub component at this moment, or am I doing something wrong here ?

2 Answers 2

2

The StubComponentCreated method in your ECL provider is called when the Stub Component is created (I know that for a fact), but judging from your findings it appears to be called when the Component creation transaction is not final yet. So that means we do have a TCMURI, but we don't have a Component we can open and edit at this point yet.

When I wrote the article I knew about the IContentLibraryContext.StubComponentCreated() method, but since my article was actually based on actions around the Media Manager Connector, I couldn't change the code in the ECL provider.

Jan's comment made a lot of sense, but I guess he also didn't test it out and just commented on the concept. I just checked with the developers and they confirmed the behaviour is as expected (they built it like this ;o).

What they added was, that if you need to change items in Tridion, you should actually use the event handlers, and not try to do so from the ECL Provider code. If it was as easy they could actually have allowed us to use the TOM.NET API inside a provider or at the very least given us a Core Service client to use. But there are a lot of reasons why they didn't do that (or could do that). So generally speaking you should try to prevent from using the Core Service from inside your ECL provider.

So in your case (it might be interesting to know what the actual reason is for your requirement to copy ECL external metadata over to Tridion metadata), you really should use the event system as suggested in my blog post, and I'll change my comment on there to indicate that we can't use the IContentLibraryContext.StubComponentCreated() for editing the Stub Component as it isn't available to us yet in there.

2
  • 1
    ok, thanks for your answer. I'll use the event system then. The reason i'm copying this data to the component metadata is the same as what you blogged about - I want to make this information available in my broker database, so I can use it for querying etc. Feb 19, 2015 at 15:42
  • @HaraldHoffelinck that is indeed a valid use case at this point, in the future we should get a way of adding additional metadata that can be indexed by the broker (which can be set at Publishing time), so we don't have to duplicate the data in the CMS. Feb 19, 2015 at 15:49
0

As Bart mentioned above, We can't use the IContentLibraryContext.StubComponentCreated() for editing the Stub Component as it isn't available to us yet in there.

Your Answer

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

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