Getting an id for existing dir on Drive - java

I am trying to get an id for an existing dir on Google Drive.
com.google.api.services.drive.model.About about = drive.about().get().execute();
com.google.api.services.drive.Drive.Children.List list =
drive.children().list(about.getRootFolderId());
Iterator<Entry<String, Object>> itr = list.entrySet().iterator();
Entry<String, Object> s;
while (itr.hasNext()) {
s = itr.next();
System.out.println(s.getKey() + "::" + s.getValue());
}
Right now this code is giving an output -
folderId::0APcEBFk-CF2pUk9PVA
which is probably not the correct id because I have 2 dirs and 3 files in my google drive.
I must be missing something, what the right way to get the id of an existing dir.
I have seen this question, and it will be helpful if I can get an equivalent java example. I am using the same account's google drive which is owning the app.

Create a List of files and iterate.
Drive service = new Drive.Builder(httpTransport, jsonFactory, credential1).build();
String query = "'" + about.getRootFolderId() +"' " + "in parents";
List<File> files = service.files().list().setQ(query).execute().getItems();
return files;
This should do.

Comparing your code to the example here you didn't call execute() on list, I think you're iterating on the request arguments.
Also it says:
folderId To list all files in the root folder, use the alias root as the value for folderId.
so you can skip getting the About.

Related

Java : How to print the content of s3 bucket

I am using jdk 11 and virtual-host-style-access (AWS SDK for Java version 2) to create/access objects in AWS s3 bucket following :
https://docs.aws.amazon.com/sdk-for-java/v2/developer-guide/examples-s3-objects.html#list-object
While I was able to create objects in the the designated bucket, I am not able to print the list of contents/objects in the bucket although, as I checked the permission, everyone is granted to view the objects in the bucket. The error message is :
software.amazon.awssdk.services.s3.model.NoSuchKeyException: The specified key does not exist. (Service: S3, Status Code: 404
This is the way the s3client is created :
adapterSmsS3Client = S3Client.builder()
.region(Region.US_WEST_2)
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create(ACCESS_KEY,SECRET_KEY)))
.endpointOverride(URI.create(BASE_URL))
.build();
And this is the way I am trying to print the list:
public static void listBucketObjects( S3Client s3, String bucketName ) {
ListBucketsResponse res1 = s3.listBuckets();
ListObjectsRequest listObjects = ListObjectsRequest
.builder()
.bucket(BUCKET_NAME)
.build();
ListObjectsResponse res = s3.listObjects(listObjects);
List<S3Object> objects = res.contents();
for (ListIterator iterVals = objects.listIterator(); iterVals.hasNext(); ) {
S3Object myValue = (S3Object) iterVals.next();
System.out.print("\n The name of the key is " + myValue.key());
System.out.print("\n The object is " + calKb(myValue.size()) + " KBs");
System.out.print("\n The owner is " + myValue.owner());
}
}
BUCKET_NAME is the name of bucket on s3 ( not any URL)
Although, I would like to mention that if I use Path-style-request (AWS SDK for Java version 1), following :
https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/examples-s3-objects.html
I am able to print contents from the same bucket. However we do not intend to go that way.
Any insight on why am I getting the "key does not exist" error or potential resolution?
If you had any problem with permissions you would have get a 403 forbidden; not a 404 NoSuchKey.
What are the names of your objects in the bucket ? My guess is that you have some special characters or url-encoded characters that causes the problem. See https://aws.amazon.com/premiumsupport/knowledge-center/404-error-nosuchkey-s3/?nc1=h_ls for more details.
And I suggest you to use listObjectsV2 instead of the V1.

how to fetch latest time of a file in S3 in java

I am new to S3. I need to fetch a file from S3, update it, and store it back to S3, so I need to fetch the latest time of this file in an existing module; it would be good if the answer is in java.
This gets a list of objects in the bucket. This also prints out each object’s name, the file size, and last modified date.
ObjectListing objects = conn.listObjects(bucket.getName());
do {
for (S3ObjectSummary objectSummary : objects.getObjectSummaries()) {
System.out.println(objectSummary.getKey() + "\t" +
ObjectSummary.getSize() + "\t" +
StringUtils.fromDate(objectSummary.getLastModified()));
}
objects = conn.listNextBatchOfObjects(objects);
} while (objects.isTruncated());
The output will look something like this:
myphoto1.jpg 251262 2011-08-08T21:35:48.000Z
myphoto2.jpg 262518 2011-08-08T21:38:01.000Z
Ref for s3 examples including above one( LISTING A BUCKET’S CONTENT) is at: http://docs.ceph.com/docs/master/radosgw/s3/java/

Retrieving modified/ checked in files from Clear Case Activity

