@@ -84,7 +84,6 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
8484 DomainDao _domainDao ;
8585 @ Inject
8686 DataCenterDao _dcDao ;
87-
8887 private final String SELECT_TEMPLATE_HOST_REF = "SELECT t.id, h.data_center_id, t.unique_name, t.name, t.public, t.featured, t.type, t.hvm, t.bits, t.url, t.format, t.created, t.account_id, " +
8988 "t.checksum, t.display_text, t.enable_password, t.guest_os_id, t.bootable, t.prepopulate, t.cross_zones, t.hypervisor_type FROM vm_template t" ;
9089
@@ -93,7 +92,6 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
9392
9493 private final String SELECT_TEMPLATE_SWIFT_REF = "SELECT t.id, t.unique_name, t.name, t.public, t.featured, t.type, t.hvm, t.bits, t.url, t.format, t.created, t.account_id, "
9594 + "t.checksum, t.display_text, t.enable_password, t.guest_os_id, t.bootable, t.prepopulate, t.cross_zones, t.hypervisor_type FROM vm_template t" ;
96-
9795 protected SearchBuilder <VMTemplateVO > TemplateNameSearch ;
9896 protected SearchBuilder <VMTemplateVO > UniqueNameSearch ;
9997 protected SearchBuilder <VMTemplateVO > tmpltTypeSearch ;
@@ -106,6 +104,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
106104 private SearchBuilder <VMTemplateVO > PublicSearch ;
107105 private SearchBuilder <VMTemplateVO > NameAccountIdSearch ;
108106 private SearchBuilder <VMTemplateVO > PublicIsoSearch ;
107+ private SearchBuilder <VMTemplateVO > UserIsoSearch ;
109108 private GenericSearchBuilder <VMTemplateVO , Long > CountTemplatesByAccount ;
110109
111110 ResourceTagsDaoImpl _tagsDao = ComponentLocator .inject (ResourceTagsDaoImpl .class );
@@ -189,6 +188,22 @@ public List<VMTemplateVO> publicIsoSearch(Boolean bootable, boolean listRemoved,
189188 return listBy (sc );
190189 }
191190
191+ @ Override
192+ public List <VMTemplateVO > userIsoSearch (boolean listRemoved ){
193+
194+ SearchBuilder <VMTemplateVO > sb = null ;
195+ sb = UserIsoSearch ;
196+ SearchCriteria <VMTemplateVO > sc = sb .create ();
197+
198+ sc .setParameters ("format" , Storage .ImageFormat .ISO );
199+ sc .setParameters ("type" , TemplateType .USER .toString ());
200+
201+ if (!listRemoved ) {
202+ sc .setParameters ("removed" , (Object )null );
203+ }
204+
205+ return listBy (sc );
206+ }
192207 @ Override
193208 public List <VMTemplateVO > listAllSystemVMTemplates () {
194209 SearchCriteria <VMTemplateVO > sc = tmpltTypeSearch .create ();
@@ -298,7 +313,12 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
298313 PublicIsoSearch .and ("type" , PublicIsoSearch .entity ().getTemplateType (), SearchCriteria .Op .EQ );
299314 PublicIsoSearch .and ("bootable" , PublicIsoSearch .entity ().isBootable (), SearchCriteria .Op .EQ );
300315 PublicIsoSearch .and ("removed" , PublicIsoSearch .entity ().getRemoved (), SearchCriteria .Op .EQ );
301-
316+
317+ UserIsoSearch = createSearchBuilder ();
318+ UserIsoSearch .and ("format" , UserIsoSearch .entity ().getFormat (), SearchCriteria .Op .EQ );
319+ UserIsoSearch .and ("type" , UserIsoSearch .entity ().getTemplateType (), SearchCriteria .Op .EQ );
320+ UserIsoSearch .and ("removed" , UserIsoSearch .entity ().getRemoved (), SearchCriteria .Op .EQ );
321+
302322 tmpltTypeHyperSearch = createSearchBuilder ();
303323 tmpltTypeHyperSearch .and ("templateType" , tmpltTypeHyperSearch .entity ().getTemplateType (), SearchCriteria .Op .EQ );
304324 SearchBuilder <HostVO > hostHyperSearch = _hostDao .createSearchBuilder ();
@@ -648,28 +668,44 @@ public Set<Pair<Long, Long>> searchTemplates(String name, String keyword, Templa
648668
649669 pstmt = txn .prepareStatement (sql );
650670 rs = pstmt .executeQuery ();
671+
651672 while (rs .next ()) {
652- Pair <Long , Long > templateZonePair = new Pair <Long , Long >(rs .getLong (1 ), rs .getLong (2 ));
653- templateZonePairList .add (templateZonePair );
673+ Pair <Long , Long > templateZonePair = new Pair <Long , Long >(rs .getLong (1 ), rs .getLong (2 ));
674+ templateZonePairList .add (templateZonePair );
654675 }
655-
656676 //for now, defaulting pageSize to a large val if null; may need to revisit post 2.2RC2
657677 if (isIso && templateZonePairList .size () < (pageSize != null ? pageSize : 500 )
658- && templateFilter != TemplateFilter .community
678+ && templateFilter != TemplateFilter .community
659679 && !(templateFilter == TemplateFilter .self && !BaseCmd .isRootAdmin (caller .getType ())) ){ //evaluates to true If root admin and filter=self
660- List <VMTemplateVO > publicIsos = publicIsoSearch (bootable , false , tags );
661- for ( int i =0 ; i < publicIsos .size (); i ++){
662- if (keyword != null && publicIsos .get (i ).getName ().contains (keyword )) {
663- templateZonePairList .add (new Pair <Long ,Long >(publicIsos .get (i ).getId (), null ));
664- continue ;
665- } else if (name != null && publicIsos .get (i ).getName ().contains (name )) {
666- templateZonePairList .add (new Pair <Long ,Long >(publicIsos .get (i ).getId (), null ));
667- continue ;
668- }else if (keyword == null && name == null ){
669- templateZonePairList .add (new Pair <Long ,Long >(publicIsos .get (i ).getId (), null ));
680+
681+ List <VMTemplateVO > publicIsos = publicIsoSearch (bootable , false , tags );
682+ List <VMTemplateVO > userIsos = userIsoSearch (false );
683+
684+ //Listing the ISOs according to the page size.Restricting the total no. of ISOs on a page
685+ //to be less than or equal to the pageSize parameter
686+
687+ int i =0 ;
688+
689+ if (startIndex > userIsos .size ()) {
690+ i =(int ) (startIndex - userIsos .size ());
691+ }
692+
693+ for (; i < publicIsos .size (); i ++) {
694+ if (templateZonePairList .size () >= pageSize ){
695+ break ;
696+ } else {
697+ if (keyword != null && publicIsos .get (i ).getName ().contains (keyword )) {
698+ templateZonePairList .add (new Pair <Long ,Long >(publicIsos .get (i ).getId (), null ));
699+ continue ;
700+ } else if (name != null && publicIsos .get (i ).getName ().contains (name )) {
701+ templateZonePairList .add (new Pair <Long ,Long >(publicIsos .get (i ).getId (), null ));
702+ continue ;
703+ } else if (keyword == null && name == null ){
704+ templateZonePairList .add (new Pair <Long ,Long >(publicIsos .get (i ).getId (), null ));
705+ }
706+ }
670707 }
671- }
672- }
708+ }
673709 } catch (Exception e ) {
674710 s_logger .warn ("Error listing templates" , e );
675711 } finally {
0 commit comments