mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-17 11:04:00 +01:00
Fixed listRegions serach by id, name
This commit is contained in:
parent
c607e03f0e
commit
a33d8f9601
@ -38,7 +38,7 @@ public class ListRegionsCmd extends BaseListCmd {
|
|||||||
//////////////// API parameters /////////////////////
|
//////////////// API parameters /////////////////////
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
|
|
||||||
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="List Region by region ID.")
|
@Parameter(name=ApiConstants.ID, type=CommandType.INTEGER, description="List Region by region ID.")
|
||||||
private Integer id;
|
private Integer id;
|
||||||
|
|
||||||
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="List Region by region name.")
|
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="List Region by region name.")
|
||||||
|
|||||||
@ -311,7 +311,22 @@ public class RegionManagerImpl implements RegionManager, Manager{
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<RegionVO> listRegions(Integer id, String name) {
|
public List<RegionVO> listRegions(Integer id, String name) {
|
||||||
return _regionDao.listByNameAndId(id, name);
|
List<RegionVO> regions = new ArrayList<RegionVO>();
|
||||||
|
if(id != null){
|
||||||
|
RegionVO region = _regionDao.findById(id);
|
||||||
|
if(region != null){
|
||||||
|
regions.add(region);
|
||||||
|
}
|
||||||
|
return regions;
|
||||||
|
}
|
||||||
|
if(name != null){
|
||||||
|
RegionVO region = _regionDao.findByName(name);
|
||||||
|
if(region != null){
|
||||||
|
regions.add(region);
|
||||||
|
}
|
||||||
|
return regions;
|
||||||
|
}
|
||||||
|
return _regionDao.listAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -16,8 +16,6 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
package org.apache.cloudstack.region.dao;
|
package org.apache.cloudstack.region.dao;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.apache.cloudstack.region.RegionVO;
|
import org.apache.cloudstack.region.RegionVO;
|
||||||
|
|
||||||
import com.cloud.utils.db.GenericDao;
|
import com.cloud.utils.db.GenericDao;
|
||||||
@ -26,5 +24,4 @@ public interface RegionDao extends GenericDao<RegionVO, Integer> {
|
|||||||
|
|
||||||
RegionVO findByName(String name);
|
RegionVO findByName(String name);
|
||||||
|
|
||||||
List<RegionVO> listByNameAndId(Integer id, String name);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,14 +16,11 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
package org.apache.cloudstack.region.dao;
|
package org.apache.cloudstack.region.dao;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.ejb.Local;
|
import javax.ejb.Local;
|
||||||
|
|
||||||
import org.apache.cloudstack.region.RegionVO;
|
import org.apache.cloudstack.region.RegionVO;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.user.UserVO;
|
|
||||||
import com.cloud.utils.db.GenericDaoBase;
|
import com.cloud.utils.db.GenericDaoBase;
|
||||||
import com.cloud.utils.db.SearchBuilder;
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
import com.cloud.utils.db.SearchCriteria;
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
@ -38,25 +35,12 @@ public class RegionDaoImpl extends GenericDaoBase<RegionVO, Integer> implements
|
|||||||
NameSearch = createSearchBuilder();
|
NameSearch = createSearchBuilder();
|
||||||
NameSearch.and("name", NameSearch.entity().getName(), SearchCriteria.Op.EQ);
|
NameSearch.and("name", NameSearch.entity().getName(), SearchCriteria.Op.EQ);
|
||||||
NameSearch.done();
|
NameSearch.done();
|
||||||
|
|
||||||
AllFieldsSearch = createSearchBuilder();
|
|
||||||
AllFieldsSearch.and("id", AllFieldsSearch.entity().getId(), SearchCriteria.Op.EQ);
|
|
||||||
AllFieldsSearch.and("name", AllFieldsSearch.entity().getName(), SearchCriteria.Op.EQ);
|
|
||||||
AllFieldsSearch.done();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RegionVO findByName(String name) {
|
public RegionVO findByName(String name) {
|
||||||
SearchCriteria<RegionVO> sc = NameSearch.create();
|
SearchCriteria<RegionVO> sc = NameSearch.create();
|
||||||
sc.setParameters("name", NameSearch);
|
sc.setParameters("name", name);
|
||||||
return findOneBy(sc);
|
return findOneBy(sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<RegionVO> listByNameAndId(Integer id, String name) {
|
|
||||||
SearchCriteria<RegionVO> sc = AllFieldsSearch.create();
|
|
||||||
sc.setParameters("id", id);
|
|
||||||
sc.setParameters("name", name);
|
|
||||||
return listBy(sc);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user