Search in sources :

Example 1 with LinkInfo

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

the class LinkGet method executeImpl.

@Override
protected Map<String, Object> executeImpl(SiteInfo site, String linkName, WebScriptRequest req, JSONObject json, Status status, Cache cache) {
    Map<String, Object> model = new HashMap<String, Object>();
    // Try to find the link
    LinkInfo link = linksService.getLink(site.getShortName(), linkName);
    if (link == null) {
        String message = "No link found with that name";
        throw new WebScriptException(Status.STATUS_NOT_FOUND, message);
    }
    // Build the model
    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 : WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap) JSONObject(org.json.simple.JSONObject) LinkInfo(org.alfresco.service.cmr.links.LinkInfo)

Example 2 with LinkInfo

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

the class LinksDeletePost 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 requested nodes from the JSON
    // Silently skips over any invalid ones specified
    List<LinkInfo> links = new ArrayList<LinkInfo>();
    if (json.containsKey("items")) {
        JSONArray items = (JSONArray) json.get("items");
        for (int i = 0; i < items.size(); i++) {
            String name = (String) items.get(i);
            LinkInfo link = linksService.getLink(site.getShortName(), name);
            if (link != null) {
                links.add(link);
            }
        }
    }
    // Check we got at least one link, and bail if not
    if (links.size() == 0) {
        String message = "No valid link names supplied";
        status.setCode(Status.STATUS_NOT_FOUND);
        status.setMessage(message);
        model.put(PARAM_MESSAGE, rb.getString(MSG_NAME_NOT_FOUND));
        return model;
    }
    // Delete each one in turn
    for (LinkInfo link : links) {
        // Do the delete
        try {
            linksService.deleteLink(link);
        } catch (AccessDeniedException e) {
            String message = "You don't have permission to delete the link with name '" + link.getTitle() + "'";
            status.setCode(Status.STATUS_FORBIDDEN);
            status.setMessage(message);
            message = rb.getString(MSG_ACCESS_DENIED);
            model.put(PARAM_MESSAGE, MessageFormat.format(message, link.getTitle()));
            return model;
        }
        // Generate the activity entry for it
        addActivityEntry("deleted", link, site, req, json);
        // Record a message (only the last one is used though!)
        String message = rb.getString(MSG_DELETED);
        model.put(PARAM_MESSAGE, MessageFormat.format(message, link.getNodeRef()));
    }
    // All done
    model.put("siteId", site.getShortName());
    model.put("site", site);
    return model;
}
Also used : AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JSONArray(org.json.simple.JSONArray) ResourceBundle(java.util.ResourceBundle) JSONObject(org.json.simple.JSONObject) LinkInfo(org.alfresco.service.cmr.links.LinkInfo)

Example 3 with LinkInfo

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

the class LinksListGet method executeImpl.

