Merge branch 'master' into Multiple_VHost_Connection
Conflicts: hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java hawkbit-security-core/src/test/java/org/eclipse/hawkbit/util/IpUtilTest.java Signed-off-by: SirWayne <dennis.melzer@bosch-si.com>
This commit is contained in:
@@ -21,7 +21,7 @@ import java.util.List;
|
||||
*/
|
||||
public class ListReportSeries extends AbstractReportSeries {
|
||||
|
||||
private final List<Number> data = new ArrayList<Number>();
|
||||
private final List<Number> data = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* @param name
|
||||
|
||||
@@ -37,19 +37,9 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public interface ActionRepository extends BaseEntityRepository<Action, Long>, JpaSpecificationExecutor<Action> {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.data.repository.CrudRepository#findAll()
|
||||
*/
|
||||
@Override
|
||||
@EntityGraph(value = "Action.all", type = EntityGraphType.LOAD)
|
||||
Iterable<Action> findAll();
|
||||
|
||||
/**
|
||||
* Retrieves an Action with all lazy attributes.
|
||||
*
|
||||
*
|
||||
* @param actionId
|
||||
* the ID of the action
|
||||
* @return the found {@link Action}
|
||||
@@ -67,13 +57,12 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
* the {@link DistributionSet} on which will be filtered
|
||||
* @return the found {@link Action}s
|
||||
*/
|
||||
@EntityGraph(value = "Action.all", type = EntityGraphType.LOAD)
|
||||
Page<Action> findByDistributionSet(final Pageable pageable, final DistributionSet ds);
|
||||
|
||||
/**
|
||||
* Retrieves all {@link Action}s which are referring the given
|
||||
* {@link Target}.
|
||||
*
|
||||
*
|
||||
* @param pageable
|
||||
* page parameters
|
||||
* @param target
|
||||
@@ -84,8 +73,9 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
|
||||
/**
|
||||
* Retrieves all {@link Action}s which are active and referring the given
|
||||
* {@link Target} in a specified order.
|
||||
*
|
||||
* {@link Target} in a specified order. Loads also the lazy
|
||||
* {@link Action#getDistributionSet()} field.
|
||||
*
|
||||
* @param pageable
|
||||
* page parameters
|
||||
* @param target
|
||||
@@ -125,14 +115,13 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
* @return the found {@link UpdateAction}s
|
||||
*/
|
||||
@Query("Select a from Action a where a.target = :target and a.distributionSet = :ds order by a.id")
|
||||
@EntityGraph(value = "Action.all", type = EntityGraphType.LOAD)
|
||||
Page<Action> findByTargetAndDistributionSet(final Pageable pageable, @Param("target") final Target target,
|
||||
@Param("ds") DistributionSet ds);
|
||||
|
||||
/**
|
||||
* Retrieves all {@link Action}s of a specific target, without pagination
|
||||
* ordered by action ID.
|
||||
*
|
||||
*
|
||||
* @param target
|
||||
* to search for
|
||||
* @return a list of actions according to the searched target
|
||||
@@ -143,7 +132,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
/**
|
||||
* Retrieves all {@link Action}s of a specific target and given active flag
|
||||
* ordered by action ID.
|
||||
*
|
||||
*
|
||||
* @param pageable
|
||||
* the pagination parameter
|
||||
* @param target
|
||||
@@ -159,8 +148,9 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
|
||||
/**
|
||||
* Retrieves all {@link Action}s of a specific target and given active flag
|
||||
* ordered by action ID.
|
||||
*
|
||||
* ordered by action ID. Loads also the lazy
|
||||
* {@link Action#getDistributionSet()} field.
|
||||
*
|
||||
* @param target
|
||||
* to search for
|
||||
* @param active
|
||||
@@ -174,7 +164,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
|
||||
/**
|
||||
* Updates all {@link Action} to inactive for all targets with given ID.
|
||||
*
|
||||
*
|
||||
* @param keySet
|
||||
* the list of actions to set inactive
|
||||
* @param targetsIds
|
||||
@@ -190,7 +180,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
* Switches the status of actions from one specific status into another,
|
||||
* only if the actions are in a specific status. This should be a atomar
|
||||
* operation.
|
||||
*
|
||||
*
|
||||
* @param statusToSet
|
||||
* the new status the actions should get
|
||||
* @param targetIds
|
||||
@@ -210,7 +200,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
* Switches the status of actions from one specific status into another,
|
||||
* only if the actions are in a specific status. This should be a atomar
|
||||
* operation.
|
||||
*
|
||||
*
|
||||
* @param statusToSet
|
||||
* the new status the actions should get
|
||||
* @param rollout
|
||||
@@ -227,7 +217,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
@Param("active") boolean active, @Param("currentStatus") Action.Status currentStatus);
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Retrieves all {@link Action}s which are active and referring to the given
|
||||
* target Ids and distribution set required migration step.
|
||||
*
|
||||
@@ -243,36 +233,24 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
|
||||
/**
|
||||
* Counts all {@link Action}s referring to the given target.
|
||||
*
|
||||
*
|
||||
* @param target
|
||||
* the target to count the {@link Action}s
|
||||
* @return the count of actions referring to the given target
|
||||
*/
|
||||
Long countByTarget(Target target);
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.data.repository.CrudRepository#save(java.lang.
|
||||
* Iterable)
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = "feedbackReceivedOverTime", allEntries = true)
|
||||
<S extends Action> List<S> save(Iterable<S> entities);
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.springframework.data.repository.CrudRepository#save(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = "feedbackReceivedOverTime", allEntries = true)
|
||||
<S extends Action> S save(S entity);
|
||||
|
||||
/**
|
||||
* Counts all {@link Action}s referring to the given DistributionSet.
|
||||
*
|
||||
*
|
||||
* @param distributionSet
|
||||
* DistributionSet to count the {@link Action}s from
|
||||
* @return the count of actions referring to the given distributionSet
|
||||
@@ -281,7 +259,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
|
||||
/**
|
||||
* Counts all {@link Action}s referring to the given rollout.
|
||||
*
|
||||
*
|
||||
* @param rollout
|
||||
* the rollout to count the {@link Action}s from
|
||||
* @return the count of actions referring to the given rollout
|
||||
@@ -293,7 +271,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
* are currently not in the given status. An in-clause statement does not
|
||||
* work with the spring-data, so this is specific usecase regarding to the
|
||||
* rollout-management to find out actions which are not in specific states.
|
||||
*
|
||||
*
|
||||
* @param rollout
|
||||
* the rollout the actions are belong to
|
||||
* @param rolloutGroup
|
||||
@@ -312,7 +290,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
|
||||
/**
|
||||
* Counts all actions referring to a given rollout and rolloutgroup.
|
||||
*
|
||||
*
|
||||
* @param rollout
|
||||
* the rollout the actions belong to
|
||||
* @param rolloutGroup
|
||||
@@ -323,7 +301,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
|
||||
/**
|
||||
* Counts all actions referring to a given rollout, rolloutgroup and status.
|
||||
*
|
||||
*
|
||||
* @param rolloutId
|
||||
* the ID of rollout the actions belong to
|
||||
* @param rolloutGroupId
|
||||
@@ -338,7 +316,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
/**
|
||||
* Retrieving all actions referring to a given rollout with a specific
|
||||
* action as parent reference and a specific status.
|
||||
*
|
||||
*
|
||||
* Finding all actions of a specific rolloutgroup parent relation.
|
||||
*
|
||||
* @param rollout
|
||||
@@ -355,7 +333,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
|
||||
/**
|
||||
* Retrieves all actions for a specific rollout and in a specific status.
|
||||
*
|
||||
*
|
||||
* @param rollout
|
||||
* the rollout the actions beglong to
|
||||
* @param actionStatus
|
||||
@@ -367,7 +345,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
/**
|
||||
* Get list of objects which has details of status and count of targets in
|
||||
* each status in specified rollout.
|
||||
*
|
||||
*
|
||||
* @param rolloutId
|
||||
* id of {@link Rollout}
|
||||
* @return list of objects with status and target count
|
||||
@@ -378,7 +356,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
/**
|
||||
* Get list of objects which has details of status and count of targets in
|
||||
* each status in specified rollout.
|
||||
*
|
||||
*
|
||||
* @param rolloutId
|
||||
* id of {@link Rollout}
|
||||
* @return list of objects with status and target count
|
||||
@@ -389,7 +367,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
/**
|
||||
* Get list of objects which has details of status and count of targets in
|
||||
* each status in specified rollout group.
|
||||
*
|
||||
*
|
||||
* @param rolloutGroupId
|
||||
* id of {@link RolloutGroup}
|
||||
* @return list of objects with status and target count
|
||||
@@ -400,7 +378,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
/**
|
||||
* Get list of objects which has details of status and count of targets in
|
||||
* each status in specified rollout group.
|
||||
*
|
||||
*
|
||||
* @param rolloutGroupId
|
||||
* list of id of {@link RolloutGroup}
|
||||
* @return list of objects with status and target count
|
||||
|
||||
@@ -15,7 +15,6 @@ import java.util.Map;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.persistence.criteria.Root;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@@ -212,14 +211,9 @@ public class ControllerManagement implements EnvironmentAware {
|
||||
@Modifying
|
||||
@Transactional
|
||||
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
|
||||
public Target findOrRegisterTargetIfItDoesNotexist(@NotNull final String targetid, final URI address) {
|
||||
final Specification<Target> spec = new Specification<Target>() {
|
||||
@Override
|
||||
public Predicate toPredicate(final Root<Target> targetRoot, final CriteriaQuery<?> query,
|
||||
final CriteriaBuilder cb) {
|
||||
return cb.equal(targetRoot.get(Target_.controllerId), targetid);
|
||||
}
|
||||
};
|
||||
public Target findOrRegisterTargetIfItDoesNotexist(@NotEmpty final String targetid, final URI address) {
|
||||
final Specification<Target> spec = (targetRoot, query, cb) -> cb.equal(targetRoot.get(Target_.controllerId),
|
||||
targetid);
|
||||
|
||||
Target target = targetRepository.findOne(spec);
|
||||
|
||||
@@ -229,9 +223,9 @@ public class ControllerManagement implements EnvironmentAware {
|
||||
target.setName(targetid);
|
||||
return targetManagement.createTarget(target, TargetUpdateStatus.REGISTERED, System.currentTimeMillis(),
|
||||
address);
|
||||
} else {
|
||||
return updateLastTargetQuery(target.getTargetInfo(), address).getTarget();
|
||||
}
|
||||
|
||||
return updateLastTargetQuery(target.getTargetInfo(), address).getTarget();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -330,7 +330,7 @@ public class DeploymentManagement {
|
||||
// one we have been switched to canceling state because for targets
|
||||
// which we have changed to
|
||||
// canceling we don't want to publish the new action update event.
|
||||
final Set<Long> targetIdsCancellList = new HashSet<Long>();
|
||||
final Set<Long> targetIdsCancellList = new HashSet<>();
|
||||
targetIds.forEach(ids -> targetIdsCancellList.addAll(overrideObsoleteUpdateActions(ids)));
|
||||
|
||||
// cancel all scheduled actions which are in-active, these actions were
|
||||
@@ -378,11 +378,13 @@ public class DeploymentManagement {
|
||||
actionStatusRepository.save(actionStatus);
|
||||
});
|
||||
|
||||
// select updated targets in order to return them
|
||||
// flush to get action IDs
|
||||
entityManager.flush();
|
||||
// collect updated target and actions IDs in order to return them
|
||||
final DistributionSetAssignmentResult result = new DistributionSetAssignmentResult(
|
||||
targets.stream().map(target -> target.getControllerId()).collect(Collectors.toList()), targets.size(),
|
||||
controllerIDs.size() - targets.size(), Lists.newArrayList(targetIdsToActions.values()),
|
||||
targetManagement);
|
||||
controllerIDs.size() - targets.size(),
|
||||
targetIdsToActions.values().stream().map(Action::getId).collect(Collectors.toList()), targetManagement);
|
||||
|
||||
LOG.debug("assignDistribution({}) finished {}", set, result);
|
||||
|
||||
@@ -391,13 +393,16 @@ public class DeploymentManagement {
|
||||
// detaching as it is not necessary to persist the set itself
|
||||
entityManager.detach(set);
|
||||
|
||||
// send distribution set assignment event
|
||||
sendDistributionSetAssignmentEvent(targets, targetIdsCancellList, targetIdsToActions, softwareModules);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void sendDistributionSetAssignmentEvent(final List<Target> targets, final Set<Long> targetIdsCancellList,
|
||||
final Map<String, Action> targetIdsToActions, final List<SoftwareModule> softwareModules) {
|
||||
targets.stream().filter(t -> !!!targetIdsCancellList.contains(t.getId()))
|
||||
.forEach(t -> assignDistributionSetEvent(t, targetIdsToActions.get(t.getControllerId()).getId(),
|
||||
softwareModules));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -430,7 +435,7 @@ public class DeploymentManagement {
|
||||
*/
|
||||
private Set<Long> overrideObsoleteUpdateActions(final List<Long> targetsIds) {
|
||||
|
||||
final Set<Long> cancelledTargetIds = new HashSet<Long>();
|
||||
final Set<Long> cancelledTargetIds = new HashSet<>();
|
||||
|
||||
// Figure out if there are potential target/action combinations that
|
||||
// need to be considered
|
||||
@@ -709,8 +714,8 @@ public class DeploymentManagement {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link Action} entity for given actionId with all lazy
|
||||
* attributes.
|
||||
* Get the {@link Action} entity for given actionId with all lazy attributes
|
||||
* (i.e. distributionSet, target, target.assignedDs).
|
||||
*
|
||||
* @param actionId
|
||||
* to be id of the action
|
||||
@@ -774,8 +779,7 @@ public class DeploymentManagement {
|
||||
multiselect.where(cb.equal(actionRoot.get(Action_.target), target));
|
||||
multiselect.orderBy(cb.desc(actionRoot.get(Action_.id)));
|
||||
multiselect.groupBy(actionRoot.get(Action_.id));
|
||||
final List<ActionWithStatusCount> resultList = entityManager.createQuery(multiselect).getResultList();
|
||||
return resultList;
|
||||
return entityManager.createQuery(multiselect).getResultList();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,7 +10,6 @@ package org.eclipse.hawkbit.repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.AssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
|
||||
@@ -19,14 +18,11 @@ import org.eclipse.hawkbit.repository.model.Target;
|
||||
* information of an assignment and how much of the assignment has been done and
|
||||
* how much of the assignments had already been existed.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class DistributionSetAssignmentResult extends AssignmentResult {
|
||||
|
||||
private final List<String> assignedTargets;
|
||||
private final List<Action> actions;
|
||||
private final List<Long> actions;
|
||||
|
||||
private final TargetManagement targetManagement;
|
||||
|
||||
@@ -48,7 +44,7 @@ public class DistributionSetAssignmentResult extends AssignmentResult {
|
||||
*
|
||||
*/
|
||||
public DistributionSetAssignmentResult(final List<String> assignedTargets, final int assigned,
|
||||
final int alreadyAssigned, final List<Action> actions, final TargetManagement targetManagement) {
|
||||
final int alreadyAssigned, final List<Long> actions, final TargetManagement targetManagement) {
|
||||
super(assigned, alreadyAssigned);
|
||||
this.assignedTargets = assignedTargets;
|
||||
this.actions = actions;
|
||||
@@ -63,9 +59,9 @@ public class DistributionSetAssignmentResult extends AssignmentResult {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the actionId
|
||||
* @return the actionIds
|
||||
*/
|
||||
public List<Action> getActions() {
|
||||
public List<Long> getActions() {
|
||||
return actions;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ public class NoCountPagingRepository {
|
||||
*/
|
||||
public <T, I extends Serializable> Slice<T> findAll(final Specification<T> spec, final Pageable pageable,
|
||||
final Class<T> domainClass) {
|
||||
final SimpleJpaNoCountRepository<T, I> noCountDao = new SimpleJpaNoCountRepository<T, I>(domainClass, em);
|
||||
final SimpleJpaNoCountRepository<T, I> noCountDao = new SimpleJpaNoCountRepository<>(domainClass, em);
|
||||
return noCountDao.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class NoCountPagingRepository {
|
||||
* org.springframework.data.domain.Pageable)
|
||||
*/
|
||||
public <T, I extends Serializable> Slice<T> findAll(final Pageable pageable, final Class<T> domainClass) {
|
||||
final SimpleJpaNoCountRepository<T, I> noCountDao = new SimpleJpaNoCountRepository<T, I>(domainClass, em);
|
||||
final SimpleJpaNoCountRepository<T, I> noCountDao = new SimpleJpaNoCountRepository<>(domainClass, em);
|
||||
return noCountDao.findAll(pageable);
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ public class NoCountPagingRepository {
|
||||
|
||||
final List<T> content = query.getResultList();
|
||||
|
||||
return new PageImpl<T>(content, pageable, content.size());
|
||||
return new PageImpl<>(content, pageable, content.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,8 +245,9 @@ public class RolloutGroupManagement {
|
||||
JoinType.LEFT);
|
||||
|
||||
final Root<RolloutTargetGroup> countQueryFrom = countQuery.distinct(true).from(RolloutTargetGroup.class);
|
||||
countQuery
|
||||
.select(cb.count(countQueryFrom.join(RolloutTargetGroup_.target).join(Target_.actions, JoinType.LEFT)))
|
||||
countQueryFrom.join(RolloutTargetGroup_.target);
|
||||
countQueryFrom.join(RolloutTargetGroup_.actions, JoinType.LEFT);
|
||||
countQuery.select(cb.count(countQueryFrom))
|
||||
.where(cb.equal(countQueryFrom.get(RolloutTargetGroup_.rolloutGroup), rolloutGroup));
|
||||
final Long totalCount = entityManager.createQuery(countQuery).getSingleResult();
|
||||
|
||||
|
||||
@@ -552,7 +552,7 @@ public class RolloutManagement {
|
||||
if (updated == 0) {
|
||||
// nothing to check, maybe another instance already checked in
|
||||
// between
|
||||
LOGGER.info("No rolloutcheck necessary for current scheduled check {}, next check at {}", lastCheck,
|
||||
LOGGER.debug("No rolloutcheck necessary for current scheduled check {}, next check at {}", lastCheck,
|
||||
lastCheck + delayBetweenChecks);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ public class TagManagement {
|
||||
public void deleteTargetTag(@NotEmpty final String targetTagName) {
|
||||
final TargetTag tag = targetTagRepository.findByNameEquals(targetTagName);
|
||||
|
||||
final List<Target> changed = new LinkedList<Target>();
|
||||
final List<Target> changed = new LinkedList<>();
|
||||
for (final Target target : targetRepository.findByTag(tag)) {
|
||||
target.getTags().remove(tag);
|
||||
changed.add(target);
|
||||
@@ -311,7 +311,7 @@ public class TagManagement {
|
||||
public void deleteDistributionSetTag(@NotEmpty final String tagName) {
|
||||
final DistributionSetTag tag = distributionSetTagRepository.findByNameEquals(tagName);
|
||||
|
||||
final List<DistributionSet> changed = new LinkedList<DistributionSet>();
|
||||
final List<DistributionSet> changed = new LinkedList<>();
|
||||
for (final DistributionSet set : distributionSetRepository.findByTag(tag)) {
|
||||
set.getTags().remove(tag);
|
||||
changed.add(set);
|
||||
|
||||
@@ -24,6 +24,7 @@ import javax.persistence.ManyToOne;
|
||||
import javax.persistence.NamedAttributeNode;
|
||||
import javax.persistence.NamedEntityGraph;
|
||||
import javax.persistence.NamedEntityGraphs;
|
||||
import javax.persistence.NamedSubgraph;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Transient;
|
||||
@@ -34,28 +35,22 @@ import org.eclipse.persistence.annotations.CascadeOnDelete;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Applicable transition changes of the software {@link SoftwareModule} state of
|
||||
* a {@link Target}, e.g. install, uninstall, update, start, stop, and
|
||||
* preparations for the transition change, i.e. download.
|
||||
* Applicable transition changes of the {@link SoftwareModule}s state of a
|
||||
* {@link Target}, e.g. install, uninstall, update and preparations for the
|
||||
* transition change, i.e. download.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* Actions are managed by the SP server (SPS) and applied to the edge controller
|
||||
* by the SP controller (SPC). Actions may also be value added commands that are
|
||||
* nor directly related to SP, e.g. factory reset.
|
||||
* Actions are managed by the SP server and applied to the targets by the
|
||||
* client.
|
||||
* <p>
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Table(name = "sp_action", indexes = { @Index(name = "sp_idx_action_01", columnList = "tenant,distribution_set"),
|
||||
@Index(name = "sp_idx_action_02", columnList = "tenant,target,active"),
|
||||
@Index(name = "sp_idx_action_prim", columnList = "tenant,id") })
|
||||
@NamedEntityGraphs({ @NamedEntityGraph(name = "Action.ds", attributeNodes = { @NamedAttributeNode("distributionSet") }),
|
||||
@NamedEntityGraph(name = "Action.all", attributeNodes = { @NamedAttributeNode("distributionSet"),
|
||||
@NamedAttributeNode("target") }) })
|
||||
@NamedAttributeNode(value = "target", subgraph = "target.ds") }, subgraphs = @NamedSubgraph(name = "target.ds", attributeNodes = @NamedAttributeNode("assignedDistributionSet") ) ) })
|
||||
@Entity
|
||||
public class Action extends BaseEntity implements Comparable<Action> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -63,7 +63,7 @@ public class ActionStatus extends BaseEntity {
|
||||
@CollectionTable(name = "sp_action_status_messages", joinColumns = @JoinColumn(name = "action_status_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_stat_msg_act_stat") ) , indexes = {
|
||||
@Index(name = "sp_idx_action_status_msgs_01", columnList = "action_status_id") })
|
||||
@Column(name = "detail_message", length = 512)
|
||||
private final List<String> messages = new ArrayList<String>();
|
||||
private final List<String> messages = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Creates a new {@link ActionStatus} object.
|
||||
|
||||
@@ -32,6 +32,8 @@ import javax.persistence.PrimaryKeyJoinColumn;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Transient;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
import org.eclipse.hawkbit.repository.model.helper.SecurityChecker;
|
||||
@@ -74,6 +76,8 @@ public class Target extends NamedEntity implements Persistable<Long> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Column(name = "controller_id", length = 64)
|
||||
@Size(min = 1)
|
||||
@NotNull
|
||||
private String controllerId;
|
||||
|
||||
@Transient
|
||||
@@ -83,7 +87,7 @@ public class Target extends NamedEntity implements Persistable<Long> {
|
||||
@JoinTable(name = "sp_target_target_tag", joinColumns = {
|
||||
@JoinColumn(name = "target", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_targtag_target") ) }, inverseJoinColumns = {
|
||||
@JoinColumn(name = "tag", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_targtag_tag") ) })
|
||||
private Set<TargetTag> tags = new HashSet<TargetTag>();
|
||||
private Set<TargetTag> tags = new HashSet<>();
|
||||
|
||||
@CascadeOnDelete
|
||||
@OneToMany(fetch = FetchType.LAZY, orphanRemoval = true, cascade = { CascadeType.REMOVE })
|
||||
|
||||
@@ -18,6 +18,7 @@ import java.util.stream.Collectors;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Expression;
|
||||
import javax.persistence.criteria.MapJoin;
|
||||
import javax.persistence.criteria.Path;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
@@ -101,7 +102,7 @@ public final class RSQLUtility {
|
||||
*/
|
||||
public static <A extends Enum<A> & FieldNameProvider, T> Specification<T> parse(final String rsql,
|
||||
final Class<A> fieldNameProvider) {
|
||||
return new RSQLSpecification<>(rsql, fieldNameProvider);
|
||||
return new RSQLSpecification<>(rsql.toLowerCase(), fieldNameProvider);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -460,16 +461,46 @@ public final class RSQLUtility {
|
||||
singleList.add(cb.lessThanOrEqualTo(pathOfString(fieldPath), value));
|
||||
break;
|
||||
case "=in=":
|
||||
singleList.add(fieldPath.in(transformedValues));
|
||||
singleList.add(getInPredicate(transformedValues, fieldPath));
|
||||
break;
|
||||
case "=out=":
|
||||
singleList.add(cb.not(fieldPath.in(transformedValues)));
|
||||
singleList.add(getOutPredicate(transformedValues, fieldPath));
|
||||
break;
|
||||
default:
|
||||
LOGGER.info("operator symbol {} is either not supported or not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
private Predicate getInPredicate(final List<Object> transformedValues, final Path<Object> fieldPath) {
|
||||
final List<String> inParams = new ArrayList<>();
|
||||
for (final Object param : transformedValues) {
|
||||
if (param instanceof String) {
|
||||
inParams.add(((String) param).toUpperCase());
|
||||
}
|
||||
}
|
||||
if (!inParams.isEmpty()) {
|
||||
return cb.upper(pathOfString(fieldPath)).in(inParams);
|
||||
} else {
|
||||
return fieldPath.in(transformedValues);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private Predicate getOutPredicate(final List<Object> transformedValues, final Path<Object> fieldPath) {
|
||||
final List<String> outParams = new ArrayList<>();
|
||||
for (final Object param : transformedValues) {
|
||||
if (param instanceof String) {
|
||||
outParams.add(((String) param).toUpperCase());
|
||||
}
|
||||
}
|
||||
if (!outParams.isEmpty()) {
|
||||
return cb.not(cb.upper(pathOfString(fieldPath)).in(outParams));
|
||||
} else {
|
||||
return cb.not(fieldPath.in(transformedValues));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private Path<Object> getMapValueFieldPath(final A enumField, final Path<Object> fieldPath) {
|
||||
if (!enumField.isMap() || enumField.getValueFieldName() == null) {
|
||||
return fieldPath;
|
||||
@@ -477,6 +508,7 @@ public final class RSQLUtility {
|
||||
return fieldPath.get(enumField.getValueFieldName());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Predicate mapToMapPredicate(final ComparisonNode node, final Path<Object> fieldPath,
|
||||
final A enumField) {
|
||||
if (!enumField.isMap()) {
|
||||
@@ -485,10 +517,12 @@ public final class RSQLUtility {
|
||||
final String[] graph = node.getSelector().split("\\" + FieldNameProvider.SUB_ATTRIBUTE_SEPERATOR);
|
||||
final String keyValue = graph[graph.length - 1];
|
||||
if (fieldPath instanceof MapJoin) {
|
||||
return cb.equal(((MapJoin<?, ?, ?>) fieldPath).key(), keyValue);
|
||||
// Currently we support only string key .So below cast is safe.
|
||||
return cb.equal(cb.upper((Expression<String>) (((MapJoin<?, ?, ?>) fieldPath).key())),
|
||||
keyValue.toUpperCase());
|
||||
}
|
||||
|
||||
return cb.equal(fieldPath.get(enumField.getKeyFieldName()), keyValue);
|
||||
return cb.equal(cb.upper(fieldPath.get(enumField.getKeyFieldName())), keyValue.toUpperCase());
|
||||
}
|
||||
|
||||
private Predicate getEqualToPredicate(final Object transformedValue, final Path<Object> fieldPath) {
|
||||
|
||||
Reference in New Issue
Block a user