is there any way to get key "last-modified" from zend Google Doc Adapter? - zend-framework

I write some code like this to getting cell value in google Spreadsheet
this code exactly work
$query = new Zend_Gdata_Spreadsheets_DocumentQuery();
$query->setSpreadsheetKey($this->spreadsheetId);
$feed = $this->spreadsheetService->getWorksheetFeed($query);
var_dump($feed);
but I need value of last modified this spreadsheet
this value are protected in $feed object :
["Last-modified"]=>
string(29) "Wed, 18 Sep 2013 08:58:44 GMT"
is there any way to get key "last-modified" of Goolgle Doc?
AND How i can access it via zend V.1?

Related

Retrieving individual resources that have legacy UUIDs in Eve

I have a MongoDB collection with legacy UUID _id fields.
I can retrieve individual objects with pymongo by passing UUID objects:
from uuid import UUID
from pymongo import MongoClient
client = MongoClient('localhost', 27017)
db = client[DB_NAME]
collection = db[COLLECTION_NAME]
one_ok = collection.find_one(
filter={'_id': UUID('eedacde6-e241-4f37-a57d-c4e8eb6601a7')})
one_not_ok = collection.find_one(
filter={'_id': 'eedacde6-e241-4f37-a57d-c4e8eb6601a7'})
print(one_ok is None) # prints False
print(one_not_ok is None) # prints True
However I can't seem to get individual resources using Eve. I get a 404 for:
http://localhost:5000/collection1/eedacde6-e241-4f37-a57d-c4e8eb6601b7
The list returned by http://localhost:5000/collection1 mentions a link collection1/eedacde6-e241-4f37-a57d-c4e8eb6601b7 that seems to match the URL that returns a 404:
<resource href="collection1" title="collection1">
<link rel="parent" href="/" title="home"/>
<_meta>
<max_results>25</max_results>
<page>1</page>
<total>2</total>
</_meta>
<resource href="collection1/eedacde6-e241-4f37-a57d-c4e8eb6601b7" title="Collection1">
<_created>Thu, 01 Jan 1970 00:00:00 GMT</_created>
<_etag>9718572fe2d17b12358691602f6bd5f1ee345b06</_etag>
<_id>eedacde6-e241-4f37-a57d-c4e8eb6601b7</_id>
<_updated>Thu, 01 Jan 1970 00:00:00 GMT</_updated>
</resource>
<resource href="collection1/98c67ae6-ee7b-4bd3-9ec1-56b70fa2a9c7" title="Collection1">
<_created>Thu, 01 Jan 1970 00:00:00 GMT</_created>
<_etag>75c2451d19750e1007274315672bf893f9654273</_etag>
<_id>98c67ae6-ee7b-4bd3-9ec1-56b70fa2a9c7</_id>
<_updated>Thu, 01 Jan 1970 00:00:00 GMT</_updated>
</resource>
</resource>
This is my DOMAIN variable in settings.py. I set it up that way after following http://python-eve.org/tutorials/custom_idfields.html .
DOMAIN = {
'collection1': {
'item_url': 'regex("[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}")',
'schema': {
'_id': {'type': 'uuid'},
},
}
}
I suspect this doesn't work because the UUIDs are 'Legacy UUIDs', but I might be wrong.
Any ideas on how I can make URL such as http://localhost:5000/collection1/eedacde6-e241-4f37-a57d-c4e8eb6601b7 return individual resources?
Workaround: hack Eve
I am able to make it work by hacking Eve. The code below must be added for each HTTP verb (GET, POST, etc).
In eve/methods/get.py
def getitem_internal(resource, **lookup):
"""
<...>
"""
req = parse_request(resource)
resource_def = config.DOMAIN[resource]
embedded_fields = resolve_embedded_fields(resource, req)
#### hack ###
if '_id' in lookup:
if 'schema' in resource_def and '_id' in resource_def['schema']:
if resource_def['schema']['_id'].get('type') == 'uuid':
lookup['_id'] = UUID(lookup['_id'])
#### end of hack ###
soft_delete_enabled = config.DOMAIN[resource]['soft_delete']
if soft_delete_enabled:
# GET requests should always fetch soft deleted documents from the db
# They are handled and included in 404 responses below.
req.show_deleted = True
document = app.data.find_one(resource, req, **lookup)
<...>

