Ejemplo n.º 1
0
  @Override
  public Map<String, Results> validateAll() {
    CacheSchemaLibrary schemaLibrary = schemaLibrary(true);
    if (store.getAdvancedCache().getRpcManager() == null) {
      // This is a non-clustered cache, which cannot run Map-Reduce. In this case, just go through
      // them
      // all and run validation manually using the mapper...
      DocumentValidationMapper mapper =
          new DocumentValidationMapper(schemaLibrary, defaultSchemaUri);
      ResultsCollector resultsCollector = new ResultsCollector();
      for (Map.Entry<String, SchematicEntry> entry : store.entrySet()) {
        String key = entry.getKey();
        SchematicEntry value = entry.getValue();
        mapper.map(key, value, resultsCollector);
      }
      return resultsCollector.getResultsByKey();
    }

    // It is a clustered cache, so we can run Map-Reduce ...

    // Create a copy of all of the JSON Schema documents ...
    InMemoryDocumentLibrary schemaDocs = new InMemoryDocumentLibrary(schemaLibrary.getName());
    for (Map.Entry<String, SchematicEntry> entry : schemaLibrary.store().entrySet()) {
      String key = entry.getKey();
      SchematicEntry value = entry.getValue();
      schemaDocs.put(key, value.getContentAsDocument());
    }

    // Now create the Map-Reduce task, using the copy of the JSON Schema library ...
    MapReduceTask<String, SchematicEntry, String, Results> task =
        new MapReduceTask<String, SchematicEntry, String, Results>(this.store);
    task.mappedWith(new DocumentValidationMapper(schemaDocs, defaultSchemaUri));
    task.reducedWith(new DocumentValidationReducer());

    // Now execute ...
    return task.execute();
  }