All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jlot.client.remote.PushRestCommand Maven / Gradle / Ivy

There is a newer version: 1.2
Show newest version
package org.jlot.client.remote;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;

import javax.inject.Inject;

import org.jlot.api.JlotApiUrls;
import org.jlot.client.remote.rest.AbstractLoginRestCommand;
import org.jlot.client.remote.support.ResourceSupport;
import org.jlot.client.remote.support.ResourceZipper;
import org.jlot.core.dto.PushResultDTO;
import org.jlot.core.form.PushForm;
import org.springframework.core.io.FileSystemResource;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

@Component
public class PushRestCommand extends AbstractLoginRestCommand>
{
	@Inject
	private ResourceZipper	resourceZipper;

	@Inject
	private ResourceSupport	resourceSupport;

	@Override
	protected List executeInternal ( PushForm pushForm )
	{
		// binary data should can not be send by json
		MultiValueMap map = new LinkedMultiValueMap();
		map.add("data", pushForm);

		Set resourceNameSet = pushForm.getResourceNameSet();
		if (pushForm.isPushTranslations())
		{
			resourceNameSet = resourceSupport.getBundleResources(pushForm.getBaseDir(), resourceNameSet);
		}
		File zipFile = resourceZipper.zip(resourceNameSet);
		FileSystemResource fileSystemResource = new FileSystemResource(zipFile);
		map.add("file", fileSystemResource);

		RestTemplate restTemplate = getRestTemplate();
		PushResultDTOList list = restTemplate.postForObject(getUrl(), map, PushResultDTOList.class, pushForm.getProjectName(), pushForm.getVersionName());
		return list.convert();
	}

	@Override
	protected String getPath ( )
	{
		return JlotApiUrls.PUSH;
	}
}

/**
 * http://stackoverflow.com/a/6179440/351758
 */
class PushResultDTOList extends ArrayList
{
	private static final long serialVersionUID = 1L;

	List convert ( )
	{
		List resultList = new ArrayList(this);
		Collections.sort(resultList);
		return resultList;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy