@Override protected boolean shouldRecordOutstanding(TagMetadata item) { ContentValues cv = item.getSetValues(); return super.shouldRecordOutstanding(item) && cv != null && ((cv.containsKey(TagMetadata.KEY.name) && TagMemberMetadata.KEY.equals(item.getValue(TagMetadata.KEY))) || (cv.containsKey(TagMetadata.DELETION_DATE.name) && item.getValue(TagMetadata.DELETION_DATE) > 0)) && RemoteModelDao.getOutstandingEntryFlag( RemoteModelDao.OUTSTANDING_ENTRY_FLAG_RECORD_OUTSTANDING); }
public void synchronizeMembers( TagData tagData, String legacyMembersString, String tagUuid, JSONArray members) { long tagId = tagData.getId(); Set<String> emails = new HashSet<String>(); Set<String> ids = new HashSet<String>(); HashMap<String, String> idToEmail = new HashMap<String, String>(); for (int i = 0; i < members.length(); i++) { JSONObject person = members.optJSONObject(i); if (person != null) { String id = person.optString("id"); // $NON-NLS-1$ if (!TextUtils.isEmpty(id)) { ids.add(id); } String email = person.optString("email"); // $NON-NLS-1$ if (!TextUtils.isEmpty(email)) { emails.add(email); } if (!TextUtils.isEmpty(id) && !TextUtils.isEmpty(email)) { idToEmail.put(id, email); } } } if (!TextUtils.isEmpty(legacyMembersString)) { try { JSONArray legacyMembers = new JSONArray(legacyMembersString); for (int i = 0; i < legacyMembers.length(); i++) { JSONObject user = legacyMembers.optJSONObject(i); if (user != null) { String id = user.optString("id"); // $NON-NLS-1$ String email = user.optString("email"); // $NON-NLS-1$ if (!TextUtils.isEmpty(id)) { createMemberLink(tagId, tagUuid, id, !ids.contains(id), false); } else if (!TextUtils.isEmpty(email)) { createMemberLink(tagId, tagUuid, email, !emails.contains(email), false); } } } } catch (JSONException e) { // } tagData.setValue(TagData.MEMBERS, ""); // $NON-NLS-1$ PluginServices.getTagDataDao().saveExisting(tagData); } TodorooCursor<TagMetadata> currentMembers = query( Query.select(TagMemberMetadata.USER_UUID) .where(TagMetadataCriteria.byTagAndWithKey(tagUuid, TagMemberMetadata.KEY))); try { TagMetadata m = new TagMetadata(); for (currentMembers.moveToNext(); !currentMembers.isAfterLast(); currentMembers.moveToNext()) { m.clear(); m.readFromCursor(currentMembers); String userId = m.getValue(TagMemberMetadata.USER_UUID); boolean exists = ids.remove(userId) || emails.remove(userId); if (exists && idToEmail.containsKey(userId)) { String email = idToEmail.get(userId); emails.remove(email); } if (!exists) { // Was in database, but not in new members list removeMemberLink(tagId, tagUuid, userId, false); } } } finally { currentMembers.close(); } for (String email : emails) { createMemberLink(tagId, tagUuid, email, false); } for (String id : ids) { createMemberLink(tagId, tagUuid, id, false); } }