diff --git a/underlay/src/main/java/bio/terra/tanagra/underlay/IndexSchema.java b/underlay/src/main/java/bio/terra/tanagra/underlay/IndexSchema.java index 5a4f5af71..3ef8cd910 100644 --- a/underlay/src/main/java/bio/terra/tanagra/underlay/IndexSchema.java +++ b/underlay/src/main/java/bio/terra/tanagra/underlay/IndexSchema.java @@ -14,10 +14,14 @@ import bio.terra.tanagra.underlay.serialization.SZGroupItems; import bio.terra.tanagra.underlay.serialization.SZUnderlay; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; +import java.util.Optional; import java.util.Set; @SuppressFBWarnings( @@ -25,9 +29,8 @@ justification = "Jackson object mapper writes the POJO fields during deserialization. Need to put this at the class level, because method-level does not handle internal lambdas.") public final class IndexSchema { - // TODO:dexamundsen change list to map - private final ImmutableList entityMainTables; - private final ImmutableList entityLevelDisplayHintTables; + private final ImmutableMap entityMainTables; + private final ImmutableMap entityLevelDisplayHintTables; private final ImmutableList entitySearchByAttributesTables; private final ImmutableList hierarchyChildParentTables; private final ImmutableList hierarchyAncestorDescendantTables; @@ -35,15 +38,15 @@ public final class IndexSchema { private final ImmutableList instanceLevelDisplayHintTables; private IndexSchema( - List entityMainTables, - List entityLevelDisplayHintTables, + Map entityMainTables, + Map entityLevelDisplayHintTables, List entitySearchByAttributesTables, List hierarchyChildParentTables, List hierarchyAncestorDescendantTables, List relationshipIdPairTables, List instanceLevelDisplayHintTables) { - this.entityMainTables = ImmutableList.copyOf(entityMainTables); - this.entityLevelDisplayHintTables = ImmutableList.copyOf(entityLevelDisplayHintTables); + this.entityMainTables = ImmutableMap.copyOf(entityMainTables); + this.entityLevelDisplayHintTables = ImmutableMap.copyOf(entityLevelDisplayHintTables); this.entitySearchByAttributesTables = ImmutableList.copyOf(entitySearchByAttributesTables); this.hierarchyChildParentTables = ImmutableList.copyOf(hierarchyChildParentTables); this.hierarchyAncestorDescendantTables = @@ -53,17 +56,11 @@ private IndexSchema( } public ITEntityMain getEntityMain(String entity) { - return entityMainTables.stream() - .filter(entityMain -> entityMain.getEntity().equals(entity)) - .findFirst() - .orElseThrow(); + return Optional.ofNullable(entityMainTables.get(entity)).orElseThrow(); } public ITEntityLevelDisplayHints getEntityLevelDisplayHints(String entity) { - return entityLevelDisplayHintTables.stream() - .filter(entityLevelDisplayHints -> entityLevelDisplayHints.getEntity().equals(entity)) - .findFirst() - .orElseThrow(); + return Optional.ofNullable(entityLevelDisplayHintTables.get(entity)).orElseThrow(); } public ITEntitySearchByAttributes getEntitySearchByAttributes( @@ -129,8 +126,8 @@ public static IndexSchema fromConfig( SourceSchema sourceSchema) { NameHelper nameHelper = new NameHelper(szBigQuery.indexData.tablePrefix); - List entityMainTables = new ArrayList<>(); - List entityLevelDisplayHintTables = new ArrayList<>(); + Map entityMainTables = new HashMap<>(); + Map entityLevelDisplayHintTables = new HashMap<>(); List entitySearchByAttributesTables = new ArrayList<>(); List hierarchyChildParentTables = new ArrayList<>(); List hierarchyAncestorDescendantTables = new ArrayList<>(); @@ -189,8 +186,8 @@ private static void fromConfigEntity( ConfigReader configReader, NameHelper nameHelper, SZBigQuery.IndexData szBigQueryIndexData, - List entityMainTables, - List entityLevelDisplayHintTables, + Map entityMainTables, + Map entityLevelDisplayHintTables, List entitySearchByAttributesTables, List hierarchyChildParentTables, List hierarchyAncestorDescendantTables) { @@ -213,7 +210,8 @@ private static void fromConfigEntity( entityGroupsWithCount.add(szCriteriaOccurrence.name); } }); - entityMainTables.add( + entityMainTables.put( + szEntity.name, new ITEntityMain( nameHelper, szBigQueryIndexData, @@ -224,7 +222,8 @@ private static void fromConfigEntity( entityGroupsWithCount)); // EntityLevelDisplayHints table. - entityLevelDisplayHintTables.add( + entityLevelDisplayHintTables.put( + szEntity.name, new ITEntityLevelDisplayHints(nameHelper, szBigQueryIndexData, szEntity.name)); // EntitySearchByAttribute tables.