示例#1
0
 @Test
 public void testGetTag() throws FOMException, JSONException, FluidException, IOException {
   // Lets create a tag underneath the user's default root namespace
   Namespace testNamespace = new Namespace(this.fdb, "", this.fdb.getUsername());
   String newName = UUID.randomUUID().toString();
   Tag newTag = testNamespace.createTag(newName, "This is a test tag", true);
   // if we successfully created a tag we'll be able to get it from FluidDB
   Tag gotTag = testNamespace.getTag(newName);
   assertEquals(newTag.getId(), gotTag.getId());
   gotTag.delete();
 }
示例#2
0
 private void initTagDataSource(OfflineAccount account) throws ServiceException {
   OfflineProvisioning prov = OfflineProvisioning.getOfflineInstance();
   tagDs = account.getDataSourceByName(dsName);
   if (tagDs == null) {
     OfflineLog.offline.debug("initializing tag datasource");
     tagDs =
         prov.createDataSource(
             account, DataSourceType.tagmap, dsName, new HashMap<String, Object>());
     // initially any previously existing local tags also have same ID as remote.
     List<Tag> tags = mbox.getTagList(null);
     for (Tag tag : tags) {
       mapTag(tag.getId(), tag.getId());
     }
   }
 }
示例#3
0
  // getInstance//////////////////////////////////////////////////////////////////////////////////////
  public static synchronized RecordManager getInstance(Context context) {
    if (RECORDS == null
        || TAGS == null
        || TAG_NAMES == null
        || SUM == null
        || recordManager == null) {
      SUM = 0;
      RECORDS = new LinkedList<>();
      TAGS = new LinkedList<>();
      TAG_NAMES = new HashMap<>();
      recordManager = new RecordManager(context);

      db.getData();

      if (BuildConfig.DEBUG) {
        if (BuildConfig.DEBUG) Log.d("CoCoin", "Load " + RECORDS.size() + " records S");
        if (BuildConfig.DEBUG) Log.d("CoCoin", "Load " + TAGS.size() + " tags S");
      }

      TAGS.add(0, new Tag(-1, "Sum Histogram", -4));
      TAGS.add(0, new Tag(-2, "Sum Pie", -5));

      for (Tag tag : TAGS) TAG_NAMES.put(tag.getId(), tag.getName());

      sortTAGS();
    }
    return recordManager;
  }
示例#4
0
 @Test
 public void testCreateTag() throws FOMException, JSONException, FluidException, IOException {
   // Lets create a tag underneath the user's default root namespace
   Namespace testNamespace = new Namespace(this.fdb, "", this.fdb.getUsername());
   String newName = UUID.randomUUID().toString();
   Tag newTag = testNamespace.createTag(newName, "This is a test tag", true);
   // if we successfully created a tag there'll be an id
   assertEquals(true, newTag.getId().length() > 0);
   testNamespace.getItem(); // not really needed
   assertEquals(true, TestUtils.contains(testNamespace.getTagNames(), newName));
   newTag.delete();
   testNamespace.getItem();
   assertEquals(false, TestUtils.contains(testNamespace.getTagNames(), newName));
   // Lets make sure validation works correctly...
   newName = "this is wrong"; // e.g. space is an invalid character
   String msg = "";
   try {
     newTag = testNamespace.createTag(newName, "This is a test namespace", false);
   } catch (FOMException ex) {
     msg = ex.getMessage();
   }
   assertEquals("Invalid name (incorrect characters or too long)", msg);
   // the new name is too long
   newName =
       "foobarbazhamandeggscheeseandpicklespamspamspamspamfoobarbazhamandeggscheeseandpicklespamspamspamspamfoobarbazhamandeggscheeseandpicklespamspamspamspamfoobarbazhamandeggscheeseandpicklespamspamspamspamfoobarbazhamandeggscheeseandpicklespamspamspamspam";
   msg = "";
   try {
     newTag = testNamespace.createTag(newName, "This is a test namespace", false);
   } catch (FOMException ex) {
     msg = ex.getMessage();
   }
   assertEquals("Invalid name (incorrect characters or too long)", msg);
 }
