@@ -5115,27 +5115,46 @@ public List<SnapshotVO> listSnapshots(ListSnapshotsCmd cmd) throws InvalidParame
51155115 accountId = account .getId ();
51165116 }
51175117
5118- Filter searchFilter = new Filter (SnapshotVO .class , "created" , false , cmd .getStartIndex (), cmd .getPageSizeVal ());
5119- SearchCriteria <SnapshotVO > sc = _snapshotDao .createSearchCriteria ();
5120-
51215118 Object name = cmd .getSnapshotName ();
51225119 Object id = cmd .getId ();
51235120 Object keyword = cmd .getKeyword ();
51245121 Object snapshotTypeStr = cmd .getSnapshotType ();
51255122 String interval = cmd .getIntervalType ();
51265123
5127- sc .addAnd ("status" , SearchCriteria .Op .EQ , Snapshot .Status .BackedUp );
5124+ Filter searchFilter = new Filter (SnapshotVO .class , "created" , false , cmd .getStartIndex (), cmd .getPageSizeVal ());
5125+ SearchBuilder <SnapshotVO > sb = _snapshotDao .createSearchBuilder ();
5126+ sb .and ("status" , sb .entity ().getStatus (), SearchCriteria .Op .EQ );
5127+ sb .and ("volumeId" , sb .entity ().getVolumeId (), SearchCriteria .Op .EQ );
5128+ sb .and ("name" , sb .entity ().getName (), SearchCriteria .Op .LIKE );
5129+ sb .and ("id" , sb .entity ().getId (), SearchCriteria .Op .EQ );
5130+ sb .and ("accountId" , sb .entity ().getAccountId (), SearchCriteria .Op .EQ );
5131+ sb .and ("snapshotTypeEQ" , sb .entity ().getSnapshotType (), SearchCriteria .Op .EQ );
5132+ sb .and ("snapshotTypeNEQ" , sb .entity ().getSnapshotType (), SearchCriteria .Op .NEQ );
5133+
5134+ if ((accountId == null ) && (domainId != null )) {
5135+ // if accountId isn't specified, we can do a domain match for the admin case
5136+ SearchBuilder <AccountVO > accountSearch = _accountDao .createSearchBuilder ();
5137+ sb .join ("accountSearch" , accountSearch , sb .entity ().getAccountId (), accountSearch .entity ().getId (), JoinType .INNER );
5138+
5139+ SearchBuilder <DomainVO > domainSearch = _domainDao .createSearchBuilder ();
5140+ domainSearch .and ("path" , domainSearch .entity ().getPath (), SearchCriteria .Op .LIKE );
5141+ accountSearch .join ("domainSearch" , domainSearch , accountSearch .entity ().getDomainId (), domainSearch .entity ().getId (), JoinType .INNER );
5142+ }
5143+
5144+ SearchCriteria <SnapshotVO > sc = sb .create ();
5145+
5146+ sc .setParameters ("status" , Snapshot .Status .BackedUp );
51285147
51295148 if (volumeId != null ) {
5130- sc .addAnd ("volumeId" , SearchCriteria . Op . EQ , volumeId );
5149+ sc .setParameters ("volumeId" , volumeId );
51315150 }
5132-
5151+
51335152 if (name != null ) {
5134- sc .addAnd ("name" , SearchCriteria . Op . LIKE , "%" + name + "%" );
5153+ sc .setParameters ("name" , "%" + name + "%" );
51355154 }
51365155
51375156 if (id != null ) {
5138- sc .addAnd ("id" , SearchCriteria .Op .EQ , id );
5157+ sc .setParameters ("id" , SearchCriteria .Op .EQ , id );
51395158 }
51405159
51415160 if (keyword != null ) {
@@ -5144,20 +5163,24 @@ public List<SnapshotVO> listSnapshots(ListSnapshotsCmd cmd) throws InvalidParame
51445163
51455164 sc .addAnd ("name" , SearchCriteria .Op .SC , ssc );
51465165 }
5147-
5166+
51485167 if (accountId != null ) {
5149- sc .addAnd ("accountId" , SearchCriteria .Op .EQ , accountId );
5168+ sc .setParameters ("accountId" , accountId );
5169+ } else if (domainId != null ) {
5170+ DomainVO domain = _domainDao .findById ((Long )domainId );
5171+ SearchCriteria joinSearch = sc .getJoin ("accountSearch" );
5172+ joinSearch .setJoinParameters ("domainSearch" , "path" , domain .getPath () + "%" );
51505173 }
51515174
51525175 if (snapshotTypeStr != null ) {
51535176 SnapshotType snapshotType = SnapshotVO .getSnapshotType ((String )snapshotTypeStr );
51545177 if (snapshotType == null ) {
51555178 throw new InvalidParameterValueException ("Unsupported snapshot type " + snapshotTypeStr );
51565179 }
5157- sc .addAnd ( "snapshotType" , SearchCriteria . Op . EQ , snapshotType .ordinal ());
5180+ sc .setParameters ( "snapshotTypeEQ" , snapshotType .ordinal ());
51585181 } else {
51595182 // Show only MANUAL and RECURRING snapshot types
5160- sc .addAnd ( "snapshotType" , SearchCriteria . Op . NEQ , Snapshot .SnapshotType .TEMPLATE .ordinal ());
5183+ sc .setParameters ( "snapshotTypeNEQ" , Snapshot .SnapshotType .TEMPLATE .ordinal ());
51615184 }
51625185
51635186 return _snapshotDao .search (sc , searchFilter );
0 commit comments