Search in sources :

Example 1 with CSVWriter

use of com.helger.commons.csv.CSVWriter in project phoss-directory by phax.

the class ExportAllManager method writeFileParticipantCSV.

@Nonnull
static ESuccess writeFileParticipantCSV(@Nonnull final EQueryMode eQueryMode) {
    final File f = _getInternalFileParticipantCSV();
    // Do it in a write lock!
    RW_LOCK.writeLock().lock();
    try (final CSVWriter aCSVWriter = new CSVWriter(FileHelper.getBufferedWriter(f, StandardCharsets.ISO_8859_1))) {
        queryAllContainedParticipantsAsCSV(eQueryMode, aCSVWriter);
        LOGGER.info("Successfully wrote all Participants as CSV to " + f.getAbsolutePath());
    } catch (final IOException ex) {
        LOGGER.error("Failed to export all Participants as CSV to " + f.getAbsolutePath(), ex);
    } finally {
        RW_LOCK.writeLock().unlock();
    }
    return ESuccess.SUCCESS;
}
Also used : CSVWriter(com.helger.commons.csv.CSVWriter) IOException(java.io.IOException) File(java.io.File) Nonnull(javax.annotation.Nonnull)

Example 2 with CSVWriter

use of com.helger.commons.csv.CSVWriter in project phoss-directory by phax.

the class ExportAllManager method queryAllContainedBusinessCardsAsCSV.

public static void queryAllContainedBusinessCardsAsCSV(@Nonnull final EQueryMode eQueryMode, @Nonnull @WillNotClose final CSVWriter aCSVWriter) throws IOException {
    _unify(aCSVWriter);
    final Query aQuery = eQueryMode.getEffectiveQuery(new MatchAllDocsQuery());
    aCSVWriter.writeNext("Participant ID", "Names (per-row)", "Country code", "Geo info", "Identifier schemes", "Identifier values", "Websites", "Contact type", "Contact name", "Contact phone", "Contact email", "Additional info", "Registration date", "Document types");
    final Consumer<? super PDStoredBusinessEntity> aConsumer = aEntity -> {
        aCSVWriter.writeNext(aEntity.getParticipantID().getURIEncoded(), StringHelper.getImplodedMapped("\n", aEntity.names(), PDStoredMLName::getNameAndLanguageCode), aEntity.getCountryCode(), aEntity.getGeoInfo(), StringHelper.getImplodedMapped("\n", aEntity.identifiers(), PDStoredIdentifier::getScheme), StringHelper.getImplodedMapped("\n", aEntity.identifiers(), PDStoredIdentifier::getValue), StringHelper.getImploded("\n", aEntity.websiteURIs()), StringHelper.getImplodedMapped("\n", aEntity.contacts(), PDStoredContact::getType), StringHelper.getImplodedMapped("\n", aEntity.contacts(), PDStoredContact::getName), StringHelper.getImplodedMapped("\n", aEntity.contacts(), PDStoredContact::getPhone), StringHelper.getImplodedMapped("\n", aEntity.contacts(), PDStoredContact::getEmail), aEntity.getAdditionalInformation(), aEntity.getRegistrationDate() == null ? "" : aEntity.getRegistrationDate().toString(), StringHelper.getImplodedMapped("\n", aEntity.documentTypeIDs(), IDocumentTypeIdentifier::getURIEncoded));
    };
    PDMetaManager.getStorageMgr().searchAllDocuments(aQuery, -1, aConsumer);
    aCSVWriter.flush();
}
Also used : Query(org.apache.lucene.search.Query) EExcelVersion(com.helger.poi.excel.EExcelVersion) CommonsTreeSet(com.helger.commons.collection.impl.CommonsTreeSet) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) PDMetaManager(com.helger.pd.indexer.mgr.PDMetaManager) LoggerFactory(org.slf4j.LoggerFactory) IMicroDocument(com.helger.xml.microdom.IMicroDocument) PDTFactory(com.helger.commons.datetime.PDTFactory) IMicroElement(com.helger.xml.microdom.IMicroElement) PDStoredBusinessEntity(com.helger.pd.indexer.storage.PDStoredBusinessEntity) PDField(com.helger.pd.indexer.storage.field.PDField) ThreadSafe(javax.annotation.concurrent.ThreadSafe) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) ICommonsOrderedMap(com.helger.commons.collection.impl.ICommonsOrderedMap) StandardCharsets(java.nio.charset.StandardCharsets) JsonObject(com.helger.json.JsonObject) WorkbookCreationHelper(com.helger.poi.excel.WorkbookCreationHelper) ICommonsList(com.helger.commons.collection.impl.ICommonsList) IJsonArray(com.helger.json.IJsonArray) UnifiedResponse(com.helger.servlet.response.UnifiedResponse) CSVWriter(com.helger.commons.csv.CSVWriter) PDStoredContact(com.helger.pd.indexer.storage.PDStoredContact) Writer(java.io.Writer) WebFileIO(com.helger.photon.app.io.WebFileIO) ESuccess(com.helger.commons.state.ESuccess) FileSystemResource(com.helger.commons.io.resource.FileSystemResource) IJsonObject(com.helger.json.IJsonObject) MicroDocument(com.helger.xml.microdom.MicroDocument) CHttpHeader(com.helger.commons.http.CHttpHeader) JsonArray(com.helger.json.JsonArray) FileHelper(com.helger.commons.io.file.FileHelper) PDStoredIdentifier(com.helger.pd.indexer.storage.PDStoredIdentifier) ICommonsSortedSet(com.helger.commons.collection.impl.ICommonsSortedSet) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nonnull(javax.annotation.Nonnull) WillNotClose(javax.annotation.WillNotClose) Logger(org.slf4j.Logger) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) StringHelper(com.helger.commons.string.StringHelper) PDTWebDateHelper(com.helger.commons.datetime.PDTWebDateHelper) IOException(java.io.IOException) File(java.io.File) JsonWriter(com.helger.json.serialize.JsonWriter) SimpleReadWriteLock(com.helger.commons.concurrent.SimpleReadWriteLock) MicroWriter(com.helger.xml.microdom.serialize.MicroWriter) Consumer(java.util.function.Consumer) PDStoredMLName(com.helger.pd.indexer.storage.PDStoredMLName) EQueryMode(com.helger.pd.indexer.storage.EQueryMode) CommonsLinkedHashMap(com.helger.commons.collection.impl.CommonsLinkedHashMap) ExcelStyle(com.helger.poi.excel.style.ExcelStyle) Comparator(java.util.Comparator) Query(org.apache.lucene.search.Query) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) PDStoredIdentifier(com.helger.pd.indexer.storage.PDStoredIdentifier) PDStoredMLName(com.helger.pd.indexer.storage.PDStoredMLName) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) PDStoredContact(com.helger.pd.indexer.storage.PDStoredContact)

