Exemple #1
0
    def testRequire(self):
        require("commons-lang:commons-lang:2.6")
        from org.apache.commons.lang import StringUtils

        self.assertEquals(StringUtils.removeStart("jip rocks", "jip"),
                          " rocks")
        self.assertEquals(StringUtils.reverse("jip rocks"), "skcor pij")
Exemple #2
0
 def setMultiDescription(self, tfPackageJson, descriptionValue):
     if descriptionValue is None:
         self.log.info("No description found. Aborting set description shadow...")
         tfPackageJson.put("dc:description.1.text", "")
         tfPackageJson.put("dc:description.1.shadow", "")
         tfPackageJson.put("dc:description.1.type", "full")
         return
     else:
         ## no tags are added to wysiwyg until user interacts with wysiwyg editor
         unescapedDescription = ""
         escapedDescription = ""
         rawDescription = StringUtils.defaultString("%s" % descriptionValue)
         ## sanitize the incoming description
         self.log.debug("raw deprecated description is: %s" % rawDescription)
         sanitizedDescription = OwaspSanitizer.sanitizeHtml("dc:description.1.text", rawDescription)
         if (sanitizedDescription):
             # not completely accurate for checking for tags but ensures a style consistent with wysiwyg editor
             if re.search("^<p>.*</p>|^&lt;p&gt;.*&lt;\/p&gt;", sanitizedDescription):
                 ## deprecated description may be unescaped or escaped already - so ensure both cases covered
                 unescapedDescription = StringEscapeUtils.unescapeHtml("%s" % sanitizedDescription)
                 escapedDescription = OwaspSanitizer.escapeHtml("%s" % sanitizedDescription)
             else:
                 unescapedDescription = StringEscapeUtils.unescapeHtml("<p>%s</p>" % sanitizedDescription)
                 escapedDescription = OwaspSanitizer.escapeHtml("<p>%s</p>" % sanitizedDescription)
         self.log.info("relevant unescaped description is: %s" % unescapedDescription)
         self.log.info("relevant escaped description is: %s" % escapedDescription)
         tfPackageJson.put("dc:description.1.text", unescapedDescription)
         tfPackageJson.put("dc:description.1.shadow", escapedDescription)
         tfPackageJson.put("dc:description.1.type", "full")
         self.log.debug("Removing deprecated 'dc:description' key...")
         tfPackageJson.remove("dc:description")
         self.log.debug(
             "Completed migrating 'dc:description' to dc:description.1.text|shadow" % tfPackageJson)
Exemple #3
0
    def testRequire(self):
        require("commons-lang:commons-lang:2.6")
        from org.apache.commons.lang import StringUtils

        self.assertEquals(StringUtils.removeStart("jip rocks", "jip"), " rocks")
        self.assertEquals(StringUtils.reverse("jip rocks"), "skcor pij")
