forked from eclipse/vorto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InformationModelEditorController.java
84 lines (68 loc) · 3.67 KB
/
InformationModelEditorController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package org.eclipse.vorto.server.devtool.controller.editor;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.tomcat.util.http.fileupload.IOUtils;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.vorto.editor.web.resource.WebEditorResourceSetProvider;
import org.eclipse.vorto.http.model.ModelId;
import org.eclipse.vorto.http.model.ModelResource;
import org.eclipse.vorto.server.devtool.service.IInformationModelEditorService;
import org.eclipse.xtext.web.server.model.IWebResourceSetProvider;
import org.eclipse.xtext.web.servlet.HttpServiceContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.google.inject.Injector;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@RestController
@RequestMapping(value = "/editor/infomodel")
public class InformationModelEditorController implements IEditorController{
@Autowired
Injector injector;
@Autowired
IInformationModelEditorService iInformationModelEditorService;
@ApiOperation(value = "Adds the function block to the resource set")
@RequestMapping(value = "/link/functionblock/{resourceId}/{namespace}/{name}/{version:.+}", method = RequestMethod.GET)
public void linkEditor(
@ApiParam(value = "ResourceId", required = true) final @PathVariable String resourceId,
@ApiParam(value = "Namespace", required = true) final @PathVariable String namespace,
@ApiParam(value = "Name", required = true) final @PathVariable String name,
@ApiParam(value = "Version", required = true) final @PathVariable String version,
@ApiParam(value = "Request", required = true) final HttpServletRequest request,
@ApiParam(value = "Response", required = true) final HttpServletResponse response) {
Objects.requireNonNull(resourceId, "resourceId must not be null");
Objects.requireNonNull(namespace, "namespace must not be null");
Objects.requireNonNull(name, "name must not be null");
Objects.requireNonNull(version, "version must not be null");
ModelId modelId = new ModelId(name, namespace, version);
HttpServiceContext httpServiceContext = new HttpServiceContext(request);
WebEditorResourceSetProvider webEditorResourceSetProvider = (WebEditorResourceSetProvider) injector
.getInstance(IWebResourceSetProvider.class);
ResourceSet resourceSet = webEditorResourceSetProvider.getResourceSetFromSession(httpServiceContext);
HashSet<String> referencedResourceSet = (HashSet<String>) webEditorResourceSetProvider
.getReferencedResourcesFromSession(httpServiceContext);
String content = iInformationModelEditorService.linkFunctionBlockToInformationModel(resourceId, modelId,
resourceSet, referencedResourceSet);
try {
IOUtils.copy(new ByteArrayInputStream(content.getBytes()), response.getOutputStream());
response.flushBuffer();
} catch (IOException e) {
throw new RuntimeException("Error copying file.", e);
}
}
@ApiOperation(value = "")
@RequestMapping(value = "/search={expression:.*}", method = RequestMethod.GET)
public List<ModelResource> searchByExpression(
@ApiParam(value = "Search expression", required = true) @PathVariable String expression) {
Objects.requireNonNull(expression, "namespace must not be null");
return iInformationModelEditorService.searchFunctionBlockByExpression(expression);
}
}