@@ -1924,7 +1924,7 @@ private Pair<List<DiskOfferingJoinVO>, Integer> searchForDiskOfferingsInternal(L
19241924 Boolean isAscending = Boolean .parseBoolean (_configDao .getValue ("sortkey.algorithm" ));
19251925 isAscending = (isAscending == null ? true : isAscending );
19261926 Filter searchFilter = new Filter (DiskOfferingJoinVO .class , "sortKey" , isAscending , cmd .getStartIndex (), cmd .getPageSizeVal ());
1927- SearchBuilder <DiskOfferingJoinVO > sb = _diskOfferingJoinDao .createSearchBuilder ();
1927+ SearchCriteria <DiskOfferingJoinVO > sc = _diskOfferingJoinDao .createSearchCriteria ();
19281928
19291929
19301930 Account account = UserContext .current ().getCaller ();
@@ -1939,21 +1939,15 @@ private Pair<List<DiskOfferingJoinVO>, Integer> searchForDiskOfferingsInternal(L
19391939 if (account .getType () == Account .ACCOUNT_TYPE_ADMIN || isPermissible (account .getDomainId (), domainId ) ) {
19401940 // check if the user's domain == do's domain || user's domain is
19411941 // a child of so's domain for non-root users
1942- sb .and ("domainId" , sb .entity ().getDomainId (), SearchCriteria .Op .EQ );
1943- SearchCriteria <DiskOfferingJoinVO > sc = sb .create ();
1944- sc .setParameters ("domainId" , domainId );
1942+ sc .addAnd ("domainId" , SearchCriteria .Op .EQ , domainId );
19451943 return _diskOfferingJoinDao .searchAndCount (sc , searchFilter );
19461944 } else {
19471945 throw new PermissionDeniedException ("The account:" + account .getAccountName ()
19481946 + " does not fall in the same domain hierarchy as the disk offering" );
19491947 }
19501948 }
19511949
1952- sb .and ("name" , sb .entity ().getName (), SearchCriteria .Op .LIKE );
1953- sb .and ("id" , sb .entity ().getId (), SearchCriteria .Op .EQ );
1954-
19551950
1956- boolean includePublicOfferings = false ;
19571951 List <Long > domainIds = null ;
19581952 // For non-root users, only return all offerings for the user's domain, and everything above till root
19591953 if ((account .getType () == Account .ACCOUNT_TYPE_NORMAL || account .getType () == Account .ACCOUNT_TYPE_DOMAIN_ADMIN )
@@ -1970,43 +1964,32 @@ private Pair<List<DiskOfferingJoinVO>, Integer> searchForDiskOfferingsInternal(L
19701964 domainRecord = _domainDao .findById (domainRecord .getParent ());
19711965 domainIds .add (domainRecord .getId ());
19721966 }
1973- sb .and ("domainIdIn" , sb .entity ().getDomainId (), SearchCriteria .Op .IN );
1967+
1968+ SearchCriteria <DiskOfferingJoinVO > spc = _diskOfferingJoinDao .createSearchCriteria ();
19741969
1975- // include also public offering if no keyword, name and id specified
1976- if ( keyword == null && name == null && id == null ){
1977- includePublicOfferings = true ;
1978- }
1970+ spc .addOr ("domainId" , SearchCriteria .Op .IN , domainIds .toArray ());
1971+ spc .addOr ("domainId" , SearchCriteria .Op .NULL ); // include public offering as where
1972+ sc .addAnd ("domainId" , SearchCriteria .Op .SC , spc );
1973+ sc .addAnd ("systemUse" , SearchCriteria .Op .EQ , false ); // non-root users should not see system offering at all
1974+
19791975 }
19801976
1981- SearchCriteria <DiskOfferingJoinVO > sc = sb .create ();
1982- if (keyword != null ) {
1977+ if (keyword != null ) {
19831978 SearchCriteria <DiskOfferingJoinVO > ssc = _diskOfferingJoinDao .createSearchCriteria ();
19841979 ssc .addOr ("displayText" , SearchCriteria .Op .LIKE , "%" + keyword + "%" );
19851980 ssc .addOr ("name" , SearchCriteria .Op .LIKE , "%" + keyword + "%" );
19861981
19871982 sc .addAnd ("name" , SearchCriteria .Op .SC , ssc );
19881983 }
19891984
1990- if (name != null ) {
1991- sc .setParameters ("name" , "%" + name + "%" );
1992- }
1993-
19941985 if (id != null ) {
1995- sc .setParameters ("id" , id );
1996- }
1997-
1998- if (domainIds != null ){
1999- sc .setParameters ("domainIdIn" , domainIds .toArray ());
1986+ sc .addAnd ("id" , SearchCriteria .Op .EQ , id );
20001987 }
20011988
2002- if (includePublicOfferings ){
2003- SearchCriteria <DiskOfferingJoinVO > spc = _diskOfferingJoinDao .createSearchCriteria ();
2004- spc .addAnd ("domainId" , SearchCriteria .Op .NULL );
2005- spc .addAnd ("systemUse" , SearchCriteria .Op .EQ , false );
2006-
2007- sc .addOr ("systemUse" , SearchCriteria .Op .SC , spc );
1989+ if (name != null ) {
1990+ sc .addAnd ("name" , SearchCriteria .Op .EQ , name );
20081991 }
2009-
1992+
20101993 // FIXME: disk offerings should search back up the hierarchy for
20111994 // available disk offerings...
20121995 /*
@@ -2083,10 +2066,10 @@ private Pair<List<ServiceOfferingJoinVO>, Integer> searchForServiceOfferingsInte
20832066 }
20842067 }
20852068
2086- boolean includePublicOfferings = false ;
2069+ // boolean includePublicOfferings = false;
20872070 if ((caller .getType () == Account .ACCOUNT_TYPE_NORMAL || caller .getType () == Account .ACCOUNT_TYPE_DOMAIN_ADMIN )
20882071 || caller .getType () == Account .ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN ) {
2089- // For non-root users
2072+ // For non-root users.
20902073 if (isSystem ) {
20912074 throw new InvalidParameterValueException ("Only root admins can access system's offering" );
20922075 }
@@ -2105,13 +2088,9 @@ private Pair<List<ServiceOfferingJoinVO>, Integer> searchForServiceOfferingsInte
21052088 SearchCriteria <ServiceOfferingJoinVO > spc = _srvOfferingJoinDao .createSearchCriteria ();
21062089
21072090 spc .addOr ("domainId" , SearchCriteria .Op .IN , domainIds .toArray ());
2108- spc .addOr ("domainId" , SearchCriteria .Op .NULL );
2091+ spc .addOr ("domainId" , SearchCriteria .Op .NULL ); // include public offering as where
21092092 sc .addAnd ("domainId" , SearchCriteria .Op .SC , spc );
21102093
2111- // include also public offering if no keyword, name and id specified
2112- if ( keyword == null && name == null && id == null ){
2113- includePublicOfferings = true ;
2114- }
21152094 }
21162095 else {
21172096 // for root users
@@ -2154,24 +2133,18 @@ private Pair<List<ServiceOfferingJoinVO>, Integer> searchForServiceOfferingsInte
21542133 }
21552134
21562135 if (isSystem != null ) {
2136+ // note that for non-root users, isSystem is always false when control comes to here
21572137 sc .addAnd ("systemUse" , SearchCriteria .Op .EQ , isSystem );
21582138 }
21592139
21602140 if (name != null ) {
2161- sc .addAnd ("name" , SearchCriteria .Op .LIKE , "%" + name + "%" );
2141+ sc .addAnd ("name" , SearchCriteria .Op .EQ , name );
21622142 }
21632143
21642144 if (vmTypeStr != null ) {
21652145 sc .addAnd ("vm_type" , SearchCriteria .Op .EQ , vmTypeStr );
21662146 }
21672147
2168- if (includePublicOfferings ){
2169- SearchCriteria <ServiceOfferingJoinVO > spc = _srvOfferingJoinDao .createSearchCriteria ();
2170- spc .addAnd ("domainId" , SearchCriteria .Op .NULL );
2171- spc .addAnd ("systemUse" , SearchCriteria .Op .EQ , false );
2172- sc .addOr ("systemUse" , SearchCriteria .Op .SC , spc );
2173- }
2174-
21752148 return _srvOfferingJoinDao .searchAndCount (sc , searchFilter );
21762149
21772150 }
0 commit comments