QBO3 Summary statement missing foreign key details - configuration

I have created a new QBO3 module, MySubject, including foreign keys to the Organization table for InvestorID and ServicerID.
When I call MySubject\Summary, I don't see the Organization records for the investor or servicer.
However, calling QBO3's core Loan\Summary does produce such foreign key output:
<LoanCollection>
<LoanItem>...</LoanItem>
<OrganizationItem>{Investor info is here}</OrganizationItem>
<OrganizationItem>{Servicer info is here}</OrganizationItem>
...
</LoanCollection>
What do I need to do to ensure the Organization nodes are emitted in the MySubject\Summary output?

Add the names of your foreign key columns to a ForeignKeys parameter of your MySubject\Summary statement.
Out of the box, the Loan\Summary statement includes:
ForeignKeys = " ServicerID AgencyID InvestorID AssignedOrganizationID AssignedPersonID "
Note the preceding and trailing spaces on this value!
A copy of the documentation is below.
It is possible for the Summary statement to return too much information. By default, all ancestors and children are included in Summary results. If an object has hundreds or thousands of children, and those children are rarely needed in the Summary statement, they can be excluded. To tailor summary results, create a Summary Statement from Design > Configuration > Installed Modules > {Module} > Statements, and add one or more of the following parameters:
AncestorDepth (int): determines how many generations of ancestors
will be returned. Enter 0 to return no ancestors, 1 to return the
immediate parent, etc.
DescendantDepth (int): determines how many generations of descendants
will be returned. Enter 0 for no descendants, 1 for children, 2 for
grandchildren, etc.
Ancestors (string): a space-delimited string of ancestors to be
included (if NULL, all ancestors will be included)
Descendants (string): a space-delimited string of descendants to be
included (if NULL, all descendants will be included)
ForeignKeys (string): a space-delimited string of foreign key columns
to include in the output (if NULL, no foreign keys will be included)
MaxCount (int): determines the maximum number of child records of a
given table and generation to include

Related

Database Schema nestest Tasklist

I am working on a database for an ordered tasklist. As some of the tasks are repetitive I need a "taskList" that can again consist of tasks and other task lists.
Find example here
In the above example TaskList 1 consists of [TaskList2, Task5, Task 6, TaskList3], where TaskList2 consists of [Task1, Task2, Task3, Task4] and so on.
My main question is:
What's the best way to set up a Database-Schema to handle this nested polymorphism? (I am using Laravels ORM)
Conceptually, your problem is solved by considering a tasklist as an ordered aggregation of tasklist items, which are tasks or (other) tasklists, as described by the following class diagram:
A DB schema that implements this conceptual model is provided by the following table schemas (where PK/FK = primary/foreign keys, and ? = optional):
tasklists( PK id, name)
tasks( PK id, name)
tasklistitems(
FK tasklist REF tasklists,
seq_no,
FK taskitem? REF tasks,
FK tasklistitem? REF tasklists
)
such that each row of tasklistitems is related to a tasklist via its first (foreign key) attribute and references either a task or a tasklist via the corresponding optional foreign key attributes taskitem and tasklistitem.
Notice that the sequence number attribute of tasklist items implements their ordering.

Making a Tree like Structure in Json With Recursion

I'm struggling to get my head around this one, i've had a few attempts and failed miserably.
Basically I have a list of Employees in a database, each with an ID. A Employee can have a parent Employee (Refer as Manager).
I need to output the structure in some sort of tree in json format like shown in this URL
https://raw.githubusercontent.com/bumbeishvili/Assets/master/Projects/D3/Organization%20Chart/redesignedChartLongData.json
Here is a very basic structure example
The JSON can have a structure like this, containing an array of employees:
{
"employees":[
{
"id": 1764,
"name": "Maaz",
... //other fields... this employee has no parent field or
// "parent" : 0 (invalid value)
},
{
"id": 1765,
"parent": 1764,
//other fields... this employee has Maaz as parent
}
]
}
"parent" can simply be an optional field of the employee, containing theid of the parent employee.
If the json had a recursion (i.e. "parent": { /*...*/ }) this would create several issues such as:
Will the parent employee only be stored as second level, or also appear in the list as top level? This adds redundancy or alternatively, search complexity. because if 1764 only appears as child of 1765, you have to potentially recursively trasverse the whole list tree in order to find any employee.
What is the maximum depth of the recursion? With trasversal problems.
Inconsistency or circular relations, leading to loops. If A is parent of B and B is parent of A. Or if there is redundancy but upon deletion the employee does not get wiped anywhere.
More complex operations: if you have a chain of 5 parent-child employees and remove the top one, what do you do with the rest? You would have to define a policy. And adjust the tree everytime.
A flat list on the other hand required just 2 O(n) searches when you are looking for example, for employee 1765. You will then find its parent id and search the list again for an employee with than id, if it exists.
When you add an employee, add without a parent field and edit it later. When you delete an employee, just delete it and eventual broken links will be found at (flat) search time.

JSON API identifiers for nested resources relative to parent

