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"]
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()
);
}
does somebody know a explicit way to programmatically login to a website in an Android-App?
Thanks in advance :)
Don't cmpletely understand what you want, but if you just need to login and see the response, you could use a webview, and parse through the html like how to get html content from a webview?.
this is an answer:
web.loadUrl("javascript: {" +
"document.getElementsByName('authid')[0].value = '" + ID + "';" +
"document.getElementsByName('authpw')[0].value = '" + PASS + "';" +
"var submit = document.getElementsByClassName('inputbutton');" +
"submit[0].click(); };");
I'm showing a google map inside a BrowserField.
This is the relevant code:
private String setUpHtmlString(Coordinates coordinates){
StringBuffer mapString = new StringBuffer();
mapString.append("" +
"<!DOCTYPE html> " +
"<html> " +
" <head> " +
" <meta http-equiv='content-type' content='text/html; charset=UTF-8' /> " +
" <title>Google Maps Multiple Markers</title> " +
" <script src='http://maps.google.com/maps/api/js?sensor=false' type='text/javascript'></script>" +
" </head> " +
" <body> " +
" <div id='map' style='width: 500px; height: 600px;'></div> " +
" <script type='text/javascript'> " +
" var locations = [ ");
for (int i = 0; i < _placesStringArray.length; i++) {
Address address = ((Place)_hashTablePlaces.get(_placesStringArray[i])).getAddress();
mapString.append("['"+address.getDescription()+"', "+address.getLatitude()+", "+address.getLongitude()+", "+i+"]");
if(i<_placesStringArray.length - 1)
mapString.append(",");
}
mapString.append("];");
mapString.append(
" var map = new google.maps.Map(document.getElementById('map'), { " +
" zoom: 15, " +
" center: new google.maps.LatLng(-25.290646, -57.584080), " +
" mapTypeId: google.maps.MapTypeId.ROADMAP }); " +
" var infowindow = new google.maps.InfoWindow(); " +
" var marker, i; " +
" for (i = 0; i < locations.length; i++) { " +
" marker = new google.maps.Marker({ " +
"icon:'https://maps.google.com/mapfiles/kml/shapes/schools_maps.png', "+
" position: new google.maps.LatLng(locations[i][1], locations[i][2]), map: map }); " +
" google.maps.event.addListener(marker, 'click', (function(marker, i) { " +
" return function() { " +
" infowindow.setContent(locations[i][0]); " +
" infowindow.open(map, marker); " +
" } " +
" })(marker, i)); } " +
" </script>" +
" </body>" +
"</html>");
return mapString.toString();
}
As you can see, the icon is pointing to an external url, but how should a write the path to a image file inside the img folder
of my app.
I tried to reference it in many ways, like these:
"icon:'local:///assets/images/marker.png'
"icon:'resources/images/marker.png'
with no success.
Thanks in advance.
I won't advice you to hardcode the html inside the .java files, because the code is not readable and also hard to find for future modifications. Inline javascript is already a bad thing, but putting everything into a string in java code is a step beyond in terms of coupling.
Option #1: the cleanest way
Instead, you can have a resource html file and load it using a "local:///" URL, as the BrowserField demo shows: Display HTML content from a resource in your application
In the same directory you can place javascript and css files, as you would do in a regular static web site. So theoretically you could also place image resource files there and reference them from html or js files. The URLs don't need the full path (e.g.: instead of local:///assets/images/marker.png you would have local:///marker.png).
If you need to insert dynamic content into the html, then you can always insert placeholders into a template html resource file, and then do a string.replace from java code to replace the placeholders with the dynamic fields.
This way you are addressing modifiability and separation of concerns.
Option #2: the dirty hack
I've shown you why your code was dirty, but as so many things in life it can still get worse. You can add a new layer of unmodifiability by encoding your image file to a base64 string, and setting a "data://" url to the image in markup or javascript. It might be acceptable for you if the icon is really small and you know in advance you are not going to change it frequently, but be aware base64 strings can grow really large.
Option #3 (not tested)
This is also kind of a hack. Assuming you can open your image using Class.getResourceAsStream, you could instantiate a ProtocolController in java code, then call setNavigationRequestHandler to set a handler that intercepts the kind of requests you are interested in, and pass the content loaded using Class.getResourceAsStream.
Bonus option: (not tested)
And here's a link to a BB forum post, where a guy shows you can also reference the image using a URL starting with "cod:///".
I'm writing some code for web services for my Android app which uses JSON. The url should look like this
url = url + "?maddr=" + mailAddr + "&pwd=FB&lect=" + """ + lectName + """ + "&fb=Test";
This is because the Lectname may be two or more words. However the compiler wont accept """, is there a character I can precede the " with to get the compiler to accept it into my string?
Try " \" ". You have to escape the "
http://en.wikipedia.org/wiki/Escape_character
You need this in (nearly) every programming language.
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/