Example 3 with CSVWriter

use of com.helger.commons.csv.CSVWriter in project phoss-directory by phax.

the class ExportAllManager method queryAllContainedParticipantsAsCSV.

public static void queryAllContainedParticipantsAsCSV(@Nonnull final EQueryMode eQueryMode, @Nonnull @WillNotClose final CSVWriter aCSVWriter) throws IOException {
    _unify(aCSVWriter);
    final Query aQuery = eQueryMode.getEffectiveQuery(new MatchAllDocsQuery());
    aCSVWriter.writeNext("Participant ID");
    final Consumer<? super IParticipantIdentifier> aConsumer = aEntity -> {
        aCSVWriter.writeNext(aEntity.getURIEncoded());
    };
    PDMetaManager.getStorageMgr().searchAll(aQuery, -1, PDField.PARTICIPANT_ID::getDocValue, aConsumer);
    aCSVWriter.flush();
}
Also used : Query(org.apache.lucene.search.Query) EExcelVersion(com.helger.poi.excel.EExcelVersion) CommonsTreeSet(com.helger.commons.collection.impl.CommonsTreeSet) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) PDMetaManager(com.helger.pd.indexer.mgr.PDMetaManager) LoggerFactory(org.slf4j.LoggerFactory) IMicroDocument(com.helger.xml.microdom.IMicroDocument) PDTFactory(com.helger.commons.datetime.PDTFactory) IMicroElement(com.helger.xml.microdom.IMicroElement) PDStoredBusinessEntity(com.helger.pd.indexer.storage.PDStoredBusinessEntity) PDField(com.helger.pd.indexer.storage.field.PDField) ThreadSafe(javax.annotation.concurrent.ThreadSafe) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) ICommonsOrderedMap(com.helger.commons.collection.impl.ICommonsOrderedMap) StandardCharsets(java.nio.charset.StandardCharsets) JsonObject(com.helger.json.JsonObject) WorkbookCreationHelper(com.helger.poi.excel.WorkbookCreationHelper) ICommonsList(com.helger.commons.collection.impl.ICommonsList) IJsonArray(com.helger.json.IJsonArray) UnifiedResponse(com.helger.servlet.response.UnifiedResponse) CSVWriter(com.helger.commons.csv.CSVWriter) PDStoredContact(com.helger.pd.indexer.storage.PDStoredContact) Writer(java.io.Writer) WebFileIO(com.helger.photon.app.io.WebFileIO) ESuccess(com.helger.commons.state.ESuccess) FileSystemResource(com.helger.commons.io.resource.FileSystemResource) IJsonObject(com.helger.json.IJsonObject) MicroDocument(com.helger.xml.microdom.MicroDocument) CHttpHeader(com.helger.commons.http.CHttpHeader) JsonArray(com.helger.json.JsonArray) FileHelper(com.helger.commons.io.file.FileHelper) PDStoredIdentifier(com.helger.pd.indexer.storage.PDStoredIdentifier) ICommonsSortedSet(com.helger.commons.collection.impl.ICommonsSortedSet) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nonnull(javax.annotation.Nonnull) WillNotClose(javax.annotation.WillNotClose) Logger(org.slf4j.Logger) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) StringHelper(com.helger.commons.string.StringHelper) PDTWebDateHelper(com.helger.commons.datetime.PDTWebDateHelper) IOException(java.io.IOException) File(java.io.File) JsonWriter(com.helger.json.serialize.JsonWriter) SimpleReadWriteLock(com.helger.commons.concurrent.SimpleReadWriteLock) MicroWriter(com.helger.xml.microdom.serialize.MicroWriter) Consumer(java.util.function.Consumer) PDStoredMLName(com.helger.pd.indexer.storage.PDStoredMLName) EQueryMode(com.helger.pd.indexer.storage.EQueryMode) CommonsLinkedHashMap(com.helger.commons.collection.impl.CommonsLinkedHashMap) ExcelStyle(com.helger.poi.excel.style.ExcelStyle) Comparator(java.util.Comparator) Query(org.apache.lucene.search.Query) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery)

