public Sprint findSprintinProject(
     String username, String projectName, String projectType, String sprintName)
     throws NullMongoTemplateException {
   Sprint sprint = null;
   MongoOperations mongoOperations = getMongoOperationInstance();
   if (mongoOperations == null) {
     throw new NullMongoTemplateException();
   }
   ProjectScrum project =
       mongoOperations.findOne(
           query(
               where("projectname")
                   .is(projectName)
                   .and("ownername")
                   .is(username)
                   .and("projecttype")
                   .is(projectType)),
           ProjectScrum.class);
   if (project != null) {
     List<Sprint> sprints = project.getSprints();
     if (sprints.size() == 0) {
       return null;
     }
     for (Sprint sprint1 : sprints) {
       if (sprint1.getSprintName().equals(sprintName)) {
         sprint = sprint1;
         break;
       }
     }
   }
   return sprint;
 }
 @Override
 public void rollback(Change change) {
   OperationType operationType = change.getOperationType();
   try {
     switch (operationType) {
       case CREATE:
         {
           Object targetObject = change.getNewObject();
           Query removeQuery = createFindQuery(targetObject);
           Object removedObject = mongoOperations.findOne(removeQuery, targetObject.getClass());
           if (removedObject != null) {
             mongoOperations.remove(removedObject);
           }
           break;
         }
       case UPDATE:
       case DELETE:
         {
           mongoOperations.save(change.getOldObject());
           break;
         }
     }
   } catch (Exception exc) {
     exc.printStackTrace();
   }
 }
 public Map<String, Integer> getQueuesOverLimit(String projectid, String projecttype)
     throws NullMongoTemplateException {
   MongoOperations mongoOperations = getMongoOperationInstance();
   if (mongoOperations == null) {
     throw new NullMongoTemplateException();
   }
   ProjectWF project =
       mongoOperations.findOne(query(where("_id").is(projectid)), ProjectWF.class, "project");
   List<Task> tasks = project.getTasks();
   int countReady = 0;
   int countInProgress = 0;
   int countComplete = 0;
   for (Task task : tasks) {
     if (task.getStatus().equals("1")) {
       countReady++;
     } else if (task.getStatus().equals("2")) {
       countInProgress++;
     } else {
       countComplete++;
     }
   }
   Map<String, Integer> table = new Hashtable<>();
   table.put("Ready", countReady);
   table.put("Inprogress", countInProgress);
   table.put("Completed", countComplete);
   return table;
 }
 public int getPercentageComplete(String projectid, String projecttype)
     throws NullMongoTemplateException {
   MongoOperations mongoOperations = getMongoOperationInstance();
   if (mongoOperations == null) {
     throw new NullMongoTemplateException();
   }
   ProjectKanban project =
       mongoOperations.findOne(query(where("_id").is(projectid)), ProjectKanban.class, "project");
   List<Task> tasks = project.getTasks();
   int countReady = 0;
   int countInProgress = 0;
   int countComplete = 0;
   for (Task task : tasks) {
     if (task.getStatus().equals("Ready")) {
       countReady++;
     } else if (task.getStatus().equals("Inprogress")) {
       countInProgress++;
     } else {
       countComplete++;
     }
   }
   int totalCount = countComplete + countReady + countInProgress;
   System.out.println(countComplete + countReady + countInProgress);
   int percentageComplete = (1 / 3) * 100;
   return percentageComplete;
 }
 public Project insertProject(Project project) {
   MongoOperations mongoOperations = getMongoOperationInstance();
   if (mongoOperations != null) {
     mongoOperations.insert(project, "project");
   }
   return project;
 }
 public String getProjecttype(String projectid) throws NullMongoTemplateException {
   MongoOperations mongoOperations = getMongoOperationInstance();
   if (mongoOperations == null) {
     throw new NullMongoTemplateException();
   }
   Project project = mongoOperations.findOne(query(where("_id").is(projectid)), Project.class);
   String projectType = project.getProjecttype();
   return projectType;
 }
 @Override
 public void inserirTemplate(Template template) throws ColetorMongoException {
   try {
     mongoOperations.save(template);
   } catch (Exception e) {
     mongoOperations.remove(template);
     throw new ColetorMongoException(e);
   }
 }
 public List<Task> getTasks(String projectid) throws NullMongoTemplateException {
   MongoOperations mongoOperations = getMongoOperationInstance();
   if (mongoOperations == null) {
     throw new NullMongoTemplateException();
   }
   Project project = mongoOperations.findOne(query(where("_id").is(projectid)), Project.class);
   List<Task> tasks = project.getTasks();
   return tasks;
 }
 public void updateProjectAddSprint(String projectid, Sprint sprint)
     throws NullMongoTemplateException {
   MongoOperations mongoOperations = getMongoOperationInstance();
   if (mongoOperations == null) {
     throw new NullMongoTemplateException();
   }
   mongoOperations.updateFirst(
       query(where("_id").is(projectid)), new Update().push("sprints", sprint), Project.class);
 }
  /** Create a capped collection. If you create an uncapped collections the tests go green. */
  @Before
  public void setUp() {
    template.dropCollection(COLLECTION_NAME);

    // capped
    template.createCollection(COLLECTION_NAME, new CollectionOptions(1000, 5, true));

    // uncapped
    // template.createCollection(COLLECTION_NAME);
  }
 /** {@link RepositoryOperations#distinct(String, Iterable)} */
 public List<Object> distinct(String field, Iterable<QueryCriteria> queryCriterias) {
   Criteria criteria = MongoQueryUtils.getQueryFromQueryCriteria(queryCriterias);
   Query query = new Query();
   if (criteria != null) {
     query.addCriteria(criteria);
   }
   return mongoOperations
       .getCollection(mongoOperations.getCollectionName(model))
       .distinct(field, query.getQueryObject());
 }
