This is an automated email from the ASF dual-hosted git repository.
ramyav pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/olingo-odata4.git
The following commit(s) were added to refs/heads/master by this push:
new acb5e5e [OLINGO-1430]Enhance metadata serializer to include OnDelete
child element for a navigation Property
acb5e5e is described below
commit acb5e5e74c4ab3a942523786394e087defa9b779
Author: ramya vasanth <[email protected]>
AuthorDate: Thu Feb 20 10:47:40 2020 +0530
[OLINGO-1430]Enhance metadata serializer to include OnDelete child element
for a navigation Property
---
.../commons/api/edm/EdmNavigationProperty.java | 2 ++
.../apache/olingo/commons/api/edm/EdmOnDelete.java | 24 +++++++++++++
.../core/edm/EdmNavigationPropertyImpl.java | 8 +++++
.../olingo/commons/core/edm/EdmOnDeleteImpl.java | 39 ++++++++++++++++++++++
.../xml/MetadataDocumentXmlSerializer.java | 9 +++++
.../xml/MetadataDocumentXmlSerializerTest.java | 19 ++++++++++-
6 files changed, 100 insertions(+), 1 deletion(-)
diff --git
a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmNavigationProperty.java
b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmNavigationProperty.java
index 593f985..39e5f51 100644
---
a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmNavigationProperty.java
+++
b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmNavigationProperty.java
@@ -57,5 +57,7 @@ public interface EdmNavigationProperty extends EdmElement,
EdmAnnotatable {
* @return all referential constraints for this navigation property.
*/
List<EdmReferentialConstraint> getReferentialConstraints();
+
+ EdmOnDelete getOnDelete();
}
diff --git
a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmOnDelete.java
b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmOnDelete.java
new file mode 100644
index 0000000..a85f361
--- /dev/null
+++
b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmOnDelete.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.commons.api.edm;
+
+public interface EdmOnDelete extends EdmAnnotatable {
+
+ String getAction();
+}
diff --git
a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmNavigationPropertyImpl.java
b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmNavigationPropertyImpl.java
index a0ee76b..6bb856c 100644
---
a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmNavigationPropertyImpl.java
+++
b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmNavigationPropertyImpl.java
@@ -26,9 +26,11 @@ import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmEntityType;
import org.apache.olingo.commons.api.edm.EdmException;
import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
+import org.apache.olingo.commons.api.edm.EdmOnDelete;
import org.apache.olingo.commons.api.edm.EdmReferentialConstraint;
import org.apache.olingo.commons.api.edm.EdmStructuredType;
import org.apache.olingo.commons.api.edm.provider.CsdlNavigationProperty;
+import org.apache.olingo.commons.api.edm.provider.CsdlOnDelete;
import org.apache.olingo.commons.api.edm.provider.CsdlReferentialConstraint;
public class EdmNavigationPropertyImpl extends AbstractEdmNamed implements
EdmNavigationProperty {
@@ -119,4 +121,10 @@ public class EdmNavigationPropertyImpl extends
AbstractEdmNamed implements EdmNa
}
return referentialConstraints;
}
+
+ @Override
+ public EdmOnDelete getOnDelete() {
+ CsdlOnDelete csdlOnDelete = navigationProperty.getOnDelete();
+ return csdlOnDelete != null ? new EdmOnDeleteImpl(edm, csdlOnDelete) :
null;
+ }
}
diff --git
a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmOnDeleteImpl.java
b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmOnDeleteImpl.java
new file mode 100644
index 0000000..098b906
--- /dev/null
+++
b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmOnDeleteImpl.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.commons.core.edm;
+
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmOnDelete;
+import org.apache.olingo.commons.api.edm.provider.CsdlOnDelete;
+
+public class EdmOnDeleteImpl extends AbstractEdmAnnotatable implements
EdmOnDelete {
+
+ private final CsdlOnDelete csdlOnDelete;
+
+ public EdmOnDeleteImpl(final Edm edm, final CsdlOnDelete csdlOnDelete) {
+ super(edm, csdlOnDelete);
+ this.csdlOnDelete = csdlOnDelete;
+ }
+
+ @Override
+ public String getAction() {
+ return csdlOnDelete.getAction().name();
+ }
+
+}
diff --git
a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java
b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java
index 5411d90..626ca7e 100644
---
a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java
+++
b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java
@@ -154,6 +154,8 @@ public class MetadataDocumentXmlSerializer {
private static final String XML_PROPERTY_VALUE = "PropertyValue";
private static final String XML_BASE_TERM = "BaseTerm";
private static final String XML_APPLIES_TO = "AppliesTo";
+ private static final String XML_ON_DELETE = "OnDelete";
+ private static final String XML_ON_DELETE_PROPERTY = "Action";
private final ServiceMetadata serviceMetadata;
private final Map<String, String> namespaceToAlias = new HashMap<>();
@@ -876,6 +878,13 @@ public class MetadataDocumentXmlSerializer {
writer.writeEndElement();
}
}
+
+ if (navigationProperty.getOnDelete() != null) {
+ writer.writeStartElement(XML_ON_DELETE);
+ writer.writeAttribute(XML_ON_DELETE_PROPERTY,
navigationProperty.getOnDelete().getAction());
+ appendAnnotations(writer, navigationProperty.getOnDelete());
+ writer.writeEndElement();
+ }
appendAnnotations(writer, navigationProperty);
diff --git
a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java
b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java
index 8b7e2ce..c5017a8 100644
---
a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java
+++
b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java
@@ -60,6 +60,9 @@ import
org.apache.olingo.commons.api.edm.provider.CsdlEnumMember;
import org.apache.olingo.commons.api.edm.provider.CsdlEnumType;
import org.apache.olingo.commons.api.edm.provider.CsdlFunction;
import org.apache.olingo.commons.api.edm.provider.CsdlFunctionImport;
+import org.apache.olingo.commons.api.edm.provider.CsdlNavigationProperty;
+import org.apache.olingo.commons.api.edm.provider.CsdlOnDelete;
+import org.apache.olingo.commons.api.edm.provider.CsdlOnDeleteAction;
import org.apache.olingo.commons.api.edm.provider.CsdlParameter;
import org.apache.olingo.commons.api.edm.provider.CsdlProperty;
import org.apache.olingo.commons.api.edm.provider.CsdlPropertyRef;
@@ -324,6 +327,9 @@ public class MetadataDocumentXmlSerializerTest {
+ "EntitySet=\"ESAllPrim\"></ActionImport>"));
assertTrue(metadata.contains("<ActionImport Name=\"AIRTEntityNoES\"
Action=\"Alias.UARTEntity\">"
+ "</ActionImport>"));
+ assertTrue(metadata.contains("<NavigationProperty Name=\"NavProperty\" "
+ + "Type=\"Alias.ETAbstract\" Nullable=\"false\"><OnDelete
Action=\"Cascade\">"
+ + "<Annotation
Term=\"core.Term\"></Annotation></OnDelete></NavigationProperty>"));
}
@Test
@@ -499,6 +505,13 @@ public class MetadataDocumentXmlSerializerTest {
private final CsdlProperty propertyString = new CsdlProperty()
.setName("PropertyString")
.setType(nameString);
+
+ private final CsdlNavigationProperty navProperty = new
CsdlNavigationProperty()
+ .setName("NavProperty")
+ .setType(nameETAbstract)
+ .setNullable(false)
+ .setOnDelete(new CsdlOnDelete().setAction(CsdlOnDeleteAction.Cascade)
+ .setAnnotations(Arrays.asList(new
CsdlAnnotation().setTerm("core.Term"))));
private final FullQualifiedName nameCTTwoPrim = new
FullQualifiedName(nameSpace, "CTTwoPrim");
private final FullQualifiedName nameCTTwoPrimBase = new
FullQualifiedName(nameSpace, "CTTwoPrimBase");
@@ -543,7 +556,8 @@ public class MetadataDocumentXmlSerializerTest {
return new CsdlEntityType()
.setName("ET")
.setKey(Collections.singletonList(new
CsdlPropertyRef().setName("PropertyInt16")))
- .setProperties(Collections.singletonList(propertyInt16_NotNullable));
+ .setProperties(Collections.singletonList(propertyInt16_NotNullable))
+ .setNavigationProperties(Collections.singletonList(navProperty));
}
return null;
}
@@ -809,6 +823,9 @@ public class MetadataDocumentXmlSerializerTest {
} else if (new FullQualifiedName("ns", "Term4").equals(termName)) {
return new
CsdlTerm().setType("Edm.String").setName("Term4").setBaseTerm("namespace.Term1");
+ } else if (new FullQualifiedName("core", "Term").equals(termName)) {
+ return new
CsdlTerm().setType("Edm.String").setName("Term").setBaseTerm("core.Term");
+
}
return null;
}