def __createFromSelected(self): self.vc("log").debug("Creating package from selected...") packageType, jsonConfigFile = self.__getPackageTypeAndJsonConfigFile() #self.vc("log").debug("packageType = '{}'", packageType) #self.vc("log").debug("jsonConfigFile = '{}'", jsonConfigFile) # if modifying existing manifest, we already have an identifier, # otherwise create a new one manifestId = self.__getActiveManifestId() if manifestId is None: manifestHash = "%s.tfpackage" % uuid.uuid4() else: manifestHash = self.__getActiveManifestPid() # store the manifest file for harvesting packageDir = FascinatorHome.getPathFile("packages") packageDir.mkdirs() manifestFile = File(packageDir, manifestHash) outStream = FileOutputStream(manifestFile) outWriter = OutputStreamWriter(outStream, "UTF-8") manifest = self.__getActiveManifest() oldType = manifest.getType() if oldType is None: manifest.setType(packageType) else: manifest.setType(oldType) #self.vc("log").debug("Manifest: {}", manifest) outWriter.write(manifest.toString(True)) outWriter.close() try: if manifestId is None: # harvest the package as an object username = self.vc("sessionState").get("username") if username is None: username = "******" # necessary? harvester = None # set up config files, and make sure they are both deployed workflowsDir = FascinatorHome.getPathFile("harvest/workflows") configFile = self.__getFile(workflowsDir, jsonConfigFile) rulesFile = self.__getFile(workflowsDir, "packaging-rules.py") # run the harvest client with our packaging workflow config harvester = HarvestClient(configFile, manifestFile, username) harvester.start() manifestId = harvester.getUploadOid() harvester.shutdown() else: # update existing object object = StorageUtils.getDigitalObject(Services.getStorage(), manifestId) manifestStream = FileUtils.openInputStream(manifestFile) StorageUtils.createOrUpdatePayload(object, manifestHash, manifestStream) manifestStream.close() object.close() except Exception, ex: error = "Packager workflow failed: %s" % str(ex) log.error(error, ex) if harvester is not None: harvester.shutdown() return '{ "status": "failed" }'
def __activate__(self, context): # Prepare variables self.index = context["fields"] self.object = context["object"] self.payload = context["payload"] self.params = context["params"] self.utils = context["pyUtils"] self.config = context["jsonConfig"] self.wfSecurityExceptions = None self.message_list = None # Because the workflow messaging system wants access to this data # BEFORE it actual hits the index we are going to cache it into an # object payload too. self.directIndex = JsonSimple() # Common data self.__newDoc() #print "+++ direct-files.py - itemType='%s'" % self.itemType # Real metadata if self.itemType == "object": self.__previews() self.__basicData() self.__metadata() # Update the 'direct.index' payload - BEFORE messages are sent directString = String(self.directIndex.toString()) inStream = ByteArrayInputStream(directString.getBytes("UTF-8")) try: StorageUtils.createOrUpdatePayload(self.object, "direct.index", inStream) except StorageException, e: print " * direct-files.py : Error updating direct payload" self.__messages() self.__displayType()
def __createFromSelected(self): print "Creating package from selected..." # if modifying existing manifest, we already have an identifier, # otherwise create a new one manifestId = self.__getActiveManifestId() if manifestId is None: manifestHash = "%s.tfpackage" % uuid.uuid4() else: manifestHash = self.__getActiveManifestPid() # store the manifest file for harvesting packageDir = FascinatorHome.getPathFile("packages") packageDir.mkdirs() manifestFile = File(packageDir, manifestHash) outStream = FileOutputStream(manifestFile) outWriter = OutputStreamWriter(outStream, "UTF-8") manifest = self.__getActiveManifest() manifest.store(outWriter, True) outWriter.close() try: if manifestId is None: # harvest the package as an object username = sessionState.get("username") if username is None: username = "******" # necessary? harvester = None # set up config files if necessary workflowsDir = FascinatorHome.getPathFile("harvest/workflows") configFile = self.__getFile(workflowsDir, "packaging-config.json") rulesFile = self.__getFile(workflowsDir, "packaging-rules.py") # run the harvest client with our packaging workflow config harvester = HarvestClient(configFile, manifestFile, username) harvester.start() manifestId = harvester.getUploadOid() harvester.shutdown() else: # update existing object object = StorageUtils.storeFile(Services.getStorage(), manifestFile) object.close() except Exception, ex: error = "Packager workflow failed: %s" % str(ex) log.error(error, ex) if harvester is not None: harvester.shutdown() return '{ status: "failed" }'
wfChanged = True wfMeta = JsonConfigHelper() wfMeta.set("id", WORKFLOW_ID) wfMeta.set("step", "pending") stages = jsonConfig.getJsonList("stages") for stage in stages: if stage.get("name") == "pending": item_security = stage.getList("visibility") workflow_security = stage.getList("security") # Has the workflow metadata changed? if wfChanged == True: jsonString = String(wfMeta.toString()) inStream = ByteArrayInputStream(jsonString.getBytes("UTF-8")) try: StorageUtils.createOrUpdatePayload(object, "workflow.metadata", inStream) except StorageException, e: print " * workflow-harvester.py : Error updating workflow payload" rules.add(AddField("workflow_id", wfMeta.get("id"))) rules.add(AddField("workflow_step", wfMeta.get("step"))) for group in workflow_security: rules.add(AddField("workflow_security", group)) # some defaults if the above failed if titleList == []: #use object's source id (i.e. most likely a filename) titleList.append(object.getSourceId()) if formatList == []: payload = object.getPayload(object.getSourceId())