How to get liferay form name through code in java - java

I am writing the code to fetch liferay forms through java but I am unable to do so. I am using recordset to do it but it is only fetching DDL recordset not forms.
public List<DDLRecordSet> getRecordSets() {
long groupId = themeDisplay.getScopeGroupId();
System.out.println("groupId:::"+groupId);
long liveGroupId = themeDisplay.getScopeGroup().getLiveGroupId();
System.out.println("LiveGroupID::"+ liveGroupId);
List<DDLRecordSet> results = DDLRecordSetLocalServiceUtil.getRecordSets(themeDisplay.getScopeGroupId());
if (liveGroupId != 0) {
results.addAll(DDLRecordSetLocalServiceUtil.getRecordSets(groupId));
}
System.out.println("Result::"+ results);
return result;
}
The output is shown only for DDL recordset not of form recordset.
Output=
Result::[{mvccVersion=0, uuid=7ca2308a-29f0-b344-8eeb-13eda08fe745, recordSetId=46003, groupId=20124, companyId=20101, userId=35402, userName=Test1 Test1, versionUserId=0, versionUserName=, createDate=Fri Jun 11 05:06:35 GMT 2021, modifiedDate=Fri Jun 11 05:06:35 GMT 2021, DDMStructureId=34991, recordSetKey=46002, version=1.0, name=, description=, minDisplayRows=10, scope=0, settings=, lastPublishDate=null}]
Please let me know where am I wrong.

To fetch all the created forms of a group/site, you can fetch the DDMFormInstances via DDMFormInstanceLocalServiceUtil.getFormInstances(groupId) (or better to use osgi references instead). For me, it is not clear what is required in your scenario (form, form-fields, form-data).
If you want the submitted data (depending on your handler this might differ), you can usually look for the corresponding DDMFormInstanceRecord and check the storageId which might be contentId of DDMContent which holds your data (usually in json).

Related

object field starting or ending with a [.] makes object resolution ambiguous in elasticsearch bulk index

