@Test public void should_not_throw_npe_when_update_with_rule_without_start_date() throws Exception { DynamicParserTokens parserTokens = new DynamicParserTokens(new VitamDescriptionResolver(Collections.emptyList()), Collections.emptyList()); JsonNode documentToUpdate = JsonHandler.getFromString( "{\n" + " \"_mgt\": {\n" + " \"AccessRule\": {\n" + " \"Rules\": [\n" + " {\n" + " \"Rule\": \"ACC-00001\"\n" + " }\n" + " ]\n" + " }\n" + " }\n" + "}" ); MongoDbInMemory mongoDbInMemory = new MongoDbInMemory(documentToUpdate, parserTokens); DurationData duration = new DurationData(); duration.setDurationUnit(ChronoUnit.FOREVER); duration.setDurationValue(12); String ruleId = "Rule"; Map<String, DurationData> durations = new HashMap<>(); durations.put(ruleId, duration); RuleAction ruleToUpdate = new RuleAction(); ruleToUpdate.setOldRule("ACC-00001"); ruleToUpdate.setRule(ruleId); RuleCategoryAction accessRuleToUpdate = new RuleCategoryAction(); accessRuleToUpdate.setRules(Collections.singletonList(ruleToUpdate)); HashMap<String, RuleCategoryAction> updates = new HashMap<>(); updates.put("AccessRule", accessRuleToUpdate); RuleActions ruleActions = new RuleActions(); ruleActions.setAdd(Collections.emptyList()); ruleActions.setDelete(Collections.emptyList()); ruleActions.setUpdate(Collections.singletonList(updates)); ThrowingCallable updateForRule = () -> mongoDbInMemory.getUpdateJsonForRule(ruleActions, durations); assertThatCode(updateForRule).doesNotThrowAnyException(); }
public JsonNode getUpdateJsonForRule(RuleActions ruleActions, Map<String, DurationData> bindRuleToDuration) throws InvalidParseOperationException { if(ruleActions != null) { final ObjectNode initialMgt = (ObjectNode) getOrCreateEmptyNodeByName(updatedDocument, MANAGEMENT_KEY, false); applyAddRuleAction(ruleActions.getAdd(), initialMgt, bindRuleToDuration); applyUpdateRuleAction(ruleActions.getUpdate(), initialMgt, bindRuleToDuration); applyDeleteRuleAction(ruleActions.getDelete(), initialMgt); updateArchiveUnitProfile(ruleActions); JsonHandler.setNodeInPath((ObjectNode) updatedDocument, MANAGEMENT_KEY, initialMgt, true); } return updatedDocument; }
MongoDbInMemory { public JsonNode getUpdateJsonForRule(RuleActions ruleActions, Map<String, DurationData> bindRuleToDuration) throws InvalidParseOperationException { if(ruleActions != null) { final ObjectNode initialMgt = (ObjectNode) getOrCreateEmptyNodeByName(updatedDocument, MANAGEMENT_KEY, false); applyAddRuleAction(ruleActions.getAdd(), initialMgt, bindRuleToDuration); applyUpdateRuleAction(ruleActions.getUpdate(), initialMgt, bindRuleToDuration); applyDeleteRuleAction(ruleActions.getDelete(), initialMgt); updateArchiveUnitProfile(ruleActions); JsonHandler.setNodeInPath((ObjectNode) updatedDocument, MANAGEMENT_KEY, initialMgt, true); } return updatedDocument; } }
MongoDbInMemory { public JsonNode getUpdateJsonForRule(RuleActions ruleActions, Map<String, DurationData> bindRuleToDuration) throws InvalidParseOperationException { if(ruleActions != null) { final ObjectNode initialMgt = (ObjectNode) getOrCreateEmptyNodeByName(updatedDocument, MANAGEMENT_KEY, false); applyAddRuleAction(ruleActions.getAdd(), initialMgt, bindRuleToDuration); applyUpdateRuleAction(ruleActions.getUpdate(), initialMgt, bindRuleToDuration); applyDeleteRuleAction(ruleActions.getDelete(), initialMgt); updateArchiveUnitProfile(ruleActions); JsonHandler.setNodeInPath((ObjectNode) updatedDocument, MANAGEMENT_KEY, initialMgt, true); } return updatedDocument; } MongoDbInMemory(JsonNode originalDocument, DynamicParserTokens parserTokens); }
MongoDbInMemory { public JsonNode getUpdateJsonForRule(RuleActions ruleActions, Map<String, DurationData> bindRuleToDuration) throws InvalidParseOperationException { if(ruleActions != null) { final ObjectNode initialMgt = (ObjectNode) getOrCreateEmptyNodeByName(updatedDocument, MANAGEMENT_KEY, false); applyAddRuleAction(ruleActions.getAdd(), initialMgt, bindRuleToDuration); applyUpdateRuleAction(ruleActions.getUpdate(), initialMgt, bindRuleToDuration); applyDeleteRuleAction(ruleActions.getDelete(), initialMgt); updateArchiveUnitProfile(ruleActions); JsonHandler.setNodeInPath((ObjectNode) updatedDocument, MANAGEMENT_KEY, initialMgt, true); } return updatedDocument; } MongoDbInMemory(JsonNode originalDocument, DynamicParserTokens parserTokens); JsonNode getUpdateJson(JsonNode request, boolean isMultiple, VarNameAdapter varNameAdapter); JsonNode getUpdateJson(AbstractParser<?> requestParser); JsonNode getUpdateJsonForRule(RuleActions ruleActions, Map<String, DurationData> bindRuleToDuration); @VisibleForTesting void resetUpdatedAU(); Set<String> getUpdatedFields(); }
MongoDbInMemory { public JsonNode getUpdateJsonForRule(RuleActions ruleActions, Map<String, DurationData> bindRuleToDuration) throws InvalidParseOperationException { if(ruleActions != null) { final ObjectNode initialMgt = (ObjectNode) getOrCreateEmptyNodeByName(updatedDocument, MANAGEMENT_KEY, false); applyAddRuleAction(ruleActions.getAdd(), initialMgt, bindRuleToDuration); applyUpdateRuleAction(ruleActions.getUpdate(), initialMgt, bindRuleToDuration); applyDeleteRuleAction(ruleActions.getDelete(), initialMgt); updateArchiveUnitProfile(ruleActions); JsonHandler.setNodeInPath((ObjectNode) updatedDocument, MANAGEMENT_KEY, initialMgt, true); } return updatedDocument; } MongoDbInMemory(JsonNode originalDocument, DynamicParserTokens parserTokens); JsonNode getUpdateJson(JsonNode request, boolean isMultiple, VarNameAdapter varNameAdapter); JsonNode getUpdateJson(AbstractParser<?> requestParser); JsonNode getUpdateJsonForRule(RuleActions ruleActions, Map<String, DurationData> bindRuleToDuration); @VisibleForTesting void resetUpdatedAU(); Set<String> getUpdatedFields();  }