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 Jun 22, 2017
1 parent 0ac1dc5 commit bf07026
Show file tree
Hide file tree
Showing 24 changed files with 268 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ 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
import org.eclipse.emf.common.notify.impl.NotificationChainImpl

class FileResourceHandler implements IServerResourceHandler {

Expand Down Expand Up @@ -69,6 +70,10 @@ class FileResourceHandler implements IServerResourceHandler {
override put(IXtextWebDocument document, IServiceContext serviceContext) throws IOException {
try {
val uri = getFileURI(document.resourceId)
val resourceSet = resourceSetProvider.get(document.resourceId, serviceContext)
if(document.resource.resourceSet === null){
document.resource.basicSetResourceSet(resourceSet, new NotificationChainImpl);
}
val outputStream = document.resource.resourceSet.URIConverter.createOutputStream(uri)
val writer = new OutputStreamWriter(outputStream, encodingProvider.getEncoding(uri))
writer.write(document.text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Map;

import org.eclipse.vorto.devtool.projectrepository.model.FileResource;
import org.eclipse.vorto.devtool.projectrepository.model.FolderResource;
import org.eclipse.vorto.devtool.projectrepository.model.ProjectResource;
import org.eclipse.vorto.devtool.projectrepository.model.Resource;
import org.eclipse.vorto.devtool.projectrepository.model.ResourceContent;
Expand Down Expand Up @@ -98,6 +99,16 @@ public ProjectResource createProject(String projectName, String commitMessage)
*/
public void uploadResource(String commitComment, UploadHandle... handle);

/**
* Updates the old properties of the resource with the new properties
*
* @param folderResource
* The folderResource whose properties would be updated
* @param properties
* 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
@@ -1,23 +1,40 @@
package org.eclipse.vorto.devtool.projectrepository.file;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import org.eclipse.vorto.devtool.projectrepository.model.Resource;

public class ProjectRepositoryFileConstants {

public static final String META_PROPERTY_AUTHOR = Resource.META_PROPERTY_AUTHOR;

public static final String META_PROPERTY_RESOURCE_ID = "resourceId";

public static final String META_PROPERTY_NAME = "name";

public static final String META_PROPERTY_NAMESPACE = "namespace";

public static final String META_PROPERTY_VERSION = "version";

public static final String META_PROPERTY_MODEL_TYPE = "modelType";

public static final String META_PROPERTY_MODEL_SUB_TYPE = "modelSubType";

public static final String META_PROPERTY_IS_PROJECT = "isProject";


public static final String META_PROPERTY_REFERENCES = "references";

public static Set<String> IMMUTABLE_META_PROPERTY_SET = new HashSet<String>(Arrays.asList(
META_PROPERTY_AUTHOR,
META_PROPERTY_IS_PROJECT,
META_PROPERTY_RESOURCE_ID,
META_PROPERTY_NAME,
META_PROPERTY_NAMESPACE,
META_PROPERTY_VERSION,
META_PROPERTY_MODEL_SUB_TYPE,
META_PROPERTY_MODEL_TYPE
));

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
Expand All @@ -32,6 +33,7 @@
import org.eclipse.vorto.devtool.projectrepository.WrongUploadHandleTypeError;
import org.eclipse.vorto.devtool.projectrepository.model.FileResource;
import org.eclipse.vorto.devtool.projectrepository.model.FileUploadHandle;
import org.eclipse.vorto.devtool.projectrepository.model.FolderResource;
import org.eclipse.vorto.devtool.projectrepository.model.FolderUploadHandle;
import org.eclipse.vorto.devtool.projectrepository.model.ProjectResource;
import org.eclipse.vorto.devtool.projectrepository.model.ProjectUploadHandle;
Expand Down Expand Up @@ -76,7 +78,7 @@ public ProjectResource createProject(String name, String commitMessage) throws R
log.info("Create a new project. Name : " + name);
File projectFolder = new File(projectsDirectory + File.separator + name);
createProjectDirectory(projectFolder);

Map<String, String> properties = addProjectResourceProperties(new HashMap<String, String>());
createMetaFile(addSystemProperties(properties), projectFolder);
log.info("Directory for Project " + name + " created.");
Expand All @@ -94,10 +96,10 @@ private Map<String, String> addSystemProperties(Map<String, String> source) {
@Override
public ProjectResource createProject(String name, Map<String, String> properties, String commitMessage)
throws ResourceAlreadyExistsError {
log.info("Create a new project. Name : " + name);
log.info("Create a new project. Name : " + name);
File projectFolder = new File(projectsDirectory + File.separator + name);
createProjectDirectory(projectFolder);

properties = addProjectResourceProperties(properties);
createMetaFile(addSystemProperties(properties), projectFolder);
log.info("Directory for Project " + name + " created.");
Expand Down Expand Up @@ -160,6 +162,27 @@ public void uploadResource(String commitComment, UploadHandle... handles) {
}
}

@Override
@SuppressWarnings({"unchecked", "rawtypes"})
public void updateFolderResourceProperties(FolderResource resource, Map<String, String> properties) {
String metaFileDirectoryPath = projectsDirectory + File.separator + resource.getPath();
File metaFileDirectory = new File(metaFileDirectoryPath);
File metaFile = new File(metaFileDirectoryPath, META_PROPERTY_FILENAME);
Properties metaProperties = new Properties();
try {
metaProperties.loadFromXML(new FileInputStream(metaFile));
} catch (Exception ex) {
// Nothing to do here.
}
HashMap<String, String> map = new HashMap(metaProperties);
for (Map.Entry<String, String> entry : properties.entrySet()) {
if(!ProjectRepositoryFileConstants.IMMUTABLE_META_PROPERTY_SET.contains(entry.getKey())){
map.put(entry.getKey(), entry.getValue());
}
}
createMetaFile(map, metaFileDirectory);
}

@Override
public void createVersionOfProject(String versionName, String projectName) {
throw new UnsupportedOperationException();
Expand Down Expand Up @@ -322,7 +345,7 @@ private File createFile(FileUploadHandle content) {
public String theProjectsDirectory() {
return this.projectsDirectory;
}

private Map<String, String> addProjectResourceProperties(Map<String, String> source) {
source.put(ProjectRepositoryFileConstants.META_PROPERTY_IS_PROJECT, String.valueOf(true));
return source;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public IProjectRepositoryService projectRepositoryService() {

@Bean
public GlobalContext getGlobalContext(){
return new GlobalContext(repositoryBasePath, referenceRepository);
return new GlobalContext(repositoryBasePath);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public IProjectRepositoryService projectRepositoryService() {

@Bean
public GlobalContext getGlobalContext(){
return new GlobalContext(repositoryBasePath, referenceRepository);
return new GlobalContext(repositoryBasePath);
}

@Bean
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.server.devtool.http.response;
package org.eclipse.vorto.server.devtool.http.request;

public class DeleteResourceRequest {

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.server.devtool.http.response;
package org.eclipse.vorto.server.devtool.http.request;

public class LinkReferenceModelRequest {

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.server.devtool.http.response;
package org.eclipse.vorto.server.devtool.http.request;

public class LinkReferenceResourceRequest {

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.server.devtool.http.request;
package org.eclipse.vorto.server.devtool.http.response;

import org.eclipse.vorto.devtool.projectrepository.model.Resource;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@
public class GlobalContext {

public String repositoryBasePath = null;

public String referenceRepository = null;

public GlobalContext(String repositoryBasePath, String referenceRepository) {

public GlobalContext(String repositoryBasePath) {
this.repositoryBasePath = repositoryBasePath;
this.referenceRepository = referenceRepository;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.eclipse.vorto.server.devtool.models;

public class LinkReferenceResponse {

private String content;
private String targetResourceId;
private String referenceResourceId;

public LinkReferenceResponse(String content, String targetResourceId, String referenceResourceId) {
this.content = content;
this.targetResourceId = targetResourceId;
this.referenceResourceId = referenceResourceId;
}

public String getContent() {
return content;
}

public void setContent(String content) {
this.content = content;
}

public String getTargetResourceId() {
return targetResourceId;
}

public void setTargetResourceId(String targetResourceId) {
this.targetResourceId = targetResourceId;
}

public String getReferenceResourceId() {
return referenceResourceId;
}

public void setReferenceResourceId(String referenceResourceId) {
this.referenceResourceId = referenceResourceId;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.eclipse.vorto.repository.api.ModelId;
import org.eclipse.vorto.repository.api.ModelInfo;
import org.eclipse.vorto.repository.api.ModelType;
import org.eclipse.vorto.server.devtool.models.LinkReferenceResponse;
import org.eclipse.vorto.server.devtool.models.ModelResource;
import org.eclipse.vorto.server.devtool.utils.DevtoolReferenceLinker;
import org.eclipse.vorto.server.devtool.utils.DevtoolRestClient;
Expand All @@ -33,26 +34,26 @@ public abstract class IEditorService {

@Autowired
private DevtoolRestClient devtoolRestClient;

@Autowired
private DevtoolReferenceLinker devtoolReferenceLinker;

@Autowired
private DevtoolUtils devtoolUtils;

@Autowired
private IProjectService projectService;

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

public abstract String generateFileContent(ModelResource modelResource);

public abstract ModelInfo getAndValidateModelInfo(ModelId modelId);
public abstract void updateVariableNames(String targetResourceId, String referenceResourceId, ResourceSet resourceSet);

public final List<ModelInfo> searchModelByExpressionAndValidate(String expression,
List<ModelType> modelTypeList) {

public abstract void updateVariableNames(String targetResourceId, String referenceResourceId,
ResourceSet resourceSet);

public final List<ModelInfo> searchModelByExpressionAndValidate(String expression, List<ModelType> modelTypeList) {
List<ModelInfo> resourceList = devtoolRestClient.searchByExpression(expression);
ArrayList<ModelInfo> modelResourceList = new ArrayList<ModelInfo>();
for (ModelInfo modelResource : resourceList) {
Expand All @@ -65,29 +66,35 @@ public final List<ModelInfo> searchModelByExpressionAndValidate(String expressio
return modelResourceList;
}

public final String linkReferenceToResource(String targetResourceId, ModelId modelId, ResourceSet resourceSet) {
public final LinkReferenceResponse linkReferenceToResource(String targetResourceId, ModelId modelId,
ResourceSet resourceSet) {
validateArguments(targetResourceId, resourceSet);
ModelInfo modelInfo = getAndValidateModelInfo(modelId);
projectService.getReferencedResource(modelInfo);
String referenceResourceId = devtoolUtils.getReferencedResourceId(modelInfo);
return linkReference(targetResourceId, referenceResourceId, resourceSet);
String content = linkReference(targetResourceId, referenceResourceId, resourceSet);
LinkReferenceResponse linkReferenceResponse = new LinkReferenceResponse(content, targetResourceId,
referenceResourceId);
return linkReferenceResponse;
}

public final String linkReferenceToResource(String targetResourceId, String referenceResourceId,
public final LinkReferenceResponse linkReferenceToResource(String targetResourceId, String referenceResourceId,
ResourceSet resourceSet) {
validateArguments(referenceResourceId, resourceSet);
validateArguments(targetResourceId, resourceSet);
return linkReference(targetResourceId, referenceResourceId, resourceSet);
String content = linkReference(targetResourceId, referenceResourceId, resourceSet);
LinkReferenceResponse linkReferenceResponse = new LinkReferenceResponse(content, targetResourceId,
referenceResourceId);
return linkReferenceResponse;
}
private void validateArguments(String resourceId, ResourceSet resourceSet){

private void validateArguments(String resourceId, ResourceSet resourceSet) {
if (!devtoolReferenceLinker.containsResource(resourceId, resourceSet)) {
throw new RuntimeException("No resource with resourceId : " + resourceId);
}
}

private String linkReference(String targetResourceId, String referenceResourceId,
ResourceSet resourceSet){

private String linkReference(String targetResourceId, String referenceResourceId, ResourceSet resourceSet) {
devtoolReferenceLinker.linkReferenceToResource(targetResourceId, referenceResourceId, resourceSet);
updateVariableNames(targetResourceId, referenceResourceId, resourceSet);
return devtoolUtils.getResourceContentsAsString(targetResourceId, resourceSet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
public interface IProjectService {

ProjectResource createProject(String projectName, String author);

ProjectResource getProject(String projectName);

List<Resource> getProjects(String author);

Expand All @@ -40,4 +42,6 @@ public interface IProjectService {
void deleteResource(String projectName, String resourceId);

void deleteResource(String projectName, String author, String resourceId);
}

void addReferenceToProject(String projectName, String resourceId);
}
Loading

0 comments on commit bf07026

Please sign in to comment.