use of org.motechproject.mds.service.MotechDataService in project motech by motech.
the class ActionHandlerServiceImpl method update.
@Override
public void update(Map<String, Object> parameters) throws ActionHandlerException {
LOGGER.debug("Action UPDATE: params: {}", parameters);
String entityClassName = getEntityClassName(parameters);
MotechDataService dataService = getEntityDataService(entityClassName);
Entity entity = getEntity(entityClassName);
Long instanceId = getInstanceId(parameters, true);
Object instance = retrieveEntityInstance(dataService, instanceId);
setInstanceProperties(instance, entity.getFields(), parameters);
dataService.update(instance);
}
use of org.motechproject.mds.service.MotechDataService in project motech by motech.
the class MdsLookupServiceImpl method buildLookupExecutor.
private LookupExecutor buildLookupExecutor(String entityClassName, String lookupName) {
String fullyQualifiedEntityClassName;
if (entityClassName.contains(".")) {
fullyQualifiedEntityClassName = entityClassName;
} else {
fullyQualifiedEntityClassName = Constants.PackagesGenerated.ENTITY + "." + entityClassName;
}
MotechDataService dataService = OSGiServiceUtils.findService(bundleContext, MotechClassPool.getInterfaceName(fullyQualifiedEntityClassName));
EntityDto entity = entityService.getEntityByClassName(fullyQualifiedEntityClassName);
LookupDto lookup = entityService.getLookupByName(entity.getId(), lookupName);
return new LookupExecutor(dataService, lookup, entityService.getLookupFieldsMapping(entity.getId(), lookupName));
}
use of org.motechproject.mds.service.MotechDataService in project motech by motech.
the class AbstractMdsExporter method exportData.
protected long exportData(EntityInfo entityInfo, TableWriter writer, String lookupName, QueryParams params, List<String> headers, Map<String, Object> lookupFields, CsvExportCustomizer exportCustomizer) {
final MotechDataService dataService = DataServiceHelper.getDataService(bundleContext, entityInfo.getClassName());
final Map<String, FieldDto> fieldMap = new HashMap<>();
for (FieldDto field : entityInfo.getFieldDtos()) {
fieldMap.put(exportCustomizer.exportDisplayName(field), field);
}
// we must respect field ordering
String[] orderedHeaders = orderHeaders(entityInfo.getAdvancedSettings().getBrowsing(), headers == null ? fieldsToHeaders(entityInfo.getFieldDtos(), exportCustomizer) : headers.toArray(new String[headers.size()]), entityInfo.getFieldDtos(), exportCustomizer);
try {
writer.writeHeader(orderedHeaders);
long rowsExported = 0;
Map<String, String> row = new HashMap<>();
List<Object> instances = StringUtils.isBlank(lookupName) ? dataService.retrieveAll(params) : mdsLookupService.findMany(entityInfo.getClassName(), lookupName, lookupFields, params);
for (Object instance : instances) {
buildCsvRow(row, fieldMap, instance, orderedHeaders, exportCustomizer);
writer.writeRow(row, orderedHeaders);
rowsExported++;
}
return rowsExported;
} catch (IOException e) {
throw new DataExportException("IO Error when writing data", e);
}
}
use of org.motechproject.mds.service.MotechDataService in project motech by motech.
the class MDSInterfaceResolver method processMDSInterfaces.
/**
* This method scans the given bundle and registers all interfaces extending
* {@link MotechDataService} interface in the {@link MotechClassPool}.
*
* @param bundle A bundle to scan in.
*/
public static void processMDSInterfaces(Bundle bundle) {
LOGGER.debug("Starting to look for MotechDataService implementations in bundle {}", bundle.getSymbolicName());
List<Class<? extends MotechDataService>> allBundleInterfaces = ReflectionsUtil.getMdsInterfaces(bundle);
for (Class clazz : allBundleInterfaces) {
LOGGER.debug("Processing {} class", clazz.getName());
Type[] interfaces = clazz.getGenericInterfaces();
ParameterizedType parameterizedType = findMDSInterface(interfaces);
LOGGER.info("Registering {} service in MotechClassPool", clazz.getName());
MotechClassPool.registerServiceInterface(discoverEntityClassName(parameterizedType), clazz.getName());
}
}
use of org.motechproject.mds.service.MotechDataService in project motech by motech.
the class InstanceServiceImpl method getInstanceHistory.
@Override
public List<BasicHistoryRecord> getInstanceHistory(Long entityId, Long instanceId, QueryParams queryParams) {
EntityDto entity = getEntity(entityId);
validateCredentialsForReading(entity);
MotechDataService service = getServiceForEntity(entity);
Object instance = service.retrieve(ID_FIELD_NAME, instanceId);
List history = historyService.getHistoryForInstance(instance, queryParams);
updateGridSize(entityId, queryParams);
List<BasicHistoryRecord> result = new ArrayList<>();
for (Object o : history) {
result.add(convertToBasicHistoryRecord(o, entity, instanceId, service));
}
return result;
}
Aggregations