def __messages(self):
        # Generic workflow messages
        if self.message_list is not None and len(self.message_list) > 0:
            msg = JsonSimple()
            msg.getJsonObject().put("oid", self.oid)
            message = msg.toString()
            for target in self.message_list:
                self.utils.sendMessage(target, message)

        # Camtasia integration
        emailStep = self.params.getProperty("emailStep")
        # First pass though... harvest queue
        if emailStep is None:
            emailStep = "emailOne"
            # The next message
            self.params.setProperty("emailStep", "emailTwo")
        else:
            # Second step... render queue
            if emailStep == "emailTwo":
                self.params.setProperty("emailStep", "completed")
        if emailStep is not None and emailStep != "completed":
            email = self.params.getProperty("relayEmail")
            body = self.__getEmailBody(emailStep)
            if email is not None and body is not None:
                msg = JsonSimple()
                msg.getJsonObject().put("to", email)
                msg.getJsonObject().put("body", body)
                message = msg.toString()
                self.utils.sendMessage("emailnotification", message)
예제 #2
0
 def get_image(self):
     self.type = "http://www.purl.org/anotar/ns/type/0.1#Tag"
     mediaFragType = "http://www.w3.org/TR/2009/WD-media-frags-20091217"
     result = '{"result":' + self.search_solr() + "}"
     if result:
         imageTagList = []
         imageTags = JsonSimple(result).getJsonSimpleList(["result"])
         for imageTag in imageTags:
             imageAno = JsonSimple()
             # We only want tags with locators, not basic tags
             locators = imageTag.getJsonSimpleList(["annotates", "locators"])
             if locators and not locators.isEmpty():
                 locatorValue = locators.get(0).getString(None, ["value"])
                 locatorType = locators.get(0).get(None, ["type"])
                 if locatorValue and locatorValue.find("#xywh=") > -1 and locatorType == mediaFragType:
                     _, locatorValue = locatorValue.split("#xywh=")
                     left, top, width, height = locatorValue.split(",")
                     object = imageAno.getJsonObject()
                     object.put("top", top)
                     object.put("left", left)
                     object.put("width", width)
                     object.put("height", height)
                     object.put("creator", imageTag.getString(None, ["creator", "literal"]))
                     object.put("creatorUri", imageTag.getString(None, ["creator", "uri"]))
                     object.put("id", imageTag.getString(None, ["id"]))
                     # tagCount = imageTag.getString(None, ["tagCount"])
                     object.put("text", imageTag.getString(None, ["content", "literal"]))
                     object.put("editable", "true")
                     imageTagList.append(imageAno.toString())
         result = "[" + ",".join(imageTagList) + "]"
     return result
예제 #3
0
 def __messages(self):
     if self.message_list is not None and len(self.message_list) > 0:
         msg = JsonSimple()
         msg.getJsonObject().put("oid", self.oid)
         message = msg.toString()
         for target in self.message_list:
             self.utils.sendMessage(target, message)
예제 #4
0
 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")
예제 #5
0
    def modify_json(self):
        # print "**** anotar.py : add_json() : adding json : " + json
        jsonSimple = JsonSimple(self.json)
        jsonObj = jsonSimple.getJsonObject()
        jsonObj.put("id", self.pid)
        rootUri = jsonSimple.getString(None, ["annotates", "rootUri"])
        if rootUri is not None:
            baseUrl = "http://%s:%s/" % (self.vc("request").serverName, self.vc("serverPort"))
            myUri = baseUrl + rootUri + "#" + self.pid
            jsonObj.put("uri", myUri)

        jsonObj.put("schemaVersionUri", "http://www.purl.org/anotar/schema/0.1")
        self.json = jsonSimple.toString()
