@Override
 public Iterable<TimelineRecord> getNextRecords(int maxResults) {
   SortedSet<TimelineRecord> result = new TreeSet<>();
   UnitOfWork uow = module.currentUnitOfWork();
   String schedulesName = SchedulerMixin.getSchedulesIdentity(scheduler);
   Schedules schedules = uow.get(Schedules.class, schedulesName);
   for (Schedule schedule : schedules.schedules()) {
     Timeline timeline = (Timeline) schedule;
     Iterable<TimelineRecord> lastRecords = timeline.getNextRecords(maxResults);
     Iterables.addAll(result, lastRecords);
   }
   return Iterables.limit(maxResults, result);
 }
  @Override
  public Iterable<TimelineRecord> getRecords(DateTime from, DateTime to) {
    SortedSet<TimelineRecord> result = new TreeSet<>();

    UnitOfWork uow = module.currentUnitOfWork();
    String schedulesName = SchedulerMixin.getSchedulesIdentity(scheduler);
    Schedules schedules = uow.get(Schedules.class, schedulesName);
    for (Schedule schedule : schedules.schedules()) {
      Timeline timeline = (Timeline) schedule;
      Iterable<TimelineRecord> lastRecords = timeline.getRecords(from, to);
      Iterables.addAll(result, lastRecords);
    }
    return result;
  }
Esempio n. 3
0
  @Test
  public void testOperators()
      throws UnitOfWorkCompletionException, ActivationException, AssemblyException {
    SingletonAssembler assembler =
        new SingletonAssembler() {
          @Override
          public void assemble(ModuleAssembly module) throws AssemblyException {
            new EntityTestAssembler().assemble(module);

            module.entities(TestEntity.class);
            module.values(TestValue.class);
            module.forMixin(TestEntity.class).declareDefaults().foo().set("Bar");
            module.forMixin(TestValue.class).declareDefaults().bar().set("Xyz");
          }
        };

    UnitOfWork uow = assembler.module().newUnitOfWork();

    try {
      EntityBuilder<TestEntity> entityBuilder = uow.newEntityBuilder(TestEntity.class, "123");
      entityBuilder.instance().value().set(assembler.module().newValue(TestValue.class));
      TestEntity testEntity = entityBuilder.newInstance();

      uow.complete();
      uow = assembler.module().newUnitOfWork();

      Iterable<TestEntity> entities = Iterables.iterable(testEntity = uow.get(testEntity));

      QueryBuilder<TestEntity> builder = assembler.module().newQueryBuilder(TestEntity.class);

      {
        Specification<Composite> where =
            QueryExpressions.eq(QueryExpressions.templateFor(TestEntity.class).foo(), "Bar");
        Assert.assertTrue(where.satisfiedBy(testEntity));
        System.out.println(where);
      }
      {
        Specification<Composite> where =
            QueryExpressions.eq(
                QueryExpressions.templateFor(TestEntity.class).value().get().bar(), "Xyz");
        Assert.assertTrue(where.satisfiedBy(testEntity));
        System.out.println(where);

        Assert.assertTrue(builder.where(where).newQuery(entities).find().equals(testEntity));
      }
    } finally {
      uow.discard();
    }
  }
  /**
   * Creates localized messages of all the constraint violations that has occured.
   *
   * <p>The key &nbsp;"<code>Qi4j_ConstraintViolation_<i><strong>CompositeType</strong></code></i>"
   * will be used to lookup the text formatting pattern from the ResourceBundle, where <strong>
   * <code><i>CompositeType</i></code></strong> is the class name of the Composite where the
   * constraint was violated. If such key does not exist, then the key &nbsp;"<code>
   * Qi4j_ConstraintViolation</code>" will be used, and if that one also doesn't exist, or the
   * resourceBundle argument is null, then the default patterns will be used;
   *
   * <table><tr><th>Type of Composite</th><th>Pattern used</th></tr>
   * <tr><td>Composite</td>
   * <td><code>Constraint Violation in {2}.{3} with constraint {4}, in composite \n{0} of type {1}</code></td>
   * </tr>
   * <tr><td>EntityComposite</td>
   * <td><code>Constraint Violation in {2}.{3} with constraint {4}, in entity {1}[id={0}]</code></td>
   * </tr>
   * <tr><td>ServiceComposite</td>
   * <td><code>Constraint Violation in {2}.{3} with constraint {4}, in service {0}</code></td>
   * </tr>
   * </table>
   *
   * Then format each ConstraintViolation according to such pattern, where the following argument
   * are passed;
   *
   * <table><tr><th>Arg</th><th>Value</th></tr>
   * <tr>
   * <td>{0}</td>
   * <td>Composite instance toString()</td>
   * </tr>
   * <tr>
   * <td>{1}</td>
   * <td>CompositeType class name</td>
   * </tr>
   * <tr>
   * <td>{2}</td>
   * <td>MixinType class name</td>
   * </tr>
   * <tr>
   * <td>{3}</td>
   * <td>MixinType method name</td>
   * </tr>
   * <tr>
   * <td>{4}</td>
   * <td>Annotation toString()</td>
   * </tr>
   * <tr>
   * <td>{5}</td>
   * <td>toString() of value passed as the argument, or "null" text if argument was null.</td>
   * </tr>
   * </table>
   *
   * <p><b>NOTE!!!</b> This class is still under construction and will be modified further.
   *
   * @param bundle The ResourceBundle for Localization, or null if default formatting and locale to
   *     be used.
   * @return An array of localized messages of the violations incurred.
   */
  public String[] localizedMessagesFrom(ResourceBundle bundle) {
    String pattern =
        "Constraint violation in {0}.{1} for method ''{3}'' with constraint \"{4}({6})\", for value ''{5}''";

    ArrayList<String> list = new ArrayList<String>();
    for (ConstraintViolation violation : constraintViolations) {
      Locale locale;
      if (bundle != null) {
        try {
          pattern = bundle.getString("qi4j.constraint." + mixinTypeName + "." + methodName);
        } catch (MissingResourceException e1) {
          try {
            pattern = bundle.getString("qi4j.constraint");
          } catch (MissingResourceException e2) {
            // ignore. The default pattern will be used.
          }
        }
        locale = bundle.getLocale();
      } else {
        locale = Locale.getDefault();
      }
      MessageFormat format = new MessageFormat(pattern, locale);

      Annotation annotation = violation.constraint();
      String name = violation.name();
      Object value = violation.value();
      String classes;
      if (Iterables.count(instanceTypes) == 1) {
        classes = Iterables.first(instanceTypes).getSimpleName();
      } else {
        classes =
            "["
                + Iterables.<Class<?>>toString(
                    instanceTypes,
                    new Function<Class<?>, String>() {
                      @Override
                      public String map(Class<?> from) {
                        return from.getSimpleName();
                      }
                    },
                    ",")
                + "]";
      }
      Object[] args =
          new Object[] {
            instanceToString,
            classes,
            mixinTypeName,
            methodName,
            annotation.toString(),
            "" + value,
            name
          };
      StringBuffer text = new StringBuffer();
      format.format(args, text, null);
      list.add(text.toString());
    }
    String[] result = new String[list.size()];
    list.toArray(result);
    return result;
  }
 @Override
 public String toString() {
   return collectionProperty + " contains " + Iterables.toList(valueCollection);
 }
 @Override
 public Iterable<Class<?>> types() {
   return Iterables.<Class<?>>iterable(serviceType);
 }
Esempio n. 7
0
 @Test
 public void testClassScannerJar() {
   Assert.assertEquals(138, Iterables.count(getClasses(Test.class)));
 }