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