private void executeCommand( CreateEntity command, CreateResult result, Authentication authentication, AsyncCallback<CreateResult> callback) { if (ProjectDTO.ENTITY_NAME.equals(command.getEntityName())) { exception(command, callback != null); } else if (PersonalEventDTO.ENTITY_NAME.equals(command.getEntityName())) { insertPersonalEvent(command, callback); } else if (ProjectReportDTO.ENTITY_NAME.equals(command.getEntityName())) { exception(command, callback != null); } else if (ReminderDTO.ENTITY_NAME.equals(command.getEntityName())) { if (result != null) { reminderAsyncDAO.saveOrUpdate((ReminderDTO) result.getEntity()); } else { insertReminder(command, authentication, callback); } } else if (MonitoredPointDTO.ENTITY_NAME.equals(command.getEntityName())) { if (result != null) { monitoredPointAsyncDAO.saveOrUpdate((MonitoredPointDTO) result.getEntity()); } else { insertMonitoredPoint(command, authentication, callback); } } else { exception(command, callback != null); } }
private void insertMonitoredPoint( final CreateEntity command, final Authentication authentication, final AsyncCallback<CreateResult> callback) { final MonitoredPointDTO monitoredPointDTO = buildMonitoredPointDTO(command.getProperties(), authentication); final RequestManager<CreateResult> requestManager = new RequestManager<CreateResult>(new CreateResult(monitoredPointDTO), callback); final int futureRequest = requestManager.prepareRequest(); final RequestManager<MonitoredPointDTO> objectRequestManager = new RequestManager<MonitoredPointDTO>( monitoredPointDTO, new RequestManagerCallback<CreateResult, MonitoredPointDTO>(requestManager) { @Override public void onRequestSuccess(MonitoredPointDTO result) { monitoredPointAsyncDAO.saveOrUpdate( result, new RequestManagerCallback<CreateResult, MonitoredPointDTO>( requestManager, futureRequest) { @Override public void onRequestSuccess(MonitoredPointDTO result) { // Monitored Point has been saved successfully. } }); } }); // Retrieves project. final Integer projectId = (Integer) command.getProperties().get(ReminderDTO.PROJECT_ID); projectAsyncDAO.get( projectId, new RequestManagerCallback<MonitoredPointDTO, ProjectDTO>(objectRequestManager) { @Override public void onRequestSuccess(ProjectDTO result) { final Integer pointsListId = result.getPointsList().getId(); monitoredPointDTO.setParentListId(pointsListId); } }); // Generates a negative ID monitoredPointAsyncDAO.generateNegativeId( new RequestManagerCallback<MonitoredPointDTO, Integer>(objectRequestManager) { @Override public void onRequestSuccess(Integer result) { monitoredPointDTO.setId(result); } }); objectRequestManager.ready(); requestManager.ready(); }