[OLINGO-1430]Enhance metadata serializer to include OnDelete child element for a navigation Property

This commit is contained in:
ramya vasanth 2020-02-20 10:47:40 +05:30
parent 5b790f82c7
commit acb5e5e74c
6 changed files with 100 additions and 1 deletions

View File

@ -57,5 +57,7 @@ public interface EdmNavigationProperty extends EdmElement, EdmAnnotatable {
* @return all referential constraints for this navigation property.
*/
List<EdmReferentialConstraint> getReferentialConstraints();
EdmOnDelete getOnDelete();
}

View File

@ -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();
}

View File

@ -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;
}
}

View File

@ -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();
}
}

View File

@ -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);

View File

@ -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;
}