List of usage examples for java.util Collection containsAll
boolean containsAll(Collection<?> c);
From source file:org.gridgain.grid.spi.cloud.ec2lite.GridEc2LiteCloudSpi.java
/** * Sends request to Amazon EC2 to start given instances. * <p>//www . j a v a 2 s . c o m * Provided instances should be in {@link #INST_STOPPED_STATE} state * in order for command to execute properly. * * @param instIds Instances IDs to start. Not {@code null} and not empty. * @throws GridSpiException Thrown if any exception occurs. */ private void startInstances(Collection<String> instIds) throws GridSpiException { assert !F.isEmpty(instIds); StartInstancesRequest req = new StartInstancesRequest().withInstanceIds(instIds); StartInstancesResult res; try { res = ec2.startInstances(req); } catch (AmazonClientException e) { throw new GridSpiException("Failed to perform start instances request.", e); } Collection<String> startInstIds = F.transform(res.getStartingInstances(), new C1<InstanceStateChange, String>() { @Override public String apply(InstanceStateChange ist) { return ist.getInstanceId(); } }); if (instIds.size() != startInstIds.size() || !instIds.containsAll(startInstIds)) throw new GridSpiException("Instances were not successfully started."); }
From source file:org.gridgain.grid.spi.cloud.ec2lite.GridEc2LiteCloudSpi.java
/** * Sends request to Amazon EC2 to stop given instances. * <p>/*from www.j a v a 2 s. co m*/ * Provided instances should be in {@link #INST_RUNNING_STATE} state * in order for command to execute properly. * * @param instIds Instances IDs to stop. Not {@code null} and not empty. * @param force Pass {@code true} to force instance stop. * @throws GridSpiException Thrown if any exception occurs. */ private void stopInstances(Collection<String> instIds, boolean force) throws GridSpiException { assert !F.isEmpty(instIds); StopInstancesRequest req = new StopInstancesRequest().withInstanceIds(instIds).withForce(force); StopInstancesResult res; try { res = ec2.stopInstances(req); } catch (AmazonClientException e) { throw new GridSpiException("Failed to perform start instances request.", e); } Collection<String> stopInstIds = F.transform(res.getStoppingInstances(), new C1<InstanceStateChange, String>() { @Override public String apply(InstanceStateChange ist) { return ist.getInstanceId(); } }); if (instIds.size() != stopInstIds.size() || !instIds.containsAll(stopInstIds)) throw new GridSpiException("Instances were not successfully stopped."); }
From source file:org.gridgain.grid.spi.cloud.ec2lite.GridEc2LiteCloudSpi.java
/** * Send request to Amazon EC2 to terminate given instances. * * @param instIds Instances IDs to terminate. Not {@code null} and not empty. * @throws GridSpiException Thrown if any exception occurs. *//* w w w . j a va2s. c o m*/ private void terminateInstances(Collection<String> instIds) throws GridSpiException { assert !F.isEmpty(instIds); TerminateInstancesRequest req = new TerminateInstancesRequest().withInstanceIds(instIds); TerminateInstancesResult res; try { res = ec2.terminateInstances(req); } catch (AmazonClientException e) { throw new GridSpiException("Failed to perform terminate instances request.", e); } Collection<String> terminatedInstIds = F.transform(res.getTerminatingInstances(), new C1<InstanceStateChange, String>() { @Override public String apply(InstanceStateChange ist) { return ist.getInstanceId(); } }); if (instIds.size() != terminatedInstIds.size() || !instIds.containsAll(terminatedInstIds)) throw new GridSpiException("Instances were not successfully terminated."); }
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.PushSelectIntoJoinRule.java
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { Collection<LogicalVariable> joinLiveVarsLeft = new HashSet<LogicalVariable>(); Collection<LogicalVariable> joinLiveVarsRight = new HashSet<LogicalVariable>(); Collection<LogicalVariable> liveInOpsToPushLeft = new HashSet<LogicalVariable>(); Collection<LogicalVariable> liveInOpsToPushRight = new HashSet<LogicalVariable>(); List<ILogicalOperator> pushedOnLeft = new ArrayList<ILogicalOperator>(); List<ILogicalOperator> pushedOnRight = new ArrayList<ILogicalOperator>(); LinkedList<ILogicalOperator> notPushedStack = new LinkedList<ILogicalOperator>(); Collection<LogicalVariable> usedVars = new HashSet<LogicalVariable>(); Collection<LogicalVariable> producedVars = new HashSet<LogicalVariable>(); AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); if (op.getOperatorTag() != LogicalOperatorTag.SELECT) { return false; }/*from www . j a va2 s.c o m*/ SelectOperator select = (SelectOperator) op; Mutable<ILogicalOperator> opRef2 = op.getInputs().get(0); AbstractLogicalOperator son = (AbstractLogicalOperator) opRef2.getValue(); AbstractLogicalOperator op2 = son; boolean needToPushOps = false; while (son.isMap()) { needToPushOps = true; Mutable<ILogicalOperator> opRefLink = son.getInputs().get(0); son = (AbstractLogicalOperator) opRefLink.getValue(); } if (son.getOperatorTag() != LogicalOperatorTag.INNERJOIN && son.getOperatorTag() != LogicalOperatorTag.LEFTOUTERJOIN) { return false; } boolean isLoj = son.getOperatorTag() == LogicalOperatorTag.LEFTOUTERJOIN; AbstractBinaryJoinOperator join = (AbstractBinaryJoinOperator) son; Mutable<ILogicalOperator> joinBranchLeftRef = join.getInputs().get(0); Mutable<ILogicalOperator> joinBranchRightRef = join.getInputs().get(1); if (needToPushOps) { ILogicalOperator joinBranchLeft = joinBranchLeftRef.getValue(); ILogicalOperator joinBranchRight = joinBranchRightRef.getValue(); VariableUtilities.getLiveVariables(joinBranchLeft, joinLiveVarsLeft); VariableUtilities.getLiveVariables(joinBranchRight, joinLiveVarsRight); Mutable<ILogicalOperator> opIterRef = opRef2; ILogicalOperator opIter = op2; while (opIter != join) { LogicalOperatorTag tag = ((AbstractLogicalOperator) opIter).getOperatorTag(); if (tag == LogicalOperatorTag.PROJECT) { notPushedStack.addFirst(opIter); } else { VariableUtilities.getUsedVariables(opIter, usedVars); VariableUtilities.getProducedVariables(opIter, producedVars); if (joinLiveVarsLeft.containsAll(usedVars)) { pushedOnLeft.add(opIter); liveInOpsToPushLeft.addAll(producedVars); } else if (joinLiveVarsRight.containsAll(usedVars)) { pushedOnRight.add(opIter); liveInOpsToPushRight.addAll(producedVars); } else { return false; } } opIterRef = opIter.getInputs().get(0); opIter = opIterRef.getValue(); } if (isLoj && pushedOnLeft.isEmpty()) { return false; } } boolean intersectsAllBranches = true; boolean[] intersectsBranch = new boolean[join.getInputs().size()]; LinkedList<LogicalVariable> selectVars = new LinkedList<LogicalVariable>(); select.getCondition().getValue().getUsedVariables(selectVars); int i = 0; for (Mutable<ILogicalOperator> branch : join.getInputs()) { LinkedList<LogicalVariable> branchVars = new LinkedList<LogicalVariable>(); VariableUtilities.getLiveVariables(branch.getValue(), branchVars); if (i == 0) { branchVars.addAll(liveInOpsToPushLeft); } else { branchVars.addAll(liveInOpsToPushRight); } if (OperatorPropertiesUtil.disjoint(selectVars, branchVars)) { intersectsAllBranches = false; } else { intersectsBranch[i] = true; } i++; } if (!intersectsBranch[0] && !intersectsBranch[1]) { return false; } if (needToPushOps) { pushOps(pushedOnLeft, joinBranchLeftRef, context); pushOps(pushedOnRight, joinBranchRightRef, context); } if (intersectsAllBranches) { addCondToJoin(select, join, context); } else { // push down Iterator<Mutable<ILogicalOperator>> branchIter = join.getInputs().iterator(); ILogicalExpression selectCondition = select.getCondition().getValue(); boolean lojToInner = false; for (int j = 0; j < intersectsBranch.length; j++) { Mutable<ILogicalOperator> branch = branchIter.next(); boolean inter = intersectsBranch[j]; if (inter) { if (j > 0 && isLoj) { // if a left outer join, if the select condition is not-null filtering, // we rewrite left outer join // to inner join for this case. if (containsNotNullFiltering(selectCondition)) { lojToInner = true; } } if ((j > 0 && isLoj) && containsNullFiltering(selectCondition)) { // Select is-null($$var) cannot be pushed in the right branch of a LOJ; notPushedStack.addFirst(select); } else { // Conditions for the left branch can always be pushed. // Other conditions can be pushed to the right branch of a LOJ. copySelectToBranch(select, branch, context); } } } if (lojToInner) { // Rewrites left outer join to inner join. InnerJoinOperator innerJoin = new InnerJoinOperator(join.getCondition()); innerJoin.getInputs().addAll(join.getInputs()); join = innerJoin; context.computeAndSetTypeEnvironmentForOperator(join); } } ILogicalOperator top = join; for (ILogicalOperator npOp : notPushedStack) { List<Mutable<ILogicalOperator>> npInpList = npOp.getInputs(); npInpList.clear(); npInpList.add(new MutableObject<ILogicalOperator>(top)); context.computeAndSetTypeEnvironmentForOperator(npOp); top = npOp; } opRef.setValue(top); return true; }
From source file:org.apache.hyracks.algebricks.rewriter.rules.PushSelectIntoJoinRule.java
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { Collection<LogicalVariable> joinLiveVarsLeft = new HashSet<LogicalVariable>(); Collection<LogicalVariable> joinLiveVarsRight = new HashSet<LogicalVariable>(); Collection<LogicalVariable> liveInOpsToPushLeft = new HashSet<LogicalVariable>(); Collection<LogicalVariable> liveInOpsToPushRight = new HashSet<LogicalVariable>(); List<ILogicalOperator> pushedOnLeft = new ArrayList<ILogicalOperator>(); List<ILogicalOperator> pushedOnRight = new ArrayList<ILogicalOperator>(); List<ILogicalOperator> pushedOnEither = new ArrayList<ILogicalOperator>(); LinkedList<ILogicalOperator> notPushedStack = new LinkedList<ILogicalOperator>(); Collection<LogicalVariable> usedVars = new HashSet<LogicalVariable>(); Collection<LogicalVariable> producedVars = new HashSet<LogicalVariable>(); AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); if (op.getOperatorTag() != LogicalOperatorTag.SELECT) { return false; }/*from ww w.j ava 2 s. com*/ SelectOperator select = (SelectOperator) op; Mutable<ILogicalOperator> opRef2 = op.getInputs().get(0); AbstractLogicalOperator son = (AbstractLogicalOperator) opRef2.getValue(); AbstractLogicalOperator op2 = son; boolean needToPushOps = false; while (son.isMap()) { needToPushOps = true; Mutable<ILogicalOperator> opRefLink = son.getInputs().get(0); son = (AbstractLogicalOperator) opRefLink.getValue(); } if (son.getOperatorTag() != LogicalOperatorTag.INNERJOIN && son.getOperatorTag() != LogicalOperatorTag.LEFTOUTERJOIN) { return false; } boolean isLoj = son.getOperatorTag() == LogicalOperatorTag.LEFTOUTERJOIN; AbstractBinaryJoinOperator join = (AbstractBinaryJoinOperator) son; Mutable<ILogicalOperator> joinBranchLeftRef = join.getInputs().get(0); Mutable<ILogicalOperator> joinBranchRightRef = join.getInputs().get(1); if (needToPushOps) { ILogicalOperator joinBranchLeft = joinBranchLeftRef.getValue(); ILogicalOperator joinBranchRight = joinBranchRightRef.getValue(); VariableUtilities.getLiveVariables(joinBranchLeft, joinLiveVarsLeft); VariableUtilities.getLiveVariables(joinBranchRight, joinLiveVarsRight); Mutable<ILogicalOperator> opIterRef = opRef2; ILogicalOperator opIter = op2; while (opIter != join) { LogicalOperatorTag tag = ((AbstractLogicalOperator) opIter).getOperatorTag(); if (tag == LogicalOperatorTag.PROJECT) { notPushedStack.addFirst(opIter); } else { VariableUtilities.getUsedVariables(opIter, usedVars); VariableUtilities.getProducedVariables(opIter, producedVars); if (usedVars.size() == 0) { pushedOnEither.add(opIter); } else if (joinLiveVarsLeft.containsAll(usedVars)) { pushedOnLeft.add(opIter); liveInOpsToPushLeft.addAll(producedVars); } else if (joinLiveVarsRight.containsAll(usedVars)) { pushedOnRight.add(opIter); liveInOpsToPushRight.addAll(producedVars); } else { return false; } } opIterRef = opIter.getInputs().get(0); opIter = opIterRef.getValue(); } if (isLoj && pushedOnLeft.isEmpty()) { return false; } } boolean intersectsAllBranches = true; boolean[] intersectsBranch = new boolean[join.getInputs().size()]; LinkedList<LogicalVariable> selectVars = new LinkedList<LogicalVariable>(); select.getCondition().getValue().getUsedVariables(selectVars); int i = 0; for (Mutable<ILogicalOperator> branch : join.getInputs()) { LinkedList<LogicalVariable> branchVars = new LinkedList<LogicalVariable>(); VariableUtilities.getLiveVariables(branch.getValue(), branchVars); if (i == 0) { branchVars.addAll(liveInOpsToPushLeft); } else { branchVars.addAll(liveInOpsToPushRight); } if (OperatorPropertiesUtil.disjoint(selectVars, branchVars)) { intersectsAllBranches = false; } else { intersectsBranch[i] = true; } i++; } if (!intersectsBranch[0] && !intersectsBranch[1]) { return false; } if (needToPushOps) { //We should push independent ops into the first branch that the selection depends on if (intersectsBranch[0]) { pushOps(pushedOnEither, joinBranchLeftRef, context); } else { pushOps(pushedOnEither, joinBranchRightRef, context); } pushOps(pushedOnLeft, joinBranchLeftRef, context); pushOps(pushedOnRight, joinBranchRightRef, context); } if (intersectsAllBranches) { addCondToJoin(select, join, context); } else { // push down Iterator<Mutable<ILogicalOperator>> branchIter = join.getInputs().iterator(); ILogicalExpression selectCondition = select.getCondition().getValue(); boolean lojToInner = false; for (int j = 0; j < intersectsBranch.length; j++) { Mutable<ILogicalOperator> branch = branchIter.next(); boolean inter = intersectsBranch[j]; if (!inter) { continue; } // if a left outer join, if the select condition is not-missing filtering, // we rewrite left outer join // to inner join for this case. if (j > 0 && isLoj && containsNotMissingFiltering(selectCondition)) { lojToInner = true; } if ((j > 0 && isLoj) && containsMissingFiltering(selectCondition)) { // Select "is-not-missing($$var)" cannot be pushed in the right branch of a LOJ; notPushedStack.addFirst(select); } else { // Conditions for the left branch can always be pushed. // Other conditions can be pushed to the right branch of a LOJ. copySelectToBranch(select, branch, context); } } if (lojToInner) { // Rewrites left outer join to inner join. InnerJoinOperator innerJoin = new InnerJoinOperator(join.getCondition()); innerJoin.getInputs().addAll(join.getInputs()); join = innerJoin; context.computeAndSetTypeEnvironmentForOperator(join); } } ILogicalOperator top = join; for (ILogicalOperator npOp : notPushedStack) { List<Mutable<ILogicalOperator>> npInpList = npOp.getInputs(); npInpList.clear(); npInpList.add(new MutableObject<ILogicalOperator>(top)); context.computeAndSetTypeEnvironmentForOperator(npOp); top = npOp; } opRef.setValue(top); return true; }
From source file:org.apache.jackrabbit.spi2dav.RepositoryServiceImpl.java
/** * @see RepositoryService#isGranted(SessionInfo, ItemId, String[] actions) *//*from ww w. j a va 2 s. co m*/ public boolean isGranted(SessionInfo sessionInfo, ItemId itemId, String[] actions) throws RepositoryException { ReportMethod method = null; try { String uri = obtainAbsolutePathFromUri(getItemUri(itemId, sessionInfo)); ReportInfo reportInfo = new ReportInfo(JcrRemotingConstants.REPORT_PRIVILEGES, ItemResourceConstants.NAMESPACE); reportInfo.setContentElement(DomUtil.hrefToXml(uri, DomUtil.createDocument())); method = new ReportMethod(uriResolver.getWorkspaceUri(sessionInfo.getWorkspaceName()), reportInfo); getClient(sessionInfo).executeMethod(method); method.checkSuccess(); MultiStatusResponse[] responses = method.getResponseBodyAsMultiStatus().getResponses(); if (responses.length < 1) { throw new ItemNotFoundException( "Unable to retrieve permissions for item " + saveGetIdString(itemId, sessionInfo)); } DavProperty<?> p = responses[0].getProperties(DavServletResponse.SC_OK) .get(SecurityConstants.CURRENT_USER_PRIVILEGE_SET); if (p == null) { return false; } // build set of privileges from given actions. NOTE: since the actions // have no qualifying namespace, the {@link ItemResourceConstants#NAMESPACE} // is used. Set<Privilege> requiredPrivileges = new HashSet<Privilege>(); for (String action : actions) { requiredPrivileges.add(Privilege.getPrivilege(action, ItemResourceConstants.NAMESPACE)); } // build set of privileges granted to the current user. CurrentUserPrivilegeSetProperty privSet = new CurrentUserPrivilegeSetProperty(p); Collection<Privilege> privileges = privSet.getValue(); // check privileges present against required privileges. return privileges.containsAll(requiredPrivileges); } catch (IOException e) { throw new RepositoryException(e); } catch (ParserConfigurationException e) { throw new RepositoryException(e); } catch (DavException e) { throw ExceptionConverter.generate(e); } finally { if (method != null) { method.releaseConnection(); } } }
From source file:org.biomart.configurator.controller.MartController.java
/** * Given a set of tables, produce the minimal set of datasets which include all the specified tables. Tables can be * included in the same dataset if they are linked by 1:M relations (1:M, 1:M in a chain), or if the table is the * last in the chain and is linked to the previous table by a pair of 1:M and M:1 relations via a third table, * simulating a M:M relation.//from w w w . java2 s . com * <p> * If the chains of tables fork, then one dataset is generated for each branch of the fork. * <p> * Every suggested dataset is synchronised before being returned. * <p> * Datasets will be named after their central tables. If a dataset with that name already exists, a '_' and sequence * number will be appended to make the new dataset name unique. * <p> * * @param includeTables * the tables that must appear in the final set of datasets. * @return the collection of datasets generated. * @throws SQLException * if there is any problem talking to the source database whilst generating the dataset. * @throws DataModelException * if synchronisation fails. */ private Collection<Mart> suggestMarts(final MartRegistry registry, final TargetSchema schema, final Collection<SourceTable> includeTables) throws SQLException, DataModelException { Log.debug("Suggesting datasets for " + includeTables); // The root tables are all those which do not have a M:1 relation // to another one of the initial set of tables. This means that // extra datasets will be created for each table at the end of // 1:M:1 relation, so that any further tables past it will still // be included. Log.debug("Finding root tables"); final Collection<SourceTable> rootTables = new HashSet<SourceTable>(includeTables); for (final Iterator<SourceTable> i = includeTables.iterator(); i.hasNext();) { final SourceTable candidate = i.next(); for (final Iterator<Relation> j = candidate.getRelations().iterator(); j.hasNext();) { final Relation rel = j.next(); if (rel.getStatus().equals(ComponentStatus.INFERRED_INCORRECT)) continue; if (!rel.isOneToMany()) continue; if (!rel.getManyKey().getTable().equals(candidate)) continue; if (includeTables.contains(rel.getFirstKey().getTable())) rootTables.remove(candidate); } } // We construct one dataset per root table. final List<Mart> suggestedMarts = new ArrayList<Mart>(); for (final Iterator<SourceTable> i = rootTables.iterator(); i.hasNext();) { final SourceTable rootTable = i.next(); Log.debug("Constructing dataset for root table " + rootTable); Mart tmpMart = null; /* * if(reuseMart) { tmpMart = registry.getMartByName(rootTable.getName()); } else */ tmpMart = new Mart(registry, rootTable.getName(), rootTable); tmpMart.setHasSource(true); tmpMart.setTargetSchema(schema); // Process it. final Collection<SourceTable> tablesIncluded = new HashSet<SourceTable>(); tablesIncluded.add(rootTable); Log.debug("Attempting to find subclass marts"); suggestedMarts .addAll(this.continueSubclassing(registry, includeTables, tablesIncluded, tmpMart, rootTable)); } // Synchronise them all. Log.debug("Synchronising constructed marts"); for (Mart ds : suggestedMarts) { ds.setTargetSchema(schema); this.synchronise(ds); } // Do any of the resulting datasets contain all the tables // exactly with subclass relations between each? // If so, just use that one dataset and forget the rest. Log.debug("Finding perfect candidate"); Mart perfectDS = null; for (final Iterator<Mart> i = suggestedMarts.iterator(); i.hasNext() && perfectDS == null;) { final Mart candidate = i.next(); // A candidate is a perfect match if the set of tables // covered by the subclass relations is the same as the // original set of tables requested. final Collection<Table> scTables = new HashSet<Table>(); for (final Iterator<Relation> j = candidate.getRelations().iterator(); j.hasNext();) { final Relation r = j.next(); if (!r.isSubclassRelation(candidate.getName())) continue; scTables.add(r.getFirstKey().getTable()); scTables.add(r.getSecondKey().getTable()); } // Finally perform the check to see if we have them all. if (scTables.containsAll(includeTables)) perfectDS = candidate; } if (perfectDS != null) { Log.debug("Perfect candidate found - dropping others"); // Drop the others. for (final Iterator<Mart> i = suggestedMarts.iterator(); i.hasNext();) { final Mart candidate = i.next(); if (!candidate.equals(perfectDS)) { registry.removeMart(candidate); i.remove(); } } // Rename it to lose any extension it may have gained. String newName = perfectDS.getCentralTable().getName(); String uniqueName = registry.getNextMartName(newName); perfectDS.setName(uniqueName); } else Log.debug("No perfect candidate found - retaining all"); // Return the final set of suggested datasets. return suggestedMarts; }
From source file:org.sakaiproject.content.tool.ListItem.java
protected void captureAccess(ParameterParser params, String index) { String access_mode = params.getString("access_mode" + index); if (access_mode == null || AccessMode.GROUPED.toString().equals(access_mode)) { // we inherit more than one group and must check whether group access changes at this item String[] access_groups = params.getStrings("access_groups" + index); SortedSet<String> new_groups = new TreeSet<String>(); if (access_groups != null) { new_groups.addAll(Arrays.asList(access_groups)); }/*from w w w .j a v a2 s. c om*/ SortedSet<String> new_group_refs = convertToRefs(new_groups); Collection inh_grps = getInheritedGroupRefs(); boolean groups_are_inherited = (new_group_refs.size() == inh_grps.size()) && inh_grps.containsAll(new_group_refs); if (groups_are_inherited) { new_groups.clear(); setGroupsById(new_groups); setAccessMode(AccessMode.INHERITED); } else { setGroupsById(new_groups); setAccessMode(AccessMode.GROUPED); } setPubview(false); } else if (ResourcesAction.PUBLIC_ACCESS.equals(access_mode)) { if (!isPubviewInherited()) { setPubview(true); setAccessMode(AccessMode.INHERITED); } } else if (AccessMode.INHERITED.toString().equals(access_mode)) { captureAccessRoles(params, index); setAccessMode(AccessMode.INHERITED); this.groups.clear(); } }
From source file:ubic.gemma.core.analysis.expression.coexpression.GeneCoexpressionSearchServiceImpl.java
/** * @param genes 1 or more.//from w w w .j ava 2s.c o m * @param stringency; this may be modified to control the number of results, unless "queryGenesOnly" is true. * @param maxResults per gene, not including the query genes themselves. Ignored if this is 'queryGenesOnly' * @param queryGenesOnly will be ignored if number of genes is 1. * @return CoexpressionMetaValueObject, in which the results are already populated and sorted. */ private CoexpressionMetaValueObject doCoexpressionSearch(Collection<Long> inputEeIds, Collection<Long> genes, int stringency, final int maxResults, final boolean queryGenesOnly, final boolean quick) { if (genes.isEmpty()) { CoexpressionMetaValueObject r = new CoexpressionMetaValueObject(); r.setErrorState("No genes selected"); return r; } boolean actuallyUseQueryGeneOnly = queryGenesOnly && genes.size() > 1; Taxon taxon = this.geneService.load(genes.iterator().next()).getTaxon(); List<ExpressionExperimentValueObject> eevos = this.getFilteredEEVos(inputEeIds, taxon); CoexpressionMetaValueObject result = this.initValueObject(genes, eevos); if (eevos.isEmpty()) { result = new CoexpressionMetaValueObject(); result.setErrorState("No experiments selected"); return result; } Collection<Long> eeIds = EntityUtils.getIds(eevos); Map<Long, List<CoexpressionValueObject>> allCoexpressions; // Note: auto-choose stringency on client size not always giving something reasonable. Also: not clear we want // to do this auto-adjust for 'query genes only'. if (genes.size() > GeneCoexpressionSearchServiceImpl.THRESHOLD_TRIGGER_QUERY_GENES_ONLY) { if (!actuallyUseQueryGeneOnly) { GeneCoexpressionSearchServiceImpl.log.info("Switching to 'query genes only'"); } actuallyUseQueryGeneOnly = true; } if (stringency < 1) stringency = 1; if (!queryGenesOnly) { stringency = Math.max(stringency, this.chooseStringency(actuallyUseQueryGeneOnly, eeIds.size(), genes.size())); GeneCoexpressionSearchServiceImpl.log .info("Stringency set to " + stringency + " based on number of experiments (" + eeIds.size() + ") and genes (" + genes.size() + ") queried"); } else { GeneCoexpressionSearchServiceImpl.log .info("Query gene only: stringency maintained at requested value=" + stringency); } assert stringency >= 1 || eeIds.size() == 1; // HACK drop the stringency until we get some results. int stepSize = 3; while (true) { if (actuallyUseQueryGeneOnly) { // note that maxResults is ignored. if (genes.size() < 2) { // should be impossible - could assert. throw new IllegalArgumentException( "cannot do inter-gene coexpression search with only one gene"); } allCoexpressions = coexpressionService.findInterCoexpressionRelationships(taxon, genes, eeIds, stringency, quick); } else { allCoexpressions = coexpressionService.findCoexpressionRelationships(taxon, genes, eeIds, stringency, maxResults, quick); } int minimum_stringency_for_requery = 2; if (allCoexpressions.isEmpty() && stringency > minimum_stringency_for_requery) { stringency -= stepSize; // step size completely made up. stringency = Math.max(minimum_stringency_for_requery, stringency); // keep stringency at least 2. GeneCoexpressionSearchServiceImpl.log.info("No results, re-querying with stringency=" + stringency); } else { // no results. break; } } GeneCoexpressionSearchServiceImpl.log.info("Final actual stringency used was " + stringency); result.setQueryStringency(stringency); result.setQueryGenesOnly(actuallyUseQueryGeneOnly); Set<Long> queryGeneIds = allCoexpressions.keySet(); assert genes.containsAll(queryGeneIds); Map<Long, GeneValueObject> idMap = EntityUtils.getIdMap(geneService.loadValueObjectsByIds(queryGeneIds)); int k = 0; for (Long queryGene : queryGeneIds) { Collection<CoexpressionValueObject> coexpressions = allCoexpressions.get(queryGene); List<CoexpressionValueObjectExt> results = this.addExtCoexpressionValueObjects(idMap.get(queryGene), coexpressions, actuallyUseQueryGeneOnly, genes); result.getResults().addAll(results); CoexpressionSummaryValueObject summary = new CoexpressionSummaryValueObject(queryGene); summary.setDatasetsAvailable(eevos.size()); summary.setLinksFound(coexpressions.size()); result.getSummaries().put(queryGene, summary); if (++k % 100 == 0) { GeneCoexpressionSearchServiceImpl.log.info("Processed results for " + k + " query genes ..."); } } Collections.sort(result.getResults()); // FIXME we might want to suppress this in some situations if (!queryGenesOnly) { result.trim(); } this.populateNodeDegrees(result); return result; }
From source file:org.sakaiproject.calendar.tool.CalendarAction.java
/** * @param newEvent//w w w. j a va2 s. co m */ public void postEventsForChanges(CalendarEventEdit newEvent) { // determine which events should be posted by comparing with saved properties try { Calendar calendar = CalendarService.getCalendar(newEvent.getCalendarReference()); if (calendar != null) { try { CalendarEvent savedEvent = calendar.getEvent(newEvent.getId()); if (savedEvent == null) { } else { EventTrackingService m_eventTrackingService = (EventTrackingService) ComponentManager .get(EventTrackingService.class); // has type changed? String savedType = savedEvent.getType(); String newType = newEvent.getType(); if (savedType == null || newType == null) { // TODO: is this an error? } else { if (!newType.equals(savedType)) { // post type-change event m_eventTrackingService.post(m_eventTrackingService.newEvent( CalendarService.EVENT_MODIFY_CALENDAR_EVENT_TYPE, newEvent.getReference() + "::" + savedType + "::" + newType, true)); } } // has title changed? if (savedEvent.getDisplayName() != null && !savedEvent.getDisplayName().equals(newEvent.getDisplayName())) { // post title-change event m_eventTrackingService.post(m_eventTrackingService.newEvent( CalendarService.EVENT_MODIFY_CALENDAR_EVENT_TITLE, newEvent.getReference(), true)); } // has start-time changed? TimeRange savedRange = savedEvent.getRange(); TimeRange newRange = newEvent.getRange(); if (savedRange == null || newRange == null) { // TODO: Is this an error? } else if (savedRange.firstTime() != null && savedRange.firstTime().compareTo(newRange.firstTime()) != 0) { // post time-change event m_eventTrackingService.post(m_eventTrackingService.newEvent( CalendarService.EVENT_MODIFY_CALENDAR_EVENT_TIME, newEvent.getReference(), true)); } // has access changed? if (savedEvent.getAccess() != newEvent.getAccess()) { // post access-change event m_eventTrackingService.post(m_eventTrackingService.newEvent( CalendarService.EVENT_MODIFY_CALENDAR_EVENT_ACCESS, newEvent.getReference(), true)); } else { Collection savedGroups = savedEvent.getGroups(); Collection newGroups = newEvent.getGroups(); if (!(savedGroups.containsAll(newGroups) && newGroups.containsAll(savedGroups))) { // post access-change event m_eventTrackingService.post(m_eventTrackingService.newEvent( CalendarService.EVENT_MODIFY_CALENDAR_EVENT_ACCESS, newEvent.getReference(), true)); } } // has frequency changed (other than exclusions)? RecurrenceRule savedRule = savedEvent.getRecurrenceRule(); RecurrenceRule newRule = newEvent.getRecurrenceRule(); if (savedRule == null && newRule == null) { // do nothing -- no change } else if (savedRule == null || newRule == null) { // post frequency-change event m_eventTrackingService.post(m_eventTrackingService.newEvent( CalendarService.EVENT_MODIFY_CALENDAR_EVENT_FREQUENCY, newEvent.getReference(), true)); } else { // check for changes in properties of the rules // (rule.getCount() rule.getFrequency() rule.getInterval() rule.getUntil() if (savedRule.getCount() != newRule.getCount() || savedRule.getInterval() != newRule.getInterval()) { // post frequency-change event m_eventTrackingService.post(m_eventTrackingService.newEvent( CalendarService.EVENT_MODIFY_CALENDAR_EVENT_FREQUENCY, newEvent.getReference(), true)); } else if ((savedRule.getFrequency() != null && !savedRule.getFrequency().equals(newRule.getFrequency())) || (savedRule.getFrequency() == null && newRule.getFrequency() != null)) { // post frequency-change event m_eventTrackingService.post(m_eventTrackingService.newEvent( CalendarService.EVENT_MODIFY_CALENDAR_EVENT_FREQUENCY, newEvent.getReference(), true)); } else if ((savedRule.getUntil() == null && newRule.getUntil() != null) || (savedRule.getUntil() != null && newRule.getUntil() == null) || (savedRule.getUntil() != null && savedRule.getUntil().getTime() != newRule.getUntil().getTime())) { // post frequency-change event m_eventTrackingService.post(m_eventTrackingService.newEvent( CalendarService.EVENT_MODIFY_CALENDAR_EVENT_FREQUENCY, newEvent.getReference(), true)); } } } // if } catch (IdUnusedException Exception) { M_log.warn(this + ":postEventsForChanges IdUnusedException Cannot find calendar event for " + newEvent.getId()); } catch (PermissionException Exception) { M_log.warn(this + ":postEventsForChanges PermissionException Cannot find calendar event for " + newEvent.getId()); } } // if } catch (IdUnusedException Exception) { M_log.warn(this + ":postEventsForChanges IdUnusedException Cannot find calendar for " + newEvent.getCalendarReference()); } catch (PermissionException Exception) { M_log.warn(this + ":postEventsForChanges PermissionException Cannot find calendar for " + newEvent.getCalendarReference()); } }