How to execute complex SQL queries for below mentioned scenarios - tooltwist

XpcSecurity credentials = ud.getCredentials();
Xpc xpc = new Xpc(credentials);
xpc.start("training.getEmployees", "select");
xpc.attrib("id", "10");
XData result = xpc.run();
• What if we want get the employees whose id between 10 and 30
• What if I want to select a record based on timestamp/date
• If want to join multiple tables and query it.

It seems that you are using an XPC Plugin (XPC class file) based on the entity "training.getEmployees" in xpc.start("training.getEmployees", "select"). In this case, do the following:
XpcSecurity credentials = ud.getCredentials();
Xpc xpc = new Xpc(credentials);
xpc.start("training.getEmployees", "select");
xpc.attrib("idLower", "10");
xpc.attrib("idUpper", "30");
XData result = xpc.run();
In the Xpc plugin (probably named "GetEmployeesXpc") within the runMethod, do the following to get the data passed through the xpc code above
// Get the method passed through xpc.start
String method = elem.getAttribute("method");
// Get the attrib using the following
XData input = new XData(elem);
String upperLimit = input.getText("//idUpper");
String lowerLimit = input.getText("//idLower");
// process the query depending on how you access your data source
if (method.equals("select")) {
// put your logic here to access your data source
String query = "select * from employees where id>"+lowerLimit+" && id<"+upperLimit";"
:
:
} else {
// Do something else
}
You can do the same way with date/timestamp or joins. Just pass the data and handle it in the Xpc plugin.

My answer might be too late but for reference purposes you might try this:
XpcSecurity credentials = ud.getCredentials();
Xpc xpc = new Xpc(credentials);
xpc.start("training.getEmployees","select");
StringBuffer whereClause = new StringBuffer();
//In xpc this is the equivalent of "id between idLower and idUpper"
whereClause.append("<whereClause>\n");
whereClause.append(" <expr op='and' returnType='char'>\n");
whereClause.append(" <expr op='ge' returnType='char'>\n");
whereClause.append(" <operand>id</operand>\n");
whereClause.append(" <operand type='literal'>"+idLower+"</operand>\n");
whereClause.append(" </expr>\n");
whereClause.append(" <expr op='le' returnType='char'>\n");
whereClause.append(" <operand>id</operand>\n");
whereClause.append(" <operand type='literal'>"+idUpper+"</operand>\n");
whereClause.append(" </expr>\n"); whereClause.append(" </expr>\n");
whereClause.append("</whereClause>\n");
xpc.input(whereClause);
XData result = xpc.run();
For table joins:
I see that you're already using xpc class. In this class put this in initialize function:
mapEntity("training.getEmployees");
addLevel("employees");
mapTable("employee", "employee", null);
mapColumn("employee_id", "employeeId", "employeeId", true, false);
mapColumn("first_name", "firstName", "firstName", false, false);
mapColumn("last_name", "lastName", "lastName", false, false);
mapTable("time_track", "timeTrack", null);
mapColumn("time_track_id", "timeTrackId", "timeTrackId", true, false);
mapColumn("time_in", "timeIn", "timeIn", false, false);
mapColumn("time_out", "timeOut", "timeOut", false, false);
mapColumn("employee_id", "employeeId", "employeeId", false, false);
addJoin("employee", "employeeId", "timeTrack", "employeeId");
which is the equivalent to Select * from employee a inner join time_track b on a.employee_id = b.employee_id
And you can now apply the condition on selecting

Related

How to execute multiple QueryBuilders in a transaction using TypeORM

