/** * Method to prepare Complex type representation. * * @param writer * @param entityMetadata * @param propertyName * @param propertiesList * @param modelName */ private void writePropertyComplexList( StreamWriter writer, EntityMetadata entityMetadata, EntityProperty property, String modelName) { @SuppressWarnings("unchecked") List<EntityProperties> propertiesList = (List<EntityProperties>) property.getValue(); String name = entityMetadata.getEntityName() + "_" + property.getName(); int parseCount = 0; for (EntityProperties properties : propertiesList) { String fqTypeName = modelName + Metadata.MODEL_SUFFIX + "." + name; // We should be able to differentiate List<ComplexType> with regular ComplexType if (entityMetadata.isPropertyList(property.getFullyQualifiedName())) { if (parseCount == 0) { writer.startElement(new QName(d, name, "d")); writer.writeAttribute(new QName(m, "type", "m"), "Bag(" + fqTypeName + ")"); writer.startElement(new QName(d, "element", "d")); parseCount++; } else { writer.startElement(new QName(d, "element", "d")); } } else { writer.startElement(new QName(d, name, "d")); writer.writeAttribute(new QName(m, "type", "m"), fqTypeName); } writeProperties(writer, entityMetadata, properties, modelName); writer.endElement(); } // For List<ComplexTypes> we should end the complex node here if (!propertiesList.isEmpty() && entityMetadata.isPropertyList(property.getFullyQualifiedName())) { writer.endElement(); } }
/* * Create a EntityModel object from a Metadata container */ private EntityModel createEntityModelFromMetadata(String modelName, Metadata metadata) { // Create the entity model EntityModel entityModel = new EntityModel(modelName); for (EntityMetadata entityMetadata : metadata.getEntitiesMetadata().values()) { EMEntity emEntity = new EMEntity(entityMetadata.getEntityName()); for (String fyllyQualifiedPropertyName : entityMetadata.getPropertyVocabularyKeySet()) { addProperties(entityMetadata, emEntity, fyllyQualifiedPropertyName); } entityModel.addEntity(emEntity); } return entityModel; }
public EntityInfo createEntityInfoFromEntityMetadata( String namespace, EntityMetadata entityMetadata) { FieldInfo keyInfo = null; List<FieldInfo> properties = new ArrayList<FieldInfo>(); for (String propertyName : entityMetadata.getPropertyVocabularyKeySet()) { String type = entityMetadata.getTermValue(propertyName, TermValueType.TERM_NAME); if (entityMetadata.getTermValue(propertyName, TermIdField.TERM_NAME).equals("true")) { keyInfo = new FieldInfo(propertyName, javaType(MetadataOData4j.termValueToEdmType(type)), null); } else { List<String> annotations = new ArrayList<String>(); if (type.equals(TermValueType.TIMESTAMP)) { annotations.add("@Temporal(TemporalType.TIMESTAMP)"); } else if (type.equals(TermValueType.DATE)) { annotations.add("@Temporal(TemporalType.DATE)"); } else if (type.equals(TermValueType.TIME)) { annotations.add("@Temporal(TemporalType.TIME)"); } FieldInfo field = new FieldInfo( propertyName, javaType(MetadataOData4j.termValueToEdmType(type)), annotations); properties.add(field); } } // Check if user has specified the name of the JPA entities String jpaNamespace = System.getProperty("jpaNamespace"); boolean isJpaEntity = (jpaNamespace == null || jpaNamespace.equals(namespace)); return new EntityInfo( entityMetadata.getEntityName(), namespace, keyInfo, properties, new ArrayList<JoinInfo>(), isJpaEntity); }