Search in sources :

Example 21 with Entity

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

the class EntityServiceImpl method addNonEditableFields.

@Override
@Transactional
public void addNonEditableFields(EntityDto entityDto, Map<String, Boolean> nonEditableFields) {
    Entity entity = allEntities.retrieveById(entityDto.getId());
    assertEntityExists(entity, entityDto.getId());
    List<Field> fields = entity.getFields();
    for (Field field : fields) {
        boolean isNonEditable = nonEditableFields.containsKey(field.getName());
        Boolean display = nonEditableFields.get(field.getName());
        field.setNonEditable(isNonEditable);
        if (display != null) {
            field.setNonDisplayable(!display);
        } else {
            field.setNonDisplayable(false);
        }
    }
}
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 22 with Entity

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

the class EntityServiceImpl method getDisplayFields.

@Override
@Transactional
public List<FieldDto> getDisplayFields(Long entityId) {
    Entity entity = allEntities.retrieveById(entityId);
    assertEntityExists(entity, entityId);
    List<Field> displayFields = new ArrayList<>(entity.getFields());
    CollectionUtils.filter(displayFields, new Predicate() {

        @Override
        public boolean evaluate(Object object) {
            Field field = (Field) object;
            return field.isUIDisplayable() && !field.isNonDisplayable();
        }
    });
    return toFieldDtos(entity, displayFields, true);
}
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) ArrayList(java.util.ArrayList) Predicate(org.apache.commons.collections.Predicate) Transactional(org.springframework.transaction.annotation.Transactional)

Example 23 with Entity

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

the class EntityServiceImpl method addLookups.

@Override
@Transactional
public void addLookups(Long entityId, Collection<LookupDto> lookups) {
    Entity entity = allEntities.retrieveById(entityId);
    assertEntityExists(entity, entityId);
    removeLookup(entity, lookups);
    addOrUpdateLookups(entity, lookups);
}
Also used : MdsEntity(org.motechproject.mds.domain.MdsEntity) Entity(org.motechproject.mds.domain.Entity) MdsVersionedEntity(org.motechproject.mds.domain.MdsVersionedEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 24 with Entity

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

the class EntityServiceImpl method removeRelatedFields.

private void removeRelatedFields(List<Field> fields, List<String> modulesToRefresh) {
    for (Field field : fields) {
        Entity entity = allEntities.retrieveByClassName(field.getMetadataValue(RELATED_CLASS));
        Field relatedField = entity.getField(field.getMetadataValue(RELATED_FIELD));
        entity.removeField(relatedField.getId());
        entity.incrementVersion();
        addModuleToRefresh(entity, modulesToRefresh);
    }
}
Also used : Field(org.motechproject.mds.domain.Field) MdsEntity(org.motechproject.mds.domain.MdsEntity) Entity(org.motechproject.mds.domain.Entity) MdsVersionedEntity(org.motechproject.mds.domain.MdsVersionedEntity)

Example 25 with Entity

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

the class EntityServiceImpl method updateRestOptions.

@Override
@Transactional
public void updateRestOptions(Long entityId, RestOptionsDto restOptionsDto) {
    Entity entity = allEntities.retrieveById(entityId);
    assertEntityExists(entity, entityId);
    entity.updateRestOptions(restOptionsDto);
}
Also used : MdsEntity(org.motechproject.mds.domain.MdsEntity) Entity(org.motechproject.mds.domain.Entity) MdsVersionedEntity(org.motechproject.mds.domain.MdsVersionedEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Entity (org.motechproject.mds.domain.Entity)97 Test (org.junit.Test)35 Field (org.motechproject.mds.domain.Field)33 MdsEntity (org.motechproject.mds.domain.MdsEntity)32 MdsVersionedEntity (org.motechproject.mds.domain.MdsVersionedEntity)32 Transactional (org.springframework.transaction.annotation.Transactional)32 ArrayList (java.util.ArrayList)14 Lookup (org.motechproject.mds.domain.Lookup)12 UserPreferences (org.motechproject.mds.domain.UserPreferences)8 Type (org.motechproject.mds.domain.Type)7 AllUserPreferences (org.motechproject.mds.repository.internal.AllUserPreferences)7 EntityDto (org.motechproject.mds.dto.EntityDto)6 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)6 HashMap (java.util.HashMap)5 FieldDto (org.motechproject.mds.dto.FieldDto)5 HashSet (java.util.HashSet)4 EntityDraft (org.motechproject.mds.domain.EntityDraft)4 MotechDataService (org.motechproject.mds.service.MotechDataService)4 Query (javax.jdo.Query)3 FieldSetting (org.motechproject.mds.domain.FieldSetting)3