@@ -3508,29 +3508,7 @@ else if (!template.isPublicTemplate() && caller.getType() != Account.ACCOUNT_TYP
35083508 }
35093509 }
35103510
3511- Integer count = uniqueTmplPair .second ();
3512- if (count .intValue () == 0 ) {
3513- // empty result
3514- return uniqueTmplPair ;
3515- }
3516- List <TemplateJoinVO > uniqueTmpls = uniqueTmplPair .first ();
3517- int i = 0 ;
3518- List <TemplateJoinVO > vrs = null ;
3519- if (showUnique ) {
3520- Long [] tzIds = new Long [uniqueTmpls .size ()];
3521- for (TemplateJoinVO v : uniqueTmpls ) {
3522- tzIds [i ++] = v .getId ();
3523- }
3524- vrs = _templateJoinDao .findByDistinctIds (tzIds );
3525- } else {
3526- String [] tzIds = new String [uniqueTmpls .size ()];
3527- for (TemplateJoinVO v : uniqueTmpls ) {
3528- tzIds [i ++] = v .getTempZonePair ();
3529- }
3530- vrs = _templateJoinDao .searchByTemplateZonePair (showRemovedTmpl , tzIds );
3531- }
3532-
3533- return new Pair <List <TemplateJoinVO >, Integer >(vrs , count );
3511+ return findTemplatesByIdOrTempZonePair (uniqueTmplPair , showRemovedTmpl , showUnique );
35343512
35353513 // TODO: revisit the special logic for iso search in
35363514 // VMTemplateDaoImpl.searchForTemplates and understand why we need to
@@ -3539,6 +3517,25 @@ else if (!template.isPublicTemplate() && caller.getType() != Account.ACCOUNT_TYP
35393517
35403518 }
35413519
3520+ // findTemplatesByIdOrTempZonePair returns the templates with the given ids if showUnique is true, or else by the TempZonePair
3521+ private Pair <List <TemplateJoinVO >, Integer > findTemplatesByIdOrTempZonePair (Pair <List <TemplateJoinVO >, Integer > templateDataPair , boolean showRemoved , boolean showUnique ) {
3522+ Integer count = templateDataPair .second ();
3523+ if (count .intValue () == 0 ) {
3524+ // empty result
3525+ return templateDataPair ;
3526+ }
3527+ List <TemplateJoinVO > templateData = templateDataPair .first ();
3528+ List <TemplateJoinVO > templates = null ;
3529+ if (showUnique ) {
3530+ Long [] templateIds = templateData .stream ().map (template -> template .getId ()).toArray (Long []::new );
3531+ templates = _templateJoinDao .findByDistinctIds (templateIds );
3532+ } else {
3533+ String [] templateZonePairs = templateData .stream ().map (template -> template .getTempZonePair ()).toArray (String []::new );
3534+ templates = _templateJoinDao .searchByTemplateZonePair (showRemoved , templateZonePairs );
3535+ }
3536+ return new Pair <List <TemplateJoinVO >, Integer >(templates , count );
3537+ }
3538+
35423539 @ Override
35433540 public ListResponse <TemplateResponse > listIsos (ListIsosCmd cmd ) {
35443541 Pair <List <TemplateJoinVO >, Integer > result = searchForIsosInternal (cmd );
0 commit comments