@Test
  public void testGetRecursiveChildIter() {
    final Document doc = XMLFactory.newDocument();

    // No children present
    assertFalse(new ChildElementIterator(doc).hasNext());

    // 1 child
    final Element eRoot = (Element) doc.appendChild(doc.createElement("root"));
    assertEquals(1, ContainerHelper.newList(new ChildElementIterator(doc)).size());

    // 2 children
    eRoot.appendChild(doc.createElement("Hallo"));
    eRoot.appendChild(doc.createTextNode(" - "));
    eRoot.appendChild(doc.createElement("Welt"));
    assertEquals(2, ContainerHelper.newList(new ChildElementIterator(eRoot)).size());
    assertEquals(
        1,
        ContainerHelper.newList(
                new ChildElementIterator(eRoot, new FilterElementWithTagName("Hallo")))
            .size());

    try {
      new ChildElementIterator(doc).remove();
      fail();
    } catch (final UnsupportedOperationException ex) {
    }
    try {
      new ChildElementIterator(null);
      fail();
    } catch (final NullPointerException ex) {
    }
  }
Пример #2
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.1415)
           .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(ContainerHelper.newList(aRecordWithAllTypes)),
               new NonBlockingByteArrayOutputStream())
           .isSuccess());
   assertTrue(
       aExporter
           .exportRecords(
               new ConstantExportRecordProvider(
                   ContainerHelper.newList(
                       aRecordWithAllTypes, aRecordWithAllTypes, aEmptyRecord)),
               new NonBlockingByteArrayOutputStream())
           .isSuccess());
   assertTrue(
       aExporter
           .exportRecords(
               new ConstantExportRecordProvider(
                   null,
                   ContainerHelper.newList(aRecordWithAllTypes, aRecordWithAllTypes, aEmptyRecord),
                   aRecordWithAllTypes),
               new NonBlockingByteArrayOutputStream())
           .isSuccess());
   assertTrue(
       aExporter
           .exportRecords(
               new ConstantExportRecordProvider(
                   aRecordWithAllTypes,
                   ContainerHelper.newList(aRecordWithAllTypes, aRecordWithAllTypes, aEmptyRecord),
                   aRecordWithAllTypes),
               new NonBlockingByteArrayOutputStream())
           .isSuccess());
 }
Пример #3
0
  public UAProfile(
      @Nullable final List<String> aProfileUrls,
      @Nullable final Map<Integer, UAProfileDiff> aProfileDiffData) {
    final int nUrls = ContainerHelper.getSize(aProfileUrls);
    final int nDiffs = ContainerHelper.getSize(aProfileDiffData);
    if (nUrls == 0 && nDiffs == 0)
      throw new IllegalArgumentException("Neither profile nor diff data found!");

    if (nUrls > 1) s_aLogger.warn("Found more than one profile URL: " + aProfileUrls);
    m_sProfileUrl = ContainerHelper.getFirstElement(aProfileUrls);
    m_aProfileDiffData =
        ContainerHelper.isEmpty(aProfileDiffData)
            ? null
            : new TreeMap<Integer, UAProfileDiff>(aProfileDiffData);
  }
 @Override
 @Nullable
 public List<String> getAttributeValues(
     @Nullable final String sName, @Nullable final List<String> aDefault) {
   final Object aValue = getAttributeObject(sName);
   if (aValue instanceof String[]) {
     // multiple values passed in the request
     return ContainerHelper.newList((String[]) aValue);
   }
   if (aValue instanceof String) {
     // single value passed in the request
     return ContainerHelper.newList((String) aValue);
   }
   // E.g. for file items
   return aDefault;
 }
