@Override public List<Execution> getActiveTests() { List<Execution> result = new ArrayList<>(); for(Execution execution:collection.find("{status: { $ne: 'ENDED' }}").as(Execution.class)) { result.add(execution); } return result; }
@Override public List<Execution> getTestExecutionsByArtefactURL(String artefactURL) { List<Execution> result = new ArrayList<>(); for(Execution execution:collection.find("{artefactURL: '" + artefactURL +"'}").as(Execution.class)) { result.add(execution); } return result; }
@Override public List<User> getAllUsers() { List<User> result = new ArrayList<>(); collection.find().as(User.class).iterator().forEachRemaining(u->result.add(u)); return result; }
@Override public Iterator<AbstractArtefact> getRootArtefacts() { JsonObjectBuilder builder = jsonProvider.createObjectBuilder(); builder.add("root", true); return collection.find(builder.build().toString()).as(AbstractArtefact.class); }
@Override public Set<String> getStateIds() { Iterator<MongoState> res = getCollection().find().as(MongoState.class).iterator(); Set<String> result = new HashSet<String>(); while (res.hasNext()){ MongoState state = res.next(); result.add(state.getId()); } return result; } }
@Override public Iterable<T> find(final String query, Object... queryParams) throws MongoDataException { try { return returnList(getCollection().find(query, queryParams)); } catch (MongoException ex) { String msg = "Unable to find documents by query " + query + " of type " + clazz.getName() + " with params " + Arrays.toString(queryParams); log.error(msg, ex); throw new MongoDataException(msg, ex); } }
@Override public Iterator<ExecutiontTaskParameters> getActiveExecutionTasks() { return collection.find("{active:true}").as(ExecutiontTaskParameters.class).iterator(); } }
@Override public Iterable<T> findAll() throws MongoDataException { try { return returnList(getCollection().find()); } catch (MongoException ex) { String msg = "Unable to find all documents of type " + clazz.getName(); log.error(msg, ex); throw new MongoDataException(msg, ex); } }
@Override public Iterable<T> find(final String query) throws MongoDataException { try { return returnList(getCollection().find(query)); } catch (MongoException ex) { String msg = "Unable to find documents by query " + query + " of type " + clazz.getName(); log.error(msg, ex); throw new MongoDataException(msg, ex); } }
@Override public Iterator<ReportNode> getReportNodesByExecutionIDAndClass(String executionID, String class_) { assert executionID != null; return collection.find( "{executionID: #, _class: #}", executionID, class_).as(ReportNode.class).iterator(); }
public void readLatestControllerLog() { MongoCursor<ControllerLog> cursor = controllerLogs.find().sort("{start:-1}").as(ControllerLog.class); if(cursor.count()>0) { latestControllerLog = controllerLogs.find().sort("{start:-1}").as(ControllerLog.class).next(); logger.info("Last start of the controller: "+ latestControllerLog.toString()); } else { logger.info("No start log found. Starting the controller for the first time against this DB..."); } }
@Override public Iterator<ReportNode> getFailedLeafReportNodesByExecutionID(String executionID) { assert executionID != null; return collection.find("{executionID: #, $or: [ { _class: 'step.commons.model.report.CallFunctionReportNode', status: {$ne:'PASSED'}}, { status: 'TECHNICAL_ERROR'} ]}", executionID) .sort("{executionTime: 1}").as(ReportNode.class).iterator(); }
@Override public Iterable<Execution> findLastStarted(int limit) { String sort = "{ startTime: -1}"; return collection.find().sort(sort).limit(limit).as(Execution.class); }
@Override public Iterator<ReportNode> getReportNodesByExecutionIDAndArtefactID(String executionID, String artefactID) { assert executionID != null; assert artefactID!=null; return collection.find("{executionID: #, artefactID: #}", executionID, new ObjectId(artefactID)).as(ReportNode.class).iterator(); }
@Override public Iterator<ReportNode> getReportNodesByExecutionID(String executionID) { assert executionID != null; return collection.find("{executionID: #}", executionID).sort("{executionTime: 1}").as(ReportNode.class).iterator(); }
private Iterator<String> doFind(MongoCollection collection, String opQuery, Object[] parameters) { if (opQuery != null) { if (parameters.length > 0) { return collection.find(opQuery, parameters).map(MongoResultMapper.getInstance()).iterator(); } else { return collection.find(opQuery).map(MongoResultMapper.getInstance()).iterator(); } } else { return collection.find().map(MongoResultMapper.getInstance()).iterator(); } }
@Override public Iterable<Execution> findLastEnded(int limit) { String sort = "{ endTime: -1}"; return collection.find().sort(sort).limit(limit).as(Execution.class); } }
@Override public Iterator<ReportNode> getLeafReportNodesByExecutionID(String executionID) { assert executionID != null; return collection.find( "{executionID: #, $or: [ { _class: 'step.commons.model.report.CallFunctionReportNode' }, { status: 'TECHNICAL_ERROR'} ]}", executionID) .sort("{executionTime: 1}").as(ReportNode.class).iterator(); }
@Override public Iterator<ReportNode> getChildren(ObjectId parentID) { return collection.find("{parentID: #}",parentID).sort("{executionTime: 1}").as(ReportNode.class).iterator(); }
@Override public Iterator<ReportNode> getChildren(ObjectId parentID, int skip, int limit) { return collection.find("{parentID: #}",parentID).skip(skip).limit(limit).sort("{executionTime: 1}").as(ReportNode.class).iterator(); }