Exemple #4
0
    def process(self):
        print " * settings.py: formData=%s" % self.vc("formData")

        result = "{}"
        portalManager = Services.getPortalManager()
        portal = portalManager.get(self.vc("portalId"))
        func = self.vc("formData").get("func")

        if func == "view-update":
            portal.setDescription(self.vc("formData").get("view-description"))
            portal.setQuery(self.vc("formData").get("view-query"))
            portal.setSearchQuery(self.vc("formData").get("view-search-query"))
            portal.setRecordsPerPage(int(self.vc("formData").get("view-records-per-page")))
            portal.setFacetCount(int(self.vc("formData").get("view-facet-count")))
            portal.setFacetDisplay(int(self.vc("formData").get("view-facet-display")))
            portal.setFacetSort(self.vc("formData").get("view-facet-sort") is not None)
            portalManager.save(portal)

        elif func == "general-update":
            config = JsonSimpleConfig()
            email = StringUtils.trimToEmpty(self.vc("formData").get("general-email"))
            systemEmail = StringUtils.trimToEmpty(config.getString(None, ["email"]))
            if systemEmail != email:
                obj = config.writableSystemConfig()
                obj.put("email", self.vc("formData").get("general-email"))
                obj.put("configured", "true")
                config.storeSystemConfig()
                # mark restart
                Services.getHouseKeepingManager().requestUrgentRestart()
            else:
                print " * settings.py: email not updated: did not change"
                self.throw_error("Email address is the same! No change saved.")

        elif func == "facets-update":
            portal.getObject(["portal"]).remove("facet-fields")
            fields = self.vc("formData").getValues("field")
            labels = self.vc("formData").getValues("label")
            displays = self.vc("formData").getValues("display")
            deletes = self.vc("formData").getValues("delete")
            for i in range(0, len(fields)):
                field = fields[i]
                if deletes[i] == "false":
                    node = portal.writeObject(["portal", "facet-fields", field])
                    node.put("label", labels[i])
                    node.put("display", displays[i])
            portalManager.save(portal)

        elif func == "sort-update":
            portal.getObject(["portal"]).remove("sort-fields")
            default = self.vc("formData").get("default")
            if default:
                portal.setSortFieldDefault(default)
            order = self.vc("formData").get("order")
            if order:
                portal.setSortFieldDefaultOrder(order)
            fields = self.vc("formData").getValues("field")
            labels = self.vc("formData").getValues("label")
            deletes = self.vc("formData").getValues("delete")
            for i in range(0, len(fields)):
                field = fields[i]
                if deletes[i] == "false":
                    node = portal.writeObject(["portal", "sort-fields"])
                    node.put(field, labels[i])
            portalManager.save(portal)

        elif func == "watcher-update":
            configFile = self.getWatcherFile()
            if configFile is not None:
                json = JsonSimpleConfig(configFile)
                pathIds = self.vc("formData").get("pathIds").split(",")
                actives = self.vc("formData").getValues("watcher-active")
                if actives is None:
                    actives = []
                deletes = self.vc("formData").getValues("watcher-delete")
                if deletes is None:
                    deletes = []
                for pathId in pathIds:
                    if pathId not in deletes:
                        path = self.vc("formData").get("%s-path" % pathId)
                        stopped = str(pathId not in actives).lower()
                        watchDir = json.writeObject(["watcher", "watchDirs", path])
                        watchDir.put("ignoreFileFilter", self.vc("formData").get("%s-file" % pathId))
                        watchDir.put("ignoreDirectories", self.vc("formData").get("%s-dir" % pathId))
                        watchDir.put("stopped", stopped)
                        json.writeArray(["watcher", "watchDirs", path, "cxtTags"])
                writer = FileWriter(configFile)
                writer.write(json.toString(True))
                writer.close()
            else:
                result = "The Watcher is not installed properly."

        elif func == "restore-default-config":
            # backup the file
            JsonSimpleConfig.backupSystemFile()
            # delete the file
            JsonSimpleConfig.getSystemFile().delete()
            # restore default
            JsonSimpleConfig.getSystemFile()
            # mark restart
            Services.getHouseKeepingManager().requestUrgentRestart()

        elif func == "housekeeping-update":
            config = JsonSimpleConfig()
            freq = StringUtils.trimToEmpty(self.vc("formData").get("housekeeping-timeout"))
            systemFreq = StringUtils.trimToEmpty(config.getString(None, ["portal", "houseKeeping", "config", "frequency"]))
            result = "House Keeper refreshed"
            if systemFreq != freq:
                # Get writeable access to underlying system
                sysConfig = JsonSimple(config.writableSystemConfig())
                # Modify the house keeping node
                hkConfig = sysConfig.writeObject(["portal", "houseKeeping", "config"])
                hkConfig.put("frequency", freq)
                # Write the underlying config back to disk
                config.storeSystemConfig()
                result = "Frequency updated, refreshing House Keeper"
            # Refresh the HouseKeeper
            message = JsonObject()
            message.put("type", "refresh")
            Services.getHouseKeepingManager().sendMessage(message.toString())

        self.writer.println(result)
        self.writer.close()