예제 #6
0
    def __activate__(self, context):
        self.velocityContext = context

        oid = self.vc("formData").get("oid")
        print "--- Creating ePub for: %s ---" % oid
        try:
            self.__epubMimetypeStream = None
            self.__epubContainerStream = None
            self.__epubcss = None
            self.__orderedItem = []
            self.__itemRefDict = {}
            # get the package manifest
            object = Services.getStorage().getObject(oid)
            sourceId = object.getSourceId()
            payload = object.getPayload(sourceId)
            self.__manifest = JsonSimple(payload.open())
            payload.close()
            object.close()
            # create the epub
            self.__getDigitalItems(self.__manifest.getJsonSimpleMap("manifest"))
            self.__createEpub()
        except Exception, e:
            log.error("Failed to create epub", e)
            self.vc("response").setStatus(500)
            writer = self.vc("response").getPrintWriter("text/plain; charset=UTF-8")
            writer.println(str(e))
            writer.close()
    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()
예제 #8
0
 def parseFFmpeg(self, parent):
     if parent is not None:
         object = parent.getObject()
         if object is not None:
             payload = None
             try:
                 payload = object.getPayload("ffmpeg.info")
                 # Stream the content out to string
                 out = ByteArrayOutputStream()
                 IOUtils.copy(payload.open(), out)
                 payload.close()
                 self.__ffmpegRaw = out.toString("UTF-8")
                 out.close()
                 payload.close()
                 # And parse it
                 self.__ffmpegData = JsonSimple(self.__ffmpegRaw)
                 if self.__ffmpegData is None:
                     return False
                 else:
                     self.__ffmpegOutputs = self.__ffmpegData.getJsonSimpleMap(["outputs"])
                     return True
             except:
                 if payload is not None:
                     payload.close()
     return False
    def queryMoodle(self, usernames):
        
        self.roleManager.setActivePlugin("moodle")
        
        rolesMap = {}
        
        courseMap = {}
#        codeList = []
#        yearList = []
#        semesterList = []
#        otherList = []
                
        for username in usernames:
            roles = self.roleManager.getRoles(username)
            for role in roles:
                thisRole = JsonSimple()
                name = self.__dbGet(role)
                if name is not None:
                    thisRole.getJsonObject().put("name", name)
                    
                    psData = self.__dbGetPS(role)
                    if psData is not None:
                        thisRole.getJsonObject().put("psData", psData)
                        code, year, semester = psData.split("_")
                        if code not in self.codeList:
                            self.codeList.append(code)
                        if year not in self.yearList:
                            self.yearList.append(year)
                        if semester not in self.semesterList:
                            self.semesterList.append(semester)
                            
                        courseMap["%s %s %s" % (code, year, semester)] = {"id": role, "name": name, "psData": psData}
                    else:
                        courseName = "%s_%s" % (name, role)
                        if courseName not in self.otherList:
                            self.otherList.append(courseName)
                        courseMap[courseName] = {"id": role, "name": name, "psData": None}
                        #otherList.append({"id": role, "name": name, "psData": None})
                    rolesMap[role] = thisRole
        
        self.codeList.sort()
        self.yearList.sort()
        self.yearList.reverse()
        self.semesterList.sort()
        self.otherList.sort()
        
        return courseMap
예제 #10
0
 def __getPackageTypes(self):
     object = self.sysConfig.getObject(["portal", "packageTypes"])
     packageTypes = JsonSimple.toJavaMap(object)
     if packageTypes.isEmpty():
         defaultPackage = JsonObject()
         defaultPackage.put("jsonconfig", "packaging-config.json")
         packageTypes.put("default", JsonSimple(defaultPackage))
     return packageTypes
예제 #11
0
    def process_tags(self, result):
        tags = []
        tagsDict = {}
        # Build a dictionary of the tags
        for doc in result:
            # Get Anotar data from Solr data
            doc = JsonSimple(doc.get("jsonString"))
            # Get actual tag text
            tag = doc.getString(None, ["content", "literal"])
            # Find out if they have locators
            locs = doc.getJsonSimpleList(["annotates", "locators"]).size()
            if locs == 0:
                # Basic tags, just aggregate counts
                if tag in tagsDict:
                    # We've seen it before, just increment the counter
                    existing = tagsDict[tag]
                    count = existing.getInteger(0, ["tagCount"])
                    existing.getJsonObject().put("tagCount", str(count + 1))
                else:
                    # First time, store this object
                    doc.getJsonObject().put("tagCount", str(1))
                    tagsDict[tag] = doc
            else:
                # Tags with a locator, special case for images etc.
                tags.append(doc.toString())

        # Push all the 'basic' counts into the list to return
        for tag in tagsDict:
            tags.append(tagsDict[tag].toString())
        return "[" + ",".join(tags) + "]"
