ヘッダーをスキップ
Oracle® Fusion Middleware Oracle Enterprise Repository統合ガイド
11g リリース1 (11.1.1.7)
B72433-02
  目次へ移動
目次
索引へ移動
索引

前
 
次
 

16 アセットAPI

この章では、アセットAPIについて説明し、アセットAPIのユースケースを示します。このユースケースで、アセットの作成または変更、アセットの検索の作成、およびアセット・ステータスとアセット・タブの操作を行う方法について解説します。

この章では、次の項目について説明します。

16.1 概要

アセットは、Oracle Enterprise Repositoryのコア・エンティティです。このドキュメントには、アセット・サブシステムのアクションの作成、読込み、更新、削除および問合せについて記述されています。また、次の項目の更新についても記述されています。

REXを使用してOracle Enterprise Repositoryのアセットを操作する場合、いくつかの問題を考慮する必要があります。メモリー消費におけるトレードオフとパフォーマンスについて、よく検討する必要があります。

16.1.1 定義

この項では、次の項目の定義について説明します。

  • IDおよびUUID

    • IDは、単一のOracle Enterprise Repositoryインスタンス内でアセットを一意に特定するために内部で使用される一意の識別子(数値)です。

    • UUIDは、Oracle Enterprise Repositoryのインスタンスで一意にアセットを特定するためにユニバーサルに使用される識別子(16進数で表される128ビットの数値)です。各アセットのUUIDは、主に読込みと検索用に表示されます。REXを使用してこのフィールドを変更しないことを強くお薦めします。ただし、管理者がアセットのUUIDを変更することを選択した場合、フォーマットは一貫している必要があります(00000000-0000-0000-0000-000000000000)。また、UUIDは、ターゲットのOracle Enterprise Repositoryインスタンス内で一意である必要があります。これ以外の場合、変更操作は失敗します。

  • 名前およびバージョン

    アセットを一意に特定するために結合した文字列のフィールド。

  • カスタム・データ

    アセットのカスタマイズ可能なメタデータは、この文字列内にXML構造で保存されています。サンプル・コードでは、カスタム・データ・メソッドを記述しています。

16.1.2 サンプル・コード

例16-1 カスタム・データ・メソッドのサンプル・コード