When one models resource relationships, the classic example give is for articles and comments. This becomes simple to model because:
articles can be uniquely identified: /articles/1
comments can be uniquely identified: /comments/2
their relationship can be provided as /articles/1/comments which would return only comments for that article
But how does one handle the case where the related resource only exists within the context of the parent?
For example, order and items:
order can be uniquely identified /orders/123
the items in that order only exist as /orders/123/items
and NOT as /items
In JSON-API the relationship object needs a "type" and "id" to specify the linkage:
"relationships": {
"links": {
"self": "http://example.com/orders/123/relationships/items",
"related": "http://example.com/orders/123/items"
},
"data": {
"type": <what goes here>,
"id": <what goes here>
}
}
The type and id for data would need to be relative to order number 123. Assuming, of course, that they don't get assigned a UUID or similar from a database because they are, in fact, a composite key. They exist primarily as a foreign key combination.
How does one handle that?
One option for the relation is to use type as order_item and id as a hash or something delimited string concatenation of the order's id and the item's id. (e.g. 123_abc). 123 I get from the order and abc I get from the item in the order.
Is there another way other than avoiding the need altogether to supply resource linkage?
Every resource must be uniquely identified by a combination of type and id according to JSON API specification:
Identification
Every resource object MUST contain an id member and a type member. The values of the id and type members MUST be strings.
Within a given API, each resource object’s type and id pair MUST identify a single, unique resource. (The set of URIs controlled by a server, or multiple servers acting as one, constitute an API.)
https://jsonapi.org/format/#document-resource-object-identification
Therefor you are not only requiring an ID for resource linkage but also to build any valid response including such a resource.
But there are no rules about how you generate that unique IDs per type. Combining an unique order ID with an unique item ID to get an unique ID per item in an order seems to be a fine approach if your data model doesn't include an ID.

Forcing multiple JOINs

I have a CASE_MEMBER table with a row for each case member, and a field to indicate the member's role on the case. Let's say role 'Parent' and role 'Child'.
In the universe I've added the CASE_MEMBER table, and created a Parent object and Child object, each object containing a WHERE statement which specifies the correct value of the role field.
Now if I try and create a report with both of these objects, it will join to CASE_MEMBER only once, with a condition of "where role = 'Parent' and role = 'Child'", which is obviously impossible.
So I need to force the query to join to CASE_MEMBER once for each member type. Is the only way to do this by creating multiple aliases of CASE_MEMBER? Or is there another way to do this that also keeps my universe structure looking clean and more resembling the actual data model?
Create an alias of CASE_MEMBER, and include the WHERE condition in the join. So your joins will be:
For CASE_MEMBER to DEMOGRAPHICS:
case_member.member = demographics.memberid and case_member.role='child'
For CASE_MEMBER to DEMOGRAPHICS_PARENT (alias of DEMOGRAPHICS):
case_member.member = demographics_parent.memberid and case_member.role='parent'
Let's say you create (using the field names from your other question), a "Case ID" object from case_member.caseid, "Child SSN" from demographics.ssn, and "Parent SSN" from demographics_parent.ssn. Creating a report with all three of these objects will produce:
SELECT
case_member.caseid,
demographics.ssn,
demographics_parent.ssn
FROM
case_member,
demographics,
demographics demographics_parent
WHERE
(case_member.member = demographics.memberid
and case_member.role='child')
(and case_member.member = demographics_parent.memberid
and case_member.role='parent')
which should produce what you want.
Note that in this example, since we are including BOTH the child and parent table, we will get two rows in the result set. One with a blank child SSN and one with a blank parent SSN. To avoid this, you'd need to put a max() around each one.that

Why do associated collections contain null values? (Hibernate, Annotation, Spring)

[Edit: Apparently, this is only an issue for arrays and FoxyBOA's answer might direct to (or even is) the answer.]
My question relates to these software: Hibernate3+Annotation, Spring MVC, MySQL and in this example also Spring Security.
I was wondering, why collections, which are automatically associated by Hibernate contain null values for each row number of the child table (besides the elements which are correct). My Example:
I have a users and an authorities table, the primary key of the users table is username which serves as foreign key. Right now, there are 13 rows in my authorities table. When I retrieve a user from the database (MySQL InnoDB) and Hibernate automatically retrieves the user's authorities corresponding to this mapping:
#OneToMany
#JoinColumn(name = "username")
#IndexColumn(name="id") // "id" was the primary key and is used to sort the elements
public Authority[] getAuthorities() {
return authorities;
}
public void setAuthorities(Authority[] authorities) {
this.authorities = authorities;
}
... I end up with a collection "authorities" containing 14 (0-13) elements of which only four are not-null (four rows in the database table belong to that specific user, so that is correct). As far as I realize, I am using Hibernate defaults for properties like Fetchmode etc. I am getting the user like this:
Criteria criteria = getSession().createCriteria(User.class);
criteria.add(Restrictions.eq("username",username));
User user = (User) criteria.uniqueResult();
The logging information from org.hibernate.loader.loader correctly "mentions" four rows for the resultset. Still, the user created has the four correct elements plus ten null values in the Array. In my specific example, this results in this exception:
java.lang.IllegalArgumentException: Granted authority element 0 is null - GrantedAuthority[] cannot contain any null elements
The answer lies in the #IndexColumn annotation. It is using the value of id as the array index, thus the number of elements in the Array is basically going to be the value of the highest ID in the Authorities table.
see the hibernate documentation on indexed collections
try removing the annotation.
Also just as a thought; have you considered using a Set for the mapping? it isn't strictly necessary, it just a bit more common form of mapping that's all.
I can recommend you check your data. If you have a missed indexes (id column in your case), then instead of missed id you'll get null in your array.
I.e.
table authorities:
username id
bob 1
bob 3
bob 5
As a result you will have an array:
{0=null, 1=bob, 2=null, 3=bob, 4=null, 5=bob}
UPDATE:
I met the situation in two cases:
Missed key values in indexed column id at authorities table (e.g. 0,1,3,4,5 - missing value 2. Hibernate will automatically add to an array value with key 2 and value null).
Indexed values are in order, but select criteria filter part of them (e.g. your HQL similar to that "from user u join u.authorities a where a.id=2". In that case hibernate load a user, but in authorities array you will have only 3 values: 0 - null, 1 - null, 2 - authority with id 2).