Fixed Rule for METADATA::COLLECTION

This commit is contained in:
Luca Frosini 2020-01-08 16:07:13 +01:00
parent 6b7feaee29
commit 58f9dc9cad
4 changed files with 56 additions and 45 deletions

View File

@ -164,51 +164,45 @@ public class TestRules extends ContextTest {
}
};
for(File dir : rulesDirectory.listFiles()) {
if(!dir.isDirectory()) {
continue;
}
File[] elaborationFilesNoMatch = dir.listFiles(filenameFilter);
for(File elaborationFileNoMatch : elaborationFilesNoMatch) {
logger.info("Comparing examples which must not match from file {}", elaborationFileNoMatch.getName());
try(BufferedReader br = new BufferedReader(new FileReader(elaborationFileNoMatch))) {
for(String line; (line = br.readLine()) != null;) {
String[] splittedLine = line.split(",");
String serviceClass = splittedLine[0];
String serviceName = splittedLine[1];
String calledMethod = splittedLine[2];
Replace replace = matcherReplace.check(serviceClass, serviceName, calledMethod);
if(replace != null) {
logger.error("{} match {} but it should NOT. This MUST not occur.", line,
matcherReplace.getMultiMatcher().toString());
throw new Exception();
} else {
logger.trace("{} does NOT match as requested", line, replacementRegex.getServiceClass(),
replacementRegex.getServiceName(), replacementRegex.getCalledMethod());
}
ServiceUsageRecord sur = TestUsageRecord.createTestServiceUsageRecord();
sur.setServiceClass(serviceClass);
sur.setServiceName(serviceName);
sur.setCalledMethod(calledMethod);
sur.validate();
//logger.trace("Should not be aggregated ServiceUsageRecord {}", sur);
for(AggregatedServiceUsageRecord asur : aggregatedMap.values()) {
try {
asur.aggregate(sur);
throw new Exception("The record has been aggregated and it should NOT");
} catch(NotAggregatableRecordsExceptions e) {
//logger.trace("{} is not aggragable as expected", sur);
}
for(File elaborationFileNoMatch : rulesDirectory.listFiles(filenameFilter)) {
logger.info("Comparing examples which must not match from file {}", elaborationFileNoMatch.getName());
try(BufferedReader br = new BufferedReader(new FileReader(elaborationFileNoMatch))) {
for(String line; (line = br.readLine()) != null;) {
String[] splittedLine = line.split(",");
String serviceClass = splittedLine[0];
String serviceName = splittedLine[1];
String calledMethod = splittedLine[2];
Replace replace = matcherReplace.check(serviceClass, serviceName, calledMethod);
if(replace != null) {
logger.error("{} match {} but it should NOT. This MUST not occur.", line,
matcherReplace.getMultiMatcher().toString());
throw new Exception();
} else {
logger.trace("{} does NOT match as requested", line, replacementRegex.getServiceClass(),
replacementRegex.getServiceName(), replacementRegex.getCalledMethod());
}
ServiceUsageRecord sur = TestUsageRecord.createTestServiceUsageRecord();
sur.setServiceClass(serviceClass);
sur.setServiceName(serviceName);
sur.setCalledMethod(calledMethod);
sur.validate();
//logger.trace("Should not be aggregated ServiceUsageRecord {}", sur);
for(AggregatedServiceUsageRecord asur : aggregatedMap.values()) {
try {
asur.aggregate(sur);
throw new Exception("The record has been aggregated and it should NOT");
} catch(NotAggregatableRecordsExceptions e) {
//logger.trace("{} is not aggragable as expected", sur);
}
}
} catch(Exception e) {
throw e;
}
} catch(Exception e) {
throw e;
}
}
logger.info(
"-----------------------------------------------------------------------------------------------------\n\n\n");
}
@ -218,7 +212,7 @@ public class TestRules extends ContextTest {
allRules();
File rulesDirectory = getRulesDirectory();
File rulesDirFile = new File(rulesDirectory, "Thredds");
File rulesFile = new File(rulesDirFile, "Thredds_METADATA::OTHER.json");
File rulesFile = new File(rulesDirFile, "Thredds_METADATA::COLLECTION.json");
testRule(rulesFile);
}

View File

@ -2,11 +2,11 @@
"match": {
"serviceClassRegex": "SDI",
"serviceNameRegex": "Thredds",
"calledMethodRegex": "^(\/){1}(?<Protocol>[a-zA-Z0-9]*){1}(\/public\/netcdf\/){1}(?<Collection>[a-zA-Z0-9_-]*)(\/){1}(.*\\.(nc|asc|tiff)).{1,}"
"calledMethodRegex": "^(\/){1}(?<Protocol>[a-zA-Z0-9]*){1}(\/public\/netcdf\/){1}(?<Collection>[a-zA-Z0-9_-]*(?<!(..\\.nc)))(\/){1}.*(?<!(..\\.nc|.\\.asc|\\.tiff))$"
},
"replace": {
"serviceClass": "SDI",
"serviceName": "Thredds",
"calledMethod": "${Protocol}::${Collection}"
"calledMethod": "METADATA::${Collection}"
}
}

View File

@ -2,11 +2,11 @@
"match": {
"serviceClassRegex": "SDI",
"serviceNameRegex": "Thredds",
"calledMethodRegex": "^(\/){1}(?<Protocol>[a-zA-Z0-9]*){1}(\/public\/netcdf\/){1}([^\/]*\\.(nc|asc|tiff)).{1,}"
"calledMethodRegex": "^(\/){1}(?<Protocol>[a-zA-Z0-9]*){1}(\/public\/netcdf\/){1}((.*\\.(nc|asc|tiff)).{1,})"
},
"replace": {
"serviceClass": "SDI",
"serviceName": "Thredds",
"calledMethod": "${Protocol}::OTHER"
"calledMethod": "METADATA::OTHER"
}
}

View File

@ -0,0 +1,17 @@
Service Class,Service Name,Called Method
SDI,Thredds,/style/ncss/layout.css
SDI,Thredds,/tds.css
SDI,Thredds,/folder.gif
SDI,Thredds,/godiva2/css/calendar-blue.css
SDI,Thredds,/godiva2/css/godiva2.css
SDI,Thredds,/style/ncss/main.css
SDI,Thredds,/tdsCat.css
SDI,Thredds,/tdsDap.css
SDI,Thredds,/
SDI,Thredds,/godiva2/theme/default/img/close.gif
SDI,Thredds,/godiva2/images/ajax-loader.gif
SDI,Thredds,/godiva2/img/blank.gif
SDI,Thredds,/godiva2/theme/default/style.css
SDI,Thredds,/js/lib/OpenLayers-2.12/theme/default/style.css
SDI,Thredds,/style/ncss/form.css
SDI,Thredds,/threddsIcon.gif
1 Service Class Service Name Called Method
2 SDI Thredds /style/ncss/layout.css
3 SDI Thredds /tds.css
4 SDI Thredds /folder.gif
5 SDI Thredds /godiva2/css/calendar-blue.css
6 SDI Thredds /godiva2/css/godiva2.css
7 SDI Thredds /style/ncss/main.css
8 SDI Thredds /tdsCat.css
9 SDI Thredds /tdsDap.css
10 SDI Thredds /
11 SDI Thredds /godiva2/theme/default/img/close.gif
12 SDI Thredds /godiva2/images/ajax-loader.gif
13 SDI Thredds /godiva2/img/blank.gif
14 SDI Thredds /godiva2/theme/default/style.css
15 SDI Thredds /js/lib/OpenLayers-2.12/theme/default/style.css
16 SDI Thredds /style/ncss/form.css
17 SDI Thredds /threddsIcon.gif