Example 4 with CSVWriter

use of com.helger.commons.csv.CSVWriter in project phoss-directory by phax.

the class ExportAllManager method writeFileBusinessCardCSV.

@Nonnull
static ESuccess writeFileBusinessCardCSV(@Nonnull final EQueryMode eQueryMode) {
    final File f = _getInternalFileBusinessCardCSV();
    // Do it in a write lock!
    RW_LOCK.writeLock().lock();
    try (final CSVWriter aCSVWriter = new CSVWriter(FileHelper.getBufferedWriter(f, StandardCharsets.ISO_8859_1))) {
        queryAllContainedBusinessCardsAsCSV(eQueryMode, aCSVWriter);
        LOGGER.info("Successfully exported all BCs as CSV to " + f.getAbsolutePath());
    } catch (final IOException ex) {
        LOGGER.error("Failed to export all BCs as CSV to " + f.getAbsolutePath(), ex);
    } finally {
        RW_LOCK.writeLock().unlock();
    }
    return ESuccess.SUCCESS;
}
Also used : CSVWriter(com.helger.commons.csv.CSVWriter) IOException(java.io.IOException) File(java.io.File) Nonnull(javax.annotation.Nonnull)

Example 5 with CSVWriter

use of com.helger.commons.csv.CSVWriter in project peppol-commons by phax.

the class PeppolDocumentTypeIdentifierPartsTest method testList.

@Test
public void testList() throws IOException {
    try (final CSVWriter aCSV = new CSVWriter(FileHelper.getBufferedWriter(new File("target/doctypes.csv"), StandardCharsets.ISO_8859_1))) {
        aCSV.setSeparatorChar(';');
        aCSV.writeNext("Status", "Namespace URI", "Local name", "Customization ID", "Version");
        SimpleFileIO.readFileLines(new File("src/test/resources/doctypes.txt"), StandardCharsets.UTF_8, sDocTypeID -> {
            final ICommonsList<String> aResult = new CommonsArrayList<>();
            try {
                final IPeppolDocumentTypeIdentifierParts aParts = PeppolDocumentTypeIdentifierParts.extractFromString(sDocTypeID);
                assertNotNull(aParts);
                aResult.add("OK");
                aResult.add(aParts.getRootNS());
                aResult.add(aParts.getLocalName());
                aResult.add(aParts.getCustomizationID());
                aResult.add(aParts.getVersion());
            } catch (final IllegalArgumentException ex) {
                aResult.add("Error");
                aResult.add(ex.getMessage());
                aResult.add(sDocTypeID);
            }
            aCSV.writeNext(aResult);
        });
    }
}
Also used : CSVWriter(com.helger.commons.csv.CSVWriter) File(java.io.File) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) Test(org.junit.Test)

Aggregations

CSVWriter (com.helger.commons.csv.CSVWriter)5 File (java.io.File)5 IOException (java.io.IOException)4 Nonnull (javax.annotation.Nonnull)4 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)3 CommonsLinkedHashMap (com.helger.commons.collection.impl.CommonsLinkedHashMap)2 CommonsTreeSet (com.helger.commons.collection.impl.CommonsTreeSet)2 ICommonsList (com.helger.commons.collection.impl.ICommonsList)2 ICommonsOrderedMap (com.helger.commons.collection.impl.ICommonsOrderedMap)2 ICommonsSortedSet (com.helger.commons.collection.impl.ICommonsSortedSet)2 SimpleReadWriteLock (com.helger.commons.concurrent.SimpleReadWriteLock)2 PDTFactory (com.helger.commons.datetime.PDTFactory)2 PDTWebDateHelper (com.helger.commons.datetime.PDTWebDateHelper)2 CHttpHeader (com.helger.commons.http.CHttpHeader)2 FileHelper (com.helger.commons.io.file.FileHelper)2 FileSystemResource (com.helger.commons.io.resource.FileSystemResource)2 ESuccess (com.helger.commons.state.ESuccess)2 StringHelper (com.helger.commons.string.StringHelper)2 IJsonArray (com.helger.json.IJsonArray)2 IJsonObject (com.helger.json.IJsonObject)2