Unverified Commit 8a19118e authored by Benaissa BENARBIA's avatar Benaissa BENARBIA Committed by GitHub
Browse files

[Vas] Item 9009 : Adapt archive search by appraisal rules to new Vitam model (#543)

* adapt appraisal search to new model

* fix unit tests
parent 8f3ce6bb
......@@ -105,11 +105,11 @@ public class ArchiveSearchConsts {
ArchiveSearchConsts.APPRAISAL_RULE_END_DATE, "#management.AppraisalRule.Rules.EndDate"
);
public static Map<String, String> INHERITED_APPRAISAL_MGT_RULES_SIMPLE_FIELDS_MAPPING =
Map.of(ArchiveSearchConsts.APPRAISAL_RULE_IDENTIFIER, "#computedInheritedRules.AppraisalRule.EndDates",
ArchiveSearchConsts.APPRAISAL_RULE_END_DATE, "#computedInheritedRules.AppraisalRule.MaxEndDate"
Map.of(ArchiveSearchConsts.APPRAISAL_RULE_IDENTIFIER, "#computedInheritedRules.AppraisalRule.Rules.Rule",
ArchiveSearchConsts.APPRAISAL_RULE_END_DATE, "#computedInheritedRules.AppraisalRule.Rules.EndDate"
);
public static String APPRAISAL_RULE_ORIGIN_INHERITED_FIELD = "#computedInheritedRules.AppraisalRule";
public static String APPRAISAL_RULE_ORIGIN_INHERITED_FIELD = "#computedInheritedRules.AppraisalRule.Rules.Rule";
public static String APPRAISAL_RULE_ORIGIN_SCOPED_FIELD = "#management.AppraisalRule.Rules.Rule";
......
......@@ -368,94 +368,55 @@ public class ArchivesSearchAppraisalQueryBuilderService implements IArchivesSear
String endDtVitamFieldNameScoped =
ArchiveSearchConsts.SCOPED_APPRAISAL_MGT_RULES_SIMPLE_FIELDS_MAPPING
.get(ArchiveSearchConsts.APPRAISAL_RULE_END_DATE);
if (ArchiveSearchConsts.AppraisalRuleOrigin.INHERITED.equals(origin)) {
//In case we have endates criteria
if (ArchiveSearchConsts.AppraisalRuleOrigin.SCOPED.equals(origin)) {
if (appraisalIdentifierCriteria.isPresent()) {
BooleanQuery identifierQuery = or();
for (CriteriaValue valueIdentifier : appraisalIdentifierCriteria.get().getValues()) {
VitamQueryHelper.addParameterCriteria(identifierQuery, ArchiveSearchConsts.CriteriaOperators.EQ,
ruleIdVitamFieldNameScoped, List.of(valueIdentifier.getValue()));
}
if (identifierQuery.isReady()) {
appraisalMgtRulesSubQuery.add(identifierQuery);
}
}
if (appraisalEndDatesCriteria.isPresent()) {
//in case we have rules id criteria
if (appraisalIdentifierCriteria.isPresent()) {
BooleanQuery intervalQuery = or();
for (CriteriaValue valueIdentifier : appraisalIdentifierCriteria.get().getValues()) {
for (CriteriaValue valueEndDate : appraisalEndDatesCriteria.get().getValues()) {
BooleanQuery intervalQueryByInterval = and();
String beginDtStr = valueEndDate.getBeginInterval();
String endDtStr = valueEndDate.getEndInterval();
if (!ObjectUtils.isEmpty(beginDtStr)) {
LocalDateTime beginDt =
LocalDateTime.parse(beginDtStr, ArchiveSearchConsts.ISO_FRENCH_FORMATER);
VitamQueryHelper.addParameterCriteria(intervalQueryByInterval,
ArchiveSearchConsts.CriteriaOperators.GTE,
ruleIdVitamFieldName + "." + valueIdentifier.getValue(),
List.of(ArchiveSearchConsts.ONLY_DATE_FRENCH_FORMATER.format(beginDt)));
}
if (!ObjectUtils.isEmpty(endDtStr)) {
LocalDateTime endDt =
LocalDateTime.parse(endDtStr, ArchiveSearchConsts.ISO_FRENCH_FORMATER);
VitamQueryHelper.addParameterCriteria(intervalQueryByInterval,
ArchiveSearchConsts.CriteriaOperators.LTE,
ruleIdVitamFieldName + "." + valueIdentifier.getValue(),
List.of(ArchiveSearchConsts.ONLY_DATE_FRENCH_FORMATER.format(endDt)));
}
if (intervalQueryByInterval.isReady()) {
intervalQuery.add(intervalQueryByInterval);
}
}
}
if (intervalQuery.isReady()) {
appraisalMgtRulesSubQuery.add(intervalQuery);
}
} else {
BooleanQuery intervalQuery = or();
for (CriteriaValue valueEndDate : appraisalEndDatesCriteria.get().getValues()) {
BooleanQuery intervalQueryByInterval = and();
String beginDtStr = valueEndDate.getBeginInterval();
String endDtStr = valueEndDate.getEndInterval();
if (!ObjectUtils.isEmpty(beginDtStr)) {
LocalDateTime beginDt =
LocalDateTime.parse(beginDtStr, ArchiveSearchConsts.ISO_FRENCH_FORMATER);
VitamQueryHelper.addParameterCriteria(intervalQueryByInterval,
ArchiveSearchConsts.CriteriaOperators.GTE,
endDtVitamFieldName,
BooleanQuery appraisalEndQuery = or();
for (CriteriaValue valueEndDate : appraisalEndDatesCriteria.get().getValues()) {
BooleanQuery intervalQueryByInterval = and();
String beginDtStr = valueEndDate.getBeginInterval();
String endDtStr = valueEndDate.getEndInterval();
if (!ObjectUtils.isEmpty(beginDtStr)) {
LocalDateTime beginDt =
LocalDateTime.parse(beginDtStr, ArchiveSearchConsts.ISO_FRENCH_FORMATER);
VitamQueryHelper
.addParameterCriteria(intervalQueryByInterval, ArchiveSearchConsts.CriteriaOperators.GTE,
endDtVitamFieldNameScoped,
List.of(ArchiveSearchConsts.ONLY_DATE_FRENCH_FORMATER.format(beginDt)));
}
}
if (!ObjectUtils.isEmpty(endDtStr)) {
LocalDateTime endDt =
LocalDateTime.parse(endDtStr, ArchiveSearchConsts.ISO_FRENCH_FORMATER);
VitamQueryHelper.addParameterCriteria(intervalQueryByInterval,
ArchiveSearchConsts.CriteriaOperators.LTE,
endDtVitamFieldName,
List.of(ArchiveSearchConsts.ONLY_DATE_FRENCH_FORMATER.format(endDt)));
}
if (intervalQueryByInterval.isReady()) {
intervalQuery.add(intervalQueryByInterval);
}
if (!ObjectUtils.isEmpty(endDtStr)) {
LocalDateTime endDt =
LocalDateTime.parse(endDtStr, ArchiveSearchConsts.ISO_FRENCH_FORMATER);
VitamQueryHelper.addParameterCriteria(intervalQueryByInterval,
ArchiveSearchConsts.CriteriaOperators.LTE, endDtVitamFieldNameScoped,
List.of(ArchiveSearchConsts.ONLY_DATE_FRENCH_FORMATER.format(endDt)));
}
if (intervalQuery.isReady()) {
appraisalMgtRulesSubQuery.add(intervalQuery);
if (intervalQueryByInterval.isReady()) {
appraisalEndQuery.add(intervalQueryByInterval);
}
}
} else {
if (appraisalIdentifierCriteria.isPresent()) {
BooleanQuery identifierQuery = or();
for (CriteriaValue valueIdentifier : appraisalIdentifierCriteria.get().getValues()) {
VitamQueryHelper
.addParameterCriteria(identifierQuery, ArchiveSearchConsts.CriteriaOperators.EXISTS,
ruleIdVitamFieldName + "." + valueIdentifier.getValue(), List.of());
}
if (identifierQuery.isReady()) {
appraisalMgtRulesSubQuery.add(identifierQuery);
}
if (appraisalEndQuery.isReady()) {
appraisalMgtRulesSubQuery.add(appraisalEndQuery);
}
}
} else if (ArchiveSearchConsts.AppraisalRuleOrigin.SCOPED.equals(origin)) {
} else if (ArchiveSearchConsts.AppraisalRuleOrigin.INHERITED.equals(origin)) {
if (appraisalIdentifierCriteria.isPresent()) {
BooleanQuery identifierQuery = or();
for (CriteriaValue valueIdentifier : appraisalIdentifierCriteria.get().getValues()) {
VitamQueryHelper.addParameterCriteria(identifierQuery, ArchiveSearchConsts.CriteriaOperators.EQ,
ruleIdVitamFieldNameScoped, List.of(valueIdentifier.getValue()));
ruleIdVitamFieldName, List.of(valueIdentifier.getValue()));
}
if (identifierQuery.isReady()) {
appraisalMgtRulesSubQuery.add(identifierQuery);
......@@ -473,7 +434,7 @@ public class ArchivesSearchAppraisalQueryBuilderService implements IArchivesSear
LocalDateTime.parse(beginDtStr, ArchiveSearchConsts.ISO_FRENCH_FORMATER);
VitamQueryHelper
.addParameterCriteria(intervalQueryByInterval, ArchiveSearchConsts.CriteriaOperators.GTE,
endDtVitamFieldNameScoped,
endDtVitamFieldName,
List.of(ArchiveSearchConsts.ONLY_DATE_FRENCH_FORMATER.format(beginDt)));
}
......@@ -481,7 +442,7 @@ public class ArchivesSearchAppraisalQueryBuilderService implements IArchivesSear
LocalDateTime endDt =
LocalDateTime.parse(endDtStr, ArchiveSearchConsts.ISO_FRENCH_FORMATER);
VitamQueryHelper.addParameterCriteria(intervalQueryByInterval,
ArchiveSearchConsts.CriteriaOperators.LTE, endDtVitamFieldNameScoped,
ArchiveSearchConsts.CriteriaOperators.LTE, endDtVitamFieldName,
List.of(ArchiveSearchConsts.ONLY_DATE_FRENCH_FORMATER.format(endDt)));
}
if (intervalQueryByInterval.isReady()) {
......
[{"$or":[{"$eq":{"#management.AppraisalRule.Rules.Rule":"APP-001"}},{"$exists":"#computedInheritedRules.AppraisalRule.EndDates.APP-001"}]}, {"$or":[{"$and":[{"$exists":"#computedInheritedRules.AppraisalRule"},{"$or":[{"$exists":"#computedInheritedRules.AppraisalRule.EndDates.APP-001"}]},{"$not":[{"$and":[{"$exists":"#management.AppraisalRule.Rules.Rule"},{"$or":[{"$eq":{"#management.AppraisalRule.Rules.Rule":"APP-001"}}]}]}]}]}]}, {"$or":[{"$eq":{"#management.AppraisalRule.FinalAction":"Destroy"}},{"$eq":{"#computedInheritedRules.AppraisalRule.FinalAction":"Destroy"}}]}]
[{"$or":[{"$eq":{"#management.AppraisalRule.Rules.Rule":"APP-001"}},{"$eq":{"#computedInheritedRules.AppraisalRule.Rules.Rule":"APP-001"}}]}, {"$or":[{"$and":[{"$exists":"#computedInheritedRules.AppraisalRule.Rules.Rule"},{"$or":[{"$eq":{"#computedInheritedRules.AppraisalRule.Rules.Rule":"APP-001"}}]},{"$not":[{"$and":[{"$exists":"#management.AppraisalRule.Rules.Rule"},{"$or":[{"$eq":{"#management.AppraisalRule.Rules.Rule":"APP-001"}}]}]}]}]}]}, {"$or":[{"$eq":{"#management.AppraisalRule.FinalAction":"Destroy"}},{"$eq":{"#computedInheritedRules.AppraisalRule.FinalAction":"Destroy"}}]}]
[{"$or":[{"$eq":{"#management.AppraisalRule.Rules.Rule":"APP-001"}},{"$exists":"#computedInheritedRules.AppraisalRule.EndDates.APP-001"}]}, {"$or":[{"$eq":{"#management.AppraisalRule.FinalAction":"Keep"}},{"$eq":{"#computedInheritedRules.AppraisalRule.FinalAction":"Keep"}}]}]
[{"$or":[{"$eq":{"#management.AppraisalRule.Rules.Rule":"APP-001"}},{"$eq":{"#computedInheritedRules.AppraisalRule.Rules.Rule":"APP-001"}}]}, {"$or":[{"$eq":{"#management.AppraisalRule.FinalAction":"Keep"}},{"$eq":{"#computedInheritedRules.AppraisalRule.FinalAction":"Keep"}}]}]
[{"$or":[{"$eq":{"#management.AppraisalRule.Rules.Rule":"APP-001"}},{"$exists":"#computedInheritedRules.AppraisalRule.EndDates.APP-001"}]}, {"$or":[{"$and":[{"$exists":"#computedInheritedRules.AppraisalRule"},{"$or":[{"$exists":"#computedInheritedRules.AppraisalRule.EndDates.APP-001"}]},{"$not":[{"$and":[{"$exists":"#management.AppraisalRule.Rules.Rule"},{"$or":[{"$eq":{"#management.AppraisalRule.Rules.Rule":"APP-001"}}]}]}]}]}]}]
[{"$or":[{"$eq":{"#management.AppraisalRule.Rules.Rule":"APP-001"}},{"$eq":{"#computedInheritedRules.AppraisalRule.Rules.Rule":"APP-001"}}]}, {"$or":[{"$and":[{"$exists":"#computedInheritedRules.AppraisalRule.Rules.Rule"},{"$or":[{"$eq":{"#computedInheritedRules.AppraisalRule.Rules.Rule":"APP-001"}}]},{"$not":[{"$and":[{"$exists":"#management.AppraisalRule.Rules.Rule"},{"$or":[{"$eq":{"#management.AppraisalRule.Rules.Rule":"APP-001"}}]}]}]}]}]}]
[{"$or":[{"$eq":{"#management.AppraisalRule.Rules.Rule":"APP-001"}},{"$exists":"#computedInheritedRules.AppraisalRule.EndDates.APP-001"}]}, {"$or":[{"$and":[{"$exists":"#computedInheritedRules.AppraisalRule"},{"$or":[{"$exists":"#computedInheritedRules.AppraisalRule.EndDates.APP-001"}]}]},{"$and":[{"$exists":"#management.AppraisalRule.Rules.Rule"},{"$or":[{"$eq":{"#management.AppraisalRule.Rules.Rule":"APP-001"}}]}]}]}]
[{"$or":[{"$eq":{"#management.AppraisalRule.Rules.Rule":"APP-001"}},{"$eq":{"#computedInheritedRules.AppraisalRule.Rules.Rule":"APP-001"}}]}, {"$or":[{"$and":[{"$exists":"#computedInheritedRules.AppraisalRule.Rules.Rule"},{"$or":[{"$eq":{"#computedInheritedRules.AppraisalRule.Rules.Rule":"APP-001"}}]}]},{"$and":[{"$exists":"#management.AppraisalRule.Rules.Rule"},{"$or":[{"$eq":{"#management.AppraisalRule.Rules.Rule":"APP-001"}}]}]}]}]
[{"$or":[{"$eq":{"#management.AppraisalRule.Rules.Rule":"APP-001"}},{"$exists":"#computedInheritedRules.AppraisalRule.EndDates.APP-001"}]}, {"$or":[{"$and":[{"$not":[{"$and":[{"$exists":"#computedInheritedRules.AppraisalRule"},{"$or":[{"$exists":"#computedInheritedRules.AppraisalRule.EndDates.APP-001"}]}]}]},{"$not":[{"$and":[{"$exists":"#management.AppraisalRule.Rules.Rule"},{"$or":[{"$eq":{"#management.AppraisalRule.Rules.Rule":"APP-001"}}]}]}]}]},{"$and":[{"$exists":"#computedInheritedRules.AppraisalRule"},{"$or":[{"$exists":"#computedInheritedRules.AppraisalRule.EndDates.APP-001"}]},{"$not":[{"$and":[{"$exists":"#management.AppraisalRule.Rules.Rule"},{"$or":[{"$eq":{"#management.AppraisalRule.Rules.Rule":"APP-001"}}]}]}]}]}]}]
[{"$or":[{"$eq":{"#management.AppraisalRule.Rules.Rule":"APP-001"}},{"$eq":{"#computedInheritedRules.AppraisalRule.Rules.Rule":"APP-001"}}]}, {"$or":[{"$and":[{"$not":[{"$and":[{"$exists":"#computedInheritedRules.AppraisalRule.Rules.Rule"},{"$or":[{"$eq":{"#computedInheritedRules.AppraisalRule.Rules.Rule":"APP-001"}}]}]}]},{"$not":[{"$and":[{"$exists":"#management.AppraisalRule.Rules.Rule"},{"$or":[{"$eq":{"#management.AppraisalRule.Rules.Rule":"APP-001"}}]}]}]}]},{"$and":[{"$exists":"#computedInheritedRules.AppraisalRule.Rules.Rule"},{"$or":[{"$eq":{"#computedInheritedRules.AppraisalRule.Rules.Rule":"APP-001"}}]},{"$not":[{"$and":[{"$exists":"#management.AppraisalRule.Rules.Rule"},{"$or":[{"$eq":{"#management.AppraisalRule.Rules.Rule":"APP-001"}}]}]}]}]}]}]
[{"$or":[{"$eq":{"#management.AppraisalRule.Rules.Rule":"APP-001"}},{"$exists":"#computedInheritedRules.AppraisalRule.EndDates.APP-001"}]}]
[{"$or":[{"$eq":{"#management.AppraisalRule.Rules.Rule":"APP-001"}},{"$eq":{"#computedInheritedRules.AppraisalRule.Rules.Rule":"APP-001"}}]}]
[{"$or":[{"$eq":{"#management.AppraisalRule.Rules.Rule":"APP-001"}},{"$exists":"#computedInheritedRules.AppraisalRule.EndDates.APP-001"}]}, {"$or":[{"$eq":{"#validComputedInheritedRules":"false"}},{"$and":[{"$exists":"#computedInheritedRules.AppraisalRule"},{"$or":[{"$exists":"#computedInheritedRules.AppraisalRule.EndDates.APP-001"}]},{"$not":[{"$and":[{"$exists":"#management.AppraisalRule.Rules.Rule"},{"$or":[{"$eq":{"#management.AppraisalRule.Rules.Rule":"APP-001"}}]}]}]}]}]}]
[{"$or":[{"$eq":{"#management.AppraisalRule.Rules.Rule":"APP-001"}},{"$eq":{"#computedInheritedRules.AppraisalRule.Rules.Rule":"APP-001"}}]}, {"$or":[{"$eq":{"#validComputedInheritedRules":"false"}},{"$and":[{"$exists":"#computedInheritedRules.AppraisalRule.Rules.Rule"},{"$or":[{"$eq":{"#computedInheritedRules.AppraisalRule.Rules.Rule":"APP-001"}}]},{"$not":[{"$and":[{"$exists":"#management.AppraisalRule.Rules.Rule"},{"$or":[{"$eq":{"#management.AppraisalRule.Rules.Rule":"APP-001"}}]}]}]}]}]}]
[{"$or":[{"$and":[{"$gte":{"#management.AppraisalRule.Rules.EndDate":"2011-11-02"}},{"$lte":{"#management.AppraisalRule.Rules.EndDate":"2021-11-02"}}]},{"$and":[{"$gte":{"#computedInheritedRules.AppraisalRule.MaxEndDate":"2011-11-02"}},{"$lte":{"#computedInheritedRules.AppraisalRule.MaxEndDate":"2021-11-02"}}]}]}]
[{"$or":[{"$and":[{"$gte":{"#management.AppraisalRule.Rules.EndDate":"2011-11-02"}},{"$lte":{"#management.AppraisalRule.Rules.EndDate":"2021-11-02"}}]},{"$and":[{"$gte":{"#computedInheritedRules.AppraisalRule.Rules.EndDate":"2011-11-02"}},{"$lte":{"#computedInheritedRules.AppraisalRule.Rules.EndDate":"2021-11-02"}}]}]}]
[{"$or":[{"$and":[{"$gte":{"#management.AppraisalRule.Rules.EndDate":"2021-11-02"}}]},{"$and":[{"$gte":{"#computedInheritedRules.AppraisalRule.MaxEndDate":"2021-11-02"}}]}]}]
[{"$or":[{"$and":[{"$gte":{"#management.AppraisalRule.Rules.EndDate":"2021-11-02"}}]},{"$and":[{"$gte":{"#computedInheritedRules.AppraisalRule.Rules.EndDate":"2021-11-02"}}]}]}]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment