What I have right now is I am authorizing using views. Now, I want to access all the underlying data inside a dataset.
view_dataset: '***'
view_table: '***'
table_dataset: '***'
view_string = "view={'projectId': '" + view_project + "', 'datasetId': '" + view_dataset + "', 'tableId': '" + view_table + "'}"
view_source = bigquery.Table(view_project + '.' + view_dataset + '.' + view_name)
dataset = client.get_dataset(table_project + '.' + table_dataset)
access_entries = dataset.access_entries
table_source = bigquery.Dataset(table_project + '.' + table_dataset)
access_entries.append(bigquery.AccessEntry(None, "view", view_source.reference.to_api_repr()))
table_source.access_entries = access_entries
table_source = client.update_dataset(table_source, ["access_entries"])
How will I be able to authorize view_dataset to access table_dataset programmatically?
To anyone who wants to authorize programatically, here is how I did it:
Create an entity ID for the dataset:
entity_id = {
'dataset': {
'projectId': table_project,
'datasetId': view_dataset,
},
'target_types': 'VIEWS'
}
Then, instead of view, use dataset:
access_entries.append(bigquery.AccessEntry(None, "dataset", entity_id))
I've managed to do this by reading the AccessEntry class on dataset.py of BigQuery.
If the ``entity_type`` is 'dataset', the ``entity_id`` is a ``dict``
that includes a 'dataset' field with a ``dict`` representing the dataset
and a 'target_types' field with a ``str`` value of the dataset's resource type:
{
'dataset': {
'projectId': string,
'datasetId': string,
},
'target_types: 'VIEWS'
}
I'm generating a report using fluentreports on my server and sending the base64 pdf string to the client on the callback. On the client once he/she receives the base64 string, I am required to print out this pdf string as a pdf which I am trying to accomplish using printJS. I also tried pdfMake but neither one wanted to work. If I console.log the base64 string and click on it, the pdf opens beautifully in the next tab but once I try to print it using printJS or pdfMake it opens a new tab and automatically closes it without doing anything. Is there any other way I could accomplish this? I've tried a lot of things already from reading up on other peoples' issues online and haven't gotten anywhere. Is there any library out there that can create a PDF document using a base64 pdf string so that I can use printJS to print out the document?
Function on the client that sends info to the server and receives back the pdf string:
submit: function () {
this.$Socket.emit('addrepair', {
CustomerID: this.$route.params.Customer.CustomerID,
Problem: this.problem,
BrandID: this.brand,
TypeID: this.type,
Model: this.model,
ColorID: this.color,
Warranty: this.convertbool(this.warranty),
Purchased: this.convertbool(this.purchase),
RushService: this.convertbool(this.rush),
DateReceived: this.datereceived,
UserID: this.UserID
}, (data) => {
if(data.authenticated==true)
{
//window.open(data.pdf)
//pdfMake.createPdf(this.convertDataURIToBinary(data.pdf)).print()
console.log(data.pdf)
printJS({printable: data.pdf, type: 'pdf'})
this.jobdialog=true
}
})
Function on the server that serves the pdf base64 string:
socket.on('addrepair', (data, callbackfn) => {
let query="INSERT INTO repair(CustomerID, Problem, BrandID, Model, ColorID, Warranty, Purchased, RushService, DateReceived, TypeID, UserID) VALUES (" + data.CustomerID + ", \'" + data.Problem + "\', " + data.BrandID + ", \'" + data.Model + "\', " + data.ColorID + ", " + data.Warranty + ", " + data.Purchased + ", " + data.RushService + ", \'" + data.DateReceived + "\', " + data.TypeID + ", " + data.UserID + ");"
con.query(query, function(err) {
if(err) {
throw err
}
else
{
query="SELECT RepairID, FirstName, LastName, Address, PhoneNumber, RushService, Purchased, DateReceived, Problem, Model, (SELECT Type from types WHERE repair.TypeID=types.TypeID) as Type, (SELECT Color from colors WHERE repair.ColorID=colors.ColorID) as Color, (SELECT Brand from brands WHERE repair.BrandID=brands.BrandID) as Brand, Warranty from repair INNER JOIN customer ON repair.CustomerID=customer.CustomerID WHERE repair.RepairID=(SELECT LAST_INSERT_ID())"
con.query(query, function(err, rows) {
if(err) {
throw err
}
else
{
var options = {
data: rows
}
//var myreport = new Report("buffer", options)
var myreport=new Report.Report("buffer", options)
.data(rows)
.pageHeader(repairheaderFunction)
.detail(repairdetailFunction)
.pageFooter(repairfooterFunction)
myreport.render(function (err, data) {
callbackfn({authenticated: true, pdf: 'data:application/pdf;base64,' + data.toString('base64')})
})
//callbackfn({authenticated: true, data: rows})
}
})
}
})
})
var repairheaderFunction = function(Report, data) {
};
var repairdetailFunction = function(Report, data) {
Report.print("#" + data.RepairID, {fontSize: 22, bold: true, underline:true, align: "center"});
Report.newLine(2);
Report.print('First Name: ' + data.FirstName + "\n")
Report.print('Last Name: ' + data.LastName + "\n")
Report.print('Address: ' + data.Address + "\n")
Report.print('Phone Number: ' + data.PhoneNumber + "\n")
Report.print('Brand: ' + data.Brand + "\n")
Report.print('Model: ' + data.Model + "\n")
Report.print('Color: ' + data.Color + "\n")
Report.print('Problem: ' + data.Problem + "\n")
Report.print('Date Received: ' + data.DateReceived.slice(15) + "\n")
/*.text('Last Name: [LastName]\n')
.text('Address: [Address]\n')
.text('Phone Number: [PhoneNumber]\n')
.text('Brand: [Brand]\n')
.text('Model: [Model]\n')
.text('Color: [Color]\n')
.text('Problem: [Problem]\n')
.text('Date Received: [DateReceived]', 1.75, 0, 1, 0.25, {
pattern: 'M/D/YY'
})*/
};
var repairfooterFunction = function(Report) {
Report.line(Report.currentX(), Report.maxY()-18, Report.maxX(), Report.maxY()-18);
Report.pageNumber({text: "Page {0} of {1}", footer: true, align: "right"});
Report.print("Printed: "+(new Date().toLocaleDateString()), {y: Report.maxY()-14, align: "left"});
};
Print.js is now supporting base64 PDF print.
Try this:
printJS({
printable: your_base64_data_string,
type: 'pdf'
base64: true
})
The documentation has been updated with an example printing a base64 PDF document.
http://printjs.crabbly.com#pdf
Was able to get this to work after a lot of playing around with the code and thinking of possible solutions. Generates the iframe, pulls up the print dialog using the autoprint property of the report and then deletes the iframe once the focus is on the document again using the 'mousemove' event
The code is below:
printIframe: function(url) {
var proxyIframe = document.createElement('iframe');
var body = document.getElementsByTagName('body')[0];
body.appendChild(proxyIframe);
proxyIframe.style.width = '100%';
proxyIframe.style.height = '100%';
proxyIframe.id='iframe'
proxyIframe.style.display = 'none';
var contentWindow = proxyIframe.contentWindow;
contentWindow.document.open();
// Set dimensions according to your needs.
// You may need to calculate the dynamically after the content has loaded
contentWindow.document.write('<iframe src="' + url + '" width="1000" height="1800" frameborder="0" marginheight="0" marginwidth="0">');
contentWindow.document.close();
var x=0
var func=function (event) {
if(x===0)
{
body.removeChild(proxyIframe)
++x
}
else
{
document.removeEventListener('mousemove', func)
}
}
contentWindow.document.body.onload=() => {
contentWindow.document.body.focus()
setTimeout(()=>{
document.addEventListener('mousemove', func)
}, 5000)
}
},
I have a form which sends by post method registration.jsp file, first saved in the database and then must open a "command.sh":
<%# page import ="java.sql.*,java.io.*"%>
<%
String user = request.getParameter("uname");
String pwd = request.getParameter("pass");
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jsp",
"root", "");
Statement st = con.createStatement();
int i = st.executeUpdate("insert into members(uname, pass, regdate) values ('" + user + "','" + pwd + "', CURDATE())");
Process p=Runtime.getRuntime().exec("./command.sh "+user+pwd);
if (i > 0) {
response.sendRedirect("welcome.jsp");
} else {
response.sendRedirect("index.jsp");
}
I am using the following code, but when I run it I get an error:
Error
Files
Yes save in the database.
I also do not know how to create a Unix user by receiving the data I sent from the jsp.
Please Help Me
Try using ServletContext.getRealPath(), for example:
String fullPath = application.getRealPath("command.sh");
String[] cmd = { fullPath + " " + user + pwd };
Process p = Runtime.getRuntime().exec(cmd);
This doesn't work. Here cl is xmpp-client object of who wants to leave from group.
cl.on('online', function (userData) {
var userJid = userData.jid.user + '#' + userData.jid.domain + "/" + userData.jid.resource,
roomJid = params.typeId + params.service + userData.jid.domain + '/' + params.userName;
pres = new xmpp.Element('presence', {
from : userJid,
to : roomJid, //54d213e000e9e50c4e8e5a2b#conference.domain/nickName
type : 'unavailable',
xmlns : 'jabber:client'
});
status = cl.send(pres);
});
I'm using this npm-module: https://github.com/vpulim/node-soap
The webservice I want to consume is only using SOAP 1.2 and returns a server error on using any other SOAP version.
Has someone experienced the same problem and knows how to set the SOAP version?
With latest version of https://github.com/vpulim/node-soap, there is option to set SOAP 1.2 header
var options = {
forceSoap12Headers: true
};
soap.createClient(url,options, function (err, client) {
//Your soap call here
});
IMO, I dont think we should modify the lib, not good for upgrade
I have solved the issue changing as NicolasZ said, my current soap/lib/client.js is:
line 187:
xml = "<soap:Envelope " +
//"xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
"xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" " +
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
encoding +
this.wsdl.xmlnsInEnvelope + '>' +
((self.soapHeaders || self.security) ?
(
"<soap:Header>" +
(self.soapHeaders ? self.soapHeaders.join("\n") : "") +
(self.security ? self.security.toXML() : "") +
"</soap:Header>"
)
:
''
) +
"<soap:Body" +
(self.bodyAttributes ? self.bodyAttributes.join(' ') : '') +
">" +
message +
"</soap:Body>" +
"</soap:Envelope>";
You could go into soap\lib\client.js to the line 186 and modify the envelope syntaxis so it is compliant with soap 1.2:
//modify this with the envelope used by soap1.2:
xml = "<soap:Envelope " +
"xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
'xmlns:xsd="http://www.w3.org/2001/XMLSchema"' +
'xmlns:ns2="http://xml.apache.org/xml-soap"' +
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
encoding +
this.wsdl.xmlnsInEnvelope + '>' +
//until here
((self.soapHeaders || self.security) ?
(
"<soap:Header>" +
(self.soapHeaders ? self.soapHeaders.join("\n") : "") +
(self.security ? self.security.toXML() : "") +
"</soap:Header>"
)
:
''
) +
"<soap:Body" +
(self.bodyAttributes ? self.bodyAttributes.join(' ') : '') +
">" +
message +
"</soap:Body>" +
"</soap:Envelope>";