コード例 #1
0
ファイル: settings.py プロジェクト: kiranba/the-fascinator
 def __init__(self):
     self.__portal = None
     action = formData.get("verb")
     if action == "create_view":
         fq = [q for q in sessionState.get("fq") if q != 'item_type:"object"']
         if fq == []:
             name = "new"
             desc = "New View"
             query = ""
         else:
             name = ""
             desc = ""
             query = str(" ".join(fq))
         newPortal = Portal(name, desc, query)
         newPortal.setFacetFields(Services.portalManager.default.facetFields)
         newPortal.setQuery(query)
         self.__portal = newPortal
     else:
         portalName = formData.get("portalName")
         print " * settings.py: portalName=%s, portalId=%s" % (portalName, portalId)
         if portalName is None or (formData.get("portalAction") == "Cancel"):
             self.__portal = Services.portalManager.get(portalId)
         else:
             self.__portal = Portal()
             self.__portal.name = portalName
             Services.portalManager.add(self.__portal)
         if formData.get("portalAction") == "Update":
             self.__updatePortal()
         if formData.get("emailAction") == "Update":
             self.__updateEmail()
         if formData.get("backupAction") == "Update":    
             self.__updateBackupPaths()
コード例 #2
0
ファイル: view.py プロジェクト: kiranba/the-fascinator
 def __init__(self):
     print " * view.py: formData=%s" % formData
     result = "{}"
     portalManager = Services.getPortalManager()
     func = formData.get("func")
     if func == "create-view":
         id = formData.get("id")
         description = formData.get("description")
         fq = [q for q in sessionState.get("fq") if q != 'item_type:"object"']
         query = str(" OR ".join(fq))
         searchQuery = sessionState.get("searchQuery")
         portal = Portal(id)
         portal.setDescription(description)
         portal.setQuery(query)
         portal.setSearchQuery(searchQuery)
         portal.setFacetFields(portalManager.getDefault().getFacetFields())
         portalManager.add(portal)
         portalManager.save(portal)
         result = '{ url: "%s/%s/home" }' % (contextPath, id)
     elif func == "delete-view":
         print " * view.py: delete portal %s" % portalId
         Services.getPortalManager().remove(portalId)
     writer = response.getPrintWriter("text/plain; charset=UTF-8")
     writer.println(result)
     writer.close()
コード例 #3
0
ファイル: view.py プロジェクト: kiranba/the-fascinator
 def __activate__(self, context):
     response = context["response"]
     writer = response.getPrintWriter("text/plain; charset=UTF-8")
     auth = context["page"].authentication
     result = JsonSimple()
     obj = result.getJsonObject()
     obj.put("status", "error")
     obj.put("message", "An unknown error has occurred")
     if auth.is_logged_in():
         services = context["Services"]
         formData = context["formData"]
         sessionState = context["sessionState"]
         urlBase = context["urlBase"]
         if urlBase.endswith("/"):
             urlBase = urlBase[:-1]
         func = formData.get("func")
         portalManager = services.portalManager
         if func == "create-view":
             try:
                 fq = [q for q in sessionState.get("fq") if q != 'item_type:"object"']
                 id = formData.get("id")
                 description = formData.get("description")
                 print "Creating view '%s': '%s'" % (id, description)
                 portal = Portal(id)
                 portal.setDescription(formData.get("description"))
                 portal.setQuery(" OR ".join(fq))
                 portal.setSearchQuery(sessionState.get("searchQuery"))
                 portal.setFacetFields(portalManager.default.facetFields)
                 portalManager.add(portal)
                 portalManager.save(portal)
                 obj.put("status", "ok")
                 obj.put("message", "View '%s' successfully created" % id)
                 obj.put("url", "%s/%s/home" % (urlBase, id))
             except Exception, e:
                 response.setStatus(500)
                 obj.put("message", str(e))
         elif func == "delete-view":
             defaultPortal = context["defaultPortal"]
             portalId = formData.get("view")
             if auth.is_admin():
                 if not portalId:
                     response.setStatus(500)
                     obj.put("message", "No view specified to be deleted")
                 elif portalId != defaultPortal:
                     # sanity check: don't delete default portal
                     print "Deleting view '%s'" % portalId
                     try:
                         portalManager.remove(portalId)
                         obj.put("status", "ok")
                         obj.put("message", "View '%s' successfully removed" % portalId)
                         obj.put("url", "%s/%s/home" % (urlBase, defaultPortal))
                     except Exception, e:
                         obj.put("message", str(e))
                 else:
                     response.setStatus(500)
                     obj.put("message", "The default view cannot be deleted")
             else:
                 response.setStatus(403)
                 obj.put("message", "Only administrative users can access this API")
