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