This query is related to Rational Clear Case Cm api programming using java. We have a requirement wherein we want to get the list of modified files of a particular stream. I am able to get the list of activities which are of type CcActivity from given Stream and Using that activitylist info I am able to fetch the Version information also.
I am unable to get the changeset information ie name of files which are modified, as there is no such method defined.
Could you please help me out as to which property or method I should use to fetch the list of mopdified file or changeset information using activity id or version information. Below is the code which I have written for getting activity list information and version information:-
PropertyRequest propertyrequest = new PropertyRequest(
CcStream.ACTIVITY_LIST,CcStream.TASK_LIST
);
stream=(CcStream) stream.doReadProperties(propertyrequest);
List<CcActivity> listOfAct = stream.getActivityList();
for(int i=0;i<listOfAct.size();i++){
CcActivity ccActivity = listOfAct.get(i);
PropertyRequest activityPropertyRequest = new PropertyRequest(
CcActivity.COMMENT,CcActivity.ID,CcActivity.DISPLAY_NAME,CcActivity.LATEST_VERSION_LIST,CcActivity.CREATOR_DISPLAY_NAME,CcActivity.NAME_RESOLVER_VIEW
,CcActivity.TASK_LIST,CcActivity.CREATOR_LOGIN_NAME,CcActivity.HEADLINE,CcActivity.COMMENT);
ccActivity = (CcActivity)ccActivity.doReadProperties(activityPropertyRequest);
trace(ccActivity.getDisplayName());
trace(ccActivity.getCreatorDisplayName());
trace("CREATOR_LOGIN_NAME :" +ccActivity.getCreatorLoginName());
trace("Headline:" +ccActivity.getHeadline());
ResourceList<javax.wvcm.Version> versionList = ccActivity.getLatestVersionList();
for(int j=0;j<versionList.size();j++){
Version version = versionList.get(j);
PropertyRequest versionPropertyRequest = new PropertyRequest(
Version.PREDECESSOR_LIST,Version.VERSION_NAME,Version.VERSION_HISTORY.nest(VersionHistory.CHILD_MAP),Version.DISPLAY_NAME,Version.COMMENT
,Version.PATHNAME_LOCATION,Version.ACTIVITY.nest(Resource.CONTENT_TYPE));
version = (Version)version.doReadProperties(versionPropertyRequest);
trace("Version Info");
trace("Version Name : " + version.getVersionName());
trace("Version Comment :" +version.getComment());
Old thread but I have recently been trying to learn how to list modified files through the API. I believe the issue is that version object returned by the ResourceList get method should be cast to CcVersion type.
This exposes the StpResource.doReadProperties(Resource context, Feedback feedback) method which requires a handle to the view we are interested in. We can also request the CcVersion specific properties that we are interested in.
The example would then become something like:
ResourceList<javax.wvcm.Version> versionList = ccActivity.getLatestVersionList();
for(int j=0;j<versionList.size();j++){
Version version = versionList.get(j);
PropertyRequest versionPropertyRequest = new PropertyRequest(CcVersion.DISPLAY_NAME, CcVersion.VIEW_RELATIVE_PATH, CcVersion.CREATION_DATE);
version = (CcVersion) version.doReadProperties(view, versionPropertyRequest);
trace("Version Info");
trace("Version DISPLAY_NAME : " + version.getDisplayName());
trace("Version VIEW_RELATIVE_PATH : " + version.getViewRelativePath());
trace("Version CREATION_DATE : " + version.getCreationDate());
}

Finding product in category

I need to find products in different categories on eBay. But when I use the tutorial code
ebay.apis.eblbasecomponents.FindProductsRequestType request = new ebay.apis.eblbasecomponents.FindProductsRequestType();
request.setCategoryID("Art");
request.setQueryKeywords("furniture");
I get the following error: QueryKeywords, CategoryID and ProductID cannot be used together.
So how is this done?
EDIT: the tutorial code is here.
EDIT2: the link to the tutorial code died, apparently. I've continued to search and the category cannot be used with the keyword search, but there's a Domain that you could presumably add to the request, but sadly it's not in the API - so I'm not sure if indeed it can be done.
The less-than-great eBay API doc is here.
This is my full request:
Shopping service = new ebay.apis.eblbasecomponents.Shopping();
ShoppingInterface port = service.getShopping();
bp = (BindingProvider) port;
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointURL);
// Add the logging handler
List<Handler> handlerList = bp.getBinding().getHandlerChain();
if (handlerList == null) {
handlerList = new ArrayList<Handler>();
}
LoggingHandler loggingHandler = new LoggingHandler();
handlerList.add(loggingHandler);
bp.getBinding().setHandlerChain(handlerList);
Map<String,Object> requestProperties = bp.getRequestContext();
Map<String, List<String>> httpHeaders = new HashMap<String, List<String>>();
requestProperties.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointURL);
httpHeaders.put("X-EBAY-API-CALL-NAME", Collections.singletonList(CALLNAME));
httpHeaders.put("X-EBAY-API-APP-ID", Collections.singletonList(APPID));
httpHeaders.put("X-EBAY-API-VERSION", Collections.singletonList(VERSION));
requestProperties.put(MessageContext.HTTP_REQUEST_HEADERS, httpHeaders);
// initialize WS operation arguments here
FindProductsRequestType request = new FindProductsRequestType();
request.setAvailableItemsOnly(true);
request.setHideDuplicateItems(true);
request.setMaxEntries(2);
request.setPageNumber(1);
request.setQueryKeywords("Postcard");
request.setDomain("");
The last line, which should set the domain like I need to, does not compile. Any idea how to solve this?
EDIT 3: I gave up on the Java API and I'm doing direct REST. The categories on eBay are actually domains now, and the URL looks like this:
String findProducts = "http://open.api.ebay.com/shopping?callname=FindProducts&responseencoding=XML&appid=" + APPID
+ "&siteid=0&version=525&"
+ "&AvailableItemsOnly=true"
+ "&QueryKeywords=" + keywords
+ "&MaxEntries=10"
+ "&DomainName=" + domainName;
This works, but you want to hear a joke? It seems like not all the domains are listed here and so it doesn't really solve this problem. Pretty disappointing work by eBay.
The solution for finding items based on keywords, in a category, is to use findItemsAdvanced. Could have saved me a lot of time if the docs for FindProducts stated this, instead of just saying that you can use either keyword search OR category search.
This is the API URL:
http://open.api.ebay.com/shoppingcallname=findItemsAdvanced&responseencoding=XML&appid=" + APPID
+ "&siteid=0&version=525&"
+ "&AvailableItemsOnly=true"
+ "&QueryKeywords=" + keywords
+ "&categoryId=" + categoryId
+ "&MaxEntries=50
For completion, if you want to get a list of all the top categories you can use this:
http://open.api.ebay.com/Shopping?callname=GetCategoryInfo&appid=" + APPID + "&siteid=0&CategoryID=-1&version=729&IncludeSelector=ChildCategories

