use of org.motechproject.mds.domain.Field in project motech by motech.
the class InstancesReader method importInstance.
public void importInstance() throws IOException {
try {
Object instance = dataService.getClassType().newInstance();
Long refId = null;
jsonReader.beginObject();
while (jsonReader.hasNext()) {
String fieldName = objectReader.readName();
if ("refId".equals(fieldName)) {
refId = jsonReader.nextLong();
} else {
Field field = entity.getField(fieldName);
readProperty(instance, field);
}
}
jsonReader.endObject();
if (null != refId) {
importContext.putInstanceOfEntity(entity.getClassName(), refId, dataService.create(instance));
}
} catch (InstantiationException | IllegalAccessException e) {
LOGGER.error("Exception occurred during importing instances", e);
}
}
use of org.motechproject.mds.domain.Field in project motech by motech.
the class EntityReader method readDataBrowsingDisplayFields.
private void readDataBrowsingDisplayFields() throws IOException {
List<String> displayFieldsNames = objectReader.readStringArray("fields");
for (Field field : entity.getFields()) {
long uiDisplayPosition = displayFieldsNames.indexOf(field.getName());
field.setUIDisplayable(uiDisplayPosition >= 0);
field.setUIDisplayPosition(uiDisplayPosition);
}
}
use of org.motechproject.mds.domain.Field in project motech by motech.
the class SwaggerGenerator method buildDefinitionProperties.
private void buildDefinitionProperties(Map<String, Property> properties, List<String> required, Entity entity, boolean includeAuto, boolean includeId) {
if (includeId) {
properties.put(Constants.Util.ID_FIELD_NAME, new Property(INTEGER_TYPE, INT64_FORMAT));
}
for (Field field : entity.getFields()) {
final String fieldName = field.getName();
if (field.isExposedViaRest()) {
// auto generated fields included only in responses
if (!field.isAutoGenerated() || includeAuto) {
Property property = SwaggerFieldConverter.fieldToProperty(field);
properties.put(fieldName, property);
if (field.isRequired()) {
required.add(fieldName);
}
}
}
}
}
use of org.motechproject.mds.domain.Field in project motech by motech.
the class EntityServiceImpl method getLookupFieldsMapping.
@Override
@Transactional
public Map<String, FieldDto> getLookupFieldsMapping(Long entityId, String lookupName) {
Entity entity = allEntities.retrieveById(entityId);
assertEntityExists(entity, entityId);
Lookup lookup = entity.getLookupByName(lookupName);
if (lookup == null) {
throw new LookupNotFoundException(entity.getName(), lookupName);
}
Map<String, FieldDto> fieldMap = new HashMap<>();
for (String lookupFieldName : lookup.getFieldsOrder()) {
Field field = lookup.getLookupFieldByName(LookupName.getFieldName(lookupFieldName));
if (lookupFieldName.contains(".")) {
Entity relatedEntity = allEntities.retrieveByClassName(field.getMetadata(Constants.MetadataKeys.RELATED_CLASS).getValue());
field = relatedEntity.getField(LookupName.getRelatedFieldName(lookupFieldName));
}
fieldMap.put(lookupFieldName, field.toDto());
}
return fieldMap;
}
use of org.motechproject.mds.domain.Field in project motech by motech.
the class EntityServiceImpl method createFieldForDraft.
private void createFieldForDraft(EntityDraft draft, DraftData draftData) {
String typeClass = draftData.getValue(DraftData.TYPE_CLASS).toString();
String displayName = draftData.getValue(DraftData.DISPLAY_NAME).toString();
String name = draftData.getValue(DraftData.NAME).toString();
Type type = ("textArea".equalsIgnoreCase(typeClass)) ? allTypes.retrieveByClassName("java.lang.String") : allTypes.retrieveByClassName(typeClass);
if (type == null) {
throw new NoSuchTypeException(typeClass);
}
Set<Lookup> fieldLookups = new HashSet<>();
Field field = new Field(draft, name, displayName, fieldLookups);
field.setType(type);
if (type.hasSettings()) {
for (TypeSetting setting : type.getSettings()) {
field.addSetting(new FieldSetting(field, setting));
}
}
if (type.hasValidation()) {
for (TypeValidation validation : type.getValidations()) {
field.addValidation(new FieldValidation(field, validation));
}
}
if (TypeDto.BLOB.getTypeClass().equals(typeClass)) {
field.setUIDisplayable(false);
} else {
field.setUIDisplayable(true);
field.setUIDisplayPosition((long) draft.getFields().size());
}
if ("textArea".equalsIgnoreCase(typeClass)) {
setSettingForTextArea(field);
}
FieldHelper.addMetadataForRelationship(typeClass, field);
FieldHelper.addOrUpdateMetadataForCombobox(field);
draft.addField(field);
allEntityDrafts.update(draft);
}
Aggregations