How to get Atlassian Confluence Space permissions by REST API? - java

I'm using Atlassian Confluence REST API. I need to get Space permissions. I couldn't find any info on it in the documentation.
Does anyone know how to get these permissions?

I can see virtually no documentation about this, however having looked at the Confluence REST API Browser, I've got a working example below. You have to be a Confluence admin, or space admin for the space...
POST: http://localhost:1990/confluence/rpc/json-rpc/confluenceservice-v2/getSpacePermissionSets
BODY: [ "ds" ]
RESPONSE:
[
{
"type": "SETSPACEPERMISSIONS",
"spacePermissions": [
{
"type": "SETSPACEPERMISSIONS",
"userName": null,
"groupName": "confluence-administrators"
}
]
},
{
"type": "EXPORTSPACE",
"spacePermissions": [
{
"type": "EXPORTSPACE",
"userName": null,
"groupName": null
},
{
"type": "EXPORTSPACE",
"userName": null,
"groupName": "confluence-users"
},
{
"type": "EXPORTSPACE",
"userName": null,
"groupName": "confluence-administrators"
}
]
},
{
"type": "SETPAGEPERMISSIONS",
"spacePermissions": [
{
"type": "SETPAGEPERMISSIONS",
"userName": null,
"groupName": "confluence-users"
},
{
"type": "SETPAGEPERMISSIONS",
"userName": null,
"groupName": "confluence-administrators"
}
]
},
{
"type": "REMOVEMAIL",
"spacePermissions": [
{
"type": "REMOVEMAIL",
"userName": null,
"groupName": "confluence-users"
},
{
"type": "REMOVEMAIL",
"userName": null,
"groupName": "confluence-administrators"
},
{
"type": "REMOVEMAIL",
"userName": null,
"groupName": null
}
]
},
{
"type": "REMOVEBLOG",
"spacePermissions": [
{
"type": "REMOVEBLOG",
"userName": null,
"groupName": null
},
{
"type": "REMOVEBLOG",
"userName": null,
"groupName": "confluence-users"
},
{
"type": "REMOVEBLOG",
"userName": null,
"groupName": "confluence-administrators"
}
]
},
{
"type": "EXPORTPAGE",
"spacePermissions": [
{
"type": "EXPORTPAGE",
"userName": null,
"groupName": null
},
{
"type": "EXPORTPAGE",
"userName": null,
"groupName": "confluence-administrators"
},
{
"type": "EXPORTPAGE",
"userName": null,
"groupName": "confluence-users"
}
]
},
{
"type": "REMOVEATTACHMENT",
"spacePermissions": [
{
"type": "REMOVEATTACHMENT",
"userName": null,
"groupName": null
},
{
"type": "REMOVEATTACHMENT",
"userName": null,
"groupName": "confluence-administrators"
},
{
"type": "REMOVEATTACHMENT",
"userName": null,
"groupName": "confluence-users"
}
]
},
{
"type": "CREATEATTACHMENT",
"spacePermissions": [
{
"type": "CREATEATTACHMENT",
"userName": null,
"groupName": "confluence-users"
},
{
"type": "CREATEATTACHMENT",
"userName": null,
"groupName": null
},
{
"type": "CREATEATTACHMENT",
"userName": null,
"groupName": "confluence-administrators"
}
]
},
{
"type": "VIEWSPACE",
"spacePermissions": [
{
"type": "VIEWSPACE",
"userName": null,
"groupName": "confluence-administrators"
},
{
"type": "VIEWSPACE",
"userName": null,
"groupName": null
},
{
"type": "VIEWSPACE",
"userName": null,
"groupName": "confluence-users"
}
]
},
{
"type": "EDITBLOG",
"spacePermissions": [
{
"type": "EDITBLOG",
"userName": null,
"groupName": null
},
{
"type": "EDITBLOG",
"userName": null,
"groupName": "confluence-users"
},
{
"type": "EDITBLOG",
"userName": null,
"groupName": "confluence-administrators"
}
]
},
{
"type": "REMOVEPAGE",
"spacePermissions": [
{
"type": "REMOVEPAGE",
"userName": null,
"groupName": "confluence-administrators"
},
{
"type": "REMOVEPAGE",
"userName": null,
"groupName": null
},
{
"type": "REMOVEPAGE",
"userName": null,
"groupName": "confluence-users"
}
]
},
{
"type": "REMOVECOMMENT",
"spacePermissions": [
{
"type": "REMOVECOMMENT",
"userName": null,
"groupName": null
},
{
"type": "REMOVECOMMENT",
"userName": null,
"groupName": "confluence-users"
},
{
"type": "REMOVECOMMENT",
"userName": null,
"groupName": "confluence-administrators"
}
]
},
{
"type": "EDITSPACE",
"spacePermissions": [
{
"type": "EDITSPACE",
"userName": null,
"groupName": "confluence-users"
},
{
"type": "EDITSPACE",
"userName": null,
"groupName": "confluence-administrators"
},
{
"type": "EDITSPACE",
"userName": null,
"groupName": null
}
]
},
{
"type": "COMMENT",
"spacePermissions": [
{
"type": "COMMENT",
"userName": null,
"groupName": "confluence-users"
},
{
"type": "COMMENT",
"userName": null,
"groupName": "confluence-administrators"
},
{
"type": "COMMENT",
"userName": null,
"groupName": null
}
]
}
]
It's using the old JSON-RPC REST APIs which have been deprecated and will eventually be replaced. But when they are replaced, you can refactor, right?

