001package co.codewizards.cloudstore.rest.client.request;
002
003import static java.util.Objects.*;
004
005import java.util.Date;
006
007import javax.ws.rs.client.WebTarget;
008import javax.ws.rs.core.Response;
009
010import co.codewizards.cloudstore.core.dto.DateTime;
011
012public class MakeDirectory extends VoidRequest {
013
014        protected final String repositoryName;
015        protected final String path;
016        protected final Date lastModified;
017
018        public MakeDirectory(final String repositoryName, final String path, final Date lastModified) {
019                this.repositoryName = requireNonNull(repositoryName, "repositoryName");
020                this.path = requireNonNull(path, "path");
021                this.lastModified = lastModified;
022        }
023
024        @Override
025        protected Response _execute() {
026                final WebTarget webTarget = createMakeDirectoryWebTarget();
027                return assignCredentials(webTarget.request()).post(null);
028        }
029
030        protected WebTarget createMakeDirectoryWebTarget() {
031//              WebTarget webTarget = client.target(getBaseURL()).path(repositoryName).path(removeLeadingAndTrailingSlash(path));
032//
033//              if (lastModified != null)
034//                      webTarget = webTarget.queryParam("lastModified", new DateTime(lastModified));
035//
036//              Response response = webTarget.request().method("MKCOL");
037//              assertResponseIndicatesSuccess(response);
038
039                // The HTTP verb "MKCOL" is not yet supported by Jersey (and not even the unterlying HTTP client)
040                // by default. We first have to add this. This will be done later (for the WebDAV support). For
041                // now, we'll use the alternative MakeDirectoryService.
042
043                WebTarget webTarget = createWebTarget("_makeDirectory", urlEncode(repositoryName), encodePath(path));
044
045                if (lastModified != null)
046                        webTarget = webTarget.queryParam("lastModified", new DateTime(lastModified));
047
048                return webTarget;
049        }
050}