public void putInterpretationComment(InterpretationComment comment) { Interpretation interpretation = comment.getInterpretation(); /* if (interpretation != null && interpretation.getAction() != null) { boolean isInterpretationSynced = (interpretation.getAction().equals(Action.SYNCED) || interpretation.getAction().equals(Action.TO_UPDATE)); if (!isInterpretationSynced) { return; } try { mDhisApi.putInterpretationComment(interpretation.getUId(), comment.getUId(), new TypedString(comment.getText())); comment.setAction(Action.SYNCED); mInterpretationCommentStore.save(comment); updateInterpretationTimeStamp(comment.getInterpretation()); } catch (APIException apiException) { handleApiException(apiException); } } */ }
public void deleteInterpretationComment(InterpretationComment comment) { Interpretation interpretation = comment.getInterpretation(); /* if (interpretation != null && interpretation.getAction() != null) { boolean isInterpretationSynced = (interpretation.getAction().equals(Action.SYNCED) || interpretation.getAction().equals(Action.TO_UPDATE)); // 1) If Action of Interpretation is TO_DELETE, // there is no meaning to remove its comments by hand. // They will be removed automatically when interpretation is removed. // 2) If Action of Interpretation is TO_POST, // we cannot create comment on server, since we don't have // interpretation UUID to associate comment with. // In all other Action cases (TO_UPDATE, SYNCED), we can delete comments if (!isInterpretationSynced) { return; } try { mDhisApi.deleteInterpretationComment( interpretation.getUId(), comment.getUId()); mInterpretationCommentStore.delete(comment); updateInterpretationTimeStamp(comment.getInterpretation()); } catch (APIException apiException) { handleApiException(apiException, comment, mInterpretationCommentStore); } } */ }
public void postInterpretationComment(InterpretationComment comment) { Interpretation interpretation = comment.getInterpretation(); /* if (interpretation != null && interpretation.getAction() != null) { boolean isInterpretationSynced = (interpretation.getAction().equals(Action.SYNCED) || interpretation.getAction().equals(Action.TO_UPDATE)); if (!isInterpretationSynced) { return; } try { Response response = mDhisApi.postInterpretationComment( interpretation.getUId(), new TypedString(comment.getText())); Header locationHeader = findLocationHeader(response.getHeaders()); String commentUid = Uri.parse(locationHeader .getValue()).getLastPathSegment(); comment.setUId(commentUid); comment.setAction(Action.SYNCED); mInterpretationStore.save(interpretation); updateInterpretationCommentTimeStamp(comment); } catch (APIException apiException) { handleApiException(apiException, comment, mInterpretationCommentStore); } } */ }
private List<User> updateInterpretationUsers( List<Interpretation> interpretations, List<InterpretationComment> comments) { Map<String, User> users = new HashMap<>(); UserAccount currentUserAccount = mUserAccountService.getCurrentUserAccount(); User currentUser = mUserStore.queryByUid(currentUserAccount.getUId()); if (currentUser == null) { currentUser = mUserAccountService.toUser(currentUserAccount); } users.put(currentUser.getUId(), currentUser); if (interpretations != null && !interpretations.isEmpty()) { for (Interpretation interpretation : interpretations) { User user = interpretation.getUser(); if (users.containsKey(user.getUId())) { user = users.get(user.getUId()); interpretation.setUser(user); } else { users.put(user.getUId(), user); } } } if (comments != null && !comments.isEmpty()) { for (InterpretationComment comment : comments) { User user = comment.getUser(); if (users.containsKey(user.getUId())) { user = users.get(user.getUId()); comment.setUser(user); } else { users.put(user.getUId(), user); } } } return new ArrayList<>(users.values()); }
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; }