@Test public void shouldUpsertEntity() throws ActionHandlerException { Map<String, Object> parameters = updateTestParams(); actionHandlerService.createOrUpdate(parameters); TestEntity expectedTestEntity = expectedPostUpdateTestEntity(); expectedTestEntity.setId(1L); ArgumentCaptor<TestEntity> testEntityCaptor = ArgumentCaptor.forClass(TestEntity.class); verify(testEntityDataService).createOrUpdate(testEntityCaptor.capture()); assertEquals(expectedTestEntity, testEntityCaptor.getValue()); }
@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); }
ActionHandlerServiceImpl implements ActionHandlerService { @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); } }
ActionHandlerServiceImpl implements ActionHandlerService { @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); }  }
ActionHandlerServiceImpl implements ActionHandlerService { @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); }  @Override void create(Map<String, Object> parameters); @Override void update(Map<String, Object> parameters); @Override void createOrUpdate(Map<String, Object> parameters); @Override void queryAndUpdate(Map<String, Object> parameters); @Override void delete(Map<String, Object> parameters); @Autowired void setBundleContext(BundleContext bundleContext); @Autowired void setAllEntities(AllEntities allEntities); }
ActionHandlerServiceImpl implements ActionHandlerService { @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); }  @Override void create(Map<String, Object> parameters); @Override void update(Map<String, Object> parameters); @Override void createOrUpdate(Map<String, Object> parameters); @Override void queryAndUpdate(Map<String, Object> parameters); @Override void delete(Map<String, Object> parameters); @Autowired void setBundleContext(BundleContext bundleContext); @Autowired void setAllEntities(AllEntities allEntities);  }