private EntityType assignUniqueLabel ( EntityType entityType , CopyState state ) { Set < String > existingLabels ; Package targetPackage = state . targetPackage ( ) ; if ( targetPackage != null ) { existingLabels = stream ( targetPackage . getEntityTypes ( ) ) . map ( EntityType :: getLabel ) . collect ( toSet ( ) ) ; } else { existingLabels = dataService . query ( ENTITY_TYPE_META_DATA , EntityType . class ) . eq ( EntityTypeMetadata . PACKAGE , null ) . findAll ( ) . map ( EntityType :: getLabel ) . collect ( toSet ( ) ) ; } entityType . setLabel ( LabelGenerator . generateUniqueLabel ( entityType . getLabel ( ) , existingLabels ) ) ; return entityType ; }
Checks if there s an EntityType in the target location with the same label . If so keeps adding a postfix until the label is unique .