Search in sources :

Example 41 with ModelInfo

use of org.eclipse.vorto.repository.core.ModelInfo 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 42 with ModelInfo

use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.

the class AbstractRepositoryController method sendAsZipFile.

protected void sendAsZipFile(final HttpServletResponse response, final String fileName, List<ModelInfo> modelInfos) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ZipOutputStream zos = new ZipOutputStream(baos);
    try {
        for (ModelInfo modelInfo : modelInfos) {
            addModelToZip(zos, modelInfo.getId());
        }
        zos.close();
        baos.close();
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
    response.setHeader(CONTENT_DISPOSITION, ATTACHMENT_FILENAME + fileName);
    response.setContentType(APPLICATION_OCTET_STREAM);
    try {
        IOUtils.copy(new ByteArrayInputStream(baos.toByteArray()), response.getOutputStream());
        response.flushBuffer();
    } catch (IOException e) {
        throw new RuntimeException("Error copying file.", e);
    }
}
Also used : ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipOutputStream(java.util.zip.ZipOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) GenerationException(org.eclipse.vorto.repository.plugin.generator.GenerationException) ModelNotFoundException(org.eclipse.vorto.repository.core.ModelNotFoundException) ModelAlreadyExistsException(org.eclipse.vorto.repository.core.ModelAlreadyExistsException) NotAuthorizedException(org.eclipse.vorto.repository.web.core.exceptions.NotAuthorizedException) IOException(java.io.IOException) ValidationException(org.eclipse.vorto.repository.core.impl.validation.ValidationException) NewNamespacesNotSupersetException(org.eclipse.vorto.repository.tenant.NewNamespacesNotSupersetException)

Example 43 with ModelInfo

use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.

the class AbstractRepositoryController method getModelWithAllDependencies.

private List<ModelInfo> getModelWithAllDependencies(ModelId modelId) {
    List<ModelInfo> modelInfos = new ArrayList<>();
    ModelInfo modelResource = getModelRepository(modelId).getById(modelId);
    modelInfos.add(modelResource);
    for (ModelId reference : modelResource.getReferences()) {
        modelInfos.addAll(getModelWithAllDependencies(reference));
    }
    return modelInfos;
}
Also used : ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ArrayList(java.util.ArrayList) ModelId(org.eclipse.vorto.model.ModelId)

Example 44 with ModelInfo

use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.

the class VortolangUpgradeTask method doUpgrade.

@Override
public void doUpgrade() throws UpgradeProblem {
    setAdminUserContext();
    List<ModelInfo> searchResult = modelSearchService.search("*");
    final String newline = System.getProperty("line.separator");
    for (ModelInfo modelInfo : searchResult) {
        ModelRepository modelRepository = (ModelRepository) repositoryFactory.getRepositoryByModel(modelInfo.getId());
        Optional<FileContent> content = modelRepository.getFileContent(modelInfo.getId(), Optional.of(modelInfo.getFileName()));
        if (content.isPresent()) {
            String currentModelContent = "";
            try {
                currentModelContent = new String(content.get().getContent(), "utf-8");
            } catch (UnsupportedEncodingException e1) {
                logger.warn("Could not set vortolang field for model " + modelInfo.getId().getPrettyFormat() + ".Skipping...", e1);
            }
            if (currentModelContent.contains("vortolang 1.0")) {
                continue;
            }
            StringBuilder contentBuilder = new StringBuilder();
            contentBuilder.append("vortolang 1.0");
            contentBuilder.append(newline);
            contentBuilder.append(newline);
            try {
                contentBuilder.append(currentModelContent);
                logger.info("Upgrading " + modelInfo.toString() + " for vortolang attribute....");
                modelRepository.save(modelInfo.getId(), contentBuilder.toString().getBytes(), modelInfo.getFileName(), UserContext.user(modelInfo.getAuthor(), modelRepository.getWorkspaceId()), false);
                logger.info("Upgrade of " + modelInfo.toString() + " successful.");
            } catch (Throwable e) {
                logger.warn("Could not set vortolang field for model " + modelInfo.getId().getPrettyFormat() + ".Skipping...", e);
            }
        }
    }
}
Also used : FileContent(org.eclipse.vorto.repository.core.FileContent) ModelRepository(org.eclipse.vorto.repository.core.impl.ModelRepository) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 45 with ModelInfo

use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.

the class SimpleSearchService method search.

private List<ModelInfo> search(String expression, Authentication authentication) {
    List<ModelInfo> result = new ArrayList<>();
    namespaceRepository.findAll().forEach(namespace -> {
        IModelRepository repository = this.repositoryFactory.getRepository(namespace.getWorkspaceId(), authentication);
        result.addAll(repository.search(expression));
    });
    return result;
}
Also used : IModelRepository(org.eclipse.vorto.repository.core.IModelRepository) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ArrayList(java.util.ArrayList)

Aggregations

ModelInfo (org.eclipse.vorto.repository.core.ModelInfo)89 Test (org.junit.Test)33 IUserContext (org.eclipse.vorto.repository.core.IUserContext)32 ModelId (org.eclipse.vorto.model.ModelId)28 IModelRepository (org.eclipse.vorto.repository.core.IModelRepository)21 FileContent (org.eclipse.vorto.repository.core.FileContent)11 ClassPathResource (org.springframework.core.io.ClassPathResource)11 IOException (java.io.IOException)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 ModelNotFoundException (org.eclipse.vorto.repository.core.ModelNotFoundException)8 WorkflowException (org.eclipse.vorto.repository.workflow.WorkflowException)8 BeforeClass (org.junit.BeforeClass)7 ResponseEntity (org.springframework.http.ResponseEntity)7 List (java.util.List)6 Optional (java.util.Optional)6 ModelAlreadyExistsException (org.eclipse.vorto.repository.core.ModelAlreadyExistsException)6 NotAuthorizedException (org.eclipse.vorto.repository.web.core.exceptions.NotAuthorizedException)6 DependencyManager (org.eclipse.vorto.repository.core.impl.utils.DependencyManager)5