/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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 de.interseroh.tmb.applauncher.server.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import de.interseroh.tmb.applauncher.shared.ApplauncherServiceEndpoint;
import de.interseroh.tmb.applauncher.shared.json.ApplauncherProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import de.interseroh.tmb.applauncher.shared.json.TargetApplication;

@RestController
public class ApplauncherConfiguration {
	private static final Logger logger = LoggerFactory
			.getLogger(ApplauncherConfiguration.class);

	@Value("${applauncher.config.json:classpath:dev.applauncher.json}")
	private Resource applauncherConfigurationJson;

	@RequestMapping(value = ApplauncherServiceEndpoint.APPLAUNCHER_CONFIG, method = RequestMethod.GET)
	public List<TargetApplication> getConfiguration() {
		List<TargetApplication> listAppProps = new ArrayList<>();
		try (InputStream jsonIs = applauncherConfigurationJson
				.getInputStream()) {
			ObjectMapper mapper = new ObjectMapper();
			ApplauncherProperties appPropes = mapper
					.readValue(jsonIs, ApplauncherProperties.class);
			listAppProps.addAll(appPropes.getApplauncherProperties()
					.getTargetApplication());
		} catch (IOException e) {
			logger.error(e.getMessage(), e);
		}

		return listAppProps;
	}
}

@@ -869,196 +869,108 @@
 ort 
-com.fasterxml.jackson.databind.ObjectMapper;%0Aimport de.interseroh.tmb.applauncher.shared.ApplauncherServiceEndpoint;%0Aimport de.interseroh.tmb.applauncher.shared.json.ApplauncherProperties;
+java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A
 %0Aimp
@@ -1327,106 +1327,196 @@
 ort 
-java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.util.ArrayList;%0Aimport java.util.List
+com.fasterxml.jackson.databind.ObjectMapper;%0A%0Aimport de.interseroh.tmb.applauncher.shared.ApplauncherServiceEndpoint;%0Aimport de.interseroh.tmb.applauncher.shared.json.ApplauncherProperties
 ;%0Aim

format imports