コード例 #1
0
ファイル: TagMetadataDao.java プロジェクト: vbjay/tasks
  public boolean memberOfTagData(String email, String tagId, String memberId) {
    Criterion criterion;
    if (!RemoteModel.isUuidEmpty(memberId) && !TextUtils.isEmpty(email)) {
      criterion =
          Criterion.or(
              TagMemberMetadata.USER_UUID.eq(email), TagMemberMetadata.USER_UUID.eq(memberId));
    } else if (!RemoteModel.isUuidEmpty(memberId)) {
      criterion = TagMemberMetadata.USER_UUID.eq(memberId);
    } else if (!TextUtils.isEmpty(email)) {
      criterion = TagMemberMetadata.USER_UUID.eq(email);
    } else {
      return false;
    }

    TodorooCursor<TagMetadata> count =
        query(
            Query.select(TagMetadata.ID)
                .where(
                    Criterion.and(
                        TagMetadataCriteria.withKey(TagMemberMetadata.KEY),
                        TagMetadata.TAG_UUID.eq(tagId),
                        criterion)));
    try {
      return count.getCount() > 0;
    } finally {
      //
    }
  }
コード例 #2
0
ファイル: TagMetadataDao.java プロジェクト: vbjay/tasks
 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);
     }
   }
 }
コード例 #3
0
ファイル: TagMetadataDao.java プロジェクト: vbjay/tasks
 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);
   }
 }
コード例 #4
0
ファイル: TagMetadataDao.java プロジェクト: vbjay/tasks
 public boolean tagHasMembers(String uuid) {
   TodorooCursor<TagMetadata> metadata =
       query(
           Query.select(TagMetadata.ID)
               .where(
                   Criterion.and(
                       TagMetadataCriteria.byTagAndWithKey(uuid, TagMemberMetadata.KEY),
                       TagMetadata.DELETION_DATE.eq(0))));
   try {
     return metadata.getCount() > 0;
   } finally {
     metadata.close();
   }
 }
コード例 #5
0
ファイル: TagMetadataDao.java プロジェクト: vbjay/tasks
  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);
  }
コード例 #6
0
ファイル: TagMetadataDao.java プロジェクト: vbjay/tasks
  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);
    }
  }