Пример #5
0
 @Test
 public void testCreate() {
   assertFalse(new HCSmall().hasChildren());
   assertEquals(0, HCSmall.create((IPredefinedLocaleTextProvider) null).getChildCount());
   assertEquals(
       0,
       HCSmall.create((IPredefinedLocaleTextProvider) null, (IPredefinedLocaleTextProvider) null)
           .getChildCount());
   assertEquals(0, HCSmall.create((IHCNodeBuilder) null).getChildCount());
   assertEquals(0, HCSmall.create((IHCNodeBuilder) null, (IHCNodeBuilder) null).getChildCount());
   assertEquals(1, HCSmall.create("Text").getChildCount());
   assertEquals(0, HCSmall.create((String) null).getChildCount());
   assertEquals(1, HCSmall.create(HCB.create("Bold")).getChildCount());
   assertEquals(0, HCSmall.create((IHCNode) null).getChildCount());
   assertEquals(3, HCSmall.create("Hallo", "Welt", "!!!").getChildCount());
   assertEquals(0, HCSmall.create(new String[0]).getChildCount());
   assertEquals(0, HCSmall.create((String[]) null).getChildCount());
   assertEquals(2, HCSmall.create(HCB.create("Bold"), HCI.create("Italic")).getChildCount());
   assertEquals(0, HCSmall.create(new IHCNode[0]).getChildCount());
   assertEquals(0, HCSmall.create((IHCNode[]) null).getChildCount());
   assertEquals(
       2,
       HCSmall.create(ContainerHelper.newList(HCB.create("Bold"), HCI.create("Italic")))
           .getChildCount());
   assertEquals(0, HCSmall.create(new ArrayList<IHCNode>()).getChildCount());
 }
Пример #6
0
 @Nonnull
 @ReturnsMutableCopy
 public List<IDirectedGraphRelation> getAllIncomingRelations() {
   return m_aIncoming == null
       ? new ArrayList<IDirectedGraphRelation>()
       : ContainerHelper.newList(m_aIncoming.values());
 }
Пример #7
0
 @Nonnull
 @ReturnsMutableCopy
 public List<CSSItem> getAllItems() {
   m_aRWLock.readLock().lock();
   try {
     return ContainerHelper.newList(m_aItems);
   } finally {
     m_aRWLock.readLock().unlock();
   }
 }
 @Nonnull
 private static String _getAsString(@Nonnull final Set<Character> aInvalidChars) {
   if (ContainerHelper.isEmpty(aInvalidChars)) return "NONE";
   final StringBuilder aSB = new StringBuilder();
   for (final Character aChar : aInvalidChars) {
     if (aSB.length() > 0) aSB.append(", ");
     final int nChar = aChar.charValue();
     aSB.append("0x").append(StringHelper.getHexStringLeadingZero(nChar, 2));
   }
   return aSB.toString();
 }
 @Test
 public void testParserSecondBefore() {
   final HolidayMap aHolidays = new HolidayMap();
   final Holidays config = new Holidays();
   final FixedWeekdayRelativeToFixed rule = new FixedWeekdayRelativeToFixed();
   rule.setWhich(Which.SECOND);
   rule.setWeekday(Weekday.MONDAY);
   rule.setWhen(When.BEFORE);
   final Fixed fixed = new Fixed();
   fixed.setDay(Integer.valueOf(29));
   fixed.setMonth(Month.JANUARY);
   rule.setDay(fixed);
   config.getFixedWeekdayRelativeToFixed().add(rule);
   s_aParser.parse(2011, aHolidays, config);
   assertEquals("Wrong number of dates.", 1, aHolidays.size());
   assertEquals(
       "Wrong date.",
       PDTFactory.createLocalDate(2011, 1, 17),
       ContainerHelper.getFirstElement(aHolidays.getAllDates()));
 }
 @Test
 public void testParserFourthAfter() {
   final HolidayMap aHolidays = new HolidayMap();
   final Holidays config = new Holidays();
   final FixedWeekdayRelativeToFixed rule = new FixedWeekdayRelativeToFixed();
   rule.setWhich(Which.FOURTH);
   rule.setWeekday(Weekday.TUESDAY);
   rule.setWhen(When.AFTER);
   final Fixed fixed = new Fixed();
   fixed.setDay(Integer.valueOf(15));
   fixed.setMonth(Month.MARCH);
   rule.setDay(fixed);
   config.getFixedWeekdayRelativeToFixed().add(rule);
   s_aParser.parse(2011, aHolidays, config);
   assertEquals("Wrong number of dates.", 1, aHolidays.size());
   assertEquals(
       "Wrong date.",
       PDTFactory.createLocalDate(2011, 4, 12),
       ContainerHelper.getFirstElement(aHolidays.getAllDates()));
 }
