Hybris. Export data. Passing incorrect impexscript to Exporter - e-commerce

I'm unable to export impexscript due to error:
de.hybris.platform.impex.jalo.ImpExException: line 3 at main script: No valid line type found for {0=, 1=user_to_test_export}
This is how I'm doing export of my data using impex
String impexScript = String.format("INSERT Customer;uid[unique=true];\n" +
";%s", customer.getUid());
ImpExMedia impExMedia = ImpExManager.getInstance().createImpExMedia("test_importexport_exportscript");
impExMedia.setData(new ByteArrayInputStream(impexScript.getBytes()), "CustomerData", "text/csv");
ExportConfiguration config = new ExportConfiguration(impExMedia, ImpExManager.getExportOnlyMode());
Exporter exporter = new Exporter(config);
exporter.export();

User/Customer can be easily exported via groovy.
import de.hybris.platform.impex.jalo.*
import de.hybris.platform.impex.jalo.exp.ExportConfiguration
import de.hybris.platform.impex.jalo.exp.Exporter
import de.hybris.platform.impex.jalo.exp.Export
String impexScript = String.format("INSERT Customer;uid[unique=true]");
ImpExMedia impExMedia = ImpExManager.getInstance().createImpExMedia("test_importexport_exportscript");
impExMedia.setData(new ByteArrayInputStream(impexScript.getBytes()), "CustomerData", "text/csv");
ExportConfiguration config = new ExportConfiguration(impExMedia, ImpExManager.getExportOnlyMode());
Exporter exporter = new Exporter(config);
Export export = exporter.export();
println(export.getExportedData())
Note: run groovy in commit mode.
Sample Output:
data_export_1676281713548(data_export_1676281713548(8798244438046))
With this PK 8798244438046 ImpExMedia can be search easily in Backoffice.

Related

attach excel files to seperate email IDs from a folder

