From 0854d023fb1654f41146c555bcc9c8fb553fd529 Mon Sep 17 00:00:00 2001 From: Gaurav Date: Tue, 2 Aug 2016 18:32:44 +0200 Subject: [PATCH] Fixed the code for the create ds for deployment view and fixed the issue for delete metadata(getting optimistic lock exception) --- .../jpa/JpaDistributionSetManagement.java | 11 +++- .../management/dstable/DistributionTable.java | 57 ++++++++++--------- 2 files changed, 39 insertions(+), 29 deletions(-) diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java index 8842a3507..e8e05a9e1 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java @@ -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) 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)); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java index 3ded0ed07..56fdd9114 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java @@ -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) 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 visibleItemIds = (List) 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 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