use of org.eclipse.vorto.core.api.repository.RepositoryException in project vorto by eclipse.
the class RestModelRepository method generateCode.
@Override
public Attachment generateCode(ModelId model, String serviceKey) {
try {
String url = "generation-router/" + model.getNamespace() + "/" + model.getName() + "/" + model.getVersion() + "/" + URLEncoder.encode(serviceKey, "utf-8");
Attachment result = httpClient.executeGetAttachment(url);
return result;
} catch (RepositoryException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException("Error querying remote repository with generateCode request.", e);
}
}
use of org.eclipse.vorto.core.api.repository.RepositoryException in project vorto by eclipse.
the class RestModelRepository method upload.
@Override
public UploadResult upload(String name, byte[] model) {
Objects.requireNonNull(model, "Model should not be null.");
Objects.requireNonNull(name, "Name should not be null.");
try {
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addBinaryBody(FILE_PARAMETER_NAME, model, ContentType.APPLICATION_OCTET_STREAM, name);
HttpEntity fileToUpload = builder.build();
UploadResultView uploadResult = httpClient.executePost("secure", fileToUpload, uploadResponseConverter);
return uploadResultConverter.apply(uploadResult);
} catch (RepositoryException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException("Error getting model info for resource", e);
}
}
use of org.eclipse.vorto.core.api.repository.RepositoryException in project vorto by eclipse.
the class AddSharedReferenceDropAction method downloadAndSaveModel.
// Download and save model from repository to local project.
// It also recursively do the same for the model references.
private Optional<IModelElement> downloadAndSaveModel(IModelProject project, ModelId modelId) {
try {
ModelResource model = modelRepo.getModel(modelId);
if (model != null) {
for (ModelId reference : model.getReferences()) {
downloadAndSaveModel(project, reference);
}
MessageDisplayFactory.getMessageDisplay().display("Downloading " + modelId.toString());
byte[] modelContent = modelRepo.downloadContent(model.getId());
return Optional.of(project.addModelElement(model.getId(), new ByteArrayInputStream(modelContent)));
} else {
MessageDisplayFactory.getMessageDisplay().displayError("Model " + modelId.toString() + " not found in repository.");
}
} catch (RepositoryException e) {
ExceptionHandlerFactory.getHandler().handle(e);
}
return Optional.empty();
}
use of org.eclipse.vorto.core.api.repository.RepositoryException in project vorto by eclipse.
the class RepositoryResourceDropAction method downloadAndSaveModel.
// Download and save model from repository to local project.
// It also recursively do the same for the model references.
private IModelElement downloadAndSaveModel(IModelProject modelProject, ModelId modelId) {
IModelElement modelElement = null;
try {
ModelResource model = modelRepo.getModel(modelId);
if (model != null) {
if (!modelProject.exists(modelId)) {
for (ModelId reference : model.getReferences()) {
downloadAndSaveModel(modelProject, reference);
}
downloadMappings(modelProject, model.getReferencedBy());
MessageDisplayFactory.getMessageDisplay().display("Downloading " + modelId.toString());
byte[] modelContent = modelRepo.downloadContent(model.getId());
modelElement = saveToProject(modelProject, modelContent, model.getId());
} else {
modelElement = modelProject.getModelElementById(modelId);
}
} else {
MessageDisplayFactory.getMessageDisplay().displayError("Model " + modelId.toString() + " not found in repository.");
}
} catch (RepositoryException e) {
ExceptionHandlerFactory.getHandler().handle(e);
}
return modelElement;
}
Aggregations