示例#5
0
 public static int deleteTag(int id) {
   int deletedId = -1;
   if (BuildConfig.DEBUG)
     Log.d(
         "CoCoin",
         "Manager: Delete tag: " + "Tag(id = " + id + ", deletedId = " + deletedId + ")");
   boolean tagReference = false;
   for (CoCoinRecord coCoinRecord : RECORDS) {
     if (coCoinRecord.getTag() == id) {
       tagReference = true;
       break;
     }
   }
   if (tagReference) {
     return DELETE_TAG_ERROR_TAG_REFERENCE;
   }
   deletedId = db.deleteTag(id);
   if (deletedId == -1) {
     if (BuildConfig.DEBUG) Log.d("CoCoin", "Delete the above tag FAIL!");
     return DELETE_TAG_ERROR_DATABASE_ERROR;
   } else {
     if (BuildConfig.DEBUG) Log.d("CoCoin", "Delete the above tag SUCCESSFULLY!");
     for (Tag tag : TAGS) {
       if (tag.getId() == deletedId) {
         TAGS.remove(tag);
         break;
       }
     }
     TAG_NAMES.remove(id);
     sortTAGS();
   }
   return deletedId;
 }
示例#6
0
 // save
 // tag/////////////////////////////////////////////////////////////////////////////////////////
 public static int saveTag(Tag tag) {
   int insertId = -1;
   if (BuildConfig.DEBUG) {
     if (BuildConfig.DEBUG) Log.d("CoCoin", "recordManager.saveTag: " + tag.toString());
   }
   boolean duplicatedName = false;
   for (Tag t : TAGS) {
     if (t.getName().equals(tag.getName())) {
       duplicatedName = true;
       break;
     }
   }
   if (duplicatedName) {
     return SAVE_TAG_ERROR_DUPLICATED_NAME;
   }
   insertId = db.saveTag(tag);
   if (insertId == -1) {
     if (BuildConfig.DEBUG) {
       if (BuildConfig.DEBUG) Log.d("CoCoin", "Save the above tag FAIL!");
       return SAVE_TAG_ERROR_DATABASE_ERROR;
     }
   } else {
     if (BuildConfig.DEBUG) {
       if (BuildConfig.DEBUG) Log.d("CoCoin", "Save the above tag SUCCESSFULLY!");
     }
     TAGS.add(tag);
     TAG_NAMES.put(tag.getId(), tag.getName());
     sortTAGS();
   }
   return insertId;
 }
示例#7
0
 /**
  * Translate a delimted list of tag names to a delimited list of correponding local tagIds
  *
  * @throws ServiceException
  */
 public String localTagsFromNames(String tagNames, String inDelim, String outDelim)
     throws ServiceException {
   if (tagNames != null && tagNames.length() > 0) {
     StringBuilder sb = new StringBuilder();
     String[] names = tagNames.split(inDelim);
     for (String name : names) {
       if (name.trim().length() <= 0) {
         continue;
       }
       Integer tagId = localIdsByName.get(name);
       if (tagId == null) {
         try {
           Tag tag = mbox.getTagByName(null, name);
           tagId = tag.getId();
           localIdsByName.put(name, tagId);
         } catch (MailServiceException mse) {
           if (MailServiceException.NO_SUCH_TAG.equals(mse.getCode())) {
             OfflineLog.offline.debug(
                 "message has tag [" + name + "] which is not visible locally");
             continue;
           } else {
             throw mse;
           }
         }
       }
       sb.append(tagId).append(outDelim);
     }
     if (sb.length() >= outDelim.length()) {
       sb.setLength(sb.length() - outDelim.length());
     }
     return sb.toString();
   } else {
     return tagNames;
   }
 }