Exemple #5
0
    def process(self):
        print " * settings.py: formData=%s" % self.vc("formData")

        result = "{}"
        portalManager = Services.getPortalManager()
        portal = portalManager.get(self.vc("portalId"))
        func = self.vc("formData").get("func")

        if func == "view-update":
            portal.setDescription(self.vc("formData").get("view-description"))
            portal.setQuery(self.vc("formData").get("view-query"))
            portal.setSearchQuery(self.vc("formData").get("view-search-query"))
            portal.setRecordsPerPage(int(self.vc("formData").get("view-records-per-page")))
            portal.setFacetCount(int(self.vc("formData").get("view-facet-count")))
            portal.setFacetDisplay(int(self.vc("formData").get("view-facet-display")))
            portal.setFacetSort(self.vc("formData").get("view-facet-sort") is not None)
            portalManager.save(portal)

        elif func == "general-update":
            config = JsonConfig()
            email = StringUtils.trimToEmpty(self.vc("formData").get("general-email"))
            systemEmail = StringUtils.trimToEmpty(config.get("email"))
            print email, systemEmail
            if systemEmail != email:
                config.set("email", self.vc("formData").get("general-email"), True)
                config.set("configured", "true", True)
                config.store(NullWriter(), True)
                # mark restart
                Services.getHouseKeepingManager().requestUrgentRestart()
            else:
                print " * settings.py: email not updated: did not change"
                self.throw_error("Email address is the same! No change saved.")

        elif func == "facets-update":
            portal.removePath("portal/facet-fields")
            fields = self.vc("formData").getValues("field")
            labels = self.vc("formData").getValues("label")
            displays = self.vc("formData").getValues("display")
            deletes = self.vc("formData").getValues("delete")
            for i in range(0, len(fields)):
                field = fields[i]
                if deletes[i] == "false":
                    portal.set("portal/facet-fields/%s/label" % field, labels[i])
                    portal.set("portal/facet-fields/%s/display" % field, displays[i])
            portalManager.save(portal)

        elif func == "sort-update":
            portal.removePath("portal/sort-fields")
            fields = self.vc("formData").getValues("field")
            labels = self.vc("formData").getValues("label")
            deletes = self.vc("formData").getValues("delete")
            for i in range(0, len(fields)):
                field = fields[i]
                if deletes[i] == "false":
                    portal.set("portal/sort-fields/%s" % field, labels[i])
            portalManager.save(portal)

        elif func == "watcher-update":
            configFile = self.getWatcherFile()
            if configFile is not None:
                pathIds = self.vc("formData").get("pathIds").split(",")
                actives = self.vc("formData").getValues("watcher-active")
                if actives is None:
                    actives = []
                deletes = self.vc("formData").getValues("watcher-delete")
                if deletes is None:
                    deletes = []
                watchDirs = HashMap()
                for pathId in pathIds:
                    if pathId not in deletes:
                        path = self.vc("formData").get("%s-path" % pathId)
                        stopped = str(pathId not in actives).lower()
                        watchDir = HashMap()
                        watchDir.put("ignoreFileFilter", self.vc("formData").get("%s-file" % pathId))
                        watchDir.put("ignoreDirectories", self.vc("formData").get("%s-dir" % pathId))
                        watchDir.put("cxtTags", [])
                        watchDir.put("stopped", stopped)
                        watchDirs.put(path, watchDir)
                json = JsonConfigHelper(self.getWatcherFile())
                json.setMap("watcher/watchDirs", watchDirs)
                json.store(FileWriter(configFile), True)
            else:
                result = "The Watcher is not installed properly."

        elif func == "restore-default-config":
            # backup the file
            JsonConfig.backupSystemFile()
            # delete the file
            JsonConfig.getSystemFile().delete()
            # restore default
            JsonConfig.getSystemFile()
            # mark restart
            Services.getHouseKeepingManager().requestUrgentRestart()

        elif func == "housekeeping-update":
            config = JsonConfig()
            freq = StringUtils.trimToEmpty(self.vc("formData").get("housekeeping-timeout"))
            systemFreq = StringUtils.trimToEmpty(config.get("portal/houseKeeping/config/frequency"))
            result = "House Keeper refreshed"
            if systemFreq != freq:
                config.set("portal/houseKeeping/config/frequency", freq, True)
                config.store(NullWriter(), True)
                result = "Frequency updated, refreshing House Keeper"
            # Refresh the HouseKeeper
            message = JsonConfigHelper()
            message.set("type", "refresh")
            Services.getHouseKeepingManager().sendMessage(message.toString())

        self.writer.println(result)
        self.writer.close()
