Incorporated the review comments.
Signed-off-by: Gaurav <gaurav.sahay@in.bosch.com>
This commit is contained in:
@@ -484,12 +484,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
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) latestDistributionSet).setLastModifiedAt(0L);
|
||||
touch(metadata.getDistributionSet());
|
||||
return distributionSetMetadataRepository.save(metadata);
|
||||
}
|
||||
|
||||
@@ -504,7 +499,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
for (final JpaDistributionSetMetadata distributionSetMetadata : metadata) {
|
||||
checkAndThrowAlreadyIfDistributionSetMetadataExists(distributionSetMetadata.getId());
|
||||
}
|
||||
metadata.forEach(m -> entityManager.merge((JpaDistributionSet) findDistributionSetById(m.getDistributionSet().getId())).setLastModifiedAt(0L));
|
||||
metadata.forEach(m -> touch(m.getDistributionSet()));
|
||||
|
||||
return new ArrayList<>(
|
||||
(Collection<? extends DistributionSetMetadata>) distributionSetMetadataRepository.save(metadata));
|
||||
@@ -520,8 +515,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
findOne(metadata.getDistributionSet(), metadata.getKey());
|
||||
// touch it to update the lock revision because we are modifying the
|
||||
// DS indirectly
|
||||
final DistributionSet latestDistributionSet = findDistributionSetById(metadata.getDistributionSet().getId());
|
||||
entityManager.merge((JpaDistributionSet) latestDistributionSet).setLastModifiedAt(0L);
|
||||
touch(metadata.getDistributionSet());;
|
||||
return distributionSetMetadataRepository.save(metadata);
|
||||
}
|
||||
|
||||
@@ -529,11 +523,23 @@ 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);
|
||||
touch(distributionSet);
|
||||
distributionSetMetadataRepository.delete(new DsMetadataCompositeKey(distributionSet, key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the latest distribution set based on ds ID after the metadata changes for that distribution set.
|
||||
* @param distributionSet Distribution set
|
||||
*/
|
||||
private void touch(final DistributionSet distributionSet) {
|
||||
final DistributionSet latestDistributionSet = findDistributionSetById(distributionSet.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) latestDistributionSet).setLastModifiedAt(0L);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<DistributionSetMetadata> findDistributionSetMetadataByDistributionSetId(final Long distributionSetId,
|
||||
final Pageable pageable) {
|
||||
|
||||
@@ -1,42 +1,47 @@
|
||||
/**
|
||||
* 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.model;
|
||||
|
||||
import org.eclipse.persistence.descriptors.DescriptorEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
* Holds details of action(Create/Update) and @link{DescriptorEvent}.
|
||||
*
|
||||
*/
|
||||
public class DescriptorEventDetails {
|
||||
|
||||
enum ActionType {
|
||||
CREATE, UPDATE;
|
||||
}
|
||||
|
||||
private DescriptorEvent descriptorEvent;
|
||||
|
||||
private ActionType actiontype;
|
||||
|
||||
public DescriptorEventDetails(ActionType actionType,
|
||||
DescriptorEvent descriptorEvent) {
|
||||
this.descriptorEvent = descriptorEvent;
|
||||
this.actiontype = actionType;
|
||||
}
|
||||
|
||||
public DescriptorEvent getDescriptorEvent() {
|
||||
return descriptorEvent;
|
||||
}
|
||||
|
||||
public ActionType getActiontype() {
|
||||
return actiontype;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* 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.model;
|
||||
|
||||
import org.eclipse.persistence.descriptors.DescriptorEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
* Holds details of action(Create/Update) and @link{DescriptorEvent}.
|
||||
*
|
||||
*/
|
||||
public class DescriptorEventDetails {
|
||||
|
||||
enum ActionType {
|
||||
CREATE, UPDATE;
|
||||
}
|
||||
|
||||
private final DescriptorEvent descriptorEvent;
|
||||
|
||||
private final ActionType actiontype;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param actionType Action type
|
||||
* @param descriptorEvent Descriptor Event
|
||||
*/
|
||||
public DescriptorEventDetails(final ActionType actionType,
|
||||
final DescriptorEvent descriptorEvent) {
|
||||
this.descriptorEvent = descriptorEvent;
|
||||
this.actiontype = actionType;
|
||||
}
|
||||
|
||||
public DescriptorEvent getDescriptorEvent() {
|
||||
return descriptorEvent;
|
||||
}
|
||||
|
||||
public ActionType getActiontype() {
|
||||
return actiontype;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,42 +1,53 @@
|
||||
/**
|
||||
* 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.model.helper;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.AbstractPropertyChangeEvent;
|
||||
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
|
||||
import org.eclipse.persistence.descriptors.DescriptorEvent;
|
||||
import org.eclipse.persistence.internal.sessions.ObjectChangeSet;
|
||||
import org.eclipse.persistence.queries.UpdateObjectQuery;
|
||||
import org.eclipse.persistence.sessions.changesets.DirectToFieldChangeRecord;
|
||||
|
||||
public class EntityPropertyChangeHelper<T extends TenantAwareBaseEntity> {
|
||||
|
||||
|
||||
public static <T extends TenantAwareBaseEntity> Map<String, AbstractPropertyChangeEvent<T>.Values> getChangeSet(
|
||||
final Class<T> clazz, final DescriptorEvent event) {
|
||||
final T rolloutGroup = clazz.cast(event.getObject());
|
||||
final ObjectChangeSet changeSet = ((UpdateObjectQuery) event.getQuery())
|
||||
.getObjectChangeSet();
|
||||
return changeSet
|
||||
.getChanges()
|
||||
.stream()
|
||||
.filter(record -> record instanceof DirectToFieldChangeRecord)
|
||||
.map(record -> (DirectToFieldChangeRecord) record)
|
||||
.collect(
|
||||
Collectors.toMap(
|
||||
record -> record.getAttribute(),
|
||||
record -> new AbstractPropertyChangeEvent<T>(
|
||||
rolloutGroup, null).new Values(record
|
||||
.getOldValue(), record.getNewValue())));
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* 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.model.helper;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.AbstractPropertyChangeEvent;
|
||||
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
|
||||
import org.eclipse.persistence.descriptors.DescriptorEvent;
|
||||
import org.eclipse.persistence.internal.sessions.ObjectChangeSet;
|
||||
import org.eclipse.persistence.queries.UpdateObjectQuery;
|
||||
import org.eclipse.persistence.sessions.changesets.DirectToFieldChangeRecord;
|
||||
|
||||
/**
|
||||
*Helper class to get the change set for the property changes in the Entity.
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public class EntityPropertyChangeHelper<T extends TenantAwareBaseEntity> {
|
||||
|
||||
|
||||
/**
|
||||
* To get the map of entity property change set
|
||||
* @param clazz
|
||||
* @param event
|
||||
* @return the map of the changeSet
|
||||
*/
|
||||
public static <T extends TenantAwareBaseEntity> Map<String, AbstractPropertyChangeEvent<T>.Values> getChangeSet(
|
||||
final Class<T> clazz, final DescriptorEvent event) {
|
||||
final T rolloutGroup = clazz.cast(event.getObject());
|
||||
final ObjectChangeSet changeSet = ((UpdateObjectQuery) event.getQuery())
|
||||
.getObjectChangeSet();
|
||||
return changeSet
|
||||
.getChanges()
|
||||
.stream()
|
||||
.filter(record -> record instanceof DirectToFieldChangeRecord)
|
||||
.map(record -> (DirectToFieldChangeRecord) record)
|
||||
.collect(
|
||||
Collectors.toMap(
|
||||
record -> record.getAttribute(),
|
||||
record -> new AbstractPropertyChangeEvent<T>(
|
||||
rolloutGroup, null).new Values(record
|
||||
.getOldValue(), record.getNewValue())));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user