package org.openbaton.nfvo.api;

import org.openbaton.exceptions.NotFoundException;
import org.openbaton.nfvo.security.interfaces.UserManagement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by lto on 13/10/16.
 */
@RestController
@RequestMapping("/api/v1/main")
public class RestMain {

  @Value("${nfvo.rabbit.brokerIp}")
  private String nfvoIp;

  @Value("${server.port}")
  private String nfvoPort;

  @Autowired private UserManagement userManagement;

  @RequestMapping(
    value = "version",
    method = RequestMethod.GET,
    produces = MediaType.TEXT_PLAIN_VALUE
  )
  public String getVersion() {
    return RestMain.class.getPackage().getImplementationVersion();
  }

  @RequestMapping(
    value = "openbaton-rc",
    method = RequestMethod.GET,
    produces = MediaType.APPLICATION_OCTET_STREAM_VALUE
  )
  public String getOpenRCFile(@RequestHeader("project-id") String projectId)
      throws NotFoundException {
    return getOpenRcFile(projectId);
  }

  private String getOpenRcFile(String projectId) throws NotFoundException {
    return "#!/bin/bash\n"
        + "\n"
        + "unset OB_NFVO_IP\n"
        + "unset OB_NFVO_PORT\n"
        + "unset OB_PROJECT_ID\n"
        + "unset OB_USERNAME\n"
        + "unset OB_PASSWORD\n\n"
        + "export OB_NFVO_IP="
        + nfvoIp
        + "\n"
        + "export OB_NFVO_PORT="
        + nfvoPort
        + "\n"
        + "export OB_PROJECT_ID="
        + projectId
        + "\n"
        + "export OB_USERNAME="
        + userManagement.getCurrentUser().getUsername()
        + "\n"
        + "echo -n Insert Open Baton Password: \n"
        + "read -s password\n"
        + "export OB_PASSWORD=$password\n";
  }
}

@@ -261,16 +261,92 @@
 .Value;%0A
+import org.springframework.boot.context.properties.ConfigurationProperties;%0A
 import o
@@ -718,16 +718,41 @@
 /main%22)%0A
+@ConfigurationProperties%0A
 public c
@@ -768,16 +768,280 @@
 Main %7B%0A%0A
+  public String getNfvoIp() %7B%0A    return nfvoIp;%0A  %7D%0A%0A  public void setNfvoIp(String nfvoIp) %7B%0A    this.nfvoIp = nfvoIp;%0A  %7D%0A%0A  public String getNfvoPort() %7B%0A    return nfvoPort;%0A  %7D%0A%0A  public void setNfvoPort(String nfvoPort) %7B%0A    this.nfvoPort = nfvoPort;%0A  %7D%0A%0A
   @Value
@@ -1064,16 +1064,26 @@
 brokerIp
+:localhost
 %7D%22)%0A  pr
@@ -1127,16 +1127,21 @@
 ver.port
+:8080
 %7D%22)%0A  pr

fix test