@Test void parseSingleEntityType() { initMetaFactories(); Entity entity = mock(Entity.class); when(entity.getString(EMX_ENTITIES_NAME)).thenReturn("testType"); when(entity.getString(EMX_ENTITIES_PACKAGE)).thenReturn(""); when(entity.getString(EMX_ENTITIES_LABEL)).thenReturn("label"); when(entity.getString(EMX_ENTITIES_DESCRIPTION)).thenReturn("desc"); when(entity.getString(EMX_ENTITIES_ABSTRACT)).thenReturn("false"); when(entity.getString(EMX_ENTITIES_EXTENDS)).thenReturn("parentEntity"); when(entity.getString(EMX_ENTITIES_BACKEND)).thenReturn("paper"); when(entity.getString(EMX_ENTITIES_TAGS)).thenReturn("tag1,tag2"); EntityType entityType = createEmxAttributeRepositoryEntityType(); when(entityTypeFactory.create("testType")) .thenAnswer( invocation -> { when(entityType.setLabel("testType")).thenReturn(entityType); when(entityType.setPackage(null)).thenReturn(entityType); return entityType; }); Tag tag1 = mock(Tag.class); Tag tag2 = mock(Tag.class); EntityType parent = mock(EntityType.class); MetaDataService metaDataService = mock(MetaDataService.class); when(metaDataService.hasBackend("paper")).thenReturn(true); when(metaDataService.getEntityType("parentEntity")).thenReturn(Optional.of(parent)); when(dataService.getMeta()).thenReturn(metaDataService); IntermediateParseResults intermediateParseResults = new IntermediateParseResults(entityTypeFactory); intermediateParseResults.addTag("tag1", tag1); intermediateParseResults.addTag("tag2", tag2); emxMetadataParser.parseSingleEntityType(intermediateParseResults, 0, entity); verify(entityType).setLabel("label"); verify(entityType).setDescription("desc"); verify(entityType).setAbstract(false); verify(entityType).setExtends(parent); verify(entityType).setBackend("paper"); verify(entityType).setTags(Arrays.asList(tag1, tag2)); }
void parseSingleEntityType( IntermediateParseResults intermediateResults, int rowIndex, Entity entity) { String emxEntityName = entity.getString(EMX_ENTITIES_NAME); String emxEntityPackage = entity.getString(EMX_ENTITIES_PACKAGE); String emxEntityLabel = entity.getString(EMX_ENTITIES_LABEL); String emxEntityDescription = entity.getString(EMX_ENTITIES_DESCRIPTION); String emxEntityAbstract = entity.getString(EMX_ENTITIES_ABSTRACT); String emxEntityExtends = entity.getString(EMX_ENTITIES_EXTENDS); String emxEntityBackend = entity.getString(EMX_ENTITIES_BACKEND); String emxEntityTags = entity.getString(EMX_ENTITIES_TAGS); if (Strings.isNullOrEmpty(emxEntityName)) { throw new MissingEmxAttributeValueException("name", EMX_ENTITIES, rowIndex); } String entityTypeId; entityTypeId = toEntityTypeId(emxEntityName, emxEntityPackage); EntityType entityType = intermediateResults.getEntityType(entityTypeId); if (entityType == null) { entityType = intermediateResults.addEntityType(entityTypeId); } if (emxEntityBackend != null) { if (!dataService.getMeta().hasBackend(emxEntityBackend)) { throw new UnknownRepositoryCollectionException(emxEntityBackend); } } else { emxEntityBackend = dataService.getMeta().getDefaultBackend().getName(); } entityType.setBackend(emxEntityBackend); if (!Strings.isNullOrEmpty(emxEntityPackage)) { setPackage(intermediateResults, rowIndex, emxEntityPackage, entityType); } if (emxEntityLabel == null) { emxEntityLabel = emxEntityName; } entityType.setLabel(emxEntityLabel); entityType.setDescription(emxEntityDescription); for (String attributeName : entity.getAttributeNames()) { if (isI18n(attributeName)) { setI18nEntityTypeLabelAndDesc(entity, entityType, attributeName); } } if (emxEntityAbstract != null) { entityType.setAbstract(parseBoolean(emxEntityAbstract, rowIndex, EMX_ENTITIES_ABSTRACT)); } if (emxEntityExtends != null) { setEntityExtends(intermediateResults, emxEntityName, emxEntityExtends, entityType, rowIndex); } List<String> tagIdentifiers = toList(emxEntityTags); if (tagIdentifiers != null && !tagIdentifiers.isEmpty()) { entityType.setTags(toTags(intermediateResults, tagIdentifiers)); } }
EmxMetadataParser implements MetadataParser { void parseSingleEntityType( IntermediateParseResults intermediateResults, int rowIndex, Entity entity) { String emxEntityName = entity.getString(EMX_ENTITIES_NAME); String emxEntityPackage = entity.getString(EMX_ENTITIES_PACKAGE); String emxEntityLabel = entity.getString(EMX_ENTITIES_LABEL); String emxEntityDescription = entity.getString(EMX_ENTITIES_DESCRIPTION); String emxEntityAbstract = entity.getString(EMX_ENTITIES_ABSTRACT); String emxEntityExtends = entity.getString(EMX_ENTITIES_EXTENDS); String emxEntityBackend = entity.getString(EMX_ENTITIES_BACKEND); String emxEntityTags = entity.getString(EMX_ENTITIES_TAGS); if (Strings.isNullOrEmpty(emxEntityName)) { throw new MissingEmxAttributeValueException("name", EMX_ENTITIES, rowIndex); } String entityTypeId; entityTypeId = toEntityTypeId(emxEntityName, emxEntityPackage); EntityType entityType = intermediateResults.getEntityType(entityTypeId); if (entityType == null) { entityType = intermediateResults.addEntityType(entityTypeId); } if (emxEntityBackend != null) { if (!dataService.getMeta().hasBackend(emxEntityBackend)) { throw new UnknownRepositoryCollectionException(emxEntityBackend); } } else { emxEntityBackend = dataService.getMeta().getDefaultBackend().getName(); } entityType.setBackend(emxEntityBackend); if (!Strings.isNullOrEmpty(emxEntityPackage)) { setPackage(intermediateResults, rowIndex, emxEntityPackage, entityType); } if (emxEntityLabel == null) { emxEntityLabel = emxEntityName; } entityType.setLabel(emxEntityLabel); entityType.setDescription(emxEntityDescription); for (String attributeName : entity.getAttributeNames()) { if (isI18n(attributeName)) { setI18nEntityTypeLabelAndDesc(entity, entityType, attributeName); } } if (emxEntityAbstract != null) { entityType.setAbstract(parseBoolean(emxEntityAbstract, rowIndex, EMX_ENTITIES_ABSTRACT)); } if (emxEntityExtends != null) { setEntityExtends(intermediateResults, emxEntityName, emxEntityExtends, entityType, rowIndex); } List<String> tagIdentifiers = toList(emxEntityTags); if (tagIdentifiers != null && !tagIdentifiers.isEmpty()) { entityType.setTags(toTags(intermediateResults, tagIdentifiers)); } } }
EmxMetadataParser implements MetadataParser { void parseSingleEntityType( IntermediateParseResults intermediateResults, int rowIndex, Entity entity) { String emxEntityName = entity.getString(EMX_ENTITIES_NAME); String emxEntityPackage = entity.getString(EMX_ENTITIES_PACKAGE); String emxEntityLabel = entity.getString(EMX_ENTITIES_LABEL); String emxEntityDescription = entity.getString(EMX_ENTITIES_DESCRIPTION); String emxEntityAbstract = entity.getString(EMX_ENTITIES_ABSTRACT); String emxEntityExtends = entity.getString(EMX_ENTITIES_EXTENDS); String emxEntityBackend = entity.getString(EMX_ENTITIES_BACKEND); String emxEntityTags = entity.getString(EMX_ENTITIES_TAGS); if (Strings.isNullOrEmpty(emxEntityName)) { throw new MissingEmxAttributeValueException("name", EMX_ENTITIES, rowIndex); } String entityTypeId; entityTypeId = toEntityTypeId(emxEntityName, emxEntityPackage); EntityType entityType = intermediateResults.getEntityType(entityTypeId); if (entityType == null) { entityType = intermediateResults.addEntityType(entityTypeId); } if (emxEntityBackend != null) { if (!dataService.getMeta().hasBackend(emxEntityBackend)) { throw new UnknownRepositoryCollectionException(emxEntityBackend); } } else { emxEntityBackend = dataService.getMeta().getDefaultBackend().getName(); } entityType.setBackend(emxEntityBackend); if (!Strings.isNullOrEmpty(emxEntityPackage)) { setPackage(intermediateResults, rowIndex, emxEntityPackage, entityType); } if (emxEntityLabel == null) { emxEntityLabel = emxEntityName; } entityType.setLabel(emxEntityLabel); entityType.setDescription(emxEntityDescription); for (String attributeName : entity.getAttributeNames()) { if (isI18n(attributeName)) { setI18nEntityTypeLabelAndDesc(entity, entityType, attributeName); } } if (emxEntityAbstract != null) { entityType.setAbstract(parseBoolean(emxEntityAbstract, rowIndex, EMX_ENTITIES_ABSTRACT)); } if (emxEntityExtends != null) { setEntityExtends(intermediateResults, emxEntityName, emxEntityExtends, entityType, rowIndex); } List<String> tagIdentifiers = toList(emxEntityTags); if (tagIdentifiers != null && !tagIdentifiers.isEmpty()) { entityType.setTags(toTags(intermediateResults, tagIdentifiers)); } } EmxMetadataParser(
      DataService dataService,
      PackageFactory packageFactory,
      AttributeFactory attrMetaFactory,
      EntityTypeFactory entityTypeFactory,
      TagFactory tagFactory,
      LanguageFactory languageFactory,
      L10nStringFactory l10nStringFactory,
      EntityTypeValidator entityTypeValidator,
      AttributeValidator attributeValidator,
      TagValidator tagValidator,
      EntityTypeDependencyResolver entityTypeDependencyResolver); }
