Skip to content

Commit

Permalink
support reverse revision sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
lllyfeng committed Aug 23, 2024
1 parent a0469a3 commit f3d7d2d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public static ValidatorResult buildChildData(YangDataContainer yangDataContainer
recordBuilder.setErrorPath(JsonCodecUtil.getJsonPath(child));
recordBuilder.setBadElement(child);
recordBuilder.setErrorMessage(new ErrorMessage(
"bad element:" + child.toString()));
"bad element:" +childSchemaNode.getJsonIdentifier()));
validatorResultBuilder.addRecord(recordBuilder.build());
}
return validatorResultBuilder.build();
Expand Down Expand Up @@ -385,7 +385,7 @@ public static ValidatorResult buildChildrenData(YangDataContainer yangDataContai
recordBuilder.setErrorPath(JsonCodecUtil.getJsonPath(child));
recordBuilder.setBadElement(child);
recordBuilder.setErrorMessage(new ErrorMessage(
"unrecognized element:" + child.toString()));
"unrecognized element:" + fieldName));
validatorResultBuilder.addRecord(recordBuilder.build());
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public enum ErrorCode {
PROPERTY_NOT_EXIST("property:${name} not exists."),
PROPERTY_NOT_MATCH("property:${name} not match."),
RANGE_OR_LENGTH_NOT_SUBSET_OF_DERIVED("range or length is not subset of derived type or builtin-type's range."),

REVISION_SEQ_ERROR(Severity.WARNING,"the sequence of revision is error, the revision date:${curDate} is newer " +
"than last revision:${lastDate}"),
REFERENCE_NODE_NOT_FOUND("can not find the reference node "),
SECTIONS_MUST_ASCEND_ORDER("sections in range or length MUST be ascend order"),
TARGET_CAN_NOT_AUGMENTED("the target node can not be augmented."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@
import org.yangcentral.yangkit.model.impl.schema.SchemaPathImpl;
import org.yangcentral.yangkit.util.ModelUtil;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -128,12 +123,16 @@ public List<Revision> getRevisions() {
}

public Optional<Revision> getCurRevision() {
return this.revisions.size() == 0 ? Optional.empty() : Optional.of(this.revisions.get(0));
if(this.revisions.isEmpty()){
return Optional.empty();
}
Collections.sort(this.revisions, (o1, o2) -> o2.getArgStr().compareTo(o1.getArgStr()));
return Optional.of(this.revisions.get(0));
}

public Optional<String> getCurRevisionDate() {
Optional<Revision> revisionOptional = this.getCurRevision();
return !revisionOptional.isPresent() ? Optional.empty() : Optional.of(revisionOptional.get().getArgStr());
Optional<Revision> revision = getCurRevision();
return revision.isPresent()?Optional.of(revision.get().getArgStr()):Optional.empty();
}

public List<Extension> getExtensions() {
Expand Down Expand Up @@ -183,7 +182,12 @@ public Map<String, ModuleId> getPrefixes() {

public ModuleId getModuleId() {
List<YangStatement> revisions = this.getSubStatement(YangBuiltinKeyword.REVISION.getQName());
return revisions.isEmpty() ? new ModuleId(this.getArgStr(), "") : new ModuleId(this.getArgStr(), revisions.get(0).getArgStr());
if(revisions.isEmpty()){
return new ModuleId(this.getArgStr(), "");
}

Collections.sort(revisions,((o1, o2) -> o2.getArgStr().compareTo(o1.getArgStr())));
return new ModuleId(this.getArgStr(), revisions.get(0).getArgStr());
}

public Optional<ModuleId> findModuleByPrefix(String prefix) {
Expand Down Expand Up @@ -828,6 +832,20 @@ protected ValidatorResult initSelf() {
if (null != revision) {
validatorResultBuilder.addRecord(ModelUtil.reportDuplicateError(revision, newRevision, Severity.WARNING));
} else {
if(!revisions.isEmpty()){
int size = revisions.size();
if(revisions.get(size-1).getArgStr().compareTo(newRevision.getArgStr()) < 0){
ValidatorRecordBuilder<Position, YangStatement> validatorRecordBuilder = new ValidatorRecordBuilder<>();
validatorRecordBuilder.setBadElement(newRevision);
validatorRecordBuilder.setSeverity(Severity.WARNING);
validatorRecordBuilder.setErrorTag(ErrorTag.BAD_ELEMENT);
validatorRecordBuilder.setErrorPath(newRevision.getElementPosition());
validatorRecordBuilder.setErrorMessage(new ErrorMessage(ErrorCode.REVISION_SEQ_ERROR.toString(
new String[]{"curDate="+ newRevision.getArgStr(),"lastDate="+revisions.get(size-1).getArgStr()}
)));
validatorResultBuilder.addRecord(validatorRecordBuilder.build());
}
}
this.revisions.add(newRevision);
}
break;
Expand Down

0 comments on commit f3d7d2d

Please sign in to comment.