Пример #11
0
 /**
  * Interpret the passed XHTML fragment as HTML and retrieve a result container with all body
  * elements.
  *
  * @param sXHTML The XHTML text fragment. This fragment is parsed as an HTML body and may
  *     therefore not contain the &lt;body&gt; tag.
  * @return <code>null</code> if the passed text could not be interpreted as XHTML or if no body
  *     element was found, an {@link IMicroContainer} with all body children otherwise.
  */
 @Nullable
 public IMicroContainer unescapeXHTMLFragment(@Nullable final String sXHTML) {
   // Ensure that the content is surrounded by a single tag
   final IMicroDocument aDoc = parseXHTMLFragment(sXHTML);
   if (aDoc != null && aDoc.getDocumentElement() != null) {
     // Find "body" case insensitive
     final IMicroElement eBody =
         HCUtils.getFirstChildElement(aDoc.getDocumentElement(), EHTMLElement.BODY);
     if (eBody != null) {
       final IMicroContainer ret = new MicroContainer();
       if (eBody.hasChildren()) {
         // Make a copy of the list, because it is modified in
         // detachFromParent!
         for (final IMicroNode aChildNode : ContainerHelper.newList(eBody.getChildren()))
           ret.appendChild(aChildNode.detachFromParent());
       }
       return ret;
     }
   }
   return null;
 }
 @Override
 public void onKeyedCounter(final String sName, final IStatisticsHandlerKeyedCounter aHandler) {
   if (aHandler.getInvocationCount() > 0) {
     final IMicroElement eKeyedCounter =
         m_eRoot
             .appendElement(StatisticsExporter.ELEMENT_KEYEDCOUNTER)
             .setAttribute(StatisticsExporter.ATTR_NAME, sName)
             .setAttribute(
                 StatisticsExporter.ATTR_INVOCATIONCOUNT,
                 Integer.toString(aHandler.getInvocationCount()));
     for (final String sKey : ContainerHelper.getSorted(aHandler.getAllKeys())) {
       eKeyedCounter
           .appendElement(StatisticsExporter.ELEMENT_KEY)
           .setAttribute(StatisticsExporter.ATTR_NAME, sKey)
           .setAttribute(
               StatisticsExporter.ATTR_INVOCATIONCOUNT,
               Integer.toString(aHandler.getInvocationCount(sKey)))
           .setAttribute(StatisticsExporter.ATTR_COUNT, Long.toString(aHandler.getCount(sKey)));
     }
   }
 }
 @Override
 public void onKeyedSize(final String sName, final IStatisticsHandlerKeyedSize aHandler) {
   if (aHandler.getInvocationCount() > 0) {
     final IMicroElement eKeyedSize =
         m_eRoot
             .appendElement(StatisticsExporter.ELEMENT_KEYEDSIZE)
             .setAttribute(StatisticsExporter.ATTR_NAME, sName)
             .setAttribute(
                 StatisticsExporter.ATTR_INVOCATIONCOUNT,
                 Integer.toString(aHandler.getInvocationCount()));
     for (final String sKey : ContainerHelper.getSorted(aHandler.getAllKeys())) {
       eKeyedSize
           .appendElement(StatisticsExporter.ELEMENT_KEY)
           .setAttribute(StatisticsExporter.ATTR_NAME, sKey)
           .setAttribute(
               StatisticsExporter.ATTR_INVOCATIONCOUNT,
               Integer.toString(aHandler.getInvocationCount(sKey)))
           .setAttribute(StatisticsExporter.ATTR_MIN, Long.toString(aHandler.getMin(sKey)))
           .setAttribute(StatisticsExporter.ATTR_AVERAGE, Long.toString(aHandler.getAverage(sKey)))
           .setAttribute(StatisticsExporter.ATTR_MAX, Long.toString(aHandler.getMax(sKey)))
           .setAttribute(StatisticsExporter.ATTR_SUM, aHandler.getSum(sKey).toString());
     }
   }
 }
  @Override
  @SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE")
  protected void showSelectedObject(
      @Nonnull final WebPageExecutionContext aWPEC, @Nonnull final IUser aSelectedObject) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final AccessManager aMgr = AccessManager.getInstance();
    final IHCTableFormView<?> aTable =
        aNodeList.addAndReturnChild(getStyler().createTableFormView(new HCCol(170), HCCol.star()));
    aTable.setSpanningHeaderContent(
        EText.HEADER_DETAILS.getDisplayTextWithArgs(
            aDisplayLocale, SecurityUI.getUserDisplayName(aSelectedObject, aDisplayLocale)));
    onShowSelectedObjectTableStart(aTable, aSelectedObject, aDisplayLocale);
    if (!useEmailAddressAsLoginName()) {
      aTable
          .createItemRow()
          .setLabel(EText.LABEL_LOGINNAME.getDisplayText(aDisplayLocale))
          .setCtrl(aSelectedObject.getLoginName());
    }
    aTable
        .createItemRow()
        .setLabel(EText.LABEL_FIRSTNAME.getDisplayText(aDisplayLocale))
        .setCtrl(aSelectedObject.getFirstName());
    aTable
        .createItemRow()
        .setLabel(EText.LABEL_LASTNAME.getDisplayText(aDisplayLocale))
        .setCtrl(aSelectedObject.getLastName());
    aTable
        .createItemRow()
        .setLabel(EText.LABEL_EMAIL.getDisplayText(aDisplayLocale))
        .setCtrl(getStyler().createEmailLink(aSelectedObject.getEmailAddress()));
    aTable
        .createItemRow()
        .setLabel(EText.LABEL_ENABLED.getDisplayText(aDisplayLocale))
        .setCtrl(EWebBasicsText.getYesOrNo(aSelectedObject.isEnabled(), aDisplayLocale));
    aTable
        .createItemRow()
        .setLabel(EText.LABEL_DELETED.getDisplayText(aDisplayLocale))
        .setCtrl(EWebBasicsText.getYesOrNo(aSelectedObject.isDeleted(), aDisplayLocale));
    aTable
        .createItemRow()
        .setLabel(EText.LABEL_LAST_LOGIN.getDisplayText(aDisplayLocale))
        .setCtrl(
            aSelectedObject.getLastLoginDateTime() != null
                ? new HCTextNode(
                    PDTToString.getAsString(aSelectedObject.getLastLoginDateTime(), aDisplayLocale))
                : HCEM.create(EText.LABEL_LAST_LOGIN_NEVER.getDisplayText(aDisplayLocale)));
    aTable
        .createItemRow()
        .setLabel(EText.LABEL_LOGIN_COUNT.getDisplayText(aDisplayLocale))
        .setCtrl(Integer.toString(aSelectedObject.getLoginCount()));
    aTable
        .createItemRow()
        .setLabel(EText.LABEL_CONSECUTIVE_FAILED_LOGIN_COUNT.getDisplayText(aDisplayLocale))
        .setCtrl(Integer.toString(aSelectedObject.getConsecutiveFailedLoginCount()));

    // user groups
    final Collection<IUserGroup> aUserGroups =
        aMgr.getAllUserGroupsWithAssignedUser(aSelectedObject.getID());
    if (aUserGroups.isEmpty()) {
      aTable
          .createItemRow()
          .setLabel(EText.LABEL_USERGROUPS_0.getDisplayText(aDisplayLocale))
          .setCtrl(HCEM.create(EText.NONE_DEFINED.getDisplayText(aDisplayLocale)));
    } else {
      final HCNodeList aUserGroupUI = new HCNodeList();
      for (final IUserGroup aUserGroup :
          ContainerHelper.getSorted(aUserGroups, new ComparatorHasName<IUserGroup>(aDisplayLocale)))
        aUserGroupUI.addChild(HCDiv.create(aUserGroup.getName()));
      aTable
          .createItemRow()
          .setLabel(
              EText.LABEL_USERGROUPS_N.getDisplayTextWithArgs(
                  aDisplayLocale, Integer.toString(aUserGroups.size())))
          .setCtrl(aUserGroupUI);
    }

    // roles
    final Set<IRole> aUserRoles = aMgr.getAllUserRoles(aSelectedObject.getID());
    if (aUserRoles.isEmpty()) {
      aTable
          .createItemRow()
          .setLabel(EText.LABEL_ROLES_0.getDisplayText(aDisplayLocale))
          .setCtrl(HCEM.create(EText.NONE_DEFINED.getDisplayText(aDisplayLocale)));
    } else {
      final HCNodeList aRoleUI = new HCNodeList();
      for (final IRole aRole :
          ContainerHelper.getSorted(aUserRoles, new ComparatorHasName<IRole>(aDisplayLocale)))
        aRoleUI.addChild(HCDiv.create(aRole.getName()));
      aTable
          .createItemRow()
          .setLabel(
              EText.LABEL_ROLES_N.getDisplayTextWithArgs(
                  aDisplayLocale, Integer.toString(aUserRoles.size())))
          .setCtrl(aRoleUI);
    }

    // custom attributes
    final Map<String, Object> aCustomAttrs = aSelectedObject.getAllAttributes();

    // Callback
    final Set<String> aHandledAttrs =
        showCustomAttrsOfSelectedObject(aSelectedObject, aCustomAttrs, aTable, aDisplayLocale);

    if (!aCustomAttrs.isEmpty()) {
      final IHCTable<?> aAttrTable = getStyler().createTable(new HCCol(170), HCCol.star());
      aAttrTable
          .addHeaderRow()
          .addCells(
              EText.HEADER_NAME.getDisplayText(aDisplayLocale),
              EText.HEADER_VALUE.getDisplayText(aDisplayLocale));
      for (final Map.Entry<String, Object> aEntry : aCustomAttrs.entrySet()) {
        final String sName = aEntry.getKey();
        if (aHandledAttrs == null || !aHandledAttrs.contains(sName)) {
          final String sValue = String.valueOf(aEntry.getValue());
          aAttrTable.addBodyRow().addCells(sName, sValue);
        }
      }

      // Maybe all custom attributes where handled in
      // showCustomAttrsOfSelectedObject
      if (aAttrTable.hasBodyRows())
        aTable
            .createItemRow()
            .setLabel(EText.LABEL_ATTRIBUTES.getDisplayText(aDisplayLocale))
            .setCtrl(aAttrTable);
    }

    // Callback
    onShowSelectedObjectTableEnd(aTable, aSelectedObject, aDisplayLocale);
  }
