use of org.motechproject.mds.dto.EntityDto in project motech by motech.
the class EntityServiceContextIT method shouldAddLookups.
@Test
public void shouldAddLookups() throws IOException {
EntityDto entityDto = new EntityDto();
entityDto.setName("LookupTestEnt");
entityDto = entityService.createEntity(entityDto);
FieldDto boolField = FieldTestHelper.fieldDto("boolField", Boolean.class);
FieldDto dtField = FieldTestHelper.fieldDto("dtField", DateTime.class);
FieldDto strField = FieldTestHelper.fieldDto("strField", String.class);
entityService.addFields(entityDto, asList(boolField, dtField, strField));
List<LookupFieldDto> lookupFieldDtos = lookupFieldsFromNames("boolField", "dtField", "strField");
lookupFieldDtos.get(1).setType(RANGE);
lookupFieldDtos.get(2).setType(SET);
LookupDto lookup = new LookupDto("lookup", false, false, lookupFieldDtos, true);
entityService.addLookups(entityDto.getId(), asList(lookup));
LookupDto lookupFromDb = entityService.getLookupByName(entityDto.getId(), "lookup");
assertNotNull(lookupFromDb);
assertEquals("lookup", lookupFromDb.getLookupName());
assertEquals("lookup", lookupFromDb.getMethodName());
assertEquals(asList("boolField", "dtField", "strField"), extract(lookupFromDb.getLookupFields(), on(LookupFieldDto.class).getName()));
assertEquals(asList(VALUE, RANGE, SET), extract(lookupFromDb.getLookupFields(), on(LookupFieldDto.class).getType()));
assertEquals(asList("boolField", "dtField", "strField"), lookupFromDb.getFieldsOrder());
}
use of org.motechproject.mds.dto.EntityDto in project motech by motech.
the class EntityServiceContextIT method shouldRetrieveAllEntities.
@Test
public void shouldRetrieveAllEntities() throws IOException {
entityService.createEntity(new EntityDto(null, null, SIMPLE_NAME_2, null, null, SecurityMode.EVERYONE, null));
entityService.createEntity(new EntityDto(null, null, SIMPLE_NAME_3, null, null, SecurityMode.EVERYONE, null));
List<EntityDto> result = entityService.listEntities();
List<String> expected = asList(SIMPLE_NAME_2, SIMPLE_NAME_3);
List<String> actual = extract(result, on(EntityDto.class).getName());
Collections.sort(expected);
Collections.sort(actual);
assertEquals(expected, actual);
}
use of org.motechproject.mds.dto.EntityDto in project motech by motech.
the class EntityServiceContextIT method shouldNotSaveEntityOfTheSameName.
@Test(expected = EntityAlreadyExistException.class)
public void shouldNotSaveEntityOfTheSameName() throws IOException {
String testEntityName1 = "TestEntity";
String testEntityName2 = "TeStEnTiTy";
EntityDto entityDto1 = new EntityDto();
entityDto1.setName(testEntityName1);
EntityDto entityDto2 = new EntityDto();
entityDto2.setName(testEntityName2);
entityService.createEntity(entityDto1);
entityService.createEntity(entityDto2);
}
use of org.motechproject.mds.dto.EntityDto in project motech by motech.
the class EntityServiceContextIT method shouldUpdateRestOptions.
@Test
public void shouldUpdateRestOptions() throws IOException {
// given
EntityDto entityDto = new EntityDto();
entityDto.setName("RestTestEnt");
entityDto = entityService.createEntity(entityDto);
FieldDto boolField = FieldTestHelper.fieldDto("boolField", Boolean.class);
FieldDto dtField = FieldTestHelper.fieldDto("dtField", DateTime.class);
FieldDto strField = FieldTestHelper.fieldDto("strField", String.class);
entityService.addFields(entityDto, asList(boolField, dtField, strField));
List<LookupFieldDto> lookupFieldDtos = lookupFieldsFromNames("boolField", "dtField", "strField");
LookupDto lookup = new LookupDto("lookup", false, false, lookupFieldDtos, true);
List<LookupFieldDto> strLookupFieldDtos = lookupFieldsFromNames("strField");
LookupDto strLookup = new LookupDto("strLookup", false, false, strLookupFieldDtos, true);
entityService.addLookups(entityDto.getId(), asList(lookup, strLookup));
RestOptionsDto restOptionsDto = new RestOptionsDto(true, false, true, false, false);
restOptionsDto.addField("boolField");
restOptionsDto.addField("strField");
restOptionsDto.addLookup("strLookup");
// when
entityService.updateRestOptions(entityDto.getId(), restOptionsDto);
// then
AdvancedSettingsDto advancedSettingsDto = entityService.getAdvancedSettings(entityDto.getId(), true);
RestOptionsDto fromDb = advancedSettingsDto.getRestOptions();
assertTrue(fromDb.isCreate());
assertFalse(fromDb.isRead());
assertTrue(fromDb.isUpdate());
assertFalse(fromDb.isDelete());
assertEquals(asList("strLookup"), fromDb.getLookupNames());
assertEquals(asList("boolField", "strField"), fromDb.getFieldNames());
}
use of org.motechproject.mds.dto.EntityDto in project motech by motech.
the class EntityServiceContextIT method testRelatedFieldGenerationForManyToManyRelationship.
@Test
public void testRelatedFieldGenerationForManyToManyRelationship() {
EntityDto entityDto1 = new EntityDto();
entityDto1.setName("RelationTestEnt1");
entityDto1 = entityService.createEntity(entityDto1);
EntityDto entityDto2 = new EntityDto();
entityDto2.setName("RelationTestEnt2");
entityDto2 = entityService.createEntity(entityDto2);
EntityDto entityDto3 = new EntityDto();
entityDto3.setName("RelationTestEnt3");
entityDto3 = entityService.createEntity(entityDto3);
EntityDraft entityDraft1 = entityService.getEntityDraft(entityDto1.getId());
Set<Lookup> fieldLookups = new HashSet<>();
Field field = new Field(entityDraft1, "newField", "Display Name", fieldLookups);
Type type = allTypes.retrieveByClassName(TypeDto.MANY_TO_MANY_RELATIONSHIP.getTypeClass());
field.setType(type);
if (type.hasSettings()) {
for (TypeSetting setting : type.getSettings()) {
field.addSetting(new FieldSetting(field, setting));
}
}
FieldMetadata metadata = new FieldMetadata(field, RELATED_CLASS);
metadata.setValue(entityDto2.getClassName());
field.addMetadata(metadata);
metadata = new FieldMetadata(field, RELATIONSHIP_COLLECTION_TYPE);
metadata.setValue("java.util.Set");
field.addMetadata(metadata);
metadata = new FieldMetadata(field, RELATED_FIELD);
metadata.setValue("relatedField");
field.addMetadata(metadata);
metadata = new FieldMetadata(field, OWNING_SIDE);
metadata.setValue("true");
entityDraft1.addField(field);
allEntityDrafts.update(entityDraft1);
entityService.commitChanges(entityDto1.getId());
FieldDto relatedField = getField(entityDto2.getId(), "relatedField");
// Changing related class
entityDraft1 = entityService.getEntityDraft(entityDto1.getId());
DraftData draftData = DraftBuilder.forFieldEdit(entityDraft1.getField("newField").getId(), "metadata.0.value", entityDto3.getClassName());
entityService.saveDraftEntityChanges(entityDto1.getId(), draftData);
entityService.commitChanges(entityDto1.getId());
// We changed related entity, so the old related entity field must be removed
relatedField = getField(entityDto2.getId(), "relatedField");
assertNull(relatedField);
relatedField = getField(entityDto3.getId(), "relatedField");
assertRelatedField(entityDto1, relatedField, "java.util.Set");
entityDraft1 = entityService.getEntityDraft(entityDto1.getId());
draftData = DraftBuilder.forFieldEdit(entityDraft1.getField("newField").getId(), "metadata.1.value", "java.util.List");
entityService.saveDraftEntityChanges(entityDto1.getId(), draftData);
draftData = DraftBuilder.forFieldEdit(entityDraft1.getField("newField").getId(), "metadata.2.value", "newNameForRelatedField");
entityService.saveDraftEntityChanges(entityDto1.getId(), draftData);
entityService.commitChanges(entityDto1.getId());
relatedField = getField(entityDto3.getId(), "newNameForRelatedField");
assertRelatedField(entityDto1, relatedField, "java.util.List");
}
Aggregations