コード例 #1
0
  private List<Interpretation> updateInterpretations(DateTime lastUpdated) {
    final Map<String, String> QUERY_MAP_BASIC = new HashMap<>();
    final Map<String, String> QUERY_MAP_FULL = new HashMap<>();
    final String BASE = "id,created,lastUpdated,name,displayName,access";

    QUERY_MAP_BASIC.put("fields", "id");
    QUERY_MAP_FULL.put(
        "fields",
        BASE
            + ",text,type,"
            + "chart"
            + "["
            + BASE
            + "],"
            + "map"
            + "["
            + BASE
            + "],"
            + "reportTable"
            + "["
            + BASE
            + "],"
            + "user"
            + "["
            + BASE
            + "],"
            + "dataSet"
            + "["
            + BASE
            + "],"
            + "period"
            + "["
            + BASE
            + "],"
            + "organisationUnit"
            + "["
            + BASE
            + "],"
            + "comments"
            + "["
            + BASE
            + ",user,text"
            + "]");

    if (lastUpdated != null) {
      QUERY_MAP_FULL.put("filter", "lastUpdated:gt:" + lastUpdated.toString());
    }

    /* List<Interpretation> actualInterpretations = NetworkUtils.unwrapResponse(mDhisApi
            .getInterpretations(QUERY_MAP_BASIC), "interpretations");

    List<Interpretation> updatedInterpretations = NetworkUtils.unwrapResponse(mDhisApi
            .getInterpretations(QUERY_MAP_FULL), "interpretations"); */

    List<Interpretation> updatedInterpretations = new ArrayList<>();

    if (updatedInterpretations != null && !updatedInterpretations.isEmpty()) {

      for (Interpretation interpretation : updatedInterpretations) {

        // build relationship with comments
        if (interpretation.getComments() != null && !interpretation.getComments().isEmpty()) {

          for (InterpretationComment comment : interpretation.getComments()) {
            comment.setInterpretation(interpretation);
          }
        }

        // we need to set mime type and interpretation to each element
        switch (interpretation.getType()) {
          case Interpretation.TYPE_CHART:
            {
              interpretation.getChart().setType(InterpretationElement.TYPE_CHART);
              interpretation.getChart().setInterpretation(interpretation);
              break;
            }
          case Interpretation.TYPE_MAP:
            {
              interpretation.getMap().setType(InterpretationElement.TYPE_MAP);
              interpretation.getMap().setInterpretation(interpretation);
              break;
            }
          case Interpretation.TYPE_REPORT_TABLE:
            {
              interpretation.getReportTable().setType(InterpretationElement.TYPE_REPORT_TABLE);
              interpretation.getReportTable().setInterpretation(interpretation);
              break;
            }
          case Interpretation.TYPE_DATA_SET_REPORT:
            {
              interpretation.getDataSet().setType(InterpretationElement.TYPE_DATA_SET);
              interpretation.getPeriod().setType(InterpretationElement.TYPE_PERIOD);
              interpretation
                  .getOrganisationUnit()
                  .setType(InterpretationElement.TYPE_ORGANISATION_UNIT);

              interpretation.getDataSet().setInterpretation(interpretation);
              interpretation.getPeriod().setInterpretation(interpretation);
              interpretation.getOrganisationUnit().setInterpretation(interpretation);
              break;
            }
        }
      }
    }

    List<Interpretation> persistedInterpretations = null;
    // mInterpretationStore.filter(Action.TO_POST);
    if (persistedInterpretations != null && !persistedInterpretations.isEmpty()) {
      for (Interpretation interpretation : persistedInterpretations) {
        List<InterpretationElement> elements = mInterpretationElementStore.list(interpretation);
        // mInterpretationService.setInterpretationElements(interpretation, elements);

        List<InterpretationComment> comments = null;
        // mInterpretationCommentStore.queryByInterpretation(interpretation, Action.TO_POST);
        interpretation.setComments(comments);
      }
    }

    // return merge(actualInterpretations, updatedInterpretations, persistedInterpretations);
    return null;
  }