Пример #12
0
  @Test
  public void testMongoTemplate() throws Exception {

    MongoOperations mongoOps = new MongoTemplate(new Mongo(), "organizer");
    Todo todo1 = new Todo();
    todo1.setId(new Random().nextLong());
    todo1.setTitle("some new todo " + UUID.randomUUID());
    mongoOps.insert(todo1);
    // mongoOps.dropCollection("person");
  }
 public List<Sprint> getSprints(String projectid) throws NullMongoTemplateException {
   MongoOperations mongoOperations = getMongoOperationInstance();
   if (mongoOperations == null) {
     throw new NullMongoTemplateException();
   }
   ProjectScrum project =
       mongoOperations.findOne(query(where("_id").is(projectid)), ProjectScrum.class, "project");
   List<Sprint> sprints = project.getSprints();
   return sprints;
 }
 public void deleteTaskFromProject(String projectid, String taskid)
     throws NullMongoTemplateException {
   MongoOperations mongoOperations = getMongoOperationInstance();
   if (mongoOperations == null) {
     throw new NullMongoTemplateException();
   }
   Query query = new Query(where("_id").is(projectid));
   Update update = new Update().pull("tasks", new BasicDBObject("_id", taskid));
   mongoOperations.updateFirst(query, update, Project.class);
 }
 public void updateProjectAddTaskToProject(Task task, String projectid)
     throws NullMongoTemplateException {
   MongoOperations mongoOperations = getMongoOperationInstance();
   if (mongoOperations == null) {
     throw new NullMongoTemplateException();
   }
   Query query = new Query(where("_id").is(projectid));
   Update update = new Update().push("tasks", task);
   mongoOperations.updateFirst(query, update, Project.class);
 }
 public void updateProjectAddTask(String projectname, String username, Task task)
     throws NullMongoTemplateException {
   MongoOperations mongoOperations = getMongoOperationInstance();
   if (mongoOperations == null) {
     throw new NullMongoTemplateException();
   }
   mongoOperations.updateFirst(
       query(where("projectname").is(projectname).and("ownername").is(username)),
       new Update().push("tasks", task),
       Resource.class);
 }
