add tests for repository entity events

Signed-off-by: Michael Hirsch <michael.hirsch@bosch-si.com>
This commit is contained in:
Michael Hirsch
2016-08-01 15:14:40 +02:00
parent 4e237f748b
commit 9c442967f8
6 changed files with 237 additions and 67 deletions

View File

@@ -11,27 +11,26 @@ package org.eclipse.hawkbit.repository.eventbus.event;
import org.eclipse.hawkbit.eventbus.event.AbstractDistributedEvent; import org.eclipse.hawkbit.eventbus.event.AbstractDistributedEvent;
import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSet;
/** /**
* * Defines the {@link AbstractDistributedEvent} for deletion of {@link DistributionSet}. * Defines the {@link AbstractDistributedEvent} for deletion of
* {@link DistributionSet}.
*
*/ */
public class DistributionDeletedEvent extends AbstractDistributedEvent{ public class DistributionDeletedEvent extends AbstractDistributedEvent {
private static final long serialVersionUID = -3308850381757843098L; private static final long serialVersionUID = -3308850381757843098L;
final Long[] distributionSetIDs; private final Long distributionId;
/** /**
* @param tenant * @param tenant
* the tenant for this event * the tenant for this event
* @param distributionSetId * @param distributionSetId
* the ID of the target which has been deleted * the ID of the distribution set which has been deleted
*/ */
public DistributionDeletedEvent(final String tenant, final Long...distributionIds) { public DistributionDeletedEvent(final String tenant, final Long distributionId) {
super(-1, tenant); super(-1, tenant);
this.distributionSetIDs = distributionIds; this.distributionId = distributionId;
} }
public Long[] getDistributionSetIDs() { public Long getDistributionSetId() {
return distributionSetIDs; return distributionId;
} }
} }

View File

@@ -28,6 +28,7 @@ import org.eclipse.hawkbit.repository.DistributionSetMetadataFields;
import org.eclipse.hawkbit.repository.DistributionSetTypeFields; import org.eclipse.hawkbit.repository.DistributionSetTypeFields;
import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.TagManagement; 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.eventbus.event.DistributionSetTagAssigmentResultEvent;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.exception.EntityLockedException; 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.DistributionSetTagAssignmentResult;
import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.tenancy.TenantAware;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageImpl;
@@ -102,6 +104,9 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Autowired @Autowired
private AfterTransactionCommitExecutor afterCommit; private AfterTransactionCommitExecutor afterCommit;
@Autowired
private TenantAware tenantAware;
@Override @Override
public DistributionSet findDistributionSetByIdWithDetails(final Long distid) { public DistributionSet findDistributionSetByIdWithDetails(final Long distid) {
return distributionSetRepository.findOne(DistributionSetSpecification.byId(distid)); return distributionSetRepository.findOne(DistributionSetSpecification.byId(distid));
@@ -193,6 +198,9 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
// handle the empty list // handle the empty list
distributionSetRepository.deleteByIdIn(toHardDelete); distributionSetRepository.deleteByIdIn(toHardDelete);
} }
Arrays.stream(distributionSetIDs)
.forEach(dsId -> eventBus.post(new DistributionDeletedEvent(tenantAware.getCurrentTenant(), dsId)));
} }
@Override @Override

View File

@@ -29,6 +29,7 @@ import javax.persistence.criteria.Root;
import org.eclipse.hawkbit.repository.TargetFields; import org.eclipse.hawkbit.repository.TargetFields;
import org.eclipse.hawkbit.repository.TargetManagement; 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.eventbus.event.TargetTagAssigmentResultEvent;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.jpa.configuration.Constants; 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.TargetTag;
import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
import org.eclipse.hawkbit.tenancy.TenantAware;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CacheEvict;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
@@ -94,6 +96,9 @@ public class JpaTargetManagement implements TargetManagement {
@Autowired @Autowired
private EventBus eventBus; private EventBus eventBus;
@Autowired
private TenantAware tenantAware;
@Autowired @Autowired
private AfterTransactionCommitExecutor afterCommit; private AfterTransactionCommitExecutor afterCommit;
@@ -206,6 +211,8 @@ public class JpaTargetManagement implements TargetManagement {
targetInfoRepository.deleteByTargetIdIn(targetsForCurrentTenant); targetInfoRepository.deleteByTargetIdIn(targetsForCurrentTenant);
targetRepository.deleteByIdIn(targetsForCurrentTenant); targetRepository.deleteByIdIn(targetsForCurrentTenant);
} }
targetsForCurrentTenant
.forEach(targetId -> eventBus.post(new TargetDeletedEvent(tenantAware.getCurrentTenant(), targetId)));
} }
@Override @Override

