/**
     * Finds entities that match given conditions.
     */
    findAndCount(conditionsOrFindOptions?: Object|FindOptions, options?: FindOptions): Rx.Observable<[ Entity[], number ]> {
        if (conditionsOrFindOptions && options) {
            return Rx.Observable.fromPromise(this.repository.findAndCount(conditionsOrFindOptions, options));

        } else if (conditionsOrFindOptions) {
            return Rx.Observable.fromPromise(this.repository.findAndCount(conditionsOrFindOptions));

        } else {
            return Rx.Observable.fromPromise(this.repository.findAndCount());
        }
    }
    /**
     * Finds first entity that matches given conditions.
     */
    findOne(conditionsOrFindOptions?: Object|FindOptions, options?: FindOptions): Rx.Observable<Entity> {
        if (conditionsOrFindOptions && options) {
            return Rx.Observable.fromPromise(this.repository.findOne(conditionsOrFindOptions, options));

        } else if (conditionsOrFindOptions) {
            return Rx.Observable.fromPromise(this.repository.findOne(conditionsOrFindOptions));

        } else {
            return Rx.Observable.fromPromise(this.repository.findOne());
        }
    }
 /**
  * Return the total number of the tasks by filter
  * @param requestNode - TaskFilterRepresentationModel
  * @returns {any}
  */
 public getTotalTasks(requestNode: TaskQueryRequestRepresentationModel): Observable<any> {
     requestNode.size = 0;
     return Observable.fromPromise(this.callApiTasksFiltered(requestNode))
         .map((res: any) => {
             return res;
         }).catch(this.handleError);
 }
export function validateTextDocumentAsync(textDocument: TextDocument, options: CSpellUserSettings): Rx.Observable<Diagnostic> {
    const limit = (options.checkLimit || defaultCheckLimit) * 1024;
    const text = textDocument.getText().slice(0, limit);
    return Rx.Observable.fromPromise<cspell.TextOffset[]>(validateText(text, options))
        .flatMap(a => a)
        .filter(a => !!a)
        .map(a => a!)
        // Convert the offset into a position
        .map(offsetWord => ({...offsetWord, position: textDocument.positionAt(offsetWord.offset) }))
        // Calculate the range
        .map(word => ({
            ...word,
            range: {
                start: word.position,
                end: ({...word.position, character: word.position.character + word.text.length })
            }
        }))
        // Convert it to a Diagnostic
        .map(({text, range}) => ({
            severity: DiagnosticSeverity.Information,
            range: range,
            message: `Unknown word: "${text}"`,
            source: diagSource
        }))
    ;
}
 .catch(error => {
     if (error.status === 401) {
         this.authService.unauthenticated();     // 401 means authentication required
         let message = this.authService.isOrgApiKeySet ? 'Incorrect organization API key' : 'Authentication is required';
         return Observable.fromPromise(this.authService.login(message))
             .mergeMap(confirmed => {
                 if (confirmed) { // logged in again, or updated api key
                     this.authService.authenticationMayChange();
                     switch (params.length) {
                         case 1:
                             return func(params[0]);
                         case 2:
                             return func(params[0], params[1]);
                         case 3:
                             return func(params[0], params[1], params[2]);
                         default:
                             return Observable.throw(new Error('Wrong number of parameters: ' + params));
                     }
                 }else {      // canceled
                     return Observable.throw(new Error('User cancelled authentication'));
                 }
             });
     }else {
         let errorDetail = error.json();
         if (errorDetail) {
             this.authService.authenticated();  // a valid API response received
             return Observable.throw(new Error(errorDetail.type + ': ' + errorDetail.message));
         }
         console.log('API call failed: ' + JSON.stringify(error));
         return Observable.throw(error);
     }
 });
 /**
  * Add a filter
  * @param filter - FilterRepresentationModel
  * @returns {FilterRepresentationModel}
  */
 addFilter(filter: FilterRepresentationModel): Observable<FilterRepresentationModel> {
     return Observable.fromPromise(this.callApiAddFilter(filter))
         .map(res => res)
         .map((response: FilterRepresentationModel) => {
             return response;
         }).catch(this.handleError);
 }
 ngOnInit() {
   // Don't process restart for Rudi ("Rudi Rule")
   let user = this.session.get().user;
   if ( user && user.id == 10 ) {
     this.router.navigate(['upload']);
     return;
   }
   
   Observable.fromPromise(this.resume.resumeIsDone())
   .ignoreElements() // make sure this doesn't emit values
   .do(() => console.log('restarting session...'))
   .concat(this.backend.resetSession())
   .subscribe({
     next: (res) => {
       console.info('success restarting session', res.json());
       let session = this.session.get();
       // keep user and token data
       this.session.reset( {user:session.user, token:session.token} ); 
       this.router.navigate(['upload']);
     },
     error: (err) => {
       console.log('error restarting session', err.json());
       this.router.navigate(['upload']);
     }
   });
 }
 exportReportToCsv(reportId: string, paramsQuery: any): Observable<any> {
     return Observable.fromPromise(this.apiService.getInstance().activiti.reportApi.exportToCsv(reportId, paramsQuery))
         .map((res: any) => {
             this.logService.info('export');
             return res;
         }).catch(err => this.handleError(err));
 }
 /**
  * Retrive all the task details
  * @param id - taskId
  * @returns {<TaskDetailsModel>}
  */
 getTaskDetails(id: string): Observable<TaskDetailsModel> {
     return Observable.fromPromise(this.callApiTaskDetails(id))
         .map(res => res)
         .map((details: any) => {
             return new TaskDetailsModel(details);
         }).catch(this.handleError);
 }
 /**
  * Create a new standalone task
  * @param task - TaskDetailsModel
  * @returns {TaskDetailsModel}
  */
 createNewTask(task: TaskDetailsModel): Observable<TaskDetailsModel> {
     return Observable.fromPromise(this.callApiCreateTask(task))
         .map(res => res)
         .map((response: TaskDetailsModel) => {
             return new TaskDetailsModel(response);
         }).catch(this.handleError);
 }