Remove unnecessary DB calls from UI
Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
@@ -63,7 +63,8 @@ public interface TargetManagement {
|
||||
*
|
||||
* @return number of found {@link Target}s.
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET + SpringEvalExpressions.HAS_AUTH_OR
|
||||
+ SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
Long countTargetByAssignedDistributionSet(@NotNull Long distId);
|
||||
|
||||
/**
|
||||
@@ -104,7 +105,8 @@ public interface TargetManagement {
|
||||
* to search for
|
||||
* @return number of found {@link Target}s.
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET + SpringEvalExpressions.HAS_AUTH_OR
|
||||
+ SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
Long countTargetByInstalledDistributionSet(@NotNull Long distId);
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,8 +11,6 @@ package org.eclipse.hawkbit.repository.model;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
|
||||
/**
|
||||
* A {@link DistributionSet} defines a meta package that combines a set of
|
||||
* {@link SoftwareModule}s which have to be or are provisioned to a
|
||||
@@ -36,12 +34,6 @@ public interface DistributionSet extends NamedVersionedEntity {
|
||||
*/
|
||||
boolean isDeleted();
|
||||
|
||||
/**
|
||||
* @return immutable {@link List} of {@link DistributionSetMetadata}
|
||||
* elements. See {@link DistributionSetManagement} to alter.
|
||||
*/
|
||||
List<DistributionSetMetadata> getMetadata();
|
||||
|
||||
/**
|
||||
* @return <code>true</code> if {@link DistributionSet} contains a mandatory
|
||||
* migration step, i.e. unfinished {@link Action}s will kept active
|
||||
@@ -49,21 +41,11 @@ public interface DistributionSet extends NamedVersionedEntity {
|
||||
*/
|
||||
boolean isRequiredMigrationStep();
|
||||
|
||||
/**
|
||||
* @return the assignedTargets
|
||||
*/
|
||||
List<Target> getAssignedTargets();
|
||||
|
||||
/**
|
||||
* @return the auto assign target filters
|
||||
*/
|
||||
List<TargetFilterQuery> getAutoAssignFilters();
|
||||
|
||||
/**
|
||||
* @return the installedTargets
|
||||
*/
|
||||
List<TargetInfo> getInstalledTargets();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return unmodifiableSet of {@link SoftwareModule}.
|
||||
|
||||
@@ -231,7 +231,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
}
|
||||
|
||||
private JpaDistributionSet findDistributionSetAndThrowExceptionIfNotFound(final Long setId) {
|
||||
final JpaDistributionSet set = (JpaDistributionSet) findDistributionSetByIdWithDetails(setId);
|
||||
final JpaDistributionSet set = (JpaDistributionSet) findDistributionSetById(setId);
|
||||
|
||||
if (set == null) {
|
||||
throw new EntityNotFoundException("Distribution set cannot be updated as it does not exixt" + setId);
|
||||
|
||||
@@ -34,7 +34,7 @@ public interface TargetTagRepository
|
||||
*/
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
Long deleteByName(final String tagName);
|
||||
Long deleteByName(String tagName);
|
||||
|
||||
/**
|
||||
* find {@link TargetTag} by its name.
|
||||
@@ -43,7 +43,7 @@ public interface TargetTagRepository
|
||||
* to filter on
|
||||
* @return the {@link TargetTag} if found, otherwise null
|
||||
*/
|
||||
JpaTargetTag findByNameEquals(final String tagName);
|
||||
JpaTargetTag findByNameEquals(String tagName);
|
||||
|
||||
/**
|
||||
* Returns all instances of the type.
|
||||
|
||||
@@ -209,7 +209,6 @@ public class JpaDistributionSet extends AbstractJpaNamedVersionedEntity implemen
|
||||
return deleted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DistributionSetMetadata> getMetadata() {
|
||||
if (metadata == null) {
|
||||
return Collections.emptyList();
|
||||
@@ -241,29 +240,11 @@ public class JpaDistributionSet extends AbstractJpaNamedVersionedEntity implemen
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Target> getAssignedTargets() {
|
||||
if (assignedToTargets == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return Collections.unmodifiableList(assignedToTargets);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TargetFilterQuery> getAutoAssignFilters() {
|
||||
return autoAssignFilters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TargetInfo> getInstalledTargets() {
|
||||
if (installedAtTargets == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return Collections.unmodifiableList(installedAtTargets);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DistributionSet [getName()=" + getName() + ", getOptLockRevision()=" + getOptLockRevision()
|
||||
|
||||
@@ -176,14 +176,6 @@ public class JpaSoftwareModule extends AbstractJpaNamedVersionedEntity implement
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public List<SoftwareModuleMetadata> getMetadata() {
|
||||
if (metadata == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return Collections.unmodifiableList(metadata);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SoftwareModule [deleted=" + deleted + ", name=" + getName() + ", version=" + getVersion()
|
||||
|
||||
@@ -83,7 +83,6 @@ public final class DistributionSetSpecification {
|
||||
targetRoot.fetch(JpaDistributionSet_.modules, JoinType.LEFT);
|
||||
targetRoot.fetch(JpaDistributionSet_.tags, JoinType.LEFT);
|
||||
targetRoot.fetch(JpaDistributionSet_.type, JoinType.LEFT);
|
||||
targetRoot.fetch(JpaDistributionSet_.metadata, JoinType.LEFT);
|
||||
query.distinct(true);
|
||||
|
||||
return predicate;
|
||||
@@ -110,8 +109,8 @@ public final class DistributionSetSpecification {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Specification} for retrieving {@link DistributionSet}s by
|
||||
* "like name or like description or like version".
|
||||
* {@link Specification} for retrieving {@link DistributionSet}s by "like
|
||||
* name or like description or like version".
|
||||
*
|
||||
* @param subString
|
||||
* to be filtered on
|
||||
@@ -125,8 +124,8 @@ public final class DistributionSetSpecification {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Specification} for retrieving {@link DistributionSet}s by
|
||||
* "has at least one of the given tag names".
|
||||
* {@link Specification} for retrieving {@link DistributionSet}s by "has at
|
||||
* least one of the given tag names".
|
||||
*
|
||||
* @param tagNames
|
||||
* to be filtered on
|
||||
|
||||
@@ -77,8 +77,6 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent {
|
||||
|
||||
private TextArea descTextArea;
|
||||
|
||||
private CommonDialogWindow window;
|
||||
|
||||
private Boolean editSwModule = Boolean.FALSE;
|
||||
|
||||
private Long baseSwModuleId;
|
||||
@@ -133,9 +131,9 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent {
|
||||
public CommonDialogWindow createUpdateSoftwareModuleWindow(final Long baseSwModuleId) {
|
||||
this.baseSwModuleId = baseSwModuleId;
|
||||
resetComponents();
|
||||
populateTypeNameCombo();
|
||||
populateValuesOfSwModule();
|
||||
createWindow();
|
||||
return window;
|
||||
return createWindow();
|
||||
}
|
||||
|
||||
private void createRequiredComponents() {
|
||||
@@ -157,7 +155,6 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent {
|
||||
typeComboBox.setStyleName(SPUIDefinitions.COMBO_BOX_SPECIFIC_STYLE + " " + ValoTheme.COMBOBOX_TINY);
|
||||
typeComboBox.setNewItemsAllowed(Boolean.FALSE);
|
||||
typeComboBox.setImmediate(Boolean.TRUE);
|
||||
populateTypeNameCombo();
|
||||
}
|
||||
|
||||
private TextField createTextField(final String in18Key, final String id) {
|
||||
@@ -181,7 +178,7 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent {
|
||||
editSwModule = Boolean.FALSE;
|
||||
}
|
||||
|
||||
private void createWindow() {
|
||||
private CommonDialogWindow createWindow() {
|
||||
final Label madatoryStarLabel = new Label("*");
|
||||
madatoryStarLabel.setStyleName("v-caption v-required-field-indicator");
|
||||
madatoryStarLabel.setWidth(null);
|
||||
@@ -198,7 +195,7 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent {
|
||||
|
||||
setCompositionRoot(formLayout);
|
||||
|
||||
window = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW)
|
||||
final CommonDialogWindow window = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW)
|
||||
.caption(i18n.get("upload.caption.add.new.swmodule")).content(this).layout(formLayout).i18n(i18n)
|
||||
.saveDialogCloseListener(new SaveOnDialogCloseListener()).buildCommonDialogWindow();
|
||||
nameTextField.setEnabled(!editSwModule);
|
||||
@@ -206,6 +203,8 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent {
|
||||
typeComboBox.setEnabled(!editSwModule);
|
||||
|
||||
typeComboBox.focus();
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
private void addNewBaseSoftware() {
|
||||
@@ -271,6 +270,7 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent {
|
||||
: HawkbitCommonUtil.trimAndNullIfEmpty(swModle.getVendor()));
|
||||
descTextArea.setValue(swModle.getDescription() == null ? HawkbitCommonUtil.SP_STRING_EMPTY
|
||||
: HawkbitCommonUtil.trimAndNullIfEmpty(swModle.getDescription()));
|
||||
|
||||
if (swModle.getType().isDeleted()) {
|
||||
typeComboBox.addItem(swModle.getType().getName());
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import java.util.Set;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.SoftwareManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleIdName;
|
||||
@@ -81,6 +82,9 @@ public class DistributionSetDetails extends AbstractNamedVersionedEntityTableDet
|
||||
@Autowired
|
||||
private transient DistributionSetManagement distributionSetManagement;
|
||||
|
||||
@Autowired
|
||||
private transient TargetManagement targetManagement;
|
||||
|
||||
@Autowired
|
||||
private DsMetadataPopupLayout dsMetadataPopupLayout;
|
||||
|
||||
@@ -183,9 +187,8 @@ public class DistributionSetDetails extends AbstractNamedVersionedEntityTableDet
|
||||
private Button assignSoftModuleButton(final String softwareModuleName) {
|
||||
if (getPermissionChecker().hasUpdateDistributionPermission()
|
||||
&& manageDistUIState.getLastSelectedDistribution().isPresent()
|
||||
&& distributionSetManagement
|
||||
.findDistributionSetById(manageDistUIState.getLastSelectedDistribution().get().getId())
|
||||
.getAssignedTargets().isEmpty()) {
|
||||
&& targetManagement.countTargetByAssignedDistributionSet(
|
||||
manageDistUIState.getLastSelectedDistribution().get().getId()) <= 0) {
|
||||
final Button reassignSoftModule = SPUIComponentProvider.getButton(softwareModuleName, "", "", "", true,
|
||||
FontAwesome.TIMES, SPUIButtonStyleSmallNoBorder.class);
|
||||
reassignSoftModule.setEnabled(false);
|
||||
|
||||
@@ -73,7 +73,8 @@ public class DsMetadataPopupLayout extends AbstractMetadataPopupLayout<Distribut
|
||||
|
||||
@Override
|
||||
protected List<MetaData> getMetadataList() {
|
||||
return Collections.unmodifiableList(getSelectedEntity().getMetadata());
|
||||
return Collections.unmodifiableList(
|
||||
distributionSetManagement.findDistributionSetMetadataByDistributionSetId(getSelectedEntity().getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -149,7 +149,6 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
|
||||
distsetTypeNameComboBox.setImmediate(true);
|
||||
distsetTypeNameComboBox.setNullSelectionAllowed(false);
|
||||
distsetTypeNameComboBox.setId(UIComponentIdProvider.DIST_ADD_DISTSETTYPE);
|
||||
populateDistSetTypeNameCombo();
|
||||
|
||||
descTextArea = new TextAreaBuilder().caption(i18n.get("textfield.description")).style("text-area-style")
|
||||
.prompt(i18n.get("textfield.description")).immediate(true).id(UIComponentIdProvider.DIST_ADD_DESC)
|
||||
|
||||
@@ -202,8 +202,7 @@ public class DistributionDetails extends AbstractNamedVersionedEntityTableDetail
|
||||
|
||||
@Override
|
||||
protected void showMetadata(final ClickEvent event) {
|
||||
final DistributionSet ds = distributionSetManagement
|
||||
.findDistributionSetByIdWithDetails(getSelectedBaseEntityId());
|
||||
final DistributionSet ds = distributionSetManagement.findDistributionSetById(getSelectedBaseEntityId());
|
||||
UI.getCurrent().addWindow(dsMetadataPopupLayout.getWindow(ds, null));
|
||||
}
|
||||
|
||||
|
||||
@@ -767,7 +767,7 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
|
||||
private void showMetadataDetails(final Object itemId) {
|
||||
final DistributionSetIdName distIdName = (DistributionSetIdName) getContainerDataSource().getItem(itemId)
|
||||
.getItemProperty(SPUILabelDefinitions.VAR_DIST_ID_NAME).getValue();
|
||||
final DistributionSet ds = distributionSetManagement.findDistributionSetByIdWithDetails(distIdName.getId());
|
||||
final DistributionSet ds = distributionSetManagement.findDistributionSetById(distIdName.getId());
|
||||
UI.getCurrent().addWindow(dsMetadataPopupLayout.getWindow(ds, null));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user