I am using elasticsearch version 6.8.7 with java rest high level client. I coded a program that uses bulk processor to bulk index some data to elasticsearch, according to the documentation provided here.
The problem is when I run my code, response fails with the message:
[type=illegal_argument_exception, reason=object field starting or ending with a [.] makes object resolution ambiguous
which is quite strange because I indexed one of the documents manually and it succeeded without any problem.
this is the part of the code that makes a index request:
String key = entry.getKey();
JSONObject val = entry.getValue();
bulkProcessor.add(new IndexRequest("tweet").type("json").id(key).source(val, XContentType.JSON));
and this is a sample of the json (val in the above):
{"in_reply_to_status_id_str":null,"in_reply_to_status_id":null,"coordinates":null,"created_at":"Mon
Apr 06 23:59:47 +0000
2020","truncated":false,"in_reply_to_user_id_str":null,"source":"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter
for
iPhone</a>","retweet_count":0,"retweeted":false,"geo":null,"in_reply_to_screen_name":null,"is_quote_status":false,"id_str":"11111111111111","in_reply_to_user_id":null,"favorite_count":7,"id":1111111111111,"text":"something","place":null,"contributors":null,"lang":"en","favorited":false}
If anyone has any ideas why this happens, I would very much appriciate their help.
update:
I changed the index nothing changed but this is the error I get in elastic terminal:
object field starting or ending with a [.] makes object resolution ambiguous: [{"possibly_sensitive_appealable":false,"in_reply_to_status_id_str":null,"in_reply_to_status_id":null,"created_at":"Mon Apr 06 23:59:49 +0000 2020","in_reply_to_user_id_str":null,"source":"http://twitter.com/download/android\" rel=\"nofollow\">Twitter for Android</a>","quoted_status_id":1111111111111,"retweet_count":0,"retweeted":false,"geo":null,"in_reply_to_screen_name":null,"is_quote_status":true,"id_str":"111111111111","in_reply_to_user_id":null,"favorite_count":15,"id":1247313090397589511,"text":"something","place":null,"lang":"fa","favorited":false,"possibly_sensitive":false,"coordinates":null,"truncated":false,"quoted_status_id_str":"1111111111111","contributors":null}]
I had the same problem, try to validate the properties, apparently all the properties in your index GET /index_name are store as String and not as a JSON object.
If this is your case:
The problem initially was with Kafka ConsumerRecord raw, I didn't set the types ConsumerRecord<String, String> and the problem was resolved.
Other option is to encode the string with a specific Encoding and also it works for me.
e.g.
IndexRequest indexRequest = new IndexRequest("twitter")
.source(record.value().getBytes(StandardCharsets.US_ASCII), XContentType.JSON);
IndexResponse indexResponse = client.index(indexRequest, RequestOptions.DEFAULT);
String id = indexResponse.getId();
log.info(id);
I'm not pretty sure that this could help you, but in my case I resolve the problem with those changes.

Delete the list of unused DAM images in database through an UI in Adobe Experience Manager

I am new to Adobe Experience Manager. My task is to retrieve the list of unused images from database and needs to delete that through an UI.
I have given a Select query which displays list of unused images. After google search I got some idea that is how to use QueryBuilder in adobe experience manager but I not aware of where to place this select query in the below code.
SQLQuery = "Select * from [nt:file]
where isdesplay([/home/cam/Bwits/master/images/top_images])
and NAME() LIKE 'cq5dam.thumbnail.140.100.png'";
The below code also I got it from adobe support website. For normal Jsp I know how to retrieve the list of files but now for the same in JSP with adobe (AEM) api no idea
I found some code an adobe help blog that is how to delete a node or folder from jsp.
How to delete a content node from a JSP in CQ authoring environments
Delete via AJAX Call
Node Path to Delete:
(e.g. ‘/content/testdelete/deletePage1’)
Char-set:
Command:
Force Delete:
(true/false)
<div id=”respText”></div>
function performDelete() {
var response = null;
var url = “/bin/wcmcommand”;
var pathObj= document.getElementById(‘pathAJ’);
if(pathObj)
{
var params = “path=”+encodeURIComponent(pathObj.value)+”&_charset_=utf-8&cmd=deletePage&force=false”;
var request = document.all ? new ActiveXObject(“Microsoft.XMLHTTP”) : new XMLHttpRequest();
//alert(params);
request.open(“post”, url, false);
request.setRequestHeader(“Content-Type”, “application/x-www-form-urlencoded”);
request.send(params);
var resp= request.responseText;
document.getElementById(‘respText’).innerHTML=resp;
}
}
</script>
</HTML>
Now I have to get the list of nodes with help of SQL Query and needs to delete that nodes at a time from this JSP.
Kindly suggest me where to place the sql query for retrieving the list of images from database.
Thanks for your cooperation in advance
As others have pointed out, there are several forums (mostly Adobe) posts out there with various approaches to address this question. However, in the spirit of diversity and enriching SO, I think this question warrants a fresh answer.
The following solution was based on JS but there is no reason why this logic cannot be implemented in any other language like Java, Ruby, bash (using CURL) or PowerShell. Also, this approach will not work for DAM assets that are referenced from CSS and JS files.
Taking the example of geometrixx OOTB DAM library, consider that most of the assets are under /content/dam/geometrixxx folder
You need a to build a recursively iterative loop that traverses the DAM library in a linear way one level at a time. This can be done using the logic below:
Step 1: Enumarate
Get root level folder structure for your content with following HTTP call:
http://localhost:4502/content/dam/geometrixx.1.json
This will return something like:
{
"jcr:primaryType":"sling:OrderedFolder",
"jcr:mixinTypes":[
"rep:AccessControllable"
],
"jcr:createdBy":"admin",
"jcr:title":"Geometrixx",
"jcr:created":"Mon Feb 27 2017 13:54:20 GMT+0000",
"portraits":{
"jcr:primaryType":"sling:OrderedFolder",
"jcr:createdBy":"admin",
"jcr:title":"Portraits",
"jcr:created":"Mon Feb 27 2017 13:54:20 GMT+0000"
},
"drm":{
"jcr:primaryType":"sling:OrderedFolder",
"jcr:createdBy":"admin",
"jcr:created":"Mon Feb 27 2017 13:54:20 GMT+0000"
},
"banners":{
"jcr:primaryType":"sling:OrderedFolder",
"jcr:createdBy":"admin",
"jcr:title":"Banners",
"jcr:created":"Mon Feb 27 2017 13:54:20 GMT+0000"
}
}
Step 2: Iterate
Recursively iterate through this structure until you reach the DAM assets for the project. For example, you when iterating: http://localhost:4502/content/dam/geometrixx/banners.1.json you will get something like:
{
"jcr:primaryType":"sling:OrderedFolder",
"jcr:createdBy":"admin",
"jcr:title":"Banners",
"jcr:created":"Mon Feb 27 2017 13:54:20 GMT+0000",
"banner-mono.png":{
"jcr:primaryType":"dam:Asset",
"jcr:createdBy":"admin",
"jcr:created":"Mon Feb 27 2017 13:54:20 GMT+0000"
},
"banner-retro.png":{
"jcr:primaryType":"dam:Asset",
"jcr:createdBy":"admin",
"jcr:created":"Mon Feb 27 2017 13:54:20 GMT+0000"
},
"banner-web20.png":{
"jcr:primaryType":"dam:Asset",
"jcr:createdBy":"admin",
"jcr:created":"Mon Feb 27 2017 13:54:20 GMT+0000"
}
}
So the key logic is to get children of folder nodes and process all the dam:Asset nodes.
Step 3: Find References
Once you hit a DAM asset, you can use the built in reference finder from
http://localhost:4502/bin/wcm/references.json?path= to find the references.
For example, using the references utility as below:
http://localhost:4502/bin/wcm/references.json?path=/content/dam/geometrixx/banners/techsummit.jpg
will get you all the references as:
{
"pages":[
{
"srcPath":"/content/dam/geometrixx/banners/techsummit.jpg",
"srcTitle":"Tech Summit",
"path":"/content/geometrixx/en/events/techsummit",
"title":"TechSummit",
"references":[
"/content/geometrixx/en/events/techsummit/jcr:content/image/fileReference",
"/content/geometrixx/en/events/techsummit/jcr:content/par/image/fileReference"
],
"published":false,
"isPage":"true"
}
]
}
Any asset that an empty pages array is an unused asset.
Step 4: Delete
A delete is just a HTTP DELETE request on the node path. For example, if you want to delete the /content/dam/geometrixx/banners/techsummit.jpg DAM asset, you just need to sent a HTTP DELETE request on:
http://localhost:4502/content/dam/geometrixx/banners/techsummit.jpg
That's it and your content will be deleted.

RestFB get events in Java

Using FQL, by means of which finds events that contain a given word. FQL works only in API version <2.1. By which I use the Graph API Explorer to display events. Eg.
search?q=york&type=event
Example of FQL
SELECT Eid, name, location, start_time, description, pic_small, creator, event venue FROM WHERE start_time> "Sun Jun 21 0:00:35 GMT 2015" AND (CONTAINS ("york")
I would like to make a search events by using RestFB not using FQL, but do not know how. The documentation is scarce.
I answered this already on github, but perhaps someone else find this useful.
Your special case is not in the documentation, but you can transfer the knowledge you find in the documentation and solve your problem: http://restfb.com/#searching
Connection<Event> eventList =
facebookClient.fetchConnection("search", Event.class,
Parameter.with("q", "york"), Parameter.with("type", "event"));
Now, you can iterate over the eventList.
Here you can find how this can be done: http://restfb.com/#fetching-connections

Invoice query always returning no more than 10 results

Using IPP Java DevKit 2.0.9 (also tried with 2.0.6), I've implemented a wrapper method for finding specific invoices in QBO by customer ID and occurring before a certain date. I'm testing with a particular customer who has 65 invoices across ~16 months, but the query always returns the 10 "latest" invoices occurring before dateFinish (endTransactionDate). I've tried various permutations as well: only including the customer ID criteria, only including the endTransactionDate, adding a "really early" startTransactionDate, development version, and production version. It's as if the API is chopping off the results list and only including the first 10 records, seemingly without a good reason.
public static List<QBInvoice> findInvoices(PlatformSessionContext context, String dataSource, Calendar dateFinish, List<String> customerIds) throws QBInvalidContextException, Exception {
QBInvoiceService invoiceService = QBServiceFactory.getService(context, QBInvoiceService.class);
QBInvoiceQuery invoiceQuery = new QBInvoiceQuery(context);
invoiceQuery.setEndTransactionDate(QuickbooksUtil.dateToQbDate(dateFinish));
if (!customerIds.isEmpty()) {
IdSet idSet = QuickbooksUtil.stringListToIdSet(context, dataSource, customerIds);
invoiceQuery.setContactIdSet(idSet);
}
return invoiceService.getInvoices(context, invoiceQuery);
}
Specify the PageNum and ResultsPerPage in your request. You are being returned the default, which is Page=1 and ResultsPerPage=10.
https://ipp.developer.intuit.com/0010_Intuit_Partner_Platform/0050_Data_Services/0400_QuickBooks_Online/0100_Calling_Data_Services/0030_Retrieving_Objects#Paging

How to parse json to a database?

I have a complex json written in a string. I know java and a little of mysql. I need to make a database out of the json.
I'm using some twitter data so the tweets contain the description of the user who tweeted it and in case it's been retweeted, it contains the description of the user who tweeted it before this user.
My objective is to create a user table ( or array or any other data structure ) which contains all the tweets this user tweeted, and all his tweets which have been retweeted.
The tweet object contains around 50-80 objects so giving an example here will make this post really long.
Example
StatusJSONImpl{createdAt=Wed Sep 28 12:04:55 IST 2011, id=118936707830775808, text='RT #nytimesbits: Google's Biggest Threat Is Google http://t.co/kTNqJFJC', source='web', isTruncated=false, inReplyToStatusId=-1, inReplyToUserId=-1, isFavorited=false, inReplyToScreenName='null', geoLocation=null, place=null, retweetCount=6, wasRetweetedByMe=false, contributors=null, annotations=null, retweetedStatus=StatusJSONImpl{createdAt=Wed Sep 28 05:35:26 IST 2011, id=118838689248985088, text='Google's Biggest Threat Is Google http://t.co/kTNqJFJC', source='The New York Times', isTruncated=false, inReplyToStatusId=-1, inReplyToUserId=-1, isFavorited=false, inReplyToScreenName='null', geoLocation=null, place=null, retweetCount=6, wasRetweetedByMe=false, contributors=null, annotations=null, retweetedStatus=null, userMentionEntities=[], urlEntities=[URLEntityJSONImpl{start=34, end=54, url=http://t.co/kTNqJFJC, expandedURL=http://nyti.ms/pR9DfX, displayURL=nyti.ms/pR9DfX}], hashtagEntities=[], user=UserJSONImpl{id=14434070, name='NYTimes Bits Blog', screenName='nytimesbits', location='The Cloud', description='News and analysis on tech and business. Also here: select retweets from NYT tech writers and friends. Account maintained by David F. Gallagher (#davidfg).', isContributorsEnabled=true, profileImageUrl='http://a1.twimg.com/profile_images/108833947/bits75_normal.jpg', profileImageUrlHttps='https://si0.twimg.com/profile_images/108833947/bits75_normal.jpg', url='http://nytimes.com/bits', isProtected=false, followersCount=53180, status=null, profileBackgroundColor='9ae4e8', profileTextColor='000000', profileLinkColor='0000ff', profileSidebarFillColor='e0ff92', profileSidebarBorderColor='87bc44', profileUseBackgroundImage=true, showAllInlineMedia=false, friendsCount=139, createdAt=Fri Apr 18 20:49:26 IST 2008, favouritesCount=5, utcOffset=-18000, timeZone='Eastern Time (US & Canada)', profileBackgroundImageUrl='http://a3.twimg.com/profile_background_images/4780380/twitter_post.png', profileBackgroundImageUrlHttps='https://si0.twimg.com/profile_background_images/4780380/twitter_post.png', profileBackgroundTiled=true, lang='en', statusesCount=6360, isGeoEnabled=false, isVerified=true, translator=false, listedCount=4671, isFollowRequestSent=false}}, userMentionEntities=[UserMentionEntityJSONImpl{start=3, end=15, name='NYTimes Bits Blog', screenName='nytimesbits', id=14434070}], urlEntities=[URLEntityJSONImpl{start=51, end=71, url=http://t.co/kTNqJFJC, expandedURL=http://nyti.ms/pR9DfX, displayURL=nyti.ms/pR9DfX}], hashtagEntities=[], user=UserJSONImpl{id=17989546, name='Wolfgang Fasching-K.', screenName='wwwof', location='Vienna', description='Digital ist besser. Fokus: IT & Internet, World News & US Politik, Medien & Pop/Kultur. http://www.riverone.at', isContributorsEnabled=false, profileImageUrl='http://a0.twimg.com/profile_images/67758989/SF050069-w_normal.JPG', profileImageUrlHttps='https://si0.twimg.com/profile_images/67758989/SF050069-w_normal.JPG', url='null', isProtected=false, followersCount=59, status=null, profileBackgroundColor='C0DEED', profileTextColor='333333', profileLinkColor='0084B4', profileSidebarFillColor='DDEEF6', profileSidebarBorderColor='C0DEED', profileUseBackgroundImage=true, showAllInlineMedia=false, friendsCount=64, createdAt=Tue Dec 09 17:09:35 IST 2008, favouritesCount=0, utcOffset=3600, timeZone='Vienna', profileBackgroundImageUrl='http://a3.twimg.com/profile_background_images/234523169/Naschmarkt-Wien-Juni10-2010-s.jpg', profileBackgroundImageUrlHttps='https://si0.twimg.com/profile_background_images/234523169/Naschmarkt-Wien-Juni10-2010-s.jpg', profileBackgroundTiled=true, lang='en', statusesCount=269, isGeoEnabled=false, isVerified=false, translator=false, listedCount=4, isFollowRequestSent=false}}
For JSON parsing, I recommend Jackson. Also, in order to validate your input, you should have a look at JSON Schema (for which I have an implementation if you want).
Here is how to parse a JSON in a string using Jackson:
final ObjectMapper mapper = new ObjectMapper();
final JsonNode node = mapper.readTree(yourInput);
// Access members:
node.get(0); // access node 0 of an array
for (final JsonNode entry: node) {
... // cycle through array nodes
}
node.get("foo"); // access property "foo" of an object
node.get("foo").getTextValue(); // access as a text
// etc etc
It also has a s*load of options to serialize to POJOs if that's what you want.
Your first step will be to parse the JSON to get an object graph, using a library like gson or any of several others.
Then (and this seems really general, but it's a pretty open question) it's a matter of determining what the schema should be, creating the tables, and looping through the object graph populating them.
You might look at "document databases" (so-called NoSQL) rather than SQL ones if you're allowed to, as they usually allow the schema to be more fluid.
If your problem is just with Twitter, you can look for dedicated APIs like Twiiter4J or Spring Social, that should provides ready java beans for tweets.
If you're realizing a small project Gson is the best solution for parsing. But if your making something more sophisticated, I suggest you to use Jackson for parsing and Hibernate as a middleware between application and sql database.

Categories