Esempio n. 1
0
  /**
   * Deploy content to the remote server - this is one half of #createResource
   *
   * @param report Create resource report that tells us what to do
   * @return report that tells us what has been done.
   */
  protected CreateResourceReport deployContent(CreateResourceReport report) {
    ContentContext cctx = context.getContentContext();
    ResourcePackageDetails details = report.getPackageDetails();

    ContentServices contentServices = cctx.getContentServices();
    String resourceTypeName = report.getResourceType().getName();

    ASUploadConnection uploadConnection = new ASUploadConnection(host, port);
    OutputStream out = uploadConnection.getOutputStream(details.getFileName());
    contentServices.downloadPackageBitsForChildResource(
        cctx, resourceTypeName, details.getKey(), out);

    JsonNode uploadResult = uploadConnection.finishUpload();
    if (verbose) log.info(uploadResult);

    if (ASUploadConnection.isErrorReply(uploadResult)) {
      report.setStatus(CreateResourceStatus.FAILURE);
      report.setErrorMessage(ASUploadConnection.getFailureDescription(uploadResult));

      return report;
    }

    String fileName = details.getFileName();

    if (fileName.startsWith(
        "C:\\fakepath\\")) { // TODO this is a hack as the server adds the fake path somehow
      fileName = fileName.substring("C:\\fakepath\\".length());
    }

    String tmpName = fileName; // TODO figure out the tmp-name biz with the AS guys

    JsonNode resultNode = uploadResult.get("result");
    String hash = resultNode.get("BYTES_VALUE").getTextValue();

    return runDeploymentMagicOnServer(report, fileName, tmpName, hash);
  }