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));
}
});
}
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);
}
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();
}
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;
}
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);
}
Aggregations