I have multiple queries that I created using QueryBuilder, I wanted to execute all of these queries inside a single transaction.
I read the documentation but it lacks information on how to use a QueryBuilder with transactions. I tried to create my queries using the same QueryRunner manager but I really feel like this does nothing.
I also tried to wrap my method using a #Transaction decoration but I get a socket hang up error.
This is my current attempt, I only added 2 queries in the example but I have 5 in total.
let user, membersInstituition
const connection = getConnection()
const queryRunner = connection.createQueryRunner()
console.log(queryRunner.isTransactionActive) // false
await queryRunner.startTransaction()
try {
console.log(queryRunner.isTransactionActive) // true
user = await queryRunner.manager
.createQueryBuilder(Usuarios, 'user')
.leftJoin(UltimaAtualizacaoMobile, 'att', 'user.id_usuario = att.id_usuario')
.select(['user.id_usuario as idUser, user.nome as name, att.ultima_atualizacao as ultimaAtualizacaoMobile'])
.where('user.id_usuario = :idUsuario', { idUsuario: idUsuario })
.execute()
membersInstituition = await queryRunner.manager
.createQueryBuilder(Instituicoes, 'insti')
.leftJoin(Amostras, 'am', 'am.id_instituicao = insti.id_instituicao')
.leftJoin(MembrosInstituicao, 'mi', 'mi.id_instituicao = insti.id_instituicao')
.leftJoin(Permissoes, 'perm', 'perm.id_permissao = mi.id_permissao')
.leftJoin(MembrosAmostra, 'mam', 'mam.id_amostra = am.id_instituicao AND mam.id_membro_instituicao = mi.id_membro_instituicao')
.where('am.id_amostra IN (:...idAmostras)', { idAmostras: idAmostras })
.andWhere('mi.id_usuario = :idUsuario', { idUsuario: idUsuario })
.select('mi.id_membro_instituicao as idMember, mam.id_membro_amostra as idMemberAmostra, insti.id_instituicao as idInstituition, perm.permissao as userPermission')
.orderBy('insti.id_instituicao', 'ASC')
.execute()
await queryRunner.commitTransaction()
console.log(queryRunner.isTransactionActive) // false
} catch (error) {
// Handle error
} finally {
await queryRunner.release()
}
Above code is indeed working, confirmed using TypeORM's logging, it shows the transaction starting and all the following queries before committing.
More info on how to enable Logging and to verify if your queries are under the same transaction: https://github.com/typeorm/typeorm/blob/master/docs/logging.md

Telegram API Client doesn't find group/send message

Im using TLSharp API Client for sending messages to groups, TLSharp is C#, but im trying to use it for VB.NET
C# Code:
//get user dialogs
var dialogs = (TLDialogsSlice) await client.GetUserDialogsAsync();
//find channel by title
var chat = dialogs.Chats
.Where(c => c.GetType() == typeof(TLChannel))
.Cast<TLChannel>()
.FirstOrDefault(c => c.Title == "<channel_title>");
//send message
await client.SendMessageAsync(new TLInputPeerChannel() { ChannelId = chat.Id, AccessHash = chat.AccessHash.Value }, "OUR_MESSAGE");
My VB.NET Code:
Dim dialogs = Await ((Await client.GetUserDialogsAsync()))
Dim chat = dialogs.Chats.lists.Where(Function(c) c.[GetType]() = GetType(TLChat)).Cast(Of TLChat)().FirstOrDefault(Function(c) c.title = "Group1")
Dim ChatId
Await client.SendMessageAsync(New TLInputPeerChat() {ChatId = chat.Id}, "TEST MSG")
The error i get:
Could not find public member 'GetAwaiter' in type 'TLDialogs'.'
I know it's not practical to convert it to vb.net, but I need it to integrate it into a project written in vb
I don't think that the client.GetUserDialogsAsync() method returns anything that is awaitable, so you should probably only have one Await in the line Dim dialogs = Await ((Await client.GetUserDialogsAsync())), and it may also require a cast:
Dim dialogs = DirectCast(Await client.GetUserDialogsAsync(), TLDialogsSlice)

Kettle (Pentaho PDI): Couldn't find starting point in this job

