示例#1
0
	def enhance( self, contentDescriptor, content, connector_url, cq_user, cq_password, asset_doWebDAV, asset_skeleton, asset_transformationRules, asset_drive, asset_filenameAttr, asset_pathAttr ):
		
		# Validate Parameters
		if not self.validInputs(connector_url,cq_user,cq_password,asset_drive,asset_filenameAttr,asset_pathAttr,"page_query","page_querylib","ia_path","ia_cacheCols"): return
		
		if asset_doWebDAV:
			# Save Asset to WebDAV Drive
			drive = asset_drive[0]
			path = re.sub("/content/dam/","/var/dam/",contentDescriptor.metadata[asset_pathAttr])
			filename = contentDescriptor.metadata[asset_filenameAttr]
			filepath = "%s:%s/%s" % (drive,path,filename)
			
			if not exists("%s:%s" % (drive,path)): makedirs("%s:%s" % (drive,path))
			file = BufferedOutputStream(FileOutputStream(filepath))
			data = Base64.decode(content.contentData)
			try: 
				file.write(data, 0, len(data))
				file.close()
				contentDescriptor.metadata["Load.Status"] = "SUCCESS"
			except:
				logger.error("! [WebDAV] Could not write %s to file system" % (contentDescriptor.url))
				file.close()
				contentDescriptor.metadata["Load.Status"] = "FAILURE"
				contentDescriptor.metadata["Load.Failure Reason"] = "! [WebDAV] Could not deposit file on file system"
				return
			
		# Build & Send Asset Metadata Payload if required
		if asset_skeleton and asset_transformationRules:
			
			# Build Payload
			payload = self.buildAssetPayload(asset_skeleton,asset_transformationRules,content,contentDescriptor)
			
			# HTTP Connection Details
			client = HttpClient()
			base64EncodedCredentials = Base64.encodeString("%s:%s" % (cq_user,cq_password))
			header = Header("Authorization", "Basic %s" % (base64EncodedCredentials))
			
			# Send Metadata Payload
			post = PostMethod(connector_url)
			post.addRequestHeader(header)
			get = GetMethod(connector_url)
			get.addRequestHeader(header)
			[loadStatus, failureReason] = self.sendPayload(client,get,post,payload,contentDescriptor.url)
			contentDescriptor.metadata["Load.Status"] = loadStatus
			if loadStatus == "SUCCESS":
				contentDescriptor.metadata["Load.Failure Reason"] = ''
			else:
				contentDescriptor.metadata["Load.Failure Reason"] = "Metadata: "+failureReason
				logger.error("! [METADATA] %s" % (failureReason))		
示例#2
0
	def getCheckInValues( self, cd, content, oracle, metadataList ):
			
		checkInMap = {}
		# Manditory Metadata
		checkInMap["dDocName"]= cd.metadata["Target.dDocName"]
		checkInMap["dDocTitle"]= cd.metadata["Target.dDocTitle"]
		checkInMap["dDocType"]= cd.metadata["Target.dDocType"]
		checkInMap["dDocAuthor"]= cd.metadata["Target.dDocAuthor"]
		checkInMap["dSecurityGroup"]= cd.metadata["Target.dSecurityGroup"]
		checkInMap["dDocAccount"]= cd.metadata["Target.dDocAccount"]
	
		# Custom Metadata
		mdMap = HashMap()
		map(lambda x: mdMap.put(x,cd.metadata["Target.%s" % x]), metadataList)
		checkInMap["customDocMetadata"] = oracle.map2IdcPropList(mdMap)
	
		# File
		filename = cd.metadata["Target.Filename"]
		if cd.metadata["Identify Metadata.Content-Type"] == "application/xhtml+xml":
			fileContents = Base64.encodeString(content.contentData)
		else:
			fileContents = content.contentData
		checkInMap["primaryFile"] = oracle.content2IdcFile(filename,fileContents)
		checkInMap["alternateFile"] = None
		
		# Extras
		propMap = {}
		# ... add more?
		checkInMap["extraProps"] = oracle.map2IdcPropList(propMap)
		
		return checkInMap