Related

trying to read JSON data from url causes url redirection

I'm trying to read date from JSON using a URL , but it throws an exception. and the response from header is 301 Moved Permanently
this basically means the there is something wrong with link, but I cannot figure out what it is exactly since the API provider did not mention anything in regard to changes to their API
Any help is appreciated.
here is my code
private static String readUrl(String urlString) throws Exception {
BufferedReader reader = null;
try {
URL url = new URL(urlString);
reader = new BufferedReader(new InputStreamReader(url.openStream()));
StringBuffer buffer = new StringBuffer();
int read;
char[] chars = new char[1024];
while ((read = reader.read(chars)) != -1)
buffer.append(chars, 0, read);
return buffer.toString();
} finally {
if (reader != null)
reader.close();
}
}
String url = "http://webservice.fanart.tv/v3/movies/" + movie.id + "?api_key=" + apikey;
List<String> enClearLogos = new ArrayList<>();
try {
JSONObject json = new JSONObject(readUrl(url));
JSONArray jsonArray = json.getJSONArray("hdmovielogo");
for(int i = 0; i < jsonArray.length(); i++){
JSONObject movieObject = jsonArray.getJSONObject(i);
if (movieObject.getString("lang").equalsIgnoreCase("en"))
enClearLogos.add(movieObject.getString("url"));
}
} catch (Exception e) {
e.printStackTrace();
}
here example
{
"name": "The Bad Guys",
"tmdb_id": "629542",
"imdb_id": "tt8115900",
"hdmovieclearart": [
{
"id": "362695",
"url": "https://assets.fanart.tv/fanart/movies/629542/hdmovieclearart/the-bad-guys-6231fd4379a87.png",
"lang": "en",
"likes": "6"
},
{
"id": "362696",
"url": "https://assets.fanart.tv/fanart/movies/629542/hdmovieclearart/the-bad-guys-6231fd53d3a96.png",
"lang": "ru",
"likes": "3"
},
{
"id": "367992",
"url": "https://assets.fanart.tv/fanart/movies/629542/hdmovieclearart/the-bad-guys-6280fb431126b.png",
"lang": "cz",
"likes": "2"
}
],
"hdmovielogo": [
{
"id": "369396",
"url": "https://assets.fanart.tv/fanart/movies/629542/hdmovielogo/the-bad-guys-629dc8e4da93a.png",
"lang": "fr",
"likes": "3"
},
{
"id": "368375",
"url": "https://assets.fanart.tv/fanart/movies/629542/hdmovielogo/the-bad-guys-62899cfba2c00.png",
"lang": "en",
"likes": "3"
},
{
"id": "371110",
"url": "https://assets.fanart.tv/fanart/movies/629542/hdmovielogo/the-bad-guys-62bdec1d38353.png",
"lang": "es",
"likes": "2"
},
{
"id": "355025",
"url": "https://assets.fanart.tv/fanart/movies/629542/hdmovielogo/the-bad-guys-61ba168a41d9b.png",
"lang": "ru",
"likes": "2"
},
{
"id": "355031",
"url": "https://assets.fanart.tv/fanart/movies/629542/hdmovielogo/the-bad-guys-61ba1f851cd32.png",
"lang": "en",
"likes": "2"
},
{
"id": "355032",
"url": "https://assets.fanart.tv/fanart/movies/629542/hdmovielogo/the-bad-guys-61ba1f96a497e.png",
"lang": "en",
"likes": "1"
},
{
"id": "366828",
"url": "https://assets.fanart.tv/fanart/movies/629542/hdmovielogo/the-bad-guys-626984d807f4d.png",
"lang": "cz",
"likes": "1"
},
{
"id": "360922",
"url": "https://assets.fanart.tv/fanart/movies/629542/hdmovielogo/the-bad-guys-6217a7c5ba60d.png",
"lang": "it",
"likes": "0"
}
],
"movieposter": [
{
"id": "367357",
"url": "https://assets.fanart.tv/fanart/movies/629542/movieposter/the-bad-guys-6274ea20dcc86.jpg",
"lang": "en",
"likes": "2"
},
{
"id": "371114",
"url": "https://assets.fanart.tv/fanart/movies/629542/movieposter/the-bad-guys-62bdecfbd6715.jpg",
"lang": "es",
"likes": "2"
},
{
"id": "368000",
"url": "https://assets.fanart.tv/fanart/movies/629542/movieposter/the-bad-guys-628108a944560.jpg",
"lang": "pt",
"likes": "2"
},
{
"id": "367358",
"url": "https://assets.fanart.tv/fanart/movies/629542/movieposter/the-bad-guys-6274ea33e2ed5.jpg",
"lang": "00",
"likes": "2"
},
{
"id": "355026",
"url": "https://assets.fanart.tv/fanart/movies/629542/movieposter/the-bad-guys-61ba169a2b57e.jpg",
"lang": "en",
"likes": "2"
},
{
"id": "358210",
"url": "https://assets.fanart.tv/fanart/movies/629542/movieposter/the-bad-guys-61ee6f9a14706.jpg",
"lang": "00",
"likes": "1"
},
{
"id": "367991",
"url": "https://assets.fanart.tv/fanart/movies/629542/movieposter/the-bad-guys-6280fb200c5bf.jpg",
"lang": "cz",
"likes": "0"
},
{
"id": "367990",
"url": "https://assets.fanart.tv/fanart/movies/629542/movieposter/the-bad-guys-6280fb1ba6d39.jpg",
"lang": "cz",
"likes": "0"
}
],
"moviethumb": [
{
"id": "371117",
"url": "https://assets.fanart.tv/fanart/movies/629542/moviethumb/the-bad-guys-62bdee5332ad2.jpg",
"lang": "es",
"likes": "2"
},
{
"id": "367994",
"url": "https://assets.fanart.tv/fanart/movies/629542/moviethumb/the-bad-guys-6280fb7b224fd.jpg",
"lang": "cz",
"likes": "1"
},
{
"id": "370972",
"url": "https://assets.fanart.tv/fanart/movies/629542/moviethumb/the-bad-guys-62bbbc9385121.jpg",
"lang": "en",
"likes": "0"
},
{
"id": "367260",
"url": "https://assets.fanart.tv/fanart/movies/629542/moviethumb/the-bad-guys-6272bfb851ca5.jpg",
"lang": "en",
"likes": "0"
}
],
"moviebackground": [
{
"id": "355027",
"url": "https://assets.fanart.tv/fanart/movies/629542/moviebackground/the-bad-guys-61ba16ab7df92.jpg",
"lang": "",
"likes": "2"
},
{
"id": "367177",
"url": "https://assets.fanart.tv/fanart/movies/629542/moviebackground/the-bad-guys-6271f6e99b835.jpg",
"lang": "",
"likes": "0"
}
],
"moviedisc": [
{
"id": "367993",
"url": "https://assets.fanart.tv/fanart/movies/629542/moviedisc/the-bad-guys-6280fb602b271.png",
"lang": "cz",
"likes": "1",
"disc": "1",
"disc_type": "bluray"
},
{
"id": "358213",
"url": "https://assets.fanart.tv/fanart/movies/629542/moviedisc/the-bad-guys-61ee85436574f.png",
"lang": "en",
"likes": "0",
"disc": "1",
"disc_type": "bluray"
}
],
"moviebanner": [
{
"id": "358216",
"url": "https://assets.fanart.tv/fanart/movies/629542/moviebanner/the-bad-guys-61ee93348cb62.jpg",
"lang": "en",
"likes": "1"
},
{
"id": "370973",
"url": "https://assets.fanart.tv/fanart/movies/629542/moviebanner/the-bad-guys-62bbbd7215d83.jpg",
"lang": "en",
"likes": "0"
}
]
}
exception message
W/System.err: org.json.JSONException: Value <html> of type java.lang.String cannot be converted to JSONObject
W/System.err: at org.json.JSON.typeMismatch(JSON.java:112)
W/System.err: at org.json.JSONObject.<init>(JSONObject.java:168)
W/System.err: at org.json.JSONObject.<init>(JSONObject.java:181)
The http:// causes url redirection and throws this message in the header response (301 Moved Permanently) so I had to use https:// instead now everything works nicely.
more info here Response 301 Moved Permanently

