この章では、リレーションシップ・タイプAPIのユースケースについて説明します。このユースケースで、Oracle Enterprise Repositoryにおいて、新しいリレーションシップ・タイプの作成、および関連アセットの変更または問合せを行う方法について解説します。
この章では、次の項目について説明します。
リレーションシップ・タイプは、2つのアセットを関連付けるために使用するリレーションシップの構造を定義します。
アセット・サブシステム
アセットを作成または編集する場合、リレーションシップ・タイプは、アセット間に存在するリレーションシップを定義または変更するために使用します。
この項では、リレーションシップ・タイプAPIを使用するユースケースについて説明します。含まれる内容は、次のとおりです。
説明
アセット間で使用されるリレーションシップの新しいタイプを作成します。
サンプル・コード
例27-1 ユースケース: 新しいリレーションシップ・タイプの作成
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(); } } }
説明
My RelationshipTypeを使用して、ターゲット・アセットを他のアセットに関連付けます。同じリレーションシップ・タイプを使用して、追加のアセットに対するリレーションシップを設定します。
サンプル・コード
例27-2 ユースケース: 関連アセットの変更
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; } }
注意: 回避するメソッド: SetPromptNotifySecondary() |
説明
関連アセット・タイプを問い合せます。
サンプル・コード
例27-3 ユースケース: 関連アセットの問合せ
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; } }
RelationshipTypeQueryの例
try { RelationshipTypeCriteria rCriteria = new RelationshipTypeCriteria(); RelationshipType[] allRelationshipTypes = FlashlineRegistry.relationshipQuery(lAuthToken, rCriteria); } catch (OpenAPIException e) { e.printStackTrace(); } catch (RemoteException re) { re.printStackTrace(); }