mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-17 18:51:10 +01:00
prepare client api fo import commands
This commit is contained in:
@@ -0,0 +1,70 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2014, Sebastian Sdorra All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer. 2. Redistributions in
|
||||||
|
* binary form must reproduce the above copyright notice, this list of
|
||||||
|
* conditions and the following disclaimer in the documentation and/or other
|
||||||
|
* materials provided with the distribution. 3. Neither the name of SCM-Manager;
|
||||||
|
* nor the names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* http://bitbucket.org/sdorra/scm-manager
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package sonia.scm.client;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteSource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
* @since 1.43
|
||||||
|
*/
|
||||||
|
public class ImportBundleRequest
|
||||||
|
{
|
||||||
|
private String type;
|
||||||
|
private String name;
|
||||||
|
private ByteSource bundle;
|
||||||
|
|
||||||
|
ImportBundleRequest()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImportBundleRequest(String type, String name, ByteSource bundle)
|
||||||
|
{
|
||||||
|
this.type = type;
|
||||||
|
this.name = name;
|
||||||
|
this.bundle = bundle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType()
|
||||||
|
{
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ByteSource getBundle()
|
||||||
|
{
|
||||||
|
return bundle;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,184 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2014, Sebastian Sdorra All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer. 2. Redistributions in
|
||||||
|
* binary form must reproduce the above copyright notice, this list of
|
||||||
|
* conditions and the following disclaimer in the documentation and/or other
|
||||||
|
* materials provided with the distribution. 3. Neither the name of SCM-Manager;
|
||||||
|
* nor the names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* http://bitbucket.org/sdorra/scm-manager
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
package sonia.scm.client;
|
||||||
|
|
||||||
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
|
import sonia.scm.repository.ImportResult;
|
||||||
|
import sonia.scm.repository.Repository;
|
||||||
|
|
||||||
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
* @since 1.43
|
||||||
|
*/
|
||||||
|
public class ImportResultWrapper
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param client
|
||||||
|
* @param type
|
||||||
|
* @param result
|
||||||
|
*/
|
||||||
|
public ImportResultWrapper(RepositoryClientHandler client, String type,
|
||||||
|
ImportResult result)
|
||||||
|
{
|
||||||
|
this.client = client;
|
||||||
|
this.type = type;
|
||||||
|
this.result = result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public List<String> getFailedDirectories()
|
||||||
|
{
|
||||||
|
List<String> directories = result.getFailedDirectories();
|
||||||
|
|
||||||
|
if (directories == null)
|
||||||
|
{
|
||||||
|
directories = ImmutableList.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
return directories;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public List<String> getImportedDirectories()
|
||||||
|
{
|
||||||
|
List<String> directories = result.getImportedDirectories();
|
||||||
|
|
||||||
|
if (directories == null)
|
||||||
|
{
|
||||||
|
directories = ImmutableList.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
return directories;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Iterable<Repository> getImportedRepositories()
|
||||||
|
{
|
||||||
|
return Iterables.transform(getImportedDirectories(),
|
||||||
|
new RepositoryResolver(client, type));
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- inner classes --------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @version Enter version here..., 14/11/29
|
||||||
|
* @author Enter your name here...
|
||||||
|
*/
|
||||||
|
private static class RepositoryResolver
|
||||||
|
implements Function<String, Repository>
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param clientHandler
|
||||||
|
* @param type
|
||||||
|
*/
|
||||||
|
public RepositoryResolver(RepositoryClientHandler clientHandler,
|
||||||
|
String type)
|
||||||
|
{
|
||||||
|
this.clientHandler = clientHandler;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- methods ------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Repository apply(String name)
|
||||||
|
{
|
||||||
|
return clientHandler.get(type, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- fields -------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private final RepositoryClientHandler clientHandler;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private final String type;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private final RepositoryClientHandler client;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private final ImportResult result;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private final String type;
|
||||||
|
}
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2014, Sebastian Sdorra All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer. 2. Redistributions in
|
||||||
|
* binary form must reproduce the above copyright notice, this list of
|
||||||
|
* conditions and the following disclaimer in the documentation and/or other
|
||||||
|
* materials provided with the distribution. 3. Neither the name of SCM-Manager;
|
||||||
|
* nor the names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* http://bitbucket.org/sdorra/scm-manager
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
package sonia.scm.client;
|
||||||
|
|
||||||
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
import javax.xml.bind.annotation.XmlTransient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
* @since 1.43
|
||||||
|
*/
|
||||||
|
@XmlRootElement(name = "import")
|
||||||
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
|
public class ImportUrlRequest
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
ImportUrlRequest() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @param name
|
||||||
|
* @param url
|
||||||
|
*/
|
||||||
|
public ImportUrlRequest(String type, String name, String url)
|
||||||
|
{
|
||||||
|
this.type = type;
|
||||||
|
this.name = name;
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getType()
|
||||||
|
{
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getUrl()
|
||||||
|
{
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
@XmlTransient
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private String url;
|
||||||
|
}
|
||||||
@@ -51,6 +51,43 @@ import java.util.Collection;
|
|||||||
public interface RepositoryClientHandler extends ClientHandler<Repository>
|
public interface RepositoryClientHandler extends ClientHandler<Repository>
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
* @since 1.43
|
||||||
|
*/
|
||||||
|
public ImportResultWrapper importFromDirectory(String type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
* @since 1.43
|
||||||
|
*/
|
||||||
|
public Repository importFromBundle(ImportBundleRequest request);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
* @since 1.43
|
||||||
|
*/
|
||||||
|
public Repository importFromUrl(ImportUrlRequest request);
|
||||||
|
|
||||||
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -45,6 +45,12 @@
|
|||||||
<version>${jersey.version}</version>
|
<version>${jersey.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.sun.jersey.contribs</groupId>
|
||||||
|
<artifactId>jersey-multipart</artifactId>
|
||||||
|
<version>${jersey.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- test scope -->
|
<!-- test scope -->
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -35,16 +35,26 @@ package sonia.scm.client;
|
|||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import com.google.common.base.Strings;
|
||||||
|
|
||||||
import sonia.scm.NotSupportedFeatuerException;
|
import sonia.scm.NotSupportedFeatuerException;
|
||||||
import sonia.scm.Type;
|
import sonia.scm.Type;
|
||||||
|
import sonia.scm.repository.ImportResult;
|
||||||
import sonia.scm.repository.Repository;
|
import sonia.scm.repository.Repository;
|
||||||
import sonia.scm.repository.Tags;
|
import sonia.scm.repository.Tags;
|
||||||
|
import sonia.scm.util.HttpUtil;
|
||||||
|
import sonia.scm.util.IOUtil;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import com.sun.jersey.api.client.ClientResponse;
|
import com.sun.jersey.api.client.ClientResponse;
|
||||||
import com.sun.jersey.api.client.GenericType;
|
import com.sun.jersey.api.client.GenericType;
|
||||||
import com.sun.jersey.api.client.WebResource;
|
import com.sun.jersey.api.client.WebResource;
|
||||||
|
import com.sun.jersey.multipart.FormDataMultiPart;
|
||||||
|
import com.sun.jersey.multipart.file.StreamDataBodyPart;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -57,6 +67,26 @@ public class JerseyRepositoryClientHandler
|
|||||||
extends AbstractClientHandler<Repository> implements RepositoryClientHandler
|
extends AbstractClientHandler<Repository> implements RepositoryClientHandler
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private static final String IMPORT_TYPE_BUNDLE = "bundle";
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private static final String IMPORT_TYPE_DIRECTORY = "directory";
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private static final String IMPORT_TYPE_URL = "url";
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private static final String PARAM_BUNDLE = "bundle";
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private static final String PARAM_NAME = "name";
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private static final String URL_IMPORT = "import/repositories/";
|
||||||
|
|
||||||
|
//~--- constructors ---------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs ...
|
* Constructs ...
|
||||||
*
|
*
|
||||||
@@ -68,6 +98,106 @@ public class JerseyRepositoryClientHandler
|
|||||||
super(session, Repository.class);
|
super(session, Repository.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Repository importFromBundle(ImportBundleRequest request)
|
||||||
|
{
|
||||||
|
WebResource r = client.resource(getImportUrl(request.getType(),
|
||||||
|
IMPORT_TYPE_BUNDLE));
|
||||||
|
Repository repository = null;
|
||||||
|
InputStream stream = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
stream = request.getBundle().openStream();
|
||||||
|
|
||||||
|
FormDataMultiPart form = new FormDataMultiPart();
|
||||||
|
|
||||||
|
form.field(PARAM_NAME, request.getName());
|
||||||
|
form.bodyPart(new StreamDataBodyPart(PARAM_BUNDLE, stream));
|
||||||
|
|
||||||
|
ClientResponse response = r.post(ClientResponse.class);
|
||||||
|
|
||||||
|
ClientUtil.checkResponse(response);
|
||||||
|
|
||||||
|
String location =
|
||||||
|
response.getHeaders().getFirst(HttpUtil.HEADER_LOCATION);
|
||||||
|
|
||||||
|
if (Strings.isNullOrEmpty(location))
|
||||||
|
{
|
||||||
|
throw new ScmClientException("no location header found after import");
|
||||||
|
}
|
||||||
|
|
||||||
|
repository = getItemByUrl(location);
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
throw new ScmClientException("could not import bundle", ex);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IOUtil.close(stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
return repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ImportResultWrapper importFromDirectory(String type)
|
||||||
|
{
|
||||||
|
WebResource r = client.resource(getImportUrl(type, IMPORT_TYPE_DIRECTORY));
|
||||||
|
ClientResponse response = r.post(ClientResponse.class);
|
||||||
|
|
||||||
|
ClientUtil.checkResponse(response);
|
||||||
|
|
||||||
|
return new ImportResultWrapper(this, type,
|
||||||
|
response.getEntity(ImportResult.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Repository importFromUrl(ImportUrlRequest request)
|
||||||
|
{
|
||||||
|
WebResource r = client.resource(getImportUrl(request.getType(),
|
||||||
|
IMPORT_TYPE_URL));
|
||||||
|
ClientResponse response = r.post(ClientResponse.class);
|
||||||
|
|
||||||
|
ClientUtil.checkResponse(response);
|
||||||
|
|
||||||
|
String location = response.getHeaders().getFirst(HttpUtil.HEADER_LOCATION);
|
||||||
|
|
||||||
|
if (Strings.isNullOrEmpty(location))
|
||||||
|
{
|
||||||
|
throw new ScmClientException("no location header found after import");
|
||||||
|
}
|
||||||
|
|
||||||
|
return getItemByUrl(location);
|
||||||
|
}
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -228,4 +358,22 @@ public class JerseyRepositoryClientHandler
|
|||||||
{
|
{
|
||||||
return urlProvider.getRepositoryUrlProvider().getAllUrl();
|
return urlProvider.getRepositoryUrlProvider().getAllUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @param importType
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String getImportUrl(String type, String importType)
|
||||||
|
{
|
||||||
|
StringBuilder buffer = new StringBuilder(URL_IMPORT);
|
||||||
|
|
||||||
|
buffer.append(type).append(HttpUtil.SEPARATOR_PATH).append(importType);
|
||||||
|
|
||||||
|
return HttpUtil.append(urlProvider.getBaseUrl(), buffer.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,6 +94,20 @@ public class RestUrlProvider implements UrlProvider
|
|||||||
return HttpUtil.append(baseUrl, PART_AUTHENTICATION).concat(extension);
|
return HttpUtil.append(baseUrl, PART_AUTHENTICATION).concat(extension);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
* @since 1.43
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getBaseUrl()
|
||||||
|
{
|
||||||
|
return baseUrl;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -48,6 +48,16 @@ public interface UrlProvider
|
|||||||
*/
|
*/
|
||||||
public String getAuthenticationUrl();
|
public String getAuthenticationUrl();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
* @since 1.43
|
||||||
|
*/
|
||||||
|
public String getBaseUrl();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -88,6 +88,20 @@ public class WUIUrlProvider implements UrlProvider
|
|||||||
return baseUrl;
|
return baseUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
* @since 1.43
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getBaseUrl()
|
||||||
|
{
|
||||||
|
return baseUrl;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -73,6 +73,12 @@ public final class HttpUtil
|
|||||||
/** Field description */
|
/** Field description */
|
||||||
public static final String ENCODING = "UTF-8";
|
public static final String ENCODING = "UTF-8";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* location header
|
||||||
|
* @since 1.43
|
||||||
|
*/
|
||||||
|
public static final String HEADER_LOCATION = "Location";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* header for identifying the scm-manager client
|
* header for identifying the scm-manager client
|
||||||
* @since 1.19
|
* @since 1.19
|
||||||
|
|||||||
Reference in New Issue
Block a user