示例#1
0
  @Before
  public void setUpEntities() {
    book = new EntityDto("Book");
    author = new EntityDto("Author");

    authorFieldInBook = fieldDto("author", ManyToManyRelationship.class);
    authorFieldInBook.addMetadata(new MetadataDto(RELATED_CLASS, "Author"));

    FieldDto bookFieldInAuthor = fieldDto("book", ManyToManyRelationship.class);
    bookFieldInAuthor.addMetadata(new MetadataDto(RELATED_CLASS, "Book"));

    when(schemaHolder.getFields(book)).thenReturn(singletonList(authorFieldInBook));
    when(schemaHolder.getFields(author)).thenReturn(singletonList(bookFieldInAuthor));

    entity1 = new EntityDto("Entity1");
    entity2 = new EntityDto("Entity2");
    entity3 = new EntityDto("Entity3");

    FieldDto entity1Field = fieldDto("entity1", OneToOneRelationship.class);
    entity1Field.addMetadata(new MetadataDto(RELATED_CLASS, "Entity2"));

    FieldDto entity2Field = fieldDto("entity2", OneToOneRelationship.class);
    entity2Field.addMetadata(new MetadataDto(RELATED_CLASS, "Entity3"));

    when(schemaHolder.getFields(entity1)).thenReturn(singletonList(entity1Field));
    when(schemaHolder.getFields(entity2)).thenReturn(singletonList(entity2Field));

    parentEntity = new EntityDto("Parent");
    childEntity = new EntityDto("Child");
    childEntity.setSuperClass("Parent");

    binaryTree = new EntityDto("Binary tree");
    FieldDto leftChild = fieldDto("leftChild", "Left child", OneToOneRelationship.class);
    leftChild.addMetadata(new MetadataDto(RELATED_CLASS, "Binary tree"));

    FieldDto rightChild = fieldDto("rightChild", "Right child", OneToOneRelationship.class);
    rightChild.addMetadata(new MetadataDto(RELATED_CLASS, "Binary tree"));

    when(schemaHolder.getFields(binaryTree)).thenReturn(asList(leftChild, rightChild));

    entity1.setRecordHistory(true);
    entity2.setRecordHistory(true);
    entity3.setRecordHistory(true);
    book.setRecordHistory(true);
    author.setRecordHistory(true);
    parentEntity.setRecordHistory(true);
    childEntity.setRecordHistory(true);
    binaryTree.setRecordHistory(true);
  }
  public static List<FieldDto> defaultFields(SchemaHolder schemaHolder) {
    TypeDto longType = schemaHolder.getType(Long.class);
    TypeDto stringType = schemaHolder.getType(String.class);
    TypeDto dateTimeType = schemaHolder.getType(DateTime.class);

    FieldDto idField =
        new FieldDto(
            Constants.Util.ID_FIELD_NAME,
            Constants.Util.ID_DISPLAY_FIELD_NAME,
            longType,
            true,
            true);
    idField.setReadOnly(true);
    idField.setMetadata(Collections.singletonList(new MetadataDto(AUTO_GENERATED, TRUE)));

    FieldDto creatorField =
        new FieldDto(
            Constants.Util.CREATOR_FIELD_NAME,
            Constants.Util.CREATOR_DISPLAY_FIELD_NAME,
            stringType,
            true,
            false);
    creatorField.setReadOnly(true);
    creatorField.addMetadata(new MetadataDto(AUTO_GENERATED, TRUE));

    FieldDto ownerField =
        new FieldDto(
            Constants.Util.OWNER_FIELD_NAME,
            Constants.Util.OWNER_DISPLAY_FIELD_NAME,
            stringType,
            false,
            false);
    ownerField.setReadOnly(true);
    ownerField.addMetadata(new MetadataDto(AUTO_GENERATED_EDITABLE, TRUE));

    FieldDto modifiedByField =
        new FieldDto(
            Constants.Util.MODIFIED_BY_FIELD_NAME,
            Constants.Util.MODIFIED_BY_DISPLAY_FIELD_NAME,
            stringType,
            true,
            false);
    modifiedByField.setReadOnly(true);
    modifiedByField.addMetadata(new MetadataDto(AUTO_GENERATED, TRUE));

    FieldDto modificationDateField =
        new FieldDto(
            Constants.Util.MODIFICATION_DATE_FIELD_NAME,
            Constants.Util.MODIFICATION_DATE_DISPLAY_FIELD_NAME,
            dateTimeType,
            true,
            false);
    modificationDateField.setReadOnly(true);
    modificationDateField.addMetadata(new MetadataDto(AUTO_GENERATED, TRUE));

    FieldDto creationDateField =
        new FieldDto(
            Constants.Util.CREATION_DATE_FIELD_NAME,
            Constants.Util.CREATION_DATE_DISPLAY_FIELD_NAME,
            dateTimeType,
            true,
            false);
    creationDateField.setReadOnly(true);
    creationDateField.addMetadata(new MetadataDto(AUTO_GENERATED, TRUE));

    return Arrays.asList(
        idField,
        creatorField,
        ownerField,
        modifiedByField,
        modificationDateField,
        creationDateField);
  }