Search in sources :

Example 6 with ModelWorkspaceReader

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();
}
Also used : ModelWorkspaceReader(org.eclipse.vorto.utilities.reader.ModelWorkspaceReader) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 7 with ModelWorkspaceReader

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();
}
Also used : FileContent(org.eclipse.vorto.repository.core.FileContent) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ModelWorkspaceReader(org.eclipse.vorto.utilities.reader.ModelWorkspaceReader) ByteArrayInputStream(java.io.ByteArrayInputStream) DependencyManager(org.eclipse.vorto.repository.core.impl.utils.DependencyManager)

Example 8 with ModelWorkspaceReader

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;
}
Also used : ModelWorkspaceReader(org.eclipse.vorto.utilities.reader.ModelWorkspaceReader) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 9 with ModelWorkspaceReader

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;
}
Also used : ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ModelWorkspaceReader(org.eclipse.vorto.utilities.reader.ModelWorkspaceReader) ByteArrayInputStream(java.io.ByteArrayInputStream) ModelContent(org.eclipse.vorto.model.ModelContent) AbstractModel(org.eclipse.vorto.model.AbstractModel) ModelNotFoundException(org.eclipse.vorto.repository.core.ModelNotFoundException) IModelWorkspace(org.eclipse.vorto.utilities.reader.IModelWorkspace) ModelId(org.eclipse.vorto.model.ModelId)

Aggregations

ModelWorkspaceReader (org.eclipse.vorto.utilities.reader.ModelWorkspaceReader)9 ByteArrayInputStream (java.io.ByteArrayInputStream)7 ModelInfo (org.eclipse.vorto.repository.core.ModelInfo)4 IModelWorkspace (org.eclipse.vorto.utilities.reader.IModelWorkspace)4 FileContent (org.eclipse.vorto.repository.core.FileContent)3 DependencyManager (org.eclipse.vorto.repository.core.impl.utils.DependencyManager)3 File (java.io.File)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 FileUtils (org.apache.commons.io.FileUtils)2 FilenameUtils (org.apache.commons.io.FilenameUtils)2 IOUtils (org.apache.commons.io.IOUtils)2 EclipseDittoGenerator (org.eclipse.vorto.codegen.ditto.EclipseDittoGenerator)2 BuilderUtils (org.eclipse.vorto.core.api.model.BuilderUtils)2 FunctionblockModel (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel)2 InformationModel (org.eclipse.vorto.core.api.model.informationmodel.InformationModel)2 ModelId (org.eclipse.vorto.core.api.model.model.ModelId)2 ModelType (org.eclipse.vorto.model.ModelType)2 AbstractGeneratorTest (org.eclipse.vorto.plugin.AbstractGeneratorTest)2 GeneratorException (org.eclipse.vorto.plugin.generator.GeneratorException)2