Search in sources :

Example 41 with Entity

use of org.motechproject.mds.domain.Entity in project motech by motech.

the class InstancesWriterTest method shouldWriteNullForNullManyRefIdRelationshipProperty.

@Test
public void shouldWriteNullForNullManyRefIdRelationshipProperty() throws Exception {
    Entity entity = EntitySchemaBuilder.eude(ENTITY).field(PROPERTY, "mds.field.relationship.oneToMany").metadata(RELATED_CLASS, EntityWithProperty.class.getName()).metadata(RELATED_FIELD, PROPERTY).done().build();
    EntityWithProperty<ArrayList<EntityWithProperty>> instance = new EntityWithProperty<>(1L, null);
    assertInstanceWrittenCorrectly(entity, instance, NULL_PROPERTY_JSON);
}
Also used : Entity(org.motechproject.mds.domain.Entity) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 42 with Entity

use of org.motechproject.mds.domain.Entity in project motech by motech.

the class InstancesWriterTest method shouldWriteMapProperty.

@Test
public void shouldWriteMapProperty() throws Exception {
    Entity entity = EntitySchemaBuilder.eude(ENTITY).field(PROPERTY, "mds.field.map").done().build();
    Map<String, String> map = new HashMap<>();
    map.put("keyOne", "valOne");
    map.put("keyTwo", "valTwo");
    assertInstanceWrittenCorrectly(entity, new EntityWithProperty<>(1L, map), "{\"refId\":1,\"property\":{\"keyOne\":\"valOne\",\"keyTwo\":\"valTwo\"}}");
}
Also used : Entity(org.motechproject.mds.domain.Entity) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 43 with Entity

use of org.motechproject.mds.domain.Entity in project motech by motech.

the class InstancesWriterTest method shouldWritePlainBooleanProperty.

@Test
public void shouldWritePlainBooleanProperty() throws Exception {
    Entity entity = EntitySchemaBuilder.eude(ENTITY).field(PROPERTY, "mds.field.boolean").done().build();
    Boolean bool = true;
    assertInstanceWrittenCorrectly(entity, new EntityWithProperty<>(1L, bool), "{\"refId\":1,\"property\":true}");
}
Also used : Entity(org.motechproject.mds.domain.Entity) Test(org.junit.Test)

Example 44 with Entity

use of org.motechproject.mds.domain.Entity in project motech by motech.

the class InstancesWriterTest method shouldWriteNullForNullOneRefIdRelationshipProperty.

@Test
public void shouldWriteNullForNullOneRefIdRelationshipProperty() throws Exception {
    Entity entity = EntitySchemaBuilder.eude(ENTITY).field(PROPERTY, "mds.field.relationship.oneToOne").metadata(RELATED_CLASS, EntityWithProperty.class.getName()).metadata(RELATED_FIELD, PROPERTY).done().build();
    EntityWithProperty<EntityWithProperty> instance = new EntityWithProperty<>(1L, null);
    assertInstanceWrittenCorrectly(entity, instance, NULL_PROPERTY_JSON);
}
Also used : Entity(org.motechproject.mds.domain.Entity) Test(org.junit.Test)

Example 45 with Entity

use of org.motechproject.mds.domain.Entity in project motech by motech.

the class EntityValidator method validateEntityComboboxesValues.

private void validateEntityComboboxesValues(EntityDraft draft) {
    Entity parent = draft.getParentEntity();
    List<Field> oldComboboxFields = draft.getParentEntity().getStringComboboxFields();
    List<Field> comboboxFields = draft.getStringComboboxFields();
    for (Field field : substract(oldComboboxFields, comboboxFields)) {
        String tableName;
        String fieldName;
        if (!field.isMultiSelectCombobox()) {
            fieldName = field.getName();
            tableName = ClassTableName.getTableName(parent);
        } else {
            fieldName = "ELEMENT";
            tableName = ClassTableName.getTableName(parent) + "_" + field.getName().toUpperCase();
        }
        List<?> values = executeSQLQuery(prepareSelectDistincQuery(tableName, fieldName));
        validateUserSuppliedValuesUsageForField(values, draft.getField(field.getName()));
    }
}
Also used : Entity(org.motechproject.mds.domain.Entity) Field(org.motechproject.mds.domain.Field)

Aggregations

Entity (org.motechproject.mds.domain.Entity)97 Test (org.junit.Test)35 Field (org.motechproject.mds.domain.Field)33 MdsEntity (org.motechproject.mds.domain.MdsEntity)32 MdsVersionedEntity (org.motechproject.mds.domain.MdsVersionedEntity)32 Transactional (org.springframework.transaction.annotation.Transactional)32 ArrayList (java.util.ArrayList)14 Lookup (org.motechproject.mds.domain.Lookup)12 UserPreferences (org.motechproject.mds.domain.UserPreferences)8 Type (org.motechproject.mds.domain.Type)7 AllUserPreferences (org.motechproject.mds.repository.internal.AllUserPreferences)7 EntityDto (org.motechproject.mds.dto.EntityDto)6 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)6 HashMap (java.util.HashMap)5 FieldDto (org.motechproject.mds.dto.FieldDto)5 HashSet (java.util.HashSet)4 EntityDraft (org.motechproject.mds.domain.EntityDraft)4 MotechDataService (org.motechproject.mds.service.MotechDataService)4 Query (javax.jdo.Query)3 FieldSetting (org.motechproject.mds.domain.FieldSetting)3