示例#8
0
 public static long updateTag(Tag tag) {
   int updateId = -1;
   if (BuildConfig.DEBUG) Log.d("CoCoin", "Manager: Update tag: " + tag.toString());
   updateId = db.updateTag(tag);
   if (updateId == -1) {
     if (BuildConfig.DEBUG) Log.d("CoCoin", "Update the above tag FAIL!");
   } else {
     if (BuildConfig.DEBUG)
       Log.d("CoCoin", "Update the above tag SUCCESSFULLY!" + " - " + updateId);
     for (Tag t : TAGS) {
       if (t.getId() == tag.getId()) {
         t.set(tag);
         break;
       }
     }
     sortTAGS();
   }
   return updateId;
 }
  /** Test saveSingleTeamTag */
  @Test
  public void testSaveSingleTeamTag() {
    Client client = createClient();
    Group group = createGroup(client);
    List<Tag> tagList = createTagList(group, 1);
    Tag tag = tagList.get(0);
    Team team1 = createTeam(client);

    TeamTag teamTag = teamTagService.saveSingleTeamTag(team1, tag);
    TeamTag newTeamTag = teamTagService.reload(teamTag);
    assertThat("teamTagPage was saved", newTeamTag.getTag().getId(), is(tag.getId()));
  }
  @Test
  public void associateTagAndCourses() {
    CourseDataOnDemand courseDod = new CourseDataOnDemand();
    Course c1 = courseDod.getNewTransientCourse(0);
    Course c2 = courseDod.getNewTransientCourse(1);

    TagDataOnDemand tagDod = new TagDataOnDemand();
    Tag tag = tagDod.getNewTransientTag(0);

    tag.getCourses().add(c1);
    tag.getCourses().add(c2);

    tag.persist();
    tag.flush();
    tag.clear();

    Assert.assertEquals(2, tag.findTag(tag.getId()).getCourses().size());
  }
  public TagMetadata(Cursor cursor) {
    while (cursor.moveToNext()) {
      Tag tag =
          new Tag(
              cursor.getString(TagsQuery.TAG_ID),
              cursor.getString(TagsQuery.TAG_NAME),
              cursor.getString(TagsQuery.TAG_CATEGORY),
              cursor.getInt(TagsQuery.TAG_ORDER_IN_CATEGORY),
              cursor.getString(TagsQuery.TAG_ABSTRACT),
              cursor.getInt(TagsQuery.TAG_COLOR));
      mTagsById.put(tag.getId(), tag);
      if (!mTagsInCategory.containsKey(tag.getCategory())) {
        mTagsInCategory.put(tag.getCategory(), new ArrayList<Tag>());
      }
      mTagsInCategory.get(tag.getCategory()).add(tag);
    }

    for (ArrayList<Tag> list : mTagsInCategory.values()) {
      Collections.sort(list);
    }
  }
  //    @Test
  // @Repeat(value = 1)
  public void entitiesUnderLoad() throws Exception {
    // This test suffered under DAT-348 and was quarantined.
    String companyName = "entitiesUnderLoad";
    setSecurity();
    SystemUser su = registerSystemUser(companyName, "entitiesUnderLoad");

    Fortress fortress =
        fortressService.registerFortress(
            su.getCompany(), new FortressInputBean("entitiesUnderLoad", true));
    String docType = "entitiesUnderLoad";

    int tagCount = 1; // unique tags per entity - tags are shared across the entities
    int docCount = 1; // how many entities to create per thread
    // Tried reducing threadMax
    int threadMax = 3; // Each thread will create a unique document type
    ArrayList<TagInputBean> tags = getTags(tagCount, false);

    Collection<Tag> createdTags =
        tagService.findTags(fortress.getCompany(), tags.get(0).getLabel());
    assertEquals("Database is not in a cleared down state", 0, createdTags.size());

    Map<Integer, EntityRunner> runners = new HashMap<>();

    CountDownLatch latch = new CountDownLatch(threadMax);
    CountDownLatch startSignal = new CountDownLatch(1);
    for (int thread = 0; thread < threadMax; thread++) {
      EntityRunner runner =
          addEntityRunner(
              thread + 1,
              su,
              fortress,
              docType,
              "ABC" + thread,
              docCount,
              tags,
              latch,
              startSignal);
      runners.put(thread, runner);
    }
    startSignal.countDown();
    latch.await();
    Tag found = null;

    for (int thread = 0; thread < threadMax; thread++) {
      assertEquals("Thread " + (thread + 1), true, runners.get(thread).isWorked());
      for (int count = 0; count < docCount; count++) {
        // Thread.sleep(2000);
        Entity entity =
            entityService.findByCode(
                su.getCompany(), fortress.getName(), docType, "ABC" + thread + "" + count);
        assertNotNull(entity);
        Collection<EntityTag> entityTags = entityTagService.findEntityTags(entity);
        if (entityTags.size() == 0) {
          logger.debug("Why is this 0?");
        }
        assertEquals(tagCount, entityTags.size());
        // Make sure every thread's tags point to the same tag
        if (found == null) found = entityTags.iterator().next().getTag();
        else
          assertEquals(
              found.toString() + " / " + entityTags.iterator().next().getTag().toString(),
              found.getId(),
              entityTags.iterator().next().getTag().getId());
      }
    }
    assertNotNull(
        tagService.findTag(fortress.getCompany(), "Deadlock", null, tags.get(0).getCode()));

    createdTags = tagService.findTags(fortress.getCompany(), "Deadlock");
    assertEquals(false, createdTags.isEmpty());
    if (createdTags.size() != tagCount) {

      for (Tag createdTag : createdTags) {
        // logger.info(createdTag.toString());
        logger.info("Finding... {}", createdTag.toString());
        Tag xtra =
            tagService.findTag(su.getCompany(), createdTag.getLabel(), null, createdTag.getCode());

        logger.info(xtra.toString());
      }
    }
    assertEquals(tagCount, createdTags.size());
  }
  public boolean isOfType(ContentTagType tagType) {
    for (Tag tag : allTags) if (tagType.getId().equals(tag.getId())) return true;

    return false;
  }
  public boolean hasTag(TagType tagType, String tagId) {
    for (Tag tag : getTagsOfType(tagType)) if (tag.getId().equals(tagId)) return true;

    return false;
  }
  public boolean hasTag(String tagId) {
    for (Tag tag : allTags) if (tag.getId().equals(tagId)) return true;

    return false;
  }
