Search in sources :

Example 1 with IContextManager

use of org.jaffa.session.IContextManager in project jaffa-framework by jaffa-projects.

the class FinderComponent2 method initializeSavedQueries.

private void initializeSavedQueries() {
    /*
         * Read the stored queries and and create a codeHelperOutElementDto so
         * that this can be used as the options to a dropdown
         */
    // Get the saved Queries
    IContextManager contextManager = ContextManagerFactory.instance();
    QuerySaver querySaver = new QuerySaver(contextManager);
    Map savedQueries = querySaver.getSavedQueryList(getComponentDefinition().getComponentName());
    String defaultQueryId = querySaver.getDefaultQueryId(getComponentDefinition().getComponentName());
    m_queryIdCodes = new CodeHelperOutElementDto();
    if (savedQueries.size() > 0) {
        // Create the codeHelperOutElementDto by iterating over the key maps
        Iterator savedQueriesIterator = savedQueries.keySet().iterator();
        while (savedQueriesIterator.hasNext()) {
            String element = (String) savedQueriesIterator.next();
            log.info("Adding " + element + " to Saved Queries");
            CodeHelperOutCodeDto codeHelperOutCodeDto = new CodeHelperOutCodeDto();
            codeHelperOutCodeDto.setCode(element);
            if (defaultQueryId != null && element.equals(defaultQueryId)) {
                codeHelperOutCodeDto.setDescription("** " + savedQueries.get(element) + " **");
            } else {
                codeHelperOutCodeDto.setDescription(savedQueries.get(element));
            }
            m_queryIdCodes.addCodeHelperOutCodeDto(codeHelperOutCodeDto);
        }
    } else {
        log.info("No Queries to add to Saved Queries");
        CodeHelperOutCodeDto codeHelperOutCodeDto = new CodeHelperOutCodeDto();
        codeHelperOutCodeDto.setCode("");
        codeHelperOutCodeDto.setDescription(MessageHelper.findMessage("label.Jaffa.Finder.NoSavedQueries", null));
        m_queryIdCodes.addCodeHelperOutCodeDto(codeHelperOutCodeDto);
    }
}
Also used : CodeHelperOutCodeDto(org.jaffa.components.codehelper.dto.CodeHelperOutCodeDto) CodeHelperOutElementDto(org.jaffa.components.codehelper.dto.CodeHelperOutElementDto) IContextManager(org.jaffa.session.IContextManager)

Example 2 with IContextManager

use of org.jaffa.session.IContextManager in project jaffa-framework by jaffa-projects.

the class QuerySaver method getSavedShortcutQueryBeans.

/**
 * Returns all the saved queries which were labeled as shortcuts.
 * These saved queries are grouped by their component names.
 * All the saved queries of one component are stored in SavedQueryList object.
 * The returned object is a list of the SavedQueryList objects.
 */
