cancel
Showing results for 
Search instead for 
Did you mean: 

search returns different number of files every time.

supratim
Champ in-the-making
Champ in-the-making
Hi all,
We have a webscript which extends BWAbstractRepositoryWebScript class.
We have a search code which basically searches all documents with
certain extensions i.e. fileType="*.jpg" and so on


    protected List<FileInfo> getList(String path, String fileType,
                                     String userName, boolean includeSubFolders) {
        String storePath;
        if (userName.equalsIgnoreCase("staging")) {
            storePath = ROOTREF; // "avm://alfrescowww/-1;www;avm_webapps;ROOT";
        } else {
            storePath = "avm://" + PROJECT_DNSNAME + "–" + userName
                    + "/-1;www;avm_webapps;ROOT";
        }
        String nodePath = storePath + ";" + path.replace('/', ';');
        NodeRef node = new NodeRef(nodePath);
        FileFolderService fileservice = this.services.getFileFolderService();
        List<FileInfo> fileList = null;
        try {
            fileList = fileservice.search(node, fileType, true);
            System.out.println("##@@@@@@@@Found files total::"+fileList.size());
        } catch (Exception e) {
            logger.error("Error Performing Operation on method getList" + e);
        }
        return fileList;
    }

Problem is, it returns different number of files for the same folder. (folder has 7000 jpg images in total).
In the log we get
Found files total::6099
Found files total::5489 and so on.
This is tested on Alfresco 3.2r2.
Could you please suggest what could be the problem?

Complete code is following

package com.nxps.alfresco.webscripts;

import static com.nxps.alfresco.webscripts.BWConstants.*;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.alfresco.model.ContentModel;
import org.alfresco.repo.avm.util.FileExtensionNameMatcher;
import org.alfresco.repo.domain.PropertyValue;
import org.alfresco.repo.model.Repository;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
import org.alfresco.service.cmr.avm.AVMService;
import org.alfresco.service.cmr.avm.VersionDescriptor;
import org.alfresco.service.cmr.avmsync.AVMDifference;
import org.alfresco.service.cmr.avmsync.AVMSyncService;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.model.FileNotFoundException;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.MimetypeService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.cmr.search.ResultSetRow;
import org.alfresco.service.cmr.search.SearchParameters;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.NameMatcher;
import org.alfresco.wcm.sandbox.SandboxService;
import org.alfresco.wcm.sandbox.SandboxVersion;
import org.alfresco.web.scripts.AbstractWebScript;
import org.alfresco.web.scripts.WebScriptException;
import org.alfresco.web.scripts.WebScriptRequest;
import org.alfresco.web.scripts.WebScriptResponse;
import org.alfresco.web.scripts.servlet.WebScriptServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
* Copyright © , XXX Pvt Ltd.
* All rights reserved
*
* @author xxx
*/

public abstract class BWAbstractRepositoryWebScript extends AbstractWebScript {
  
   private static final Log logger = LogFactory
            .getLog(BWAbstractRepositoryWebScript.class);

    // Component dependencies

    /**
     * Creating reference for Repository
     */
    protected Repository repository;
    /**
     * Creating reference for Service Registry
     */
    protected ServiceRegistry services;

    /**
     * Default constructor of BWAbstractRepositoryWebScript class
     */
    public BWAbstractRepositoryWebScript() {
    }


    /**
     * Setter for setting Repository
     */
    public void setRepository(Repository repository) {
        this.repository = repository;
    }

    /**
     * Setter for setting Service Registry
     */
    public void setServiceRegistry(ServiceRegistry services) {
        this.services = services;
    }

    /**
     * Getter for Node Service
     */
    protected NodeService getNodeService() {
        return services.getNodeService();
    }

    /**
     * Getter for Content Service
     */
    protected ContentService getContentService() {
        return services.getContentService();
    }

    /**
     * Getter for Mine Type Service
     */
    protected MimetypeService getMimetypeService() {
        return services.getMimetypeService();
    }

    /**
     * Getter for File Folder Service
     */
    protected FileFolderService getFileFolderService() {
        return services.getFileFolderService();
    }