예제 #12
0
 def __activate__(self, context):
     self.roles = context["page"].authentication.get_roles_list()
     self.config = context["systemConfig"]
     workflows = JsonSimple.toJavaMap(self.config.getObject(["uploader"]))
     self.uploaders = LinkedHashMap()
     
     for workflow in workflows.keySet():
         if workflows.get(workflow).getString("", ["upload-template"]):
             for role in workflows.get(workflow).getArray(["security"]):
                 if str(role) in self.roles:
                     self.uploaders.put(workflow, workflows.get(workflow))
예제 #13
0
 def getJson(self, state = "open"):
     title = "%s (%s)" % (self.getName(), self.getCount())
     json = JsonSimple()
     jsonObj = json.getJsonObject()
     attributes = JsonObject()
     attributes.put("id", self.getId())
     attributes.put("fq", self.getFacetQuery())
     attributes.put("title", title)
     jsonObj.put("data", title)
     jsonObj.put("attributes", attributes)
     hasSubFacets = not self.getSubFacets().isEmpty()
     if hasSubFacets:
         jsonObj.put("state", state)
         subFacetList = ArrayList()
         for subFacet in self.getSubFacets():
             subFacetList.add(subFacet.getJson("closed"))
         children = JSONArray()
         children.addAll(subFacetList)
         jsonObj.put("children", children)
     return json
