How to set a DateTime property to an artifact
If our use case is to search for items which promoted after a specific date there is a way to set a DateTime property to an artifact, we made an example for that:
In case a user would like to search for an item based on an artifact's promotion date, the user can set a DateTime artifact property which later he can use to search.
For example:
1. Add DateTime property to an artifact by Set Item Properties rest API command:
curl -uadmin:password -X PUT "http://localhost:8081/artifactory/api/storage/npm-local/.npm/npmtest/npmtest-1.0.2.json?properties=PromotedOnProdDate=$(date +%Y-%m-%dT%H:%M:%OS%z)"
2. Verify that the Item Properties has been modified:
curl -uadmin:password -X GET "http://localhost:8081/artifactory/api/storage/npm-local/.npm/npmtest/npmtest-1.0.2.json?properties"
{
"properties" : {
"PromotedOnProdDate" : [ "2019-04-17T13:54:28 0300" ]
},
"uri" : "http://localhost:8081/artifactory/api/storage/npm-local/.npm/npmtest/npmtest-1.0.2.json"
}
3. Search with aql for items that match the criteria:
curl -uadmin:password -XPOST "http://localhost:8081/artifactory/api/search/aql" -H "Content-Type: text/plain" -d 'items.find({"@PromotedOnProdDate" : {"$gt" : "2019-07-16T19:20:30.45+01:00"}})
'
{
"results" : [ {
"repo" : "npm-local",
"path" : ".npm/npmtest",
"name" : "npmtest-1.0.2.json",
"type" : "file",
"size" : 631,
"created" : "2019-02-06T09:53:59.152Z",
"created_by" : "_system_",
"modified" : "2019-02-06T09:53:59.124Z",
"modified_by" : "_system_",
"updated" : "2019-02-06T09:53:59.153Z"
} ],
"range" : {
"start_pos" : 0,
"end_pos" : 1,
"total" : 1
}
}