Пример #15
0
 /**
  * @return The global map from entity reference string to the according entity (e.g. from <code>
  *     "&amp;ndash;"</code> to <code>EHTMLEntity.ndash</code>). Never <code>null</code> nor empty.
  */
 @Nonnull
 @Nonempty
 @ReturnsMutableCopy
 public static final Map<String, EHTMLEntity> getEntityRefToEntityMap() {
   return ContainerHelper.newMap(s_aEntityRefToEntityMap);
 }
Пример #16
0
 @Nonnegative
 public int getIncomingRelationCount() {
   return ContainerHelper.getSize(m_aIncoming);
 }
Пример #17
0
 public boolean hasIncomingRelations() {
   return ContainerHelper.isNotEmpty(m_aIncoming);
 }
Пример #18
0
 public boolean hasOutgoingRelations() {
   return ContainerHelper.isNotEmpty(m_aOutgoing);
 }
Пример #19
0
 @Nullable
 public IJSExpression getArgAtIndex(final int nIndex) {
   return ContainerHelper.getSafe(this.m_aArgs, nIndex);
 }
Пример #20
0
 /**
  * Returns all arguments of the invocation.
  *
  * @return If there's no arguments, an empty array will be returned.
  */
 @Nonnull
 @ReturnsMutableCopy
 public List<IJSExpression> args() {
   return ContainerHelper.newList(this.m_aArgs);
 }
