Ejemplo n.º 1
0
  private boolean checkAndHandleIfVisibleDsSwitchesFromCompleteToIncomplete(
      final List<DistributionSetUpdateEvent> events,
      final List<DistributionSetIdName> visibleItemIds) {
    final List<DistributionSet> setsThatAreVisibleButNotCompleteAnymore =
        events
            .stream()
            .map(event -> event.getEntity())
            .filter(set -> !set.isComplete())
            .filter(set -> visibleItemIds.contains(DistributionSetIdName.generate(set)))
            .collect(Collectors.toList());

    if (!setsThatAreVisibleButNotCompleteAnymore.isEmpty()) {
      refreshDistributions();

      if (setsThatAreVisibleButNotCompleteAnymore
          .stream()
          .anyMatch(
              set -> set.getId().equals(managementUIState.getLastSelectedDsIdName().getId()))) {
        managementUIState.setLastSelectedDistribution(null);
        managementUIState.setLastSelectedEntity(null);
      }

      return true;
    }

    return false;
  }
Ejemplo n.º 2
0
 @Override
 protected Object getItemIdToSelect() {
   if (managementUIState.getSelectedDsIdName().isPresent()) {
     return managementUIState.getSelectedDsIdName().get();
   }
   return null;
 }
Ejemplo n.º 3
0
 private void rePinDistribution(final Button pinBtn, final Long distID) {
   if (managementUIState.getTargetTableFilters().getPinnedDistId().isPresent()
       && distID.equals(managementUIState.getTargetTableFilters().getPinnedDistId().get())) {
     applyPinStyle(pinBtn);
     isDistPinned = Boolean.TRUE;
     distributinPinnedBtn = pinBtn;
     eventBus.publish(this, PinUnpinEvent.PIN_DISTRIBUTION);
   }
 }
Ejemplo n.º 4
0
  private void displayTargetCountStatus() {
    final TargetTableFilters targFilParams = managementUIState.getTargetTableFilters();
    final StringBuilder message = getTotalTargetMessage();

    if (targFilParams.hasFilter()) {
      message.append(HawkbitCommonUtil.SP_STRING_PIPE);
      message.append(i18n.get("label.filter.targets"));
      if (managementUIState.getTargetsTruncated() != null) {
        message.append(targetTable.size() + managementUIState.getTargetsTruncated());
      } else {
        message.append(targetTable.size());
      }
      message.append(HawkbitCommonUtil.SP_STRING_PIPE);
      final String status = i18n.get("label.filter.status");
      final String overdue = i18n.get("label.filter.overdue");
      final String tags = i18n.get("label.filter.tags");
      final String text = i18n.get("label.filter.text");
      final String dists = i18n.get("label.filter.dist");
      final String custom = i18n.get("label.filter.custom");
      final StringBuilder filterMesgBuf = new StringBuilder(i18n.get("label.filter"));
      filterMesgBuf.append(HawkbitCommonUtil.SP_STRING_SPACE);
      filterMesgBuf.append(getStatusMsg(targFilParams.getClickedStatusTargetTags(), status));
      filterMesgBuf.append(getOverdueStateMsg(targFilParams.isOverdueFilterEnabled(), overdue));
      filterMesgBuf.append(
          getTagsMsg(targFilParams.isNoTagSelected(), targFilParams.getClickedTargetTags(), tags));
      filterMesgBuf.append(
          targFilParams
              .getSearchText()
              .map(search -> text)
              .orElse(HawkbitCommonUtil.SP_STRING_SPACE));
      filterMesgBuf.append(
          targFilParams
              .getDistributionSet()
              .map(set -> dists)
              .orElse(HawkbitCommonUtil.SP_STRING_SPACE));
      filterMesgBuf.append(
          targFilParams
              .getTargetFilterQuery()
              .map(query -> custom)
              .orElse(HawkbitCommonUtil.SP_STRING_SPACE));
      final String filterMesageChk = filterMesgBuf.toString().trim();
      String filterMesage = filterMesageChk;
      if (filterMesage.endsWith(",")) {
        filterMesage = filterMesageChk.substring(0, filterMesageChk.length() - 1);
      }
      message.append(filterMesage);
    }

    if ((targetTable.size() + Optional.fromNullable(managementUIState.getTargetsTruncated()).or(0L))
        > SPUIDefinitions.MAX_TABLE_ENTRIES) {
      message.append(HawkbitCommonUtil.SP_STRING_PIPE);
      message.append(i18n.get("label.filter.shown"));
      message.append(SPUIDefinitions.MAX_TABLE_ENTRIES);
    }

    setCaption(message.toString());
  }
