/**
  * @param $target_vol
  * @return bool
  */
 public function ingest($target_vol)
 {
     static::$logger->addInfo("Ingest processing beginning");
     $this->report[] = 'Ingest begins: volume set: ' . $target_vol;
     // TODO make a config parameter
     if (!static::$manager->has('staging://default/' . $target_vol)) {
         $msg = 'No such volume found in staging directory: nothing to do.';
         static::$logger->alert(__CLASS__ . '::' . __FUNCTION__ . ': ' . $msg);
         $this->report[] = $msg;
         return false;
     }
     $this->target_vol = $target_vol;
     $ss = new SchemaService();
     $this->schemas = $ss->schemas();
     static::$logger->addInfo("Loaded " . count($this->schemas) . " schemas.");
     if (count($this->schemas) < 1) {
         static::$logger->addCritical("No schemas: run failed.");
         $this->report[] = 'No schemas found: run failed';
         $this->errors[] = 'No schema documents found. The system requires at least a default schema.';
         return false;
     }
     if (!($cnt = $this->loadSpools())) {
         static::$logger->addWarning("Nothing on spools: run failed.");
         $this->report[] = 'Nothing on the spools: run failed';
         return false;
     }
     $this->report[] = 'Spooled: ' . $cnt . ' assets';
     if (!static::$manager->has('default://' . $target_vol)) {
         if (!static::$manager->createDir('default://' . $target_vol)) {
             $msg = "Failed to make target directory: {$target_vol}";
             $this->report[] = $msg . ': run failed';
             $this->errors[] = $msg . ' Check file permissions for data directory.';
             static::$logger->addCritical($msg . ': run failed.');
             return false;
         }
         $msg = "Created target directory.";
         static::$logger->addInfo($msg);
     }
     $msg = "Begin despooling...";
     $this->report[] = $msg;
     static::$logger->addInfo($msg);
     $mimeTypes = array_keys($this->spool);
     foreach ($mimeTypes as $mimeType) {
         foreach ($this->spool[$mimeType] as $file) {
             if (strpos($file, '.') !== 0) {
                 $this->ingestAsset($mimeType, $file);
             }
         }
     }
     $msg = "Finished despooling. Processing complete.";
     $this->report[] = $msg;
     static::$logger->addInfo($msg);
     return true;
 }
 private function test_sidecar($sidecar)
 {
     $service = new SchemaService();
     if ($ret = $service->isValid($sidecar)) {
         $this->scanlog->info('Sidecar file is valid');
     } else {
         foreach ($ret as $e) {
             $this->scanlog->error($e['property'] . ': ' . $e['message']);
         }
     }
 }
 /**
  * @param $json     text content of asset data file
  */
 private function reload($json)
 {
     $ss = new SchemaService();
     try {
         $resp = $ss->isValid($json);
         if (is_array($resp)) {
             $data = Util::decode_json($json);
             static::$logger->error(__CLASS__ . '::' . __FUNCTION__ . ': schema in use: ' . $data->mimeType);
             foreach ($resp as $k => $v) {
                 foreach ($v as $item => $line) {
                     static::$logger->error(__CLASS__ . '::' . __FUNCTION__ . ': data not validated: ' . $k . ': ' . $item . ' => ' . $line);
                 }
             }
             throw new ReposeJsonInstantiationError(json_last_error_msg());
         } else {
             $data = Util::decode_json($json);
             $this->loadData($data);
             static::$logger->addInfo(__CLASS__ . '::' . __FUNCTION__ . ': loaded json data');
         }
     } catch (ReposeJsonInstantiationError $e) {
         static::$logger->addAlert(__CLASS__ . '::' . __FUNCTION__ . ': Failed to validate sidecar file: ' . $e->getMessage());
     }
 }
 public function schemaSchemaPOST(Request $request, Response $response, $args)
 {
     $service = new SchemaService();
     $schemaSchema = $service->getSchemaSchema();
     // $schemaSchema is already json
     return $response->getBody()->write($schemaSchema);
 }