Skip Headers
Oracle® Fusion Middleware Integration Guide for Oracle Enterprise Repository
11g Release 1 (11.1.1.7)

Part Number E15754-15
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
PDF · Mobi · ePub

27 Relationship Types API

This chapter provides use cases for the Relationship Types API that describe how to create a new relationship type and modify or query related assets in Oracle Enterprise Repository.

This chapter includes the following sections:

27.1 Overview

The Relationship Type defines the structure of a relationship that is used to associate two assets.

Asset Subsystems

When creating or editing assets, Relationship Types are used to define or modify the relationships that exist between assets.

27.2 Use Cases

This section describes the use cases using the Relationship Types API. It includes the following topics:

27.2.1 Use Case: Create a New Relationship Type

Description

Creating a new type of relationship to be used between assets.

Sample Code

Example 27-1 Use Case: Create a New Relationship Type

package com.flashline.sample.relationshiptypeapi;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import com.flashline.registry.openapi.base.OpenAPIException;
import com.flashline.registry.openapi.entity.AuthToken;
import com.flashline.registry.openapi.entity.RelationshipType;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
 com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class CreateNewRelationshipType {
         public static void main(String pArgs[]) throws java.rmi.RemoteException,
 OpenAPIException {
                    try{
          ///////////////////////////////////////////////////////////
          // Connect to Oracle Enterprise Repository
          ///////////////////////////////////////////////////////////
                      URL lURL = null;
                      lURL = new URL(pArgs[0]);
                      FlashlineRegistry repository =new
 FlashlineRegistryServiceLocator().getFlashlineRegistry(lURL);
          // //////////////////////////////
          // Authenticate with OER
          // //////////////////////////////
                      AuthToken authToken = repository.authTokenCreate(pArgs[1],
 pArgs[2]);
                      // -----------------------------------------
                      // create the new relationship type
                      String newRelationshipTypeName
 ="My-NewRelationshipTypeName";  //Relationship Type name must contain only alpha
 characters or hyphens
                      RelationshipType newRelationshipType =
 repository.relationshipTypeCreate(authToken, newRelationshipTypeName);
                      System.out.println("The new relationshipType id =
 "+newRelationshipType.getID()+" ");
          // -----------------------------------------
          // set the direction definition and the display text describing the
 relationship type
          //// Two-way = "BIDIRECTIONAL"
          //// Two-way, order matters = "ORDERED-BIDIRECTIONAL"
          //// One-way = "UNIDIRECTIONAL"
          newRelationshipType.setDirection("ORDERED-BIDIRECTIONAL");
          newRelationshipType.setDisplayPrimary("Contained In"); // Source Asset -
 'Contained In' - Target Asset
          newRelationshipType.setDisplaySecondary("Contains");   // Target Asset -
 'Contains' - Source Asset
          newRelationshipType = repository.relationshipTypeUpdate(authToken,
 newRelationshipType);
          // -----------------------------------------
          // delete the new relationship type
          repository.relationshipTypeDelete(authToken,
 newRelationshipType.getID());
                    }catch(OpenAPIException  lEx) {
                      System.out.println("ServerCode = "+
 lEx.getServerErrorCode());
                      System.out.println("Message    = "+ lEx.getMessage());
                      System.out.println("StackTrace:");
                      lEx.printStackTrace();
                    } catch (RemoteException lEx) {
                      lEx.printStackTrace();
                    } catch (ServiceException lEx) {
                      lEx.printStackTrace();
                    } catch (MalformedURLException lEx) {
                      lEx.printStackTrace();
                    }
                  }
}

27.2.2 Use Case: Modify Related Assets

Description

A target asset is related to other assets using My RelationshipType. Using this same relationship type, establish a relationship to an additional asset.

Sample Code

Example 27-2 Use Case: Modify Related Assets

package com.flashline.sample.relationshiptypeapi;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import com.flashline.registry.openapi.base.OpenAPIException;
import com.flashline.registry.openapi.entity.Asset;
import com.flashline.registry.openapi.entity.AuthToken;
import com.flashline.registry.openapi.entity.RelationshipType;
import com.flashline.registry.openapi.query.RelationshipTypeCriteria;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
 com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class FindRelationshipTypeAndUseInAsset {
         public static void main(String pArgs[]) throws OpenAPIException,
 RemoteException, ServiceException {
                    try{
          ///////////////////////////////////////////////////////////
          // Connect to Oracle Enterprise Repository
          ///////////////////////////////////////////////////////////
                      URL lURL = null;
                      lURL = new URL(pArgs[0]);
                      FlashlineRegistry repository =new
 FlashlineRegistryServiceLocator().getFlashlineRegistry(lURL);
          // //////////////////////////////
          // Authenticate with OER
          // //////////////////////////////
                      AuthToken authToken = repository.authTokenCreate(pArgs[1],
 pArgs[2]);
          Asset myAsset = repository.assetRead(authToken, 563);
                      //MY_OTHER_ASSET_ID should be an integer and should be the
 id of an asset in the repository
                      RelationshipType[] allRelationshipTypes =
 getAllRelationshipTypes(repository, authToken);
                      for (int i = 0; i < allRelationshipTypes.length; i++) {
                        if
 (allRelationshipTypes[i].getName().equals("MyRelationshipType2")) {
                          //This is the relationship type, modify the assets that
 are related
                          // using it
                          RelationshipType myRelationshipType =
 allRelationshipTypes[i];
                          Asset otherAsset = repository.assetRead(authToken, 569); 
 //569= MY_OTHER_ASSET_ID
                          //MY_OTHER_ASSET_ID should be an integer and should be
 the id of an asset in the repository
                          //add this asset to the list of related assets
                          long[] oldSecondaryIDs =
 myRelationshipType.getSecondaryIDs();
                          long[] newSecondaryIDs = new long[oldSecondaryIDs.length
 + 1];
                          for (int j = 0; j < oldSecondaryIDs.length; j++) {
                            newSecondaryIDs[j] = oldSecondaryIDs[j];
                          }
                          newSecondaryIDs[newSecondaryIDs.length - 1] =
 otherAsset.getID();
                          myRelationshipType.setSecondaryIDs(newSecondaryIDs);
                        }
                      }
                      myAsset.setRelationshipTypes(allRelationshipTypes);
                      repository.assetUpdate(authToken, myAsset);
                    }catch(OpenAPIException  lEx) {
                      System.out.println("ServerCode = "+
 lEx.getServerErrorCode());
                      System.out.println("Message    = "+ lEx.getMessage());
                      System.out.println("StackTrace:");
                      lEx.printStackTrace();
                    } catch (RemoteException lEx) {
                      lEx.printStackTrace();
                    } catch (ServiceException lEx) {
                      lEx.printStackTrace();
                    } catch (MalformedURLException lEx) {
                      lEx.printStackTrace();
                    }
                  }
   /**
     * This method returns every relationship type in the repository
     * @param repository
     * @param authToken
     * @return
     * @throws RemoteException
     */
    public static RelationshipType[] getAllRelationshipTypes(FlashlineRegistry
 repository, AuthToken authToken) throws RemoteException {
      //Create an empty relationship type criteria object
      RelationshipTypeCriteria criteria = new RelationshipTypeCriteria();
      criteria.setNameCriteria("");
      RelationshipType[] allRelationshipTypes =
 repository.relationshipTypeQuery(authToken, criteria);
      return allRelationshipTypes;
    }
}

Note:

Methods to Avoid - SetPromptNotifySecondary()

27.2.3 Use Case: Query Related Assets

Description

Querying for related asset types.

Sample Code

Example 27-3 Use Case: Query Related Assets

package com.flashline.sample.relationshiptypeapi;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import com.flashline.registry.openapi.base.OpenAPIException;
import com.flashline.registry.openapi.entity.Asset;
import com.flashline.registry.openapi.entity.AuthToken;
import com.flashline.registry.openapi.entity.RelationshipType;
import com.flashline.registry.openapi.query.RelationshipTypeCriteria;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
 com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class FindRelationshipTypeAndUseInAsset {
         public static void main(String pArgs[]) throws OpenAPIException,
 RemoteException, ServiceException {
                    try{
          ///////////////////////////////////////////////////////////
          // Connect to Oracle Enterprise Repository
          ///////////////////////////////////////////////////////////
                      URL lURL = null;
                      lURL = new URL(pArgs[0]);
                      FlashlineRegistry repository =new
 FlashlineRegistryServiceLocator().getFlashlineRegistry(lURL);
          // //////////////////////////////
          // Authenticate with OER
          // //////////////////////////////
                      AuthToken authToken = repository.authTokenCreate(pArgs[1],
 pArgs[2]);
          Asset myAsset = repository.assetRead(authToken, 563);
                      //MY_OTHER_ASSET_ID should be an integer and should be the
 id of an asset in the repository
                      RelationshipType[] allRelationshipTypes =
 getAllRelationshipTypes(repository, authToken);
                      for (int i = 0; i < allRelationshipTypes.length; i++) {
                        if
 (allRelationshipTypes[i].getName().equals("MyRelationshipType2")) {
                          //This is the relationship type, modify the assets that
 are related
                          // using it
                          RelationshipType myRelationshipType =
 allRelationshipTypes[i];
                          Asset otherAsset = repository.assetRead(authToken, 569); 
 //569= MY_OTHER_ASSET_ID
                          //MY_OTHER_ASSET_ID should be an integer and should be
 the id of an asset in the repository
                          //add this asset to the list of related assets
                          long[] oldSecondaryIDs =
 myRelationshipType.getSecondaryIDs();
                          long[] newSecondaryIDs = new long[oldSecondaryIDs.length
 + 1];
                          for (int j = 0; j < oldSecondaryIDs.length; j++) {
                            newSecondaryIDs[j] = oldSecondaryIDs[j];
                          }
                          newSecondaryIDs[newSecondaryIDs.length - 1] =
 otherAsset.getID();
                          myRelationshipType.setSecondaryIDs(newSecondaryIDs);
                        }
                      }
                      myAsset.setRelationshipTypes(allRelationshipTypes);
                      repository.assetUpdate(authToken, myAsset);
                    }catch(OpenAPIException  lEx) {
                      System.out.println("ServerCode = "+
 lEx.getServerErrorCode());
                      System.out.println("Message    = "+ lEx.getMessage());
                      System.out.println("StackTrace:");
                      lEx.printStackTrace();
                    } catch (RemoteException lEx) {
                      lEx.printStackTrace();
                    } catch (ServiceException lEx) {
                      lEx.printStackTrace();
                    } catch (MalformedURLException lEx) {
                      lEx.printStackTrace();
                    }
                  }
   /**
     * This method returns every relationship type in the repository
     * @param repository
     * @param authToken
     * @return
     * @throws RemoteException
     */
    public static RelationshipType[] getAllRelationshipTypes(FlashlineRegistry
 repository, AuthToken authToken) throws RemoteException {
      //Create an empty relationship type criteria object
      RelationshipTypeCriteria criteria = new RelationshipTypeCriteria();
      criteria.setNameCriteria("");
      RelationshipType[] allRelationshipTypes =
 repository.relationshipTypeQuery(authToken, criteria);
      return allRelationshipTypes;
    }
}

Example of the RelationshipTypeQuery

try
{
   RelationshipTypeCriteria rCriteria = new RelationshipTypeCriteria();
   RelationshipType[] allRelationshipTypes =
 FlashlineRegistry.relationshipQuery(lAuthToken, rCriteria);
}
catch (OpenAPIException e)
{
     e.printStackTrace();
}
catch (RemoteException re)
{
    re.printStackTrace();
}