/** * This is the main method of this class. It's easy to generate a Resource object, and then the * Resource can be used to generate the EMEntity * * @return */ public EMEntity toEMEntity(FieldTypeChecker fieldTypeChecker) { EMEntity entity = null; /* * If this is an enqlist, use the application name as it could be sometimes "-LIST" and sometimes not. */ if (this.type == RESOURCE_TYPE.enqlist) { entity = new EMEntity(type + EMUtils.camelCaseName(this.underlyingApplicationName)); } else { entity = new EMEntity(type + EMUtils.camelCaseName(t24name)); } entity.setT24Name(t24name); for (ResourceField field : fields) { List<EMProperty> properties = entity.getProperties(); // Create the property EMProperty property = new EMProperty(field.getIrisName()); property.setT24Name(field.getT24name()); if (field.isMandatory()) { property.addVocabularyTerm(new EMTerm(EMTermType.REQ_TERM, "true")); } if (field.isPrimaryKey()) { property.addVocabularyTerm(new EMTerm(EMTermType.ID_TERM, "true")); } // Value types are unreliable - only add to the model if it is flagged as safe in the // fieldTypeChecker if (!field.getValueType().isEmpty() && fieldTypeChecker.isTypeSafe(this.underlyingApplicationName, field.getT24name())) { property.addVocabularyTerm(new EMTerm(EMTermType.TYPE_TERM, field.getValueType())); } if (!field.getBusinessType().isEmpty()) { property.addVocabularyTerm( new EMTerm(EMTermType.BUSINESS_TYPE_TERM, field.getBusinessType())); } // Handle the selection field flags. if (field.isSelectionOnly()) { property.addVocabularyTerm(new EMTerm(EMTermType.FIELD_RESTRICTION_TERM, "filterOnly")); property.setSelectionInfo("selectionOnly: true"); } else if (field.getSelectionField().isEmpty()) { property.addVocabularyTerm(new EMTerm(EMTermType.FIELD_RESTRICTION_TERM, "displayOnly")); property.setSelectionInfo("selectable: false"); } else if (field.getSelectionField().equals(field.getT24name())) { // Doesn't need FIELD_RESTRICTION because is both displayable and filterable. property.setSelectionInfo(""); // Display nothing, since the values are the same } else { // Doesn't need FIELD_RESTRICTION because is both displayable and filterable. property.setSelectionInfo("selectionField: " + field.getSelectionField()); } // handle the 'joinedTo' field if (!field.getJoinedTo().isEmpty()) { property.setJoinedto("joinedTo: " + field.getJoinedTo()); } // handle the 'propertyGroup' field if (!field.getPropertyGroup().isEmpty()) { property.setPropertyGroup("propertyGroup: " + field.getPropertyGroup()); } // Now add the property to the right part of the entity, may need to create parent properties String mvGroupName = field.getMvGroup(); if (!mvGroupName.isEmpty()) { String mvgn = EMUtils.camelCaseName(mvGroupName) + GeneratorConstants.MVGROUP_SUFFIX; EMProperty mvGroup = EMUtils.getPropertyByName(properties, mvgn); if (mvGroup == null) { mvGroup = new EMProperty(mvgn); mvGroup.addVocabularyTerm(new EMTerm(EMTermType.LIST_TERM, "true")); if (RESOURCE_TYPE.version.equals(type)) { IRISMetadataGeneratorCommon.addOriginalMvSvPropertiesInGroup(mvGroup); } properties.add(mvGroup); properties = mvGroup.getSubProperties(); } else { properties = mvGroup.getSubProperties(); } if (field.isLanguageField() && field.getSvGroup().isEmpty()) { mvGroup.addVocabularyTerm(new EMTerm(EMTermType.TERM_LANG_TYPE, "true")); EMProperty languageCodeProperty = new EMProperty("LanguageCode"); properties.add(languageCodeProperty); } } String svGroupName = field.getSvGroup(); if (!svGroupName.isEmpty()) { String svgn = EMUtils.camelCaseName(svGroupName) + GeneratorConstants.SVGROUP_SUFFIX; EMProperty svGroup = EMUtils.getPropertyByName(properties, svgn); if (svGroup == null) { svGroup = new EMProperty(svgn); svGroup.addVocabularyTerm(new EMTerm(EMTermType.LIST_TERM, "true")); if (RESOURCE_TYPE.version.equals(type)) { IRISMetadataGeneratorCommon.addOriginalMvSvPropertiesInGroup(svGroup); } properties.add(svGroup); properties = svGroup.getSubProperties(); } else { properties = svGroup.getSubProperties(); } if (field.isLanguageField()) { svGroup.addVocabularyTerm(new EMTerm(EMTermType.TERM_LANG_TYPE, "true")); EMProperty languageCodeProperty = new EMProperty("LanguageCode"); properties.add(languageCodeProperty); } } properties.add(property); } return entity; }