package com.flashline.sample.assetapi;
import java.io.StringReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.xml.rpc.ServiceException;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;
import org.jdom.xpath.XPath;
import com.flashline.registry.openapi.base.OpenAPIException;
import com.flashline.registry.openapi.entity.AuthToken;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
 com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class UpdateCustomData {
  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);
      ////////////////////////////////////////////////////////////
      // Login to OER
      ////////////////////////////////////////////////////////////
      AuthToken authToken = repository.authTokenCreate(
          pArgs[1],pArgs[2]);
      //////////////////////////////////////////
      // assetUpdateCustomDataString
      //////////////////////////////////////////
      // Find and Modify a custom data field value with a value supplied on the
 command line
      Long currentLicenses = new
 Long(repository.assetReadCustomDataString(authToken, 589, "/
_-total-licenses-owned"));
      currentLicenses = new Long(currentLicenses.intValue() + 1);
      //    save the modifications
      //  NOTICE: A leading slash is required to specify the appropriate path to
 the element being updated.
      repository.assetUpdateCustomDataString(authToken, 589, "/
_-total-licenses-owned", currentLicenses.toString());
      //////////////////////////////////////////
      // assetUpdateCustomDataStringArray
      //////////////////////////////////////////
      // Add a custom data field value with a value supplied on the command line
      Format formatter = new SimpleDateFormat("yyyyMMdd");
      String dateFormat = formatter.format(new Date());
      // NOTICE: for the following method, there is no leading slash for the
 elements being updated.
      String[] versionHistory = {"version-history/version-history/version-number",
 "version-history/version-history/production-date-yyyymmdd-",
 "version-history/version-history/comments"};
      String[] versionHistoryValues = {currentLicenses.toString(), dateFormat,
 "Updated version History: " + dateFormat};
      //    save the modifications
      repository.assetUpdateCustomDataStringArray(authToken, 589, versionHistory,
 versionHistoryValues);
      //////////////////////////////////////////
      // assetUpdateCustomDataNode
      //////////////////////////////////////////
      //The following updates a specific custom data element called
 "document-name" that is a child of "document",
      //which is a child of "documentation"
      XPath lXPath = null;
      List lElms = null;
      //First read the Node "documentation" of the specific asset
      String lXMLDocumentation = repository.assetReadCustomDataNode(authToken,
 589, "documentation");
      //Using DOM, convert the XML to a Document
      Document lDoc = null;
      SAXBuilder lBuilder = new SAXBuilder();
      StringReader lReader = null;
      lReader = new StringReader(lXMLDocumentation);
      lBuilder.setValidation(false);
      lBuilder.setIgnoringElementContentWhitespace(true);
      lDoc = lBuilder.build(lReader);
      lXPath = XPath.newInstance("documentation/document");
      lElms = lXPath.selectNodes(lDoc);
      //Cycle through the "document" elements until we find the one we want.  Then
 update it.
      for (int i=0;i<lElms.size();i++) {
        Element lElm = (Element)lElms.get(i);
        List lChildElms = lElm.getChildElements();
        for (int x=0;x<lChildElms.size();x++) {
          Element lChildElm = (Element)lChildElms.get(x);
          if (lChildElm.getName().equals("document-name") &&
 lChildElm.getValue().equals("API")) {
            lChildElm.setText("API KHAN");
          } else {
            lChildElm.setText(lChildElm.getValue());
          }
        }
      }
      //Convert the Document back to an XML string and update the asset's custom
 data.
      repository.assetUpdateCustomDataNode(authToken, 589, "documentation", new
 XMLOutputter().outputString(lDoc));
      //////////////////////////////////////////
      // assetUpdateCustomDataNodeArray
      //////////////////////////////////////////
      try {
        //The following updates multiple custom data elements.  One is called
 "document-name" that is a child of "document",
        //which is a child of "documentation"
        //The other is the element called "also-known-as"
        lXPath = null;
        lElms = null;
        //First read the Node "documentation" of the specific asset
        lXMLDocumentation = repository.assetReadCustomDataNode(authToken, 589,
 "documentation");
        //Using DOM, convert the XML to a Document
        lDoc = null;
        lBuilder = new SAXBuilder();
        lReader = null;
        lReader = new StringReader(lXMLDocumentation);
        lBuilder.setValidation(false);
        lBuilder.setIgnoringElementContentWhitespace(true);
        lDoc = lBuilder.build(lReader);
        lXPath = XPath.newInstance("documentation/document");
        lElms = lXPath.selectNodes(lDoc);
        //Cycle through the "document" elements until we find the one we want. 
 Then update it.
        for (int i=0;i<lElms.size();i++) {
          Element lElm = (Element)lElms.get(i);
          List lChildElms = lElm.getChildElements();
          for (int x=0;x<lChildElms.size();x++) {
            Element lChildElm = (Element)lChildElms.get(x);
            if (lChildElm.getName().equals("document-name") &&
 lChildElm.getValue().equals("API")) {
              lChildElm.setText("API KHAN");
            } else {
              lChildElm.setText(lChildElm.getValue());
            }
          }
        }
        String lDoc1 = new XMLOutputter().outputString(lDoc);
        //Get the next element
        lXMLDocumentation = repository.assetReadCustomDataNode(authToken, 589,
 "also-known-as");
        lDoc = null;
        lBuilder = new SAXBuilder();
        lReader = null;
        lReader = new StringReader(lXMLDocumentation);
        lBuilder.setValidation(false);
        lBuilder.setIgnoringElementContentWhitespace(true);
        lDoc = lBuilder.build(lReader);
        lXPath = XPath.newInstance("also-known-as");
        lElms = lXPath.selectNodes(lDoc);
        //Get the also-known-as element
        for (int i=0;i<lElms.size();i++) {
          Element lElm = (Element)lElms.get(i);
          lElm.setText("Modified Alias");
        }
        String lDoc2 = new XMLOutputter().outputString(lDoc);
        //Convert the Document back to an XML string and update the asset's custom
 data.
        repository.assetUpdateCustomDataNodeFromStringArray(authToken, 589, new
 String[] {"documentation", "also-known-as"}, new String[] {lDoc1, lDoc2});
      } catch (Exception e) {
        e.printStackTrace();
      }
    } 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();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

16.1.3 関連するサブシステム

この項では、アセットAPIで使用される次の関連サブシステムについて説明します。

  • アセット・タイプ

    すべてのアセットには、アクティブで有効なアセット・タイプが必要です。このアセット・タイプは、アセット用のカスタム・データに保存できるメタデータを定義します。

  • ベンダー

    必要に応じて、アセットをベンダーにリンクできます。リンクはベンダーID別に行います。

  • 許容値

    アセットを作成または編集する場合、許容値リストに含まれる許容値は、アセット・タイプ用に定義されたメタデータ要素のオプションとして使用します。許容値リストの許容値を使用するには、アセット(Asset.GetCustomData())のカスタム・データを変更して、許容値のIDを参照します。

  • リレーションシップ・タイプ

    リレーションシップ・タイプは、アセット間に存在できるリレーションシップの種類を定義します。

  • カテゴリ分けタイプ

    カテゴリ分けタイプは、アセット・タイプに追加された最上位レベルのグループのカテゴリ分けです。カテゴリ分けは、アセットを記述します。

  • プロジェクト

    アセットは、プロジェクト別に作成できます。アセット用にプロジェクトを作成すると、IDの配列で格納されます。

  • ユーザー

    ユーザーはアセットに割り当てることができます。メタデータの操作の担当者です。

16.2 ユースケース

この項では、アセットAPIを使用するユースケースについて説明します。含まれる内容は、次のとおりです。

16.2.1 ユースケース: 新しいアセットの作成

説明

新しいアセットを作成し、これをOracle Enterprise Repositoryに入力します。

サンプル・コード

例16-2 ユースケース: 新しいアセットの作成

package com.flashline.sample.assetapi;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.util.Calendar;
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.service.v300.FlashlineRegistry;
import
 com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class CreateNewAsset {
  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);
      ///////////////////////////////////
      // Login to OER
      ///////////////////////////////////
      AuthToken authToken = repository.authTokenCreate(
          pArgs[1],pArgs[2]);
      ///////////////////////////////////
      // Create new asset
      ///////////////////////////////////
      Asset myAsset = repository.assetCreate(authToken,
          "My Asset Name108", "My Version
 "+Calendar.getInstance().getTimeInMillis(), 144);
      ////////////////////////////////////////////
      //The following demonstrates how to modify a custom data Date element on an
 asset.
      //This date must be in a specific format and the name of the element must by
 known.
      //In this example, the name of the element is "testdate".  This element must
 have been created in the
      //asset type as a Date element
      //Update the testdate field to January 1, 2007
      //Note: the format of the date should match the system setting for Short
 Date.
      repository.assetUpdateCustomDataString(authToken, myAsset.getID(),
 "testdate", "2007-1-1");
    } 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();
    }
  }
}

16.2.2 ユースケース: XMLからの新しいアセットの作成

説明

アセットのXML表現から新しいアセットを作成することもできます。スキーマを使用してアセットのXMLを検証してから、作成します。アセット・タイプのスキーマは、例16-3に示されているように、オープンAPIで使用できます。

個別に検証を実行する必要はありません。作成の前に、アセットのXMLが内部で検証されるためです。個別に検証を実行する場合、Xerces 2.0などの検証用のXMLパーサーを見つける必要があります。

サンプル・コード

例16-3 ユースケース: XMLからの新しいアセットの作成

