forked from eclipse/vorto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FunctionBlockEditorServiceImpl.java
61 lines (52 loc) · 2.38 KB
/
FunctionBlockEditorServiceImpl.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
package org.eclipse.vorto.server.devtool.service.impl;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.vorto.http.model.ModelId;
import org.eclipse.vorto.http.model.ModelResource;
import org.eclipse.vorto.server.devtool.service.IFunctionBlockEditorService;
import org.eclipse.vorto.server.devtool.utils.InformationModelEditorReferenceLinker;
import org.eclipse.vorto.server.devtool.utils.InformationModelEditorRestClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class FunctionBlockEditorServiceImpl implements IFunctionBlockEditorService {
@Autowired
InformationModelEditorRestClient informationModelEditorRestClient;
@Autowired
InformationModelEditorReferenceLinker infomrationModelRefernceLinker;
@Override
public String linkDatatypeToFunctionBlock(String functionBlockResourceId, ModelId datatypeModelId,
ResourceSet resourceSet, Set<String> referencedResourceSet) {
infomrationModelRefernceLinker.linkDataTypeToFunctionBlock(functionBlockResourceId, datatypeModelId,
resourceSet, referencedResourceSet);
Resource functionBlockResource = resourceSet.getResource(URI.createURI(functionBlockResourceId), true);
try {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
functionBlockResource.save(byteArrayOutputStream, null);
return byteArrayOutputStream.toString();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public List<ModelResource> searchDataTypeByExpression(String expression) {
return searchModelByExpressionAndValidate(expression, org.eclipse.vorto.http.model.ModelType.Datatype);
}
private List<ModelResource> searchModelByExpressionAndValidate(String expression,
org.eclipse.vorto.http.model.ModelType modelType) {
List<ModelResource> resourceList = informationModelEditorRestClient.searchByExpression(expression);
ArrayList<ModelResource> modelResourceList = new ArrayList<ModelResource>();
for (ModelResource modelResource : resourceList) {
if (modelResource.getModelType().equals(modelType)) {
modelResourceList.add(modelResource);
}
}
return modelResourceList;
}
}