Search in sources :

Example 6 with LinkInfo

use of org.alfresco.service.cmr.links.LinkInfo in project alfresco-remote-api by Alfresco.

the class LinksPost method executeImpl.

@Override
protected Map<String, Object> executeImpl(SiteInfo site, String linkName, WebScriptRequest req, JSONObject json, Status status, Cache cache) {
    final ResourceBundle rb = getResources();
    Map<String, Object> model = new HashMap<String, Object>();
    // Get the new link details from the JSON
    String title;
    String description;
    String url;
    boolean internal;
    List<String> tags;
    // Fetch the main properties
    title = getOrNull(json, "title");
    description = getOrNull(json, "description");
    url = getOrNull(json, "url");
    // Handle internal / not internal
    internal = json.containsKey("internal");
    // Do the tags
    tags = getTags(json);
    // Create the link
    LinkInfo link;
    try {
        link = linksService.createLink(site.getShortName(), title, description, url, internal);
    } catch (AccessDeniedException e) {
        String message = "You don't have permission to create a link";
        status.setCode(Status.STATUS_FORBIDDEN);
        status.setMessage(message);
        model.put(PARAM_MESSAGE, rb.getString(MSG_ACCESS_DENIED));
        return model;
    }
    // Set the tags if required
    if (tags != null && tags.size() > 0) {
        link.getTags().addAll(tags);
        linksService.updateLink(link);
    }
    // Generate an activity for the change
    addActivityEntry("created", link, site, req, json);
    // Build the model
    // Really!
    model.put(PARAM_MESSAGE, link.getSystemName());
    model.put(PARAM_ITEM, renderLink(link));
    model.put("node", link.getNodeRef());
    model.put("link", link);
    model.put("site", site);
    model.put("siteId", site.getShortName());
    // All done
    return model;
}
Also used : AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) HashMap(java.util.HashMap) ResourceBundle(java.util.ResourceBundle) JSONObject(org.json.simple.JSONObject) LinkInfo(org.alfresco.service.cmr.links.LinkInfo)

Aggregations

HashMap (java.util.HashMap)6 LinkInfo (org.alfresco.service.cmr.links.LinkInfo)6 JSONObject (org.json.simple.JSONObject)6 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)4 ResourceBundle (java.util.ResourceBundle)3 ArrayList (java.util.ArrayList)2 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)2 Date (java.util.Date)1 Map (java.util.Map)1 PagingRequest (org.alfresco.query.PagingRequest)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 JSONArray (org.json.simple.JSONArray)1