예제 #14
0
    def __activate__(self, context):
        self.vc = context

        responseType = "text/html; charset=UTF-8"
        responseMsg = ""
        func = self.vc("formData").get("func")
        if func == "placeName":
            try:
                placeName = self.vc("formData").get("q")
                url = "http://ws.geonames.org/searchJSON?fuzzy=0.7&q=" + placeName
                client = BasicHttpClient(url)
                get = GetMethod(url)
                statusInt = client.executeMethod(get)
                r = str(statusInt)
                json = JsonSimple(get.getResponseBodyAsString().strip())
                for geoName in json.getJsonSimpleList("geonames"):
                    responseMsg += "%s, %s|%s \n" % (geoName.getString(None, "name"), geoName.getString(None, "countryName"), geoName.getString(None, "geonameId"))
            except Exception, e:
                print "exception: ", str(e)
                r = str(e), None
            responseType = "text/plain; charset=UTF-8"
 def queryMoodle(self):
     username = self.vc("formData").get("username")
     # We are going to bypass the authentication Jython
     #   object to directly access the moodle plugin.
     self.roleManager.setActivePlugin("moodle")
     roles = self.roleManager.getRoles(username)
     if len(roles) == 0:
         self.throw_error("The given user is invalid or has no courses.")
     else:
         roleIds = []
         roleList = []
         # For each role (courseId)
         for role in roles:
             thisRole = JsonSimple()
             # Query the database for the course's name
             name = self.__dbGet(role)
             if name is not None:
                 roleIds.append("\"" + role + "\"")
                 thisRole.getJsonObject().put("name", name)
                 psData = self.__dbGetPS(role)
                 if psData is not None:
                     thisRole.getJsonObject().put("psData", psData)
                 roleList.append("\"" + role + "\" : " + thisRole.toString())
         keys = "\"keys\" : [" + ",".join(roleIds) + "]"
         data = "\"data\" : {" + ",".join(roleList) + "}"
         response = "{" + keys + "," + data + "}"
         self.writer.println(response)
         self.writer.close()
    def queryMoodleOld(self, username):
        # We are going to bypass the authentication Jython
        #   object to directly access the moodle plugin.
        
        self.roleManager.setActivePlugin("moodle")
        roles = self.roleManager.getRoles(username)

        rolesMap = {}
        # For each role (courseId)
        for role in roles:
            thisRole = JsonSimple()
            # Query the database for the course's name
            name = self.__dbGet(role)
            if name is not None:
                thisRole.getJsonObject().put("name", name)

                # Query the database for the course's Peoplesoft data
                psData = self.__dbGetPS(role)
                if psData is not None:
                    thisRole.getJsonObject().put("psData", psData)
                rolesMap[role] = thisRole
        return rolesMap
 def __activate__(self, context):
     self.request = context["request"]
     self.services = context["Services"]
     
     self.__metadata = JsonSimple()
     
     # get the oid
     uri = URLDecoder.decode(self.request.getAttribute("RequestURI"))
     matches = re.match("^(.*?)/(.*?)/(?:(.*?)/)?(.*)$", uri)
     if matches and matches.group(3):
         oid = matches.group(3)
         
     self.__object = self.services.getStorage().getObject(oid)
     
     self.__mergeData()
     
     response = context["response"]
     response.setHeader("Content-Disposition", "attachment; filename=metadata.json")
     writer = response.getPrintWriter("application/json; charset=UTF-8")
     #Content-Disposition
     writer.println(self.__metadata)
     writer.close()
 def __mergeData(self):
     
     requiredMetadata = ["format", "width", "height", "timeSpent", "size"]
     
     try:
         # ffmpeg.info data:
         ffmpegPayload = self.__object.getPayload("ffmpeg.info")
         ffmpegInfo = JsonSimple(ffmpegPayload.open())
         
         ffmpegOutput = ffmpegInfo.getJsonSimpleMap(["outputs"])
         
         map = JsonSimple()
         for key in ffmpegOutput.keySet():
             data = ffmpegOutput.get(key)
             detailMap = JsonSimple()
             for field in data.getJsonObject().keySet():
                 if field in requiredMetadata:
                     detailMap.getJsonObject().put(field, data.getString("", [field]))
             map.getJsonObject().put(key, detailMap)
         
         self.__metadata.getJsonObject().put("outputs", map)
         ffmpegPayload.close()
     except Exception, e:
         print str(e)
예제 #19
0
    def __activate__(self, context):
        request = context["request"]
        response = context["response"]
        writer = response.getPrintWriter("text/javascript; charset=UTF-8")
        result = JsonSimple()

        ## Look for the JSONP callback to use
        jsonpCallback = request.getParameter("callback")
        if jsonpCallback is None:
            jsonpCallback = request.getParameter("jsonp_callback")
            if jsonpCallback is None:
                response.setStatus(403)
                writer.println("Error: This interface only responds to JSONP")
                writer.close()
                return

        if context["page"].authentication.is_logged_in():
            result.getJsonObject().put("isAuthenticated", "true")
        else:
            result.getJsonObject().put("isAuthenticated", "false")

        writer.println(jsonpCallback + "(" + result.toString() + ")")
        writer.close()
