Пример #1
0
  /**
   * Deletes a tag.
   *
   * @param tagId Tag ID
   * @param userId User ID
   */
  public void delete(String tagId, String userId) {
    EntityManager em = ThreadLocalContext.get().getEntityManager();

    // Get the tag
    Query q = em.createQuery("select t from Tag t where t.id = :id and t.deleteDate is null");
    q.setParameter("id", tagId);
    Tag tagDb = (Tag) q.getSingleResult();

    // Delete the tag
    Date dateNow = new Date();
    tagDb.setDeleteDate(dateNow);

    // Delete linked data
    q =
        em.createQuery(
            "update DocumentTag dt set dt.deleteDate = :dateNow where dt.tagId = :tagId and dt.deleteDate is not null");
    q.setParameter("dateNow", dateNow);
    q.setParameter("tagId", tagId);
    q.executeUpdate();

    q =
        em.createQuery(
            "update Acl a set a.deleteDate = :dateNow where a.sourceId = :tagId and a.deleteDate is null");
    q.setParameter("tagId", tagId);
    q.setParameter("dateNow", dateNow);
    q.executeUpdate();

    // Create audit log
    AuditLogUtil.create(tagDb, AuditLogType.DELETE, userId);
  }
Пример #2
0
  /**
   * Creates a new tag.
   *
   * @param tag Tag
   * @param userId User ID
   * @return New ID
   */
  public String create(Tag tag, String userId) {
    // Create the UUID
    tag.setId(UUID.randomUUID().toString());

    // Create the tag
    EntityManager em = ThreadLocalContext.get().getEntityManager();
    tag.setCreateDate(new Date());
    em.persist(tag);

    // Create audit log
    AuditLogUtil.create(tag, AuditLogType.CREATE, userId);

    return tag.getId();
  }
Пример #3
0
  /**
   * Update a tag.
   *
   * @param tag Tag to update
   * @param userId User ID
   * @return Updated tag
   */
  public Tag update(Tag tag, String userId) {
    EntityManager em = ThreadLocalContext.get().getEntityManager();

    // Get the tag
    Query q = em.createQuery("select t from Tag t where t.id = :id and t.deleteDate is null");
    q.setParameter("id", tag.getId());
    Tag tagFromDb = (Tag) q.getSingleResult();

    // Update the tag
    tagFromDb.setName(tag.getName());
    tagFromDb.setColor(tag.getColor());
    tagFromDb.setParentId(tag.getParentId());

    // Create audit log
    AuditLogUtil.create(tagFromDb, AuditLogType.UPDATE, userId);

    return tagFromDb;
  }