The following code sample demonstrates adding, deleting and modifying attribute joint child relationships using the Strategy COM SDK 9.5.0 in C#.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DSSCOMMasterLib;
namespace TestJointChildRel
{
class Program
{
// Constants for connecting to the intelligence server
const string hostname = "SERVER-NAME";
const string projectname = "Strategy Tutorial";
const string login = "administrator";
const string pass = "";
static void Main(string[] args)
{
IDSSSource ObjSource;
IDSSSession ServerSession;
// Establish a session with the intelligence server
ServerSession = Create_Session(hostname, "com", "com", projectname);
ObjSource = ServerSession.ObjectSource;
// Trigger main method to add joint relationships
TestReadAddJointChildRelationships(ref ObjSource);
// Close session
ServerSession.Close();
}
private static void TestReadAddJointChildRelationships(ref IDSSSource ObjSource)
{
try
{
// Get the parent attribute
IDSSAttribute Customer = getAttributeObj(ref ObjSource, "Customer");
ListRelationships(ref Customer);
IDSSAttribute Customer1 = getAttributeObj(ref ObjSource, "Customer1");
ListRelationships(ref Customer1);
IDSSAttribute Customer2 = getAttributeObj(ref ObjSource, "Customer2");
ListRelationships(ref Customer2);
IDSSAttribute Customer3 = getAttributeObj(ref ObjSource, "Customer3");
ListRelationships(ref Customer3);
IDSSAttribute objParentAttr = getAttributeObj(ref ObjSource, "Customer3");
IDSSTable guide_table = getTableObj(ref ObjSource, "ORDER_FACT");
// Find new attribute objects to work with
IDSSAttribute add1 = getAttributeObj(ref ObjSource, "Supplier");
IDSSAttribute add2 = getAttributeObj(ref ObjSource, "Order");
IDSSAttribute add3 = getAttributeObj(ref ObjSource, "Ship Date");
if (objParentAttr == null || add1 == null || add2 == null || add3 == null)
{
System.Diagnostics.Trace.WriteLine("No such Object: ");
return;
}
System.Diagnostics.Trace.WriteLine("\nAttribute: " + objParentAttr.Info.Name + ", ID: " + objParentAttr.Info.ID);
// Print the attribute initial relationships
ListRelationships(ref objParentAttr);
// Remove all existing relationships
DeleteAllRelationships(ref objParentAttr, ref ObjSource);
// Print the attribute initial relationships
ListRelationships(ref objParentAttr);
// Test, add a relationship with two attributes (joint child relationship)
objParentAttr = AddJoinRel(ObjSource, objParentAttr, guide_table, add2, add3);
System.Diagnostics.Trace.WriteLine("After add two (attribute array): ");
ListRelationships(ref objParentAttr);
}
catch (System.Exception e)
{
Console.WriteLine("Exception: " + e.Message);
System.Diagnostics.Trace.WriteLine("Exception: " + e.Message);
}
}
private static IDSSAttribute AddJoinRel(IDSSSource ObjSource, IDSSAttribute objParentAttr, IDSSTable guide_table, IDSSAttribute add2, IDSSAttribute add3)
{
// Allocate array of 2 attributes to path to new relationship
Object[] attributes = new Object[2];
attributes[0] = add2;
attributes[1] = add3;
// Based on the 4'th option, passing an array with two attributes
try
{
IDSSAttributeRelationship newRel = objParentAttr.Children.Add(attributes);
if (newRel != null)
{
newRel.HasRelationship = true;
var rel = newRel.Relationship;
if (rel != null)
{
rel.ERType = EnumDSSERType.DssERType1M;
rel.RelationshipType = EnumDSSExtnType.DssExtnTypeTable;
rel.JoinType = EnumDSSJoinType.DssJoinTypeDirect;
rel.PartialType = EnumDSSPartialType.DssPartialTypeFF;
if (guide_table != null)
rel.Guide = (IDSSObjectInfo)guide_table;
}
// Save parent attribute object...
objParentAttr.Info.Save();
IDSSObjectInfo ppCurrent;
ObjSource.SaveObject(objParentAttr.Info, objParentAttr.Info.Parent, EnumDSSSourceFlags.DssSourceTotalObject | EnumDSSSourceFlags.DssSourceSaveOverwrite, null, 0, 0, out ppCurrent);
// Save Children attribute
ObjSource.SaveObject(add2.Info, add2.Info.Parent, EnumDSSSourceFlags.DssSourceTotalObject | EnumDSSSourceFlags.DssSourceSaveOverwrite, null, 0, 0, out ppCurrent);
ObjSource.SaveObject(add3.Info, add3.Info.Parent, EnumDSSSourceFlags.DssSourceTotalObject | EnumDSSSourceFlags.DssSourceSaveOverwrite, null, 0, 0, out ppCurrent);
ObjSource.SaveObject(ObjSource.Schema.SystemDimension.Info, ObjSource.Schema.SystemDimension.Info.Parent, EnumDSSSourceFlags.DssSourceSaveOverwrite, null, 0, 0, out ppCurrent);
ObjSource.Schema.Info.Save();
}
}
catch (System.Exception e)
{
System.Diagnostics.Trace.WriteLine("Exception: " + e.Message);
}
System.Diagnostics.Trace.WriteLine("Done");
return objParentAttr;
}
private static void ListRelationships(ref IDSSAttribute oAttribute)
{
try
{
System.Diagnostics.Trace.WriteLine("\nAttribute: " + oAttribute.Info.Name);
System.Diagnostics.Trace.WriteLine("--------------------------" );
System.Diagnostics.Trace.WriteLine("Number of relationships: " + oAttribute.Children.Count());
for (int i = 1; i <= oAttribute.Children.Count(); ++i)
{
IDSSAttributeRelationship oChild = oAttribute.Children.Item(i); //
System.Diagnostics.Trace.WriteLine("IDSSAttributeRelationship " + i + ":\n");
System.Diagnostics.Trace.WriteLine("\tRelation count " + oChild.Count() +
"\n\tHasRelationship: " + oChild.HasRelationship );
IDSSRelationship rel = oChild.Relationship;
if (rel != null)
{
System.Diagnostics.Trace.WriteLine("\tIDSSRelationship: " +
"\n\t\tERType: " + rel.ERType.ToString() +
"\n\t\tRelationshipType: " + rel.RelationshipType.ToString() +
"\n\t\tJoinType: " + rel.JoinType.ToString() +
"\n\t\tPartialType: " + rel.PartialType.ToString());
if (rel.Guide != null)
System.Diagnostics.Trace.WriteLine("\t\tGuide: " + rel.Guide.Name);
}
// ElementsCollection
// Child attribute or a joint child attributes
for (int j = 1; j <= oChild.Count(); ++j)
{
Console.WriteLine("Child Name: " + oChild.Item(j).Info.Name);
System.Diagnostics.Trace.WriteLine("Child Name: " + oChild.Item(j).Info.Name);
};
// Relationship table
if (oChild.HasRelationship && oChild.Relationship.Guide!=null)
{
Console.WriteLine("Relationship table: " + oChild.Relationship.Guide.Name);
System.Diagnostics.Trace.WriteLine("Relationship table: " + oChild.Relationship.Guide.Name);
}
else
Console.WriteLine("No Relationship table ");
}
}
catch (System.Exception e)
{
System.Diagnostics.Trace.WriteLine(e.Message);
}
}
private static void DeleteAllRelationships(ref IDSSAttribute objParentAttr, ref IDSSSource ObjSource)
{
System.Diagnostics.Trace.WriteLine("Delete All relationships: Number of relationships: " + objParentAttr.Children.Count());
// Retrieve relationships from objParentAttr
int n = objParentAttr.Children.Count();
for (int i = n; i > 0; --i)
{
// Individually delete each relationship
System.Diagnostics.Trace.WriteLine("Delete relationship " + i);
IDSSAttributeRelationship oChild = objParentAttr.Children.Item(i); //
object o = (object)oChild;
objParentAttr.Children.Remove(oChild);
}
// Retrieve number of relationships left
int ii = objParentAttr.Children.Count();
// Save changes to object and source
objParentAttr.Info.Save();
IDSSObjectInfo objInfo=null;
ObjSource.SaveObject(objParentAttr.Info, objParentAttr.Info.Parent,
EnumDSSSourceFlags.DssSourceTotalObject | EnumDSSSourceFlags.DssSourceSaveOverwrite
, null, 0, 0, out objInfo);
ObjSource.SaveObject(ObjSource.Schema.SystemDimension.Info, ObjSource.Schema.SystemDimension.Info.Parent, EnumDSSSourceFlags.DssSourceSaveOverwrite, null, 0, 0, out objInfo);
ObjSource.Schema.Info.Save();
}
// Retrieve IDSSAttribute using attribute name and ObjSource
private static IDSSAttribute getAttributeObj(ref IDSSSource ObjSource, string name)
{
IDSSAttribute attr = null;
IDSSFolder folder = FindObjectByName(ref ObjSource, EnumDSSObjectType.DssTypeAttribute, name);
if (folder.Count() > 0)
{
//objInfo1 = (folder.Item(1));
attr = (IDSSAttribute)(folder.Item(1));
}
return attr;
}
// Retrieve IDSSTable using name and ObjSource
private static IDSSTable getTableObj(ref IDSSSource ObjSource, string name)
{
IDSSTable attr = null;
IDSSFolder folder = FindObjectByName(ref ObjSource, EnumDSSObjectType.DssTypeTable, name);
if (folder.Count() > 0)
{
//objInfo1 = (folder.Item(1));
attr = (IDSSTable)(folder.Item(1));
}
return attr;
}
// Establish a session with intelligence server
private static IDSSSession Create_Session(String ServerName, String UserName, String Password, String ProjName)
{
IDSSSession ServerSession;
DSSDataSource ProjSource;
IDSSDataSource ConnectProject;
IDSSDataSourceEnumerator ProjList;
int ps = 0;
ProjSource = new DSSDataSource();
ProjSource.Type = EnumDSSDataSourceType.DssDataSourceTypeServer;
ProjSource.Location = hostname;
ProjSource.Mode = EnumDSSConnectionMode.DssConnectionModeServerAccess;
ProjSource.AuthMode = EnumDSSAuthModes.DssAuthStandard;
ProjSource.login = login;
ProjSource.Passwd = pass;
ProjSource.Init();
ProjList = ProjSource.Enumerator;
ConnectProject = ProjList.ItemByProjectName(ProjName, out ps);
ConnectProject.Init();
ServerSession = ConnectProject.CreateSession();
return ServerSession;
}
// Search for object of specific type using name
private static IDSSFolder FindObjectByName(ref IDSSSource ObjSource, EnumDSSObjectType enumType, string strName)
{
// creating search object
IDSSSearch objSearch = (IDSSSearch)ObjSource.NewObject(EnumDSSObjectType.DssTypeSearch);
// Setting search type for the specific object type and object name pattern
objSearch.Types.Add(enumType);
objSearch.NamePattern = strName;
// obtaining the search results
IDSSFolder objObjectsFound = objSearch.Execute();
return objObjectsFound;
}
}
}
PREREQUISITES:
For the sample to work, the Strategy Web JAR files must be accessible by the Java Runtime
Environment. The Strategy Web JAR files can be found under:
Note:
More elaborate programs will require additional library files and are out of the scope of this document.
ADDITIONAL INFORMATION:
The Strategy SDK allows you to customize the standard Strategy Web interface, and extend and integrate the Strategy business intelligence functionality into other applications. However, before changing the way Strategy Web products look or behave, it is helpful to understand how the application is built. For more information regarding the Strategy Web architecture or the process of customizing Strategy Web, please refer to Strategy Developer Zone (https://community.strategy.com/topic/0TO44000000FliLGAS/sdk).
To access the Strategy Developer Zone, you must have access to the Strategy Knowledge Base, you must have purchased the Strategy SDK, and you must be current on your Strategy maintenance agreement. If you are a US-based business and believe that you satisfy all three of these conditions but you do not have access to the Strategy Developer Zone, please contact Strategy Technical Support at support@microstrategy.com or at (703) 848-8700. If you are an international business, please contact Strategy Technical Support at the appropriate email address or phone number found at https://www.microstrategy.com/en/support/contact-support.
CUSTOMIZATION WARNING:
This customization is provided as a convenience to Strategy users and is only directly applicable to the version stated. While this code may apply to other releases directly, Strategy Technical Support makes no guarantees that the code provided will apply to any future or previous builds. In the event of a code change in future builds, Strategy Technical Support makes no guarantee that an updated version of this particular customization will be provided. In the event of a code change in future builds, Strategy may not be able to provide additional code on this matter even though this customization is provided at this time for this specific build. For enhancements to this customization or to incorporate similar functionality into other versions, contact your Account Executive to inquire about Strategy Consulting assistance.
252603