code: EntityType createTargetMetadata(
        MappingTarget mappingTarget,
        String entityTypeId,
        String packageId,
        String label,
        Boolean addSourceAttribute) {
      EntityType targetMetadata =
          EntityType.newInstance(mappingTarget.getTarget(), DEEP_COPY_ATTRS, attrMetaFactory);
      targetMetadata.setId(entityTypeId);
  
      if (label != null) {
        targetMetadata.setLabel(label);
      } else {
        targetMetadata.setLabel(entityTypeId);
      }
  
      if (TRUE.equals(addSourceAttribute)) {
        targetMetadata.addAttribute(attrMetaFactory.create().setName(SOURCE));
      }
  
      if (dataService.hasRepository(entityTypeId)) {
        EntityType entityType =
            dataService
                .getMeta()
                .getEntityType(entityTypeId)
                .orElseThrow(() -> new UnknownEntityTypeException(entityTypeId));
        targetMetadata.setPackage(entityType.getPackage());
      } else if (packageId != null) {
        Package aPackage =
            dataService
                .getMeta()
                .getPackage(packageId)
                .orElseThrow(() -> new UnknownEntityException(PACKAGE, packageId));
        targetMetadata.setPackage(aPackage);
      } else {
        throw new MolgenisDataException("Package can't be null");
      }
  
      return targetMetadata;
    }
docs: Package-private for testability