EmxMetadataParser implements MetadataParser { void parseSingleEntityType( IntermediateParseResults intermediateResults, int rowIndex, Entity entity) { String emxEntityName = entity.getString(EMX_ENTITIES_NAME); String emxEntityPackage = entity.getString(EMX_ENTITIES_PACKAGE); String emxEntityLabel = entity.getString(EMX_ENTITIES_LABEL); String emxEntityDescription = entity.getString(EMX_ENTITIES_DESCRIPTION); String emxEntityAbstract = entity.getString(EMX_ENTITIES_ABSTRACT); String emxEntityExtends = entity.getString(EMX_ENTITIES_EXTENDS); String emxEntityBackend = entity.getString(EMX_ENTITIES_BACKEND); String emxEntityTags = entity.getString(EMX_ENTITIES_TAGS); if (Strings.isNullOrEmpty(emxEntityName)) { throw new MissingEmxAttributeValueException("name", EMX_ENTITIES, rowIndex); } String entityTypeId; entityTypeId = toEntityTypeId(emxEntityName, emxEntityPackage); EntityType entityType = intermediateResults.getEntityType(entityTypeId); if (entityType == null) { entityType = intermediateResults.addEntityType(entityTypeId); } if (emxEntityBackend != null) { if (!dataService.getMeta().hasBackend(emxEntityBackend)) { throw new UnknownRepositoryCollectionException(emxEntityBackend); } } else { emxEntityBackend = dataService.getMeta().getDefaultBackend().getName(); } entityType.setBackend(emxEntityBackend); if (!Strings.isNullOrEmpty(emxEntityPackage)) { setPackage(intermediateResults, rowIndex, emxEntityPackage, entityType); } if (emxEntityLabel == null) { emxEntityLabel = emxEntityName; } entityType.setLabel(emxEntityLabel); entityType.setDescription(emxEntityDescription); for (String attributeName : entity.getAttributeNames()) { if (isI18n(attributeName)) { setI18nEntityTypeLabelAndDesc(entity, entityType, attributeName); } } if (emxEntityAbstract != null) { entityType.setAbstract(parseBoolean(emxEntityAbstract, rowIndex, EMX_ENTITIES_ABSTRACT)); } if (emxEntityExtends != null) { setEntityExtends(intermediateResults, emxEntityName, emxEntityExtends, entityType, rowIndex); } List<String> tagIdentifiers = toList(emxEntityTags); if (tagIdentifiers != null && !tagIdentifiers.isEmpty()) { entityType.setTags(toTags(intermediateResults, tagIdentifiers)); } } EmxMetadataParser(
      DataService dataService,
      PackageFactory packageFactory,
      AttributeFactory attrMetaFactory,
      EntityTypeFactory entityTypeFactory,
      TagFactory tagFactory,
      LanguageFactory languageFactory,
      L10nStringFactory l10nStringFactory,
      EntityTypeValidator entityTypeValidator,
      AttributeValidator attributeValidator,
      TagValidator tagValidator,
      EntityTypeDependencyResolver entityTypeDependencyResolver); @Override ParsedMetaData parse(
      final RepositoryCollection source, @Nullable @CheckForNull String packageId); @Override EntitiesValidationReport validate(RepositoryCollection source); }
