/*
 * Waltz - Enterprise Architecture
 * Copyright (C) 2016  Khartec Ltd.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.khartec.waltz.web.endpoints.extracts;

import com.khartec.waltz.web.endpoints.Endpoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import static com.khartec.waltz.common.Checks.checkNotNull;
import static com.khartec.waltz.web.WebUtilities.mkPath;


@Service
public class DataExtractEndpoint implements Endpoint {

    private static final Logger LOG = LoggerFactory.getLogger(DataExtractEndpoint.class);
    private static final String BASE_URL = mkPath("data-extract");

    private final LogicalFlowExtractor logicalFlowExtractor;
    private final OrgUnitExtractor orgUnitExtractor;


    @Autowired
    public DataExtractEndpoint(LogicalFlowExtractor logicalFlowExtractor,
                               OrgUnitExtractor orgUnitExtractor) {
        checkNotNull(logicalFlowExtractor, "logicalFlowExtractor cannot be null");
        checkNotNull(orgUnitExtractor, "orgUnitExtractor cannot be null");

        this.logicalFlowExtractor = logicalFlowExtractor;
        this.orgUnitExtractor = orgUnitExtractor;
    }


    @Override
    public void register() {
        orgUnitExtractor.register(BASE_URL);
        logicalFlowExtractor.register(BASE_URL);
    }

}

@@ -993,26 +993,131 @@
 ork.
-stereotype.Service
+context.annotation.AnnotationConfigApplicationContext;%0Aimport org.springframework.stereotype.Service;%0A%0Aimport java.util.Map
 ;%0A%0Ai
@@ -1473,452 +1473,311 @@
 ate 
-final LogicalFlowExtractor logicalFlowExtractor;%0A    private final OrgUnitExtractor orgUnitExtractor;%0A%0A%0A    @Autowired%0A    public DataExtractEndpoint(LogicalFlowExtractor logicalFlowExtractor,%0A                               OrgUnitExtractor orgUnitExtractor) %7B%0A        checkNotNull(logicalFlowExtractor, %22logicalFlowExtractor cannot be null%22);%0A        checkNotNull(orgUnitExtractor, %22orgUnitExtractor cannot be null%22);%0A%0A        this.logicalFlow
+static AnnotationConfigApplicationContext ctx;%0A%0A    @Autowired%0A    public DataExtractEndpoint(AnnotationConfigApplicationContext ctx) %7B%0A        checkNotNull(ctx, %22ctx cannot be null%22);%0A        this.ctx = ctx;%0A    %7D%0A%0A%0A    @Override%0A    public void register() %7B%0A        Map%3CString, BaseDataExtractor%3E data
 Extr
@@ -1785,22 +1785,39 @@
 ctor
+s
  = 
-logicalFlow
+ctx.getBeansOfType(BaseData
 Extr
@@ -1817,24 +1817,31 @@
 ataExtractor
+.class)
 ;%0A        th
@@ -1842,166 +1842,129 @@
     
-this.orgUnitExtractor = orgUnitExtractor;%0A    %7D%0A%0A%0A    @Override%0A    public void register() %7B%0A        orgUnitExtractor.register(BASE_URL);%0A        logicalFlowE
+dataExtractors.forEach((name, extractor) -%3E %7B%0A            LOG.info(%22Registering Data extractor: %7B%7D%22, name);%0A            e
 xtra
@@ -1988,16 +1988,28 @@
 E_URL);%0A
+        %7D);%0A
     %7D%0A%0A%7D

use DI to initialise data extractors