コード例 #4
0
ファイル: settings.py プロジェクト: kiranba/the-fascinator
    def __activate__(self, context):
        self.velocityContext = context

        self.__portal = None
        action = self.vc("formData").get("verb")
        if action == "create_view":
            fq = [q for q in self.vc("sessionState").get("fq") if q != 'item_type:"object"']
            if fq == []:
                name = "new"
                desc = "New View"
                query = ""
            else:
                name = ""
                desc = ""
                query = str(" ".join(fq))
            newPortal = Portal(name, desc, query)
            newPortal.setFacetFields(Services.portalManager.default.facetFields)
            newPortal.setQuery(query)
            self.__portal = newPortal
        else:
            portalName = self.vc("formData").get("portalName")
            print " * settings.py: portalName=%s, portalId=%s" % (portalName, self.vc("portalId"))
            if portalName is None or (self.vc("formData").get("portalAction") == "Cancel"):
                self.__portal = Services.portalManager.get(self.vc("portalId"))
            else:
                self.__portal = Portal()
                self.__portal.name = portalName
                Services.portalManager.add(self.__portal)
            if self.vc("formData").get("portalAction") == "Update":
                self.__updatePortal()
            if self.vc("formData").get("emailAction") == "Update":
                self.__updateEmail()
コード例 #5
0
ファイル: settings.py プロジェクト: kiranba/the-fascinator
class SettingsData:

    def __init__(self):
        pass

    def __activate__(self, context):
        self.velocityContext = context

        self.__portal = None
        action = self.vc("formData").get("verb")
        if action == "create_view":
            fq = [q for q in self.vc("sessionState").get("fq") if q != 'item_type:"object"']
            if fq == []:
                name = "new"
                desc = "New View"
                query = ""
            else:
                name = ""
                desc = ""
                query = str(" ".join(fq))
            newPortal = Portal(name, desc, query)
            newPortal.setFacetFields(Services.portalManager.default.facetFields)
            newPortal.setQuery(query)
            self.__portal = newPortal
        else:
            portalName = self.vc("formData").get("portalName")
            print " * settings.py: portalName=%s, portalId=%s" % (portalName, self.vc("portalId"))
            if portalName is None or (self.vc("formData").get("portalAction") == "Cancel"):
                self.__portal = Services.portalManager.get(self.vc("portalId"))
            else:
                self.__portal = Portal()
                self.__portal.name = portalName
                Services.portalManager.add(self.__portal)
            if self.vc("formData").get("portalAction") == "Update":
                self.__updatePortal()
            if self.vc("formData").get("emailAction") == "Update":
                self.__updateEmail()
    
    # Get from velocity context
    def vc(self, index):
        if self.velocityContext[index] is not None:
            return self.velocityContext[index]
        else:
            log.error("ERROR: Requested context entry '" + index + "' doesn't exist")
            return None

    def isSelected(self, category):
        selected = self.vc("sessionState").get("settingsCategory")
        if category == selected:
            return "selected"
        return ""
    
    def __updatePortal(self):
        self.__portal.name = self.vc("formData").get("portalName")
        self.__portal.description = self.vc("formData").get("portalDescription")
        self.__portal.query = self.vc("formData").get("portalQuery")
        self.__portal.recordsPerPage = int(self.vc("formData").get("portalRecordsPerPage"))
        self.__portal.facetCount = int(self.vc("formData").get("portalFacetLimit"))
        self.__portal.facetSort = self.vc("formData").get("portalFacetSort") is not None
        facetFields = self.__portal.facetFields
        facetFields.clear()
        size = int(self.vc("formData").get("portalFacetSize"))
        for i in range(1,size+2):
            nameKey = "portalFacet_%s_name" % i
            labelKey = "portalFacet_%s_label" % i
            name = self.vc("formData").get(nameKey)
            label = self.vc("formData").get(labelKey)
            print "facet: key: %s, label: %s" % (name, label)
            if name is not None and label is not None:
                facetFields.put(name, label)
        self.__portal.setFacetFields(facetFields)
        sortFields = self.__portal.sortFields
        sortFields.clear()
        size = int(self.vc("formData").get("portalSortSize"))
        for i in range(1,size+2):
            nameKey = "portalSort_%s_name" % i
            labelKey = "portalSort_%s_label" % i
            name = self.vc("formData").get(nameKey)
            label = self.vc("formData").get(labelKey)
            print "sort: key: %s, label: %s" % (name, label)
            if name is not None and label is not None:
                sortFields.put(name, label)
        self.__portal.setSortFields(sortFields)
        Services.portalManager.save(self.__portal)
    
    def getPortal(self):
        return self.__portal
    
    def getIndexerPlugins(self):
        return PluginManager.getIndexerPlugins()
    
    def getStoragePlugins(self):
        return PluginManager.getStoragePlugins()
    
    def getHarvesterPlugins(self):
        return PluginManager.getHarvesterPlugins()
    
    def getTransformerPlugins(self):
        return PluginManager.getTransformerPlugins()
    
    def getWatcherConfig(self):
        json = JsonConfig()
        watcherPath = json.get("watcher/path", "${fascinator.home}/watcher)")
        configFile = File("%s/app/config.json" % watcherPath)
        if configFile.exists():
            return JsonConfigHelper(configFile)
        return None
    
    def getEmail(self):
        return JsonConfig().get("email")
    
    def getTimeout(self):
        return JsonConfig().get("portal/houseKeeping/config/frequency")
    
    def getFacetDisplays(self):
        facetDisplays = self.__portal.getMap("portal/facet-displays")
        if facetDisplays is None or facetDisplays.isEmpty():
            facetDisplays = HashMap()
            facetDisplays.put("list", "List menu")
            facetDisplays.put("tree", "Dynamic tree")
        return facetDisplays
