use of org.eclipse.vorto.repository.core.FileContent in project vorto by eclipse.
the class VortoModelImporter method convert.
@Override
protected List<ModelResource> convert(FileUpload fileUpload, Context context) {
List<ModelResource> result = new ArrayList<>();
if (fileUpload.getFileExtension().equalsIgnoreCase(EXTENSION_ZIP)) {
Collection<FileContent> fileContents = getFileContents(fileUpload);
result.addAll(fileContents.stream().map(fileContent -> (ModelResource) getModelParserFactory().getParser(fileContent.getFileName()).parse(new ByteArrayInputStream(fileContent.getContent()))).collect(Collectors.toList()));
} else {
final ModelResource modelInfo = (ModelResource) getModelParserFactory().getParser(fileUpload.getFileExtension()).parse(new ByteArrayInputStream(fileUpload.getContent()));
result.add(modelInfo);
}
return Collections.unmodifiableList(result);
}
use of org.eclipse.vorto.repository.core.FileContent 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.repository.core.FileContent 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.FileContent in project vorto by eclipse.
the class AbstractRepositoryController method createSingleModelContent.
protected void createSingleModelContent(ModelId modelId, HttpServletResponse response) {
Optional<FileContent> fileContent = getModelRepository(modelId).getFileContent(modelId, Optional.empty());
final byte[] modelContent = fileContent.get().getContent();
if (modelContent != null && modelContent.length > 0) {
response.setHeader(CONTENT_DISPOSITION, ATTACHMENT_FILENAME + fileContent.get().getFileName());
response.setContentType(APPLICATION_OCTET_STREAM);
try {
IOUtils.copy(new ByteArrayInputStream(modelContent), response.getOutputStream());
response.flushBuffer();
} catch (IOException e) {
throw new RuntimeException("Error copying file.", e);
}
} else {
throw new RuntimeException("File not found.");
}
}
use of org.eclipse.vorto.repository.core.FileContent 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);
}
}
}
}
Aggregations