    /**
     * Getter for Node Reference
     */
    protected NodeRef getNodeRef(WebScriptRequest req) {
        // NOTE: This web script must be executed in a HTTP Servlet environment
        if (!(req instanceof WebScriptServletRequest)) {
            throw new WebScriptException(
                    "Content retrieval must be executed in HTTP Servlet environment");
        }
        HttpServletRequest httpReq = ((WebScriptServletRequest) req)
                .getHttpServletRequest();

        // locate the root path
        String path = (String) httpReq.getParameter("path");
        if (path == null) {
            path = "/images";
        }
        if (path.startsWith("/")) {
            path = path.substring(1, path.length());
        }

        // build a path elements list
        List<String> pathElements = new ArrayList<String>();
        StringTokenizer tokenizer = new StringTokenizer(path, "/");
        while (tokenizer.hasMoreTokens()) {
            String childName = tokenizer.nextToken();
            pathElements.add(childName);
        }

        // look up the child
        NodeRef nodeRef = null;
        try {
            NodeRef companyHomeRef = this.repository.getCompanyHome();
            nodeRef = getFileFolderService().resolveNamePath(companyHomeRef,
                    pathElements).getNodeRef();
        } catch (FileNotFoundException fnfe) {
            throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND,
                    "Unable to locate path");
        }
        if (nodeRef == null) {
            throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND,
                    "Unable to locate path");
        }

        return nodeRef;
    }

    /**
     * @param res     Reference of Web Service Response
     * @param nodeRef Streams the contents of the referenced file on the response
     */
    protected void output(WebScriptResponse res, NodeRef nodeRef) {
        try {
            ContentReader reader = this.services.getContentService().getReader(
                    nodeRef, ContentModel.PROP_CONTENT);
            // stream back
            reader.getContent(res.getOutputStream());
        } catch (Exception e) {
            throw new WebScriptException("Unable to stream output");
        }

    }

    /**
     * Initialization process of the project
     */
    protected void init() {
        this.createProject();
        for (Iterator iter = objectType.keySet().iterator(); iter.hasNext();) {
            String folderPath = objectType.get(((String) iter.next())
                    .toLowerCase());
            this.createPath(folderPath);
        }
        // this.createContentSchema();
        this.createTemplates();
    }

    /**
     * Creating the templates
     */
    private void createTemplates() {
        List<String> filePaths = new ArrayList<String>();
        filePaths.add("/bw/templates/bSchoolTemplates/bSchoolTemplate.xml");
        filePaths.add("/bw/templates/storiesAroundTheWorld.xml");
        filePaths.add("/bw/templates/bwPlusTemplate.xml");
        filePaths.add("/bw/templates/andMoreTemplate.xml");
        filePaths.add("/bw/templates/currentPoll.xml");
        filePaths.add("/bw/templates/currentQuote.xml");
        filePaths.add("/bw/templates/dataLandingPageTemplate.xml");
        filePaths.add("/bw/templates/homepageTemplate.xml");
        filePaths.add("/Web_Forms/content.xsd");
        filePaths.add("/Web_Forms/bwImage.xsd");
        filePaths.add("/Web_Forms/storyContent.xsd");
        filePaths.add("/Web_Forms/mediaContent.xsd");
        filePaths.add("/bw/siteSections/Magazine.xml");
        filePaths.add("/bw/siteSections/Opinion.xml");
        filePaths.add("/bw/siteSections/BusinessSchools.xml");
        filePaths.add("/bw/siteSections/More.xml");
        filePaths.add("/bw/siteSubSections/BusinessSchools_Blogs.xml");
        filePaths.add("/bw/siteSubSections/BusinessSchools_Directory.xml");
        filePaths.add("/bw/siteSubSections/BusinessSchools_FacultySpeak.xml");
        filePaths.add("/bw/siteSubSections/BusinessSchools_PreparingForCAT.xml");
        filePaths.add("/bw/siteSubSections/BusinessSchools_Training.xml");
        filePaths.add("/bw/siteSubSections/Magazine_Archives.xml");
        filePaths.add("/bw/siteSubSections/Magazine_CurrentIssue.xml");
        filePaths.add("/bw/siteSubSections/Magazine_SubscribeBW.xml");
        filePaths.add("/bw/siteSubSections/Opinion_Columnists.xml");
        filePaths.add("/bw/siteSubSections/Opinion_Feedback.xml");
        filePaths.add("/bw/siteSubSections/Opinion_QuickTake.xml");

        for (String filePath : filePaths) {
            String folderPath = filePath
                    .substring(0, filePath.lastIndexOf("/"));
            String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
            logger.debug("File Name: " + fileName);
            logger.debug("Folder Path: " + folderPath);
            this.createPath(folderPath);
            String parentRef = ROOTREF + folderPath;
            byte[] contents;
            try {
                contents = this.readFileFromSystem(System
                        .getProperty("java.io.tmpdir")
                        + "/filesToBeUploaded/" + fileName);
                this.createFile("/" + folderPath, fileName, contents);
            } catch (IOException e) {
                logger.error("Error in reading File : " + filePath + e);
                logger.error(e);
            }
        }
    }

    /** Creating the Project */
    private void createProject() {
        String dnsName = PROJECT_DNSNAME;
        String name = PROJECT_NAME;
        String title = PROJECT_TITLE;
        String description = PROJECT_DESCRIPTION;
        this.services.getWebProjectService().createWebProject(dnsName, name,
                title, description);
    }
   /** Creation of the content schema*/
    protected void createContentSchema() {
        String parentRef = ROOTREF;// "avm://alfrescowww/-1;www;avm_webapps;ROOT";
        String folderName = "Web_Forms";
        String path = ROOT_PATH;// "alfrescowww:/www/avm_webapps/ROOT";
        AVMService avmService = this.services.getAVMService();
        try {
            avmService.createDirectory(path, folderName);
        } catch (Exception e) {
            logger.error("Exception Performing Operation on method createContentSchema" + e);
        }
        parentRef = parentRef + ";" + folderName;
        // read file content.xsd from system and write to alfresco
        Map<String, String> files = new HashMap<String, String>();
        files.put(CONTENT_FILE_PATH, CONTENT_FILE_NAME);
        files.put(STORYCONTENT_FILE_PATH, STORYCONTENT_FILE_NAME);
        files.put(MEDIACONTENT_FILE_PATH, MEDIACONTENT_FILE_NAME);
        for (Iterator<String> iter = files.keySet().iterator(); iter.hasNext();) {
            String filePath = iter.next();
            String fileName = files.get(filePath);
            byte[] contents;
            try {
                contents = this.readFileFromSystem(filePath);
                this.createFile("/" + folderName, fileName, contents);
            } catch (IOException e) {
                logger.error("Error in reading File : " + filePath);
                logger.error("Error Performing Operation", e);
            }

        }
    }

    /**
     * Creating the absolute path
     * @param path The location of the folder
     */
    public void createPath(String path) {
        StringTokenizer folders = new StringTokenizer(path, "/");
        String parentRef = ROOTREF; // "avm://alfrescowww/-1;www;avm_webapps;ROOT";
        String parentPath = ROOT_PATH; // "alfrescowww:/www/avm_webapps/ROOT";
        while (folders.hasMoreTokens()) {
            String folderName = folders.nextToken();
            AVMService avmService = this.services.getAVMService();
            try {
                avmService.createDirectory(parentPath, folderName);
            } catch (Exception e) {
                logger.error("Error Performing Operation on method createPath" + e);
            }
            parentPath = parentPath + "/" + folderName;
            parentRef = parentRef + ";" + folderName;
        }
    }

    /**
     *   To read data from the file
     * @param path The location of the file
     * @return  the byte array of the data
     * @throws IOException If I/O exception occurs
     */
    protected byte[] readFileFromSystem(String path) throws IOException {
        File file = new File(path);
        InputStream is = new FileInputStream(file);
        long length = file.length();

        // Create the byte array to hold the data
        byte[] bytes = new byte[(int) length];

        // Read in the bytes
        int offset = 0;
        int numRead = 0;
        while (offset < bytes.length
                && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
            offset += numRead;
        }

        // Ensure all the bytes have been read in
        if (offset < bytes.length) {
            throw new IOException("Could not completely read file "
                    + file.getName());
        }

        // Close the input stream and return bytes
        is.close();
        return bytes;
    }

    /**
     * Creates the file using following paramaters
     * @param fPath Location of the file
     * @param fName The file name
     * @param contents The array containing the data
     * @return True if file created else false
     */
    protected boolean createFile(String fPath, String fName, byte[] contents) {
        boolean status = false;
        try {
            // String path = "alfrescowww–admin:/www/avm_webapps/ROOT";
            String path = ROOT_PATH;// "alfrescowww:/www/avm_webapps/ROOT";
            logger.debug("Creating File Name:   " + fName);
            OutputStream newFile = this.services.getAVMService().createFile(
                    path + fPath, fName);
            newFile.write(contents);
            newFile.close();
            status = true;
        } catch (Exception e) {
            logger.debug("File " + fName + " Already Exists");
        }
        return status;
    }

    /**
     * Saving the user data to the file
     * @param rootPath contains the path of root directory
     * @param fPath  contains File location
     * @param fName  contains file name
     * @param contents  used to stored user data
     * @return  On success returns true
     */
    protected boolean writeToUser(String rootPath, String fPath, String fName,
                                  byte[] contents) {
        boolean status = false;
        try {
            logger.debug("Created File Name:   " + fName);
            OutputStream newFile = this.services.getAVMService().createFile(
                    rootPath + fPath, fName);
            newFile.write(contents);
            newFile.close();
            status = true;
        } catch (Exception e) {
            logger.debug("In Catch Block for creating file : " + fName);
        }
        return status;
    }

    /**
     *  Used to create Image
     * @param fPath  contains File location
     * @param fName  contains file name
     * @param contents  used to stored data
     * @return On success returns true
     */
    protected boolean createImage(String fPath, String fName, byte[] contents) {
        boolean status = false;
        try {
            // String path = "alfrescowww–admin:/www/avm_webapps/ROOT";
            String path = ROOT_PATH;// "alfrescowww:/www/avm_webapps/ROOT";
            logger.debug("Creating File with Name:   " + fName);
            OutputStream newFile = this.services.getAVMService().createFile(
                    path + fPath, fName);
            newFile.write(contents);
            newFile.close();
            status = true;
        } catch (Exception e) {
            logger.error("In Catch Block", e);

        }
        return status;
    }

    /**
     * Used to delete the file
     * @param fName Name of the to be deleted
     * @return On success returns true
     */
    protected boolean deleteFile(String fName) {
        boolean status = false;
        try {
            // String path = "alfrescowww–admin:/www/avm_webapps/ROOT";
            String path = ROOT_PATH;// "alfrescowww:/www/avm_webapps/ROOT";
            logger.debug("Deleted File Name:   " + fName);
            this.services.getAVMService().removeNode(path + "/" + fName);
            status = true;
        } catch (Exception e) {
            logger.error("In Catch Block", e);
        }
        return status;
    }

    /**
     * Used to update the file
     * @param filePath  Location of the file
     * @param contents Contains the updated information
     * @return On success returns true
     */
    protected boolean updateFile(String filePath, String contents) {
        String noderef = ROOTREF + ";" + filePath.replace('/', ';');
        NodeRef nodeRef = new NodeRef(noderef);
        ContentWriter writer = this.services.getContentService().getWriter(
                nodeRef, ContentModel.PROP_CONTENT, true);
        writer.putContent(contents);
        return true;
    }

    /**
     * Getting list of files
     * @param path location of the file
     * @param fileType specifying type pf file
     * @param userName user of the file
     * @param includeSubFolders  Boolean checking if it contains sub folder
     * @return   list of files
     */
    protected List<FileInfo> getList(String path, String fileType,
                                     String userName, boolean includeSubFolders) {
        String storePath;
        if (userName.equalsIgnoreCase("staging")) {
            storePath = ROOTREF; // "avm://alfrescowww/-1;www;avm_webapps;ROOT";
        } else {
            storePath = "avm://" + PROJECT_DNSNAME + "–" + userName
                    + "/-1;www;avm_webapps;ROOT";
        }
        String nodePath = storePath + ";" + path.replace('/', ';');
        NodeRef node = new NodeRef(nodePath);
        FileFolderService fileservice = this.services.getFileFolderService();
        List<FileInfo> fileList = null;
        try {
            fileList = fileservice.search(node, fileType, true);
            System.out.println("##@@@@@@@@Found files total::"+fileList.size());
        } catch (Exception e) {
            logger.error("Error Performing Operation on method getList" + e);
        }
        return fileList;
    }

    /**
     * Getting contents of the file
     * @param filePath  Location of the file
     * @return  contents of the file
     */
    protected String getFileContents(String filePath) {
        String noderef = ROOTREF + filePath.replace('/', ';');
        NodeRef nodeRef = new NodeRef(noderef);
        ContentReader reader = this.services.getContentService().getReader(
                nodeRef, ContentModel.PROP_CONTENT);
        return reader.getContentString();
    }

    /**
     *  Getting contents of the file by inputing two parameters
     * @param filePath Location of the file
     * @param userName user of the file
     * @return contents of the file
     */
    protected String getFileContents(String filePath, String userName) {
        String storePath;
        if (userName == null || userName.equalsIgnoreCase("staging")) {
            storePath = ROOTREF;
        } else {
            storePath = "avm://" + PROJECT_DNSNAME + "–" + userName
                    + "/-1;www;avm_webapps;ROOT";
        }
        String noderef = storePath + ";" + filePath.replace('/', ';');
        // String noderef = ROOTREF + filePath.replace('/', ';');
        NodeRef nodeRef = new NodeRef(noderef);
        ContentReader reader = this.services.getContentService().getReader(
                nodeRef, ContentModel.PROP_CONTENT);
        return reader.getContentString();
    }

    /**
     * Getter  for content reader
     * @param nodeRef  reference of Node
     * @return content reader reference
     */
    protected ContentReader getContentReader(NodeRef nodeRef) {
        return this.services.getContentService().getReader(nodeRef,
                ContentModel.PROP_CONTENT);
    }

    /**
     * Getter for  content writer
     * @param nodeRef reference of Node
     * @return  content writer reference
     */
    protected ContentWriter getContentWriter(NodeRef nodeRef) {
        return this.services.getContentService().getWriter(nodeRef,
                ContentModel.PROP_CONTENT, true);
    }

    /**
     * Getting list of changed nodes
     * @param sbStoreId contains the store id
     * @param path stores the path
     * @return  list of nodes changed
     */
    @SuppressWarnings("unchecked")
    protected List getUserSandboxChanges(String sbStoreId, String path) {
        SandboxService sandboxService = this.services.getSandboxService();
        List changedNodes = sandboxService.listChangedWebApp(sbStoreId, path,
                true);
        logger.debug("The Number of changed Nodes found : "
                + changedNodes.size());
        return changedNodes;
    }

    /**
     * Get the sand box changes using lucene
     * @param sbStoreId contains the store id
     * @param path stores the path
     */
    protected void getStagingSandboxChangesUsingLucene(String sbStoreId,
                                                       String path) {
        NodeRef rootNode = new NodeRef(ROOTREF + ";bw;images;");
        SearchParameters sp = new SearchParameters();
        sp.addStore(rootNode.getStoreRef());
        sp.setLanguage(SearchService.LANGUAGE_LUCENE);
        sp
                .setQuery("@cm\\:modified:\"[2009-01-09T14:02:35.000Z TO 2009-01-09T14:11:30.000Z\"");
        ResultSet results = null;
        try {
            results = services.getSearchService().query(sp);
            for (ResultSetRow row : results) {
                NodeRef currentNodeRef = row.getNodeRef();
                logger.debug("Node ID:  " + currentNodeRef.getId());
            }
        } finally {
            if (results != null) {
                results.close();
            }
        }
    }

    /**
     * Get the sand box changes
     * @param sbStoreId contains the store id
     * @param path stores the path
     * @param startDate
     * @return list of nodes changed
     */
    protected List getStagingSandboxChanges(String sbStoreId, String path,
                                            Date startDate) {
        List<AVMNodeDescriptor> changedNodes = new ArrayList<AVMNodeDescriptor>();
        SandboxService sandboxService = this.services.getSandboxService();
        Date endDate = new Date();
        List snapShots = sandboxService.listSnapshots(sbStoreId, startDate,
                endDate, true);
        logger.debug("Number of snapshots:   " + snapShots.size());
        if (snapShots.size() > 0) {
            SandboxVersion oldSnapshot = (SandboxVersion) snapShots
                    .get(snapShots.size() - 1);
            AVMSyncService avmSyncService = this.services.getAVMSyncService();
            AVMService avmService = this.services.getAVMService();
            NameMatcher excluder = new FileExtensionNameMatcher();
            sbStoreId = ROOT_PATH + path;
            List<AVMDifference> differenceList = avmSyncService.compare(
                    oldSnapshot.getVersion() - 1, sbStoreId, -1, sbStoreId,
                    excluder);
            logger.debug("Number of Differences  :  "
                    + differenceList.size());
            AVMNodeDescriptor nodeDescriptor;
            for (AVMDifference diff : differenceList) {
                nodeDescriptor = avmService.lookup(
                        diff.getDestinationVersion(),
                        diff.getDestinationPath(), true);
                changedNodes.add(nodeDescriptor);
            }
        }
        return changedNodes;
    }

    /**
     * Adding property to AVMService
     * @param filePath location of the file
     * @param property reference of QName
     * @param val
     * @return  on success return true
     */
    protected boolean addProperty(String filePath, QName property, Long val) {
        boolean added = false;
        try {
            AVMService avmService = this.services.getAVMService();
            String path = ROOT_PATH + filePath;
            PropertyValue value = new PropertyValue(DataTypeDefinition.INT, val);
            avmService.setNodeProperty(path, property, value);

        } catch (Exception e) {
            logger.error("Error Performing Operation on method addProperty" + e);
        }
        return added;
    }

    /**
     *  Getting wpStroe users
     * @param wpStoreId containing wp store id
     * @return  list of users
     */
    protected Set<String> getUsers(String wpStoreId) {
        Map<String, String> usersMap = this.services.getWebProjectService()
                .listWebUsers(wpStoreId);
        Set<String> users = usersMap.keySet();
        for (String key : users) {
            logger.debug("Key : " + key + "  Value : "
                    + usersMap.get(key));
        }
        return users;
    }

    /**
     * Submit the file to staging
     * @param userName user of the file
     * @param fPath location of the file
     * @param fName  name of the file
     */
    protected void submitFileToStaging(String userName, String fPath,
                                       String fName) {
        String sbStoreId = PROJECT_DNSNAME + "–" + userName;
        String relativePath = "/www/avm_webapps/ROOT" + fPath + fName;
        String submitLabel = "submited file " + fPath + fName;
        String submitComment = "This is a submit done from web script to "
                + "submit the file with path: " + fPath + fName;
        this.services.getSandboxService().submit(sbStoreId, relativePath,
                submitLabel, submitComment);
    }

    /**
     * submitting all file to staging
     * @param userName user of the file
     * @param fPath location of the file
     */
    protected void submitAllToStaging(String userName, String fPath) {
        String sbStoreId = PROJECT_DNSNAME + "–" + userName;
        String relativePath = "/www/avm_webapps/ROOT" + fPath;
        String submitLabel = "submited file " + fPath;
        String submitComment = "This is a submit done from web script to "
                + "submit the file with path: " + fPath;
        this.services.getSandboxService().submit(sbStoreId, relativePath,
                submitLabel, submitComment);
    }

    /**
     * used to create the snap shot
     */
    public void createSnapshot() {
        String tag = "Created Users";
        logger.debug(1);
        String description = "Taking snapshot after writing users to alfresco";
        logger.debug(2);
        this.services.getAVMService().createSnapshot(PROJECT_DNSNAME, tag,
                description);
        logger.debug(3);
    }

    /**
     * Authenticate the user for login
     */
    public void login() {
        this.services.getAuthenticationService().authenticate(USERNAME,
                PASSWORD.toCharArray());
    }

    /**
     *  Retriving the  file meta data
     * @param files contains the information about a file
     * @param storePath   location of the store
     * @param fpath  location of the file
     * @return  file information  as list
     */
    protected List<FileMetaData> getFileMetaDataList(List<FileInfo> files, String storePath, String fpath) {
        logger.debug("Store path:  " + storePath);
        logger.debug("File path:  " + fpath);
        List<FileMetaData> fileList = new ArrayList<FileMetaData>();
        FileMetaData fileMetaData;
        for (FileInfo info : files) {
            Map<QName, Serializable> properties = info.getProperties();
            fileMetaData = new FileMetaData();
            fileMetaData.setCreateDate(info.getCreatedDate());
            fileMetaData.setModDate(info.getModifiedDate());
            fileMetaData.setName(info.getName());
            String fileName = info.getNodeRef().toString().substring(
                    storePath.length()).replace(';', '/');
            fileMetaData.setPath(fileName);
            if (fpath.contains(objectType.get("content"))) {
                long readCount = 0;
                if (properties.containsKey(READ_COUNT_QNAME)) {
                    readCount = Integer.parseInt(properties.get(
                            READ_COUNT_QNAME).toString());
                }
                fileMetaData.setReadCount(readCount);
                long emailCount = 0;
                if (properties.containsKey(EMAIL_COUNT_QNAME)) {
                    emailCount = Integer.parseInt(properties.get(
                            EMAIL_COUNT_QNAME).toString());
                }
                fileMetaData.setEmailCount(emailCount);
            }
            fileList.add(fileMetaData);
        }
        Collections.sort(fileList);
        return fileList;
    }

}

