Package com.dotmarketing.tag.model

Examples of com.dotmarketing.tag.model.Tag


    APILocator.getUserAPI().save(user,APILocator.getUserAPI().getSystemUser(),false);
    HibernateUtil.saveOrUpdate(userProxy);

    List<TagInode> tags = TagFactory.getTagInodeByInode(userProxy.getInode());
    for (TagInode tag: tags) {
      Tag tempTag = TagFactory.getTagByTagId(tag.getTagId());
      TagFactory.deleteTagInode(tempTag.getTagName(), userProxy.getInode());
    }
    if(tags.size() > 0){
      TagFactory.addTag(form.getTags(), userProxy.getUserId(), userProxy.getInode());
    }
   
View Full Code Here


    List<TagInode> tags = TagFactory.getTagInodeByInode(userProxy.getInode());
    StringBuilder tagsString = new StringBuilder(128);
    tagsString.ensureCapacity(32);
    for (TagInode tag: tags) {
      Tag retrievedTag = TagFactory.getTagByTagId(tag.getTagId());
      if (0 < tagsString.length())
        tagsString.append(", " + retrievedTag.getTagName());
      else
        tagsString.append(retrievedTag.getTagName());
    }
    form.setTags(tagsString.toString());

    CategoryAPI categoryAPI = APILocator.getCategoryAPI();
    List<String> categories = new ArrayList<String>();
View Full Code Here

   */
  public static Tag getTag(String name, String userId) {

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

      tag = (Tag) dh.load();
    } catch (DotHibernateException e) {
      Logger.error(TagFactory.class,"getTag failed:" + e, e);
    }
        // if doesn't exists then the tag is created
        if (tag.getTagName() == null) {
          // creating tag
          return addTag(name, userId);
        }
        // returning tag
        return tag;
View Full Code Here

   * @param userId owner of the new tag
   * @return new tag created
   */
    public static Tag addTag(String tagName, String userId) {
    //creates new Tag
      Tag tag = new Tag();
      tag.setTagName(tagName);
      tag.setUserId(userId);
        try {
      HibernateUtil.save(tag);
    } catch (DotHibernateException e) {
      Logger.error(TagFactory.class,"addTag failed:" + e, e);
    }
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 tagName, String userId) {
    Tag tag = getTag(tagName, userId);
      try {
      HibernateUtil.delete(tag);
    } catch (DotHibernateException e) {
      Logger.error(TagFactory.class,"deleteTag failed:" + e, e);
    }
View Full Code Here

      oldTagName = escapeSingleQuote(oldTagName);

      List tagToEdit = getTagByName(oldTagName);
      Iterator it = tagToEdit.iterator();
      for (int i = 0; it.hasNext(); i++) {
        Tag tag = (Tag)it.next();

        tag.setTagName(tagName);
        HibernateUtil.saveOrUpdate(tag);
      }
    }
    catch (Exception e) {}
  }
View Full Code Here

   */

    public static TagInode addTagInode(String tagName, String inode, String hostId) throws Exception {

      //Ensure the tag exists in the tag table
      Tag existingTag = getTag(tagName, "", hostId);

      //validates the tagInode already exists
    TagInode existingTagInode = getTagInode(existingTag.getTagId(), inode);

      if (existingTagInode.getTagId() == null) {

        //the tagInode does not exists, so creates a new TagInode
        TagInode tagInode = new TagInode();
        tagInode.setTagId(existingTag.getTagId());
        /*long i = 0;
        try{
          i =Long.parseLong(inode);
        }catch (Exception e) {
        Logger.error(this, "Unable to get Long value from " + inode, e);
View Full Code Here

            String tagUserID = (String) hash.get("user_id");
            String tagName = (String) hash.get("tagname");
           
            //Creates the tag only if the tagUserID is in the userIds list.
            if(belongsToUser(userIds, tagUserID, tagName)){
              Tag tag = new Tag();
              tag.setTagName(tagName);
              tag.setUserId(tagUserID);
              tags.add(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;

          for(Tag tag : tags){

            if(isGlobalTag(tag)){
              newTag = tag;
              globalTagExists = true;
            }
            if(tag.getHostId()!=null && tag.getHostId().equals(hostId)){
              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);
                  }
                  }
            }
            catch(Exception e){
              Logger.warn(TagFactory.class, "There was an error saving the tag. There's already a tag for selected host");
              //return existent tag for selected host
            }
          }
        }

        String oldUserId = newTag.getUserId();
        if ( oldUserId != null && !oldUserId.isEmpty() ) {

            if ( userId == null || userId.isEmpty() ) {
                userId = oldUserId;
            } else if ( !oldUserId.equals( userId ) && !oldUserId.contains( userId ) ) {
                userId = oldUserId + "," + userId;
            }
        }

        newTag.setUserId( userId );
        updateTag(newTag.getTagId(), userId);

        // returning tag
        return newTag;
  }
View Full Code Here

   * @return new tag created
   * @throws DotHibernateException
   */
    public static 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(TagFactory.class, "Unable to load host.");
          }

        try {
          hostId=host.getMap().get("tagStorage").toString();
        } catch (NullPointerException e) {
          hostId = Host.SYSTEM_HOST;
        }

      }
      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.