/** * 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); }
// 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); }