示例#16
0
 public Collection<Issue> search() {
   List<String> predicates = new ArrayList<String>();
   java.text.DateFormat dateFormat = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
   if (this.after == null && this.before != null) {
     predicates.add(" view_issue.created_at <= '" + dateFormat.format(this.before) + "'");
   } else if (this.after == null && this.before == null) {
     /* Do nothing. */
   } else if (this.after != null && this.before != null) {
     predicates.add(
         " view_issue.created_at BETWEEN '"
             + dateFormat.format(this.after)
             + "' AND '"
             + dateFormat.format(this.before)
             + "'");
   } else if (this.after != null && this.before == null) {
     predicates.add(" view_issue.created_at >= '" + dateFormat.format(this.after) + "'");
   }
   if (this.mentionings != null && !this.mentionings.isEmpty()) {
     StringBuilder stringBuilder = new StringBuilder();
     int quantityOfMentionings = 0;
     for (String mentioning : this.mentionings) {
       stringBuilder.append(" view_issue.title LIKE '%" + mentioning + "%' ");
       quantityOfMentionings++;
       if (quantityOfMentionings < this.mentionings.size()) {
         stringBuilder.append("OR ");
       }
     }
     /*stringBuilder.append(" ESCAPE '!' ");*/
     predicates.add(stringBuilder.toString());
   }
   if (this.issuer != null) {
     predicates.add(" view_issue.issuer_id = " + this.issuer.getId().toString() + " ");
   }
   StringBuilder queryBuilder = new StringBuilder("SELECT DISTINCT view_issue.* FROM view_issue ");
   if (this.containsTags != null && !this.containsTags.isEmpty()) {
     queryBuilder.append("JOIN view_tag_usage ON view_issue.id = view_tag_usage.issue_id ");
     StringBuilder stringBuilder = new StringBuilder();
     stringBuilder.append(" view_tag_usage.id IN (");
     int quantityOfTags = 0;
     for (Tag tag : this.containsTags) {
       stringBuilder.append(tag.getId());
       quantityOfTags++;
       if (quantityOfTags < this.containsTags.size()) {
         stringBuilder.append(", ");
       }
     }
     stringBuilder.append(")");
     predicates.add(stringBuilder.toString());
   }
   if (!predicates.isEmpty()) {
     String operation;
     if (this.conjunction) {
       operation = " AND ";
     } else {
       operation = " OR ";
     }
     int quantityOfChunks = 0;
     queryBuilder.append(" WHERE ");
     for (String chunkOfPredicate : predicates) {
       queryBuilder.append(chunkOfPredicate);
       quantityOfChunks++;
       if (quantityOfChunks < predicates.size()) {
         queryBuilder.append(operation);
       }
     }
   }
   queryBuilder.append(";");
   IssueDatasource datasource =
       DatasourceFactory.<IssueDatasource>getInstance(IssueDatasource.class);
   Collection<Data> collectionOfData = datasource.read(queryBuilder.toString());
   if (collectionOfData == null) {
     return null;
   }
   List<Issue> issues = new ArrayList<Issue>();
   for (Data data : collectionOfData) {
     Issue issue = Issue.getInstance(data);
     issues.add(issue);
   }
   return (Collection<Issue>) issues;
 }
