private Message addUserView() { try { DesignDocument userDocument = prepareDocument("_design/users"); Map<String, MapReduce> views = new HashMap<>(); MapReduce passwordFunction = new MapReduce(); passwordFunction.setMap("function(doc) { if(doc.email&& doc.password) { emit(doc.email, doc.password); } }"); MapReduce usernameFunction = new MapReduce(); usernameFunction.setMap("function(doc) { if(doc.email) { emit(doc.email, doc); } }"); views.put("password", passwordFunction); views.put("username", usernameFunction); userDocument.setViews(views); Response resp = Utils.getCouchDbUserClient().design().synchronizeWithDb(userDocument); if (resp.getError() != null) return Notifications.error("Preparing database 'users'..."); else return Notifications.success("Preparing database 'users'..."); } catch (Exception e) { return Notifications.error("Preparing database 'users'..."); } }
private Message addConnectionView() { try { DesignDocument connectionDocument = prepareDocument("_design/connection"); Map<String, MapReduce> views = new HashMap<>(); MapReduce frequentFunction = new MapReduce(); frequentFunction.setMap("function(doc) { if(doc.from && doc.to) { emit([doc.from, doc.to] , 1 ); } }"); frequentFunction.setReduce("function (key, values) { return sum(values); }"); views.put("frequent", frequentFunction); connectionDocument.setViews(views); Response resp = Utils.getCouchDbConnectionClient().design().synchronizeWithDb(connectionDocument); if (resp.getError() != null) return Notifications.error("Preparing database 'connection'..."); else return Notifications.success("Preparing database 'connection'..."); } catch (Exception e) { return Notifications.error("Preparing database 'connection'..."); } }
private Message addUserView() { try { DesignDocument userDocument = prepareDocument("_design/users"); Map<String, MapReduce> views = new HashMap<>(); MapReduce passwordFunction = new MapReduce(); passwordFunction.setMap("function(doc) { if(doc.email&& doc.password) { emit(doc.email, doc.password); } }"); MapReduce usernameFunction = new MapReduce(); usernameFunction.setMap("function(doc) { if(doc.email) { emit(doc.email, doc); } }"); views.put("password", passwordFunction); views.put("username", usernameFunction); userDocument.setViews(views); Response resp = Utils.getCouchDbUserClient().design().synchronizeWithDb(userDocument); if (resp.getError() != null) return Notifications.error("Preparing database 'users'..."); else return Notifications.success("Preparing database 'users'..."); } catch (Exception e) { return Notifications.error("Preparing database 'users'..."); } }
private Message addConnectionView() { try { DesignDocument connectionDocument = prepareDocument("_design/connection"); Map<String, MapReduce> views = new HashMap<>(); MapReduce frequentFunction = new MapReduce(); frequentFunction.setMap("function(doc) { if(doc.from && doc.to) { emit([doc.from, doc.to] , 1 ); } }"); frequentFunction.setReduce("function (key, values) { return sum(values); }"); views.put("frequent", frequentFunction); connectionDocument.setViews(views); Response resp = Utils.getCouchDbConnectionClient().design().synchronizeWithDb(connectionDocument); if (resp.getError() != null) return Notifications.error("Preparing database 'connection'..."); else return Notifications.success("Preparing database 'connection'..."); } catch (Exception e) { return Notifications.error("Preparing database 'connection'..."); } }