How to retrieve user entered input in adaptive card in java

Attached the JSON of adaptive card I sent in teams.
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "Container",
"items": [
{
"type": "TextBlock",
"text": "Publish Adaptive Card schema",
"weight": "bolder",
"size": "medium"
},
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"width": "auto",
"items": [
{
"type": "Image",
"url": "https://pbs.twimg.com/profile_images/3647943215/d7f12830b3c17a5a9e4afcc370e3a37e_400x400.jpeg",
"size": "medium",
"style": "person"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Matt Hidinger",
"weight": "bolder",
"wrap": true
},
{
"type": "TextBlock",
"spacing": "none",
"text": "Created Tuesday, Feb 14, 2017",
"isSubtle": true,
"wrap": true
}
]
}
]
}
]
},
{
"type": "Container",
"items": [
{
"type": "TextBlock",
"text": "Now that we have defined the main rules and features of the format, we need to produce a schema and publish it to GitHub. The schema will be the starting point of our reference documentation.",
"wrap": true
},
{
"type": "FactSet",
"facts": [
{
"title": "Board:",
"value": "Adaptive Card"
},
{
"title": "List:",
"value": "Backlog"
},
{
"title": "Assigned to:",
"value": "Matt Hidinger"
},
{
"title": "Due date:",
"value": "Not set"
}
]
}
]
}
],
"actions": [
{
"type": "Action.ShowCard",
"title": "Set due date",
"card": {
"version": "1.0",
"type": "AdaptiveCard",
"body": [
{
"type": "Input.Date",
"id": "dueDate",
"title": "Select due date"
}
],
"actions": [
{
"type": "Action.Submit",
"title": "OK"
}
]
}
},
{
"type": "Action.ShowCard",
"title": "Comment",
"card": {
"version": "1.0",
"type": "AdaptiveCard",
"body": [
{
"type": "Input.Text",
"id": "comment",
"isMultiline": true,
"placeholder": "Enter your comment"
}
],
"actions": [
{
"type": "Action.Submit",
"title": "OK"
}
]
}
},
{
"type": "Action.OpenUrl",
"title": "View",
"url": "http://adaptivecards.io"
}
]
}
After User entered values and click ok, reply from bot is "Echo:"
How can i display the entered value as reply from bot.
I have implemented this to get activity, but this method is not called when use click ok.