示例#3
0
    def getCheckInValues(self, cd, content, oracle, metadataList):

        checkInMap = {}
        # Manditory Metadata
        checkInMap["dDocName"] = cd.metadata["Target.dDocName"]
        checkInMap["dDocTitle"] = cd.metadata["Target.dDocTitle"]
        checkInMap["dDocType"] = cd.metadata["Target.dDocType"]
        checkInMap["dDocAuthor"] = cd.metadata["Target.dDocAuthor"]
        checkInMap["dSecurityGroup"] = cd.metadata["Target.dSecurityGroup"]
        checkInMap["dDocAccount"] = cd.metadata["Target.dDocAccount"]

        # Custom Metadata
        mdMap = HashMap()
        map(lambda x: mdMap.put(x, cd.metadata["Target.%s" % x]), metadataList)
        checkInMap["customDocMetadata"] = oracle.map2IdcPropList(mdMap)

        # File
        filename = cd.metadata["Target.Filename"]
        if cd.metadata[
                "Identify Metadata.Content-Type"] == "application/xhtml+xml":
            fileContents = Base64.encodeString(content.contentData)
        else:
            fileContents = content.contentData
        checkInMap["primaryFile"] = oracle.content2IdcFile(
            filename, fileContents)
        checkInMap["alternateFile"] = None

        # Extras
        propMap = {}
        # ... add more?
        checkInMap["extraProps"] = oracle.map2IdcPropList(propMap)

        return checkInMap
示例#4
0
	def enhancePages( self, project, connector_url, cq_user, cq_password, page_query, page_queryLib ):	
				
		# Validate Parameters
		if not self.validInputs(connector_url,cq_user,cq_password,"asset_drive","asset_filenameAttr","asset_pathAttr",page_query,page_queryLib,"ia_path","ia_cacheCols"): return
		
		# HTTP Connection Details
		client = HttpClient()
		base64EncodedCredentials = Base64.encodeString("%s:%s" % (cq_user,cq_password))
		header = Header("Authorization", "Basic %s" % (base64EncodedCredentials))
		
		# Cycle through contentdescriptors specified by scope query
		query = queryLibrarianService.findQueryByName(page_queryLib, page_query)
		params = HashMap()
		params.put('projectId',project.id)
		res = queryLibrarianService.executeQuery(query, params)
		
		# Get cd
		for r in res:
			cd = r[0]
			post = PostMethod(connector_url)
			post.addRequestHeader(header)
			get = GetMethod(connector_url)
			get.addRequestHeader(header)
			try:
				payload = cd.getContent()[0].getContentData().encode("utf-8")
				[loadStatus, failureReason] = self.sendPayload(client,get,post,payload,cd.url)
				cd.metadata["Load.Status"] = loadStatus
				cd.metadata["Load.Failure Reason"] = failureReason
				if loadStatus != "SUCCESS":
					logger.error("url: %s, reason: %s" % (cd.url, failureReason))
			except:
				cd.metadata["Load.Status"] = "FAILURE"
				cd.metadata["Load.Failure Reason"] = "Null content"
				logger.error("url: %s, reason: %s" % (cd.url, failureReason))
示例#5
0
	def enhanceIA( self, connector_url, cq_user, cq_password, ia_path, ia_cacheCols ):
		
		# Validate Parameters
		if not self.validInputs(connector_url,cq_user,cq_password,"asset_drive","asset_filenameAttr","asset_pathAttr","page_query","page_queryLib",ia_path,ia_cacheCols): return
		
		# HTTP Connection Details
		client = HttpClient()
		base64EncodedCredentials = Base64.encodeString("%s:%s" % (cq_user,cq_password))
		header = Header("Authorization", "Basic %s" % (base64EncodedCredentials))
		
		# IA Build
		cached_IA = self.cacheIA(ia_path,ia_cacheCols)
		for placeholder in cached_IA:
			
			post = PostMethod(connector_url)
			post.addRequestHeader(header)
			get = GetMethod(connector_url)
			get.addRequestHeader(header)
			
			# Prep Payload
			path = placeholder["Path"]
			filename = placeholder["Filename"]
			template_path = placeholder["Template Path"]
			label = placeholder["Label"]
			
			# Send Payload
			payload = '<page path="%s" filename="%s" template_path="%s" label="%s"><node path="jcr:content" type="nt:unstructured"><prop name="jcr:title" type="String">%s</prop></node></page>' % (path,filename,template_path,label,label)
			[loadStatus, failureReason] = self.sendPayload(client,get,post,payload,path+filename)
			if loadStatus != "SUCCESS":
				logger.error("url: %s, reason: %s" % (placeholder["URL"], failureReason))