Does openstack4j support set header when upload image?

I have some problem about OpenStack swift object storage. I want to set an expiration for objects. I use openstack4j. My upload object code
public void add(String objectName, InputStream imageStream) {
OSClientV3 clientV3 = OSFactory.clientFromToken(swiftOS.getToken());
Map<String, String> metaData = new HashMap<>();
metaData.put("X-Delete-After", "120");
ObjectPutOptions objectPutOptions = ObjectPutOptions.create();
objectPutOptions.metadata(metaData);
clientV3.objectStorage().objects().put(container, objectName,
Payloads.create(imageStream), objectPutOptions);
}
But it doesn't work.
Then I tried to use swift command line.
swift stat test test-19b8e4d4-1085-490d-b866-97f0ada0d46c
What I get is
Account: AUTH_01d73f1e49ed4dfd9535c831eed4ccf9
Container: test
Object: test-19b8e4d4-1085-490d-b866-97f0ada0d46c
Content Type: application/octet-stream
Content Length: 2414
Last Modified: Wed, 20 Dec 2017 07:58:56 GMT
ETag: 1cb55838010ed189c0698b6b5cade3ed
Meta X-Delete-After: 120
X-Openstack-Request-Id: tx4f1f57ef08e34d9296bfd-005a3a184b
X-Timestamp: 1513756735.97761
X-Trans-Id: tx4f1f57ef08e34d9296bfd-005a3a184b
Accept-Ranges: bytes
When I upload an object by
swift upload test test.jpg -H "X-Delete-After: 120"
and then
swift stat test test.jpg
What I get is
Account: AUTH_01d73f1e49ed4dfd9535c831eed4ccf9
Container: test
Object: test.jpg
Content Type: application/octet-stream
Content Length: 1688
Last Modified: Wed, 20 Dec 2017 08:03:20 GMT
ETag: 8a2d75ff8db40610a52a492abac09d3b
Meta Mtime: 1513755398.217256
X-Delete-At: 1513757119
Accept-Ranges: bytes
X-Timestamp: 1513756999.02865
X-Trans-Id: txc016e1aff901450aa934b-005a3a194c
X-Openstack-Request-Id: txc016e1aff901450aa934b-005a3a194c
It is like openstack document said.
The X-Delete-After header takes an integer number of seconds.
The proxy server that receives the request will convert this
header into an X-Delete-At header using its current time plus
the value given.
But why openstack4j doesn't work?
Looks like we can use
objectPutOptions.getOptions().put("X-Delete-After", "120");
As the getOptions call returns the headers map straight up.
You should use header instead of metadata:
objectPutOptions.header("X-Delete-After", "120");

Retrieve AEM Page Properties via Search/QueryBuilder API