class MetadataData:
    def __init__(self):
        pass

    def __activate__(self, context):
        self.request = context["request"]
        self.services = context["Services"]
        
        self.__metadata = JsonSimple()
        
        # get the oid
        uri = URLDecoder.decode(self.request.getAttribute("RequestURI"))
        matches = re.match("^(.*?)/(.*?)/(?:(.*?)/)?(.*)$", uri)
        if matches and matches.group(3):
            oid = matches.group(3)
            
        self.__object = self.services.getStorage().getObject(oid)
        
        self.__mergeData()
        
        response = context["response"]
        response.setHeader("Content-Disposition", "attachment; filename=metadata.json")
        writer = response.getPrintWriter("application/json; charset=UTF-8")
        #Content-Disposition
        writer.println(self.__metadata)
        writer.close()
        
    def __mergeData(self):
        
        requiredMetadata = ["format", "width", "height", "timeSpent", "size"]
        
        try:
            # ffmpeg.info data:
            ffmpegPayload = self.__object.getPayload("ffmpeg.info")
            ffmpegInfo = JsonSimple(ffmpegPayload.open())
            
            ffmpegOutput = ffmpegInfo.getJsonSimpleMap(["outputs"])
            
            map = JsonSimple()
            for key in ffmpegOutput.keySet():
                data = ffmpegOutput.get(key)
                detailMap = JsonSimple()
                for field in data.getJsonObject().keySet():
                    if field in requiredMetadata:
                        detailMap.getJsonObject().put(field, data.getString("", [field]))
                map.getJsonObject().put(key, detailMap)
            
            self.__metadata.getJsonObject().put("outputs", map)
            ffmpegPayload.close()
        except Exception, e:
            print str(e)
        
        try:
            # workflow.metadata
            workflowPayload = self.__object.getPayload("workflow.metadata")
            workflowInfo = JsonSimple(workflowPayload.open())
            
            formData = workflowInfo.getObject(["formData"])
            for key in formData.keySet():
                self.__metadata.getJsonObject().put(key, formData.get(key))
            workflowPayload.close()
        except Exception, e:
            print str(e)
예제 #21
0
                defaultName = organizations.attrib.get("default")
                organizations = organizations.findall(ns+"organization")
                organizations = [o for o in organizations if o.attrib.get("identifier")==defaultName]
                organization = organizations[0]
                title = organization.find(ns+"title").text
                rvtMap.put("title", title)
                items = organization.findall(ns+"item")
                rvtMap.put("toc", self.__getJsonItems(ns, items, resources))
            except Exception, e:
                 data["error"] = "Error - %s" % str(e)
                 print data["error"]
            object.close()
        except StorageException, e:
            data["DEBUG"] = str(e.getMessage())

        rvtManifest = JsonSimple(rvtMap)
        return rvtManifest.toString()

    def __getJsonItems(self, ns, items, resources):
        rvtNodes = ArrayList()
        for item in items:
            attr = item.attrib
            isvisible = attr.get("isvisible") == "true"
            idref = attr.get("identifierref")
            id = resources.get(idref)
            title = item.find(ns+"title").text
            if isvisible and id and id.endswith(".htm"):
                rvtNode = HashMap()
                rvtNode.put("visible", True)
                rvtNode.put("relPath", id)
                rvtNode.put("title", title)
예제 #22
0
    def __workflow(self):
        # Workflow data
        WORKFLOW_ID = "packaging"
        wfChanged = False
        workflow_security = []
        self.message_list = None
        try:
            wfPayload = self.object.getPayload("workflow.metadata")
            wfMeta = self.utils.getJsonObject(wfPayload.open())
            wfPayload.close()

            # Are we indexing because of a workflow progression?
            targetStep = wfMeta.getString(None, ["targetStep"])
            if targetStep is not None and targetStep != wfMeta.getString(None, ["step"]):
                wfChanged = True
                # Step change
                wfMeta.getJsonObject().put("step", targetStep)
                wfMeta.getJsonObject().remove("targetStep")

            # This must be a re-index then
            else:
                targetStep = wfMeta.getString(None, ["step"])

            # Security change
            stages = self.config.getJsonSimpleList(["stages"])
            for stage in stages:
                if stage.getString(None, ["name"]) == targetStep:
                    wfMeta.getJsonObject().put("label", stage.getString(None, ["label"]))
                    self.item_security = stage.getStringList(["visibility"])
                    workflow_security = stage.getStringList(["security"])
                    if wfChanged == True:
                        self.message_list = stage.getStringList(["message"])

            # Form processing
            formData = wfMeta.getObject(["formData"])
            if formData is not None:
                formData = JsonSimple(formData)
            else:
                formData = None

            coreFields = ["title", "creator", "contributor", "description", "format", "creationDate"]
            if formData is not None:
                # Core fields
                title = formData.getStringList(["title"])
                if title:
                    self.titleList = title
                creator = formData.getStringList(["creator"])
                if creator:
                    self.creatorList = creator
                contributor = formData.getStringList(["contributor"])
                if contributor:
                    self.contributorList = contributor
                description = formData.getStringList(["description"])
                if description:
                    self.descriptionList = description
                format = formData.getStringList(["format"])
                if format:
                    self.formatList = format
                creation = formData.getStringList(["creationDate"])
                if creation:
                    self.creationDate = creation
                # Non-core fields
                data = formData.getJsonObject()
                for field in data.keySet():
                    if field not in coreFields:
                        self.customFields[field] = formData.getStringList([field])

        except StorageException, e:
            # No workflow payload, time to create
            wfChanged = True
            wfMeta = JsonSimple()
            wfMetaObj = wfMeta.getJsonObject()
            wfMetaObj.put("id", WORKFLOW_ID)
            wfMetaObj.put("step", "pending")
            wfMetaObj.put("pageTitle", "Uploaded Files - Management")
            stages = self.config.getJsonSimpleList(["stages"])
            for stage in stages:
                if stage.getString(None, ["name"]) == "pending":
                    wfMetaObj.put("label", stage.getString(None, ["label"]))
                    self.item_security = stage.getStringList(["visibility"])
                    workflow_security = stage.getStringList(["security"])
                    self.message_list = stage.getStringList(["message"])
