use of com.helger.commons.collection.impl.CommonsHashSet in project phive by phax.
the class VOM1Validator method validateOptions.
public static void validateOptions(@Nonnull final String sXPath, @Nonnull final String sLocalXPath, @Nullable final List<VOMOptionType> aOptions, @Nonnull final ErrorList aErrorList) {
if (aOptions != null) {
int nIndex = 1;
final ICommonsSet<String> aNames = new CommonsHashSet<>();
for (final VOMOptionType aOption : aOptions) {
// Name must be neither null nor empty
final String sName = aOption.getName();
if (StringHelper.hasNoText(sName))
aErrorList.add(_createError(EVOMErrorCode.REQUIRED_NOT_EMPTY, sXPath + sLocalXPath + '[' + nIndex + "]/name"));
else if (!aNames.add(sName))
aErrorList.add(_createError(EVOMErrorCode.OPTION_NAME_NOT_UNIQUE.getErrorMessage(sName, sXPath), sXPath + '[' + nIndex + "]/name"));
// Value may be empty
final String sValue = aOption.getValue();
if (sValue == null)
aErrorList.add(_createError(EVOMErrorCode.REQUIRED, sXPath + sLocalXPath + '[' + nIndex + "]/value"));
nIndex++;
}
}
}
use of com.helger.commons.collection.impl.CommonsHashSet in project phive by phax.
the class VOM1Validator method validateSchematron.
public static void validateSchematron(@Nonnull final String sXPath, @Nullable final VOMSchematronType aSchematron, @Nonnull final IVOMNamespaceContextResolver aNamespaceContextResolver, @Nonnull final IVOMResourceResolver aResourceResolver, @Nonnull final ErrorList aErrorList) {
if (aSchematron == null) {
aErrorList.add(_createError(EVOMErrorCode.REQUIRED, sXPath));
} else {
final String sBuiltIn = aSchematron.getBuiltIn();
if (sBuiltIn != null) {
final IReadableResource aRes = aResourceResolver.getResourceOfID(sBuiltIn);
if (aRes == null)
aErrorList.add(_createError(EVOMErrorCode.BUILTIN_RESOURCE_NOT_FOUND.getErrorMessage(sBuiltIn), sXPath + "/builtin"));
} else {
// Resource
validateCoordinates(sXPath + "/resource", aSchematron.getResource(), aErrorList);
}
// TODO prerequisite
validateNamespaces(sXPath + "/namespaces", aSchematron.getNamespaces(), aNamespaceContextResolver, aErrorList);
// Custom errors
if (aSchematron.hasCustomErrorEntries()) {
int nIndex = 1;
int nErrors = 0;
final ICommonsSet<String> aIDs = new CommonsHashSet<>();
for (final VOMCustomError aCustomError : aSchematron.getCustomError()) {
final String sLocalXPath = sXPath + "/customError[" + nIndex + ']';
final String sID = aCustomError.getId();
if (StringHelper.hasNoText(sID)) {
aErrorList.add(_createError(EVOMErrorCode.REQUIRED_NOT_EMPTY, sLocalXPath + "/id"));
++nErrors;
} else {
if (aIDs.contains(sID))
aErrorList.add(_createWarn(EVOMErrorCode.CUSTOM_ERROR_ALREADY_MAPPED.getErrorMessage(sID), sLocalXPath + "/id"));
aIDs.add(sID);
}
++nIndex;
}
if (aIDs.isEmpty() && nErrors == 0)
aErrorList.add(_createWarn(EVOMErrorCode.CUSTOM_ERRORS_EMPTY, sXPath));
}
validateOptions(sXPath, "/option", aSchematron.getOption(), aErrorList);
}
}
use of com.helger.commons.collection.impl.CommonsHashSet in project ph-masterdata by phax.
the class ECurrencyTest method testGetMissingCurrencies.
@Test
@Ignore
public void testGetMissingCurrencies() {
final ICommonsMap<Locale, Currency> aMap = CurrencyHelper.getLocaleToCurrencyMap();
final ICommonsMap<Currency, ICommonsSet<Locale>> aAllOfCurrency = new CommonsHashMap<>();
for (final Map.Entry<Locale, Currency> aEntry : aMap.entrySet()) {
if (ECurrency.findFirst(ECurrency.filterContainsLocale(aEntry.getKey())) == null) {
aAllOfCurrency.computeIfAbsent(aEntry.getValue(), k -> new CommonsHashSet<>()).add(aEntry.getKey());
}
}
final StringBuilder aSB = new StringBuilder();
for (final Map.Entry<Currency, ICommonsSet<Locale>> a : aAllOfCurrency.getSortedByKey(Comparator.comparing(Currency::getCurrencyCode)).entrySet()) {
final StringBuilder aLocale = new StringBuilder();
for (final Locale aLoc : a.getValue().getSorted(Comparator.comparing(Locale::toString))) {
if (aLocale.length() > 0)
aLocale.append(',');
aLocale.append('"').append(aLoc.toString()).append('"');
}
final String sID = a.getKey().getCurrencyCode();
aSB.append(sID + " (Currency.getInstance (\"" + sID + "\"), ECurrencyName." + sID + ", " + aLocale.toString() + "),");
}
LOGGER.info(aSB.toString());
}
use of com.helger.commons.collection.impl.CommonsHashSet in project peppol-commons by phax.
the class MainCreatePredefinedEnumsFromXML_v8x method _handleDocumentTypes.
private static void _handleDocumentTypes(final Document aDocumentSheet) {
final PCLDocumentTypesType aList = new GenericJAXBMarshaller<>(PCLDocumentTypesType.class, new QName("dummy")).read(aDocumentSheet);
// Create Java source
try {
final JDefinedClass jEnum = CM._package(RESULT_PACKAGE_PREFIX + "doctype")._enum("EPredefinedDocumentTypeIdentifier")._implements(IPeppolPredefinedDocumentTypeIdentifier.class);
jEnum.annotate(CodingStyleguideUnaware.class);
jEnum.javadoc().add(DO_NOT_EDIT);
// Add metadata
jEnum.field(JMod.PUBLIC_STATIC_FINAL, CM.ref(String.class), "CODE_LIST_VERSION", JExpr.lit(aList.getVersion()));
jEnum.field(JMod.PUBLIC_STATIC_FINAL, CM.INT, "CODE_LIST_ENTRY_COUNT", JExpr.lit(aList.getEntryCount().intValue()));
final ICommonsSet<String> aAllShortcutNames = new CommonsHashSet<>();
// Add all enum constants
for (final PCLDocumentTypeType aRow : aList.getDocumentType()) {
final String sProfileCode = aRow.getName();
final String sScheme = aRow.getScheme();
final String sValue = aRow.getValue();
final String sInitialRelease = aRow.getInitialRelease();
final EPeppolCodeListItemState eState = _getState(aRow.getState());
final boolean bDeprecated = !eState.isActive();
final String sDeprecationRelease = aRow.getDeprecationRelease();
final LocalDate aRemovalDate = aRow.getRemovalDateLocal();
// Split ID in it's pieces
final IPeppolDocumentTypeIdentifierParts aDocIDParts = PeppolDocumentTypeIdentifierParts.extractFromString(sValue);
final String sEnumConstName = RegExHelper.getAsIdentifier(sValue);
if (jEnum.getEnumConstantOfName(sEnumConstName) != null) {
// Avoid weird side effects
throw new IllegalStateException("The enum constant '" + sEnumConstName + "' is already in use");
}
final JEnumConstant jEnumConst = jEnum.enumConstant(sEnumConstName);
if (bDeprecated) {
jEnumConst.annotate(Deprecated.class);
jEnumConst.javadoc().addDeprecated().add("since " + sDeprecationRelease + " - this item should not be used to issue new identifiers!");
}
jEnumConst.arg(JExpr.lit(sScheme));
{
final JInvocation aNew = JExpr._new(CM.ref(PeppolDocumentTypeIdentifierParts.class)).arg(aDocIDParts.getRootNS()).arg(aDocIDParts.getLocalName()).arg(aDocIDParts.getCustomizationID()).arg(aDocIDParts.getVersion());
jEnumConst.arg(aNew);
}
jEnumConst.arg(JExpr.lit(sProfileCode));
jEnumConst.arg(CM.ref(Version.class).staticInvoke("parse").arg(sInitialRelease));
jEnumConst.arg(CM.ref(EPeppolCodeListItemState.class).enumConstantRef(eState));
jEnumConst.arg(bDeprecated ? CM.ref(Version.class).staticInvoke("parse").arg(sDeprecationRelease) : JExpr._null());
jEnumConst.arg(_asExpr(aRemovalDate));
jEnumConst.arg(JExpr.lit(aRow.isIssuedByOpenpeppol()));
jEnumConst.arg(JExpr.lit(StringParser.parseInt(aRow.getBisVersion(), -1)));
jEnumConst.arg(aRow.getDomainCommunity() == null ? JExpr._null() : JExpr.lit(aRow.getDomainCommunity()));
{
final JInvocation aNew = JExpr._new(CM.ref(CommonsArrayList.class).narrowEmpty());
for (final PCLProcessIDType aProcID : aRow.getProcessId()) aNew.arg(CIdentifier.getURIEncoded(aProcID.getScheme(), aProcID.getValue()));
jEnumConst.arg(aNew);
}
jEnumConst.javadoc().add("<code>" + sValue + "</code><br>");
jEnumConst.javadoc().addTag(JDocComment.TAG_SINCE).add("code list " + sInitialRelease);
// Also create a shortcut for more readable names
final String sShortcutName = CodeGenerationHelper.createShortcutDocumentTypeIDName(aDocIDParts);
if (sShortcutName != null) {
// Make unique name
int nNext = 2;
String sRealShortcutName = sShortcutName;
while (!aAllShortcutNames.add(sRealShortcutName)) {
sRealShortcutName = sShortcutName + nNext;
nNext++;
}
final JFieldVar aShortcut = jEnum.field(JMod.PUBLIC | JMod.STATIC | JMod.FINAL, jEnum, sRealShortcutName, jEnumConst);
aShortcut.javadoc().add("Same as {@link #" + sEnumConstName + "}");
if (bDeprecated) {
aShortcut.annotate(Deprecated.class);
aShortcut.javadoc().addDeprecated().add("since " + sDeprecationRelease + " - this item should not be used to issue new identifiers!");
}
jEnumConst.javadoc().add("\nSame as {@link #" + sRealShortcutName + "}");
}
}
// fields
final JFieldVar fScheme = jEnum.field(JMod.PRIVATE | JMod.FINAL, String.class, "m_sScheme");
final JFieldVar fParts = jEnum.field(JMod.PRIVATE | JMod.FINAL, IPeppolDocumentTypeIdentifierParts.class, "m_aParts");
final JFieldVar fID = jEnum.field(JMod.PRIVATE | JMod.FINAL, String.class, "m_sID");
final JFieldVar fProfileCode = jEnum.field(JMod.PRIVATE | JMod.FINAL, String.class, "m_sProfileCode");
final JFieldVar fInitialRelease = jEnum.field(JMod.PRIVATE | JMod.FINAL, Version.class, "m_aInitialRelease");
final JFieldVar fState = jEnum.field(JMod.PRIVATE | JMod.FINAL, EPeppolCodeListItemState.class, "m_eState");
final JFieldVar fDeprecationRelease = jEnum.field(JMod.PRIVATE | JMod.FINAL, Version.class, "m_aDeprecationRelease");
final JFieldVar fRemovalDate = jEnum.field(JMod.PRIVATE | JMod.FINAL, LocalDate.class, "m_aRemovalDate");
final JFieldVar fIssuedByOpenPeppol = jEnum.field(JMod.PRIVATE | JMod.FINAL, boolean.class, "m_bIssuedByOpenPeppol");
final JFieldVar fBISVersion = jEnum.field(JMod.PRIVATE | JMod.FINAL, int.class, "m_nBISVersion");
final JFieldVar fDomainCommunity = jEnum.field(JMod.PRIVATE | JMod.FINAL, String.class, "m_sDomainCommunity");
final JFieldVar fProcessIDs = jEnum.field(JMod.PRIVATE | JMod.FINAL, CM.ref(ICommonsList.class).narrow(IProcessIdentifier.class), "m_aProcessIDs");
// Constructor
final JMethod jCtor = jEnum.constructor(0);
final JVar jScheme = jCtor.param(JMod.FINAL, String.class, "sScheme");
jScheme.annotate(Nonnull.class);
jScheme.annotate(Nonempty.class);
final JVar jParts = jCtor.param(JMod.FINAL, IPeppolDocumentTypeIdentifierParts.class, "aParts");
jParts.annotate(Nonnull.class);
final JVar jProfileCode = jCtor.param(JMod.FINAL, String.class, "sProfileCode");
jProfileCode.annotate(Nonnull.class);
jProfileCode.annotate(Nonempty.class);
final JVar jInitialRelease = jCtor.param(JMod.FINAL, Version.class, "aInitialRelease");
jInitialRelease.annotate(Nonnull.class);
final JVar jState = jCtor.param(JMod.FINAL, EPeppolCodeListItemState.class, "eState");
jState.annotate(Nonnull.class);
final JVar jDeprecationRelease = jCtor.param(JMod.FINAL, Version.class, "aDeprecationRelease");
jDeprecationRelease.annotate(Nullable.class);
final JVar jRemovalDate = jCtor.param(JMod.FINAL, LocalDate.class, "aRemovalDate");
jRemovalDate.annotate(Nullable.class);
final JVar jIssuedByOpenPeppol = jCtor.param(JMod.FINAL, boolean.class, "bIssuedByOpenPeppol");
final JVar jBISVersion = jCtor.param(JMod.FINAL, int.class, "nBISVersion");
final JVar jDomainCommunity = jCtor.param(JMod.FINAL, String.class, "sDomainCommunity");
jDomainCommunity.annotate(Nullable.class);
final JVar jProcessIDs = jCtor.param(JMod.FINAL, CM.ref(ICommonsList.class).narrow(String.class), "aProcessIDs");
jCtor.body().assign(fScheme, jScheme).assign(fParts, jParts).assign(fProfileCode, jProfileCode).assign(fID, fParts.invoke("getAsDocumentTypeIdentifierValue")).assign(fInitialRelease, jInitialRelease).assign(fState, jState).assign(fDeprecationRelease, jDeprecationRelease).assign(fRemovalDate, jRemovalDate).assign(fIssuedByOpenPeppol, jIssuedByOpenPeppol).assign(fBISVersion, jBISVersion).assign(fDomainCommunity, jDomainCommunity).assign(fProcessIDs, CM.ref(CommonsArrayList.class).narrowEmpty()._new().arg(jProcessIDs).arg(new JLambdaMethodRef(CM.ref(PeppolIdentifierFactory.class).staticRef("INSTANCE"), "parseProcessIdentifier")));
// public String getScheme ()
JMethod m = jEnum.method(JMod.PUBLIC, String.class, "getScheme");
m.annotate(Nonnull.class);
m.annotate(Nonempty.class);
m.body()._return(fScheme);
// public String getValue ()
m = jEnum.method(JMod.PUBLIC, String.class, "getValue");
m.annotate(Nonnull.class);
m.annotate(Nonempty.class);
m.body()._return(fID);
// public String getRootNS ()
m = jEnum.method(JMod.PUBLIC, String.class, "getRootNS");
m.annotate(Nonnull.class);
m.annotate(Nonempty.class);
m.body()._return(fParts.invoke(m.name()));
// public String getLocalName ()
m = jEnum.method(JMod.PUBLIC, String.class, "getLocalName");
m.annotate(Nonnull.class);
m.annotate(Nonempty.class);
m.body()._return(fParts.invoke(m.name()));
// public String getSubTypeIdentifier ()
m = jEnum.method(JMod.PUBLIC, String.class, "getSubTypeIdentifier");
m.annotate(Nonnull.class);
m.annotate(Nonempty.class);
m.body()._return(fParts.invoke(m.name()));
if (false) {
// public String getTransactionID ()
m = jEnum.method(JMod.PUBLIC, String.class, "getTransactionID");
m.annotate(Nonnull.class);
m.annotate(Nonempty.class);
m.body()._return(fParts.invoke(m.name()));
// public List<String> getExtensionIDs ()
m = jEnum.method(JMod.PUBLIC, CM.ref(ICommonsList.class).narrow(String.class), "getExtensionIDs");
m.annotate(Nonnull.class);
m.annotate(ReturnsMutableCopy.class);
m.body()._return(fParts.invoke(m.name()));
}
// public String getCustomizationID ()
m = jEnum.method(JMod.PUBLIC, String.class, "getCustomizationID");
m.annotate(Nonnull.class);
m.annotate(Nonempty.class);
m.body()._return(fParts.invoke(m.name()));
// public String getVersion ()
m = jEnum.method(JMod.PUBLIC, String.class, "getVersion");
m.annotate(Nonnull.class);
m.annotate(Nonempty.class);
m.body()._return(fParts.invoke(m.name()));
// public String getCommonName ()
m = jEnum.method(JMod.PUBLIC, String.class, "getCommonName");
m.annotate(Nonnull.class);
m.annotate(Nonempty.class);
m.body()._return(fProfileCode);
// public String getAsDocumentTypeIdentifierValue ()
m = jEnum.method(JMod.PUBLIC, String.class, "getAsDocumentTypeIdentifierValue");
m.annotate(Nonnull.class);
m.annotate(Nonempty.class);
m.body()._return(fID);
// public PeppolDocumentTypeIdentifier getAsDocumentTypeIdentifier ()
m = jEnum.method(JMod.PUBLIC, PeppolDocumentTypeIdentifier.class, "getAsDocumentTypeIdentifier");
m.annotate(Nonnull.class);
m.body()._return(JExpr._new(CM.ref(PeppolDocumentTypeIdentifier.class)).arg(JExpr._this()));
// public IPeppolDocumentTypeIdentifierParts getParts
m = jEnum.method(JMod.PUBLIC, IPeppolDocumentTypeIdentifierParts.class, "getParts");
m.annotate(Nonnull.class);
m.body()._return(fParts);
// public Version getInitialRelease ()
m = jEnum.method(JMod.PUBLIC, Version.class, "getInitialRelease");
m.annotate(Nonnull.class);
m.body()._return(fInitialRelease);
// public EPeppolCodeListItemState getState ()
m = jEnum.method(JMod.PUBLIC, EPeppolCodeListItemState.class, "getState");
m.annotate(Nonnull.class);
m.body()._return(fState);
// public Version getDeprecationRelease ()
m = jEnum.method(JMod.PUBLIC, Version.class, "getDeprecationRelease");
m.annotate(Nullable.class);
m.body()._return(fDeprecationRelease);
// public LocalDate getRemovalDate ()
m = jEnum.method(JMod.PUBLIC, LocalDate.class, "getRemovalDate");
m.annotate(Nullable.class);
m.body()._return(fRemovalDate);
// public boolean isIssuedByOpenPeppol ()
m = jEnum.method(JMod.PUBLIC, boolean.class, "isIssuedByOpenPeppol");
m.body()._return(fIssuedByOpenPeppol);
// public int getBISVersion ()
m = jEnum.method(JMod.PUBLIC, int.class, "getBISVersion");
m.annotate(CheckForSigned.class);
m.body()._return(fBISVersion);
// since 7.3 this method is nullable
// public String getDomainCommunity ()
m = jEnum.method(JMod.PUBLIC, String.class, "getDomainCommunity");
m.annotate(Nullable.class);
m.body()._return(fDomainCommunity);
// public ICommonsList<IProcessIdentifier> getAllProcessIDs()
m = jEnum.method(JMod.PUBLIC, CM.ref(ICommonsList.class).narrow(IProcessIdentifier.class), "getAllProcessIDs");
m.annotate(Nonnull.class);
m.annotate(Nonempty.class);
m.annotate(ReturnsMutableCopy.class);
m.body()._return(fProcessIDs.invoke("getClone"));
// @Nullable
// public static EPredefinedDocumentTypeIdentifier
// getFromDocumentTypeIdentifierOrNull(@Nullable final
// IDocumentTypeIdentifier aDocTypeID)
m = jEnum.method(JMod.PUBLIC | JMod.STATIC, jEnum, "getFromDocumentTypeIdentifierOrNull");
{
m.annotate(Nullable.class);
final JVar jValue = m.param(JMod.FINAL, IDocumentTypeIdentifier.class, "aDocTypeID");
jValue.annotate(Nullable.class);
final JBlock jIf = m.body()._if(jValue.neNull())._then();
final JForEach jForEach = jIf.forEach(jEnum, "e", jEnum.staticInvoke("values"));
jForEach.body()._if(jForEach.var().invoke("hasScheme").arg(jValue.invoke("getScheme")).cand(jForEach.var().invoke("hasValue").arg(jValue.invoke("getValue"))))._then()._return(jForEach.var());
m.body()._return(JExpr._null());
}
} catch (final JCodeModelException ex) {
LOGGER.error("Failed to create source", ex);
}
}
use of com.helger.commons.collection.impl.CommonsHashSet in project phoss-smp by phax.
the class SMPRendererPublic method createDefaultFooter.
/**
* @param bShowApplicationName
* <code>true</code> to show the application name and version,
* <code>false</code> to hide it.
* @param bShowSource
* <code>true</code> to show the link to the source, <code>false</code>
* to hide it.
* @param bShowAuthor
* <code>true</code> to show the author, <code>false</code> to hide it.
* @return The footer to be used for /public and /secure. Never
* <code>null</code> but maybe empty.
*/
@Nonnull
public static BootstrapContainer createDefaultFooter(final boolean bShowApplicationName, final boolean bShowSource, final boolean bShowAuthor) {
final BootstrapContainer aContainer = new BootstrapContainer().setID(CLayout.LAYOUT_AREAID_FOOTER).setFluid(true);
if (bShowApplicationName) {
aContainer.addChild(new HCP().addChild(CSMP.getApplicationTitleAndVersion() + " with " + SMPServerConfiguration.getRESTType().getDisplayName() + " API"));
}
// By
{
final HCP aBy = new HCP();
// Author
if (bShowAuthor)
aBy.addChild("Created by ").addChild(HCA_MailTo.createLinkedEmail("philip@helger.com", "Philip Helger"));
// Source
if (bShowSource) {
if (aBy.hasChildren())
aBy.addChild(" - ");
aBy.addChild(new HCA(new SimpleURL("https://github.com/phax/phoss-smp")).setTargetBlank().addChild(CSMP.APPLICATION_TITLE + " on GitHub"));
}
if (aBy.hasChildren())
aContainer.addChild(aBy);
}
// Imprint
if (SMPWebAppConfiguration.isImprintEnabled()) {
final String sImprintText = SMPWebAppConfiguration.getImprintText();
if (StringHelper.hasText(sImprintText)) {
final ISimpleURL aImprintHref = SMPWebAppConfiguration.getImprintHref();
final IHCElementWithChildren<?> aNode;
if (aImprintHref != null) {
// Link and text
final String sImprintTarget = SMPWebAppConfiguration.getImprintTarget();
final HC_Target aTarget = StringHelper.hasText(sImprintTarget) ? new HC_Target(sImprintTarget) : null;
aNode = new HCA(aImprintHref).addChild(sImprintText).setTarget(aTarget);
} else {
// Text only
aNode = new HCSpan().addChild(sImprintText);
}
// Already trimmed
final String sImprintCSSClasses = SMPWebAppConfiguration.getImprintCSSClasses();
if (StringHelper.hasText(sImprintCSSClasses)) {
final ICommonsSet<String> aUniqueNames = new CommonsHashSet<>(RegExHelper.getSplitToList(sImprintCSSClasses, "\\s+"));
for (final String sCSSClass : aUniqueNames) aNode.addClass(DefaultCSSClassProvider.create(sCSSClass));
}
aContainer.addChild(new HCP().addChild("Imprint ").addChild(aNode));
}
}
return aContainer;
}
Aggregations