sciabarra
9/19/2013 - 9:19 PM

Working CSDT interface

Working CSDT interface

 // interface to csdt from sbt
  val wcsCsdtTask = InputKey[Unit]("wcs-dt", "WCS Development Tool") <<= inputTask {
    (argTask: TaskKey[Seq[String]]) =>
      (argTask, wcsVersion, wcsUrl, wcsSites, wcsUser, wcsPassword, fullClasspath in Compile, streams, runner) map {
        (args, version, url, sites, user, password, classpath, s, runner) =>
          val re = "^(cas-client-core-\\d|csdt-client-\\d|rest-api-\\d|wem-sso-api-\\d|wem-sso-api-cas-\\d|spring-\\d|commons-logging-|servlet-api).*.jar$".r;
          val seljars = classpath.files.filter(f => !re.findAllIn(f.getName).isEmpty)
          val workspaces = (file("export") / "envision").listFiles.filter(_.isDirectory).map(_.getName).mkString("'", "', '", "'")
          if (args.size == 0) {
            println("""usage: wcs-dt  [<cmd>]  [<selector> ...] [#<workspace>]
                       | <workspace> defaults to 'workspace',
                       |   must be one of: %s
                       | <cmd> defaults to 'listcs'
                       |   must be one of 'listcs', 'listds', 'import', 'export', 
                       | <selector> check developer tool documentation for syntax
                       |  defaults for commands are
                       |      listcs: @ALL_ASSETS
                       |      listds: @ALL_ASSETS
                       |      import: @SITE @ASSET_TYPE @ALL_ASSETS @STARTMENU @TREETAB
                       |      export: @SITE @ASSET_TYPE
                       |""".stripMargin.format(workspaces))
          } else {

            val workspace = ("#workspace" +: args).reverse.filter(_.startsWith("#")).head.substring(1)

            val args1 = args.filter(!_.startsWith("#"))

            val firstArg = if (args1.size > 0) args1(0) else "listcs"

            val resources = if (args1.size > 1) args1.drop(1)
            else firstArg match {
              case "listcs" => Seq("@ALL_ASSETS")
              case "listds" => Seq("@ALL_ASSETS")
              case "import" =>
                Seq("@SITE", "@ASSET_TYPE", "@ALL_ASSETS", "@STARTMENU", "@TREETAB")
              case "export" =>
                Seq("@SITE", "@ASSET_TYPE")
              case _ =>
                println("Unknown command")
                Seq()
            }

            for (res <- resources) {
              val cmd = Array(url + "/ContentServer",
                "username=" + user,
                "password=" + password,
                "cmd=" + firstArg,
                "resources=" + res,
                //"fromSites=" + sites,
                "datastore=" + workspace)

              Run.run("com.fatwire.csdt.client.main.CSDT", seljars, cmd, s.log)(runner)

            }
          }
      }
  }