cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edi...@apache.org
Subject [3/8] starting unit test
Date Wed, 21 Nov 2012 03:01:19 GMT
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/573d13dd/engine/storage/src/org/apache/cloudstack/storage/image/ImageServiceImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/ImageServiceImpl.java b/engine/storage/src/org/apache/cloudstack/storage/image/ImageServiceImpl.java
index 18561e6..38f669b 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/ImageServiceImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/ImageServiceImpl.java
@@ -26,69 +26,66 @@ import org.apache.cloudstack.storage.image.downloader.ImageDownloader;
 import org.apache.cloudstack.storage.image.manager.ImageDataStoreManager;
 import org.apache.cloudstack.storage.image.provider.ImageDataStoreProviderManager;
 import org.apache.cloudstack.storage.image.store.ImageDataStore;
+import org.springframework.stereotype.Component;
 
+@Component
 public class ImageServiceImpl implements ImageService {
+    @Inject
+    ImageDataStoreProviderManager imageStoreProviderMgr;
 
-	@Inject
-	ImageDataStoreProviderManager imageStoreProviderMgr;
-	@Inject
-	
-	@Override
-	public boolean registerTemplate(long templateId, long imageStoreId) {
-		ImageDataStore ids = imageStoreProviderMgr.getDataStore(imageStoreId);
-		TemplateInfo template = ids.registerTemplate(templateId);
-		if (ids.needDownloadToCacheStorage()) {
-			ImageDownloader imageDl = ids.getImageDownloader();
-			imageDl.downloadImage(template);
-		}
-		return true;
-	}
+    @Override
+    public TemplateEntity registerTemplate(long templateId, long imageStoreId) {
+        ImageDataStore ids = imageStoreProviderMgr.getDataStore(imageStoreId);
+        TemplateObject to = ids.registerTemplate(templateId);
+        return new TemplateEntityImpl(to);
+    }
 
-	@Override
-	public boolean deleteTemplate(long templateId) {
-		// TODO Auto-generated method stub
-		return false;
-	}
+    @Override
+    public boolean deleteTemplate(long templateId) {
+        // TODO Auto-generated method stub
+        return false;
+    }
 
-	@Override
-	public long registerIso(String isoUrl, long accountId) {
-		// TODO Auto-generated method stub
-		return 0;
-	}
+    @Override
+    public long registerIso(String isoUrl, long accountId) {
+        // TODO Auto-generated method stub
+        return 0;
+    }
 
-	@Override
-	public boolean deleteIso(long isoId) {
-		// TODO Auto-generated method stub
-		return false;
-	}
+    @Override
+    public boolean deleteIso(long isoId) {
+        // TODO Auto-generated method stub
+        return false;
+    }
 
-	@Override
-	public boolean revokeTemplateAccess(long templateId, long endpointId) {
-		// TODO Auto-generated method stub
-		return false;
-	}
+    @Override
+    public boolean revokeTemplateAccess(long templateId, long endpointId) {
+        // TODO Auto-generated method stub
+        return false;
+    }
 
-	@Override
-	public String grantIsoAccess(long isoId, long endpointId) {
-		// TODO Auto-generated method stub
-		return null;
-	}
+    @Override
+    public String grantIsoAccess(long isoId, long endpointId) {
+        // TODO Auto-generated method stub
+        return null;
+    }
 
-	@Override
-	public boolean revokeIsoAccess(long isoId, long endpointId) {
-		// TODO Auto-generated method stub
-		return false;
-	}
+    @Override
+    public boolean revokeIsoAccess(long isoId, long endpointId) {
+        // TODO Auto-generated method stub
+        return false;
+    }
 
-	@Override
-	public TemplateEntity getTemplateEntity(long templateId) {
-		TemplateObject to = imageStoreProviderMgr.getTemplate(templateId);
-		return new TemplateEntityImpl(to);
-	}
+    @Override
+    public TemplateEntity getTemplateEntity(long templateId) {
+        ImageDataStore dataStore = imageStoreProviderMgr.getDataStoreFromTemplateId(templateId);
+        TemplateObject to = dataStore.getTemplate(templateId);
+        return new TemplateEntityImpl(to);
+    }
 
-	@Override
-	public TemplateInfo grantTemplateAccess(TemplateInfo template, EndPoint endpointId) {
-		// TODO Auto-generated method stub
-		return null;
-	}
+    @Override
+    public boolean grantTemplateAccess(TemplateInfo template, EndPoint endpointId) {
+        // TODO Auto-generated method stub
+        return true;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/573d13dd/engine/storage/src/org/apache/cloudstack/storage/image/TemplateEntityImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/TemplateEntityImpl.java b/engine/storage/src/org/apache/cloudstack/storage/image/TemplateEntityImpl.java
index 384ca0d..e775d25 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/TemplateEntityImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/TemplateEntityImpl.java
@@ -32,6 +32,7 @@ import com.cloud.storage.Storage.TemplateType;
 
 public class TemplateEntityImpl implements TemplateEntity {
     protected TemplateInfo templateInfo;
+
     public TemplateEntityImpl(TemplateInfo templateInfo) {
         this.templateInfo = templateInfo;
     }
@@ -40,7 +41,6 @@ public class TemplateEntityImpl implements TemplateEntity {
         return templateInfo.getImageDataStore();
     }
 
-
     public long getImageDataStoreId() {
         return getImageDataStore().getImageDataStoreId();
     }
@@ -51,14 +51,18 @@ public class TemplateEntityImpl implements TemplateEntity {
 
     @Override
     public String getUuid() {
-        // TODO Auto-generated method stub
-        return null;
+        return this.templateInfo.getUuid();
     }
 
     @Override
     public long getId() {
+       return this.templateInfo.getId();
+    }
+
+    @Override
+    public String getExternalId() {
         // TODO Auto-generated method stub
-        return 0;
+        return null;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/573d13dd/engine/storage/src/org/apache/cloudstack/storage/image/TemplateInfo.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/TemplateInfo.java b/engine/storage/src/org/apache/cloudstack/storage/image/TemplateInfo.java
index fedbafb..0e11f3e 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/TemplateInfo.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/TemplateInfo.java
@@ -22,7 +22,13 @@ import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskTyp
 import org.apache.cloudstack.storage.image.store.ImageDataStoreInfo;
 
 public interface TemplateInfo {
-	ImageDataStoreInfo getImageDataStore();
-	long getId();
-	VolumeDiskType getDiskType();
+    ImageDataStoreInfo getImageDataStore();
+
+    long getId();
+
+    VolumeDiskType getDiskType();
+    
+    String getPath();
+    
+    String getUuid();
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/573d13dd/engine/storage/src/org/apache/cloudstack/storage/image/TemplateObject.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/TemplateObject.java b/engine/storage/src/org/apache/cloudstack/storage/image/TemplateObject.java
index 24c656a..5d65a3a 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/TemplateObject.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/TemplateObject.java
@@ -24,24 +24,38 @@ import org.apache.cloudstack.storage.image.db.ImageDataVO;
 import org.apache.cloudstack.storage.image.store.ImageDataStoreInfo;
 
 public class TemplateObject implements TemplateInfo {
-	private ImageDataVO imageVO;
-	public TemplateObject(ImageDataVO template) {
-		this.imageVO = template;
-	}
-	@Override
-	public ImageDataStoreInfo getImageDataStore() {
-		// TODO Auto-generated method stub
-		return null;
-	}
-
-	@Override
-	public long getId() {
-		// TODO Auto-generated method stub
-		return 0;
-	}
-
-	@Override
-	public VolumeDiskType getDiskType() {
-		return VolumeDiskTypeHelper.getDiskType(imageVO.getFormat());
-	}
+    private ImageDataVO imageVO;
+    private ImageDataStoreInfo dataStore;
+
+    public TemplateObject(ImageDataVO template, ImageDataStoreInfo dataStore) {
+        this.imageVO = template;
+        this.dataStore = dataStore;
+    }
+
+    @Override
+    public ImageDataStoreInfo getImageDataStore() {
+        return this.dataStore;
+    }
+
+    @Override
+    public long getId() {
+        return this.imageVO.getId();
+    }
+
+    @Override
+    public VolumeDiskType getDiskType() {
+        return VolumeDiskTypeHelper.getDiskType(imageVO.getFormat());
+    }
+
+    @Override
+    public String getPath() {
+        //TODO: add installation path if it's downloaded to cache storage already
+        return this.imageVO.getUrl();
+    }
+
+    @Override
+    public String getUuid() {
+        // TODO Auto-generated method stub
+        return null;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/573d13dd/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDaoStoreDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDaoStoreDaoImpl.java b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDaoStoreDaoImpl.java
index 4f1a510..995aa5e 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDaoStoreDaoImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDaoStoreDaoImpl.java
@@ -21,6 +21,7 @@ package org.apache.cloudstack.storage.image.db;
 import org.springframework.stereotype.Component;
 
 import com.cloud.utils.db.GenericDaoBase;
+
 @Component
 public class ImageDaoStoreDaoImpl extends GenericDaoBase<ImageDataStoreVO, Long> implements ImageDataStoreDao {
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/573d13dd/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataDao.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataDao.java b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataDao.java
index b336ffa..5f79e96 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataDao.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataDao.java
@@ -31,41 +31,51 @@ import com.cloud.utils.Pair;
 import com.cloud.utils.db.GenericDao;
 
 public interface ImageDataDao extends GenericDao<ImageDataVO, Long> {
-	public List<ImageDataVO> listByPublic();
-	public ImageDataVO findByName(String templateName);
-	public ImageDataVO findByTemplateName(String templateName);	
-
-	//public void update(ImageDataVO template);
-
-
-	public List<ImageDataVO> listAllSystemVMTemplates();
-
-	public List<ImageDataVO> listDefaultBuiltinTemplates();
-	public String getRoutingTemplateUniqueName();
-	public List<ImageDataVO> findIsosByIdAndPath(Long domainId, Long accountId, String path);
-	public List<ImageDataVO> listReadyTemplates();
-	public List<ImageDataVO> listByAccountId(long accountId);
-	public Set<Pair<Long, Long>> searchTemplates(String name, String keyword, TemplateFilter templateFilter, boolean isIso,
-	        List<HypervisorType> hypers, Boolean bootable, DomainVO domain, Long pageSize, Long startIndex, Long zoneId,
-	        HypervisorType hyperType, boolean onlyReady, boolean showDomr, List<Account> permittedAccounts, Account caller,
-	        ListProjectResourcesCriteria listProjectResourcesCriteria, Map<String, String> tags);
-	
-    public Set<Pair<Long, Long>> searchSwiftTemplates(String name, String keyword, TemplateFilter templateFilter,
-            boolean isIso, List<HypervisorType> hypers, Boolean bootable, DomainVO domain, Long pageSize, Long startIndex,
-            Long zoneId, HypervisorType hyperType, boolean onlyReady, boolean showDomr, List<Account> permittedAccounts, Account caller, Map<String, String> tags);
-
-	public long addTemplateToZone(ImageDataVO tmplt, long zoneId);
-	public List<ImageDataVO> listAllInZone(long dataCenterId);	
-	
+    public List<ImageDataVO> listByPublic();
+
+    public ImageDataVO findByName(String templateName);
+
+    public ImageDataVO findByTemplateName(String templateName);
+
+    // public void update(ImageDataVO template);
+
+    public List<ImageDataVO> listAllSystemVMTemplates();
+
+    public List<ImageDataVO> listDefaultBuiltinTemplates();
+
+    public String getRoutingTemplateUniqueName();
+
+    public List<ImageDataVO> findIsosByIdAndPath(Long domainId, Long accountId, String path);
+
+    public List<ImageDataVO> listReadyTemplates();
+
+    public List<ImageDataVO> listByAccountId(long accountId);
+
+    public Set<Pair<Long, Long>> searchTemplates(String name, String keyword, TemplateFilter templateFilter, boolean isIso, List<HypervisorType> hypers, Boolean bootable, DomainVO domain,
+            Long pageSize, Long startIndex, Long zoneId, HypervisorType hyperType, boolean onlyReady, boolean showDomr, List<Account> permittedAccounts, Account caller,
+            ListProjectResourcesCriteria listProjectResourcesCriteria, Map<String, String> tags);
+
+    public Set<Pair<Long, Long>> searchSwiftTemplates(String name, String keyword, TemplateFilter templateFilter, boolean isIso, List<HypervisorType> hypers, Boolean bootable, DomainVO domain,
+            Long pageSize, Long startIndex, Long zoneId, HypervisorType hyperType, boolean onlyReady, boolean showDomr, List<Account> permittedAccounts, Account caller, Map<String, String> tags);
+
+    public long addTemplateToZone(ImageDataVO tmplt, long zoneId);
+
+    public List<ImageDataVO> listAllInZone(long dataCenterId);
+
     public List<ImageDataVO> listByHypervisorType(List<HypervisorType> hyperTypes);
-	public List<ImageDataVO> publicIsoSearch(Boolean bootable, boolean listRemoved, Map<String, String> tags);
-	public List<ImageDataVO> userIsoSearch(boolean listRemoved);
+
+    public List<ImageDataVO> publicIsoSearch(Boolean bootable, boolean listRemoved, Map<String, String> tags);
+
+    public List<ImageDataVO> userIsoSearch(boolean listRemoved);
+
     ImageDataVO findSystemVMTemplate(long zoneId);
+
     ImageDataVO findSystemVMTemplate(long zoneId, HypervisorType hType);
 
     ImageDataVO findRoutingTemplate(HypervisorType type);
+
     List<Long> listPrivateTemplatesByHost(Long hostId);
+
     public Long countTemplatesForAccount(long accountId);
-	
-}
 
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/573d13dd/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataDaoImpl.java b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataDaoImpl.java
index 27b12fb..5444a28 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataDaoImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataDaoImpl.java
@@ -59,6 +59,7 @@ import com.cloud.tags.dao.ResourceTagsDaoImpl;
 import com.cloud.template.VirtualMachineTemplate.TemplateFilter;
 import com.cloud.user.Account;
 import com.cloud.utils.Pair;
+import com.cloud.utils.component.ComponentInject;
 import com.cloud.utils.component.ComponentLocator;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.db.Filter;
@@ -74,26 +75,26 @@ import com.cloud.utils.exception.CloudRuntimeException;
 @Component
 public class ImageDataDaoImpl extends GenericDaoBase<ImageDataVO, Long> implements ImageDataDao {
     private static final Logger s_logger = Logger.getLogger(VMTemplateDaoImpl.class);
-    
-    @Inject
-    VMTemplateZoneDao _templateZoneDao;
-    @Inject
-    VMTemplateDetailsDao _templateDetailsDao;
-    
-    @Inject
-    ConfigurationDao  _configDao;
-    @Inject
-    HostDao   _hostDao;
-    @Inject
-    DomainDao _domainDao;
-    @Inject
-    DataCenterDao _dcDao;
-    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, " +
-    								"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";
-    
-    private final String SELECT_TEMPLATE_ZONE_REF = "SELECT t.id, tzr.zone_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, " +
-									"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 INNER JOIN template_zone_ref tzr on (t.id = tzr.template_id) ";
-    
+
+
+    VMTemplateZoneDao _templateZoneDao = null;
+   
+    VMTemplateDetailsDao _templateDetailsDao = null;
+
+   
+    ConfigurationDao _configDao = null;
+
+    HostDao _hostDao = null;
+
+    DomainDao _domainDao = null;
+
+    DataCenterDao _dcDao = null;
+    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, "
+            + "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";
+
+    private final String SELECT_TEMPLATE_ZONE_REF = "SELECT t.id, tzr.zone_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, "
+            + "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 INNER JOIN template_zone_ref tzr on (t.id = tzr.template_id) ";
+
     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, "
             + "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";
     protected SearchBuilder<ImageDataVO> TemplateNameSearch;
@@ -111,39 +112,38 @@ public class ImageDataDaoImpl extends GenericDaoBase<ImageDataVO, Long> implemen
     private SearchBuilder<ImageDataVO> UserIsoSearch;
     private GenericSearchBuilder<ImageDataVO, Long> CountTemplatesByAccount;
 
-    ResourceTagsDaoImpl _tagsDao = ComponentLocator.inject(ResourceTagsDaoImpl.class);
-
-
+    //ResourceTagsDaoImpl _tagsDao = ComponentInject.inject(ResourceTagsDaoImpl.class);
+    ResourceTagsDaoImpl _tagsDao = null;
     private String routerTmpltName;
     private String consoleProxyTmpltName;
-    
+
     protected ImageDataDaoImpl() {
     }
-    
+
     @Override
     public List<ImageDataVO> listByPublic() {
-    	SearchCriteria<ImageDataVO> sc = PublicSearch.create();
-    	sc.setParameters("public", 1);
-	    return listBy(sc);
-	}
-    
-	@Override
-	public ImageDataVO findByName(String templateName) {
-		SearchCriteria<ImageDataVO> sc = UniqueNameSearch.create();
-		sc.setParameters("uniqueName", templateName);
-		return findOneIncludingRemovedBy(sc);
-	}
-
-	@Override
-	public ImageDataVO findByTemplateName(String templateName) {
-		SearchCriteria<ImageDataVO> sc = NameSearch.create();
-		sc.setParameters("name", templateName);
-		return findOneIncludingRemovedBy(sc);
-	}
+        SearchCriteria<ImageDataVO> sc = PublicSearch.create();
+        sc.setParameters("public", 1);
+        return listBy(sc);
+    }
+
+    @Override
+    public ImageDataVO findByName(String templateName) {
+        SearchCriteria<ImageDataVO> sc = UniqueNameSearch.create();
+        sc.setParameters("uniqueName", templateName);
+        return findOneIncludingRemovedBy(sc);
+    }
+
+    @Override
+    public ImageDataVO findByTemplateName(String templateName) {
+        SearchCriteria<ImageDataVO> sc = NameSearch.create();
+        sc.setParameters("name", templateName);
+        return findOneIncludingRemovedBy(sc);
+    }
 
     @Override
-    public List<ImageDataVO> publicIsoSearch(Boolean bootable, boolean listRemoved, Map<String, String> tags){
-        
+    public List<ImageDataVO> publicIsoSearch(Boolean bootable, boolean listRemoved, Map<String, String> tags) {
+
         SearchBuilder<ImageDataVO> sb = null;
         if (tags == null || tags.isEmpty()) {
             sb = PublicIsoSearch;
@@ -154,9 +154,9 @@ public class ImageDataDaoImpl extends GenericDaoBase<ImageDataVO, Long> implemen
             sb.and("type", sb.entity().getTemplateType(), SearchCriteria.Op.EQ);
             sb.and("bootable", sb.entity().isBootable(), SearchCriteria.Op.EQ);
             sb.and("removed", sb.entity().getRemoved(), SearchCriteria.Op.EQ);
-            
+
             SearchBuilder<ResourceTagVO> tagSearch = _tagsDao.createSearchBuilder();
-            for (int count=0; count < tags.size(); count++) {
+            for (int count = 0; count < tags.size(); count++) {
                 tagSearch.or().op("key" + String.valueOf(count), tagSearch.entity().getKey(), SearchCriteria.Op.EQ);
                 tagSearch.and("value" + String.valueOf(count), tagSearch.entity().getValue(), SearchCriteria.Op.EQ);
                 tagSearch.cp();
@@ -165,21 +165,21 @@ public class ImageDataDaoImpl extends GenericDaoBase<ImageDataVO, Long> implemen
             sb.groupBy(sb.entity().getId());
             sb.join("tagSearch", tagSearch, sb.entity().getId(), tagSearch.entity().getResourceId(), JoinBuilder.JoinType.INNER);
         }
-        
+
         SearchCriteria<ImageDataVO> sc = sb.create();
-        
-    	sc.setParameters("public", 1);
-    	sc.setParameters("format", "ISO");
-    	sc.setParameters("type", TemplateType.PERHOST.toString());
-    	if (bootable != null) {
-    	    sc.setParameters("bootable", bootable);
-    	}
-    	
-    	if (!listRemoved) {
-    		sc.setParameters("removed", (Object)null);
-    	}
-    	
-    	if (tags != null && !tags.isEmpty()) {
+
+        sc.setParameters("public", 1);
+        sc.setParameters("format", "ISO");
+        sc.setParameters("type", TemplateType.PERHOST.toString());
+        if (bootable != null) {
+            sc.setParameters("bootable", bootable);
+        }
+
+        if (!listRemoved) {
+            sc.setParameters("removed", (Object) null);
+        }
+
+        if (tags != null && !tags.isEmpty()) {
             int count = 0;
             sc.setJoinParameters("tagSearch", "resourceType", TaggedResourceType.ISO.toString());
             for (String key : tags.keySet()) {
@@ -188,12 +188,12 @@ public class ImageDataDaoImpl extends GenericDaoBase<ImageDataVO, Long> implemen
                 count++;
             }
         }
-    	
+
         return listBy(sc);
     }
-    
+
     @Override
-    public List<ImageDataVO> userIsoSearch(boolean listRemoved){
+    public List<ImageDataVO> userIsoSearch(boolean listRemoved) {
 
         SearchBuilder<ImageDataVO> sb = null;
         sb = UserIsoSearch;
@@ -203,25 +203,26 @@ public class ImageDataDaoImpl extends GenericDaoBase<ImageDataVO, Long> implemen
         sc.setParameters("type", TemplateType.USER.toString());
 
         if (!listRemoved) {
-            sc.setParameters("removed", (Object)null);
+            sc.setParameters("removed", (Object) null);
         }
 
         return listBy(sc);
     }
-	@Override
-	public List<ImageDataVO> listAllSystemVMTemplates() {
-		SearchCriteria<ImageDataVO> sc = tmpltTypeSearch.create();
-		sc.setParameters("templateType", Storage.TemplateType.SYSTEM);
-		
-		Filter filter = new Filter(ImageDataVO.class, "id", false, null, null);
-		return listBy(sc, filter);
-	}
+
+    @Override
+    public List<ImageDataVO> listAllSystemVMTemplates() {
+        SearchCriteria<ImageDataVO> sc = tmpltTypeSearch.create();
+        sc.setParameters("templateType", Storage.TemplateType.SYSTEM);
+
+        Filter filter = new Filter(ImageDataVO.class, "id", false, null, null);
+        return listBy(sc, filter);
+    }
 
     @Override
     public List<Long> listPrivateTemplatesByHost(Long hostId) {
 
-        String sql = "select * from template_host_ref as thr INNER JOIN vm_template as t ON t.id=thr.template_id " 
-            + "where thr.host_id=? and t.public=0 and t.featured=0 and t.type='USER' and t.removed is NULL";
+        String sql = "select * from template_host_ref as thr INNER JOIN vm_template as t ON t.id=thr.template_id "
+                + "where thr.host_id=? and t.public=0 and t.featured=0 and t.type='USER' and t.removed is NULL";
 
         List<Long> l = new ArrayList<Long>();
 
@@ -240,140 +241,139 @@ public class ImageDataDaoImpl extends GenericDaoBase<ImageDataVO, Long> implemen
         }
         return l;
     }
-	
-	@Override
-	public List<ImageDataVO> listReadyTemplates() {
-		SearchCriteria<ImageDataVO> sc = createSearchCriteria();
-		sc.addAnd("ready", SearchCriteria.Op.EQ, true);
-		sc.addAnd("format", SearchCriteria.Op.NEQ, Storage.ImageFormat.ISO);
-		return listIncludingRemovedBy(sc);
-	}
-	
-	@Override
-	public List<ImageDataVO> findIsosByIdAndPath(Long domainId, Long accountId, String path) {
-		SearchCriteria<ImageDataVO> sc = createSearchCriteria();
-		sc.addAnd("iso", SearchCriteria.Op.EQ, true);
-		if (domainId != null) {
+
+    @Override
+    public List<ImageDataVO> listReadyTemplates() {
+        SearchCriteria<ImageDataVO> sc = createSearchCriteria();
+        sc.addAnd("ready", SearchCriteria.Op.EQ, true);
+        sc.addAnd("format", SearchCriteria.Op.NEQ, Storage.ImageFormat.ISO);
+        return listIncludingRemovedBy(sc);
+    }
+
+    @Override
+    public List<ImageDataVO> findIsosByIdAndPath(Long domainId, Long accountId, String path) {
+        SearchCriteria<ImageDataVO> sc = createSearchCriteria();
+        sc.addAnd("iso", SearchCriteria.Op.EQ, true);
+        if (domainId != null) {
             sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
         }
-		if (accountId != null) {
+        if (accountId != null) {
             sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
         }
-		if (path != null) {
+        if (path != null) {
             sc.addAnd("path", SearchCriteria.Op.EQ, path);
         }
-		return listIncludingRemovedBy(sc);
-	}
+        return listIncludingRemovedBy(sc);
+    }
 
-	@Override
-	public List<ImageDataVO> listByAccountId(long accountId) {
+    @Override
+    public List<ImageDataVO> listByAccountId(long accountId) {
         SearchCriteria<ImageDataVO> sc = AccountIdSearch.create();
         sc.setParameters("accountId", accountId);
         return listBy(sc);
-	}
-	
-	@Override
+    }
+
+    @Override
     public List<ImageDataVO> listByHypervisorType(List<HypervisorType> hyperTypes) {
-		SearchCriteria<ImageDataVO> sc = createSearchCriteria();
+        SearchCriteria<ImageDataVO> sc = createSearchCriteria();
         hyperTypes.add(HypervisorType.None);
         sc.addAnd("hypervisorType", SearchCriteria.Op.IN, hyperTypes.toArray());
-		return listBy(sc);
-	}
-
-	@Override
-	public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
-		boolean result = super.configure(name, params);
-		
-	    PublicSearch = createSearchBuilder();
-	    PublicSearch.and("public", PublicSearch.entity().isPublicTemplate(), SearchCriteria.Op.EQ);
-
-		routerTmpltName = (String)params.get("routing.uniquename");
-		
-		s_logger.debug("Found parameter routing unique name " + routerTmpltName);
-		if (routerTmpltName==null) {
-			routerTmpltName="routing";
-		}
-		
-		consoleProxyTmpltName = (String)params.get("consoleproxy.uniquename");
-		if(consoleProxyTmpltName == null) {
+        return listBy(sc);
+    }
+
+    @Override
+    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
+        boolean result = super.configure(name, params);
+
+        PublicSearch = createSearchBuilder();
+        PublicSearch.and("public", PublicSearch.entity().isPublicTemplate(), SearchCriteria.Op.EQ);
+
+        routerTmpltName = (String) params.get("routing.uniquename");
+
+        s_logger.debug("Found parameter routing unique name " + routerTmpltName);
+        if (routerTmpltName == null) {
+            routerTmpltName = "routing";
+        }
+
+        consoleProxyTmpltName = (String) params.get("consoleproxy.uniquename");
+        if (consoleProxyTmpltName == null) {
             consoleProxyTmpltName = "routing";
         }
-		if(s_logger.isDebugEnabled()) {
+        if (s_logger.isDebugEnabled()) {
             s_logger.debug("Use console proxy template : " + consoleProxyTmpltName);
         }
 
-		UniqueNameSearch = createSearchBuilder();
-		UniqueNameSearch.and("uniqueName", UniqueNameSearch.entity().getUniqueName(), SearchCriteria.Op.EQ);
-		NameSearch = createSearchBuilder();
-		NameSearch.and("name", NameSearch.entity().getName(), SearchCriteria.Op.EQ);
-
-		NameAccountIdSearch = createSearchBuilder();
-		NameAccountIdSearch.and("name", NameAccountIdSearch.entity().getName(), SearchCriteria.Op.EQ);
-		NameAccountIdSearch.and("accountId", NameAccountIdSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
-
-		PublicIsoSearch = createSearchBuilder();
-		PublicIsoSearch.and("public", PublicIsoSearch.entity().isPublicTemplate(), SearchCriteria.Op.EQ);
-		PublicIsoSearch.and("format", PublicIsoSearch.entity().getFormat(), SearchCriteria.Op.EQ);
-		PublicIsoSearch.and("type", PublicIsoSearch.entity().getTemplateType(), SearchCriteria.Op.EQ);
-		PublicIsoSearch.and("bootable", PublicIsoSearch.entity().isBootable(), SearchCriteria.Op.EQ);
-		PublicIsoSearch.and("removed", PublicIsoSearch.entity().getRemoved(), SearchCriteria.Op.EQ);
-
-		UserIsoSearch = createSearchBuilder();
-		UserIsoSearch.and("format", UserIsoSearch.entity().getFormat(), SearchCriteria.Op.EQ);
-		UserIsoSearch.and("type", UserIsoSearch.entity().getTemplateType(), SearchCriteria.Op.EQ);
-		UserIsoSearch.and("removed", UserIsoSearch.entity().getRemoved(), SearchCriteria.Op.EQ);
-
-		tmpltTypeHyperSearch = createSearchBuilder();
-		tmpltTypeHyperSearch.and("templateType", tmpltTypeHyperSearch.entity().getTemplateType(), SearchCriteria.Op.EQ);
-		SearchBuilder<HostVO> hostHyperSearch = _hostDao.createSearchBuilder();
-		hostHyperSearch.and("type", hostHyperSearch.entity().getType(), SearchCriteria.Op.EQ);
-		hostHyperSearch.and("zoneId", hostHyperSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
-		hostHyperSearch.groupBy(hostHyperSearch.entity().getHypervisorType());
-		
-		tmpltTypeHyperSearch.join("tmplHyper", hostHyperSearch, hostHyperSearch.entity().getHypervisorType(), tmpltTypeHyperSearch.entity().getHypervisorType(), JoinBuilder.JoinType.INNER);
-		hostHyperSearch.done();
-		tmpltTypeHyperSearch.done();
-		
-		tmpltTypeHyperSearch2 = createSearchBuilder();
-		tmpltTypeHyperSearch2.and("templateType", tmpltTypeHyperSearch2.entity().getTemplateType(), SearchCriteria.Op.EQ);
-		tmpltTypeHyperSearch2.and("hypervisorType", tmpltTypeHyperSearch2.entity().getHypervisorType(), SearchCriteria.Op.EQ);
-
-		
-		tmpltTypeSearch = createSearchBuilder();
+        UniqueNameSearch = createSearchBuilder();
+        UniqueNameSearch.and("uniqueName", UniqueNameSearch.entity().getUniqueName(), SearchCriteria.Op.EQ);
+        NameSearch = createSearchBuilder();
+        NameSearch.and("name", NameSearch.entity().getName(), SearchCriteria.Op.EQ);
+
+        NameAccountIdSearch = createSearchBuilder();
+        NameAccountIdSearch.and("name", NameAccountIdSearch.entity().getName(), SearchCriteria.Op.EQ);
+        NameAccountIdSearch.and("accountId", NameAccountIdSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
+
+        PublicIsoSearch = createSearchBuilder();
+        PublicIsoSearch.and("public", PublicIsoSearch.entity().isPublicTemplate(), SearchCriteria.Op.EQ);
+        PublicIsoSearch.and("format", PublicIsoSearch.entity().getFormat(), SearchCriteria.Op.EQ);
+        PublicIsoSearch.and("type", PublicIsoSearch.entity().getTemplateType(), SearchCriteria.Op.EQ);
+        PublicIsoSearch.and("bootable", PublicIsoSearch.entity().isBootable(), SearchCriteria.Op.EQ);
+        PublicIsoSearch.and("removed", PublicIsoSearch.entity().getRemoved(), SearchCriteria.Op.EQ);
+
+        UserIsoSearch = createSearchBuilder();
+        UserIsoSearch.and("format", UserIsoSearch.entity().getFormat(), SearchCriteria.Op.EQ);
+        UserIsoSearch.and("type", UserIsoSearch.entity().getTemplateType(), SearchCriteria.Op.EQ);
+        UserIsoSearch.and("removed", UserIsoSearch.entity().getRemoved(), SearchCriteria.Op.EQ);
+
+        tmpltTypeHyperSearch = createSearchBuilder();
+        tmpltTypeHyperSearch.and("templateType", tmpltTypeHyperSearch.entity().getTemplateType(), SearchCriteria.Op.EQ);
+        SearchBuilder<HostVO> hostHyperSearch = _hostDao.createSearchBuilder();
+        hostHyperSearch.and("type", hostHyperSearch.entity().getType(), SearchCriteria.Op.EQ);
+        hostHyperSearch.and("zoneId", hostHyperSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
+        hostHyperSearch.groupBy(hostHyperSearch.entity().getHypervisorType());
+
+        tmpltTypeHyperSearch.join("tmplHyper", hostHyperSearch, hostHyperSearch.entity().getHypervisorType(), tmpltTypeHyperSearch.entity().getHypervisorType(), JoinBuilder.JoinType.INNER);
+        hostHyperSearch.done();
+        tmpltTypeHyperSearch.done();
+
+        tmpltTypeHyperSearch2 = createSearchBuilder();
+        tmpltTypeHyperSearch2.and("templateType", tmpltTypeHyperSearch2.entity().getTemplateType(), SearchCriteria.Op.EQ);
+        tmpltTypeHyperSearch2.and("hypervisorType", tmpltTypeHyperSearch2.entity().getHypervisorType(), SearchCriteria.Op.EQ);
+
+        tmpltTypeSearch = createSearchBuilder();
         tmpltTypeSearch.and("removed", tmpltTypeSearch.entity().getRemoved(), SearchCriteria.Op.NULL);
-		tmpltTypeSearch.and("templateType", tmpltTypeSearch.entity().getTemplateType(), SearchCriteria.Op.EQ);
+        tmpltTypeSearch.and("templateType", tmpltTypeSearch.entity().getTemplateType(), SearchCriteria.Op.EQ);
 
-		AccountIdSearch = createSearchBuilder();
-		AccountIdSearch.and("accountId", AccountIdSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
+        AccountIdSearch = createSearchBuilder();
+        AccountIdSearch.and("accountId", AccountIdSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
         AccountIdSearch.and("publicTemplate", AccountIdSearch.entity().isPublicTemplate(), SearchCriteria.Op.EQ);
-		AccountIdSearch.done();
-		
-		SearchBuilder<VMTemplateZoneVO> tmpltZoneSearch = _templateZoneDao.createSearchBuilder();
-		tmpltZoneSearch.and("removed", tmpltZoneSearch.entity().getRemoved(), SearchCriteria.Op.NULL);
-		tmpltZoneSearch.and("zoneId", tmpltZoneSearch.entity().getZoneId(), SearchCriteria.Op.EQ);
-		
-		TmpltsInZoneSearch = createSearchBuilder();
-		TmpltsInZoneSearch.and("removed", TmpltsInZoneSearch.entity().getRemoved(), SearchCriteria.Op.NULL);
-		TmpltsInZoneSearch.and().op("avoidtype", TmpltsInZoneSearch.entity().getTemplateType(), SearchCriteria.Op.NEQ);
-		TmpltsInZoneSearch.or("templateType", TmpltsInZoneSearch.entity().getTemplateType(), SearchCriteria.Op.NULL);
-		TmpltsInZoneSearch.cp();
-		TmpltsInZoneSearch.join("tmpltzone", tmpltZoneSearch, tmpltZoneSearch.entity().getTemplateId(), TmpltsInZoneSearch.entity().getId(), JoinBuilder.JoinType.INNER);
-		tmpltZoneSearch.done();
-		TmpltsInZoneSearch.done();
-
-		CountTemplatesByAccount = createSearchBuilder(Long.class);
-		CountTemplatesByAccount.select(null, Func.COUNT, null);        
-		CountTemplatesByAccount.and("account", CountTemplatesByAccount.entity().getAccountId(), SearchCriteria.Op.EQ);
-		CountTemplatesByAccount.and("removed", CountTemplatesByAccount.entity().getRemoved(), SearchCriteria.Op.NULL);
-		CountTemplatesByAccount.done();
-
-		return result;
-	}
-
-	@Override
-	public String getRoutingTemplateUniqueName() {
-		return routerTmpltName;
-	}
+        AccountIdSearch.done();
+
+        SearchBuilder<VMTemplateZoneVO> tmpltZoneSearch = _templateZoneDao.createSearchBuilder();
+        tmpltZoneSearch.and("removed", tmpltZoneSearch.entity().getRemoved(), SearchCriteria.Op.NULL);
+        tmpltZoneSearch.and("zoneId", tmpltZoneSearch.entity().getZoneId(), SearchCriteria.Op.EQ);
+
+        TmpltsInZoneSearch = createSearchBuilder();
+        TmpltsInZoneSearch.and("removed", TmpltsInZoneSearch.entity().getRemoved(), SearchCriteria.Op.NULL);
+        TmpltsInZoneSearch.and().op("avoidtype", TmpltsInZoneSearch.entity().getTemplateType(), SearchCriteria.Op.NEQ);
+        TmpltsInZoneSearch.or("templateType", TmpltsInZoneSearch.entity().getTemplateType(), SearchCriteria.Op.NULL);
+        TmpltsInZoneSearch.cp();
+        TmpltsInZoneSearch.join("tmpltzone", tmpltZoneSearch, tmpltZoneSearch.entity().getTemplateId(), TmpltsInZoneSearch.entity().getId(), JoinBuilder.JoinType.INNER);
+        tmpltZoneSearch.done();
+        TmpltsInZoneSearch.done();
+
+        CountTemplatesByAccount = createSearchBuilder(Long.class);
+        CountTemplatesByAccount.select(null, Func.COUNT, null);
+        CountTemplatesByAccount.and("account", CountTemplatesByAccount.entity().getAccountId(), SearchCriteria.Op.EQ);
+        CountTemplatesByAccount.and("removed", CountTemplatesByAccount.entity().getRemoved(), SearchCriteria.Op.NULL);
+        CountTemplatesByAccount.done();
+
+        return result;
+    }
+
+    @Override
+    public String getRoutingTemplateUniqueName() {
+        return routerTmpltName;
+    }
 
     @Override
     public Set<Pair<Long, Long>> searchSwiftTemplates(String name, String keyword, TemplateFilter templateFilter, boolean isIso, List<HypervisorType> hypers, Boolean bootable, DomainVO domain,
@@ -493,29 +493,27 @@ public class ImageDataDaoImpl extends GenericDaoBase<ImageDataVO, Long> implemen
         return templateZonePairList;
     }
 
-
-	@Override
-	public Set<Pair<Long, Long>> searchTemplates(String name, String keyword, TemplateFilter templateFilter, 
-	        boolean isIso, List<HypervisorType> hypers, Boolean bootable, DomainVO domain, Long pageSize, Long startIndex,
-	        Long zoneId, HypervisorType hyperType, boolean onlyReady, boolean showDomr,List<Account> permittedAccounts,
-	        Account caller, ListProjectResourcesCriteria listProjectResourcesCriteria, Map<String, String> tags) {
+    @Override
+    public Set<Pair<Long, Long>> searchTemplates(String name, String keyword, TemplateFilter templateFilter, boolean isIso, List<HypervisorType> hypers, Boolean bootable, DomainVO domain,
+            Long pageSize, Long startIndex, Long zoneId, HypervisorType hyperType, boolean onlyReady, boolean showDomr, List<Account> permittedAccounts, Account caller,
+            ListProjectResourcesCriteria listProjectResourcesCriteria, Map<String, String> tags) {
         StringBuilder builder = new StringBuilder();
         if (!permittedAccounts.isEmpty()) {
             for (Account permittedAccount : permittedAccounts) {
                 builder.append(permittedAccount.getAccountId() + ",");
             }
         }
-        
+
         String permittedAccountsStr = builder.toString();
-        
+
         if (permittedAccountsStr.length() > 0) {
-            //chop the "," off
-            permittedAccountsStr = permittedAccountsStr.substring(0, permittedAccountsStr.length()-1);
+            // chop the "," off
+            permittedAccountsStr = permittedAccountsStr.substring(0, permittedAccountsStr.length() - 1);
         }
-	    
-	    Transaction txn = Transaction.currentTxn();
+
+        Transaction txn = Transaction.currentTxn();
         txn.start();
-        
+
         /* Use LinkedHashSet here to guarantee iteration order */
         Set<Pair<Long, Long>> templateZonePairList = new LinkedHashSet<Pair<Long, Long>>();
         PreparedStatement pstmt = null;
@@ -523,57 +521,57 @@ public class ImageDataDaoImpl extends GenericDaoBase<ImageDataVO, Long> implemen
         StringBuilder relatedDomainIds = new StringBuilder();
         String sql = SELECT_TEMPLATE_ZONE_REF;
         String groupByClause = "";
-        try {        	
-        	//short accountType;
-        	//String accountId = null;
-        	String guestOSJoin = "";  
-        	StringBuilder templateHostRefJoin = new StringBuilder();
-        	String dataCenterJoin = "", lpjoin = "";
-        	String tagsJoin = "";
-
-        	if (isIso && !hyperType.equals(HypervisorType.None)) { 
-        		guestOSJoin = " INNER JOIN guest_os guestOS on (guestOS.id = t.guest_os_id) INNER JOIN guest_os_hypervisor goh on ( goh.guest_os_id = guestOS.id) ";
-        	}
-        	if (onlyReady){
-        		templateHostRefJoin.append(" INNER JOIN  template_host_ref thr on (t.id = thr.template_id) INNER JOIN host h on (thr.host_id = h.id)");
-        		sql = SELECT_TEMPLATE_HOST_REF;
+        try {
+            // short accountType;
+            // String accountId = null;
+            String guestOSJoin = "";
+            StringBuilder templateHostRefJoin = new StringBuilder();
+            String dataCenterJoin = "", lpjoin = "";
+            String tagsJoin = "";
+
+            if (isIso && !hyperType.equals(HypervisorType.None)) {
+                guestOSJoin = " INNER JOIN guest_os guestOS on (guestOS.id = t.guest_os_id) INNER JOIN guest_os_hypervisor goh on ( goh.guest_os_id = guestOS.id) ";
+            }
+            if (onlyReady) {
+                templateHostRefJoin.append(" INNER JOIN  template_host_ref thr on (t.id = thr.template_id) INNER JOIN host h on (thr.host_id = h.id)");
+                sql = SELECT_TEMPLATE_HOST_REF;
                 groupByClause = " GROUP BY t.id, h.data_center_id ";
-        	}
-        	if ((templateFilter == TemplateFilter.featured) || (templateFilter == TemplateFilter.community)) {
-        	    dataCenterJoin = " INNER JOIN data_center dc on (h.data_center_id = dc.id)";
-        	}
-        	
-        	if (templateFilter == TemplateFilter.sharedexecutable){
-        	    lpjoin = " INNER JOIN launch_permission lp ON t.id = lp.template_id ";
-        	}
-        	
-        	if (tags != null && !tags.isEmpty()) {
-        	    tagsJoin = " INNER JOIN resource_tags r ON t.id = r.resource_id ";
-        	}
-        	       	
-        	sql +=  guestOSJoin + templateHostRefJoin + dataCenterJoin + lpjoin + tagsJoin;
-        	String whereClause = "";
-        	
-        	//All joins have to be made before we start setting the condition settings
-        	if ((listProjectResourcesCriteria == ListProjectResourcesCriteria.SkipProjectResources 
-        			|| (!permittedAccounts.isEmpty() && !(templateFilter == TemplateFilter.community || templateFilter == TemplateFilter.featured))) && 
-        			!(caller.getType() != Account.ACCOUNT_TYPE_NORMAL && templateFilter == TemplateFilter.all)) {
-        		whereClause += " INNER JOIN account a on (t.account_id = a.id)";
-        		if ((templateFilter == TemplateFilter.self || templateFilter == TemplateFilter.selfexecutable) && (caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN)) {                	            		
-            		 whereClause += " INNER JOIN domain d on (a.domain_id = d.id) WHERE d.path LIKE '" + domain.getPath() + "%'";     
-             		if (listProjectResourcesCriteria == ListProjectResourcesCriteria.SkipProjectResources) {
-            			whereClause += " AND a.type != " + Account.ACCOUNT_TYPE_PROJECT;
-            		}
-        		} else 
-        			if (listProjectResourcesCriteria == ListProjectResourcesCriteria.SkipProjectResources) {
-        				whereClause += " WHERE a.type != " + Account.ACCOUNT_TYPE_PROJECT;
-        		}
-        	}
-        	
+            }
+            if ((templateFilter == TemplateFilter.featured) || (templateFilter == TemplateFilter.community)) {
+                dataCenterJoin = " INNER JOIN data_center dc on (h.data_center_id = dc.id)";
+            }
+
+            if (templateFilter == TemplateFilter.sharedexecutable) {
+                lpjoin = " INNER JOIN launch_permission lp ON t.id = lp.template_id ";
+            }
+
+            if (tags != null && !tags.isEmpty()) {
+                tagsJoin = " INNER JOIN resource_tags r ON t.id = r.resource_id ";
+            }
+
+            sql += guestOSJoin + templateHostRefJoin + dataCenterJoin + lpjoin + tagsJoin;
+            String whereClause = "";
+
+            // All joins have to be made before we start setting the condition
+            // settings
+            if ((listProjectResourcesCriteria == ListProjectResourcesCriteria.SkipProjectResources || (!permittedAccounts.isEmpty() && !(templateFilter == TemplateFilter.community || templateFilter == TemplateFilter.featured)))
+                    && !(caller.getType() != Account.ACCOUNT_TYPE_NORMAL && templateFilter == TemplateFilter.all)) {
+                whereClause += " INNER JOIN account a on (t.account_id = a.id)";
+                if ((templateFilter == TemplateFilter.self || templateFilter == TemplateFilter.selfexecutable)
+                        && (caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN)) {
+                    whereClause += " INNER JOIN domain d on (a.domain_id = d.id) WHERE d.path LIKE '" + domain.getPath() + "%'";
+                    if (listProjectResourcesCriteria == ListProjectResourcesCriteria.SkipProjectResources) {
+                        whereClause += " AND a.type != " + Account.ACCOUNT_TYPE_PROJECT;
+                    }
+                } else if (listProjectResourcesCriteria == ListProjectResourcesCriteria.SkipProjectResources) {
+                    whereClause += " WHERE a.type != " + Account.ACCOUNT_TYPE_PROJECT;
+                }
+            }
+
             if (!permittedAccounts.isEmpty()) {
                 for (Account account : permittedAccounts) {
-                    //accountType = account.getType();
-                    //accountId = Long.toString(account.getId());
+                    // accountType = account.getType();
+                    // accountId = Long.toString(account.getId());
                     DomainVO accountDomain = _domainDao.findById(account.getDomainId());
 
                     // get all parent domain ID's all the way till root domain
@@ -589,148 +587,154 @@ public class ImageDataDaoImpl extends GenericDaoBase<ImageDataVO, Long> implemen
                     }
 
                     // get all child domain ID's
-                    if (isAdmin(account.getType()) ) {
+                    if (isAdmin(account.getType())) {
                         List<DomainVO> allChildDomains = _domainDao.findAllChildren(accountDomain.getPath(), accountDomain.getId());
                         for (DomainVO childDomain : allChildDomains) {
                             relatedDomainIds.append(childDomain.getId());
                             relatedDomainIds.append(",");
                         }
                     }
-                    relatedDomainIds.setLength(relatedDomainIds.length()-1);
+                    relatedDomainIds.setLength(relatedDomainIds.length() - 1);
                 }
             }
-            
+
             String attr = " AND ";
             if (whereClause.endsWith(" WHERE ")) {
-            	attr += " WHERE ";
+                attr += " WHERE ";
             }
-            
+
             if (!isIso) {
-        	    if ( hypers.isEmpty() ) {
-        	        return templateZonePairList;
-        	    } else {
-        	        StringBuilder relatedHypers = new StringBuilder();
-        	        for (HypervisorType hyper : hypers ) {
-        	            relatedHypers.append("'");
-        	            relatedHypers.append(hyper.toString());
+                if (hypers.isEmpty()) {
+                    return templateZonePairList;
+                } else {
+                    StringBuilder relatedHypers = new StringBuilder();
+                    for (HypervisorType hyper : hypers) {
+                        relatedHypers.append("'");
+                        relatedHypers.append(hyper.toString());
                         relatedHypers.append("'");
-        	            relatedHypers.append(",");
-        	        }
-        	        relatedHypers.setLength(relatedHypers.length()-1);
+                        relatedHypers.append(",");
+                    }
+                    relatedHypers.setLength(relatedHypers.length() - 1);
                     whereClause += attr + " t.hypervisor_type IN (" + relatedHypers + ")";
-        	    }
-        	}
-            
-            if (!permittedAccounts.isEmpty() && !(templateFilter == TemplateFilter.featured || 
-                    templateFilter == TemplateFilter.community || templateFilter == TemplateFilter.executable)  && !isAdmin(caller.getType()) ) {
-            	whereClause += attr + "t.account_id IN (" + permittedAccountsStr + ")";
-            }
-
-        	if (templateFilter == TemplateFilter.featured) {
-            	whereClause += attr + "t.public = 1 AND t.featured = 1";
-            	if (!permittedAccounts.isEmpty()) {
-            	    whereClause += attr + "(dc.domain_id IN (" + relatedDomainIds + ") OR dc.domain_id is NULL)";
-            	}            	            
+                }
+            }
+
+            if (!permittedAccounts.isEmpty() && !(templateFilter == TemplateFilter.featured || templateFilter == TemplateFilter.community || templateFilter == TemplateFilter.executable)
+                    && !isAdmin(caller.getType())) {
+                whereClause += attr + "t.account_id IN (" + permittedAccountsStr + ")";
+            }
+
+            if (templateFilter == TemplateFilter.featured) {
+                whereClause += attr + "t.public = 1 AND t.featured = 1";
+                if (!permittedAccounts.isEmpty()) {
+                    whereClause += attr + "(dc.domain_id IN (" + relatedDomainIds + ") OR dc.domain_id is NULL)";
+                }
             } else if (templateFilter == TemplateFilter.self || templateFilter == TemplateFilter.selfexecutable) {
                 whereClause += " AND t.account_id IN (" + permittedAccountsStr + ")";
             } else if (templateFilter == TemplateFilter.sharedexecutable) {
-            		whereClause += " AND " +
-                	" (t.account_id IN (" + permittedAccountsStr + ") OR" +
-                	" lp.account_id IN (" + permittedAccountsStr + "))";	
+                whereClause += " AND " + " (t.account_id IN (" + permittedAccountsStr + ") OR" + " lp.account_id IN (" + permittedAccountsStr + "))";
             } else if (templateFilter == TemplateFilter.executable && !permittedAccounts.isEmpty()) {
-            	whereClause += attr + "(t.public = 1 OR t.account_id IN (" + permittedAccountsStr + "))";
+                whereClause += attr + "(t.public = 1 OR t.account_id IN (" + permittedAccountsStr + "))";
             } else if (templateFilter == TemplateFilter.community) {
-            	whereClause += attr + "t.public = 1 AND t.featured = 0";
-            	if (!permittedAccounts.isEmpty()) {
-            	    whereClause += attr + "(dc.domain_id IN (" + relatedDomainIds + ") OR dc.domain_id is NULL)";
-            	}
+                whereClause += attr + "t.public = 1 AND t.featured = 0";
+                if (!permittedAccounts.isEmpty()) {
+                    whereClause += attr + "(dc.domain_id IN (" + relatedDomainIds + ") OR dc.domain_id is NULL)";
+                }
             } else if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN && !isIso) {
-            	return templateZonePairList;
-            }
-        	
-        	if (tags != null && !tags.isEmpty()) {
-        	    whereClause += " AND (";
-        	    boolean first = true;
-        	    for (String key : tags.keySet()) {
-        	        if (!first) {
-        	            whereClause += " OR ";
-        	        }
-        	        whereClause += "(r.key=\"" + key + "\" and r.value=\"" + tags.get(key) + "\")";
-        	        first = false;
-        	    }
-        	    whereClause += ")";
-        	}
-            
+                return templateZonePairList;
+            }
+
+            if (tags != null && !tags.isEmpty()) {
+                whereClause += " AND (";
+                boolean first = true;
+                for (String key : tags.keySet()) {
+                    if (!first) {
+                        whereClause += " OR ";
+                    }
+                    whereClause += "(r.key=\"" + key + "\" and r.value=\"" + tags.get(key) + "\")";
+                    first = false;
+                }
+                whereClause += ")";
+            }
+
             if (whereClause.equals("")) {
-            	whereClause += " WHERE ";
+                whereClause += " WHERE ";
             } else if (!whereClause.equals(" WHERE ")) {
-            	whereClause += " AND ";
+                whereClause += " AND ";
             }
-            
-            sql += whereClause + getExtrasWhere(templateFilter, name, keyword, isIso, bootable, hyperType, zoneId,
-                    onlyReady, showDomr) + groupByClause + getOrderByLimit(pageSize, startIndex);
+
+            sql += whereClause + getExtrasWhere(templateFilter, name, keyword, isIso, bootable, hyperType, zoneId, onlyReady, showDomr) + groupByClause + getOrderByLimit(pageSize, startIndex);
 
             pstmt = txn.prepareStatement(sql);
             rs = pstmt.executeQuery();
 
             while (rs.next()) {
-               Pair<Long, Long> templateZonePair = new Pair<Long, Long>(rs.getLong(1), rs.getLong(2));
-                               templateZonePairList.add(templateZonePair);
+                Pair<Long, Long> templateZonePair = new Pair<Long, Long>(rs.getLong(1), rs.getLong(2));
+                templateZonePairList.add(templateZonePair);
             }
-           //for now, defaulting pageSize to a large val if null; may need to revisit post 2.2RC2 
-           if(isIso && templateZonePairList.size() < (pageSize != null ? pageSize : 500) 
-                   && templateFilter != TemplateFilter.community
-                   && !(templateFilter == TemplateFilter.self && !BaseCmd.isRootAdmin(caller.getType())) ){ //evaluates to true If root admin and filter=self
-
-               List<ImageDataVO> publicIsos = publicIsoSearch(bootable, false, tags);
-               List<ImageDataVO> userIsos = userIsoSearch(false);
-
-               //Listing the ISOs according to the page size.Restricting the total no. of ISOs on a page
-               //to be less than or equal to the pageSize parameter
-
-               int i=0;
-
-               if (startIndex > userIsos.size()) {
-                   i=(int) (startIndex - userIsos.size());
-               }
+            // for now, defaulting pageSize to a large val if null; may need to
+            // revisit post 2.2RC2
+            if (isIso && templateZonePairList.size() < (pageSize != null ? pageSize : 500) && templateFilter != TemplateFilter.community
+                    && !(templateFilter == TemplateFilter.self && !BaseCmd.isRootAdmin(caller.getType()))) { // evaluates
+                                                                                                             // to
+                                                                                                             // true
+                                                                                                             // If
+                                                                                                             // root
+                                                                                                             // admin
+                                                                                                             // and
+                                                                                                             // filter=self
+
+                List<ImageDataVO> publicIsos = publicIsoSearch(bootable, false, tags);
+                List<ImageDataVO> userIsos = userIsoSearch(false);
+
+                // Listing the ISOs according to the page size.Restricting the
+                // total no. of ISOs on a page
+                // to be less than or equal to the pageSize parameter
+
+                int i = 0;
+
+                if (startIndex > userIsos.size()) {
+                    i = (int) (startIndex - userIsos.size());
+                }
 
-               for (; i < publicIsos.size(); i++) {
-                   if(templateZonePairList.size() >= pageSize){
+                for (; i < publicIsos.size(); i++) {
+                    if (templateZonePairList.size() >= pageSize) {
                         break;
-                        } else {
+                    } else {
                         if (keyword != null && publicIsos.get(i).getName().contains(keyword)) {
-                            templateZonePairList.add(new Pair<Long,Long>(publicIsos.get(i).getId(), null));
+                            templateZonePairList.add(new Pair<Long, Long>(publicIsos.get(i).getId(), null));
                             continue;
                         } else if (name != null && publicIsos.get(i).getName().contains(name)) {
-                            templateZonePairList.add(new Pair<Long,Long>(publicIsos.get(i).getId(), null));
+                            templateZonePairList.add(new Pair<Long, Long>(publicIsos.get(i).getId(), null));
                             continue;
-                        } else if (keyword == null && name == null){
-                            templateZonePairList.add(new Pair<Long,Long>(publicIsos.get(i).getId(), null));
+                        } else if (keyword == null && name == null) {
+                            templateZonePairList.add(new Pair<Long, Long>(publicIsos.get(i).getId(), null));
                         }
-                      }
                     }
                 }
+            }
         } catch (Exception e) {
             s_logger.warn("Error listing templates", e);
         } finally {
-        	try {
-        		if (rs != null) {
-        			rs.close();
-        		}
-        		if (pstmt != null) {
-        			pstmt.close();
-        		}
-        		txn.commit();
-        	} catch( SQLException sqle) {
-        		s_logger.warn("Error in cleaning up", sqle);
-        	}
-        }
-        
+            try {
+                if (rs != null) {
+                    rs.close();
+                }
+                if (pstmt != null) {
+                    pstmt.close();
+                }
+                txn.commit();
+            } catch (SQLException sqle) {
+                s_logger.warn("Error in cleaning up", sqle);
+            }
+        }
+
         return templateZonePairList;
-	}
+    }
 
-	private String getExtrasWhere(TemplateFilter templateFilter, String name, String keyword, boolean isIso, Boolean bootable, HypervisorType hyperType, Long zoneId, boolean onlyReady, boolean showDomr) {
-	    String sql = "";
+    private String getExtrasWhere(TemplateFilter templateFilter, String name, String keyword, boolean isIso, Boolean bootable, HypervisorType hyperType, Long zoneId, boolean onlyReady,
+            boolean showDomr) {
+        String sql = "";
         if (keyword != null) {
             sql += " t.name LIKE \"%" + keyword + "%\" AND";
         } else if (name != null) {
@@ -740,159 +744,161 @@ public class ImageDataDaoImpl extends GenericDaoBase<ImageDataVO, Long> implemen
         if (isIso) {
             sql += " t.format = 'ISO'";
             if (!hyperType.equals(HypervisorType.None)) {
-            	sql += " AND goh.hypervisor_type = '" + hyperType.toString() + "'";
+                sql += " AND goh.hypervisor_type = '" + hyperType.toString() + "'";
             }
         } else {
             sql += " t.format <> 'ISO'";
             if (!hyperType.equals(HypervisorType.None)) {
-            	sql += " AND t.hypervisor_type = '" + hyperType.toString() + "'";
+                sql += " AND t.hypervisor_type = '" + hyperType.toString() + "'";
             }
         }
-        
+
         if (bootable != null) {
-        	sql += " AND t.bootable = " + bootable;
+            sql += " AND t.bootable = " + bootable;
         }
 
-        if (onlyReady){
-        	sql += " AND thr.download_state = '" +Status.DOWNLOADED.toString() + "'" + " AND thr.destroyed=0 ";
-        	if (zoneId != null){
-        		sql += " AND h.data_center_id = " +zoneId;
+        if (onlyReady) {
+            sql += " AND thr.download_state = '" + Status.DOWNLOADED.toString() + "'" + " AND thr.destroyed=0 ";
+            if (zoneId != null) {
+                sql += " AND h.data_center_id = " + zoneId;
             }
-        }else if (zoneId != null){
-        	sql += " AND tzr.zone_id = " +zoneId+ " AND tzr.removed is null" ;
-        }else{
-        	sql += " AND tzr.removed is null ";
+        } else if (zoneId != null) {
+            sql += " AND tzr.zone_id = " + zoneId + " AND tzr.removed is null";
+        } else {
+            sql += " AND tzr.removed is null ";
+        }
+        if (!showDomr) {
+            sql += " AND t.type != '" + Storage.TemplateType.SYSTEM.toString() + "'";
         }
-        if (!showDomr){
-        	sql += " AND t.type != '" +Storage.TemplateType.SYSTEM.toString() + "'";
-        }        
 
         sql += " AND t.removed IS NULL";
 
         return sql;
-	}
-
-	private String getOrderByLimit(Long pageSize, Long startIndex) {
-    	Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm"));
-    	isAscending = (isAscending == null ? true : isAscending);
-    	
-		String sql;
-		if (isAscending) {
-			sql = " ORDER BY t.sort_key ASC";
-		} else {
-			sql = " ORDER BY t.sort_key DESC";
-		}
-    	
+    }
+
+    private String getOrderByLimit(Long pageSize, Long startIndex) {
+        Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm"));
+        isAscending = (isAscending == null ? true : isAscending);
+
+        String sql;
+        if (isAscending) {
+            sql = " ORDER BY t.sort_key ASC";
+        } else {
+            sql = " ORDER BY t.sort_key DESC";
+        }
+
         if ((pageSize != null) && (startIndex != null)) {
             sql += " LIMIT " + startIndex.toString() + "," + pageSize.toString();
         }
         return sql;
-	}
-
-	@Override
-	@DB
-	public long addTemplateToZone(ImageDataVO tmplt, long zoneId) {
-		Transaction txn = Transaction.currentTxn();
-		txn.start();
-		ImageDataVO tmplt2 = findById(tmplt.getId());
-		if (tmplt2 == null){
-			if (persist(tmplt) == null) {
-				throw new CloudRuntimeException("Failed to persist the template " + tmplt);
-			}
-			if(tmplt.getDetails() != null) {
-				_templateDetailsDao.persist(tmplt.getId(), tmplt.getDetails());
-			}
-		}
-		VMTemplateZoneVO tmpltZoneVO = _templateZoneDao.findByZoneTemplate(zoneId, tmplt.getId());
-		if (tmpltZoneVO == null ) {
-		    tmpltZoneVO = new VMTemplateZoneVO(zoneId, tmplt.getId(), new Date());
-		    _templateZoneDao.persist(tmpltZoneVO);
-		} else {
-		    tmpltZoneVO.setRemoved(null);
-		    tmpltZoneVO.setLastUpdated(new Date());
-		    _templateZoneDao.update(tmpltZoneVO.getId(), tmpltZoneVO);
-		}
-		txn.commit();
-		
-		return tmplt.getId();
-	}
-
-	@Override
-	@DB
-	public List<ImageDataVO> listAllInZone(long dataCenterId) {
-		SearchCriteria<ImageDataVO> sc = TmpltsInZoneSearch.create();
-		sc.setParameters("avoidtype", TemplateType.PERHOST.toString());
-		sc.setJoinParameters("tmpltzone", "zoneId", dataCenterId);
-		return listBy(sc);
-	}
-
-	@Override
-	public List<ImageDataVO> listDefaultBuiltinTemplates() {
-		SearchCriteria<ImageDataVO> sc = tmpltTypeSearch.create();
-		sc.setParameters("templateType", Storage.TemplateType.BUILTIN);
-		return listBy(sc);
-	}
-	
-	@Override
-	public ImageDataVO findSystemVMTemplate(long zoneId) {
-		SearchCriteria<ImageDataVO> sc = tmpltTypeHyperSearch.create();
-		sc.setParameters("templateType", Storage.TemplateType.SYSTEM);
-		sc.setJoinParameters("tmplHyper",  "type", Host.Type.Routing);
-		sc.setJoinParameters("tmplHyper", "zoneId", zoneId);
-
-		//order by descending order of id and select the first (this is going to be the latest)
-		List<ImageDataVO> tmplts = listBy(sc, new Filter(ImageDataVO.class, "id", false, null, 1l));
-		
-		if (tmplts.size() > 0) {
-			return tmplts.get(0);
-		} else {
-			return null;
-		}
-	}
-	
-	public ImageDataVO findSystemVMTemplate(long zoneId, HypervisorType hType) {
-	    SearchCriteria<ImageDataVO> sc = tmpltTypeHyperSearch.create();
-	    sc.setParameters("templateType", Storage.TemplateType.SYSTEM);
-	    sc.setJoinParameters("tmplHyper",  "type", Host.Type.Routing);
-	    sc.setJoinParameters("tmplHyper", "zoneId", zoneId);
-
-	    //order by descending order of id
-	    List<ImageDataVO> tmplts = listBy(sc, new Filter(ImageDataVO.class, "id", false, null, null));
-
-	    for (ImageDataVO tmplt: tmplts) {
-	        if (tmplt.getHypervisorType() == hType) {
-	            return tmplt;
-	        }
-	    }
-	    if (tmplts.size() > 0 && hType == HypervisorType.Any) {
-	        return tmplts.get(0);
-	    }
-	    return null;
-	}
-
-	@Override
-	public ImageDataVO findRoutingTemplate(HypervisorType hType) {
-	    SearchCriteria<ImageDataVO> sc = tmpltTypeHyperSearch2.create();
+    }
+
+    @Override
+    @DB
+    public long addTemplateToZone(ImageDataVO tmplt, long zoneId) {
+        Transaction txn = Transaction.currentTxn();
+        txn.start();
+        ImageDataVO tmplt2 = findById(tmplt.getId());
+        if (tmplt2 == null) {
+            if (persist(tmplt) == null) {
+                throw new CloudRuntimeException("Failed to persist the template " + tmplt);
+            }
+            if (tmplt.getDetails() != null) {
+                _templateDetailsDao.persist(tmplt.getId(), tmplt.getDetails());
+            }
+        }
+        VMTemplateZoneVO tmpltZoneVO = _templateZoneDao.findByZoneTemplate(zoneId, tmplt.getId());
+        if (tmpltZoneVO == null) {
+            tmpltZoneVO = new VMTemplateZoneVO(zoneId, tmplt.getId(), new Date());
+            _templateZoneDao.persist(tmpltZoneVO);
+        } else {
+            tmpltZoneVO.setRemoved(null);
+            tmpltZoneVO.setLastUpdated(new Date());
+            _templateZoneDao.update(tmpltZoneVO.getId(), tmpltZoneVO);
+        }
+        txn.commit();
+
+        return tmplt.getId();
+    }
+
+    @Override
+    @DB
+    public List<ImageDataVO> listAllInZone(long dataCenterId) {
+        SearchCriteria<ImageDataVO> sc = TmpltsInZoneSearch.create();
+        sc.setParameters("avoidtype", TemplateType.PERHOST.toString());
+        sc.setJoinParameters("tmpltzone", "zoneId", dataCenterId);
+        return listBy(sc);
+    }
+
+    @Override
+    public List<ImageDataVO> listDefaultBuiltinTemplates() {
+        SearchCriteria<ImageDataVO> sc = tmpltTypeSearch.create();
+        sc.setParameters("templateType", Storage.TemplateType.BUILTIN);
+        return listBy(sc);
+    }
+
+    @Override
+    public ImageDataVO findSystemVMTemplate(long zoneId) {
+        SearchCriteria<ImageDataVO> sc = tmpltTypeHyperSearch.create();
+        sc.setParameters("templateType", Storage.TemplateType.SYSTEM);
+        sc.setJoinParameters("tmplHyper", "type", Host.Type.Routing);
+        sc.setJoinParameters("tmplHyper", "zoneId", zoneId);
+
+        // order by descending order of id and select the first (this is going
+        // to be the latest)
+        List<ImageDataVO> tmplts = listBy(sc, new Filter(ImageDataVO.class, "id", false, null, 1l));
+
+        if (tmplts.size() > 0) {
+            return tmplts.get(0);
+        } else {
+            return null;
+        }
+    }
+
+    public ImageDataVO findSystemVMTemplate(long zoneId, HypervisorType hType) {
+        SearchCriteria<ImageDataVO> sc = tmpltTypeHyperSearch.create();
+        sc.setParameters("templateType", Storage.TemplateType.SYSTEM);
+        sc.setJoinParameters("tmplHyper", "type", Host.Type.Routing);
+        sc.setJoinParameters("tmplHyper", "zoneId", zoneId);
+
+        // order by descending order of id
+        List<ImageDataVO> tmplts = listBy(sc, new Filter(ImageDataVO.class, "id", false, null, null));
+
+        for (ImageDataVO tmplt : tmplts) {
+            if (tmplt.getHypervisorType() == hType) {
+                return tmplt;
+            }
+        }
+        if (tmplts.size() > 0 && hType == HypervisorType.Any) {
+            return tmplts.get(0);
+        }
+        return null;
+    }
+
+    @Override
+    public ImageDataVO findRoutingTemplate(HypervisorType hType) {
+        SearchCriteria<ImageDataVO> sc = tmpltTypeHyperSearch2.create();
         sc.setParameters("templateType", Storage.TemplateType.SYSTEM);
         sc.setParameters("hypervisorType", hType);
 
-        //order by descending order of id and select the first (this is going to be the latest)
+        // order by descending order of id and select the first (this is going
+        // to be the latest)
         List<ImageDataVO> tmplts = listBy(sc, new Filter(ImageDataVO.class, "id", false, null, 1l));
-        
+
         if (tmplts.size() > 0) {
             return tmplts.get(0);
         } else {
             return null;
         }
-	}
+    }
 
     @Override
     public Long countTemplatesForAccount(long accountId) {
-    	SearchCriteria<Long> sc = CountTemplatesByAccount.create();
+        SearchCriteria<Long> sc = CountTemplatesByAccount.create();
         sc.setParameters("account", accountId);
         return customSearch(sc, null).get(0);
     }
-    
+
     @Override
     @DB
     public boolean remove(Long id) {
@@ -900,7 +906,7 @@ public class ImageDataDaoImpl extends GenericDaoBase<ImageDataVO, Long> implemen
         txn.start();
         ImageDataVO template = createForUpdate();
         template.setRemoved(new Date());
-        
+
         ImageDataVO vo = findById(id);
         if (vo != null) {
             if (vo.getFormat().equalsIgnoreCase(new ISO().toString())) {
@@ -914,12 +920,9 @@ public class ImageDataDaoImpl extends GenericDaoBase<ImageDataVO, Long> implemen
         txn.commit();
         return result;
     }
-    
+
     private boolean isAdmin(short accountType) {
-	    return ((accountType == Account.ACCOUNT_TYPE_ADMIN) ||
-	    	    (accountType == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) ||
-	            (accountType == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) ||
-	            (accountType == Account.ACCOUNT_TYPE_READ_ONLY_ADMIN));
-	}
-    
+        return ((accountType == Account.ACCOUNT_TYPE_ADMIN) || (accountType == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) || (accountType == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) || (accountType == Account.ACCOUNT_TYPE_READ_ONLY_ADMIN));
+    }
+
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/573d13dd/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreProviderDao.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreProviderDao.java b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreProviderDao.java
index 466afa2..37a2fe9 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreProviderDao.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreProviderDao.java
@@ -21,5 +21,4 @@ package org.apache.cloudstack.storage.image.db;
 import com.cloud.utils.db.GenericDao;
 
 public interface ImageDataStoreProviderDao extends GenericDao<ImageDataStoreProviderVO, Long> {
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/573d13dd/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreProviderVO.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreProviderVO.java b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreProviderVO.java
index 799a459..5cc5b8d 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreProviderVO.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreProviderVO.java
@@ -25,25 +25,25 @@ import javax.persistence.Table;
 import javax.persistence.TableGenerator;
 
 @Entity
-@Table(name="image_data_store_provider")
+@Table(name = "image_data_store_provider")
 public class ImageDataStoreProviderVO {
     @Id
-    @TableGenerator(name="image_data_store_provider_sq", table="sequence", pkColumnName="name", valueColumnName="value", pkColumnValue="image_data_store_provider_seq", allocationSize=1)
-    @Column(name="id", nullable = false)
+    @TableGenerator(name = "image_data_store_provider_sq", table = "sequence", pkColumnName = "name", valueColumnName = "value", pkColumnValue = "image_data_store_provider_seq", allocationSize = 1)
+    @Column(name = "id", nullable = false)
     private long id;
-    
-    @Column(name="name", nullable = false)
+
+    @Column(name = "name", nullable = false)
     private String name;
-    
+
     public long getId() {
-    	return this.id;
+        return this.id;
     }
-    
+
     public String getName() {
-    	return this.name;
+        return this.name;
     }
-    
+
     public void setName(String name) {
-    	this.name = name;
+        this.name = name;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/573d13dd/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreVO.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreVO.java b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreVO.java
index 7177203..5094418 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreVO.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreVO.java
@@ -25,36 +25,36 @@ import javax.persistence.Table;
 import javax.persistence.TableGenerator;
 
 @Entity
-@Table(name="image_data_store")
+@Table(name = "image_data_store")
 public class ImageDataStoreVO {
     @Id
-    @TableGenerator(name="image_data_store_sq", table="sequence", pkColumnName="name", valueColumnName="value", pkColumnValue="image_data_store_seq", allocationSize=1)
-    @Column(name="id", nullable = false)
+    @TableGenerator(name = "image_data_store_sq", table = "sequence", pkColumnName = "name", valueColumnName = "value", pkColumnValue = "image_data_store_seq", allocationSize = 1)
+    @Column(name = "id", nullable = false)
     private long id;
-    
-    @Column(name="name", nullable = false)
+
+    @Column(name = "name", nullable = false)
     private String name;
-    
-    @Column(name="image_provider", nullable = false)
+
+    @Column(name = "image_provider", nullable = false)
     private long provider;
-    
+
     public long getId() {
-    	return this.id;
+        return this.id;
     }
-    
+
     public String getName() {
-    	return this.name;
+        return this.name;
     }
-    
+
     public long getProvider() {
-    	return this.provider;
+        return this.provider;
     }
-    
+
     public void setName(String name) {
-    	this.name = name;
+        this.name = name;
     }
-    
+
     public void setProvider(long provider) {
-    	this.provider = provider;
+        this.provider = provider;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/573d13dd/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataVO.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataVO.java b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataVO.java
index eff2dbc..efce33c 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataVO.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataVO.java
@@ -41,101 +41,100 @@ import com.cloud.storage.Storage.TemplateType;
 import com.cloud.utils.db.GenericDao;
 
 @Entity
-@Table(name="vm_template")
+@Table(name = "vm_template")
 public class ImageDataVO implements Identity {
     @Id
-    @TableGenerator(name="vm_template_sq", table="sequence", pkColumnName="name", valueColumnName="value", pkColumnValue="vm_template_seq", allocationSize=1)
-    @Column(name="id", nullable = false)
+    @TableGenerator(name = "vm_template_sq", table = "sequence", pkColumnName = "name", valueColumnName = "value", pkColumnValue = "vm_template_seq", allocationSize = 1)
+    @Column(name = "id", nullable = false)
     private long id;
 
-    @Column(name="format")
+    @Column(name = "format")
     private String format;
 
-    @Column(name="unique_name")
+    @Column(name = "unique_name")
     private String uniqueName;
 
-    @Column(name="name")
+    @Column(name = "name")
     private String name = null;
 
-    @Column(name="public")
+    @Column(name = "public")
     private boolean publicTemplate = true;
 
-    @Column(name="featured")
+    @Column(name = "featured")
     private boolean featured;
 
-    @Column(name="type")
+    @Column(name = "type")
     private Storage.TemplateType templateType;
 
-    @Column(name="url")
+    @Column(name = "url")
     private String url = null;
 
-    @Column(name="hvm")
+    @Column(name = "hvm")
     private boolean requiresHvm;
 
-    @Column(name="bits")
+    @Column(name = "bits")
     private int bits;
 
-    @Temporal(value=TemporalType.TIMESTAMP)
-    @Column(name=GenericDao.CREATED_COLUMN)
+    @Temporal(value = TemporalType.TIMESTAMP)
+    @Column(name = GenericDao.CREATED_COLUMN)
     private Date created = null;
 
-    @Column(name=GenericDao.REMOVED)
+    @Column(name = GenericDao.REMOVED)
     @Temporal(TemporalType.TIMESTAMP)
     private Date removed;
 
-    @Column(name="account_id")
+    @Column(name = "account_id")
     private long accountId;
 
-    @Column(name="checksum")
-    private String checksum;    
+    @Column(name = "checksum")
+    private String checksum;
 
-    @Column(name="display_text", length=4096)
+    @Column(name = "display_text", length = 4096)
     private String displayText;
 
-    @Column(name="enable_password")
+    @Column(name = "enable_password")
     private boolean enablePassword;
 
-    @Column(name="guest_os_id")
+    @Column(name = "guest_os_id")
     private long guestOSId;
 
-    @Column(name="bootable")
+    @Column(name = "bootable")
     private boolean bootable = true;
 
-    @Column(name="prepopulate")
+    @Column(name = "prepopulate")
     private boolean prepopulate = false;
 
-    @Column(name="cross_zones")
+    @Column(name = "cross_zones")
     private boolean crossZones = false;
 
-    @Column(name="hypervisor_type")
-    @Enumerated(value=EnumType.STRING)
+    @Column(name = "hypervisor_type")
+    @Enumerated(value = EnumType.STRING)
     private HypervisorType hypervisorType;
 
-    @Column(name="extractable")
+    @Column(name = "extractable")
     private boolean extractable = true;
 
-    @Column(name="source_template_id")
+    @Column(name = "source_template_id")
     private Long sourceTemplateId;
 
-    @Column(name="template_tag")
+    @Column(name = "template_tag")
     private String templateTag;
-    
-    @Column(name="uuid")
+
+    @Column(name = "uuid")
     private String uuid;
-    
-    @Column(name="sort_key")
+
+    @Column(name = "sort_key")
     private int sortKey;
-    
-    @Column(name="enable_sshkey")
+
+    @Column(name = "enable_sshkey")
     private boolean enableSshKey;
-    
-    @Column(name="image_data_store_id")
+
+    @Column(name = "image_data_store_id")
     private long imageDataStoreId;
-    
+
     @Transient
     Map details;
 
-
     public String getUniqueName() {
         return uniqueName;
     }
@@ -145,7 +144,7 @@ public class ImageDataVO implements Identity {
     }
 
     protected ImageDataVO() {
-    	this.uuid = UUID.randomUUID().toString();
+        this.uuid = UUID.randomUUID().toString();
     }
 
     public boolean getEnablePassword() {
@@ -306,44 +305,44 @@ public class ImageDataVO implements Identity {
 
     public String getTemplateTag() {
         return templateTag;
-    }    
+    }
 
     public void setTemplateTag(String templateTag) {
         this.templateTag = templateTag;
-    }   
+    }
 
     public long getDomainId() {
         return -1;
     }
-    
+
     @Override
     public String getUuid() {
-    	return this.uuid;
+        return this.uuid;
     }
-    
+
     public void setUuid(String uuid) {
-    	this.uuid = uuid;
+        this.uuid = uuid;
     }
-    
+
     public Map getDetails() {
-    	return this.details;
+        return this.details;
     }
-    
+
     public void setDetails(Map details) {
-    	this.details = details;
+        this.details = details;
     }
 
     @Override
     public boolean equals(Object that) {
-        if (this == that ) {
+        if (this == that) {
             return true;
         }
-        if (!(that instanceof VMTemplateVO)){
+        if (!(that instanceof VMTemplateVO)) {
             return false;
         }
-        VMTemplateVO other = (VMTemplateVO)that;
+        VMTemplateVO other = (VMTemplateVO) that;
 
-        return ((this.getUniqueName().equals(other.getUniqueName())));		
+        return ((this.getUniqueName().equals(other.getUniqueName())));
     }
 
     @Override
@@ -353,6 +352,7 @@ public class ImageDataVO implements Identity {
 
     @Transient
     String toString;
+
     @Override
     public String toString() {
         if (toString == null) {
@@ -364,29 +364,29 @@ public class ImageDataVO implements Identity {
     public void setRemoved(Date removed) {
         this.removed = removed;
     }
-    
+
     public void setSortKey(int key) {
-    	sortKey = key;
+        sortKey = key;
     }
-    
+
     public int getSortKey() {
-    	return sortKey;
-    }
-
-	public boolean getEnableSshKey() {
-		return enableSshKey;
-	}
-	
-	public void setEnableSshKey(boolean enable) {
-		enableSshKey = enable;
-	}
-	
-	public long getImageDataStoreId() {
-		return this.imageDataStoreId;
-	}
-	
-	public void setImageDataStoreId(long dataStoreId) {
-		this.imageDataStoreId = dataStoreId;
-	}
+        return sortKey;
+    }
+
+    public boolean getEnableSshKey() {
+        return enableSshKey;
+    }
+
+    public void setEnableSshKey(boolean enable) {
+        enableSshKey = enable;
+    }
+
+    public Long getImageDataStoreId() {
+        return this.imageDataStoreId;
+    }
+
+    public void setImageDataStoreId(long dataStoreId) {
+        this.imageDataStoreId = dataStoreId;
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/573d13dd/engine/storage/src/org/apache/cloudstack/storage/image/downloader/ImageDownloader.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/downloader/ImageDownloader.java b/engine/storage/src/org/apache/cloudstack/storage/image/downloader/ImageDownloader.java
index ef9bc3f..adb247a 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/downloader/ImageDownloader.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/downloader/ImageDownloader.java
@@ -21,5 +21,5 @@ package org.apache.cloudstack.storage.image.downloader;
 import org.apache.cloudstack.storage.image.TemplateInfo;
 
 public interface ImageDownloader {
-	public void downloadImage(TemplateInfo template);
+    public void downloadImage(TemplateInfo template);
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/573d13dd/engine/storage/src/org/apache/cloudstack/storage/image/driver/ImageDataStoreDriver.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/driver/ImageDataStoreDriver.java b/engine/storage/src/org/apache/cloudstack/storage/image/driver/ImageDataStoreDriver.java
index 07f4515..42e52e5 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/driver/ImageDataStoreDriver.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/driver/ImageDataStoreDriver.java
@@ -21,8 +21,11 @@ package org.apache.cloudstack.storage.image.driver;
 import org.apache.cloudstack.storage.image.TemplateInfo;
 
 public interface ImageDataStoreDriver {
-	boolean registerTemplate(TemplateInfo template);
-	String grantAccess(long templateId, long endPointId);
-	boolean revokeAccess(long templateId, long endPointId);
-	boolean deleteTemplate(TemplateInfo template);
+    boolean registerTemplate(TemplateInfo template);
+
+    String grantAccess(long templateId, long endPointId);
+
+    boolean revokeAccess(long templateId, long endPointId);
+
+    boolean deleteTemplate(TemplateInfo template);
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/573d13dd/engine/storage/src/org/apache/cloudstack/storage/image/driver/ImageDataStoreDriverImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/driver/ImageDataStoreDriverImpl.java b/engine/storage/src/org/apache/cloudstack/storage/image/driver/ImageDataStoreDriverImpl.java
index 714bee1..e395cf1 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/driver/ImageDataStoreDriverImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/driver/ImageDataStoreDriverImpl.java
@@ -21,33 +21,32 @@ package org.apache.cloudstack.storage.image.driver;
 import org.apache.cloudstack.storage.image.TemplateInfo;
 
 public class ImageDataStoreDriverImpl implements ImageDataStoreDriver {
-	
-	public ImageDataStoreDriverImpl() {
-	}
-	@Override
-	public boolean registerTemplate(TemplateInfo template) {
-		//TODO: check the availability of template 
-		return true;
-	}
-
-	@Override
-	public String grantAccess(long templateId, long endPointId) {
-		// TODO Auto-generated method stub
-		return null;
-	}
-
-	@Override
-	public boolean revokeAccess(long templateId, long endPointId) {
-		// TODO Auto-generated method stub
-		return false;
-	}
-
-	@Override
-	public boolean deleteTemplate(TemplateInfo template) {
-		// TODO Auto-generated method stub
-		return false;
-	}
-
-	
+
+    public ImageDataStoreDriverImpl() {
+    }
+
+    @Override
+    public boolean registerTemplate(TemplateInfo template) {
+        // TODO: check the availability of template
+        return true;
+    }
+
+    @Override
+    public String grantAccess(long templateId, long endPointId) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public boolean revokeAccess(long templateId, long endPointId) {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    @Override
+    public boolean deleteTemplate(TemplateInfo template) {
+        // TODO Auto-generated method stub
+        return false;
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/573d13dd/engine/storage/src/org/apache/cloudstack/storage/image/format/BAREMETAL.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/format/BAREMETAL.java b/engine/storage/src/org/apache/cloudstack/storage/image/format/BAREMETAL.java
index c3de2f1..72e683b 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/format/BAREMETAL.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/format/BAREMETAL.java
@@ -23,9 +23,10 @@ import org.springframework.stereotype.Component;
 
 @Component
 public class BAREMETAL extends BaseType implements ImageFormat {
-	private final String type = "BAREMETAL";
-	@Override
-	public String toString() {
-		return type;
-	}
+    private final String type = "BAREMETAL";
+
+    @Override
+    public String toString() {
+        return type;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/573d13dd/engine/storage/src/org/apache/cloudstack/storage/image/format/ISO.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/format/ISO.java b/engine/storage/src/org/apache/cloudstack/storage/image/format/ISO.java
index f27d16b..2f01a27 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/format/ISO.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/format/ISO.java
@@ -23,9 +23,10 @@ import org.springframework.stereotype.Component;
 
 @Component
 public class ISO extends BaseType implements ImageFormat {
-	private final String type = "ISO";
-	@Override
-	public String toString() {
-		return type;
-	}
+    private final String type = "ISO";
+
+    @Override
+    public String toString() {
+        return type;
+    }
 }


Mime
View raw message