hawkBit repository uses Optional on single entity find/get requests (#435)

* Repo returns optionals.
* Improved exception handling for collection usage in repo queries.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
Kai Zimmermann
2017-02-16 10:09:14 +01:00
committed by GitHub
parent d21af83804
commit 804522f966
232 changed files with 2104 additions and 2377 deletions

View File

@@ -1,57 +0,0 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.ui;
import org.eclipse.hawkbit.repository.event.TenantAwareEvent;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.vaadin.spring.events.EventBus;
import com.vaadin.server.VaadinSession;
import com.vaadin.ui.UI;
import com.vaadin.util.CurrentInstance;
/**
* A {@link Runnable} implementation for the {@link UI#access(Runnable)} to
* dispatch events to the UI in the UI thread.
*/
public class DispatcherRunnable implements Runnable {
private final SecurityContext userContext;
private final TenantAwareEvent event;
private final VaadinSession session;
private final EventBus eventBus;
/**
* @param eventBus
* the event bus to distribute the event to
* @param session
* the current Vaadin session
* @param userContext
* the context of the currently logged in user to distribute the
* event to
* @param event
* the event which is distributed to the UI.
*/
public DispatcherRunnable(final EventBus eventBus, final VaadinSession session, final SecurityContext userContext,
final TenantAwareEvent event) {
this.eventBus = eventBus;
this.session = session;
this.userContext = userContext;
this.event = event;
}
@Override
public void run() {
CurrentInstance.setCurrent(session.getUIs().iterator().next());
CurrentInstance.setCurrent(session);
SecurityContextHolder.setContext(userContext);
eventBus.publish(this, event);
}
}

View File

@@ -16,8 +16,8 @@ package org.eclipse.hawkbit.ui.artifacts.event;
public class UploadStatusEvent {
/**
* TenantAwareEvent type definition of events during the artifact upload life-cycle
* from receiving the upload until the process end.
* TenantAwareEvent type definition of events during the artifact upload
* life-cycle from receiving the upload until the process end.
*/
public enum UploadStatusEventType {
RECEIVE_UPLOAD, UPLOAD_FAILED, UPLOAD_IN_PROGRESS, UPLOAD_STARTED, UPLOAD_FINISHED, UPLOAD_SUCCESSFUL, UPLOAD_STREAMING_FAILED, UPLOAD_STREAMING_FINISHED, ABORT_UPLOAD

View File

@@ -240,7 +240,7 @@ public class UploadViewConfirmationWindowLayout extends AbstractConfirmationWind
for (final String swModuleTypeName : artifactUploadState.getSelectedDeleteSWModuleTypes()) {
softwareManagement.deleteSoftwareModuleType(
softwareManagement.findSoftwareModuleTypeByName(swModuleTypeName).getId());
softwareManagement.findSoftwareModuleTypeByName(swModuleTypeName).get().getId());
}
addToConsolitatedMsg(FontAwesome.TASKS.getHtml() + SPUILabelDefinitions.HTML_SPACE
+ i18n.get("message.sw.module.type.delete", new Object[] { deleteSWModuleTypeCount }));

View File

@@ -225,7 +225,7 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent {
final String type = typeComboBox.getValue() != null ? typeComboBox.getValue().toString() : null;
final SoftwareModuleCreate softwareModule = entityFactory.softwareModule().create()
.type(softwareManagement.findSoftwareModuleTypeByName(type)).name(name).version(version)
.type(softwareManagement.findSoftwareModuleTypeByName(type).get()).name(name).version(version)
.description(description).vendor(vendor);
final SoftwareModule newSoftwareModule = softwareManagement.createSoftwareModule(softwareModule);
@@ -243,10 +243,9 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent {
final String type = typeComboBox.getValue() != null ? typeComboBox.getValue().toString() : null;
final SoftwareManagement swMgmtService = SpringContextHelper.getBean(SoftwareManagement.class);
final SoftwareModule swModule = swMgmtService.findSoftwareModuleByNameAndVersion(name, version,
swMgmtService.findSoftwareModuleTypeByName(type).getId());
if (swModule != null) {
if (swMgmtService.findSoftwareModuleByNameAndVersion(name, version,
swMgmtService.findSoftwareModuleTypeByName(type).get().getId()).isPresent()) {
uiNotifcation.displayValidationError(
i18n.get("message.duplicate.softwaremodule", new Object[] { name, version }));
return true;
@@ -276,7 +275,7 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent {
return;
}
editSwModule = Boolean.TRUE;
final SoftwareModule swModule = softwareManagement.findSoftwareModuleById(baseSwModuleId);
final SoftwareModule swModule = softwareManagement.findSoftwareModuleById(baseSwModuleId).get();
nameTextField.setValue(swModule.getName());
versionTextField.setValue(swModule.getVersion());
vendorTextField.setValue(HawkbitCommonUtil.trimAndNullIfEmpty(swModule.getVendor()));

View File

@@ -201,7 +201,7 @@ public class SoftwareModuleDetails extends AbstractNamedVersionedEntityTableDeta
@Override
protected void showMetadata(final ClickEvent event) {
final SoftwareModule swmodule = softwareManagement.findSoftwareModuleById(getSelectedBaseEntityId());
final SoftwareModule swmodule = softwareManagement.findSoftwareModuleById(getSelectedBaseEntityId()).get();
/* display the window */
UI.getCurrent().addWindow(swMetadataPopupLayout.getWindow(swmodule, null));
}

View File

@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.ui.artifacts.smtable;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.eclipse.hawkbit.repository.SoftwareManagement;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
@@ -148,7 +149,7 @@ public class SoftwareModuleTable extends AbstractNamedVersionTable<SoftwareModul
}
@Override
protected SoftwareModule findEntityByTableValue(final Long entityTableId) {
protected Optional<SoftwareModule> findEntityByTableValue(final Long entityTableId) {
return softwareManagement.findSoftwareModuleById(entityTableId);
}
@@ -259,7 +260,7 @@ public class SoftwareModuleTable extends AbstractNamedVersionTable<SoftwareModul
}
private void showMetadataDetails(final Long itemId) {
final SoftwareModule swmodule = softwareManagement.findSoftwareModuleById(itemId);
final SoftwareModule swmodule = softwareManagement.findSoftwareModuleById(itemId).get();
/* display the window */
UI.getCurrent().addWindow(swMetadataPopupLayout.getWindow(swmodule, null));
}

View File

@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.ui.artifacts.smtype;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.hawkbit.repository.EntityFactory;
@@ -119,10 +120,11 @@ public class CreateUpdateSoftwareTypeLayout extends CreateUpdateTypeLayout<Softw
@Override
protected Color getColorForColorPicker() {
final SoftwareModuleType typeSelected = swTypeManagementService
final Optional<SoftwareModuleType> typeSelected = swTypeManagementService
.findSoftwareModuleTypeByName(tagNameComboBox.getValue().toString());
if (null != typeSelected) {
return typeSelected.getColour() != null ? ColorPickerHelper.rgbToColorConverter(typeSelected.getColour())
if (typeSelected.isPresent()) {
return typeSelected.get().getColour() != null
? ColorPickerHelper.rgbToColorConverter(typeSelected.get().getColour())
: ColorPickerHelper.rgbToColorConverter(ColorPickerConstants.DEFAULT_COLOR);
}
return ColorPickerHelper.rgbToColorConverter(ColorPickerConstants.DEFAULT_COLOR);
@@ -195,9 +197,7 @@ public class CreateUpdateSoftwareTypeLayout extends CreateUpdateTypeLayout<Softw
@Override
protected void setTagDetails(final String targetTagSelected) {
tagName.setValue(targetTagSelected);
final SoftwareModuleType selectedTypeTag = swTypeManagementService
.findSoftwareModuleTypeByName(targetTagSelected);
if (null != selectedTypeTag) {
swTypeManagementService.findSoftwareModuleTypeByName(targetTagSelected).ifPresent(selectedTypeTag -> {
tagDesc.setValue(selectedTypeTag.getDescription());
typeKey.setValue(selectedTypeTag.getKey());
if (selectedTypeTag.getMaxAssignments() == 1) {
@@ -206,7 +206,7 @@ public class CreateUpdateSoftwareTypeLayout extends CreateUpdateTypeLayout<Softw
assignOptiongroup.setValue(multiAssignStr);
}
setColorPickerComponentsColor(selectedTypeTag.getColour());
}
});
}
private void singleMultiOptionGroup() {
@@ -236,12 +236,12 @@ public class CreateUpdateSoftwareTypeLayout extends CreateUpdateTypeLayout<Softw
}
@Override
protected SoftwareModuleType findEntityByKey() {
protected Optional<SoftwareModuleType> findEntityByKey() {
return swTypeManagementService.findSoftwareModuleTypeByKey(typeKey.getValue());
}
@Override
protected SoftwareModuleType findEntityByName() {
protected Optional<SoftwareModuleType> findEntityByName() {
return swTypeManagementService.findSoftwareModuleTypeByName(tagName.getValue());
}

View File

@@ -49,7 +49,7 @@ public class SMTypeFilterButtonClick extends AbstractFilterSingleButtonClick imp
@Override
protected void filterClicked(final Button clickedButton) {
final SoftwareModuleType softwareModuleType = softwareManagement
.findSoftwareModuleTypeByName(clickedButton.getData().toString());
.findSoftwareModuleTypeByName(clickedButton.getData().toString()).get();
artifactUploadState.getSoftwareModuleFilters().setSoftwareModuleType(softwareModuleType);
eventBus.publish(this, SMFilterEvent.FILTER_BY_TYPE);
}

View File

@@ -41,7 +41,7 @@ public class SMTypeFilterButtons extends AbstractFilterButtons {
private final ArtifactUploadState artifactUploadState;
private final UploadViewClientCriterion uploadViewClientCriterion;
SMTypeFilterButtons(final UIEventBus eventBus, final ArtifactUploadState artifactUploadState,
final UploadViewClientCriterion uploadViewClientCriterion, final SoftwareManagement softwareManagement) {
super(eventBus, new SMTypeFilterButtonClick(eventBus, artifactUploadState, softwareManagement));

View File

@@ -17,6 +17,7 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import org.eclipse.hawkbit.repository.ArtifactManagement;
import org.eclipse.hawkbit.repository.exception.ArtifactUploadFailedException;
@@ -196,8 +197,8 @@ public class UploadConfirmationWindow implements Button.ClickListener {
final Item item = uploadDetailsTable.getItem(itemId);
if (HawkbitCommonUtil.trimAndNullIfEmpty(fileName) != null) {
final Long baseSwId = (Long) item.getItemProperty(BASE_SOFTWARE_ID).getValue();
final List<Artifact> artifactList = artifactManagement.findByFilenameAndSoftwareModule(fileName, baseSwId);
if (!artifactList.isEmpty()) {
final Optional<Artifact> artifact = artifactManagement.findByFilenameAndSoftwareModule(fileName, baseSwId);
if (artifact.isPresent()) {
warningIconLabel.setVisible(true);
if (isErrorIcon(warningIconLabel)) {
warningIconLabel.removeStyleName(SPUIStyleDefinitions.ERROR_LABEL);
@@ -438,11 +439,11 @@ public class UploadConfirmationWindow implements Button.ClickListener {
final Label errorLabel, final String oldFileName, final Long currentSwId) {
if (warningLabel == null && (errorLabelCount > 1 || (duplicateCount == 1 && errorLabelCount == 1))) {
final List<Artifact> artifactList = artifactManagement.findByFilenameAndSoftwareModule(oldFileName,
final Optional<Artifact> artifactList = artifactManagement.findByFilenameAndSoftwareModule(oldFileName,
currentSwId);
errorLabel.removeStyleName(SPUIStyleDefinitions.ERROR_LABEL);
errorLabel.setDescription(i18n.get(ALREADY_EXISTS_MSG));
if (artifactList.isEmpty()) {
if (!artifactList.isPresent()) {
errorLabel.setVisible(false);
}
redErrorLabelCount--;

View File

@@ -12,7 +12,6 @@ import java.util.List;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.MetaData;
import org.eclipse.hawkbit.repository.model.NamedVersionedEntity;
import org.eclipse.hawkbit.ui.SpPermissionChecker;
@@ -162,7 +161,7 @@ public abstract class AbstractMetadataPopupLayout<E extends NamedVersionedEntity
this.selectedEntity = selectedEntity;
}
protected abstract void checkForDuplicate(E entity, String value);
protected abstract boolean checkForDuplicate(E entity, String value);
protected abstract M createMetadata(E entity, String key, String value);
@@ -422,12 +421,10 @@ public abstract class AbstractMetadataPopupLayout<E extends NamedVersionedEntity
}
private boolean duplicateCheck(final E entity) {
try {
checkForDuplicate(entity, keyTextField.getValue());
// we do not want to log the exception here, does not make sense
} catch (@SuppressWarnings("squid:S1166") final EntityNotFoundException exception) {
if (!checkForDuplicate(entity, keyTextField.getValue())) {
return false;
}
uiNotification.displayValidationError(i18n.get("message.metadata.duplicate.check", keyTextField.getValue()));
return true;
}
@@ -458,9 +455,7 @@ public abstract class AbstractMetadataPopupLayout<E extends NamedVersionedEntity
private void onRowClick(final SelectionEvent event) {
final Set<Object> itemsSelected = event.getSelected();
if (!itemsSelected.isEmpty()) {
final Object itemSelected = itemsSelected.stream().findFirst().isPresent()
? itemsSelected.stream().findFirst().get() : null;
popualateKeyValue(itemSelected);
popualateKeyValue(itemsSelected.iterator().next());
addIcon.setEnabled(true);
} else {
keyTextField.clear();

View File

@@ -9,6 +9,7 @@
package org.eclipse.hawkbit.ui.common.detailslayout;
import java.util.List;
import java.util.Optional;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.EntityFactory;
@@ -22,6 +23,7 @@ import org.eclipse.hawkbit.ui.utils.I18N;
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider;
import org.eclipse.hawkbit.ui.utils.UINotification;
import org.springframework.data.domain.PageRequest;
import com.vaadin.data.Item;
import com.vaadin.data.util.IndexedContainer;
@@ -83,7 +85,8 @@ public class DistributionSetMetadatadetailslayout extends Table {
}
selectedDistSetId = distributionSet.getId();
final List<DistributionSetMetadata> dsMetadataList = distributionSetManagement
.findDistributionSetMetadataByDistributionSetId(selectedDistSetId);
.findDistributionSetMetadataByDistributionSetId(selectedDistSetId, new PageRequest(0, 500))
.getContent();
if (null != dsMetadataList && !dsMetadataList.isEmpty()) {
dsMetadataList.forEach(dsMetadata -> setDSMetadataProperties(dsMetadata));
}
@@ -108,7 +111,7 @@ public class DistributionSetMetadatadetailslayout extends Table {
private IndexedContainer getDistSetContainer() {
final IndexedContainer container = new IndexedContainer();
container.addContainerProperty(METADATA_KEY, String.class, "");
setColumnExpandRatio(METADATA_KEY, 0.7f);
setColumnExpandRatio(METADATA_KEY, 0.7F);
setColumnAlignment(METADATA_KEY, Align.LEFT);
if (permissionChecker.hasUpdateDistributionPermission()) {
@@ -148,15 +151,15 @@ public class DistributionSetMetadatadetailslayout extends Table {
}
private void showMetadataDetails(final Long selectedDistSetId, final String metadataKey) {
final DistributionSet distSet = distributionSetManagement.findDistributionSetById(selectedDistSetId);
if (distSet == null) {
final Optional<DistributionSet> distSet = distributionSetManagement.findDistributionSetById(selectedDistSetId);
if (!distSet.isPresent()) {
notification.displayWarning(i18n.get("distributionset.not.exists"));
return;
}
/* display the window */
UI.getCurrent()
.addWindow(dsMetadataPopupLayout.getWindow(distSet, entityFactory.generateMetadata(metadataKey, "")));
UI.getCurrent().addWindow(
dsMetadataPopupLayout.getWindow(distSet.get(), entityFactory.generateMetadata(metadataKey, "")));
}
}

View File

@@ -174,7 +174,7 @@ public class SoftwareModuleMetadatadetailslayout extends Table {
}
private void showMetadataDetails(final Long selectedSWModuleId, final String metadataKey) {
final SoftwareModule swmodule = softwareManagement.findSoftwareModuleById(selectedSWModuleId);
final SoftwareModule swmodule = softwareManagement.findSoftwareModuleById(selectedSWModuleId).get();
/* display the window */
UI.getCurrent()
.addWindow(swMetadataPopupLayout.getWindow(swmodule, entityFactory.generateMetadata(metadataKey, "")));

View File

@@ -12,6 +12,8 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
@@ -99,7 +101,7 @@ public abstract class AbstractTable<E extends NamedEntity, I> extends Table impl
if (values == null) {
values = Collections.emptySet();
}
return values.stream().filter(item -> item != null).collect(Collectors.toSet());
return values.stream().filter(Objects::nonNull).collect(Collectors.toSet());
}
private void onValueChange() {
@@ -107,14 +109,15 @@ public abstract class AbstractTable<E extends NamedEntity, I> extends Table impl
final Set<I> values = getTableValue(this);
E entity = null;
I lastId = null;
if (!values.isEmpty()) {
lastId = Iterables.getLast(values);
entity = findEntityByTableValue(lastId);
}
setManagementEntitiyStateValues(values, lastId);
publishEntityAfterValueChange(entity);
if (lastId != null) {
findEntityByTableValue(lastId).ifPresent(this::publishEntityAfterValueChange);
}
}
protected void setManagementEntitiyStateValues(final Set<I> values, final I lastId) {
@@ -255,7 +258,7 @@ public abstract class AbstractTable<E extends NamedEntity, I> extends Table impl
return ids;
}
protected abstract E findEntityByTableValue(I lastSelectedId);
protected abstract Optional<E> findEntityByTableValue(I lastSelectedId);
protected abstract void publishEntityAfterValueChange(E selectedLastEntity);

View File

@@ -252,7 +252,7 @@ public abstract class AbstractTagToken<T extends BaseEntity> implements Serializ
}
protected Long getTagIdByTagName(final Long tagId) {
return tagDetails.entrySet().stream().filter(entry -> entry.getValue().getId().equals(tagId)).findFirst()
return tagDetails.entrySet().stream().filter(entry -> entry.getValue().getId().equals(tagId)).findAny()
.map(entry -> entry.getKey()).orElse(null);
}

View File

@@ -23,6 +23,7 @@ import org.eclipse.hawkbit.ui.management.state.ManagementUIState;
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
import org.eclipse.hawkbit.ui.utils.I18N;
import org.eclipse.hawkbit.ui.utils.UINotification;
import org.springframework.data.domain.PageRequest;
import org.vaadin.spring.events.EventBus.UIEventBus;
import org.vaadin.spring.events.EventScope;
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
@@ -36,6 +37,8 @@ public class TargetTagToken extends AbstractTargetTagToken<Target> {
private static final long serialVersionUID = 7124887018280196721L;
private static final int MAX_TAGS = 500;
// To Be Done : have to set this value based on view???
private static final Boolean NOTAGS_SELECTED = Boolean.FALSE;
@@ -106,7 +109,7 @@ public class TargetTagToken extends AbstractTargetTagToken<Target> {
protected void populateContainer() {
container.removeAllItems();
tagDetails.clear();
for (final TargetTag tag : tagManagement.findAllTargetTags()) {
for (final TargetTag tag : tagManagement.findAllTargetTags(new PageRequest(0, MAX_TAGS))) {
setContainerPropertValues(tag.getId(), tag.getName(), tag.getColour());
}
}

View File

@@ -1,42 +0,0 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.ui.components;
import com.vaadin.ui.HorizontalLayout;
/**
* Table Horizonatl layout with Style.
*
*
*
*/
public class SPUITableHorizonatlLayout {
private HorizontalLayout tableHorizonatlLayout;
/**
* Constructor.
*/
public SPUITableHorizonatlLayout() {
tableHorizonatlLayout = new HorizontalLayout();
decorate();
}
/**
* Decorate.
*/
private void decorate() {
tableHorizonatlLayout.setSpacing(false);
tableHorizonatlLayout.setMargin(false);
}
public HorizontalLayout getTableHorizonatlLayout() {
return tableHorizonatlLayout;
}
}

View File

@@ -1,83 +0,0 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.ui.components;
import org.eclipse.hawkbit.ui.utils.I18N;
import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil;
import org.eclipse.hawkbit.ui.utils.SpringContextHelper;
import com.vaadin.ui.VerticalLayout;
/**
* ChangeLog Vertical layout for Target and Distribution.
*
*
*
*/
public class SPUIUpdateLogLayout {
private final VerticalLayout changeLogLayout;
/**
* Parametric constructor.
*
* @param changeLogLayout
* as layout
* @param lastModifiedAt
* as Date
* @param lastModifiedBy
* as string
* @param createdAt
* as date
* @param createdBy
* as string
*/
public SPUIUpdateLogLayout(final VerticalLayout changeLogLayout, final Long lastModifiedAt,
final String lastModifiedBy, final Long createdAt, final String createdBy) {
this.changeLogLayout = changeLogLayout;
changeLogLayout.setSpacing(true);
changeLogLayout.setMargin(true);
decorate(lastModifiedAt, lastModifiedBy, createdAt, createdBy);
}
/**
* Decorate.
*
* @param lastModifiedAt
* @param lastModifiedBy
* @param createdAt
* @param createdBy
*/
private void decorate(final Long lastModifiedAt, final String lastModifiedBy, final Long createdAt,
final String createdBy) {
final I18N i18n = SpringContextHelper.getBean(I18N.class);
changeLogLayout.addComponent(SPUIComponentProvider.createNameValueLabel(i18n.get("label.created.at"),
createdAt == null ? "" : SPDateTimeUtil.getFormattedDate(createdAt)));
changeLogLayout.addComponent(SPUIComponentProvider.createNameValueLabel(i18n.get("label.created.by"),
createdBy == null ? "" : createdBy));
if (null != lastModifiedAt) {
changeLogLayout.addComponent(SPUIComponentProvider.createNameValueLabel(i18n.get("label.modified.date"),
SPDateTimeUtil.getFormattedDate(lastModifiedAt)));
changeLogLayout.addComponent(SPUIComponentProvider.createNameValueLabel(i18n.get("label.modified.by"),
lastModifiedBy == null ? "" : lastModifiedBy));
}
}
/**
* GET Change LogLayout.
*
* @return VerticalLayout as UI
*/
public VerticalLayout getChangeLogLayout() {
return changeLogLayout;
}
}

View File

@@ -14,7 +14,7 @@ import com.vaadin.client.connectors.ButtonRendererConnector;
import com.vaadin.shared.ui.Connect;
/**
* A connector for {@link HtmlButtonRenderer}.
* A connector for {@link HtmlButtonRenderer}.
*
*/
@Connect(org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlButtonRenderer.class)

View File

@@ -35,4 +35,4 @@ public class RolloutRendererConnector extends ClickableRendererConnector<Rollout
protected HandlerRegistration addClickHandler(final RendererClickHandler<JsonObject> handler) {
return getRenderer().addClickHandler(handler);
}
}
}

View File

@@ -15,9 +15,10 @@ import com.vaadin.ui.Grid.AbstractRenderer;
* Renders label with provided value and style.
*
*/
public class HtmlLabelRenderer extends AbstractRenderer<String> {
public class HtmlLabelRenderer extends AbstractRenderer<String> {
private static final long serialVersionUID = -7675588068526774915L;
/**
* Creates a new text renderer
*/

View File

@@ -49,14 +49,12 @@ public final class DistributionsViewClientCriterion extends ServerViewClientCrit
criteria[0] = ServerViewComponentClientCriterion.createBuilder()
.dragSourceIdPrefix(UIComponentIdProvider.DIST_TABLE_ID)
.dropTargetIdPrefixes(UIComponentIdProvider.DELETE_BUTTON_WRAPPER_ID)
.dropAreaIds(UIComponentIdProvider.DELETE_BUTTON_WRAPPER_ID)
.build();
.dropAreaIds(UIComponentIdProvider.DELETE_BUTTON_WRAPPER_ID).build();
// Distribution set type acceptable components.
criteria[1] = ServerViewComponentClientCriterion.createBuilder()
.dragSourceIdPrefix(SPUIDefinitions.DISTRIBUTION_SET_TYPE_ID_PREFIXS)
.dropTargetIdPrefixes(UIComponentIdProvider.DELETE_BUTTON_WRAPPER_ID)
.dropAreaIds(UIComponentIdProvider.DELETE_BUTTON_WRAPPER_ID)
.build();
.dropAreaIds(UIComponentIdProvider.DELETE_BUTTON_WRAPPER_ID).build();
// Upload software module table acceptable components.
criteria[2] = ServerViewComponentClientCriterion.createBuilder()
.dragSourceIdPrefix(UIComponentIdProvider.UPLOAD_SOFTWARE_MODULE_TABLE)
@@ -68,8 +66,7 @@ public final class DistributionsViewClientCriterion extends ServerViewClientCrit
criteria[3] = ServerViewComponentClientCriterion.createBuilder()
.dragSourceIdPrefix(SPUIDefinitions.SOFTWARE_MODULE_TAG_ID_PREFIXS)
.dropTargetIdPrefixes(UIComponentIdProvider.DELETE_BUTTON_WRAPPER_ID)
.dropAreaIds(UIComponentIdProvider.DELETE_BUTTON_WRAPPER_ID)
.build();
.dropAreaIds(UIComponentIdProvider.DELETE_BUTTON_WRAPPER_ID).build();
return criteria;
}

View File

@@ -13,9 +13,6 @@ import com.vaadin.ui.Button;
/**
* Interface to define method for button decoration.
*
*
*
*/
@FunctionalInterface
public interface SPUIButtonDecorator {

View File

@@ -14,12 +14,6 @@ import com.vaadin.ui.themes.ValoTheme;
/**
* Style for button: Small NoBorder.
*
*
*
*
*
*
*/
public class SPUIButtonStyleSmallNoBorder implements SPUIButtonDecorator {

View File

@@ -1,42 +0,0 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.ui.decorators;
import com.vaadin.server.Resource;
import com.vaadin.ui.Button;
import com.vaadin.ui.themes.ValoTheme;
/**
* Style for button: Small NoBorder Height UnDefined.
*
*/
public class SPUIButtonStyleSmallNoBorderUH implements SPUIButtonDecorator {
@Override
public Button decorate(final Button button, final String style, final boolean setStyle, final Resource icon) {
button.addStyleName(ValoTheme.BUTTON_SMALL);
button.addStyleName(ValoTheme.BUTTON_BORDERLESS_COLORED);
button.setHeightUndefined();
// Set Style
if (null != style) {
if (setStyle) {
button.setStyleName(style);
} else {
button.addStyleName(style);
}
}
// Set icon
if (null != icon) {
button.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
button.setIcon(icon);
}
return button;
}
}

View File

@@ -1,179 +0,0 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.ui.decorators;
/**
* DTO for Embeded UI decoration.
*
*
*
*/
public class SPUIEmbedValue {
private String id;
private String data;
private String styleName;
private boolean immediate;
private String source;
private int type;
private String mimeType;
private String description;
/**
* GET - ID.
*
* @return id
*/
public String getId() {
return id;
}
/**
* SET - ID.
*
* @param id
* as ID
*/
public void setId(String id) {
this.id = id;
}
/**
* GET - DATA.
*
* @return data
*/
public String getData() {
return data;
}
/**
* SET - DATA.
*
* @param data
* as data
*/
public void setData(String data) {
this.data = data;
}
/**
* GET - STYLE NAME.
*
* @return style name
*/
public String getStyleName() {
return styleName;
}
/**
* SET - STYLE NAME.
*
* @param styleName
* as Style
*/
public void setStyleName(String styleName) {
this.styleName = styleName;
}
/**
* CHECK - IMM.
*
* @return flag
*/
public boolean isImmediate() {
return immediate;
}
/**
* SET - IMM.
*
* @param immediate
* as flag
*/
public void setImmediate(boolean immediate) {
this.immediate = immediate;
}
/**
* GET - SOURCE.
*
* @return source
*/
public String getSource() {
return source;
}
/**
* SET - SOURCE.
*
* @param source
* as source
*/
public void setSource(String source) {
this.source = source;
}
/**
* GET - TYPE.
*
* @return type
*/
public int getType() {
return type;
}
/**
* SET - TYPE.
*
* @param type
* as type
*/
public void setType(int type) {
this.type = type;
}
/**
* GET - MIME.
*
* @return mime
*/
public String getMimeType() {
return mimeType;
}
/**
* SET - MIME.
*
* @param mimeType
* as mime
*/
public void setMimeType(String mimeType) {
this.mimeType = mimeType;
}
/**
* GET - DESC.
*
* @return desc
*/
public String getDescription() {
return description;
}
/**
* SET - DESC.
*
* @param description
* as desc
*/
public void setDescription(String description) {
this.description = description;
}
}

View File

@@ -9,6 +9,7 @@
package org.eclipse.hawkbit.ui.distributions.disttype;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
@@ -152,11 +153,11 @@ public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout<Distri
@Override
protected Color getColorForColorPicker() {
final DistributionSetType existedDistType = distributionSetManagement
final Optional<DistributionSetType> existedDistType = distributionSetManagement
.findDistributionSetTypeByName(tagNameComboBox.getValue().toString());
if (null != existedDistType) {
return existedDistType.getColour() != null
? ColorPickerHelper.rgbToColorConverter(existedDistType.getColour())
if (existedDistType.isPresent()) {
return existedDistType.get().getColour() != null
? ColorPickerHelper.rgbToColorConverter(existedDistType.get().getColour())
: ColorPickerHelper.rgbToColorConverter(ColorPickerConstants.DEFAULT_COLOR);
}
return ColorPickerHelper.rgbToColorConverter(ColorPickerConstants.DEFAULT_COLOR);
@@ -522,12 +523,10 @@ public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout<Distri
*/
@Override
protected void setTagDetails(final String distSetTypeSelected) {
tagName.setValue(distSetTypeSelected);
getSourceTableData();
selectedTable.getContainerDataSource().removeAllItems();
final DistributionSetType selectedTypeTag = fetchDistributionSetType(distSetTypeSelected);
if (null != selectedTypeTag) {
distributionSetManagement.findDistributionSetTypeByName(distSetTypeSelected).ifPresent(selectedTypeTag -> {
tagDesc.setValue(selectedTypeTag.getDescription());
typeKey.setValue(selectedTypeTag.getKey());
if (distributionSetManagement.countDistributionSetsByType(selectedTypeTag.getId()) <= 0) {
@@ -541,20 +540,12 @@ public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout<Distri
}
createOriginalSelectedTableContainer();
for (final SoftwareModuleType swModuleType : selectedTypeTag.getOptionalModuleTypes()) {
addTargetTableforUpdate(swModuleType, false);
}
for (final SoftwareModuleType swModuleType : selectedTypeTag.getMandatoryModuleTypes()) {
addTargetTableforUpdate(swModuleType, true);
}
selectedTypeTag.getOptionalModuleTypes()
.forEach(swModuleType -> addTargetTableforUpdate(swModuleType, false));
selectedTypeTag.getMandatoryModuleTypes()
.forEach(swModuleType -> addTargetTableforUpdate(swModuleType, true));
setColorPickerComponentsColor(selectedTypeTag.getColour());
}
}
private DistributionSetType fetchDistributionSetType(final String distTypeName) {
return distributionSetManagement.findDistributionSetTypeByName(distTypeName);
});
}
@SuppressWarnings("unchecked")
@@ -590,12 +581,12 @@ public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout<Distri
}
@Override
protected DistributionSetType findEntityByKey() {
protected Optional<DistributionSetType> findEntityByKey() {
return distributionSetManagement.findDistributionSetTypeByKey(typeKey.getValue());
}
@Override
protected DistributionSetType findEntityByName() {
protected Optional<DistributionSetType> findEntityByName() {
return distributionSetManagement.findDistributionSetTypeByName(tagName.getValue());
}

View File

@@ -11,7 +11,6 @@ package org.eclipse.hawkbit.ui.distributions.disttype;
import java.io.Serializable;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterSingleButtonClick;
import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState;
import org.eclipse.hawkbit.ui.management.event.DistributionTableFilterEvent;
@@ -49,9 +48,8 @@ public class DSTypeFilterButtonClick extends AbstractFilterSingleButtonClick imp
@Override
protected void filterClicked(final Button clickedButton) {
final DistributionSetType distSetType = distributionSetManagement
.findDistributionSetTypeByName(clickedButton.getData().toString());
manageDistUIState.getManageDistFilters().setClickedDistSetType(distSetType);
distributionSetManagement.findDistributionSetTypeByName(clickedButton.getData().toString())
.ifPresent(manageDistUIState.getManageDistFilters()::setClickedDistSetType);
eventBus.publish(this, DistributionTableFilterEvent.FILTER_BY_TAG);
}

View File

@@ -38,7 +38,7 @@ public class DSTypeFilterButtons extends AbstractFilterButtons {
private final ManageDistUIState manageDistUIState;
private final DistributionsViewClientCriterion distributionsViewClientCriterion;
DSTypeFilterButtons(final UIEventBus eventBus, final ManageDistUIState manageDistUIState,
final DistributionsViewClientCriterion distributionsViewClientCriterion,
final DistributionSetManagement distributionSetManagement) {

View File

@@ -159,7 +159,7 @@ public class DistributionSetDetails extends AbstractNamedVersionedEntityTableDet
}
for (final SoftwareModuleIdName swIdName : softwareModuleIdNameList) {
final SoftwareModule softwareModule = softwareManagement.findSoftwareModuleById(swIdName.getId());
final SoftwareModule softwareModule = softwareManagement.findSoftwareModuleById(swIdName.getId()).get();
if (assignedSWModule.containsKey(softwareModule.getType().getName())) {
assignedSWModule.get(softwareModule.getType().getName()).append("</br>").append("<I>")
.append(getUnsavedAssigedSwModule(softwareModule.getName(), softwareModule.getVersion()))
@@ -374,7 +374,7 @@ public class DistributionSetDetails extends AbstractNamedVersionedEntityTableDet
assignedSWModule.clear();
}
setSelectedBaseEntity(
distributionSetManagement.findDistributionSetByIdWithDetails(getSelectedBaseEntityId()));
distributionSetManagement.findDistributionSetByIdWithDetails(getSelectedBaseEntityId()).get());
UI.getCurrent().access(this::populateModule);
}
}
@@ -409,7 +409,7 @@ public class DistributionSetDetails extends AbstractNamedVersionedEntityTableDet
@Override
protected void showMetadata(final ClickEvent event) {
final DistributionSet ds = distributionSetManagement
.findDistributionSetByIdWithDetails(getSelectedBaseEntityId());
.findDistributionSetByIdWithDetails(getSelectedBaseEntityId()).get();
UI.getCurrent().addWindow(dsMetadataPopupLayout.getWindow(ds, null));
}
}

View File

@@ -13,6 +13,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
@@ -121,7 +122,7 @@ public class DistributionSetTable extends AbstractNamedVersionTable<Distribution
private void handleSelectedAndUpdatedDs(final List<DistributionSetUpdateEvent> events) {
manageDistUIState.getLastSelectedDistribution()
.ifPresent(lastSelectedDsIdName -> events.stream()
.filter(event -> event.getEntityId().equals(lastSelectedDsIdName)).findFirst()
.filter(event -> event.getEntityId().equals(lastSelectedDsIdName)).findAny()
.ifPresent(event -> eventBus.publish(this,
new DistributionTableEvent(BaseEntityEventType.SELECTED_ENTITY, event.getEntity()))));
}
@@ -184,7 +185,7 @@ public class DistributionSetTable extends AbstractNamedVersionTable<Distribution
}
@Override
protected DistributionSet findEntityByTableValue(final Long entityTableId) {
protected Optional<DistributionSet> findEntityByTableValue(final Long entityTableId) {
return distributionSetManagement.findDistributionSetByIdWithDetails(entityTableId);
}
@@ -242,14 +243,15 @@ public class DistributionSetTable extends AbstractNamedVersionTable<Distribution
}
private void handleDropEvent(final Table source, final Set<Long> softwareModulesIdList, final Object distId) {
final DistributionSet distributionSet = distributionSetManagement.findDistributionSetById((Long) distId);
final Optional<DistributionSet> distributionSet = distributionSetManagement
.findDistributionSetById((Long) distId);
if (distributionSet == null) {
if (!distributionSet.isPresent()) {
notification.displayWarning(i18n.get("distributionset.not.exists"));
return;
}
final DistributionSetIdName distributionSetIdName = new DistributionSetIdName(distributionSet);
final DistributionSetIdName distributionSetIdName = new DistributionSetIdName(distributionSet.get());
final HashMap<Long, HashSet<SoftwareModuleIdName>> map;
if (manageDistUIState.getConsolidatedDistSoftwarewList().containsKey(distributionSetIdName)) {
@@ -264,7 +266,7 @@ public class DistributionSetTable extends AbstractNamedVersionTable<Distribution
final String name = (String) softwareItem.getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue();
final String swVersion = (String) softwareItem.getItemProperty(SPUILabelDefinitions.VAR_VERSION).getValue();
final SoftwareModule softwareModule = softwareManagement.findSoftwareModuleById(softwareModuleId);
final SoftwareModule softwareModule = softwareManagement.findSoftwareModuleById(softwareModuleId).get();
if (validSoftwareModule((Long) distId, softwareModule)) {
final SoftwareModuleIdName softwareModuleIdName = new SoftwareModuleIdName(softwareModuleId,
name.concat(":" + swVersion));
@@ -326,7 +328,7 @@ public class DistributionSetTable extends AbstractNamedVersionTable<Distribution
if (!isSoftwareModuleDragged(distId, sm)) {
return false;
}
final DistributionSet ds = distributionSetManagement.findDistributionSetByIdWithDetails(distId);
final DistributionSet ds = distributionSetManagement.findDistributionSetByIdWithDetails(distId).get();
if (!validateSoftwareModule(sm, ds)) {
return false;
}
@@ -490,7 +492,7 @@ public class DistributionSetTable extends AbstractNamedVersionTable<Distribution
}
private void showMetadataDetails(final Long itemId) {
final DistributionSet ds = distributionSetManagement.findDistributionSetByIdWithDetails(itemId);
final DistributionSet ds = distributionSetManagement.findDistributionSetByIdWithDetails(itemId).get();
UI.getCurrent().addWindow(dsMetadataPopupLayout.getWindow(ds, null));
}

View File

@@ -20,6 +20,7 @@ import org.eclipse.hawkbit.ui.SpPermissionChecker;
import org.eclipse.hawkbit.ui.common.AbstractMetadataPopupLayout;
import org.eclipse.hawkbit.ui.utils.I18N;
import org.eclipse.hawkbit.ui.utils.UINotification;
import org.springframework.data.domain.PageRequest;
import org.vaadin.spring.events.EventBus.UIEventBus;
import com.google.common.collect.Lists;
@@ -44,13 +45,10 @@ public class DsMetadataPopupLayout extends AbstractMetadataPopupLayout<Distribut
}
@Override
protected void checkForDuplicate(final DistributionSet entity, final String value) {
distributionSetManagement.findDistributionSetMetadata(entity.getId(), value);
protected boolean checkForDuplicate(final DistributionSet entity, final String value) {
return distributionSetManagement.findDistributionSetMetadata(entity.getId(), value).isPresent();
}
/**
* Create metadata for DistributionSet.
*/
@Override
protected DistributionSetMetadata createMetadata(final DistributionSet entity, final String key,
final String value) {
@@ -60,9 +58,6 @@ public class DsMetadataPopupLayout extends AbstractMetadataPopupLayout<Distribut
return dsMetaData;
}
/**
* Update metadata for DistributionSet.
*/
@Override
protected DistributionSetMetadata updateMetadata(final DistributionSet entity, final String key,
final String value) {
@@ -74,14 +69,11 @@ public class DsMetadataPopupLayout extends AbstractMetadataPopupLayout<Distribut
@Override
protected List<MetaData> getMetadataList() {
return Collections.unmodifiableList(
distributionSetManagement.findDistributionSetMetadataByDistributionSetId(getSelectedEntity().getId()));
return Collections.unmodifiableList(distributionSetManagement
.findDistributionSetMetadataByDistributionSetId(getSelectedEntity().getId(), new PageRequest(0, 500))
.getContent());
}
/**
* Update metadata for DistributionSet.
*/
@Override
protected void deleteMetadata(final DistributionSet entity, final String key, final String value) {
distributionSetManagement.deleteDistributionSetMetadata(entity.getId(), key);

View File

@@ -17,7 +17,6 @@ import java.util.stream.Collectors;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.SoftwareManagement;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent;
import org.eclipse.hawkbit.ui.common.confirmwindow.layout.AbstractConfirmationWindowLayout;
import org.eclipse.hawkbit.ui.common.confirmwindow.layout.ConfirmationTab;
@@ -278,7 +277,7 @@ public class DistributionsConfirmationWindowLayout extends AbstractConfirmationW
for (final String swModuleTypeName : manageDistUIState.getSelectedDeleteSWModuleTypes()) {
softwareManagement.deleteSoftwareModuleType(
softwareManagement.findSoftwareModuleTypeByName(swModuleTypeName).getId());
softwareManagement.findSoftwareModuleTypeByName(swModuleTypeName).get().getId());
}
addToConsolitatedMsg(FontAwesome.TASKS.getHtml() + SPUILabelDefinitions.HTML_SPACE
+ i18n.get("message.sw.module.type.delete", new Object[] { deleteSWModuleTypeCount }));
@@ -460,10 +459,10 @@ public class DistributionsConfirmationWindowLayout extends AbstractConfirmationW
private void deleteDistSetTypeAll(final ConfirmationTab tab) {
final int deleteDistTypeCount = manageDistUIState.getSelectedDeleteDistSetTypes().size();
for (final String deleteDistTypeName : manageDistUIState.getSelectedDeleteDistSetTypes()) {
dsManagement
.deleteDistributionSetType(dsManagement.findDistributionSetTypeByName(deleteDistTypeName).getId());
}
manageDistUIState.getSelectedDeleteDistSetTypes().stream()
.map(deleteDistTypeName -> dsManagement.findDistributionSetTypeByName(deleteDistTypeName).get().getId())
.forEach(dsManagement::deleteDistributionSetType);
addToConsolitatedMsg(FontAwesome.TASKS.getHtml() + SPUILabelDefinitions.HTML_SPACE
+ i18n.get("message.dist.type.delete", new Object[] { deleteDistTypeCount }));
manageDistUIState.getSelectedDeleteDistSetTypes().clear();

View File

@@ -44,8 +44,8 @@ public class SwMetadataPopupLayout extends AbstractMetadataPopupLayout<SoftwareM
}
@Override
protected void checkForDuplicate(final SoftwareModule entity, final String value) {
softwareManagement.findSoftwareModuleMetadata(entity.getId(), value);
protected boolean checkForDuplicate(final SoftwareModule entity, final String value) {
return softwareManagement.findSoftwareModuleMetadata(entity.getId(), value).isPresent();
}
/**

View File

@@ -215,7 +215,7 @@ public class SwModuleDetails extends AbstractNamedVersionedEntityTableDetailsLay
@Override
protected void showMetadata(final ClickEvent event) {
final SoftwareModule swmodule = softwareManagement.findSoftwareModuleById(getSelectedBaseEntityId());
final SoftwareModule swmodule = softwareManagement.findSoftwareModuleById(getSelectedBaseEntityId()).get();
UI.getCurrent().addWindow(swMetadataPopupLayout.getWindow(swmodule, null));
}
}

View File

@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.ui.distributions.smtable;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import org.eclipse.hawkbit.repository.ArtifactManagement;
@@ -148,7 +149,7 @@ public class SwModuleTable extends AbstractNamedVersionTable<SoftwareModule, Lon
private void handleSelectedAndUpdatedSoftwareModules(final List<SoftwareModuleUpdatedEvent> events) {
manageDistUIState.getSelectedBaseSwModuleId()
.ifPresent(lastSelectedModuleId -> events.stream()
.filter(event -> lastSelectedModuleId.equals(event.getEntityId())).findFirst()
.filter(event -> lastSelectedModuleId.equals(event.getEntityId())).findAny()
.ifPresent(lastEvent -> eventBus.publish(this,
new SoftwareModuleEvent(BaseEntityEventType.SELECTED_ENTITY, lastEvent.getEntity()))));
}
@@ -257,7 +258,7 @@ public class SwModuleTable extends AbstractNamedVersionTable<SoftwareModule, Lon
}
@Override
protected SoftwareModule findEntityByTableValue(final Long lastSelectedId) {
protected Optional<SoftwareModule> findEntityByTableValue(final Long lastSelectedId) {
return softwareManagement.findSoftwareModuleById(lastSelectedId);
}
@@ -420,7 +421,7 @@ public class SwModuleTable extends AbstractNamedVersionTable<SoftwareModule, Lon
}
private void showMetadataDetails(final Long itemId) {
final SoftwareModule swmodule = softwareManagement.findSoftwareModuleById(itemId);
final SoftwareModule swmodule = softwareManagement.findSoftwareModuleById(itemId).get();
UI.getCurrent().addWindow(swMetadataPopupLayout.getWindow(swmodule, null));
}

View File

@@ -49,7 +49,7 @@ public class DistSMTypeFilterButtonClick extends AbstractFilterSingleButtonClick
@Override
protected void filterClicked(final Button clickedButton) {
final SoftwareModuleType smType = softwareManagement
.findSoftwareModuleTypeByName(clickedButton.getData().toString());
.findSoftwareModuleTypeByName(clickedButton.getData().toString()).get();
manageDistUIState.getSoftwareModuleFilters().setSoftwareModuleType(smType);
eventBus.publish(this, SMFilterEvent.FILTER_BY_TYPE);
}

View File

@@ -42,10 +42,10 @@ public class DistSMTypeFilterButtons extends AbstractFilterButtons {
private static final long serialVersionUID = 6804534533362387433L;
private final ManageDistUIState manageDistUIState;
private final ManageDistUIState manageDistUIState;
private final DistributionsViewClientCriterion distributionsViewClientCriterion;
DistSMTypeFilterButtons(final UIEventBus eventBus, final ManageDistUIState manageDistUIState,
final DistributionsViewClientCriterion distributionsViewClientCriterion,
final SoftwareManagement softwareManagement) {

View File

@@ -400,7 +400,7 @@ public class CreateOrUpdateFilterHeader extends VerticalLayout implements Button
}
private boolean doesAlreadyExists() {
if (targetFilterQueryManagement.findTargetFilterQueryByName(nameTextField.getValue()) != null) {
if (targetFilterQueryManagement.findTargetFilterQueryByName(nameTextField.getValue()).isPresent()) {
notification.displayValidationError(i18n.get("message.target.filter.duplicate", nameTextField.getValue()));
return true;
}

View File

@@ -12,6 +12,7 @@ import java.io.Serializable;
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
import org.eclipse.hawkbit.ui.common.CommonDialogWindow;
@@ -104,10 +105,8 @@ public class DistributionSetSelectWindow
*/
public void showForTargetFilter(final Long tfqId) {
this.tfqId = tfqId;
final TargetFilterQuery tfq = targetFilterQueryManagement.findTargetFilterQueryById(tfqId);
if (tfq == null) {
throw new IllegalStateException("TargetFilterQuery does not exist for the given id");
}
final TargetFilterQuery tfq = targetFilterQueryManagement.findTargetFilterQueryById(tfqId)
.orElseThrow(() -> new EntityNotFoundException(TargetFilterQuery.class, tfqId));
initLocal();
@@ -165,7 +164,8 @@ public class DistributionSetSelectWindow
}
private void updateTargetFilterQueryDS(final Long targetFilterQueryId, final Long dsId) {
final TargetFilterQuery tfq = targetFilterQueryManagement.findTargetFilterQueryById(targetFilterQueryId);
final TargetFilterQuery tfq = targetFilterQueryManagement.findTargetFilterQueryById(targetFilterQueryId)
.orElseThrow(() -> new EntityNotFoundException(TargetFilterQuery.class, targetFilterQueryId));
if (dsId != null) {
confirmWithConsequencesDialog(tfq, dsId);

View File

@@ -181,7 +181,7 @@ public class TargetFilterTable extends Table {
if (ok) {
final Long rowId = (Long) ((Button) event.getComponent()).getData();
final String deletedFilterName = targetFilterQueryManagement.findTargetFilterQueryById(rowId)
.getName();
.get().getName();
targetFilterQueryManagement.deleteTargetFilterQuery(rowId);
/*
@@ -254,7 +254,7 @@ public class TargetFilterTable extends Table {
private void onClickOfDetailButton(final ClickEvent event) {
final String targetFilterName = (String) ((Button) event.getComponent()).getData();
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement
.findTargetFilterQueryByName(targetFilterName);
.findTargetFilterQueryByName(targetFilterName).get();
filterManagementUIState.setFilterQueryValue(targetFilterQuery.getQuery());
filterManagementUIState.setTfQuery(targetFilterQuery);
filterManagementUIState.setEditViewDisplayed(true);

View File

@@ -140,4 +140,3 @@ public class AutoCompleteTextFieldConnector extends AbstractExtensionConnector {
rpc.suggest(textFieldWidget.getValue(), textFieldWidget.getCursorPos());
}
}

View File

@@ -73,4 +73,4 @@ public class SuggestTokenDto implements Serializable {
public String toString() {
return "SuggestTokenDto [start=" + start + ", end=" + end + ", suggestion=" + suggestion + "]";
}
}
}

View File

@@ -8,6 +8,8 @@
*/
package org.eclipse.hawkbit.ui.layouts;
import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.TagManagement;
@@ -147,7 +149,7 @@ public abstract class AbstractCreateUpdateTagLayout<E extends NamedEntity> exten
@Override
public void saveOrUpdate() {
if (isUpdateAction()) {
updateEntity(findEntityByName());
updateEntity(findEntityByName().orElse(null));
return;
}
@@ -295,15 +297,16 @@ public abstract class AbstractCreateUpdateTagLayout<E extends NamedEntity> exten
* @return the color which should be selected in the color-picker component.
*/
protected Color getColorForColorPicker() {
final TargetTag targetTagSelected = tagManagement.findTargetTag(tagNameComboBox.getValue().toString());
if (targetTagSelected == null) {
final Optional<TargetTag> targetTagSelected = tagManagement
.findTargetTag(tagNameComboBox.getValue().toString());
if (!targetTagSelected.isPresent()) {
final DistributionSetTag distTag = tagManagement
.findDistributionSetTag(tagNameComboBox.getValue().toString());
.findDistributionSetTag(tagNameComboBox.getValue().toString()).get();
return distTag.getColour() != null ? ColorPickerHelper.rgbToColorConverter(distTag.getColour())
: ColorPickerHelper.rgbToColorConverter(ColorPickerConstants.DEFAULT_COLOR);
}
return targetTagSelected.getColour() != null
? ColorPickerHelper.rgbToColorConverter(targetTagSelected.getColour())
return targetTagSelected.get().getColour() != null
? ColorPickerHelper.rgbToColorConverter(targetTagSelected.get().getColour())
: ColorPickerHelper.rgbToColorConverter(ColorPickerConstants.DEFAULT_COLOR);
}
@@ -604,14 +607,11 @@ public abstract class AbstractCreateUpdateTagLayout<E extends NamedEntity> exten
}
private boolean isDuplicateByName() {
final E existingType = findEntityByName();
if (existingType != null) {
uiNotification.displayValidationError(
i18n.get("message.tag.duplicate.check", new Object[] { existingType.getName() }));
return true;
}
final Optional<E> existingType = findEntityByName();
existingType.ifPresent(type -> uiNotification
.displayValidationError(i18n.get("message.tag.duplicate.check", new Object[] { type.getName() })));
return false;
return existingType.isPresent();
}
protected boolean isDuplicate() {
@@ -658,7 +658,7 @@ public abstract class AbstractCreateUpdateTagLayout<E extends NamedEntity> exten
public void removeColorChangeListener(final ColorChangeListener listener) {
}
protected abstract E findEntityByName();
protected abstract Optional<E> findEntityByName();
protected abstract String getWindowCaption();

View File

@@ -8,6 +8,8 @@
*/
package org.eclipse.hawkbit.ui.layouts;
import java.util.Optional;
import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.TagManagement;
import org.eclipse.hawkbit.repository.model.NamedEntity;
@@ -229,15 +231,11 @@ public abstract class CreateUpdateTypeLayout<E extends NamedEntity> extends Abst
}
private boolean isDuplicateByKey() {
final Optional<E> existingType = findEntityByKey();
final E existingType = findEntityByKey();
existingType.ifPresent(type -> uiNotification.displayValidationError(getDuplicateKeyErrorMessage(type)));
if (existingType != null) {
uiNotification.displayValidationError(getDuplicateKeyErrorMessage(existingType));
return true;
}
return false;
return existingType.isPresent();
}
@Override
@@ -245,7 +243,7 @@ public abstract class CreateUpdateTypeLayout<E extends NamedEntity> extends Abst
return isDuplicateByKey() || super.isDuplicate();
}
protected abstract E findEntityByKey();
protected abstract Optional<E> findEntityByKey();
protected abstract String getDuplicateKeyErrorMessage(E existingType);

View File

@@ -432,7 +432,7 @@ public class ActionHistoryTable extends TreeTable {
.getValue();
final org.eclipse.hawkbit.repository.model.Action action = deploymentManagement
.findActionWithDetails(actionId);
.findActionWithDetails(actionId).get();
final Pageable pageReq = new PageRequest(0, 1000,
new Sort(Direction.DESC, ActionStatusFields.ID.getFieldName()));
final Page<ActionStatus> actionStatusList;

View File

@@ -9,6 +9,7 @@
package org.eclipse.hawkbit.ui.management.dstable;
import java.util.Collections;
import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
@@ -213,7 +214,7 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
.updateDistributionSet(entityFactory.distributionSet().update(editDistId)
.name(distNameTextField.getValue()).description(descTextArea.getValue())
.version(distVersionTextField.getValue()).requiredMigrationStep(isMigStepReq)
.type(distributionSetManagement.findDistributionSetTypeById(distSetTypeId)));
.type(distributionSetManagement.findDistributionSetTypeById(distSetTypeId).get()));
notificationMessage.displaySuccess(i18n.get("message.new.dist.save.success",
new Object[] { currentDS.getName(), currentDS.getVersion() }));
// update table row+details layout
@@ -233,9 +234,9 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
final String desc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue());
final boolean isMigStepReq = reqMigStepCheckbox.getValue();
final DistributionSet newDist = distributionSetManagement
.createDistributionSet(entityFactory.distributionSet().create().name(name).version(version)
.description(desc).type(distributionSetManagement.findDistributionSetTypeById(distSetTypeId))
final DistributionSet newDist = distributionSetManagement.createDistributionSet(
entityFactory.distributionSet().create().name(name).version(version).description(desc)
.type(distributionSetManagement.findDistributionSetTypeById(distSetTypeId).get())
.requiredMigrationStep(isMigStepReq));
eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.ADD_ENTITY, newDist));
@@ -250,18 +251,19 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
final String name = distNameTextField.getValue();
final String version = distVersionTextField.getValue();
final DistributionSet existingDs = distributionSetManagement.findDistributionSetByNameAndVersion(name, version);
final Optional<DistributionSet> existingDs = distributionSetManagement.findDistributionSetByNameAndVersion(name,
version);
/*
* Distribution should not exists with the same name & version. Display
* error message, when the "existingDs" is not null and it is add window
* (or) when the "existingDs" is not null and it is edit window and the
* distribution Id of the edit window is different then the "existingDs"
*/
if (existingDs != null && !existingDs.getId().equals(editDistId)) {
if (existingDs.isPresent() && !existingDs.get().getId().equals(editDistId)) {
distNameTextField.addStyleName(SPUIStyleDefinitions.SP_TEXTFIELD_LAYOUT_ERROR_HIGHTLIGHT);
distVersionTextField.addStyleName(SPUIStyleDefinitions.SP_TEXTFIELD_LAYOUT_ERROR_HIGHTLIGHT);
notificationMessage.displayValidationError(
i18n.get("message.duplicate.dist", new Object[] { existingDs.getName(), existingDs.getVersion() }));
notificationMessage.displayValidationError(i18n.get("message.duplicate.dist",
new Object[] { existingDs.get().getName(), existingDs.get().getVersion() }));
return true;
}
@@ -291,21 +293,22 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
return;
}
final DistributionSet distSet = distributionSetManagement.findDistributionSetByIdWithDetails(editDistId);
if (distSet == null) {
final Optional<DistributionSet> distSet = distributionSetManagement
.findDistributionSetByIdWithDetails(editDistId);
if (!distSet.isPresent()) {
return;
}
editDistribution = Boolean.TRUE;
distNameTextField.setValue(distSet.getName());
distVersionTextField.setValue(distSet.getVersion());
if (distSet.getType().isDeleted()) {
distsetTypeNameComboBox.addItem(distSet.getType().getId());
distNameTextField.setValue(distSet.get().getName());
distVersionTextField.setValue(distSet.get().getVersion());
if (distSet.get().getType().isDeleted()) {
distsetTypeNameComboBox.addItem(distSet.get().getType().getId());
}
distsetTypeNameComboBox.setValue(distSet.getType().getId());
distsetTypeNameComboBox.setValue(distSet.get().getType().getId());
reqMigStepCheckbox.setValue(distSet.isRequiredMigrationStep());
descTextArea.setValue(distSet.getDescription());
reqMigStepCheckbox.setValue(distSet.get().isRequiredMigrationStep());
descTextArea.setValue(distSet.get().getDescription());
}
/**

View File

@@ -8,6 +8,8 @@
*/
package org.eclipse.hawkbit.ui.management.dstable;
import java.util.Optional;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.TagManagement;
@@ -195,12 +197,13 @@ public class DistributionDetails extends AbstractNamedVersionedEntityTableDetail
@Override
protected void showMetadata(final ClickEvent event) {
final DistributionSet ds = distributionSetManagement.findDistributionSetById(getSelectedBaseEntityId());
if (ds == null) {
final Optional<DistributionSet> ds = distributionSetManagement
.findDistributionSetById(getSelectedBaseEntityId());
if (!ds.isPresent()) {
notificationMessage.displayWarning(getI18n().get("distributionset.not.exists"));
return;
}
UI.getCurrent().addWindow(dsMetadataPopupLayout.getWindow(ds, null));
UI.getCurrent().addWindow(dsMetadataPopupLayout.getWindow(ds.get(), null));
}
}

View File

@@ -13,6 +13,7 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
@@ -117,8 +118,8 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
updateVisableTableEntries(eventContainer.getEvents(), visibleItemIds);
}
final Long lastSelectedDsIdName = managementUIState.getLastSelectedDsIdName();
eventContainer.getEvents().stream().filter(event -> event.getEntityId().equals(lastSelectedDsIdName))
.findFirst().ifPresent(event -> eventBus.publish(this,
eventContainer.getEvents().stream().filter(event -> event.getEntityId().equals(lastSelectedDsIdName)).findAny()
.ifPresent(event -> eventBus.publish(this,
new DistributionTableEvent(BaseEntityEventType.SELECTED_ENTITY, event.getEntity())));
}
@@ -303,7 +304,7 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
}
@Override
protected DistributionSet findEntityByTableValue(final Long lastSelectedId) {
protected Optional<DistributionSet> findEntityByTableValue(final Long lastSelectedId) {
return distributionSetManagement.findDistributionSetByIdWithDetails(lastSelectedId);
}
@@ -425,13 +426,14 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
}
final Long distId = (Long) item.getItemProperty("id").getValue();
final DistributionSet findDistributionSetById = distributionSetManagement.findDistributionSetById(distId);
if (findDistributionSetById == null) {
final Optional<DistributionSet> findDistributionSetById = distributionSetManagement
.findDistributionSetById(distId);
if (!findDistributionSetById.isPresent()) {
notification.displayWarning(i18n.get("distributionset.not.exists"));
return;
}
showOrHidePopupAndNotification(validate(targetDetailsList, findDistributionSetById));
showOrHidePopupAndNotification(validate(targetDetailsList, findDistributionSetById.get()));
}
@Override
@@ -526,12 +528,12 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
return;
}
final Target targetObj = targetService.findTargetByControllerIDWithDetails(
final Optional<Target> targetObj = targetService.findTargetByControllerIDWithDetails(
managementUIState.getDistributionTableFilters().getPinnedTarget().get().getControllerId());
if (targetObj != null) {
final DistributionSet assignedDistribution = targetObj.getAssignedDistributionSet();
final DistributionSet installedDistribution = targetObj.getTargetInfo().getInstalledDistributionSet();
if (targetObj.isPresent()) {
final DistributionSet assignedDistribution = targetObj.get().getAssignedDistributionSet();
final DistributionSet installedDistribution = targetObj.get().getTargetInfo().getInstalledDistributionSet();
Long installedDistId = null;
Long assignedDistId = null;
if (null != installedDistribution) {
@@ -717,12 +719,12 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
}
private void showMetadataDetails(final Object itemId) {
final DistributionSet ds = distributionSetManagement.findDistributionSetById((Long) itemId);
if (ds == null) {
final Optional<DistributionSet> ds = distributionSetManagement.findDistributionSetById((Long) itemId);
if (!ds.isPresent()) {
notification.displayWarning(i18n.get("distributionset.not.exists"));
return;
}
UI.getCurrent().addWindow(dsMetadataPopupLayout.getWindow(ds, null));
UI.getCurrent().addWindow(dsMetadataPopupLayout.getWindow(ds.get(), null));
}
}

View File

@@ -11,9 +11,11 @@ package org.eclipse.hawkbit.ui.management.dstag;
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
import java.util.List;
import java.util.Optional;
import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.TagManagement;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
import org.eclipse.hawkbit.ui.SpPermissionChecker;
import org.eclipse.hawkbit.ui.colorpicker.ColorPickerConstants;
@@ -69,12 +71,12 @@ public class CreateUpdateDistributionTagLayoutWindow extends AbstractCreateUpdat
@Override
protected void updateEntity(final DistributionSetTag entity) {
updateExistingTag(findEntityByName());
updateExistingTag(findEntityByName()
.orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, tagName.getValue())));
}
@Override
protected DistributionSetTag findEntityByName() {
protected Optional<DistributionSetTag> findEntityByName() {
return tagManagement.findDistributionSetTag(tagName.getValue());
}
@@ -136,14 +138,14 @@ public class CreateUpdateDistributionTagLayoutWindow extends AbstractCreateUpdat
@Override
public void setTagDetails(final String distTagSelected) {
tagName.setValue(distTagSelected);
final DistributionSetTag selectedDistTag = tagManagement.findDistributionSetTag(distTagSelected);
if (null != selectedDistTag) {
tagDesc.setValue(selectedDistTag.getDescription());
if (null == selectedDistTag.getColour()) {
final Optional<DistributionSetTag> selectedDistTag = tagManagement.findDistributionSetTag(distTagSelected);
if (selectedDistTag.isPresent()) {
tagDesc.setValue(selectedDistTag.get().getDescription());
if (null == selectedDistTag.get().getColour()) {
setTagColor(getColorPickerLayout().getDefaultColor(), ColorPickerConstants.DEFAULT_COLOR);
} else {
setTagColor(ColorPickerHelper.rgbToColorConverter(selectedDistTag.getColour()),
selectedDistTag.getColour());
setTagColor(ColorPickerHelper.rgbToColorConverter(selectedDistTag.get().getColour()),
selectedDistTag.get().getColour());
}
}
}

View File

@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.ui.management.footer;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
@@ -330,13 +331,14 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout {
private boolean isDsInUseInBulkUpload(final Set<Long> distributionIdNameSet, final Long dsInBulkUpload) {
if (distributionIdNameSet.contains(dsInBulkUpload)) {
final DistributionSet distributionSet = distributionSetManagement.findDistributionSetById(dsInBulkUpload);
if (distributionSet == null) {
final Optional<DistributionSet> distributionSet = distributionSetManagement
.findDistributionSetById(dsInBulkUpload);
if (!distributionSet.isPresent()) {
notification.displayWarning(i18n.get("distributionset.not.exists"));
return true;
}
notification.displayValidationError(i18n.get("message.tag.use.bulk.upload", HawkbitCommonUtil
.getFormattedNameVersion(distributionSet.getName(), distributionSet.getVersion())));
.getFormattedNameVersion(distributionSet.get().getName(), distributionSet.get().getVersion())));
return true;
}
return false;

View File

@@ -304,7 +304,7 @@ public class BulkUploadHandler extends CustomComponent
final TargetBulkUpload targetBulkUpload = managementUIState.getTargetTableFilters().getBulkUpload();
final List<String> targetsList = targetBulkUpload.getTargetsCreated();
final Long dsSelected = (Long) comboBox.getValue();
if (distributionSetManagement.findDistributionSetById(dsSelected) == null) {
if (!distributionSetManagement.findDistributionSetById(dsSelected).isPresent()) {
return i18n.get("message.bulk.upload.assignment.failed");
}
deploymentManagement.assignDistributionSet(targetBulkUpload.getDsNameAndVersion(), actionType,
@@ -316,7 +316,7 @@ public class BulkUploadHandler extends CustomComponent
final Map<Long, TagData> tokensSelected = targetBulkTokenTags.getTokensAdded();
final List<String> deletedTags = new ArrayList<>();
for (final TagData tagData : tokensSelected.values()) {
if (tagManagement.findTargetTagById(tagData.getId()) == null) {
if (!tagManagement.findTargetTagById(tagData.getId()).isPresent()) {
deletedTags.add(tagData.getName());
} else {
targetManagement.toggleTagAssignment(

View File

@@ -8,6 +8,8 @@
*/
package org.eclipse.hawkbit.ui.management.targettable;
import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.TargetManagement;
@@ -162,12 +164,12 @@ public class TargetAddUpdateWindowLayout extends CustomComponent {
* @return window or {@code null} if target is not exists.
*/
public Window getWindow(final String controllerId) {
final Target target = targetManagement.findTargetByControllerID(controllerId);
if (target == null) {
final Optional<Target> target = targetManagement.findTargetByControllerID(controllerId);
if (!target.isPresent()) {
uINotification.displayWarning(i18n.get("target.not.exists", new Object[] { controllerId }));
return null;
}
populateValuesOfTarget(target);
populateValuesOfTarget(target.get());
createNewWindow();
window.addStyleName("target-update-window");
return window;
@@ -188,8 +190,8 @@ public class TargetAddUpdateWindowLayout extends CustomComponent {
private boolean isDuplicate() {
final String newControlllerId = controllerIDTextField.getValue();
final Target existingTarget = targetManagement.findTargetByControllerID(newControlllerId.trim());
if (existingTarget != null) {
final Optional<Target> existingTarget = targetManagement.findTargetByControllerID(newControlllerId.trim());
if (existingTarget.isPresent()) {
uINotification.displayValidationError(
i18n.get("message.target.duplicate.check", new Object[] { newControlllerId }));
return true;

View File

@@ -150,7 +150,8 @@ public class TargetBeanQuery extends AbstractBeanQuery<ProxyTarget> {
prxyTarget.setInstalledDistributionSet(null);
prxyTarget.setAssignedDistributionSet(null);
} else {
final Target target = getTargetManagement().findTargetByControllerIDWithDetails(targ.getControllerId());
final Target target = getTargetManagement().findTargetByControllerIDWithDetails(targ.getControllerId())
.get();
final DistributionSet installedDistributionSet = target.getTargetInfo().getInstalledDistributionSet();
prxyTarget.setInstalledDistributionSet(installedDistributionSet);
final DistributionSet assignedDistributionSet = target.getAssignedDistributionSet();

View File

@@ -17,6 +17,7 @@ import org.eclipse.hawkbit.ui.common.tagdetails.AbstractTargetTagToken;
import org.eclipse.hawkbit.ui.management.state.ManagementUIState;
import org.eclipse.hawkbit.ui.utils.I18N;
import org.eclipse.hawkbit.ui.utils.UINotification;
import org.springframework.data.domain.PageRequest;
import org.vaadin.spring.events.EventBus.UIEventBus;
/**
@@ -26,6 +27,8 @@ import org.vaadin.spring.events.EventBus.UIEventBus;
public class TargetBulkTokenTags extends AbstractTargetTagToken {
private static final long serialVersionUID = 4159616629565523717L;
private static final int MAX_TAGS = 500;
TargetBulkTokenTags(final SpPermissionChecker checker, final I18N i18n, final UINotification uinotification,
final UIEventBus eventBus, final ManagementUIState managementUIState, final TagManagement tagManagement) {
super(checker, i18n, uinotification, eventBus, managementUIState, tagManagement);
@@ -65,7 +68,7 @@ public class TargetBulkTokenTags extends AbstractTargetTagToken {
protected void addAlreadySelectedTags() {
for (final String tagName : managementUIState.getTargetTableFilters().getBulkUpload().getAssignedTagNames()) {
addNewToken(tagManagement.findTargetTag(tagName).getId());
addNewToken(tagManagement.findTargetTag(tagName).get().getId());
}
}
@@ -73,7 +76,7 @@ public class TargetBulkTokenTags extends AbstractTargetTagToken {
protected void populateContainer() {
container.removeAllItems();
tagDetails.clear();
for (final TargetTag tag : tagManagement.findAllTargetTags()) {
for (final TargetTag tag : tagManagement.findAllTargetTags(new PageRequest(0, MAX_TAGS))) {
setContainerPropertValues(tag.getId(), tag.getName(), tag.getColour());
}

View File

@@ -22,6 +22,7 @@ import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -295,7 +296,7 @@ public class TargetTable extends AbstractTable<Target, Long> {
}
@Override
protected Target findEntityByTableValue(final Long lastSelectedId) {
protected Optional<Target> findEntityByTableValue(final Long lastSelectedId) {
return targetManagement.findTargetById(lastSelectedId);
}
@@ -540,8 +541,8 @@ public class TargetTable extends AbstractTable<Target, Long> {
Lists.newArrayListWithCapacity(0), null);
}
final TargetTag tag = tagManagement.findTargetTag(targTagName);
if (tag == null) {
final Optional<TargetTag> tag = tagManagement.findTargetTag(targTagName);
if (!tag.isPresent()) {
notification.displayWarning(i18n.get("targettag.not.exists", new Object[] { targTagName }));
return new TargetTagAssignmentResult(0, 0, 0, Lists.newArrayListWithCapacity(0),
Lists.newArrayListWithCapacity(0), null);
@@ -594,12 +595,12 @@ public class TargetTable extends AbstractTable<Target, Long> {
return;
}
final Long targetId = (Long) targetItemId;
final Target target = targetManagement.findTargetById(targetId);
if (target == null) {
final Optional<Target> target = targetManagement.findTargetById(targetId);
if (!target.isPresent()) {
getNotification().displayWarning(i18n.get("target.not.exists", new Object[] { "" }));
return;
}
final TargetIdName createTargetIdName = new TargetIdName(target);
final TargetIdName createTargetIdName = new TargetIdName(target.get());
final List<DistributionSet> findDistributionSetAllById = distributionSetManagement
.findDistributionSetAllById(ids);

View File

@@ -8,6 +8,7 @@
*/
package org.eclipse.hawkbit.ui.management.targettable;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.Executor;
@@ -339,13 +340,13 @@ public class TargetTableHeader extends AbstractTableHeader {
return;
}
final Long distributionSetId = distributionIdSet.iterator().next();
final DistributionSet distributionSet = distributionSetManagement
final Optional<DistributionSet> distributionSet = distributionSetManagement
.findDistributionSetById(distributionSetId);
if (distributionSet == null) {
if (!distributionSet.isPresent()) {
notification.displayWarning(i18n.get("distributionset.not.exists"));
return;
}
final DistributionSetIdName distributionSetIdName = new DistributionSetIdName(distributionSet);
final DistributionSetIdName distributionSetIdName = new DistributionSetIdName(distributionSet.get());
managementUIState.getTargetTableFilters().setDistributionSet(distributionSetIdName);
addFilterTextField(distributionSetIdName);
}

View File

@@ -10,7 +10,7 @@ package org.eclipse.hawkbit.ui.management.targettag;
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
import java.util.List;
import java.util.Optional;
import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.TagManagement;
@@ -25,6 +25,7 @@ import org.eclipse.hawkbit.ui.management.event.TargetTagTableEvent;
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
import org.eclipse.hawkbit.ui.utils.I18N;
import org.eclipse.hawkbit.ui.utils.UINotification;
import org.springframework.data.domain.PageRequest;
import org.vaadin.spring.events.EventBus.UIEventBus;
/**
@@ -35,6 +36,8 @@ public class CreateUpdateTargetTagLayoutWindow extends AbstractCreateUpdateTagLa
private static final long serialVersionUID = 2446682350481560235L;
private static final int MAX_TAGS = 500;
/**
* Constructor for CreateUpdateTargetTagLayoutWindow
*
@@ -69,8 +72,8 @@ public class CreateUpdateTargetTagLayoutWindow extends AbstractCreateUpdateTagLa
@Override
public void populateTagNameCombo() {
tagNameComboBox.removeAllItems();
final List<TargetTag> trgTagNameList = tagManagement.findAllTargetTags();
trgTagNameList.forEach(value -> tagNameComboBox.addItem(value.getName()));
tagManagement.findAllTargetTags(new PageRequest(0, MAX_TAGS))
.forEach(value -> tagNameComboBox.addItem(value.getName()));
}
/**
@@ -83,14 +86,14 @@ public class CreateUpdateTargetTagLayoutWindow extends AbstractCreateUpdateTagLa
@Override
public void setTagDetails(final String targetTagSelected) {
tagName.setValue(targetTagSelected);
final TargetTag selectedTargetTag = tagManagement.findTargetTag(targetTagSelected);
if (selectedTargetTag != null) {
tagDesc.setValue(selectedTargetTag.getDescription());
if (null == selectedTargetTag.getColour()) {
final Optional<TargetTag> selectedTargetTag = tagManagement.findTargetTag(targetTagSelected);
if (selectedTargetTag.isPresent()) {
tagDesc.setValue(selectedTargetTag.get().getDescription());
if (null == selectedTargetTag.get().getColour()) {
setTagColor(getColorPickerLayout().getDefaultColor(), ColorPickerConstants.DEFAULT_COLOR);
} else {
setTagColor(ColorPickerHelper.rgbToColorConverter(selectedTargetTag.getColour()),
selectedTargetTag.getColour());
setTagColor(ColorPickerHelper.rgbToColorConverter(selectedTargetTag.get().getColour()),
selectedTargetTag.get().getColour());
}
}
}
@@ -106,7 +109,7 @@ public class CreateUpdateTargetTagLayoutWindow extends AbstractCreateUpdateTagLa
}
@Override
protected TargetTag findEntityByName() {
protected Optional<TargetTag> findEntityByName() {
return tagManagement.findTargetTag(tagName.getValue());
}

View File

@@ -52,7 +52,7 @@ public class CustomTargetTagFilterButtonClick extends AbstractFilterSingleButton
@Override
protected void filterClicked(final Button clickedButton) {
final TargetFilterQuery targetFilterQuery = this.targetFilterQueryManagement
.findTargetFilterQueryById((Long) clickedButton.getData());
.findTargetFilterQueryById((Long) clickedButton.getData()).get();
this.managementUIState.getTargetTableFilters().setTargetFilterQuery(targetFilterQuery.getId());
this.eventBus.publish(this, TargetFilterEvent.FILTER_BY_TARGET_FILTER_QUERY);
}

View File

@@ -331,7 +331,7 @@ public final class DashboardMenu extends CustomComponent {
*/
public DashboardMenuItem getByViewName(final String viewName) {
final Optional<DashboardMenuItem> findFirst = dashboardVaadinViews.stream()
.filter(view -> view.getViewName().equals(viewName)).findFirst();
.filter(view -> view.getViewName().equals(viewName)).findAny();
if (!findFirst.isPresent()) {
return null;

View File

@@ -8,11 +8,12 @@
*/
package org.eclipse.hawkbit.ui.rollout.groupschart;
import org.eclipse.hawkbit.ui.rollout.groupschart.client.GroupsPieChartState;
import com.vaadin.ui.AbstractComponent;
import java.util.List;
import org.eclipse.hawkbit.ui.rollout.groupschart.client.GroupsPieChartState;
import com.vaadin.ui.AbstractComponent;
/**
* Draws a pie charts for the provided groups.
*/

View File

@@ -8,10 +8,11 @@
*/
package org.eclipse.hawkbit.ui.rollout.groupschart.client;
import com.vaadin.client.communication.StateChangeEvent;
import org.eclipse.hawkbit.ui.rollout.groupschart.GroupsPieChart;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractComponentConnector;
import com.vaadin.shared.ui.Connect;

View File

@@ -8,10 +8,10 @@
*/
package org.eclipse.hawkbit.ui.rollout.groupschart.client;
import com.vaadin.shared.AbstractComponentState;
import java.util.List;
import com.vaadin.shared.AbstractComponentState;
/**
* State to transfer for the groups pie chart between server and client.
*/

View File

@@ -620,7 +620,8 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
private boolean duplicateCheckForEdit() {
final String rolloutNameVal = getRolloutName();
if (!rollout.getName().equals(rolloutNameVal) && rolloutManagement.findRolloutByName(rolloutNameVal) != null) {
if (!rollout.getName().equals(rolloutNameVal)
&& rolloutManagement.findRolloutByName(rolloutNameVal).isPresent()) {
uiNotification.displayValidationError(i18n.get("message.rollout.duplicate.check", rolloutNameVal));
return false;
}
@@ -707,7 +708,7 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
}
private boolean duplicateCheck() {
if (rolloutManagement.findRolloutByName(getRolloutName()) != null) {
if (rolloutManagement.findRolloutByName(getRolloutName()).isPresent()) {
uiNotification.displayValidationError(i18n.get("message.rollout.duplicate.check", getRolloutName()));
return false;
}
@@ -854,7 +855,7 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
return;
}
rollout = rolloutManagement.findRolloutById(rolloutId);
rollout = rolloutManagement.findRolloutById(rolloutId).get();
description.setValue(rollout.getDescription());
distributionSet.setValue(rollout.getDistributionSet().getId());
setActionType(rollout);

View File

@@ -12,7 +12,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import com.vaadin.ui.UI;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.RolloutManagement;
@@ -60,6 +59,7 @@ import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextArea;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
/**
* Define groups for a Rollout
@@ -278,8 +278,8 @@ public class DefineGroupsLayout extends GridLayout {
final UI ui = UI.getCurrent();
runningValidation = rolloutManagement
.validateTargetsInGroups(savedRolloutGroups, targetFilter, System.currentTimeMillis());
runningValidation = rolloutManagement.validateTargetsInGroups(savedRolloutGroups, targetFilter,
System.currentTimeMillis());
runningValidation.addCallback(validation -> ui.access(() -> this.setGroupsValidation(validation)),
throwable -> ui.access(() -> this.setGroupsValidation(null)));
@@ -288,7 +288,7 @@ public class DefineGroupsLayout extends GridLayout {
private void setGroupsValidation(RolloutGroupsValidation validation) {
groupsValidation = validation;
if(validationRequested) {
if (validationRequested) {
validateRemainingTargets();
return;
}
@@ -317,9 +317,7 @@ public class DefineGroupsLayout extends GridLayout {
* Status of the groups validation
*/
public enum ValidationStatus {
VALID,
INVALID,
LOADING
VALID, INVALID, LOADING
}
/**
@@ -337,7 +335,6 @@ public class DefineGroupsLayout extends GridLayout {
void validation(ValidationStatus isValid);
}
private class GroupRow {
private TextField groupName;

View File

@@ -8,17 +8,18 @@
*/
package org.eclipse.hawkbit.ui.rollout.rollout;
import com.vaadin.ui.Component;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;
import java.util.Collections;
import java.util.List;
import org.eclipse.hawkbit.repository.builder.RolloutGroupCreate;
import org.eclipse.hawkbit.repository.model.RolloutGroup;
import org.eclipse.hawkbit.repository.model.RolloutGroupsValidation;
import org.eclipse.hawkbit.ui.common.builder.LabelBuilder;
import org.eclipse.hawkbit.ui.utils.I18N;
import java.util.Collections;
import java.util.List;
import com.vaadin.ui.Component;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;
/**
* Displays a legend for the Groups of a Rollout with the count of targets in
@@ -112,8 +113,8 @@ public class GroupsLegendLayout extends VerticalLayout {
}
/**
* Display an indication that the legend is being calculated.
* When the loading process is done one of the populate methods should be called.
* Display an indication that the legend is being calculated. When the
* loading process is done one of the populate methods should be called.
*/
public void displayLoading() {
populateGroupsLegendByTargetCounts(Collections.emptyList());
@@ -178,7 +179,8 @@ public class GroupsLegendLayout extends VerticalLayout {
* @param groups
* List of groups with their name
*/
public void populateGroupsLegendByValidation(final RolloutGroupsValidation validation, final List<RolloutGroupCreate> groups) {
public void populateGroupsLegendByValidation(final RolloutGroupsValidation validation,
final List<RolloutGroupCreate> groups) {
loadingLabel.setVisible(false);
if (validation == null) {
return;

View File

@@ -177,7 +177,8 @@ public class RolloutListGrid extends AbstractGrid {
if (!rolloutUIState.isShowRollOuts()) {
return;
}
final Rollout rollout = rolloutManagement.findRolloutWithDetailedStatus(rolloutChangeEvent.getRolloutId());
final Rollout rollout = rolloutManagement.findRolloutWithDetailedStatus(rolloutChangeEvent.getRolloutId())
.get();
final TotalTargetCountStatus totalTargetCountStatus = rollout.getTotalTargetCountStatus();
final LazyQueryContainer rolloutContainer = (LazyQueryContainer) getContainerDataSource();
final Item item = rolloutContainer.getItem(rolloutChangeEvent.getRolloutId());

View File

@@ -287,7 +287,7 @@ public class RolloutGroupListGrid extends AbstractGrid {
@Override
public void click(final RendererClickEvent event) {
rolloutUIState.setRolloutGroup(
rolloutGroupManagement.findRolloutGroupWithDetailedStatus((Long) event.getItemId()));
rolloutGroupManagement.findRolloutGroupWithDetailedStatus((Long) event.getItemId()).get());
eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUP_TARGETS);
}
}