Feature/ctx aware and access controller2 (#1456)
* Introduce the AccessControlManager and use if for the TargetManagement and TargetTypeManagement. Signed-off-by: Michael Herdt <Michael.Herdt@bosch.io> * Extend the access control manager by an API to serialize the current active context and persist it for scheduled background operations like auto-assignment. Signed-off-by: Michael Herdt <Michael.Herdt@bosch.io> * Verify modification is permitted before performing automatic assignment Signed-off-by: Michael Herdt <Michael.Herdt@bosch.io> * Start with controlling distribution set type access. Perform some refactoring. Signed-off-by: Michael Herdt <Michael.Herdt@bosch.io> * Support distribution set access control. Increase character limit to 512 chars for access control context. Refactor default implementations. Signed-off-by: Michael Herdt <Michael.Herdt@bosch.io> * Introduce ContextRunner and define admin execution to check for duplicates before creating/updating entities. Signed-off-by: Michael Herdt <Michael.Herdt@bosch.io> * Introduce Software Module, Module Type and Artifact control management. Fix tests. Signed-off-by: Michael Herdt <Michael.Herdt@bosch.io> * Introduce access controlling test base. Add first test verifying the read operations for target types. Signed-off-by: Michael Herdt <Michael.Herdt@bosch.io> * Finalize target type access controlling test. Signed-off-by: Michael Herdt <Michael.Herdt@bosch.io> * Introduce ContextRunnerTest and TargetAccessControllingTest. Signed-off-by: Michael Herdt <Michael.Herdt@bosch.io> * Introduce DistributionSetAccessControllingTest and fix missing access control specifications. Signed-off-by: Michael Herdt <Michael.Herdt@bosch.io> * Extend test cases. Include only updatable targets into rollout. Signed-off-by: Michael Herdt <Michael.Herdt@bosch.io> * Fix action visibility. Signed-off-by: Michael Herdt <Michael.Herdt@bosch.io> * Modifiable->Updatable & UPDATE check where needed Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com> * ContextRunner superseded by ContextAware + ContextRunner remaned to ContextAware (move as a cenral entry/concept). It now extends (and replace) TenantAware + SecurityContextTenantAware becomes ContextAware + Pluggable serialization mechanism (default Java serialization of contexts) for SecurityContextTenantAware (using SecurityContextSerializer) + AccessControl methods are added to ensure no entities fill be retrieved just to call access control - so, if all permitted - no additional db queries will be made + <repo type>AccessControl classes removed and replaced with AccessControl <repo type> generics + AccessControlService removed - every AccessControl is registered and overiden independently + access_control_context in DB increased to 4k (in order to support java security context serialization) + needed adaptaion of implemtation and tests done Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com> * Refactor SoftModules & DistSets Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com> * Refactoring of the Repositories Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com> * Repostiotory level permissions Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com> * Improvements Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com> * Simplification of AccessControl interface * Simplifications & management package Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com> * Implementation improvements + Artifact management & repo reviewed and tuned + Action(Status) management & repo reviewed and tuned + SoftwareModule(Type/Meta) management & repo reviewed and tuned + DistributionSet(Type/Tag/Meta) management(+Invalidation) & repo reviewed and tuned + Target(Tag/Type/Meta) management & repo reviewed and tuned + TargetQueryFilter management & repo reviewed and tuned * Apply suggestions from code review Suggestions accepted. Thanks @herdt-michael Co-authored-by: Michael Herdt <michael.herdt@bosch.com> * Apply suggestions from code review 2 Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com> --------- Signed-off-by: Michael Herdt <Michael.Herdt@bosch.io> Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com> Co-authored-by: Michael Herdt <Michael.Herdt@bosch.com>
This commit is contained in:
@@ -78,7 +78,6 @@ public class TargetsToNoTargetTypeAssignmentSupport extends AbstractTargetsToTar
|
||||
final Collection<String> controllerIdsToAssign = sourceItems.stream().map(ProxyTarget::getControllerId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return targetManagement.unAssignType(controllerIdsToAssign);
|
||||
return targetManagement.unassignType(controllerIdsToAssign);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ public class TargetTagToken extends AbstractTagToken<ProxyTarget> {
|
||||
getMasterEntity().ifPresent(masterEntity -> {
|
||||
final Long masterEntityId = masterEntity.getId();
|
||||
|
||||
final Target unassignedTarget = targetManagement.unAssignTag(masterEntity.getControllerId(),
|
||||
final Target unassignedTarget = targetManagement.unassignTag(masterEntity.getControllerId(),
|
||||
tagData.getId());
|
||||
if (checkUnassignmentResult(unassignedTarget, masterEntityId)) {
|
||||
uiNotification.displaySuccess(getAssignmentMsgFor("message.unassigned.one",
|
||||
|
||||
@@ -106,7 +106,7 @@ public class AutoAssignmentWindowController extends
|
||||
// store/show dialog
|
||||
if (entity.isAutoAssignmentEnabled() && entity.getDistributionSetInfo() != null) {
|
||||
final Long autoAssignDsId = entity.getDistributionSetInfo().getId();
|
||||
final Long targetsForAutoAssignmentCount = targetManagement.countByRsqlAndNonDSAndCompatible(autoAssignDsId,
|
||||
final long targetsForAutoAssignmentCount = targetManagement.countByRsqlAndNonDSAndCompatibleAndUpdatable(autoAssignDsId,
|
||||
entity.getQuery());
|
||||
|
||||
final String confirmationCaption = getI18n()
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetTagManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
||||
import org.eclipse.hawkbit.ContextAware;
|
||||
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
import org.eclipse.hawkbit.ui.AbstractHawkbitUI;
|
||||
@@ -102,7 +103,8 @@ public class DeploymentView extends AbstractEventListenersAwareView implements B
|
||||
final TenantConfigurationManagement configManagement,
|
||||
final TargetManagementStateDataSupplier targetManagementStateDataSupplier,
|
||||
final SystemSecurityContext systemSecurityContext, @Qualifier("uiExecutor") final Executor uiExecutor,
|
||||
final TenantAware tenantAware, final ConfirmationManagement confirmationManagement) {
|
||||
final TenantAware tenantAware, final ConfirmationManagement confirmationManagement,
|
||||
final ContextAware contextAware) {
|
||||
this.permChecker = permChecker;
|
||||
this.managementUIState = managementUIState;
|
||||
|
||||
@@ -112,14 +114,15 @@ public class DeploymentView extends AbstractEventListenersAwareView implements B
|
||||
if (permChecker.hasTargetReadPermission()) {
|
||||
this.targetTagFilterLayout = new TargetTagFilterLayout(uiDependencies, managementUIState,
|
||||
targetFilterQueryManagement, targetTypeManagement, targetTagManagement, targetManagement,
|
||||
managementUIState.getTargetTagFilterLayoutUiState(), distributionSetTypeManagement);
|
||||
managementUIState.getTargetTagFilterLayoutUiState(), distributionSetTypeManagement, contextAware);
|
||||
|
||||
this.targetGridLayout = new TargetGridLayout(uiDependencies, targetManagement, targetTypeManagement,
|
||||
deploymentManagement, uiProperties, targetTagManagement, distributionSetManagement, uiExecutor,
|
||||
configManagement, targetManagementStateDataSupplier, systemSecurityContext,
|
||||
managementUIState.getTargetTagFilterLayoutUiState(), managementUIState.getTargetGridLayoutUiState(),
|
||||
managementUIState.getTargetBulkUploadUiState(),
|
||||
managementUIState.getDistributionGridLayoutUiState(), tenantAware, confirmationManagement);
|
||||
managementUIState.getDistributionGridLayoutUiState(), tenantAware, confirmationManagement,
|
||||
contextAware);
|
||||
this.targetCountLayout = targetGridLayout.getCountMessageLabel().createFooterMessageComponent();
|
||||
|
||||
this.actionHistoryLayout = new ActionHistoryLayout(uiDependencies, deploymentManagement,
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
package org.eclipse.hawkbit.ui.management.targettable;
|
||||
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.ContextAware;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.ui.common.AbstractAddNamedEntityWindowController;
|
||||
import org.eclipse.hawkbit.ui.common.CommonUiDependencies;
|
||||
@@ -31,6 +32,7 @@ public class AddTargetWindowController
|
||||
private final TargetWindowLayout layout;
|
||||
private final EventView view;
|
||||
private final ProxyTargetValidator proxyTargetValidator;
|
||||
private final ContextAware contextAware;
|
||||
|
||||
/**
|
||||
* Constructor for AddTargetWindowController
|
||||
@@ -45,13 +47,15 @@ public class AddTargetWindowController
|
||||
* EventView
|
||||
*/
|
||||
public AddTargetWindowController(final CommonUiDependencies uiDependencies, final TargetManagement targetManagement,
|
||||
final TargetWindowLayout layout, final EventView view) {
|
||||
final TargetWindowLayout layout, final EventView view,
|
||||
final ContextAware contextAware) {
|
||||
super(uiDependencies);
|
||||
|
||||
this.targetManagement = targetManagement;
|
||||
this.layout = layout;
|
||||
this.view = view;
|
||||
this.proxyTargetValidator = new ProxyTargetValidator(uiDependencies);
|
||||
this.contextAware = contextAware;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -103,8 +107,12 @@ public class AddTargetWindowController
|
||||
|
||||
@Override
|
||||
protected boolean isEntityValid(final ProxyTarget entity) {
|
||||
return proxyTargetValidator.isEntityValid(entity,
|
||||
() -> targetManagement.getByControllerID(entity.getControllerId()).isPresent());
|
||||
return proxyTargetValidator.isEntityValid(
|
||||
entity,
|
||||
() -> contextAware.runAsTenant( // disable acm checks
|
||||
contextAware.getCurrentTenant(),
|
||||
() ->
|
||||
targetManagement.getByControllerID(entity.getControllerId()).isPresent()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetTagManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
||||
import org.eclipse.hawkbit.ContextAware;
|
||||
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
import org.eclipse.hawkbit.ui.UiProperties;
|
||||
@@ -116,9 +117,10 @@ public class TargetGridLayout extends AbstractGridComponentLayout {
|
||||
* TenantAware
|
||||
* @param confirmationManagement
|
||||
* ConfirmationManagement
|
||||
* @param contextAware
|
||||
* ContextAware
|
||||
*/
|
||||
public TargetGridLayout(
|
||||
final CommonUiDependencies uiDependencies, final TargetManagement targetManagement,
|
||||
public TargetGridLayout(final CommonUiDependencies uiDependencies, final TargetManagement targetManagement,
|
||||
final TargetTypeManagement targetTypeManagement, final DeploymentManagement deploymentManagement,
|
||||
final UiProperties uiProperties, final TargetTagManagement targetTagManagement,
|
||||
final DistributionSetManagement distributionSetManagement, final Executor uiExecutor,
|
||||
@@ -129,9 +131,9 @@ public class TargetGridLayout extends AbstractGridComponentLayout {
|
||||
final TargetGridLayoutUiState targetGridLayoutUiState,
|
||||
final TargetBulkUploadUiState targetBulkUploadUiState,
|
||||
final DistributionGridLayoutUiState distributionGridLayoutUiState, final TenantAware tenantAware,
|
||||
final ConfirmationManagement confirmationManagement) {
|
||||
final ConfirmationManagement confirmationManagement, final ContextAware contextAware) {
|
||||
final TargetWindowBuilder targetWindowBuilder = new TargetWindowBuilder(uiDependencies, targetManagement,
|
||||
targetTypeManagement, EventView.DEPLOYMENT);
|
||||
targetTypeManagement, EventView.DEPLOYMENT, contextAware);
|
||||
final TargetMetaDataWindowBuilder targetMetaDataWindowBuilder = new TargetMetaDataWindowBuilder(uiDependencies,
|
||||
targetManagement);
|
||||
final BulkUploadWindowBuilder bulkUploadWindowBuilder = new BulkUploadWindowBuilder(uiDependencies,
|
||||
@@ -169,7 +171,7 @@ public class TargetGridLayout extends AbstractGridComponentLayout {
|
||||
targetGrid.getSelectionSupport());
|
||||
this.targetModifiedListener = new EntityModifiedListener.Builder<>(uiDependencies.getEventBus(),
|
||||
ProxyTarget.class).viewAware(layoutViewAware)
|
||||
.entityModifiedAwareSupports(getTargetModifiedAwareSupports()).build();
|
||||
.entityModifiedAwareSupports(getTargetModifiedAwareSupports()).build();
|
||||
this.tagModifiedListener = new EntityModifiedListener.Builder<>(uiDependencies.getEventBus(), ProxyTag.class)
|
||||
.parentEntityType(ProxyTarget.class).viewAware(layoutViewAware)
|
||||
.entityModifiedAwareSupports(getTagModifiedAwareSupports()).build();
|
||||
|
||||
@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.ui.management.targettable;
|
||||
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement;
|
||||
import org.eclipse.hawkbit.ContextAware;
|
||||
import org.eclipse.hawkbit.ui.common.AbstractEntityWindowBuilder;
|
||||
import org.eclipse.hawkbit.ui.common.CommonUiDependencies;
|
||||
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyTarget;
|
||||
@@ -29,6 +30,7 @@ public class TargetWindowBuilder extends AbstractEntityWindowBuilder<ProxyTarget
|
||||
private final TargetTypeManagement targetTypeManagement;
|
||||
|
||||
private final EventView view;
|
||||
private final ContextAware contextAware;
|
||||
|
||||
/**
|
||||
* Constructor for TargetWindowBuilder
|
||||
@@ -41,14 +43,17 @@ public class TargetWindowBuilder extends AbstractEntityWindowBuilder<ProxyTarget
|
||||
* TargetTypeManagement
|
||||
* @param view
|
||||
* EventView
|
||||
* @param contextAware
|
||||
* ContextAware
|
||||
*/
|
||||
public TargetWindowBuilder(final CommonUiDependencies uiDependencies, final TargetManagement targetManagement,
|
||||
final TargetTypeManagement targetTypeManagement, final EventView view) {
|
||||
final TargetTypeManagement targetTypeManagement, final EventView view, final ContextAware contextAware) {
|
||||
super(uiDependencies);
|
||||
|
||||
this.targetManagement = targetManagement;
|
||||
this.targetTypeManagement = targetTypeManagement;
|
||||
this.view = view;
|
||||
this.contextAware = contextAware;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -59,13 +64,13 @@ public class TargetWindowBuilder extends AbstractEntityWindowBuilder<ProxyTarget
|
||||
@Override
|
||||
public Window getWindowForAdd() {
|
||||
return getWindowForNewEntity(new AddTargetWindowController(uiDependencies, targetManagement,
|
||||
new TargetWindowLayout(getI18n(), targetTypeManagement), view));
|
||||
new TargetWindowLayout(getI18n(), targetTypeManagement), view, contextAware));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Window getWindowForUpdate(final ProxyTarget proxyTarget) {
|
||||
return getWindowForEntity(proxyTarget, new UpdateTargetWindowController(uiDependencies, targetManagement,
|
||||
new TargetWindowLayout(getI18n(), targetTypeManagement)));
|
||||
new TargetWindowLayout(getI18n(), targetTypeManagement), contextAware));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
package org.eclipse.hawkbit.ui.management.targettable;
|
||||
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.ContextAware;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetUpdate;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.ui.common.AbstractUpdateNamedEntityWindowController;
|
||||
@@ -28,6 +29,7 @@ public class UpdateTargetWindowController
|
||||
|
||||
private String controllerIdBeforeEdit;
|
||||
private final ProxyTargetValidator proxyTargetValidator;
|
||||
private final ContextAware contextAware;
|
||||
|
||||
/**
|
||||
* Constructor for UpdateTargetWindowController
|
||||
@@ -38,14 +40,18 @@ public class UpdateTargetWindowController
|
||||
* TargetManagement
|
||||
* @param layout
|
||||
* TargetWindowLayout
|
||||
* @param contextAware
|
||||
* ContextAware
|
||||
*/
|
||||
public UpdateTargetWindowController(final CommonUiDependencies uiDependencies,
|
||||
final TargetManagement targetManagement, final TargetWindowLayout layout) {
|
||||
final TargetManagement targetManagement, final TargetWindowLayout layout,
|
||||
final ContextAware contextAware) {
|
||||
super(uiDependencies);
|
||||
|
||||
this.targetManagement = targetManagement;
|
||||
this.layout = layout;
|
||||
this.proxyTargetValidator = new ProxyTargetValidator(uiDependencies);
|
||||
this.contextAware = contextAware;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,9 +88,10 @@ public class UpdateTargetWindowController
|
||||
|
||||
final Target updatedTarget = targetManagement.update(targetUpdate);
|
||||
|
||||
// Un-assigning target type needs another DB request to update the target type value to Null
|
||||
if (entity.getTypeInfo() == null){
|
||||
return targetManagement.unAssignType(entity.getControllerId());
|
||||
// Un-assigning target type needs another DB request to update the target type
|
||||
// value to Null
|
||||
if (entity.getTypeInfo() == null) {
|
||||
return targetManagement.unassignType(entity.getControllerId());
|
||||
}
|
||||
|
||||
return updatedTarget;
|
||||
@@ -98,10 +105,14 @@ public class UpdateTargetWindowController
|
||||
@Override
|
||||
protected boolean isEntityValid(final ProxyTarget entity) {
|
||||
final String controllerId = entity.getControllerId();
|
||||
return proxyTargetValidator.isEntityValid(entity, () -> hasControllerIdChanged(controllerId)
|
||||
&& targetManagement.getByControllerID(controllerId).isPresent());
|
||||
return proxyTargetValidator.isEntityValid(entity,
|
||||
() -> contextAware.runAsTenant( // disable acm checks
|
||||
contextAware.getCurrentTenant(),
|
||||
() -> hasControllerIdChanged(controllerId)
|
||||
&& targetManagement.getByControllerID(controllerId).isPresent()));
|
||||
}
|
||||
|
||||
|
||||
private boolean hasControllerIdChanged(final String trimmedControllerId) {
|
||||
return !controllerIdBeforeEdit.equals(trimmedControllerId);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetTagManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement;
|
||||
import org.eclipse.hawkbit.ContextAware;
|
||||
import org.eclipse.hawkbit.ui.common.CommonUiDependencies;
|
||||
import org.eclipse.hawkbit.ui.common.event.EventTopics;
|
||||
import org.eclipse.hawkbit.ui.common.event.TargetFilterTabChangedEventPayload;
|
||||
@@ -57,12 +58,12 @@ public class TargetTagFilterLayout extends AbstractFilterLayout {
|
||||
final TargetFilterQueryManagement targetFilterQueryManagement,
|
||||
final TargetTypeManagement targetTypeManagement, final TargetTagManagement targetTagManagement,
|
||||
final TargetManagement targetManagement, final TargetTagFilterLayoutUiState targetTagFilterLayoutUiState,
|
||||
final DistributionSetTypeManagement distributionSetTypeManagement) {
|
||||
final DistributionSetTypeManagement distributionSetTypeManagement, final ContextAware contextAware) {
|
||||
final TargetTagWindowBuilder targetTagWindowBuilder = new TargetTagWindowBuilder(uiDependencies,
|
||||
targetTagManagement);
|
||||
|
||||
final TargetTypeWindowBuilder targetTypeWindowBuilder = new TargetTypeWindowBuilder(uiDependencies,
|
||||
targetTypeManagement, distributionSetTypeManagement);
|
||||
targetTypeManagement, distributionSetTypeManagement, contextAware);
|
||||
|
||||
this.targetTagFilterHeader = new TargetTagFilterHeader(uiDependencies, targetTagFilterLayoutUiState,
|
||||
targetTagWindowBuilder, targetTypeWindowBuilder);
|
||||
|
||||
@@ -12,6 +12,7 @@ package org.eclipse.hawkbit.ui.management.targettag.targettype;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement;
|
||||
import org.eclipse.hawkbit.ContextAware;
|
||||
import org.eclipse.hawkbit.repository.model.TargetType;
|
||||
import org.eclipse.hawkbit.ui.common.AbstractAddNamedEntityWindowController;
|
||||
import org.eclipse.hawkbit.ui.common.CommonUiDependencies;
|
||||
@@ -31,6 +32,7 @@ public class AddTargetTypeWindowController
|
||||
private final TargetTypeWindowLayout layout;
|
||||
private final ProxyTargetTypeValidator validator;
|
||||
private final TargetTypeManagement targetTypeManagement;
|
||||
private final ContextAware contextAware;
|
||||
|
||||
/**
|
||||
* Constructor for AddTargetTypeWindowController
|
||||
@@ -41,14 +43,18 @@ public class AddTargetTypeWindowController
|
||||
* targetTypeManagement
|
||||
* @param layout
|
||||
* TargetTypeWindowLayout
|
||||
* @param contextAware
|
||||
* ContextAware
|
||||
*/
|
||||
public AddTargetTypeWindowController(final CommonUiDependencies uiDependencies,
|
||||
final TargetTypeManagement targetTypeManagement, final TargetTypeWindowLayout layout) {
|
||||
final TargetTypeManagement targetTypeManagement, final TargetTypeWindowLayout layout,
|
||||
final ContextAware contextAware) {
|
||||
super(uiDependencies);
|
||||
|
||||
this.targetTypeManagement = targetTypeManagement;
|
||||
this.layout = layout;
|
||||
this.validator = new ProxyTargetTypeValidator(uiDependencies);
|
||||
this.contextAware = contextAware;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -63,10 +69,9 @@ public class AddTargetTypeWindowController
|
||||
|
||||
@Override
|
||||
protected TargetType persistEntityInRepository(final ProxyTargetType entity) {
|
||||
return targetTypeManagement.create(getEntityFactory().targetType().create()
|
||||
.name(entity.getName()).description(entity.getDescription()).colour(entity.getColour())
|
||||
.compatible(entity.getSelectedDsTypes().stream().map(ProxyType::getId)
|
||||
.collect(Collectors.toSet())));
|
||||
return targetTypeManagement.create(getEntityFactory().targetType().create().name(entity.getName())
|
||||
.description(entity.getDescription()).colour(entity.getColour())
|
||||
.compatible(entity.getSelectedDsTypes().stream().map(ProxyType::getId).collect(Collectors.toSet())));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -81,6 +86,9 @@ public class AddTargetTypeWindowController
|
||||
|
||||
@Override
|
||||
protected boolean isEntityValid(final ProxyTargetType entity) {
|
||||
return validator.isEntityValid(entity, () -> targetTypeManagement.getByName(entity.getName()).isPresent());
|
||||
return validator.isEntityValid(entity,
|
||||
() -> contextAware.runAsTenant( // disable acm checks
|
||||
contextAware.getCurrentTenant(),
|
||||
() -> targetTypeManagement.getByName(entity.getName()).isPresent()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ package org.eclipse.hawkbit.ui.management.targettag.targettype;
|
||||
import com.vaadin.ui.Window;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement;
|
||||
import org.eclipse.hawkbit.ContextAware;
|
||||
import org.eclipse.hawkbit.ui.common.AbstractEntityWindowBuilder;
|
||||
import org.eclipse.hawkbit.ui.common.CommonDialogWindow;
|
||||
import org.eclipse.hawkbit.ui.common.CommonUiDependencies;
|
||||
@@ -25,23 +26,28 @@ public class TargetTypeWindowBuilder extends AbstractEntityWindowBuilder<ProxyTa
|
||||
|
||||
private final TargetTypeManagement targetTypeManagement;
|
||||
private final DistributionSetTypeManagement dsTypeManagement;
|
||||
private final ContextAware contextAware;
|
||||
|
||||
/**
|
||||
* Constructor for TargetTypeWindowBuilder
|
||||
*
|
||||
* @param uiDependencies
|
||||
* {@link CommonUiDependencies}
|
||||
* @param dsTypeManagement
|
||||
* DistributionSetTypeManagement
|
||||
* @param targetTypeManagement
|
||||
* TargetTypeManagement
|
||||
* @param dsTypeManagement
|
||||
* DistributionSetTypeManagement
|
||||
* @param contextAware
|
||||
* ContextAware
|
||||
*/
|
||||
public TargetTypeWindowBuilder(final CommonUiDependencies uiDependencies, final TargetTypeManagement targetTypeManagement,
|
||||
final DistributionSetTypeManagement dsTypeManagement) {
|
||||
public TargetTypeWindowBuilder(final CommonUiDependencies uiDependencies,
|
||||
final TargetTypeManagement targetTypeManagement, final DistributionSetTypeManagement dsTypeManagement,
|
||||
final ContextAware contextAware) {
|
||||
super(uiDependencies);
|
||||
|
||||
this.targetTypeManagement = targetTypeManagement;
|
||||
this.dsTypeManagement = dsTypeManagement;
|
||||
this.contextAware = contextAware;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -51,16 +57,16 @@ public class TargetTypeWindowBuilder extends AbstractEntityWindowBuilder<ProxyTa
|
||||
|
||||
@Override
|
||||
public Window getWindowForAdd() {
|
||||
CommonDialogWindow window = getWindowForNewEntity(new AddTargetTypeWindowController(uiDependencies, targetTypeManagement,
|
||||
new TargetTypeWindowLayout(uiDependencies, dsTypeManagement)));
|
||||
CommonDialogWindow window = getWindowForNewEntity(new AddTargetTypeWindowController(uiDependencies,
|
||||
targetTypeManagement, new TargetTypeWindowLayout(uiDependencies, dsTypeManagement), contextAware));
|
||||
window.hideMandatoryExplanation();
|
||||
return window;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Window getWindowForUpdate(final ProxyTargetType proxyType) {
|
||||
CommonDialogWindow window = getWindowForEntity(proxyType, new UpdateTargetTypeWindowController(uiDependencies, targetTypeManagement,
|
||||
new TargetTypeWindowLayout(uiDependencies, dsTypeManagement)));
|
||||
CommonDialogWindow window = getWindowForEntity(proxyType, new UpdateTargetTypeWindowController(uiDependencies,
|
||||
targetTypeManagement, new TargetTypeWindowLayout(uiDependencies, dsTypeManagement), contextAware));
|
||||
window.hideMandatoryExplanation();
|
||||
return window;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement;
|
||||
import org.eclipse.hawkbit.ContextAware;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.TargetType;
|
||||
import org.eclipse.hawkbit.ui.common.AbstractEntityWindowLayout;
|
||||
@@ -37,6 +38,7 @@ public class UpdateTargetTypeWindowController
|
||||
private final TypeToProxyTypeMapper<DistributionSetType> dsTypeToProxyTypeMapper;
|
||||
private final TargetTypeWindowLayout layout;
|
||||
private final ProxyTargetTypeValidator validator;
|
||||
private final ContextAware contextAware;
|
||||
|
||||
private String nameBeforeEdit;
|
||||
|
||||
@@ -49,13 +51,16 @@ public class UpdateTargetTypeWindowController
|
||||
* TargetTypeManagement
|
||||
* @param layout
|
||||
* TargetTypeWindowLayout
|
||||
* @param contextAware
|
||||
* ContextAware
|
||||
*/
|
||||
public UpdateTargetTypeWindowController(final CommonUiDependencies uiDependencies,
|
||||
final TargetTypeManagement targetTypeManagement,
|
||||
final TargetTypeWindowLayout layout) {
|
||||
final TargetTypeManagement targetTypeManagement, final TargetTypeWindowLayout layout,
|
||||
final ContextAware contextAware) {
|
||||
super(uiDependencies);
|
||||
|
||||
this.targetTypeManagement = targetTypeManagement;
|
||||
this.contextAware = contextAware;
|
||||
this.dsTypeToProxyTypeMapper = new TypeToProxyTypeMapper<>();
|
||||
this.layout = layout;
|
||||
this.validator = new ProxyTargetTypeValidator(uiDependencies);
|
||||
@@ -89,14 +94,16 @@ public class UpdateTargetTypeWindowController
|
||||
@Override
|
||||
protected TargetType persistEntityInRepository(final ProxyTargetType entity) {
|
||||
|
||||
final Set<Long> dsTypesIds = getDsTypesByDsTypeId(entity.getId()).stream().map(ProxyType::getId).collect(Collectors.toSet());
|
||||
final Set<Long> dsTypesIds = getDsTypesByDsTypeId(entity.getId()).stream().map(ProxyType::getId)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
final Set<Long> selectedDsIds = entity.getSelectedDsTypes().stream().map(ProxyType::getId).collect(Collectors.toSet());
|
||||
final Set<Long> selectedDsIds = entity.getSelectedDsTypes().stream().map(ProxyType::getId)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
final Set<Long> dsTypesForRemoval = getDsTypesByDsTypeId(entity.getId()).stream().map(ProxyType::getId)
|
||||
.filter(dsType -> !selectedDsIds.contains(dsType)).collect(Collectors.toSet());
|
||||
final Set<Long> dsTypesForAdd = selectedDsIds.stream()
|
||||
.filter(dsType -> !dsTypesIds.contains(dsType)).collect(Collectors.toSet());
|
||||
final Set<Long> dsTypesForAdd = selectedDsIds.stream().filter(dsType -> !dsTypesIds.contains(dsType))
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
dsTypesForRemoval.forEach(dsType -> targetTypeManagement.unassignDistributionSetType(entity.getId(), dsType));
|
||||
|
||||
@@ -104,8 +111,8 @@ public class UpdateTargetTypeWindowController
|
||||
targetTypeManagement.assignCompatibleDistributionSetTypes(entity.getId(), dsTypesForAdd);
|
||||
}
|
||||
|
||||
return targetTypeManagement.update(getEntityFactory().targetType().update(entity.getId())
|
||||
.name(entity.getName()).description(entity.getDescription()).colour(entity.getColour()));
|
||||
return targetTypeManagement.update(getEntityFactory().targetType().update(entity.getId()).name(entity.getName())
|
||||
.description(entity.getDescription()).colour(entity.getColour()));
|
||||
|
||||
}
|
||||
|
||||
@@ -123,7 +130,9 @@ public class UpdateTargetTypeWindowController
|
||||
protected boolean isEntityValid(final ProxyTargetType entity) {
|
||||
final String name = entity.getName();
|
||||
return validator.isEntityValid(entity,
|
||||
() -> hasNamedChanged(name) && targetTypeManagement.getByName(name).isPresent());
|
||||
() -> contextAware.runAsTenant( // disable acm checks
|
||||
contextAware.getCurrentTenant(),
|
||||
() -> hasNamedChanged(name) && targetTypeManagement.getByName(name).isPresent()));
|
||||
}
|
||||
|
||||
private boolean hasNamedChanged(final String trimmedName) {
|
||||
|
||||
@@ -134,6 +134,7 @@ public class AddRolloutWindowLayout extends AbstractRolloutWindowLayout {
|
||||
}
|
||||
|
||||
private Long getTotalTargets(final String filterQuery, final Long distSetTypeId) {
|
||||
// TODO AC - Check for updatable targets only
|
||||
if (StringUtils.isEmpty(filterQuery)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user