5 REPLIES 5

dhalupa
Champ on-the-rise
Champ on-the-rise
This discussion might help you. Take a look at the last post

Kind regards,

Denis

supratim
Champ in-the-making
Champ in-the-making
Thank you Denis,
I have joined the linkedin group, my membership is subjected to approval of group manager!
Can you please point me to some other resource for the time being?
Many thanks, I really appreciate your help.

dhalupa
Champ on-the-rise
Champ on-the-rise
Ok, copy/paste…

I was also intrigued by this behaviour, and have looked into the code a bit. Here are my conclusions..
There are few reasons for such behaviour. When search is initated using SearchService, first thing obviously is to query lucene index with passed query. This will return a collection of lucene search hits. A search hit contains node id which satisfies search expression. This is pretty quick process but this collection knows nothing about user rights on particular nodes. Therefore acl evaluation on each hit has to be performed. There are few parameters which affect this process

(1) system.acl.maxPermissionCheckTimeMillis defaults to 10000ms and defines maximum time that will be spent on ACL evaluation
(2) system.acl.maxPermissionChecks defaults to 1000 and defines maximum number of ACL evaluations that will be performed for collection of hits that will be returned from Lucene query. If the number of hits exceedes this number, the rest will simply be discarded
(3) number of ACLs held in cache which defaults to 1000

ACL evaluation process will go through all hits from collection, if ACL is present in the cache, than cached ACL will be used. If not, ACL will be retreived from database. This means that each ACL which is not present in the cache will result in a database query. Before evaluation of each hit, it will be checked whether maximum time(1) or maximum number(2) has been exceeded. If so, evaluation will be stopped and rest of hits will be discarded.

Looking into above process, the reasons for behaviour mentioned in previous post can be understood. It is also clear that this behaviour can be affected by changing the values of those three parameteres.

Kind regards,

Denis

supratim
Champ in-the-making
Champ in-the-making
wow! That worked! Thanks a lot. Alfresco rocks, so do you! Cheers!

gilles
Champ in-the-making
Champ in-the-making
Hi, what do you mean by "That worked"? Did you manage to fetch all the nodes?
What config did you use?
What config could I use for a 5000 folders + 5000 contents repository? Any benchmarks?
If I "lucene" search in the node browser I often get exactly 101 results but sometimes more. Is there a limit behind this?
What's the better way to be sure to fecth all matching nodes?
Thanks in advance,
Gilles
(Alfresco 2.9)