Is there a way to retrieve data stored as page metadata (Page Properties) stored in a separate JCR node via the QueryBuilder API?
Example:
The search results should include the data under ~/article-1/jcr:content/thumbnail. However, the only results I am getting are data under the ~article-1/jcr:content/content (a parsys included on the template).
An example query:
http://localhost:4502/bin/querybuilder.json?p.hits=full&path=/content/path/to/articles
Results in (snippet):
{
"jcr:path":"/content/path/to/articles/article-1",
"jcr:createdBy":"admin",
"jcr:created":"Tue Dec 03 2013 16:26:51 GMT-0500",
"jcr:primaryType":"cq:Page"
},
{
"jcr:path":"/content/path/to/articles/article-1/jcr:content",
"sling:resourceType":"myapp/components/global/page/productdetail",
"jcr:lockIsDeep":true,
"jcr:uuid":"4ddebe08-82e1-44e9-9197-4241dca65bdf",
"jcr:title":"Article 1",
"jcr:mixinTypes":[
"mix:lockable",
"mix:versionable"
],
"jcr:created":"Tue Dec 03 2013 16:26:51 GMT-0500",
"jcr:baseVersion":"24cabbda-1e56-4d37-bfba-d0d52aba1c00",
"cq:lastReplicationAction":"Activate",
"jcr:isCheckedOut":true,
"cq:template":"/apps/myapp/templates/global/productdetail",
"cq:lastModifiedBy":"admin",
"jcr:primaryType":"cq:PageContent",
"jcr:predecessors":[
"24cabbda-1e56-4d37-bfba-d0d52aba1c00"
],
"cq:tags":[
"mysite:mytag"
],
"jcr:createdBy":"admin",
"jcr:versionHistory":"9dcd41d4-2e10-4d52-b0c0-1ea20e102e68",
"cq:lastReplicatedBy":"admin",
"cq:lastModified":"Mon Dec 09 2013 17:57:59 GMT-0500",
"cq:lastReplicated":"Mon Dec 16 2013 11:42:54 GMT-0500",
"jcr:lockOwner":"admin"
}
Search configuration is the out-of-the-box default.
EDIT: Data is returning in JSON, however, is not accessable in the API:
Result:
{
"success":true,
"results":2,
"total":2,
"offset":0,
"hits":[
{
"jcr:path":"/content/path/to/articles/article-a",
"jcr:createdBy":"admin",
"jcr:created":"Tue Dec 03 2013 16:27:01 GMT-0500",
"jcr:primaryType":"cq:Page",
"jcr:content":{
"sling:resourceType":"path/to/components/global/page/productdetail",
"_comment":"// ***SNIP*** //",
"thumbnail":{
"jcr:lastModifiedBy":"admin",
"imageRotate":"0",
"jcr:lastModified":"Wed Dec 04 2013 12:10:47 GMT-0500",
"jcr:primaryType":"nt:unstructured"
}
}
},
{
"jcr:path":"/content/path/to/articles/article-1",
"jcr:createdBy":"admin",
"jcr:created":"Tue Dec 03 2013 16:26:51 GMT-0500",
"jcr:primaryType":"cq:Page",
"jcr:content":{
"sling:resourceType":"path/to/components/global/page/productdetail",
"_comment":"// ***SNIP*** //",
"thumbnail":{
"jcr:lastModifiedBy":"admin",
"imageRotate":"0",
"fileReference":"/content/dam/path/to/IBMDemo/apparel/women/wsh005_shoes/WSH005_0533_is_main.jpg",
"jcr:lastModified":"Mon Dec 09 2013 17:57:58 GMT-0500",
"jcr:primaryType":"nt:unstructured"
}
}
}
]
}
Implementation code:
searchCriteria.put("path", path);
searchCriteria.put("type", "cq:Page");
searchCriteria.put("p.offset", offset.toString());
searchCriteria.put("p.limit", limit.toString());
searchCriteria.put("p.hits", "full");
searchCriteria.put("p.properties", "thumbnail");
searchCriteria.put("p.nodedepth", "2");
PredicateGroup predicateGroup = PredicateGroup.create(searchCriteria);
Query query = queryBuilder.createQuery(predicateGroup, session);
SearchResult result = query.getResult();
for (Hit hit : result.getHits()) {
try {
ValueMap properties = hit.getProperties();
VFSearchResult res = new VFSearchResult();
res.setUrl(hit.getPath());
res.setImageUrl((String)properties.get("thumbnail"));
res.setTags((String[])properties.get("cq:tags"));
res.setTeaserText((String)properties.get("teaserText"));
res.setTitle((String)properties.get("jcr:title"));
searchResults.add(res);
} catch (RepositoryException rex) {
logger.debug(String.format("could not retrieve node properties: %1s", rex));
}
}
After setting the path in the query, then set one or more property filters, such as in this example:
type=cq:Page
path=/content/path/to/articles
property=jcr:content/thumbnail
property.operation=exists
p.hits=selective
p.properties=jcr:content/thumbnail someSpecificThumbnailPropertyToRetrieve
p.limit=100000
You can set those on /libs/cq/search/content/querydebug.html and then also use that to get the JSON URL for the same query.
Check this out for some other examples: http://dev.day.com/docs/en/cq/5-5/dam/customizing_and_extendingcq5dam/query_builder.html
You could use CURL to retrieve node properties in the HTML/ JSON/ XML format. All you have to do is install download CURL and run your curl commands from your terminal from the same directory as the curl's .exe file.
HTML example:
C:\Users\****\Desktop>curl -u username:password http://localhost:4502/content/geometrixx-media/en/gadgets/leaps-in-ai.html
JSON example:
**C:\Users\****\Desktop>**curl -u username:password http://localhost:4502/content/geometrixx-media/en/gadgets/leaps-in-ai.html.tidy.infinity.json
Note: infinity in the above query ensures you get every property of every node under your specified path recursively

