Refactored the code for displaying distributions in the deployment view.

This commit is contained in:
Gaurav
2016-08-01 15:12:03 +02:00
parent dfd449592c
commit 60cc2c333c
2 changed files with 25 additions and 30 deletions

View File

@@ -13,7 +13,6 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
@@ -34,13 +33,11 @@ import javax.persistence.OneToMany;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.UniqueConstraint; import javax.persistence.UniqueConstraint;
import org.eclipse.hawkbit.repository.eventbus.event.AbstractPropertyChangeEvent;
import org.eclipse.hawkbit.repository.eventbus.event.DistributionCreatedEvent; import org.eclipse.hawkbit.repository.eventbus.event.DistributionCreatedEvent;
import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetUpdateEvent; import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetUpdateEvent;
import org.eclipse.hawkbit.repository.exception.DistributionSetTypeUndefinedException; import org.eclipse.hawkbit.repository.exception.DistributionSetTypeUndefinedException;
import org.eclipse.hawkbit.repository.exception.UnsupportedSoftwareModuleForThisDistributionSetException; import org.eclipse.hawkbit.repository.exception.UnsupportedSoftwareModuleForThisDistributionSetException;
import org.eclipse.hawkbit.repository.jpa.model.helper.AfterTransactionCommitExecutorHolder; import org.eclipse.hawkbit.repository.jpa.model.helper.AfterTransactionCommitExecutorHolder;
import org.eclipse.hawkbit.repository.jpa.model.helper.EntityPropertyChangeHelper;
import org.eclipse.hawkbit.repository.jpa.model.helper.EventBusHolder; import org.eclipse.hawkbit.repository.jpa.model.helper.EventBusHolder;
import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSet;
@@ -299,14 +296,6 @@ public class JpaDistributionSet extends AbstractJpaNamedVersionedEntity
@Override @Override
public void fireUpdateEvent(final JpaDistributionSet jpaDistributionSet, final DescriptorEvent descriptorEvent) { public void fireUpdateEvent(final JpaDistributionSet jpaDistributionSet, final DescriptorEvent descriptorEvent) {
final Map<String, AbstractPropertyChangeEvent<JpaDistributionSet>.Values> changeSet = EntityPropertyChangeHelper
.getChangeSet(JpaDistributionSet.class, descriptorEvent);
if (changeSet.containsKey(COMPLETE) && changeSet.get(COMPLETE).getOldValue().equals(false)
&& changeSet.get(COMPLETE).getNewValue().equals(true)) {
AfterTransactionCommitExecutorHolder.getInstance().getAfterCommit().afterCommit(() -> EventBusHolder
.getInstance().getEventBus().post(new DistributionCreatedEvent(jpaDistributionSet)));
}
AfterTransactionCommitExecutorHolder.getInstance().getAfterCommit().afterCommit(() -> EventBusHolder AfterTransactionCommitExecutorHolder.getInstance().getAfterCommit().afterCommit(() -> EventBusHolder
.getInstance().getEventBus().post(new DistributionSetUpdateEvent(jpaDistributionSet))); .getInstance().getEventBus().post(new DistributionSetUpdateEvent(jpaDistributionSet)));

View File

@@ -21,7 +21,6 @@ import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.SpPermissionChecker;
import org.eclipse.hawkbit.repository.TargetManagement; 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.DistributionDeletedEvent;
import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetUpdateEvent; import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetUpdateEvent;
import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSet;
@@ -123,9 +122,6 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
final Object firstEvent = events.get(0); final Object firstEvent = events.get(0);
if (DistributionDeletedEvent.class.isInstance(firstEvent)) { if (DistributionDeletedEvent.class.isInstance(firstEvent)) {
onDistributionDeleteEvent((List<DistributionDeletedEvent>) events); onDistributionDeleteEvent((List<DistributionDeletedEvent>) events);
} else if (DistributionCreatedEvent.class.isInstance(firstEvent)
&& ((DistributionCreatedEvent) firstEvent).getEntity().isComplete()) {
refreshDistributions();
} }
} }
@@ -133,17 +129,27 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
@EventBusListenerMethod(scope = EventScope.SESSION) @EventBusListenerMethod(scope = EventScope.SESSION)
void onEvents(final DistributionSetUpdateEvent event) { void onEvents(final DistributionSetUpdateEvent event) {
final DistributionSet ds = event.getEntity(); final DistributionSet ds = event.getEntity();
final DistributionSetIdName lastSelectedDsIdName = managementUIState.getLastSelectedDsIdName();
final List<DistributionSetIdName> visibleItemIds = (List<DistributionSetIdName>) getVisibleItemIds(); final List<DistributionSetIdName> visibleItemIds = (List<DistributionSetIdName>) getVisibleItemIds();
final Boolean dsVisible = visibleItemIds.stream().filter(e -> e.getId().equals(ds.getId())).findFirst().isPresent();
if((ds.isComplete() && !dsVisible) ){
refreshDistributions();
}
else if( (!ds.isComplete() && dsVisible)){
refreshDistributions();
managementUIState.setLastSelectedDistribution(null);
}
else if(dsVisible){
UI.getCurrent().access(() -> updateDistributionInTable(event.getEntity()));
}
final DistributionSetIdName lastSelectedDsIdName = managementUIState.getLastSelectedDsIdName();
// refresh the details tabs only if selected ds is updated // 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())) { if (lastSelectedDsIdName != null && lastSelectedDsIdName.getId().equals(ds.getId())) {
// update table row+details layout // update table row+details layout
eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.UPDATED_ENTITY, ds)); 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()));
} }
} }
@@ -261,7 +267,7 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
@Override @Override
public Object generateCell(final Table source, final Object itemId, final Object columnId) { public Object generateCell(final Table source, final Object itemId, final Object columnId) {
HorizontalLayout iconLayout = new HorizontalLayout(); final HorizontalLayout iconLayout = new HorizontalLayout();
final String nameVersionStr = getNameAndVerion(itemId); final String nameVersionStr = getNameAndVerion(itemId);
final Button manageMetaDataBtn = createManageMetadataButton(nameVersionStr); final Button manageMetaDataBtn = createManageMetadataButton(nameVersionStr);
manageMetaDataBtn.addClickListener(event -> showMetadataDetails(itemId)); manageMetaDataBtn.addClickListener(event -> showMetadataDetails(itemId));
@@ -281,7 +287,7 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
return name + "." + version; return name + "." + version;
} }
private Button createManageMetadataButton(String nameVersionStr) { private Button createManageMetadataButton(final String nameVersionStr) {
final Button manageMetadataBtn = SPUIComponentProvider.getButton( final Button manageMetadataBtn = SPUIComponentProvider.getButton(
SPUIComponentIdProvider.DS_TABLE_MANAGE_METADATA_ID + "." + nameVersionStr, "", "", null, false, SPUIComponentIdProvider.DS_TABLE_MANAGE_METADATA_ID + "." + nameVersionStr, "", "", null, false,
FontAwesome.LIST_ALT, SPUIButtonStyleSmallNoBorder.class); FontAwesome.LIST_ALT, SPUIButtonStyleSmallNoBorder.class);
@@ -729,20 +735,20 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
} }
private void showMetadataDetails(Object itemId) { private void showMetadataDetails(final Object itemId) {
final DistributionSetIdName distIdName = (DistributionSetIdName) getContainerDataSource().getItem(itemId) final DistributionSetIdName distIdName = (DistributionSetIdName) getContainerDataSource().getItem(itemId)
.getItemProperty(SPUILabelDefinitions.VAR_DIST_ID_NAME).getValue(); .getItemProperty(SPUILabelDefinitions.VAR_DIST_ID_NAME).getValue();
DistributionSet ds = distributionSetManagement.findDistributionSetByIdWithDetails(distIdName.getId()); final DistributionSet ds = distributionSetManagement.findDistributionSetByIdWithDetails(distIdName.getId());
UI.getCurrent().addWindow(dsMetadataPopupLayout.getWindow(ds, null)); UI.getCurrent().addWindow(dsMetadataPopupLayout.getWindow(ds, null));
} }
private void onDistributionDeleteEvent(List<DistributionDeletedEvent> events) { private void onDistributionDeleteEvent(final List<DistributionDeletedEvent> events) {
final LazyQueryContainer dsContainer = (LazyQueryContainer) getContainerDataSource(); final LazyQueryContainer dsContainer = (LazyQueryContainer) getContainerDataSource();
final List<Object> visibleItemIds = (List<Object>) getVisibleItemIds(); final List<Object> visibleItemIds = (List<Object>) getVisibleItemIds();
boolean shouldRefreshDs = false; boolean shouldRefreshDs = false;
for (final DistributionDeletedEvent deletedEvent : events) { for (final DistributionDeletedEvent deletedEvent : events) {
Long[] distributionSetIDs = deletedEvent.getDistributionSetIDs(); final Long[] distributionSetIDs = deletedEvent.getDistributionSetIDs();
for (Long dsId : distributionSetIDs) { for (final Long dsId : distributionSetIDs) {
final DistributionSetIdName targetIdName = new DistributionSetIdName(dsId, null, null); final DistributionSetIdName targetIdName = new DistributionSetIdName(dsId, null, null);
if (visibleItemIds.contains(targetIdName)) { if (visibleItemIds.contains(targetIdName)) {
dsContainer.removeItem(targetIdName); dsContainer.removeItem(targetIdName);