Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
Cesar Quinteiro
How to send more than one actionId to a JSON service
February 25, 2013 4:37 PM
Answer

Cesar Quinteiro

Rank: Junior Member

Posts: 32

Join Date: October 18, 2011

Recent Posts

I have the following code that works fine:

 1public static void setPermision() throws Exception
 2{
 3    HttpHost targetHost = new HttpHost("localhost",8080,"http");
 4    DefaultHttpClient httpclient = new DefaultHttpClient();
 5    httpclient.getCredentialsProvider().setCredentials(
 6            new AuthScope(targetHost.getHostName(), targetHost.getPort()),
 7            new UsernamePasswordCredentials("test@liferay.com", "brasin"));
 8
 9    // Create AuthCache instance
10    AuthCache authCache = new BasicAuthCache();
11    // Generate BASIC scheme object and add it to the local
12    // auth cache
13    BasicScheme basicAuth = new BasicScheme();
14    authCache.put(targetHost, basicAuth);
15
16    // Add AuthCache to the execution context
17    BasicHttpContext ctx = new BasicHttpContext();
18    ctx.setAttribute(ClientContext.AUTH_CACHE, authCache);
19    HttpPost post = new HttpPost("/api/secure/jsonws/resourcepermission/set-individual-resource-permissions");
20    List<NameValuePair> params = new ArrayList<NameValuePair>();
21    params.add(new BasicNameValuePair("groupId", "10179"));
22    params.add(new BasicNameValuePair("companyId","10153")); //@@ ADAPT
23    params.add(new BasicNameValuePair("name", "com.liferay.portlet.documentlibrary.model.DLFileEntry"));
24    params.add(new BasicNameValuePair("primKey", "19503"));
25    // 10169 es el rol "site member" por defecto, si esto cambiara adaptar en consecuencia
26   
27    params.add(new BasicNameValuePair("roleIdsToActionIds", "{10169:ADD_DISCUSSION}"));//,10169:DELETE_DISCUSSION}"));
28    UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF-8");
29
30   
31    post.setEntity(entity);
32    HttpResponse resp = httpclient.execute(targetHost, post, ctx);
33    System.out.println(resp.getStatusLine());
34    OutputStream respuesta = new ByteArrayOutputStream();
35    resp.getEntity().writeTo(respuesta);
36
37    System.err.println("contenido respuestas" +respuesta.toString());
38    httpclient.getConnectionManager().shutdown();
39}

the problem is that I don’t found the correct way to send more than one actionId I try with:
1params.add(new BasicNameValuePair("roleIdsToActionIds", "{10169:ADD_DISCUSSION,10169:DELETE_DISCUSSION}")); ---> I get duplicate Key error
2
3  params.add(new BasicNameValuePair("roleIdsToActionIds", "{10169:ADD_DISCUSSION, VIEW}")); ---> I get :{"exception":"Expected a ':' after a key at character 27”}
4
5params.add(new BasicNameValuePair("roleIdsToActionIds", "{10169:[ADD_DISCUSSION, VIEW]}")); ---> I get :  respuestas{"exception":"com.liferay.portal.NoSuchResourceActionException: com.liferay.portlet.documentlibrary.model.dlfileentry#[add_discussion”}

How can you send more than one Id for one RoleID?