List of usage examples for java.util LinkedList addAll
public boolean addAll(Collection<? extends E> c)
From source file:org.kuali.rice.kew.actionrequest.service.impl.NotificationSuppression.java
/** * add metadata (a NodeState) to the route node so that if this action request is regenerated * verbatim, the notification email will suppressed (since it is a duplicate!). * @param nodeInstance where additional NodeState will be added * @param actionRequestValue // ww w. j a v a 2s.c om */ public void addNotificationSuppression(RouteNodeInstance nodeInstance, ActionRequestValue actionRequestValue) { // iterative depth first traversal of the action request tree LinkedList<ActionRequestValue> stack = new LinkedList<ActionRequestValue>(); // push stack.add(actionRequestValue); while (stack.size() > 0) { // pop our next action request ActionRequestValue childActionRequest = stack.removeLast(); // process this action request only if it is a leaf if (childActionRequest.getChildrenRequests() == null || childActionRequest.getChildrenRequests().size() == 0) { List<String> requestKeys = getSuppressNotifyNodeStateKeys(childActionRequest); if (requestKeys != null) for (String requestKey : requestKeys) { if (nodeInstance.getNodeState(requestKey) == null) { // only add once NodeState ns = new NodeState(); ns.setKey(requestKey); ns.setValue("notification suppression"); nodeInstance.addNodeState(ns); } } } // put child action requests on the stack if (childActionRequest.getChildrenRequests() != null) { // equivalent to 'push' all stack.addAll(childActionRequest.getChildrenRequests()); } } }
From source file:org.eclipse.ecr.opencmis.impl.server.CMISQLQueryMaker.java
/** * {@inheritDoc}/* w w w . j ava2s.c o m*/ * <p> * The optional parameters must be passed: {@code params[0]} is the * {@link NuxeoCmisService}, optional {@code params[1]} is a type info map. */ @Override public Query buildQuery(SQLInfo sqlInfo, Model model, PathResolver pathResolver, String statement, QueryFilter queryFilter, Object... params) throws StorageException { database = sqlInfo.database; dialect = sqlInfo.dialect; this.model = model; NuxeoCmisService service = (NuxeoCmisService) params[0]; typeInfo = params.length > 1 ? (Map<String, PropertyDefinition<?>>) params[1] : null; TypeManagerImpl typeManager = service.repository.getTypeManager(); boolean addSystemColumns = true; // TODO hierTable = database.getTable(Model.HIER_TABLE_NAME); query = new QueryObject(typeManager); QueryUtil queryUtil = new QueryUtil(); CmisQueryWalker walker = null; try { walker = queryUtil.getWalker(statement); walker.query(query, new AnalyzingWalker()); } catch (RecognitionException e) { String msg; if (walker == null) { msg = e.getMessage(); } else { msg = "Line " + e.line + ":" + e.charPositionInLine + " " + walker.getErrorMessage(e, walker.getTokenNames()); } throw new QueryParseException(msg, e); } catch (QueryParseException e) { throw e; } catch (Exception e) { throw new QueryParseException(e.getMessage(), e); } // now resolve column selectors to actual database columns for (CmisSelector sel : query.getSelectReferences()) { recordSelectSelector(sel); } for (CmisSelector sel : query.getJoinReferences()) { recordSelector(sel, JOIN); } for (CmisSelector sel : query.getWhereReferences()) { recordSelector(sel, WHERE); } for (SortSpec spec : query.getOrderBys()) { recordSelector(spec.getSelector(), ORDER_BY); } boolean distinct = false; // TODO extension boolean skipHidden = true; // ignore hidden and trashed documents addSystemColumns(addSystemColumns, distinct, skipHidden); /* * Find info about fragments needed. */ List<String> whereClauses = new LinkedList<String>(); List<Serializable> whereParams = new LinkedList<Serializable>(); /* * Walk joins. */ List<JoinSpec> joins = query.getJoins(); StringBuilder from = new StringBuilder(); List<Serializable> fromParams = new LinkedList<Serializable>(); for (int njoin = -1; njoin < joins.size(); njoin++) { boolean firstTable = njoin == -1; JoinSpec join; String alias; if (firstTable) { join = null; alias = query.getMainTypeAlias(); } else { join = joins.get(njoin); alias = join.alias; } String typeQueryName = query.getTypeQueryName(alias); String qual = alias; if (qual.equals(typeQueryName)) { qual = null; } Table qualHierTable; qualHierTable = getTable(hierTable, qual); // table this join is about Table table; if (firstTable) { table = qualHierTable; } else { // find which table in onLeft/onRight refers to current // qualifier table = null; for (ColumnReference col : Arrays.asList(join.onLeft, join.onRight)) { if (alias.equals(col.getTypeQueryName())) { table = ((Column) col.getInfo()).getTable(); break; } } if (table == null) { throw new QueryParseException("Bad query, qualifier not found: " + qual); } // do requested join if (join.kind.equals("LEFT") || join.kind.equals("RIGHT")) { from.append(" "); from.append(join.kind); } from.append(" JOIN "); } boolean isRelation = table.getKey().equals(REL_FRAGMENT_NAME); // join requested table String name; if (table.isAlias()) { name = table.getRealTable().getQuotedName() + " " + table.getQuotedName(); } else { name = table.getQuotedName(); } from.append(name); if (!firstTable) { // emit actual join requested from.append(" ON "); from.append(((Column) join.onLeft.getInfo()).getFullQuotedName()); from.append(" = "); from.append(((Column) join.onRight.getInfo()).getFullQuotedName()); } // join other fragments for qualifier String tableMainId = table.getColumn(Model.MAIN_KEY).getFullQuotedName(); for (Table t : allTables.get(qual).values()) { if (t.getKey().equals(table.getKey())) { // this one was the first, already done continue; } String n; if (t.isAlias()) { n = t.getRealTable().getQuotedName() + " " + t.getQuotedName(); } else { n = t.getQuotedName(); } from.append(" LEFT JOIN "); from.append(n); from.append(" ON "); from.append(t.getColumn(Model.MAIN_KEY).getFullQuotedName()); from.append(" = "); from.append(tableMainId); } // restrict to relevant primary types List<String> types = new ArrayList<String>(); TypeDefinition td = query.getTypeDefinitionFromQueryName(typeQueryName); if (td.getParentTypeId() != null) { // don't add abstract root types types.add(td.getId()); } LinkedList<TypeDefinitionContainer> typesTodo = new LinkedList<TypeDefinitionContainer>(); typesTodo.addAll(typeManager.getTypeDescendants(td.getId(), -1, Boolean.TRUE)); // recurse to get all subtypes TypeDefinitionContainer tc; while ((tc = typesTodo.poll()) != null) { types.add(tc.getTypeDefinition().getId()); typesTodo.addAll(tc.getChildren()); } if (types.isEmpty()) { // shoudn't happen types = Collections.singletonList("__NOSUCHTYPE__"); } StringBuilder qms = new StringBuilder(); for (int i = 0; i < types.size(); i++) { if (i != 0) { qms.append(", "); } qms.append("?"); } whereClauses.add(String.format("%s IN (%s)", qualHierTable.getColumn(model.MAIN_PRIMARY_TYPE_KEY).getFullQuotedName(), qms)); whereParams.addAll(types); // lifecycle not deleted filter if (skipHidden) { Table misc = getTable(database.getTable(model.MISC_TABLE_NAME), qual); Column lscol = misc.getColumn(model.MISC_LIFECYCLE_STATE_KEY); whereClauses.add(String.format("%s <> ?", lscol.getFullQuotedName())); whereParams.add(LifeCycleConstants.DELETED_STATE); } // security check boolean checkSecurity = !isRelation // && queryFilter != null && queryFilter.getPrincipals() != null; if (checkSecurity) { Serializable principals; Serializable permissions; if (dialect.supportsArrays()) { principals = queryFilter.getPrincipals(); permissions = queryFilter.getPermissions(); } else { principals = StringUtils.join(queryFilter.getPrincipals(), '|'); permissions = StringUtils.join(queryFilter.getPermissions(), '|'); } if (dialect.supportsReadAcl()) { /* optimized read acl */ String readAclTable; String readAclIdCol; String readAclAclIdCol; if (joins.size() == 0) { readAclTable = model.HIER_READ_ACL_TABLE_NAME; readAclIdCol = model.HIER_READ_ACL_TABLE_NAME + '.' + model.HIER_READ_ACL_ID; readAclAclIdCol = model.HIER_READ_ACL_TABLE_NAME + '.' + model.HIER_READ_ACL_ACL_ID; } else { String al = "nxr" + (njoin + 1); readAclTable = model.HIER_READ_ACL_TABLE_NAME + " " + al; // TODO dialect readAclIdCol = al + '.' + model.HIER_READ_ACL_ID; readAclAclIdCol = al + '.' + model.HIER_READ_ACL_ACL_ID; } whereClauses.add(dialect.getReadAclsCheckSql(readAclAclIdCol)); whereParams.add(principals); from.append(String.format(" JOIN %s ON %s = %s", readAclTable, tableMainId, readAclIdCol)); } else { whereClauses.add(dialect.getSecurityCheckSql(tableMainId)); whereParams.add(principals); whereParams.add(permissions); } } } /* * WHERE clause. */ Tree whereNode = walker.getWherePredicateTree(); if (whereNode != null) { GeneratingWalker generator = new GeneratingWalker(); generator.walkPredicate(whereNode); whereClauses.add(generator.whereBuf.toString()); whereParams.addAll(generator.whereBufParams); // add JOINs for the external fulltext matches Collections.sort(generator.ftJoins); // implicit JOINs last // (PostgreSQL) for (org.eclipse.ecr.core.storage.sql.jdbc.db.Join join : generator.ftJoins) { from.append(join.toString()); if (join.tableParam != null) { fromParams.add(join.tableParam); } } } /* * SELECT clause. */ List<String> selectWhat = new ArrayList<String>(); List<Serializable> selectParams = new ArrayList<Serializable>(1); for (SqlColumn rc : realColumns) { selectWhat.add(rc.sql); } selectParams.addAll(realColumnsParams); CMISQLMapMaker mapMaker = new CMISQLMapMaker(realColumns, virtualColumns, service); String what = StringUtils.join(selectWhat, ", "); if (distinct) { what = "DISTINCT " + what; } /* * ORDER BY clause. */ List<String> orderbys = new LinkedList<String>(); for (SortSpec spec : query.getOrderBys()) { String orderby; CmisSelector sel = spec.getSelector(); if (sel instanceof ColumnReference) { Column column = (Column) sel.getInfo(); orderby = column.getFullQuotedName(); } else { orderby = fulltextMatchInfo.scoreAlias; } if (!spec.ascending) { orderby += " DESC"; } orderbys.add(orderby); } /* * Create the whole select. */ Select select = new Select(null); select.setWhat(what); select.setFrom(from.toString()); // TODO(fromParams); // TODO add before whereParams select.setWhere(StringUtils.join(whereClauses, " AND ")); select.setOrderBy(StringUtils.join(orderbys, ", ")); Query q = new Query(); q.selectInfo = new SQLInfoSelect(select.getStatement(), mapMaker); q.selectParams = selectParams; q.selectParams.addAll(fromParams); q.selectParams.addAll(whereParams); return q; }
From source file:com.commander4j.db.JDBDespatch.java
public boolean delete() { PreparedStatement stmtupdate; boolean result = false; setErrorMessage(""); logger.debug("delete [" + getDespatchNo() + "]"); LinkedList<String> assignedList = new LinkedList<String>(); JDBPallet pal = new JDBPallet(getHostID(), getSessionID()); if (isValid(false) == true) { String journeyRef = getJourneyRef(); assignedList.clear();/*w ww. ja va 2 s . co m*/ assignedList.addAll(getAssignedSSCCs()); if (assignedList.size() > 0) { for (int j = 0; j < assignedList.size(); j++) { if (pal.getPalletProperties(assignedList.get(j))) { pal.setDespatchNo(""); pal.update(); } } } try { stmtupdate = Common.hostList.getHost(getHostID()).getConnection(getSessionID()).prepareStatement( Common.hostList.getHost(getHostID()).getSqlstatements().getSQL("JDBDespatch.delete")); stmtupdate.setString(1, getDespatchNo()); stmtupdate.execute(); stmtupdate.clearParameters(); Common.hostList.getHost(getHostID()).getConnection(getSessionID()).commit(); stmtupdate.close(); if (journeyRef.equals("") == false) { JDBJourney jrny = new JDBJourney(getHostID(), getSessionID()); if (jrny.getJourneyRefProperties(journeyRef)) { jrny.setStatus("Unassigned"); jrny.setDespatchNo(""); jrny.update(); } } result = true; } catch (SQLException e) { setErrorMessage(e.getMessage()); } } return result; }
From source file:org.ohmage.reminders.types.location.LocTrigService.java
private long getMinCategoryExpirationTime(int categId) { LocationTrigger locTrig = new LocationTrigger(); LocTrigDB db = new LocTrigDB(this); db.open();/*from www. j av a 2 s . co m*/ String categName = db.getCategoryName(categId); db.close(); int minReentry = -1; LinkedList<Integer> trigs = new LinkedList<Integer>(); TriggerDB dbHelper = new TriggerDB(this); dbHelper.open(); trigs.addAll(locTrig.getAllActiveTriggerIds(this, null)); dbHelper.close(); for (int trig : trigs) { LocTrigDesc desc = new LocTrigDesc(); if (!desc.loadString(locTrig.getTrigger(this, trig))) { continue; } if (!desc.getLocation().equalsIgnoreCase(categName)) { continue; } int cur = desc.getMinReentryInterval(); if (minReentry == -1) { minReentry = cur; } else if (cur < minReentry) { minReentry = cur; } } if (minReentry == -1) { return -1; } return (minReentry * 60 * 1000); }
From source file:org.ohmage.reminders.types.location.LocTrigService.java
private void triggerIfRequired(int categId) { LocTrigDB db = new LocTrigDB(this); db.open();/* w w w . j a v a 2s .co m*/ String categName = db.getCategoryName(categId); db.close(); LocationTrigger locTrig = new LocationTrigger(); LinkedList<Integer> trigs = new LinkedList<Integer>(); TriggerDB dbHelper = new TriggerDB(this); dbHelper.open(); trigs.addAll(locTrig.getAllActiveTriggerIds(this, null)); dbHelper.close(); for (int trigId : trigs) { LocTrigDesc desc = new LocTrigDesc(); if (!desc.loadString(locTrig.getTrigger(this, trigId))) { continue; } if (!desc.getLocation().equalsIgnoreCase(categName)) { continue; } if (desc.isRangeEnabled()) { Log.v(TAG, "LocTrigService: Range enabling. Checking whether" + " to trigger"); if (locTrig.hasTriggeredToday(this, trigId)) { Log.v(TAG, "LocTrigService: Has triggered today, skipping"); continue; } Calendar cal = Calendar.getInstance(); SimpleTime now = new SimpleTime(cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE)); if (now.isBefore(desc.getStartTime())) { continue; } SimpleTime end = desc.getEndTime(); if (now.isAfter(end)) { continue; } else if (now.equals(end) && cal.get(Calendar.SECOND) > 0) { continue; } Log.v(TAG, "LocTrigService: Triggering now"); cancelTriggerAlwaysAlarm(trigId); locTrig.notifyTrigger(this, trigId); } else if (mCategPrevTS == LocTrigDB.TIME_STAMP_INVALID) { Log.v(TAG, "LocTrigService: Invalid categ timestamp." + " Triggering..."); locTrig.notifyTrigger(this, trigId); } else { long elapsed = System.currentTimeMillis() - mCategPrevTS; long minReentry = desc.getMinReentryInterval() * 60 * 1000; if (elapsed > minReentry) { Log.v(TAG, "LocTrigService: Beyond minimum re-entry. " + "Triggering..."); locTrig.notifyTrigger(this, trigId); } else { Log.v(TAG, "LocTrigService: Minimum re-entry has not expired. " + " Not triggering."); } } } }
From source file:org.ohmage.reminders.types.location.LocTrigService.java
private void updateSamplingStatus() { LinkedList<Integer> actTrigs = new LinkedList<Integer>(); LocationTrigger lt = new LocationTrigger(); TriggerDB dbHelper = new TriggerDB(this); dbHelper.open();//from w w w . j a v a 2s.c o m actTrigs.addAll(lt.getAllActiveTriggerIds(this, null)); dbHelper.close(); //Start sampling if there are active surveys //or if the location tracing is enabled. if (mLocTraceEnabled || (actTrigs.size() > 0 && mLocList.size() > 0)) { startSampling(); } else { stopSampling(); } }
From source file:org.ohmage.triggers.types.location.LocTrigService.java
private long getMinCategoryExpirationTime(int categId) { LocationTrigger locTrig = new LocationTrigger(); LocTrigDB db = new LocTrigDB(this); db.open();/*from w ww . ja v a2 s .c om*/ String categName = db.getCategoryName(categId); db.close(); int minReentry = -1; LinkedList<Integer> trigs = new LinkedList<Integer>(); DbHelper dbHelper = new DbHelper(this); for (Campaign c : dbHelper.getReadyCampaigns()) { trigs.addAll(locTrig.getAllActiveTriggerIds(this, c.mUrn)); } for (int trig : trigs) { LocTrigDesc desc = new LocTrigDesc(); if (!desc.loadString(locTrig.getTrigger(this, trig))) { continue; } if (!desc.getLocation().equalsIgnoreCase(categName)) { continue; } int cur = desc.getMinReentryInterval(); if (minReentry == -1) { minReentry = cur; } else if (cur < minReentry) { minReentry = cur; } } if (minReentry == -1) { return -1; } return (minReentry * 60 * 1000); }
From source file:com.datatorrent.stram.webapp.OperatorDiscoverer.java
/** * Enrich portClassHier with class/interface names that map to a list of parent classes/interfaces. * For any class encountered, find its parents too.<br/> * Also find the port types which have assignable schema classes. * * @param oper Operator to work on * @param portClassHierarchy In-Out param that contains a mapping of class/interface to its parents * @param portTypesWithSchemaClasses Json that will contain all the ports which have any schema classes. *///from w w w . j av a2 s . c o m public void buildAdditionalPortInfo(JSONObject oper, JSONObject portClassHierarchy, JSONObject portTypesWithSchemaClasses) { try { JSONArray ports = oper.getJSONArray(OperatorDiscoverer.PORT_TYPE_INFO_KEY); for (int i = 0; i < ports.length(); i++) { JSONObject port = ports.getJSONObject(i); String portType = port.optString("type"); if (portType == null) { //skipping if port type is null continue; } if (typeGraph.size() == 0) { buildTypeGraph(); } try { //building port class hierarchy LinkedList<String> queue = Lists.newLinkedList(); queue.add(portType); while (!queue.isEmpty()) { String currentType = queue.remove(); if (portClassHierarchy.has(currentType)) { //already present in the json so we skip. continue; } List<String> immediateParents = typeGraph.getParents(currentType); if (immediateParents == null) { portClassHierarchy.put(currentType, Lists.<String>newArrayList()); continue; } portClassHierarchy.put(currentType, immediateParents); queue.addAll(immediateParents); } } catch (JSONException e) { LOG.warn("building port type hierarchy {}", portType, e); } //finding port types with schema classes if (portTypesWithSchemaClasses.has(portType)) { //already present in the json so skipping continue; } if (portType.equals("byte") || portType.equals("short") || portType.equals("char") || portType.equals("int") || portType.equals("long") || portType.equals("float") || portType.equals("double") || portType.equals("java.lang.String") || portType.equals("java.lang.Object")) { //ignoring primitives, strings and object types as this information is needed only for complex types. continue; } if (port.has("typeArgs")) { //ignoring any type with generics continue; } boolean hasSchemaClasses = false; List<String> instantiableDescendants = typeGraph.getInstantiableDescendants(portType); if (instantiableDescendants != null) { for (String descendant : instantiableDescendants) { try { if (typeGraph.isInstantiableBean(descendant)) { hasSchemaClasses = true; break; } } catch (JSONException ex) { LOG.warn("checking descendant is instantiable {}", descendant); } } } portTypesWithSchemaClasses.put(portType, hasSchemaClasses); } } catch (JSONException e) { // should not reach this LOG.error("JSON Exception {}", e); throw new RuntimeException(e); } }
From source file:org.ohmage.triggers.types.location.LocTrigService.java
private void triggerIfRequired(int categId) { LocTrigDB db = new LocTrigDB(this); db.open();/*from w ww . j ava2s .c o m*/ String categName = db.getCategoryName(categId); db.close(); LocationTrigger locTrig = new LocationTrigger(); LinkedList<Integer> trigs = new LinkedList<Integer>(); DbHelper dbHelper = new DbHelper(this); for (Campaign c : dbHelper.getReadyCampaigns()) { trigs.addAll(locTrig.getAllActiveTriggerIds(this, c.mUrn)); } for (int trigId : trigs) { LocTrigDesc desc = new LocTrigDesc(); if (!desc.loadString(locTrig.getTrigger(this, trigId))) { continue; } if (!desc.getLocation().equalsIgnoreCase(categName)) { continue; } if (desc.isRangeEnabled()) { Log.i(DEBUG_TAG, "LocTrigService: Range enabling. Checking whether" + " to trigger"); if (locTrig.hasTriggeredToday(this, trigId)) { Log.i(DEBUG_TAG, "LocTrigService: Has triggered today, skipping"); continue; } Calendar cal = Calendar.getInstance(); SimpleTime now = new SimpleTime(cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE)); if (now.isBefore(desc.getStartTime())) { continue; } SimpleTime end = desc.getEndTime(); if (now.isAfter(end)) { continue; } else if (now.equals(end) && cal.get(Calendar.SECOND) > 0) { continue; } Log.i(DEBUG_TAG, "LocTrigService: Triggering now"); cancelTriggerAlwaysAlarm(trigId); locTrig.notifyTrigger(this, trigId); } else if (mCategPrevTS == LocTrigDB.TIME_STAMP_INVALID) { Log.i(DEBUG_TAG, "LocTrigService: Invalid categ timestamp." + " Triggering..."); locTrig.notifyTrigger(this, trigId); } else { long elapsed = System.currentTimeMillis() - mCategPrevTS; long minReentry = desc.getMinReentryInterval() * 60 * 1000; if (elapsed > minReentry) { Log.i(DEBUG_TAG, "LocTrigService: Beyond minimum re-entry. " + "Triggering..."); locTrig.notifyTrigger(this, trigId); } else { Log.i(DEBUG_TAG, "LocTrigService: Minimum re-entry has not expired. " + " Not triggering."); } } } }
From source file:org.ohmage.triggers.types.location.LocTrigService.java
private void updateSamplingStatus() { LinkedList<Integer> actTrigs = new LinkedList<Integer>(); LocationTrigger lt = new LocationTrigger(); DbHelper dbHelper = new DbHelper(this); for (Campaign c : dbHelper.getReadyCampaigns()) { actTrigs.addAll(lt.getAllActiveTriggerIds(this, c.mUrn)); }/*from w ww .j a v a2s . co m*/ //Start sampling if there are active surveys //or if the location tracing is enabled. if (mLocTraceEnabled || (actTrigs.size() > 0 && mLocList.size() > 0)) { startSampling(); } else { stopSampling(); } }