package jp.ac.nii.prl.mape.plan.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jp.ac.nii.prl.mape.plan.service.AdaptationService;
import jp.ac.nii.prl.mape.plan.service.DeploymentService;
import jp.ac.nii.prl.mape.plan.service.InstanceService;
import jp.ac.nii.prl.mape.plan.service.InstanceTypeService;

@RestController
@Component
@RequestMapping("/deployment")
public class DeploymentController {

	@Autowired
	private InstanceService instanceService;

	@Autowired
	private AdaptationService adaptationService;
	
	@Autowired
	private DeploymentService deploymentService;
	
	@Autowired
	private InstanceTypeService instanceTypeService;
	
}

@@ -132,28 +132,225 @@
 ork.
-stereotype.Component
+http.HttpHeaders;%0Aimport org.springframework.http.HttpStatus;%0Aimport org.springframework.http.ResponseEntity;%0Aimport org.springframework.stereotype.Component;%0Aimport org.springframework.web.bind.annotation.RequestBody
 ;%0Aim
@@ -410,16 +410,78 @@
 apping;%0A
+import org.springframework.web.bind.annotation.RequestMethod;%0A
 import o
@@ -527,32 +527,255 @@
 RestController;%0A
+import org.springframework.web.servlet.support.ServletUriComponentsBuilder;%0A%0Aimport jp.ac.nii.prl.mape.plan.model.Deployment;%0Aimport jp.ac.nii.prl.mape.plan.model.Instance;%0Aimport jp.ac.nii.prl.mape.plan.model.InstanceType;
 %0Aimport jp.ac.ni
@@ -1326,10 +1326,777 @@
 vice;%0A%09%0A
+%09@RequestMapping(method=RequestMethod.POST)%0A%09public ResponseEntity%3C?%3E createDeployment(@RequestBody Deployment deployment) %7B%0A%09%09deploymentService.save(deployment);%0A%09%09for (InstanceType instType:deployment.getInstanceTypes()) %7B%0A%09%09%09instanceTypeService.save(instType);%0A%09%09%7D%0A%09%09for (Instance instance:deployment.getInstances()) %7B%0A%09%09%09instance.setDeployment(deployment);%0A%09%09%09instanceService.setInstanceType(instance);%0A%09%09%09instanceService.save(instance);%0A%09%09%7D%0A%09%09adaptationService.save(deployment.getAdaptation());%0A%0A%09%09HttpHeaders httpHeaders = new HttpHeaders();%0A%09%09httpHeaders.setLocation(ServletUriComponentsBuilder%0A%09%09%09%09.fromCurrentRequest().path(%22/%7Bid%7D%22)%0A%09%09%09%09.buildAndExpand(deployment.getId()).toUri());%0A%09%09return new ResponseEntity%3C%3E(null, httpHeaders, HttpStatus.CREATED);%0A%09%7D%0A%09%0A
 %7D%0A

PUT method to create a new deployment from JSON