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);
}
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);
}
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());
}
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()));
}
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"));
}
Aggregations