09-26-2006 08:43 AM
import java.util.List;
import junit.framework.TestCase;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.search.impl.lucene.LuceneIndexerAndSearcher;
import org.alfresco.repo.search.impl.lucene.LuceneSearcherImpl;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern;
import org.alfresco.util.ApplicationContextHelper;
import org.springframework.context.ApplicationContext;
public class LuceneTest extends TestCase{
static NodeService nodeService = null;
static DictionaryService dictionaryService = null;
static AuthenticationComponent authenticationComponent = null;
static LuceneIndexerAndSearcher indexerAndSearcher = null;
static boolean setupCompleted = false;
@Override
protected void setUp() throws Exception {
if(!setupCompleted) {
// initialise app content
ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
// get registry of services
ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
// get required services
nodeService = serviceRegistry.getNodeService();
dictionaryService = serviceRegistry.getDictionaryService();
indexerAndSearcher = (LuceneIndexerAndSearcher) ctx.getBean("luceneIndexerAndSearcherFactory");
authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
authenticationComponent.setSystemUserAsCurrentUser();
setupCompleted = true;
}
}
public void testFindAllAuditableAspectsInTheRepository() {
LuceneSearcherImpl searcher = LuceneSearcherImpl.getSearcher(getCompanyHome().getStoreRef(), indexerAndSearcher);
String queryStr = "ASPECT:\"" + ContentModel.ASPECT_AUDITABLE.toString() + "\"";
searcher.setDictionaryService(dictionaryService);
ResultSet results = searcher.query(getCompanyHome().getStoreRef(), "lucene", queryStr, null, null);
assertTrue(results.getNodeRefs().size()>0);
}
private NodeRef getCompanyHome() {
StoreRef spacesStoreRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
NodeRef rootNodeRef = nodeService.getRootNode(spacesStoreRef);
List<ChildAssociationRef> childRefs = nodeService.getChildAssocs(rootNodeRef,
RegexQNamePattern.MATCH_ALL, QName.createQName(NamespaceService.APP_MODEL_1_0_URI, "company_home"));
ChildAssociationRef companyHomeRef = childRefs.get(0);
NodeRef companyHome = companyHomeRef.getChildRef();
return companyHome;
}
}
09-26-2006 09:55 AM
ASPECT:"{http://www.alfresco.org/model/content/1.0}auditable"
09-26-2006 10:52 AM
ResultSet results = serviceRegistry.getSearchService().query(getCompanyHome().getStoreRef(), "lucene", "ASPECT:\"" + ContentModel.ASPECT_AUDITABLE.toString() + "\"");
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.