示例#6
0
    def enhancePages(self, project, connector_url, cq_user, cq_password,
                     page_query, page_queryLib):

        # Validate Parameters
        if not self.validInputs(connector_url, cq_user, cq_password,
                                "asset_drive", "asset_filenameAttr",
                                "asset_pathAttr", page_query, page_queryLib,
                                "ia_path", "ia_cacheCols"):
            return

        # HTTP Connection Details
        client = HttpClient()
        base64EncodedCredentials = Base64.encodeString("%s:%s" %
                                                       (cq_user, cq_password))
        header = Header("Authorization",
                        "Basic %s" % (base64EncodedCredentials))

        # Cycle through contentdescriptors specified by scope query
        query = queryLibrarianService.findQueryByName(page_queryLib,
                                                      page_query)
        params = HashMap()
        params.put('projectId', project.id)
        res = queryLibrarianService.executeQuery(query, params)

        # Get cd
        for r in res:
            cd = r[0]
            post = PostMethod(connector_url)
            post.addRequestHeader(header)
            get = GetMethod(connector_url)
            get.addRequestHeader(header)
            try:
                payload = cd.getContent()[0].getContentData().encode("utf-8")
                [loadStatus,
                 failureReason] = self.sendPayload(client, get, post, payload,
                                                   cd.url)
                cd.metadata["Load.Status"] = loadStatus
                cd.metadata["Load.Failure Reason"] = failureReason
                if loadStatus != "SUCCESS":
                    logger.error("url: %s, reason: %s" %
                                 (cd.url, failureReason))
            except:
                cd.metadata["Load.Status"] = "FAILURE"
                cd.metadata["Load.Failure Reason"] = "Null content"
                logger.error("url: %s, reason: %s" % (cd.url, failureReason))
示例#7
0
	def enhance( self, contentDescriptor, content, vamosa_webservice, db, verbose ):
		
		sitecore = VamosaService()
		sitecore.init_service(vamosa_webservice)
		if db == None: db = "master"
		
		# LOAD ASSET
		if contentDescriptor.metadata["Identify Metadata.Content-Type"] != "application/xhtml+xml":
			
			# Use Web Service
			path = contentDescriptor.metadata["Target.Path"]
			filename = contentDescriptor.metadata["Target.Name"]
			name = filename.split('.')[0]
			extension = filename.split('.')[-1]
			dataString = content.contentData
			dataBytes = Base64.decode(dataString)
			id = sitecore.uploadAsset(path,name,extension,dataBytes,db)
			logger.info("Asset loaded with ID: %s" % (id))
			contentDescriptor.metadata["Load.ID"] = id
			
		# LOAD CONTENT
		else:
			if Project.getProjectAsSubProject(contentDescriptor.project).getSubprojectType() == "PLACEHOLDER":
				# Create Placeholder
				parent_path = contentDescriptor.metadata["Target.Path"]
				template_path = contentDescriptor.metadata["Target.Template Path"]
				name = contentDescriptor.metadata["Target.Name"]
				id = sitecore.createItem(parent_path,template_path,name,db,[],[])
				logger.info("Placeholder Loaded with ID: %s" % (id))
				contentDescriptor.metadata["Load.ID"] = id
				contentDescriptor.metadata["Load.Type"] = "PLACEHOLDER"
				if verbose: logger.info(sitecore.getItemFields("%s/%s" % (parent_path,name),db))
			else:
				# Prepare fields
				dom = content.contentDOM
				fields = map(lambda x: x.attributeValue("name"), dom.selectNodes("//item/*"))
				values = map(lambda x: x.getText(), dom.selectNodes("//item/*"))
				
				# Create Object
				parent_path = contentDescriptor.metadata["Target.Path"]
				name = contentDescriptor.metadata["Target.Name"]
				sitecore.updateFields(db,"%s/%s" % (parent_path,name),fields,values)
				logger.info("Content Updated with ID: %s" % (contentDescriptor.metadata["Load.ID"]))
				contentDescriptor.metadata["Load.Type"] = "CONTENT"
				if verbose: logger.info(sitecore.getItemFields("%s/%s" % (parent_path,name),db))
