Expand my Community achievements bar.

Adding a Policy to a document located in the Repository

Avatar

Level 2

Is it possible to add a Policy to a document stored in the Repository? I've been trying to do this but it does not seen to work. This is what I am doing:

  1. Retrieve from Repository the Resource containing the Document.
  2. Extract Document from Resource.
  3. Apply Policy to the Document.
  4. Update Resource

Up to this point all works without any problem. However, if a now retrieve the Resource and check the Policy of its Document I get the following exception: SDKException: getRMLicenseID: document has no license or invalid Rights Management encryption -- (error code bin: 774, hex: 0x306) -- Invalid argument(error code bin: 1281, hex: 0x501).

The following is a self-contained program that replicates the problem:

package lctest;


import com.adobe.edc.sdk.SDKException;

import com.adobe.idp.Document;

import com.adobe.repository.RepositoryException;

import java.util.*;

import com.adobe.idp.dsc.clientsdk.ServiceClientFactory;

import com.adobe.idp.dsc.clientsdk.ServiceClientFactoryProperties;

import com.adobe.livecycle.rightsmanagement.RMInspectResult;

import com.adobe.livecycle.rightsmanagement.RMSecureDocumentResult;

import com.adobe.livecycle.rightsmanagement.client.*;

import com.adobe.livecycle.rightsmanagement.client.infomodel.*;

import com.adobe.repository.bindings.dsc.client.ResourceRepositoryClient;

import com.adobe.repository.infomodel.bean.Resource;



public class RepositoryPolicies

{

public static void main(String[] args)

{

try

{

String username = "iftdocs";

String password = "password";

String policySet= "docmgt";

String path = "/IFT Documents/DocManager/Environment/yabby_traps_kill_platypus.pdf";


//Set connection properties required to invoke LiveCycle ES2

Properties connectionProps = new Properties();

connectionProps.setProperty(ServiceClientFactoryProperties.DSC_DEFAULT_EJB_ENDPOINT, "jnp://ift-3:1200");

connectionProps.setProperty(ServiceClientFactoryProperties.DSC_TRANSPORT_PROTOCOL, ServiceClientFactoryProperties.DSC_EJB_PROTOCOL);

connectionProps.setProperty(ServiceClientFactoryProperties.DSC_SERVER_TYPE, "JBoss");

connectionProps.setProperty(ServiceClientFactoryProperties.DSC_CREDENTIAL_USERNAME, username);

connectionProps.setProperty(ServiceClientFactoryProperties.DSC_CREDENTIAL_PASSWORD, password);

// Create the service client factory

ServiceClientFactory scFactory = ServiceClientFactory.createInstance(connectionProps);


//Create a RightsManagementClient object

RightsManagementClient rightsClient = new RightsManagementClient(scFactory);


// Create a ResourceRepositoryClient object using the service client factory

ResourceRepositoryClient repositoryClient = new ResourceRepositoryClient(scFactory);


//Create a Document Manager object

DocumentManager documentManager = rightsClient.getDocumentManager();


// Retrieve the resource

Resource r = repositoryClient.readResource(path);

// Retrieve Document

Document d = r.getContent().getDataDocument();


PolicySearchFilter pf = new PolicySearchFilter();


pf.setPolicySetName(policySet);

pf.setName("View");

pf.setType(Policy.ORGANIZATIONAL_POLICY);


PolicyManager policyManager = rightsClient.getPolicyManager();

Policy[] policies = policyManager.getPolicies(pf,100);

Policy lcPolicy = policies[0];


System.out.println("--- Apply Policy: "+lcPolicy.getName());


RMSecureDocumentResult protectDoc =

documentManager.protectDocument(d,"yabby_traps_kill_platypus.pdf",

policySet,lcPolicy.getName(),

null,null,null);


System.out.println("---Policy Applied---------------");


r.getContent().setDataDocument(d);

repositoryClient.updateResource(r.getPath(),r,false);


System.out.println("---Resource Updated---------------");


// Retrieve the resource

r = repositoryClient.readResource(path);

// Retrieve Document

d = r.getContent().getDataDocument();

// Retrieve Policy

RMInspectResult inspectResult = documentManager.inspectDocument(d);


//Get the name of the policy

System.out.println("Policy Set: "+inspectResult.getPolicySetName());

System.out.println("Policy Name: "+inspectResult.getPolicyName());

}

catch (RepositoryException ex)

{

System.out.println("RepositoryException: "+ex.getMessage());

}

catch (SDKException ex)

{

System.out.println("SDKException: "+ex.getMessage());

}

}

}

3 Replies

Avatar

Level 10

Do you get the same error if you use the same code but then store the policy protected document back to the file system?

Jasmin

Avatar

Level 5

Is the same path at second time? It seems that is a different path when you try to retrieve.

Why don't you build this in LC Workbench?

Diego

Avatar

Level 2

Thank you Jasmin and Diego. Your replies made me look carefully at my code and I found that I was not updating the repository with Document without the Policy added. I was doing the following:

RMSecureDocumentResult protectDoc = documentManager.protectDocument(unproctDoc,                "yabby_traps_kill_platypus.pdf", policySet, lcPolicy.getName(), null, null, null);


r.getContent().setDataDocument(unproctDoc);

repositoryClient.updateResource(r.getPath(),r,false);

Instead I should have been doing the following:

RMSecureDocumentResult protectDoc = documentManager.protectDocument(unproctDoc,                "yabby_traps_kill_platypus.pdf", policySet, lcPolicy.getName(), null, null, null);


r.getContent().setDataDocument(protectDoc.getProtectedDoc());

repositoryClient.updateResource(r.getPath(),r,false);