@Test void testToEntityType() { String id = "id"; String label = "label"; String i18nLabelLangEn = "en"; String i18nLabelValue = "en label"; Map<String, String> i18nLabel = singletonMap(i18nLabelLangEn, i18nLabelValue); String description = "description"; String i18nDescriptionLangEn = "en"; String i18nDescriptionValue = "en description"; Map<String, String> i18nDescription = singletonMap(i18nDescriptionLangEn, i18nDescriptionValue); String backend = "backend"; EditorPackageIdentifier editorPackageIdentifier = EditorPackageIdentifier.create("packageId", "package label"); EditorEntityTypeParent editorEntityTypeParent = EditorEntityTypeParent.create( "entityTypeParentId", "entity type parent label", of(EditorAttributeIdentifier.create("parentAttrId0", "parent attribute #0")), null); List<EditorAttribute> editorAttributes = of(mock(EditorAttribute.class)); List<EditorAttributeIdentifier> editorReferringAttributes = of(mock(EditorAttributeIdentifier.class)); ImmutableList<EditorTagIdentifier> editorTags = of(EditorTagIdentifier.create("tag0", "tag #0")); EditorAttributeIdentifier idAttribute = EditorAttributeIdentifier.create("idAttr", "id attribute"); EditorAttributeIdentifier labelAttribute = EditorAttributeIdentifier.create("labelAttr", "label attribute"); List<EditorAttributeIdentifier> lookupAttributes = of(EditorAttributeIdentifier.create("attr0", "attribute #0")); EditorEntityType editorEntityType = EditorEntityType.create( id, label, i18nLabel, description, i18nDescription, true, backend, editorPackageIdentifier, editorEntityTypeParent, editorAttributes, editorReferringAttributes, editorTags, idAttribute, labelAttribute, lookupAttributes); EntityType entityType = mock(EntityType.class); when(entityTypeFactory.create()).thenReturn(entityType); Package package_ = mock(Package.class); when(packageMapper.toPackageReference(editorPackageIdentifier)).thenReturn(package_); EntityType parentEntityType = mock(EntityType.class); when(entityTypeParentMapper.toEntityTypeReference(editorEntityTypeParent)) .thenReturn(parentEntityType); @SuppressWarnings("unchecked") Iterable<Tag> tags = mock(Iterable.class); when(tagMapper.toTagReferences(editorTags)).thenReturn(tags); @SuppressWarnings("unchecked") Iterable<Attribute> attributes = mock(Iterable.class); when(attributeMapper.toAttributes(editorAttributes, editorEntityType)).thenReturn(attributes); assertEquals(entityTypeMapper.toEntityType(editorEntityType), entityType); verify(entityType).setId(id); verify(entityType).setLabel(label); verify(entityType).setLabel(i18nLabelLangEn, i18nLabelValue); verify(entityType).setLabel("nl", null); verify(entityType).setLabel("de", null); verify(entityType).setLabel("es", null); verify(entityType).setLabel("it", null); verify(entityType).setLabel("pt", null); verify(entityType).setLabel("fr", null); verify(entityType).setLabel("xx", null); verify(entityType).setDescription(description); verify(entityType).setDescription(i18nDescriptionLangEn, i18nDescriptionValue); verify(entityType).setDescription("nl", null); verify(entityType).setDescription("de", null); verify(entityType).setDescription("es", null); verify(entityType).setDescription("it", null); verify(entityType).setDescription("pt", null); verify(entityType).setDescription("fr", null); verify(entityType).setDescription("xx", null); verify(entityType).setAbstract(true); verify(entityType).setBackend(backend); verify(entityType).setPackage(package_); verify(entityType).setExtends(parentEntityType); verify(entityType).setOwnAllAttributes(attributes); verify(entityType).setTags(tags); verifyNoMoreInteractions(entityType); }
public EntityType toEntityType(EditorEntityType editorEntityType) { if (!editorEntityType.isAbstract() && editorEntityType.getIdAttribute() == null) { throw new MolgenisDataException( "ID attribute for EntityType [" + editorEntityType.getLabel() + "] cannot be null"); } EntityType entityType = entityTypeFactory.create(); entityType.setId(editorEntityType.getId()); entityType.setPackage(packageMapper.toPackageReference(editorEntityType.getPackage())); entityType.setLabel(editorEntityType.getLabel()); if (editorEntityType.getLabelI18n() != null) { getLanguageCodes() .forEach( languageCode -> entityType.setLabel( languageCode, editorEntityType.getLabelI18n().get(languageCode))); } entityType.setDescription(editorEntityType.getDescription()); if (editorEntityType.getDescriptionI18n() != null) { getLanguageCodes() .forEach( languageCode -> entityType.setDescription( languageCode, editorEntityType.getDescriptionI18n().get(languageCode))); } entityType.setOwnAllAttributes( attributeMapper.toAttributes(editorEntityType.getAttributes(), editorEntityType)); entityType.setAbstract(editorEntityType.isAbstract()); entityType.setExtends( entityTypeParentMapper.toEntityTypeReference(editorEntityType.getEntityTypeParent())); entityType.setTags(tagMapper.toTagReferences(editorEntityType.getTags())); entityType.setBackend(editorEntityType.getBackend()); return entityType; }
EntityTypeMapper { public EntityType toEntityType(EditorEntityType editorEntityType) { if (!editorEntityType.isAbstract() && editorEntityType.getIdAttribute() == null) { throw new MolgenisDataException( "ID attribute for EntityType [" + editorEntityType.getLabel() + "] cannot be null"); } EntityType entityType = entityTypeFactory.create(); entityType.setId(editorEntityType.getId()); entityType.setPackage(packageMapper.toPackageReference(editorEntityType.getPackage())); entityType.setLabel(editorEntityType.getLabel()); if (editorEntityType.getLabelI18n() != null) { getLanguageCodes() .forEach( languageCode -> entityType.setLabel( languageCode, editorEntityType.getLabelI18n().get(languageCode))); } entityType.setDescription(editorEntityType.getDescription()); if (editorEntityType.getDescriptionI18n() != null) { getLanguageCodes() .forEach( languageCode -> entityType.setDescription( languageCode, editorEntityType.getDescriptionI18n().get(languageCode))); } entityType.setOwnAllAttributes( attributeMapper.toAttributes(editorEntityType.getAttributes(), editorEntityType)); entityType.setAbstract(editorEntityType.isAbstract()); entityType.setExtends( entityTypeParentMapper.toEntityTypeReference(editorEntityType.getEntityTypeParent())); entityType.setTags(tagMapper.toTagReferences(editorEntityType.getTags())); entityType.setBackend(editorEntityType.getBackend()); return entityType; } }
EntityTypeMapper { public EntityType toEntityType(EditorEntityType editorEntityType) { if (!editorEntityType.isAbstract() && editorEntityType.getIdAttribute() == null) { throw new MolgenisDataException( "ID attribute for EntityType [" + editorEntityType.getLabel() + "] cannot be null"); } EntityType entityType = entityTypeFactory.create(); entityType.setId(editorEntityType.getId()); entityType.setPackage(packageMapper.toPackageReference(editorEntityType.getPackage())); entityType.setLabel(editorEntityType.getLabel()); if (editorEntityType.getLabelI18n() != null) { getLanguageCodes() .forEach( languageCode -> entityType.setLabel( languageCode, editorEntityType.getLabelI18n().get(languageCode))); } entityType.setDescription(editorEntityType.getDescription()); if (editorEntityType.getDescriptionI18n() != null) { getLanguageCodes() .forEach( languageCode -> entityType.setDescription( languageCode, editorEntityType.getDescriptionI18n().get(languageCode))); } entityType.setOwnAllAttributes( attributeMapper.toAttributes(editorEntityType.getAttributes(), editorEntityType)); entityType.setAbstract(editorEntityType.isAbstract()); entityType.setExtends( entityTypeParentMapper.toEntityTypeReference(editorEntityType.getEntityTypeParent())); entityType.setTags(tagMapper.toTagReferences(editorEntityType.getTags())); entityType.setBackend(editorEntityType.getBackend()); return entityType; } EntityTypeMapper(
      EntityTypeFactory entityTypeFactory,
      AttributeMapper attributeMapper,
      AttributeReferenceMapper attributeReferenceMapper,
      PackageMapper packageMapper,
      TagMapper tagMapper,
      EntityTypeParentMapper entityTypeParentMapper); }
