Example #1
0
 @Test
 public void testBasicExport() {
   final ExportRecord aRecordWithAllTypes =
       new ExportRecord()
           .addField("Hallo")
           .addField(PDTFactory.getCurrentLocalTime())
           .addField(PDTFactory.getCurrentLocalDate())
           .addField(PDTFactory.getCurrentLocalDateTime())
           .addField(PDTFactory.getCurrentDateTime())
           .addField(true)
           .addField(4711)
           .addField(-123456789012345L)
           .addField(new BigInteger("1234512345123451234512345123451234512345123451234512345"))
           .addField(3.1145)
           .addField(new BigDecimal("12345123451234512345123451234512345123451234512345.12345"));
   final ExportRecord aEmptyRecord = new ExportRecord();
   final ExporterCSV aExporter = new ExporterCSV(CCharset.CHARSET_ISO_8859_1_OBJ);
   // Fails because no record is present
   assertTrue(
       aExporter
           .exportRecords(new EmptyExportRecordProvider(), new NonBlockingByteArrayOutputStream())
           .isFailure());
   assertTrue(
       aExporter
           .exportRecords(
               new ConstantExportRecordProvider(CollectionHelper.newList(aRecordWithAllTypes)),
               new NonBlockingByteArrayOutputStream())
           .isSuccess());
   assertTrue(
       aExporter
           .exportRecords(
               new ConstantExportRecordProvider(
                   CollectionHelper.newList(
                       aRecordWithAllTypes, aRecordWithAllTypes, aEmptyRecord)),
               new NonBlockingByteArrayOutputStream())
           .isSuccess());
   assertTrue(
       aExporter
           .exportRecords(
               new ConstantExportRecordProvider(
                   null,
                   CollectionHelper.newList(
                       aRecordWithAllTypes, aRecordWithAllTypes, aEmptyRecord),
                   aRecordWithAllTypes),
               new NonBlockingByteArrayOutputStream())
           .isSuccess());
   assertTrue(
       aExporter
           .exportRecords(
               new ConstantExportRecordProvider(
                   aRecordWithAllTypes,
                   CollectionHelper.newList(
                       aRecordWithAllTypes, aRecordWithAllTypes, aEmptyRecord),
                   aRecordWithAllTypes),
               new NonBlockingByteArrayOutputStream())
           .isSuccess());
 }
Example #2
0
 protected final void logClassPath() {
   // List class path elements in trace mode
   if (GlobalDebug.isDebugMode()) {
     final List<String> aCP = ClassPathHelper.getAllClassPathEntries();
     s_aLogger.info("Class path [" + aCP.size() + " elements]:");
     for (final String sCP : CollectionHelper.getSortedInline(aCP)) s_aLogger.info("  " + sCP);
   }
 }
 @Test
 public void testListAllSerbianCountries() {
   for (final Locale aLocale :
       CollectionHelper.getSorted(Locale.getAvailableLocales(), new ComparatorLocale()))
     if (aLocale.getLanguage().equals("sr")
         || aLocale.getLanguage().equals("sh")
         || aLocale.getLanguage().equals("bs"))
       s_aLogger.info(aLocale.toString() + ": " + aLocale.getDisplayName());
 }
 @Nonnull
 @ReturnsMutableCopy
 public Collection<FormState> getAllFormStates() {
   m_aRWLock.readLock().lock();
   try {
     return CollectionHelper.newList(m_aMap.values());
   } finally {
     m_aRWLock.readLock().unlock();
   }
 }
 /** @return A non-<code>null</code> but maybe empty set with all currently logged in user IDs. */
 @Nonnull
 @ReturnsMutableCopy
 public Set<String> getAllLoggedInUserIDs() {
   m_aRWLock.readLock().lock();
   try {
     return CollectionHelper.newSet(m_aLoggedInUsers.keySet());
   } finally {
     m_aRWLock.readLock().unlock();
   }
 }
 /**
  * @return A non-<code>null</code> but maybe empty collection with the details of all currently
  *     logged in users.
  */
 @Nonnull
 @ReturnsMutableCopy
 public Collection<LoginInfo> getAllLoginInfos() {
   m_aRWLock.readLock().lock();
   try {
     return CollectionHelper.newList(m_aLoggedInUsers.values());
   } finally {
     m_aRWLock.readLock().unlock();
   }
 }
 public void clearCertificates() throws OpenAS2Exception {
   final KeyStore aKeyStore = getKeyStore();
   try {
     // Make a copy to be sure
     for (final String sAlias : CollectionHelper.newList(aKeyStore.aliases()))
       aKeyStore.deleteEntry(sAlias);
     save(getFilename(), getPassword());
   } catch (final GeneralSecurityException ex) {
     throw WrappedOpenAS2Exception.wrap(ex);
   }
 }
