Package com.dotmarketing.tag.business

Examples of com.dotmarketing.tag.business.TagAPI


    try {
      user = uWebAPI.getLoggedInUser(request);

      ObjectMapper mapper = new ObjectMapper();
      mapper.configure(Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
      TagAPI tagAPI = APILocator.getTagAPI();

      String termFilter = "";
      if(UtilMethods.isSet(request.getParameter("tagname"))) {
        termFilter = request.getParameter("tagname").toLowerCase();
      }

      boolean globalTagsFilter = false;

      if(UtilMethods.isSet(request.getParameter("global"))) {
        if(request.getParameter("global").equalsIgnoreCase("1"))
          globalTagsFilter = true;
      }

      String hostFilter = request.getSession().getAttribute(com.dotmarketing.util.WebKeys.CMS_SELECTED_HOST_ID).toString();

      String sort = request.getParameter("sort");

      String action = request.getParameter("action");

      if(UtilMethods.isSet(action) && action.equals("export")) {
        List<Tag> tagsList = tagAPI.getFilteredTags(termFilter, hostFilter, globalTagsFilter, sort, 0, 0);
        exportTags(request,  response,  tagsList);
        return;
      }

      if(UtilMethods.isSet(action) && action.equals("download")) {
        downloadCSVSampleFile(response);
        return;
      }

      int start = 0;
      int count = 20;
      String startStr = request.getParameter("start");
      String countStr = request.getParameter("count");

      if(UtilMethods.isSet(startStr) && UtilMethods.isSet(countStr)) {
        start = Integer.parseInt(request.getParameter("start"));
        count = Integer.parseInt(request.getParameter("count"));
      }


      List<Map<String,Object>> items = new ArrayList<Map<String,Object>>();

      List<Tag> tags = null;
      termFilter = StringEscapeUtils.unescapeJava(termFilter)
      if(UtilMethods.isSet(termFilter)){
        tags = tagAPI.getFilteredTags(termFilter, hostFilter, globalTagsFilter, sort, start, count);
      }else{
        tags = tagAPI.getFilteredTags("", hostFilter, globalTagsFilter, sort, start, count);
      }

      if(tags!=null) {
        for (Tag tag : tags) {
          String hostId = tag.getHostId();
          Host host = null;
          try{
            host = APILocator.getHostAPI().find(hostId, user, true);
          }
          catch (Exception e){
            Logger.error(this, "Unable to get host from tag Id:"+ tag.getHostId());
          }
          if (host!=null){
            Map<String,Object> tagMap = new HashMap<String,Object>();
            String hostName = "";
            if(host.isSystemHost())
              hostName = LanguageUtil.get(APILocator.getUserAPI().getSystemUser(), "tag-all-hosts");
            else
              hostName = host.getHostname();
            tagMap.put("tagId", tag.getTagId());
            tagMap.put("tagname", tag.getTagName());
            tagMap.put("hostId", tag.getHostId());
            tagMap.put("hostName", hostName);
            items.add(tagMap);
          }
        }
      }

      Map<String,Object> m = new HashMap<String, Object>();
      m.put("items", items);
      m.put("numRows", tagAPI.getFilteredTags(termFilter, hostFilter, globalTagsFilter, sort, 0, 0).size());
      String s = mapper.writeValueAsString(m);
      response.setContentType("text/plain");
      response.getWriter().write(s);
      response.getWriter().flush();
      response.getWriter().close();
View Full Code Here

TOP

Related Classes of com.dotmarketing.tag.business.TagAPI

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.