예제 #23
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()
    def __workflow(self):
        # Workflow data
        WORKFLOW_ID = "usq"
        wfChanged = False
        workflow_security = []
        try:
            wfPayload = self.object.getPayload("workflow.metadata")
            wfMeta = self.utils.getJsonObject(wfPayload.open())
            wfPayload.close()

            # Are we indexing because of a workflow progression?
            targetStep = wfMeta.getString(None, ["targetStep"])
            if targetStep is not None and targetStep != wfMeta.getString(None, ["step"]):
                wfChanged = True
                # Step change
                wfMeta.getJsonObject().put("step", targetStep)
                wfMeta.getJsonObject().remove("targetStep")

            # This must be a re-index then
            else:
                targetStep = wfMeta.getString(None, ["step"])

            # Security change
            stages = self.config.getJsonSimpleList(["stages"])
            for stage in stages:
                if stage.getString(None, ["name"]) == targetStep:
                    wfMeta.getJsonObject().put("label", stage.getString(None, ["label"]))
                    self.item_security = stage.getStringList(["visibility"])
                    workflow_security = stage.getStringList(["security"])
                    if wfChanged == True:
                        self.message_list = stage.getStringList(["message"])

            # Form processing
            formData = wfMeta.getObject(["formData"])
            if formData is not None:
                formData = JsonSimple(formData)
            else:
                formData = None
            coreFields = ["title", "creator", "contributor", "description", "format", "creationDate"]
            if formData is not None:
                # Core fields
                title = formData.getStringList(["title"])
                if title:
                    self.titleList = title
                creator = formData.getStringList(["creator"])
                if creator:
                    self.creatorList = creator
                contributor = formData.getStringList(["contributor"])
                if contributor:
                    self.contributorList = contributor
                description = formData.getStringList(["description"])
                if description:
                    self.descriptionList = description
                format = formData.getStringList(["format"])
                if format:
                    self.formatList = format
                creation = formData.getStringList(["creationDate"])
                if creation:
                    self.creationDate = creation
                # Course security - basic
                course = formData.getString(None, ["course_code"])
                if course:
                    self.item_security.add(course)
                # Course security - moodle
                moodle_courses = formData.getString(None, ["moodleSecurity"])
                if moodle_courses:
                    moodleList = moodle_courses.split(",")
                    for course in moodleList:
                        if course != "":
                            self.item_security.add(course)
                # Course facets - Peoplesoft
                psMoodle_courses = formData.getString(None, ["psMoodle"])
                if psMoodle_courses:
                    psMoodleList = psMoodle_courses.split(",")
                    for course in psMoodleList:
                        if course != "":
                            self.__indexCourse(course)

                # Non-core fields
                data = formData.getJsonObject()
                for field in data.keySet():
                    if field not in coreFields:
                        data = formData.getStringList([field])
                        if field.startswith("dc_subject."):
                            subjectField = "dc_subject"
                            if self.customFields.has_key(subjectField):
                                subjectList = self.customFields[subjectField]
                                if subjectList:
                                    for subject in subjectList:
                                        data.add(subject)
                            field = subjectField
                        self.customFields[field] = data

        except StorageException, e:
            # No workflow payload, time to create
            wfChanged = True
            wfMeta = JsonSimple()
            wfMetaObj = wfMeta.getJsonObject()
            wfMetaObj.put("id", WORKFLOW_ID)
            wfMetaObj.put("step", "pending")
            wfMetaObj.put("pageTitle", "Uploaded Files - Management")
            stages = self.config.getJsonSimpleList(["stages"])
            for stage in stages:
                if stage.getString(None, ["name"]) == "pending":
                    wfMetaObj.put("label", stage.getString(None, ["label"]))
                    self.item_security = stage.getStringList(["visibility"])
                    workflow_security = stage.getStringList(["security"])
                    self.message_list = stage.getStringList(["message"])