package com.flashline.sample.assetapi;
import java.io.IOException;
import java.io.StringReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.util.Calendar;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.rpc.ServiceException;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;
import com.flashline.registry.openapi.base.OpenAPIException;
import com.flashline.registry.openapi.entity.AuthToken;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
 com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class CreateNewAssetFromXML {
  public static void main(String pArgs[]) throws ServiceException,
      ParserConfigurationException, SAXException, IOException {
    String SCHEMA_LANGUAGE =
 "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
    String XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";
    String SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource";
    SAXParserFactory lSaxParserFactory = null;
    SAXParser lSaxParser = null;
    try {
      ///////////////////////////////////////////////////////////
      // Connect to Oracle Enterprise Repository
      ///////////////////////////////////////////////////////////
      URL lURL = null;
      lURL = new URL(pArgs[0]);
      FlashlineRegistry repository = new FlashlineRegistryServiceLocator()
          .getFlashlineRegistry(lURL);
      ///////////////////////////////////
      // Login to OER
      ///////////////////////////////////
      AuthToken authToken = repository.authTokenCreate(pArgs[1],pArgs[2]);
      // Anonymous class to handle validation errors
      DefaultHandler lDefaultHandler = new DefaultHandler() {
        public void error(SAXParseException exception) throws SAXException {
          throw exception;
        }
        public void fatalError(SAXParseException exception) throws SAXException {
          throw exception;
        }
      };
      //////////////////////////////////////////////////////////////////////
      // Define the asset you want to create in XML
      //////////////////////////////////////////////////////////////////////
      // This is the XML of the asset we're creating. Typically it would
      // come from a GUI or other asset creation mechanism. It is hard
      // coded for this example.
      /////////////////////////////////////////////////////////////////////
      String assetXML = "<asset id=\"0\">"
          + "           <asset-type id=\"145\" icon=\"component.gif\"
 lastSavedDate=\"17 Jul 2007 12:00:00 AM\">Component</asset-type>"
          + "           <mandatory-data>"
          + "               <name>NewComponent</name>"
          + "              
 <version>"+Calendar.getInstance().getTimeInMillis()+"</version>"
          + "               <description><![CDATA[My Description]]></description>"
          + "               <keywords/>"
          + "               <notification-email/>"
          + "               <applied-policies/>"
          + "               <vendor id=\"0\"/>"
          + "               <file-informations/>"
          + "               <hash-informations/>"
          + "               <producing-projects/>"
          + "               <submission-files/>"
          + "               <applied-compliance-templates/>"
          + "               <contacts/>"
          + "               <relationships/>"
          + "               <categorization-types/>"
          + "           </mandatory-data>"
          + "           <admin-data>"
          + "           </admin-data>"
          + "       </asset>";
      //////////////////////////////////////////////////////////////////////
      // This returns the Schema for the asset type of the asset we're
      // creating
      //////////////////////////////////////////////////////////////////////
      String schema = repository.assetTypeSchemaRead(authToken, 144);
      //////////////////////////////////////////////////////////////////////
      // This block of code shows validating the asset XML against
      // the schema
      //////////////////////////////////////////////////////////////////////
      lSaxParserFactory = SAXParserFactory.newInstance();
      lSaxParserFactory.setNamespaceAware(true);
      lSaxParserFactory.setValidating(true);
      lSaxParser = lSaxParserFactory.newSAXParser();
      lSaxParser.setProperty(SCHEMA_LANGUAGE, XML_SCHEMA);
      lSaxParser.setProperty(SCHEMA_SOURCE, new InputSource(new StringReader(
          schema)));
      lSaxParser.parse(new InputSource(new StringReader(assetXML)),
          lDefaultHandler);
      //////////////////////////////////////////////////////////////////////
      // If no exception was thrown the asset XML validates and
      // the creation should not fail due to XML formatting errors.
      //////////////////////////////////////////////////////////////////////
      repository.assetCreateFromXML(authToken, assetXML);
    } 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();
    }
  }
}

16.2.3 ユースケース: アセットの変更

説明

既存のアセットのメタデータを変更します。

サンプル・コード

例16-4 ユースケース: アセットの変更

package com.flashline.sample.assetapi;
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.Categorization;
import com.flashline.registry.openapi.entity.CategorizationType;
import com.flashline.registry.openapi.query.CategorizationTypeCriteria;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
 com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class ModifyExistingAsset {
  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);
      ////////////////////////////////////////////////////////////
      // Login to OER
      ////////////////////////////////////////////////////////////
      AuthToken authToken = repository.authTokenCreate(
          pArgs[1],pArgs[2]);
      ////////////////////////////////////////////////////////////
      // Read the asset you want to modify
      ////////////////////////////////////////////////////////////
      Asset myAsset = repository.assetRead(authToken, 559);
      // 559 is the example asset number
      ////////////////////////////////////////////////////////////
      // Modify the name, version, description, and notification
      // email
      ////////////////////////////////////////////////////////////
      myAsset.setName("New Name");
      myAsset.setVersion("New Version");
      myAsset.setDescription("New Description");
      myAsset.setNotificationEmail("user@example.com");
      ////////////////////////////////////////////////////////////
      // Modify Categorizations on the asset
      ////////////////////////////////////////////////////////////
      // Setup arrays used for assigning categorizations
      CategorizationType[] lAllCatTypes = null;
      Categorization[] lAllCats = null;
      CategorizationType[] lCatTypes = new CategorizationType[1];
      Categorization[] lCats = new Categorization[1];
      ////////////////////////////////////////////////////////////
      // Search for all categorizations that are asset assignable
      ////////////////////////////////////////////////////////////
      CategorizationTypeCriteria categorizationTypeCriteria = new
 CategorizationTypeCriteria();
      categorizationTypeCriteria.setNameCriteria("");
      lAllCatTypes = repository.categorizationTypeQuery(authToken,
          categorizationTypeCriteria);
      ////////////////////////////////////////////////////////////
      // Find all the categorizations to be assigned to the asset
      ////////////////////////////////////////////////////////////
      for (int i = 0; i < lAllCatTypes.length; i++) {
        CategorizationType lCatType = repository.categorizationTypeRead(
            authToken, lAllCatTypes[i].getID());
        lAllCats = repository.categorizationReadByType(authToken,
            lCatType, true, true);
        if (lAllCats.length > 0) {
          lCatTypes[0] = lCatType;
          // when we find the first one, use it
          break;
        }
      }
      lCats[0] = lAllCats[0];
      ////////////////////////////////////////////////////////////
      // Modify the asset to use the categorizations
      ////////////////////////////////////////////////////////////
      myAsset.setCategorizations(lCats);
      myAsset.setCategorizationTypes(lCatTypes);
      ////////////////////////////////////////////////////////////
      // Modify the custom access settings for the asset
      ////////////////////////////////////////////////////////////
      String[] lCasTypes = repository.customAccessSettingTypesGet(authToken);
      String[] lCustomAccessSettings = null;
      if (lCasTypes!=null && lCasTypes.length>0) {
        lCustomAccessSettings = repository.customAccessSettingNamesGet(authToken,
 lCasTypes[0]);
      }
      if (lCustomAccessSettings!=null && lCustomAccessSettings.length>0) {
        String[] myCustomAccessSettings = { lCustomAccessSettings[0] };
        myAsset.setCustomAccessSettings(myCustomAccessSettings);
      }
      ////////////////////////////////////////////////////////////
      // Add producing projects to the asset
      ////////////////////////////////////////////////////////////
      long[] producingProjectsIDs = new long[1];
      producingProjectsIDs[0] = 50000;
      myAsset.setProducingProjectsIDs(producingProjectsIDs);
      ////////////////////////////////////////////////////////////
      // save the modifications
      ////////////////////////////////////////////////////////////
      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();
    }
  }
}

