Package com.dotmarketing.portlets.categories.model

Examples of com.dotmarketing.portlets.categories.model.Category


   * @throws DotDataException
   * @throws DotSecurityException
   * @deprecated this methods was deprecated because it hits the database, try to use the lucene search methods instead.
   */
  public List<Contentlet> getLastestContents(String structureType, String categoryName, int maxResults) throws DotDataException, DotSecurityException {
    Category category = categoryAPI.findByName(categoryName, user, true);
    Structure structure = StructureCache.getStructureByType(structureType);
    return getLastestContents(structure, category, maxResults);
  }
View Full Code Here


   * @throws DotDataException
   * @throws DotSecurityException
   * @deprecated this methods was deprecated because it hits the database, try to use the lucene search methods instead.
   */
  public List<Contentlet> getLastestContents(String structureType, String categoryName) throws DotDataException, DotSecurityException {
    Category category = categoryAPI.findByName(categoryName, user, true);
    Structure structure = StructureCache.getStructureByType(structureType);
    return getLastestContents(structure, category);
  }
View Full Code Here

   * @throws DotSecurityException
   * @deprecated This method was deprecated because it uses the presentation name of the field
   *              we encourage the use of the logical name of the field instead @see getFieldByLogicalName
   */
  public List<Contentlet> getContents(String structureType, String categoryName) throws DotDataException, DotSecurityException {
    Category category = categoryAPI.findByName(categoryName, user, true);
    Structure structure = StructureCache.getStructureByType(structureType);
    StringBuffer buffy = new StringBuffer();
    buffy.append("+live:true +deleted:false +structureInode:" + structure.getInode() + " +c" + category.getInode() + "c:on");
    return conAPI.search(buffy.toString(), 0, -1, "mod_date", user, true);
  }