java.lang.NullPointerException trying to get specific values from hashmap

I've spent several frustrating days on this now and would appreciate some help. I have a Java agent in Lotus Domino 8.5.3 which is activated by a cgi:POST from my Lotusscript validation agent which is checking that customer has filled in the Billing and delivery address form. This is the code that parses the incoming data into a HashMap where field names are mapped to their respective values.
HashMap hmParam = new HashMap(); //Our Hashmap for request_content data
//Grab transaction parameters from form that called agent (CGI: request_content)
if (contentDecoded != null) {
String[] arrParam = contentDecoded.split("&");
for(int i=0; i < arrParam.length; i++) {
int n = arrParam[i].indexOf("=");
String paramName = arrParam[i].substring(0, n);
String paramValue = arrParam[i].substring(n + 1, arrParam[i].length());
hmParam.put(paramName, paramValue); //Old HashMap
if (paramName.equalsIgnoreCase("transaction_id")) {
transactionID = paramValue;
description = "Order " + transactionID + " from Fareham Wine Cellar";
//System.out.println("OrderID = " + transactionID);
}
if (paramName.equalsIgnoreCase("amount")) {
orderTotal = paramValue;
}
if (paramName.equalsIgnoreCase("deliveryCharge")) {
shipping = paramValue;
}
}
}
The block of code above dates back over a year to my original integration of shopping cart to Barclays EPDQ payment gateway. In that agent I recover the specific values and build a form that is then submitted to EPDQ CPI later on in the agent like this;
out.print("<input type=\"hidden\" name=\"shipping\" value=\"");
out.println(hmParam.get("shipping") + "\">");
I want to do exactly the same thing here, except when I try the agent crashes with a null pointer exception. I can successfully iterate through the hashMap with the snippet below, so I know the data is present, but I can't understand why I can't use myHashMap.Get(key) to get each field value in the order I want them for the html form. The original agent in another application is still in use so what is going on? The data too is essentially unchanged String fieldnames mapped to String values.
Iterator it = cgiData.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pairs = (Map.Entry)it.next();
out.println("<br />" + pairs.getKey() + " = " + pairs.getValue());
//System.out.println(pairs.getKey() + " = " + pairs.getValue());
}
I did two things that may have had an impact, in the process of trying to debug what was going on I needed these further imports;
import java.util.Iterator;
import java.util.Map;
Although I'm not iterating over the hashMap, I've left them in in case which gives me the option of dumping the hashMap out to my system audit trail when application is in production. In variations of the snippet below after it started working I was able to get to any of the data I needed, even if the value was Null, and toString() also seemed to be optional again, as it made no difference to the output.
String cgiValue = "";
cgiValue = hmParam.get("ship_to_lastname").toString();
out.println("<br />Lastname: " + cgiValue);
out.println("<br />Company name: " + hmParam.get("bill_to_company"));
out.println("<br />First name: " + hmParam.get("ship_to_firstname"));
The second thing I did, while trying to get code to work was I enabled the option "Compile Java code with debugging information" for the agent, this may have done something to the way the project was built within the Domino Developer client.
I think I have to put this down to some sort of internal error created when Domino Designer compiled the code. I had a major crash last night while working on this which necessitated a cold boot of my laptop. You also may find that when using Domino Designer 8.5.x that strange things can happen if you don't completely close down all the tasks from time to time with KillNotes

Categories

Resources