How to parse a JSON with SCIM Schemas in java

I have the following json which get from endpoint,
{
"schemas": [
"urn:ietf:params:scim:api:messages:2.0:response",
"urn:scim:schemas:extension:customattrs:2.0:User"
],
"meta": {
"resourceType": "User",
"created": "2011-08-01T18:29:49.793Z",
"lastModified": "2011-08-01T18:29:49.793Z",
"version": "W/\"f250dd84f0671c3\""
},
"userName": "bjensen",
"phoneNumbers": [
{
"value": "555-555-8377",
"type": "work"
}
],
"emails": [
{
"value": "bjensen#example.com",
"type": "work",
"primary": true
}
],
"urn:scim:schemas:extension:customattrs:2.0:User": {
"userName": "bjensen",
"address": ""
}
}
please suggest me to parse the json along with schemas "urn:scim:schemas:extension:customattrs:2.0:User" into java object

Insert object to nested array

I'm trying to insert an object to a nested array through the java api, but I get the following error
MapperParsingException[object mapping for [X] tried to parse field [null] as object, but found a concrete value]
doing it through Kibana as shown below the same script works.
Any ideas on how to fix this?
The java code is the following
HashMap<String, Object> params = new HashMap<>();
params.put("object", objectAsString);
Script script = new Script(ScriptType.INLINE, "painless", "ctx._source.media.add(params.object)", params);
UpdateResponse result = elasticClient.prepareUpdate(indexName, "Type", documentId).setScript(script).execute().actionGet();
Trhough Kibana
POST index/document/id/_update
{
"script": {
"lang": "painless",
"inline": "ctx._source.media.add(params.object)",
"params": {
"object": {
"description" : "A second image",
"height" : 5,
"weight": 5,
"name" : "Test",
"orientation" : "Vertical",
"url" : "htttp://newurl.jpg",
"tags":["first","second"],
"type":"image"
}
}
}
}
The template mapping is the following:
"mappings": {
"FOLDER_MODULE": {
"properties": {
"name": {
"type": "keyword"
},
"publisherId": {
"type": "keyword"
},
"username": {
"type": "keyword"
},
"media": {
"type": "nested",
"properties": {
"id": {
"type": "text"
},
"name": {
"type": "text"
},
"publisherId": {
"type": "short"
},
"tags": {
"type": "text"
},
"description": {
"type": "text"
},
"url": {
"type": "keyword"
},
"createdDate": {
"format": "strict_date_optional_time||epoch_millis",
"type": "date"
},
"height": {
"type": "float"
},
"width": {
"type": "float"
},
"weight": {
"type": "float"
},
"orientation": {
"type": "keyword"
},
"status": {
"type": "keyword"
},
"type": {
"type": "keyword"
},
"username": {
"type": "keyword"
}
}
}
}
}
}

