how to link 3 tables in quarkus? - quarkus-panache

I m new on framework quakus. I know how to do it with SQL, but no in quakus...
Can you say me the best way/practice for have a json format with 3 tables
client-- commands-- articles
When i get a client how to have for one client, all commands ans all articles by commands.
I do that with the 2 first table
Client
#OneToMany(mappedBy = "client")
public List<ClientCmd> clientCmdList;
Its ok, but how can i link the tbale article in client (no relation beetwen client and article).

Perhaps it will serve to another beginner
I do
#OneToMany(mapped = "client")
public List<Clientcmd> clientCmdList;
in client
#OneToMany(mapped = "commande")
public List<Commandeart> commandeArtist;
in commande
When i do a
getByClient
The system retreive to me all the commands and articles for a client.
Thierry

Related

How do I fetch data using user ID on StackAPI?

Is it possible to fetch data using StackAPI using UserID instead of "fromdate" or "questionID" etc?
I want to fetch the questions and tags used by a particular user.
What's the syntax for it.
I have tried
from stackapi import StackAPI
SITE = StackAPI('stackoverflow')
SITE._api_key = None
associated_users = SITE.fetch('/users/{}/associated'.format(10286273),
pagesize=1)
associated_users
But I don't know how to print data from it.
I don't see how "associated" is relevant to your stated goal.
You are interested in queries like:
tags = SITE.fetch('/users/{}/tags'.format(10286273), site='stackoverflow')
questions = SITE.fetch('/users/{}/questions'.format(10286273), site='stackoverflow')
which retrieve details on seven posts,
mentioning tags like python and chatbot.
cf https://api.stackexchange.com/docs/questions-by-ids

infusionsoft contact field query with python

I know how to connect to Infusionsoft with Python 3 and how to process the following simple example:
#Set up the contact data we want to add
contact = {}; #blank dictionary
contact[“FirstName”] = “John”;
contact[“LastName”] = “Doe”;
contact[“Email”] = "john#doe.com";
contact[“Company”] = “ACME”;
But how do I mass update the WHOLE database? e.g. If I want to update ALL The Phone1 fields with an extra bit of code using IF statements.
Using Infusionsoft API you can only update contacts data one by one, sending a separate request per contact. Exact request depends on which type of API you use: REST or XML-RPC

How to find all documents in couchDB using ektrop library

I have gone through all the blogs available for the ektrop library and also the source code of the library.I have found that get(class obj,String id) function is available but If I use this function then only one document will be returned according to the id given.So I want to read all the changed documents present in the bucket.How Can I achieve this.Thanks in advance any help would be appreciable.
You are probably looking for the _all_docs endpoint.
ViewQuery q = new ViewQuery().allDocs().includeDocs(true);
List<Sofa> bulkLoaded = db.queryView(q, Sofa.class);
You can find more detailed information in the api
Hello all I have got the answer the question asked by me above.Here is the steps by which you can get the all documents or simply the result of _changes API is used.
Integrate the Ektorp library into your project.
Use the follwing code to get the all document.
HttpClient httpClient = new StdHttpClient.Builder()
.url("http://localhost:5984/")
.build();
CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);
CouchDbConnector db = new StdCouchDbConnector("my_database", dbInstance);
ChangesCommand.Builder builder = new ChangesCommand.Builder();
ChangesCommand changesCommand =builder.build() ;
List<DocumentChange> documentChangeList=db.changes(changesCommand);
for(int i=0;i<documentChangeList.size()-1;i++) {
System.out.println(documentChangeList.get(i).getId());
}

Add plot to sample jhipster app

