use of org.eclipse.vorto.utilities.reader.ModelWorkspaceReader in project vorto by eclipse.
the class ModelRepository method createWorkspaceFromModelAndReferences.
private IModelWorkspace createWorkspaceFromModelAndReferences(ModelId modelId) {
ModelWorkspaceReader reader = IModelWorkspace.newReader();
ModelResource resource = getEMFResource(modelId);
reader.addFile(new ByteArrayInputStream(resource.toDSL()), resource.getType());
getModelsReferencing(modelId).forEach(reference -> {
ModelResource referencingModel = getEMFResource(reference.getId());
reader.addFile(new ByteArrayInputStream(referencingModel.toDSL()), referencingModel.getType());
});
return reader.read();
}
use of org.eclipse.vorto.utilities.reader.ModelWorkspaceReader in project vorto by eclipse.
the class DefaultPayloadMappingService method getWorkspaceForModel.
private IModelWorkspace getWorkspaceForModel(final ModelId modelId) {
List<ModelInfo> allModels = getModelWithAllDependencies(modelId);
DependencyManager dm = new DependencyManager(new HashSet<>(allModels));
allModels = dm.getSorted();
ModelWorkspaceReader workspaceReader = IModelWorkspace.newReader();
for (ModelInfo model : allModels) {
FileContent modelContent = this.modelRepositoryFactory.getRepositoryByModel(model.getId()).getFileContent(model.getId(), Optional.of(model.getFileName())).get();
workspaceReader.addFile(new ByteArrayInputStream(modelContent.getContent()), model.getType());
}
return workspaceReader.read();
}
use of org.eclipse.vorto.utilities.reader.ModelWorkspaceReader in project vorto by eclipse.
the class GeneratorTest method andModels.
public GeneratorTest andModels(ModelEntry... modelEntries) throws GeneratorTestException {
ModelWorkspaceReader modelWorkspaceReader = IModelWorkspace.newReader();
for (ModelEntry modelEntry : modelEntries) {
if (modelEntry.modelDsl == null || modelEntry.modelType == null) {
throw new GeneratorTestException("Cannot read model");
}
modelWorkspaceReader.addFile(new ByteArrayInputStream(modelEntry.modelDsl.getBytes(StandardCharsets.UTF_8)), modelEntry.modelType);
}
this.modelWorkspace = modelWorkspaceReader.read();
return this;
}
use of org.eclipse.vorto.utilities.reader.ModelWorkspaceReader in project vorto by eclipse.
the class ModelIdToModelContentConverter method convert.
@Override
public ModelContent convert(ModelId modelId, Optional<String> platformKey) {
modelId = repositoryFactory.getRepositoryByNamespace(modelId.getNamespace()).getLatestModelVersionIfLatestTagIsSet(modelId);
if (!repositoryFactory.getRepositoryByModel(modelId).exists(modelId)) {
throw new ModelNotFoundException(String.format("Model [%s] does not exist", modelId.getPrettyFormat()), null);
}
ModelWorkspaceReader workspaceReader = getWorkspaceForModel(modelId);
ModelContent result = new ModelContent();
result.setRoot(modelId);
if (platformKey.isPresent()) {
final List<ModelInfo> mappingResources = repositoryFactory.getRepositoryByModel(modelId).getMappingModelsForTargetPlatform(modelId, platformKey.get(), Optional.empty());
if (!mappingResources.isEmpty()) {
// adding to workspace reader in order to resolve cross linking between mapping models correctly
mappingResources.forEach(mapping -> workspaceReader.addFile(new ByteArrayInputStream(repositoryFactory.getRepositoryByModel(mapping.getId()).getFileContent(mapping.getId(), Optional.empty()).get().getContent()), org.eclipse.vorto.model.ModelType.Mapping));
final IModelWorkspace workspace = workspaceReader.read();
workspace.get().forEach(model -> {
Optional<MappingModel> mappingModel = getMappingModelForModel(mappingResources, model);
if (mappingModel.isPresent()) {
AbstractModel createdModel = ModelDtoFactory.createResource(flattenHierarchy(model), mappingModel);
createdModel.setTargetPlatformKey(platformKey.get());
result.getModels().put(new ModelId(model.getName(), model.getNamespace(), model.getVersion()), createdModel);
} else {
result.getModels().put(new ModelId(model.getName(), model.getNamespace(), model.getVersion()), ModelDtoFactory.createResource(flattenHierarchy(model), Optional.empty()));
}
});
} else {
final IModelWorkspace workspace = workspaceReader.read();
workspace.get().forEach(model -> {
AbstractModel createdModel = ModelDtoFactory.createResource(flattenHierarchy(model), Optional.empty());
createdModel.setTargetPlatformKey(platformKey.get());
result.getModels().put(new ModelId(model.getName(), model.getNamespace(), model.getVersion()), createdModel);
});
}
} else {
final IModelWorkspace workspace = workspaceReader.read();
workspace.get().forEach(model -> {
AbstractModel createdModel = ModelDtoFactory.createResource(flattenHierarchy(model), Optional.empty());
result.getModels().put(new ModelId(model.getName(), model.getNamespace(), model.getVersion()), createdModel);
});
}
return result;
}
Aggregations