Search in sources :

Example 1 with DependencyManager

use of org.eclipse.vorto.repository.core.impl.utils.DependencyManager in project vorto by eclipse.

the class ModelRepository method saveChangeSetIntoRepository.

/**
 * saves the given changeset in a sorted way into the repository in the context of the given user
 *
 * @param changeSet
 * @param user
 */
private void saveChangeSetIntoRepository(ChangeSet changeSet, IUserContext user) {
    DependencyManager dm = new DependencyManager();
    changeSet.getChanges().forEach(model -> dm.addResource(new ModelResource(model)));
    dm.getSorted().forEach(sortedModel -> save((ModelResource) sortedModel, user));
}
Also used : DependencyManager(org.eclipse.vorto.repository.core.impl.utils.DependencyManager)

Example 2 with DependencyManager

use of org.eclipse.vorto.repository.core.impl.utils.DependencyManager 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;
}
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 3 with DependencyManager

use of org.eclipse.vorto.repository.core.impl.utils.DependencyManager 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();
}
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 4 with DependencyManager

use of org.eclipse.vorto.repository.core.impl.utils.DependencyManager 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 5 with DependencyManager

use of org.eclipse.vorto.repository.core.impl.utils.DependencyManager in project vorto by eclipse.

the class AbstractModelImporter method sortAndSaveToRepository.

private List<ModelInfo> sortAndSaveToRepository(List<ModelResource> resources, FileUpload extractedFile, Context context) {
    final IUserContext user = context.getUser();
    List<ModelInfo> savedModels = new ArrayList<>();
    DependencyManager dm = new DependencyManager();
    for (ModelResource resource : resources) {
        dm.addResource(resource);
    }
    dm.getSorted().forEach(resource -> {
        try {
            IModelRepository modelRepository = modelRepoFactory.getRepositoryByModel(resource.getId());
            ModelInfo importedModel = modelRepository.save((ModelResource) resource, user);
            savedModels.add(importedModel);
            postProcessImportedModel(importedModel, new FileContent(extractedFile.getFileName(), extractedFile.getContent()), user);
        } catch (Exception e) {
            logger.error("Problem importing model", e);
            throw new ModelImporterException("Problem importing model", e);
        }
    });
    return savedModels;
}
Also used : IModelRepository(org.eclipse.vorto.repository.core.IModelRepository) FileContent(org.eclipse.vorto.repository.core.FileContent) IUserContext(org.eclipse.vorto.repository.core.IUserContext) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ModelResource(org.eclipse.vorto.repository.core.ModelResource) ArrayList(java.util.ArrayList) DependencyManager(org.eclipse.vorto.repository.core.impl.utils.DependencyManager) IOException(java.io.IOException) BulkUploadException(org.eclipse.vorto.repository.web.core.exceptions.BulkUploadException)

Aggregations

DependencyManager (org.eclipse.vorto.repository.core.impl.utils.DependencyManager)5 FileContent (org.eclipse.vorto.repository.core.FileContent)4 ModelInfo (org.eclipse.vorto.repository.core.ModelInfo)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ModelWorkspaceReader (org.eclipse.vorto.utilities.reader.ModelWorkspaceReader)3 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 IModelRepository (org.eclipse.vorto.repository.core.IModelRepository)1 IUserContext (org.eclipse.vorto.repository.core.IUserContext)1 ModelResource (org.eclipse.vorto.repository.core.ModelResource)1 BulkUploadException (org.eclipse.vorto.repository.web.core.exceptions.BulkUploadException)1