Example #1
0
 public ResourceField getFieldByIrisName(String irisName) {
   for (ResourceField field : fields) {
     if (field.getIrisName().equals(irisName)) {
       return field;
     }
   }
   return null;
 }
Example #2
0
 public ResourceField getFieldByT24Name(String t24name) {
   for (ResourceField field : fields) {
     if (field.getT24name().equals(t24name)) {
       return field;
     }
   }
   return null;
 }
Example #3
0
 public boolean hasPrimaryKey() {
   for (ResourceField field : fields) {
     if (field.isPrimaryKey()) {
       return true;
     }
   }
   return false;
 }
Example #4
0
 private void addField(ResourceField newField) {
   if (fields.contains(newField)) {
     // Already there, we need to merge certain values.
     // If the field is marked as selectionOnly, but a resultField with same name, we can change it
     // to selectable
     ResourceField existingField = this.getFieldByIrisName(newField.getIrisName());
     if (!newField.getSelectionField().isEmpty()) {
       existingField.setSelectionField(newField.getSelectionField());
     }
     // If the data type of the new field differs from the existing one, set it to String to be the
     // most open type possible.
     if (!newField.getValueType().equals(existingField.getValueType())) {
       existingField.setValueType(GeneratorConstants.T24_TYPE_STRING);
     }
     // If the new field is the primary key, mark the existing field as the primary key
     if (!existingField.isPrimaryKey() && newField.isPrimaryKey()) {
       existingField.setPrimaryKey(true);
     }
   } else {
     // Not there yet, so add it.
     fields.add(newField);
   }
 }
Example #5
0
  /**
   * 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;
  }
Example #6
0
 /**
  * Returns true if the specified field is optional.
  *
  * @param field to check
  * @return true if optional
  */
 public static boolean isOptionalField(@NotNull Field field) {
   ResourceField rf = field.getAnnotation(ResourceField.class);
   ListField lf = field.getAnnotation(ListField.class);
   PrimaryKey pk = field.getAnnotation(PrimaryKey.class);
   return (rf != null && rf.value()) || (lf != null && lf.optional()) || (pk != null);
 }