Ejemplo n.º 1
0
  /**
   * Method that will verify if a given template title is already used by another template
   *
   * @param title template title to verify
   * @param templateInode template inode in case we are editing a template, null or empty in case of
   *     a new template
   * @param hostIdentifier current host identifier
   * @return
   * @throws DotDataException
   * @throws SystemException
   * @throws PortalException
   * @throws DotSecurityException
   */
  public boolean duplicatedTitle(String title, String templateInode, String hostIdentifier)
      throws DotDataException, SystemException, PortalException, DotSecurityException {

    HttpServletRequest req = WebContextFactory.get().getHttpServletRequest();
    User user = userWebAPI.getLoggedInUser(req);
    boolean respectFrontendRoles = userWebAPI.isLoggedToFrontend(req);

    // Getting the current host
    Host host = hostAPI.find(hostIdentifier, user, respectFrontendRoles);

    // The template name must be unique
    Template foundTemplate =
        FactoryLocator.getTemplateFactory().findWorkingTemplateByName(title, host);
    boolean duplicatedTitle = false;
    if (foundTemplate != null && InodeUtils.isSet(foundTemplate.getInode())) {
      if (!UtilMethods.isSet(templateInode)) {
        duplicatedTitle = true;
      } else {
        if (!foundTemplate.getInode().equals(templateInode)) {
          duplicatedTitle = true;
        }
      }
    }

    return duplicatedTitle;
  }
Ejemplo n.º 2
0
 public String checkDependencies(String templateInode)
     throws DotDataException, DotRuntimeException, DotSecurityException, PortalException,
         SystemException {
   HttpServletRequest req = WebContextFactory.get().getHttpServletRequest();
   User user = userWebAPI.getLoggedInUser(req);
   boolean respectFrontendRoles = userWebAPI.isLoggedToFrontend(req);
   return templateAPI.checkDependencies(templateInode, user, respectFrontendRoles);
 }
Ejemplo n.º 3
0
  public Map<String, Object> fetchTemplates(
      Map<String, String> query,
      Map<String, String> queryOptions,
      int start,
      int count,
      List<String> sort)
      throws PortalException, SystemException, DotDataException, DotSecurityException {

    HttpServletRequest req = WebContextFactory.get().getHttpServletRequest();
    User user = userWebAPI.getLoggedInUser(req);
    boolean respectFrontendRoles = userWebAPI.isLoggedToFrontend(req);
    if (count <= 0) count = 10;

    List<Template> fullListTemplates = new ArrayList<Template>();
    List<Template> totalTemplates = new ArrayList<Template>();
    Host host = hostAPI.find(query.get("hostId"), user, respectFrontendRoles);

    try {
      String filter = query.get("fullTitle");
      if (UtilMethods.isSet(filter)) {
        filter = filter.replaceAll("\\*", "");
        filter = filter.replaceAll("\\?", "");
      }

      if (UtilMethods.isSet(query.get("hostId"))) {
        int startF = start;
        int countF = count;
        if (start == 0) {
          Template t = new Template();
          t.setOwner(user.getUserId());
          t.setModUser(user.getUserId());
          t.setInode("0");
          t.setTitle("--- " + LanguageUtil.get(user, "All-Hosts") + " ---");
          t.setIdentifier("0");
          fullListTemplates.add(t);
          totalTemplates.add(t);
          countF = count - 1;
        } else {
          startF = start - 1;
        }
        fullListTemplates.addAll(
            templateAPI.findTemplatesUserCanUse(
                user, host.getHostname(), filter, true, startF, countF));
        totalTemplates.addAll(
            templateAPI.findTemplatesUserCanUse(user, host.getHostname(), filter, true, 0, 1000));
      }

      // doesn't currently respect archived
      if (fullListTemplates.size() == 0) {
        fullListTemplates.addAll(
            templateAPI.findTemplatesUserCanUse(
                user, "", filter, true, start, start > 0 ? count : count + 1));
        totalTemplates.addAll(templateAPI.findTemplatesUserCanUse(user, "", filter, true, 0, 1000));
      }

    } catch (DotDataException e) {
      Logger.error(this, e.getMessage(), e);
      throw new DotDataException(e.getMessage(), e);
    }
    // Collections.sort(fullListTemplates, new TemplateComparator(baseHostId));
    Map<String, Object> results = new HashMap<String, Object>();
    List<Map<String, Object>> list = new LinkedList<Map<String, Object>>();

    boolean shouldIncludeTemplate = true;
    String toInclude = queryOptions.get("includeTemplate");
    for (Template template : fullListTemplates) {
      Map<String, Object> contMap = buildTemplateMap(template);
      list.add(contMap);
    }
    if (toInclude != null && shouldIncludeTemplate) {
      Template template =
          templateAPI.findWorkingTemplate(
              toInclude, APILocator.getUserAPI().getSystemUser(), false);
      if (template != null) {
        list.add(buildTemplateMap(template));
      }
    }

    //		totalTemplates = templateAPI.findTemplatesAssignedTo(host);
    //		if(start >= list.size()) start =  list.size() - 1;
    //		if(start < 0)  start  = 0;
    //		if(start + count >= list.size()) count = list.size() - start;
    //		List<Map<String, Object>> templates = list.subList(start, start + count);

    results.put("totalResults", totalTemplates.size());

    results.put("list", list);

    return results;
  }