16.2.4 ユースケース: アセットへのユーザーの割当て

説明

複数のユーザーを1つのアセットに割り当てることができます。

サンプル・コード

例16-5 ユースケース: アセットへのユーザーの割当て

package com.flashline.sample.assetapi;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.util.Calendar;
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.AssignedUser;
import com.flashline.registry.openapi.entity.AuthToken;
import com.flashline.registry.openapi.entity.RegistryUser;
import com.flashline.registry.openapi.query.UserCriteria;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
 com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class AssignUsers {
  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);
      //////////////////////////////////////////////////////////
      // Login to OER
      //////////////////////////////////////////////////////////
      AuthToken authToken = repository.authTokenCreate(
          pArgs[1],pArgs[2]);
      //////////////////////////////////////////////////////////
      // Retrieve desired asset
      //////////////////////////////////////////////////////////
      Asset myAsset = repository.assetRead(authToken, 559);
      // 559 is the example asset number
      //////////////////////////////////////////////////////////
      // Create array of AssignedUser objects
      //////////////////////////////////////////////////////////
      AssignedUser[] lUsers = new AssignedUser[3];
      //////////////////////////////////////////////////////////
      // NOTE:
      //
      // The AssignedUser object has two methods:
      // setUserID(long)
      // setAssignedDate(Calendar).
      // (Specifies the date the user was assigned to the
      // asset. If no date is specified, the current date
      // is used.)
      //////////////////////////////////////////////////////////
      //////////////////////////////////////////////////////////
      // Add AssignedUser objects to the array
      //////////////////////////////////////////////////////////
      AssignedUser lUser = new AssignedUser();
      lUser.setUserID(99); // 99 is the admin user id
      lUsers[0] = lUser;
      lUser = new AssignedUser();
      RegistryUser lRegistryUser1 = createRegistryUser(repository, authToken);
      lUser.setUserID(lRegistryUser1.getID());
      lUsers[1] = lUser;
      lUser = new AssignedUser();
      RegistryUser lRegistryUser2 = createRegistryUser(repository, authToken);
      lUser.setUserID(lRegistryUser2.getID());
      lUsers[2] = lUser;
      //////////////////////////////////////////////////////////
      // Add array to the asset that is being updated
      //////////////////////////////////////////////////////////
      myAsset.setAssignedUsers(lUsers);
      //////////////////////////////////////////////////////////
      // save the modifications
      //////////////////////////////////////////////////////////
      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();
    }
  }
  protected static RegistryUser createRegistryUser(FlashlineRegistry repository,
 AuthToken authToken) throws OpenAPIException, RemoteException {
    RegistryUser lRet = null;
    String lUserName = "user"+Calendar.getInstance().getTimeInMillis();
    lRet = repository.userCreate(authToken, lUserName, "", lUserName,
 lUserName+"@example.com", lUserName, false, false, false);
    return lRet;
  }
}

16.2.5 ユースケース: アセットの検索の作成

説明

特定の条件を満たすアセットをすべて検索します。

サンプル・コード

例16-6 ユースケース: アセットの検索の作成

