String fromName = null;
String navPropName = null;
NavigationProperty navProp = navPropertyView.getEdmNavigationProperty();
String namespace = buildNamespace(associationView);
Association association = associationView.getEdmAssociation();
navProp.setRelationship(new FullQualifiedName(namespace, association
.getName()));
FullQualifiedName associationEndTypeOne = association.getEnd1()
.getType();
FullQualifiedName associationEndTypeTwo = association.getEnd2()
.getType();
Attribute<?, ?> jpaAttribute = propertyView.getJPAAttribute();
navProp.setMapping(new Mapping().setInternalName(jpaAttribute.getName()));
String jpaEntityTypeName = propertyView.getJPAEdmEntityTypeView()
.getJPAEntityType().getName();
JPAEdmMappingModelAccess mappingModelAccess = navPropertyView
.getJPAEdmMappingModelAccess();
String targetEntityTypeName = null;
if (jpaAttribute.isCollection()) {
targetEntityTypeName = ((PluralAttribute<?, ?, ?>) jpaAttribute).getElementType().getJavaType().getSimpleName();
} else {
targetEntityTypeName = jpaAttribute.getJavaType().getSimpleName();
}
if (mappingModelAccess != null
&& mappingModelAccess.isMappingModelExists()) {
navPropName = mappingModelAccess.mapJPARelationship(
jpaEntityTypeName, jpaAttribute.getName());
toName = mappingModelAccess.mapJPAEntityType(targetEntityTypeName);
fromName = mappingModelAccess
.mapJPAEntityType(jpaEntityTypeName);
}
if (toName == null) {
toName = targetEntityTypeName;
}
if (fromName == null) {
fromName = jpaEntityTypeName;
}
if (navPropName == null) {
navPropName = toName.concat(NAVIGATION_NAME);
}
if (count > 1) {
navPropName = navPropName + Integer.toString(count - 1);
}
navProp.setName(navPropName);
if (toName.equals(associationEndTypeOne.getName())) {
navProp.setFromRole(association.getEnd2().getRole());
navProp.setToRole(association.getEnd1().getRole());
} else if (toName.equals(associationEndTypeTwo.getName())) {
navProp.setToRole(association.getEnd2().getRole());
navProp.setFromRole(association.getEnd1().getRole());
}
}