/**
   * Centralized way to create ResourceStoreRequests, since we have to fill in various things in
   * Request context, like authenticated username, etc.
   *
   * @param isLocal
   * @return
   */
  protected ArtifactStoreRequest getResourceStoreRequest(
      Request request,
      boolean localOnly,
      String repositoryId,
      String g,
      String a,
      String v,
      String p,
      String c,
      String e)
      throws ResourceException {
    if (StringUtils.isBlank(p) && StringUtils.isBlank(e)) {
      // if packaging and extension is both blank, it is a bad request
      throw new ResourceException(
          Status.CLIENT_ERROR_BAD_REQUEST,
          "Deployment tried with both 'packaging' and/or 'extension' being empty! One of these values is mandatory!");
    }

    MavenRepository mavenRepository = getMavenRepository(repositoryId);

    // if extension is not given, fall-back to packaging and apply mapper
    if (StringUtils.isBlank(e)) {
      e = mavenRepository.getArtifactPackagingMapper().getExtensionForPackaging(p);
    }

    // clean up the classifier
    if (StringUtils.isBlank(c)) {
      c = null;
    }

    Gav gav = null;

    try {
      gav =
          new Gav(
              g,
              a,
              v,
              c,
              e,
              null,
              null,
              null,
              VersionUtils.isSnapshot(v),
              false,
              null,
              false,
              null);
    } catch (IllegalArtifactCoordinateException ex) {
      throw new ResourceException(
          Status.CLIENT_ERROR_BAD_REQUEST, "Illegal artifact coordinate.", ex);
    }

    ArtifactStoreRequest result = new ArtifactStoreRequest(mavenRepository, gav, localOnly);

    if (getLogger().isDebugEnabled()) {
      getLogger().debug("Created ArtifactStoreRequest request for " + result.getRequestPath());
    }

    // stuff in the originating remote address
    result
        .getRequestContext()
        .put(AccessManager.REQUEST_REMOTE_ADDRESS, getValidRemoteIPAddress(request));

    // stuff in the user id if we have it in request
    if (request.getChallengeResponse() != null
        && request.getChallengeResponse().getIdentifier() != null) {
      result
          .getRequestContext()
          .put(AccessManager.REQUEST_USER, request.getChallengeResponse().getIdentifier());
    }

    // this is HTTPS, get the cert and stuff it too for later
    if (request.isConfidential()) {
      result.getRequestContext().put(AccessManager.REQUEST_CONFIDENTIAL, Boolean.TRUE);

      List<?> certs = (List<?>) request.getAttributes().get("org.restlet.https.clientCertificates");

      if (certs != null) {
        result.getRequestContext().put(AccessManager.REQUEST_CERTIFICATES, certs);
      }
    }

    // put the incoming URLs
    result.setRequestAppRootUrl(getContextRoot(request).toString());
    result.setRequestUrl(request.getOriginalRef().toString());

    return result;
  }