EntityTypeMapper { public EntityType toEntityType(EditorEntityType editorEntityType) { if (!editorEntityType.isAbstract() && editorEntityType.getIdAttribute() == null) { throw new MolgenisDataException( "ID attribute for EntityType [" + editorEntityType.getLabel() + "] cannot be null"); } EntityType entityType = entityTypeFactory.create(); entityType.setId(editorEntityType.getId()); entityType.setPackage(packageMapper.toPackageReference(editorEntityType.getPackage())); entityType.setLabel(editorEntityType.getLabel()); if (editorEntityType.getLabelI18n() != null) { getLanguageCodes() .forEach( languageCode -> entityType.setLabel( languageCode, editorEntityType.getLabelI18n().get(languageCode))); } entityType.setDescription(editorEntityType.getDescription()); if (editorEntityType.getDescriptionI18n() != null) { getLanguageCodes() .forEach( languageCode -> entityType.setDescription( languageCode, editorEntityType.getDescriptionI18n().get(languageCode))); } entityType.setOwnAllAttributes( attributeMapper.toAttributes(editorEntityType.getAttributes(), editorEntityType)); entityType.setAbstract(editorEntityType.isAbstract()); entityType.setExtends( entityTypeParentMapper.toEntityTypeReference(editorEntityType.getEntityTypeParent())); entityType.setTags(tagMapper.toTagReferences(editorEntityType.getTags())); entityType.setBackend(editorEntityType.getBackend()); return entityType; } EntityTypeMapper(
      EntityTypeFactory entityTypeFactory,
      AttributeMapper attributeMapper,
      AttributeReferenceMapper attributeReferenceMapper,
      PackageMapper packageMapper,
      TagMapper tagMapper,
      EntityTypeParentMapper entityTypeParentMapper); EditorEntityType toEditorEntityType(
      EntityType entityType, List<Attribute> referringAttributes); EditorEntityType createEditorEntityType(); EntityType toEntityType(EditorEntityType editorEntityType); }
