@Test public void testJsonDiff() throws Exception { String s1 = "{\"a\":1,\"b\":2,\"c\":[{\"a\":1,\"b\":2},{\"a\":3,\"b\":4}]}"; String s2 = "{\"a\":1,\"b\":2,\"c\":[{\"xa\":199,\"b\":20},{\"a\":1,\"b\":2}],\"e\":{\"alpha\":123,\"bravo\":1234}}"; JsonNode json1 = JsonHandler.getFromString(s1); JsonNode json2 = JsonHandler.getFromString(s2); JsonNode target = JsonDiff.asJson(json1, json2); assertEquals(target.toString(), "[{\"op\":\"add\",\"path\":\"/c/0\",\"value\":{\"xa\":199,\"b\":20}},{\"op\":\"remove\",\"path\":\"/c/2\"},{\"op\":\"add\",\"path\":\"/e\",\"value\":{\"alpha\":123,\"bravo\":1234}}]"); target = JsonDiff.asJson(json1, json1); assertEquals(target.toString(), "[]"); assertTrue( rulesFileManager.checkRuleConformity(JsonHandler.createArrayNode(), JsonHandler.createArrayNode(), 0)); }
public boolean checkRuleConformity(ArrayNode array1, ArrayNode array2, int tenant) { if (!array1.toString().equals(array2.toString())) { JsonNode patch = JsonDiff.asJson(array1, array2); alertService.createAlert("Check failed: the security save of the rules repository of tenant " + tenant + " is not equal to its value in database.\n" + patch); return false; } return true; }
RulesManagerFileImpl implements ReferentialFile<FileRules> { public boolean checkRuleConformity(ArrayNode array1, ArrayNode array2, int tenant) { if (!array1.toString().equals(array2.toString())) { JsonNode patch = JsonDiff.asJson(array1, array2); alertService.createAlert("Check failed: the security save of the rules repository of tenant " + tenant + " is not equal to its value in database.\n" + patch); return false; } return true; } }
RulesManagerFileImpl implements ReferentialFile<FileRules> { public boolean checkRuleConformity(ArrayNode array1, ArrayNode array2, int tenant) { if (!array1.toString().equals(array2.toString())) { JsonNode patch = JsonDiff.asJson(array1, array2); alertService.createAlert("Check failed: the security save of the rules repository of tenant " + tenant + " is not equal to its value in database.\n" + patch); return false; } return true; } RulesManagerFileImpl(MongoDbAccessAdminImpl dbConfiguration, VitamCounterService vitamCounterService,
        OntologyLoader ontologyLoader, VitamRuleService vitamRuleService); @VisibleForTesting  RulesManagerFileImpl(MongoDbAccessAdminImpl dbConfiguration,
        VitamCounterService vitamCounterService,
        FunctionalBackupService backupService, LogbookOperationsClientFactory logbookOperationsClientFactory,
        MetaDataClientFactory metaDataClientFactory,
        ProcessingManagementClientFactory processingManagementClientFactory,
        WorkspaceClientFactory workspaceClientFactory,
        OntologyLoader ontologyLoader,
        VitamRuleService vitamRuleService); }
RulesManagerFileImpl implements ReferentialFile<FileRules> { public boolean checkRuleConformity(ArrayNode array1, ArrayNode array2, int tenant) { if (!array1.toString().equals(array2.toString())) { JsonNode patch = JsonDiff.asJson(array1, array2); alertService.createAlert("Check failed: the security save of the rules repository of tenant " + tenant + " is not equal to its value in database.\n" + patch); return false; } return true; } RulesManagerFileImpl(MongoDbAccessAdminImpl dbConfiguration, VitamCounterService vitamCounterService,
        OntologyLoader ontologyLoader, VitamRuleService vitamRuleService); @VisibleForTesting  RulesManagerFileImpl(MongoDbAccessAdminImpl dbConfiguration,
        VitamCounterService vitamCounterService,
        FunctionalBackupService backupService, LogbookOperationsClientFactory logbookOperationsClientFactory,
        MetaDataClientFactory metaDataClientFactory,
        ProcessingManagementClientFactory processingManagementClientFactory,
        WorkspaceClientFactory workspaceClientFactory,
        OntologyLoader ontologyLoader,
        VitamRuleService vitamRuleService); @Override void importFile(InputStream rulesFileStream, String filename); ArrayNode checkFile(InputStream rulesFileStream, Map<Integer, List<ErrorReport>> errorsMap,
        List<FileRulesModel> usedDeletedRules, List<FileRulesModel> usedUpdatedRules,
        List<FileRulesModel> usedUpdateRulesForUpdateUnit, List<FileRulesModel> insertRules,
        Set<String> notUsedDeletedRules, Set<String> notUsedUpdatedRules); @Override FileRules findDocumentById(String id); @Override RequestResponseOK<FileRules> findDocuments(JsonNode select); InputStream generateErrorReport(Map<Integer, List<ErrorReport>> errors,
        List<FileRulesModel> usedDeletedRules, List<FileRulesModel> usedUpdatedRules,
        StatusCode status, GUID eipMaster); ArrayNode getRuleFromCollection(int tenant); ArrayNode getRuleFromOffer(int tenant); boolean checkRuleConformity(ArrayNode array1, ArrayNode array2, int tenant); }
RulesManagerFileImpl implements ReferentialFile<FileRules> { public boolean checkRuleConformity(ArrayNode array1, ArrayNode array2, int tenant) { if (!array1.toString().equals(array2.toString())) { JsonNode patch = JsonDiff.asJson(array1, array2); alertService.createAlert("Check failed: the security save of the rules repository of tenant " + tenant + " is not equal to its value in database.\n" + patch); return false; } return true; } RulesManagerFileImpl(MongoDbAccessAdminImpl dbConfiguration, VitamCounterService vitamCounterService,
        OntologyLoader ontologyLoader, VitamRuleService vitamRuleService); @VisibleForTesting  RulesManagerFileImpl(MongoDbAccessAdminImpl dbConfiguration,
        VitamCounterService vitamCounterService,
        FunctionalBackupService backupService, LogbookOperationsClientFactory logbookOperationsClientFactory,
        MetaDataClientFactory metaDataClientFactory,
        ProcessingManagementClientFactory processingManagementClientFactory,
        WorkspaceClientFactory workspaceClientFactory,
        OntologyLoader ontologyLoader,
        VitamRuleService vitamRuleService); @Override void importFile(InputStream rulesFileStream, String filename); ArrayNode checkFile(InputStream rulesFileStream, Map<Integer, List<ErrorReport>> errorsMap,
        List<FileRulesModel> usedDeletedRules, List<FileRulesModel> usedUpdatedRules,
        List<FileRulesModel> usedUpdateRulesForUpdateUnit, List<FileRulesModel> insertRules,
        Set<String> notUsedDeletedRules, Set<String> notUsedUpdatedRules); @Override FileRules findDocumentById(String id); @Override RequestResponseOK<FileRules> findDocuments(JsonNode select); InputStream generateErrorReport(Map<Integer, List<ErrorReport>> errors,
        List<FileRulesModel> usedDeletedRules, List<FileRulesModel> usedUpdatedRules,
        StatusCode status, GUID eipMaster); ArrayNode getRuleFromCollection(int tenant); ArrayNode getRuleFromOffer(int tenant); boolean checkRuleConformity(ArrayNode array1, ArrayNode array2, int tenant);  }