org.jlot.client.remote.PullRestCommand Maven / Gradle / Ivy
package org.jlot.client.remote;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import org.jlot.api.JlotApiUrls;
import org.jlot.client.remote.rest.AbstractLoginRestCommand;
import org.jlot.core.form.PullForm;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.stereotype.Component;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
@Component
public class PullRestCommand extends AbstractLoginRestCommand
{
@Override
protected File executeInternal ( PullForm pullForm )
{
String projectName = pullForm.getProjectName();
String versionName = pullForm.getVersionName();
RestTemplate restTemplate = getRestTemplate();
ByteArrayResource resource = restTemplate.postForObject(getUrl(), pullForm, ByteArrayResource.class, projectName, versionName);
File file;
try
{
file = File.createTempFile("jlot", ".zip");
FileOutputStream fileOutputStream = new FileOutputStream(file);
FileCopyUtils.copy(resource.getInputStream(), fileOutputStream);
}
catch (IOException e)
{
throw new RestClientException("Pull Response was invalid", e);
}
return file;
}
@Override
protected String getPath ( )
{
return JlotApiUrls.PULL;
}
}