Sample ImportRequisiteList interface usage
Use the ImportRequisiteList interface to determine and retrieve all the dependent objects for objects in a import list container object and hold the object names in a requisite list container object.
The requisite list container object lists all the dependent object names that are required for import but are not specified in the import list container object. The object names in the object container are obtained from the objects in the compressed file. The object names were exported from the source Product Master instance.
See IBM® Javadoc Documentation to view all of the available information on the parameters, returns, exceptions, and syntax for the ImportRequisiteList class.
This sample code shows the getRequisiteObjects(ExportList.Type type) method that is being used to retrieve all objects of type ExportList.Type.SPEC. The getRequisiteTypesForObject(ExportList.Type type, java.lang.String objectName) method is also used to retrieve all of the objects that are dependent to the specified object type type, and name name, in the import list container object. The getRequisiteObjectsForObjectByType(ExportList.Type importObjectType, java.lang.String objectName, ExportList.Type requisiteObjectType) method is then used to retrieve all of the objects of type reqdType that are dependent to the specified object type type, and name name, in the import list container object.
Context ctx = null;
EnvironmentImporter envImporter = null;
ImportList importList = null;
try
{
ctx = PIMContextFactory.getContext("Admin","xxx","MyCompany");
envImporter = ctx.getEnvironmentImporter();
Document archive = ctx.getDocstoreManager().getDocument("/data/wpc.zip");
importList=envImporter.getImportList(archive);
importList.removeObjects(ExportList.Type.SPEC);
ImportRequisiteList requisites = importList.getRequisites();
List <String> specNames = requisites.getRequisiteObjects(ExportList.Type.SPEC);
for(String name : specNames)
{
try{
importList.addObject(ExportList.Type.SPEC, name);
}
catch(PIMInternalException exc)
{
System.out.println("Spec " + name + "does not exist in archive");
}
}
//For each object type
for (Type type : importList.getObjectTypes())
{
//Get the objects of the type
for(String name : importList.getObjectNames(type))
{
//for each object, get the types which this object needs, for instance, CATALOG needs SPEC, HIERARCHY
for(Type reqdType : requisites.getRequisiteTypesForObject(type, name))
{
System.out.println(type + " " + name + " requires the following objects of type" + reqdType );
//get the objects of each type, CATALOG MyCatalog depends on SPEC primSpec and secSpec
for (String reqdObjectName : requisites.getAllRequisiteObjectsForObjectByType(type, name, reqdType))
{
System.out.println(reqdObjectName);
}
}
}
}
}
catch (PIMAuthorizationException ae)
{
// Expected a failure
System.out.println("Authorization Failure");
return;
}
catch(PIMInternalException ie)
{
System.out.println("Internal Error");
return;
}
catch(Exception e)
{
System.out.println(e.getMessage());
}