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:
@@ -483,11 +483,13 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
|||||||
if (distributionSetMetadataRepository.exists(metadata.getId())) {
|
if (distributionSetMetadataRepository.exists(metadata.getId())) {
|
||||||
throwMetadataKeyAlreadyExists(metadata.getId().getKey());
|
throwMetadataKeyAlreadyExists(metadata.getId().getKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final DistributionSet latestDistributionSet = findDistributionSetById(metadata.getDistributionSet().getId());
|
||||||
// merge base distribution set so optLockRevision gets updated and audit
|
// merge base distribution set so optLockRevision gets updated and audit
|
||||||
// log written because
|
// log written because
|
||||||
// modifying metadata is modifying the base distribution set itself for
|
// modifying metadata is modifying the base distribution set itself for
|
||||||
// auditing purposes.
|
// auditing purposes.
|
||||||
entityManager.merge((JpaDistributionSet) metadata.getDistributionSet()).setLastModifiedAt(0L);
|
entityManager.merge((JpaDistributionSet) latestDistributionSet).setLastModifiedAt(0L);
|
||||||
return distributionSetMetadataRepository.save(metadata);
|
return distributionSetMetadataRepository.save(metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -502,7 +504,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
|||||||
for (final JpaDistributionSetMetadata distributionSetMetadata : metadata) {
|
for (final JpaDistributionSetMetadata distributionSetMetadata : metadata) {
|
||||||
checkAndThrowAlreadyIfDistributionSetMetadataExists(distributionSetMetadata.getId());
|
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<>(
|
return new ArrayList<>(
|
||||||
(Collection<? extends DistributionSetMetadata>) distributionSetMetadataRepository.save(metadata));
|
(Collection<? extends DistributionSetMetadata>) distributionSetMetadataRepository.save(metadata));
|
||||||
@@ -518,7 +520,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
|||||||
findOne(metadata.getDistributionSet(), metadata.getKey());
|
findOne(metadata.getDistributionSet(), metadata.getKey());
|
||||||
// touch it to update the lock revision because we are modifying the
|
// touch it to update the lock revision because we are modifying the
|
||||||
// DS indirectly
|
// 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);
|
return distributionSetMetadataRepository.save(metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -526,6 +529,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
|||||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||||
@Modifying
|
@Modifying
|
||||||
public void deleteDistributionSetMetadata(final DistributionSet distributionSet, final String key) {
|
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));
|
distributionSetMetadataRepository.delete(new DsMetadataCompositeKey(distributionSet, key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ 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;
|
||||||
@@ -122,6 +123,9 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -132,17 +136,19 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
|
|||||||
|
|
||||||
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();
|
||||||
|
|
||||||
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();
|
||||||
|
if (ds.getId().equals(managementUIState.getLastSelectedDsIdName().getId())) {
|
||||||
|
managementUIState.setLastSelectedDistribution(null);
|
||||||
|
managementUIState.setLastSelectedEntity(null);
|
||||||
|
}
|
||||||
|
|
||||||
if((ds.isComplete() && !dsVisible) ){
|
} else if (dsVisible) {
|
||||||
refreshDistributions();
|
|
||||||
}
|
|
||||||
else if( (!ds.isComplete() && dsVisible)){
|
|
||||||
refreshDistributions();
|
|
||||||
managementUIState.setLastSelectedDistribution(null);
|
|
||||||
}
|
|
||||||
else if(dsVisible){
|
|
||||||
UI.getCurrent().access(() -> updateDistributionInTable(event.getEntity()));
|
UI.getCurrent().access(() -> updateDistributionInTable(event.getEntity()));
|
||||||
}
|
}
|
||||||
final DistributionSetIdName lastSelectedDsIdName = managementUIState.getLastSelectedDsIdName();
|
final DistributionSetIdName lastSelectedDsIdName = managementUIState.getLastSelectedDsIdName();
|
||||||
@@ -271,7 +277,7 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
|
|||||||
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;
|
||||||
}
|
}
|
||||||
@@ -279,7 +285,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();
|
||||||
@@ -319,9 +324,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()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user