Correlate by name - SmartPlant Foundation - IM Update 46 - Help - Hexagon

SmartPlant Foundation Help

Language
English
Product
SmartPlant Foundation
Search by Category
Help
SmartPlant Foundation / SDx Version
10
SmartPlant Markup Plus Version
10.0 (2019)
Smart Review Version
2020 (15.0)

In the default implementation, the SameAs relationships manage correlation between two objects. For example, objectA in the PID domain is the same as objectB in the IDX domain. These special relationships are placed inside the published XML file and are generated when manually correlating after retrieve. There is an Auto-Correlate workflow that matches objects by name and creates the SameAs relationships; this workflow is certified for use on CDW.

  • Auto-Correlate will not generate a SameAs relationship if doing so would result in a conflict (that is, generating the SameAs relationship would result in the CDW object being related to more than one object of the same Class definition).

  • If processing a SameAs relationship generated by Auto-Correlate would result in a conflict, then the SameAs will be ignored.

  • If two different objects have the same class and the same name, they cannot be consolidated by Auto-Correlate.

  • SameAs relationships that are published by the tool (identified as a SameAs relationship without an OBID) are saved in the database. Existing SPFTEFComprisedOf relationships in customer data are processed in the same manner as a SameAs relationship generated by Auto-Correlate. If needed, the data may be corrected by publishing the SameAs relationships or by reconsolidating.

  • A SameAs can result in two objects being related to the same CDW object. If a new object with the same class and same name is published without a SameAs, it will not be related to the existing CDW object, but instead will be related to a new CDW object.

  • If an object is renamed, any objects related to the renamed object because of a tool-published SameAs will remain related. However, auto-correlated objects will be related to a new CDW object.

Auto-correlation customization

You can perform a sideways override of ISPFTEFToolDataFileDefault and override the following methods:

  • PostProcessAutoCorrelatedStructure – This method allows customization of the auto-correlated, structured object collection determined by out-of-the box code. The method is called once for every shared object definition for each unique class definition in the tool data file. It is called after the default logic is executed for that shared object definition and an updated, auto-correlated structure is available.

  • RetrieveObjectsWithClassDefUID – This method is used to retrieve all published objects from the database with names that match the input criteria.

For those projects that use non-Hexagon tools for authoring data or SmartPlant Foundation for authoring, there is no mechanism to correlate. To address this gap and to provide more flexibility than just name correlation, written custom code has been written to use the unique key definition to define where two objects are the same. This custom code can be modified as required to fit the needs of your business.

In the following example, we use a unique key definition on the CDW class definition to define how we correlate. We also specify that the configuration and name define uniqueness. You can look at other related information and include that in the unique key as well.

<ClassDef>

<IObject UID="SPFCDWInstrument" Name="SPFCDWInstrument" Description="Instrument (Planned Material)" />

<IClassDef />

<ISchemaObj DisplayName="Instrument (Planned Material)" />

<ISPFClassDefExt SPFIsConfigurationControlled="True" SPFUniqueKeyDef="CDWInst,CurrentConfig,Name"/>

</ClassDef>

The method to override is called OnCreateNewObjectAndMergeWithInputs. This method is on the ISPFCDWPublishedDocVersionDefault interface.

The process logic is described below:

  1. Look to see if the CDW class definition has a unique key.

  2. Create a temporary object, and set all the properties.

  3. Call the GenerateKey function, which returns a unique key.

  4. Look in the database for another CDW object with the same unique key.

    1. If one is found, update and return it.

    2. Otherwise, create a new CDW Object, and return it.

  5. The ComprisedOf relationship will be created between the tool data and the object returned.

Public Overrides Function OnCreateNewObjectAndMergeWithInputs(ByVal pobjPublishedItem As Generated.IObject, ByVal pobjExistingCDWItem As Generated.IObject, ByVal pobjCDWObject As StreamingSchema.Model.SchemaObjectDef, ByVal pstrCDWUID As String) As Generated.IObject

'

