@Test void testToEntityTypeWithoutIdAttribute() { EditorEntityType editorEntityType = mock(EditorEntityType.class); when(editorEntityType.getIdAttribute()).thenReturn(null); when(editorEntityType.getLabelAttribute()).thenReturn(mock(EditorAttributeIdentifier.class)); when(editorEntityType.getLabel()).thenReturn("test"); Exception exception = assertThrows( MolgenisDataException.class, () -> entityTypeMapper.toEntityType(editorEntityType)); assertThat(exception.getMessage()) .containsPattern("ID attribute for EntityType \\[test\\] cannot be null"); }
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);  }