Exemple #1
0
 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 __activate__(self, context):
     self.request = context["request"]
     self.portalId = context["portalId"]
     self.request.setAttribute("Content-Type", "application/opensearchdescription+xml")
     
     jc = JsonConfig()
     baseUrl = jc.get("urlBase")
     if baseUrl.endswith("/"):
         baseUrl = baseUrl[:-1]
     self.__baseUrl = baseUrl
 def __activate__(self, context):
     self.log = context["log"]
     self.services = context["Services"]
     self.portalId = context["portalId"]
     self.formData = context["formData"]
     self.request = context["request"]
     #self.request.setAttribute("Content-Type", "application/x-fascinator-lookup+json")
     self.request.setAttribute("Content-Type", "application/json")
     self.__solrData = self.__getSolrData()
     self.__results = self.__solrData.getJsonList("response/docs")
 
     jc = JsonConfig()
     baseUrl = jc.get("urlBase")
     if baseUrl.endswith("/"):
         baseUrl = baseUrl[:-1]
     self.__baseUrl = baseUrl
Exemple #4
0
 def __getPackageTypes(self):
     json = JsonConfigHelper(JsonConfig.getSystemFile())
     packageTypes = json.getMap("portal/packageTypes")
     packageTypes = dict(packageTypes)
     if packageTypes=={}:
         packageTypes["default"] = {"jsonconfig":"packaging-config.json"}
     return packageTypes
Exemple #5
0
class LayoutData:
    def __init__(self):
        self.authentication = Authentication()
        self.authentication.session_init()
        self.config = JsonConfig()

    def getPortal(self):
        return Services.getPortalManager().get(portalId)

    def getPortals(self):
        return Services.getPortalManager().portals

    def getPortalName(self):
        return self.getPortal().getDescription()

    def escapeXml(self, text):
        return StringEscapeUtils.escapeXml(text)

    def escapeHtml(self, text):
        return StringEscapeUtils.escapeHtml(text)

    def unescapeHtml(self, text):
        return StringEscapeUtils.unescapeHtml(text)

    def md5Hash(self, data):
        return md5.new(data).hexdigest()

    def capitalise(self, text):
        return text[0].upper() + text[1:]

    def getTemplate(self, templateName):
        portalName = portalId
        if not Services.pageService.resourceExists(portalId, templateName, False):
            portalName = Services.portalManager.DEFAULT_PORTAL_NAME
        return "%s/%s" % (portalName, templateName)

    def isConfigured(self):
        return self.config.isConfigured()

    def isNotConfigured(self):
        return not self.config.isConfigured()

    def isOutdated(self):
        return self.config.isOutdated()

    def needRestart(self):
        return "true" == sessionState.get("need-restart", "false")
Exemple #6
0
 def __getPackageTypeAndJsonConfigFile(self):
     try:
         packageType = self.vc("formData").get("packageType", "default")
         if packageType == "":
             packageType = "default"
         json = JsonConfigHelper(JsonConfig.getSystemFile())
         pt = json.getMap("portal/packageTypes/" + packageType)
         jsonConfigFile = pt.get("jsonconfig")
         if jsonConfigFile is None:
             jsonConfigFile = "packaging-config.json"
     except Exception, e:
         jsonConfigFile = "packaging-config.json"