This is the below code to separate as per the requirement enter image description here
The code executes till the time of separating the files per country to excel, but the final mail attachment is not done due to this error 'com_error: (-2147352567, 'Exception occurred.', (4096, 'Microsoft Outlook', 'Cannot find this file. Verify the path and file name are correct.', None, 0, -2147024894), None)
'
import os, datetime,pathlib,schedule
import csv
from time import sleep
import win32com.client as client
import win32com.client as win32 # pip install pywin32
from pathlib import Path
import os
import pickle
import win32com
from PIL import ImageGrab
workbook_path = r'C:\Users\cb\OneDrive\final.xlsx'
#C:\Users\cb\Desktop\Automate
EXCEL_FILE_PATH = Path.cwd() / "final_new.xlsx"
ATTACHMENT_DIR = Path.cwd() / "Attachments"
ATTACHMENT_DIR.mkdir(exist_ok=True)
data = pd.read_excel(workbook_path, sheet_name="Sheet1")
data.head()
# Query/Filter the data frame and export the filtered data frame as an Excel file
for unique_value in unique_values:
data_output = data.query(f"{column_name} == #unique_value")
output_path = ATTACHMENT_DIR / f"{unique_value}.xlsx"
data_output.to_excel(output_path, sheet_name=unique_value, index=False)
#EXCEL_FILE_PATH = r'C:\Users\cb\OneDrive\paste this as people.csv'
email_list = pd.read_excel('yeah.xlsx')
email_list.tail()
outlook = win32com.client.dynamic.Dispatch("outlook.Application")#.GetNameSpace("MAPI")
for index, row in email_list.iterrows():
mail = outlook.CreateItem(0)
mail.To = row["Email ID"]
mail.CC = row["CC"]
mail.Subject = f"issue is for Country - {row['COUNTRY']}"
mail.HTMLBody = f"""
Hi {row['Contact Name']},
Please find attached the report for {row['COUNTRY']}.
This is a Test email
Best Regards,
team Auto
"""
attachment_path = str(ATTACHMENT_DIR / f"{row['COUNTRY']}.xlsx")
mail.Attachments.Add(Source=attachment_path)
mail.Display()
'Exception occurred.', (4096, 'Microsoft Outlook', 'Cannot find this file. Verify the path and file name are correct.'
It seems the problem is related to attaching a file:
attachment_path = str(ATTACHMENT_DIR / f"{row['COUNTRY']}.xlsx")
mail.Attachments.Add(Source=attachment_path)
The Attachments.Add method creates a new attachment in the Attachments collection. The source of the attachment can be a file (represented by the full file system path with a file name) or an Outlook item that constitutes the attachment. You need to make sure that such file exists on the disk. Try to copy the result file path and open the file from the shell.

How to list all assets (groupId, name, size) in a Nexus3 repository?

I know it is very simple to do in OrientDB :
select * from asset where bucket.repository_name = 'my-repo-release';
but I need to get this list remotely, not in local orientdb console, so I need a groovy script and I can't find it anywhere.
Here is the example script :
https://github.com/sonatype-nexus-community/nexus-scripting-examples
it can be found in the "nexus-script-example" project :
import org.sonatype.nexus.repository.storage.Asset
import org.sonatype.nexus.repository.storage.Query
import org.sonatype.nexus.repository.storage.StorageFacet
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
def assetListFile = new File('/tmp/assetListFile.txt')
def request = new JsonSlurper().parseText("{\"repoName\":\"maven-releases\",\"startDate\":\"2016-01-01\"}")
assert request.repoName: 'repoName parameter is required'
assert request.startDate: 'startDate parameter is required, format: yyyy-mm-dd'
log.info("Gathering Asset list for repository: ${request.repoName} as of startDate: ${request.startDate}")
def repo = repository.repositoryManager.get(request.repoName)
StorageFacet storageFacet = repo.facet(StorageFacet)
def tx = storageFacet.txSupplier().get()
try {
tx.begin()
Iterable<Asset> assets = tx.findAssets(Query.builder().where('last_updated > ').param(request.startDate).build(), [repo])
assets.each {Asset asset ->
assetListFile << asset.name() + '\n'
}
}
finally {
tx.close()
}
All properties of an asset (object org.sonatype.nexus.repository.storage.Asset) are accessible, including asset.size().

using pymongo load data to jupyter notebook and get collection list

I am trying to connect mongo DB using pymongo.
how can I get collection list?
import pymongo
from pymongo import MongoClient
import pandas as pd
import json
uri = "mongodb://XXX:abcd#dev-mongo.XXX.com/YYY?authSource=admin&authMechanism=SCRAM-SHA-1"
client = MongoClient(uri)
db = client['database_name']
collection=db['collection_name']
coll_list = db.collection_names()
import pymongo
db_connect = pymongo.MongoClient("localhost", 27017)
database_name = 'MY_DATABASE_NAME'
database = db_connect[database_name]
collection = database.list_collection_names(include_system_collections=False)
for collect in collection:
print (collect)

Bigquery Not Accepting Stackdriver's Sink Writer Identity

I've been following the documentation to export logs from Stackdriver to Bigquery. I've tried the following:
from google.cloud.logging.client import Client as lClient
from google.cloud.bigquery.client import Client as bqClient
from google.cloud.bigquery.dataset import AccessGrant
import os
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'path_to_json.json'
lc = lClient()
bqc = bqClient()
ds = bqc.dataset('working_dataset')
acc = ds.access_grants
acc.append(AccessGrant('WRITER', 'groupByEmail', 'cloud-logs#system.gserviceaccount.com')) #this is the service account that is shown in our Exports tab in GCP.
ds.access_grants = acc
ds.update()
But we get the error message:
NotFound: 404 Not found: Email cloud-logs#system.gserviceaccount.com (PUT https://www.googleapis.com/bigquery/v2/projects/[project-id]/datasets/[working-dataset])
Why won't our dataset be updated? The key being used is the one which already created the dataset itself.

Jenkins - Email notifications

I'm trying to customize email using Groovy with the email-ext plugin. As I add new features to these emails, I may introduce errors in the scripts and so receive bad mails containing the StackTrace. So, I'd like to be able to send notifications on finished jobs as my jobs may take many hours (more than 4 currently).
Is there a way to ask jenkins to send notifications on finished jobs (using Groovy or any other scripting language)?
find a solution :
import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;
import groovy.text.Template
import groovy.text.SimpleTemplateEngine
import javax.mail.*
import javax.mail.internet.*
//-------------- Job params --------------
projectName="YourProjectName";
buildNum = 10;
templateName="groovy-html-cobertura.template";
recipients="someone#somewhere.com";
sender="jenkins#somewhere.com";
smtpHost="mysmtphost";
//------------End Job params -------------
for (hudson.model.AbstractProject p : hudson.model.Hudson.instance.projects) {
if(p.name.equals(projectName)){
for (hudson.model.AbstractBuild b : p.getBuilds() ) {
if(b.getNumber() == buildNum){
println b;
b.reload();
def binding = [ "build" : b,
"project" : b.getProject(),
"rooturl" : hudson.model.Hudson.getInstance().getRootUrl(),
"it" : new hudson.plugins.emailext.plugins.content.ScriptContentBuildWrapper(b),
"spc" : " " ]
def engine = new SimpleTemplateEngine()
java.io.File file = new java.io.File(hudson.model.Hudson.getInstance ().getRootPath().getBaseName()+"/email-templates/"+templateName);
mailBody = engine.createTemplate(file.getText()).make(binding).toString();
port = 25
props = new Properties()
props.put('mail.smtp.host', smtpHost)
props.put('mail.smtp.port', port.toString())
session = Session.getDefaultInstance(props, null)
// Construct the message
msg = new MimeMessage(session)
msg.from = new InternetAddress(sender)
msg.sentDate = new Date()
msg.subject = 'Template Test'
msg.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients))
msg.setHeader('Organization', 'i-BP')
msg.setContent(mailBody,
'text/html')
// Send the message
Transport.send(msg)
}
}
}
}