UTC_TIMESTAMP() to user defined timezone?

I am storing timestamps in my db using UTC_TIMESTAMP().
I want to output them based on user selected timezone. I tried writing a small function to do this, however, it does not output correctly.
// Date/time converter
function convertTZ($date, $tz, $tzFormat)
{
$date = new DateTime($date);
$date->setTimezone(new DateTimeZone($tz));
return $date->format($tzFormat);
}
echo $_SESSION['dtCurrLogin'].'<br />';
echo convertTZ($_SESSION['dtCurrLogin'], 'UTC', 'F j, Y # g:i:s a e');
dtCurrLogin from db = 2013-09-12 01:23:45
the above outputs :
2013-09-12 01:23:45
September 12, 2013 # 5:23:45 am UTC
Obviously this is not correct as I went from UTC to UTC so they should be equal. If I change to output EST then it shows 1:23:45 am, but of course that would not be right either.
Didn't realize I needed to specify incoming timezone... using the following worked for me...
function convertTZ($date_time, $from_tz, $to_tz, $format_tz)
{
$time_object = new DateTime($date_time, new DateTimeZone($from_tz));
$time_object->setTimezone(new DateTimeZone($to_tz));
return $time_object->format($format_tz);
}

Current date / time to RFC 2822 date function with vb / classic asp

I am trying to write a script to push data out to an amazon s3 bucket and I need to generate what I believe is an RFC 2822 date to send in the header request.
The date looks like this "Tue, 12 June 2012 23:41:58 +0000"
I just need a function to generate the correct time format as I am getting the following error.
RequestTimeTooSkewed The difference between the request time and the current time is too large.
This is what I have so far...
<%
sTimeStamp = "Tue, 12 June 2012 23:41:58 +00002012-06-12T22:45:47Z"
sAWSAccessKeyId = "AESDQWDQWD"
sSignature=Encrypt("SecretQWEQWEQWEQWEYAYAY")
AWSServiceUrl = "https://s3.amazonaws.com/"
Set oXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
oXMLHTTP.open "GET", AWSServiceUrl, False
oXMLHTTP.setRequestHeader "Authorization", "AWS " & sAWSAccessKeyId & ":" & sSignature
oXMLHTTP.setRequestHeader "x-amz-date", sTimeStamp
on error resume next
oXMLHTTP.send sRequest
Response.Write oXMLHTTP.responseText
%>
Any ideas?
The simplest way to do it is to get JScript to help:
<script runat="server" language="javascript">
function JSNow() { return new Date(); }
</script>
Now you can get the string format for the time required with:
Dim sTimeStamp: sTimeStamp = JSNow().toString()