EmxMetadataParser implements MetadataParser { void parseSingleEntityType( IntermediateParseResults intermediateResults, int rowIndex, Entity entity) { String emxEntityName = entity.getString(EMX_ENTITIES_NAME); String emxEntityPackage = entity.getString(EMX_ENTITIES_PACKAGE); String emxEntityLabel = entity.getString(EMX_ENTITIES_LABEL); String emxEntityDescription = entity.getString(EMX_ENTITIES_DESCRIPTION); String emxEntityAbstract = entity.getString(EMX_ENTITIES_ABSTRACT); String emxEntityExtends = entity.getString(EMX_ENTITIES_EXTENDS); String emxEntityBackend = entity.getString(EMX_ENTITIES_BACKEND); String emxEntityTags = entity.getString(EMX_ENTITIES_TAGS); if (Strings.isNullOrEmpty(emxEntityName)) { throw new MissingEmxAttributeValueException("name", EMX_ENTITIES, rowIndex); } String entityTypeId; entityTypeId = toEntityTypeId(emxEntityName, emxEntityPackage); EntityType entityType = intermediateResults.getEntityType(entityTypeId); if (entityType == null) { entityType = intermediateResults.addEntityType(entityTypeId); } if (emxEntityBackend != null) { if (!dataService.getMeta().hasBackend(emxEntityBackend)) { throw new UnknownRepositoryCollectionException(emxEntityBackend); } } else { emxEntityBackend = dataService.getMeta().getDefaultBackend().getName(); } entityType.setBackend(emxEntityBackend); if (!Strings.isNullOrEmpty(emxEntityPackage)) { setPackage(intermediateResults, rowIndex, emxEntityPackage, entityType); } if (emxEntityLabel == null) { emxEntityLabel = emxEntityName; } entityType.setLabel(emxEntityLabel); entityType.setDescription(emxEntityDescription); for (String attributeName : entity.getAttributeNames()) { if (isI18n(attributeName)) { setI18nEntityTypeLabelAndDesc(entity, entityType, attributeName); } } if (emxEntityAbstract != null) { entityType.setAbstract(parseBoolean(emxEntityAbstract, rowIndex, EMX_ENTITIES_ABSTRACT)); } if (emxEntityExtends != null) { setEntityExtends(intermediateResults, emxEntityName, emxEntityExtends, entityType, rowIndex); } List<String> tagIdentifiers = toList(emxEntityTags); if (tagIdentifiers != null && !tagIdentifiers.isEmpty()) { entityType.setTags(toTags(intermediateResults, tagIdentifiers)); } } EmxMetadataParser(
      DataService dataService,
      PackageFactory packageFactory,
      AttributeFactory attrMetaFactory,
      EntityTypeFactory entityTypeFactory,
      TagFactory tagFactory,
      LanguageFactory languageFactory,
      L10nStringFactory l10nStringFactory,
      EntityTypeValidator entityTypeValidator,
      AttributeValidator attributeValidator,
      TagValidator tagValidator,
      EntityTypeDependencyResolver entityTypeDependencyResolver); @Override ParsedMetaData parse(
      final RepositoryCollection source, @Nullable @CheckForNull String packageId); @Override EntitiesValidationReport validate(RepositoryCollection source); static final String EMX_PACKAGES; static final String EMX_ENTITIES; static final String EMX_ATTRIBUTES; static final String EMX_PACKAGE_NAME; static final String EMX_PACKAGE_DESCRIPTION; static final String EMX_PACKAGE_PARENT; static final String EMX_PACKAGE_TAGS; static final String EMX_PACKAGE_LABEL; static final String EMX_ENTITIES_NAME; static final String EMX_ENTITIES_PACKAGE; static final String EMX_ENTITIES_LABEL; static final String EMX_ENTITIES_DESCRIPTION; static final String EMX_ENTITIES_ABSTRACT; static final String EMX_ENTITIES_EXTENDS; static final String EMX_ENTITIES_BACKEND; static final String EMX_ENTITIES_TAGS; static final String EMX_ATTRIBUTES_NAME; static final String EMX_ATTRIBUTES_ENTITY; static final String EMX_ATTRIBUTES_REF_ENTITY; static final String EMX_ATTRIBUTES_MAPPED_BY; static final String EMX_ATTRIBUTES_DEFAULT_VALUE; static final String EMX_ATTRIBUTES_ID_ATTRIBUTE; static final String EMX_ATTRIBUTES_LOOKUP_ATTRIBUTE; static final String EMX_ATTRIBUTES_LABEL_ATTRIBUTE; static final String EMX_ATTRIBUTES_PART_OF_ATTRIBUTE; static final String EMX_ATTRIBUTES_AGGREGATEABLE; static final String EMX_ATTRIBUTES_DATA_TYPE; static final String EMX_ATTRIBUTES_EXPRESSION; static final String EMX_ATTRIBUTES_NILLABLE; static final String EMX_ATTRIBUTES_VISIBLE; static final String EMX_ATTRIBUTES_LABEL; static final String EMX_ATTRIBUTES_DESCRIPTION; static final String EMX_ATTRIBUTES_ENUM_OPTIONS; static final String EMX_ATTRIBUTES_RANGE_MIN; static final String EMX_ATTRIBUTES_RANGE_MAX; static final String EMX_ATTRIBUTES_READ_ONLY; static final String EMX_ATTRIBUTES_UNIQUE; static final String EMX_ATTRIBUTES_VALIDATION_EXPRESSION; static final String EMX_ATTRIBUTES_TAGS; static final String EMX_ATTRIBUTES_AUTO; static final String AUTO; }