Included some hints from review.
Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
@@ -165,6 +165,8 @@ public class JpaControllerManagement implements ControllerManagement {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Action> findOldestActiveActionByTarget(final Target target) {
|
public Optional<Action> findOldestActiveActionByTarget(final Target target) {
|
||||||
|
// used in favorite to findFirstByTargetAndActiveOrderByIdAsc due to
|
||||||
|
// DATAJPA-841 issue.
|
||||||
return actionRepository.findFirstByTargetAndActive(new Sort(Direction.ASC, "id"), (JpaTarget) target, true);
|
return actionRepository.findFirstByTargetAndActive(new Sort(Direction.ASC, "id"), (JpaTarget) target, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
|
|||||||
|
|
||||||
for (final RolloutGroup rolloutGroup : rolloutGroups) {
|
for (final RolloutGroup rolloutGroup : rolloutGroups) {
|
||||||
final TotalTargetCountStatus totalTargetCountStatus = new TotalTargetCountStatus(
|
final TotalTargetCountStatus totalTargetCountStatus = new TotalTargetCountStatus(
|
||||||
allStatesForRollout.get(rolloutGroup.getId()), new Long(rolloutGroup.getTotalTargets()));
|
allStatesForRollout.get(rolloutGroup.getId()), Long.valueOf(rolloutGroup.getTotalTargets()));
|
||||||
rolloutGroup.setTotalTargetCountStatus(totalTargetCountStatus);
|
rolloutGroup.setTotalTargetCountStatus(totalTargetCountStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +128,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
|
|||||||
.getStatusCountByRolloutGroupId(rolloutGroupId);
|
.getStatusCountByRolloutGroupId(rolloutGroupId);
|
||||||
|
|
||||||
final TotalTargetCountStatus totalTargetCountStatus = new TotalTargetCountStatus(rolloutStatusCountItems,
|
final TotalTargetCountStatus totalTargetCountStatus = new TotalTargetCountStatus(rolloutStatusCountItems,
|
||||||
new Long(rolloutGroup.getTotalTargets()));
|
Long.valueOf(rolloutGroup.getTotalTargets()));
|
||||||
rolloutGroup.setTotalTargetCountStatus(totalTargetCountStatus);
|
rolloutGroup.setTotalTargetCountStatus(totalTargetCountStatus);
|
||||||
return rolloutGroup;
|
return rolloutGroup;
|
||||||
|
|
||||||
|
|||||||
@@ -204,7 +204,7 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
|||||||
@Override
|
@Override
|
||||||
public Long countSoftwareModulesByType(final SoftwareModuleType type) {
|
public Long countSoftwareModulesByType(final SoftwareModuleType type) {
|
||||||
|
|
||||||
final List<Specification<JpaSoftwareModule>> specList = new LinkedList<>();
|
final List<Specification<JpaSoftwareModule>> specList = new ArrayList<>(2);
|
||||||
|
|
||||||
Specification<JpaSoftwareModule> spec = SoftwareModuleSpecification.equalType((JpaSoftwareModuleType) type);
|
Specification<JpaSoftwareModule> spec = SoftwareModuleSpecification.equalType((JpaSoftwareModuleType) type);
|
||||||
specList.add(spec);
|
specList.add(spec);
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ import com.google.common.base.Splitter;
|
|||||||
// sub entities
|
// sub entities
|
||||||
@SuppressWarnings("squid:S2160")
|
@SuppressWarnings("squid:S2160")
|
||||||
public class JpaActionStatus extends AbstractJpaTenantAwareBaseEntity implements ActionStatus {
|
public class JpaActionStatus extends AbstractJpaTenantAwareBaseEntity implements ActionStatus {
|
||||||
|
private static final int MESSAGE_ENTRY_LENGTH = 512;
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@Column(name = "target_occurred_at")
|
@Column(name = "target_occurred_at")
|
||||||
@@ -138,9 +140,9 @@ public class JpaActionStatus extends AbstractJpaTenantAwareBaseEntity implements
|
|||||||
public final void addMessage(final String message) {
|
public final void addMessage(final String message) {
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
if (messages == null) {
|
if (messages == null) {
|
||||||
messages = new ArrayList<>((message.length() / 512) + 1);
|
messages = new ArrayList<>((message.length() / MESSAGE_ENTRY_LENGTH) + 1);
|
||||||
}
|
}
|
||||||
Splitter.fixedLength(512).split(message).forEach(messages::add);
|
Splitter.fixedLength(MESSAGE_ENTRY_LENGTH).split(message).forEach(messages::add);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.eclipse.hawkbit.eventbus.event.EntityEvent;
|
import org.eclipse.hawkbit.eventbus.event.EntityEvent;
|
||||||
|
import org.eclipse.hawkbit.eventbus.event.Event;
|
||||||
import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails;
|
import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails;
|
||||||
import org.eclipse.hawkbit.ui.UIEventProvider;
|
import org.eclipse.hawkbit.ui.UIEventProvider;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -98,7 +99,7 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy {
|
|||||||
*/
|
*/
|
||||||
@Subscribe
|
@Subscribe
|
||||||
@AllowConcurrentEvents
|
@AllowConcurrentEvents
|
||||||
public void dispatch(final org.eclipse.hawkbit.eventbus.event.Event event) {
|
public void dispatch(final Event event) {
|
||||||
// to dispatch too many events which are not interested on the UI
|
// to dispatch too many events which are not interested on the UI
|
||||||
if (!isEventProvided(event)) {
|
if (!isEventProvided(event)) {
|
||||||
LOG.trace("Event is not supported in the UI!!! Dropped event is {}", event);
|
LOG.trace("Event is not supported in the UI!!! Dropped event is {}", event);
|
||||||
@@ -111,7 +112,7 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isEventProvided(final org.eclipse.hawkbit.eventbus.event.Event event) {
|
private boolean isEventProvided(final Event event) {
|
||||||
return eventProvider.getSingleEvents().contains(event.getClass())
|
return eventProvider.getSingleEvents().contains(event.getClass())
|
||||||
|| eventProvider.getBulkEvents().contains(event.getClass());
|
|| eventProvider.getBulkEvents().contains(event.getClass());
|
||||||
}
|
}
|
||||||
@@ -148,8 +149,7 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy {
|
|||||||
* @return {@code true} if the event can be dispatched to the UI otherwise
|
* @return {@code true} if the event can be dispatched to the UI otherwise
|
||||||
* {@code false}
|
* {@code false}
|
||||||
*/
|
*/
|
||||||
protected static boolean eventSecurityCheck(final SecurityContext userContext,
|
protected static boolean eventSecurityCheck(final SecurityContext userContext, final Event event) {
|
||||||
final org.eclipse.hawkbit.eventbus.event.Event event) {
|
|
||||||
if (userContext == null || userContext.getAuthentication() == null) {
|
if (userContext == null || userContext.getAuthentication() == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -182,13 +182,13 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<org.eclipse.hawkbit.eventbus.event.Event> events = new ArrayList<>(size);
|
final List<Event> events = new ArrayList<>(size);
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
final org.eclipse.hawkbit.eventbus.event.Event pollEvent = queue.poll();
|
final Event pollEvent = queue.poll();
|
||||||
if (pollEvent == null) {
|
if (pollEvent == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
events.add(i, pollEvent);
|
events.add(pollEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (events.isEmpty()) {
|
if (events.isEmpty()) {
|
||||||
@@ -213,8 +213,7 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doDispatch(final List<org.eclipse.hawkbit.eventbus.event.Event> events,
|
private void doDispatch(final List<Event> events, final WrappedSession wrappedSession) {
|
||||||
final WrappedSession wrappedSession) {
|
|
||||||
final SecurityContext userContext = (SecurityContext) wrappedSession
|
final SecurityContext userContext = (SecurityContext) wrappedSession
|
||||||
.getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY);
|
.getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY);
|
||||||
final SecurityContext oldContext = SecurityContextHolder.getContext();
|
final SecurityContext oldContext = SecurityContextHolder.getContext();
|
||||||
@@ -225,10 +224,10 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy {
|
|||||||
if (vaadinSession.getState() != State.OPEN) {
|
if (vaadinSession.getState() != State.OPEN) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LOG.debug("UI EventBus aggregator of UI {} got lock on session.", uiid);
|
LOG.debug("UI EventBus aggregator of UI {} got lock on session.", vaadinUI.getUIId());
|
||||||
fowardSingleEvents(events, userContext);
|
fowardSingleEvents(events, userContext);
|
||||||
fowardBulkEvents(events, userContext);
|
fowardBulkEvents(events, userContext);
|
||||||
LOG.debug("UI EventBus aggregator of UI {} left lock on session.", uiid);
|
LOG.debug("UI EventBus aggregator of UI {} left lock on session.", vaadinUI.getUIId());
|
||||||
}).get();
|
}).get();
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
LOG.error("Wait for Vaadin session for UI {} interrupted!", uiid, e);
|
LOG.error("Wait for Vaadin session for UI {} interrupted!", uiid, e);
|
||||||
@@ -237,8 +236,7 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fowardBulkEvents(final List<org.eclipse.hawkbit.eventbus.event.Event> events,
|
private void fowardBulkEvents(final List<Event> events, final SecurityContext userContext) {
|
||||||
final SecurityContext userContext) {
|
|
||||||
final Set<Class<?>> filterBulkEvenTypes = eventProvider.getFilteredBulkEventsType(events);
|
final Set<Class<?>> filterBulkEvenTypes = eventProvider.getFilteredBulkEventsType(events);
|
||||||
|
|
||||||
for (final Class<?> bulkType : filterBulkEvenTypes) {
|
for (final Class<?> bulkType : filterBulkEvenTypes) {
|
||||||
@@ -252,8 +250,7 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fowardSingleEvents(final List<org.eclipse.hawkbit.eventbus.event.Event> events,
|
private void fowardSingleEvents(final List<Event> events, final SecurityContext userContext) {
|
||||||
final SecurityContext userContext) {
|
|
||||||
events.stream()
|
events.stream()
|
||||||
.filter(event -> DelayedEventBusPushStrategy.eventSecurityCheck(userContext, event)
|
.filter(event -> DelayedEventBusPushStrategy.eventSecurityCheck(userContext, event)
|
||||||
&& eventProvider.getSingleEvents().contains(event.getClass()))
|
&& eventProvider.getSingleEvents().contains(event.getClass()))
|
||||||
|
|||||||
Reference in New Issue
Block a user