Пример #17
0
 @Override
 public void alterarTemplate(Template templateAtualizado) throws ColetorMongoException {
   Template templateTemp = null;
   try {
     templateTemp = this.buscarPorId(templateAtualizado.getId());
     mongoOperations.save(templateAtualizado);
   } catch (Exception e) {
     mongoOperations.save(templateTemp);
     throw new ColetorMongoException(e);
   }
 }
  @Before
  public void setUp() {

    if (!operations.collectionExists(Customer.class)) {
      operations.createCollection(Customer.class);
    }

    // just make sure we remove everything properly
    operations.getCollection("system.js").remove(new BasicDBObject());
    repository.deleteAll();
  }
 /**
  * Creates an index on the desired field in the target collection.
  *
  * @param field
  * @param direction
  * @param isUnique
  * @param isSparse
  */
 public void createIndex(
     String field, Sort.Direction direction, boolean isUnique, boolean isSparse) {
   Integer dir = direction.equals(Sort.Direction.ASC) ? 1 : -1;
   DBObject index = new BasicDBObject(field, dir);
   DBObject options = new BasicDBObject();
   if (isSparse) options.put("sparse", true);
   if (isUnique) options.put("unique", true);
   DBCollection collection =
       mongoOperations.getCollection(mongoOperations.getCollectionName(model));
   collection.createIndex(index, options);
 }
 public void updateProjectDeleteStoryFromSprint(
     String projectid, Sprint sprint, String taskScrumid) throws NullMongoTemplateException {
   MongoOperations mongoOperations = getMongoOperationInstance();
   if (mongoOperations == null) {
     throw new NullMongoTemplateException();
   }
   Query query = new Query(where("_id").is(projectid));
   Update update = new Update().pull("sprints", new BasicDBObject("_id", sprint.getId()));
   mongoOperations.updateFirst(query, update, Project.class);
   mongoOperations.updateFirst(
       query(where("_id").is(projectid)), new Update().push("sprints", sprint), Project.class);
 }
  /**
   * Store and call an arbitrary JavaScript function (in this case a simple echo script) via its
   * name.
   */
  @Test
  public void saveAndCallScriptViaName() {

    operations
        .scriptOps()
        .register(
            new NamedMongoScript(
                "echoScript", new ExecutableMongoScript("function(x) { return x; }")));

    Object o = operations.scriptOps().call("echoScript", "Hello echo...!");
    assertThat(o, is((Object) "Hello echo...!"));
  }
  public Project getProject(String projectid) throws NullMongoTemplateException {
    MongoOperations mongoOperations = getMongoOperationInstance();
    if (mongoOperations == null) {
      throw new NullMongoTemplateException();
    }
    Project project = mongoOperations.findOne(query(where("_id").is(projectid)), Project.class);

    if (project.getProjecttype().equals("SCRUM")) {
      ProjectScrum ps =
          mongoOperations.findOne(query(where("_id").is(projectid)), ProjectScrum.class, "project");
      project = ps;
    }
    return project;
  }
  @Override
  public List<MaintenanceSpendBySupplier> getMaintenanceSpendBetweenTwoDates(Date from, Date to) {
    Date fromDate = dateTimeFormatHelper.resetTimeAndMonthStart(from);
    Date toDate = dateTimeFormatHelper.resetTimeAndMonthEnd(to);
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(toDate);
    // Set time fields to last hour:minute:second:millisecond
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 59);
    calendar.set(Calendar.MILLISECOND, 999);

    Query maintenanceSpendListQuery = new Query();
    maintenanceSpendListQuery.addCriteria(
        Criteria.where("transactionDate")
            .exists(true)
            .andOperator(
                Criteria.where("transactionDate").gte(fromDate),
                Criteria.where("transactionDate").lte(calendar.getTime())));

    /*
    List<MaintenanceSpendBySupplier> maintenanceSpendList = mongoOperation.find(maintenanceSpendListQuery, MaintenanceSpendBySupplier.class);

    System.out.println(" MaintenanceSpendBySupplierRepository - GENERAL QUERY - Start= " + to + " | To= " + to);
    if (maintenanceSpendList.isEmpty()) {
    System.out.println("MaintenanceSpendBySupplierRepository  - GENERAL QUERY - NO MATCHING RECORDS FOUND");
    }

    for (MaintenanceSpendBySupplier maintenanceSpend : maintenanceSpendList) {
    System.out.println(" MaintenanceSpendBySupplierRepository - GENERAL QUERY - Date= " + maintenanceSpend.getTransactionDate() + " | Cost= " + maintenanceSpend.getMaintenanceCost() + " | Truck= " + maintenanceSpend.getTruckId() + " | Supplier" + maintenanceSpend.getSupplierId());
    }
    System.out.println("--==--");
    */
    return mongoOperation.find(maintenanceSpendListQuery, MaintenanceSpendBySupplier.class);
  }
  private List<MaintenanceSpendBySupplier> getTruckMaintenanceSpend(
      Truck truck, Date from, Date to) {
    Query truckMaintenanceSpendListQuery = new Query();
    truckMaintenanceSpendListQuery.addCriteria(
        Criteria.where("truckId")
            .is(truck.getId())
            .andOperator(
                Criteria.where("transactionDate").gte(from),
                Criteria.where("transactionDate").lte(to)));

    /*
    * List<MaintenanceSpendBySupplier> maintenanceSpendList = mongoOperation.find(truckMaintenanceSpendListQuery, MaintenanceSpendBySupplier.class);

    System.out.println(" MaintenanceSpendBySupplierRepository - TRUCK QUERY - Start= " + to + " | To= " + to + "  FOR truckId: " + truck.getId());
    if (maintenanceSpendList.isEmpty()) {
    System.out.println("MaintenanceSpendBySupplierRepository  - TRUCK QUERY - NO MATCHING RECORDS FOUND");
    }

    for (MaintenanceSpendBySupplier maintenanceSpend : maintenanceSpendList) {
    System.out.println(" MaintenanceSpendBySupplierRepository - TRUCK QUERY - Date= " + maintenanceSpend.getTransactionDate() + " | Cost= " + maintenanceSpend.getMaintenanceCost() + " | Truck= " + maintenanceSpend.getTruckId() + " | Supplier" + maintenanceSpend.getSupplierId());
    }
    System.out.println("--==--");
    */

    return mongoOperation.find(truckMaintenanceSpendListQuery, MaintenanceSpendBySupplier.class);
  }
 public List<HelloWorld> getManybyName(String name) {
   System.out.println("DAO: Querying all data name:" + name);
   Query query = new Query();
   query.addCriteria(Criteria.where("name").is(name));
   System.out.println("DAO: Return data");
   return mongoOps.find(query, HelloWorld.class, COLLECTION);
 }
  /**
   * Test case to show the usage of the geo-spatial APIs to lookup people within a given distance of
   * a reference point.
   */
  @Test
  public void exposesGeoSpatialFunctionality() {

    GeospatialIndex indexDefinition = new GeospatialIndex("address.location");
    indexDefinition.getIndexOptions().put("min", -180);
    indexDefinition.getIndexOptions().put("max", 180);

    operations.indexOps(Customer.class).ensureIndex(indexDefinition);

    Customer ollie = new Customer("Oliver", "Gierke");
    ollie.setAddress(new Address(new Point(52.52548, 13.41477)));
    ollie = repository.save(ollie);

    Point referenceLocation = new Point(52.51790, 13.41239);
    Distance oneKilometer = new Distance(1, Metrics.KILOMETERS);

    GeoResults<Customer> result =
        repository.findByAddressLocationNear(referenceLocation, oneKilometer);

    assertThat(result.getContent(), hasSize(1));

    Distance distanceToFirstStore = result.getContent().get(0).getDistance();
    assertThat(distanceToFirstStore.getMetric(), is(Metrics.KILOMETERS));
    assertThat(distanceToFirstStore.getValue(), closeTo(0.862, 0.001));
  }
 /** {@link RepositoryOperations#update} */
 public <S extends T> S update(S s) {
   if (exists(s.getId())) {
     mongoOperations.save(s);
     return s;
   }
   return null;
 }
  /*
   * (non-Javadoc)
   * @see de.mq.portfolio.exchangerate.support.ExchangeRateDatebaseRepository#exchangerates(java.util.Collection)
   */
  @Override
  public final Collection<ExchangeRate> exchangerates(
      final Collection<ExchangeRate> exchangerates) {
    Assert.notNull(exchangerates);
    final Collection<ExchangeRate> rates = new HashSet<>();
    rates.addAll(exchangerates);

    rates.addAll(
        exchangerates
            .stream()
            .map(er -> new ExchangeRateImpl(er.target(), er.source()))
            .collect(Collectors.toSet()));

    final Collection<ExchangeRate> results = new HashSet<>();
    rates.forEach(
        rate ->
            results.addAll(
                mongoOperations.find(
                    Query.query(
                        Criteria.where(SOURCE_FIELD_NAME)
                            .is(rate.source())
                            .and(TARGET_FIELD_NAME)
                            .is(rate.target())),
                    ExchangeRateImpl.class)));
    return Collections.unmodifiableCollection(results);
  }
  @Test
  public void testBasicQuery() {
    BasicDBObject query = new BasicDBObject();
    query.put(EmployeeProperties.EMPLOYEE_ID, "28241");

    BasicDBObject fields = new BasicDBObject();
    fields.put(EmployeeProperties.ID, 0);
    fields.put(EmployeeProperties.LAST_NAME, 1);
    fields.put(EmployeeProperties.EMPLOYEE_ID, 1);

    DBCollection collection = mongoOps.getCollection(EmployeeProperties.COLLECTION);
    log.info(
        "MongoDB Query Explain Plan:  "
            + collection
                .find(query, fields)
                .hint(new BasicDBObject(EmployeeProperties.EMPLOYEE_ID, 1))
                .explain());
    DBCursor cursor =
        collection.find(query, fields).hint(new BasicDBObject(EmployeeProperties.EMPLOYEE_ID, 1));

    log.info(cursor.count() + "");

    assertNotNull("cursor was null.", cursor);
    assertEquals("cursor count was not 1.", 1, cursor.count());

    log.info("Query (" + query.toString() + ")");

    while (cursor.hasNext()) {
      DBObject dbo = cursor.next();
      log.info(dbo.toString());
      assertEquals("Keyset size not equal to 2.", 2, dbo.keySet().size());
    }

    log.info(cursor.explain().toString());
  }
Пример #30
0
 private String getEntityOwnerTenant(final EntityResource entityResource) {
   final Class<?> collectionClass =
       (entityBelongsToProvider(entityResource) ? Provider.class : Application.class);
   final Criteria criteria = Criteria.where("_id").is(entityResource.getEntityOwner());
   final TenantResource entityOwner =
       (TenantResource) mongoOps.find(new Query(criteria), collectionClass).get(0);
   return entityOwner.getTenantId();
 }