@@ -3426,29 +3426,7 @@ else if (!template.isPublicTemplate() && caller.getType() != Account.ACCOUNT_TYP
34263426 }
34273427 }
34283428
3429- Integer count = uniqueTmplPair .second ();
3430- if (count .intValue () == 0 ) {
3431- // empty result
3432- return uniqueTmplPair ;
3433- }
3434- List <TemplateJoinVO > uniqueTmpls = uniqueTmplPair .first ();
3435- int i = 0 ;
3436- List <TemplateJoinVO > vrs = null ;
3437- if (showUnique ) {
3438- Long [] tzIds = new Long [uniqueTmpls .size ()];
3439- for (TemplateJoinVO v : uniqueTmpls ) {
3440- tzIds [i ++] = v .getId ();
3441- }
3442- vrs = _templateJoinDao .findByDistinctIds (tzIds );
3443- } else {
3444- String [] tzIds = new String [uniqueTmpls .size ()];
3445- for (TemplateJoinVO v : uniqueTmpls ) {
3446- tzIds [i ++] = v .getTempZonePair ();
3447- }
3448- vrs = _templateJoinDao .searchByTemplateZonePair (showRemovedTmpl , tzIds );
3449- }
3450-
3451- return new Pair <List <TemplateJoinVO >, Integer >(vrs , count );
3429+ return findTemplatesByIdOrTempZonePair (uniqueTmplPair , showRemovedTmpl , showUnique );
34523430
34533431 // TODO: revisit the special logic for iso search in
34543432 // VMTemplateDaoImpl.searchForTemplates and understand why we need to
@@ -3457,6 +3435,25 @@ else if (!template.isPublicTemplate() && caller.getType() != Account.ACCOUNT_TYP
34573435
34583436 }
34593437
3438+ // findTemplatesByIdOrTempZonePair returns the templates with the given ids if showUnique is true, or else by the TempZonePair
3439+ private Pair <List <TemplateJoinVO >, Integer > findTemplatesByIdOrTempZonePair (Pair <List <TemplateJoinVO >, Integer > templateDataPair , boolean showRemoved , boolean showUnique ) {
3440+ Integer count = templateDataPair .second ();
3441+ if (count .intValue () == 0 ) {
3442+ // empty result
3443+ return templateDataPair ;
3444+ }
3445+ List <TemplateJoinVO > templateData = templateDataPair .first ();
3446+ List <TemplateJoinVO > templates = null ;
3447+ if (showUnique ) {
3448+ Long [] templateIds = templateData .stream ().map (template -> template .getId ()).toArray (Long []::new );
3449+ templates = _templateJoinDao .findByDistinctIds (templateIds );
3450+ } else {
3451+ String [] templateZonePairs = templateData .stream ().map (template -> template .getTempZonePair ()).toArray (String []::new );
3452+ templates = _templateJoinDao .searchByTemplateZonePair (showRemoved , templateZonePairs );
3453+ }
3454+ return new Pair <List <TemplateJoinVO >, Integer >(templates , templateDataPair .second ());
3455+ }
3456+
34603457 @ Override
34613458 public ListResponse <TemplateResponse > listIsos (ListIsosCmd cmd ) {
34623459 Pair <List <TemplateJoinVO >, Integer > result = searchForIsosInternal (cmd );
0 commit comments