Content Management Scenarios

This document describes how the code in com.ptc.core.foundation.content.server and com.ptc.core.foundation.content.common may be used for various content-management scenarios. Each scenario will be described, and a sequential description of steps or an actual code fragment will be provided.

1. Uploading and Attaching a File to a ContentHolder

To attach a file to a ContentHolder as an ApplicationData content item, you must first upload it to a staging area, then in a subsequent step, attach it to the holder. The next scenario shows how to upload the file content. The second scenario, shows how to add the ContentItem to the holder.

1.1. Uploading a File to be attached to a ContentHolder

Upload file content to the staging area.

    On the client
  1. Open the file using an OpenFileForReadCommand
  2. Open a post stream to the server - DETAILS ARE IGNORED FOR NOW
  3. Transfer the data between the file stream and the post stream with a TransferStreamDataCommand
  4. On the server
  5. Send the data received from the client posts to the staging area using a StageContentFromInputStreamCommand
  6. Return the ApplicationData content item produced as result data by the StageContentFromInputStreamCommand to the client

The ApplicationData TypeInstance that is obtained from the StageContentCommand will contain the file name, the uploaded from path, the size of the file, and a checksum. It will also contain a URI that can be used to locate the file data in the staging area later, when the ApplicationData is attached to the ContentHolder. The caller, however, does not need to worry about the URI value. This ApplicationData should be attached to the ContentHolder as in the next scenario...

1.2. Adding a New ContentItem to a ContentHolder

Given a ContentHolder that is persisted, add a new ContentItem to the holder.

  1. Pick the ContentItem's role type and set it as a model-based attribute on the ContentItem itself.
  2. The ContentItem must be added as an attribute value in the ContentHolder container. The AttributeTypeIdentifier for this attribute is a NonPersistedAttributeTypeIdentifier obtained from the method ContentConstants.contentHolderModContentItemAti(...).
  3. Then the ContentHolder must be updated using an UpdatePersistentEntityCommand
      TypeInstance content_holder = ...;
      TypeInstance app_data = ...; // assumed to be an ApplicationData
 
      // make the content item a secondary content item
      CommandUtility.putAttributeContent(ContentConstants.CONTENT_ITEM_ROLE_NAME_ATI,
            app_data, "SECONDARY");
 
      // Add the content item as a new attribute value
      ContentUtil.markContentItemAsNew(content_holder, app_data);
 
      // Update the holder that bears the ContentItem
      UpdatePersistentEntityCommand update_command = new UpdatePersistentEntityCommand();
      update_command.setSource(content_holder);
      ...; // set other inputs
 
      // execute the update - performs the add
      update_command = (UpdatePersistentEntityCommand)update_command.execute();

2. Removing a ContentItem from a ContentHolder

Given a ContentHolder and a ContentItem on that holder, remove the ContentItem.

  1. The ContentItem must first be marked as a removed attribute in the ContentHolder container. This is done by adding it to ensure it is in the type instance's attribute container, then immediately removing the value using its AttribyteIdentifier to make the value get marked as deleted. The AttributeTypeIdentifier for this attribute is a NonPersistedAttributeTypeIdentifier obtained from the method ContentConstants.contentHolderModContentItemAti(...).
  2. Then the ContentHolder must be updated using an UpdatePersistentEntityCommand
      TypeInstance content_holder = ...;
      TypeInstance app_data = ...;
 
      // Mark the content item as a removed attribute value.
      // The utility method vastly simplifies this task.	
      ContentUtil.markContentItemAsDeleted(content_holder, content_item);
 
      // Update the holder that bears the ContentItem
      UpdatePersistentEntityCommand update_command = new UpdatePersistentEntityCommand();
      update_command.setSource(content_holder);
      ...; // set other inputs
 
      // execute the update - performs the delete
      update_command = (UpdatePersistentEntityCommand)update_command.execute();

3. Getting the ContentItems associated with a ContentHolder

Given a ContentHolder as a TypeInstance obtain the set of ContentItems associated with it.

4. Getting the Secondary ContentItems associated with a ContentHolder

Given a ContentHolder as a TypeInstance obtain just the set of secondary ContentItems associated with it. This scenario is nearly identical to the previous, the difference in code is emphasized.

      TypeInstance content_holder = ...;
      GetContentItemsCommand get_cmd = new GetContentItemsCommand();
      get_cmd.setContentHolder(content_holder);
      get_cmd.setRole(ContentRoleType.SECONDARY.toString()); // use the simple internal value
      get_cmd = (GetContentItemsCommand)get_cmd.execute();
 
      // get the updated content holder
      content_holder = get_cmd.getContentHolder();
 
      // get the content items
      TypeInstance[] content_items = get_cmd.getContentItems();
      ... // do something with them

5. Replacing the file data for an ApplicationData ContentItem

full documentation forthcoming

      TypeInstance content_holder = ...;
      TypeInstance old_app_data = ...; // the item to replace
 
      // Stage the content for the new item - the result is
      // the new ApplicationData instance.
      StageContentCommand stage_command = ...;
      stage_command = (StageContentCommand)stage_command.execute();
      TypeInstance new_app_data = stage_comand.getApplicationData();
 
      // Make the new content item a secondary content item (or whatever
      // other role type you'd like)
      CommandUtility.putAttributeContent(
            ContentConstants.CONTENT_ITEM_ROLE_NAME_ATI,
            new_app_data, "SECONDARY");
 
      // Mark the old content item as a deleted attribute value.
      // The utility method vastly simplifies this task.	
      ContentUtil.markContentItemAsDeleted(content_holder, old_app_data);

      // Mark the new content item as a mew attribute value.
      // The utility method vastly simplifies this task.	
      ContentUtil.markContentItemAsNew(content_holder, new_app_data);
 
      // Update the holder that bears the ContentItems
      UpdatePersistentEntityCommand update_command = new UpdatePersistentEntityCommand();
      update_command.setSource(content_holder);
      ...; // set other inputs
 
      // execute the update - performs the delete and add
      update_command = (UpdatePersistentEntityCommand)update_command.execute();

6. Creating and Adding URLData to a ContentHolder

documentation forthcoming

7. Updating URLData on a ContentHolder

documentation forthcoming

8. Downloading file data for an ApplicationData instance

documentation forthcoming