Skip to content

Commit

Permalink
Integrated function block editor with devtool
Browse files Browse the repository at this point in the history
Signed-off-by: shiv12095 <shiv12095@iiitd.ac.in>
  • Loading branch information
shiv12095 committed Jul 25, 2016
1 parent c9609a2 commit 8f4ea15
Show file tree
Hide file tree
Showing 14 changed files with 472 additions and 71 deletions.

This file was deleted.

34 changes: 30 additions & 4 deletions server/devtool/pom.xml
Expand Up @@ -86,9 +86,30 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>font-awesome</artifactId>
<version>4.2.0</version>
<groupId>org.eclipse.vorto</groupId>
<artifactId>org.eclipse.vorto.editor.web</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.vorto</groupId>
<artifactId>org.eclipse.vorto.editor.functionblock</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.vorto</groupId>
<artifactId>org.eclipse.vorto.editor.functionblock.web</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.vorto</groupId>
<artifactId>org.eclipse.vorto.editor.functionblock.ide</artifactId>
<version>${project.version}</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.vorto</groupId>
Expand Down Expand Up @@ -117,7 +138,7 @@
<artifactId>commons-lang3</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>requirejs</artifactId>
<version>2.1.15</version>
Expand Down Expand Up @@ -147,5 +168,10 @@
<artifactId>angular-smart-table</artifactId>
<version>2.1.6</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>font-awesome</artifactId>
<version>4.2.0</version>
</dependency>
</dependencies>
</project>
Expand Up @@ -18,8 +18,12 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.eclipse.vorto.core.api.model.functionblock.impl.FunctionblockModelImpl;
import org.eclipse.vorto.core.api.model.informationmodel.impl.InformationModelPackageImpl;
import org.eclipse.vorto.editor.functionblock.FunctionblockRuntimeModule;
import org.eclipse.vorto.editor.functionblock.FunctionblockStandaloneSetup;
import org.eclipse.vorto.editor.functionblock.web.FunctionblockServlet;
import org.eclipse.vorto.editor.functionblock.web.FunctionblockWebModule;
import org.eclipse.vorto.editor.infomodel.InformationModelRuntimeModule;
import org.eclipse.vorto.editor.infomodel.web.InformationModelServlet;
import org.eclipse.vorto.editor.infomodel.web.InformationModelWebModule;
Expand All @@ -39,9 +43,9 @@
public class XtextConfiguration {

private final List<ExecutorService> executorServices = CollectionLiterals.<ExecutorService> newArrayList();

@Bean
public Injector getOnjectorBean(){
public Injector getInjectorBean() {
final Provider<ExecutorService> _function = new Provider<ExecutorService>() {
@Override
public ExecutorService get() {
Expand All @@ -56,13 +60,26 @@ public void apply(final ExecutorService it) {
}
};
final Provider<ExecutorService> executorServiceProvider = _function;

FunctionblockStandaloneSetup.doSetup();
InformationModelPackageImpl.init();
FunctionblockStandaloneSetup.doSetup();
return Guice.createInjector(Modules.override(new InformationModelRuntimeModule()).with(new InformationModelWebModule(executorServiceProvider)));


return Guice.createInjector(
// Modules.override(new FunctionblockRuntimeModule())
// .with(new FunctionblockWebModule(executorServiceProvider)),
Modules.override(new InformationModelRuntimeModule())
.with(new InformationModelWebModule(executorServiceProvider)));
}

@Bean
public ServletRegistrationBean functionBlockXtextServlet() {
return new ServletRegistrationBean(new FunctionblockServlet(), "/functionblock/xtext-service/*");
}

@Bean
public ServletRegistrationBean xtextServlet() {
return new ServletRegistrationBean(new InformationModelServlet(), "/xtext-service/*");
public ServletRegistrationBean informationModelXtextServlet() {
return new ServletRegistrationBean(new InformationModelServlet(), "/infomodel/xtext-service/*");
}

}
@@ -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);
}
}
Expand Up @@ -11,7 +11,7 @@

import org.apache.tomcat.util.http.fileupload.IOUtils;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.vorto.editor.infomodel.web.resource.InformationModelResourceSetProvider;
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;
Expand Down Expand Up @@ -40,7 +40,8 @@ public class InformationModelEditorController {

@ApiOperation(value = "Adds the function block to the resource set")
@RequestMapping(value = "/link/functionblock/{resourceId}/{namespace}/{name}/{version:.+}", method = RequestMethod.GET)
public void linkFunctionBlock(@ApiParam(value = "ResourceId", required = true) final @PathVariable String resourceId,
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,
Expand All @@ -53,14 +54,16 @@ public void linkFunctionBlock(@ApiParam(value = "ResourceId", required = true) f
Objects.requireNonNull(version, "version must not be null");

ModelId modelId = new ModelId(name, namespace, version);

HttpServiceContext httpServiceContext = new HttpServiceContext(request);
InformationModelResourceSetProvider informationModelResourceSetProvider = (InformationModelResourceSetProvider) injector.getInstance(IWebResourceSetProvider.class);
ResourceSet resourceSet = informationModelResourceSetProvider.getResourceSetFromSession(httpServiceContext);
HashSet<String> referencedResourceSet = (HashSet<String>) informationModelResourceSetProvider
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);

String content = iInformationModelEditorService.linkFunctionBlockToInformationModel(resourceId, modelId,
resourceSet, referencedResourceSet);
try {
IOUtils.copy(new ByteArrayInputStream(content.getBytes()), response.getOutputStream());
response.flushBuffer();
Expand Down
@@ -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;
}

}
@@ -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);

}

0 comments on commit 8f4ea15

Please sign in to comment.