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