@SuppressWarnings("unchecked") @Override protected void updateEntity(final SoftwareModule baseEntity, final Item item) { final String swNameVersion = HawkbitCommonUtil.concatStrings(":", baseEntity.getName(), baseEntity.getVersion()); item.getItemProperty(SPUILabelDefinitions.NAME_VERSION).setValue(swNameVersion); item.getItemProperty("swId").setValue(baseEntity.getId()); item.getItemProperty(SPUILabelDefinitions.VAR_VENDOR).setValue(baseEntity.getVendor()); super.updateEntity(baseEntity, item); }
private DmfSoftwareModule convertToAmqpSoftwareModule(final Target target, final Entry<SoftwareModule, List<SoftwareModuleMetadata>> entry) { final DmfSoftwareModule amqpSoftwareModule = new DmfSoftwareModule(); amqpSoftwareModule.setModuleId(entry.getKey().getId()); amqpSoftwareModule.setModuleType(entry.getKey().getType().getKey()); amqpSoftwareModule.setModuleVersion(entry.getKey().getVersion()); amqpSoftwareModule.setArtifacts(convertArtifacts(target, entry.getKey().getArtifacts())); if (!CollectionUtils.isEmpty(entry.getValue())) { amqpSoftwareModule.setMetadata(convertMetadata(entry.getValue())); } return amqpSoftwareModule; }
private static boolean checkModule(final String fileName, final SoftwareModule module) { return null == module || !module.getArtifactByFilename(fileName).isPresent(); }
/** * Constructor. * * @param softwareModule * the softwareModule */ public SoftwareModuleIdName(final SoftwareModule softwareModule) { this(softwareModule.getId(), softwareModule.getName(), softwareModule.getVersion()); }
/** * Create Label for SW Module. * * @param labelName * as Name * @param swModule * as Module (JVM|OS|AH) * @return Label as UI */ private static Label getSWModlabel(final String labelName, final SoftwareModule swModule) { return SPUIComponentProvider.createNameValueLabel(labelName + " : ", swModule.getName(), swModule.getVersion()); }
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 ProxyBaseSoftwareModuleItem getProxyBean(final SoftwareModule bean) { final ProxyBaseSoftwareModuleItem proxy = new ProxyBaseSoftwareModuleItem(); proxy.setSwId(bean.getId()); final String swNameVersion = HawkbitCommonUtil.concatStrings(":", bean.getName(), bean.getVersion()); proxy.setNameAndVersion(swNameVersion); proxy.setCreatedDate(SPDateTimeUtil.getFormattedDate(bean.getCreatedAt())); proxy.setLastModifiedDate(SPDateTimeUtil.getFormattedDate(bean.getLastModifiedAt())); proxy.setName(bean.getName()); proxy.setVersion(bean.getVersion()); proxy.setVendor(bean.getVendor()); proxy.setDescription(bean.getDescription()); proxy.setCreatedByUser(UserDetailsFormatter.loadAndFormatCreatedBy(bean)); proxy.setModifiedByUser(UserDetailsFormatter.loadAndFormatLastModifiedBy(bean)); return proxy; }
protected boolean compareSoftwareModulesById(final SoftwareModule softwareModule, final Long selectedBaseSwModuleId) { if (softwareModule == null) { return false; } return softwareModule.getId().equals(selectedBaseSwModuleId); }
/** * fill the data of a softwareModule in the content of the window */ private void populateValuesOfSwModule() { if (baseSwModuleId == null) { return; } editSwModule = Boolean.TRUE; softwareModuleManagement.get(baseSwModuleId).ifPresent(swModule -> { nameTextField.setValue(swModule.getName()); versionTextField.setValue(swModule.getVersion()); vendorTextField.setValue(swModule.getVendor()); descTextArea.setValue(swModule.getDescription()); softwareModuleType = new LabelBuilder().name(swModule.getType().getName()).caption("Type").buildLabel(); }); }
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>"));
static MgmtSoftwareModule toResponse(final SoftwareModule softwareModule) { if (softwareModule == null) { return null; } final MgmtSoftwareModule response = new MgmtSoftwareModule(); MgmtRestModelMapper.mapNamedToNamed(response, softwareModule); response.setModuleId(softwareModule.getId()); response.setVersion(softwareModule.getVersion()); response.setType(softwareModule.getType().getKey()); response.setVendor(softwareModule.getVendor()); response.setDeleted(softwareModule.isDeleted()); response.add(linkTo(methodOn(MgmtSoftwareModuleRestApi.class).getSoftwareModule(response.getModuleId())) .withSelfRel()); return response; }
/** * Searches through modules for the given type. * * @param type * to search for * @return SoftwareModule of given type */ default Optional<SoftwareModule> findFirstModuleByType(final SoftwareModuleType type) { return getModules().stream().filter(module -> module.getType().equals(type)).findAny(); }
@Override // Exception squid:S3655 - Optional access is checked in checkModule // subroutine @SuppressWarnings("squid:S3655") public ResponseEntity<Void> downloadArtifactMd5(@PathVariable("tenant") final String tenant, @PathVariable("controllerId") final String controllerId, @PathVariable("softwareModuleId") final Long softwareModuleId, @PathVariable("fileName") final String fileName) { final Target target = controllerManagement.getByControllerId(controllerId) .orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId)); final SoftwareModule module = controllerManagement.getSoftwareModule(softwareModuleId) .orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, softwareModuleId)); if (checkModule(fileName, module)) { LOG.warn("Software module with id {} could not be found.", softwareModuleId); return ResponseEntity.notFound().build(); } final Artifact artifact = module.getArtifactByFilename(fileName) .orElseThrow(() -> new EntityNotFoundException(Artifact.class, fileName)); checkAndLogDownload(requestResponseContextHolder.getHttpServletRequest(), target, module.getId()); try { FileStreamingUtil.writeMD5FileResponse(requestResponseContextHolder.getHttpServletResponse(), artifact.getMd5Hash(), fileName); } catch (final IOException e) { LOG.error("Failed to stream MD5 File", e); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } return ResponseEntity.ok().build(); }
private void populateDetails() { if (getSelectedBaseEntity() != null) { String maxAssign; if (getSelectedBaseEntity().getType().getMaxAssignments() == 1) { maxAssign = getI18n().getMessage("label.singleAssign.type"); } else { maxAssign = getI18n().getMessage("label.multiAssign.type"); } updateSoftwareModuleDetailsLayout(getSelectedBaseEntity().getType().getName(), getSelectedBaseEntity().getVendor(), maxAssign); } else { updateSoftwareModuleDetailsLayout("", "", ""); } }
private void unassignSW(final ClickEvent event, final DistributionSet distributionSet, final Set<SoftwareModule> alreadyAssignedSwModules) { final SoftwareModule unAssignedSw = getSoftwareModule(event.getButton().getId(), alreadyAssignedSwModules); if (distributionSetManagement.isInUse(distributionSet.getId())) { uiNotification.displayValidationError(i18n.getMessage("message.error.notification.ds.target.assigned", distributionSet.getName(), distributionSet.getVersion())); } else { final DistributionSet newDistributionSet = distributionSetManagement .unassignSoftwareModule(distributionSet.getId(), unAssignedSw.getId()); manageDistUIState.setLastSelectedEntityId(newDistributionSet.getId()); eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.SELECTED_ENTITY, newDistributionSet)); eventBus.publish(this, DistributionsUIEvent.ORDER_BY_DISTRIBUTION); uiNotification.displaySuccess(i18n.getMessage("message.sw.unassigned", unAssignedSw.getName())); } }
/** * @param artifactId * to look for * @return found {@link Artifact} */ default Optional<Artifact> getArtifact(final Long artifactId) { return getArtifacts().stream().filter(artifact -> artifact.getId().equals(artifactId)).findAny(); }
public static String softwareModuleUpdatableFieldsOnly(final SoftwareModule module) throws JSONException { final StringBuilder builder = new StringBuilder(); builder.append(new JSONObject().put("description", module.getDescription()).put("vendor", module.getVendor()) .toString()); return builder.toString(); }
/** * @param value * @param alreadyAssignedSwModules * @return */ protected SoftwareModule getSoftwareModule(final String softwareModule, final Set<SoftwareModule> alreadyAssignedSwModules) { for (final SoftwareModule sw : alreadyAssignedSwModules) { if (softwareModule.equals(sw.getName())) { return sw; } } return null; }
private ProxyBaseSoftwareModuleItem getProxyBean(final SoftwareModule bean) { final ProxyBaseSoftwareModuleItem proxy = new ProxyBaseSoftwareModuleItem(); proxy.setSwId(bean.getId()); final String swNameVersion = HawkbitCommonUtil.concatStrings(":", bean.getName(), bean.getVersion()); proxy.setNameAndVersion(swNameVersion); proxy.setCreatedDate(SPDateTimeUtil.getFormattedDate(bean.getCreatedAt())); proxy.setLastModifiedDate(SPDateTimeUtil.getFormattedDate(bean.getLastModifiedAt())); proxy.setName(bean.getName()); proxy.setVersion(bean.getVersion()); proxy.setVendor(bean.getVendor()); proxy.setDescription(bean.getDescription()); proxy.setCreatedByUser(UserDetailsFormatter.loadAndFormatCreatedBy(bean)); proxy.setModifiedByUser(UserDetailsFormatter.loadAndFormatLastModifiedBy(bean)); return proxy; }