save entity-find results and iterate throught it later - moqui

I'm doing a conditional entity-find and want to save the results somewhere to iterate through it later. I searched around and found 2 solutions. I'm using mySql btw.
1-create a temp table and insert results into it
2-saving results in a file (csv, ...)
now my question is:
1-which solution is preferable or maybe suggest another solution (common/trusted pattern)
2- how to do it? (for example I don't know how to create a table on the fly or drop it in moqui.Suggesting a resource/example source code etc. would be awesome)
thanks in advance

One possible approach would be to convert the list that your entity-find gives you to binary data and store it as a DbResourceFile using the moqui.resource.DbResource entities, and using the utilities from org.apache.commons.io etc.
EDIT - To expound in response to comment below, I was thinking along such lines as
<set field="fileData" from="yourList.toString().getBytes()" />
<service-call name="create#moqui.resource.DbResource" in-map="[filename:'ExampleListFrom01012019.bin', isFile:'N']" out-map="context" />
<service-call name="create#moqui.resource.DbResourceFile" in-map="context + [mimeType:'application/octet-stream', fileData:fileData]" />
Then bring it back after a find on the DBResource with something like
<set field="convertedBack" from="x.fileData.getBinaryStream()" type="NewList" />
I haven't tried this, and there are no near samples in the code that I know of.
This type of conversion between types is not best practice, but storing lists to iterate through them later is probably not either.
Perhaps it would help if you elaborated on your business requirement.

Related

Concat in xslt, unable to get an image from server

I am new to xslt coding, I am trying to fix an issue in existing piece of code. I got stuck up at a point
<fo:external-graphic content-width="150pt"
content-height="50pt"
src="url:{concat('${OA_MEDIA}/',$revised_last_name,',',DOCUMENT_BUYER_FIRST_NAME,'.gif')}" />
The above piece of code is trying to find a .gif file in OA_MEDIA directory. Till that part I can understand fine.
When I am placing a file name as "Eckert,Tim.gif" (excluding the quotes) my program isn't picking that file
In the above piece, I printed $revised_lastname and $document_buyer_first_name..It's coming as Tim and Eckert, but it's still not picking the file. If I am hardcoding a file name like below it's working fine
<fo:external-graphic content-width="150pt"
content-height="50pt"
src="url:{concat('${OA_MEDIA}/','Tim','.gif')}" />
How can I print what value is coming into the src in above piece of code so I can see what file is it trying to look in the $OA_MEDIA.
Any suggestions are appreciated.
Thanks!
Your first problem appears to be that in your constructed URI and your file name, you have put the given name and the family name in different orders: Tim,Eckert.gif vs Eckert,Tim.gif. Choose one.
If you still have problems after that, your next step is to confirm that your concatenation is producing the value you expect. I'd add a line like
<xsl:message>Generating fo:external graphic with URI <xsl:value-of
select="concat('url:',
'${OA_MEDIA}/',
$revised_last_name,
',',
DOCUMENT_BUYER_FIRST_NAME,
'.gif')"/></xsl:message>
And if that did not shed light on what was going wrong, I'd insert individual messages to display the current value of $revised_last_name and DOCUMENT_BUYER_FIRST_NAME.
More than that it's difficult to say, because your question does not provide a short, self-contained, complete example that allows readers to reproduce the problem you are trying to solve. There is good advice on asking effective questions in the SO help files and in Eric Raymond and Rick Moen's essay How to ask questions the smart way.

Avoid duplicates in the destination schema

I have a little problem. I want to map every detail line to one OrderInfo. The destination schema can not have any duplicate OrderInfo. All the detail lines should be in the destination orderInfo, but the SuppliersOrderNo and BuyersOrderNo should not be twice.
Any ideas how to do this, is it possible to use XSL or inline script?
<inv:OrderInfo>
<inv:SuppliersOrderNo>123456</inv:SuppliersOrderNo>
<inv:BuyersOrderNo>6789</inv:BuyersOrderNo>
<inv:DetailLines>
<inv:DetailLine>
<inv:InvoiceDetailLineNo>1</inv:InvoiceDetailLineNo>
<inv:Item>
<inv:SuppliersArticleNo>article2</inv:SuppliersArticleNo>
<inv:SuppliersDescription>BestArticle</inv:SuppliersDescription>
</inv:Item>
</inv:DetailLine>
<inv:DetailLine>
<inv:InvoiceDetailLineNo>2</inv:InvoiceDetailLineNo>
<inv:Item>
<inv:SuppliersArticleNo>article3</inv:SuppliersArticleNo>
<inv:SuppliersDescription>AlmostBestArticle</inv:SuppliersDescription>
</inv:Item>
</inv:DetailLine>
</inv:DetailLines>
</inv:OrderInfo>
<inv:OrderInfo>
<inv:SuppliersOrderNo>123456</inv:SuppliersOrderNo>
<inv:BuyersOrderNo>6789</inv:BuyersOrderNo>
<inv:DetailLines>
<inv:DetailLine>
<inv:InvoiceDetailLineNo>1</inv:InvoiceDetailLineNo>
<inv:Item>
<inv:SuppliersArticleNo>article1337</inv:SuppliersArticleNo>
<inv:SuppliersDescription>WOW</inv:SuppliersDescription>
</inv:Item>
</inv:DetailLine>
</inv:DetailLines>
</inv:OrderInfo>
If you want to do this purely in XSLT, you'll have to use Muenchian gruoping. I wrote a blog that links to some other blogs on how to do this in BizTalk a little while back: https://blog.tallan.com/2014/12/09/muenchian-grouping-in-biztalk-while-keeping-mapper-functionality/
To summarize the blog: if you pursue this, you'll need a map that's completely custom XSLT somewhere, but you could put it into a custom pipeline component if you still want to be able to use "regular" maps functionality without any other caveats (in my blog I describe a method of doing that in a pipeline component so that a "regular" BizTalk map can still be used on the preprocessed output). There are lots of resources on Muenchian grouping out there (including on StackOverflow), so I'm not rehashing all of that in this answer.
You could also try to serialize the message in a C# component and use some LINQ methods to group/sort/order/etc, or if you're inserting the content into SQL at some point you could do it in SQL (which would be able to handle this kind of task more naturally).