Пример #21
0
 @Nullable
 @ReturnsImmutableObject
 public Map<Integer, UAProfileDiff> getProfileDiffData() {
   return ContainerHelper.makeUnmodifiable(m_aProfileDiffData);
 }
Пример #22
0
 @Nonnegative
 public int getDiffCount() {
   return ContainerHelper.getSize(m_aProfileDiffData);
 }
Пример #23
0
 /**
  * @return The global map from entity reference string to the according entity (e.g. from <code>
  *     '–'</code> to <code>EHTMLEntity.ndash</code>). Never <code>null</code> nor empty.
  */
 @Nonnull
 @Nonempty
 @ReturnsMutableCopy
 public static final Map<Character, EHTMLEntity> getCharToEntityMap() {
   return ContainerHelper.newMap(s_aCharToEntityMap);
 }
 /** @return A list of all XSD resources used for validation. Never <code>null</code>. */
 @Nonnull
 @Nonempty
 @ReturnsMutableCopy
 public final List<IReadableResource> getOriginalXSDs() {
   return ContainerHelper.newList(m_aXSDs);
 }
Пример #25
0
 @Override
 @Nonnull
 @ReturnsMutableCopy
 public List<DATATYPE> getValues() {
   return ContainerHelper.newList(getData());
 }
Пример #26
0
 /**
  * @return The global map from entity reference string to the according character (e.g. from
  *     <code>"&amp;ndash;"</code> to <code>'–'</code> ). Never <code>null</code> nor empty.
  */
 @Nonnull
 @Nonempty
 @ReturnsMutableCopy
 public static final Map<String, Character> getEntityRefToCharMap() {
   return ContainerHelper.newMap(s_aEntityRefToCharMap);
 }
  @Override
  @SuppressWarnings("null")
  protected void validateAndSaveInputParameters(
      @Nonnull final WebPageExecutionContext aWPEC,
      @Nullable final IUser aSelectedObject,
      @Nonnull final FormErrors aFormErrors,
      final boolean bEdit) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final boolean bIsAdministrator = aSelectedObject != null && aSelectedObject.isAdministrator();
    final AccessManager aAccessMgr = AccessManager.getInstance();
    String sLoginName = aWPEC.getAttr(FIELD_LOGINNAME);
    final String sFirstName = aWPEC.getAttr(FIELD_FIRSTNAME);
    final String sLastName = aWPEC.getAttr(FIELD_LASTNAME);
    final String sEmailAddress = aWPEC.getAttr(FIELD_EMAILADDRESS);
    final String sPassword = aWPEC.getAttr(FIELD_PASSWORD);
    final String sPasswordConf = aWPEC.getAttr(FIELD_PASSWORD_CONFIRM);
    final boolean bEnabled =
        bIsAdministrator ? true : aWPEC.getCheckBoxAttr(FIELD_ENABLED, DEFAULT_ENABLED);
    final Collection<String> aUserGroupIDs =
        bIsAdministrator
            ? aAccessMgr.getAllUserGroupIDsWithAssignedUser(aSelectedObject.getID())
            : aWPEC.getAttrs(FIELD_USERGROUPS);

    if (useEmailAddressAsLoginName()) {
      sLoginName = sEmailAddress;
    } else {
      if (StringHelper.hasNoText(sLoginName))
        aFormErrors.addFieldError(
            FIELD_LOGINNAME, EText.ERROR_LOGINNAME_REQUIRED.getDisplayText(aDisplayLocale));
    }

    if (StringHelper.hasNoText(sLastName)) {
      if (isLastNameMandatory())
        aFormErrors.addFieldError(
            FIELD_LASTNAME, EText.ERROR_LASTNAME_REQUIRED.getDisplayText(aDisplayLocale));
    }

    if (StringHelper.hasNoText(sEmailAddress)) {
      if (isEmailMandatory())
        aFormErrors.addFieldError(
            FIELD_EMAILADDRESS, EText.ERROR_EMAIL_REQUIRED.getDisplayText(aDisplayLocale));
    } else if (!EmailAddressUtils.isValid(sEmailAddress))
      aFormErrors.addFieldError(
          FIELD_EMAILADDRESS, EText.ERROR_EMAIL_INVALID.getDisplayText(aDisplayLocale));
    else {
      final IUser aSameLoginUser = aAccessMgr.getUserOfLoginName(sEmailAddress);
      if (aSameLoginUser != null)
        if (!bEdit || !aSameLoginUser.equals(aSelectedObject))
          aFormErrors.addFieldError(
              FIELD_EMAILADDRESS, EText.ERROR_EMAIL_IN_USE.getDisplayText(aDisplayLocale));
    }

    if (!bEdit) {
      final List<String> aPasswordErrors =
          GlobalPasswordSettings.getPasswordConstraintList()
              .getInvalidPasswordDescriptions(sPassword, aDisplayLocale);
      for (final String sPasswordError : aPasswordErrors)
        aFormErrors.addFieldError(FIELD_PASSWORD, sPasswordError);
      if (!EqualsUtils.equals(sPassword, sPasswordConf))
        aFormErrors.addFieldError(
            FIELD_PASSWORD_CONFIRM,
            EText.ERROR_PASSWORDS_DONT_MATCH.getDisplayText(aDisplayLocale));
    }

    if (ContainerHelper.isEmpty(aUserGroupIDs))
      aFormErrors.addFieldError(
          FIELD_USERGROUPS, EText.ERROR_NO_USERGROUP.getDisplayText(aDisplayLocale));
    else if (!aAccessMgr.containsAllUserGroupsWithID(aUserGroupIDs))
      aFormErrors.addFieldError(
          FIELD_USERGROUPS, EText.ERROR_INVALID_USERGROUPS.getDisplayText(aDisplayLocale));

    // Call custom method
    final Map<String, String> aCustomAttrMap =
        validateCustomParameters(aWPEC, aSelectedObject, aFormErrors, bEdit);

    if (aFormErrors.isEmpty()) {
      // All fields are valid -> save
      if (bEdit) {
        final String sUserID = aSelectedObject.getID();

        final Map<String, Object> aAttrMap = aSelectedObject.getAllAttributes();
        if (aCustomAttrMap != null) aAttrMap.putAll(aCustomAttrMap);

        // We're editing an existing object
        aAccessMgr.setUserData(
            sUserID,
            sLoginName,
            sEmailAddress,
            sFirstName,
            sLastName,
            m_aDefaultUserLocale,
            aAttrMap,
            !bEnabled);
        aNodeList.addChild(
            getStyler().createSuccessBox(EText.SUCCESS_EDIT.getDisplayText(aDisplayLocale)));

        // assign to the matching user groups
        final Collection<String> aPrevUserGroupIDs =
            aAccessMgr.getAllUserGroupIDsWithAssignedUser(sUserID);
        // Create all missing assignments
        final Set<String> aUserGroupsToBeAssigned =
            ContainerHelper.getDifference(aUserGroupIDs, aPrevUserGroupIDs);
        for (final String sUserGroupID : aUserGroupsToBeAssigned)
          aAccessMgr.assignUserToUserGroup(sUserGroupID, sUserID);

        // Delete all old assignments
        final Set<String> aUserGroupsToBeUnassigned =
            ContainerHelper.getDifference(aPrevUserGroupIDs, aUserGroupIDs);
        for (final String sUserGroupID : aUserGroupsToBeUnassigned)
          aAccessMgr.unassignUserFromUserGroup(sUserGroupID, sUserID);

      } else {
        // We're creating a new object
        final IUser aNewUser =
            aAccessMgr.createNewUser(
                sLoginName,
                sEmailAddress,
                sPassword,
                sFirstName,
                sLastName,
                m_aDefaultUserLocale,
                aCustomAttrMap,
                !bEnabled);
        if (aNewUser != null) {
          aNodeList.addChild(
              getStyler().createSuccessBox(EText.SUCCESS_CREATE.getDisplayText(aDisplayLocale)));

          // assign to the matching internal user groups
          for (final String sUserGroupID : aUserGroupIDs)
            aAccessMgr.assignUserToUserGroup(sUserGroupID, aNewUser.getID());
        } else
          aNodeList.addChild(
              getStyler().createErrorBox(EText.FAILURE_CREATE.getDisplayText(aDisplayLocale)));
      }
    }
  }
