Ejemplo n.º 1
0
  /*
   * List of expressions in GDL 1. guide definition pre-conditions 2.
   * archetype binding predicates 3. rule when statements 4. rule then
   * statements
   */
  private void bindExpressions(Guide guide) throws Exception {
    List<String> preConditions = guide.getDefinition().getPreConditions();

    guide.getDefinition().setPreConditionExpressions(parseExpressions(preConditions));

    GuideDefinition definition = guide.getDefinition();
    if (definition.getArchetypeBindings() != null) {
      Collection<ArchetypeBinding> bindings = definition.getArchetypeBindings();
      for (ArchetypeBinding binding : bindings) {
        binding.setPredicateStatements(parseExpressions(binding.getPredicates()));
      }
      if (definition.getRules() != null) {
        Collection<Rule> rules = definition.getRules().values();
        for (Rule rule : rules) {
          rule.setWhenStatements(parseExpressions(rule.getWhen()));
          rule.setThenStatements(toAssignments(parseExpressions(rule.getThen())));
        }
      }
    }
  }
Ejemplo n.º 2
0
  /** Guide parsing */
  public static Guide parseGuide(String json) throws JSONException {
    JSONObject jGuide = new JSONObject(json);
    JSONArray jSteps = jGuide.getJSONArray("steps");
    JSONArray jTools = jGuide.getJSONArray("tools");
    JSONArray jParts = jGuide.getJSONArray("parts");
    JSONObject jAuthor = jGuide.getJSONObject("author");
    Guide guide = new Guide(jGuide.getInt("guideid"));

    guide.setTitle(jGuide.getString("title"));
    guide.setTopic(jGuide.getString("category"));
    guide.setSubject(jGuide.getString("subject"));
    guide.setAuthor(jAuthor.getString("username"));
    guide.setTimeRequired(jGuide.getString("time_required"));
    guide.setDifficulty(jGuide.getString("difficulty"));
    guide.setIntroductionRaw(jGuide.getString("introduction_raw"));
    guide.setIntroductionRendered(jGuide.getString("introduction_rendered"));
    guide.setIntroImage(parseImage(jGuide, "image"));
    guide.setSummary(jGuide.isNull("summary") ? "" : jGuide.getString("summary"));
    guide.setRevisionid(jGuide.getInt("revisionid"));
    guide.setPublic(jGuide.getBoolean("public"));
    guide.setType(jGuide.getString("type"));
    guide.setPatrolThreshold(jGuide.getInt("patrol_threshold"));

    if (jGuide.has("can_edit")) {
      guide.setCanEdit(jGuide.getBoolean("can_edit"));
    }

    for (int i = 0; i < jSteps.length(); i++) {
      guide.addStep(parseStep(jSteps.getJSONObject(i), i + 1));
    }

    for (int i = 0; i < jTools.length(); i++) {
      guide.addTool(parseTool(jTools.getJSONObject(i)));
    }

    for (int i = 0; i < jParts.length(); i++) {
      guide.addPart(parsePart(jParts.getJSONObject(i)));
    }

    return guide;
  }