Search in sources :

Example 6 with Entity

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

the class RelationshipSorter method sort.

public void sort(List<Entity> entities) {
    final Map<Entity, Integer> entitiesOrder = new HashMap<>();
    EntitiesRetriever entitiesRetriever = new EntitiesRetriever(entities);
    for (Entity entity : entities) {
        traverse(entity, new ArrayList<Entity>(), entitiesOrder, entitiesRetriever);
    }
    Collections.sort(entities, new Comparator<Entity>() {

        @Override
        public int compare(Entity entity1, Entity entity2) {
            // reverse
            return Integer.compare(entitiesOrder.get(entity2), entitiesOrder.get(entity1));
        }
    });
}
Also used : Entity(org.motechproject.mds.domain.Entity) HashMap(java.util.HashMap)

Example 7 with Entity

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

the class ExportWriter method beginEntry.

private EntryWriter beginEntry(ImportExportBlueprint.Record record) throws IOException {
    jsonWriter.beginObject();
    Entity entity = exportContext.getEntity(record.getEntityName());
    return new EntryWriter(jsonWriter, entity, exportContext);
}
Also used : Entity(org.motechproject.mds.domain.Entity)

Example 8 with Entity

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

the class EntryReader method readSchema.

public Entity readSchema() throws IOException {
    objectReader.expect("schema");
    Entity entity = null != existingEntity ? importContext.setupExistingEntity(existingEntity) : importContext.setupNewEntity(entityName);
    EntityReader entityReader = new EntityReader(jsonReader, entity, importContext);
    return entityReader.readEntity();
}
Also used : Entity(org.motechproject.mds.domain.Entity)

Example 9 with Entity

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

the class ImportManifestReader method readManifest.

public ImportManifest readManifest() throws IOException {
    ImportManifest manifest = new ImportManifest();
    jsonReader.beginArray();
    while (jsonReader.hasNext()) {
        jsonReader.beginObject();
        String entityName = objectReader.readString("entity");
        EntityDefinitionType entityType = objectReader.readEnum("type", EntityDefinitionType.class);
        Entity existingEntity = getExistingEntity(entityName);
        boolean canImport = isImportable(existingEntity, entityType);
        String moduleName = null != existingEntity && existingEntity.isDDE() ? existingEntity.getModule() : "MDS";
        ImportManifest.Record manifestRecord = manifest.addRecord(entityName, moduleName);
        objectReader.expectAndSkip("schema");
        manifestRecord.setCanIncludeSchema(canImport);
        if (jsonReader.hasNext()) {
            objectReader.expectAndSkip("instances");
            manifestRecord.setCanIncludeData(canImport);
        }
        if (jsonReader.hasNext()) {
            throw new JsonParseException("Invalid json format! Unexpected property: " + jsonReader.nextName());
        }
        jsonReader.endObject();
    }
    jsonReader.endArray();
    return manifest;
}
Also used : ImportManifest(org.motechproject.mds.domain.ImportManifest) EntityDefinitionType(org.motechproject.mds.domain.EntityDefinitionType) Entity(org.motechproject.mds.domain.Entity) JsonParseException(com.google.gson.JsonParseException)

Example 10 with Entity

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

the class SwaggerGenerator method generateDocumentation.

@Override
public void generateDocumentation(Writer writer, String serverPrefix, Locale locale) {
    LOGGER.info("Generating REST documentation");
    SwaggerModel swaggerModel = initialSwaggerModel(serverPrefix, locale);
    swaggerModel.addDefinition("Metadata", buildMetadataDefinition());
    for (Entity entity : allEntities.retrieveAll()) {
        addCrudEndpoints(swaggerModel, entity, locale);
        addLookupEndpoints(swaggerModel, entity, locale);
        addDefinitions(swaggerModel, entity);
    }
    if (swaggerModel.getDefinitions().size() == 1) {
        swaggerModel.getInfo().setDescription(String.format("%s \n\n**%s [%s](%s)**", msg(locale, API_DESCRIPTION_KEY), msg(locale, NO_ENTITY_IS_EXPOSED_KEY), msg(locale, REST_API_DOCS_KEY), property(REST_API_DOCS_URL_KEY)));
    }
    Gson gson = buildGson();
    gson.toJson(swaggerModel, writer);
}
Also used : Entity(org.motechproject.mds.domain.Entity) SwaggerModel(org.motechproject.mds.docs.swagger.model.SwaggerModel) Gson(com.google.gson.Gson)

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