use of org.motechproject.mds.service.MotechDataService in project motech by motech.
the class MDSDataProvider method findById.
private Object findById(String type, String idParam) {
Long id = parseId(idParam);
String serviceName = MotechClassPool.getInterfaceName(type);
MotechDataService service = OSGiServiceUtils.findService(bundleContext, serviceName);
if (null != service) {
return service.findById(id);
} else {
getLogger().error("Service %s not found", serviceName);
return null;
}
}
use of org.motechproject.mds.service.MotechDataService in project motech by motech.
the class ComboboxValueRepositoryContextIT method setUpTestData.
private void setUpTestData() throws Exception {
MotechDataService service = getService();
final Object instance1 = objectInstance("one", asList("one", "two"));
final Object instance2 = objectInstance("two", asList("two", "one", "four"));
final Object instance3 = objectInstance("four", asList("four", "four", "four"));
final Object instance4 = objectInstance("five", singletonList("five"));
final Object instance5 = objectInstance("one", asList("one", "two", "four", "three"));
final Object instance6 = objectInstance(null, null);
final Object instance7 = objectInstance(null, singletonList(null));
final Object instance8 = objectInstance("", singletonList(""));
service.doInTransaction(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
service.create(instance1);
service.create(instance2);
service.create(instance3);
service.create(instance4);
service.create(instance5);
service.create(instance6);
service.create(instance7);
service.create(instance8);
}
});
assertEquals("There were issues creating test data", 8, service.count());
}
use of org.motechproject.mds.service.MotechDataService in project motech by motech.
the class ActionHandlerServiceImpl method setRelationshipInstanceProperty.
private void setRelationshipInstanceProperty(Object instance, Field field, Object value) throws ActionHandlerException {
RelationshipHolder relationshipHolder = new RelationshipHolder(field);
try {
if (null != value) {
String relatedClassName = relationshipHolder.getRelatedClass();
MotechDataService relatedClassDataService = getEntityDataService(relatedClassName);
if (relationshipHolder.isManyToOne() || relationshipHolder.isOneToOne()) {
Object relatedInstance = getRelatedInstance(relatedClassDataService, value);
PropertyUtil.safeSetProperty(instance, field.getName(), relatedInstance);
} else if (relationshipHolder.isManyToMany() || relationshipHolder.isOneToMany()) {
List<Object> relatedInstances = getRelatedInstances(relatedClassDataService, value);
PropertyUtil.safeSetCollectionProperty(instance, field.getName(), relatedInstances);
}
} else {
PropertyUtil.safeSetProperty(instance, field.getName(), null);
}
} catch (RuntimeException e) {
throw new ActionHandlerException("Cannot set instance property " + field.getName() + " with value " + value, e);
}
}
use of org.motechproject.mds.service.MotechDataService in project motech by motech.
the class ActionHandlerServiceImpl method create.
@Override
public void create(Map<String, Object> parameters) throws ActionHandlerException {
LOGGER.debug("Action CREATE: params: {}", parameters);
String entityClassName = getEntityClassName(parameters);
MotechDataService dataService = getEntityDataService(entityClassName);
Entity entity = getEntity(entityClassName);
Object instance = createEntityInstance(dataService);
setInstanceProperties(instance, entity.getFields(), parameters);
dataService.create(instance);
}
use of org.motechproject.mds.service.MotechDataService in project motech by motech.
the class ActionHandlerServiceImpl method createOrUpdate.
@Override
public void createOrUpdate(Map<String, Object> parameters) throws ActionHandlerException {
LOGGER.debug("Action CREATE OR UPDATE: params {}", parameters);
String entityClassName = getEntityClassName(parameters);
MotechDataService dataService = getEntityDataService(entityClassName);
Entity entity = getEntity(entityClassName);
Long instanceId = getInstanceId(parameters, false);
Object instance = createEntityInstance(dataService);
PropertyUtil.safeSetProperty(instance, Constants.Util.ID_FIELD_NAME, instanceId);
setInstanceProperties(instance, entity.getFields(), parameters);
dataService.createOrUpdate(instance);
}
Aggregations