Exemple #7
0
 def __init__(self):
     #if formData.get("verb") == "clear-session":
     # http://139.86.38.58:8003/rep.TempTest-Content1/packages/ATest/one.htm
     # http://localhost:8080/danno/annotea/
     # "?w3c_annotates="
     # "?w3c_reply_tree="
     self.__baseUrl = None
     
     self.__annotationUri = "http://www.w3.org/2000/10/annotation-ns#Annotation"
     self.__annoReplyUri = "http://www.w3.org/2001/03/thread#Reply"
     self.__annoType = "http://www.w3.org/2000/10/annotationType#"   # startswith
     self.__replyType = "http://www.w3.org/2001/12/replyType#"
     ns = HashMap()
     ns.put("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
     ns.put("dc", "http://purl.org/dc/elements/1.1/")
     ns.put("anno", "http://www.w3.org/2000/10/annotation-ns#")
     ns.put("thread", "http://www.w3.org/2001/03/thread#")
     ns.put("adfi", "http://usq.edu.au/adfi/")
     DocumentFactory.getInstance().setXPathNamespaceURIs(ns)
     self.saxReader = SAXReader()
     jConfig = JsonConfig()
     self.__baseUrl = jConfig.get("/annotation/server")
     self.__storageType = jConfig.get("/annotation/storageType", "danno")
Exemple #8
0
    def __activate__(self, context):
        self.request = context["request"]
        self.response = context["response"]
        self.formData = context["formData"]

        if self.request.isXHR():
            print " **** formData: %s" % self.formData
            queue = self.formData.get("queueName")
            msg = self.formData.get("queueMessage")
            self.queueMessage(queue, msg);
            out = self.response.getPrintWriter("text/plain")
            out.println(self.formData)
            out.close()

        self.config = JsonConfigHelper(JsonConfig.getSystemFile())
        self.threads = self.config.getJsonList("messaging/threads")
Exemple #9
0
 def __init__(self):
     self.authentication = Authentication()
     self.authentication.session_init()
     self.config = JsonConfig()
Exemple #10
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 #11
0
    def __processRequest(self):
        baseUrl = "http://%s:%s%s/%s" % (request.serverName, serverPort, contextPath, portalId)
        depositUrl = "%s/sword/deposit.post" % baseUrl
        sword = SwordSimpleServer(depositUrl)
        try:
            p =  request.path.split(portalId+"/"+pageName+"/")[1]  # portalPath
        except:
            p = ""
        if p=="post":
            print "\n--- post ---"
            c = sword.getClient()
            c.clearProxy()
            c.clearCredentials()
            postMsg = sword.getPostMessage();
            postMsg.filetype = "application/zip"
            postMsg.filepath = "/home/ward/Desktop/Test.zip"
            depositResponse = c.postFile(postMsg)
            return str(depositResponse)
        elif p=="servicedocument":
            #print "\n--- servicedocument ---"
            sdr = sword.getServiceDocumentRequest()
            sdr.username = formData.get("username", "test")
            sdr.password = formData.get("password", "test")
            if formData.get("test"):
                depositUrl += "?test=1"
            sd = sword.doServiceDocument(sdr)  # get a serviceDocument
            out = response.getPrintWriter("text/xml")
            out.println(str(sd))
            out.close()
            bindings["pageName"] = "-noTemplate-"
            return sd
        elif p=="deposit.post":
            #print "\n--- deposit ---  formData='%s'" % str(formData)
            inputStream = formData.getInputStream()
            headers = {}
            for x in formData.getHeaders().entrySet():
                headers[x.getKey()] = x.getValue()
            deposit = sword.getDeposit()
            noOp = headers.get("X-No-Op") or "false"
            deposit.noOp = (noOp.lower()=="true") or \
                (formData.get("test") is not None)
            contentDisposition = headers.get("Content-Disposition", "")
            filename = ""
            if contentDisposition!="":
                try:
                    filename = contentDisposition.split("filename=")[1]
                    deposit.filename = filename
                except: pass
            slug = headers.get("Slug")
            if slug is not None and slug!="":
                deposit.slug = slug
            #elif filename!="":
            #    deposit.slug = filename

            deposit.username = "******"
            deposit.password = deposit.username
            try:
                file = File.createTempFile("tmptf", ".zip")
                file.deleteOnExit()
                fos = FileOutputStream(file.getAbsolutePath())
                IOUtils.copy(inputStream, fos)
                fos.close()
                print "copied posted data to '%s'" % file.getAbsolutePath()
            except Exception, e:
                print "--- Exception - '%s'" % str(e)
            deposit.contentDisposition = file.getAbsolutePath()         #????
            deposit.file = inputStream
            depositResponse = sword.doDeposit(deposit)
            id = str(depositResponse.getEntry().id)
            try:
                print
                #imsPlugin = PluginManager.getTransformer("ims")
                jsonConfig = JsonConfig()
                #imsPlugin.init(jsonConfig.getSystemFile())
                #harvestClient = HarvestClient(jsonConfig.getSystemFile());
                storagePlugin = PluginManager.getStorage(jsonConfig.get("storage/type"))
                #storagePlugin.init(jsonConfig.getSystemFile())

                setConfigUri = self.__getPortal().getClass().getResource("/swordRule.json").toURI()
                configFile = File(setConfigUri)
                harvestConfig = JsonConfigHelper(configFile);
                tFile = File.createTempFile("harvest", ".json")
                tFile.deleteOnExit()
                harvestConfig.set("configDir", configFile.getParent())
                harvestConfig.set("sourceFile", file.getAbsolutePath())
                harvestConfig.store(FileWriter(tFile))

                zipObject = GenericDigitalObject(id)
                zipObject.addPayload(FilePayload(file, id))
                #digitalObject = imsPlugin.transform(zipObject, file)
                qStorage = QueueStorage(storagePlugin, tFile)
                qStorage.init(jsonConfig.getSystemFile())
                qStorage.addObject(zipObject)
                if deposit.noOp:
                    print "-- Testing noOp='true' --"
                else:
                    # deposit the content
                    pass
            except Exception, e:
                print "---"
                print " -- Exception - '%s'" % str(e)
                print "---"
 def __metadataFormatList(self):
     metadataFormats = JsonConfig().getMap("portal/oai-pmh/metadataFormats")
     metadataList = []
     for format in metadataFormats.keySet():
         metadataList.append(str(format))
     return metadataList
 def getMetadataFormats(self):
     conf = JsonConfig()
     formats = conf.getMap("portal/oai-pmh/metadataFormats")
     return formats
 def getUrlBase(self):
     conf = JsonConfig()
     return "%s%s/detail/" % (conf.get("urlBase"), self.__portalName)
Exemple #15
0
 def __init__(self):
     self.config = JsonConfigHelper(JsonConfig.getSystemFile())
     self.threads = self.config.getJsonList("messaging/threads")
Exemple #16
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()