001package co.codewizards.cloudstore.rest.server.service;
002
003import java.net.URL;
004
005import javax.ws.rs.Consumes;
006import javax.ws.rs.GET;
007import javax.ws.rs.Path;
008import javax.ws.rs.PathParam;
009import javax.ws.rs.Produces;
010import javax.ws.rs.core.MediaType;
011
012import org.slf4j.Logger;
013import org.slf4j.LoggerFactory;
014
015import co.codewizards.cloudstore.core.dto.RepositoryDTO;
016import co.codewizards.cloudstore.core.repo.local.LocalRepoRegistry;
017import co.codewizards.cloudstore.core.repo.transport.RepoTransport;
018import co.codewizards.cloudstore.core.repo.transport.RepoTransportFactory;
019import co.codewizards.cloudstore.core.repo.transport.RepoTransportFactoryRegistry;
020
021@Path("_RepositoryDTO/{repositoryName}")
022@Consumes(MediaType.APPLICATION_XML)
023@Produces(MediaType.APPLICATION_XML)
024public class RepositoryDTOService
025{
026        private static final Logger logger = LoggerFactory.getLogger(RepositoryDTOService.class);
027
028        {
029                logger.debug("<init>: created new instance");
030        }
031
032        private @PathParam("repositoryName") String repositoryName;
033
034        @GET
035        public RepositoryDTO getRepositoryDTO()
036        {
037                URL localRootURL = LocalRepoRegistry.getInstance().getLocalRootURLForRepositoryNameOrFail(repositoryName);
038                RepoTransportFactoryRegistry repoTransportRegistry = RepoTransportFactoryRegistry.getInstance();
039                RepoTransportFactory repoTransportFactory = repoTransportRegistry.getRepoTransportFactory(localRootURL);
040                RepoTransport repoTransport = repoTransportFactory.createRepoTransport(localRootURL, null);
041                try {
042                        RepositoryDTO repositoryDTO = repoTransport.getRepositoryDTO();
043                        return repositoryDTO;
044                } finally {
045                        repoTransport.close();
046                }
047        }
048}