From 65cdf51e633334383c184f7067474860ed49f551 Mon Sep 17 00:00:00 2001 From: SanduDS Date: Sun, 27 Feb 2022 12:32:36 +0530 Subject: [PATCH] Add applicant related operations --- peoplehr/Ballerina.toml | 2 +- peoplehr/client.bal | 42 +++++++++++++++++ peoplehr/constants.bal | 1 + peoplehr/tests/test.bal | 85 +++++++++++++++++++++++++++-------- peoplehr/types.bal | 99 +++++++++++++++++++++++++++++++++++++++-- 5 files changed, 207 insertions(+), 22 deletions(-) diff --git a/peoplehr/Ballerina.toml b/peoplehr/Ballerina.toml index 0fc2bb9..9556faa 100644 --- a/peoplehr/Ballerina.toml +++ b/peoplehr/Ballerina.toml @@ -2,7 +2,7 @@ distribution = "2201.0.0" org = "ballerinax" name = "peoplehr" -version = "1.1.0" +version = "1.1.1" authors = ["Ballerina"] icon = "icon.png" repository = "https://github.com/ballerina-platform/module-ballerinax-peoplehr" diff --git a/peoplehr/client.bal b/peoplehr/client.bal index 6eef790..ea7559e 100644 --- a/peoplehr/client.bal +++ b/peoplehr/client.bal @@ -217,6 +217,48 @@ public isolated client class Client { return check self.HTTPClient->post(VACANCY, request); } + # Creates New Applicant + # + # + payload - New applicant detail + # + return - Successful response or an error + @display{label: "Create New Applicant"} + isolated remote function createNewApplicant(@display{label: "New Applicant detail"} NewApplicant payload) returns + OperationStatus|error { + http:Request request = new; + json jsonBody = check payload.cloneWithType(json); + json authentication = {APIKey: self.config.apiKey, Action: "CreateNewApplicant"}; + request.setJsonPayload(check jsonBody.mergeJson(authentication)); + return check self.HTTPClient->post(APPLICANT, request); + } + + # Upload applicant document + # + # + payload - Request detail on new document + # + return - Successful response or an error + @display{label: "Upload new applicant document"} + isolated remote function uploadApplicantDocument(@display{label: "New applicant document"} NewDocument payload) + returns OperationStatus|error { + http:Request request = new; + json jsonBody = check payload.cloneWithType(json); + json authentication = {APIKey: self.config.apiKey, Action: "uploadapplicantdocument"}; + request.setJsonPayload(check jsonBody.mergeJson(authentication)); + return check self.HTTPClient->post(APPLICANT, request); + } + + # Checks duplicate applicant + # + # + payload - Request detail on an applicant + # + return - Successful response or an error + @display{label: "Check duplicate applicant"} + isolated remote function checkDuplicateApplicant(@display{label: "Applicant detail"} ApplicantInformation payload) + returns OperationStatus|error { + http:Request request = new; + json jsonBody = check payload.cloneWithType(json); + json authentication = {APIKey: self.config.apiKey, Action: "CheckDuplicateApplicant"}; + request.setJsonPayload(check jsonBody.mergeJson(authentication)); + return check self.HTTPClient->post(APPLICANT, request); + } + # Gets query result By query name details. # # + payload - Request detail on a query diff --git a/peoplehr/constants.bal b/peoplehr/constants.bal index fda1632..b7dd069 100644 --- a/peoplehr/constants.bal +++ b/peoplehr/constants.bal @@ -19,3 +19,4 @@ const string EMPLOYEE = "/Employee"; const string VACANCY = "/Vacancy"; const string HOLIDAY = "/Holiday"; const string SALARY = "/Salary"; +const string APPLICANT = "/Applicant"; diff --git a/peoplehr/tests/test.bal b/peoplehr/tests/test.bal index 99d87ec..3287599 100644 --- a/peoplehr/tests/test.bal +++ b/peoplehr/tests/test.bal @@ -31,8 +31,10 @@ Client baseClient = check new ({apiKey: apiKey, baseURL: baseURL}); @test:Config {enable: true} function checkAuthentication() returns error? { log:printInfo("Check Authentication"); - AuthenticationResponse response = check baseClient->checkAuthentication({EmailAddress: emailAddress, - Password: password}); + AuthenticationResponse response = check baseClient->checkAuthentication({ + EmailAddress: emailAddress, + Password: password + }); log:printInfo(response.toString()); } @@ -43,15 +45,22 @@ function testGetQueryResultByQueryName() returns error? { log:printInfo(response.Message); } -@test:Config {enable: false, dependsOn: [testGetEmployeeDetailById, testMarkAsLeaverById, testMarkAsLeaverById, - testAddNewHoliday]} +@test:Config { + enable: false, + dependsOn: [ + testGetEmployeeDetailById, + testMarkAsLeaverById, + testMarkAsLeaverById, + testAddNewHoliday + ] +} function testUpdateEmployeeId() returns error? { log:printInfo("Update Employee Id"); EmployeeIdUpdateRequest EmployeeIdUpdateRequest = { ReasonForChange: "Test only", OldEmployeeId: employeeId, NewEmployeeId: (check random:createIntInRange(100, 1000)).toString() - }; + }; OperationStatus response = check baseClient->updateEmployeeId(EmployeeIdUpdateRequest); log:printInfo(response.Message); } @@ -61,8 +70,8 @@ function testGetAllEmployeeDetail() returns error? { log:printInfo("Get All Employee Detail"); AllEmployeesRequest AllEmployeesRequest = { IncludeLeavers: false - }; - EmployeesResponse response= check baseClient->getAllEmployees(AllEmployeesRequest); + }; + EmployeesResponse response = check baseClient->getAllEmployees(AllEmployeesRequest); log:printInfo(response.Message); } @@ -72,7 +81,7 @@ function testGetEmployeeDetailById() returns error? { EmployeeRequest EmployeeRequest = { EmployeeId: employeeId }; - EmployeeResponse response= check baseClient->getEmployeeById(EmployeeRequest); + EmployeeResponse response = check baseClient->getEmployeeById(EmployeeRequest); log:printInfo(response.Message); } @@ -93,7 +102,6 @@ function testCreateNewEmployee() returns error? { log:printInfo(response.Message); } - @test:Config {enable: true} function testUpdateEmployeeDetail() returns error? { log:printInfo("Update Employee Detail"); @@ -102,7 +110,7 @@ function testUpdateEmployeeDetail() returns error? { FirstName: "BallerinaUser", ReasonForChange: "Test" }; - OperationStatus response= check baseClient->updateEmployee(employee); + OperationStatus response = check baseClient->updateEmployee(employee); log:printInfo(response.Message); } @@ -119,7 +127,7 @@ function testMarkAsLeaverById() returns error? { AdditionalComments: "Test", SupportingComments: "supporting comments" }; - OperationStatus response= check baseClient->markAsLeaverById(employeeLeaverStatus); + OperationStatus response = check baseClient->markAsLeaverById(employeeLeaverStatus); log:printInfo(response.Message); } @@ -130,7 +138,7 @@ function testGetSalaryDetail() returns error? { EmployeeId: "PW2", IsIncludeHistory: false }; - SalaryDetailGetResponse response= check baseClient->getSalaryDetail(salaryDetailRequest); + SalaryDetailGetResponse response = check baseClient->getSalaryDetail(salaryDetailRequest); log:printInfo(response.toString()); } @@ -145,7 +153,7 @@ function testAddNewHoliday() returns error? { DurationInDays: "1", DurationInMinutes: "450" }; - OperationStatus response= check baseClient->addNewHoliday(newHolidayRequest); + OperationStatus response = check baseClient->addNewHoliday(newHolidayRequest); log:printInfo(response.toString()); } @@ -155,7 +163,7 @@ function testGetHolidayDetail() returns error? { HolidayDetail holidayDetail = { EmployeeId: "PW2" }; - HolidayGetResponse response= check baseClient->getHolidayDetail(holidayDetail); + HolidayGetResponse response = check baseClient->getHolidayDetail(holidayDetail); log:printInfo(response.toString()); } @@ -167,7 +175,7 @@ function testDeleteHoliday() returns error? { StartDate: "2023-07-27", EndDate: "2023-07-27" }; - OperationStatus response= check baseClient->deleteHoliday(holidayDetail); + OperationStatus response = check baseClient->deleteHoliday(holidayDetail); log:printInfo(response.Message); } @@ -177,13 +185,54 @@ function testGetVacancy() returns error? { GetVacancyResultRequest vacancyDetail = { VacancyReference: "VA1" }; - VacancyGetResponse response= check baseClient->getVacancy(vacancyDetail); + VacancyGetResponse response = check baseClient->getVacancy(vacancyDetail); log:printInfo(response.Message); } @test:Config {enable: true} function testGetAllVacancies() returns error? { log:printInfo("Get All Vacancies"); - AllVacancies response= check baseClient->getAllVacancies(); + AllVacancies response = check baseClient->getAllVacancies(); + log:printInfo(response.toString()); +} + +@test:Config {enable: true} +function testCreateNewApplicant() returns error? { + log:printInfo("Create new applicant"); + NewApplicant newApplicant = { + FirstName: "Smith", + LastName: "Perera", + Email: "testapplicant@wso2.com", + Documents: [{DocumentName: "CV01", Url: "www.mycv.com"}], + Skills: "Programming", + VacancyReference: "VA100" + }; + OperationStatus response = check baseClient->createNewApplicant(newApplicant); + log:printInfo(response.Message); +} + +@test:Config {enable: true, dependsOn: [testCreateNewApplicant]} +function testUploadApplicantDocument() returns error? { + log:printInfo("Upload new document"); + NewDocument newDocument = { + ApplicantId: "6604761", + Description: "Degree", + DocumentName: "transcript.txt", + File: "dGVzdCBmaWxlCg==" + }; + OperationStatus response = check baseClient->uploadApplicantDocument(newDocument); log:printInfo(response.toString()); -} \ No newline at end of file +} + +@test:Config {enable: true, dependsOn: [testCreateNewApplicant]} +function testCheckDuplicateApplicant() returns error? { + log:printInfo("Check duplicate applicant"); + ApplicantInformation applicantInformation = { + FirstName: "Smith", + LastName: "Perera", + Email: "testapplicant@wso2.com", + VacancyReference: "VA3" + }; + OperationStatus response = check baseClient->checkDuplicateApplicant(applicantInformation); + log:printInfo(response.toString()); +} diff --git a/peoplehr/types.bal b/peoplehr/types.bal index 6e35c57..bfeae37 100644 --- a/peoplehr/types.bal +++ b/peoplehr/types.bal @@ -69,7 +69,7 @@ public type EmployeeVerification record { string EmployeeId?; }; -# Represents the response type of `UpdateEmployeeId` operation +# Represents the response type of an operation # # + Result - The response of the operation public type OperationStatus record { @@ -177,7 +177,7 @@ public type AllVacancies record {| # + AdditionalQuestions - Additional questions # + InternalQuestions - Internal questions on the vacancy public type Vacancy record { - string? VacancyName?; + string VacancyName?; string? VacancyDescription?; string? Company?; string? Location?; @@ -790,7 +790,6 @@ public type HolidayUpdateRequest record {| # + LastActionDateTime - The last action date time # + IsToilHoliday - indicates whether isToil Holiday public type Holiday record {| - *Authentication; string StartDate?; string EndDate?; int DurationType?; @@ -805,6 +804,7 @@ public type Holiday record {| string Status?; string LastActionDateTime?; boolean IsToilHoliday?; + *Authentication; |}; # Represents holiday detail @@ -818,3 +818,96 @@ public type HolidayDetail record {| string EndDate?; *Authentication; |}; + +# Represents additional question +# +# + QuestionId - Question ID +# + Value - Value default value +public type AdditionalQuestion record { + string QuestionId; + string Value; +}; + +# Internal questions for create new applicant +# +public type InternalQuestion record { + *AdditionalQuestion; +}; + +# Represents Document detail +# +# + DocumentName - Document name +# + Url - URL for the document +public type Document record { + string DocumentName; + string Url; +}; + +# Represents new applicant +# +# + VacancyReference - Vacancy reference for create new applicant +# + FirstName - First name for create new applicant +# + LastName - Last name for create new applicant +# + Email - Email for create new applicant +# + Gender - Gender for create new applicant +# + DateOfBirth - Date of birth for create new applicant +# + PostCode - Post code for create new applicant +# + Address - Address for create new applicant +# + PhoneNumber - PhoneNumber for create new applicant +# + OtherContactDetails - Other contact details for create new applicant +# + Source - Source for create new applicant +# + AdditionalQuestions - Source for create new applicant +# + InternalQuestions - Internal questions for create new applicant +# + Documents - Documents for create new applicant +# + Skills - Skills for create new applicant +# + RecruitmentCost - Recruitment cost for create new applicant +# + DateLastContacted - Date last contacted for create new applicant +public type NewApplicant record {| + string VacancyReference?; + string FirstName; + string LastName; + string Email?; + string Gender?; + string DateOfBirth?; + string PostCode?; + string Address?; + string PhoneNumber?; + string OtherContactDetails?; + string Source?; + AdditionalQuestion[] AdditionalQuestions?; + InternalQuestion[] InternalQuestions?; + Document[] Documents; + string Skills; + string RecruitmentCost?; + string DateLastContacted?; + *Authentication; + json...; +|}; + +# Represents document detail +# +# + ApplicantId - ApplicantId for upload applicant document +# + DocumentName - Document name for upload applicant document(<= 100 characters) +# + Description - Description for upload applicant document(<= 256 characters) +# + File - File for upload applicant document +public type NewDocument record {| + string ApplicantId; + string DocumentName; + string Description; + string File; + *Authentication; +|}; + +# Applicant information for duplicate checking +# +# + VacancyReference - Vacancy reference for check duplicate applicant +# + FirstName - First name for check duplicate applicant(<= 50 characters) +# + LastName - Last name for check duplicate applicant(<= 50 characters) +# + Email - Email for check duplicate applicant +public type ApplicantInformation record {| + string FirstName; + string LastName; + string VacancyReference; + string Email?; + *Authentication; +|};