/** * Checks if the given {@link SoftwareModuleType} is in * {@link #getOptionalModuleTypes()}. * * @param softwareModuleType * search for * @return <code>true</code> if found */ default boolean containsOptionalModuleType(final SoftwareModuleType softwareModuleType) { return containsOptionalModuleType(softwareModuleType.getId()); }
public static String softwareModuleTypesCreatableFieldsOnly(final List<SoftwareModuleType> types) throws JSONException { final StringBuilder builder = new StringBuilder(); builder.append("["); int i = 0; for (final SoftwareModuleType module : types) { builder.append(new JSONObject().put("name", module.getName()).put("description", module.getDescription()) .put("key", module.getKey()).put("maxAssignments", module.getMaxAssignments()).toString()); if (++i < types.size()) { builder.append(","); } } builder.append("]"); return builder.toString(); }
public boolean addModule(final SoftwareModule softwareModule) { if (modules == null) { modules = new HashSet<>(); } checkTypeCompatability(softwareModule); final Optional<SoftwareModule> found = modules.stream() .filter(module -> module.getId().equals(softwareModule.getId())).findAny(); if (found.isPresent()) { return false; } final long allready = modules.stream() .filter(module -> module.getType().getKey().equals(softwareModule.getType().getKey())).count(); if (allready >= softwareModule.getType().getMaxAssignments()) { modules.stream().filter(module -> module.getType().getKey().equals(softwareModule.getType().getKey())) .findAny().ifPresent(modules::remove); } if (modules.add(softwareModule)) { complete = type.checkComplete(this); return true; } return false; }
private void addSoftwareModulesToConsolidatedDsAssignmentMap(final DistributionSet distributionSet, final Set<SoftwareModule> softwareModules) { final Map<Long, Set<SoftwareModuleIdName>> assignmentMap = getConsolidatedAssignmentMap(distributionSet); for (final SoftwareModule softwareModule : softwareModules) { final SoftwareModuleIdName softwareModuleIdName = new SoftwareModuleIdName(softwareModule); final Long smTypeID = softwareModule.getType().getId(); assignmentMap.computeIfAbsent(smTypeID, key -> new HashSet<SoftwareModuleIdName>()); if (softwareModule.getType().getMaxAssignments() > 1) { // add application assignmentMap.get(smTypeID).add(softwareModuleIdName); } else if (softwareModule.getType().getMaxAssignments() == 1) { // replace firmware assignmentMap.get(smTypeID).clear(); assignmentMap.get(smTypeID).add(softwareModuleIdName); } publishAssignEvent(distributionSet.getId(), softwareModule); } }
@SuppressWarnings("unchecked") protected void createSourceTableData() { sourceTableContainer.removeAllItems(); final Iterable<SoftwareModuleType> moduleTypeBeans = softwareModuleTypeManagement .findAll(PageRequest.of(0, 1000)); Item saveTblitem; for (final SoftwareModuleType swTypeTag : moduleTypeBeans) { saveTblitem = sourceTableContainer.addItem(swTypeTag.getId()); saveTblitem.getItemProperty(DIST_TYPE_NAME).setValue(swTypeTag.getName()); saveTblitem.getItemProperty(DIST_TYPE_DESCRIPTION).setValue(swTypeTag.getDescription()); } }
static MgmtSoftwareModuleType toResponse(final SoftwareModuleType type) { final MgmtSoftwareModuleType result = new MgmtSoftwareModuleType(); MgmtRestModelMapper.mapNamedToNamed(result, type); result.setKey(type.getKey()); result.setMaxAssignments(type.getMaxAssignments()); result.setModuleId(type.getId()); result.setDeleted(type.isDeleted()); result.add(linkTo(methodOn(MgmtSoftwareModuleTypeRestApi.class).getSoftwareModuleType(result.getModuleId())) .withSelfRel()); return result; }
private JpaDistributionSetType setModuleType(final SoftwareModuleType smType, final boolean mandatory) { if (elements == null) { elements = new HashSet<>(); elements.add(new DistributionSetTypeElement(this, (JpaSoftwareModuleType) smType, mandatory)); return this; } // check if this was in the list before before final Optional<DistributionSetTypeElement> existing = elements.stream() .filter(element -> element.getSmType().getKey().equals(smType.getKey())).findAny(); if (existing.isPresent()) { existing.get().setMandatory(mandatory); } else { elements.add(new DistributionSetTypeElement(this, (JpaSoftwareModuleType) smType, mandatory)); } return this; }
@SuppressWarnings("unchecked") private void addTargetTableForUpdate(final SoftwareModuleType swModuleType, final boolean mandatory) { if (getTwinTables().getSelectedTableContainer() == null) { return; } final Item saveTblitem = getTwinTables().getSelectedTableContainer().addItem(swModuleType.getId()); getTwinTables().getSourceTable().removeItem(swModuleType.getId()); saveTblitem.getItemProperty(DistributionSetTypeSoftwareModuleSelectLayout.getDistTypeName()) .setValue(swModuleType.getName()); final CheckBox mandatoryCheckbox = new CheckBox("", mandatory); mandatoryCheckbox.setId(swModuleType.getName()); saveTblitem.getItemProperty(DistributionSetTypeSoftwareModuleSelectLayout.getDistTypeMandatory()) .setValue(mandatoryCheckbox); final Item originalItem = originalSelectedTableContainer.addItem(swModuleType.getId()); originalItem.getItemProperty(DistributionSetTypeSoftwareModuleSelectLayout.getDistTypeName()) .setValue(swModuleType.getName()); originalItem.getItemProperty(DistributionSetTypeSoftwareModuleSelectLayout.getDistTypeMandatory()) .setValue(mandatoryCheckbox); getWindow().updateAllComponents(mandatoryCheckbox); }
if (assignedSWModule.containsKey(module.getType().getName())) { if (module.getType().getMaxAssignments() > 1) { assignedSWModule.get(module.getType().getName()).append("</br>").append("<I>") .append(getUnsavedAssignedSwModule(module.getName(), module.getVersion())).append("</I>"); if (module.getType().getMaxAssignments() == 1) { assignedSWModule.put(module.getType().getName(), new StringBuilder().append("<I>") .append(getUnsavedAssignedSwModule(module.getName(), module.getVersion())).append("</I>")); assignedSWModule.put(module.getType().getName(), new StringBuilder().append("<I>") .append(getUnsavedAssignedSwModule(module.getName(), module.getVersion())).append("</I>"));
private static ProxyBaseSwModuleItem getProxyBean(final AssignedSoftwareModule customSoftwareModule) { final SoftwareModule bean = customSoftwareModule.getSoftwareModule(); final ProxyBaseSwModuleItem proxyItem = new ProxyBaseSwModuleItem(); proxyItem.setSwId(bean.getId()); final String swNameVersion = HawkbitCommonUtil.concatStrings(":", bean.getName(), bean.getVersion()); proxyItem.setNameAndVersion(swNameVersion); proxyItem.setCreatedDate(SPDateTimeUtil.getFormattedDate(bean.getCreatedAt())); proxyItem.setLastModifiedDate(SPDateTimeUtil.getFormattedDate(bean.getLastModifiedAt())); proxyItem.setName(bean.getName()); proxyItem.setVersion(bean.getVersion()); proxyItem.setVendor(bean.getVendor()); proxyItem.setDescription(bean.getDescription()); proxyItem.setCreatedByUser(UserDetailsFormatter.loadAndFormatCreatedBy(bean)); proxyItem.setModifiedByUser(UserDetailsFormatter.loadAndFormatLastModifiedBy(bean)); proxyItem.setAssigned(customSoftwareModule.isAssigned()); proxyItem.setColour(bean.getType().getColour()); proxyItem.setTypeId(bean.getType().getId()); return proxyItem; }
private JpaDistributionSetType setModuleType(final SoftwareModuleType smType, final boolean mandatory) { if (elements == null) { elements = new HashSet<>(); elements.add(new DistributionSetTypeElement(this, (JpaSoftwareModuleType) smType, mandatory)); return this; } // check if this was in the list before before final Optional<DistributionSetTypeElement> existing = elements.stream() .filter(element -> element.getSmType().getKey().equals(smType.getKey())).findAny(); if (existing.isPresent()) { existing.get().setMandatory(mandatory); } else { elements.add(new DistributionSetTypeElement(this, (JpaSoftwareModuleType) smType, mandatory)); } return this; }
@SuppressWarnings("unchecked") private void addTargetTableForUpdate(final SoftwareModuleType swModuleType, final boolean mandatory) { if (getTwinTables().getSelectedTableContainer() == null) { return; } final Item saveTblitem = getTwinTables().getSelectedTableContainer().addItem(swModuleType.getId()); getTwinTables().getSourceTable().removeItem(swModuleType.getId()); saveTblitem.getItemProperty(DistributionSetTypeSoftwareModuleSelectLayout.getDistTypeName()) .setValue(swModuleType.getName()); final CheckBox mandatoryCheckbox = new CheckBox("", mandatory); mandatoryCheckbox.setId(swModuleType.getName()); saveTblitem.getItemProperty(DistributionSetTypeSoftwareModuleSelectLayout.getDistTypeMandatory()) .setValue(mandatoryCheckbox); final Item originalItem = originalSelectedTableContainer.addItem(swModuleType.getId()); originalItem.getItemProperty(DistributionSetTypeSoftwareModuleSelectLayout.getDistTypeName()) .setValue(swModuleType.getName()); originalItem.getItemProperty(DistributionSetTypeSoftwareModuleSelectLayout.getDistTypeMandatory()) .setValue(mandatoryCheckbox); getWindow().updateAllComponents(mandatoryCheckbox); }
if (assignedSWModule.containsKey(module.getType().getName())) { if (module.getType().getMaxAssignments() > 1) { assignedSWModule.get(module.getType().getName()).append("</br>").append("<I>") .append(getUnsavedAssignedSwModule(module.getName(), module.getVersion())).append("</I>"); if (module.getType().getMaxAssignments() == 1) { assignedSWModule.put(module.getType().getName(), new StringBuilder().append("<I>") .append(getUnsavedAssignedSwModule(module.getName(), module.getVersion())).append("</I>")); assignedSWModule.put(module.getType().getName(), new StringBuilder().append("<I>") .append(getUnsavedAssignedSwModule(module.getName(), module.getVersion())).append("</I>"));
@SuppressWarnings("unchecked") protected void createSourceTableData() { sourceTableContainer.removeAllItems(); final Iterable<SoftwareModuleType> moduleTypeBeans = softwareModuleTypeManagement .findAll(new PageRequest(0, 1000)); Item saveTblitem; for (final SoftwareModuleType swTypeTag : moduleTypeBeans) { saveTblitem = sourceTableContainer.addItem(swTypeTag.getId()); saveTblitem.getItemProperty(DIST_TYPE_NAME).setValue(swTypeTag.getName()); saveTblitem.getItemProperty(DIST_TYPE_DESCRIPTION).setValue(swTypeTag.getDescription()); } }
private void addSoftwareModulesToConsolidatedDsAssignmentMap(final DistributionSet distributionSet, final Set<SoftwareModule> softwareModules) { final Map<Long, Set<SoftwareModuleIdName>> assignmentMap = getConsolidatedAssignmentMap(distributionSet); for (final SoftwareModule softwareModule : softwareModules) { final SoftwareModuleIdName softwareModuleIdName = new SoftwareModuleIdName(softwareModule); final Long smTypeID = softwareModule.getType().getId(); assignmentMap.computeIfAbsent(smTypeID, key -> new HashSet<SoftwareModuleIdName>()); if (softwareModule.getType().getMaxAssignments() > 1) { // add application assignmentMap.get(smTypeID).add(softwareModuleIdName); } else if (softwareModule.getType().getMaxAssignments() == 1) { // replace firmware assignmentMap.get(smTypeID).clear(); assignmentMap.get(smTypeID).add(softwareModuleIdName); } publishAssignEvent(distributionSet.getId(), softwareModule); } }
public boolean addModule(final SoftwareModule softwareModule) { if (modules == null) { modules = new HashSet<>(); } checkTypeCompatability(softwareModule); final Optional<SoftwareModule> found = modules.stream() .filter(module -> module.getId().equals(softwareModule.getId())).findAny(); if (found.isPresent()) { return false; } final long allready = modules.stream() .filter(module -> module.getType().getKey().equals(softwareModule.getType().getKey())).count(); if (allready >= softwareModule.getType().getMaxAssignments()) { modules.stream().filter(module -> module.getType().getKey().equals(softwareModule.getType().getKey())) .findAny().ifPresent(modules::remove); } if (modules.add(softwareModule)) { complete = type.checkComplete(this); return true; } return false; }
private static ProxyBaseSwModuleItem getProxyBean(final AssignedSoftwareModule customSoftwareModule) { final SoftwareModule bean = customSoftwareModule.getSoftwareModule(); final ProxyBaseSwModuleItem proxyItem = new ProxyBaseSwModuleItem(); proxyItem.setSwId(bean.getId()); final String swNameVersion = HawkbitCommonUtil.concatStrings(":", bean.getName(), bean.getVersion()); proxyItem.setNameAndVersion(swNameVersion); proxyItem.setCreatedDate(SPDateTimeUtil.getFormattedDate(bean.getCreatedAt())); proxyItem.setLastModifiedDate(SPDateTimeUtil.getFormattedDate(bean.getLastModifiedAt())); proxyItem.setName(bean.getName()); proxyItem.setVersion(bean.getVersion()); proxyItem.setVendor(bean.getVendor()); proxyItem.setDescription(bean.getDescription()); proxyItem.setCreatedByUser(UserDetailsFormatter.loadAndFormatCreatedBy(bean)); proxyItem.setModifiedByUser(UserDetailsFormatter.loadAndFormatLastModifiedBy(bean)); proxyItem.setAssigned(customSoftwareModule.isAssigned()); proxyItem.setColour(bean.getType().getColour()); proxyItem.setTypeId(bean.getType().getId()); return proxyItem; }
/** * Checks if the given {@link SoftwareModuleType} is in * {@link #getMandatoryModuleTypes()}. * * @param softwareModuleType * search for * @return <code>true</code> if found */ default boolean containsMandatoryModuleType(final SoftwareModuleType softwareModuleType) { return containsMandatoryModuleType(softwareModuleType.getId()); }