001package co.codewizards.cloudstore.rest.server.service; 002 003import javax.ws.rs.Consumes; 004import javax.ws.rs.POST; 005import javax.ws.rs.Path; 006import javax.ws.rs.PathParam; 007import javax.ws.rs.Produces; 008import javax.ws.rs.QueryParam; 009import javax.ws.rs.core.MediaType; 010 011import org.slf4j.Logger; 012import org.slf4j.LoggerFactory; 013 014import co.codewizards.cloudstore.core.repo.transport.RepoTransport; 015import co.codewizards.cloudstore.core.util.AssertUtil; 016 017@Path("_copy/{repositoryName}") 018@Consumes(MediaType.APPLICATION_XML) 019@Produces(MediaType.APPLICATION_XML) 020public class CopyService extends AbstractServiceWithRepoToRepoAuth 021{ 022 private static final Logger logger = LoggerFactory.getLogger(CopyService.class); 023 024 { 025 logger.debug("<init>: created new instance"); 026 } 027 028 @POST 029 public void copy(@QueryParam("to") final String toPath) 030 { 031 copy("", toPath); 032 } 033 034 @POST 035 @Path("{path:.*}") 036 public void copy(@PathParam("path") String path, @QueryParam("to") final String toPath) 037 { 038 AssertUtil.assertNotNull(path, "path"); 039 final RepoTransport repoTransport = authenticateAndCreateLocalRepoTransport(); 040 try { 041 path = repoTransport.unprefixPath(path); 042 repoTransport.copy(path, toPath); 043 } finally { 044 repoTransport.close(); 045 } 046 } 047}