package com.flashline.sample.assetapi;
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.AssetSummary;
import com.flashline.registry.openapi.entity.AuthToken;
import com.flashline.registry.openapi.query.AssetCriteria;
import com.flashline.registry.openapi.query.DateRangeSearchTerm;
import com.flashline.registry.openapi.query.SearchTerm;
import com.flashline.registry.openapi.query.TabStatusSearchTerm;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
 com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class FindAssets {
  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);
      ////////////////////////////////////////////////////////////
      // Login to OER
      ////////////////////////////////////////////////////////////
      AuthToken authToken = repository.authTokenCreate(
          pArgs[1],pArgs[2]);
      ////////////////////////////////////////////////////////////
      // Search for all assets
      ////////////////////////////////////////////////////////////
      AssetCriteria criteria = new AssetCriteria();
      AssetSummary[] assets = repository.assetQuerySummary(authToken, criteria);
      ////////////////////////////////////////////////////////////
      // try a general search which includes Name, version,
      // description, and keywords
      ////////////////////////////////////////////////////////////
      criteria = new AssetCriteria();
      criteria.setGeneralCriteria("My Asset");
      assets = repository.assetQuerySummary(authToken, criteria);
      ////////////////////////////////////////////////////////////
      // Search for assets that contain a specific search string
      // in one particular field.
      ////////////////////////////////////////////////////////////
      criteria = new AssetCriteria();
      criteria.setNameCriteria("My Name");
      criteria.setVersionCriteria("My version");
      criteria.setDescriptionCriteria("My Description");
      assets = repository.assetQuerySummary(authToken, criteria);
      ////////////////////////////////////////////////////////////
      // Implementing a Search through the AssetCriteria Object
      // --------------------------------------------------
      // If no operator is specified when implementing a search
      // using the setSearchTerms method in the AssetCriteria
      // object, the system defaults to the operator EQUALS.
      // The operator LIKE must be specified if required for the
      // search.
      ////////////////////////////////////////////////////////////
      criteria = new AssetCriteria();
      SearchTerm lSearchTerm = new SearchTerm();
      lSearchTerm.setKey("name");
      lSearchTerm.setOperator("LIKE");
      lSearchTerm.setValue("Test");
      SearchTerm[] lTerms = new SearchTerm[1];
      lTerms[0] = lSearchTerm;
      criteria.setSearchTerms(lTerms);
      assets = repository.assetQuerySummary(authToken, criteria);
      //Search for assets where a specific DATETIME field is a given age
      //////////////////////////////////////////////////////////////////
      criteria = new AssetCriteria();
      //Not specifying an operator defaults to 'equals'.
      DateRangeSearchTerm lTerm = new DateRangeSearchTerm();
      /////////////////////////
      //date-range is the query key.  registereddate is the date field we are
 searching on
      //Allowable fields to search on:
      //submitteddate
      //registereddate
      //accepteddate
      //createddate
      //updateddate
      //To do a search for all assets that were registered more than 5 days ago
      lTerm.setKey("date-range");
      //Set the value to a day 5 days older than the current date.  Assume today's
 date is 1/10/2007
      //The format defaults to OER's system setting for Short Date Format.
      //The format can be set to any valid date format using setDateFormat() and
 passing the date format.
      lTerm.setDateFormat("yyyy-MM-dd");
      lTerm.setBeginDate("2007-1-5");
      lTerm.setBeginOperator("lt");
      lTerm.setDateField("registereddate");
      lTerms = new SearchTerm[1];
      lTerms[0] = lTerm;
      criteria.setSearchTerms(lTerms);
      assets = repository.assetQuerySummary(authToken, criteria);
      //Search for assets where a given date field is within a date range
      //////////////////////////////////////////////////////////////////
      criteria = new AssetCriteria();
      lTerm = new DateRangeSearchTerm();
      /////////////////////////
      //date-range is the query key.  registereddate is the date field we are
 searching on
      //Allowable fields to search on:
      //submitteddate
      //registereddate
      //accepteddate
      //createddate
      //updateddate
      //The following SearchTerm translates to "Assets where the registereddate is
 greater than or equal to Jan. 1, 2007
      lTerm.setKey("date-range");
      //The format defaults to OER's system setting for Short Date Format.
      //The format can be set to any valid date format using setDateFormat() and
 passing the date format.
      lTerm.setDateField("registereddate");
      lTerm.setDateFormat("yyyy-MM-yy");
      lTerm.setBeginDate("2007-01-01");
      lTerm.setBeginOperator("gte");
      lTerm.setEndDate("2007-01-10");
      lTerm.setEndOperator("lte");
      //The following SearchTerm translates to "Assets where the registereddate is
 less than or equal to Jan. 10, 2007
      criteria.setSearchTerms(new SearchTerm[] {lTerm});
      //This query returns all assets that were registered between January 1 and
 January 10, including those days.
      assets = repository.assetQuerySummary(authToken, criteria);
      //Search for assets where a given tab has been approved or unapproved
      //////////////////////////////////////////////////////////////////
      criteria = new AssetCriteria();
      TabStatusSearchTerm lTabTerm = new TabStatusSearchTerm();
      //tabstatus is the type of search we want to do.  overview is the name of
 the tab we want to search on
      lTabTerm.setKey("tabstatus");
      lTabTerm.setTabNames(new String[] {"overview"});
      lTabTerm.setApproved(true);
      criteria.setSearchTerms(new SearchTerm[] {lTabTerm});
      //This query returns all assets with the Overview tab being approved
      assets = repository.assetQuerySummary(authToken, criteria);
      //You may also search by a date range.
      lTabTerm.setKey("tabstatus");
      lTabTerm.setTabNames(new String[] {"overview"});
      lTabTerm.setApproved(false);
      lTabTerm.setBeginDate("2007-1-01");
      lTabTerm.setBeginOperator("lte");
      criteria.setSearchTerms(new SearchTerm[] {lTabTerm});
      //The following returns all assets that have the Overview tab unapproved
 since or before January 1, 2007
      assets = repository.assetQuerySummary(authToken, criteria);
      //Search for assets where a custom field date has a specific value.
      //This test returns all assets that have a testdate of January 1, 2007.
      //The testdate field is a custom data date element.
      //////////////////////////////////////////////////////////////////
      criteria = new AssetCriteria();
      DateRangeSearchTerm lDateRangeTerm = new DateRangeSearchTerm();
      //Test Equals
      lDateRangeTerm.setKey("/asset/custom-data/testdate");
      lDateRangeTerm.setBeginDate("2007-01-1");
      lDateRangeTerm.setBeginOperator("eq");
      criteria.setSearchTerms(new SearchTerm[] {lDateRangeTerm});
      assets = repository.assetQuerySummary(authToken, criteria);
    } 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();
    }
  }
}

16.2.6 ユースケース: アセット・ステータスのアップグレード

説明

アセットのステータス・レベルを未発行から、発行済、承認済、登録済に変更します。

サンプル・コード

例16-7 ユースケース: アセット・ステータスのアップグレード

package com.flashline.sample.assetapi;
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.KeyValuePair;
import com.flashline.registry.openapi.query.AssetCriteria;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
 com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class PromoteAsset {
  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);
      ///////////////////////////////////////////////////////////
      // Login to OER
      ///////////////////////////////////////////////////////////
      AuthToken authToken = repository.authTokenCreate(
          pArgs[1],pArgs[2]);
      long lAssetID = 559;
      // -------------------------------------------------------
      // asset with id 559 would have to be unsubmitted for this to work
      AssetCriteria lAssetCriteria = new AssetCriteria();
      lAssetCriteria.setIDCriteria(lAssetID);
      KeyValuePair lKeyValuePair = repository.assetEvaluate(authToken,
 lAssetCriteria, "Registration Status");
      if (!lKeyValuePair.getValue().equalsIgnoreCase("unsubmitted")) {
        unregisterAsset(repository, authToken, lAssetID);
      }
      ///////////////////////////////////////////////////////////
      // promote the asset from unsubmitted to submitted
      ///////////////////////////////////////////////////////////
      repository.assetSubmit(authToken, lAssetID);
      // asset 559 would have to be unsubmitted for this to work
      ///////////////////////////////////////////////////////////
      // promote the asset from submitted to accepted
      ///////////////////////////////////////////////////////////
      repository.assetAccept(authToken, lAssetID);
      // asset 561 would have to be submitted for this to work
      ///////////////////////////////////////////////////////////
      // promote the asset from accepted to registered
      ///////////////////////////////////////////////////////////
      repository.assetRegister(authToken, lAssetID);
      // asset 563 would have to be accepted for this to work
    } 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();
    }
  }
  protected static void unregisterAsset(FlashlineRegistry repository, AuthToken
 authToken, long pAssetID) {
    try {
      repository.assetUnRegister(authToken, pAssetID);
    } catch (Exception e) {
    }
    try {
      repository.assetUnAccept(authToken, pAssetID);
    } catch (Exception e) {
    }
    try {
      repository.assetUnSubmit(authToken, pAssetID);
    } catch (Exception e) {
    }
  }
}

16.2.7 ユースケース: アセット・ステータスのダウングレード

説明

前述のユースケースとは反対に、アセットのステータス・レベルを登録済から、承認済、発行済、未発行に変更します。

サンプル・コード

例16-8 ユースケース: アセット・ステータスのダウングレード

