X-Git-Url: https://gerrit.onap.org/r/gitweb?p=aai%2Fgizmo.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fschema%2FRelationshipSchemaLoader.java;h=0e10fc3228e6f5c37faa8c1739e3c98bfa18fe05;hp=761f6adbf60c3f62c91b0acefd0d56b0668214ae;hb=b713fc2e83452517654c9e37c6380cb68bfbafe7;hpb=d41ef90610aadb5aa3372d5922155e4fc4e0a407 diff --git a/src/main/java/org/onap/schema/RelationshipSchemaLoader.java b/src/main/java/org/onap/schema/RelationshipSchemaLoader.java index 761f6ad..0e10fc3 100644 --- a/src/main/java/org/onap/schema/RelationshipSchemaLoader.java +++ b/src/main/java/org/onap/schema/RelationshipSchemaLoader.java @@ -29,8 +29,10 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.Date; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.SortedSet; import java.util.Timer; import java.util.TimerTask; @@ -48,6 +50,7 @@ import org.onap.crud.exception.CrudException; import org.onap.crud.logging.CrudServiceMsgs; import org.onap.crud.util.CrudServiceConstants; import org.onap.crud.util.FileWatcher; +import org.springframework.core.io.Resource; import org.springframework.core.io.UrlResource; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.ResourcePatternResolver; @@ -71,7 +74,7 @@ public class RelationshipSchemaLoader { } public synchronized static void loadModels(String version) throws CrudException { - String pattern = String.format(".*(%s)" + fileExt, version); + String pattern = String.format("DbEdgeRules.*(%s)" + fileExt, version); load(Pattern.compile(pattern), Pattern.compile(edgePropsFiles + version + fileExt)); } @@ -111,20 +114,31 @@ public class RelationshipSchemaLoader { private static void load(Pattern rulesPattern, Pattern edgePropsPattern) throws CrudException { ClassLoader cl = RelationshipSchemaLoader.class.getClassLoader(); ResourcePatternResolver rulesResolver = new PathMatchingResourcePatternResolver(cl); - List rulesFiles; + List rulesFiles = new ArrayList(); + Set existingFiles = new HashSet(); String rulesDir = CrudServiceConstants.CRD_HOME_MODEL; try { - // getResources method returns objects of type "Resource" - // 1. We are getting all the objects from the classpath which has - // "DbEdgeRules" in the name. - // 2. We run them through a filter and return only the objects which match - // the supplied pattern "p" - // 3. We then collect the objects in a list. At this point we have a list - // of the kind of files we require. - rulesFiles = Arrays.stream(rulesResolver.getResources("classpath*:/dbedgerules/DbEdgeRules*" + fileExt)) - .filter(r -> !myMatcher(rulesPattern, r.getFilename()).isEmpty()).collect(Collectors.toList()); - + // Allow additional DBEdgeRule files to be dropped in manually (in addition to those found on the classpath) + File[] edgeRuleFileList = new File(rulesDir).listFiles((d, name) -> rulesPattern.matcher(name).matches()); + for (File file : edgeRuleFileList) { + rulesFiles.add(file); + existingFiles.add(filename(file)); + } + + // Get DBEdgeRules from the jar on the classpath. Don't include any that conflict with files which + // were dropped manually. + Resource[] rawResourceList = rulesResolver.getResources("classpath*:/dbedgerules/DbEdgeRules*" + fileExt); + List prunedResourceList = new ArrayList(); + for (Resource resource : rawResourceList) { + if (!existingFiles.contains(filename(resource))) { + prunedResourceList.add(resource); + } + } + + rulesFiles.addAll(Arrays.stream(prunedResourceList.toArray(new Resource[prunedResourceList.size()])) + .filter(r -> !myMatcher(rulesPattern, r.getFilename()).isEmpty()).collect(Collectors.toList())); + // This gets all the objects of type "File" from external directory (not // on the classpath) // 1. From an external directory (one not on the classpath) we get all the @@ -135,7 +149,7 @@ public class RelationshipSchemaLoader { // this list // to the previous collection (rulesFiles) rulesFiles - .addAll(Arrays.stream(new File(rulesDir).listFiles((d, name) -> edgePropsPattern.matcher(name).matches())) + .addAll(Arrays.stream(new File(rulesDir).listFiles( (d, name) -> edgePropsPattern.matcher(name).matches() )) .collect(Collectors.toList())); if (rulesFiles.isEmpty()) {