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.dto.DateTime;
015import co.codewizards.cloudstore.core.repo.transport.RepoTransport;
016import co.codewizards.cloudstore.core.util.AssertUtil;
017
018@Path("_makeDirectory/{repositoryName}")
019@Consumes(MediaType.APPLICATION_XML)
020@Produces(MediaType.APPLICATION_XML)
021public class MakeDirectoryService extends AbstractServiceWithRepoToRepoAuth
022{
023        private static final Logger logger = LoggerFactory.getLogger(MakeDirectoryService.class);
024
025        {
026                logger.debug("<init>: created new instance");
027        }
028
029        private @QueryParam("lastModified") DateTime lastModified;
030
031        @POST
032        public void makeDirectory()
033        {
034                makeDirectory("");
035        }
036
037        @POST
038        @Path("{path:.*}")
039        public void makeDirectory(@PathParam("path") String path)
040        {
041                AssertUtil.assertNotNull(path, "path");
042                try (final RepoTransport repoTransport = authenticateAndCreateLocalRepoTransport();) {
043                        path = repoTransport.unprefixPath(path);
044                        repoTransport.makeDirectory(path, lastModified == null ? null : lastModified.toDate());
045                }
046        }
047}