Use Case: Get Appraisal Reports

Class: net.hrider.api.usecases.GetReports.java

This example shows how to get the reports available for a specific appraisal and how to download their content.

As in the previous examples, we use the link to the company and the appraisal to obtain both resources through a GET call:

Link companyLink = root.getLinks().getCompanies().build(companyId);
Company company = service.get(Company.class, companyLink);        
Link appraisalLink = company.getLinks().getAppraisals().build("" + appraisalId);
Appraisal appraisal = service.get(Appraisal.class, appraisalLink);


Following the appraisal's reports link we get all the reports available to it:

ReportsCollection collection = service.get(ReportsCollection.class, appraisal.getLinks().getReports());
List<Report> reports = collection.getEmbedded().getReports();
printReports(reports);


For a feedback appraisal we get this result:

ID                            Description                               Mimetypes           
---------------------------   ---------------------------------------   ---------------------------------
survey-list                   Survey list                               text/csv,application/vnd.ms-excel
feedback-reports              Individual reports for feedback appra...  application/json    
feedback-results              Individual results list for feedback ...  text/csv,application/vnd.ms-excel
feedback-results-jobs         Results by jobs for feedback appraisal    text/csv,application/vnd.ms-excel
feedback-results-gender       Results by gender for feedback appraisal  text/csv,application/vnd.ms-excel
feedback-results-age          Results by age for feedback appraisal     text/csv,application/vnd.ms-excel
feedback-results-antiquity    Results by seniority ranges for feedb...  text/csv,application/vnd.ms-excel
feedback-detail               Individual results detailed by indica...  text/csv,application/vnd.ms-excel
feedback-group-detail         Individual results detailed by indica...  text/csv,application/vnd.ms-excel
feedback-action-plan          Action plan objectives list for each ...  text/csv,application/vnd.ms-excel


Each report contains an ID, a description of what the report contains, and the content types that are supported to download.
For example, the second report, with ID feedback-results can be download at both Excel and CSV and includes the list of individual results for a feedback appraisal.
The following code snippet downloads the report in Excel and saves it to a file:

Report report = collection.getEmbedded().findReport("feedback-results");
InputStream in = service.get(InputStream.class, report.getLinks().getSelf(), 
            net.hrider.api.Constants.MIMETYPE_EXCEL);

try (FileOutputStream fout = new FileOutputStream(new File(outputDir, "feedback-results.xls"))) {
    saveToFile(in, fout);
} catch (IOException ex) {
    LOG.log(Level.SEVERE, "error saving file", ex);
}


Alternatively we could have created the link manually using the report ID. In this example the URI to the report would be (replacing 'companyId' and 'appraisalId' with their corresponding IDs):

https://dev.hrider.net/api/v1/companies/companyId/appraisals/appraisalId/reports/feedback-results