예제 #25
0
class HeadData:
    def __init__(self):
        pass

    def __activate__(self, context):
        self.velocityContext = context
        self.__metadata = self.vc("metadata")
        self.__urlBase = None
        self.__ffmpegRaw = None
        self.__ffmpegData = None
        self.__ffmpegOutputs = None

    # 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 getBasicFFmpegData(self, index):
        if self.__ffmpegData is not None:
            output = self.__ffmpegData.getString(None, [index])
            if output is not None:
                return output
        return ""

    def getFFmpegData(self, pid, index):
        if self.__ffmpegOutputs is not None:
            output = self.__ffmpegOutputs.get(pid).getString(None, [index])
            if output is not None:
                return output
        return ""

    # Get The MIME Type of a payload
    def getMimeType(self, pid, parent):
        if parent is not None:
            object = parent.getObject()
            if object is not None:
                try:
                    payload = object.getPayload(pid)
                    return payload.getContentType()
                except:
                    pass
        return "unknown"

    def getTranscodings(self):
        pass

    def getRawFFmpeg(self):
        return self.__ffmpegRaw

    def getSplashScreen(self, metadata, preference):
        #TODO - Proper checking that the prefered payload actually exists
        if preference is not None and preference != "":
            return preference

        # Fall back to the thumbnail if no preference was given
        thumbnail = metadata.getFirst("thumbnail")
        if thumbnail is not None:
            return thumbnail
        return ""

    def isAudio(self, mime):
        return mime.startswith("audio/")

    def isVideo(self, mime):
        return mime.startswith("video/")

    # Turn a Python boolean into a javascript boolean
    def jsBool(self, pBool):
        if pBool:
            return "true"
        else:
            return "false"

    def parseFFmpeg(self, parent):
        if parent is not None:
            payload = None
            object = parent.getObject()
            if object is not None:
                try:
                    payload = object.getPayload("ffmpeg.info")
                    # Stream the content out to string
                    out = ByteArrayOutputStream()
                    IOUtils.copy(payload.open(), out)
                    payload.close()
                    self.__ffmpegRaw = out.toString("UTF-8")
                    out.close()
                    payload.close()
                    # And parse it
                    self.__ffmpegData = JsonSimple(self.__ffmpegRaw)
                    if self.__ffmpegData is None:
                        return False
                    else:
                        self.__ffmpegOutputs = self.__ffmpegData.getJsonSimpleMap(["outputs"])
                        return True
                except:
                    if payload is not None:
                        payload.close()
        return False

    def renderUrl(self, payload):
        if self.__urlBase is None:
            portal = self.vc("portalPath")
            page = self.vc("pageName")
            id = self.__metadata.getFirst("id")
            self.__urlBase = portal + "/" + page + "/" + id + "/"
        return self.__urlBase + payload
