Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
Cesar Quinteiro
How to fill fieldsMap to fill up a JSON DLAppServiceUtil#addFileEntry
February 11, 2013 9:05 AM
Answer

Cesar Quinteiro

Rank: Junior Member

Posts: 30

Join Date: October 18, 2011

Recent Posts

In the JSON API ( http://localhost:8080/api/jsonws?signature=/dlapp/add-file-entry-9-repositoryId-folderId-sourceFileName-mimeType-title-description-changeLog-bytes-serviceContext ) it says:

….and expando bridge attributes for the file entry. In a Liferay repository, it may include:

fileEntryTypeId - ID for a custom file entry type
fieldsMap - mapping for fields associated with a custom file entry type

I am able to fill up fileEntryTypeId but I don’t found the way to fill fieldsMap

1) create a custom field in the FileEntryTypeId = 14534 with the name “cfParticipantes”

then I call the JSON with the following code:
 1public static void addDLFileEntry(String groupId, String folderId, String title, String description, String fileEntryTypeId, String file, String is, String size, String scopeGroupId, String mimeType,String sTRBytes, String STRBytes) throws Exception {
 2   
 3   
 4    HttpHost targetHost = new HttpHost("localhost",8080,"http");
 5    DefaultHttpClient httpclient = new DefaultHttpClient();
 6    httpclient.getCredentialsProvider().setCredentials(
 7            new AuthScope(targetHost.getHostName(), targetHost.getPort()),
 8            new UsernamePasswordCredentials("test@liferay.com", “****"));
 9
10    // Create AuthCache instance
11    AuthCache authCache = new BasicAuthCache();
12    // Generate BASIC scheme object and add it to the local
13    // auth cache
14    BasicScheme basicAuth = new BasicScheme();
15    authCache.put(targetHost, basicAuth);
16
17    // Add AuthCache to the execution context
18    BasicHttpContext ctx = new BasicHttpContext();
19    ctx.setAttribute(ClientContext.AUTH_CACHE, authCache);
20    HttpPost post = new HttpPost("/api/secure/jsonws/dlapp/add-file-entry");
21    List<NameValuePair> params = new ArrayList<NameValuePair>();
22
23    params.add(new BasicNameValuePair("repositoryId","10179"));// "19"));
24    params.add(new BasicNameValuePair("folderId",folderId));
25    params.add(new BasicNameValuePair("sourceFileName", "/Applications/Liferay/liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/webapps/pdfs/ACTANum126.pdf"));
26    params.add(new BasicNameValuePair("mimeType", mimeType));
27   
28    params.add(new BasicNameValuePair("title", title+new Date().getTime()));
29    params.add(new BasicNameValuePair("description", "description"));
30    params.add(new BasicNameValuePair("changeLog", "file"));
31 //   nvps.add(new BasicNameValuePair("data", se));
32    params.add(new BasicNameValuePair("bytes", sTRBytes));//STRBytes));
33   // params.add(new BasicNameValuePair("serviceContext.scopeGroupId", "10179"));
34   params.add(new BasicNameValuePair("fileEntryTypeId", "14534")); 
35    params.add(new BasicNameValuePair("fieldsMap","[{\"cfParticipantes\":\"cesar\"}"));  ///!!!!!!!!!!!!!!!!!!!!!!!!! >>>>>>>>>> I fill that values here and previous line
36    UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF-8");
37//    entity.addPart( "bytes", new StringBody( paramValue.toString(), "text/plain",
38//            Charset.forName( "UTF-8" )));
39
40   
41    post.setEntity(entity);
42    HttpResponse resp = httpclient.execute(targetHost, post, ctx);
43    System.out.println(resp.getStatusLine());
44    resp.getEntity().writeTo(System.out);
45    httpclient.getConnectionManager().shutdown();
46
47}


params.add(new BasicNameValuePair("fileEntryTypeId", "14534")); works fine I get the DLFileEntry created assigned to that type of document, but:
params.add(new BasicNameValuePair("fieldsMap","[{\"cfParticipantes\":\"cesar\"}")); doesn’t work, I don’t get any data in that custom field.

How do you fill up this custom fields?