use of org.eclipse.vorto.utilities.reader.ModelWorkspaceReader in project vorto by eclipse.
the class VortoModelImporter method preValidation.
/**
* changes the namespace of the uploaded vorto model(s) , if target namespace is specified
*/
@Override
protected FileUpload preValidation(FileUpload fileUpload, Context context) {
if (context.getTargetNamespace().isPresent()) {
if (fileUpload.getFileExtension().endsWith(EXTENSION_ZIP)) {
ModelWorkspaceReader reader = IModelWorkspace.newReader();
getUploadedFilesFromZip(fileUpload.getContent()).stream().filter(this::isSupported).forEach(extractedFile -> {
reader.addFile(new ByteArrayInputStream(addVortolangIfMissing(extractedFile).getContent()), ModelType.fromFileName(extractedFile.getFileExtension()));
});
IModelWorkspace workspace = reader.read();
ChangeSet changeSet = RefactoringTask.from(workspace).toNamespaceForAllModels(context.getTargetNamespace().get()).execute();
ZipUploadFile zipFile = new ZipUploadFile(fileUpload.getFileName());
for (Model model : changeSet.get()) {
ModelResource resource = new ModelResource(model);
zipFile.addToZip(FileUpload.create(resource.getId().getPrettyFormat().replace("\\.", "_") + resource.getType().getExtension(), resource.toDSL()));
}
return zipFile.getFileUpload();
} else {
return refactor(addVortolangIfMissing(fileUpload), context.getTargetNamespace().get());
}
} else {
return addVortolangIfMissing(fileUpload);
}
}
use of org.eclipse.vorto.utilities.reader.ModelWorkspaceReader in project vorto by eclipse.
the class ModelIdToModelContentConverter method getWorkspaceForModel.
private ModelWorkspaceReader getWorkspaceForModel(final ModelId modelId) {
Collection<ModelInfo> allModels = getModelWithAllDependencies(modelId);
DependencyManager dm = new DependencyManager(new HashSet<>(allModels));
allModels = dm.getSorted();
ModelWorkspaceReader workspaceReader = IModelWorkspace.newReader();
for (ModelInfo model : allModels) {
FileContent modelContent = repositoryFactory.getRepositoryByModel(model.getId()).getFileContent(model.getId(), Optional.of(model.getFileName())).get();
workspaceReader.addFile(new ByteArrayInputStream(modelContent.getContent()), model.getType());
}
return workspaceReader;
}
use of org.eclipse.vorto.utilities.reader.ModelWorkspaceReader in project vorto by eclipse.
the class EclipseDittoGeneratorTest method inheritanceFunctionBlockProvider.
public InformationModel inheritanceFunctionBlockProvider(String rootFunctionBlockName, String... functionBlocks) {
ModelWorkspaceReader mwr = IModelWorkspace.newReader();
for (String parentFb : functionBlocks) {
mwr.addFile(getClass().getClassLoader().getResourceAsStream(folderPath + parentFb), ModelType.Functionblock);
}
IModelWorkspace workspace = mwr.read();
FunctionblockModel fb = (FunctionblockModel) workspace.get().stream().filter(p -> p.getName().equals(rootFunctionBlockName)).findAny().get();
return Utils.toInformationModel(fb);
}
use of org.eclipse.vorto.utilities.reader.ModelWorkspaceReader in project vorto by eclipse.
the class AbstractRepositoryController method getWorkspaceForModel.
protected 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 = getModelRepository(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 EclipseDittoGeneratorTest method modelProvider.
public InformationModel modelProvider(String... filenames) {
ModelWorkspaceReader mwr = IModelWorkspace.newReader();
for (String filename : filenames) {
mwr.addFile(getClass().getClassLoader().getResourceAsStream(folderPath + filename), FILENAME_TO_TYPE_MAP.get(FilenameUtils.getExtension(filename)));
}
IModelWorkspace workspace = mwr.read();
InformationModel model = (InformationModel) workspace.get().stream().filter(p -> p instanceof InformationModel).findAny().get();
return model;
}
Aggregations