예제 #26
0
class DetailData:
    def __init__(self):
        pass
    
    def __activate__(self, context):
        self.__ffmpegRaw = None
        self.__ffmpegData = None
        self.__ffmpegOutputs = None
        self.__urlBase = context["urlBase"]
    
    def escape(self, text):
        return StringEscapeUtils.escapeHtml(text)

    def getBasicFFmpegData(self, index):
        if self.__ffmpegData is not None:
            output = self.__ffmpegData.getString(None, [index])
            if output is not None:
                return output
        return ""

    def getFFmpegData(self, pid, index):
        if self.__ffmpegOutputs is not None:
            output = self.__ffmpegOutputs.get(pid).getString(None, [index])
            if output is not None:
                return output
        return ""

    def getFFmpegDebugging(self, pid):
        if self.__ffmpegOutputs is not None:
            output = self.__ffmpegOutputs.get(pid).getString(None, ["debugOutput"])
            return self.makeHtml(output)
        else:
            return "Not found!"

    # Get The MIME Type of a payload
    def getMimeType(self, pid, parent):
        if parent is not None:
            object = parent.getObject()
            if object is not None:
                try:
                    payload = object.getPayload(pid)
                    return payload.getContentType()
                except:
                    pass
        return "unknown"

    def getRawFFmpeg(self):
        return self.makeHtml(self.__ffmpegRaw)

    def getSplashScreen(self, metadata, preference):
        #TODO - Proper checking that the prefered payload actually exists
        if preference is not None and preference != "":
            return preference

        # Fall back to the thumbnail if no preference was given
        thumbnail = metadata.get("thumbnail")
        if thumbnail is not None:
            return thumbnail
        return ""

    def getTranscodings(self):
        if self.__ffmpegOutputs is not None:
            return self.__ffmpegOutputs.keySet()
        else:
            return ArrayList()

    def isAudio(self, mime):
        return mime.startswith("audio/")

    def isVideo(self, mime):
        return mime.startswith("video/")

    # Turn a Python boolean into a javascript boolean
    def jsBool(self, pBool):
        if pBool:
            return "true"
        else:
            return "false"

    def makeHtml(self, input):
        input = input.replace(" ", " ")
        input = input.replace("\r\n", "<br/>")
        input = input.replace("\r", "<br/>")
        input = input.replace("\n", "<br/>")
        input = input.replace("\\r\\n", "<br/>")
        input = input.replace("\\r", "<br/>")
        input = input.replace("\\n", "<br/>")
        return input

    def niceSize(self, size):
        # Cast to a number
        size = eval(size)
        # Bytes
        if (size > 1000):
            # KBytes
            size = size / 1000;
            if (size > 1000):
                # MBytes
                size = size / 1000;
                if (size > 1000):
                    # GBytes
                    size = size / 1000;
                    return str(round(size, 1)) + "Gb"
                else:
                    return str(round(size, 1)) + "Mb"
            else:
                return str(round(size, 1)) + "Kb"
        else:
            return str(size) + "b"

    def parseFFmpeg(self, parent):
        if parent is not None:
            object = parent.getObject()
            if object is not None:
                payload = None
                try:
                    payload = object.getPayload("ffmpeg.info")
                    # Stream the content out to string
                    out = ByteArrayOutputStream()
                    IOUtils.copy(payload.open(), out)
                    payload.close()
                    self.__ffmpegRaw = out.toString("UTF-8")
                    out.close()
                    payload.close()
                    # And parse it
                    self.__ffmpegData = JsonSimple(self.__ffmpegRaw)
                    if self.__ffmpegData is None:
                        return False
                    else:
                        self.__ffmpegOutputs = self.__ffmpegData.getJsonSimpleMap(["outputs"])
                        return True
                except:
                    if payload is not None:
                        payload.close()
        return False
    
    def getUrlBase(self):
        return self.__urlBase
예제 #27
0
 def getStageInfo(self, workflowId):
     uploader = self.uploaders.get(workflowId)
     config = JsonSimple(File(StrSubstitutor.replaceSystemProperties(uploader.getString("", ["json-config"]))))
     return StageInfo(config.getArray(["stages"]))