Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Signed-off-by: shiv12095 <[email protected]>
  • Loading branch information
shiv12095 committed Aug 28, 2017
1 parent 6abdb2c commit 32ec76d
Show file tree
Hide file tree
Showing 60 changed files with 2,581 additions and 372 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
package org.eclipse.vorto.editor.datatype.web

import org.eclipse.vorto.editor.web.resource.ContentTypeProvider
import org.eclipse.vorto.editor.web.resource.FileResourceHandler
import org.eclipse.vorto.editor.web.resource.WebEditorResourceSetProvider
import org.eclipse.vorto.editor.web.resource.WedEditorResourceHandler
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor
import org.eclipse.xtext.web.server.model.IWebResourceSetProvider
import org.eclipse.xtext.web.server.persistence.IServerResourceHandler
Expand All @@ -36,7 +36,7 @@ class DatatypeWebModule extends AbstractDatatypeWebModule {
}

def Class<? extends IServerResourceHandler> bindIServerResourceHandler() {
return FileResourceHandler;
return WedEditorResourceHandler;
}

override bindIContentTypeProvider() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
package org.eclipse.vorto.editor.functionblock.web

import org.eclipse.vorto.editor.web.resource.ContentTypeProvider
import org.eclipse.vorto.editor.web.resource.FileResourceHandler
import org.eclipse.vorto.editor.web.resource.WebEditorResourceSetProvider
import org.eclipse.vorto.editor.web.resource.WedEditorResourceHandler
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor
import org.eclipse.xtext.web.server.model.IWebResourceSetProvider
import org.eclipse.xtext.web.server.persistence.IServerResourceHandler
Expand All @@ -36,7 +36,7 @@ class FunctionblockWebModule extends AbstractFunctionblockWebModule {
}

def Class<? extends IServerResourceHandler> bindIServerResourceHandler() {
return FileResourceHandler;
return WedEditorResourceHandler;
}

override bindIContentTypeProvider() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
package org.eclipse.vorto.editor.infomodel.web

import org.eclipse.vorto.editor.web.resource.ContentTypeProvider
import org.eclipse.vorto.editor.web.resource.FileResourceHandler
import org.eclipse.vorto.editor.web.resource.WebEditorResourceSetProvider
import org.eclipse.vorto.editor.web.resource.WedEditorResourceHandler
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor
import org.eclipse.xtext.web.server.model.IWebResourceSetProvider
import org.eclipse.xtext.web.server.persistence.IServerResourceHandler
Expand All @@ -36,7 +36,7 @@ class InformationModelWebModule extends AbstractInformationModelWebModule {
}

def Class<? extends IServerResourceHandler> bindIServerResourceHandler() {
return FileResourceHandler;
return WedEditorResourceHandler;
}

override bindIContentTypeProvider() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/**
* Copyright (c) 2017 Bosch Software Innovations GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* The Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Bosch Software Innovations GmbH - Please refer to git log
*/
package org.eclipse.vorto.editor.web.resource

import com.google.inject.Inject
import java.io.ByteArrayInputStream
import java.io.IOException
import org.eclipse.emf.common.notify.impl.NotificationChainImpl
import org.eclipse.emf.common.util.URI
import org.eclipse.emf.common.util.WrappedException
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.emf.ecore.resource.ResourceSet
import org.eclipse.vorto.devtool.projectrepository.IProjectRepositoryService
import org.eclipse.vorto.devtool.projectrepository.model.FileUploadHandle
import org.eclipse.vorto.devtool.projectrepository.model.FolderResource
import org.eclipse.vorto.devtool.projectrepository.model.ModelResource
import org.eclipse.vorto.devtool.projectrepository.model.ResourceType
import org.eclipse.vorto.devtool.projectrepository.utils.ProjectRepositoryConstants
import org.eclipse.xtext.resource.XtextResource
import org.eclipse.xtext.web.server.IServiceContext
import org.eclipse.xtext.web.server.model.IWebDocumentProvider
import org.eclipse.xtext.web.server.model.IWebResourceSetProvider
import org.eclipse.xtext.web.server.model.IXtextWebDocument
import org.eclipse.xtext.web.server.persistence.IServerResourceHandler

