Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2011 JBoss Inc
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *       http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.drools.guvnor.server;
 
 
 
 import java.util.List;
 
 public class RepositoryCategoryOperations {
 
     private static final LoggingHelper log = LoggingHelper.getLogger(RepositoryCategoryOperations.class);
 
     @Inject @Preferred
     private RulesRepository rulesRepository;
 
     @Inject
     private ServiceSecurity serviceSecurity;
 
     @Inject
     private Identity identity;
 
     @Deprecated
     public void setRulesRepositoryForTest(RulesRepository repository) {
         // TODO use GuvnorTestBase with a real RepositoryAssetOperations instead
         this. = repository;
     }
 
     @SuppressWarnings("rawtypes")
     protected String[] loadChildCategories(String categoryPath) {
         List<StringresultList = new ArrayList<String>();
         CategoryFilter filter = new CategoryFilter();
 
         CategoryItem item = .loadCategory(categoryPath);
         List children = item.getChildTags();
         for (Object aChildren : children) {
             String childCategoryName = ((CategoryItemaChildren).getName();
             if (filter.acceptNavigate(categoryPath,
                     childCategoryName)) {
                 resultList.add(childCategoryName);
             }
         }
 
         return resultList.toArray(new String[resultList.size()]);
     }
 
     protected Boolean createCategory(String path,
                                      String name,
                                      String description) {
 
         .info("USER:" + getCurrentUserName() + " CREATING category: [" + name + "] in path [" + path + "]");
 
         if (path == null || "".equals(path)) {
             path = "/";
         }
         path = HtmlCleaner.cleanHTML(path);
 
         .loadCategory(path).addCategory(name,
                 description);
         .save();
         return .;
     }
 
     protected void renameCategory(String fullPathAndName,
                                   String newName) {
         .renameCategory(fullPathAndName,
                 newName);
     }

    
loadRuleListForCategories

    protected TableDataResult loadRuleListForCategories(String categoryPath,
                                                        int skip,
                                                        int numRows,
                                                        String tableConfigthrows SerializationException {
        // First check the user has permission to access this categoryPath.
            TableDisplayHandler handler = new TableDisplayHandler(tableConfig);
            return handler.loadRuleListTable(new AssetItemPageResult());
        }
        AssetItemPageResult result = .findAssetsByCategory(categoryPath,
                false,
                skip,
                numRows);
        TableDisplayHandler handler = new TableDisplayHandler(tableConfig);
        return handler.loadRuleListTable(result);
    }
        // Do query
        long start = System.currentTimeMillis();
        // NOTE: Filtering is handled in repository.findAssetsByCategory()
        int numRowsToReturn = (request.getPageSize() == null ? -1 : request.getPageSize());
                false,
                request.getStartRowIndex(),
                numRowsToReturn);
        .debug("Search time: " + (System.currentTimeMillis() - start));
        // Populate response
        boolean hasMoreRows = result.hasNext;
        List<CategoryPageRowrowList = new CategoryRuleListPageRowBuilder()
                .withPageRequest(request)
                .withIdentity()
                .withContent(result.assets.iterator())
                .build();
        PageResponse<CategoryPageRowpageResponse = new PageResponseBuilder<CategoryPageRow>()
                .withStartRowIndex(request.getStartRowIndex())
                .withPageRowList(rowList)
                .withLastPage(!hasMoreRows)
                .buildWithTotalRowCount(-1);
        long methodDuration = System.currentTimeMillis() - start;
        .debug("Searched for Assest with Category (" + request.getCategoryPath() + ") in " + methodDuration + " ms.");
        return pageResponse;
    }
    protected void removeCategory(String categoryPaththrows SerializationException {
        .info("USER:" + getCurrentUserName() + " REMOVING CATEGORY path: [" + categoryPath + "]");
        try {
            .loadCategory(categoryPath).remove();
            .save();
        } catch (RulesRepositoryException e) {
            .info("Unable to remove category [" + categoryPath + "]. It is probably still used: " + e.getMessage());
            throw new DetailedSerializationException("Unable to remove category. It is probably still used.",
                    e.getMessage());
        }
    }
    private String getCurrentUserName() {
        return .getSession().getUserID();
    }
New to GrepCode? Check out our FAQ X