Search in sources :

Example 86 with Entity

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

the class EntityServiceImpl method updateMaxFetchDepth.

@Override
@Transactional
public void updateMaxFetchDepth(Long entityId, Integer maxFetchDepth) {
    Entity entity = allEntities.retrieveById(entityId);
    assertEntityExists(entity, entityId);
    entity.setMaxFetchDepth(maxFetchDepth);
    allEntities.update(entity);
}
Also used : MdsEntity(org.motechproject.mds.domain.MdsEntity) Entity(org.motechproject.mds.domain.Entity) MdsVersionedEntity(org.motechproject.mds.domain.MdsVersionedEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 87 with Entity

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

the class EntityServiceImpl method getEntityFieldById.

@Override
@Transactional
public FieldDto getEntityFieldById(Long entityId, Long fieldId) {
    Entity entity = allEntities.retrieveById(entityId);
    Field field = entity.getField(fieldId);
    if (field == null) {
        throw new FieldNotFoundException(entity.getClassName(), fieldId);
    }
    return field.toDto();
}
Also used : MdsEntity(org.motechproject.mds.domain.MdsEntity) Entity(org.motechproject.mds.domain.Entity) MdsVersionedEntity(org.motechproject.mds.domain.MdsVersionedEntity) Field(org.motechproject.mds.domain.Field) FieldNotFoundException(org.motechproject.mds.exception.field.FieldNotFoundException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 88 with Entity

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

the class EntityServiceImpl method updateTracking.

@Override
@Transactional
public void updateTracking(Long entityId, TrackingDto trackingDto) {
    Entity entity = allEntities.retrieveById(entityId);
    assertEntityExists(entity, entityId);
    entity.updateTracking(trackingDto);
}
Also used : MdsEntity(org.motechproject.mds.domain.MdsEntity) Entity(org.motechproject.mds.domain.Entity) MdsVersionedEntity(org.motechproject.mds.domain.MdsVersionedEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 89 with Entity

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

the class EntityServiceImpl method updateDraft.

@Override
@Transactional
public EntityDto updateDraft(Long entityId) {
    Entity entity = allEntities.retrieveById(entityId);
    EntityDraft draft = getEntityDraft(entityId);
    allEntityDrafts.setProperties(draft, entity);
    draft.setChangesMade(false);
    return draft.toDto();
}
Also used : MdsEntity(org.motechproject.mds.domain.MdsEntity) Entity(org.motechproject.mds.domain.Entity) MdsVersionedEntity(org.motechproject.mds.domain.MdsVersionedEntity) EntityDraft(org.motechproject.mds.domain.EntityDraft) Transactional(org.springframework.transaction.annotation.Transactional)

Example 90 with Entity

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

the class SwaggerGeneratorTest method entities.

private List<Entity> entities() {
    List<Entity> entities = new ArrayList<>();
    // Entity 1
    Entity entity = new Entity();
    entity.setClassName("org.example.TestEntity");
    entity.setName("TestEntity");
    entity.setModule("example");
    entity.setNamespace("ns");
    RestOptions restOptions = new RestOptions(entity);
    restOptions.setAllowCreate(true);
    restOptions.setAllowRead(true);
    entity.setRestOptions(restOptions);
    List<Field> fields = new ArrayList<>();
    Field strField = field("str", String.class, true, true);
    strField.setTooltip("A string field used in tests");
    fields.add(strField);
    fields.add(field("integerField", Integer.class, true, true));
    Field longField = field("longField", Long.class, false, true);
    fields.add(longField);
    fields.add(field("timeField", Time.class, false, true));
    fields.add(field("ignoredField", String.class, false, false));
    fields.addAll(autoGeneratedFields());
    entity.setFields(fields);
    Lookup lookup = new Lookup("Find By Str & Long", true, true, asList(strField, longField), true, "findByStrLong");
    lookup.setFieldsOrder(asList("str", "longField"));
    entity.addLookup(lookup);
    entities.add(entity);
    // Entity 2
    entity = new Entity();
    entity.setClassName("org.motechproject.ExampleEnt");
    entity.setName("ExampleEnt");
    restOptions = new RestOptions(entity);
    restOptions.setAllowUpdate(true);
    restOptions.setAllowDelete(true);
    entity.setRestOptions(restOptions);
    fields = new ArrayList<>();
    fields.add(field("doubleField", Double.class, true, true));
    fields.add(field("dateField", Date.class, false, true));
    Field dtField = field("dtField", DateTime.class, false, true);
    fields.add(dtField);
    fields.add(field("ldField", LocalDate.class, false, true));
    Field localeField = field("localeField", Locale.class, false, true);
    fields.add(localeField);
    Field listField = FieldTestHelper.fieldWithComboboxSettings(entity, "listField", "list disp", List.class, true, false, asList("one", "two", "three"));
    listField.setExposedViaRest(true);
    listField.setRequired(true);
    fields.add(listField);
    fields.addAll(autoGeneratedFields());
    entity.setFields(fields);
    lookup = new Lookup("By Dt and Locale", false, true, asList(dtField, localeField), false, "byDtAndLocale");
    lookup.setRangeLookupFields(asList(dtField.getName()));
    lookup.setSetLookupFields(asList(localeField.getName()));
    lookup.setFieldsOrder(asList("dtField", "localeField"));
    entity.addLookup(lookup);
    entities.add(entity);
    return entities;
}
Also used : Entity(org.motechproject.mds.domain.Entity) ArrayList(java.util.ArrayList) RestOptions(org.motechproject.mds.domain.RestOptions) Time(org.motechproject.commons.date.model.Time) DateTime(org.joda.time.DateTime) LocalDate(org.joda.time.LocalDate) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) Field(org.motechproject.mds.domain.Field) Lookup(org.motechproject.mds.domain.Lookup)

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