Search in sources :

Example 1 with SavedSearchDetails

use of org.alfresco.module.org_alfresco_module_rm.search.SavedSearchDetails in project records-management by Alfresco.

the class RMv2SavedSearchPatch method executePatch.

/**
 * @see org.alfresco.repo.module.AbstractModuleComponent#executeInternal()
 */
@Override
protected void executePatch() {
    if (siteService.getSite(DEFAULT_SITE_NAME) != null) {
        // get the saved searches
        List<SavedSearchDetails> savedSearches = recordsManagementSearchService.getSavedSearches(DEFAULT_SITE_NAME);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("  ... updating " + savedSearches.size() + " saved searches");
        }
        for (SavedSearchDetails savedSearchDetails : savedSearches) {
            // refresh the query
            String refreshedJSON = savedSearchDetails.toJSONString();
            NodeRef nodeRef = savedSearchDetails.getNodeRef();
            if (nodeRef != null) {
                ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
                writer.putContent(refreshedJSON);
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("    ... updated saved search " + savedSearchDetails.getName() + " (nodeRef=" + nodeRef.toString() + ")");
                }
            }
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) SavedSearchDetails(org.alfresco.module.org_alfresco_module_rm.search.SavedSearchDetails)

Example 2 with SavedSearchDetails

use of org.alfresco.module.org_alfresco_module_rm.search.SavedSearchDetails in project records-management by Alfresco.

the class RMv23SavedSearchesPatchUnitTest method executePatch.

/**
 * Given that I am upgrading an existing repository to v2.3
 * When I execute the patch
 * Then any existing rm saved searches will have the saved search aspect applied
 */
@Test
public void executePatch() {
    MockitoAnnotations.initMocks(this);
    NodeRef noderef1 = new NodeRef("foo://123/456");
    NodeRef noderef2 = new NodeRef("bar://123/456");
    List<SavedSearchDetails> searches = asList(mockSavedSearchDetails1, mockSavedSearchDetails2);
    when(mockSavedSearchDetails1.getNodeRef()).thenReturn(noderef1);
    when(mockSavedSearchDetails2.getNodeRef()).thenReturn(noderef2);
    when(recordsManagementSearchService.getSavedSearches("rm")).thenReturn(searches);
    // execute patch
    patch.applyInternal();
    verify(nodeService, times(1)).addAspect(noderef1, ASPECT_SAVED_SEARCH, null);
    verify(nodeService, times(1)).addAspect(noderef2, ASPECT_SAVED_SEARCH, null);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) SavedSearchDetails(org.alfresco.module.org_alfresco_module_rm.search.SavedSearchDetails) Test(org.junit.Test)

Example 3 with SavedSearchDetails

use of org.alfresco.module.org_alfresco_module_rm.search.SavedSearchDetails in project records-management by Alfresco.

the class RMSavedSearchesGet method executeImpl.

/*
     * @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.Status, org.alfresco.web.scripts.Cache)
     */
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    // create model object with the lists model
    Map<String, Object> model = new HashMap<String, Object>(13);
    // Get the site id and confirm it is valid
    Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
    String siteId = templateVars.get("site");
    if (siteId == null || siteId.length() == 0) {
        throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Site id not provided.");
    }
    if (siteService.getSite(siteId) == null) {
        throw new WebScriptException(Status.STATUS_NOT_FOUND, "Site not found.");
    }
    // Get the saved search details
    List<SavedSearchDetails> details = recordsManagementSearchService.getSavedSearches(siteId);
    List<Item> items = new ArrayList<Item>();
    for (SavedSearchDetails savedSearchDetails : details) {
        String name = savedSearchDetails.getName();
        String description = savedSearchDetails.getDescription();
        String query = savedSearchDetails.getCompatibility().getQuery();
        String params = savedSearchDetails.getCompatibility().getParams();
        String sort = savedSearchDetails.getCompatibility().getSort();
        Item item = new Item(name, description, query, params, sort);
        items.add(item);
    }
    model.put("savedSearches", items);
    return model;
}
Also used : WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SavedSearchDetails(org.alfresco.module.org_alfresco_module_rm.search.SavedSearchDetails)

Aggregations

SavedSearchDetails (org.alfresco.module.org_alfresco_module_rm.search.SavedSearchDetails)3 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)1 Test (org.junit.Test)1 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)1