package alien4cloud.deployment.matching.services.location;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component;

import com.google.common.collect.Lists;

import alien4cloud.dao.IGenericSearchDAO;
import alien4cloud.deployment.matching.plugins.ILocationMatcher;
import alien4cloud.model.deployment.matching.ILocationMatch;
import alien4cloud.model.deployment.matching.LocationMatch;
import alien4cloud.model.orchestrators.Orchestrator;
import alien4cloud.model.orchestrators.locations.Location;
import alien4cloud.model.topology.Topology;
import alien4cloud.orchestrators.locations.services.LocationService;
import alien4cloud.orchestrators.services.OrchestratorService;
import alien4cloud.paas.exception.LocationMatchingException;
import alien4cloud.utils.AlienUtils;
import lombok.Getter;
import lombok.Setter;

/**
 * Default location matcher for topologies
 *
 */

@Component("default-location-matcher")
@Getter
@Setter
public class DefaultLocationMatcher implements ILocationMatcher {

    @Resource(name = "alien-es-dao")
    private IGenericSearchDAO alienDAO;

    @Resource
    private LocationService locationService;

    @Resource
    private OrchestratorService orchestratorService;
    @Resource
    private LocationMatchNodeFilter locationMatchNodeFilter;

    @Override
    public List<ILocationMatch> match(Topology topology) throws LocationMatchingException {
        List<ILocationMatch> matched = Lists.newArrayList();

        try {
            // get all enabled orchestrators
            List<Orchestrator> enabledOrchestrators = orchestratorService.getAll();
            if (CollectionUtils.isEmpty(enabledOrchestrators)) {
                return matched;
            }

            Map<String, Orchestrator> orchestratorMap = AlienUtils.fromListToMap(enabledOrchestrators, "id", true);
            List<Location> locations = locationService.getOrchestratorsLocations(orchestratorMap.keySet());
            for (Location location : locations) {
                matched.add(new LocationMatch(location, orchestratorMap.get(location.getOrchestratorId()), null));
            }

            // filter on supported artifacts
            locationMatchNodeFilter.filter(matched, topology);

            return matched;
        } catch (Exception e) {
            throw new LocationMatchingException("Failed to match topology <" + topology.getId() + "> against locations. ", e);
        }
    }
}

@@ -134,16 +134,61 @@
 ource;%0A%0A
+import lombok.Getter;%0Aimport lombok.Setter;%0A%0A
 import o
@@ -289,91 +289,8 @@
 t;%0A%0A
-import com.google.common.collect.Lists;%0A%0Aimport alien4cloud.dao.IGenericSearchDAO;%0A
 impo
@@ -861,50 +861,47 @@
 ls;%0A
+%0A
 import 
-lombok.Getter;%0Aimport lombok.Setter
+com.google.common.collect.Lists
 ;%0A%0A/
@@ -1079,87 +1079,8 @@
 r %7B%0A
-%0A    @Resource(name = %22alien-es-dao%22)%0A    private IGenericSearchDAO alienDAO;%0A%0A
     
@@ -1134,17 +1134,16 @@
 ervice;%0A
-%0A
     @Res

Remove useless field and DI on IGenericSearchDAO.