UNPKG

@mindconnect/mindconnect-nodejs

Version:

NodeJS Library for MindSphere Connectivity - TypeScript SDK for MindSphere - MindSphere Command Line Interface - MindSphere Development Proxy

94 lines 4.97 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const console_1 = require("console"); const command_utils_1 = require("./command-utils"); const fs = require("fs"); const path = require("path"); const mime = require("mime-types"); let color = (0, command_utils_1.getColor)("magenta"); exports.default = (program) => { program .command("sdi-ontology-jobs") .alias("sdb") .option("-m, --mode [submit|info]", "submit|info", "submit") .option("-o, --ontology <ontology>", "ontology file (json or owl)") .option("-n, --name <name>", "the ontology name", "myontology") .option("-i, --ontologyid <ontologyid>", "the ontology id (for update)") .option("-k, --keymappingtype <keymappingtype>", "key mapping type", "INNER JOIN") .option("-s, --description <description>", "the ontology description", "created-by-mindsphere-cli") .option("-j, --jobid <ontologyid>", "the jobid for --info command") .option("-k, --passkey <passkey>", "passkey") .option("-y, --retry <number>", "retry attempts before giving up", "3") .option("-v, --verbose", "verbose output") .description(color("manage ontology jobs for SDI *")) .action((options) => { (() => __awaiter(void 0, void 0, void 0, function* () { try { checkRequiredParamaters(options); const sdk = (0, command_utils_1.getSdk)(options); color = (0, command_utils_1.adjustColor)(color, options); (0, command_utils_1.homeDirLog)(options.verbose, color); (0, command_utils_1.proxyLog)(options.verbose, color); switch (options.mode) { case "info": yield dataOntologyJobInfo(sdk, options); break; case "submit": yield submitOntology(sdk, options); break; default: throw Error(`no such option: ${options.mode}`); } } catch (err) { (0, command_utils_1.errorLog)(err, options.verbose); } }))(); }) .on("--help", () => { (0, console_1.log)("\n Examples:\n"); (0, console_1.log)(` mc sdi-ontology-jobs --mode submit --ontology <ontologyfile>\t upload ontology`); (0, console_1.log)(` mc sdi-ontology-jobs --mode info --jobid <jobid> \t\t\t get sdi ontology upload job info`); (0, command_utils_1.serviceCredentialLog)(); }); }; function checkRequiredParamaters(options) { options.mode === "submit" && !options.ontology && (0, command_utils_1.errorLog)("you have to provide a ontology file to submit a sdi ontology upload job (see mc sdi-ontology-jobs --help for more details)", true); options.mode === "info" && !options.jobid && (0, command_utils_1.errorLog)("you have to provide the jobid to get infos about the sdi ontology upload job (see mc sdi-ontology-jobs --help for more details)", true); } function dataOntologyJobInfo(sdk, options) { return __awaiter(this, void 0, void 0, function* () { const sdiClient = sdk.GetSemanticDataInterConnectClient(); const dataOntologyJob = yield sdiClient.GetOntologyJobStatus(`${options.jobid}`); printDataOntologyJob(dataOntologyJob, options); }); } function printDataOntologyJob(dataOntology, options) { (0, command_utils_1.printObjectInfo)("Submit Ontology Job:", dataOntology, options, ["id", "status"], color); } function submitOntology(sdk, options) { return __awaiter(this, void 0, void 0, function* () { const filePath = path.resolve(options.ontology); const file = fs.readFileSync(filePath); const mimeType = mime.lookup(filePath); const uploadedName = path.basename(filePath); const result = yield sdk .GetSemanticDataInterConnectClient() .PostOntologyJob(uploadedName, file, mimeType, options.name, options.ontologyid, options.description || "created by mindsphere.cli", options.keymapping); printDataOntologyJob(result, options); }); } //# sourceMappingURL=sdi-ontology-jobs.js.map