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