Ejemplo n.º 5
0
 private void showOrHidePopupAndNotification(final String message) {
   if (null != managementUIState.getAssignedList()
       && !managementUIState.getAssignedList().isEmpty()) {
     eventBus.publish(this, ManagementUIEvent.UPDATE_COUNT);
   }
   if (null != message) {
     uiNotification.displayValidationError(message);
   }
 }
Ejemplo n.º 6
0
 /**
  * TenantAwareEvent Listener for Pinning Distribution.
  *
  * @param event
  */
 @EventBusListenerMethod(scope = EventScope.UI)
 public void onEvent(final PinUnpinEvent event) {
   if (event == PinUnpinEvent.PIN_DISTRIBUTION
       && managementUIState.getTargetTableFilters().getPinnedDistId().isPresent()) {
     displayCountLabel(managementUIState.getTargetTableFilters().getPinnedDistId().get());
   } else {
     setValue("");
     displayTargetCountStatus();
   }
 }
Ejemplo n.º 7
0
 private void saveDistributionPinnedBtn(final Button pinBtn) {
   if (managementUIState.getTargetTableFilters().getPinnedDistId().isPresent()
       && managementUIState
           .getTargetTableFilters()
           .getPinnedDistId()
           .get()
           .equals(((DistributionSetIdName) pinBtn.getData()).getId())) {
     setDistributinPinnedBtn(pinBtn);
   }
 }
Ejemplo n.º 8
0
 /*
  * (non-Javadoc)
  *
  * @see
  * com.vaadin.ui.TabSheet.SelectedTabChangeListener#selectedTabChange(com
  * .vaadin.ui.TabSheet.SelectedTabChangeEvent)
  */
 @Override
 public void selectedTabChange(final SelectedTabChangeEvent event) {
   if (i18n.get("caption.filter.simple").equals(getSelectedTab().getCaption())) {
     managementUIState.setCustomFilterSelected(false);
     eventBus.publish(this, ManagementUIEvent.RESET_TARGET_FILTER_QUERY);
   } else {
     managementUIState.setCustomFilterSelected(true);
     eventBus.publish(this, ManagementUIEvent.RESET_SIMPLE_FILTERS);
   }
 }
Ejemplo n.º 9
0
 private void switchToTabSelectedOnLoad() {
   if (managementUIState.isCustomFilterSelected()) {
     this.setSelectedTab(targetFilterQueryButtonsTab);
   } else {
     this.setSelectedTab(simpleFilterTab);
   }
 }
Ejemplo n.º 10
0
  @EventBusListenerMethod(scope = EventScope.SESSION)
  void onDistributionSetUpdateEvents(final DistributionSetUpdatedEventContainer eventContainer) {

    final List<DistributionSetIdName> visibleItemIds =
        (List<DistributionSetIdName>) getVisibleItemIds();

    if (allOfThemAffectCompletedSetsThatAreNotVisible(eventContainer.getEvents(), visibleItemIds)) {
      refreshDistributions();
    } else if (!checkAndHandleIfVisibleDsSwitchesFromCompleteToIncomplete(
        eventContainer.getEvents(), visibleItemIds)) {
      updateVisableTableEntries(eventContainer.getEvents(), visibleItemIds);
    }

    final DistributionSetIdName lastSelectedDsIdName = managementUIState.getLastSelectedDsIdName();
    // refresh the details tabs only if selected ds is updated
    if (lastSelectedDsIdName != null) {
      final Optional<DistributionSet> selectedSetUpdated =
          eventContainer
              .getEvents()
              .stream()
              .map(event -> event.getEntity())
              .filter(set -> set.getId().equals(lastSelectedDsIdName.getId()))
              .findFirst();

      if (selectedSetUpdated.isPresent()) {
        // update table row+details layout
        eventBus.publish(
            this,
            new DistributionTableEvent(
                BaseEntityEventType.SELECTED_ENTITY, selectedSetUpdated.get()));
      }
    }
  }
