예제 #1
0
 def getLabel(self, jsonFile, key, listKey, valKey, labelKey):
     value = self.metadata.get(key)
     jsonLabelFile = System.getProperty("fascinator.home") + jsonFile
     jsonLabel = JsonSimple(File(jsonLabelFile))
     entries = jsonLabel.getJsonArray()
     # the structure of the json file is fun and complicated
     if entries is None:
         entries = jsonLabel.getArray(listKey)
     else:
         valKey = "value"
         labelKey = "label"
     for entry in entries:
         entryJson = JsonSimple(entry)
         if value == entryJson.getString("", valKey):
             return entryJson.getString("", labelKey)
     return None
예제 #2
0
파일: detail.py 프로젝트: nishen/redbox
 def getLabel(self, jsonFile, key, listKey, valKey, labelKey):
     value = self.metadata.get(key)
     jsonLabelFile = System.getProperty("fascinator.home") + jsonFile
     jsonLabel = JsonSimple(File(jsonLabelFile))
     entries = jsonLabel.getJsonArray()
     # the structure of the json file is fun and complicated
     if entries is None:
         entries = jsonLabel.getArray(listKey)
     else:
         valKey = "value"
         labelKey = "label"
     for entry in entries:
         entryJson = JsonSimple(entry)
         if value == entryJson.getString("", valKey):
             return entryJson.getString("", labelKey)
     return None
예제 #3
0
    def __getPayloadJsonArray(self, oid, payloadName):
        """
        Get the content (JsonArray) of a payload
        return the JSONArray or an empty (new) one 
        """
        storedObj = self.Services.getStorage().getObject(oid)

        payloadList = storedObj.getPayloadIdList()
        if payloadList.contains(payloadName):
            # print "Updating existing"
            payloadObj = storedObj.getPayload(payloadName)
            payloadJson = JsonSimple(payloadObj.open())
            objList = payloadJson.getJsonArray()
        else:
            # print "Creating new one"
            objList = JSONArray()

        return objList
예제 #4
0
파일: detail.py 프로젝트: ozej8y/redbox
 def getLabel(self, jsonFile, key):
     value = self.metadata.get(key)
     jsonLabelFile = System.getProperty("fascinator.home") + jsonFile
     jsonF = JsonSimple(File(jsonLabelFile))
     entries = jsonF.getJsonArray()
     if entries is None:
         entries = jsonF.getArray('results')
         if entries is None:
             self.log.debug("Unknown data source format: JSON file {} or its 'results' has no array.", jsonLabelFile)
             return None
     
     for entry in entries:
         entryJson = JsonSimple(entry)
         if value == entryJson.getString("", "id"):
             return entryJson.getString("", "label")
         elif value == entryJson.getString("", "value"):
             return entryJson.getString("", "label")
         
     return None
예제 #5
0
 def __getPayloadJsonArray(self, oid, payloadName):
     """
     Get the content (JsonArray) of a payload
     return the JSONArray or an empty (new) one 
     """
     storedObj = self.Services.getStorage().getObject(oid)
     
     payloadList = storedObj.getPayloadIdList()
     if payloadList.contains(payloadName):
         # print "Updating existing"
         payloadObj = storedObj.getPayload(payloadName)
         payloadJson = JsonSimple(payloadObj.open())
         objList = payloadJson.getJsonArray()
     else:
         # print "Creating new one"
         objList = JSONArray()
     
     return objList
      
예제 #6
0
    def getLabel(self, jsonFile, key):
        value = self.metadata.get(key)
        jsonLabelFile = System.getProperty("fascinator.home") + jsonFile
        jsonF = JsonSimple(File(jsonLabelFile))
        entries = jsonF.getJsonArray()
        if entries is None:
            entries = jsonF.getArray('results')
            if entries is None:
                self.log.debug(
                    "Unknown data source format: JSON file {} or its 'results' has no array.",
                    jsonLabelFile)
                return None

        for entry in entries:
            entryJson = JsonSimple(entry)
            if value == entryJson.getString("", "id"):
                return entryJson.getString("", "label")
            elif value == entryJson.getString("", "value"):
                return entryJson.getString("", "label")

        return None
