...
- cps-ri/src/main/java/org/onap/cps/spi/entities/YangResourceEntity.java
Code Block language java theme RDarkMidnight title YangResourceEntity.java changes linenumbers true collapse true @NotNull @Column private String moduleName; @NotNull @Column private String revision;
...
Code Block | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
// need to add the following pattern in line 79 private static final Pattern RFC6020_RECOMMENDED_FILENAME_PATTERN = Pattern.compile("([\\w-]+)@(\\d{4}-\\d{2}-\\d{2})(?:\\.yang)?", Pattern.CASE_INSENSITIVE); // in the method synchronizeYangResources the following changes need to be added // after line 123 final Map<String,String> metaDataMap = getModuleNameAndRevision(entry.getKey(), entry.getValue()); // after line 127 yangResourceEntity.setModuleName(metaDataMap.get("moduleName")); yangResourceEntity.setRevision(metaDataMap.get("revision")); // at the end of the file add the following methods private static HashMap<String, String> getModuleNameAndRevision(final String sourceName, final String source) { final HashMap<String, String> metaDataMap = new HashMap<>(); final var revisionSourceIdentifier = createIdentifierFromSourceName(checkNotNull(sourceName)); YangTextSchemaSource tempYangTextSchemaSource = new YangTextSchemaSource(revisionSourceIdentifier) { @Override protected MoreObjects.ToStringHelper addToStringAttributes( final MoreObjects.ToStringHelper toStringHelper) { return toStringHelper; } @Override public InputStream openStream() { return new ByteArrayInputStream(source.getBytes(StandardCharsets.UTF_8)); } }; try { final var dependencyInfo = YangModelDependencyInfo.forYangText(tempYangTextSchemaSource); metaDataMap.put("moduleName", dependencyInfo.getName()); metaDataMap.put("revision", String.valueOf(dependencyInfo.getRevision())); } catch (IOException e) { e.printStackTrace(); } catch (YangSyntaxErrorException e) { e.printStackTrace(); } return metaDataMap; } private static RevisionSourceIdentifier createIdentifierFromSourceName(final String sourceName) { final var matcher = RFC6020_RECOMMENDED_FILENAME_PATTERN.matcher(sourceName); if (matcher.matches()) { return RevisionSourceIdentifier.create(matcher.group(1), Revision.of(matcher.group(2))); } return RevisionSourceIdentifier.create(sourceName); } |
...