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;
}
Aggregations