示例#17
0
  /**
   * Tags or untags all messages in the conversation. Persists the change to the database and cache.
   * If the conversation includes at least one unread {@link Message} whose tagged state is
   * changing, updates the {@link Tag}'s unread count appropriately.
   *
   * <p>Messages in the conversation are omitted from this operation if one or more of the following
   * applies:
   *
   * <ul>
   *   <li>The caller lacks {@link ACL#RIGHT_WRITE} permission on the <code>Message</code>.
   *   <li>The caller has specified a {@link MailItem.TargetConstraint} that explicitly excludes the
   *       <code>Message</code>.
   *   <li>The caller has specified the maximum change number they know about, and the
   *       (modification/content) change number on the <code>Message</code> is greater.
   * </ul>
   *
   * As a result of all these constraints, no messages may actually be tagged/untagged.
   *
   * @perms {@link ACL#RIGHT_WRITE} on all the messages
   */
  @Override
  void alterTag(Tag tag, boolean add) throws ServiceException {
    if (tag == null) throw ServiceException.FAILURE("missing tag argument", null);
    if (!add && !isTagged(tag)) return;
    if (tag.getId() == Flag.ID_FLAG_UNREAD)
      throw ServiceException.FAILURE("unread state must be set with alterUnread", null);
    // don't let the user tag things as "has attachments" or "draft"
    if (tag instanceof Flag && (tag.getBitmask() & Flag.FLAG_SYSTEM) != 0)
      throw MailServiceException.CANNOT_TAG(tag, this);

    markItemModified(tag instanceof Flag ? Change.MODIFIED_FLAGS : Change.MODIFIED_TAGS);

    TargetConstraint tcon = mMailbox.getOperationTargetConstraint();
    boolean excludeAccess = false;

    List<Message> msgs = getMessages();
    List<Integer> targets = new ArrayList<Integer>(msgs.size());
    for (Message msg : msgs) {
      // skip messages that don't need to be changed, or that the client can't modify, doesn't know
      // about, or has explicitly excluded
      if (msg.isTagged(tag) == add) {
        continue;
      } else if (!msg.canAccess(ACL.RIGHT_WRITE)) {
        excludeAccess = true;
        continue;
      } else if (!msg.checkChangeID() || !TargetConstraint.checkItem(tcon, msg)) {
        continue;
      } else if (add && !tag.canTag(msg)) {
        throw MailServiceException.CANNOT_TAG(tag, this);
      }

      targets.add(msg.getId());
      msg.tagChanged(tag, add);

      // since we're adding/removing a tag, the tag's unread count may change
      int delta = add ? 1 : -1;
      if (tag.trackUnread() && msg.isUnread())
        tag.updateUnread(delta, isTagged(Flag.ID_FLAG_DELETED) ? delta : 0);

      // if we're adding/removing the \Deleted flag, update the folder and tag "deleted" and
      // "deleted unread" counts
      if (tag.getId() == Flag.ID_FLAG_DELETED) {
        getFolder().updateSize(0, delta, 0);
        // note that Message.updateUnread() calls updateTagUnread()
        if (msg.isUnread()) msg.updateUnread(0, delta);
      }
    }

    if (targets.isEmpty()) {
      if (excludeAccess)
        throw ServiceException.PERM_DENIED("you do not have sufficient permissions");
    } else {
      if (ZimbraLog.mailop.isDebugEnabled()) {
        String operation = add ? "Setting" : "Unsetting";
        ZimbraLog.mailop.debug(
            "%s %s for %s.  Affected ids: %s",
            operation,
            getMailopContext(tag),
            getMailopContext(this),
            StringUtil.join(",", targets));
      }
      recalculateCounts(msgs);
      DbMailItem.alterTag(tag, targets, add);
    }
  }