View Full Code Here

      List<Category> categoryContentlet = categoryAPI.getChildren(contentlet, user, true);
      Iterator it = categoryContentlet.iterator();
      if (UtilMethods.isSet(categoryList)) {
        while (it.hasNext()) {
          Category cat = (Category)it.next();
          if (categoryList.contains(cat)) {
            returnList.add(content);
            break;
          }
        }
View Full Code Here

            ActionErrors ae = super.validate(mapping, request);

            Logger.debug(this, "action errors: " + ae);

            if (UtilMethods.isSet(getKey())) {
                Category cat = null;
        try {
          cat = categoryAPI.findByKey(getKey(), user, false);

                  if (cat != null && (InodeUtils.isSet(cat.getInode())) && (!cat.getInode().equalsIgnoreCase(this.inode))) {
                      ae.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.category.folder.taken"));
                      return ae;
                  }
        } catch (DotDataException e) {
                    ae.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.system.error"));
View Full Code Here

                  String catString="";
                  if(!categories.isEmpty()) {
                      String catId=f.getValues();

                      // we get all subcategories (recursive)
                      Category category=APILocator.getCategoryAPI().find(catId, APILocator.getUserAPI().getSystemUser(), false);
                      List<Category> childrens=APILocator.getCategoryAPI().getAllChildren(
                              category, APILocator.getUserAPI().getSystemUser(), false);

                      // we look for categories that match childrens for the
                      // categoryId of the field
View Full Code Here

        //Creating new categories

        HibernateUtil.startTransaction();

        //Adding the parent category
        Category parentCategory = new Category();
        parentCategory.setCategoryName( "Movies" + time );
        parentCategory.setKey( "movies" + time );
        parentCategory.setCategoryVelocityVarName( "movies" + time );
        parentCategory.setSortOrder( (String) null );
        parentCategory.setKeywords( null );
        //Saving it
        categoryAPI.save( null, parentCategory, user, false );

        //Creating child categories
        //New Child category
        Category childCategory1 = new Category();
        childCategory1.setCategoryName( "Action" + time );
        childCategory1.setKey( "action" + time );
        childCategory1.setCategoryVelocityVarName( "action" + time );
        childCategory1.setSortOrder( (String) null );
        childCategory1.setKeywords( null );
        //Saving it
        categoryAPI.save( parentCategory, childCategory1, user, false );
        categories.add( childCategory1 );
        //New Child category
        Category childCategory2 = new Category();
        childCategory2.setCategoryName( "Drama" + time );
        childCategory2.setKey( "drama" + time );
        childCategory2.setCategoryVelocityVarName( "drama" + time );
        childCategory2.setSortOrder( (String) null );
        childCategory2.setKeywords( null );
        //Saving it
        categoryAPI.save( parentCategory, childCategory2, user, false );
        categories.add( childCategory2 );

        HibernateUtil.commitTransaction();
View Full Code Here

        HibernateUtil.startTransaction();

        //---------------------------------------------------------------
        //Adding the parent category
        Category parentCategory = new Category();
        parentCategory.setCategoryName( "Movies" + time );
        parentCategory.setKey( "movies" + time );
        parentCategory.setCategoryVelocityVarName( "movies" + time );
        parentCategory.setSortOrder( (String) null );
        parentCategory.setKeywords( null );
        //Saving it
        categoryAPI.save( null, parentCategory, user, false );

        //Verify the cache -> THE SAVE SHOULD ADD NOTHING TO CACHE, JUST THE LOAD
        Category cachedCategory = categoryCache.get( parentCategory.getCategoryId() );
        assertNull( cachedCategory );
        //The find should add the category to the cache
        Category foundCategory = categoryAPI.find( parentCategory.getCategoryId(), user, false );
        assertNotNull( foundCategory );
        //Now it should be in cache
        cachedCategory = categoryCache.get( parentCategory.getCategoryId() );
        assertNotNull( cachedCategory );
        assertEquals( cachedCategory, parentCategory );

        //---------------------------------------------------------------
        //Creating child categories

        //New Child category
        Category childCategory1 = new Category();
        childCategory1.setCategoryName( "Action" + time );
        childCategory1.setKey( "action" + time );
        childCategory1.setCategoryVelocityVarName( "action" + time );
        childCategory1.setSortOrder( (String) null );
        childCategory1.setKeywords( null );
        //Saving it
        categoryAPI.save( parentCategory, childCategory1, user, false );
        categories.add( childCategory1 );

        //Verify the cache -> THE SAVE SHOULD ADD NOTHING TO CACHE, JUST THE LOAD
        cachedCategory = categoryCache.get( childCategory1.getCategoryId() );
        assertNull( cachedCategory );
        //The find should add the category to the cache
        foundCategory = categoryAPI.find( childCategory1.getCategoryId(), user, false );
        assertNotNull( foundCategory );
        //Now it should be in cache
        cachedCategory = categoryCache.get( childCategory1.getCategoryId() );
        assertNotNull( cachedCategory );
        assertEquals( cachedCategory, childCategory1 );

        //---------------------------------------------------------------
        //New Child category
        Category childCategory2 = new Category();
        childCategory2.setCategoryName( "Drama" + time );
        childCategory2.setKey( "drama" + time );
        childCategory2.setCategoryVelocityVarName( "drama" + time );
        childCategory2.setSortOrder( (String) null );
        childCategory2.setKeywords( null );
        //Saving it
        categoryAPI.save( parentCategory, childCategory2, user, false );
        categories.add( childCategory2 );

        //SUB-CATEGORY: Adding another level
        Category subCategory = new Category();
        subCategory.setCategoryName( "Drama_Sublevel1" + time );
        subCategory.setKey( "drama_Sublevel1" + time );
        subCategory.setCategoryVelocityVarName( "dramaSubLevel1" + time );
        subCategory.setSortOrder( (String) null );
        subCategory.setKeywords( null );
        //Saving it
        categoryAPI.save( childCategory2, subCategory, user, false );

        HibernateUtil.commitTransaction();

        //***************************************************************

        //PARENT CATEGORY
        //Verify If we find the children for the parent category we just added categories
        List<String> cachedCategories = categoryCache.getChildren( parentCategory );
        assertNull( cachedCategories );//Verify the cache -> We should have nothing on cache at this point
        List<Category> children = categoryAPI.getChildren( parentCategory, user, true );
        assertNotNull( children );
        assertTrue( children.size() > 0 );
        assertTrue( children.size() == 2 );
        //Now it should be something in cache
        cachedCategories = categoryCache.getChildren( parentCategory );
        assertNotNull( cachedCategories );
        assertTrue( cachedCategories.size() == 2 );

        //---------------------------------------------------------------
        //CATEGORY 1
        //Verify If we find the parent for the categories we just added categories
        cachedCategories = categoryCache.getParents( childCategory1 );
        assertNull( cachedCategories );//Verify the cache -> We should have nothing on cache at this point
        List<Category> parents = categoryAPI.getParents( childCategory1, user, false );
        assertNotNull( parents );
        assertTrue( parents.size() > 0 );
        assertEquals( parents.get( 0 ), parentCategory );
        //Now it should be something in cache
        cachedCategories = categoryCache.getParents( childCategory1 );
        assertNotNull( cachedCategories );
        assertTrue( cachedCategories.size() == 1 );

        //---------------------------------------------------------------
        //CATEGORY 2
        parents = categoryAPI.getParents( childCategory2, user, false );
        assertNotNull( parents );
        assertTrue( parents.size() > 0 );
        assertEquals( parents.get( 0 ), parentCategory );
        //Verify If we find the children for this child category
        cachedCategories = categoryCache.getChildren( childCategory2 );
        assertNull( cachedCategories );//Verify the cache -> We should have nothing on cache at this point
        children = categoryAPI.getChildren( childCategory2, user, true );
        assertNotNull( children );
        assertTrue( children.size() > 0 );
        assertTrue( children.size() == 1 );
        //Now it should be something in cache
        cachedCategories = categoryCache.getChildren( childCategory2 );
        assertNotNull( cachedCategories );
        assertTrue( cachedCategories.size() == 1 );

        //---------------------------------------------------------------
        //SUB-CATEGORY
        //Verify If we find the parent for the sub-category we just added
        cachedCategories = categoryCache.getParents( subCategory );
        assertNull( cachedCategories );//Verify the cache -> We should have nothing on cache at this point
        parents = categoryAPI.getParents( subCategory, user, false );
        assertNotNull( parents );
        assertTrue( parents.size() > 0 );
        assertEquals( parents.get( 0 ), childCategory2 );
        //Now it should be something in cache
        cachedCategories = categoryCache.getParents( subCategory );
        assertNotNull( cachedCategories );
        assertTrue( cachedCategories.size() == 1 );

        //***************************************************************
        //Lets add another subcategory to verify we are cleaning the caches

        //SUB-CATEGORY: Adding another subcategory
        Category subCategory2 = new Category();
        subCategory2.setCategoryName( "Drama_Sublevel1_2" + time );
        subCategory2.setKey( "drama_Sublevel1_2" + time );
        subCategory2.setCategoryVelocityVarName( "dramaSubLevel1_2" + time );
        subCategory2.setSortOrder( (String) null );
        subCategory2.setKeywords( null );
        //Saving it
        categoryAPI.save( childCategory2, subCategory2, user, false );

        //Verify the parent of the one we just saved
        parents = categoryAPI.getParents( subCategory2, user, false );
        assertNotNull( parents );
        assertTrue( parents.size() > 0 );
        assertEquals( parents.get( 0 ), childCategory2 );

        //Verify If the children list was updated
        cachedCategories = categoryCache.getChildren( childCategory2 );
        assertNull( cachedCategories );//Verify the cache -> We should have nothing on cache at this point
        children = categoryAPI.getChildren( childCategory2, user, true );
        assertNotNull( children );
        assertTrue( children.size() > 0 );
        assertTrue( children.size() == 2 );
        //Now it should be something in cache
        cachedCategories = categoryCache.getChildren( childCategory2 );
        assertNotNull( cachedCategories );
        assertTrue( cachedCategories.size() == 2 );

        //************************DELETE*********************************
        //Delete the category
        categoryAPI.delete( childCategory2, user, false );
        //Verify the cache
        cachedCategories = categoryCache.getChildren( parentCategory );
        assertNull( cachedCategories );//Verify the cache -> The delete should clean the cache
        children = categoryAPI.getChildren( parentCategory, user, true );
        assertNotNull( children );
        assertTrue( children.size() > 0 );
        assertTrue( children.size() == 1 );

        Category category = categoryCache.get( childCategory2.getCategoryId() );
        assertNull( category );//Shouldn't exits
        cachedCategories = categoryCache.getChildren( childCategory2 );
        assertNull( cachedCategories );//Shouldn't exist
    }
View Full Code Here

        sb.append("#set($_dummy=$!dotcms_content_" ).append( content.getIdentifier() ).append( ".put(\"" ).append( field.getVelocityVarName() ).append( "ButtonCode\", \"" ).append( (field.getValues() == null ? "" : field.getValues()) ).append( "\"))");

      } else if (field.getFieldType().equals(Field.FieldType.CATEGORY.toString())) {

        // Get the Category Field
        Category category=categoryAPI.find(field.getValues(), systemUser, false);

        // Get all the Contentlets Categories
        List<Category> selectedCategories=categoryAPI.getParents(content, systemUser, false);

        // Initialize variables
        String catInodes="";
        Set<Category> categoryList=new HashSet<Category>();
        List<Category> categoryTree=categoryAPI.getAllChildren(category, systemUser, false);

        if (selectedCategories.size() > 0 && categoryTree != null) {
          for (int k=0; k < categoryTree.size(); k++) {
            Category cat=(Category) categoryTree.get(k);
            for (Category categ : selectedCategories) {
              if (categ.getInode().equalsIgnoreCase(cat.getInode())) {
                categoryList.add(cat);
              }
            }
          }
        }

        if (categoryList.size() > 0) {
          Iterator<Category> it=categoryList.iterator();
          StringBuilder catbuilder=new StringBuilder();
          while (it.hasNext()) {
            Category cat=(Category) it.next();
            catbuilder.append("\"").append(cat.getInode()).append("\"") ;
            if (it.hasNext()) {
              catbuilder.append(",");
            }
          }
          catInodes=catbuilder.toString();
         
          sb.append("#set($catobjects=$categories.filterCategoriesByUserPermissions([" ).append( catInodes ).append( "]))");
          sb.append("#set($_dummy=$!dotcms_content_" ).append( content.getIdentifier() ).append( ".put(\"" ).append( field.getVelocityVarName() ).append( "CategoryObjects\", $catobjects))");
                  sb.append("#set($_dummy=$!dotcms_content_" ).append( content.getIdentifier() ).append( ".put(\"" ).append( field.getVelocityVarName() ).append( "Categories\", $categories.fetchCategoriesInodes($catobjects)))");
                  sb.append("#set($_dummy=$!dotcms_content_" ).append( content.getIdentifier() ).append( ".put(\"" ).append( field.getVelocityVarName() ).append( "\", $categories.fetchCategoriesInodes($catobjects)))");
                  sb.append("#set($_dummy=$!dotcms_content_" ).append( content.getIdentifier() ).append( ".put(\"" ).append( field.getVelocityVarName() ).append( "CategoriesNames\", $categories.fetchCategoriesNames($catobjects)))");
                  sb.append("#set($_dummy=$!dotcms_content_" ).append( content.getIdentifier() ).append( ".put(\"" ).append( field.getVelocityVarName() ).append( "CategoriesKeys\", $categories.fetchCategoriesKeys($catobjects)))");
        }
        else {
            sb.append("#set($_dummy=$!dotcms_content_" ).append( content.getIdentifier() ).append( ".put(\"" ).append( field.getVelocityVarName() ).append( "CategoryObjects\", $contents.getEmptyList()))");
                  sb.append("#set($_dummy=$!dotcms_content_" ).append( content.getIdentifier() ).append( ".put(\"" ).append( field.getVelocityVarName() ).append( "Categories\", $contents.getEmptyList()))");
                  sb.append("#set($_dummy=$!dotcms_content_" ).append( content.getIdentifier() ).append( ".put(\"" ).append( field.getVelocityVarName() ).append( "\", $contents.getEmptyList()))");
                  sb.append("#set($_dummy=$!dotcms_content_" ).append( content.getIdentifier() ).append( ".put(\"" ).append( field.getVelocityVarName() ).append( "CategoriesNames\", $contents.getEmptyList()))");
                  sb.append("#set($_dummy=$!dotcms_content_" ).append( content.getIdentifier() ).append( ".put(\"" ).append( field.getVelocityVarName() ).append( "CategoriesKeys\", $contents.getEmptyList()))");
        }       
      }

    }

    // get the contentlet categories to make a list
    String categories="";
    Set<Category> categoryList=new HashSet<Category>(categoryAPI.getParents(content, systemUser, false));
    if (categoryList != null && categoryList.size()>0) {
        StringBuilder catbuilder=new StringBuilder();
      Iterator<Category> it=categoryList.iterator();
      while (it.hasNext()) {
        Category category=it.next();
        catbuilder.append("\"").append(category.getInode()).append("\"");
        if (it.hasNext()) {
          catbuilder.append(",");
        }
      }
      categories=catbuilder.toString();
View Full Code Here

  private void loadPermission(String inode, HttpServletRequest request, HttpServletResponse response) throws Exception {
    UserWebAPI uWebAPI = WebAPILocator.getUserWebAPI();
    User user = uWebAPI.getLoggedInUser(request);
    CategoryAPI categoryAPI = APILocator.getCategoryAPI();
    Category cat = categoryAPI.find(inode, user, false);
    request.setAttribute(com.dotmarketing.util.WebKeys.PERMISSIONABLE_EDIT, cat);
    RequestDispatcher rd = request.getRequestDispatcher("/html/portlet/ext/common/edit_permissions_tab_ajax.jsp");
    rd.include(request, response);
  }
View Full Code Here

TOP

Related Classes of com.dotmarketing.portlets.categories.model.Category

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.