Get node details in Alfresco via back-end webscript - java

I want to get node details via Backend webscript but I have some issues. I've tried two webscripts:
alfresco/service/slingshot/doclib2/node/workspace/SpacesStore/a10a0777-40f4-42da-b236-8845eb26294e
alfresco/service/slingshot/doclib/node/workspace/SpacesStore/a10a0777-40f4-42da-b236-8845eb26294e.
The first one gave me this response :
{
"status" :
{
"code" : 410,
"name" : "Gone",
"description" : "Resource is no longer available at the server and no forwarding address is known."
},
"message" : "Location is 'null'. (No permission?)",
"exception" : "",
"callstack" :
[
],
"server" : "Enterprise v4.2.0 (r57217-b28) schema 6,034",
"time" : "Jun 10, 2014 10:28:15 AM"
}
and the second :
{
"status" :
{
"code" : 500,
"name" : "Internal Error",
"description" : "An error inside the HTTP server which prevented it from fulfilling the request."
},
"message" : "05100028 Wrapped Exception (with status template): 05100077 Failed to execute script 'classpath*:alfresco\/templates\/webscripts\/org\/alfresco\/slingshot\/documentlibrary\/node.get.js': 05100076 Site container UploadComponent.java does not refer to a folder.",
"exception" : "org.springframework.extensions.webscripts.WebScriptException - 05100028 Wrapped Exception (with status template): 05100077 Failed to execute script 'classpath*:alfresco\/templates\/webscripts\/org\/alfresco\/slingshot\/documentlibrary\/node.get.js': 05100076 Site container UploadComponent.java does not refer to a folder.",
"callstack" :
[
"" ,"org.alfresco.repo.site.SiteServiceException: 05100076 Site container UploadComponent.java does not refer to a folder."
,"
Updated :
You can notice that in the second webSript the error says that my file UploadComponent.java does not refer to a folder. Does this script take a cm:folder as an argument. If there is another web-script that returns the node details (properties: nodeRef, mimetype, size... ) from nodeRef please show it to me. thanks !

Pro tip - You can see all of the available web scripts at http://localhost:8080/alfresco/service/index/uri/
You're supposed to use the CMIS web scripts where possible, and this also makes for the simplest request.
http://<MyAlfresco>/alfresco/service/cmis/i/8826b8f4-9f61-41a4-9f21-14ad5b6395ab
This returns the full set of properties for the nodeRef workspace://SpacesStore/8826b8f4-9f61-41a4-9f21-14ad5b6395ab.
Some of the XML you will receive is:
<cmis:properties>
<cmis:propertyInteger propertyDefinitionId="cmis:contentStreamLength" displayName="Content Stream Length" queryName="cmis:contentStreamLength"><cmis:value>36864</cmis:value></cmis:propertyInteger>
<cmis:propertyId propertyDefinitionId="cmis:objectTypeId" displayName="Object Type Id" queryName="cmis:objectTypeId"><cmis:value>cmis:document</cmis:value></cmis:propertyId>
<cmis:propertyString propertyDefinitionId="cmis:versionSeriesCheckedOutBy" displayName="Version Series Checked Out By" queryName="cmis:versionSeriesCheckedOutBy"/>
<cmis:propertyBoolean propertyDefinitionId="cmis:isPrivateWorkingCopy" displayName="Is private working copy" queryName="cmis:isPrivateWorkingCopy"/>
<cmis:propertyId propertyDefinitionId="cmis:versionSeriesCheckedOutId" displayName="Version Series Checked Out Id" queryName="cmis:versionSeriesCheckedOutId"/>
<cmis:propertyId propertyDefinitionId="cmis:versionSeriesId" displayName="Version series id" queryName="cmis:versionSeriesId"><cmis:value>workspace://SpacesStore/8826b8f4-9f61-41a4-9f21-14ad5b6395ab</cmis:value></cmis:propertyId>
<cmis:propertyBoolean propertyDefinitionId="cmis:isLatestVersion" displayName="Is Latest Version" queryName="cmis:isLatestVersion"><cmis:value>true</cmis:value></cmis:propertyBoolean>
</cmis:properties>
I also checked and this should give you the properties for any node regardless of where it is situated in your Alfresco instance.

There are a few webscripts you can use, such as the CMIS ones, but I think the simplest is probably the Slingshot Document Library Node webscript, with ID org/alfresco/slingshot/documentlibrary/node.get. You can read about it at http://localhost:8080/alfresco/service/script/org/alfresco/slingshot/documentlibrary/node.get
For a node with noderef workspace://SpacesStore/357b6dad-d434-4a46-a7e0-731df50e5e90 the URL is http://localhost:8080/alfresco/service/slingshot/doclib/node/workspace/SpacesStore/357b6dad-d434-4a46-a7e0-731df50e5e90, and the JSON returned looks something like:
{
"metadata":
{
"parent":
{
"nodeRef": "workspace://SpacesStore/7f4e374c-7c7c-4356-bf8f-0ec6bfc5eac4",
"permissions":
{
"userAccess":
{
"permissions": true,
"edit": true,
"delete": true,
"cancel-checkout": false,
"create": true
}
}
},
"onlineEditing": true
},
"item":
{
"nodeRef": "workspace://SpacesStore/357b6dad-d434-4a46-a7e0-731df50e5e90",
"nodeType": "cm:content",
"type": "document",
"mimetype": "application\/vnd.ms-project",
"isFolder": false,
"isLink": false,
"fileName": "testPROJECT.mpx",
"displayName": "testPROJECT.mpx",
"status": "",
"title": "testPROJECT.mpx",
"description": "",
"author": "",
"createdOn": "2014-06-10T15:17:33.791+01:00",
"createdBy": "Administrator",
"createdByUser": "admin",
"modifiedOn": "2014-06-10T15:17:42.258+01:00",
"modifiedBy": "Administrator",
"modifiedByUser": "admin",
"lockedBy": "",
"lockedByUser": "",
"size": "3555",
"version": "1.0",
"contentUrl": "api/node/content/workspace/SpacesStore/357b6dad-d434-4a46-a7e0-731df50e5e90/testPROJECT.mpx",
"webdavUrl": "\/webdav\/User%20Homes\/administrator\/testPROJECT.mpx",
"actionSet": "document",
"tags": [],
"activeWorkflows": "",
"isFavourite": false,
"likes":
{
"isLiked": false,
"totalLikes": 0
},
"location":
{
"repositoryId": "8ff64edd-57d3-4198-ac3d-8386f47bf5bb",
"site": "",
"siteTitle": "",
"container": "",
"path": "\/User Homes\/administrator",
"file": "testPROJECT.mpx",
"parent":
{
"nodeRef": "workspace:\/\/SpacesStore\/7f4e374c-7c7c-4356-bf8f-0ec6bfc5eac4"
}
},
"permissions":
{
"inherited": true,
"roles":
[
"ALLOWED;administrator;All;INHERITED",
"ALLOWED;ROLE_OWNER;All;INHERITED"
],
"userAccess":
{
"permissions": true,
"edit": true,
"delete": true,
"cancel-checkout": false,
"create": true
}
},
"custom": {},
"actionLabels":
{
}
}
}
I believe that's all the metadata and properties you're after. It's a webscript used by Share, so ought to be well tested and used. As you can see from the location section, it's a webscript which works for both site-based and non-site nodes equally
(If you do hit problems with it, probably best to ensure you're running the latest service pack if on enterprise, or newest release for community)

Related

Mule 3.7.3 - Dataveawe Message Transformer Encoding Wrongly

I am using mule to transform some webservice responses on my project, and currently i am using DataWeave message transformer.
JSON that i should transform :
{
"odata.metadata": "http://mchwtatmsdb/Across/CrossTank/api/v1/$metadata#Translations",
"value": [
{
"SourceSentence": {
"Id": 2750901,
"Text": "Refrigerator:",
"Language": 1033
},
"TargetSentence": {
"Id": 2750902,
"Text": "Kühlschrank:",
"Language": 1031
},
"Id": 2264817,
"Similarity": 100,
"CreationDate": "2009-02-25T12:56:15",
"Creator": "41e8d49d-0de7-4a96-a220-af96d94fe4b0",
"ModificationDate": "2009-02-25T12:56:15",
"Modificator": "00000000-0000-0000-0000-000000000000",
"State": "SmartInserted",
"Note": ""
},
{
"SourceSentence": {
"Id": 2750906,
"Text": "Refrigerator*",
"Language": 1033
},
"TargetSentence": {
"Id": 2750907,
"Text": "Kühlschrank*",
"Language": 1031
},
"Id": 2264822,
"Similarity": 100,
"CreationDate": "2009-02-25T12:55:46",
"Creator": "41e8d49d-0de7-4a96-a220-af96d94fe4b0",
"ModificationDate": "2009-02-25T12:55:46",
"Modificator": "00000000-0000-0000-0000-000000000000",
"State": "SmartInserted",
"Note": ""
}
]
}
I am basically using transformer, define metadatas respective to json files that is included in the project.
So transformer part is so simple :
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
{
"odata.metadata": payload."odata.metadata",
value: payload.value map ((value , indexOfValue) -> {
SourceSentence: {
Id: value.SourceSentence.Id,
Text: value.SourceSentence.Text as :string,
Language: value.SourceSentence.Language
},
TargetSentence: {
Id: value.TargetSentence.Id,
Text: value.TargetSentence.Text,
Language: value.TargetSentence.Language
},
Similarity: value.Similarity
})
}]]></dw:set-payload>
Transformation runs in expected way and it gets the necessary fields that i've set in dataweave transformer, after transformer implemented on json string, it changes the encoding somehow, and output doesn't show special characters. Such as:
{
"odata.metadata": "http://mchwtatmsdb/Across/CrossTank/api/v1/$metadata#Translations",
"value": [
{
"SourceSentence": {
"Id": 2750901,
"Text": "Refrigerator:",
"Language": 1033
},
"TargetSentence": {
"Id": 2750902,
"Text": "K252hlschrank:",
"Language": 1031
},
"Similarity": 100
},
{
"SourceSentence": {
"Id": 2750906,
"Text": "Refrigerator*",
"Language": 1033
},
"TargetSentence": {
"Id": 2750907,
"Text": "K252hlschrank*",
"Language": 1031
},
"Similarity": 100
}
]
}
"Text": "K252hlschrank*" part of the string is showing "ü" character as "252" i tried to run project both on the Windows an Linux environment. On linux, character is shown as "\u00" so i think this is somehow related OS problem. I've tried several things to fix the problem.
Tried to change project properties, set encoding to "UTF-8". It didn't work.
Tried to change run configuration, set encoding to "UTF-8". It didn't work.
Tried to give -Dfile.encoding="UTF-8" parameter into run parameters of Java, again it didn't work.
What is source of this problem, are transformers direclty using operating system's encoding ? Because without transformation, main json file represented as "ü", no encoding problem.
I solved this problem by changing my windows language settings to English(United Kingdom) from Turkish... Don't know how it is effected but it did the magic.

org.json JsonObject.has() returning true for key that doesn't exist

Edit - Resolved:
The issued turned out to be a combination of our logging code and how json.org handles the distinction between Javascript null and Javascript undefined. Our logging code didn't print null values in objects, so although the json object I saw had no "invoice" field, the actual input had a null "invoice" field. JSONObject's .has() method reported that there was an "invoice" field, but when I tried to access it, it's value was null so it wasn't possible to access it. Replacing the .has() check with a .isNull() check (which considers both absent fields and null values) resolved the problem.
In my Google App Engine application, we parse webhook data in the form of json and go down different code paths depending on the presence of a certain key in the json object - if $.data.object.invoice exists we do some work, otherwise we don't. However, when running in production, this detection seems to be broken. I do a simple
jsonObject.getJSONObject("data").getJSONObject("object").has("invoice")
to check for the invoice key and sometimes this returns true even when the invoice key doesn't exist. I came across this error because we do make use of the invoice value when it exists, and I was getting JSONExceptions trying to access it, even though it was protected by a has() check. I added the following logging to ensure that I was doing everything correct:
boolean isAutomaticCharge = jsonObject.getJSONObject("data").getJSONObject("object").has("invoice");
boolean doesGettingStringWork;
try {
jsonObject.getJSONObject("data").getJSONObject("object").getString("invoice");
doesGettingStringWork = true;
}
catch (JSONException e) {
doesGettingStringWork = false;
}
Logger.log("The value of automatic charge is: " + isAutomaticCharge);
Logger.log("Geting the invoice worked? " + doesGettingStringWork);
Logger.log(jsonObject.getJSONObject("data").getJSONObject("object").toString());
if (isAutomaticCharge) {
handleFailedCharge(jsonObject);
}
else {
//Manual Charge
}
And in production the following data resulted in isAutomaticCharge being true and doesGettingStringWork being false:
{
"id": "evt_16vC0s1WJGsEk3Qvnstmq6fa",
"object": "event",
"api_version": "2014-03-28",
"created": 1444678274,
"data": {
"object": {
"id": "ch_16vC0r1WJGsEk3Qv5rxezNQj",
"object": "charge",
"amount": 1900,
"amount_refunded": 0,
"captured": false,
"card": {
"id": "card_16vC0k1WJGsEk3Qvl9LLEt5K",
"object": "card",
"brand": "MasterCard",
"country": "CA",
"customer": "cus_79V0ZH6qFFA4K0",
"cvc_check": "fail",
"exp_month": 9,
"exp_year": 2016,
"fingerprint": "ifxs23sixYzpKant",
"funding": "credit",
"last4": "6912",
"metadata": {},
"name": "derek#footbole.com",
"type": "MasterCard"
},
"created": 1444678273,
"currency": "usd",
"customer": "cus_79V0ZH6qFFA4K0",
"failure_code": "card_declined",
"failure_message": "Your card was declined.",
"fraud_details": {},
"livemode": true,
"metadata": {},
"paid": false,
"refunded": false,
"refunds": [],
"source": {
"id": "card_16vC0k1WJGsEk3Qvl9LLEt5K",
"object": "card",
"brand": "MasterCard",
"country": "CA",
"customer": "cus_79V0ZH6qFFA4K0",
"cvc_check": "fail",
"exp_month": 9,
"exp_year": 2016,
"fingerprint": "ifxs23sixYzpKant",
"funding": "credit",
"last4": "6912",
"metadata": {},
"name": "derek#footbole.com",
"type": "MasterCard"
},
"status": "failed"
}
},
"livemode": true,
"pending_webhooks": 2,
"request": "req_79V0v7433eb9hZ",
"type": "charge.failed"
}
When I run the code locally and feed it that json, it works as expected with isAutomaticCharge and doesGettingStringWork both being false.
I'm running version 20140107 of org.json. I declare a new JSONObject for every request, so threading shouldn't be an issue. Has anyone else had issues running org.json on Google App Engine?

How can I send this params (parent,level,expanded,isLeaf) to server in jqGrid Tree Grid?

I can't send this params to server using jqTreeGrid and Java with Struts2:
level
parent
isLeaf
expanded
I have created a jqGrid TreeGrid using this documentation treegrid
This is my code:
jQuery("#treegrid2").jqGrid({
treeGrid: true,
treeGridModel : 'adjacency',
ExpandColumn : 'name',
url: './getTaskManagement.action',
editurl:'./sendActions.action',
datatype: "json",
jsonReader: {root: "listTask", repeatitems: false},
mtype: "POST",
colNames:["id","Task Division","PM", "Risk", "Duration","Start Date","End Date","NR","Comments","Parent","isLeaf","Level","Expanded"],
colModel:[
{name:'id',index:'id', width:1,hidden:true,key:true,editable:true},
{name:'name',index:'name', width:420,editable:true},
{name:'pm',index:'pm', width:80, align:"center",editable:true},
{name:'risk',index:'risk', width:60, align:"center",editable:true},
{name:'duration',index:'duration', width:80, align:"right",editable:true},
{name:'begin',index:'begin', width:80,align:"right",editable:true},
{name:'end',index:'end', width:80,align:"right",editable:true},
{name:'nr',index:'nr', width:80,align:"right",editable:true},
{name:'comments',index:'comments', width:170,align:"center",editable:true},
{name:'parent',index:'parent',hidden:true,editable:true},
{name:'isLeaf',index:'isLeaf',hidden:true,editable:true},
{name:'level',index:'level',hidden:true,editable:true},
{name:'expanded',index:'expanded',hidden:true,editable:true}
],
height:'auto',
viewrecords : true,
multiselect : true,
multiboxonly : true,
pager : "#ptreegrid2",
caption: "Example TreeGrid"
});
and this is the json result from server:
{
"actions": "success",
"rows": [
{
"begin": "2014-01-27",
"comments": "Some comments",
"duration": 20,
"end": "2014-02-17",
"expanded": "false",
"id": 1,
"isLeaf": "false",
"level": "0",
"name": "<b>A.Project Launch</b>",
"nr": "Some NR",
"parent": "",
"pm": "Some pm",
"risk": "Some risk"
},
{
"begin": "2014-01-27",
"comments": "Some comments",
"duration": 2,
"end": "2014-01-29",
"expanded": "false",
"id": 2,
"isLeaf": "true",
"level": "1",
"name": "Reverse SAMIR (if necessary): review what is in production",
"nr": "Some NR",
"parent": "1",
"pm": "Some pm",
"risk": "Some risk"
}
]
}
When I Try to edit a record using jqGrid pager I can send all params from colModel, except level, parent, isLeaf and expanded.
Request Header Form data:
id:1
name:A.Project Launch
pm:Some pm
risk:Some risk
duration:20
begin:2014-01-27
end:2014-02-17
nr:Some NR
comments:Some comments
oper:edit
and when I try to add new record send these params to server:
id:
name:a
pm:b
risk:c
duration:1
begin:e
end:f
nr:g
comments:h
parent:
oper:add
However never sends the other params (level,isLeaf,Expnaded), I need the params beacause I want to save an object with Java in database. so If these params are null obviusly in database are null too.
When I Try to retrieve the json data again (level,isLeaf,Expnaded,parent) are null and jqGrid TreeGrid don't respect the format because need these params for build correctly the Tree Grid.
Does somebody have an idea to solve this?
thanks and regards!!

In Rally how can get priority, severity drop list options using Web Services v2.0

Like priority can be High,Low ,Medium.
As shown in diagram , get value of state drop down list etc in Json form
something like this
"State": [{
"id": "1",
"name": "open",
},
{
"id": "2",
"name": "close",
}]
Need this kind of values using web services V2.0
You may query on TypeDefinition object using Name attribute:
https://rally1.rallydev.com/slm/webservice/v2.0/typedefinition?query=(Name = Defect)
which will return a reference to the TypeDefinition:
_ref": "https://rally1.rallydev.com/slm/webservice/v2.0/typedefinition/12352608495
Now if you use the ObjectID of the TypeDefinition you may get to Attributes collection:
https://rally1.rallydev.com/slm/webservice/v2.0/TypeDefinition/12352608495/Attributes
Using "Defect" instead of ObjectID of defect type def will not work.
Now you get attribute definitions of defect TypeDefinition. Here is an excerpt from the response, related to State attribute:
{
"_rallyAPIMajor": "2",
"_rallyAPIMinor": "0",
"_ref": "https://rally1.rallydev.com/slm/webservice/v2.0/attributedefinition/-12507",
"_objectVersion": "1",
"_refObjectName": "State",
"CreationDate": "2006-02-11T12:29:05.000Z",
"_CreatedAt": "Feb 11, 2006",
"ObjectID": -12507,
"Subscription": {...},
"Workspace": null,
"AllowedQueryOperators": {...},
"AllowedValueType": null,
"AllowedValues": {
"_rallyAPIMajor": "2",
"_rallyAPIMinor": "0",
"_ref": "https://rally1.rallydev.com/slm/webservice/v2.0/AttributeDefinition/-12507/AllowedValues",
"_type": "AllowedAttributeValue",
"Count": 4
},
"AttributeType": "RATING",
"Constrained": true,
"Custom": false,
"ElementName": "State",
"Filterable": true,
"Hidden": false,
"MaxFractionalDigits": -1,
"MaxLength": 128,
"Name": "State",
"Note": "State of the defect",
"Owned": true,
"ReadOnly": false,
"Required": true,
"SystemRequired": true,
"Type": "string",
"VisibleOnlyToAdmins": false,
"_type": "AttributeDefinition"
}
You can get the details of State attribute using this URL available from the response above:
https://rally1.rallydev.com/slm/webservice/v2.0/AttributeDefinition/-12507/AllowedValues
The Attributes endpoint returns the attribute definitions and allowed values for the default workspace if the workspace is not specified. The default workspace can be overridden with the "workspace" parameter.
Here is an example of getting AllowedValues for 'ScheduleState' in AppSDK2:
model.getField('ScheduleState').getAllowedValueStore().load({
callback: function(records, operation, success) {
Ext.Array.each(records, function(allowedValue) {
console.log(allowedValue.get('StringValue'));
});
You may see a full example of an app that builds a grid based on allowed values for Resolution field in this post.
For more details see Rally.domain.WsapiField
But when i had done the same thing i got response in which some of ElementName is missing like Priority,Severity etc. Any Solution on this.

SugarCRM REST API: get_relationships returns empty beans

I try to load contacts from a given account using the REST api of sugarcrm using Java. This "kind of" works... My test scenario should return two records. It does, but the records do a) not contain all fields and b) all the returned fields have empty values:
See the entry_list part of the returned JSON:
{"entry_list": [
{
"id": null,
"module_name": "Contacts",
"name_value_list": {
"name": {
"name": "name",
"value": ""
},
"deleted": {
"name": "deleted",
"value": 0
},
"do_not_call": {
"name": "do_not_call",
"value": "0"
}
}
},
{
"id": null,
"module_name": "Contacts",
"name_value_list": {
"name": {
"name": "name",
"value": ""
},
"deleted": {
"name": "deleted",
"value": 0
},
"do_not_call": {
"name": "do_not_call",
"value": "0"
}
}
}
Here is what I set as rest_data in my request:
rest_data.put("session", sessionId);
rest_data.put("module_name", moduleName);
rest_data.put("module_id", sourceId);
rest_data.put("link_field_name", relationField);
rest_data.put("related_module_query", "");
rest_data.put("related_fields", Arrays.asList());
rest_data.put("related_module_link_name_to_fields_array", Arrays.asList());
rest_data.put("offset", 0);
rest_data.put("order_by", "name ASC");
rest_data.put("limit", 0);
So I'd expect that I receive:
- all records -> works
- all fields for every record -> works not
- all values for all fields for every record -> works not
I'm using v4_1 of the REST api.
Does anybody have some hints on this?
Unlike get_entry_list works you cannot specify an empty array for the related_fields parameter. You must specify at least one field name.

Categories