Example #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))		
Example #2
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))
	def content2IdcFile( self, name, content ):
		byteArray = Base64.decode(content)
		return IdcFile(name,byteArray)
 def content2IdcFile(self, name, content):
     byteArray = Base64.decode(content)
     return IdcFile(name, byteArray)
Example #5
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))
Example #6
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))