/* * Create a property with vocabulary term from the Edmx property */ public static EMProperty createEMProperty(EdmProperty property) { EMProperty emProperty = new EMProperty(property.getName()); if (property.isNullable()) { emProperty.addVocabularyTerm(new EMTerm(TermMandatory.TERM_NAME, "true")); } // Set the value type vocabulary term EdmType type = property.getType(); if (type.equals(EdmSimpleType.DATETIME)) { emProperty.addVocabularyTerm(new EMTerm(TermValueType.TERM_NAME, TermValueType.TIMESTAMP)); } else if (type.equals(EdmSimpleType.TIME)) { emProperty.addVocabularyTerm(new EMTerm(TermValueType.TERM_NAME, TermValueType.TIME)); } else if (type.equals(EdmSimpleType.INT64) || type.equals(EdmSimpleType.INT32) || type.equals(EdmSimpleType.INT16)) { emProperty.addVocabularyTerm( new EMTerm(TermValueType.TERM_NAME, TermValueType.INTEGER_NUMBER)); } else if (type.equals(EdmSimpleType.SINGLE) || type.equals(EdmSimpleType.DOUBLE) || type.equals(EdmSimpleType.DECIMAL)) { emProperty.addVocabularyTerm(new EMTerm(TermValueType.TERM_NAME, TermValueType.NUMBER)); } else if (type.equals(EdmSimpleType.BOOLEAN)) { emProperty.addVocabularyTerm(new EMTerm(TermValueType.TERM_NAME, TermValueType.BOOLEAN)); } return emProperty; }
// adds the property tree to the entity metadata private void addProperties( EntityMetadata entityMetadata, EMEntity entity, String fyllyQualifiedPropertyName) { List<String> propertyNames = new ArrayList<String>(Arrays.asList(fyllyQualifiedPropertyName.split("\\."))); String rootPropertyName = propertyNames.get(0); EMProperty rootProperty = null; if (entity.contains(rootPropertyName)) { // this property already added to the entity rootProperty = entity.getProperty(rootPropertyName); } else { // new property so create and add to the entity rootProperty = new EMProperty(rootPropertyName); entity.addProperty(rootProperty); Vocabulary vocabulary = entityMetadata.getPropertyVocabulary(rootPropertyName); for (Term term : vocabulary.getTerms()) { rootProperty.addVocabularyTerm(new EMTerm(term.getName(), term.getValue())); } } propertyNames.remove(0); // removes root property as it's already added to the entity addChildProperties(entityMetadata, rootProperty, propertyNames); }
// adds the child properties to the top most property private void addChildProperties( EntityMetadata entityMetadata, EMProperty parentProperty, List<String> childPropertyNames) { String fullyQualifiedPropertyName = parentProperty.getName(); for (String childPropertyName : childPropertyNames) { fullyQualifiedPropertyName = fullyQualifiedPropertyName + "." + childPropertyName; EMProperty childProperty = null; if (parentProperty.hasChildProperty(childPropertyName)) { // this property already added to the parent property childProperty = parentProperty.getChildProperty(childPropertyName); } else { // this is a new child property so create and add to the parent property childProperty = new EMProperty(childPropertyName); parentProperty.addChildProperty(childProperty); Vocabulary propertyVocabulary = entityMetadata.getPropertyVocabulary(fullyQualifiedPropertyName); for (Term vocTerm : propertyVocabulary.getTerms()) { if (TermComplexGroup.TERM_NAME.equals(vocTerm.getName())) { // complex group term not added as the properties are built in tree structure continue; } childProperty.addVocabularyTerm(new EMTerm(vocTerm.getName(), vocTerm.getValue())); } } parentProperty = childProperty; } }
/** * Generate project artefacts from conceptual interaction and metadata models. * * @param metadata metadata model * @param interactionModel Conceptual interaction model * @param commands Commands * @param srcOutputPath Path to output directory * @param configOutputPath Path to configuration files directory * @param generateMockResponder Indicates whether to generate artifacts for a mock responder * @return true if successful, false otherwise */ public boolean generateArtifacts( Metadata metadata, InteractionModel interactionModel, Commands commands, File srcOutputPath, File configOutputPath, boolean generateMockResponder) { // Create the entity model String modelName = metadata.getModelName(); EntityModel entityModel = createEntityModelFromMetadata(modelName, metadata); // Add error entities for (IMState state : interactionModel.getErrorHandlerStates()) { EMEntity emEntity = new EMEntity(state.getName()); EMProperty empErrorMvGroup = new EMProperty("ErrorsMvGroup"); empErrorMvGroup.addVocabularyTerm(new EMTerm(TermIdField.TERM_NAME, "true")); empErrorMvGroup.addVocabularyTerm(new EMTerm(TermListType.TERM_NAME, "true")); empErrorMvGroup.addVocabularyTerm(new EMTerm(TermComplexType.TERM_NAME, "true")); emEntity.addProperty(empErrorMvGroup); EMProperty empCode = new EMProperty("Code"); empCode.addVocabularyTerm(new EMTerm(TermComplexGroup.TERM_NAME, "ErrorsMvGroup")); emEntity.addProperty(empCode); EMProperty empInfo = new EMProperty("Info"); empInfo.addVocabularyTerm(new EMTerm(TermComplexGroup.TERM_NAME, "ErrorsMvGroup")); emEntity.addProperty(empInfo); EMProperty empText = new EMProperty("Text"); empText.addVocabularyTerm(new EMTerm(TermComplexGroup.TERM_NAME, "ErrorsMvGroup")); emEntity.addProperty(empText); EMProperty empType = new EMProperty("Type"); empType.addVocabularyTerm(new EMTerm(TermComplexGroup.TERM_NAME, "ErrorsMvGroup")); emEntity.addProperty(empType); entityModel.addEntity(emEntity); } // Obtain resource information String namespace = modelName + Metadata.MODEL_SUFFIX; List<EntityInfo> entitiesInfo = new ArrayList<EntityInfo>(); for (EntityMetadata entityMetadata : metadata.getEntitiesMetadata().values()) { EntityInfo entityInfo = createEntityInfoFromEntityMetadata(namespace, entityMetadata); addNavPropertiesToEntityInfo(entityInfo, interactionModel); entitiesInfo.add(entityInfo); } return generateArtifacts( entityModel, interactionModel, commands, entitiesInfo, srcOutputPath, configOutputPath, generateMockResponder); }