use of org.motechproject.mds.domain.ImportExportBlueprint in project motech by motech.
the class SettingsController method exportEntities.
@RequestMapping(value = "/settings/export", method = RequestMethod.POST, consumes = "application/x-www-form-urlencoded")
@ResponseStatus(HttpStatus.OK)
@PreAuthorize(Roles.HAS_SETTINGS_ACCESS)
public void exportEntities(HttpServletRequest request, HttpServletResponse response) throws IOException {
ImportExportBlueprint blueprint = getBlueprint(request.getParameterMap());
response.setContentType("application/json");
response.setCharacterEncoding(UTF_8);
response.setHeader("Content-Disposition", "attachment; filename=mds.json");
importExportService.exportEntities(blueprint, response.getWriter());
}
use of org.motechproject.mds.domain.ImportExportBlueprint 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;
}
use of org.motechproject.mds.domain.ImportExportBlueprint in project motech by motech.
the class SettingsController method getBlueprint.
private ImportExportBlueprint getBlueprint(Map requestParameterMap) {
ImportExportBlueprint blueprint = new ImportExportBlueprint();
for (Object parameterEntryObject : requestParameterMap.entrySet()) {
Map.Entry parameterEntry = (Map.Entry) parameterEntryObject;
String entity = parameterEntry.getKey() instanceof String ? (String) parameterEntry.getKey() : null;
List<String> include = parameterEntry.getValue() instanceof String[] ? Arrays.asList((String[]) parameterEntry.getValue()) : null;
if (null != entity && null != include) {
if (include.contains(INCLUDE_SCHEMA)) {
blueprint.includeEntitySchema(entity, true);
}
if (include.contains(INCLUDE_DATA)) {
blueprint.includeEntityData(entity, true);
}
}
}
return blueprint;
}
Aggregations