@@ -2683,6 +2683,7 @@ private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(ListTempl
26832683 TemplateFilter templateFilter = TemplateFilter .valueOf (cmd .getTemplateFilter ());
26842684 Long id = cmd .getId ();
26852685 Map <String , String > tags = cmd .getTags ();
2686+ boolean showRemovedTmpl = cmd .getShowRemoved ();
26862687 Account caller = UserContext .current ().getCaller ();
26872688
26882689 boolean listAll = false ;
@@ -2710,14 +2711,14 @@ private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(ListTempl
27102711
27112712 return searchForTemplatesInternal (id , cmd .getTemplateName (), cmd .getKeyword (), templateFilter , false , null ,
27122713 cmd .getPageSizeVal (), cmd .getStartIndex (), cmd .getZoneId (), hypervisorType , showDomr ,
2713- cmd .listInReadyState (), permittedAccounts , caller , listProjectResourcesCriteria , tags );
2714+ cmd .listInReadyState (), permittedAccounts , caller , listProjectResourcesCriteria , tags , showRemovedTmpl );
27142715 }
27152716
27162717 private Pair <List <TemplateJoinVO >, Integer > searchForTemplatesInternal (Long templateId , String name ,
27172718 String keyword , TemplateFilter templateFilter , boolean isIso , Boolean bootable , Long pageSize ,
27182719 Long startIndex , Long zoneId , HypervisorType hyperType , boolean showDomr , boolean onlyReady ,
27192720 List <Account > permittedAccounts , Account caller , ListProjectResourcesCriteria listProjectResourcesCriteria ,
2720- Map <String , String > tags ) {
2721+ Map <String , String > tags , boolean showRemovedTmpl ) {
27212722
27222723 // check if zone is configured, if not, just return empty list
27232724 List <HypervisorType > hypers = null ;
@@ -2740,7 +2741,11 @@ private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(Long temp
27402741
27412742 // verify templateId parameter and specially handle it
27422743 if (templateId != null ) {
2743- template = _templateDao .findById (templateId );
2744+ if (showRemovedTmpl ){
2745+ template = _templateDao .findByIdIncludingRemoved (templateId );
2746+ }else {
2747+ template = _templateDao .findById (templateId );
2748+ }
27442749 if (template == null ) {
27452750 throw new InvalidParameterValueException ("Please specify a valid template ID." );
27462751 }// If ISO requested then it should be ISO.
@@ -2758,6 +2763,10 @@ private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(Long temp
27582763 ex .addProxyObject (template .getUuid (), "templateId" );
27592764 throw ex ;
27602765 }
2766+ if ((template == null ) || ((template .getRemoved () != null ) && !showRemovedTmpl )){ // If template is removed and showRemoved flag not turned -> throw exception. findbyId returns removed template as well above.
2767+ s_logger .error ("Please specify a valid template ID, template " + template .getUuid () + " is removed" );
2768+ throw new InvalidParameterValueException ("Please specify a valid template ID " + template .getUuid ());
2769+ }
27612770
27622771 // if template is not public, perform permission check here
27632772 if (!template .isPublicTemplate () && caller .getType () != Account .ACCOUNT_TYPE_ADMIN ) {
@@ -2940,6 +2949,9 @@ private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(Long temp
29402949 // don't return removed template, this should not be needed since we
29412950 // changed annotation for removed field in TemplateJoinVO.
29422951 // sc.addAnd("removed", SearchCriteria.Op.NULL);
2952+ if (!showRemovedTmpl ){
2953+ sc .addAnd ("removed" , SearchCriteria .Op .NULL );
2954+ }
29432955
29442956 // search unique templates and find details by Ids
29452957 Pair <List <TemplateJoinVO >, Integer > uniqueTmplPair = _templateJoinDao .searchAndCount (sc , searchFilter );
@@ -2979,6 +2991,7 @@ private Pair<List<TemplateJoinVO>, Integer> searchForIsosInternal(ListIsosCmd cm
29792991 TemplateFilter isoFilter = TemplateFilter .valueOf (cmd .getIsoFilter ());
29802992 Long id = cmd .getId ();
29812993 Map <String , String > tags = cmd .getTags ();
2994+ boolean showRemovedIso = cmd .getShowRemoved ();
29822995 Account caller = UserContext .current ().getCaller ();
29832996
29842997 boolean listAll = false ;
@@ -3005,7 +3018,7 @@ private Pair<List<TemplateJoinVO>, Integer> searchForIsosInternal(ListIsosCmd cm
30053018
30063019 return searchForTemplatesInternal (cmd .getId (), cmd .getIsoName (), cmd .getKeyword (), isoFilter , true ,
30073020 cmd .isBootable (), cmd .getPageSizeVal (), cmd .getStartIndex (), cmd .getZoneId (), hypervisorType , true ,
3008- cmd .listInReadyState (), permittedAccounts , caller , listProjectResourcesCriteria , tags );
3021+ cmd .listInReadyState (), permittedAccounts , caller , listProjectResourcesCriteria , tags , showRemovedIso );
30093022 }
30103023
30113024 @ Override
0 commit comments