예제 #7
0
class LaunchData:
    def __init__(self):
        pass

    def __activate__(self, context):
        self.log = context["log"]
        self.request = context["request"]
        self.sessionState = context["sessionState"]
        self.sessionState.set("username", "admin")
        processingSet = self.request.getParameter("processingSet")
        self.procMsg = None
        # read configuration and trigger processing stream sets
        # storing the return object on the map
        configFilePath = FascinatorHome.getPath(
            "process") + "/processConfig.json"
        procConfigFile = File(configFilePath)
        if procConfigFile.exists() == True:
            self.dataMap = HashMap()
            self.dataMap.put("indexer", context['Services'].getIndexer())
            self.procConfigJson = JsonSimple(procConfigFile)
            for configObj in self.procConfigJson.getJsonArray():
                configJson = JsonSimple(configObj)
                procId = configJson.getString("", "id")
                if processingSet is not None:
                    if procId == processingSet:
                        self.execProcSet(procId, configJson)
                else:
                    self.execProcSet(procId, configJson)
            if self.procMsg is None:
                self.procMsg = "Processing complete!"
        else:
            self.procMsg = "Configuration file does not exist: " + configFilePath

    def execProcSet(self, procId, configJson):
        self.execProcessors(procId, configJson, self.dataMap, "pre")
        self.execProcessors(procId, configJson, self.dataMap, "main")
        self.execProcessors(procId, configJson, self.dataMap, "post")

    def execProcessors(self, procId, configJson, dataMap, stageName):
        for procObj in configJson.getArray(stageName):
            procJson = JsonSimple(procObj)
            procClassName = procJson.getString("", "class")
            procConfigPath = procJson.getString("", "config")

            procInputKey = procJson.getString("", "inputKey")
            procOutputKey = procJson.getString("", "outputKey")
            procClass = Class.forName(procClassName)
            procInst = procClass.newInstance()

            procMethod = procClass.getMethod(
                "process", self.get_class("java.lang.String"),
                self.get_class("java.lang.String"),
                self.get_class("java.lang.String"),
                self.get_class("java.lang.String"),
                self.get_class("java.lang.String"),
                self.get_class("java.util.HashMap"))
            procMethod.invoke(procInst, procId, procInputKey, procOutputKey,
                              stageName, procConfigPath, dataMap)

    # Standard Java Class forName seems to have issues at least with Interfaces.
    # This is an alternative method taken from http://stackoverflow.com/questions/452969/does-python-have-an-equivalent-to-java-class-forname
    def get_class(self, kls):
        parts = kls.split('.')
        module = ".".join(parts[:-1])
        m = __import__(module)
        for comp in parts[1:]:
            m = getattr(m, comp)
        return m

    def getProcMsg(self):
        return self.procMsg
예제 #8
0
class LaunchData:

    def __init__(self):
        pass
    def __activate__(self, context):
        self.log = context["log"]
        self.request = context["request"]
        self.sessionState = context["sessionState"]
        self.sessionState.set("username","admin")
        processingSet = self.request.getParameter("processingSet")
        self.procMsg = None
        # read configuration and trigger processing stream sets
        # storing the return object on the map
        configFilePath = FascinatorHome.getPath("process")+"/processConfig.json"
        procConfigFile = File(configFilePath)
        if procConfigFile.exists() == True:
            self.dataMap = HashMap()
            self.dataMap.put("indexer", context['Services'].getIndexer())
            self.procConfigJson = JsonSimple(procConfigFile)
            for configObj in self.procConfigJson.getJsonArray():
                configJson = JsonSimple(configObj)
                procId = configJson.getString("", "id")
                if processingSet is not None: 
                    if procId == processingSet:
                        self.execProcSet(procId, configJson)
                else:
                    self.execProcSet(procId, configJson)
            if self.procMsg is None:
                self.procMsg = "Processing complete!"
        else:
            self.procMsg = "Configuration file does not exist: " + configFilePath
            
    def execProcSet(self, procId, configJson):
        self.execProcessors(procId, configJson, self.dataMap, "pre")
        self.execProcessors(procId, configJson, self.dataMap, "process")
        self.execProcessors(procId, configJson, self.dataMap, "post")
        
    def execProcessors(self, procId, configJson, dataMap, stageName):
        for procObj in configJson.getArray(stageName):
            procJson = JsonSimple(procObj)
            procClassName = procJson.getString("", "class")
            procConfigPath = procJson.getString("", "config")
            
            procInputKey = procJson.getString("", "inputKey")
            procOutputKey = procJson.getString("", "outputKey")
            procClass = Class.forName(procClassName)
            procInst = procClass.newInstance()
            
            procMethod = procClass.getMethod("process", self.get_class("java.lang.String"),self.get_class("java.lang.String"), self.get_class("java.lang.String"),self.get_class("java.lang.String"),self.get_class("java.lang.String"), self.get_class("java.util.HashMap"))
            procMethod.invoke(procInst, procId, procInputKey, procOutputKey, stageName, procConfigPath, dataMap)
            
        
    # Standard Java Class forName seems to have issues at least with Interfaces. 
    # This is an alternative method taken from http://stackoverflow.com/questions/452969/does-python-have-an-equivalent-to-java-class-forname    
    def get_class(self, kls):
        parts = kls.split('.')
        module = ".".join(parts[:-1])
        m = __import__( module )
        for comp in parts[1:]:
            m = getattr(m, comp)            
        return m    
    
    def getProcMsg(self):
        return self.procMsg