List of usage examples for com.mongodb BasicDBList BasicDBList
BasicDBList
From source file:eu.vital.vitalcep.publisher.encoder.Encoder.java
public Document dolceOutput2Document(String input, String id, String sensor, String observationTime) throws ParseException { Document outputObservation = new Document(); String[] values = input.split(" "); String valueEvent = null;//from w w w .j av a 2 s . c om String locationEvent = null; String timeEvent = null; String idEvent = null; String complexEvent = null; Boolean hasLoc = false; complexEvent = values[1]; BasicDBList payloadBDBList = new BasicDBList(); for (int z = 3; z < values.length; z++) { Document payloadLine = new Document(); String token = values[z]; if (token.compareToIgnoreCase("SensorId") == 0) { idEvent = values[z + 1].substring(1, values[z + 1].length() - 2); payloadLine.put("dataType", "string"); payloadLine.put("name", values[z]); payloadLine.put("value", values[z + 1].substring(1, values[z + 1].length() - 2)); payloadBDBList.add(payloadLine); } else if (token.compareToIgnoreCase("Position") == 0) { locationEvent = values[z + 1]; payloadLine.put("dataType", "pos"); payloadLine.put("name", values[z]); payloadLine.put("value", values[z + 1]); payloadBDBList.add(payloadLine); hasLoc = true; } else if (token.equals("Time")) { timeEvent = getDolceTime2UTCString(values[z + 1]); payloadLine.put("dataType", "time"); payloadLine.put("name", values[z]); payloadLine.put("value", timeEvent); payloadBDBList.add(payloadLine); //from observationTime } else if ((z % 3) == 0) { valueEvent = values[z + 1]; payloadLine.put("dataType", values[z - 1]); payloadLine.put("name", values[z]); if ("time".equals(values[z - 1])) { payloadLine.put("value", getDolceTime2UTCString(values[z + 1])); } else { payloadLine.put("value", values[z + 1]); } payloadBDBList.add(payloadLine); } } outputObservation.put("@context", "http://vital-iot.eu/contexts/measurement.jsonld"); outputObservation.put("id", sensor + "/observation/" + id); outputObservation.put("type", "ssn:Observation"); outputObservation.put("ssn:observedBy", sensor); Document property = new Document(); property.put("type", "vital:ComplexEvent"); outputObservation.put("ssn:observationProperty", property); Document resultTime = new Document(); if (timeEvent != null) { resultTime.put("time:inXSDDateTime", timeEvent);//check format } else { resultTime.put("time:inXSDDateTime", observationTime); } outputObservation.put("ssn:observationResultTime", resultTime); //"time:inXSDDateTime": "2015-10-14T11:59:11+02:00" Document hasValue = new Document(); hasValue.put("type", "ssn:ObservationValue"); Document valuex = new Document(); Document value = new Document(); value.put("complexEvent", complexEvent); value.put("payload", payloadBDBList); /* busca localization*/ if (hasLoc) { String[] aLoc = locationEvent.split("\\\\"); //de Elisa values[10].split("\\"); Document loc = new Document(); loc.put("type", "geo:Point"); loc.put("geo:lat", aLoc[1]);//ver loc.put("geo:long", aLoc[0]);//ver value.put("dul:hasLocation", loc); } /* busca el value*/ Document speedObs = new Document(); speedObs.put("type", "ssn:SensorOutput"); Document speedValue = new Document(); speedValue.put("type", "ssn:ObservationValue"); speedValue.put("value", valueEvent); //de Elisavalues[5]); speedValue.put("qudt:unit", "qudt:KilometerPerHour"); speedObs.put("ssn:hasValue", speedValue); //value.put("ssn:ObservationResult",speedObs); //ver si falta algo value.put("ssn:observedBy", idEvent); valuex.put("value", value); valuex.put("type", "ssn:ObservationValue"); Document observationResult = new Document(); observationResult.put("ssn:hasValue", valuex); observationResult.put("type", "ssn:SensorOutput"); outputObservation.put("ssn:observationResult", observationResult); return outputObservation; }
From source file:example.springdata.mongodb.util.MongosSystemForTestFactory.java
License:Apache License
private void initializeReplicaSet(Entry<String, List<IMongodConfig>> entry) throws Exception { String replicaName = entry.getKey(); List<IMongodConfig> mongoConfigList = entry.getValue(); if (mongoConfigList.size() < 3) { throw new Exception("A replica set must contain at least 3 members."); }//from w w w . j av a 2 s . c om // Create 3 mongod processes for (IMongodConfig mongoConfig : mongoConfigList) { if (!mongoConfig.replication().getReplSetName().equals(replicaName)) { throw new Exception("Replica set name must match in mongo configuration"); } IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder().defaultsWithLogger(Command.MongoD, logger) .processOutput(outputFunction.apply(Command.MongoD)).build(); MongodStarter starter = MongodStarter.getInstance(runtimeConfig); MongodExecutable mongodExe = starter.prepare(mongoConfig); MongodProcess process = mongodExe.start(); mongodProcessList.add(process); } Thread.sleep(1000); MongoClientOptions mo = MongoClientOptions.builder().connectTimeout(10).build(); MongoClient mongo = new MongoClient( new ServerAddress(mongoConfigList.get(0).net().getServerAddress().getHostName(), mongoConfigList.get(0).net().getPort()), mo); DB mongoAdminDB = mongo.getDB(ADMIN_DATABASE_NAME); CommandResult cr = mongoAdminDB.command(new BasicDBObject("isMaster", 1)); logger.info("isMaster: {}", cr); // Build BSON object replica set settings DBObject replicaSetSetting = new BasicDBObject(); replicaSetSetting.put("_id", replicaName); BasicDBList members = new BasicDBList(); int i = 0; for (IMongodConfig mongoConfig : mongoConfigList) { DBObject host = new BasicDBObject(); host.put("_id", i++); host.put("host", mongoConfig.net().getServerAddress().getHostName() + ":" + mongoConfig.net().getPort()); members.add(host); } replicaSetSetting.put("members", members); logger.info(replicaSetSetting.toString()); // Initialize replica set cr = mongoAdminDB.command(new BasicDBObject("replSetInitiate", replicaSetSetting)); logger.info("replSetInitiate: {}", cr); Thread.sleep(5000); cr = mongoAdminDB.command(new BasicDBObject("replSetGetStatus", 1)); logger.info("replSetGetStatus: {}", cr); // Check replica set status before to proceed while (!isReplicaSetStarted(cr)) { logger.info("Waiting for 3 seconds..."); Thread.sleep(1000); cr = mongoAdminDB.command(new BasicDBObject("replSetGetStatus", 1)); logger.info("replSetGetStatus: {}", cr); } mongo.close(); mongo = null; }
From source file:ezbake.locksmith.db.AbstractLocksmithManager.java
License:Apache License
protected DBObject keyQuery(String id, String user) { DBObject keyMatch = new BasicDBObject(KEY_ID, id); if (user != null) { DBObject ownerMatch = new BasicDBObject(KEY_OWNER, user); DBObject sharedMAtch = new BasicDBObject(ACCESS_LIST, user); BasicDBList exp1 = new BasicDBList(); exp1.add(ownerMatch);/*www. j a v a 2 s . co m*/ exp1.add(sharedMAtch); keyMatch.put("$or", exp1); } return keyMatch; }
From source file:ezbake.services.centralPurge.helpers.EzCentralPurgeServiceHelpers.java
License:Apache License
public static BasicDBList encodeURISet(Set<Long> longSet) { BasicDBList basicDBList = new BasicDBList(); for (Long uri : longSet) { BasicDBObject dbURI = new BasicDBObject(); dbURI.append(URI, uri);// ww w .j a v a 2s . co m basicDBList.add(dbURI); } return basicDBList; }
From source file:ezbake.services.centralPurge.helpers.EzCentralPurgeServiceHelpers.java
License:Apache License
public static DBObject encodePurgeInitiationResult(PurgeInitiationResult purgeInitiationResult) { BasicDBList basicDBList = new BasicDBList(); for (String uri : purgeInitiationResult.getUrisNotFound()) { BasicDBObject dbURI = new BasicDBObject(); dbURI.append(URI, uri);// w ww. j a v a 2 s. c om basicDBList.add(dbURI); } DBObject setToBePurged = encodeURISet(purgeInitiationResult.getToBePurged()); BasicDBObjectBuilder purgeInitiationResultBuilder = BasicDBObjectBuilder.start() .add(PurgeId, purgeInitiationResult.getPurgeId()).add(ToBePurged, setToBePurged) .add(URIsNotFoundSet, basicDBList); return purgeInitiationResultBuilder.get(); }
From source file:ezbake.services.centralPurge.helpers.EzCentralPurgeServiceHelpers.java
License:Apache License
public static BasicDBList encodeApplicationPurgeState(ApplicationPurgeState applicationPurgeState) { BasicDBList basicDBList = new BasicDBList(); Map<String, ServicePurgeState> servicePurgeStateMap = applicationPurgeState.getServicePurgestates(); for (String serviceName : servicePurgeStateMap.keySet()) { BasicDBObject dbServicePurgestate = new BasicDBObject(); dbServicePurgestate.append(ServiceName, serviceName); dbServicePurgestate.append(PurgeStateString, encodeServicePurgeState(servicePurgeStateMap.get(serviceName))); basicDBList.add(dbServicePurgestate); }/*from www. j a va 2 s . c o m*/ return basicDBList; }
From source file:ezbake.services.centralPurge.helpers.EzCentralPurgeServiceHelpers.java
License:Apache License
public static BasicDBList encodeApplicationStateMap(Map<String, ApplicationPurgeState> appMap) { BasicDBList basicDBList = new BasicDBList(); for (String key : appMap.keySet()) { ApplicationPurgeState applicationPurgeState = appMap.get(key); BasicDBObject dbApplicationPurgeState = new BasicDBObject(); dbApplicationPurgeState.append(ApplicationName, key); dbApplicationPurgeState.append(ApplicationPurgeStateString, encodeApplicationPurgeState(applicationPurgeState)); basicDBList.add(dbApplicationPurgeState); }//from w w w .ja v a2 s.co m return basicDBList; }
From source file:ezbake.services.centralPurge.helpers.EzCentralPurgeServiceHelpers.java
License:Apache License
public static DBObject encodePurgeInfo(PurgeInfo purgeInfo) { BasicDBList basicDBListUris = new BasicDBList(); for (String uri : purgeInfo.getDocumentUris()) { BasicDBObject dbURI = new BasicDBObject(); dbURI.append(URI, uri);/*from w w w . j a v a2 s . com*/ basicDBListUris.add(dbURI); } BasicDBList basicDBListUrisNotFound = new BasicDBList(); for (String uriNotFound : purgeInfo.getDocumentUrisNotFound()) { BasicDBObject dbURINotFound = new BasicDBObject(); dbURINotFound.append(URI, uriNotFound); basicDBListUris.add(dbURINotFound); } BasicDBObjectBuilder purgeInfoBuilder = BasicDBObjectBuilder.start().add(PurgeId, purgeInfo.getId()) .add(PurgeBitVector, encodeURISet(purgeInfo.getPurgeDocumentIds())) .add(Description, purgeInfo.getDescription()).add(PurgeName, purgeInfo.getName()) .add(User, purgeInfo.getUser()) .add(CompletelyPurged, encodeURISet(purgeInfo.getCompletelyPurgedDocumentIds())) .add(Resolved, purgeInfo.isResolved()).add(URIsFoundSet, basicDBListUris) .add(URIsNotFoundSet, basicDBListUrisNotFound) .add(TimeStampString, encodeDateTime(purgeInfo.getTimeStamp())); return purgeInfoBuilder.get(); }
From source file:FloodPrototype.FloodProvider.java
License:Apache License
@Override public List<DBObject> update(User user, Date minTimestamp, Date maxTimestamp) { List<DBObject> list = new ArrayList<DBObject>(); BasicDBList timestamp = new BasicDBList(); timestamp.add(new BasicDBObject("timestamp", new BasicDBObject("$gt", minTimestamp))); timestamp.add(new BasicDBObject("timestamp", new BasicDBObject("$lte", maxTimestamp))); BasicDBObject query = new BasicDBObject("$and", timestamp); query.append("class", "flood"); DBCursor cursor = db.getCollection("events").find(query).sort(new BasicDBObject("timestamp", -1)); for (DBObject obj : cursor) { //if( obj.get("event").equals("new") ) { BasicDBObject objQuery = new BasicDBObject("_id", obj.get("id")); obj.put("data", db.getCollection("floodsims").findOne(objQuery)); list.add(obj);/*from www . j a v a2 s . co m*/ //} } return list; }
From source file:fr.cirad.web.controller.gigwa.base.AbstractVariantController.java
License:Open Source License
/** * Builds the variant data query./* ww w.j ava 2s . c o m*/ * * @param sModule the module * @param projId the proj id * @param selectedVariantTypes the selected variant types * @param selectedSequences the selected sequences * @param minposition the minposition * @param maxposition the maxposition * @param alleleCounts the allele counts * @return the basic db list * @throws Exception the exception */ private BasicDBList buildVariantDataQuery(String sModule, int projId, List<String> selectedVariantTypes, List<String> selectedSequences, Long minposition, Long maxposition, List<String> alleleCounts) throws Exception { BasicDBList variantFeatureFilterList = new BasicDBList(); /* Step to match selected variant types */ if (selectedVariantTypes != null && selectedVariantTypes.size() > 0) { BasicDBList orList1 = new BasicDBList(); DBObject orSelectedVariantTypesList = new BasicDBObject(); for (String aSelectedVariantTypes : selectedVariantTypes) { DBObject orClause1 = new BasicDBObject(VariantData.FIELDNAME_TYPE, aSelectedVariantTypes); orList1.add(orClause1); orSelectedVariantTypesList.put("$or", orList1); } variantFeatureFilterList.add(orSelectedVariantTypesList); } /* Step to match selected chromosomes */ if (selectedSequences != null && selectedSequences.size() > 0 && selectedSequences.size() != getProjectSequences(sModule, projId).size()) variantFeatureFilterList.add(new BasicDBObject( VariantData.FIELDNAME_REFERENCE_POSITION + "." + ReferencePosition.FIELDNAME_SEQUENCE, new BasicDBObject("$in", selectedSequences))); /* Step to match variants that have a position included in the specified range */ if (minposition != null || maxposition != null) { if (minposition != null) { DBObject firstPosStart = new BasicDBObject( VariantData.FIELDNAME_REFERENCE_POSITION + "." + ReferencePosition.FIELDNAME_START_SITE, new BasicDBObject("$gte", minposition)); variantFeatureFilterList.add(firstPosStart); } if (maxposition != null) { DBObject lastPosStart = new BasicDBObject( VariantData.FIELDNAME_REFERENCE_POSITION + "." + ReferencePosition.FIELDNAME_START_SITE, new BasicDBObject("$lte", maxposition)); variantFeatureFilterList.add(lastPosStart); } } /* Step to match selected number of alleles */ if (alleleCounts != null) { BasicDBList orList3 = new BasicDBList(); DBObject orSelectedNumberOfAllelesList = new BasicDBObject(); for (String aSelectedNumberOfAlleles : alleleCounts) { int alleleNumber = Integer.parseInt(aSelectedNumberOfAlleles); orList3.add(new BasicDBObject(VariantData.FIELDNAME_KNOWN_ALLELE_LIST, new BasicDBObject("$size", alleleNumber))); orSelectedNumberOfAllelesList.put("$or", orList3); } variantFeatureFilterList.add(orSelectedNumberOfAllelesList); } return variantFeatureFilterList; }