I have a number of xml's that come in haphazardly that contain a Ocount, and Lnumber, as well as other data. I have created a class to get that data.
My problem is that how can I group xml's that have the same Lnumber(string), until it reaches the Ocount(int). (the xmls that have the same lnumber has the same Ocount). And eventually send out a email telling with xmls has been processed.
String readLine = FileHandler.checkListFile(sh.getShipmentHeader().getBillToCustomer());
if (!readLine.isEmpty())
{
int orderCount = 0;
int index = readLine.indexOf(";") + 1;
String customerName = readLine.substring(index, readLine.indexOf(";", index)).trim();
index = readLine.indexOf(";", index) + 1;
String to = readLine.substring(index, readLine.length()).trim();
if (!billMap.containsKey(sh.getShipmentHeader().getBillToCustomer()))
{
billMap.put(sh.getShipmentHeader().getBillToCustomer(), 1);
orderCount = 1;
}
else
{
billMap.put(sh.getShipmentHeader().getBillToCustomer(), ((int) billMap.get(sh.getShipmentHeader().getBillToCustomer())) + 1);
orderCount = (int) billMap.get(sh.getShipmentHeader().getBillToCustomer());
}
outboundMessage += sh.getShipmentHeader().getOrderNumber() + li ;
logger.info("On-Demand Outbound Export Info: " + orderCount + " processed out of " + sh.getShipmentHeader().getOrderCount() +
" for " + customerName);
if (orderCount == sh.getShipmentHeader().getOrderCount())
{
Email email = new Email();
billMap.remove(sh.getShipmentHeader().getBillToCustomer());
outboundMessage += li + "Total of #"+ sh.getShipmentHeader().getOrderCount() + " orders processed for "+ customerName + li ;
logger.info("On-Demand Email sent for " + customerName);
System.out.println(outboundMessage);
email.outboundEmail("TEST: Orders for " + customerName + " complete", outboundMessage, to);
outboundMessage = "";
email = null;
}}
I been working on this for days, where am I going wrong.
It seems like you are having difficulty obtaining information from xmls. I suggest using XStream [1]. It is capable of serialising objects to xml and back. By using XStream, you can get an Object from the xml and compare variables (Lnumber and Ocount) easily.
If you insist using this code, I suggest adding comments to notify us what you are doing, but if want an easier alternative to work with xml files using java, I highly suggest using XStream as a solution.
[1] http://x-stream.github.io/
Related
I am trying to read a EBCDIC file and convert it to ASCII format in Java, with a help of copybook. I am using JRecord to read the copybook. So now, how do I get the field level from the copybook using JRecord?
Edit 1:
Kindly excuse me for a vague question. I have no experience in mainframe or cobol. I am adding few more details if it could help.
My source file contains multiple transaction details. The copybook contains the information on the transaction and the fields relating to that particular transaction.
I have to split the each transaction and its fields to a separate file(containing one transaction and respective fields).
CopyBook
In attached copybook, the field in line 1 can have values from line 2 to line 4. If the EXTRA-TYPE is 01, then I have to read fields in line 6 to line 11. Similarly, if the EXTRA-TYPE is 02, then I have to read fields in line 12 to line 16.
I am trying to split the Transaction type and its respective fields dynamically.
(I need to get the start and end position of the fields with respect to the transaction type in line 1)How do I achieve this in Java?
I appreciate your help.
Why do you need to get the Field Level ???. To convert a file to ascii you do not need the Field Level.
Utility Conversion Program
To Convert a Cobol File to ascii you can use one of the utility programs:
Cobol2Csv sub-project - converts a Cobol data file to a Csv file
Cobol2Xml sub-project - converts a Cobol data file to a Xml file
Cobol2Json json utiltiy
Java processing of a Cobol file
If you want to do some processing on the File, you can use the Generate
function of the RecordEditor to generate sample JRecord code from the Cobol copybook.
Code generated with standard template
If you use the standard template, the RecordEditor will generate code like:
AbstractLine line;
int lineNum = 0;
try {
ICobolIOBuilder iob = JRecordInterface1.COBOL
.newIOBuilder(copybookName)
.setFont("cp037")
.setFileOrganization(Constants.IO_FIXED_LENGTH)
.setSplitCopybook(CopybookLoader.SPLIT_NONE)
;
FieldNamesDtar020.RecordDtar020 rDtar020 = FieldNamesDtar020.RECORD_DTAR020;
AbstractLineReader reader = iob.newReader(dataFile);
while ((line = reader.read()) != null) {
lineNum += 1;
System.out.println(
line.getFieldValue(rDtar020.keycodeNo).asString()
+ " " + line.getFieldValue(rDtar020.storeNo).asString()
+ " " + line.getFieldValue(rDtar020.date).asString()
+ " " + line.getFieldValue(rDtar020.deptNo).asString()
+ " " + line.getFieldValue(rDtar020.qtySold).asString()
+ " " + line.getFieldValue(rDtar020.salePrice).asString()
);
}
reader.close();
} catch (Exception e) {
System.out.println("~~> " + lineNum + " " + e);
System.out.println();
e.printStackTrace();
}
Code generated with lineWrapper template
AbstractLine line;
int lineNum = 0;
try {
ICobolIOBuilder iob = JRecordInterface1.COBOL
.newIOBuilder(copybookName)
.setFont("cp037")
.setFileOrganization(Constants.IO_FIXED_LENGTH)
.setSplitCopybook(CopybookLoader.SPLIT_NONE)
;
LineDtar020JR lineDtar020JR = new LineDtar020JR();
AbstractLineReader reader = iob.newReader(dataFile);
while ((line = reader.read()) != null) {
lineNum += 1;
lineDtar020JR.setLine(line);
System.out.println(
lineDtar020JR.getKeycodeNo()
+ " " + lineDtar020JR.getStoreNo()
+ " " + lineDtar020JR.getDate()
+ " " + lineDtar020JR.getDeptNo()
+ " " + lineDtar020JR.getQtySold()
+ " " + lineDtar020JR.getSalePrice()
);
}
reader.close();
} catch (Exception e) {
System.out.println("~~> " + lineNum + " " + e);
System.out.println();
e.printStackTrace();
}
Generic Cobol processing
If you want to do more generic processing you can use a fieldIterator:
FieldIterator fieldIterator = line.getFieldIterator("Record-Name");
JRecord Examples
In the latest release of JRecord 0.81.4 there are examples in the Source/JRecord_IO_Builder_Examples/src directory
Tree processing
If you need to access level numbers with JRecord, use CobolSchemaReader.newCobolSchemaReader(...) interface.
Also you could look at the code for Cobol2Xml sub-project. It does tree processing by extending CobolSchemaReader
Have a read of
http://www.catb.org/~esr/faqs/smart-questions.html or https://www.mikeash.com/getting_answers.html about asking questions
But any way:
Using the Code Generation
Download the Recordeditor from https://sourceforge.net/projects/record-editor/files/Test/Version_0.98.3/ the USB version does not need to be installed - just unzip it
Start the RecordEditor and select the generate option
Enter the Cobol Copybook, Sample cobol file (if you hava one). You will
probably be able to use the Split Copybook On Redefines option
On the Records panel, enter DA147-EXTRA-TYPE in the Record Type field
Press the Generate Code button. On the next screen you can select the template. The Standard template is a good starting point
Press the Generate code button, The program should generate some sample code like:
ICobolIOBuilder iob = JRecordInterface1.COBOL
.newIOBuilder(copybookName)
.setFileOrganization(Constants.IO_BIN_TEXT)
.setSplitCopybook(CopybookLoader.SPLIT_REDEFINE)
;
FieldNamesAmspodownloadRedef1.RecordPoHeaderRecord rPoHeaderRecord = FieldNamesAmspodownloadRedef1.RECORD_PO_HEADER_RECORD;
FieldNamesAmspodownloadRedef1.RecordProductRecord rProductRecord = FieldNamesAmspodownloadRedef1.RECORD_PRODUCT_RECORD;
FieldNamesAmspodownloadRedef1.RecordLocationRecord rLocationRecord = FieldNamesAmspodownloadRedef1.RECORD_LOCATION_RECORD;
AbstractLineReader reader = iob.newReader(dataFile);
while ((line = reader.read()) != null) {
lineNum += 1;
if (
"H1".equals(line.getFieldValue(rPoHeaderRecord.recordType).asString())
) {
System.out.println(
line.getFieldValue(rPoHeaderRecord.recordType).asString()
+ " " + line.getFieldValue(rPoHeaderRecord.sequenceNumber).asString()
+ " " + line.getFieldValue(rPoHeaderRecord.vendor).asString()
+ " " + line.getFieldValue(rPoHeaderRecord.po).asString()
....
+ " " + line.getFieldValue(rPoHeaderRecord.cancelByDate).asString()
+ " " + line.getFieldValue(rPoHeaderRecord.ediType).asString()
);
}
if (
"D1".equals(line.getFieldValue(rProductRecord.recordType).asString())
) {
System.out.println(
line.getFieldValue(rProductRecord.recordType).asString()
+ " " + line.getFieldValue(rProductRecord.packQty).asString()
+ " " + line.getFieldValue(rProductRecord.packCost).asString()
+ " " + line.getFieldValue(rProductRecord.apn).asString()
+ " " +
.....
+ " " + line.getFieldValue(rProductRecord.productName).asString()
);
}
if (
"S1".equals(line.getFieldValue(rLocationRecord.recordType).asString())
) {
System.out.println(
line.getFieldValue(rLocationRecord.recordType).asString()
+ " " + line.getFieldValue(rLocationRecord.dcNumbe.get(0)).asString()
+ " " + line.getFieldValue(rLocationRecord.packQuantit.get(0)).asString()
);
}
I have a few test values in my database and i want to fetch them all in android.
This is my following JSON output of the values inside my Database:
[{"email_address":"rainier_gaari#hotmail.com","comment":"qwehgashdgaskdaweq","date_comment":"2014-06-21","time_comment":"08:28:00","password":"rainier1990"},
{"email_address":"rainier_gaari#hotmail.com","comment":"asfasdasdasd","date_comment":"2104-06-12","time_comment":"09:03:00","password":"rainier1990"}
{"email_address":"rainier_gaari#hotmail.com","comment":"asdsfafd","date_comment":"2014-06-22","time_comment":"04:44:00","password":"rainier1990"}]
But every time that I run this code: http://prntscr.com/3vhs5j , it only gives me the first line of the JSON output.: http://prntscr.com/3vi34b
How can I show all the rows( instead of 1 row)in android?
You can use a JSONObject provided by the android API. The JSONObject has a method called getJSONArray()
http://developer.android.com/reference/org/json/JSONObject.html#getJSONArray(java.lang.String)
your error there is that you are instantiating a JSONArray with your Object. you should try this:
JSONArray myArray =jsonObject.getJSONArray();
This is a snippet of code from one of my apps that worked very well to retrieve Json data.
success = jObject.getInt(TAG_SUCCESS);
vehicles = jObject.getJSONArray(Vehicle.TAG_VEHICLES);
if(success == 1) {
// loop through all the vehicles
for(int i = 0; i < vehicles.length(); i++) {
JSONObject obj = vehicles.getJSONObject(i);
// Get each element based on it's tag
String year = obj.getString(Vehicle.TAG_YEAR);
String model = obj.getString(Vehicle.TAG_MODEL);
String brand = obj.getString(Vehicle.TAG_BRAND);
String color = obj.getString(Vehicle.TAG_COLOR);
String license_plate = obj.getString(Vehicle.TAG_LICENSE);
String main_driver = obj.getString(Vehicle.TAG_DRIVER);
String policeNumber = obj.getString(Vehicle.TAG_POLICENUMBER);
String driversLicense = obj.getString(Vehicle.TAG_DRIVER_LICENSE);
String licenseState = obj.getString(Vehicle.TAG_LICENSE_STATE);
String driverBirthday = obj.getString(Vehicle.TAG_BIRTHDAY_MONTH) + "/" +
obj.getString(Vehicle.TAG_BIRTHDAY_DAY) + "/" +
obj.get(Vehicle.TAG_BIRTHDAY_YEAR);
String driverGender = obj.getString(Vehicle.TAG_DRIVER_GENDER);
ListRowGroup group = new ListRowGroup(brand + " " + year + " " + model, brand);
group.children.add(brand + " " + year + " " + model);
group.children.add(policeNumber);
group.children.add(model);
group.children.add(color);
group.children.add(license_plate);
group.children.add(main_driver);
group.children.add(driversLicense + " - " + licenseState);
group.children.add(driverBirthday + " - " + driverGender);
vehiclesGroup.append(i, group);
}
It would help if you put some of the code for getting the JSON in your question, to make it easier to reference, but, I don't see a loop, which is why it only gets the first line.
You may want to refer to this question: JSON Array iteration in Android/Java but basically use the length property of the JSONArray and loop through that many times.
I'm trying to retrieve all of my network updates using the linkedin-j API. I can fetch the first 10 updates, but do not know how to retrieve any more.
The following code retrieves the first 10 updates:
Network network = client.getNetworkUpdates(EnumSet.of(NetworkUpdateType.STATUS_UPDATE));
System.out.println("Total updates fetched:" + network.getUpdates().getTotal());
for (Update update : network.getUpdates().getUpdateList()) {
System.out.println("-------------------------------");
System.out.println(update.getUpdateKey() + ":" + update.getUpdateContent().getPerson().getFirstName() + " " + update.getUpdateContent().getPerson().getLastName() + "->" + update.getUpdateContent().getPerson().getCurrentStatus());
if (update.getUpdateComments() != null) {
System.out.println("Total comments fetched:" + update.getUpdateComments().getTotal());
for (UpdateComment comment : update.getUpdateComments().getUpdateCommentList()) {
System.out.println(comment.getPerson().getFirstName() + " " + comment.getPerson().getLastName() + "->" + comment.getComment());
}
}
}
There is another method called network.getUpdates().getStart(), but I don't know how to implement it. I've been at this for hours, and any advice would be appreciated.
If you would like to use pagination in linkedin-j, then you could use getNetworkUpdates(Set, int, int) along with network.getUpdates().getTotal().
public Network getNetworkUpdates(Set<NetworkUpdateType> updateTypes, int start, int count);
I have to develop one android native application using stringbuffer with html content.
Here i have used below code:
PayPalInvoiceItem item1 = new PayPalInvoiceItem();
sb.append("<html><body><table>");
for (int i = 0; i < Constants.mItem_Detail
.size(); i++) {
String title = Constants.mItem_Detail
.get(i).get(
SingleMenuItem.KEY_PNAME);
String qty = Constants.mItem_Detail.get(i)
.get(SingleMenuItem.KEY_QTY);
String cost = Constants.mItem_Detail.get(i)
.get(SingleMenuItem.KEY_PRICE);
String total = Constants.mItem_Detail
.get(i).get(
SingleMenuItem.KEY_TOTAL);
total_count=total_count+Integer.parseInt(qty);
StringBuffer buffer = sb.append("<tr>" + "<td>" + title
+ "</td><td>" + qty + " * " + cost
+ "</td>" + " = <td>" + total
+ " " + "</td></tr>");
item1.setName(buffer.toString());
Now i have to run the application means my output is looking like
<html><body><table>"<tr>" "<td>"krishna
"</td><td>" 1 " * " 100
+ "</td>" = <td>" 100
+ " " + "</td></tr>
But i need the o/p like:
krishna 1 100 100
veni 2 30 60
How can i do????
please help me ???
EDIT:
here i have to change the below line item1.setName(buffer.toString());
to
item.setName(buffer.toString(), "text/html; charset=utf-8"); means am getting following error:
The method setName(String) in the type PayPalInvoiceItem is not applicable for the arguments (String,
String)
How can i resolve these error ????
What is the 'item' you are trying to setName on? by the sounds of things you probably just need to create a WebView like this:
WebView view = new WebView(this);
view.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
view.loadData(stringBuffer.toString(), "text/html", "UTF-8");
setContentView(view);
you also seem to have not terminated the HTML correctly i.e your last write to the StringBuffer should be:
stringBuffer.append("</table></body></html>");
also check your line:
total_count=total_count+Integer.parseInt(qty);
should it not be:
total_count=total_count+Integer.parseInt(total);
I've some customized models into Alfresco and I need to extract the aspect information and the content from Repository.
I need, passing the keywords and the model name (it's an aspect), to extract content or the aspects associated to the model.
search/{keywords}?model={model?}
this is the javascript I'm using to extract the content passing the model
var docs = search.luceneSearch("#kd\\:commonname_content_type_tag:\"" + model + "\"");
How can I concatenate two aspects properties?
I did it into Java but the syntax in Javascript seems quite different:
queryString = "+TYPE:\"" + Constants.createQNameString(CommonAspects.NAMESPACE_KD_CONTENT_MODEL, DrugModel.TYPE_SUPPLIER) + "\" ";
queryString += "+#kd\\:SupplierID:" + drugBrandNameBean.getSupplierID();
String supplier = contentQuery.getUUID(queryString);
Another question, how can I process the Javascript docs? Can I access to my aspects?
I tried something like that but it didn't works:
var docs = search.luceneSearch("#kd\\:commonname_content_type_tag:\"" + model + "\"");
for (var i=0; i<docs.length; i++) {
log += "Searching " + commonName + " - Name: " + docs[i].name + "\tPath: " + docs[i].displayPath;
log += "\tType: " + docs[i].commonname_content_type_tag + "\r\n";
}
The rows extracted are correct but the commonname_content_type_tag properties is always not defined:
Searching acarbose - Name: exenatide - Contraindication Path: /Company Home/CommonName Type: undefined
Thanks for the help!
Andrea
Try something like that:
docs[i].properties["kd:commonname_content_type_tag"]