' Note:- ExistingCDWItem is nothing

'

' NOTE: Need to do this bit below.

' If this object is a document then attempt to link the document to its doc master instead of creating a CDW object for it.

'

If pobjPublishedItem IsNot Nothing AndAlso pobjPublishedItem.Interfaces.Contains("IDocument") Then

Me.CoreModule.QueryRequest.AddQueryInterface("ISPFTEFPublishedDocMaster")

'

' As the Doc Master and the 2 tier document have the same UID then it is better to find by UID

'

Dim lobjDocMasters As IObjectDictionary = CoreModule.QueryRequest.RunByUID(pobjPublishedItem.UID)

If lobjDocMasters IsNot Nothing AndAlso lobjDocMasters.Count > 0 Then

Return lobjDocMasters(0)

End If

'

' If a document master has not been found then the code continues to create a regular CDW object for this published object.

'

End If

'

' Extract the config

'

Dim lstrConfig As String = ""

If pobjExistingCDWItem IsNot Nothing Then

lstrConfig = pobjExistingCDWItem.Config

End If

If String.IsNullOrEmpty(lstrConfig) Then lstrConfig = CoreModule.Server.Context.CreateConfiguration.ToString

'

' Append an _S on the end so we can distinguish from Tool object plus we are consistent with the original implementation. Use function so we

' can change this in just one place should it be wrong.

'

Dim lstrNewUID As String = pstrCDWUID

'

' Make up your own correlate rules here....

'

Dim lobjClassDef As IClassDef = CType(Me.CoreModule.ProcessCache.Item(pobjCDWObject.ClassDefinitionUID, "SCHEMA").Interfaces("IClassDef"), IClassDef)

If String.IsNullOrEmpty(lobjClassDef.SPFUniqueKeyDef) = False Then

'

' Create a temp object so we can call the generate key method

'

Dim lobjTempObj As IObject = Utilities.GeneralUtilities.InstantiateObjectNoFootprint(Me.CoreModule, lobjClassDef.UID, "", "", "")

lobjTempObj.Config = lstrConfig

'

' Need to call the base function that will set the properties on the temp object from the tool representation

'

OnSetPropertiesFromSource(lobjTempObj, pobjCDWObject)

'

' Now call the GenerateKey

'

Dim lstrUniqueKey As String = CType(lobjTempObj.Interfaces("IObject"), IObjectDefault).GetClass.GenerateKey(lobjClassDef.SPFUniqueKeyDef)

'

' Now search the database looking for unique key

'

Dim lcolUniqueKeys As New Specialized.StringCollection

lcolUniqueKeys.Add(lstrUniqueKey)

'

' Look for objects with these unique keys

'

Dim lobjDataMgr As New DataAccess.DataManager(Me.CoreModule)

Dim lcolExistingOBIDs As Generic.Dictionary(Of String, ArrayList) = lobjDataMgr.GetExistingOBIDsForDomainAndConfigAndUniquekey(lcolUniqueKeys, Me.TargetDomain.UID, lstrConfig)

'

' If there are existing obid's then use that object

'

If lcolExistingOBIDs.Count > 0 Then

Dim lobjCDWExistingItems As IObjectDictionary = Me.CoreModule.QueryRequest.RunByOBIDCollection(lcolExistingOBIDs(lstrUniqueKey))

If lobjCDWExistingItems.Count > 0 Then

Dim lobjExistingCDWItem As IObject = lobjCDWExistingItems(0)

'

' Perform the mapping

' Call function to update the CDW Object

'

Dim lobjUpdatedItem As IObject = OnUpdateObjectAndMergeWithInputs(lobjExistingCDWItem, pobjCDWObject)

'

' Send back the first item

'

Return lobjExistingCDWItem

End If

End If

End If

'

' Call the mybase code

'

Return MyBase.OnCreateNewObjectAndMergeWithInputs(pobjPublishedItem, pobjExistingCDWItem, pobjCDWObject, pstrCDWUID)

End Function