public static List<SavedQueryBean> getSavedShortcutQueryBeans() {
    IContextManager contextManager = ContextManagerFactory.instance();
    QuerySaver querySaver = new QuerySaver(contextManager);
    // get all the component names
    Set propertyNames = contextManager.getPropertyNames(S_USERPREF + ".*");
    Set componentNames = new HashSet();
    for (Iterator it = propertyNames.iterator(); it.hasNext(); ) {
        String pn = (String) it.next();
        pn = pn.replaceFirst(S_USERPREF + ".", "");
        if (pn.indexOf("." + S_QUERY) > 0) {
            pn = pn.substring(0, pn.indexOf("." + S_QUERY));
            if (pn != null && pn.length() > 0) {
                componentNames.add(pn);
            }
        }
    }
    List out = new ArrayList();
    String[] cpns = (String[]) componentNames.toArray(new String[0]);
    Arrays.sort(cpns);
    for (int i = 0; i < cpns.length; i++) {
        // get all saved queries
        Map asq = querySaver.getSavedQueryList(cpns[i]);
        // filter out the queries that are shortcuts
        List bag = new ArrayList();
        for (Iterator it = asq.keySet().iterator(); it.hasNext(); ) {
            String qId = (String) it.next();
            if (!querySaver.savedQueryHasShortcut(cpns[i], qId)) {
                bag.add(qId);
            }
        }
        for (int j = 0; j < bag.size(); j++) {
            String qId = (String) bag.get(j);
            asq.remove(qId);
        }
        if (asq.size() > 0) {
            // assemble into the output list
            SavedQueryBean sql = new SavedQueryBean(cpns[i]);
            for (Iterator it = asq.keySet().iterator(); it.hasNext(); ) {
                String qId = (String) it.next();
                String qname = (String) asq.get(qId);
                // construct the url
                String url = "startComponent.do?finalUrl=jaffa_closeBrowser&component=" + cpns[i] + "&displayResultsScreen=true&useQuery=" + qId;
                sql.setSavedQueryUrl(qId, qname, url);
            }
            out.add(sql);
        }
    }
    return out;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IContextManager(org.jaffa.session.IContextManager) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 3 with IContextManager

use of org.jaffa.session.IContextManager in project jaffa-framework by jaffa-projects.

the class UserContextWrapperTest method testUserRoles.

/**
 * Make sure the request / UserRoles are set
 */
public void testUserRoles() throws Exception {
    log.info("RUN: " + getName());
    try {
        UserContextWrapper ucw = new UserContextWrapper(UserDataWrapper.USER1, DummyPortletFilter.class);
        IContextManager cm = ContextManagerFactory.instance();
        // Test stuff from the thread rules
        assertNotNull("Bad value in : request", cm.getProperty("request"));
        HttpServletRequest req = (HttpServletRequest) cm.getProperty("request");
        assertTrue("User should have access to " + UserDataWrapper.USER1_ROLES[0], req.isUserInRole(UserDataWrapper.USER1_ROLES[0]));
        assertTrue("User should have access to " + UserDataWrapper.USER1_ROLES[1], req.isUserInRole(UserDataWrapper.USER1_ROLES[1]));
        assertFalse("User should NOT have access to DUMMYROLE1", req.isUserInRole("DUMMYROLE1"));
        ucw.unsetContext();
    } catch (Exception e) {
        log.fatal("Test Failed", e);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IContextManager(org.jaffa.session.IContextManager)

Example 4 with IContextManager

use of org.jaffa.session.IContextManager in project jaffa-framework by jaffa-projects.

the class ApplicationRule method createFacts.

/**
 * Creates a Collection of ApplicationRule instances by looking up the ApplicationRules for the input name.
 * This should typically be used if the rule points to a comma-separated list of values, or if
 * the value is Iterable.
 * A null is returned if an entry is not found for the input.
 * @param name the application rule name.
 * @return a Collection of ApplicationRule instances
 */
public static Collection<ApplicationRule> createFacts(String name) {
    IContextManager contextManager = ContextManagerFactory.instance();
    if (contextManager.getThreadContext().containsKey(name)) {
        Collection<ApplicationRule> applicationRules = new LinkedList<ApplicationRule>();
        Object values = contextManager.getProperty(name);
        if (values != null) {
            // split a comma-separated string into an array
            if (values instanceof String)
                values = ((String) values).split(",");
            // create an instance for each element in an array/collection
            if (values.getClass().isArray()) {
                for (Object value : (Object[]) values) applicationRules.add(new ApplicationRule(name, value));
            } else if (values instanceof Iterable) {
                for (Object value : (Iterable) values) applicationRules.add(new ApplicationRule(name, value));
            } else
                applicationRules.add(new ApplicationRule(name, values));
        } else
            applicationRules.add(new ApplicationRule(name, values));
        return applicationRules;
    }
    return null;
}
Also used : IContextManager(org.jaffa.session.IContextManager) LinkedList(java.util.LinkedList)

Example 5 with IContextManager

use of org.jaffa.session.IContextManager in project jaffa-framework by jaffa-projects.

the class FinderComponent2 method loadQuery.

public void loadQuery() throws ApplicationException {
    if (getSavedQueryId() != null) {
        getUserSession().getWidgetCache(getComponentId()).clear();
        Map queryData = null;
        IContextManager contextManager = ContextManagerFactory.instance();
        QuerySaver querySaver = new QuerySaver(contextManager);
        queryData = querySaver.getSavedQueryFields(this.getComponentDefinition().getComponentName(), getSavedQueryId().toString());
        if (queryData != null) {
            setQueryData(queryData);
            String defaultQueryId = querySaver.getDefaultQueryId(this.getComponentDefinition().getComponentName());
            if (defaultQueryId != null && defaultQueryId.equals(getSavedQueryId().toString()))
                setDefaultQueryYn(new Boolean(true));
            else
                setDefaultQueryYn(new Boolean(false));
            if (querySaver.savedQueryHasShortcut(this.getComponentDefinition().getComponentName(), getSavedQueryId().toString()))
                setQueryHasShortcutYn(new Boolean(true));
            else
                setQueryHasShortcutYn(new Boolean(false));
            setNewQueryName(querySaver.getSavedQueryName(this.getComponentDefinition().getComponentName(), getSavedQueryId().toString()));
        } else {
            throw new QueryNotFoundException(getSavedQueryId().toString());
        }
    }
}
Also used : IContextManager(org.jaffa.session.IContextManager)

Aggregations

IContextManager (org.jaffa.session.IContextManager)13 IOException (java.io.IOException)2 GetQueryDataException (org.jaffa.exceptions.GetQueryDataException)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 CodeHelperOutCodeDto (org.jaffa.components.codehelper.dto.CodeHelperOutCodeDto)1 CodeHelperOutElementDto (org.jaffa.components.codehelper.dto.CodeHelperOutElementDto)1 ApplicationRulesManager (org.jaffa.loader.config.ApplicationRulesManager)1 UserSession (org.jaffa.presentation.portlet.session.UserSession)1 Test (org.junit.Test)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpSession (org.springframework.mock.web.MockHttpSession)1