Ejemplo n.º 11
0
  private void assignDsTag(final DragAndDropEvent event) {
    final com.vaadin.event.dd.TargetDetails taregtDet = event.getTargetDetails();
    final Table distTable = (Table) taregtDet.getTarget();
    final Set<DistributionSetIdName> distsSelected = getTableValue(distTable);
    final Set<Long> distList = new HashSet<>();

    final AbstractSelectTargetDetails dropData =
        (AbstractSelectTargetDetails) event.getTargetDetails();
    final Object distItemId = dropData.getItemIdOver();

    if (!distsSelected.contains(distItemId)) {
      distList.add(((DistributionSetIdName) distItemId).getId());
    } else {
      distList.addAll(distsSelected.stream().map(t -> t.getId()).collect(Collectors.toList()));
    }

    final String distTagName =
        HawkbitCommonUtil.removePrefix(
            event.getTransferable().getSourceComponent().getId(),
            SPUIDefinitions.DISTRIBUTION_TAG_ID_PREFIXS);

    final DistributionSetTagAssignmentResult result =
        distributionSetManagement.toggleTagAssignment(distList, distTagName);

    uiNotification.displaySuccess(
        HawkbitCommonUtil.createAssignmentMessage(distTagName, result, i18n));
    if (result.getAssigned() >= 1
        && managementUIState.getDistributionTableFilters().isNoTagSelected()) {
      refreshFilter();
    }
  }
Ejemplo n.º 12
0
  private StringBuilder getTotalTargetMessage() {
    if (managementUIState.getTargetsTruncated() != null) {
      // set the icon
      setIcon(FontAwesome.INFO_CIRCLE);
      setDescription(
          i18n.get(
              "label.target.filter.truncated",
              managementUIState.getTargetsTruncated(),
              SPUIDefinitions.MAX_TABLE_ENTRIES));
    } else {
      setIcon(null);
      setDescription(null);
    }

    final StringBuilder message = new StringBuilder(i18n.get("label.target.filter.count"));
    message.append(managementUIState.getTargetsCountAll());

    return message;
  }
Ejemplo n.º 13
0
  private void pinDitribution(final Button eventBtn) {

    /* if distribution set is pinned ,unpin target if pinned */
    managementUIState.getDistributionTableFilters().setPinnedTargetId(null);
    /* Dist table restyle */
    eventBus.publish(this, PinUnpinEvent.PIN_DISTRIBUTION);
    applyPinStyle(eventBtn);
    styleDistributionSetTable();
    isDistPinned = Boolean.FALSE;
  }
Ejemplo n.º 14
0
  private void checkifAlreadyPinned(final Button eventBtn) {
    final Long newPinnedDistItemId = ((DistributionSetIdName) eventBtn.getData()).getId();
    Long pinnedDistId = null;
    if (managementUIState.getTargetTableFilters().getPinnedDistId().isPresent()) {
      pinnedDistId = managementUIState.getTargetTableFilters().getPinnedDistId().get();
    }
    if (pinnedDistId == null) {
      isDistPinned = !isDistPinned;
      managementUIState.getTargetTableFilters().setPinnedDistId(newPinnedDistItemId);
    } else if (newPinnedDistItemId.equals(pinnedDistId)) {
      isDistPinned = Boolean.FALSE;
    } else {
      isDistPinned = true;
      managementUIState.getTargetTableFilters().setPinnedDistId(newPinnedDistItemId);
      distributinPinnedBtn.setStyleName(getPinStyle());
    }

    distributinPinnedBtn = eventBtn;
  }