示例#8
0
    def enhanceIA(self, connector_url, cq_user, cq_password, ia_path,
                  ia_cacheCols):

        # Validate Parameters
        if not self.validInputs(connector_url, cq_user, cq_password,
                                "asset_drive", "asset_filenameAttr",
                                "asset_pathAttr", "page_query",
                                "page_queryLib", ia_path, ia_cacheCols):
            return

        # HTTP Connection Details
        client = HttpClient()
        base64EncodedCredentials = Base64.encodeString("%s:%s" %
                                                       (cq_user, cq_password))
        header = Header("Authorization",
                        "Basic %s" % (base64EncodedCredentials))

        # IA Build
        cached_IA = self.cacheIA(ia_path, ia_cacheCols)
        for placeholder in cached_IA:

            post = PostMethod(connector_url)
            post.addRequestHeader(header)
            get = GetMethod(connector_url)
            get.addRequestHeader(header)

            # Prep Payload
            path = placeholder["Path"]
            filename = placeholder["Filename"]
            template_path = placeholder["Template Path"]
            label = placeholder["Label"]

            # Send Payload
            payload = '<page path="%s" filename="%s" template_path="%s" label="%s"><node path="jcr:content" type="nt:unstructured"><prop name="jcr:title" type="String">%s</prop></node></page>' % (
                path, filename, template_path, label, label)
            [loadStatus,
             failureReason] = self.sendPayload(client, get, post, payload,
                                               path + filename)
            if loadStatus != "SUCCESS":
                logger.error("url: %s, reason: %s" %
                             (placeholder["URL"], failureReason))
示例#9
0
	def getGetFile( self, result ):
		fileBytes = result.getDownloadFile()
		return Base64.encodeBytes(fileBytes)
示例#10
0
	def content2IdcFile( self, name, content ):
		byteArray = Base64.decode(content)
		return IdcFile(name,byteArray)
示例#11
0
 def getGetFile(self, result):
     fileBytes = result.getDownloadFile()
     return Base64.encodeBytes(fileBytes)
示例#12
0
 def content2IdcFile(self, name, content):
     byteArray = Base64.decode(content)
     return IdcFile(name, byteArray)
