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;
}
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();
}
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();
}
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;
}
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);
});
}
}
Aggregations