Exemple #6
0
    def process(self):
        self.log.debug(" * settings.py: formData={}", self.vc("formData"))

        valid = self.vc("page").csrfSecurePage()
        if not valid:
            self.throw_error("Invalid request")
            return

        result = "{}"
        portalManager = self.vc("Services").getPortalManager()
        portal = portalManager.get(self.vc("portalId"))
        func = self.vc("formData").get("func")

        if func == "view-update":
            portal.setDescription(self.vc("formData").get("view-description"))
            portal.setQuery(self.vc("formData").get("view-query"))
            portal.setSearchQuery(self.vc("formData").get("view-search-query"))
            portal.setRecordsPerPage(
                int(self.vc("formData").get("view-records-per-page")))
            portal.setFacetCount(
                int(self.vc("formData").get("view-facet-count")))
            portal.setFacetDisplay(
                int(self.vc("formData").get("view-facet-display")))
            portal.setFacetSort(
                self.vc("formData").get("view-facet-sort") is not None)
            portalManager.save(portal)

        elif func == "general-update":
            config = JsonSimpleConfig()
            email = StringUtils.trimToEmpty(
                self.vc("formData").get("general-email"))
            systemEmail = StringUtils.trimToEmpty(
                config.getString(None, ["email"]))
            if systemEmail != email:
                obj = config.writableSystemConfig()
                obj.put("email", self.vc("formData").get("general-email"))
                obj.put("configured", "true")
                config.storeSystemConfig()
                # mark restart
                self.vc("Services").getHouseKeepingManager(
                ).requestUrgentRestart()
            else:
                self.log.debug(
                    " * settings.py: email not updated: did not change")
                self.throw_error("Email address is the same! No change saved.")

        elif func == "facets-update":
            portal.getObject(["portal"]).remove("facet-fields")
            fields = self.vc("formData").getValues("field")
            labels = self.vc("formData").getValues("label")
            displays = self.vc("formData").getValues("display")
            deletes = self.vc("formData").getValues("delete")
            for i in range(0, len(fields)):
                field = fields[i]
                if deletes[i] == "false":
                    node = portal.writeObject(
                        ["portal", "facet-fields", field])
                    node.put("label", labels[i])
                    node.put("display", displays[i])
            portalManager.save(portal)

        elif func == "sort-update":
            portal.getObject(["portal"]).remove("sort-fields")
            default = self.vc("formData").get("default")
            if default:
                portal.setSortFieldDefault(default)
            order = self.vc("formData").get("order")
            if order:
                portal.setSortFieldDefaultOrder(order)
            fields = self.vc("formData").getValues("field")
            labels = self.vc("formData").getValues("label")
            deletes = self.vc("formData").getValues("delete")
            for i in range(0, len(fields)):
                field = fields[i]
                if deletes[i] == "false":
                    node = portal.writeObject(["portal", "sort-fields"])
                    node.put(field, labels[i])
            portalManager.save(portal)

        elif func == "watcher-update":
            configFile = self.getWatcherFile()
            if configFile is not None:
                json = JsonSimpleConfig(configFile)
                pathIds = self.vc("formData").get("pathIds").split(",")
                actives = self.vc("formData").getValues("watcher-active")
                if actives is None:
                    actives = []
                deletes = self.vc("formData").getValues("watcher-delete")
                if deletes is None:
                    deletes = []
                for pathId in pathIds:
                    if pathId not in deletes:
                        path = self.vc("formData").get("%s-path" % pathId)
                        stopped = str(pathId not in actives).lower()
                        watchDir = json.writeObject(
                            ["watcher", "watchDirs", path])
                        watchDir.put(
                            "ignoreFileFilter",
                            self.vc("formData").get("%s-file" % pathId))
                        watchDir.put(
                            "ignoreDirectories",
                            self.vc("formData").get("%s-dir" % pathId))
                        watchDir.put("stopped", stopped)
                        json.writeArray(
                            ["watcher", "watchDirs", path, "cxtTags"])
                writer = FileWriter(configFile)
                writer.write(json.toString(True))
                writer.close()
            else:
                result = "The Watcher is not installed properly."

        elif func == "restore-default-config":
            # backup the file
            JsonSimpleConfig.backupSystemFile()
            # delete the file
            JsonSimpleConfig.getSystemFile().delete()
            # restore default
            JsonSimpleConfig.getSystemFile()
            # mark restart
            self.vc("Services").getHouseKeepingManager().requestUrgentRestart()

        elif func == "housekeeping-update":
            config = JsonSimpleConfig()
            freq = StringUtils.trimToEmpty(
                self.vc("formData").get("housekeeping-timeout"))
            systemFreq = StringUtils.trimToEmpty(
                config.getString(
                    None, ["portal", "houseKeeping", "config", "frequency"]))
            result = "House Keeper refreshed"
            if systemFreq != freq:
                # Get writeable access to underlying system
                sysConfig = JsonSimple(config.writableSystemConfig())
                # Modify the house keeping node
                hkConfig = sysConfig.writeObject(
                    ["portal", "houseKeeping", "config"])
                hkConfig.put("frequency", freq)
                # Write the underlying config back to disk
                config.storeSystemConfig()
                result = "Frequency updated, refreshing House Keeper"
            # Refresh the HouseKeeper
            message = JsonObject()
            message.put("type", "refresh")
            self.vc("Services").getHouseKeepingManager().sendMessage(
                message.toString())

        self.writer.println(result)
        self.writer.close()