Ejemplo n.º 15
0
 private Map<String, Object> prepareQueryConfigFilters() {
   final Map<String, Object> queryConfig = Maps.newHashMapWithExpectedSize(4);
   managementUIState
       .getDistributionTableFilters()
       .getSearchText()
       .ifPresent(value -> queryConfig.put(SPUIDefinitions.FILTER_BY_TEXT, value));
   managementUIState
       .getDistributionTableFilters()
       .getPinnedTargetId()
       .ifPresent(value -> queryConfig.put(SPUIDefinitions.ORDER_BY_PINNED_TARGET, value));
   final List<String> list = new ArrayList<>();
   queryConfig.put(
       SPUIDefinitions.FILTER_BY_NO_TAG,
       managementUIState.getDistributionTableFilters().isNoTagSelected());
   if (!managementUIState.getDistributionTableFilters().getDistSetTags().isEmpty()) {
     list.addAll(managementUIState.getDistributionTableFilters().getDistSetTags());
   }
   queryConfig.put(SPUIDefinitions.FILTER_BY_TAG, list);
   return queryConfig;
 }
Ejemplo n.º 16
0
 private String validate(
     final Set<TargetIdName> targetDetailsList,
     final DistributionSetIdName distributionSetIdName) {
   String pendingActionMessage = null;
   for (final TargetIdName trgtNameId : targetDetailsList) {
     if (null != trgtNameId) {
       if (managementUIState.getAssignedList().keySet().contains(trgtNameId)
           && managementUIState.getAssignedList().get(trgtNameId).equals(distributionSetIdName)) {
         pendingActionMessage =
             getPendingActionMessage(
                 pendingActionMessage,
                 trgtNameId.getControllerId(),
                 HawkbitCommonUtil.getDistributionNameAndVersion(
                     distributionSetIdName.getName(), distributionSetIdName.getVersion()));
       } else {
         managementUIState.getAssignedList().put(trgtNameId, distributionSetIdName);
       }
     }
   }
   return pendingActionMessage;
 }
Ejemplo n.º 17
0
 @Override
 protected void publishEntityAfterValueChange(final DistributionSet selectedLastEntity) {
   eventBus.publish(
       this, new DistributionTableEvent(BaseEntityEventType.SELECTED_ENTITY, selectedLastEntity));
   if (selectedLastEntity != null) {
     managementUIState.setLastSelectedDistribution(
         new DistributionSetIdName(
             selectedLastEntity.getId(),
             selectedLastEntity.getName(),
             selectedLastEntity.getVersion()));
   }
 }
Ejemplo n.º 18
0
  private void styleDistributionTableOnPinning() {
    if (!managementUIState.getDistributionTableFilters().getPinnedTargetId().isPresent()) {
      return;
    }

    final Target targetObj =
        targetService.findTargetByControllerIDWithDetails(
            managementUIState.getDistributionTableFilters().getPinnedTargetId().get());

    if (targetObj != null) {
      final DistributionSet assignedDistribution = targetObj.getAssignedDistributionSet();
      final DistributionSet installedDistribution =
          targetObj.getTargetInfo().getInstalledDistributionSet();
      Long installedDistId = null;
      Long assignedDistId = null;
      if (null != installedDistribution) {
        installedDistId = installedDistribution.getId();
      }
      if (null != assignedDistribution) {
        assignedDistId = assignedDistribution.getId();
      }
      styleDistributionSetTable(installedDistId, assignedDistId);
    }
  }
Ejemplo n.º 19
0
 @Override
 protected void setDataAvailable(final boolean available) {
   managementUIState.setNoDataAvailableDistribution(!available);
 }
Ejemplo n.º 20
0
 private void unPinDistribution(final Button eventBtn) {
   managementUIState.getTargetTableFilters().setPinnedDistId(null);
   eventBus.publish(this, PinUnpinEvent.UNPIN_DISTRIBUTION);
   resetPinStyle(eventBtn);
 }
Ejemplo n.º 21
0
 @Override
 protected boolean isMaximized() {
   return managementUIState.isDsTableMaximized();
 }
Ejemplo n.º 22
0
 @Override
 protected boolean isFirstRowSelectedOnLoad() {
   return !managementUIState.getSelectedDsIdName().isPresent()
       || managementUIState.getSelectedDsIdName().get().isEmpty();
 }