Search in sources :

Example 1 with PDLucene

use of com.helger.pd.indexer.lucene.PDLucene in project phoss-directory by phax.

the class PDMetaManager method onAfterInstantiation.

@Override
protected void onAfterInstantiation(@Nonnull final IScope aScope) {
    try {
        m_aLucene = new PDLucene();
        m_aStorageMgr = new PDStorageManager(m_aLucene);
        m_aIndexerMgr = new PDIndexerManager(m_aStorageMgr);
        LOGGER.info(ClassHelper.getClassLocalName(this) + " was initialized");
    } catch (final Exception ex) {
        if (GlobalDebug.isProductionMode()) {
            new InternalErrorBuilder().setThrowable(ex).addErrorMessage(ClassHelper.getClassLocalName(this) + " init failed").handle();
        }
        throw new InitializationException("Failed to init " + ClassHelper.getClassLocalName(this), ex);
    }
}
Also used : PDLucene(com.helger.pd.indexer.lucene.PDLucene) InternalErrorBuilder(com.helger.photon.core.interror.InternalErrorBuilder) InitializationException(com.helger.commons.exception.InitializationException) PDStorageManager(com.helger.pd.indexer.storage.PDStorageManager) InitializationException(com.helger.commons.exception.InitializationException)

Example 2 with PDLucene

use of com.helger.pd.indexer.lucene.PDLucene in project phoss-directory by phax.

the class PDStorageManagerTest method testGetAllDocumentsOfCountryCode.

@Test
public void testGetAllDocumentsOfCountryCode() throws IOException {
    final IParticipantIdentifier aParticipantID = PDMetaManager.getIdentifierFactory().createParticipantIdentifier("myscheme-actorid-upis", "0088:test");
    assertNotNull(aParticipantID);
    try (final PDStorageManager aMgr = new PDStorageManager(new PDLucene())) {
        final PDStoredMetaData aMetaData = _createMockMetaData();
        aMgr.createOrUpdateEntry(aParticipantID, _createMockBI(aParticipantID), aMetaData);
        try {
            // No country - no docs
            ICommonsList<PDStoredBusinessEntity> aDocs = aMgr.getAllDocuments(new TermQuery(PDField.COUNTRY_CODE.getExactMatchTerm("")), -1);
            assertEquals(0, aDocs.size());
            // Search for NO
            aDocs = aMgr.getAllDocuments(new TermQuery(PDField.COUNTRY_CODE.getExactMatchTerm("NO")), -1);
            assertEquals(1, aDocs.size());
            final PDStoredBusinessEntity aSingleDoc = aDocs.get(0);
            assertEquals(aParticipantID, aSingleDoc.getParticipantID());
            assertEquals("junittest", aSingleDoc.getMetaData().getOwnerID());
            assertEquals("NO", aSingleDoc.getCountryCode());
        } finally {
            // Finally delete the entry again
            aMgr.deleteEntry(aParticipantID, aMetaData, true);
        }
    }
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) PDLucene(com.helger.pd.indexer.lucene.PDLucene) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Test(org.junit.Test)

Example 3 with PDLucene

use of com.helger.pd.indexer.lucene.PDLucene in project phoss-directory by phax.

the class PDStorageManagerTest method testGetAllDocumentsOfParticipant.

