use of org.motechproject.mds.dto.LookupDto in project motech by motech.
the class Entity method advancedSettingsDto.
@NotPersistent
public AdvancedSettingsDto advancedSettingsDto() {
AdvancedSettingsDto advancedSettingsDto = new AdvancedSettingsDto();
RestOptionsDto restDto;
if (null == restOptions) {
restDto = new RestOptions(this).toDto();
} else {
restDto = restOptions.toDto();
}
List<LookupDto> indexes = new ArrayList<>();
for (Lookup lookup : getLookups()) {
indexes.add(lookup.toDto());
}
Tracking trackingMapping = getTracking();
TrackingDto trackingDto = (trackingMapping == null) ? new TrackingDto() : trackingMapping.toDto();
advancedSettingsDto.setIndexes(indexes);
advancedSettingsDto.setEntityId(getId());
advancedSettingsDto.setBrowsing(getBrowsingSettings().toDto());
advancedSettingsDto.setRestOptions(restDto);
advancedSettingsDto.setTracking(trackingDto);
return advancedSettingsDto;
}
use of org.motechproject.mds.dto.LookupDto in project motech by motech.
the class EntityServiceImpl method addNonPersistentDataForLookupFields.
private void addNonPersistentDataForLookupFields(Collection<LookupDto> lookupDtos, Entity entity) {
for (LookupDto lookup : lookupDtos) {
for (LookupFieldDto lookupField : lookup.getLookupFields()) {
Field field = entity.getField(lookupField.getName());
if (StringUtils.isNotBlank(lookupField.getRelatedName())) {
Entity relatedEntity = allEntities.retrieveByClassName(field.getMetadata(Constants.MetadataKeys.RELATED_CLASS).getValue());
Field relatedField = relatedEntity.getField(lookupField.getRelatedName());
addNonPersistentDataForLookupField(relatedField, lookupField, field.getDisplayName(), relatedField.getDisplayName());
} else {
addNonPersistentDataForLookupField(field, lookupField, field.getDisplayName(), null);
}
}
}
}
use of org.motechproject.mds.dto.LookupDto in project motech by motech.
the class EntityServiceImpl method editFieldForDraft.
private void editFieldForDraft(EntityDraft draft, DraftData draftData) {
String fieldIdStr = draftData.getValue(DraftData.FIELD_ID).toString();
if (StringUtils.isNotBlank(fieldIdStr)) {
Long fieldId = Long.valueOf(fieldIdStr);
Field field = draft.getField(fieldId);
if (field != null) {
String path = draftData.getPath();
List value = (List) draftData.getValue(DraftData.VALUE);
// Convert to dto for UI updates
FieldDto dto = field.toDto();
dto.setUiChanged(true);
FieldHelper.setField(dto, path, value);
// If field name was changed add this change to map
if (NAME_PATH.equals(path)) {
draft.addFieldNameChange(field.getName(), value.get(0).toString());
List<LookupDto> lookups = draft.advancedSettingsDto().getIndexes();
// Perform update
field.update(dto);
// we need update fields name in lookup fieldsOrder
draft.updateIndexes(lookups);
FieldHelper.addOrUpdateMetadataForCombobox(field);
} else if (UNIQUE_PATH.equals(path)) {
// check if unique was removed on this field
boolean originalUnique = false;
Field originalField = draft.getParentEntity().getField(field.getName());
if (originalField != null) {
originalUnique = originalField.isUnique();
}
boolean newVal = (boolean) value.get(0);
if (originalUnique && !newVal) {
// we will be dropping the unique constraint for this field
draft.addUniqueToRemove(field.getName());
}
// Perform update
field.update(dto);
} else if (REQUIRED_PATH.equals(path)) {
Field originalField = draft.getParentEntity().getField(field.getName());
handleRequiredChanges(originalField, draft, value, field);
// Perform update
field.update(dto);
} else {
// Perform update
field.update(dto);
}
allEntityDrafts.update(draft);
}
}
}
use of org.motechproject.mds.dto.LookupDto in project motech by motech.
the class EntityServiceImpl method getLookups.
private List<LookupDto> getLookups(Long entityId, boolean forDraft) {
Entity entity = (forDraft) ? getEntityDraft(entityId) : allEntities.retrieveById(entityId);
assertEntityExists(entity, entityId);
List<LookupDto> lookupDtos = new ArrayList<>();
for (Lookup lookup : entity.getLookups()) {
lookupDtos.add(lookup.toDto());
}
return lookupDtos;
}
use of org.motechproject.mds.dto.LookupDto in project motech by motech.
the class MdsBundleIT method prepareTestEntities.
private void prepareTestEntities() throws IOException {
getLogger().info("Preparing entities for testing");
EntityDto entityDto = new EntityDto(9999L, FOO);
entityDto = entityService.createEntity(entityDto);
SchemaHolder schemaHolder = entityService.getSchema();
generator.regenerateMdsDataBundle(schemaHolder);
List<FieldDto> fields = new ArrayList<>();
fields.add(new FieldDto(null, entityDto.getId(), TypeDto.BOOLEAN, new FieldBasicDto("Some Boolean", "someBoolean"), false, null));
// this field is unique
fields.add(new FieldDto(null, entityDto.getId(), TypeDto.STRING, new FieldBasicDto("Some String", "someString", false, true), false, null, null, asList(new SettingDto("mds.form.label.textarea", false, BOOLEAN)), null));
// test with capitalized name
fields.add(new FieldDto(null, entityDto.getId(), TypeDto.STRING, new FieldBasicDto("Capital Name", "CapitalName"), false, null, null, asList(new SettingDto("mds.form.label.textarea", false, BOOLEAN)), null));
fields.add(new FieldDto(null, entityDto.getId(), COLLECTION, new FieldBasicDto("Some List", "someList"), false, null, null, asList(new SettingDto(Constants.Settings.COMBOBOX_VALUES, new LinkedList<>(), COLLECTION, REQUIRE), new SettingDto(Constants.Settings.ALLOW_USER_SUPPLIED, true, BOOLEAN), new SettingDto(Constants.Settings.ALLOW_MULTIPLE_SELECTIONS, true, BOOLEAN)), null));
fields.add(new FieldDto(null, entityDto.getId(), TypeDto.DATETIME, new FieldBasicDto("dateTime", "someDateTime"), false, null));
fields.add(new FieldDto(null, entityDto.getId(), TypeDto.DATETIME8, new FieldBasicDto("someJavaDateTime", "someJavaDateTime"), false, null));
fields.add(new FieldDto(null, entityDto.getId(), TypeDto.MAP, new FieldBasicDto("someMap", "someMap"), false, Arrays.asList(new MetadataDto(MAP_KEY_TYPE, String.class.getName()), new MetadataDto(MAP_VALUE_TYPE, TestClass.class.getName())), null, null, null));
fields.add(new FieldDto(null, entityDto.getId(), TypeDto.PERIOD, new FieldBasicDto("somePeriod", "somePeriod"), false, null));
fields.add(new FieldDto(null, entityDto.getId(), TypeDto.BLOB, new FieldBasicDto("someBlob", "someBlob"), false, null));
fields.add(new FieldDto(null, entityDto.getId(), TypeDto.LOCAL_DATE, new FieldBasicDto("someLocalDate", "someLocalDate"), false, null));
fields.add(new FieldDto(null, entityDto.getId(), TypeDto.LOCAL_DATE8, new FieldBasicDto("someJavaDate", "someJavaDate"), false, null));
fields.add(new FieldDto(null, entityDto.getId(), TypeDto.DATE, new FieldBasicDto("someDate", "someDate"), false, null));
fields.add(new FieldDto(null, entityDto.getId(), TypeDto.TIME, new FieldBasicDto("someTime", "someTime"), false, null));
List<SettingDto> decimalSettings = asList(new SettingDto("mds.form.label.precision", 10), new SettingDto("mds.form.label.scale", 5));
fields.add(new FieldDto(null, entityDto.getId(), TypeDto.DOUBLE, new FieldBasicDto("Some Decimal", "someDecimal"), false, null, null, decimalSettings, null));
fields.add(new FieldDto(null, entityDto.getId(), TypeDto.INTEGER, new FieldBasicDto("someInteger", "someInt"), false, null));
fields.add(new FieldDto(null, entityDto.getId(), TypeDto.COLLECTION, new FieldBasicDto("Some Enum", "someEnum"), false, null, null, asList(new SettingDto(Constants.Settings.COMBOBOX_VALUES, asList("one", "two", "three"), COLLECTION, REQUIRE), new SettingDto(Constants.Settings.ALLOW_USER_SUPPLIED, false, BOOLEAN), new SettingDto(Constants.Settings.ALLOW_MULTIPLE_SELECTIONS, false, BOOLEAN)), null));
entityService.addFields(entityDto, fields);
List<LookupDto> lookups = new ArrayList<>();
List<LookupFieldDto> lookupFields = new ArrayList<>();
lookupFields.add(new LookupFieldDto(null, "someBoolean", LookupFieldType.VALUE));
lookups.add(new LookupDto("By boolean", false, false, lookupFields, true, "byBool", asList("someBoolean")));
lookupFields = new ArrayList<>();
lookupFields.add(new LookupFieldDto(null, "someString", LookupFieldType.VALUE));
lookups.add(new LookupDto("By unique String", true, false, lookupFields, true, "byUniqueString", asList("someString")));
lookupFields = new ArrayList<>();
lookupFields.add(new LookupFieldDto(null, "someBoolean", LookupFieldType.VALUE));
lookupFields.add(new LookupFieldDto(null, "someDateTime", LookupFieldType.RANGE));
lookupFields.add(new LookupFieldDto(null, "someString", LookupFieldType.SET));
lookupFields.add(new LookupFieldDto(null, "someList", LookupFieldType.VALUE));
lookups.add(new LookupDto("Combined", false, false, lookupFields, true));
lookupFields = new ArrayList<>();
lookupFields.add(new LookupFieldDto(null, "someInt", LookupFieldType.VALUE, "<="));
lookups.add(new LookupDto("With custom operator", false, false, lookupFields, true, "customOperator", asList("someInt")));
lookupFields = new ArrayList<>();
lookupFields.add(new LookupFieldDto(null, "someString", LookupFieldType.VALUE, "matches()"));
lookups.add(new LookupDto("With matches", false, false, lookupFields, true, "matchesOperator", asList("someString")));
lookupFields = new ArrayList<>();
lookupFields.add(new LookupFieldDto(null, "someString", LookupFieldType.VALUE, Constants.Operators.MATCHES_CASE_INSENSITIVE));
lookups.add(new LookupDto("With matches case insensitive", false, false, lookupFields, true, "matchesOperatorCI", singletonList("someString")));
entityService.addLookups(entityDto.getId(), lookups);
schemaHolder = entityService.getSchema();
generator.regenerateMdsDataBundle(schemaHolder);
getLogger().info("Entities ready for testing");
}
Aggregations