View File

@@ -0,0 +1,161 @@
/**
* 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 static org.fest.assertions.Assertions.assertThat;
import java.net.URI;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import org.eclipse.hawkbit.eventbus.event.Event;
import org.eclipse.hawkbit.repository.eventbus.event.DistributionCreatedEvent;
import org.eclipse.hawkbit.repository.eventbus.event.DistributionDeletedEvent;
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.jpa.AbstractJpaIntegrationTest;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
import org.fest.assertions.api.Assertions;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import ru.yandex.qatools.allure.annotations.Description;
import ru.yandex.qatools.allure.annotations.Features;
import ru.yandex.qatools.allure.annotations.Stories;
@Features("Component Tests - Repository")
@Stories("Entity Events")
public class RepositoryEntityEventTest extends AbstractJpaIntegrationTest {
@Autowired
private EventBus eventBus;
private final MyEventListener eventListener = new MyEventListener();
@Before
public void beforeTest() {
eventListener.queue.clear();
eventBus.register(eventListener);
}
@Test
@Description("Verifies that the target created event is published when a target has been created")
public void targetCreatedEventIsPublished() throws InterruptedException {
final Target createdTarget = targetManagement.createTarget(entityFactory.generateTarget("12345"));
final TargetCreatedEvent targetCreatedEvent = eventListener.waitForEvent(TargetCreatedEvent.class, 1,
TimeUnit.SECONDS);
assertThat(targetCreatedEvent).isNotNull();
assertThat(targetCreatedEvent.getEntity().getId()).isEqualTo(createdTarget.getId());
}
@Test
@Description("Verifies that the target update event is published when a target has been updated")
public void targetUpdateEventIsPublished() throws InterruptedException {
final Target createdTarget = targetManagement.createTarget(entityFactory.generateTarget("12345"));
createdTarget.setName("updateName");
targetManagement.updateTarget(createdTarget);
final TargetUpdatedEvent targetUpdatedEvent = eventListener.waitForEvent(TargetUpdatedEvent.class, 1,
TimeUnit.SECONDS);
assertThat(targetUpdatedEvent).isNotNull();
assertThat(targetUpdatedEvent.getEntity().getId()).isEqualTo(createdTarget.getId());
}
@Test
@Description("Verifies that the target info update event is published when a target info has been updated")
public void targetInfoUpdateEventIsPublished() throws InterruptedException {
final Target createdTarget = targetManagement.createTarget(entityFactory.generateTarget("12345"));
controllerManagament.updateTargetStatus(createdTarget.getTargetInfo(), TargetUpdateStatus.PENDING,
System.currentTimeMillis(), URI.create("http://127.0.0.1"));
final TargetInfoUpdateEvent targetInfoUpdatedEvent = eventListener.waitForEvent(TargetInfoUpdateEvent.class, 1,
TimeUnit.SECONDS);
assertThat(targetInfoUpdatedEvent).isNotNull();
assertThat(targetInfoUpdatedEvent.getEntity().getTarget().getId()).isEqualTo(createdTarget.getId());
}
@Test
@Description("Verifies that the target deleted event is published when a target has been deleted")
public void targetDeletedEventIsPublished() throws InterruptedException {
final Target createdTarget = targetManagement.createTarget(entityFactory.generateTarget("12345"));
targetManagement.deleteTargets(createdTarget.getId());
final TargetDeletedEvent targetDeletedEvent = eventListener.waitForEvent(TargetDeletedEvent.class, 1,
TimeUnit.SECONDS);
assertThat(targetDeletedEvent).isNotNull();
assertThat(targetDeletedEvent.getTargetId()).isEqualTo(createdTarget.getId());
}
@Test
@Description("Verifies that the distribution set created event is published when a distribution set has been created")
public void distributionSetCreatedEventIsPublished() throws InterruptedException {
final DistributionSet generateDistributionSet = entityFactory.generateDistributionSet();
generateDistributionSet.setName("dsEventTest");
generateDistributionSet.setVersion("1");
final DistributionSet createDistributionSet = distributionSetManagement
.createDistributionSet(generateDistributionSet);
final DistributionCreatedEvent dsCreatedEvent = eventListener.waitForEvent(DistributionCreatedEvent.class, 1,
TimeUnit.SECONDS);
assertThat(dsCreatedEvent).isNotNull();
assertThat(dsCreatedEvent.getEntity().getId()).isEqualTo(createDistributionSet.getId());
}
@Test
@Description("Verifies that the distribution set deleted event is published when a distribution set has been deleted")
public void distributionSetDeletedEventIsPublished() throws InterruptedException {
final DistributionSet generateDistributionSet = entityFactory.generateDistributionSet();
generateDistributionSet.setName("dsEventTest");
generateDistributionSet.setVersion("1");
final DistributionSet createDistributionSet = distributionSetManagement
.createDistributionSet(generateDistributionSet);
distributionSetManagement.deleteDistributionSet(createDistributionSet);
final DistributionDeletedEvent dsDeletedEvent = eventListener.waitForEvent(DistributionDeletedEvent.class, 1,
TimeUnit.SECONDS);
assertThat(dsDeletedEvent).isNotNull();
assertThat(dsDeletedEvent.getDistributionSetId()).isEqualTo(createDistributionSet.getId());
}
private class MyEventListener {
private final BlockingQueue<Event> queue = new LinkedBlockingQueue<>();
@Subscribe
public void onEvent(final Event event) {
queue.offer(event);
}
public <T> T waitForEvent(final Class<T> eventType, final long timeout, final TimeUnit timeUnit)
throws InterruptedException {
Event event = null;
while ((event = queue.poll(timeout, timeUnit)) != null) {
if (event.getClass().isAssignableFrom(eventType)) {
return (T) event;
}
}
Assertions.fail("Missing event " + eventType + " within timeout " + timeout + " " + timeUnit);
return null;
}
}
}

View File

@@ -130,8 +130,8 @@ public class DistributionSetTable extends AbstractNamedVersionTable<Distribution
@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 = manageDistUIState.getLastSelectedDistribution().isPresent() ? manageDistUIState final DistributionSetIdName lastSelectedDsIdName = manageDistUIState.getLastSelectedDistribution().isPresent()
.getLastSelectedDistribution().get() : null; ? manageDistUIState.getLastSelectedDistribution().get() : null;
final List<DistributionSetIdName> visibleItemIds = (List<DistributionSetIdName>) getVisibleItemIds(); 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
@@ -219,9 +219,9 @@ public class DistributionSetTable extends AbstractNamedVersionTable<Distribution
protected void publishEntityAfterValueChange(final DistributionSet distributionSet) { protected void publishEntityAfterValueChange(final DistributionSet distributionSet) {
eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.SELECTED_ENTITY, distributionSet)); eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.SELECTED_ENTITY, distributionSet));
eventBus.publish(this, DistributionsUIEvent.ORDER_BY_DISTRIBUTION); eventBus.publish(this, DistributionsUIEvent.ORDER_BY_DISTRIBUTION);
if(distributionSet!=null){ if (distributionSet != null) {
manageDistUIState.setLastSelectedEntity(new DistributionSetIdName(distributionSet.getId(), manageDistUIState.setLastSelectedEntity(new DistributionSetIdName(distributionSet.getId(),
distributionSet.getName(),distributionSet.getVersion())); distributionSet.getName(), distributionSet.getVersion()));
} }
} }
@@ -525,13 +525,13 @@ public class DistributionSetTable extends AbstractNamedVersionTable<Distribution
public Object generateCell(final Table source, final Object itemId, final Object columnId) { public Object generateCell(final Table source, final Object itemId, final Object columnId) {
final String nameVersionStr = getNameAndVerion(itemId); final String nameVersionStr = getNameAndVerion(itemId);
final Button manageMetaDataBtn = createManageMetadataButton(nameVersionStr); final Button manageMetaDataBtn = createManageMetadataButton(nameVersionStr);
manageMetaDataBtn.addClickListener(event -> showMetadataDetails(((DistributionSetIdName) itemId).getId())); manageMetaDataBtn
.addClickListener(event -> showMetadataDetails(((DistributionSetIdName) itemId).getId()));
return manageMetaDataBtn; return manageMetaDataBtn;
} }
}); });
} }
@Override @Override
protected List<TableColumn> getTableVisibleColumns() { protected List<TableColumn> getTableVisibleColumns() {
final List<TableColumn> columnList = super.getTableVisibleColumns(); final List<TableColumn> columnList = super.getTableVisibleColumns();
@@ -541,7 +541,7 @@ public class DistributionSetTable extends AbstractNamedVersionTable<Distribution
return columnList; return columnList;
} }
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);
@@ -550,9 +550,9 @@ public class DistributionSetTable extends AbstractNamedVersionTable<Distribution
return manageMetadataBtn; return manageMetadataBtn;
} }
private void showMetadataDetails(Long itemId) { private void showMetadataDetails(final Long itemId) {
DistributionSet ds = distributionSetManagement.findDistributionSetByIdWithDetails(itemId); final DistributionSet ds = distributionSetManagement.findDistributionSetByIdWithDetails(itemId);
UI.getCurrent().addWindow(dsMetadataPopupLayout.getWindow(ds,null)); UI.getCurrent().addWindow(dsMetadataPopupLayout.getWindow(ds, null));
} }
private String getNameAndVerion(final Object itemId) { private String getNameAndVerion(final Object itemId) {
@@ -580,24 +580,22 @@ public class DistributionSetTable extends AbstractNamedVersionTable<Distribution
} }
private void updateDistributionInTable(final DistributionSet editedDs) { private void updateDistributionInTable(final DistributionSet editedDs) {
final Item item = getContainerDataSource().getItem( final Item item = getContainerDataSource()
new DistributionSetIdName(editedDs.getId(), editedDs.getName(), editedDs.getVersion())); .getItem(new DistributionSetIdName(editedDs.getId(), editedDs.getName(), editedDs.getVersion()));
updateEntity(editedDs, item); updateEntity(editedDs, item);
} }
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 distributionSetId = deletedEvent.getDistributionSetId();
for (Long dsId : distributionSetIDs) { final DistributionSetIdName targetIdName = new DistributionSetIdName(distributionSetId, null, null);
final DistributionSetIdName targetIdName = new DistributionSetIdName(dsId, null, null); if (visibleItemIds.contains(targetIdName)) {
if (visibleItemIds.contains(targetIdName)) { dsContainer.removeItem(targetIdName);
dsContainer.removeItem(targetIdName); } else {
} else { shouldRefreshDs = true;
shouldRefreshDs = true;
}
} }
} }

View File

@@ -125,7 +125,7 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
onDistributionDeleteEvent((List<DistributionDeletedEvent>) events); onDistributionDeleteEvent((List<DistributionDeletedEvent>) events);
} else if (DistributionCreatedEvent.class.isInstance(firstEvent) } else if (DistributionCreatedEvent.class.isInstance(firstEvent)
&& ((DistributionCreatedEvent) firstEvent).getEntity().isComplete()) { && ((DistributionCreatedEvent) firstEvent).getEntity().isComplete()) {
refreshDistributions(); refreshDistributions();
} }
} }
@@ -137,12 +137,12 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
final List<DistributionSetIdName> visibleItemIds = (List<DistributionSetIdName>) getVisibleItemIds(); 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
// 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()) { } else if (visibleItemIds.stream().filter(e -> e.getId().equals(ds.getId())).findFirst().isPresent()) {
//update the name/version details visible in table // update the name/version details visible in table
UI.getCurrent().access(() -> updateDistributionInTable(event.getEntity())); UI.getCurrent().access(() -> updateDistributionInTable(event.getEntity()));
} }
} }
@@ -261,11 +261,11 @@ 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));
iconLayout.addComponent((Button)getPinButton(itemId)); iconLayout.addComponent((Button) getPinButton(itemId));
iconLayout.addComponent(manageMetaDataBtn); iconLayout.addComponent(manageMetaDataBtn);
return iconLayout; return iconLayout;
} }
@@ -273,7 +273,6 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
}); });
} }
private String getNameAndVerion(final Object itemId) { private String getNameAndVerion(final Object itemId) {
final Item item = getItem(itemId); final Item item = getItem(itemId);
final String name = (String) item.getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); final String name = (String) item.getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue();
@@ -281,7 +280,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);
@@ -313,9 +312,9 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
@Override @Override
protected void publishEntityAfterValueChange(final DistributionSet selectedLastEntity) { protected void publishEntityAfterValueChange(final DistributionSet selectedLastEntity) {
eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.SELECTED_ENTITY, selectedLastEntity)); eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.SELECTED_ENTITY, selectedLastEntity));
if(selectedLastEntity!=null){ if (selectedLastEntity != null) {
managementUIState.setLastSelectedDistribution(new DistributionSetIdName(selectedLastEntity.getId(), managementUIState.setLastSelectedDistribution(new DistributionSetIdName(selectedLastEntity.getId(),
selectedLastEntity.getName(),selectedLastEntity.getVersion())); selectedLastEntity.getName(), selectedLastEntity.getVersion()));
} }
} }
@@ -729,26 +728,24 @@ 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 distributionSetId = deletedEvent.getDistributionSetId();
for (Long dsId : distributionSetIDs) { final DistributionSetIdName targetIdName = new DistributionSetIdName(distributionSetId, null, null);
final DistributionSetIdName targetIdName = new DistributionSetIdName(dsId, null, null); if (visibleItemIds.contains(targetIdName)) {
if (visibleItemIds.contains(targetIdName)) { dsContainer.removeItem(targetIdName);
dsContainer.removeItem(targetIdName); } else {
} else { shouldRefreshDs = true;
shouldRefreshDs = true;
}
} }
} }