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(); }
private void insertPersonalEvent( CreateEntity command, final AsyncCallback<CreateResult> callback) { final Event event = buildPersonalEvent(command.getProperties()); final PersonalCalendarIdentifier identifier = (PersonalCalendarIdentifier) event.getParent().getIdentifier(); final Date key = (Date) command.getProperties().get(Event.DATE); // Loading the parent calendar. personalCalendarAsyncDAO.get( identifier.getId(), new AsyncCallback<Calendar>() { @Override public void onFailure(Throwable caught) { if (callback != null) { callback.onFailure(caught); } } @Override public void onSuccess(Calendar result) { List<Event> events = result.getEvents().get(key); if (events == null) { events = new ArrayList<Event>(); result.getEvents().put(key, events); } events.add(event); // Creating the callback, if necessary. final AsyncCallback<Calendar> calendarCallback; if (callback != null) { calendarCallback = new AsyncCallback<Calendar>() { @Override public void onFailure(Throwable caught) { callback.onFailure(caught); } @Override public void onSuccess(Calendar result) { callback.onSuccess(new CreateResult(new PersonalEventDTO())); } }; } else { calendarCallback = null; } // Persisting the new event. personalCalendarAsyncDAO.saveOrUpdate(result, calendarCallback); } }); }
private void exception(CreateEntity command, boolean throwException) throws UnavailableCommandException { if (throwException) { throw new UnavailableCommandException( "Creation of type '" + command.getEntityName() + "' is not supported yet."); } }