@Test
public void testGetAllDocumentsOfParticipant() throws IOException {
    final IParticipantIdentifier aParticipantID = PDMetaManager.getIdentifierFactory().createParticipantIdentifier("myscheme-actorid-upis", "0088:test");
    assertNotNull(aParticipantID);
    try (final PDStorageManager aMgr = new PDStorageManager(new PDLucene())) {
        final PDStoredMetaData aMetaData = _createMockMetaData();
        aMgr.createOrUpdateEntry(aParticipantID, _createMockBI(aParticipantID), aMetaData);
        try {
            final ICommonsList<PDStoredBusinessEntity> aDocs = aMgr.getAllDocumentsOfParticipant(aParticipantID);
            assertEquals(2, aDocs.size());
            // Test entity 1
            final PDStoredBusinessEntity aDoc1 = aDocs.get(0);
            assertEquals(aParticipantID, aDoc1.getParticipantID());
            assertEquals("junittest", aDoc1.getMetaData().getOwnerID());
            assertEquals("AT", aDoc1.getCountryCode());
            assertEquals(PDTFactory.createLocalDate(2015, Month.JULY, 6), aDoc1.getRegistrationDate());
            assertEquals(1, aDoc1.names().size());
            assertEquals("Philip's mock Peppol receiver", aDoc1.names().get(0).getName());
            assertNull(aDoc1.names().get(0).getLanguageCode());
            assertEquals("Vienna", aDoc1.getGeoInfo());
            assertEquals(10, aDoc1.identifiers().size());
            for (int i = 0; i < aDoc1.identifiers().size(); ++i) {
                assertEquals("scheme" + i, aDoc1.identifiers().get(i).getScheme());
                assertEquals("value" + i, aDoc1.identifiers().get(i).getValue());
            }
            assertEquals(1, aDoc1.websiteURIs().size());
            assertEquals("http://www.peppol.eu", aDoc1.websiteURIs().get(0));
            assertEquals(1, aDoc1.contacts().size());
            assertEquals("support", aDoc1.contacts().get(0).getType());
            assertEquals("BC name", aDoc1.contacts().get(0).getName());
            assertEquals("test@example.org", aDoc1.contacts().get(0).getEmail());
            assertEquals("12345", aDoc1.contacts().get(0).getPhone());
            assertEquals("This is a mock entry for testing purposes only", aDoc1.getAdditionalInformation());
            // Test entity 2
            final PDStoredBusinessEntity aDoc2 = aDocs.get(1);
            assertEquals(aParticipantID, aDoc2.getParticipantID());
            assertEquals("junittest", aDoc2.getMetaData().getOwnerID());
            assertEquals("NO", aDoc2.getCountryCode());
            assertNull(aDoc2.getRegistrationDate());
            assertEquals(3, aDoc2.names().size());
            assertEquals("Entity2a", aDoc2.names().get(0).getName());
            assertEquals("no", aDoc2.names().get(0).getLanguageCode());
            assertEquals("Entity2b", aDoc2.names().get(1).getName());
            assertEquals("de", aDoc2.names().get(1).getLanguageCode());
            assertEquals("Entity2c", aDoc2.names().get(2).getName());
            assertEquals("en", aDoc2.names().get(2).getLanguageCode());
            assertNull(aDoc2.getGeoInfo());
            assertEquals(0, aDoc2.identifiers().size());
            assertEquals(0, aDoc2.websiteURIs().size());
            assertEquals(0, aDoc2.contacts().size());
            assertEquals("Mock", aDoc2.getAdditionalInformation());
        } finally {
            // Finally delete the entry again
            aMgr.deleteEntry(aParticipantID, aMetaData, true);
        }
    }
}
Also used : PDLucene(com.helger.pd.indexer.lucene.PDLucene) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Test(org.junit.Test)

Example 4 with PDLucene

use of com.helger.pd.indexer.lucene.PDLucene in project phoss-directory by phax.

the class PageSecureAdminLuceneInformation method fillContent.

@Override
protected void fillContent(final WebPageExecutionContext aWPEC) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final PDLucene aLucene = PDMetaManager.getLucene();
    final BootstrapTable aTable = new BootstrapTable();
    aTable.addBodyRow().addCells("Lucene index directory", PDLucene.getLuceneIndexDir().getAbsolutePath());
    try {
        final DirectoryReader aReader = aLucene.getReader();
        if (aReader != null)
            aTable.addBodyRow().addCells("Directory information", aReader.toString());
    } catch (final IOException ex) {
        aTable.addBodyRow().addCell("Directory information").addCell(HCExtHelper.nl2divList(ex.getClass().getName() + "\n" + StackTraceHelper.getStackAsString(ex)));
    }
    aNodeList.addChild(aTable);
}
Also used : HCNodeList(com.helger.html.hc.impl.HCNodeList) PDLucene(com.helger.pd.indexer.lucene.PDLucene) BootstrapTable(com.helger.photon.bootstrap4.table.BootstrapTable) DirectoryReader(org.apache.lucene.index.DirectoryReader) IOException(java.io.IOException)

Aggregations

PDLucene (com.helger.pd.indexer.lucene.PDLucene)4 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)2 Test (org.junit.Test)2 InitializationException (com.helger.commons.exception.InitializationException)1 HCNodeList (com.helger.html.hc.impl.HCNodeList)1 PDStorageManager (com.helger.pd.indexer.storage.PDStorageManager)1 BootstrapTable (com.helger.photon.bootstrap4.table.BootstrapTable)1 InternalErrorBuilder (com.helger.photon.core.interror.InternalErrorBuilder)1 IOException (java.io.IOException)1 DirectoryReader (org.apache.lucene.index.DirectoryReader)1 TermQuery (org.apache.lucene.search.TermQuery)1