@Override
protected Map<String, Object> executeImpl(SiteInfo site, String linkName, WebScriptRequest req, JSONObject json, Status status, Cache cache) {
    // Decide on what kind of request they wanted
    String filter = req.getParameter("filter");
    // Tagging?
    boolean tagFiltering = true;
    String tag = req.getParameter("tag");
    if (tag == null || tag.length() == 0) {
        tagFiltering = false;
    }
    // User?
    boolean userFiltering = false;
    String user = null;
    if ("user".equals(filter)) {
        userFiltering = true;
        user = AuthenticationUtil.getFullyAuthenticatedUser();
    }
    // Date?
    boolean dateFiltering = false;
    Date from = null;
    Date to = null;
    if ("recent".equals(filter)) {
        dateFiltering = true;
        Date now = new Date();
        from = new Date(now.getTime() - RECENT_SEARCH_PERIOD_DAYS * ONE_DAY_MS);
        to = new Date(now.getTime() + ONE_DAY_MS);
    }
    // Get the links for the list
    PagingRequest paging = buildPagingRequest(req);
    paging.setRequestTotalCountMax(paging.getSkipCount() + paging.getRequestTotalCountMax());
    PagingResults<LinkInfo> links;
    if (tagFiltering) {
        links = linksService.findLinks(site.getShortName(), user, from, to, tag, paging);
    } else {
        if (userFiltering) {
            links = linksService.listLinks(site.getShortName(), user, paging);
        } else if (dateFiltering) {
            links = linksService.listLinks(site.getShortName(), from, to, paging);
        } else {
            links = linksService.listLinks(site.getShortName(), paging);
        }
    }
    // For each one in our page, grab details of any ignored instances
    List<Map<String, Object>> items = new ArrayList<Map<String, Object>>();
    for (LinkInfo link : links.getPage()) {
        Map<String, Object> result = renderLink(link);
        items.add(result);
    }
    Map<String, Object> data = new HashMap<String, Object>();
    data.put("items", items);
    data.put("pageSize", paging.getMaxItems());
    data.put("startIndex", paging.getSkipCount());
    data.put("itemCount", items.size());
    int total = items.size();
    if (links.getTotalResultCount() != null && links.getTotalResultCount().getFirst() != null) {
        total = links.getTotalResultCount().getFirst();
    }
    data.put("total", total);
    if (total == paging.getRequestTotalCountMax()) {
        data.put("totalRecordsUpper", true);
    } else {
        data.put("totalRecordsUpper", false);
    }
    // We need the container node for permissions checking
    NodeRef container;
    if (links.getPage().size() > 0) {
        container = links.getPage().get(0).getContainerNodeRef();
    } else {
        // Find the container (if it's been created yet)
        container = siteService.getContainer(site.getShortName(), LinksServiceImpl.LINKS_COMPONENT);
        if (container == null) {
            // Brand new site, no write operations on links have happened
            // Fudge it for now with the site itself, the first write call
            // will have the container created
            container = site.getNodeRef();
        }
    }
    // All done
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("data", data);
    model.put("links", container);
    model.put("siteId", site.getShortName());
    model.put("site", site);
    return model;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LinkInfo(org.alfresco.service.cmr.links.LinkInfo) Date(java.util.Date) PagingRequest(org.alfresco.query.PagingRequest) NodeRef(org.alfresco.service.cmr.repository.NodeRef) JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with LinkInfo

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

the class LinkDelete method executeImpl.

@Override
protected Map<String, Object> executeImpl(SiteInfo site, String linkName, WebScriptRequest req, JSONObject json, Status status, Cache cache) {
    Map<String, Object> model = new HashMap<String, Object>();
    // Try to find the link
    LinkInfo link = linksService.getLink(site.getShortName(), linkName);
    if (link == null) {
        String message = "No link found with that name";
        throw new WebScriptException(Status.STATUS_NOT_FOUND, message);
    }
    // Delete it
    try {
        linksService.deleteLink(link);
    } catch (AccessDeniedException e) {
        String message = "You don't have permission to delete that link";
        throw new WebScriptException(Status.STATUS_FORBIDDEN, message);
    }
    // Mark it as gone
    status.setCode(Status.STATUS_NO_CONTENT);
    return model;
}
Also used : AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap) JSONObject(org.json.simple.JSONObject) LinkInfo(org.alfresco.service.cmr.links.LinkInfo)

Example 5 with LinkInfo

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

the class LinkPut 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>();
    // Try to find the link
    LinkInfo link = linksService.getLink(site.getShortName(), linkName);
    if (link == null) {
        String message = "No link found with that name";
        status.setCode(Status.STATUS_NOT_FOUND);
        status.setMessage(message);
        model.put(PARAM_MESSAGE, rb.getString(MSG_NOT_FOUND));
        return model;
    }
    // Get the new link details from the JSON
    // Update the main properties
    link.setTitle(getOrNull(json, "title"));
    link.setDescription(getOrNull(json, "description"));
    String url = getOrNull(json, "url");
    link.setURL(url);
    // Handle internal / not internal
    if (json.containsKey("internal")) {
        link.setInternal(true);
    } else {
        link.setInternal(false);
    }
    // Do the tags
    link.getTags().clear();
    List<String> tags = getTags(json);
    if (tags != null && tags.size() > 0) {
        link.getTags().addAll(tags);
    }
    // Update the link
    try {
        link = linksService.updateLink(link);
    } catch (AccessDeniedException e) {
        String message = "You don't have permission to update that link";
        status.setCode(Status.STATUS_FORBIDDEN);
        status.setMessage(message);
        model.put(PARAM_MESSAGE, rb.getString(MSG_ACCESS_DENIED));
        return model;
    }
    // Generate an activity for the change
    addActivityEntry("updated", link, site, req, json);
    // Build the model
    model.put(PARAM_MESSAGE, "Node " + link.getNodeRef() + " updated");
    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