Search in sources :

Example 91 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class EntityServiceContextIT method shouldFindEntitiesByPackage.

@Test
public void shouldFindEntitiesByPackage() {
    entityService.createEntity(new EntityDto(null, "org.motechproject.ivr.Test", SIMPLE_NAME, null, null, SecurityMode.EVERYONE, null));
    entityService.createEntity(new EntityDto(null, "org.motechproject.csd.domain.Address", "Address", null, null, SecurityMode.EVERYONE, null));
    entityService.createEntity(new EntityDto(null, "org.motechproject.csd.another.Provider", "Provider", null, null, SecurityMode.EVERYONE, null));
    List<EntityDto> entities = entityService.findEntitiesByPackage("org.motechproject.csd");
    assertNotNull(entities);
    List<String> result = extract(entities, on(EntityDto.class).getName());
    Collections.sort(result);
    assertEquals(asList("Address", "Provider"), result);
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) Test(org.junit.Test)

Example 92 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class EntityServiceContextIT method shouldFindEntitiesByBundle.

@Test
public void shouldFindEntitiesByBundle() {
    EntityDto lessons = new EntityDto(null, "org.motechproject.mtraining.domain.Lesson", "Lesson", "mtraining", null, SecurityMode.EVERYONE, null);
    lessons.setBundleSymbolicName("org.motechproject.mtraining");
    entityService.createEntity(lessons);
    EntityDto chapters = new EntityDto(null, "org.motechproject.mtraining.domain.Chapter", "Chapter", "mtraining", null, SecurityMode.EVERYONE, null);
    chapters.setBundleSymbolicName("org.motechproject.mtraining");
    entityService.createEntity(chapters);
    EntityDto wrong = new EntityDto(null, "org.motechproject.mtraining.domain.Wrong", "Chapter", "mtraining", null, SecurityMode.EVERYONE, null);
    wrong.setBundleSymbolicName("org.motechproject.other");
    entityService.createEntity(wrong);
    List<EntityDto> entities = entityService.listEntitiesByBundle("org.motechproject.mtraining");
    assertNotNull(entities);
    List<String> result = extract(entities, on(EntityDto.class).getName());
    Collections.sort(result);
    assertEquals(asList("Chapter", "Lesson"), result);
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) Test(org.junit.Test)

Example 93 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class EntityServiceContextIT method shouldUpdateFetchDepth.

@Test
public void shouldUpdateFetchDepth() {
    EntityDto entityDto = new EntityDto();
    entityDto.setName("FetchDepthTest");
    entityDto = entityService.createEntity(entityDto);
    assertNull(entityDto.getMaxFetchDepth());
    entityService.updateMaxFetchDepth(entityDto.getId(), 3);
    entityDto = entityService.getEntity(entityDto.getId());
    assertEquals(Integer.valueOf(3), entityDto.getMaxFetchDepth());
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) Test(org.junit.Test)

Example 94 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class EntityServiceContextIT method shouldAddLookupWithRelatedField.

@Test
public void shouldAddLookupWithRelatedField() {
    EntityDto entityWithLookup = new EntityDto();
    entityWithLookup.setName("entityWithLookup");
    entityWithLookup = entityService.createEntity(entityWithLookup);
    EntityDto relatedEntity = new EntityDto();
    relatedEntity.setName("relatedEntity");
    relatedEntity = entityService.createEntity(relatedEntity);
    FieldDto stringField = FieldTestHelper.fieldDto("stringField", String.class);
    FieldDto nameField = FieldTestHelper.fieldDto("nameField", String.class);
    FieldDto lengthField = FieldTestHelper.fieldDto("lengthField", Long.class);
    FieldDto relationField = FieldTestHelper.fieldDto("relatedField", TypeDto.ONE_TO_MANY_RELATIONSHIP.getTypeClass());
    relationField.addMetadata(new MetadataDto(RELATED_CLASS, relatedEntity.getClassName()));
    entityService.addFields(entityWithLookup, asList(stringField, relationField));
    entityService.addFields(relatedEntity, asList(nameField, lengthField));
    List<LookupFieldDto> lookupFieldDtos = lookupFieldsFromNames("relatedField.nameField", "relatedField.lengthField", "stringField");
    LookupDto lookup = new LookupDto("lookup", false, false, lookupFieldDtos, true);
    entityService.addLookups(entityWithLookup.getId(), lookup);
    LookupDto lookupFromDb = entityService.getLookupByName(entityWithLookup.getId(), "lookup");
    assertNotNull(lookupFromDb);
    assertEquals(asList("relatedField.nameField", "relatedField.lengthField", "stringField"), lookupFromDb.getFieldsOrder());
    assertEquals(asList("relatedField", "relatedField", "stringField"), extract(lookupFromDb.getLookupFields(), on(LookupFieldDto.class).getName()));
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) LookupDto(org.motechproject.mds.dto.LookupDto) MetadataDto(org.motechproject.mds.dto.MetadataDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) Test(org.junit.Test)

