Search in sources :

Example 1 with UploadResultView

use of org.eclipse.vorto.repository.model.UploadResultView 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 2 with UploadResultView

use of org.eclipse.vorto.repository.model.UploadResultView in project vorto by eclipse.

the class StringToUploadResult method emptyUploadResult.

/**
 * Return empty error view incase of invalid json or null values.
 * @return Empty Upload result with error message.
 */
private UploadResultView emptyUploadResult() {
    UploadResultView errorResult = new UploadResultView();
    errorResult.setErrorMessage("Error while uploading to remote repository.");
    errorResult.setValid(false);
    return errorResult;
}
Also used : UploadResultView(org.eclipse.vorto.repository.model.UploadResultView)

Aggregations

UploadResultView (org.eclipse.vorto.repository.model.UploadResultView)2 HttpEntity (org.apache.http.HttpEntity)1 MultipartEntityBuilder (org.apache.http.entity.mime.MultipartEntityBuilder)1 CheckInModelException (org.eclipse.vorto.core.api.repository.CheckInModelException)1 RepositoryException (org.eclipse.vorto.core.api.repository.RepositoryException)1