class WedEditorResourceHandler implements IServerResourceHandler {

@Inject
private IWebResourceSetProvider resourceSetProvider

@Inject
private IWebDocumentProvider documentProvider

@Inject
private IProjectRepositoryService repositoryService;

def getModelResource(String resourceId) {
val modelResource = repositoryService.createQuery.property(ProjectRepositoryConstants.META_PROPERTY_RESOURCE_ID,
resourceId).singleResult() as ModelResource;
return modelResource;
}

def createResource(ModelResource modelResource, URI uri, ResourceSet resourceSet){
val resourceList = resourceSet.getResources();
var createResource = true;
for (Resource resource : resourceList) {
if (resource.getURI().equals(uri)) {
createResource = false;
}
}
if(createResource){
val resource = resourceSet.createResource(uri)
resource.load(new ByteArrayInputStream(modelResource.content), resourceSet.getLoadOptions())
}
}

override get(String resourceId, IServiceContext serviceContext) throws IOException {
try {
val resourceSet = resourceSetProvider.get(resourceId, serviceContext)
val modelResource = getModelResource(resourceId)
val uri = URI.createURI(ProjectRepositoryConstants.DUMMY + modelResource.path)
createResource(modelResource, uri, resourceSet)
val xtextResource = resourceSet.getResource(uri, true) as XtextResource
return documentProvider.get(resourceId, serviceContext) => [
setInput(xtextResource)
]
} catch (WrappedException exception) {
throw exception.cause
}
}

override put(IXtextWebDocument document, IServiceContext serviceContext) throws IOException {
try {
val resourceId = document.resourceId
val resourceSet = resourceSetProvider.get(resourceId, serviceContext)
if (document.resource.resourceSet === null) {
document.resource.basicSetResourceSet(resourceSet, new NotificationChainImpl)
}
val content = document.text
val modelResource = getModelResource(resourceId)
val fileName = modelResource.properties.get(ProjectRepositoryConstants.META_PROPERTY_FILE_NAME)
val projectName = modelResource.properties.get(ProjectRepositoryConstants.META_PROPERTY_PROJECT_NAME)

val projectResource = repositoryService.createQuery().path(projectName.replace("\\", "/")).type(
ResourceType.ProjectResource).singleResult();
val fileUploadHandle = new FileUploadHandle(projectResource as FolderResource, fileName, content.bytes)
repositoryService.uploadResource(null, fileUploadHandle)

} catch (WrappedException exception) {
throw exception.cause
}
}
}
5 changes: 3 additions & 2 deletions server/devtool/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
<modules>
<module>projectrepository-api</module>
<module>projectrepository-file</module>
<module>projectrepository-modeshape</module>
<module>org.eclipse.vorto.editor.web</module>
<module>org.eclipse.vorto.editor.datatype.web</module>
<module>org.eclipse.vorto.editor.functionblock.web</module>
<module>org.eclipse.vorto.editor.infomodel.web</module>
<module>webeditor</module>
</modules>
</project>

</project>
15 changes: 13 additions & 2 deletions server/devtool/projectrepository-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,18 @@
<name>Project-Repository API</name>
<description>Project Repository API which lets you persist your projects to various storages</description>

</project>

<dependencies>

<!-- Vorto Dependencies -->
<dependency>
<groupId>org.eclipse.vorto</groupId>
<artifactId>repository-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.vorto</groupId>
<artifactId>org.eclipse.vorto.server.commons</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
*/
package org.eclipse.vorto.devtool.projectrepository;


import java.util.Map;

import org.eclipse.vorto.devtool.projectrepository.exception.ResourceAlreadyExistsError;
import org.eclipse.vorto.devtool.projectrepository.model.FileResource;
import org.eclipse.vorto.devtool.projectrepository.model.FolderResource;
import org.eclipse.vorto.devtool.projectrepository.model.ProjectResource;
Expand Down Expand Up @@ -108,7 +110,7 @@ public ProjectResource createProject(String projectName, String commitMessage)
* The properties of the resource that would be added / modified
*/
public void updateFolderResourceProperties(FolderResource folderResource, Map<String,String> properties);

/**
* Create a version of a project.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Contributors:
* Bosch Software Innovations GmbH - Please refer to git log
*/
package org.eclipse.vorto.devtool.projectrepository;
package org.eclipse.vorto.devtool.projectrepository.exception;

/**
* Exception superclass for all exceptions thrown within project repository.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Contributors:
* Bosch Software Innovations GmbH - Please refer to git log
*/
package org.eclipse.vorto.devtool.projectrepository;
package org.eclipse.vorto.devtool.projectrepository.exception;

/**
* Exception thrown when a duplicate resource shall be created.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Contributors:
* Bosch Software Innovations GmbH - Please refer to git log
*/
package org.eclipse.vorto.devtool.projectrepository;
package org.eclipse.vorto.devtool.projectrepository.exception;

/**
* Thrown when a UploadHandle is of the wrong type for the intended purpose.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,17 @@
public class FileResource extends Resource {

private String encoding;
private String fileName;

public String getFileName() {
return fileName;
}

public void setFileName(String fileName) {
this.fileName = fileName;
}

public void setEncoding(String encoding) {
public void setEncoding(String encoding) {
this.encoding = encoding;
}

Expand All @@ -45,8 +54,6 @@ public String toString() {
return "FileResource [encoding=" + encoding + ", toString()=" + super.toString() + "]";
}



}

/* EOF */
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,31 @@ public class FileUploadHandle extends UploadHandle {
private byte[] content;

private String encoding;

private String fileName;

public FileUploadHandle(FolderResource folder, String fileName, byte[] content, String encoding) {
public FileUploadHandle(FolderResource folder, String fileName, byte[] content, String encoding) {
super(folder.getPath() + "/" + fileName);
this.content = content;
this.encoding = encoding;
this.fileName = fileName;
}

public FileUploadHandle(FolderResource folder, String fileName, byte[] content) {
super(folder.getPath() + "/" + fileName);
this.content = content;
this.fileName = fileName;
this.encoding = "utf-8";
}

public byte[] getContent() {
return content;
}

public String getFileName() {
return fileName;
}

/**
* @return the encoding name for this file upload handle.
*/
Expand Down
Loading

0 comments on commit 32ec76d

Please sign in to comment.