I'm manually creating a Job using Kettle from Java, but I get the error message Couldn't find starting point in this job.
KettleEnvironment.init();
JobMeta jobMeta = new JobMeta();
JobEntrySpecial start = new JobEntrySpecial("START", true, false);
start.setStart(true);
JobEntryCopy startEntry = new JobEntryCopy(start);
jobMeta.addJobEntry(startEntry);
JobEntryTrans jet1 = new JobEntryTrans("first");
Trans trans1 = jet1.getTrans();
jet1.setFileName("file.ktr");
JobEntryCopy jc1 = new JobEntryCopy(jet1);
jobMeta.addJobEntry(jc1);
jobMeta.addJobHop(new JobHopMeta(startEntry, jc1));
Job job = new Job(null, jobMeta);
job.setInteractive(true);
job.start();
I've discovered that I was missing
job.setStartJobEntryCopy(startEntry);
Class org.pentaho.di.job.JobMeta class has method findJobEntry
U can use it to look for entry point called "START
This is how it is original source of kettle-pdi
private JobMeta jobMeta;
....
// Where do we start?
jobEntryCopy startpoint;
....
if ( startJobEntryCopy == null ) {
startpoint = jobMeta.findJobEntry( JobMeta.STRING_SPECIAL_START, 0, false );
// and then
JobEntrySpecial jes = (JobEntrySpecial) startpoint.getEntry();

Is there a scoping variable for Rally like __PROJECT_SCOPING__ but for releases?

I'm trying to make a Release Summary Rally App that responds to the pages Release Scoping on the page instead of having it's own release "picker".
I'm looking to replace
{
key: "release",
type: "release",
fetch: "Notes",
query: new rally.sdk.util.Query("ObjectID = " + rally.sdk.util.Ref.getOidFromRef(releaseDropdown.getSelectedItem()))
}
with something like this:
{
key: "release",
type: "release",
fetch: "Notes",
query: new rally.sdk.util.Query("ObjectID = " + __RELEASE_SCOPING__)
}
But I can't find any evidence of such a field.
How is the release status on the page communicated to the apps on the page? How can I get a handle on what release is currently being displayed so I can manipulate my app to respond to that information?
This is totally possible. Check out this doc:
https://help.rallydev.com/apps-timebox-filtered-dashboards
Your code would then probably look something like this:
var panelContext = rally.sdk.util.Context.getPanelContext();
if(panelContext.timeboxFilter && panelContext.timeboxFilter.release) {
var release = panelContext.timeboxFilter.release; //the release object
var releaseQuery = panelContext.timeboxFilter.query; //a query to find all "like" releases in the current project scope
var queryObj = {
key: "release",
type: "release",
fetch: "Notes",
query: new rally.sdk.util.Query("ObjectID = " + release.ObjectID)
}
//do the query
//rallyDataSource.findAll(queryObj...)
}

NetSuite API - How to send tracking number back to Invoice or Sales Order?

I'm integrating a shipping solution with NetSuite via the SOAP API. I can retrieve the shipAddress via the searchRecord call. Now I need to send the tracking number, service used, and cost back into NetSuite. Hoping someone can point me in the right direction as searching hasn't turned up any answers for me. An example XML would be great.
Im pretty much pasting what I was had an external developer attempt to implement as the response but I don't understand how to setup the envelope to receive it within NS on a record...I think this is what is handling the update post to Field:
'
var a = new Array();
a['Content-Type'] = 'text/xml; charset=utf-8';
a['POST'] = '/FedexNSService/Service1.asmx HTTP/1.1';
a['Content-Length'] = data.length;
a['SOAPAction'] = 'https://wsbeta.fedex.com:443/web-services/ship/ReturnFedexLable';
nlapiLogExecution('DEBUG', 'Results', 'data : ' + data);
var response = nlapiRequestURL('http://sonatauat.adaaitsolutions.com/FedexNSService/Service1.asmx?op=ReturnFedexLable', data, a, null,null);
nlapiLogExecution('DEBUG', 'response', response);
var responseXML = nlapiStringToXML(response.getBody());
nlapiLogExecution('DEBUG', 'responseXML', responseXML);
var responseCode = response.getCode();
nlapiLogExecution('DEBUG', 'responseCode', responseCode);
var body = response.getBody();
nlapiLogExecution('DEBUG', 'body', body);
nlapiLogExecution('DEBUG', 'responseXML '+responseXML, 'responseCode : ' + responseCode);
nlapiLogExecution('DEBUG', 'body ', 'body : ' +body);
var imageurl ='';
if(responseXML != null)
{
var rawfeeds = nlapiSelectNodes(responseXML, "//Tracking");
var FileInternalId = nlapiSelectValue(rawfeeds[0], "FileInternalId");
var TrackingIds = nlapiSelectValue(rawfeeds[1], "TrackingIds");
nlapiLogExecution('DEBUG', 'FileInternalId '+FileInternalId, 'TrackingIds : '+TrackingIds );
if(FileInternalId)
{
var image=nlapiLoadFile(5985);
imageurl=image.getURL();
imageurl = ("https://system.netsuite.com"+imageurl);
nlapiLogExecution('DEBUG','image',imageurl);
}
}
return imageurl;
'
In order to update a sales order with the information via SOAP you need to create a sales order object, set the values and call either an update, or an upsert method:
[JAVA]
SalesOrder so = new SalesOrder();
so.setExternalId("externalID"); //This should correspond to the previous external ID for updates.
...set_other_fields_as_required...
WriteResponse wr = ns.getPort().update(so); //ns = _port if you're using the samples
[C#]
var so = new SalesOrder();
so.externalId = "externalID";
...set_other_fields_as_required...
var wr = Service.upsert(so);
PHP should be similar, but I haven't used the PHP toolkit so I can't say for certain.
This should help get you started.