public void removeMemberLinks( long tagId, String tagUuid, String[] memberIds, boolean suppressOutstanding) { TagMetadata deleteTemplate = new TagMetadata(); deleteTemplate.setValue( TagMetadata.TAG_ID, tagId); // Need this for recording changes in outstanding table deleteTemplate.setValue(TagMetadata.DELETION_DATE, DateUtilities.now()); if (memberIds != null) { for (String uuid : memberIds) { // TODO: Right now this is in a loop because each deleteTemplate needs the individual // tagUuid in order to record // the outstanding entry correctly. If possible, this should be improved to a single query deleteTemplate.setValue( TagMemberMetadata.USER_UUID, uuid); // Need this for recording changes in outstanding table if (suppressOutstanding) { deleteTemplate.putTransitory(SyncFlags.ACTFM_SUPPRESS_OUTSTANDING_ENTRIES, true); } update( Criterion.and( TagMetadataCriteria.withKey(TagMemberMetadata.KEY), TagMetadata.DELETION_DATE.eq(0), TagMetadata.TAG_UUID.eq(tagUuid), TagMemberMetadata.USER_UUID.eq(uuid)), deleteTemplate); } } }
public void createMemberLink( long tagId, String tagUuid, String memberId, boolean removedMember, boolean suppressOutstanding) { TagMetadata newMetadata = TagMemberMetadata.newMemberMetadata(tagId, tagUuid, memberId); if (removedMember) { newMetadata.setValue(TagMetadata.DELETION_DATE, DateUtilities.now()); } if (suppressOutstanding) { newMetadata.putTransitory(SyncFlags.ACTFM_SUPPRESS_OUTSTANDING_ENTRIES, true); } if (update( Criterion.and( TagMetadataCriteria.byTagAndWithKey(tagUuid, TagMemberMetadata.KEY), TagMemberMetadata.USER_UUID.eq(memberId)), newMetadata) <= 0) { if (suppressOutstanding) { newMetadata.putTransitory(SyncFlags.ACTFM_SUPPRESS_OUTSTANDING_ENTRIES, true); } createNew(newMetadata); } }
@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 removeMemberLink( long tagId, String tagUuid, String memberId, boolean suppressOutstanding) { TagMetadata deleteTemplate = new TagMetadata(); deleteTemplate.setValue( TagMetadata.TAG_ID, tagId); // Need this for recording changes in outstanding table deleteTemplate.setValue(TagMetadata.DELETION_DATE, DateUtilities.now()); deleteTemplate.setValue( TagMemberMetadata.USER_UUID, memberId); // Need this for recording changes in outstanding table if (suppressOutstanding) { deleteTemplate.putTransitory(SyncFlags.ACTFM_SUPPRESS_OUTSTANDING_ENTRIES, true); } update( Criterion.and( TagMetadataCriteria.withKey(TagMemberMetadata.KEY), TagMetadata.DELETION_DATE.eq(0), TagMetadata.TAG_UUID.eq(tagUuid), TagMemberMetadata.USER_UUID.eq(memberId)), deleteTemplate); }
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); } }