Feature target metadata ui (#765)

* add metadata tab and popup to target UI

Signed-off-by: Stefan Klotz <stefan.klotz@bosch-si.com>

* send event to update UI

Signed-off-by: Stefan Klotz <stefan.klotz@bosch-si.com>

* send event on target meta data delete and update

Signed-off-by: Stefan Klotz <stefan.klotz@bosch-si.com>

* display selected element name in details layout and metadata popup of UI

Signed-off-by: Stefan Klotz <stefan.klotz@bosch-si.com>

* add comments to explain manual event publishing

Signed-off-by: Stefan Klotz <stefan.klotz@bosch-si.com>

* remove option to hide metadata button in details layout

Signed-off-by: Stefan Klotz <stefan.klotz@bosch-si.com>

* fix typos and refactor

Signed-off-by: Stefan Klotz <stefan.klotz@bosch-si.com>

* fix typos

Signed-off-by: Stefan Klotz <stefan.klotz@bosch-si.com>

* fix wrong method call

Signed-off-by: Stefan Klotz <stefan.klotz@bosch-si.com>
This commit is contained in:
Stefan Klotz
2018-11-26 11:10:49 +01:00
committed by Dominic Schabel
parent 9d38f76c43
commit be348030b2
17 changed files with 313 additions and 65 deletions

View File

@@ -35,6 +35,7 @@ import org.eclipse.hawkbit.repository.builder.TargetCreate;
import org.eclipse.hawkbit.repository.builder.TargetUpdate;
import org.eclipse.hawkbit.repository.event.remote.TargetAttributesRequestedEvent;
import org.eclipse.hawkbit.repository.event.remote.TargetDeletedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.TargetUpdatedEvent;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.jpa.builder.JpaTargetCreate;
@@ -182,10 +183,16 @@ public class JpaTargetManagement implements TargetManagement {
final JpaTarget updatedTarget = touch(target);
return Collections.unmodifiableList(md.stream()
final List<TargetMetadata> createdMetadata = Collections.unmodifiableList(md.stream()
.map(meta -> targetMetadataRepository
.save(new JpaTargetMetadata(meta.getKey(), meta.getValue(), updatedTarget)))
.collect(Collectors.toList()));
// TargetUpdatedEvent is not sent within the touch() method due to the
// "lastModifiedAt" field being ignored in JpaTarget
eventPublisher.publishEvent(new TargetUpdatedEvent(updatedTarget, applicationContext.getId()));
return createdMetadata;
}
private void checkAndThrowIfTargetMetadataAlreadyExists(final TargetMetadataCompositeKey metadataId) {
@@ -219,16 +226,21 @@ public class JpaTargetManagement implements TargetManagement {
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public TargetMetadata updateMetaData(final String controllerId, final MetaData md) {
public TargetMetadata updateMetadata(final String controllerId, final MetaData md) {
// check if exists otherwise throw entity not found exception
final JpaTargetMetadata toUpdate = (JpaTargetMetadata) getMetaDataByControllerId(controllerId, md.getKey())
final JpaTargetMetadata updatedMetadata = (JpaTargetMetadata) getMetaDataByControllerId(controllerId,
md.getKey())
.orElseThrow(() -> new EntityNotFoundException(TargetMetadata.class, controllerId, md.getKey()));
toUpdate.setValue(md.getValue());
updatedMetadata.setValue(md.getValue());
// touch it to update the lock revision because we are modifying the
// target indirectly
touch(controllerId);
return targetMetadataRepository.save(toUpdate);
final JpaTarget target = touch(controllerId);
final JpaTargetMetadata matadata = targetMetadataRepository.save(updatedMetadata);
// target update event is set to ignore "lastModifiedAt" field so it is
// not send automatically within the touch() method
eventPublisher.publishEvent(new TargetUpdatedEvent(target, applicationContext.getId()));
return matadata;
}
@Override
@@ -239,8 +251,11 @@ public class JpaTargetManagement implements TargetManagement {
final JpaTargetMetadata metadata = (JpaTargetMetadata) getMetaDataByControllerId(controllerId, key)
.orElseThrow(() -> new EntityNotFoundException(TargetMetadata.class, controllerId, key));
touch(controllerId);
final JpaTarget target = touch(controllerId);
targetMetadataRepository.delete(metadata.getId());
// target update event is set to ignore "lastModifiedAt" field so it is
// not send automatically within the touch() method
eventPublisher.publishEvent(new TargetUpdatedEvent(target, applicationContext.getId()));
}
@Override

View File

@@ -152,9 +152,9 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
verifyThrownExceptionBy(() -> targetManagement.findMetaDataByControllerIdAndRsql(PAGE, NOT_EXIST_ID, "name==*"),
"Target");
verifyThrownExceptionBy(
() -> targetManagement.updateMetaData(NOT_EXIST_ID, entityFactory.generateTargetMetadata("xxx", "xxx")),
() -> targetManagement.updateMetadata(NOT_EXIST_ID, entityFactory.generateTargetMetadata("xxx", "xxx")),
"Target");
verifyThrownExceptionBy(() -> targetManagement.updateMetaData(target.getControllerId(),
verifyThrownExceptionBy(() -> targetManagement.updateMetadata(target.getControllerId(),
entityFactory.generateTargetMetadata(NOT_EXIST_ID, "xxx")), "TargetMetadata");
}
@@ -1002,7 +1002,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
Thread.sleep(100);
// update the target metadata
final JpaTargetMetadata updated = (JpaTargetMetadata) targetManagement.updateMetaData(target.getControllerId(),
final JpaTargetMetadata updated = (JpaTargetMetadata) targetManagement.updateMetadata(target.getControllerId(),
entityFactory.generateTargetMetadata(knownKey, knownUpdateValue));
// we are updating the target meta data so also modifying the base
// software