/*
 * Copyright 2018 Netflix, Inc.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.netflix.conductor.service;

import com.netflix.conductor.annotations.Audit;
import com.netflix.conductor.annotations.Trace;
import com.netflix.conductor.common.metadata.tasks.Task;
import com.netflix.conductor.core.config.Configuration;
import com.netflix.conductor.core.execution.WorkflowExecutor;
import com.netflix.conductor.dao.QueueDAO;
import com.netflix.conductor.service.utils.ServiceUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.Properties;


@Audit
@Singleton
@Trace
public class AdminServiceImpl implements AdminService {

    private static Logger LOGGER = LoggerFactory.getLogger(AdminServiceImpl.class);

    private final Configuration config;

    private final ExecutionService executionService;

    private final QueueDAO queueDAO;

    private String version;

    private String buildDate;

    @Inject
    public AdminServiceImpl(Configuration config, ExecutionService executionService, QueueDAO queueDAO) {
        this.config = config;
        this.executionService = executionService;
        this.queueDAO = queueDAO;
        this.version = "UNKNOWN";
        this.buildDate = "UNKNOWN";

        try {
            InputStream propertiesIs = this.getClass().getClassLoader().getResourceAsStream("META-INF/conductor-core.properties");
            Properties prop = new Properties();
            prop.load(propertiesIs);
            this.version = prop.getProperty("Implementation-Version");
            this.buildDate = prop.getProperty("Build-Date");
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
        }
    }

    public Map<String, Object> getAllConfig() {
        Map<String, Object> map = config.getAll();
        map.put("version", version);
        map.put("buildDate", buildDate);
        return map;
    }

    public List<Task> getListOfPendingTask(String taskType, Integer start, Integer count) {
        ServiceUtils.checkNotNullOrEmpty(taskType, "TaskType cannot be null or empty.");
        List<Task> tasks = executionService.getPendingTasksForTaskType(taskType);
        int total = start + count;
        total = (tasks.size() > total) ? total : tasks.size();
        if (start > tasks.size()) start = tasks.size();
        return tasks.subList(start, total);
    }


    public String requeueSweep(String workflowId) {
        ServiceUtils.checkNotNullOrEmpty(workflowId, "WorkflowId cannot be null or empty.");
        boolean pushed = queueDAO.pushIfNotExists(WorkflowExecutor.DECIDER_QUEUE, workflowId, config.getSweepFrequency());
        return pushed + "." + workflowId;
    }
}

@@ -2341,32 +2341,142 @@
        %7D%0A    %7D%0A%0A
+    /**%0A     * Get all the configuration parameters.%0A     * @return all the configuration parameters.%0A     */%0A
     public Map%3CS
@@ -2503,24 +2503,24 @@
 lConfig() %7B%0A
-
         Map%3C
@@ -2659,24 +2659,275 @@
 map;%0A    %7D%0A%0A
+    /**%0A     * Get the list of pending tasks for a given task type.%0A     *%0A     * @param taskType Name of the task%0A     * @param start Start index of pagination%0A     * @param count Number of entries%0A     * @return list of pending %7B@link Task%7D%0A     */%0A
     public L
@@ -3382,16 +3382,212 @@
 %0A    %7D%0A%0A
+    /**%0A     * Queue up all the running workflows for sweep.%0A     *%0A     * @param workflowId Id of the workflow%0A     * @return the id of the workflow instance that can be use for tracking.%0A     */
 %0A    pub

add missing javadoc