Exemple #7
0
 def __init__(self):
     print " * settings.py: formData=%s" % formData
     result = "{}"
     portalManager = Services.getPortalManager()
     portal = portalManager.get(portalId)
     func = formData.get("func")
     if func == "view-update":
         portal.setDescription(formData.get("view-description"))
         portal.setQuery(formData.get("view-query"))
         portal.setSearchQuery(formData.get("view-search-query"))
         print " *** ", formData.get("view-records-per-page")
         portal.setRecordsPerPage(int(formData.get("view-records-per-page")))
         portal.setFacetCount(int(formData.get("view-facet-count")))
         portal.setFacetSort(formData.get("view-facet-sort") is not None)
         portalManager.save(portal)
     elif func == "general-update":
         config = JsonConfig()
         email = StringUtils.trimToEmpty(formData.get("general-email"))
         systemEmail = StringUtils.trimToEmpty(config.get("email"))
         print email, systemEmail
         if systemEmail != email:
             config.set("email", formData.get("general-email"), True)
             config.set("configured", "true", True)
             config.store(NullWriter(), True)
             # mark restart
             sessionState.set("need-restart", "true")
         else:
             print " * settings.py: email not updated: did not change"
     elif func == "facets-update":
         portal.removePath("portal/facet-fields")
         fields = formData.getValues("field")
         labels = formData.getValues("label")
         displays = formData.getValues("display")
         deletes = formData.getValues("delete")
         for i in range(0, len(fields)):
             field = fields[i]
             if deletes[i] == "false":
                 portal.set("portal/facet-fields/%s/label" % field, labels[i])
                 portal.set("portal/facet-fields/%s/display" % field, displays[i])
         portalManager.save(portal)
     elif func == "backup-update":
         pathIds = formData.get("pathIds").split(",")
         actives = formData.getValues("backup-active")
         deletes = formData.getValues("backup-delete")
         if actives is None:
             actives = []
         #renditions = formData.getValues("backup-rendition")
         #if renditions is None:
         #    renditions = []
         views = formData.getValues("backup-view")
         if views is None:
             views = []
         paths = HashMap()
         for pathId in pathIds:
             if deletes is None or pathId not in deletes:
                 path = formData.get("%s-path" % pathId)
                 pathName = path.replace("/", "_").replace("${user.home}", "")
                 active = str(pathId in actives).lower()
                 #rendition = str(pathId in renditions).lower()
                 view = str(pathId in views).lower()
                 ignoreFilter = formData.get("%s-ignore" % pathId)
                 
                 json = HashMap()
                 json.put("path", path)
                 json.put("active", active)
                 json.put("include-portal-view", view)
                 json.put("ignoreFilter", ignoreFilter)
                 
                 storage = HashMap()
                 storage.put("type", "file-system")
                 
                 filesystem = HashMap()
                 filesystem.put("home", path)
                 filesystem.put("use-link", "false")
                 storage.put("file-system", filesystem)
                 
                 json.put("storage", storage)
                 paths.put(pathName, json)
         # reset the path first
         portal.setMap("portal/backup/paths", HashMap())
         portal.setMultiMap("portal/backup/paths", paths)
         portalManager.save(portal)
     elif func == "watcher-update":
         configFile = self.getWatcherFile()
         if configFile is not None:
             pathIds = formData.get("pathIds").split(",")
             actives = formData.getValues("watcher-active")
             if actives is None:
                 actives = []
             deletes = formData.getValues("watcher-delete")
             if deletes is None:
                 deletes = []
             watchDirs = HashMap()
             for pathId in pathIds:
                 if pathId not in deletes:
                     path = formData.get("%s-path" % pathId)
                     stopped = str(pathId not in actives).lower()
                     watchDir = HashMap()
                     watchDir.put("ignoreFileFilter", formData.get("%s-file" % pathId))
                     watchDir.put("ignoreDirectories", formData.get("%s-dir" % pathId))
                     watchDir.put("cxtTags", [])
                     watchDir.put("stopped", stopped)
                     watchDirs.put(path, watchDir)
             json = JsonConfigHelper(self.getWatcherFile())
             json.setMap("watcher/watchDirs", watchDirs)
             json.store(FileWriter(configFile), True)
         else:
             result = "The Watcher is not installed properly."
     elif func == "restore-default-config":
         # delete the file
         JsonConfig.getSystemFile().delete()
         # restore default
         JsonConfig.getSystemFile()
         # mark restart
         sessionState.set("need-restart", "true")
     writer = response.getPrintWriter("text/plain; charset=UTF-8")
     writer.println(result)
     writer.close()