Added assignment quota error UI extractor (#1278)
* added assignment quota error UI extractor * Verify amount of effected assignments instead of overall result count. Signed-off-by: Bogdan Bondar <Bogdan.Bondar@bosch.io> Co-authored-by: Michael Herdt <Michael.Herdt@bosch.com>
This commit is contained in:
@@ -114,11 +114,11 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
|
||||
|
||||
// enforce the 'max targets per auto assign' quota right here even
|
||||
// if the result of the filter query can vary over time
|
||||
if (create.getAutoAssignDistributionSetId().isPresent()) {
|
||||
create.getAutoAssignDistributionSetId().ifPresent(dsId -> {
|
||||
WeightValidationHelper.usingContext(systemSecurityContext, tenantConfigurationManagement)
|
||||
.validate(create);
|
||||
assertMaxTargetsQuota(query);
|
||||
}
|
||||
assertMaxTargetsQuota(query, create.getName().orElse(null), dsId);
|
||||
});
|
||||
});
|
||||
|
||||
return targetFilterQueryRepository.save(create.build());
|
||||
@@ -244,7 +244,8 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
|
||||
// query is going to change
|
||||
if (targetFilterQuery.getAutoAssignDistributionSet() != null
|
||||
&& !query.equals(targetFilterQuery.getQuery())) {
|
||||
assertMaxTargetsQuota(query);
|
||||
assertMaxTargetsQuota(query, targetFilterQuery.getName(),
|
||||
targetFilterQuery.getAutoAssignDistributionSet().getId());
|
||||
}
|
||||
|
||||
// set the new query
|
||||
@@ -268,11 +269,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
|
||||
targetFilterQuery.setConfirmationRequired(false);
|
||||
} else {
|
||||
WeightValidationHelper.usingContext(systemSecurityContext, tenantConfigurationManagement).validate(update);
|
||||
// we cannot be sure that the quota was enforced at creation time
|
||||
// because the Target Filter Query REST API does not allow to
|
||||
// specify an
|
||||
// auto-assign distribution set when creating a target filter query
|
||||
assertMaxTargetsQuota(targetFilterQuery.getQuery());
|
||||
assertMaxTargetsQuota(targetFilterQuery.getQuery(), targetFilterQuery.getName(), update.getDsId());
|
||||
final JpaDistributionSet ds = (JpaDistributionSet) distributionSetManagement
|
||||
.getValidAndComplete(update.getDsId());
|
||||
verifyDistributionSetAndThrowExceptionIfDeleted(ds);
|
||||
@@ -320,15 +317,15 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
|
||||
try {
|
||||
RSQLUtility.validateRsqlFor(query, TargetFields.class);
|
||||
return true;
|
||||
} catch (RSQLParserException | RSQLParameterUnsupportedFieldException e) {
|
||||
} catch (final RSQLParserException | RSQLParameterUnsupportedFieldException e) {
|
||||
LOGGER.debug("The RSQL query '" + query + "' is invalid.", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void assertMaxTargetsQuota(final String query) {
|
||||
QuotaHelper.assertAssignmentQuota(targetManagement.countByRsql(query),
|
||||
quotaManagement.getMaxTargetsPerAutoAssignment(), Target.class, TargetFilterQuery.class);
|
||||
private void assertMaxTargetsQuota(final String query, final String filterName, final long dsId) {
|
||||
QuotaHelper.assertAssignmentQuota(filterName, targetManagement.countByRsqlAndNonDSAndCompatible(dsId, query),
|
||||
quotaManagement.getMaxTargetsPerAutoAssignment(), Target.class, TargetFilterQuery.class, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user