コード例 #6
0
ファイル: settings.py プロジェクト: kiranba/the-fascinator
class SettingsData:

    def __init__(self):
        self.__portal = None
        action = formData.get("verb")
        if action == "create_view":
            fq = [q for q in sessionState.get("fq") if q != 'item_type:"object"']
            if fq == []:
                name = "new"
                desc = "New View"
                query = ""
            else:
                name = ""
                desc = ""
                query = str(" ".join(fq))
            newPortal = Portal(name)
            newPortal.setFacetFields(Services.portalManager.default.facetFields)
            newPortal.setQuery(query)
            self.__portal = newPortal
        else:
            portalName = formData.get("portalName")
            print " * settings.py: portalName=%s, portalId=%s" % (portalName, portalId)
            if portalName is None or (formData.get("portalAction") == "Cancel"):
                self.__portal = Services.portalManager.get(portalId)
            else:
                self.__portal = Portal(portalName)
                self.__portal.name = portalName
                Services.portalManager.add(self.__portal)
            if formData.get("portalAction") == "Update":
                self.__updatePortal()
            if formData.get("emailAction") == "Update":
                self.__updateEmail()
            if formData.get("backupAction") == "Update":    
                self.__updateBackupPaths()
        
    def __updateEmail(self):
        self.__portal.email = formData.get("emailAddress")
        Services.portalManager.save(self.__portal)
        
    def __updateBackupPaths(self):
        backupPaths = self.__portal.backupPaths
        size = int(formData.get("backupUrlSize"))
        for i in range (1, size+2):  
            keyName = "backupPaths_%s_name" % i
            activeName = "backupPaths_%s_active" % i
            includeName = "backupPaths_%s_include-rendition-meta" % i
            includePortal = "backupPaths_%s_include-portal-view" % i
            filterName = "backupPaths_%s_filter" % i
            
            name = formData.get(keyName)
            activeValue = formData.get(activeName)
            includeRenditionValue = formData.get(includeName)
            filterValue = formData.get(filterName)
            portalViewValue = formData.get(includePortal)
            #print " * setting.py Updatebackup Path: name='%s', active='%s', includeRenditionValue='%s', filter='%s', count='%s'" % \
            #    (name, activeValue, includeRenditionValue, filterValue, i) 
            if name is not None:
                newInfo = {}
                newInfo["active"] = activeValue is not None
                newInfo["include-rendition-meta"] = includeRenditionValue is not None
                newInfo["ignoreFilter"] = filterValue
                newInfo["include-portal-view"] = portalViewValue is not None
                backupPaths.put(name, newInfo)
            self.__portal.setBackupPaths(backupPaths)
        Services.portalManager.save(self.__portal)
    
    def __updatePortal(self):
        self.__portal.name = formData.get("portalName")
        self.__portal.description = formData.get("portalDescription")
        self.__portal.query = formData.get("portalQuery")
        self.__portal.recordsPerPage = int(formData.get("portalRecordsPerPage"))
        self.__portal.facetCount = int(formData.get("portalFacetLimit"))
        self.__portal.facetSort = formData.get("portalFacetSort") is not None
        facetFields = self.__portal.facetFields
        facetFields.clear()
        size = int(formData.get("portalFacetSize"))
        for i in range(1,size+2):
            nameKey = "portalFacet_%s_name" % i
            labelKey = "portalFacet_%s_label" % i
            name = formData.get(nameKey)
            label = formData.get(labelKey)
            #print "key: %s, label: %s" % (name, label)
            if name is not None and label is not None:
                facetFields.put(name, label)
        self.__portal.setFacetFields(facetFields)
        Services.portalManager.save(self.__portal)
    
    def getPortal(self):
        return self.__portal
    
    def getIndexerPlugins(self):
        return PluginManager.getIndexerPlugins()
    
    def getStoragePlugins(self):
        return PluginManager.getStoragePlugins()
    
    def getHarvesterPlugins(self):
        return PluginManager.getHarvesterPlugins()
    
    def getTransformerPlugins(self):
        return PluginManager.getTransformerPlugins()