Operating system requirements: iOS 5.0 or later.
Mobile device: iPad.
This example describes some methods of working with data source dimension elements. After starting the example the following operations are executed:
Selected dimension elements are retrieved.
Element tree and array of selected dimension element keys are retrieved.
New dimension elements are created based on the obtained tree.
Text description of dimension elements is retrieved.
One of the dimension elements is retrieved by means of the key obtained from array of element keys.
Name, description, hash code, key, parent element and parent element key are retrieved for selected element.
Linked dimension of selected element is retrieved.
Identifier and value of one of the element attributes are retrieved by means of the attribute name obtained from array of linked dimension attributes.
Executing the example requires to place the following code instead of the executeExample method of the ViewController class (see the Data Analysis section):
-(void)executeExample { // Get array of cube dimensions SNArray allDimensions = [self allDimensions]; // Get cube dimension with the index in array SPPLDimension dimension = allDimensions->objectAtIndex<PPLDimension>(1); // Get current dimension elements SPPLDimensionElements dimensionElements = dimension->elements(); // Get dimension element tree SPPLCommonTree dimensionElementsItemsTree = dimensionElements->itemsTree(); // Create a new dimension element object based on obtained tree SPPLDimensionElements createdElements = new PPLDimensionElements(dimensionElementsItemsTree); // Get description of dimension elements SNString elementsDescription = createdElements->description(); printf("Description of dimension elements:\n%s\n", elementsDescription->UTF8String()); // Get array of all dimension element keys SNInt64Array elementsItemsKeys = createdElements->itemsKeys(); // Get element key with the index 0 int64 elementKey = elementsItemsKeys->objectAtIndex(0); // Get dimension element by key SPPLDimensionElement baseElement = createdElements->getElementByKey(elementKey); SPPLDimensionElement element = new PPLDimensionElement::PPLDimensionElement(dimensionElementDescription(baseElement), baseElement->relatedDimension()); // Get selected element name printf("Dimension element: %s\n", baseElement->name()->UTF8String()); printf("Element description:\n%s\n", baseElement->description()->UTF8String()); printf("Dimension element hash code: %d\n", baseElement->hash()); printf("Dimension element key: %lld\n", element->key()); // Get parent element SPPLDimensionElement parentElement = createdElements->getParentElement(element); if(parentElement != NULL) { printf("Parent element: %s\n", parentElement->name()->UTF8String()); } else printf("Parent element is missing\n"); // Get parent element key printf("Parent element key: %lld\n", element->parentKey()); // Get linked element dimension printf("Linked dimension: %s\n", baseElement->relatedDimension()->name()->UTF8String()); // Get selected dimension attributes SPPLDimensionAttributes attributes = baseElement->relatedDimension()->attributes(); // Get array of attributes SNArray attributesArray = attributes->items(); if (attributesArray->count() > 0) { // Get attribute with the index 0 SPPLDimensionAttribute attribute = attributesArray->objectAtIndex<PPLDimensionAttribute>(0); printf("Linked dimension attribute: %s\n", attribute->name()->UTF8String()); // Get element attribute identifier by attribute name SNID valueId = baseElement->valueByAttributeName(attribute->name()); if (valueId != NULL) { // Get element attribute by attribute name NSmartPtr<NNumber> value = baseElement->valueByAttributeName<NNumber>(attribute->name()); printf("Element attribute identifier: %s\n", valueId->description()->UTF8String()); printf("Element attribute value: %d\n", value->integerValue()); } } } // Returns dictionary with settings of specified dimension element SNDictionary dimensionElementDescription(SPPLDimensionElement element) { SNMutableDictionary dimensionElementDescription = NMutableDictionary::mutableDictionary(); SPPLDimensionTableInfo tableInfo = element->relatedDimension()->tableInfo(); dimensionElementDescription->setObjectForKey(NNumber::numberWithLongLong(element->key()), tableInfo->primaryKey()); dimensionElementDescription->setObjectForKey(NNumber::numberWithLongLong(element->parentKey()), tableInfo->parentKey()); return dimensionElementDescription; }
After executing the example the development environment console displays description of dimension elements, information about selected dimension element, information about linked element dimension, and also identifier and values of selected element attribute:
Description of dimension elements:
Elements count: 173
Dimension element: World
Element description:
World ,(1, parent: 0)
Dimension element hash code: 1
Dimension element key: 1
Parent element is missing
Parent element key: 0
Linked dimension: Regions
Linked dimension attribute: TOPO_ID
Element attribute identifier: <NNumber:318106>
Element attribute value: 318106
See also: