Search in sources :

Example 66 with Entity

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

the class EntityWriterTest method shouldWriteModifiedDDE.

@Test
public void shouldWriteModifiedDDE() throws IOException {
    Entity dde = buildModifiedDDE();
    String ddeJsonResource = "json/EntityWriterTest_ModifiedDDE.json";
    assertEntityWrittenCorrectly(dde, ddeJsonResource);
}
Also used : Entity(org.motechproject.mds.domain.Entity) Test(org.junit.Test)

Example 67 with Entity

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

the class ActionHandlerServiceImpl method queryAndUpdate.

@Override
public void queryAndUpdate(Map<String, Object> parameters) throws ActionHandlerException {
    LOGGER.debug("Action QUERY AND UPDATE: params {}", parameters);
    String entityClassName = getEntityClassName(parameters);
    MotechDataService dataService = getEntityDataService(entityClassName);
    Entity entity = getEntity(entityClassName);
    List<?> instances = dataService.retrieveAll();
    for (Object instance : instances) {
        setInstancePropertiesForQuery(instance, entity.getFields(), parameters);
        dataService.update(instance);
    }
}
Also used : Entity(org.motechproject.mds.domain.Entity) MotechDataService(org.motechproject.mds.service.MotechDataService)

Example 68 with Entity

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

the class ImportExportServiceImpl method sortBlueprintRecords.

private ImportExportBlueprint sortBlueprintRecords(ImportExportBlueprint blueprint) {
    List<Entity> entities = new ArrayList<>(blueprint.size());
    for (ImportExportBlueprint.Record record : blueprint) {
        entities.add(allEntities.retrieveByClassName(record.getEntityName()));
    }
    RelationshipSorter relationshipSorter = new RelationshipSorter();
    relationshipSorter.sort(entities);
    ImportExportBlueprint sortedBlueprint = new ImportExportBlueprint();
    for (Entity entity : entities) {
        String entityName = entity.getClassName();
        sortedBlueprint.includeEntitySchema(entityName, blueprint.isIncludeEntitySchema(entityName));
        sortedBlueprint.includeEntityData(entityName, blueprint.isIncludeEntityData(entityName));
    }
    return sortedBlueprint;
}
Also used : Entity(org.motechproject.mds.domain.Entity) ArrayList(java.util.ArrayList) RelationshipSorter(org.motechproject.mds.helper.RelationshipSorter) ImportExportBlueprint(org.motechproject.mds.domain.ImportExportBlueprint)

Example 69 with Entity

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

the class ImportReader method beginEntry.

public EntryReader beginEntry() throws IOException {
    jsonReader.beginObject();
    String entityName = objectReader.readString("entity");
    EntityDefinitionType entityType = objectReader.readEnum("type", EntityDefinitionType.class);
    Entity entity = importContext.getEntity(entityName);
    return new EntryReader(jsonReader, entityName, entityType, entity, importContext);
}
Also used : EntityDefinitionType(org.motechproject.mds.domain.EntityDefinitionType) Entity(org.motechproject.mds.domain.Entity)

Example 70 with Entity

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

the class ImportContext method setupNewEntity.

public Entity setupNewEntity(String entityName) {
    Entity entity = new Entity(entityName);
    EntityHelper.addDefaultFields(entity, allTypes);
    return entity;
}
Also used : Entity(org.motechproject.mds.domain.Entity)

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