A very basic question from a newbie to the wonderful jhipster ecosystem.
How do I add an additional page to my app that displays two plots based on queries on the database?
I have created the demo jhipster app that tracks authors and books in a postgres database as described in the tutorial.
I would now like to add a summary page to my sample jhipster app that displays two plots based on data retrieved from an sql query.
1) barplot of total books published per author
select author_id, count(*)
from book
group by author_id
2) line plot showing number of publications for each author per year
select author_id,extract(year from publication_date) as year,count(*)
from book
group by author_id,year
I would normally use R/Shiny and plotly to create this type of dashboard, but would really appreciate any guidance on how to achieve the same using the jhipster framework
Thanks
Iain
I see 2 tasks here. In general you first prepare 2 API endpoints to deliver the data to your frontend (keep in mind, JHI provides both server and client), and then using plotly (js) to do your plots
preparing API
you should translate your SQL query to JPA, like this:
public interface BookRepository extends JpaRepository<Book,Long> {
#Query("select b.authorId, count(b.id) from Book b group by b.authorId ")
List<Book> findAllGroupByAuthor();
#Query("select b.authorId, YEAR(b.publicationDate) as year,count(*) from Book b group by b.authorId, b.year")
List<Book> findAllGroupByAuthorAndYear();
}
then you add this to some RestControllers. Here is an example
#RestController
#RequestMapping("/api/books/query/")
public class CustomBookQueryResource {
private BookRepository bookRepository;
public CustomBookQueryResource(BookRepository bookRepository) {
this.bookRepository = bookRepository;
}
#GetMapping("/group_by_author")
public ResponseEntity<List<Book>> groupByAuthor() {
return ResponseEntity.ok(bookRepository.findAllGroupByAuthor());
}
#GetMapping("/group_by_author_and_year")
public ResponseEntity<List<Book>> groupByAuthorAndYear() {
return ResponseEntity.ok(bookRepository.findAllGroupByAuthorAndYear());
}
}
so until this point, you should already have some api endpoints, serving your data. Now you should add your custom query book service in angular
angular
.module('<yourApp>')
.factory('CustomBookQuery', CustomBookQuery);
CustomBookQuery.$inject = ['$http'];
function CustomBookQuery ($http) {
var resourceUrl = 'api/books/query/';
return {
findAllGroupByAuthor: function () {
return $http.get(resourceUrl + 'group_by_author');
},
findAllGroupByAuthorAndYear: function () {
return $http.get(resourceUrl + 'group_by_author_and_year');
}
};
}
Now you just can inject your service and pass its promises resolves to your plotly, which is already has and JS part and a Angular implementation
(I coded above code from mind, so it's not tested)
For simple cases where your query only involves one entity it might be as simple as adding a method or methods to the associated Repository interface and have Spring Data handle the query generation.
Take a look at https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods.query-creation
and if you'd prefer to supply the query
https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.at-query
You could then add an HTML page with JS to render the plot of the results of the query.
For situations that require a join over entities there’s a few possible approaches…
You could create a view in PostGresQL that would effectively make a table which is this query and then create an Entity for it (and then render them in your fav JS lib). This is my preferred option. You would need to update the liquidbase file to create the view. You would make an Entity and you would create a Spring Data repository interface (which will result in the autogeneration of a REST service etc) and then render using HTML and JS.
Alternatively, JPA entities can be queries using JPQL. That will give you a collection of objects that you can render with Angular.js or whatever your fav JS library.
http://www.oracle.com/technetwork/articles/vasiliev-jpql-087123.html
You can also use JPA to map native SQL to a PoJo (see especially the JPA 2.1 notes) and then create a REST service and render using your JS.
JPA : How to convert a native query result set to POJO class collection
http://www.thoughts-on-java.org/jpa-native-queries/

Creating record in other databases from CRM 2011

Is there any solution to create record in other DBs from the CRM 2011 records? When a record such as "cost" was created in CRM 2011, we want a record would be created in out Oracle DB. Could it be done through a plugin? Or a service should be created for this?
Could you please provide me references or solutions for this.
Any helps would be greatly appreciated.
We had a similar request from a customer a while ago. They claimed that CRM's database wasn't to be trusted and wanted to securely store a copy of the records created in - guess what - SQL Server too. (Yes, we do understand the irony. They didn't.)
The way we've resolved it was to create a plugin. However, bear in mind that simply reacting to the message of Create won't really do. You need to set up a listener for three of the CRUD operations (retrieval doesn't affect the external database so it's rather C_UD operations, then).
Here's the skeleton of the main Execute method.
public void Execute(IServiceProvider serviceProvider)
{
Context = GetContextFromProvider(serviceProvider);
Service = GetServiceFromProvider(serviceProvider);
switch (Context.MessageName)
{
case "Create": ExecuteCreate(); break;
case "Update": ExecuteUpdate(); break;
case "Delete": ExecuteDelete(); break;
}
}
After this dispatcher, you can implement the actual calls to the other database. There are three gotchas I'd like to give you head-up on.
Remember to provide a suitable value to the outer DB when CRM doesn't offer you one.
Register the plugin as asynchronous since you'll be talking to an external resource.
Consider the problem with entity references, whether to store them recursively as well.
Walk-through for plugin construction
Link to CRM SDK if you haven't got that
Information on registering the plugin
And besides that, I've got a walk-through (including code and structure) on the subject in my blog. The URL to it, you'll have to figure out yourself - I'm not going to self-promote but it's got to do with my name and WP. Google is your friend. :)
You could use a plugin to create a record in another system, although you would need to think about syncing and ensure you don't get duplicates, but it certainly can be done.
Tutorial on plugins can be found here.
You need to write a plugin that runs on Create and uses the information on the created Cost entity to create a record in your Oracle DB.
As an example:
public void Execute(IServiceProvider serviceProvider)
{
var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
//get the created entity from CRM
var theCreatedEntity = context.InputParameters["Target"] as Entity;
//build up a stored procedure call
using (OracleConnection objConn = new OracleConnection("connection string"))
{
var cmd = new OracleCommand();
cmd.Connection = objConn;
cmd.CommandText = "stored procedure name";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("param1", OracleType.Number).Value = theCreatedEntity.GetAttributeValue<int>("Attribute1");
cmd.Parameters.Add("param2", OracleType.Number).Value = theCreatedEntity.GetAttributeValue<int>("Attribute2");
//etc
cmd.ExecuteNonQuery();
}
}
That should give you enough to get going

Resources