Пример #28
0
 /**
  * @return The global map from character string to the according entity reference string (e.g.
  *     from <code>"–"</code> to <code>"&amp;ndash;"</code> ). Never <code>null</code> nor empty.
  */
 @Nonnull
 @Nonempty
 @ReturnsMutableCopy
 public static final Map<String, String> getCharStringToEntityRefMap() {
   return ContainerHelper.newMap(s_aCharStringToEntityRefMap);
 }
  @Nonnull
  protected IHCNode getTabWithUsers(
      @Nonnull final Locale aDisplayLocale,
      @Nonnull final Collection<? extends IUser> aUsers,
      @Nonnull @Nonempty final String sTableID) {
    final boolean bSeparateLoginName = !useEmailAddressAsLoginName();
    final AccessManager aMgr = AccessManager.getInstance();
    // List existing
    final List<HCCol> aCols = new ArrayList<HCCol>();
    aCols.add(new HCCol(200));
    if (bSeparateLoginName) aCols.add(new HCCol(200));
    aCols.add(HCCol.star());
    aCols.add(new HCCol(150));
    aCols.add(createActionCol(3));
    final IHCTable<?> aTable =
        getStyler().createTable(ArrayHelper.newArray(aCols, HCCol.class)).setID(sTableID);
    final HCRow aHeaderRow = aTable.addHeaderRow();
    aHeaderRow.addCell(EText.HEADER_NAME.getDisplayText(aDisplayLocale));
    if (bSeparateLoginName)
      aHeaderRow.addCell(EText.HEADER_LOGINNAME.getDisplayText(aDisplayLocale));
    aHeaderRow.addCells(
        EText.HEADER_EMAIL.getDisplayText(aDisplayLocale),
        EText.HEADER_USERGROUPS.getDisplayText(aDisplayLocale),
        EWebBasicsText.MSG_ACTIONS.getDisplayText(aDisplayLocale));

    for (final IUser aCurUser : aUsers) {
      final ISimpleURL aViewLink = createViewURL(aCurUser);

      final HCRow aRow = aTable.addBodyRow();
      aRow.addCell(
          new HCA(aViewLink).addChild(SecurityUI.getUserDisplayName(aCurUser, aDisplayLocale)));
      if (bSeparateLoginName) aRow.addCell(new HCA(aViewLink).addChild(aCurUser.getLoginName()));
      aRow.addCell(new HCA(aViewLink).addChild(aCurUser.getEmailAddress()));

      // User groups
      final Collection<IUserGroup> aUserGroups =
          aMgr.getAllUserGroupsWithAssignedUser(aCurUser.getID());
      final StringBuilder aUserGroupsStr = new StringBuilder();
      for (final IUserGroup aUserGroup :
          ContainerHelper.getSorted(
              aUserGroups, new ComparatorHasName<IUserGroup>(aDisplayLocale))) {
        if (aUserGroupsStr.length() > 0) aUserGroupsStr.append(", ");
        aUserGroupsStr.append(aUserGroup.getName());
      }
      aRow.addCell(new HCA(aViewLink).addChild(aUserGroupsStr.toString()));

      final IHCCell<?> aActionCell = aRow.addCell();

      // Edit user
      if (isEditAllowed(aCurUser)) aActionCell.addChild(createEditLink(aCurUser, aDisplayLocale));
      else aActionCell.addChild(createEmptyAction());

      // Copy
      aActionCell.addChild(createCopyLink(aCurUser, aDisplayLocale));

      // Reset password of user
      if (canResetPassword(aCurUser)) {
        aActionCell.addChild(
            new HCA(
                    LinkUtils.getSelfHref()
                        .add(CHCParam.PARAM_ACTION, ACTION_RESET_PASSWORD)
                        .add(CHCParam.PARAM_OBJECT, aCurUser.getID()))
                .setTitle(
                    EText.TITLE_RESET_PASSWORD.getDisplayTextWithArgs(
                        aDisplayLocale, SecurityUI.getUserDisplayName(aCurUser, aDisplayLocale)))
                .addChild(getResetPasswordIcon()));
      } else aActionCell.addChild(createEmptyAction());
    }

    final HCNodeList aNodeList = new HCNodeList();
    aNodeList.addChild(aTable);

    final DataTables aDataTables = getStyler().createDefaultDataTables(aTable, aDisplayLocale);
    aDataTables.getOrCreateColumnOfTarget(3).addClass(CSS_CLASS_ACTION_COL).setSortable(false);
    aDataTables.setInitialSorting(1, ESortOrder.ASCENDING);
    aNodeList.addChild(aDataTables);

    // Required for best layout inside a tab!
    aTable.removeAllColumns();

    return aNodeList;
  }
Пример #30
0
 /**
  * Ctor
  *
  * @param aList List to use as the basis
  */
 public JSONPropertyValueList(@Nullable final Iterable<? extends DATATYPE> aList) {
   super(ContainerHelper.newList(aList));
 }