@@ -1941,7 +1941,7 @@ private Pair<List<DiskOfferingJoinVO>, Integer> searchForDiskOfferingsInternal(L
19411941 Boolean isAscending = Boolean .parseBoolean (_configDao .getValue ("sortkey.algorithm" ));
19421942 isAscending = (isAscending == null ? true : isAscending );
19431943 Filter searchFilter = new Filter (DiskOfferingJoinVO .class , "sortKey" , isAscending , cmd .getStartIndex (), cmd .getPageSizeVal ());
1944- SearchBuilder <DiskOfferingJoinVO > sb = _diskOfferingJoinDao .createSearchBuilder ();
1944+ SearchCriteria <DiskOfferingJoinVO > sc = _diskOfferingJoinDao .createSearchCriteria ();
19451945
19461946
19471947 Account account = UserContext .current ().getCaller ();
@@ -1956,21 +1956,15 @@ private Pair<List<DiskOfferingJoinVO>, Integer> searchForDiskOfferingsInternal(L
19561956 if (account .getType () == Account .ACCOUNT_TYPE_ADMIN || isPermissible (account .getDomainId (), domainId ) ) {
19571957 // check if the user's domain == do's domain || user's domain is
19581958 // a child of so's domain for non-root users
1959- sb .and ("domainId" , sb .entity ().getDomainId (), SearchCriteria .Op .EQ );
1960- SearchCriteria <DiskOfferingJoinVO > sc = sb .create ();
1961- sc .setParameters ("domainId" , domainId );
1959+ sc .addAnd ("domainId" , SearchCriteria .Op .EQ , domainId );
19621960 return _diskOfferingJoinDao .searchAndCount (sc , searchFilter );
19631961 } else {
19641962 throw new PermissionDeniedException ("The account:" + account .getAccountName ()
19651963 + " does not fall in the same domain hierarchy as the disk offering" );
19661964 }
19671965 }
19681966
1969- sb .and ("name" , sb .entity ().getName (), SearchCriteria .Op .LIKE );
1970- sb .and ("id" , sb .entity ().getId (), SearchCriteria .Op .EQ );
1971-
19721967
1973- boolean includePublicOfferings = false ;
19741968 List <Long > domainIds = null ;
19751969 // For non-root users, only return all offerings for the user's domain, and everything above till root
19761970 if ((account .getType () == Account .ACCOUNT_TYPE_NORMAL || account .getType () == Account .ACCOUNT_TYPE_DOMAIN_ADMIN )
@@ -1987,43 +1981,32 @@ private Pair<List<DiskOfferingJoinVO>, Integer> searchForDiskOfferingsInternal(L
19871981 domainRecord = _domainDao .findById (domainRecord .getParent ());
19881982 domainIds .add (domainRecord .getId ());
19891983 }
1990- sb .and ("domainIdIn" , sb .entity ().getDomainId (), SearchCriteria .Op .IN );
1984+
1985+ SearchCriteria <DiskOfferingJoinVO > spc = _diskOfferingJoinDao .createSearchCriteria ();
19911986
1992- // include also public offering if no keyword, name and id specified
1993- if ( keyword == null && name == null && id == null ){
1994- includePublicOfferings = true ;
1995- }
1987+ spc .addOr ("domainId" , SearchCriteria .Op .IN , domainIds .toArray ());
1988+ spc .addOr ("domainId" , SearchCriteria .Op .NULL ); // include public offering as where
1989+ sc .addAnd ("domainId" , SearchCriteria .Op .SC , spc );
1990+ sc .addAnd ("systemUse" , SearchCriteria .Op .EQ , false ); // non-root users should not see system offering at all
1991+
19961992 }
19971993
1998- SearchCriteria <DiskOfferingJoinVO > sc = sb .create ();
1999- if (keyword != null ) {
1994+ if (keyword != null ) {
20001995 SearchCriteria <DiskOfferingJoinVO > ssc = _diskOfferingJoinDao .createSearchCriteria ();
20011996 ssc .addOr ("displayText" , SearchCriteria .Op .LIKE , "%" + keyword + "%" );
20021997 ssc .addOr ("name" , SearchCriteria .Op .LIKE , "%" + keyword + "%" );
20031998
20041999 sc .addAnd ("name" , SearchCriteria .Op .SC , ssc );
20052000 }
20062001
2007- if (name != null ) {
2008- sc .setParameters ("name" , "%" + name + "%" );
2009- }
2010-
20112002 if (id != null ) {
2012- sc .setParameters ("id" , id );
2013- }
2014-
2015- if (domainIds != null ){
2016- sc .setParameters ("domainIdIn" , domainIds .toArray ());
2003+ sc .addAnd ("id" , SearchCriteria .Op .EQ , id );
20172004 }
20182005
2019- if (includePublicOfferings ){
2020- SearchCriteria <DiskOfferingJoinVO > spc = _diskOfferingJoinDao .createSearchCriteria ();
2021- spc .addAnd ("domainId" , SearchCriteria .Op .NULL );
2022- spc .addAnd ("systemUse" , SearchCriteria .Op .EQ , false );
2023-
2024- sc .addOr ("systemUse" , SearchCriteria .Op .SC , spc );
2006+ if (name != null ) {
2007+ sc .addAnd ("name" , SearchCriteria .Op .EQ , name );
20252008 }
2026-
2009+
20272010 // FIXME: disk offerings should search back up the hierarchy for
20282011 // available disk offerings...
20292012 /*
@@ -2100,10 +2083,10 @@ private Pair<List<ServiceOfferingJoinVO>, Integer> searchForServiceOfferingsInte
21002083 }
21012084 }
21022085
2103- boolean includePublicOfferings = false ;
2086+ // boolean includePublicOfferings = false;
21042087 if ((caller .getType () == Account .ACCOUNT_TYPE_NORMAL || caller .getType () == Account .ACCOUNT_TYPE_DOMAIN_ADMIN )
21052088 || caller .getType () == Account .ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN ) {
2106- // For non-root users
2089+ // For non-root users.
21072090 if (isSystem ) {
21082091 throw new InvalidParameterValueException ("Only root admins can access system's offering" );
21092092 }
@@ -2122,13 +2105,9 @@ private Pair<List<ServiceOfferingJoinVO>, Integer> searchForServiceOfferingsInte
21222105 SearchCriteria <ServiceOfferingJoinVO > spc = _srvOfferingJoinDao .createSearchCriteria ();
21232106
21242107 spc .addOr ("domainId" , SearchCriteria .Op .IN , domainIds .toArray ());
2125- spc .addOr ("domainId" , SearchCriteria .Op .NULL );
2108+ spc .addOr ("domainId" , SearchCriteria .Op .NULL ); // include public offering as where
21262109 sc .addAnd ("domainId" , SearchCriteria .Op .SC , spc );
21272110
2128- // include also public offering if no keyword, name and id specified
2129- if ( keyword == null && name == null && id == null ){
2130- includePublicOfferings = true ;
2131- }
21322111 }
21332112 else {
21342113 // for root users
@@ -2171,24 +2150,18 @@ private Pair<List<ServiceOfferingJoinVO>, Integer> searchForServiceOfferingsInte
21712150 }
21722151
21732152 if (isSystem != null ) {
2153+ // note that for non-root users, isSystem is always false when control comes to here
21742154 sc .addAnd ("systemUse" , SearchCriteria .Op .EQ , isSystem );
21752155 }
21762156
21772157 if (name != null ) {
2178- sc .addAnd ("name" , SearchCriteria .Op .LIKE , "%" + name + "%" );
2158+ sc .addAnd ("name" , SearchCriteria .Op .EQ , name );
21792159 }
21802160
21812161 if (vmTypeStr != null ) {
21822162 sc .addAnd ("vm_type" , SearchCriteria .Op .EQ , vmTypeStr );
21832163 }
21842164
2185- if (includePublicOfferings ){
2186- SearchCriteria <ServiceOfferingJoinVO > spc = _srvOfferingJoinDao .createSearchCriteria ();
2187- spc .addAnd ("domainId" , SearchCriteria .Op .NULL );
2188- spc .addAnd ("systemUse" , SearchCriteria .Op .EQ , false );
2189- sc .addOr ("systemUse" , SearchCriteria .Op .SC , spc );
2190- }
2191-
21922165 return _srvOfferingJoinDao .searchAndCount (sc , searchFilter );
21932166
21942167 }
0 commit comments