/*
 * 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 java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

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.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.databind.ObjectMapper;

import de.interseroh.tmb.applauncher.shared.ApplauncherServiceEndpoint;
import de.interseroh.tmb.applauncher.shared.json.ApplauncherProperties;
import de.interseroh.tmb.applauncher.shared.json.TargetedApplication;

@RestController
@CrossOrigin
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<TargetedApplication> getConfiguration() {
        List<TargetedApplication> listAppProps = new ArrayList<>();
        try (InputStream jsonIs = applauncherConfigurationJson
                .getInputStream()) {
            ObjectMapper mapper = new ObjectMapper();
            ApplauncherProperties appPropes = mapper.readValue(jsonIs, ApplauncherProperties.class);
            listAppProps.addAll(appPropes.getApplauncherProperties()
                    .getTargetedApplication());
        } catch (IOException e) {
            logger.error(e.getMessage(), e);
        }

        return listAppProps;
    }
}

@@ -869,108 +869,266 @@
 ort 
-java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A
+com.fasterxml.jackson.databind.ObjectMapper;%0Aimport de.interseroh.tmb.applauncher.shared.ApplauncherServiceEndpoint;%0Aimport de.interseroh.tmb.applauncher.shared.json.ApplauncherProperties;%0Aimport de.interseroh.tmb.applauncher.shared.json.TargetedApplication;
 %0Aimp
@@ -1289,68 +1289,8 @@
 ce;%0A
-import org.springframework.web.bind.annotation.CrossOrigin;%0A
 impo
@@ -1485,266 +1485,106 @@
 ort 
-com.fasterxml.jackson.databind.ObjectMapper;%0A%0Aimport de.interseroh.tmb.applauncher.shared.ApplauncherServiceEndpoint;%0Aimport de.interseroh.tmb.applauncher.shared.json.ApplauncherProperties;%0Aimport de.interseroh.tmb.applauncher.shared.json.TargetedApplication
+java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.util.ArrayList;%0Aimport java.util.List
 ;%0A%0A@
@@ -1602,21 +1602,8 @@
 ler%0A
-@CrossOrigin%0A
 publ
@@ -1638,20 +1638,17 @@
 ation %7B%0A
-    
+%09
 private 
@@ -1690,28 +1690,19 @@
 Factory%0A
-            
+%09%09%09
 .getLogg
@@ -1738,20 +1738,17 @@
 lass);%0A%0A
-    
+%09
 @Value(%22
@@ -1807,20 +1807,17 @@
 json%7D%22)%0A
-    
+%09
 private 
@@ -1856,20 +1856,17 @@
 nJson;%0A%0A
-    
+%09
 @Request
@@ -1956,20 +1956,17 @@
 od.GET)%0A
-    
+%09
 public L
@@ -2011,24 +2011,18 @@
 ion() %7B%0A
-        
+%09%09
 List%3CTar
@@ -2073,24 +2073,18 @@
 st%3C%3E();%0A
-        
+%09%09
 try (Inp
@@ -2130,32 +2130,20 @@
 ionJson%0A
-                
+%09%09%09%09
 .getInpu
@@ -2155,28 +2155,19 @@
 am()) %7B%0A
-            
+%09%09%09
 ObjectMa
@@ -2200,28 +2200,19 @@
 pper();%0A
-            
+%09%09%09
 Applaunc
@@ -2243,16 +2243,22 @@
 = mapper
+%0A%09%09%09%09%09
 .readVal
@@ -2298,28 +2298,19 @@
 class);%0A
-            
+%09%09%09
 listAppP
@@ -2362,28 +2362,13 @@
 s()%0A
-                    
+%09%09%09%09%09
 .get
@@ -2391,24 +2391,18 @@
 ion());%0A
-        
+%09%09
 %7D catch 
@@ -2423,20 +2423,11 @@
 ) %7B%0A
-            
+%09%09%09
 logg
@@ -2459,27 +2459,15 @@
 e);%0A
-        %7D%0A%0A        
+%09%09%7D%0A%0A%09%09
 retu
@@ -2487,12 +2487,9 @@
 ps;%0A
-    
+%09
 %7D%0A%7D%0A

remove @CrossOrigin Annotation and prettify code.