package com.flashline.sample.assetapi;
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.KeyValuePair;
import com.flashline.registry.openapi.query.AssetCriteria;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
 com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class DemoteAsset {
  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);
      ///////////////////////////////////////////////////////////
      // Login to OER
      ///////////////////////////////////////////////////////////
      AuthToken authToken = repository.authTokenCreate(
          pArgs[1],pArgs[2]);
      long lAssetID = 559;
      // -------------------------------------------------------
      // asset with id 559 would have to be registered for this to work
      AssetCriteria lAssetCriteria = new AssetCriteria();
      lAssetCriteria.setIDCriteria(lAssetID);
      KeyValuePair lKeyValuePair = repository.assetEvaluate(authToken,
 lAssetCriteria, "Registration Status");
      if (!lKeyValuePair.getValue().equalsIgnoreCase("registered")) {
        registerAsset(repository, authToken, lAssetID);
      }
      ///////////////////////////////////////////////////////////
      // demote the asset from registered to accepted
      ///////////////////////////////////////////////////////////
      repository.assetUnRegister(authToken, lAssetID);
      ///////////////////////////////////////////////////////////
      // demote the asset from accepted to submitted
      ///////////////////////////////////////////////////////////
      repository.assetUnAccept(authToken, lAssetID);
      ///////////////////////////////////////////////////////////
      // demote the asset from submitted to unsubmitted
      ///////////////////////////////////////////////////////////
      repository.assetUnSubmit(authToken, lAssetID);
    } 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();
    }
  }
  protected static void registerAsset(FlashlineRegistry repository, AuthToken
 authToken, long pAssetID) {
    try {
      repository.assetSubmit(authToken, pAssetID);
    } catch (Exception e) {
    }
    try {
      repository.assetAccept(authToken, pAssetID);
    } catch (Exception e) {
    }
    try {
      repository.assetRegister(authToken, pAssetID);
    } catch (Exception e) {
    }
  }
}

16.2.8 ユースケース: プロジェクトからのコンプライアンス・テンプレートの適用と削除

説明

コンプライアンス・テンプレートのプロジェクトへの追加およびプロジェクトからの削除を行うことができます。


注意:

アセットがプロジェクトに適用されていて、そのアセットがコンプライアンス・テンプレートでない場合、OpenAPIExceptionが発生します。


サンプル・コード

例16-9 ユースケース: プロジェクトからのコンプライアンス・テンプレートの適用および削除

package com.flashline.sample.assetapi;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.util.Calendar;
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.AssetType;
import com.flashline.registry.openapi.entity.AuthToken;
import com.flashline.registry.openapi.entity.Project;
import com.flashline.registry.openapi.query.AssetCriteria;
import com.flashline.registry.openapi.query.AssetTypeCriteria;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
 com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class AddRemoveTemplate {
  public static void main(String pArgs[]) throws OpenAPIException,
 RemoteException,
      ServiceException {
    try {
      URL lURL = null;
      lURL = new URL(pArgs[0]);
      ///////////////////////////////////////////////////////////
      // Connect to Oracle Enterprise Repository
      ///////////////////////////////////////////////////////////
      FlashlineRegistry repository = new FlashlineRegistryServiceLocator()
          .getFlashlineRegistry(lURL);
      ///////////////////////////////////////////////////////////
      // Login to OER
      ///////////////////////////////////////////////////////////
      AuthToken authToken = repository.authTokenCreate(pArgs[1],
          pArgs[2]);
      ///////////////////////////////////////////////////////////
      // Read or Create a Compliance Template Type and Asset
      ///////////////////////////////////////////////////////////
      AssetType ctType = null;
      AssetTypeCriteria lAssetTypeCriteria = new AssetTypeCriteria();
      lAssetTypeCriteria.setArcheTypeCriteria("Compliance Template Type");
      AssetType[] lAssetTypes =
        repository.assetTypeQuery(authToken, lAssetTypeCriteria);
      if (lAssetTypes!=null && lAssetTypes.length>0) {
        ctType = lAssetTypes[0];
      } else {
        ctType = repository.assetTypeCreateComplianceTemplate(authToken,
            "My Compliance Template
 Type"+Calendar.getInstance().getTimeInMillis());
      }
      Asset lComplianceTemplateAsset = null;
      AssetCriteria lAssetCriteria = new AssetCriteria();
      lAssetCriteria.setAssetTypeCriteria(ctType.getID());
      Asset[] lAssets = repository.assetQuery(authToken, lAssetCriteria);
      if (lAssets!=null && lAssets.length>0) {
        lComplianceTemplateAsset = lAssets[0];
      } else {
        lComplianceTemplateAsset = repository.assetCreate(authToken, "My
 Compliance Template",
            ""+Calendar.getInstance().getTimeInMillis(), ctType.getID());
      }
      ///////////////////////////////////////////////////////////
      // Create a String array of Project IDs that the Compliance
      // Template is applied to.
      ///////////////////////////////////////////////////////////
      String[] lProjectIDs = { "50000" };
      // /////////////////////////////////////////////////////////
      // Apply template to the projects.
      // /////////////////////////////////////////////////////////
      repository.assetApplyToProjects(authToken, lProjectIDs,
          lComplianceTemplateAsset);
      ///////////////////////////////////////////////////////////
      // Retrieve an array of Projects that this template is
      // applied to.
      ///////////////////////////////////////////////////////////
      Project[] lProjects = repository.assetReadAppliedToProjects(
          authToken, lComplianceTemplateAsset);
      String lMsg = "Compliance Template '" + lComplianceTemplateAsset.getName();
      lMsg += "' applied to Project(s): ";
      for (int i=0; lProjects!=null && i<lProjects.length; i++) {
        lMsg += ""+lProjects[i].getName()+(i+1==lProjects.length ? "." : ", ");
      }
      System.out.println(lMsg);
      ///////////////////////////////////////////////////////////
      // Create a String array of Project IDs that the Compliance
      // Template is removed from.
      ///////////////////////////////////////////////////////////
      String[] lRemoveProjectIDs = { "50000" };
      ///////////////////////////////////////////////////////////
      // Remove template from the projects.
      ///////////////////////////////////////////////////////////
      repository.assetRemoveAppliedToProjects(authToken,
          lRemoveProjectIDs, lComplianceTemplateAsset);
    } 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();
    }
  }
}

16.2.9 ユースケース: 新しいバージョンのアセットの作成および古いバージョンのリタイア

説明

リポジトリを更新して、新しいバージョンのアセットを使用できるようにし、以前のバージョンのアセットをリタイアします。

サンプル・コード

例16-10 ユースケース: 新しいバージョンのアセットの作成

