/* * 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 Map<String, Object> complexTypeHandler(String propertyName, EntityMetadata em) { Map<String, Object> map = new HashMap<>(); // 1st level for (String property : em.getPropertyVocabularyKeySet()) { if (property.startsWith(propertyName) && !property.equals(propertyName)) { if (em.isPropertyList(property)) { // Complex Map<String, Object> subMap = complexTypeHandler(property, em); map.put(em.getSimplePropertyName(property), subMap); } else { // SIMPLE Pattern pattern = Pattern.compile("(?:" + propertyName + ")(?:\\.)(.*)"); Matcher matcher = pattern.matcher(property); while (matcher.find()) { String propertyCapture = matcher.group(1); if (em.getSimplePropertyName(property).equals(propertyCapture)) { ArrayList<String> obj = new ArrayList<String>(); if (em.isPropertyNumber(property)) { obj.add(0, "double"); } else if (em.isPropertyDate(property)) { obj.add(0, "date"); } else if (em.isPropertyBoolean(property)) { obj.add(0, "boolean"); } else { obj.add(0, "string"); } String description = em.getTermValue(property, "TERM_DESCRIPTION"); description = (null != description) ? description : ""; obj.add(1, description); map.put(em.getSimplePropertyName(property), obj); } } } } } return map; }
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); }