X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2FRestCodec.java;h=763d1c604e759f3b5cb4842eeccaabcf3d40051a;hb=e8ee8a8897013fb90376e21ccd9fc54a98a8c251;hp=611fb490907584d4e47bee30686b7244af049140;hpb=f8225a74b7c11db1ebf77ab9de998c2e953f8ed8;p=controller.git diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestCodec.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestCodec.java index 611fb49090..763d1c604e 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestCodec.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestCodec.java @@ -12,17 +12,17 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.opendaylight.controller.sal.core.api.mount.MountInstance; +import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint; import org.opendaylight.controller.sal.rest.impl.RestUtil; import org.opendaylight.controller.sal.restconf.impl.IdentityValuesDTO.IdentityValue; import org.opendaylight.controller.sal.restconf.impl.IdentityValuesDTO.Predicate; import org.opendaylight.yangtools.concepts.Codec; import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeIdentifier; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeIdentifierWithPredicates; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeWithValue; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.data.api.codec.IdentityrefCodec; import org.opendaylight.yangtools.yang.data.api.codec.InstanceIdentifierCodec; import org.opendaylight.yangtools.yang.data.api.codec.LeafrefCodec; @@ -47,7 +47,7 @@ public class RestCodec { } public static final Codec from(final TypeDefinition typeDefinition, - final MountInstance mountPoint) { + final DOMMountPoint mountPoint) { return new ObjectCodec(typeDefinition, mountPoint); } @@ -62,7 +62,7 @@ public class RestCodec { private final TypeDefinition type; - private ObjectCodec(final TypeDefinition typeDefinition, final MountInstance mountPoint) { + private ObjectCodec(final TypeDefinition typeDefinition, final DOMMountPoint mountPoint) { type = RestUtil.resolveBaseTypeFrom(typeDefinition); if (type instanceof IdentityrefTypeDefinition) { identityrefCodec = new IdentityrefCodecImpl(mountPoint); @@ -88,11 +88,6 @@ public class RestCodec { "Value is not instance of IdentityrefTypeDefinition but is {}. Therefore NULL is used as translation of - {}", input == null ? "null" : input.getClass(), String.valueOf(input)); return null; - } else if (type instanceof LeafrefTypeDefinition) { - if (input instanceof IdentityValuesDTO) { - return LEAFREF_DEFAULT_CODEC.deserialize(((IdentityValuesDTO) input).getOriginValue()); - } - return LEAFREF_DEFAULT_CODEC.deserialize(input); } else if (type instanceof InstanceIdentifierTypeDefinition) { if (input instanceof IdentityValuesDTO) { return instanceIdentifier.deserialize(input); @@ -102,7 +97,7 @@ public class RestCodec { input == null ? "null" : input.getClass(), String.valueOf(input)); return null; } else { - TypeDefinitionAwareCodec> typeAwarecodec = TypeDefinitionAwareCodec + final TypeDefinitionAwareCodec> typeAwarecodec = TypeDefinitionAwareCodec .from(type); if (typeAwarecodec != null) { if (input instanceof IdentityValuesDTO) { @@ -115,7 +110,7 @@ public class RestCodec { return null; } } - } catch (ClassCastException e) { // TODO remove this catch when everyone use codecs + } catch (final ClassCastException e) { // TODO remove this catch when everyone use codecs logger.error( "ClassCastException was thrown when codec is invoked with parameter " + String.valueOf(input), e); @@ -134,7 +129,7 @@ public class RestCodec { } else if (type instanceof InstanceIdentifierTypeDefinition) { return instanceIdentifier.serialize(input); } else { - TypeDefinitionAwareCodec> typeAwarecodec = TypeDefinitionAwareCodec + final TypeDefinitionAwareCodec> typeAwarecodec = TypeDefinitionAwareCodec .from(type); if (typeAwarecodec != null) { return typeAwarecodec.serialize(input); @@ -144,7 +139,7 @@ public class RestCodec { return null; } } - } catch (ClassCastException e) { // TODO remove this catch when everyone use codecs + } catch (final ClassCastException e) { // TODO remove this catch when everyone use codecs logger.error( "ClassCastException was thrown when codec is invoked with parameter " + String.valueOf(input), e); @@ -158,21 +153,21 @@ public class RestCodec { private final Logger logger = LoggerFactory.getLogger(IdentityrefCodecImpl.class); - private final MountInstance mountPoint; + private final DOMMountPoint mountPoint; - public IdentityrefCodecImpl(final MountInstance mountPoint) { + public IdentityrefCodecImpl(final DOMMountPoint mountPoint) { this.mountPoint = mountPoint; } @Override public IdentityValuesDTO serialize(final QName data) { - return new IdentityValuesDTO(data.getNamespace().toString(), data.getLocalName(), data.getPrefix(), null); + return new IdentityValuesDTO(data.getNamespace().toString(), data.getLocalName(), null, null); } @Override public QName deserialize(final IdentityValuesDTO data) { - IdentityValue valueWithNamespace = data.getValuesWithNamespaces().get(0); - Module module = getModuleByNamespace(valueWithNamespace.getNamespace(), mountPoint); + final IdentityValue valueWithNamespace = data.getValuesWithNamespaces().get(0); + final Module module = getModuleByNamespace(valueWithNamespace.getNamespace(), mountPoint); if (module == null) { logger.info("Module was not found for namespace {}", valueWithNamespace.getNamespace()); logger.info("Idenetityref will be translated as NULL for data - {}", String.valueOf(valueWithNamespace)); @@ -200,24 +195,24 @@ public class RestCodec { public static class InstanceIdentifierCodecImpl implements InstanceIdentifierCodec { private final Logger logger = LoggerFactory.getLogger(InstanceIdentifierCodecImpl.class); - private final MountInstance mountPoint; + private final DOMMountPoint mountPoint; - public InstanceIdentifierCodecImpl(final MountInstance mountPoint) { + public InstanceIdentifierCodecImpl(final DOMMountPoint mountPoint) { this.mountPoint = mountPoint; } @Override - public IdentityValuesDTO serialize(final InstanceIdentifier data) { - IdentityValuesDTO identityValuesDTO = new IdentityValuesDTO(); - for (PathArgument pathArgument : data.getPathArguments()) { - IdentityValue identityValue = qNameToIdentityValue(pathArgument.getNodeType()); + public IdentityValuesDTO serialize(final YangInstanceIdentifier data) { + final IdentityValuesDTO identityValuesDTO = new IdentityValuesDTO(); + for (final PathArgument pathArgument : data.getPathArguments()) { + final IdentityValue identityValue = qNameToIdentityValue(pathArgument.getNodeType()); if (pathArgument instanceof NodeIdentifierWithPredicates && identityValue != null) { - List predicates = keyValuesToPredicateList(((NodeIdentifierWithPredicates) pathArgument) + final List predicates = keyValuesToPredicateList(((NodeIdentifierWithPredicates) pathArgument) .getKeyValues()); identityValue.setPredicates(predicates); } else if (pathArgument instanceof NodeWithValue && identityValue != null) { - List predicates = new ArrayList<>(); - String value = String.valueOf(((NodeWithValue) pathArgument).getValue()); + final List predicates = new ArrayList<>(); + final String value = String.valueOf(((NodeWithValue) pathArgument).getValue()); predicates.add(new Predicate(null, value)); identityValue.setPredicates(predicates); } @@ -227,12 +222,12 @@ public class RestCodec { } @Override - public InstanceIdentifier deserialize(final IdentityValuesDTO data) { - List result = new ArrayList(); - IdentityValue valueWithNamespace = data.getValuesWithNamespaces().get(0); - Module module = getModuleByNamespace(valueWithNamespace.getNamespace(), mountPoint); + public YangInstanceIdentifier deserialize(final IdentityValuesDTO data) { + final List result = new ArrayList(); + final IdentityValue valueWithNamespace = data.getValuesWithNamespaces().get(0); + final Module module = getModuleByNamespace(valueWithNamespace.getNamespace(), mountPoint); if (module == null) { - logger.info("Module by namespace '{}' of first node in instance-identiefier was not found.", + logger.info("Module by namespace '{}' of first node in instance-identifier was not found.", valueWithNamespace.getNamespace()); logger.info("Instance-identifier will be translated as NULL for data - {}", String.valueOf(valueWithNamespace.getValue())); @@ -240,11 +235,11 @@ public class RestCodec { } DataNodeContainer parentContainer = module; - List identities = data.getValuesWithNamespaces(); + final List identities = data.getValuesWithNamespaces(); for (int i = 0; i < identities.size(); i++) { - IdentityValue identityValue = identities.get(i); + final IdentityValue identityValue = identities.get(i); URI validNamespace = resolveValidNamespace(identityValue.getNamespace(), mountPoint); - DataSchemaNode node = ControllerContext.getInstance().findInstanceDataChildByNameAndNamespace( + final DataSchemaNode node = ControllerContext.findInstanceDataChildByNameAndNamespace( parentContainer, identityValue.getValue(), validNamespace); if (node == null) { logger.info("'{}' node was not found in {}", identityValue, parentContainer.getChildNodes()); @@ -252,13 +247,13 @@ public class RestCodec { String.valueOf(identityValue.getValue())); return null; } - QName qName = node.getQName(); + final QName qName = node.getQName(); PathArgument pathArgument = null; if (identityValue.getPredicates().isEmpty()) { pathArgument = new NodeIdentifier(qName); } else { if (node instanceof LeafListSchemaNode) { // predicate is value of leaf-list entry - Predicate leafListPredicate = identityValue.getPredicates().get(0); + final Predicate leafListPredicate = identityValue.getPredicates().get(0); if (!leafListPredicate.isLeafList()) { logger.info("Predicate's data is not type of leaf-list. It should be in format \".='value'\""); logger.info("Instance-identifier will be translated as NULL for data - {}", @@ -267,11 +262,11 @@ public class RestCodec { } pathArgument = new NodeWithValue(qName, leafListPredicate.getValue()); } else if (node instanceof ListSchemaNode) { // predicates are keys of list - DataNodeContainer listNode = (DataNodeContainer) node; - Map predicatesMap = new HashMap<>(); - for (Predicate predicate : identityValue.getPredicates()) { + final DataNodeContainer listNode = (DataNodeContainer) node; + final Map predicatesMap = new HashMap<>(); + for (final Predicate predicate : identityValue.getPredicates()) { validNamespace = resolveValidNamespace(predicate.getName().getNamespace(), mountPoint); - DataSchemaNode listKey = ControllerContext.getInstance() + final DataSchemaNode listKey = ControllerContext .findInstanceDataChildByNameAndNamespace(listNode, predicate.getName().getValue(), validNamespace); predicatesMap.put(listKey.getQName(), predicate.getValue()); @@ -286,7 +281,7 @@ public class RestCodec { } result.add(pathArgument); if (i < identities.size() - 1) { // last element in instance-identifier can be other than - // DataNodeContainer + // DataNodeContainer if (node instanceof DataNodeContainer) { parentContainer = (DataNodeContainer) node; } else { @@ -298,13 +293,13 @@ public class RestCodec { } } - return result.isEmpty() ? null : InstanceIdentifier.create(result); + return result.isEmpty() ? null : YangInstanceIdentifier.create(result); } private List keyValuesToPredicateList(final Map keyValues) { - List result = new ArrayList<>(); - for (QName qName : keyValues.keySet()) { - Object value = keyValues.get(qName); + final List result = new ArrayList<>(); + for (final QName qName : keyValues.keySet()) { + final Object value = keyValues.get(qName); result.add(new Predicate(qNameToIdentityValue(qName), String.valueOf(value))); } return result; @@ -312,14 +307,14 @@ public class RestCodec { private IdentityValue qNameToIdentityValue(final QName qName) { if (qName != null) { - return new IdentityValue(qName.getNamespace().toString(), qName.getLocalName(), qName.getPrefix()); + return new IdentityValue(qName.getNamespace().toString(), qName.getLocalName()); } return null; } } - private static Module getModuleByNamespace(final String namespace, final MountInstance mountPoint) { - URI validNamespace = resolveValidNamespace(namespace, mountPoint); + private static Module getModuleByNamespace(final String namespace, final DOMMountPoint mountPoint) { + final URI validNamespace = resolveValidNamespace(namespace, mountPoint); Module module = null; if (mountPoint != null) { @@ -334,7 +329,7 @@ public class RestCodec { return module; } - private static URI resolveValidNamespace(final String namespace, final MountInstance mountPoint) { + private static URI resolveValidNamespace(final String namespace, final DOMMountPoint mountPoint) { URI validNamespace; if (mountPoint != null) { validNamespace = ControllerContext.getInstance().findNamespaceByModuleName(mountPoint, namespace);