Example 95 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class EntityServiceContextIT method shouldAddNewFieldForLookupAndSaveEntity.

@Test
public void shouldAddNewFieldForLookupAndSaveEntity() throws IOException {
    EntityDto entityDto = new EntityDto();
    entityDto.setName("myEntity");
    entityDto = entityService.createEntity(entityDto);
    // add a new field to draft
    EntityDraft entityDraft = entityService.getEntityDraft(entityDto.getId());
    entityService.saveDraftEntityChanges(entityDraft.getId(), DraftBuilder.forNewField("disp", "testFieldName", Long.class.getName()));
    FieldDto field = selectFirst(entityService.getFields(entityDraft.getId()), having(on(FieldDto.class).getBasic().getName(), equalTo("testFieldName")));
    LookupDto lookup = new LookupDto("lookup", false, false, null, true);
    entityService.addLookups(entityDraft.getId(), Collections.singletonList(lookup));
    Map<String, Object> values = new HashMap<>();
    values.put("path", "indexes.0.$addField");
    values.put("advanced", true);
    values.put("value", Collections.singletonList(field.getId()));
    DraftData draftData = new DraftData();
    draftData.setEdit(true);
    draftData.setValues(values);
    entityService.saveDraftEntityChanges(entityDraft.getId(), draftData);
    entityService.commitChanges(entityDto.getId());
    assertNotNull(entityService.getLookupByName(entityDto.getId(), "lookup").getLookupField("testFieldName"));
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) HashMap(java.util.HashMap) LookupDto(org.motechproject.mds.dto.LookupDto) DraftData(org.motechproject.mds.dto.DraftData) EntityDraft(org.motechproject.mds.domain.EntityDraft) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) Test(org.junit.Test)

Aggregations

EntityDto (org.motechproject.mds.dto.EntityDto)136 Test (org.junit.Test)61 FieldDto (org.motechproject.mds.dto.FieldDto)53 ArrayList (java.util.ArrayList)34 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)32 MotechDataService (org.motechproject.mds.service.MotechDataService)26 LookupDto (org.motechproject.mds.dto.LookupDto)24 List (java.util.List)19 BasicEntityRecord (org.motechproject.mds.web.domain.BasicEntityRecord)12 Method (java.lang.reflect.Method)11 FieldTestHelper.lookupFieldDto (org.motechproject.mds.testutil.FieldTestHelper.lookupFieldDto)11 Arrays.asList (java.util.Arrays.asList)9 FieldBasicDto (org.motechproject.mds.dto.FieldBasicDto)9 EntityRecord (org.motechproject.mds.web.domain.EntityRecord)9 AdvancedSettingsDto (org.motechproject.mds.dto.AdvancedSettingsDto)7 TypeDto (org.motechproject.mds.dto.TypeDto)7 HashMap (java.util.HashMap)6 SchemaHolder (org.motechproject.mds.dto.SchemaHolder)6 BasicFieldRecord (org.motechproject.mds.web.domain.BasicFieldRecord)6 FieldRecord (org.motechproject.mds.web.domain.FieldRecord)6