package com.flashline.sample.assetapi;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.util.Calendar;
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 CreateNewVersionOfAsset {
  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);
      ///////////////////////////////////////////////////////////
      // Login to OER
      ///////////////////////////////////////////////////////////
      AuthToken authToken = repository.authTokenCreate(
          pArgs[1],pArgs[2]);
      ///////////////////////////////////////////////////////////
      // Read old asset.
      // Update metadata as necessary.
      // Save as new asset.
      ///////////////////////////////////////////////////////////
      Asset myAsset = repository.assetRead(authToken, 561);
      ///////////////////////////////////////////////////////////
      // Find the "next-version" relationship for the asset
      ///////////////////////////////////////////////////////////
      RelationshipType[] allRelationshipTypes =
 getAllRelationshipTypes(repository, authToken);
      for (int i = 0; i < allRelationshipTypes.length; i++) {
        if (allRelationshipTypes[i].getName().equals("next-version")) {
          ///////////////////////////////////////////////////////////
          // This is the relationship type, modify the assets that are related
          // using it
          ///////////////////////////////////////////////////////////
          RelationshipType myRelationshipType = allRelationshipTypes[i];
          ///////////////////////////////////////////////////////////
          // Add the old version to list of previous versions of the
          // newly created asset
          ///////////////////////////////////////////////////////////
          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] = 561;
          myRelationshipType.setSecondaryIDs(newSecondaryIDs);
        }
      }
      Asset myNewAsset = repository.assetCreate(authToken,
          myAsset.getName(), ""+Calendar.getInstance().getTimeInMillis(),
 myAsset.getTypeID());
      myNewAsset.setRelationshipTypes(allRelationshipTypes);
      ///////////////////////////////////////////////////////////
      // Update the new asset
      ///////////////////////////////////////////////////////////
      myNewAsset = repository.assetUpdate(authToken, myNewAsset);
      ///////////////////////////////////////////////////////////
      // retire the old asset
      ///////////////////////////////////////////////////////////
      repository.assetRetire(authToken, 561);
    } 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;
  }
}

16.2.10 ユースケース: アセットのグループの削除

説明

リポジトリに属さないアセットのグループを削除します。

サンプル・コード

例16-11 ユースケース: リポジトリからの不要なアセットの削除

package com.flashline.sample.assetapi;
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.query.AssetCriteria;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
 com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class DeleteAssets {
  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);
      ///////////////////////////////////////////////////////////
      // Login to OER
      ///////////////////////////////////////////////////////////
      AuthToken authToken = repository.authTokenCreate(
          pArgs[1],pArgs[2]);
      ///////////////////////////////////////////////////////////
      // find the assets to delete
      ///////////////////////////////////////////////////////////
      AssetCriteria criteria = new AssetCriteria();
      criteria.setGeneralCriteria("delete me");
      Asset[] assets = repository.assetQuery(authToken, criteria);
      ///////////////////////////////////////////////////////////
      // Iterate through assets, deleting them one at a time.
      ///////////////////////////////////////////////////////////
      for (int i = 0; i < assets.length; i++) {
        repository.assetDelete(authToken, assets[i].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();
    }
  }
}

短所:

アセットは完全に削除されます。オープンAPIでは、削除したアセットをリストアするメソッドがありません。

回避するメソッド:

次のメソッドはオープンAPIのコンテキストでは意味がないので、使用しないでください。

  • setAcceptedByID

  • setAcceptedByName

  • setAcceptedByDate

  • setActiveStatus

  • setAssigned

  • setAssignedToID

  • setAssignedDate

  • setCategorizationTypes

  • setCreatedByID

  • setCreatedByName

  • setCreatedByDate

  • setDeleted

  • setEntityType

  • setExtractable

  • setFullAsset

  • setInactive

  • setKey

  • setLoadedDate

  • setLongName

  • setNotifyUpdatedRelationships

  • setRegisteredByID

  • setRegisteredByName

  • setRegisteredDate

  • setRegistrationStatus

  • setRegistrationStatusBaseName

  • setRegistrationStatusRegistered

  • setRegistrationStatusRejected

  • setRegistrationStatusSubmittedPendingReview

  • setRegistrationStatusSubmittedUnderReview

  • setRegistrationStatusUnsubmitted

  • setRejectionReason

  • setRetired

  • setSubmittedByID

  • setSubmittedByName

  • setSubmittedDate

  • setTypeIcon

  • setTypeName

  • setUpdatedDate

  • setVendorName

  • setVisible

一般的なミスの回避

  • アセットのルール

    • アセットは、アクティブで有効なアセット・タイプに割り当てる必要があります。

    • アセットの名前/バージョンの文字列は一意のペアである必要があります。

    • 新しいアセットのIDは0にする必要があります。

    • 新しいアセットのアクティブなステータスはアクティブである必要があります。

提供されていない機能

  • カスタム・データを変更するためのヘルパー・メソッド

  • 追加の検証

    アセットを保存する場合、Oracle Enterprise Repositoryでは、現在、次の内容を検証しています。

    • アセット・タイプが有効でアクティブであること

    • 名前/バージョンが一意であること

    • アセットを作成する場合、アクティブなステータスが有効であること

    • アセットを更新する場合、アセットがすでに存在すること

    • コンタクトが重複していないこと

    • カテゴリ分けが有効であること

    • 今後のバージョンのリポジトリの検証内容

      • カスタム・データが正しいフォーマットのXMLであること

      • カスタム・データにはアセット・タイプに基づいて有効なXMLが含まれていること

16.2.11 ユースケース: アセットの検索およびカスタム・データのアップグレード

説明

特定のカスタム・データ値ですべてのアセットの検索を実行し、これらのアセットのそれぞれについてカスタム・データの一部を更新します。注意: assetUpdateCustomDataNodeメソッドを使用する場合、アセットは自動的に保存されます。

サンプル・コード

例16-12 ユースケース: アセットの検索およびカスタム・データのアップグレード