Example #8
0
 Favorite(
     @Nonnull @Nonempty final String sID,
     @Nonnull @Nonempty final String sUserID,
     @Nonnull @Nonempty final String sApplicationID,
     @Nonnull @Nonempty final String sMenuItemID,
     @Nonnull @Nonempty final String sDisplayName,
     @Nullable final Map<String, String> aAdditionalParams) {
   m_sID = ValueEnforcer.notEmpty(sID, "ID");
   m_sUserID = ValueEnforcer.notEmpty(sUserID, "User ID");
   m_sMenuItemID = ValueEnforcer.notEmpty(sMenuItemID, "menu item ID");
   m_sApplicationID = ValueEnforcer.notEmpty(sApplicationID, "application ID");
   setDisplayName(sDisplayName);
   m_aAdditionalParams = CollectionHelper.newMap(aAdditionalParams);
 }
 @Test
 public void testListAllCountries() {
   for (final Locale aLocale :
       CollectionHelper.getSorted(
           Locale.getAvailableLocales(), new CollatingComparatorLocaleCountry(Locale.US)))
     if (aLocale.getCountry().length() > 0)
       s_aLogger.info(
           aLocale.getCountry()
               + " "
               + aLocale.getDisplayCountry()
               + " ("
               + aLocale.toString()
               + ")");
 }
/**
 * This is the reader and writer for {@link BusinessInformationType} documents. This class may be
 * derived to override protected methods from {@link AbstractJAXBMarshaller}.
 *
 * @author Philip Helger
 */
public class PDBusinessInformationMarshaller
    extends AbstractJAXBMarshaller<BusinessInformationType> {
  /** XSD resources */
  public static final List<? extends IReadableResource> BUSINESS_CARD_XSDS =
      CollectionHelper.newUnmodifiableList(
          new ClassPathResource("/schemas/pd-business-information-201511.xsd"));

  /** Constructor */
  public PDBusinessInformationMarshaller() {
    super(BusinessInformationType.class, BUSINESS_CARD_XSDS);
  }

  @Override
  @Nonnull
  protected final JAXBElement<BusinessInformationType> wrapObject(
      final BusinessInformationType aCodeListDocument) {
    return new ObjectFactory().createBusinessInformation(aCodeListDocument);
  }
}
Example #11
0
 protected final void logThirdpartyModules() {
   // List all third party modules for later evaluation
   final Set<IThirdPartyModule> aModules =
       ThirdPartyModuleRegistry.getInstance().getAllRegisteredThirdPartyModules();
   if (!aModules.isEmpty()) {
     s_aLogger.info("Using the following third party modules:");
     for (final IThirdPartyModule aModule :
         CollectionHelper.getSorted(
             aModules,
             new CollatingComparatorHasDisplayName<IHasDisplayName>(
                 SystemHelper.getSystemLocale())))
       if (!aModule.isOptional()) {
         String sMsg = "  " + aModule.getDisplayName();
         if (aModule.getVersion() != null) sMsg += ' ' + aModule.getVersion().getAsString(true);
         sMsg += " licensed under " + aModule.getLicense().getDisplayName();
         if (aModule.getLicense().getVersion() != null)
           sMsg += ' ' + aModule.getLicense().getVersion().getAsString();
         s_aLogger.info(sMsg);
       }
   }
 }
