Uploaded image for project: 'Isis'
  1. Isis
  2. ISIS-1512

MetaModelValidator should detect domain services that have collections, and fail-fast.

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.13.0
    • Fix Version/s: 1.14.0
    • Component/s: Core
    • Labels:
      None

      Description

      this issue arose because attempting to download the metamodel.csv threw an exception when it encountered an invalid class (specifically, EstatioFakeDataService):

      @DomainService(nature = NatureOfService.DOMAIN)
      public class EstatioFakeDataService {
      
          static Random random;
          static {
              random = new Random(System.currentTimeMillis());
          }
      
          Faker2 faker2;
          @PostConstruct
          public void init() {
              faker2 = new Faker2(random);
          }
      
          @Inject
          private ClockService clockService;
      
          @Inject
          private DomainObjectContainer container;
      
          private RandomService randomService;
      
          private final Values values;
          private final Collections collections;
          private final Dates dates;
          private final Periods periods;
      
          public EstatioFakeDataService() {
      
              randomService = new RandomService(random);
      
              this.values = new Values();
              this.collections = new Collections();
              this.dates = new Dates();
              this.periods = new Periods();
      
          }
      
          @Programmatic
          public PhoneNumber phoneNumber() {
              return faker2.phoneNumber();
          }
      
          @Programmatic
          public Options options() {
              return faker2.options();
          }
      
          @Programmatic
          public Internet internet() {
              return faker2.internet();
          }
      
          @Programmatic
          public Code code() {
              return faker2.code();
          }
      
          @Programmatic
          public Business business() {
              return faker2.business();
          }
      
          @Programmatic
          public Address address() {
              return faker2.address();
          }
      
          @Programmatic
          public Name name() {
              return faker2.name();
          }
      
          @Programmatic
          public Lorem lorem() {
              return faker2.lorem();
          }
      
          public Values values() {
              return values;
          }
      
          public Collections collections() {
              return collections;
          }
      
          public Dates dates() {
              return dates;
          }
      
          public Periods periods() {
              return periods;
          }
      
          public class Values {
      
              public String code(final int numChars) {
                  final StringBuilder buf = new StringBuilder();
                  final char[] chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
                  for (int i = 0; i < numChars; i++) {
                      char c = collections().anElement(chars);
                      buf.append(c);
                  }
                  return buf.toString();
              }
      
              public int anInt(final int upTo) {
                  return randomService.nextInt(upTo);
              }
      
              public int anInt(final int min, final int max) {
                  return min + randomService.nextInt(max-min);
              }
      
              public int aDouble(final int upTo) {
                  return randomService.nextInt(upTo);
              }
      
              public boolean aCoinFlip() {
                  return randomService.nextDouble() < 0.5;
              }
      
              public boolean aDiceRollOf6() {
                  return anInt(6) == 5;
              }
      
          }
      
          public class Collections  {
      
              public <E extends Enum<E>> E anEnum(final Class<E> enumType) {
                  final E[] enumConstants = enumType.getEnumConstants();
                  return enumConstants[values().anInt(enumConstants.length)];
              }
      
              public <T> T aBounded(final Class<T> cls) {
                  final List<T> list = container.allInstances(cls);
                  return anElement(list);
              }
      
              public <T> T anElement(final List<T> list) {
                  final int randomIdx = values().anInt(list.size());
                  return list.get(randomIdx);
              }
      
              public char anElement(final char[] elements) {
                  final int randomIdx = values().anInt(elements.length);
                  return elements[randomIdx];
              }
      
              public byte anElement(final byte[] elements) {
                  final int randomIdx = values().anInt(elements.length);
                  return elements[randomIdx];
              }
      
              public short anElement(final short[] elements) {
                  final int randomIdx = values().anInt(elements.length);
                  return elements[randomIdx];
              }
      
              public int anElement(final int[] elements) {
                  final int randomIdx = values().anInt(elements.length);
                  return elements[randomIdx];
              }
      
              public long anElement(final long[] elements) {
                  final int randomIdx = values().anInt(elements.length);
                  return elements[randomIdx];
              }
      
              public float anElement(final float[] elements) {
                  final int randomIdx = values().anInt(elements.length);
                  return elements[randomIdx];
              }
      
              public double anElement(final double[] elements) {
                  final int randomIdx = values().anInt(elements.length);
                  return elements[randomIdx];
              }
      
              public boolean anElement(final boolean[] elements) {
                  final int randomIdx = values().anInt(elements.length);
                  return elements[randomIdx];
              }
      
              public <T> T anElement(final T[] elements) {
                  final int randomIdx = values().anInt(elements.length);
                  return elements[randomIdx];
              }
          }
      
      
          public class Dates {
      
              public LocalDate around(final Period period) {
                  final LocalDate now = clockService.now();
                  return values().aCoinFlip() ? before(period): after(period);
              }
      
              public LocalDate before(final Period period) {
                  final LocalDate now = clockService.now();
                  return now.minus(period);
              }
      
              public LocalDate after(final Period period) {
                  final LocalDate now = clockService.now();
                  return now.plus(period);
              }
      
          }
      
          public class Periods {
      
              public Period days(final int minDays, final int maxDays) {
                  return Period.days(values().anInt(minDays, maxDays));
              }
      
              public Period daysUpTo(final int maxDays) {
                  return days(0, maxDays);
              }
      
              public Period months(final int minMonths, final int maxMonths) {
                  return Period.months(values().anInt(minMonths, maxMonths));
              }
      
              public Period monthsUpTo(final int months) {
                  return months(0, months);
              }
      
              public Period years(final int minYears, final int maxYears) {
                  return Period.years(values().anInt(minYears, maxYears));
              }
      
              public Period yearsUpTo(final int years) {
                  return years(0, years);
              }
      
          }
      }
      

        Activity

        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 1d8ac13fdf28bc2b5b6a58d2cf372312f9af6262 in isis's branch refs/heads/maint-1.14.0 from Dan Haywood
        [ https://git-wip-us.apache.org/repos/asf?p=isis.git;h=1d8ac13 ]

        ISIS-1512: adds metamodel validator for DomainService annotation facet factory, to check...

        ... that no services have collections. This is disabled by default, can be enabled using a configuration property.

        Show
        jira-bot ASF subversion and git services added a comment - Commit 1d8ac13fdf28bc2b5b6a58d2cf372312f9af6262 in isis's branch refs/heads/maint-1.14.0 from Dan Haywood [ https://git-wip-us.apache.org/repos/asf?p=isis.git;h=1d8ac13 ] ISIS-1512 : adds metamodel validator for DomainService annotation facet factory, to check... ... that no services have collections. This is disabled by default, can be enabled using a configuration property.
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 1d8ac13fdf28bc2b5b6a58d2cf372312f9af6262 in isis's branch refs/heads/master from Dan Haywood
        [ https://git-wip-us.apache.org/repos/asf?p=isis.git;h=1d8ac13 ]

        ISIS-1512: adds metamodel validator for DomainService annotation facet factory, to check...

        ... that no services have collections. This is disabled by default, can be enabled using a configuration property.

        Show
        jira-bot ASF subversion and git services added a comment - Commit 1d8ac13fdf28bc2b5b6a58d2cf372312f9af6262 in isis's branch refs/heads/master from Dan Haywood [ https://git-wip-us.apache.org/repos/asf?p=isis.git;h=1d8ac13 ] ISIS-1512 : adds metamodel validator for DomainService annotation facet factory, to check... ... that no services have collections. This is disabled by default, can be enabled using a configuration property.

          People

          • Assignee:
            danhaywood Dan Haywood
            Reporter:
            danhaywood Dan Haywood
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development