public class DynaAdminHierarchyInfo extends java.lang.Object implements HierarchyInfo
An implementation of HierarchyInfo that can be configured to represent a hierarchy structure using the MVSuggest administrative boundary catalogs.
Before setting this class to the job configuration's ConfigParams.HIERARCHY_INFO_CLASS property, an instance should be created and configured with the desired structure.
The following example illustrates how a hierarchy structure for a three-level world admin boundaries is created.
//create a new instance
DynaAdminHierarchyInfo dahi = new DynaAdminHierarchyInfo();
//add hierarchy levels to the instance
dahi.addLevel(1, "world_continents", "_id", null);//wolrd continents are related to their children by their "_id" field and do not need a field to join with their parents since it is the hierarchy's top level
dahi.addLevel(2, "world_countries", "properties.COUNTRY CODE", "properties.CONTINENT");//countries are related to their children by the field "properties.COUNTRY CODE" and to their parents by the field "properties.CONTINENT"
dahi.addLevel(3, "world_states_provinces", null, "properties.ISO");//states & provinces only need to know how to find their parents (field "properties.ISO") and do not have children as there are no more levels below
//call initialize to save the hierarchy configuration in the job configuration
dahi.initialize(conf);//conf is a job configuration
UNDEFINED_PARENT_ID| Constructor and Description |
|---|
DynaAdminHierarchyInfo()
Creates a new empty instance
|
| Modifier and Type | Method and Description |
|---|---|
void |
addLevel(int level, java.lang.String name, java.lang.String childrenJoinField, java.lang.String parentJoinField)
Adds a level to the hierarchy.
|
java.util.Collection<java.lang.String> |
getEntriesIds(int level)
Gets the ids of all the elements in the given hierarchy level
|
JGeometry |
getEntryGeometry(int level, java.lang.String entryId)
Gets the geometry of the specified entry in the given hierarchy level
|
java.lang.String |
getLevelName(int level)
Gets the name which identifies the given hierarchy level number.
|
int |
getLevelNumber(java.lang.String levelName)
Gets the number of the hierarchy level identified by the given name
|
int |
getNumberOfLevels()
Gets the total number of hierarchy levels
|
java.lang.String |
getParentId(int childLevel, java.lang.String childId)
Gets the id of the parent of the given entry
|
void |
initialize(Configuration conf)
This method is called always once a new instance is created.
|
void |
load(Path[] hierDataPaths, int fromLevel, JobConf conf)
Loads the hierarchical catalog content from the given paths.
|
void |
loadFromIndex(HierarchyDataIndexReader[] readers, int fromLevel, Configuration conf)
Loads the hierarchical catalog content from previously generated indices.
|
public DynaAdminHierarchyInfo()
public void addLevel(int level,
java.lang.String name,
java.lang.String childrenJoinField,
java.lang.String parentJoinField)
level - the hierarchy level number.name - the hierarchy level namechildrenJoinField - the path to the JSON field used to associate entries of this level with their children. If null is passed, the _id field will be used by default.parentJoinField - the path to the JSON field used to associate entries of this level with their parent. If null is passed, parents will be searched performing a Within spatial operation between the current record's geometry and the upper level entries geometries until one satisfies the operation.public java.util.Collection<java.lang.String> getEntriesIds(int level)
HierarchyInfogetEntriesIds in interface HierarchyInfolevel - a hierarchy level number: a number between 1 and the number of hierarchy levels
public JGeometry getEntryGeometry(int level,
java.lang.String entryId)
HierarchyInfogetEntryGeometry in interface HierarchyInfolevel - the hierarchy level of the entryentryId - the id of the entrypublic java.lang.String getLevelName(int level)
HierarchyInfogetLevelName in interface HierarchyInfolevel - a hierarchy level number: a number between 1 and the number of hierarchy levelspublic int getLevelNumber(java.lang.String levelName)
HierarchyInfogetLevelNumber in interface HierarchyInfolevelName - a hierarchy level namepublic int getNumberOfLevels()
HierarchyInfogetNumberOfLevels in interface HierarchyInfo
public java.lang.String getParentId(int childLevel,
java.lang.String childId)
HierarchyInfogetParentId in interface HierarchyInfochildLevel - the hierarchy level where the child entry belongs tochildId - the child idpublic void initialize(Configuration conf)
HierarchyInfoinitialize in interface HierarchyInfoconf - a configuration instance
public void load(Path[] hierDataPaths,
int fromLevel,
JobConf conf)
throws java.lang.Exception
HierarchyInfoload in interface HierarchyInfohierDataPaths - an array containing paths for each hierarchy level that needs to be loaded. The hierarchy levels to be loaded are determined by the paths array length and the value of fromLevel parameter. The array's length is inside the range: 1 <= length <= number of hierarchies. The paths are ordered by its hierarchy level in ascending way. The path in the array corresponds to the hierarchy level number resulting of adding the element index to the value of the fromLevel parameter (i + fromLevel). For example: for a hierarchy with 10 levels, load from level 6 to 10. In this case, the path array will contain 5 elements and fromValue will be 6. If the 10 levels need to be loaded, the path array length must be 10 and fromValue must be 1.fromLevel - specifies the hierarchy level from which the hierarchy levels must be loaded. The value is in the range 1<= fromLevel <= number of hierarchies.conf - the job configurationjava.lang.Exceptionpublic void loadFromIndex(HierarchyDataIndexReader[] readers, int fromLevel, Configuration conf) throws java.lang.Exception
HierarchyInfoloadFromIndex in interface HierarchyInforeaders - an array of HierarchyDataIndexReader. The readers are sorted by hierarchy level in ascending order. The top hierarchy level is determined by the value of fromLevel.fromLevel - specifies the hierarchy level from which the hierarchy levels must be loaded. The value is in the range 1<= fromLevel <= number of hierarchies.conf - the job configurationjava.lang.ExceptionCopyright © 2016 Oracle and/or its affiliates. All Rights Reserved.