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();
}
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);
}
}
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;
}
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);
}
}
}
}
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;
}
Aggregations