EntityTypeMapper { public EntityType toEntityType(EditorEntityType editorEntityType) { if (!editorEntityType.isAbstract() && editorEntityType.getIdAttribute() == null) { throw new MolgenisDataException( "ID attribute for EntityType [" + editorEntityType.getLabel() + "] cannot be null"); } EntityType entityType = entityTypeFactory.create(); entityType.setId(editorEntityType.getId()); entityType.setPackage(packageMapper.toPackageReference(editorEntityType.getPackage())); entityType.setLabel(editorEntityType.getLabel()); if (editorEntityType.getLabelI18n() != null) { getLanguageCodes() .forEach( languageCode -> entityType.setLabel( languageCode, editorEntityType.getLabelI18n().get(languageCode))); } entityType.setDescription(editorEntityType.getDescription()); if (editorEntityType.getDescriptionI18n() != null) { getLanguageCodes() .forEach( languageCode -> entityType.setDescription( languageCode, editorEntityType.getDescriptionI18n().get(languageCode))); } entityType.setOwnAllAttributes( attributeMapper.toAttributes(editorEntityType.getAttributes(), editorEntityType)); entityType.setAbstract(editorEntityType.isAbstract()); entityType.setExtends( entityTypeParentMapper.toEntityTypeReference(editorEntityType.getEntityTypeParent())); entityType.setTags(tagMapper.toTagReferences(editorEntityType.getTags())); entityType.setBackend(editorEntityType.getBackend()); return entityType; } EntityTypeMapper(
      EntityTypeFactory entityTypeFactory,
      AttributeMapper attributeMapper,
      AttributeReferenceMapper attributeReferenceMapper,
      PackageMapper packageMapper,
      TagMapper tagMapper,
      EntityTypeParentMapper entityTypeParentMapper); EditorEntityType toEditorEntityType(
      EntityType entityType, List<Attribute> referringAttributes); EditorEntityType createEditorEntityType(); EntityType toEntityType(EditorEntityType editorEntityType);  }