Skip to content

Commit

Permalink
Refactored editor service interface. Showing function block models in…
Browse files Browse the repository at this point in the history
… search results of function block editor browser window

Signed-off-by: shiv12095 <shiv12095@iiitd.ac.in>
  • Loading branch information
shiv12095 committed Aug 16, 2016
1 parent 657304a commit a865306
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 171 deletions.
Expand Up @@ -14,7 +14,7 @@
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.vorto.server.devtool.service.editor.FunctionBlockEditorServiceImpl;
import org.eclipse.xtext.web.server.model.IWebResourceSetProvider;
import org.eclipse.xtext.web.servlet.HttpServiceContext;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -36,7 +36,7 @@ public class FunctionBlockEditorController implements IEditorController {
Injector injector;

@Autowired
IFunctionBlockEditorService iFunctionBlockEditorService;
FunctionBlockEditorServiceImpl functionBlockEditorService;

@ApiOperation(value = "Adds the data type to the resource set")
@RequestMapping(value = "/link/datatype/{resourceId}/{namespace}/{name}/{version:.+}", method = RequestMethod.GET)
Expand All @@ -60,7 +60,7 @@ public void linkEditor(@ApiParam(value = "ResourceId", required = true) final @P
HashSet<String> referencedResourceSet = (HashSet<String>) webEditorResourceSetProvider
.getReferencedResourcesFromSession(httpServiceContext);

String content = iFunctionBlockEditorService.linkDatatypeToFunctionBlock(resourceId, modelId, resourceSet, referencedResourceSet);
String content = functionBlockEditorService.linkModelToResource(resourceId, modelId, resourceSet, referencedResourceSet);
try {
IOUtils.copy(new ByteArrayInputStream(content.getBytes()), response.getOutputStream());
response.flushBuffer();
Expand All @@ -75,6 +75,6 @@ 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);
return functionBlockEditorService.searchModelByExpression(expression);
}
}
Expand Up @@ -14,7 +14,7 @@
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.vorto.server.devtool.service.editor.InformationModelEditorServiceImpl;
import org.eclipse.xtext.web.server.model.IWebResourceSetProvider;
import org.eclipse.xtext.web.servlet.HttpServiceContext;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -30,18 +30,17 @@

@RestController
@RequestMapping(value = "/editor/infomodel")
public class InformationModelEditorController implements IEditorController{
public class InformationModelEditorController implements IEditorController {

@Autowired
Injector injector;

@Autowired
IInformationModelEditorService iInformationModelEditorService;
InformationModelEditorServiceImpl 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,
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,
Expand All @@ -62,8 +61,8 @@ public void linkEditor(
HashSet<String> referencedResourceSet = (HashSet<String>) webEditorResourceSetProvider
.getReferencedResourcesFromSession(httpServiceContext);

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

return iInformationModelEditorService.searchModelByExpression(expression);
}
}

This file was deleted.

This file was deleted.

@@ -0,0 +1,44 @@
package org.eclipse.vorto.server.devtool.service.editor;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
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.DevtoolReferenceLinker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class FunctionBlockEditorServiceImpl extends IEditorService {

@Autowired
DevtoolReferenceLinker devtoolReferenceLinker;

public String linkModelToResource(String functionBlockResourceId, ModelId datatypeModelId,
ResourceSet resourceSet, Set<String> referencedResourceSet) {
devtoolReferenceLinker.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);
}

}

public List<ModelResource> searchModelByExpression(String expression) {
List<ModelResource> modelList = searchModelByExpressionAndValidate(expression + " " + org.eclipse.vorto.http.model.ModelType.Datatype.toString() , org.eclipse.vorto.http.model.ModelType.Datatype);
List<ModelResource> functionBlockModelList = searchModelByExpressionAndValidate(expression + " " + org.eclipse.vorto.http.model.ModelType.Functionblock.toString(), org.eclipse.vorto.http.model.ModelType.Functionblock);
modelList.addAll(functionBlockModelList);
return modelList;
}
}
@@ -0,0 +1,36 @@
package org.eclipse.vorto.server.devtool.service.editor;

import java.util.ArrayList;
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;
import org.eclipse.vorto.server.devtool.utils.DevtoolRestClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public abstract class IEditorService {

@Autowired
DevtoolRestClient devtoolRestClient;

public abstract String linkModelToResource(String infoModelResourceId, ModelId modelId, ResourceSet resourceSet,
Set<String> referencedResourceSet);

public abstract List<ModelResource> searchModelByExpression(String expression);

protected final List<ModelResource> searchModelByExpressionAndValidate(String expression,
org.eclipse.vorto.http.model.ModelType modelType) {
List<ModelResource> resourceList = devtoolRestClient.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,40 @@
package org.eclipse.vorto.server.devtool.service.editor;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
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.DevtoolReferenceLinker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class InformationModelEditorServiceImpl extends IEditorService {

@Autowired
DevtoolReferenceLinker devtoolReferenceLinker;

public String linkModelToResource(String infoModelResourceId, ModelId functionBlockModelId,
ResourceSet resourceSet, Set<String> referencedResourceSet) {
devtoolReferenceLinker.linkFunctionBlockToInfoModel(infoModelResourceId, functionBlockModelId,
resourceSet, referencedResourceSet);
Resource infoModelResource = resourceSet.getResource(URI.createURI(infoModelResourceId), true);
try {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
infoModelResource.save(byteArrayOutputStream, null);
return byteArrayOutputStream.toString();
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public List<ModelResource> searchModelByExpression(String expression) {
return searchModelByExpressionAndValidate(expression + org.eclipse.vorto.http.model.ModelType.Functionblock.toString(), org.eclipse.vorto.http.model.ModelType.Functionblock);
}
}

This file was deleted.

This file was deleted.

Expand Up @@ -424,18 +424,15 @@ define(["angular"], function(angular) {
$scope.search = function() {
var filter = null;
var modelType = null;
filter = $scope.queryFilter;
if ($scope.tabs[$scope.selectedTabIndex]['language'] == 'infomodel') {
modelType = "fbmodel";
filter = $scope.queryFilter + " " + modelType;
$http.get('./editor/infomodel/search=' + filter).success(
function(data, status, headers, config) {
$scope.models = data;
}).error(function(data, status, headers, config) {
$scope.models = [];
});
} else if ($scope.tabs[$scope.selectedTabIndex]['language'] == 'fbmodel') {
modelType = "Datatype";
filter = $scope.queryFilter + " " + modelType;
$http.get('./editor/functionblock/search=' + filter).success(
function(data, status, headers, config) {
$scope.models = data;
Expand Down

0 comments on commit a865306

Please sign in to comment.