Example #12
0
 @Nonnull
 @ReturnsMutableCopy
 public Map<String, String> getAdditionalParams() {
   return CollectionHelper.newMap(m_aAdditionalParams);
 }
Example #13
0
 @Nonnull
 @ReturnsMutableCopy
 public List<CSSValue> getAllContainedValues() {
   return CollectionHelper.newList(m_aValues);
 }
  @Override
  protected void fillContent(final WebPageExecutionContext aWPEC) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final IIdentifierFactory aIdentifierFactory = PDMetaManager.getIdentifierFactory();

    {
      final BootstrapRow aHeaderRow = aNodeList.addAndReturnChild(new BootstrapRow());
      // The logo
      aHeaderRow.createColumn(12, 12, 1, 2).addClass(CBootstrapCSS.HIDDEN_SM);
      aHeaderRow
          .createColumn(12, 6, 5, 4)
          .addChild(
              new HCExtImg(new SimpleURL("/imgs/pd-logo.png")).addClass(CBootstrapCSS.PULL_LEFT));
      aHeaderRow
          .createColumn(12, 6, 5, 4)
          .addChild(
              new HCExtImg(new SimpleURL("/imgs/peppol.png")).addClass(CBootstrapCSS.PULL_RIGHT));
      aHeaderRow.createColumn(12, 12, 1, 2).addClass(CBootstrapCSS.HIDDEN_SM);
    }

    final String sQuery = aWPEC.getAttributeAsString(FIELD_QUERY);
    final String sParticipantID = aWPEC.getAttributeAsString(FIELD_PARTICIPANT_ID);
    boolean bShowQuery = true;

    if (aWPEC.hasAction(CPageParam.ACTION_VIEW) && StringHelper.hasText(sParticipantID)) {
      final IParticipantIdentifier aParticipantID =
          aIdentifierFactory.parseParticipantIdentifier(sParticipantID);
      if (aParticipantID != null) {
        // Show small query box
        aNodeList.addChild(_createSmallQueryBox(aWPEC));

        // Search document matching participant ID
        final ICommonsList<PDStoredDocument> aResultDocs =
            PDMetaManager.getStorageMgr().getAllDocumentsOfParticipant(aParticipantID);
        // Group by participant ID
        final IMultiMapListBased<IParticipantIdentifier, PDStoredDocument> aGroupedDocs =
            PDStorageManager.getGroupedByParticipantID(aResultDocs);
        if (aGroupedDocs.isEmpty())
          s_aLogger.warn(
              "No stored document matches participant identifier '" + sParticipantID + "'");
        else {
          if (aGroupedDocs.size() > 1)
            s_aLogger.warn(
                "Found "
                    + aGroupedDocs.size()
                    + " entries for participant identifier '"
                    + sParticipantID
                    + "' - weird");
          // Get the first one
          final List<PDStoredDocument> aDocuments =
              CollectionHelper.getFirstElement(aGroupedDocs.values());
          bShowQuery = false;

          aNodeList.addChild(getUIHandler().createPageHeader("Details for " + sParticipantID));

          final BootstrapTabBox aTabBox = aNodeList.addAndReturnChild(new BootstrapTabBox());

          // Business information
          {
            final HCNodeList aOL = new HCNodeList();
            int nIndex = 1;
            for (final PDStoredDocument aStoredDoc : aDocuments) {
              final BootstrapPanel aPanel = aOL.addAndReturnChild(new BootstrapPanel());
              if (aDocuments.size() > 1)
                aPanel.getOrCreateHeader().addChild("Business information entity " + nIndex);
              aPanel
                  .getBody()
                  .addChild(PDCommonUI.showBusinessInfoDetails(aStoredDoc, aDisplayLocale));
              ++nIndex;
            }
            // Add whole list or just the first item?
            final IHCNode aTabLabel =
                new HCSpan()
                    .addChild("Business information ")
                    .addChild(new BootstrapBadge().addChild(Integer.toString(aDocuments.size())));
            aTabBox.addTab("businessinfo", aTabLabel, aOL, true);
          }

          // Document types
          {
            final HCOL aDocTypeCtrl = new HCOL();
            final List<IDocumentTypeIdentifier> aDocTypeIDs =
                CollectionHelper.getSorted(
                    aResultDocs.get(0).getAllDocumentTypeIDs(),
                    IDocumentTypeIdentifier.comparator());
            for (final IDocumentTypeIdentifier aDocTypeID : aDocTypeIDs) {
              final IHCLI<?> aLI = aDocTypeCtrl.addItem();
              aLI.addChild(PDCommonUI.getDocumentTypeID(aDocTypeID));
              try {
                final IPeppolDocumentTypeIdentifierParts aParts =
                    PeppolIdentifierHelper.getDocumentTypeIdentifierParts(aDocTypeID);
                aLI.addChild(PDCommonUI.getDocumentTypeIDDetails(aParts));
              } catch (final IllegalArgumentException ex) {
                // Happens for non-PEPPOL identifiers
              }
            }
            aTabBox.addTab(
                "doctypes",
                new HCSpan()
                    .addChild("Document types ")
                    .addChild(new BootstrapBadge().addChild(Integer.toString(aDocTypeIDs.size()))),
                aDocTypeCtrl.hasChildren()
                    ? aDocTypeCtrl
                    : new BootstrapWarnBox()
                        .addChild("No document types available for this participant"),
                false);
          }
        }
      } else s_aLogger.warn("Failed to parse participant identifier '" + sParticipantID + "'");
    }

    if (bShowQuery) {
      if (StringHelper.hasText(sQuery)) {
        // Show small query box
        aNodeList.addChild(_createSmallQueryBox(aWPEC));

        s_aLogger.info("Searching for '" + sQuery + "'");

        // Build Lucene query
        final Query aLuceneQuery =
            PDQueryManager.convertQueryStringToLuceneQuery(PDMetaManager.getLucene(), sQuery);

        if (s_aLogger.isDebugEnabled())
          s_aLogger.debug("Created query for '" + sQuery + "' is <" + aLuceneQuery + ">");

        // Search all documents
        final ICommonsList<PDStoredDocument> aResultDocs =
            PDMetaManager.getStorageMgr().getAllDocuments(aLuceneQuery);

        s_aLogger.info(
            "  Result for <" + aLuceneQuery + "> are " + aResultDocs.size() + " documents");

        // Group by participant ID
        final IMultiMapListBased<IParticipantIdentifier, PDStoredDocument> aGroupedDocs =
            PDStorageManager.getGroupedByParticipantID(aResultDocs);

        final int nMaxResults = 10;

        // Display results
        if (aGroupedDocs.isEmpty()) {
          aNodeList.addChild(
              new BootstrapInfoBox()
                  .addChild("No search results found for query '" + sQuery + "'"));
        } else {
          final HCOL aOL = new HCOL().setStart(1);
          for (final Map.Entry<IParticipantIdentifier, ICommonsList<PDStoredDocument>> aEntry :
              aGroupedDocs.entrySet()) {
            final IParticipantIdentifier aDocParticipantID = aEntry.getKey();
            final ICommonsList<PDStoredDocument> aDocs = aEntry.getValue();

            // Start result document
            final HCDiv aResultItem = new HCDiv().addClass(CSS_CLASS_RESULT_DOC);
            final HCDiv aHeadRow = aResultItem.addAndReturnChild(new HCDiv());
            aHeadRow.addChild(aDocParticipantID.getURIEncoded());
            if (aDocs.size() > 1) aHeadRow.addChild(" (" + aDocs.size() + " entities)");
            aHeadRow
                .addChild(" ")
                .addChild(
                    new BootstrapButton(EBootstrapButtonType.SUCCESS, EBootstrapButtonSize.MINI)
                        .addChild("Show details")
                        .setIcon(EDefaultIcon.MAGNIFIER)
                        .setOnClick(
                            aWPEC
                                .getSelfHref()
                                .add(FIELD_QUERY, sQuery)
                                .add(CPageParam.PARAM_ACTION, CPageParam.ACTION_VIEW)
                                .add(FIELD_PARTICIPANT_ID, aDocParticipantID.getURIEncoded())));

            // Show all entities of the stored document
            final HCUL aUL = aResultItem.addAndReturnChild(new HCUL());
            for (final PDStoredDocument aStoredDoc : aEntry.getValue()) {
              final IHCLI<?> aLI =
                  aUL.addAndReturnItem(new HCLI().addClass(CSS_CLASS_RESULT_DOC_HEADER));
              final HCDiv aDocHeadRow = new HCDiv();
              if (aStoredDoc.hasCountryCode()) {
                // Add country flag (if available)
                aDocHeadRow.addChild(PDCommonUI.getFlagNode(aStoredDoc.getCountryCode()));
                aDocHeadRow.addChild(
                    new HCSpan()
                        .addChild(aStoredDoc.getCountryCode())
                        .addClass(CSS_CLASS_RESULT_DOC_COUNTRY_CODE));
              }
              if (aStoredDoc.hasName())
                aDocHeadRow.addChild(
                    new HCSpan()
                        .addChild(aStoredDoc.getName())
                        .addClass(CSS_CLASS_RESULT_DOC_NAME));
              if (aDocHeadRow.hasChildren()) aLI.addChild(aDocHeadRow);

              if (aStoredDoc.hasGeoInfo())
                aLI.addChild(
                    new HCDiv()
                        .addChildren(HCExtHelper.nl2divList(aStoredDoc.getGeoInfo()))
                        .addClass(CSS_CLASS_RESULT_DOC_GEOINFO));
              if (aStoredDoc.hasAdditionalInformation())
                aLI.addChild(
                    new HCDiv()
                        .addChildren(HCExtHelper.nl2divList(aStoredDoc.getAdditionalInformation()))
                        .addClass(CSS_CLASS_RESULT_DOC_FREETEXT));
            }

            aOL.addItem(aResultItem);

            // Break at 10 results
            if (aOL.getChildCount() >= nMaxResults) break;
          }
          aNodeList.addChild(aOL);
        }
      } else {
        // Show big query box
        final HCForm aBigQueryBox =
            new HCForm().setAction(aWPEC.getSelfHref()).setMethod(EHCFormMethod.GET);
        aBigQueryBox.addChild(
            new HCDiv().addClass(CSS_CLASS_BIG_QUERY_BOX).addChild(_createQueryEdit()));
        aBigQueryBox.addChild(
            new HCDiv()
                .addClass(CSS_CLASS_BIG_QUERY_BUTTONS)
                .addChild(
                    new BootstrapSubmitButton()
                        .addChild("Search PEPPOL Directory")
                        .setIcon(EDefaultIcon.MAGNIFIER)));

        final BootstrapRow aBodyRow = aNodeList.addAndReturnChild(new BootstrapRow());
        aBodyRow.createColumn(12, 1, 2, 3).addClass(CBootstrapCSS.HIDDEN_XS);
        aBodyRow.createColumn(12, 10, 8, 6).addChild(aBigQueryBox);
        aBodyRow.createColumn(12, 1, 2, 3).addClass(CBootstrapCSS.HIDDEN_XS);
      }
    }
  }
 @Nonnull
 @ReturnsMutableCopy
 public Collection<VALUETYPE> getAllAttributeValues() {
   return CollectionHelper.newList(m_aAttrs.values());
 }
 @Nonnull
 @ReturnsMutableCopy
 public Set<KEYTYPE> getAllAttributeNames() {
   return CollectionHelper.newSet(m_aAttrs.keySet());
 }
 @Nonnull
 @ReturnsMutableCopy
 public Map<KEYTYPE, VALUETYPE> getAllAttributes() {
   return CollectionHelper.newMap(m_aAttrs);
 }