Enable push for update target, create/update/delete ds
Renamed constant MAX_TARGET_TABLE_ENTRIES Signed-off-by: Asharani <asharani.murugesh@in.bosch.com>
This commit is contained in:
@@ -1,39 +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.eventbus.event;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class TargetDeletedEvent extends AbstractDistributedEvent {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final long targetId;
|
||||
|
||||
/**
|
||||
* @param tenant
|
||||
* the tenant for this event
|
||||
* @param targetId
|
||||
* the ID of the target which has been deleted
|
||||
*/
|
||||
public TargetDeletedEvent(final String tenant, final long targetId) {
|
||||
super(-1, tenant);
|
||||
this.targetId = targetId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the targetId
|
||||
*/
|
||||
public long getTargetId() {
|
||||
return targetId;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* 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.repository.eventbus.event;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
|
||||
/**
|
||||
* Defines the {@link AbstractBaseEntityEvent} of creating a new {@link DistributionSet}.
|
||||
*
|
||||
*/
|
||||
public class DistributionCreatedEvent extends AbstractBaseEntityEvent<DistributionSet> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* @param distributionSet
|
||||
* the distributionSet which has been created
|
||||
*/
|
||||
public DistributionCreatedEvent(final DistributionSet distributionSet) {
|
||||
super(distributionSet);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* 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.repository.eventbus.event;
|
||||
|
||||
import org.eclipse.hawkbit.eventbus.event.AbstractDistributedEvent;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
|
||||
|
||||
/**
|
||||
* * Defines the {@link AbstractDistributedEvent} for deletion of {@link DistributionSet}.
|
||||
|
||||
*
|
||||
*/
|
||||
public class DistributionDeletedEvent extends AbstractDistributedEvent{
|
||||
private static final long serialVersionUID = -3308850381757843098L;
|
||||
final Long[] distributionSetIDs;
|
||||
/**
|
||||
* @param tenant
|
||||
* the tenant for this event
|
||||
* @param distributionSetId
|
||||
* the ID of the target which has been deleted
|
||||
*/
|
||||
public DistributionDeletedEvent(final String tenant, final Long...distributionIds) {
|
||||
super(-1, tenant);
|
||||
this.distributionSetIDs = distributionIds;
|
||||
}
|
||||
|
||||
public Long[] getDistributionSetIDs() {
|
||||
return distributionSetIDs;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* 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.repository.eventbus.event;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
|
||||
/**
|
||||
* Defines the {@link AbstractBaseEntityEvent} for update a {@link DistributionSet}.
|
||||
*
|
||||
*/
|
||||
public class DistributionSetUpdateEvent extends AbstractBaseEntityEvent<DistributionSet> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param tag
|
||||
* the tag which is updated
|
||||
*/
|
||||
public DistributionSetUpdateEvent(final DistributionSet ds) {
|
||||
super(ds);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* 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.repository.eventbus.event;
|
||||
|
||||
import org.eclipse.hawkbit.eventbus.event.AbstractDistributedEvent;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
|
||||
/**
|
||||
*
|
||||
* Defines the {@link AbstractBaseEntityEvent} of deleting a {@link Target}.
|
||||
*/
|
||||
public class TargetDeletedEvent extends AbstractDistributedEvent {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final long targetId;
|
||||
|
||||
/**
|
||||
* @param tenant
|
||||
* the tenant for this event
|
||||
* @param targetId
|
||||
* the ID of the target which has been deleted
|
||||
*/
|
||||
public TargetDeletedEvent(final String tenant, final long targetId) {
|
||||
super(-1, tenant);
|
||||
this.targetId = targetId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the targetId
|
||||
*/
|
||||
public long getTargetId() {
|
||||
return targetId;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* 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.repository.eventbus.event;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
|
||||
/**
|
||||
* Defines the {@link AbstractBaseEntityEvent} of updating a {@link Target}.
|
||||
*
|
||||
*/
|
||||
public class TargetUpdatedEvent extends AbstractBaseEntityEvent<Target> {
|
||||
|
||||
private static final long serialVersionUID = 5665118668865832477L;
|
||||
|
||||
public TargetUpdatedEvent(Target baseEntity) {
|
||||
super(baseEntity);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,6 +28,7 @@ import org.eclipse.hawkbit.repository.DistributionSetMetadataFields;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetTypeFields;
|
||||
import org.eclipse.hawkbit.repository.SystemManagement;
|
||||
import org.eclipse.hawkbit.repository.TagManagement;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.DistributionDeletedEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagAssigmentResultEvent;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityLockedException;
|
||||
@@ -54,6 +55,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
@@ -102,6 +104,9 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
@Autowired
|
||||
private AfterTransactionCommitExecutor afterCommit;
|
||||
|
||||
@Autowired
|
||||
private TenantAware tenantAware;
|
||||
|
||||
@Override
|
||||
public DistributionSet findDistributionSetByIdWithDetails(final Long distid) {
|
||||
return distributionSetRepository.findOne(DistributionSetSpecification.byId(distid));
|
||||
@@ -168,32 +173,39 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public void deleteDistributionSet(final Long... distributionSetIDs) {
|
||||
final List<Long> toHardDelete = new ArrayList<>();
|
||||
public void deleteDistributionSet(final Long... distributionSetIDs) {
|
||||
final List<Long> toHardDelete = new ArrayList<>();
|
||||
|
||||
final List<Long> assigned = distributionSetRepository
|
||||
.findAssignedToTargetDistributionSetsById(distributionSetIDs);
|
||||
assigned.addAll(distributionSetRepository.findAssignedToRolloutDistributionSetsById(distributionSetIDs));
|
||||
final List<Long> assigned = distributionSetRepository
|
||||
.findAssignedToTargetDistributionSetsById(distributionSetIDs);
|
||||
assigned.addAll(distributionSetRepository
|
||||
.findAssignedToRolloutDistributionSetsById(distributionSetIDs));
|
||||
|
||||
// soft delete assigned
|
||||
if (!assigned.isEmpty()) {
|
||||
distributionSetRepository.deleteDistributionSet(assigned.toArray(new Long[assigned.size()]));
|
||||
}
|
||||
// soft delete assigned
|
||||
if (!assigned.isEmpty()) {
|
||||
distributionSetRepository.deleteDistributionSet(assigned
|
||||
.toArray(new Long[assigned.size()]));
|
||||
}
|
||||
|
||||
// mark the rest as hard delete
|
||||
for (final Long setId : distributionSetIDs) {
|
||||
if (!assigned.contains(setId)) {
|
||||
toHardDelete.add(setId);
|
||||
}
|
||||
}
|
||||
// mark the rest as hard delete
|
||||
for (final Long setId : distributionSetIDs) {
|
||||
if (!assigned.contains(setId)) {
|
||||
toHardDelete.add(setId);
|
||||
}
|
||||
}
|
||||
|
||||
// hard delete the rest if exixts
|
||||
if (!toHardDelete.isEmpty()) {
|
||||
// don't give the delete statement an empty list, JPA/Oracle cannot
|
||||
// handle the empty list
|
||||
distributionSetRepository.deleteByIdIn(toHardDelete);
|
||||
}
|
||||
}
|
||||
// hard delete the rest if exixts
|
||||
if (!toHardDelete.isEmpty()) {
|
||||
// don't give the delete statement an empty list, JPA/Oracle cannot
|
||||
// handle the empty list
|
||||
distributionSetRepository.deleteByIdIn(toHardDelete);
|
||||
}
|
||||
|
||||
afterCommit.afterCommit(() -> eventBus
|
||||
.post(new DistributionDeletedEvent(tenantAware
|
||||
.getCurrentTenant(), distributionSetIDs)));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Modifying
|
||||
|
||||
@@ -29,6 +29,7 @@ import javax.persistence.criteria.Root;
|
||||
|
||||
import org.eclipse.hawkbit.repository.TargetFields;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.TargetDeletedEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.TargetTagAssigmentResultEvent;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.jpa.configuration.Constants;
|
||||
@@ -48,6 +49,7 @@ import org.eclipse.hawkbit.repository.model.TargetIdName;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -97,6 +99,10 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
@Autowired
|
||||
private AfterTransactionCommitExecutor afterCommit;
|
||||
|
||||
|
||||
@Autowired
|
||||
private TenantAware tenantAware;
|
||||
|
||||
@Override
|
||||
public Target findTargetByControllerID(final String controllerId) {
|
||||
return targetRepository.findByControllerId(controllerId);
|
||||
@@ -202,10 +208,12 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
// hibernate session.
|
||||
final List<Long> targetsForCurrentTenant = targetRepository.findAll(Lists.newArrayList(targetIDs)).stream()
|
||||
.map(Target::getId).collect(Collectors.toList());
|
||||
if (!targetsForCurrentTenant.isEmpty()) {
|
||||
targetInfoRepository.deleteByTargetIdIn(targetsForCurrentTenant);
|
||||
targetRepository.deleteByIdIn(targetsForCurrentTenant);
|
||||
}
|
||||
if (!targetsForCurrentTenant.isEmpty()) {
|
||||
targetInfoRepository.deleteByTargetIdIn(targetsForCurrentTenant);
|
||||
targetRepository.deleteByIdIn(targetsForCurrentTenant);
|
||||
targetsForCurrentTenant.forEach(targetId -> notifyTargetDeleted(
|
||||
tenantAware.getCurrentTenant(), targetId));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -652,4 +660,8 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
return resultList;
|
||||
}
|
||||
|
||||
|
||||
private void notifyTargetDeleted(final String tenant, final Long targetId) {
|
||||
afterCommit.afterCommit(() -> eventBus.post(new TargetDeletedEvent(tenant, targetId)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,154 +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.repository.jpa.eventbus;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.eclipse.hawkbit.eventbus.event.TargetDeletedEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.TargetCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.TargetInfoUpdateEvent;
|
||||
import org.eclipse.hawkbit.repository.jpa.TargetRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecutor;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetInfo;
|
||||
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.google.common.eventbus.EventBus;
|
||||
|
||||
/**
|
||||
* An aspect implementation which wraps the necessary repository services for
|
||||
* saving {@link TenantAwareBaseEntity}s to publish create or update events.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Service
|
||||
@Aspect
|
||||
public class EntityChangeEventListener {
|
||||
|
||||
@Autowired
|
||||
private EventBus eventBus;
|
||||
|
||||
@Autowired
|
||||
private TenantAware tenantAware;
|
||||
|
||||
@Autowired
|
||||
private EntityManager entityManager;
|
||||
|
||||
@Autowired
|
||||
private AfterTransactionCommitExecutor afterCommit;
|
||||
|
||||
/**
|
||||
* In case the a {@link Target} is created a corresponding
|
||||
* {@link TargetInfo} is created as well. We need the {@link TargetInfo}
|
||||
* information in the target created event. So we are listening to the
|
||||
* {@link TargetInfo} creation to indicate if an Target has been created.
|
||||
*
|
||||
* @param joinpoint
|
||||
* the aspect join point
|
||||
* @return the object of the {@link ProceedingJoinPoint#proceed()}
|
||||
* @throws Throwable
|
||||
* in case exception happens in the
|
||||
* {@link ProceedingJoinPoint#proceed()}
|
||||
*/
|
||||
@Around("execution(* org.eclipse.hawkbit.repository.jpa.TargetInfoRepository.save(..))")
|
||||
// Exception squid:S00112 - Is aspectJ proxy
|
||||
@SuppressWarnings({ "squid:S00112" })
|
||||
public Object targetCreated(final ProceedingJoinPoint joinpoint) throws Throwable {
|
||||
final boolean isNew = isTargetInfoNew(joinpoint.getArgs()[0]);
|
||||
final Object result = joinpoint.proceed();
|
||||
if (result instanceof TargetInfo) {
|
||||
if (isNew) {
|
||||
notifyTargetCreated(entityManager.merge(entityManager.merge(((TargetInfo) result).getTarget())));
|
||||
} else {
|
||||
notifyTargetInfoChanged((TargetInfo) result);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Proxy method around the delete method of the {@link TargetRepository} to
|
||||
* notify the {@link TargetDeletedEvent} in case targets has been deleted.
|
||||
*
|
||||
* @param joinpoint
|
||||
* the aspect join point
|
||||
* @return the object of the {@link ProceedingJoinPoint#proceed()}
|
||||
* @throws Throwable
|
||||
* in case exception happens in the
|
||||
* {@link ProceedingJoinPoint#proceed()}
|
||||
*/
|
||||
@Around("execution(* org.eclipse.hawkbit.repository.jpa.TargetRepository.deleteByIdIn(..))")
|
||||
// Exception squid:S00112 - Is aspectJ proxy
|
||||
@SuppressWarnings({ "squid:S00112" })
|
||||
public Object targetDeletedById(final ProceedingJoinPoint joinpoint) throws Throwable {
|
||||
final String currentTenant = tenantAware.getCurrentTenant();
|
||||
final Object result = joinpoint.proceed();
|
||||
final Collection<Long> targetIds = (Collection<Long>) joinpoint.getArgs()[0];
|
||||
targetIds.forEach(targetId -> notifyTargetDeleted(currentTenant, targetId));
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Proxy method around the delete method of the {@link TargetRepository} to
|
||||
* notify the {@link TargetDeletedEvent} in case targets has been deleted.
|
||||
*
|
||||
* @param joinpoint
|
||||
* the aspect join point
|
||||
* @return the object of the {@link ProceedingJoinPoint#proceed()}
|
||||
* @throws Throwable
|
||||
* in case exception happens in the
|
||||
* {@link ProceedingJoinPoint#proceed()}
|
||||
*/
|
||||
@Around("execution(* org.eclipse.hawkbit.repository.jpa.TargetRepository.delete(..))")
|
||||
// Exception squid:S00112 - Is aspectJ proxy
|
||||
@SuppressWarnings({ "squid:S00112", "unchecked" })
|
||||
public Object targetDeleted(final ProceedingJoinPoint joinpoint) throws Throwable {
|
||||
final String currentTenant = tenantAware.getCurrentTenant();
|
||||
final Object result = joinpoint.proceed();
|
||||
final Object param = joinpoint.getArgs()[0];
|
||||
// delete by id
|
||||
if (param instanceof Long) {
|
||||
notifyTargetDeleted(currentTenant, (Long) param);
|
||||
} else if (param instanceof Target) {
|
||||
notifyTargetDeleted(currentTenant, ((Target) param).getId());
|
||||
} else if (param instanceof Iterable) {
|
||||
((Iterable<Target>) param).forEach(target -> notifyTargetDeleted(currentTenant, target.getId()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void notifyTargetCreated(final Target t) {
|
||||
afterCommit.afterCommit(() -> eventBus.post(new TargetCreatedEvent(t)));
|
||||
|
||||
}
|
||||
|
||||
private void notifyTargetInfoChanged(final TargetInfo targetInfo) {
|
||||
afterCommit.afterCommit(() -> eventBus.post(new TargetInfoUpdateEvent(targetInfo)));
|
||||
}
|
||||
|
||||
private void notifyTargetDeleted(final String tenant, final Long targetId) {
|
||||
afterCommit.afterCommit(() -> eventBus.post(new TargetDeletedEvent(tenant, targetId)));
|
||||
}
|
||||
|
||||
private static boolean isTargetInfoNew(final Object targetInfo) {
|
||||
return ((JpaTargetInfo) targetInfo).isNew();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* 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.repository.jpa.model;
|
||||
|
||||
/**
|
||||
*
|
||||
* Interface defining the action to be performed after entity is
|
||||
* created/updated.
|
||||
*
|
||||
*/
|
||||
public interface AbstractDescriptorEventVisitor {
|
||||
void publishEventPostAction(DescriptorEventDetails eventDetails);
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
/**
|
||||
* 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.repository.jpa.model;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.AbstractPropertyChangeEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.ActionCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.ActionPropertyChangeEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.DistributionCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetUpdateEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.RolloutGroupPropertyChangeEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.RolloutPropertyChangeEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.TargetCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.TargetInfoUpdateEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.TargetUpdatedEvent;
|
||||
import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecutor;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.DescriptorEventDetails.ActionType;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.AfterTransactionCommitExecutorHolder;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.EventBusHolder;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
|
||||
import org.eclipse.persistence.descriptors.DescriptorEvent;
|
||||
import org.eclipse.persistence.internal.sessions.ObjectChangeSet;
|
||||
import org.eclipse.persistence.queries.UpdateObjectQuery;
|
||||
import org.eclipse.persistence.sessions.changesets.DirectToFieldChangeRecord;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.common.eventbus.EventBus;
|
||||
|
||||
/**
|
||||
* Implementation of @link{AbstractDescriptorEventVisitor} .Publishes the
|
||||
* appropriate event after any action on entity like create/update.
|
||||
*
|
||||
*/
|
||||
public class AbstractDescriptorEventVisitorImpl implements
|
||||
AbstractDescriptorEventVisitor {
|
||||
|
||||
private static final String COMPLETE = "complete";
|
||||
private static final Logger LOG = LoggerFactory
|
||||
.getLogger(AbstractDescriptorEventVisitorImpl.class);
|
||||
|
||||
@Override
|
||||
public void publishEventPostAction(final DescriptorEventDetails event) {
|
||||
Method method = null;
|
||||
DescriptorEvent descriptorEvent = event.getDescriptorEvent();
|
||||
ActionType actiontype = event.getActiontype();
|
||||
try {
|
||||
method = getMethod(descriptorEvent, actiontype);
|
||||
if (method != null) {
|
||||
method.invoke(this, descriptorEvent.getObject(),
|
||||
descriptorEvent);
|
||||
}
|
||||
} catch (NoSuchMethodException | SecurityException
|
||||
| IllegalAccessException | IllegalArgumentException
|
||||
| InvocationTargetException e) {
|
||||
LOG.info(
|
||||
"Exception when invoking approriate method to publis event {}",
|
||||
e);
|
||||
}
|
||||
}
|
||||
|
||||
private Method getMethod(DescriptorEvent descriptorEvent,
|
||||
ActionType actiontype) throws NoSuchMethodException {
|
||||
if (actiontype == ActionType.UPDATE) {
|
||||
return this.getClass().getMethod("publishEventAfterUpdate",
|
||||
descriptorEvent.getObject().getClass(),
|
||||
DescriptorEvent.class);
|
||||
} else if (actiontype == ActionType.CREATE) {
|
||||
return this.getClass().getMethod("publishEventAfterCreate",
|
||||
descriptorEvent.getObject().getClass(),
|
||||
DescriptorEvent.class);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void publishEventAfterCreate(JpaAction action, DescriptorEvent event) {
|
||||
if (action.getRollout() != null) {
|
||||
getAfterTransactionCommmitExecutor().afterCommit(
|
||||
() -> getEventBus().post(new ActionCreatedEvent(action)));
|
||||
}
|
||||
}
|
||||
|
||||
public void publishEventAfterCreate(JpaTarget target, DescriptorEvent event) {
|
||||
getAfterTransactionCommmitExecutor().afterCommit(
|
||||
() -> getEventBus().post(new TargetCreatedEvent(target)));
|
||||
}
|
||||
|
||||
public void publishEventAfterCreate(JpaDistributionSet ds,
|
||||
DescriptorEvent event) {
|
||||
getAfterTransactionCommmitExecutor().afterCommit(
|
||||
() -> getEventBus().post(new DistributionCreatedEvent(ds)));
|
||||
|
||||
}
|
||||
|
||||
public void publishEventAfterUpdate(JpaAction action, DescriptorEvent event) {
|
||||
getAfterTransactionCommmitExecutor().afterCommit(
|
||||
() -> getEventBus().post(
|
||||
new ActionPropertyChangeEvent(action, getChangeSet(
|
||||
Action.class, event))));
|
||||
}
|
||||
|
||||
public void publishEventAfterUpdate(JpaTarget target, DescriptorEvent event) {
|
||||
getAfterTransactionCommmitExecutor().afterCommit(
|
||||
() -> getEventBus().post(new TargetUpdatedEvent(target)));
|
||||
}
|
||||
|
||||
public void publishEventAfterUpdate(JpaTargetInfo targetInfo,
|
||||
DescriptorEvent event) {
|
||||
getAfterTransactionCommmitExecutor()
|
||||
.afterCommit(
|
||||
() -> getEventBus().post(
|
||||
new TargetInfoUpdateEvent(targetInfo)));
|
||||
}
|
||||
|
||||
public void publishEventAfterUpdate(JpaRollout entity, DescriptorEvent event) {
|
||||
getAfterTransactionCommmitExecutor().afterCommit(
|
||||
() -> getEventBus().post(
|
||||
new RolloutPropertyChangeEvent(entity, getChangeSet(
|
||||
Rollout.class, event))));
|
||||
}
|
||||
|
||||
public void publishEventAfterUpdate(JpaRolloutGroup entity,
|
||||
DescriptorEvent event) {
|
||||
getAfterTransactionCommmitExecutor().afterCommit(
|
||||
() -> getEventBus().post(
|
||||
new RolloutGroupPropertyChangeEvent(entity,
|
||||
getChangeSet(RolloutGroup.class, event))));
|
||||
|
||||
}
|
||||
|
||||
public void publishEventAfterUpdate(JpaDistributionSet entity,
|
||||
DescriptorEvent event) {
|
||||
Map<String, AbstractPropertyChangeEvent<JpaDistributionSet>.Values> changeSet = getChangeSet(
|
||||
JpaDistributionSet.class, event);
|
||||
if (changeSet.containsKey(COMPLETE)
|
||||
&& changeSet.get(COMPLETE).getOldValue().equals(false)
|
||||
&& changeSet.get(COMPLETE).getNewValue().equals(true)) {
|
||||
getAfterTransactionCommmitExecutor().afterCommit(
|
||||
() -> getEventBus().post(
|
||||
new DistributionCreatedEvent(entity)));
|
||||
}
|
||||
|
||||
getAfterTransactionCommmitExecutor().afterCommit(
|
||||
() -> getEventBus()
|
||||
.post(new DistributionSetUpdateEvent(entity)));
|
||||
|
||||
}
|
||||
|
||||
private <T extends TenantAwareBaseEntity> Map<String, AbstractPropertyChangeEvent<T>.Values> getChangeSet(
|
||||
final Class<T> clazz, final DescriptorEvent event) {
|
||||
final T rolloutGroup = clazz.cast(event.getObject());
|
||||
final ObjectChangeSet changeSet = ((UpdateObjectQuery) event.getQuery())
|
||||
.getObjectChangeSet();
|
||||
return changeSet
|
||||
.getChanges()
|
||||
.stream()
|
||||
.filter(record -> record instanceof DirectToFieldChangeRecord)
|
||||
.map(record -> (DirectToFieldChangeRecord) record)
|
||||
.collect(
|
||||
Collectors.toMap(
|
||||
record -> record.getAttribute(),
|
||||
record -> new AbstractPropertyChangeEvent<T>(
|
||||
rolloutGroup, null).new Values(record
|
||||
.getOldValue(), record.getNewValue())));
|
||||
}
|
||||
|
||||
private AfterTransactionCommitExecutor getAfterTransactionCommmitExecutor() {
|
||||
return AfterTransactionCommitExecutorHolder.getInstance()
|
||||
.getAfterCommit();
|
||||
}
|
||||
|
||||
private EventBus getEventBus() {
|
||||
return EventBusHolder.getInstance().getEventBus();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -32,7 +32,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
@MappedSuperclass
|
||||
@Access(AccessType.FIELD)
|
||||
@EntityListeners({ AuditingEntityListener.class, CacheFieldEntityListener.class, EntityPropertyChangeListener.class })
|
||||
public abstract class AbstractJpaBaseEntity implements BaseEntity {
|
||||
public abstract class AbstractJpaBaseEntity implements BaseEntity,AcceptVisitor {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@@ -178,4 +178,9 @@ public abstract class AbstractJpaBaseEntity implements BaseEntity {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void postActionOnEntity(AbstractDescriptorEventVisitor visitor, DescriptorEventDetails eventDetails){
|
||||
visitor.publishEventPostAction(eventDetails);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* 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.repository.jpa.model;
|
||||
|
||||
/**
|
||||
* Interface to accept visitor @link{AbstractDescriptorEventVisitor}.
|
||||
*
|
||||
*/
|
||||
public interface AcceptVisitor {
|
||||
public void postActionOnEntity(AbstractDescriptorEventVisitor visitor,
|
||||
DescriptorEventDetails eventDetails);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* 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.repository.jpa.model;
|
||||
|
||||
import org.eclipse.persistence.descriptors.DescriptorEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
* Holds details of action(Create/Update) and @link{DescriptorEvent}.
|
||||
*
|
||||
*/
|
||||
public class DescriptorEventDetails {
|
||||
|
||||
enum ActionType {
|
||||
CREATE, UPDATE;
|
||||
}
|
||||
|
||||
private DescriptorEvent descriptorEvent;
|
||||
|
||||
private ActionType actiontype;
|
||||
|
||||
public DescriptorEventDetails(ActionType actionType,
|
||||
DescriptorEvent descriptorEvent) {
|
||||
this.descriptorEvent = descriptorEvent;
|
||||
this.actiontype = actionType;
|
||||
}
|
||||
|
||||
public DescriptorEvent getDescriptorEvent() {
|
||||
return descriptorEvent;
|
||||
}
|
||||
|
||||
public ActionType getActiontype() {
|
||||
return actiontype;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,28 +8,9 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.model;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.AbstractPropertyChangeEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.ActionCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.ActionPropertyChangeEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.RolloutGroupPropertyChangeEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.RolloutPropertyChangeEvent;
|
||||
import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecutor;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.AfterTransactionCommitExecutorHolder;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.EventBusHolder;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.DescriptorEventDetails.ActionType;
|
||||
import org.eclipse.persistence.descriptors.DescriptorEvent;
|
||||
import org.eclipse.persistence.descriptors.DescriptorEventAdapter;
|
||||
import org.eclipse.persistence.internal.sessions.ObjectChangeSet;
|
||||
import org.eclipse.persistence.queries.UpdateObjectQuery;
|
||||
import org.eclipse.persistence.sessions.changesets.DirectToFieldChangeRecord;
|
||||
|
||||
import com.google.common.eventbus.EventBus;
|
||||
|
||||
/**
|
||||
* Listens to change in property values of an entity.
|
||||
@@ -37,50 +18,19 @@ import com.google.common.eventbus.EventBus;
|
||||
*/
|
||||
public class EntityPropertyChangeListener extends DescriptorEventAdapter {
|
||||
|
||||
@Override
|
||||
public void postInsert(final DescriptorEvent event) {
|
||||
if (event.getObject().getClass().equals(Action.class)) {
|
||||
final Action action = (Action) event.getObject();
|
||||
if (action.getRollout() != null) {
|
||||
final EventBus eventBus = getEventBus();
|
||||
final AfterTransactionCommitExecutor afterCommit = getAfterTransactionCommmitExecutor();
|
||||
afterCommit.afterCommit(() -> eventBus.post(new ActionCreatedEvent(action)));
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void postInsert(final DescriptorEvent event) {
|
||||
AbstractDescriptorEventVisitor visitor = new AbstractDescriptorEventVisitorImpl();
|
||||
((AbstractJpaBaseEntity) event.getObject()).postActionOnEntity(visitor,
|
||||
new DescriptorEventDetails(ActionType.CREATE, event));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postUpdate(final DescriptorEvent event) {
|
||||
if (event.getObject().getClass().equals(JpaAction.class)) {
|
||||
getAfterTransactionCommmitExecutor().afterCommit(() -> getEventBus().post(
|
||||
new ActionPropertyChangeEvent((Action) event.getObject(), getChangeSet(Action.class, event))));
|
||||
} else if (event.getObject().getClass().equals(JpaRollout.class)) {
|
||||
getAfterTransactionCommmitExecutor().afterCommit(() -> getEventBus().post(
|
||||
new RolloutPropertyChangeEvent((Rollout) event.getObject(), getChangeSet(Rollout.class, event))));
|
||||
} else if (event.getObject().getClass().equals(JpaRolloutGroup.class)) {
|
||||
getAfterTransactionCommmitExecutor().afterCommit(
|
||||
() -> getEventBus().post(new RolloutGroupPropertyChangeEvent((RolloutGroup) event.getObject(),
|
||||
getChangeSet(RolloutGroup.class, event))));
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void postUpdate(final DescriptorEvent event) {
|
||||
AbstractDescriptorEventVisitor visitor = new AbstractDescriptorEventVisitorImpl();
|
||||
((AbstractJpaBaseEntity) event.getObject()).postActionOnEntity(visitor,
|
||||
new DescriptorEventDetails(ActionType.UPDATE, event));
|
||||
}
|
||||
|
||||
private <T extends TenantAwareBaseEntity> Map<String, AbstractPropertyChangeEvent<T>.Values> getChangeSet(
|
||||
final Class<T> clazz, final DescriptorEvent event) {
|
||||
final T rolloutGroup = clazz.cast(event.getObject());
|
||||
final ObjectChangeSet changeSet = ((UpdateObjectQuery) event.getQuery()).getObjectChangeSet();
|
||||
return changeSet.getChanges().stream().filter(record -> record instanceof DirectToFieldChangeRecord)
|
||||
.map(record -> (DirectToFieldChangeRecord) record)
|
||||
.collect(Collectors.toMap(record -> record.getAttribute(),
|
||||
record -> new AbstractPropertyChangeEvent<T>(rolloutGroup, null).new Values(
|
||||
record.getOldValue(), record.getNewValue())));
|
||||
}
|
||||
|
||||
private AfterTransactionCommitExecutor getAfterTransactionCommmitExecutor() {
|
||||
return AfterTransactionCommitExecutorHolder.getInstance().getAfterCommit();
|
||||
}
|
||||
|
||||
private EventBus getEventBus() {
|
||||
return EventBusHolder.getInstance().getEventBus();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,25 +12,29 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.hawkbit.eventbus.event.Event;
|
||||
import org.eclipse.hawkbit.eventbus.event.TargetDeletedEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.DistributionCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.DistributionDeletedEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagCreatedBulkEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagDeletedEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagUpdateEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetUpdateEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.RolloutChangeEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.RolloutGroupChangeEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.TargetCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.TargetDeletedEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.TargetInfoUpdateEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.TargetTagCreatedBulkEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.TargetTagDeletedEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.TargetTagUpdateEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.TargetUpdatedEvent;
|
||||
|
||||
/**
|
||||
* The default hawkbit event provider.
|
||||
*/
|
||||
public class HawkbitEventProvider implements UIEventProvider {
|
||||
|
||||
private static final Set<Class<? extends Event>> SINGLE_EVENTS = new HashSet<>(6);
|
||||
private static final Set<Class<? extends Event>> BULK_EVENTS = new HashSet<>(3);
|
||||
private static final Set<Class<? extends Event>> SINGLE_EVENTS = new HashSet<>(9);
|
||||
private static final Set<Class<? extends Event>> BULK_EVENTS = new HashSet<>(5);
|
||||
|
||||
static {
|
||||
SINGLE_EVENTS.add(TargetTagCreatedBulkEvent.class);
|
||||
@@ -41,10 +45,14 @@ public class HawkbitEventProvider implements UIEventProvider {
|
||||
SINGLE_EVENTS.add(RolloutGroupChangeEvent.class);
|
||||
SINGLE_EVENTS.add(RolloutChangeEvent.class);
|
||||
SINGLE_EVENTS.add(TargetTagUpdateEvent.class);
|
||||
SINGLE_EVENTS.add(DistributionSetUpdateEvent.class);
|
||||
|
||||
BULK_EVENTS.add(TargetCreatedEvent.class);
|
||||
BULK_EVENTS.add(TargetInfoUpdateEvent.class);
|
||||
BULK_EVENTS.add(TargetDeletedEvent.class);
|
||||
BULK_EVENTS.add(DistributionDeletedEvent.class);
|
||||
BULK_EVENTS.add(DistributionCreatedEvent.class);
|
||||
BULK_EVENTS.add(TargetUpdatedEvent.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,6 +21,9 @@ import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.SoftwareManagement;
|
||||
import org.eclipse.hawkbit.repository.SpPermissionChecker;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.DistributionCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.DistributionDeletedEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetUpdateEvent;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleIdName;
|
||||
@@ -116,6 +119,33 @@ public class DistributionSetTable extends AbstractNamedVersionTable<Distribution
|
||||
}
|
||||
}
|
||||
|
||||
@EventBusListenerMethod(scope = EventScope.SESSION)
|
||||
void onEvents(final DistributionSetUpdateEvent event) {
|
||||
final DistributionSet ds = event.getEntity();
|
||||
final DistributionSetIdName lastSelectedDsIdName = manageDistUIState.getLastSelectedDistribution().isPresent() ? manageDistUIState
|
||||
.getLastSelectedDistribution().get() : null;
|
||||
final List<DistributionSetIdName> visibleItemIds = (List<DistributionSetIdName>) getVisibleItemIds();
|
||||
|
||||
// refresh the details tabs only if selected ds is updated
|
||||
if (lastSelectedDsIdName != null && lastSelectedDsIdName.getId().equals(ds.getId())) {
|
||||
// update table row+details layout
|
||||
eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.UPDATED_ENTITY, ds));
|
||||
} else if (visibleItemIds.stream().filter(e -> e.getId().equals(ds.getId())).findFirst().isPresent()) {
|
||||
// update the name/version details visible in table
|
||||
UI.getCurrent().access(() -> updateDistributionInTable(event.getEntity()));
|
||||
}
|
||||
}
|
||||
|
||||
@EventBusListenerMethod(scope = EventScope.SESSION)
|
||||
void onEvents(final List<?> events) {
|
||||
final Object firstEvent = events.get(0);
|
||||
if (DistributionCreatedEvent.class.isInstance(firstEvent)) {
|
||||
refreshDistributions();
|
||||
} else if (DistributionDeletedEvent.class.isInstance(firstEvent)) {
|
||||
onDistributionDeleteEvent((List<DistributionDeletedEvent>) events);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTableId() {
|
||||
return SPUIComponentIdProvider.DIST_TABLE_ID;
|
||||
@@ -422,11 +452,15 @@ public class DistributionSetTable extends AbstractNamedVersionTable<Distribution
|
||||
@EventBusListenerMethod(scope = EventScope.SESSION)
|
||||
void onEvent(final DistributionTableEvent event) {
|
||||
onBaseEntityEvent(event);
|
||||
if (BaseEntityEventType.UPDATED_ENTITY != event.getEventType()) {
|
||||
return;
|
||||
}
|
||||
UI.getCurrent().access(() -> updateDistributionInTable(event.getEntity()));
|
||||
}
|
||||
|
||||
@EventBusListenerMethod(scope = EventScope.SESSION)
|
||||
void onEvent(final SaveActionWindowEvent event) {
|
||||
if (event == SaveActionWindowEvent.DELETED_DISTRIBUTIONS || event == SaveActionWindowEvent.SAVED_ASSIGNMENTS) {
|
||||
if (event == SaveActionWindowEvent.SAVED_ASSIGNMENTS) {
|
||||
UI.getCurrent().access(() -> refreshFilter());
|
||||
}
|
||||
}
|
||||
@@ -467,6 +501,78 @@ public class DistributionSetTable extends AbstractNamedVersionTable<Distribution
|
||||
@Override
|
||||
protected void setDataAvailable(final boolean available) {
|
||||
manageDistUIState.setNoDataAvailableDist(!available);
|
||||
|
||||
}
|
||||
|
||||
private void refreshDistributions() {
|
||||
final LazyQueryContainer dsContainer = (LazyQueryContainer) getContainerDataSource();
|
||||
final int size = dsContainer.size();
|
||||
if (size < SPUIDefinitions.MAX_TABLE_ENTRIES) {
|
||||
refreshTablecontainer();
|
||||
}
|
||||
if (size != 0) {
|
||||
setData(SPUIDefinitions.DATA_AVAILABLE);
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshTablecontainer() {
|
||||
final LazyQueryContainer dsContainer = (LazyQueryContainer) getContainerDataSource();
|
||||
dsContainer.refresh();
|
||||
selectRow();
|
||||
}
|
||||
|
||||
private void updateDistributionInTable(final DistributionSet editedDs) {
|
||||
final Item item = getContainerDataSource().getItem(
|
||||
new DistributionSetIdName(editedDs.getId(), editedDs.getName(), editedDs.getVersion()));
|
||||
updateEntity(editedDs, item);
|
||||
}
|
||||
|
||||
private void onDistributionDeleteEvent(List<DistributionDeletedEvent> events) {
|
||||
final LazyQueryContainer dsContainer = (LazyQueryContainer) getContainerDataSource();
|
||||
final List<Object> visibleItemIds = (List<Object>) getVisibleItemIds();
|
||||
boolean shouldRefreshDs = false;
|
||||
for (final DistributionDeletedEvent deletedEvent : events) {
|
||||
Long[] distributionSetIDs = deletedEvent.getDistributionSetIDs();
|
||||
for (Long dsId : distributionSetIDs) {
|
||||
final DistributionSetIdName targetIdName = new DistributionSetIdName(dsId, null, null);
|
||||
if (visibleItemIds.contains(targetIdName)) {
|
||||
dsContainer.removeItem(targetIdName);
|
||||
} else {
|
||||
shouldRefreshDs = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldRefreshDs) {
|
||||
refreshOnDelete();
|
||||
} else {
|
||||
dsContainer.commit();
|
||||
}
|
||||
reSelectItemsAfterDeletionEvent();
|
||||
}
|
||||
|
||||
private void refreshOnDelete() {
|
||||
final LazyQueryContainer dsContainer = (LazyQueryContainer) getContainerDataSource();
|
||||
final int size = dsContainer.size();
|
||||
refreshTablecontainer();
|
||||
if (size != 0) {
|
||||
setData(SPUIDefinitions.DATA_AVAILABLE);
|
||||
}
|
||||
}
|
||||
|
||||
private void reSelectItemsAfterDeletionEvent() {
|
||||
Set<Object> values = new HashSet<>();
|
||||
if (isMultiSelect()) {
|
||||
values = new HashSet<>((Set<?>) getValue());
|
||||
} else {
|
||||
values.add(getValue());
|
||||
}
|
||||
setValue(null);
|
||||
|
||||
for (final Object value : values) {
|
||||
if (getVisibleItemIds().contains(value)) {
|
||||
select(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ import com.google.common.base.Strings;
|
||||
public class ManageDistBeanQuery extends AbstractBeanQuery<ProxyDistribution> {
|
||||
|
||||
private static final long serialVersionUID = 5176481314404662215L;
|
||||
private Sort sort = new Sort(Direction.ASC, "name", "version");
|
||||
private Sort sort = new Sort(Direction.ASC, "createdAt");
|
||||
private String searchText = null;
|
||||
private transient DistributionSetManagement distributionSetManagement;
|
||||
private transient Page<DistributionSet> firstPageDistributionSets = null;
|
||||
|
||||
@@ -155,9 +155,9 @@ public class CustomTargetBeanQuery extends AbstractBeanQuery<ProxyTarget> {
|
||||
size = getTargetManagement().countTargetByTargetFilterQuery(filterQuery);
|
||||
}
|
||||
getFilterManagementUIState().setTargetsCountAll(size);
|
||||
if (size > SPUIDefinitions.MAX_TARGET_TABLE_ENTRIES) {
|
||||
getFilterManagementUIState().setTargetsTruncated(size - SPUIDefinitions.MAX_TARGET_TABLE_ENTRIES);
|
||||
size = SPUIDefinitions.MAX_TARGET_TABLE_ENTRIES;
|
||||
if (size > SPUIDefinitions.MAX_TABLE_ENTRIES) {
|
||||
getFilterManagementUIState().setTargetsTruncated(size - SPUIDefinitions.MAX_TABLE_ENTRIES);
|
||||
size = SPUIDefinitions.MAX_TABLE_ENTRIES;
|
||||
} else {
|
||||
getFilterManagementUIState().setTargetsTruncated(null);
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ public class TargetFilterCountMessageLabel extends Label {
|
||||
// set the icon
|
||||
setIcon(FontAwesome.INFO_CIRCLE);
|
||||
setDescription(i18n.get("label.target.filter.truncated", filterManagementUIState.getTargetsTruncated(),
|
||||
SPUIDefinitions.MAX_TARGET_TABLE_ENTRIES));
|
||||
SPUIDefinitions.MAX_TABLE_ENTRIES));
|
||||
|
||||
} else {
|
||||
setIcon(null);
|
||||
@@ -102,8 +102,8 @@ public class TargetFilterCountMessageLabel extends Label {
|
||||
targetMessage.append(totalTargets);
|
||||
targetMessage.append(HawkbitCommonUtil.SP_STRING_SPACE);
|
||||
targetMessage.append(i18n.get("label.filter.shown"));
|
||||
if (totalTargets > SPUIDefinitions.MAX_TARGET_TABLE_ENTRIES) {
|
||||
targetMessage.append(SPUIDefinitions.MAX_TARGET_TABLE_ENTRIES);
|
||||
if (totalTargets > SPUIDefinitions.MAX_TABLE_ENTRIES) {
|
||||
targetMessage.append(SPUIDefinitions.MAX_TABLE_ENTRIES);
|
||||
} else {
|
||||
targetMessage.append(HawkbitCommonUtil.SP_STRING_SPACE);
|
||||
targetMessage.append(totalTargets);
|
||||
|
||||
@@ -10,8 +10,10 @@ package org.eclipse.hawkbit.ui.management.dstable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
@@ -23,10 +25,10 @@ import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.TenantMetaData;
|
||||
import org.eclipse.hawkbit.ui.common.CommonDialogWindow;
|
||||
import org.eclipse.hawkbit.ui.common.DistributionSetIdName;
|
||||
import org.eclipse.hawkbit.ui.common.DistributionSetTypeBeanQuery;
|
||||
import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType;
|
||||
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
|
||||
import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent;
|
||||
import org.eclipse.hawkbit.ui.distributions.dstable.DistributionSetTable;
|
||||
import org.eclipse.hawkbit.ui.management.event.DragEvent;
|
||||
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.I18N;
|
||||
@@ -90,6 +92,9 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
|
||||
@Autowired
|
||||
private transient EntityFactory entityFactory;
|
||||
|
||||
@Autowired
|
||||
private transient DistributionSetTable distributionSetTable;
|
||||
|
||||
private TextField distNameTextField;
|
||||
private TextField distVersionTextField;
|
||||
private Label madatoryLabel;
|
||||
@@ -243,8 +248,6 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
|
||||
distributionSetManagement.updateDistributionSet(currentDS);
|
||||
notificationMessage.displaySuccess(i18n.get("message.new.dist.save.success",
|
||||
new Object[] { currentDS.getName(), currentDS.getVersion() }));
|
||||
// update table row+details layout
|
||||
eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.UPDATED_ENTITY, currentDS));
|
||||
} catch (final EntityAlreadyExistsException entityAlreadyExistsException) {
|
||||
LOG.error("Update distribution failed {}", entityAlreadyExistsException);
|
||||
notificationMessage.displayValidationError(
|
||||
@@ -290,7 +293,9 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
|
||||
/* close the window */
|
||||
closeThisWindow();
|
||||
|
||||
eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.NEW_ENTITY, newDist));
|
||||
final Set<DistributionSetIdName> s = new HashSet<>();
|
||||
s.add(new DistributionSetIdName(newDist.getId(),newDist.getName(),newDist.getVersion()));
|
||||
distributionSetTable.setValue(s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ import com.google.common.base.Strings;
|
||||
public class DistributionBeanQuery extends AbstractBeanQuery<ProxyDistribution> {
|
||||
|
||||
private static final long serialVersionUID = 5862679853949173536L;
|
||||
private Sort sort = new Sort(Direction.ASC, "name", "version");
|
||||
private Sort sort = new Sort(Direction.ASC, "createdAt");
|
||||
private Collection<String> distributionTags;
|
||||
private String searchText;
|
||||
private String pinnedControllerId;
|
||||
|
||||
@@ -20,6 +20,9 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.SpPermissionChecker;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.DistributionCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.DistributionDeletedEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetUpdateEvent;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
@@ -105,6 +108,35 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
|
||||
notAllowedMsg = i18n.get("message.action.not.allowed");
|
||||
}
|
||||
|
||||
@EventBusListenerMethod(scope = EventScope.SESSION)
|
||||
void onEvents(final List<?> events) {
|
||||
final Object firstEvent = events.get(0);
|
||||
if (DistributionDeletedEvent.class.isInstance(firstEvent)) {
|
||||
onDistributionDeleteEvent((List<DistributionDeletedEvent>) events);
|
||||
} else if (DistributionCreatedEvent.class.isInstance(firstEvent)
|
||||
&& ((DistributionCreatedEvent) firstEvent).getEntity().isComplete()) {
|
||||
refreshDistributions();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EventBusListenerMethod(scope = EventScope.SESSION)
|
||||
void onEvents(final DistributionSetUpdateEvent event) {
|
||||
final DistributionSet ds = event.getEntity();
|
||||
final DistributionSetIdName lastSelectedDsIdName = managementUIState.getLastSelectedDsIdName();
|
||||
final List<DistributionSetIdName> visibleItemIds = (List<DistributionSetIdName>) getVisibleItemIds();
|
||||
|
||||
// refresh the details tabs only if selected ds is updated
|
||||
// refresh the details tabs only if selected ds is updated
|
||||
if (lastSelectedDsIdName != null && lastSelectedDsIdName.getId().equals(ds.getId())) {
|
||||
// update table row+details layout
|
||||
eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.UPDATED_ENTITY, ds));
|
||||
} else if (visibleItemIds.stream().filter(e -> e.getId().equals(ds.getId())).findFirst().isPresent()) {
|
||||
//update the name/version details visible in table
|
||||
UI.getCurrent().access(() -> updateDistributionInTable(event.getEntity()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* DistributionTableFilterEvent.
|
||||
*
|
||||
@@ -658,4 +690,69 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
|
||||
|
||||
}
|
||||
|
||||
private void onDistributionDeleteEvent(List<DistributionDeletedEvent> events) {
|
||||
final LazyQueryContainer dsContainer = (LazyQueryContainer) getContainerDataSource();
|
||||
final List<Object> visibleItemIds = (List<Object>) getVisibleItemIds();
|
||||
boolean shouldRefreshDs = false;
|
||||
for (final DistributionDeletedEvent deletedEvent : events) {
|
||||
Long[] distributionSetIDs = deletedEvent.getDistributionSetIDs();
|
||||
for (Long dsId : distributionSetIDs) {
|
||||
final DistributionSetIdName targetIdName = new DistributionSetIdName(dsId, null, null);
|
||||
if (visibleItemIds.contains(targetIdName)) {
|
||||
dsContainer.removeItem(targetIdName);
|
||||
} else {
|
||||
shouldRefreshDs = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldRefreshDs) {
|
||||
refreshOnDelete();
|
||||
} else {
|
||||
dsContainer.commit();
|
||||
}
|
||||
reSelectItemsAfterDeletionEvent();
|
||||
}
|
||||
|
||||
private void reSelectItemsAfterDeletionEvent() {
|
||||
Set<Object> values = new HashSet<>();
|
||||
if (isMultiSelect()) {
|
||||
values = new HashSet<>((Set<?>) getValue());
|
||||
} else {
|
||||
values.add(getValue());
|
||||
}
|
||||
setValue(null);
|
||||
|
||||
for (final Object value : values) {
|
||||
if (getVisibleItemIds().contains(value)) {
|
||||
select(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshDistributions() {
|
||||
final LazyQueryContainer dsContainer = (LazyQueryContainer) getContainerDataSource();
|
||||
final int size = dsContainer.size();
|
||||
if (size < SPUIDefinitions.MAX_TABLE_ENTRIES) {
|
||||
refreshTablecontainer();
|
||||
}
|
||||
if (size != 0) {
|
||||
setData(SPUIDefinitions.DATA_AVAILABLE);
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshOnDelete() {
|
||||
final LazyQueryContainer dsContainer = (LazyQueryContainer) getContainerDataSource();
|
||||
final int size = dsContainer.size();
|
||||
refreshTablecontainer();
|
||||
if (size != 0) {
|
||||
setData(SPUIDefinitions.DATA_AVAILABLE);
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshTablecontainer() {
|
||||
final LazyQueryContainer dsContainer = (LazyQueryContainer) getContainerDataSource();
|
||||
dsContainer.refresh();
|
||||
selectRow();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ public class CountMessageLabel extends Label {
|
||||
// set the icon
|
||||
setIcon(FontAwesome.INFO_CIRCLE);
|
||||
setDescription(i18n.get("label.target.filter.truncated", managementUIState.getTargetsTruncated(),
|
||||
SPUIDefinitions.MAX_TARGET_TABLE_ENTRIES));
|
||||
SPUIDefinitions.MAX_TABLE_ENTRIES));
|
||||
totalTargetTableEnteries += managementUIState.getTargetsTruncated();
|
||||
} else {
|
||||
setIcon(null);
|
||||
@@ -184,9 +184,9 @@ public class CountMessageLabel extends Label {
|
||||
final StringBuilder message = new StringBuilder(i18n.get("label.target.filter.count"));
|
||||
message.append(managementUIState.getTargetsCountAll());
|
||||
message.append(HawkbitCommonUtil.SP_STRING_SPACE);
|
||||
if (totalTargetTableEnteries > SPUIDefinitions.MAX_TARGET_TABLE_ENTRIES) {
|
||||
if (totalTargetTableEnteries > SPUIDefinitions.MAX_TABLE_ENTRIES) {
|
||||
message.append(i18n.get("label.filter.shown"));
|
||||
message.append(SPUIDefinitions.MAX_TARGET_TABLE_ENTRIES);
|
||||
message.append(SPUIDefinitions.MAX_TABLE_ENTRIES);
|
||||
} else {
|
||||
if (!targFilParams.hasFilter()) {
|
||||
message.append(i18n.get("label.filter.shown"));
|
||||
|
||||
@@ -387,7 +387,6 @@ public class ManangementConfirmationWindowLayout extends AbstractConfirmationWin
|
||||
managementUIState.getTargetTableFilters().getPinnedDistId()
|
||||
.ifPresent(distId -> unPinDeletedDS(deletedIds, distId));
|
||||
|
||||
eventBus.publish(this, SaveActionWindowEvent.DELETED_DISTRIBUTIONS);
|
||||
managementUIState.getDeletedDistributionList().clear();
|
||||
|
||||
}
|
||||
|
||||
@@ -190,9 +190,9 @@ public class TargetBeanQuery extends AbstractBeanQuery<ProxyTarget> {
|
||||
|
||||
final ManagementUIState tmpManagementUIState = getManagementUIState();
|
||||
tmpManagementUIState.setTargetsCountAll(totSize);
|
||||
if (size > SPUIDefinitions.MAX_TARGET_TABLE_ENTRIES) {
|
||||
tmpManagementUIState.setTargetsTruncated(size - SPUIDefinitions.MAX_TARGET_TABLE_ENTRIES);
|
||||
size = SPUIDefinitions.MAX_TARGET_TABLE_ENTRIES;
|
||||
if (size > SPUIDefinitions.MAX_TABLE_ENTRIES) {
|
||||
tmpManagementUIState.setTargetsTruncated(size - SPUIDefinitions.MAX_TABLE_ENTRIES);
|
||||
size = SPUIDefinitions.MAX_TABLE_ENTRIES;
|
||||
} else {
|
||||
tmpManagementUIState.setTargetsTruncated(null);
|
||||
}
|
||||
|
||||
@@ -17,11 +17,12 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.eventbus.event.TargetDeletedEvent;
|
||||
import org.eclipse.hawkbit.repository.SpPermissionChecker;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.TargetCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.TargetDeletedEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.TargetInfoUpdateEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.TargetUpdatedEvent;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetIdName;
|
||||
import org.eclipse.hawkbit.repository.model.TargetInfo;
|
||||
@@ -142,6 +143,8 @@ public class TargetTable extends AbstractTable<Target, TargetIdName> {
|
||||
onTargetInfoUpdateEvents((List<TargetInfoUpdateEvent>) events);
|
||||
} else if (TargetDeletedEvent.class.isInstance(firstEvent)) {
|
||||
onTargetDeletedEvent((List<TargetDeletedEvent>) events);
|
||||
} else if(TargetUpdatedEvent.class.isInstance(firstEvent)){
|
||||
onTargetUpdateEvents((List<TargetUpdatedEvent>) events);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -809,7 +812,7 @@ public class TargetTable extends AbstractTable<Target, TargetIdName> {
|
||||
private void refreshTargets() {
|
||||
final LazyQueryContainer targetContainer = (LazyQueryContainer) getContainerDataSource();
|
||||
final int size = targetContainer.size();
|
||||
if (size < SPUIDefinitions.MAX_TARGET_TABLE_ENTRIES) {
|
||||
if (size < SPUIDefinitions.MAX_TABLE_ENTRIES) {
|
||||
refreshTablecontainer();
|
||||
} else {
|
||||
// If table is not refreshed , explicitly target total count and
|
||||
@@ -829,10 +832,12 @@ public class TargetTable extends AbstractTable<Target, TargetIdName> {
|
||||
final TargetIdName targetIdName) {
|
||||
final LazyQueryContainer targetContainer = (LazyQueryContainer) getContainerDataSource();
|
||||
final Item item = targetContainer.getItem(targetIdName);
|
||||
item.getItemProperty(SPUILabelDefinitions.VAR_TARGET_STATUS).setValue(targetInfo.getUpdateStatus());
|
||||
item.getItemProperty(SPUILabelDefinitions.VAR_NAME).setValue(target.getName());
|
||||
item.getItemProperty(SPUILabelDefinitions.VAR_POLL_STATUS_TOOL_TIP)
|
||||
.setValue(HawkbitCommonUtil.getPollStatusToolTip(targetInfo.getPollStatus(), i18n));
|
||||
if (targetInfo != null) {
|
||||
item.getItemProperty(SPUILabelDefinitions.VAR_POLL_STATUS_TOOL_TIP).setValue(
|
||||
HawkbitCommonUtil.getPollStatusToolTip(targetInfo.getPollStatus(), i18n));
|
||||
item.getItemProperty(SPUILabelDefinitions.VAR_TARGET_STATUS).setValue(targetInfo.getUpdateStatus());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isLastSelectedTarget(final TargetIdName targetIdName) {
|
||||
@@ -879,6 +884,35 @@ public class TargetTable extends AbstractTable<Target, TargetIdName> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void onTargetUpdateEvents(List<TargetUpdatedEvent> events) {
|
||||
final List<Object> visibleItemIds = (List<Object>) getVisibleItemIds();
|
||||
boolean shoulTargetsUpdated = false;
|
||||
Target lastSelectedTarget = null;
|
||||
for (final TargetUpdatedEvent targetUpdatedEvent : events) {
|
||||
Target target = targetUpdatedEvent.getEntity();
|
||||
final TargetIdName targetIdName = target.getTargetIdName();
|
||||
if (Filters.or(getTargetTableFilters(target)).doFilter()) {
|
||||
shoulTargetsUpdated = true;
|
||||
} else {
|
||||
if (visibleItemIds.contains(targetIdName)) {
|
||||
updateVisibleItemOnEvent(null, target, targetIdName);
|
||||
}
|
||||
}
|
||||
if (isLastSelectedTarget(targetIdName)) {
|
||||
lastSelectedTarget = target;
|
||||
}
|
||||
}
|
||||
if (shoulTargetsUpdated) {
|
||||
refreshTargets();
|
||||
}
|
||||
if (lastSelectedTarget != null) {
|
||||
eventBus.publish(this, new TargetTableEvent(BaseEntityEventType.SELECTED_ENTITY, lastSelectedTarget));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void onTargetCreatedEvents() {
|
||||
refreshTargets();
|
||||
}
|
||||
@@ -953,8 +987,8 @@ public class TargetTable extends AbstractTable<Target, TargetIdName> {
|
||||
size = getTargetsCountWithFilter(totalTargetsCount, status, targetTags, distributionId, searchText,
|
||||
noTagClicked, pinnedDistId);
|
||||
|
||||
if (size > SPUIDefinitions.MAX_TARGET_TABLE_ENTRIES) {
|
||||
managementUIState.setTargetsTruncated(size - SPUIDefinitions.MAX_TARGET_TABLE_ENTRIES);
|
||||
if (size > SPUIDefinitions.MAX_TABLE_ENTRIES) {
|
||||
managementUIState.setTargetsTruncated(size - SPUIDefinitions.MAX_TABLE_ENTRIES);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -140,9 +140,9 @@ public class RolloutGroupTargetsBeanQuery extends AbstractBeanQuery<ProxyTarget>
|
||||
size = firstPageTargetSets.getTotalElements();
|
||||
}
|
||||
getRolloutUIState().setRolloutGroupTargetsTotalCount(size);
|
||||
if (size > SPUIDefinitions.MAX_TARGET_TABLE_ENTRIES) {
|
||||
getRolloutUIState().setRolloutGroupTargetsTruncated(size - SPUIDefinitions.MAX_TARGET_TABLE_ENTRIES);
|
||||
return SPUIDefinitions.MAX_TARGET_TABLE_ENTRIES;
|
||||
if (size > SPUIDefinitions.MAX_TABLE_ENTRIES) {
|
||||
getRolloutUIState().setRolloutGroupTargetsTruncated(size - SPUIDefinitions.MAX_TABLE_ENTRIES);
|
||||
return SPUIDefinitions.MAX_TABLE_ENTRIES;
|
||||
}
|
||||
|
||||
return (int) size;
|
||||
|
||||
@@ -94,7 +94,7 @@ public class RolloutGroupTargetsCountLabelMessage extends Label {
|
||||
// set the icon
|
||||
setIcon(FontAwesome.INFO_CIRCLE);
|
||||
setDescription(i18n.get("rollout.group.label.target.truncated",
|
||||
rolloutUIState.getRolloutGroupTargetsTruncated(), SPUIDefinitions.MAX_TARGET_TABLE_ENTRIES));
|
||||
rolloutUIState.getRolloutGroupTargetsTruncated(), SPUIDefinitions.MAX_TABLE_ENTRIES));
|
||||
totalTargetTableEnteries += rolloutUIState.getRolloutGroupTargetsTruncated();
|
||||
} else {
|
||||
setIcon(null);
|
||||
@@ -104,9 +104,9 @@ public class RolloutGroupTargetsCountLabelMessage extends Label {
|
||||
final StringBuilder message = new StringBuilder(i18n.get("label.target.filter.count"));
|
||||
message.append(rolloutUIState.getRolloutGroupTargetsTotalCount());
|
||||
message.append(HawkbitCommonUtil.SP_STRING_SPACE);
|
||||
if (totalTargetTableEnteries > SPUIDefinitions.MAX_TARGET_TABLE_ENTRIES) {
|
||||
if (totalTargetTableEnteries > SPUIDefinitions.MAX_TABLE_ENTRIES) {
|
||||
message.append(i18n.get("label.filter.shown"));
|
||||
message.append(SPUIDefinitions.MAX_TARGET_TABLE_ENTRIES);
|
||||
message.append(SPUIDefinitions.MAX_TABLE_ENTRIES);
|
||||
} else {
|
||||
message.append(i18n.get("label.filter.shown"));
|
||||
message.append(rolloutGroupTargetsListGrid.getContainerDataSource().size());
|
||||
|
||||
@@ -268,10 +268,6 @@ public final class SPUIDefinitions {
|
||||
* New Target save icon id.
|
||||
*/
|
||||
public static final String NEW_TARGET_SAVE = "target.add.save";
|
||||
/**
|
||||
* New Target discard icon id.
|
||||
*/
|
||||
// public static final String NEW_TARGET_DISCARD = "target.add.discard";
|
||||
/**
|
||||
* New Target add icon id.
|
||||
*/
|
||||
@@ -344,15 +340,6 @@ public final class SPUIDefinitions {
|
||||
* New Target tag color lable id.
|
||||
*/
|
||||
public static final String NEW_TARGET_TAG_COLOR = "target.tag.add.color";
|
||||
/**
|
||||
* New Target tag save icon id.
|
||||
*/
|
||||
// public static final String NEW_TARGET_TAG_SAVE = "target.tag.add.save";
|
||||
/**
|
||||
* New Target tag discard icon id.
|
||||
*/
|
||||
// public static final String NEW_TARGET_TAG_DISRACD =
|
||||
// "target.tag.add.discard";
|
||||
/**
|
||||
* New Target tag add icon id.
|
||||
*/
|
||||
@@ -860,7 +847,7 @@ public final class SPUIDefinitions {
|
||||
* truncates it. This protects to endless scroll to very high page numbers
|
||||
* which is very in performant.
|
||||
*/
|
||||
public static final int MAX_TARGET_TABLE_ENTRIES = 5000;
|
||||
public static final int MAX_TABLE_ENTRIES = 5000;
|
||||
|
||||
/**
|
||||
* New software module set type add icon id.
|
||||
|
||||
Reference in New Issue
Block a user