forked from eclipse/vorto
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrated function block editor with devtool
Signed-off-by: shiv12095 <shiv12095@iiitd.ac.in>
- Loading branch information
Showing
14 changed files
with
472 additions
and
71 deletions.
There are no files selected for viewing
40 changes: 0 additions & 40 deletions
40
...org/eclipse/vorto/editor/infomodel/web/resource/InformationModelResourceSetProvider.xtend
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
.../main/java/org/eclipse/vorto/server/devtool/controller/FunctionBlockEditorController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package org.eclipse.vorto.server.devtool.controller; | ||
|
||
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.IFunctionBlockEditorService; | ||
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/functionblock") | ||
public class FunctionBlockEditorController { | ||
|
||
@Autowired | ||
Injector injector; | ||
|
||
@Autowired | ||
IFunctionBlockEditorService iFunctionBlockEditorService; | ||
|
||
@ApiOperation(value = "Adds the data type to the resource set") | ||
@RequestMapping(value = "/link/datatype/{resourceId}/{namespace}/{name}/{version:.+}", method = RequestMethod.GET) | ||
public void linkFunctionBlock(@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 = iFunctionBlockEditorService.linkDatatypeToFunctionBlock(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 iFunctionBlockEditorService.searchDataTypeByExpression(expression); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...rc/main/java/org/eclipse/vorto/server/devtool/service/FunctionBlockEditorServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package org.eclipse.vorto.server.devtool.service; | ||
|
||
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.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); | ||
System.out.println(byteArrayOutputStream.toString()); | ||
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; | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
...l/src/main/java/org/eclipse/vorto/server/devtool/service/IFunctionBlockEditorService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.eclipse.vorto.server.devtool.service; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import org.eclipse.emf.ecore.resource.ResourceSet; | ||
import org.eclipse.vorto.http.model.ModelId; | ||
import org.eclipse.vorto.http.model.ModelResource; | ||
|
||
public interface IFunctionBlockEditorService { | ||
|
||
String linkDatatypeToFunctionBlock(String functionBlockResourceId, ModelId datatypeModelId, ResourceSet resourceSet, | ||
Set<String> referencedResourceSet); | ||
|
||
List<ModelResource> searchDataTypeByExpression(String expression); | ||
|
||
} |
Oops, something went wrong.