Package com.dotmarketing.tag.model

Examples of com.dotmarketing.tag.model.Tag


        HibernateUtil dh = new HibernateUtil(Tag.class);

      dh.setQuery("from tag in class com.dotmarketing.tag.model.Tag where tag_id = ?");
        dh.setParam(tagId);

        Tag tag = (Tag) dh.load();

        return tag;
  }
View Full Code Here


     * Deletes a tag
     * @param tagName name of the tag to be deleted
     * @param userId id of the tag owner
     */
  public static void deleteTag(String tagIdthrows DotHibernateException  {
    Tag tag = getTagByTagId(tagId);
    deleteTag(tag);
  }
View Full Code Here

    }

  public static void updateTag(String tagId, String tagName, String hostId) throws Exception  {

    Tag tag = getTagByTagIdAndHostId(tagId,hostId);

      if(UtilMethods.isSet(tag.getTagId())){
        tag.setTagName(tagName);
      tag.setUserId("");
      if(UtilMethods.isSet(hostId))
        tag.setHostId(hostId);
      HibernateUtil.saveOrUpdate(tag);
      }

  }
View Full Code Here

  }
 
  public static void updateTag(String tagId, String newUserId) throws Exception  {

    Tag tag = getTagByTagId(tagId);

      if(UtilMethods.isSet(tag.getTagId())){
      tag.setUserId(newUserId);
      HibernateUtil.saveOrUpdate(tag);
      }
  }
View Full Code Here

      }
  }

  public static void updateTag(String tagId, String tagName, boolean updateTagReference, String hostId) throws Exception  {

    Tag tag = getTagByTagId(tagId);
    boolean tagAlreadyExistsForNewTagStorage = false;

    //This block of code prevent saving duplicated tags when editing tag storage from host
    List<Tag> tags = getTagByName(tagName.toLowerCase());

    for(Tag t: tags){
      if(t.getHostId().equals(hostId)){
        //The tag with new tag storage already exists
        tagAlreadyExistsForNewTagStorage = true;
      }
      if(t.getTagId().equals(tagId)){
        //select tag to be updated
        tag = t;
      }
    }

    //update selected tag if it's set and if previous tag storage is different.
      if(UtilMethods.isSet(tag.getTagId())&&!tagAlreadyExistsForNewTagStorage){
        tag.setTagName(tagName);
      tag.setUserId("");
      if(updateTagReference){
        if(UtilMethods.isSet(hostId))
          tag.setHostId(hostId);
      }
      HibernateUtil.saveOrUpdate(tag);
      }

  }
View Full Code Here

      dh.setQuery("from tag in class com.dotmarketing.tag.model.Tag where tag_id = ? and host_id = ?");
        dh.setParam(tagId);
        dh.setParam(hostId);

        Tag tag = (Tag) dh.load();

        return tag;
  }
View Full Code Here

    // validating if exists a tag with the name provided
        HibernateUtil dh = new HibernateUtil(List.class);
      dh.setQuery("from tag in class com.dotmarketing.tag.model.Tag where lower(tagName) = ?");
        dh.setParam(name.toLowerCase());

        Tag newTag = new Tag();
        List<Tag> tags = (List<Tag>) dh.list();
        // if doesn't exists then the tag is created
        if (tags == null || tags.size() == 0) {
          // creating tag
          return saveTag(name, userId, hostId);
        }
        else {
          //check if global tag already exists
          boolean globalTagExists = false;

          //check if tag exists with same tag name but for a different host
          boolean tagExists = false;

          Host host = APILocator.getHostAPI().find(hostId, APILocator.getUserAPI().getSystemUser(), true);
          if(host.getMap().get("tagStorage") == null){
            existHostId = host.getMap().get("identifier").toString();
          }
          else {
            existHostId = host.getMap().get("tagStorage").toString();
          }
          for(Tag tag : tags){

            if(isGlobalTag(tag)){
              newTag = tag;
              globalTagExists = true;
            }
            if(tag.getHostId().equals(existHostId)){
              newTag = tag;
                tagExists = true;
            }
        }

          if(!globalTagExists){
            //if global doesn't exist, then save the tag and after it checks if it was stored as a global tag
            try{
                  if(!tagExists)
                    newTag = saveTag(name, userId, hostId);

                  if(newTag.getHostId().equals(Host.SYSTEM_HOST)){
                    //move references of non-global tags to new global tag and delete duplicate non global tags
                      for(Tag tag : tags){
                        List<TagInode> tagInodes = getTagInodeByTagId(tag.getTagId());
                        for (TagInode tagInode : tagInodes){
                          updateTagInode(tagInode, newTag.getTagId());
                        }
                        deleteTag(tag);
                  }
                  }
            }
View Full Code Here

        HibernateUtil dh = new HibernateUtil(Tag.class);

      dh.setQuery("from tag in class com.dotmarketing.tag.model.Tag where tag_id = ?");
        dh.setParam(tagId);

        Tag tag = (Tag) dh.load();

        return tag;
  }
View Full Code Here

      dh.setQuery("from tag in class com.dotmarketing.tag.model.Tag where tag_id = ? and host_id = ?");
        dh.setParam(tagId);
        dh.setParam(hostId);

        Tag tag = (Tag) dh.load();

        return tag;
  }
View Full Code Here

   * @return new tag created
   * @throws DotHibernateException
   */
    public Tag saveTag(String tagName, String userId, String hostId) throws Exception {

      Tag tag = new Tag();
      //creates new Tag
      tag.setTagName(tagName);
      tag.setUserId(userId);

      Host host = null;

      if(UtilMethods.isSet(hostId) && !hostId.equals(Host.SYSTEM_HOST)){
        try{
            if(!UtilMethods.isSet(hostId)){
              host = APILocator.getHostAPI().findDefaultHost(APILocator.getUserAPI().getSystemUser(), true);
            }
            else {
              host = APILocator.getHostAPI().find(hostId,APILocator.getUserAPI().getSystemUser(), true);
            }
          }
          catch (Exception e) {
            Logger.error(this, "Unable to load host.");
          }

          if(host.getMap().get("tagStorage") == null){
            hostId = host.getMap().get("identifier").toString();
          }
          else {
            hostId = host.getMap().get("tagStorage").toString();
          }

        /*try {
          hostId=host.getMap().get("tagStorage").toString();
        } catch(NullPointerException e) {
          hostId = Host.SYSTEM_HOST;
          Logger.info(this, "No tag storage for Host, chosing global");
        }*/

      }
      else {
        hostId = Host.SYSTEM_HOST;
      }
      tag.setHostId(hostId);
      HibernateUtil.save(tag);

      return tag;
    }
View Full Code Here

TOP

Related Classes of com.dotmarketing.tag.model.Tag

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.