private static Document mergeDataSets(final Iterable<Document> dataSetList) { final Document dataSet = new Document(); for (final Document doc : dataSetList) { doc.forEach(dataSet::put); } return dataSet; }
private static JSONObject documentToJSON(Document doc){ JSONObject ret = new JSONObject(); doc.forEach((prop, value) -> ret.put(prop, value)); return ret; }
/** * Method which is used for extracting record values (in the form of an Object array) from a * MongoDB {@link Document}, according to the table's field type order. * * @param document the {@link Document} from which the values should be retrieved. * @return an array of extracted values, all cast to {@link Object} type for portability. */ private Object[] extractRecord(Document document) { List<Object> result = new ArrayList<>(); for (String attributeName : this.attributeNames) { Object attributeValue = document.get(attributeName); if (attributeValue instanceof Document) { HashMap<Object, Object> attributAsAMap = new HashMap<>(); ((Document) attributeValue).forEach(attributAsAMap::put); result.add(attributAsAMap); } else { result.add(attributeValue); } } return result.toArray(); }
public Map<String, AdditionalAttribute> convertAdditionalAttributesToDataModelType(Document customAnnotation) { Map<String, AdditionalAttribute> attributeMap = new HashMap<>(); for (String key : customAnnotation.keySet()) { Document document = customAnnotation.get(key, Document.class); HashMap<String, String> map = new HashMap<>(); document.forEach((k, value) -> map.put(k, value.toString())); AdditionalAttribute attribute = new AdditionalAttribute(map); attributeMap.put(key, attribute); } return attributeMap; }
public static JSONObject getNodeByKey(String job_id, String key){ JSONObject ret = new JSONObject(); db.getCollection("nodes").find(eq("_id", getDbKey(job_id, key))).first() .forEach((prop, value) -> ret.put(prop, value)); return ret; }
public static JSONObject getEdgeByKey(String job_id, String key){ JSONObject ret = new JSONObject(); db.getCollection("edges").find(eq("_id", getDbKey(job_id, key))).first() .forEach((prop, value) -> ret.put(prop, value)); return ret; }
@Override public QueryResult updateProjectMetadata(ProjectMetadata projectMetadata, boolean updateCounters) { Document mongo = new GenericDocumentComplexConverter<>(ProjectMetadata.class).convertToStorageType(projectMetadata); // Update field by field, instead of replacing the whole object to preserve existing fields like "_lock" List<Bson> updates = new ArrayList<>(mongo.size()); mongo.forEach((s, o) -> { // Do not update counters if (updateCounters || !s.equals(COUNTERS_FIELD)) { updates.add(new Document("$set", new Document(s, o))); } }); return collection.update(QUERY, Updates.combine(updates), new QueryOptions(UPSERT, true)); }
@Override public QueryResult updateStudyConfiguration(StudyConfiguration studyConfiguration, QueryOptions options) { Document studyMongo = new DocumentToStudyConfigurationConverter().convertToStorageType(studyConfiguration); // Update field by field, instead of replacing the whole object to preserve existing fields like "_lock" Document query = new Document("_id", studyConfiguration.getStudyId()); List<Bson> updates = new ArrayList<>(studyMongo.size()); studyMongo.forEach((s, o) -> updates.add(new Document("$set", new Document(s, o)))); QueryResult<UpdateResult> queryResult = collection.update(query, Updates.combine(updates), new QueryOptions(UPSERT, true)); // studyConfigurationMap.put(studyConfiguration.getStudyId(), studyConfiguration); return queryResult; }
((Document) expectedIndex.getKeys()).forEach((key, value) -> indexName.append("_").append(key).append("_").append(value)); indexName.deleteCharAt(0);
if (studyDocument.containsKey(GENOTYPES_FIELD)) { studyDocument.get(GENOTYPES_FIELD, Document.class) .forEach((gt, sampleIds) -> addSampleIdsGenotypes(gts, gt, (Collection<Integer>) sampleIds)); if (studyDocument.containsKey(GENOTYPES_FIELD)) { studyDocument.get(GENOTYPES_FIELD, Document.class) .forEach((gt, sampleIds) -> addSampleIdsGenotypes(gts, gt, (Collection<Integer>) sampleIds));
private IdentityProvider convert(IdentityProviderMongo identityProviderMongo) { if (identityProviderMongo == null) { return null; } IdentityProvider identityProvider = new IdentityProvider(); identityProvider.setId(identityProviderMongo.getId()); identityProvider.setName(identityProviderMongo.getName()); identityProvider.setType(identityProviderMongo.getType()); identityProvider.setConfiguration(identityProviderMongo.getConfiguration()); identityProvider.setMappers((Map) identityProviderMongo.getMappers()); if (identityProviderMongo.getRoleMapper() != null) { Map<String, String[]> roleMapper = new HashMap<>(identityProviderMongo.getRoleMapper().size()); identityProviderMongo.getRoleMapper().forEach((key, value) -> { List lstValue = (List) value; String[] arr = new String[lstValue.size()]; lstValue.toArray(arr); roleMapper.put(key, arr); }); identityProvider.setRoleMapper(roleMapper); } identityProvider.setDomain(identityProviderMongo.getDomain()); identityProvider.setExternal(identityProviderMongo.isExternal()); identityProvider.setCreatedAt(identityProviderMongo.getCreatedAt()); identityProvider.setUpdatedAt(identityProviderMongo.getUpdatedAt()); return identityProvider; }