Fixed the code for the create ds for deployment view and fixed the issue

for delete metadata(getting optimistic lock exception)
This commit is contained in:
Gaurav
2016-08-02 18:32:44 +02:00
parent 1bf91372ae
commit 0854d023fb
2 changed files with 39 additions and 29 deletions

View File

@@ -483,11 +483,13 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
if (distributionSetMetadataRepository.exists(metadata.getId())) {
throwMetadataKeyAlreadyExists(metadata.getId().getKey());
}
final DistributionSet latestDistributionSet = findDistributionSetById(metadata.getDistributionSet().getId());
// merge base distribution set so optLockRevision gets updated and audit
// log written because
// modifying metadata is modifying the base distribution set itself for
// auditing purposes.
entityManager.merge((JpaDistributionSet) metadata.getDistributionSet()).setLastModifiedAt(0L);
entityManager.merge((JpaDistributionSet) latestDistributionSet).setLastModifiedAt(0L);
return distributionSetMetadataRepository.save(metadata);
}
@@ -502,7 +504,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
for (final JpaDistributionSetMetadata distributionSetMetadata : metadata) {
checkAndThrowAlreadyIfDistributionSetMetadataExists(distributionSetMetadata.getId());
}
metadata.forEach(m -> entityManager.merge((JpaDistributionSet) m.getDistributionSet()).setLastModifiedAt(0L));
metadata.forEach(m -> entityManager.merge((JpaDistributionSet) findDistributionSetById(m.getDistributionSet().getId())).setLastModifiedAt(0L));
return new ArrayList<>(
(Collection<? extends DistributionSetMetadata>) distributionSetMetadataRepository.save(metadata));
@@ -518,7 +520,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
findOne(metadata.getDistributionSet(), metadata.getKey());
// touch it to update the lock revision because we are modifying the
// DS indirectly
entityManager.merge((JpaDistributionSet) metadata.getDistributionSet()).setLastModifiedAt(0L);
final DistributionSet latestDistributionSet = findDistributionSetById(metadata.getDistributionSet().getId());
entityManager.merge((JpaDistributionSet) latestDistributionSet).setLastModifiedAt(0L);
return distributionSetMetadataRepository.save(metadata);
}
@@ -526,6 +529,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
@Modifying
public void deleteDistributionSetMetadata(final DistributionSet distributionSet, final String key) {
final DistributionSet latestDistributionSet = findDistributionSetById(distributionSet.getId());
entityManager.merge((JpaDistributionSet) latestDistributionSet).setLastModifiedAt(0L);
distributionSetMetadataRepository.delete(new DsMetadataCompositeKey(distributionSet, key));
}

View File

@@ -21,6 +21,7 @@ import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.EntityFactory;
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;
@@ -92,16 +93,16 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
@Autowired
private ManagementViewAcceptCriteria managementViewAcceptCriteria;
@Autowired
private transient TargetManagement targetService;
@Autowired
private DsMetadataPopupLayout dsMetadataPopupLayout;
@Autowired
private transient DistributionSetManagement distributionSetManagement;
@Autowired
private EntityFactory entityFactory;
@@ -122,35 +123,40 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
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 List<DistributionSetIdName> visibleItemIds = (List<DistributionSetIdName>) getVisibleItemIds();
final Boolean dsVisible = visibleItemIds.stream().filter(e -> e.getId().equals(ds.getId())).findFirst().isPresent();
if((ds.isComplete() && !dsVisible) ){
final Boolean dsVisible = visibleItemIds.stream().filter(e -> e.getId().equals(ds.getId())).findFirst()
.isPresent();
if ((ds.isComplete() && !dsVisible)) {
refreshDistributions();
}
else if( (!ds.isComplete() && dsVisible)){
} else if ((!ds.isComplete() && dsVisible)) {
refreshDistributions();
managementUIState.setLastSelectedDistribution(null);
}
else if(dsVisible){
if (ds.getId().equals(managementUIState.getLastSelectedDsIdName().getId())) {
managementUIState.setLastSelectedDistribution(null);
managementUIState.setLastSelectedEntity(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
if (lastSelectedDsIdName != null && lastSelectedDsIdName.getId().equals(ds.getId())) {
// update table row+details layout
eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.UPDATED_ENTITY, ds));
}
}
}
/**
@@ -271,22 +277,21 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
final String nameVersionStr = getNameAndVerion(itemId);
final Button manageMetaDataBtn = createManageMetadataButton(nameVersionStr);
manageMetaDataBtn.addClickListener(event -> showMetadataDetails(itemId));
iconLayout.addComponent((Button)getPinButton(itemId));
iconLayout.addComponent((Button) getPinButton(itemId));
iconLayout.addComponent(manageMetaDataBtn);
return iconLayout;
}
});
}
private String getNameAndVerion(final Object itemId) {
final Item item = getItem(itemId);
final String name = (String) item.getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue();
final String version = (String) item.getItemProperty(SPUILabelDefinitions.VAR_VERSION).getValue();
return name + "." + version;
}
private Button createManageMetadataButton(final String nameVersionStr) {
final Button manageMetadataBtn = SPUIComponentProvider.getButton(
SPUIComponentIdProvider.DS_TABLE_MANAGE_METADATA_ID + "." + nameVersionStr, "", "", null, false,
@@ -319,9 +324,9 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
@Override
protected void publishEntityAfterValueChange(final DistributionSet selectedLastEntity) {
eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.SELECTED_ENTITY, selectedLastEntity));
if(selectedLastEntity!=null){
managementUIState.setLastSelectedDistribution(new DistributionSetIdName(selectedLastEntity.getId(),
selectedLastEntity.getName(),selectedLastEntity.getVersion()));
if (selectedLastEntity != null) {
managementUIState.setLastSelectedDistribution(new DistributionSetIdName(selectedLastEntity.getId(),
selectedLastEntity.getName(), selectedLastEntity.getVersion()));
}
}
@@ -734,7 +739,7 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
managementUIState.setNoDataAvailableDistribution(!available);
}
private void showMetadataDetails(final Object itemId) {
final DistributionSetIdName distIdName = (DistributionSetIdName) getContainerDataSource().getItem(itemId)
.getItemProperty(SPUILabelDefinitions.VAR_DIST_ID_NAME).getValue();