7

I have written a plugin for SDL Translation Management Service which should add the UserData for the creator of the TranslationJob to the resolved items:

    public void TranslationJob_Resolved(object sender, ResolvedItemsEventArgs e)
    {
        // Create a duplicate IEnumerable to make modifications to the resolved items
        List<ResolvedItem> resolvedItems = e.Items.ToList();

        try
        {
            // Retrieve the translation job
            TranslationJob translationJob = sender as TranslationJob;

            if (translationJob != null)
            {
                // Retrieve the creator TcmUri
                TcmUri creatorUri = translationJob.CreatorUri;

                // Use the CoreService to retrieve the creator TcmItem
                UserData userItem = CoreServiceFactory.Get<UserData>(creatorUri.ToString());

                if (userItem != null)
                {
                    Logger.Log("User Item found for: " + userItem.Title);

                    // Create a new tcmUri to set the publication to 0
                    TcmUri tcmUri = new TcmUri(creatorUri.ItemId, creatorUri.ItemType, 0, creatorUri.Version);

                    // Validate the user and create a TcmItem
                    TcmItem tcmItem = new TcmItem(tcmUri);

                    // Add the creator TcmItem to the translation job resolved items
                    ResolvedItem resolvedItem = new ResolvedItem(tcmItem, translationJob);

                    resolvedItems.Add(resolvedItem);
                }
            }
        }
        catch(Exception ex)
        {
            Logger.Log("Unexpected error: {0}", ex);
        }

        // Assign the modified IEnumerable
        e.Items = resolvedItems;
    }

An exception is thrown when trying to initialise a new ResolvedItem object:

Tridion.TranslationManager.DomainModel.TcmClientException: Invalid context Publication specified in URI: tcm:115-19-65552. Expecting: 0. ---> System.ServiceModel.FaultException`1[Tridion.ContentManager.CoreService.Client.CoreServiceFault]: Invalid context Publication specified in URI: tcm:115-19-65552. Expecting: 0.

I am struggling to determine why the publication component of the TcmId is 115 despite me explicitly setting it to 0 for the tcmUri.

Can anyone provide any guidance on why this is happening and how I can resolve it?

1
  • One thought we had was that the TranslationJob determines the context publication and doesn't support components that can't be blueprinted such as UserData... Hopefully this isn't the case.
    – John Askew
    Dec 16, 2014 at 11:14

1 Answer 1

6

The public constructor for ResolvedItem manipulates the publication of the TcmItem.

public ResolvedItem(TcmItem sourceItem, TranslationJob job)
{
  if (sourceItem == null)
    throw new LocalizableArgumentNullException("sourceItem");
  if (job == null)
    throw new LocalizableArgumentNullException("job");
  this._job = job;
  TcmUri tcmUri = new TcmUri(sourceItem.InternalTcmItem.TcmUri.UriInPublication(job.InternalTranslationJob.ContextItemUri));
  TcmItem tcmItem = tcmUri.PublicationId == sourceItem.Uri.PublicationId ? sourceItem : new TcmItem(tcmUri);
  Tridion.TranslationManager.DomainModel.TcmUri publicationUriFromItemUri = Utilities.GetPublicationUriFromItemUri(sourceItem.Uri.WrappedTcmUri);
  this._resolvedItem = new Tridion.TranslationManager.DomainModel.ResolvedItem(tcmItem.InternalTcmItem, job.InternalTranslationJob.TranslationJobManager.UserContext, publicationUriFromItemUri, publicationUriFromItemUri, true, job.InternalTranslationJob, string.Empty);
}

The other constructor is internal and we are unable to modify the TranslationJob.ContextItemUri (no getter).

This means that an item must support blueprinting to be added as a ResolvedItem and we can't extend or override this behaviour.

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.