Search in sources :

Example 61 with Field

use of org.motechproject.mds.domain.Field in project motech by motech.

the class EntityHelper method removeAdditionalFieldsAndLookups.

/**
 * In case of DDE, removes all fields and lookups that are not part of the original schema (was added later).
 * In case of EUDE, removes all fields and lookups.
 * @param entity entity to remove fields and lookups from
 */
public static void removeAdditionalFieldsAndLookups(Entity entity) {
    Iterator<Field> fieldIterator = entity.getFields().iterator();
    while (fieldIterator.hasNext()) {
        Field field = fieldIterator.next();
        if (!field.isAutoGenerated() && !field.isReadOnly()) {
            fieldIterator.remove();
        }
    }
    Iterator<Lookup> lookupIterator = entity.getLookups().iterator();
    while (lookupIterator.hasNext()) {
        Lookup lookup = lookupIterator.next();
        if (!lookup.isReadOnly()) {
            lookupIterator.remove();
        }
    }
}
Also used : Field(org.motechproject.mds.domain.Field) Lookup(org.motechproject.mds.domain.Lookup)

Example 62 with Field

use of org.motechproject.mds.domain.Field in project motech by motech.

the class EntityWriter method writeFields.

private void writeFields() throws IOException {
    jsonWriter.name("fields");
    jsonWriter.beginArray();
    for (Field field : entity.getFields()) {
        if (!field.isReadOnly()) {
            fieldWriter.writeField(field);
        }
    }
    jsonWriter.endArray();
}
Also used : Field(org.motechproject.mds.domain.Field)

Example 63 with Field

use of org.motechproject.mds.domain.Field in project motech by motech.

the class EntityServiceImpl method addFilterableFields.

@Override
@Transactional
public void addFilterableFields(EntityDto entityDto, Collection<String> fieldNames) {
    Entity entity = allEntities.retrieveById(entityDto.getId());
    assertEntityExists(entity, entityDto.getId());
    for (Field field : entity.getFields()) {
        if (!field.isUiChanged()) {
            field.setUIFilterable(fieldNames.contains(field.getName()));
        }
    }
}
Also used : MdsEntity(org.motechproject.mds.domain.MdsEntity) Entity(org.motechproject.mds.domain.Entity) MdsVersionedEntity(org.motechproject.mds.domain.MdsVersionedEntity) Field(org.motechproject.mds.domain.Field) Transactional(org.springframework.transaction.annotation.Transactional)

Example 64 with Field

use of org.motechproject.mds.domain.Field in project motech by motech.

the class EntityServiceImpl method findEntityFieldByName.

@Override
@Transactional
public FieldDto findEntityFieldByName(Long entityId, String name) {
    Entity entity = allEntities.retrieveById(entityId);
    Field field = entity.getField(name);
    if (field == null) {
        throw new FieldNotFoundException(entity.getClassName(), name);
    }
    return field.toDto();
}
Also used : MdsEntity(org.motechproject.mds.domain.MdsEntity) Entity(org.motechproject.mds.domain.Entity) MdsVersionedEntity(org.motechproject.mds.domain.MdsVersionedEntity) Field(org.motechproject.mds.domain.Field) FieldNotFoundException(org.motechproject.mds.exception.field.FieldNotFoundException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 65 with Field

use of org.motechproject.mds.domain.Field in project motech by motech.

the class EntityServiceImpl method addFields.

@Override
@Transactional
public void addFields(Long entityId, Collection<FieldDto> fields) {
    Entity entity = allEntities.retrieveById(entityId);
    assertEntityExists(entity, entityId);
    removeFields(entity, fields);
    for (FieldDto fieldDto : fields) {
        Field existing = entity.getField(fieldDto.getBasic().getName());
        if (null != existing) {
            existing.update(fieldDto);
        } else {
            addField(entity, fieldDto);
        }
    }
}
Also used : MdsEntity(org.motechproject.mds.domain.MdsEntity) Entity(org.motechproject.mds.domain.Entity) MdsVersionedEntity(org.motechproject.mds.domain.MdsVersionedEntity) Field(org.motechproject.mds.domain.Field) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Field (org.motechproject.mds.domain.Field)73 Entity (org.motechproject.mds.domain.Entity)33 Test (org.junit.Test)24 Lookup (org.motechproject.mds.domain.Lookup)16 MdsEntity (org.motechproject.mds.domain.MdsEntity)15 MdsVersionedEntity (org.motechproject.mds.domain.MdsVersionedEntity)15 Type (org.motechproject.mds.domain.Type)14 ArrayList (java.util.ArrayList)13 Transactional (org.springframework.transaction.annotation.Transactional)13 FieldDto (org.motechproject.mds.dto.FieldDto)12 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)12 HashSet (java.util.HashSet)8 Matchers.anyString (org.mockito.Matchers.anyString)6 FieldSetting (org.motechproject.mds.domain.FieldSetting)6 TypeSetting (org.motechproject.mds.domain.TypeSetting)6 UserPreferences (org.motechproject.mds.domain.UserPreferences)5 EntityDto (org.motechproject.mds.dto.EntityDto)5 AllUserPreferences (org.motechproject.mds.repository.internal.AllUserPreferences)5 FieldMetadata (org.motechproject.mds.domain.FieldMetadata)4 LookupDto (org.motechproject.mds.dto.LookupDto)4