Search in sources :

Example 1 with RepositoryException

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);
    }
}
Also used : Attachment(org.eclipse.vorto.core.api.repository.Attachment) RepositoryException(org.eclipse.vorto.core.api.repository.RepositoryException) CheckInModelException(org.eclipse.vorto.core.api.repository.CheckInModelException) RepositoryException(org.eclipse.vorto.core.api.repository.RepositoryException)

Example 2 with RepositoryException

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);
    }
}
Also used : MultipartEntityBuilder(org.apache.http.entity.mime.MultipartEntityBuilder) UploadResultView(org.eclipse.vorto.repository.model.UploadResultView) HttpEntity(org.apache.http.HttpEntity) RepositoryException(org.eclipse.vorto.core.api.repository.RepositoryException) CheckInModelException(org.eclipse.vorto.core.api.repository.CheckInModelException) RepositoryException(org.eclipse.vorto.core.api.repository.RepositoryException)

Example 3 with RepositoryException

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();
}
Also used : ModelResource(org.eclipse.vorto.core.api.repository.ModelResource) ByteArrayInputStream(java.io.ByteArrayInputStream) RepositoryException(org.eclipse.vorto.core.api.repository.RepositoryException) ModelId(org.eclipse.vorto.core.api.model.model.ModelId)

Example 4 with RepositoryException

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;
}
Also used : IModelElement(org.eclipse.vorto.core.ui.model.IModelElement) ModelResource(org.eclipse.vorto.core.api.repository.ModelResource) RepositoryException(org.eclipse.vorto.core.api.repository.RepositoryException) ModelId(org.eclipse.vorto.core.api.model.model.ModelId)

Aggregations

RepositoryException (org.eclipse.vorto.core.api.repository.RepositoryException)4 ModelId (org.eclipse.vorto.core.api.model.model.ModelId)2 CheckInModelException (org.eclipse.vorto.core.api.repository.CheckInModelException)2 ModelResource (org.eclipse.vorto.core.api.repository.ModelResource)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 HttpEntity (org.apache.http.HttpEntity)1 MultipartEntityBuilder (org.apache.http.entity.mime.MultipartEntityBuilder)1 Attachment (org.eclipse.vorto.core.api.repository.Attachment)1 IModelElement (org.eclipse.vorto.core.ui.model.IModelElement)1 UploadResultView (org.eclipse.vorto.repository.model.UploadResultView)1