mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 13:10:44 +00:00
Update QMetaDataProducingEntity to know how to produce table meta data; Add MetaDataCustomizers to work with producer helpers
This commit is contained in:
@ -39,6 +39,7 @@ import com.kingsrook.qqq.backend.core.model.metadata.producers.TestMetaDataProdu
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.producers.TestMetaDataProducingPossibleValueEnum;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.producers.TestNoInterfacesExtendsObject;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.producers.TestNoValidConstructorMetaDataProducer;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
@ -76,6 +77,17 @@ class MetaDataProducerHelperTest
|
||||
assertEquals(2, enumPVS.getEnumValues().size());
|
||||
assertEquals(new QPossibleValue<>(1, "One"), enumPVS.getEnumValues().get(0));
|
||||
|
||||
////////////////////////////////////////////
|
||||
// annotation on table -> table meta data //
|
||||
////////////////////////////////////////////
|
||||
assertTrue(qInstance.getTables().containsKey(TestMetaDataProducingEntity.TABLE_NAME));
|
||||
QTableMetaData table = qInstance.getTables().get(TestMetaDataProducingEntity.TABLE_NAME);
|
||||
assertEquals(TestMetaDataProducingEntity.TABLE_NAME, table.getName());
|
||||
assertEquals("id", table.getPrimaryKeyField());
|
||||
assertEquals(2, table.getFields().size());
|
||||
assertTrue(table.getField("name").getIsRequired());
|
||||
assertEquals("Customized Label", table.getLabel());
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// annotation on PVS table -> PVS meta data //
|
||||
//////////////////////////////////////////////
|
||||
|
@ -26,7 +26,6 @@ import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.model.data.QField;
|
||||
import com.kingsrook.qqq.backend.core.model.data.QRecord;
|
||||
import com.kingsrook.qqq.backend.core.model.data.QRecordEntity;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.MetaDataProducerInterface;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.producers.annotations.ChildJoin;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.producers.annotations.ChildRecordListWidget;
|
||||
@ -38,7 +37,10 @@ import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
||||
/*******************************************************************************
|
||||
** QRecord Entity for TestMetaDataProducingEntity table
|
||||
*******************************************************************************/
|
||||
@QMetaDataProducingEntity(producePossibleValueSource = true,
|
||||
@QMetaDataProducingEntity(
|
||||
produceTableMetaData = true,
|
||||
tableMetaDataCustomizer = TestMetaDataProducingEntity.TableMetaDataCustomizer.class,
|
||||
producePossibleValueSource = true,
|
||||
childTables =
|
||||
{
|
||||
@ChildTable(childTableEntityClass = TestMetaDataProducingChildEntity.class,
|
||||
@ -46,24 +48,31 @@ import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
||||
childRecordListWidget = @ChildRecordListWidget(enabled = true, label = "Test Children", maxRows = 15))
|
||||
}
|
||||
)
|
||||
public class TestMetaDataProducingEntity extends QRecordEntity implements MetaDataProducerInterface<QTableMetaData>
|
||||
public class TestMetaDataProducingEntity extends QRecordEntity
|
||||
{
|
||||
public static final String TABLE_NAME = "testMetaDataProducingEntity";
|
||||
|
||||
@QField(isEditable = false, isPrimaryKey = true)
|
||||
private Integer id;
|
||||
|
||||
@QField(isRequired = true)
|
||||
private String name;
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
**
|
||||
***************************************************************************/
|
||||
@Override
|
||||
public QTableMetaData produce(QInstance qInstance) throws QException
|
||||
public static class TableMetaDataCustomizer implements MetaDataCustomizerInterface<QTableMetaData>
|
||||
{
|
||||
return new QTableMetaData()
|
||||
.withName(TABLE_NAME)
|
||||
.withFieldsFromEntity(TestMetaDataProducingEntity.class);
|
||||
/***************************************************************************
|
||||
**
|
||||
***************************************************************************/
|
||||
@Override
|
||||
public QTableMetaData customizeMetaData(QInstance qInstance, QTableMetaData table) throws QException
|
||||
{
|
||||
table.withLabel("Customized Label");
|
||||
return table;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -116,4 +125,35 @@ public class TestMetaDataProducingEntity extends QRecordEntity implements MetaDa
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for name
|
||||
*******************************************************************************/
|
||||
public String getName()
|
||||
{
|
||||
return (this.name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for name
|
||||
*******************************************************************************/
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for name
|
||||
*******************************************************************************/
|
||||
public TestMetaDataProducingEntity withName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user