Search in sources :

Example 1 with ImportExportBlueprint

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());
}
Also used : ImportExportBlueprint(org.motechproject.mds.domain.ImportExportBlueprint) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ImportExportBlueprint

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;
}
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 3 with ImportExportBlueprint

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;
}
Also used : ImportExportBlueprint(org.motechproject.mds.domain.ImportExportBlueprint) Map(java.util.Map)

Aggregations

ImportExportBlueprint (org.motechproject.mds.domain.ImportExportBlueprint)3 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Entity (org.motechproject.mds.domain.Entity)1 RelationshipSorter (org.motechproject.mds.helper.RelationshipSorter)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1