示例#13
0
    def enhance(self, contentDescriptor, content, vamosa_webservice, db,
                verbose):

        sitecore = VamosaService()
        sitecore.init_service(vamosa_webservice)
        if db == None: db = "master"

        # LOAD ASSET
        if contentDescriptor.metadata[
                "Identify Metadata.Content-Type"] != "application/xhtml+xml":

            # Use Web Service
            path = contentDescriptor.metadata["Target.Path"]
            filename = contentDescriptor.metadata["Target.Name"]
            name = filename.split('.')[0]
            extension = filename.split('.')[-1]
            dataString = content.contentData
            dataBytes = Base64.decode(dataString)
            id = sitecore.uploadAsset(path, name, extension, dataBytes, db)
            logger.info("Asset loaded with ID: %s" % (id))
            contentDescriptor.metadata["Load.ID"] = id

        # LOAD CONTENT
        else:
            if Project.getProjectAsSubProject(
                    contentDescriptor.project).getSubprojectType(
                    ) == "PLACEHOLDER":
                # Create Placeholder
                parent_path = contentDescriptor.metadata["Target.Path"]
                template_path = contentDescriptor.metadata[
                    "Target.Template Path"]
                name = contentDescriptor.metadata["Target.Name"]
                id = sitecore.createItem(parent_path, template_path, name, db,
                                         [], [])
                logger.info("Placeholder Loaded with ID: %s" % (id))
                contentDescriptor.metadata["Load.ID"] = id
                contentDescriptor.metadata["Load.Type"] = "PLACEHOLDER"
                if verbose:
                    logger.info(
                        sitecore.getItemFields("%s/%s" % (parent_path, name),
                                               db))
            else:
                # Prepare fields
                dom = content.contentDOM
                fields = map(lambda x: x.attributeValue("name"),
                             dom.selectNodes("//item/*"))
                values = map(lambda x: x.getText(),
                             dom.selectNodes("//item/*"))

                # Create Object
                parent_path = contentDescriptor.metadata["Target.Path"]
                name = contentDescriptor.metadata["Target.Name"]
                sitecore.updateFields(db, "%s/%s" % (parent_path, name),
                                      fields, values)
                logger.info("Content Updated with ID: %s" %
                            (contentDescriptor.metadata["Load.ID"]))
                contentDescriptor.metadata["Load.Type"] = "CONTENT"
                if verbose:
                    logger.info(
                        sitecore.getItemFields("%s/%s" % (parent_path, name),
                                               db))
示例#14
0
    def enhance(self, contentDescriptor, content, connector_url, cq_user,
                cq_password, asset_doWebDAV, asset_skeleton,
                asset_transformationRules, asset_drive, asset_filenameAttr,
                asset_pathAttr):

        # Validate Parameters
        if not self.validInputs(connector_url, cq_user, cq_password,
                                asset_drive, asset_filenameAttr,
                                asset_pathAttr, "page_query", "page_querylib",
                                "ia_path", "ia_cacheCols"):
            return

        if asset_doWebDAV:
            # Save Asset to WebDAV Drive
            drive = asset_drive[0]
            path = re.sub("/content/dam/", "/var/dam/",
                          contentDescriptor.metadata[asset_pathAttr])
            filename = contentDescriptor.metadata[asset_filenameAttr]
            filepath = "%s:%s/%s" % (drive, path, filename)

            if not exists("%s:%s" % (drive, path)):
                makedirs("%s:%s" % (drive, path))
            file = BufferedOutputStream(FileOutputStream(filepath))
            data = Base64.decode(content.contentData)
            try:
                file.write(data, 0, len(data))
                file.close()
                contentDescriptor.metadata["Load.Status"] = "SUCCESS"
            except:
                logger.error("! [WebDAV] Could not write %s to file system" %
                             (contentDescriptor.url))
                file.close()
                contentDescriptor.metadata["Load.Status"] = "FAILURE"
                contentDescriptor.metadata[
                    "Load.Failure Reason"] = "! [WebDAV] Could not deposit file on file system"
                return

        # Build & Send Asset Metadata Payload if required
        if asset_skeleton and asset_transformationRules:

            # Build Payload
            payload = self.buildAssetPayload(asset_skeleton,
                                             asset_transformationRules,
                                             content, contentDescriptor)

            # HTTP Connection Details
            client = HttpClient()
            base64EncodedCredentials = Base64.encodeString(
                "%s:%s" % (cq_user, cq_password))
            header = Header("Authorization",
                            "Basic %s" % (base64EncodedCredentials))

            # Send Metadata Payload
            post = PostMethod(connector_url)
            post.addRequestHeader(header)
            get = GetMethod(connector_url)
            get.addRequestHeader(header)
            [loadStatus,
             failureReason] = self.sendPayload(client, get, post, payload,
                                               contentDescriptor.url)
            contentDescriptor.metadata["Load.Status"] = loadStatus
            if loadStatus == "SUCCESS":
                contentDescriptor.metadata["Load.Failure Reason"] = ''
            else:
                contentDescriptor.metadata[
                    "Load.Failure Reason"] = "Metadata: " + failureReason
                logger.error("! [METADATA] %s" % (failureReason))