Chameleon: Why is a repeating comment truncated?

I'm having trouble with the transformation of an HL7 message. Its got an NTE segment with repeating fields of type string.
ex:
MSH|^~\&|HOST||TD-SYN||201207031000||ORU^R01|0017|P|2.3
PID|1||0001|
NTE|||Comment 1~Comment 2~Comment3
What happens after a graphical transformation is, NTE just takes Comment 1 and the rest of the repeating comments are ignored.
MSH|^~\&|HOST||TD-SYN||201207031000||ORU^R01|0017|P|2.3
PID|1||0001|
NTE|||Comment 1|
I tried setting the "Repeats" field of NTE segment's grammar to 10 but doesn't make a difference. Also, no script is manipulating that field of NTE, so I have no idea why it truncates it that way. Can someone tell me what's going on?
Glad you found it. Just as a general help, use sometimes the HAPI TestPanel to convert into XML, then you see very well how to loop over your HL7 elements. You then also know if you're using a correct HL7 structure.
In your example on the 3rd element in NTE <NTE.3>:
<?xml version="1.0" encoding="UTF-8"?>
<ORU_R01 xmlns="urn:hl7-org:v2xml">
<MSH>
<MSH.1>|</MSH.1>
<MSH.2>^~\&</MSH.2>
<MSH.3>
<HD.1>HOST</HD.1>
</MSH.3>
<MSH.5>
<HD.1>TD-SYN</HD.1>
</MSH.5>
<MSH.7>
<TS.1>201207031000</TS.1>
</MSH.7>
<MSH.9>
<CM_MSG.1>ORU</CM_MSG.1>
<CM_MSG.2>R01</CM_MSG.2>
</MSH.9>
<MSH.10>0017</MSH.10>
<MSH.11>
<PT.1>P</PT.1>
</MSH.11>
<MSH.12>2.3</MSH.12>
</MSH>
<ORU_R01.RESPONSE>
<ORU_R01.PATIENT>
<PID>
<PID.1>1</PID.1>
<PID.3>
<CX.1>0001</CX.1>
</PID.3>
</PID>
<NTE>
<NTE.3>Comment 1</NTE.3>
<NTE.3>Comment 2</NTE.3>
<NTE.3>Comment3</NTE.3>
</NTE>
</ORU_R01.PATIENT>
</ORU_R01.RESPONSE>
</ORU_R01>
I just found the answer from its documentation. It isn't actually truncated.
The default value of "value" is the first element in the repeatable field. Thus,
all I had to do is to access the repeating fields via field.repeat_field(index).value. :)

Deleting a value from sql database using jsp

I'm trying to use jsp to rendering a simple database and have the ability to delete a row using a button. I'm running into the trouble of not being able to fetch the primary key from the row because I've been using to iterate through the table. I've tried passing just simple numbers to denote the primary key (integers) but its not grabbing it.
Lets say I want to delete the row with the primary key of 12.
<form action="deleteResponse.jsp">
<c:set var="numId" value="12"/>
<input type="submit" name="delete" value="Delete"/>
</form>
This generates a button which opens up deleteResponse.jsp which has the following to catch the value.
<sql:update var="counselorDelete" dataSource="jdbc/IFPWAFCAD">
DELETE FROM Counselor
WHERE counselor_id = ?<sql:param value="${param.numId}"/>
</sql:update>
It's not doing anything, and I'm not sure whats going on with it. If I manually put in the value 12 in the sql query it will delete the row but it won't do it if I try to fetch the value.
Thanks very much in advance!
Also as a side note. I'm having a hard time understanding how to properly write JSPs. I see that most of the time people use <% Java code %> but in the netbean tutorial, it uses the and functions. Could someone explain that to me? I'm also using glassfish as a localhost sql server. Netbean generates a glassfish xml but I also see people using DriverManager.getConnection methods. Which one is conventionally better?
I would try to separate the UI/JSP code from the DAO layer, using a seperate Bean to handle all the insert/uodate/delete operations.
Take a look at the logfiles of your Applicationserver, this might give you some hints.
Kr, R
Edit: Concerning the sql:
<sql:update var="counselorDelete" dataSource="jdbc/IFPWAFCAD"
sql="DELETE FROM Counselor WHERE counselor_id = ?" >
<sql:param value="${param.numId}"/>
</sql:update>

How to pass a field that is an array list in a java bean, within a JasperReports?

Could some indicate a working example or a snippet of code for JasperReports regarding ArrayList as a Field in a javabean datasource.
I have a List of Employees. Each Employee has a name field, and an array of Phone with type and number as its fields.
Do i use a subreport for Phones I have not found a working example? Cant seem to compile subreport_jasper file?
Do i use a list component instead...
<c:list ...>
<datasetRun subDataset="Addresses">
<datasetParameter name="Phone">
<datasetParameterExpression><![CDATA[$F{Phone}]]></datasetParameterExpression>
</datasetParameter>
</datasetRun>
This does seems to work either?
Thank in advance
I wrote this article while working with MongoDB. It deals with handling fields that are collections. It should be exactly what you need. (You can just ignore the MongoDB part.)
The key idea is that you use this to pass data to a List or Table or Subreport:
new net.sf.jasperreports.engine.data.JRMapCollectionDataSource($F{PhoneArray})