package com.flashline.sample.assetapi;
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.AssetSummary;
import com.flashline.registry.openapi.entity.AuthToken;
import com.flashline.registry.openapi.query.AssetCriteria;
import com.flashline.registry.openapi.query.SearchTerm;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
 com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class UpdateAssetTestResults {
  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);
      ///////////////////////////////////////////////////////////
      // Login to OER
      ///////////////////////////////////////////////////////////
      AuthToken authToken = repository.authTokenCreate(pArgs[1],
          pArgs[2]);
      ///////////////////////////////////////////////////////////
      // create a criteria object searching for all assets with a
      // custom-data element for test-frequency equal to 'DAILY'
      ///////////////////////////////////////////////////////////
      SearchTerm[] searchTermArray = new SearchTerm[1];
      SearchTerm term = new SearchTerm();
      term.setKey("/asset/custom-data/test-frequency");
      term.setValue("DAILY");
      searchTermArray[0] = term;
      AssetCriteria criteria = new AssetCriteria();
      criteria.setSearchTerms(searchTermArray);
      ///////////////////////////////////////////////////////////
      // perform search, getting back summary objects. loop through
      // objects and perform an action on each one
      ///////////////////////////////////////////////////////////
      AssetSummary[] assets = repository.assetQuerySummary(authToken,
          criteria);
      ///////////////////////////////////////////////////////////
      // Loop through search results
      ///////////////////////////////////////////////////////////
      for (int i = 0; i < assets.length; i++) {
        long assetID = assets[i].getID();
        String testResult = null;
        ///////////////////////////////////////////////////////////
        // Update value in the asset
        ///////////////////////////////////////////////////////////
        repository.assetUpdateCustomDataNode(
            authToken, assetID, "/asset/custom-data/test-result", testResult);
      }
    } 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();
    }
  }
}

16.2.12 ユースケース: アセットのタブの読込み

説明

アセットのタブを読み込みます。

サンプル・コード

例16-13 ユースケース: アセットのタブの読込み

package com.flashline.sample.assetapi;
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.TabBean;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
 com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class AssetReadTabs {
  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);
      TabBean[] lTabBeans = null;
      ///////////////////////////////////
      // Login to OER
      ///////////////////////////////////
      AuthToken authToken = repository.authTokenCreate(pArgs[1],pArgs[2]);
      ///////////////////////////////////
      // read an asset's tabs
      ///////////////////////////////////
      lTabBeans = repository.assetTabsRead(authToken, 559);
    } 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();
    }
  }
}

16.2.13 ユースケース: タブ・タイプに基づいたアセットのタブの取得

説明

タブ・タイプ別に特定のアセット・タブを取得します。

サンプル・コード

例16-14 ユースケース: タブ・タイプに基づいたアセットのタブの取得

package com.flashline.sample.assetapi;
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.TabBean;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
 com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class AssetGetTabByType {
  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);
      Asset lAsset = null;
      TabBean lTabBean = null;
      ///////////////////////////////////
      // Login to OER
      ///////////////////////////////////
      AuthToken authToken = repository.authTokenCreate(pArgs[1],pArgs[2]);
      ///////////////////////////////////
      // read an asset
      ///////////////////////////////////
      lAsset = repository.assetRead(authToken, 559);
      ///////////////////////////////////
      // get an asset's tab by tabbeantype
      ///////////////////////////////////
      lTabBean = repository.assetTabRead(authToken, lAsset.getID(), 458);
    } 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();
    }
  }
}

16.2.14 ユースケース: タブの承認および未承認

説明

アセットのタブを承認するか、または未承認にします。

サンプル・コード

例16-15 ユースケース: タブの承認および未承認

package com.flashline.sample.assetapi;
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.service.v300.FlashlineRegistry;
import
 com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;

public class ApproveUnapproveTab {
  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);
      ///////////////////////////////////
      // Login to OER
      ///////////////////////////////////
      AuthToken authToken = repository.authTokenCreate(pArgs[1],pArgs[2]);
      ///////////////////////////////////
      // approve an asset tab
      ///////////////////////////////////
      repository.assetTabApprove(authToken, 559, 1864);
      ///////////////////////////////////
      // unapprove an asset tab
      ///////////////////////////////////
      repository.assetTabUnapprove(authToken, 559, 1864);
    } 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();
    }
  }
}

16.2.15 ユースケース: 特定のタブ用のアセットのメタデータの読込み

説明

特定のタブに基づいたアセットのメタデータを読み込みます。

サンプル・コード

例16-16 ユースケース: 特定のタブ用のアセットのメタデータの読込み

package com.flashline.sample.assetapi;

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.AssetMetadataElement;
import com.flashline.registry.openapi.entity.AssetMetadataTableElement;
import com.flashline.registry.openapi.entity.AuthToken;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;

public class AssetGetMetadataByTab {
  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);
      Asset lAsset = null;

      ///////////////////////////////////
      // Login to OER
      ///////////////////////////////////
      AuthToken authToken = repository.authTokenCreate(pArgs[1],pArgs[2]);

      ///////////////////////////////////
      // read an asset
      ///////////////////////////////////
      lAsset = repository.assetRead(authToken, 589);

      ///////////////////////////////////
      // Get the metadata elements based
      // on the asset ID and the tab name
      ///////////////////////////////////
      AssetMetadataElement[] lElements =
repository.assetReadTabMetadata(authToken, lAsset.getID(), "Overview");

      //An AssetMetadataElement represents a custom or mandatory data element of an asset
      for (AssetMetadataElement lElement : lElements) {
        //This represents a TABLE element type
        if (lElement.getValue() instanceof AssetMetadataTableElement) {
          AssetMetadataTableElement lTable =
(AssetMetadataTableElement)lElement.getValue();
          System.out.println(lElement.getDisplayName());
          //A TABLE can have multiple elements
          for (AssetMetadataElement lTableElement : lTable.getElements()) {
            //An element of a TABLE can be another TABLE
            if (lTableElement.getValue() instanceofAssetMetadataTableElement) {

System.out.println(((AssetMetadataTableElement)lTableElement.getValue()).getDisplayName());
              for (AssetMetadataElement lChildElement :
((AssetMetadataTableElement)lTableElement.getValue()).getElements()) {
                System.out.println(lChildElement.getDisplayName() + " : " +
lChildElement.getValue());
              }
            } else {
              //Or an element of a TABLE can be a regular value
              System.out.println(lTableElement.getDisplayName() + " : " +
lTableElement.getValue());
            }
          }
          //This represents a MULTIPLE ITEM LIST
        }  else if (lElement.getValue() instanceof String[]) {
          System.out.println(lElement.getDisplayName());
          for (String lString : (String[])lElement.getValue()) {
            System.out.println(lString);
          }
          //This represents a SINGLE ITEM
        } else {
          System.out.println(lElement.getDisplayName() + " : " +
lElement.getValue());
        }
      }
    } 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();
    }
  }
}