176176import com .cloud .tags .ResourceTagVO ;
177177import com .cloud .tags .dao .ResourceTagDao ;
178178import com .cloud .template .VirtualMachineTemplate .TemplateFilter ;
179+ import com .cloud .template .VirtualMachineTemplate .State ;
179180import com .cloud .user .Account ;
180181import com .cloud .user .AccountManager ;
181182import com .cloud .user .DomainManager ;
@@ -2716,6 +2717,7 @@ private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(ListTempl
27162717 TemplateFilter templateFilter = TemplateFilter .valueOf (cmd .getTemplateFilter ());
27172718 Long id = cmd .getId ();
27182719 Map <String , String > tags = cmd .getTags ();
2720+ boolean showRemovedTmpl = cmd .getShowRemoved ();
27192721 Account caller = CallContext .current ().getCallingAccount ();
27202722
27212723 boolean listAll = false ;
@@ -2740,12 +2742,12 @@ private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(ListTempl
27402742 HypervisorType hypervisorType = HypervisorType .getType (cmd .getHypervisor ());
27412743
27422744 return searchForTemplatesInternal (id , cmd .getTemplateName (), cmd .getKeyword (), templateFilter , false , null , cmd .getPageSizeVal (), cmd .getStartIndex (),
2743- cmd .getZoneId (), hypervisorType , showDomr , cmd .listInReadyState (), permittedAccounts , caller , listProjectResourcesCriteria , tags );
2745+ cmd .getZoneId (), hypervisorType , showDomr , cmd .listInReadyState (), permittedAccounts , caller , listProjectResourcesCriteria , tags , showRemovedTmpl );
27442746 }
27452747
27462748 private Pair <List <TemplateJoinVO >, Integer > searchForTemplatesInternal (Long templateId , String name , String keyword , TemplateFilter templateFilter , boolean isIso ,
27472749 Boolean bootable , Long pageSize , Long startIndex , Long zoneId , HypervisorType hyperType , boolean showDomr , boolean onlyReady , List <Account > permittedAccounts ,
2748- Account caller , ListProjectResourcesCriteria listProjectResourcesCriteria , Map <String , String > tags ) {
2750+ Account caller , ListProjectResourcesCriteria listProjectResourcesCriteria , Map <String , String > tags , boolean showRemovedTmpl ) {
27492751
27502752 // check if zone is configured, if not, just return empty list
27512753 List <HypervisorType > hypers = null ;
@@ -2964,7 +2966,14 @@ private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(Long temp
29642966 // sc.addAnd("removed", SearchCriteria.Op.NULL);
29652967
29662968 // search unique templates and find details by Ids
2967- Pair <List <TemplateJoinVO >, Integer > uniqueTmplPair = _templateJoinDao .searchAndCount (sc , searchFilter );
2969+ Pair <List <TemplateJoinVO >, Integer > uniqueTmplPair = null ;
2970+ if (showRemovedTmpl ){
2971+ uniqueTmplPair = _templateJoinDao .searchIncludingRemovedAndCount (sc , searchFilter );
2972+ } else {
2973+ sc .addAnd ("templateState" , SearchCriteria .Op .EQ , State .Active );
2974+ uniqueTmplPair = _templateJoinDao .searchAndCount (sc , searchFilter );
2975+ }
2976+
29682977 Integer count = uniqueTmplPair .second ();
29692978 if (count .intValue () == 0 ) {
29702979 // empty result
@@ -2976,7 +2985,7 @@ private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(Long temp
29762985 for (TemplateJoinVO v : uniqueTmpls ) {
29772986 tzIds [i ++] = v .getTempZonePair ();
29782987 }
2979- List <TemplateJoinVO > vrs = _templateJoinDao .searchByTemplateZonePair (tzIds );
2988+ List <TemplateJoinVO > vrs = _templateJoinDao .searchByTemplateZonePair (showRemovedTmpl , tzIds );
29802989 return new Pair <List <TemplateJoinVO >, Integer >(vrs , count );
29812990
29822991 // TODO: revisit the special logic for iso search in
@@ -3000,6 +3009,7 @@ private Pair<List<TemplateJoinVO>, Integer> searchForIsosInternal(ListIsosCmd cm
30003009 TemplateFilter isoFilter = TemplateFilter .valueOf (cmd .getIsoFilter ());
30013010 Long id = cmd .getId ();
30023011 Map <String , String > tags = cmd .getTags ();
3012+ boolean showRemovedISO = cmd .getShowRemoved ();
30033013 Account caller = CallContext .current ().getCallingAccount ();
30043014
30053015 boolean listAll = false ;
@@ -3023,7 +3033,7 @@ private Pair<List<TemplateJoinVO>, Integer> searchForIsosInternal(ListIsosCmd cm
30233033 HypervisorType hypervisorType = HypervisorType .getType (cmd .getHypervisor ());
30243034
30253035 return searchForTemplatesInternal (cmd .getId (), cmd .getIsoName (), cmd .getKeyword (), isoFilter , true , cmd .isBootable (), cmd .getPageSizeVal (), cmd .getStartIndex (),
3026- cmd .getZoneId (), hypervisorType , true , cmd .listInReadyState (), permittedAccounts , caller , listProjectResourcesCriteria , tags );
3036+ cmd .getZoneId (), hypervisorType , true , cmd .listInReadyState (), permittedAccounts , caller , listProjectResourcesCriteria , tags , showRemovedISO );
30273037 }
30283038
30293039 @ Override
0 commit comments