Precondition on data pipeline

I did some set of activities on json script. Need to add precondition on it.
how to use precondition on json script.
In precondition, i need to check the mysql db field. once flag as 'Y',
start execution else should be stop the execution.
You can use a ShellCommandPrecondition for this which will let you write a custom precondition.
{
"objects": [
{
"schedule": {
"ref": "DefaultSchedule"
},
"resourceRole": "DataPipelineDefaultResourceRole",
"role": "DataPipelineDefaultRole",
"name": "DefaultResource1",
"id": "ResourceId_dWoZ0",
"type": "Ec2Resource",
"terminateAfter": "1 Hour"
},
{
"name": "DefaultPrecondition1",
"id": "PreconditionId_yA2rV",
"type": "ShellCommandPrecondition",
"command": "<Script to check mysql field>"
},
{
"occurrences": "1",
"period": "1 Day",
"name": "RunOnce",
"id": "DefaultSchedule",
"type": "Schedule",
"startAt": "FIRST_ACTIVATION_DATE_TIME"
},
{
"failureAndRerunMode": "CASCADE",
"schedule": {
"ref": "DefaultSchedule"
},
"resourceRole": "DataPipelineDefaultResourceRole",
"role": "DataPipelineDefaultRole",
"pipelineLogUri": "s3://<mybucket>",
"scheduleType": "cron",
"name": "Default",
"id": "Default"
},
{
"schedule": {
"ref": "DefaultSchedule"
},
"name": "DefaultActivity1",
"runsOn": {
"ref": "ResourceId_dWoZ0"
},
"precondition": {
"ref": "PreconditionId_yA2rV"
},
"id": "ActivityId_gmQ0W",
"type": "ShellCommandActivity",
"command": "echo 'Hello world'"
}
],
"parameters": []
}

Categories