├── .gitignore ├── dip ├── before │ └── GlobomanticsHR │ │ ├── .idea │ │ ├── .name │ │ ├── compiler.xml │ │ ├── encodings.xml │ │ ├── libraries │ │ │ ├── Maven__javax_activation_activation_1_1.xml │ │ │ ├── Maven__javax_mail_mail_1_5_0_b01.xml │ │ │ ├── Maven__org_apiguardian_apiguardian_api_1_1_0.xml │ │ │ ├── Maven__org_junit_jupiter_junit_jupiter_api_5_5_0_RC1.xml │ │ │ ├── Maven__org_junit_platform_junit_platform_commons_1_5_0_RC1.xml │ │ │ └── Maven__org_opentest4j_opentest4j_1_2_0.xml │ │ ├── misc.xml │ │ ├── modules.xml │ │ ├── vcs.xml │ │ └── workspace.xml │ │ ├── GlobomanticsHR.iml │ │ ├── hr.iml │ │ ├── pom.xml │ │ └── src │ │ ├── main │ │ ├── java │ │ │ └── hr │ │ │ │ ├── documents │ │ │ │ ├── ExportableJson.java │ │ │ │ ├── ExportablePdf.java │ │ │ │ ├── ExportableText.java │ │ │ │ ├── Payslip.java │ │ │ │ └── WorkContract.java │ │ │ │ ├── logging │ │ │ │ └── ConsoleLogger.java │ │ │ │ ├── main │ │ │ │ ├── ApproveSLAMain.java │ │ │ │ ├── CalculateEmployeeTaxesMain.java │ │ │ │ ├── ExportPayslipMain.java │ │ │ │ ├── NatHolidayEmployeeTimeOffMain.java │ │ │ │ ├── PayEmployeesMain.java │ │ │ │ └── SaveEmployeesMain.java │ │ │ │ ├── notifications │ │ │ │ └── EmailSender.java │ │ │ │ ├── payment │ │ │ │ └── PaymentProcessor.java │ │ │ │ ├── persistence │ │ │ │ ├── EmployeeFileRepository.java │ │ │ │ └── EmployeeFileSerializer.java │ │ │ │ ├── personnel │ │ │ │ ├── Employee.java │ │ │ │ ├── FullTimeEmployee.java │ │ │ │ ├── Intern.java │ │ │ │ ├── PartTimeEmployee.java │ │ │ │ ├── ServiceLicenseAgreement.java │ │ │ │ └── Subcontractor.java │ │ │ │ └── taxes │ │ │ │ ├── FullTimeTaxCalculator.java │ │ │ │ ├── InternTaxCalculator.java │ │ │ │ ├── PartTimeTaxCalculator.java │ │ │ │ ├── TaxCalculator.java │ │ │ │ └── TaxCalculatorFactory.java │ │ └── resources │ │ │ ├── employees.csv │ │ │ ├── payment_business_requirements.txt │ │ │ ├── payslip_business_requirements.txt │ │ │ ├── subcontractor_business_requirements.txt │ │ │ ├── taxes_business_requirements.txt │ │ │ └── taxes_business_requirements_v2.txt │ │ └── test │ │ └── java │ │ └── hr │ │ └── payment │ │ └── PaymentProcessorTest.java ├── m7_sourcecode.zip └── refactored │ └── GlobomanticsHR │ ├── .idea │ ├── .name │ ├── encodings.xml │ └── workspace.xml │ ├── GlobomanticsHR.iml │ ├── hr.iml │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── hr │ │ │ ├── documents │ │ │ ├── ExportableJson.java │ │ │ ├── ExportablePdf.java │ │ │ ├── ExportableText.java │ │ │ ├── Payslip.java │ │ │ └── WorkContract.java │ │ │ ├── logging │ │ │ └── ConsoleLogger.java │ │ │ ├── main │ │ │ ├── ApproveSLAMain.java │ │ │ ├── CalculateEmployeeTaxesMain.java │ │ │ ├── ExportPayslipMain.java │ │ │ ├── NatHolidayEmployeeTimeOffMain.java │ │ │ ├── PayEmployeesMain.java │ │ │ └── SaveEmployeesMain.java │ │ │ ├── notifications │ │ │ ├── EmailSender.java │ │ │ └── EmployeeNotifier.java │ │ │ ├── payment │ │ │ └── PaymentProcessor.java │ │ │ ├── persistence │ │ │ ├── EmployeeFileRepository.java │ │ │ ├── EmployeeFileSerializer.java │ │ │ └── EmployeeRepository.java │ │ │ ├── personnel │ │ │ ├── Employee.java │ │ │ ├── FullTimeEmployee.java │ │ │ ├── Intern.java │ │ │ ├── PartTimeEmployee.java │ │ │ ├── ServiceLicenseAgreement.java │ │ │ └── Subcontractor.java │ │ │ └── taxes │ │ │ ├── FullTimeTaxCalculator.java │ │ │ ├── InternTaxCalculator.java │ │ │ ├── PartTimeTaxCalculator.java │ │ │ ├── TaxCalculator.java │ │ │ └── TaxCalculatorFactory.java │ └── resources │ │ ├── employees.csv │ │ ├── payment_business_requirements.txt │ │ ├── payslip_business_requirements.txt │ │ ├── subcontractor_business_requirements.txt │ │ ├── taxes_business_requirements.txt │ │ └── taxes_business_requirements_v2.txt │ └── test │ └── java │ └── hr │ └── payment │ └── PaymentProcessorTest.java ├── isp ├── before │ └── GlobomanticsHR │ │ ├── .idea │ │ ├── .name │ │ ├── compiler.xml │ │ ├── encodings.xml │ │ ├── misc.xml │ │ ├── modules.xml │ │ ├── uiDesigner.xml │ │ ├── vcs.xml │ │ └── workspace.xml │ │ ├── GlobomanticsHR.iml │ │ ├── hr.iml │ │ ├── pom.xml │ │ └── src │ │ └── main │ │ ├── java │ │ └── hr │ │ │ ├── documents │ │ │ ├── ExportableDocument.java │ │ │ └── Payslip.java │ │ │ ├── logging │ │ │ └── ConsoleLogger.java │ │ │ ├── main │ │ │ ├── ApproveSLAMain.java │ │ │ ├── CalculateEmployeeTaxesMain.java │ │ │ ├── ExportPayslipMain.java │ │ │ ├── NatHolidayEmployeeTimeOffMain.java │ │ │ └── SaveEmployeesMain.java │ │ │ ├── persistence │ │ │ ├── EmployeeFileSerializer.java │ │ │ └── EmployeeRepository.java │ │ │ ├── personnel │ │ │ ├── Employee.java │ │ │ ├── FullTimeEmployee.java │ │ │ ├── Intern.java │ │ │ ├── PartTimeEmployee.java │ │ │ ├── ServiceLicenseAgreement.java │ │ │ └── Subcontractor.java │ │ │ └── taxes │ │ │ ├── FullTimeTaxCalculator.java │ │ │ ├── InternTaxCalculator.java │ │ │ ├── PartTimeTaxCalculator.java │ │ │ ├── TaxCalculator.java │ │ │ └── TaxCalculatorFactory.java │ │ └── resources │ │ ├── payslip_business_requirements.txt │ │ ├── subcontractor_business_requirements.txt │ │ ├── taxes_business_requirements.txt │ │ └── taxes_business_requirements_v2.txt ├── refactored │ └── GlobomanticsHR │ │ ├── .idea │ │ ├── .name │ │ ├── compiler.xml │ │ ├── encodings.xml │ │ ├── misc.xml │ │ ├── modules.xml │ │ ├── uiDesigner.xml │ │ ├── vcs.xml │ │ └── workspace.xml │ │ ├── GlobomanticsHR.iml │ │ ├── hr.iml │ │ ├── pom.xml │ │ └── src │ │ └── main │ │ ├── java │ │ └── hr │ │ │ ├── documents │ │ │ ├── ExportableJson.java │ │ │ ├── ExportablePdf.java │ │ │ ├── ExportableText.java │ │ │ ├── Payslip.java │ │ │ └── WorkContract.java │ │ │ ├── logging │ │ │ └── ConsoleLogger.java │ │ │ ├── main │ │ │ ├── ApproveSLAMain.java │ │ │ ├── CalculateEmployeeTaxesMain.java │ │ │ ├── ExportPayslipMain.java │ │ │ ├── NatHolidayEmployeeTimeOffMain.java │ │ │ └── SaveEmployeesMain.java │ │ │ ├── persistence │ │ │ ├── EmployeeFileSerializer.java │ │ │ └── EmployeeRepository.java │ │ │ ├── personnel │ │ │ ├── Employee.java │ │ │ ├── FullTimeEmployee.java │ │ │ ├── Intern.java │ │ │ ├── PartTimeEmployee.java │ │ │ ├── ServiceLicenseAgreement.java │ │ │ └── Subcontractor.java │ │ │ └── taxes │ │ │ ├── FullTimeTaxCalculator.java │ │ │ ├── InternTaxCalculator.java │ │ │ ├── PartTimeTaxCalculator.java │ │ │ ├── TaxCalculator.java │ │ │ └── TaxCalculatorFactory.java │ │ └── resources │ │ ├── payslip_business_requirements.txt │ │ ├── subcontractor_business_requirements.txt │ │ ├── taxes_business_requirements.txt │ │ └── taxes_business_requirements_v2.txt └── sourcecode_m6.zip ├── lsp ├── before │ └── GlobomanticsHR │ │ ├── .idea │ │ ├── .name │ │ ├── compiler.xml │ │ ├── encodings.xml │ │ ├── misc.xml │ │ ├── modules.xml │ │ ├── vcs.xml │ │ └── workspace.xml │ │ ├── GlobomanticsHR.iml │ │ ├── hr.iml │ │ ├── pom.xml │ │ └── src │ │ └── main │ │ ├── java │ │ └── hr │ │ │ ├── documents │ │ │ └── ExportableDocument.java │ │ │ ├── logging │ │ │ └── ConsoleLogger.java │ │ │ ├── main │ │ │ ├── ApproveSLAMain.java │ │ │ ├── CalculateEmployeeTaxesMain.java │ │ │ ├── NatHolidayEmployeeTimeOffMain.java │ │ │ └── SaveEmployeesMain.java │ │ │ ├── persistence │ │ │ ├── EmployeeFileSerializer.java │ │ │ └── EmployeeRepository.java │ │ │ ├── personnel │ │ │ ├── Employee.java │ │ │ ├── FullTimeEmployee.java │ │ │ ├── Intern.java │ │ │ ├── PartTimeEmployee.java │ │ │ ├── ServiceLicenseAgreement.java │ │ │ └── Subcontractor.java │ │ │ └── taxes │ │ │ ├── FullTimeTaxCalculator.java │ │ │ ├── InternTaxCalculator.java │ │ │ ├── PartTimeTaxCalculator.java │ │ │ ├── TaxCalculator.java │ │ │ └── TaxCalculatorFactory.java │ │ └── resources │ │ ├── subcontractor_business_requirements.txt │ │ ├── taxes_business_requirements.txt │ │ └── taxes_business_requirements_v2.txt ├── m5_sourcecode.zip └── refactored │ └── GlobomanticsHR │ ├── .idea │ ├── .name │ ├── compiler.xml │ ├── encodings.xml │ ├── misc.xml │ ├── modules.xml │ ├── vcs.xml │ └── workspace.xml │ ├── GlobomanticsHR.iml │ ├── hr.iml │ ├── pom.xml │ └── src │ └── main │ ├── java │ └── hr │ │ ├── documents │ │ └── ExportableDocument.java │ │ ├── logging │ │ └── ConsoleLogger.java │ │ ├── main │ │ ├── ApproveSLAMain.java │ │ ├── CalculateEmployeeTaxesMain.java │ │ ├── NatHolidayEmployeeTimeOffMain.java │ │ └── SaveEmployeesMain.java │ │ ├── persistence │ │ ├── EmployeeFileSerializer.java │ │ └── EmployeeRepository.java │ │ ├── personnel │ │ ├── Employee.java │ │ ├── FullTimeEmployee.java │ │ ├── Intern.java │ │ ├── PartTimeEmployee.java │ │ ├── ServiceLicenseAgreement.java │ │ └── Subcontractor.java │ │ └── taxes │ │ ├── FullTimeTaxCalculator.java │ │ ├── InternTaxCalculator.java │ │ ├── PartTimeTaxCalculator.java │ │ ├── TaxCalculator.java │ │ └── TaxCalculatorFactory.java │ └── resources │ ├── subcontractor_business_requirements.txt │ ├── taxes_business_requirements.txt │ └── taxes_business_requirements_v2.txt ├── ocp ├── before │ └── GlobomanticsHR │ │ ├── .idea │ │ ├── .name │ │ ├── compiler.xml │ │ ├── encodings.xml │ │ ├── misc.xml │ │ ├── modules.xml │ │ ├── uiDesigner.xml │ │ ├── vcs.xml │ │ └── workspace.xml │ │ ├── GlobomanticsHR.iml │ │ ├── hr.iml │ │ ├── pom.xml │ │ └── src │ │ └── main │ │ ├── java │ │ └── hr │ │ │ ├── documents │ │ │ └── ExportableDocument.java │ │ │ ├── logging │ │ │ └── ConsoleLogger.java │ │ │ ├── main │ │ │ ├── CalculateTaxesMain.java │ │ │ └── SaveEmployeesMain.java │ │ │ ├── persistence │ │ │ ├── EmployeeFileSerializer.java │ │ │ └── EmployeeRepository.java │ │ │ ├── personnel │ │ │ ├── Employee.java │ │ │ ├── FullTimeEmployee.java │ │ │ ├── Intern.java │ │ │ └── PartTimeEmployee.java │ │ │ └── taxes │ │ │ └── TaxCalculator.java │ │ └── resources │ │ ├── taxes_business_requirements.txt │ │ └── taxes_business_requirements_v2.txt ├── m4_sourcecode.zip └── refactored │ └── GlobomanticsHR │ ├── .idea │ ├── .name │ ├── compiler.xml │ ├── encodings.xml │ ├── misc.xml │ ├── modules.xml │ ├── uiDesigner.xml │ ├── vcs.xml │ └── workspace.xml │ ├── GlobomanticsHR.iml │ ├── hr.iml │ ├── pom.xml │ └── src │ └── main │ ├── java │ └── hr │ │ ├── documents │ │ └── ExportableDocument.java │ │ ├── logging │ │ └── ConsoleLogger.java │ │ ├── main │ │ ├── CalculateTaxesMain.java │ │ └── SaveEmployeesMain.java │ │ ├── persistence │ │ ├── EmployeeFileSerializer.java │ │ └── EmployeeRepository.java │ │ ├── personnel │ │ ├── Employee.java │ │ ├── FullTimeEmployee.java │ │ ├── Intern.java │ │ └── PartTimeEmployee.java │ │ └── taxes │ │ ├── FullTimeTaxCalculator.java │ │ ├── InternTaxCalculator.java │ │ ├── PartTimeTaxCalculator.java │ │ ├── TaxCalculator.java │ │ └── TaxCalculatorFactory.java │ └── resources │ ├── taxes_business_requirements.txt │ └── taxes_business_requirements_v2.txt └── srp ├── before └── GlobomanticsHR │ ├── .idea │ ├── .name │ ├── compiler.xml │ ├── encodings.xml │ ├── misc.xml │ ├── modules.xml │ ├── vcs.xml │ └── workspace.xml │ ├── GlobomanticsHR.iml │ ├── hr.iml │ ├── pom.xml │ └── src │ └── main │ └── java │ └── hr │ ├── documents │ └── ExportableDocument.java │ ├── main │ └── SaveEmployeesMain.java │ ├── persistence │ └── EmployeeRepository.java │ └── personnel │ ├── Employee.java │ ├── FullTimeEmployee.java │ ├── Intern.java │ └── PartTimeEmployee.java ├── m3-sourcecode.zip └── refactored └── GlobomanticsHR ├── .idea ├── .name ├── compiler.xml ├── encodings.xml ├── misc.xml ├── modules.xml ├── vcs.xml └── workspace.xml ├── Anna_Smith.rec ├── Billy_Leech.rec ├── GlobomanticsHR.iml ├── Magda_Iovan.rec ├── Steve_Jones.rec ├── hr.iml ├── pom.xml └── src └── main └── java └── hr ├── documents └── ExportableDocument.java ├── logging └── ConsoleLogger.java ├── main └── SaveEmployeesMain.java ├── persistence ├── EmployeeFileSerializer.java └── EmployeeRepository.java └── personnel ├── Employee.java ├── FullTimeEmployee.java ├── Intern.java └── PartTimeEmployee.java /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | pom.xml.tag 3 | pom.xml.releaseBackup 4 | pom.xml.versionsBackup 5 | pom.xml.next 6 | release.properties 7 | dependency-reduced-pom.xml 8 | buildNumber.properties 9 | .mvn/timing.properties 10 | 11 | # Avoid ignoring Maven wrapper jar file (.jar files are usually ignored) 12 | !/.mvn/wrapper/maven-wrapper.jar 13 | 14 | .idea/ 15 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/.idea/.name: -------------------------------------------------------------------------------- 1 | hr -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/.idea/libraries/Maven__javax_activation_activation_1_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/.idea/libraries/Maven__javax_mail_mail_1_5_0_b01.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_5_0_RC1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_5_0_RC1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/.idea/libraries/Maven__org_opentest4j_opentest4j_1_2_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/GlobomanticsHR.iml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/hr.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | globomantics 8 | hr 9 | 1.0.0 10 | 11 | 12 | 1.8 13 | 1.8 14 | 15 | 16 | 17 | 18 | javax.mail 19 | mail 20 | 1.5.0-b01 21 | 22 | 23 | org.junit.jupiter 24 | junit-jupiter-api 25 | RELEASE 26 | test 27 | 28 | 29 | org.mockito 30 | mockito-all 31 | 1.9.5 32 | 33 | 34 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/src/main/java/hr/documents/ExportableJson.java: -------------------------------------------------------------------------------- 1 | package hr.documents; 2 | 3 | public interface ExportableJson { 4 | String toJson(); 5 | } 6 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/src/main/java/hr/documents/ExportablePdf.java: -------------------------------------------------------------------------------- 1 | package hr.documents; 2 | 3 | public interface ExportablePdf { 4 | byte[] toPdf(); 5 | } 6 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/src/main/java/hr/documents/ExportableText.java: -------------------------------------------------------------------------------- 1 | package hr.documents; 2 | 3 | public interface ExportableText { 4 | String toTxt(); 5 | } 6 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/src/main/java/hr/documents/Payslip.java: -------------------------------------------------------------------------------- 1 | package hr.documents; 2 | 3 | import hr.personnel.Employee; 4 | 5 | import java.time.Month; 6 | 7 | public class Payslip implements ExportableText { 8 | private String employeeName; 9 | private int monthlyIncome; 10 | private Month month; 11 | 12 | public Payslip(Employee employee, Month month) { 13 | this.employeeName = employee.getFullName(); 14 | this.monthlyIncome = employee.getMonthlyIncome(); 15 | this.month = month; 16 | } 17 | 18 | public Month getMonth() { 19 | return month; 20 | } 21 | 22 | public int getMonthlyIncome() { 23 | return monthlyIncome; 24 | } 25 | 26 | public String getEmployeeName() { 27 | return employeeName; 28 | } 29 | 30 | @Override 31 | public String toTxt() { 32 | StringBuilder sb = new StringBuilder(); 33 | sb.append("MONTH: ").append(this.month); 34 | sb.append(System.lineSeparator()); 35 | sb.append("NAME: ").append(this.employeeName); 36 | sb.append(System.lineSeparator()); 37 | sb.append("INCOME: ").append(this.monthlyIncome); 38 | sb.append(System.lineSeparator()); 39 | 40 | return sb.toString(); 41 | } 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/src/main/java/hr/documents/WorkContract.java: -------------------------------------------------------------------------------- 1 | package hr.documents; 2 | 3 | public class WorkContract implements 4 | ExportableJson, 5 | ExportableText, 6 | ExportablePdf { 7 | private String content; 8 | 9 | public WorkContract(String content) { 10 | this.content = content; 11 | } 12 | 13 | @Override 14 | public byte[] toPdf() { 15 | // Test implementation, in reality this would 16 | // be more complex 17 | return content.getBytes(); 18 | } 19 | 20 | @Override 21 | public String toJson() { 22 | // Test implementation, in reality this would 23 | // be more complex 24 | return "{'content':'" + this.content + "'}"; 25 | } 26 | 27 | @Override 28 | public String toTxt() { 29 | // Test implementation, in reality this would 30 | // be more complex 31 | return this.content; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/src/main/java/hr/logging/ConsoleLogger.java: -------------------------------------------------------------------------------- 1 | package hr.logging; 2 | 3 | public class ConsoleLogger { 4 | public void writeInfo(String msg) { 5 | System.out.println("Info: " + msg); 6 | } 7 | 8 | public void writeError(String msg, Exception e) { 9 | System.err.println("Error: " + msg + ";" + e); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/src/main/java/hr/main/ApproveSLAMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.personnel.ServiceLicenseAgreement; 4 | import hr.personnel.Subcontractor; 5 | 6 | import java.util.Arrays; 7 | import java.util.List; 8 | 9 | public class ApproveSLAMain { 10 | public static void main(String[] args) { 11 | // Define SLA 12 | int minTimeOffPercent = 98; 13 | int maxResolutionDays = 2; 14 | ServiceLicenseAgreement companySla = new ServiceLicenseAgreement( 15 | minTimeOffPercent, 16 | maxResolutionDays); 17 | 18 | // Get collaborators from their own source 19 | Subcontractor subcontractor1 = new Subcontractor( 20 | "Rebekah Jackson", 21 | "rebekah-jackson@abc.com", 22 | 3000, 23 | 15); 24 | Subcontractor subcontractor2 = new Subcontractor( 25 | "Harry Fitz", 26 | "harryfitz@def.com", 27 | 3000, 15); 28 | List collaborators = Arrays.asList(subcontractor1, subcontractor2); 29 | 30 | // Check SLA 31 | for (Subcontractor s : collaborators) { 32 | s.approveSLA(companySla); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/src/main/java/hr/main/CalculateEmployeeTaxesMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.logging.ConsoleLogger; 4 | import hr.persistence.EmployeeFileSerializer; 5 | import hr.persistence.EmployeeFileRepository; 6 | import hr.personnel.Employee; 7 | import hr.taxes.TaxCalculator; 8 | import hr.taxes.TaxCalculatorFactory; 9 | 10 | import java.text.NumberFormat; 11 | import java.util.List; 12 | import java.util.Locale; 13 | 14 | public class CalculateEmployeeTaxesMain { 15 | public static void main(String[] args) { 16 | // Create dependencies 17 | ConsoleLogger consoleLogger = new ConsoleLogger(); 18 | EmployeeFileSerializer employeeFileSerializer = new EmployeeFileSerializer(); 19 | EmployeeFileRepository repository = new EmployeeFileRepository(employeeFileSerializer); 20 | 21 | // Grab employees 22 | List employees = repository.findAll(); 23 | 24 | // Calculate taxes 25 | Locale locale = new Locale("en", "US"); 26 | NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(locale); 27 | 28 | double totalTaxes = 0; 29 | for (Employee employee: employees){ 30 | TaxCalculator taxCalculator = TaxCalculatorFactory.create(employee); 31 | 32 | // compute individual tax 33 | double tax = taxCalculator.calculate(employee); 34 | String formattedTax = currencyFormatter.format(tax); 35 | consoleLogger.writeInfo(employee.getFullName() + " taxes: " + formattedTax); 36 | 37 | // add to company total taxes 38 | totalTaxes += taxCalculator.calculate(employee); 39 | } 40 | consoleLogger.writeInfo("Total taxes = " + currencyFormatter.format(totalTaxes)); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/src/main/java/hr/main/ExportPayslipMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.documents.Payslip; 4 | import hr.logging.ConsoleLogger; 5 | import hr.persistence.EmployeeFileSerializer; 6 | import hr.persistence.EmployeeFileRepository; 7 | import hr.personnel.Employee; 8 | 9 | import java.time.Month; 10 | import java.util.List; 11 | 12 | public class ExportPayslipMain { 13 | public static void main(String[] args) { 14 | // Create dependencies 15 | ConsoleLogger consoleLogger = new ConsoleLogger(); 16 | EmployeeFileSerializer employeeFileSerializer = new EmployeeFileSerializer(); 17 | EmployeeFileRepository repository = new EmployeeFileRepository(employeeFileSerializer); 18 | 19 | // Grab employees 20 | List employees = repository.findAll(); 21 | 22 | for (Employee employee : employees){ 23 | Payslip payslip = new Payslip(employee , Month.AUGUST); 24 | 25 | String exportableText = payslip.toTxt().toUpperCase(); 26 | System.out.println(exportableText); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/src/main/java/hr/main/NatHolidayEmployeeTimeOffMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.logging.ConsoleLogger; 4 | import hr.persistence.EmployeeFileSerializer; 5 | import hr.persistence.EmployeeFileRepository; 6 | import hr.personnel.Employee; 7 | import hr.personnel.FullTimeEmployee; 8 | 9 | import java.util.List; 10 | 11 | public class NatHolidayEmployeeTimeOffMain { 12 | public static void main(String[] args) { 13 | // Create dependencies 14 | ConsoleLogger consoleLogger = new ConsoleLogger(); 15 | EmployeeFileSerializer employeeFileSerializer = new EmployeeFileSerializer(); 16 | EmployeeFileRepository repository = new EmployeeFileRepository(employeeFileSerializer); 17 | 18 | // Grab employees 19 | List employees = repository.findAll(); 20 | Employee manager = new FullTimeEmployee("Steve Jackson", 5000); 21 | 22 | // Request time off for each employee on 23 | // national holiday 24 | for (Employee employee : employees){ 25 | employee.requestTimeOff(1, manager); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/src/main/java/hr/main/PayEmployeesMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.payment.PaymentProcessor; 4 | 5 | public class PayEmployeesMain { 6 | 7 | /* 8 | Will take a couple of seconds to execute due to the 9 | sending of mails. 10 | */ 11 | 12 | public static void main(String[] args) { 13 | PaymentProcessor paymentProcessor = new PaymentProcessor(); 14 | int totalPayments = paymentProcessor.sendPayments(); 15 | System.out.println("Total payments " + totalPayments); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/src/main/java/hr/main/SaveEmployeesMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.logging.ConsoleLogger; 4 | import hr.persistence.EmployeeFileSerializer; 5 | import hr.persistence.EmployeeFileRepository; 6 | import hr.personnel.Employee; 7 | 8 | import java.io.IOException; 9 | import java.util.List; 10 | 11 | public class SaveEmployeesMain { 12 | public static void main(String[] args) { 13 | // Grab employees 14 | EmployeeFileSerializer employeeFileSerializer = new EmployeeFileSerializer(); 15 | ConsoleLogger consoleLogger = new ConsoleLogger(); 16 | 17 | EmployeeFileRepository repository = new EmployeeFileRepository(employeeFileSerializer); 18 | List employees = repository.findAll(); 19 | 20 | // Save all 21 | for (Employee e : employees){ 22 | try { 23 | repository.save(e); 24 | consoleLogger.writeInfo("Saved employee " + e.toString()); 25 | } catch (IOException exception) { 26 | consoleLogger.writeError("Error saving employee", exception); 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/src/main/java/hr/payment/PaymentProcessor.java: -------------------------------------------------------------------------------- 1 | package hr.payment; 2 | 3 | import hr.notifications.EmailSender; 4 | import hr.persistence.EmployeeFileRepository; 5 | import hr.persistence.EmployeeFileSerializer; 6 | import hr.personnel.Employee; 7 | 8 | import java.util.List; 9 | 10 | public class PaymentProcessor { 11 | 12 | private EmployeeFileRepository employeeRepository; 13 | 14 | public PaymentProcessor(){ 15 | EmployeeFileSerializer serializer = 16 | new EmployeeFileSerializer(); 17 | this.employeeRepository = 18 | new EmployeeFileRepository(serializer); 19 | } 20 | 21 | public int sendPayments(){ 22 | List employees = this.employeeRepository.findAll(); 23 | int totalPayments = 0; 24 | 25 | for(Employee employee : employees){ 26 | totalPayments += employee.getMonthlyIncome(); 27 | EmailSender.notify(employee); 28 | } 29 | 30 | return totalPayments; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/src/main/java/hr/persistence/EmployeeFileSerializer.java: -------------------------------------------------------------------------------- 1 | package hr.persistence; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public class EmployeeFileSerializer { 6 | public String serialize(Employee employee) { 7 | StringBuilder sb = new StringBuilder(); 8 | 9 | sb.append("### EMPLOYEE RECORD ####"); 10 | sb.append(System.lineSeparator()); 11 | sb.append("NAME: "); 12 | sb.append(employee.getFullName()); 13 | sb.append(System.lineSeparator()); 14 | sb.append("POSITION: "); 15 | sb.append(employee.getClass().getTypeName()); 16 | sb.append(System.lineSeparator()); 17 | sb.append("EMAIL: "); 18 | sb.append(employee.getEmail()); 19 | sb.append(System.lineSeparator()); 20 | sb.append("MONTHLY WAGE: "); 21 | sb.append(employee.getMonthlyIncome()); 22 | sb.append(System.lineSeparator()); 23 | 24 | return sb.toString(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/src/main/java/hr/personnel/Employee.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | /* 4 | Models an employee form a business perspective 5 | */ 6 | public abstract class Employee { 7 | private String firstName; 8 | private String lastName; 9 | private int monthlyIncome; 10 | private int nbHoursPerWeek; 11 | 12 | public Employee(String fullName, int monthlyIncome) { 13 | setMonthlyIncome(monthlyIncome); 14 | 15 | String[] names = fullName.split(" "); 16 | this.firstName = names[0]; 17 | this.lastName = names[1]; 18 | } 19 | 20 | public String getEmail() { 21 | return this.firstName + "." + 22 | this.lastName + 23 | "@globomanticshr.com"; 24 | } 25 | 26 | public abstract void requestTimeOff(int nbDays, Employee manager); 27 | 28 | @Override 29 | public String toString() { 30 | return this.firstName + " " + 31 | this.lastName + " - " + 32 | this.monthlyIncome; 33 | } 34 | 35 | public int getMonthlyIncome() { 36 | return monthlyIncome; 37 | } 38 | 39 | public void setMonthlyIncome(int monthlyIncome) { 40 | if (monthlyIncome < 0) { 41 | throw new IllegalArgumentException("Income must be positive"); 42 | } 43 | 44 | this.monthlyIncome = monthlyIncome; 45 | } 46 | 47 | public int getNbHoursPerWeek() { 48 | return nbHoursPerWeek; 49 | } 50 | 51 | public void setNbHoursPerWeek(int nbHoursPerWeek) { 52 | if (nbHoursPerWeek <= 0) { 53 | throw new IllegalArgumentException("Income must be positive"); 54 | } 55 | 56 | this.nbHoursPerWeek = nbHoursPerWeek; 57 | } 58 | 59 | public String getFullName() { 60 | return this.firstName + " " + this.lastName; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/src/main/java/hr/personnel/FullTimeEmployee.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class FullTimeEmployee extends Employee { 4 | public FullTimeEmployee(String fullName, int monthlyIncome) { 5 | super(fullName, monthlyIncome); 6 | this.setNbHoursPerWeek(40); 7 | } 8 | 9 | @Override 10 | public void requestTimeOff(int nbDays, Employee manager) { 11 | /* 12 | HR business logic for time off for full time employees 13 | */ 14 | 15 | System.out.println("Time off request for full time employee " + 16 | this.getFullName() + 17 | "; Nb days " + nbDays + 18 | "; Requested from " + manager.getFullName()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/src/main/java/hr/personnel/Intern.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class Intern extends Employee { 4 | public Intern(String fullName, int monthlyIncome, int nbHours) { 5 | super(fullName, monthlyIncome); 6 | setNbHoursPerWeek(nbHours); 7 | } 8 | 9 | @Override 10 | public void requestTimeOff(int nbDays, Employee manager) { 11 | /* 12 | HR business logic for time off for interns 13 | */ 14 | 15 | System.out.println("Time off request for intern " + 16 | this.getFullName() + 17 | "; Nb days " + nbDays + 18 | "; Requested from " + manager.getFullName()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/src/main/java/hr/personnel/PartTimeEmployee.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class PartTimeEmployee extends Employee { 4 | public PartTimeEmployee(String fullName, int monthlyIncome) { 5 | super(fullName, monthlyIncome); 6 | this.setNbHoursPerWeek(20); 7 | } 8 | 9 | @Override 10 | public void requestTimeOff(int nbDays, Employee manager) { 11 | /* 12 | HR business logic for time off for part time employees 13 | */ 14 | 15 | System.out.println("Time off request for part time employee " + 16 | this.getFullName() + 17 | "; Nb days " + nbDays + 18 | "; Requested from " + manager.getFullName()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/src/main/java/hr/personnel/ServiceLicenseAgreement.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class ServiceLicenseAgreement { 4 | private int minUptimePercent; 5 | private int problemResolutionTimeDays; 6 | 7 | public ServiceLicenseAgreement(int minUptime, int problemResolutionTimeDays) { 8 | this.minUptimePercent = minUptime; 9 | this.problemResolutionTimeDays = problemResolutionTimeDays; 10 | } 11 | 12 | public int getMinUptimePercent() { 13 | return minUptimePercent; 14 | } 15 | 16 | public int getProblemResolutionTimeDays() { 17 | return problemResolutionTimeDays; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/src/main/java/hr/personnel/Subcontractor.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class Subcontractor { 4 | 5 | private final int monthlyIncome; 6 | private int nbHoursPerWeek; 7 | private String email; 8 | private String name; 9 | 10 | public Subcontractor(String name, 11 | String email, 12 | int monthlyIncome, 13 | int nbHoursPerWeek) { 14 | 15 | this.name = name; 16 | this.email = email; 17 | this.monthlyIncome = monthlyIncome; 18 | this.nbHoursPerWeek = nbHoursPerWeek; 19 | } 20 | 21 | public boolean approveSLA(ServiceLicenseAgreement sla) { 22 | boolean result = false; 23 | if (sla.getMinUptimePercent() >= 98 && 24 | sla.getProblemResolutionTimeDays() <= 2) { 25 | result = true; 26 | } 27 | 28 | System.out.println("SLA approval for " + this.name + ": " + result); 29 | return result; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/src/main/java/hr/taxes/FullTimeTaxCalculator.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public class FullTimeTaxCalculator implements TaxCalculator { 6 | private final int RETIREMENT_TAX_PERCENTAGE = 10; 7 | private final int INCOME_TAX_PERCENTAGE = 16; 8 | private final int BASE_HEALTH_INSURANCE = 100; 9 | 10 | 11 | public double calculate(Employee employee) { 12 | return BASE_HEALTH_INSURANCE + 13 | (employee.getMonthlyIncome() * RETIREMENT_TAX_PERCENTAGE) / 100 + 14 | (employee.getMonthlyIncome() * INCOME_TAX_PERCENTAGE) / 100; 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/src/main/java/hr/taxes/InternTaxCalculator.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public class InternTaxCalculator implements TaxCalculator { 6 | private final int INCOME_TAX_PERCENTAGE = 16; 7 | 8 | public double calculate(Employee employee) { 9 | int monthlyIncome = employee.getMonthlyIncome(); 10 | if (monthlyIncome < 350) { 11 | return 0; 12 | } else { 13 | return (monthlyIncome * INCOME_TAX_PERCENTAGE) / 100; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/src/main/java/hr/taxes/PartTimeTaxCalculator.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public class PartTimeTaxCalculator implements TaxCalculator { 6 | private final int RETIREMENT_TAX_PERCENTAGE = 5; 7 | private final int INCOME_TAX_PERCENTAGE = 16; 8 | private final int BASE_HEALTH_INSURANCE = 100; 9 | 10 | public double calculate(Employee employee) { 11 | int monthlyIncome = employee.getMonthlyIncome(); 12 | return BASE_HEALTH_INSURANCE + 13 | (monthlyIncome * RETIREMENT_TAX_PERCENTAGE) / 100 + 14 | (monthlyIncome * INCOME_TAX_PERCENTAGE) / 100; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/src/main/java/hr/taxes/TaxCalculator.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public interface TaxCalculator { 6 | double calculate(Employee employee); 7 | } 8 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/src/main/java/hr/taxes/TaxCalculatorFactory.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | import hr.personnel.FullTimeEmployee; 5 | import hr.personnel.Intern; 6 | import hr.personnel.PartTimeEmployee; 7 | 8 | public class TaxCalculatorFactory { 9 | public static TaxCalculator create(Employee employee) { 10 | if (employee instanceof FullTimeEmployee) { 11 | return new FullTimeTaxCalculator(); 12 | } 13 | 14 | if (employee instanceof PartTimeEmployee) { 15 | return new PartTimeTaxCalculator(); 16 | } 17 | 18 | if (employee instanceof Intern) { 19 | return new InternTaxCalculator(); 20 | } 21 | 22 | throw new RuntimeException("Invalid employee type"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/src/main/resources/employees.csv: -------------------------------------------------------------------------------- 1 | Name,Income,Nb Hours/Week 2 | Anna Smith,2000,40 3 | Billy Leach,920,40 4 | Steve Jones,800,20 5 | Magda Iovan,920,20, 6 | John Lee,300,10, 7 | Catherine Allison,500,15 8 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/src/main/resources/payment_business_requirements.txt: -------------------------------------------------------------------------------- 1 | #Business Requirement Document 2 | #Version 1.0 3 | 4 | We need a system that can retrieve all employees 5 | and pay their incomes. 6 | 7 | Upon completion, the total paid sum must be calculated in order 8 | to compare it with the finance department. 9 | 10 | Each employee should receive an email after the income payment 11 | was sent successfully. -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/src/main/resources/payslip_business_requirements.txt: -------------------------------------------------------------------------------- 1 | #Business Requirement Document 2 | #Version 1.0 3 | 4 | The team needs to implement an exportable document: payslip. 5 | It should contain the following information: 6 | - month of income 7 | - name of employee 8 | - income of employee for the given month 9 | 10 | At the moment we just want to export as text but it 11 | might be possible to extend this to other formats. -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/src/main/resources/subcontractor_business_requirements.txt: -------------------------------------------------------------------------------- 1 | #Business Requirement Document 2 | #Version 1.0 3 | 4 | A subcontractor is an entity that works similar to an employee 5 | for various projects. We need to implement this feature because in most 6 | companies employees work with external collaborators. 7 | 8 | We are interested in the contact info (name, own email), 9 | cost (monthly income) and nb of hours worked. 10 | 11 | They need to have an SLA approved before working. 12 | 13 | Because subcontractors are external, they are not eligible 14 | to time off. Nor do we need to calculate taxes for them. 15 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/src/main/resources/taxes_business_requirements.txt: -------------------------------------------------------------------------------- 1 | #Business Requirement Document 2 | #Version 1.0 3 | 4 | Taxes for employees are calculated like this: 5 | 6 | - Fixed $100 amount for base health insurance 7 | - 16% income tax 8 | - 10% retirement tax -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/src/main/resources/taxes_business_requirements_v2.txt: -------------------------------------------------------------------------------- 1 | #Business Requirement Document 2 | #Version 2.0 3 | 4 | Taxes for employees are calculated like this: 5 | 6 | 1) For full time employees 7 | 8 | - Fixed $100 amount for base health insurance 9 | - 16% income tax 10 | - 10% retirement tax 11 | 12 | 2) For part time employees 13 | 14 | - Fixed $100 amount for base health insurance 15 | - 16% income tax 16 | - 5% retirement tax 17 | 18 | 3) For interns 19 | - If income < 350 => no tax due to state aid 20 | - Else => only 16% income tax 21 | -------------------------------------------------------------------------------- /dip/before/GlobomanticsHR/src/test/java/hr/payment/PaymentProcessorTest.java: -------------------------------------------------------------------------------- 1 | package hr.payment; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | public class PaymentProcessorTest { 8 | 9 | @Test 10 | public void send_payments_should_pay_all_employee_salaries(){ 11 | // arrange 12 | PaymentProcessor paymentProcessor = new PaymentProcessor(); 13 | 14 | // act 15 | int result = paymentProcessor.sendPayments(); 16 | 17 | // assert 18 | assertEquals(5440, result); 19 | } 20 | } -------------------------------------------------------------------------------- /dip/m7_sourcecode.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dangeabunea/pluralsight-solid-principles-java/745a3f35a6a31fb653fadabc42ec788cafda1ceb/dip/m7_sourcecode.zip -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/.idea/.name: -------------------------------------------------------------------------------- 1 | hr -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/GlobomanticsHR.iml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/hr.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | globomantics 8 | hr 9 | 1.0.0 10 | 11 | 12 | 1.8 13 | 1.8 14 | 15 | 16 | 17 | 18 | javax.mail 19 | mail 20 | 1.5.0-b01 21 | 22 | 23 | org.junit.jupiter 24 | junit-jupiter-api 25 | RELEASE 26 | test 27 | 28 | 29 | org.mockito 30 | mockito-all 31 | 1.9.5 32 | 33 | 34 | -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/src/main/java/hr/documents/ExportableJson.java: -------------------------------------------------------------------------------- 1 | package hr.documents; 2 | 3 | public interface ExportableJson { 4 | String toJson(); 5 | } 6 | -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/src/main/java/hr/documents/ExportablePdf.java: -------------------------------------------------------------------------------- 1 | package hr.documents; 2 | 3 | public interface ExportablePdf { 4 | byte[] toPdf(); 5 | } 6 | -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/src/main/java/hr/documents/ExportableText.java: -------------------------------------------------------------------------------- 1 | package hr.documents; 2 | 3 | public interface ExportableText { 4 | String toTxt(); 5 | } 6 | -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/src/main/java/hr/documents/Payslip.java: -------------------------------------------------------------------------------- 1 | package hr.documents; 2 | 3 | import hr.personnel.Employee; 4 | 5 | import java.time.Month; 6 | 7 | public class Payslip implements ExportableText { 8 | private String employeeName; 9 | private int monthlyIncome; 10 | private Month month; 11 | 12 | public Payslip(Employee employee, Month month) { 13 | this.employeeName = employee.getFullName(); 14 | this.monthlyIncome = employee.getMonthlyIncome(); 15 | this.month = month; 16 | } 17 | 18 | public Month getMonth() { 19 | return month; 20 | } 21 | 22 | public int getMonthlyIncome() { 23 | return monthlyIncome; 24 | } 25 | 26 | public String getEmployeeName() { 27 | return employeeName; 28 | } 29 | 30 | @Override 31 | public String toTxt() { 32 | StringBuilder sb = new StringBuilder(); 33 | sb.append("MONTH: ").append(this.month); 34 | sb.append(System.lineSeparator()); 35 | sb.append("NAME: ").append(this.employeeName); 36 | sb.append(System.lineSeparator()); 37 | sb.append("INCOME: ").append(this.monthlyIncome); 38 | sb.append(System.lineSeparator()); 39 | 40 | return sb.toString(); 41 | } 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/src/main/java/hr/documents/WorkContract.java: -------------------------------------------------------------------------------- 1 | package hr.documents; 2 | 3 | public class WorkContract implements 4 | ExportableJson, 5 | ExportableText, 6 | ExportablePdf { 7 | private String content; 8 | 9 | public WorkContract(String content) { 10 | this.content = content; 11 | } 12 | 13 | @Override 14 | public byte[] toPdf() { 15 | // Test implementation, in reality this would 16 | // be more complex 17 | return content.getBytes(); 18 | } 19 | 20 | @Override 21 | public String toJson() { 22 | // Test implementation, in reality this would 23 | // be more complex 24 | return "{'content':'" + this.content + "'}"; 25 | } 26 | 27 | @Override 28 | public String toTxt() { 29 | // Test implementation, in reality this would 30 | // be more complex 31 | return this.content; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/src/main/java/hr/logging/ConsoleLogger.java: -------------------------------------------------------------------------------- 1 | package hr.logging; 2 | 3 | public class ConsoleLogger { 4 | public void writeInfo(String msg) { 5 | System.out.println("Info: " + msg); 6 | } 7 | 8 | public void writeError(String msg, Exception e) { 9 | System.err.println("Error: " + msg + ";" + e); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/src/main/java/hr/main/ApproveSLAMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.personnel.ServiceLicenseAgreement; 4 | import hr.personnel.Subcontractor; 5 | 6 | import java.util.Arrays; 7 | import java.util.List; 8 | 9 | public class ApproveSLAMain { 10 | public static void main(String[] args) { 11 | // Define SLA 12 | int minTimeOffPercent = 98; 13 | int maxResolutionDays = 2; 14 | ServiceLicenseAgreement companySla = new ServiceLicenseAgreement( 15 | minTimeOffPercent, 16 | maxResolutionDays); 17 | 18 | // Get collaborators from their own source 19 | Subcontractor subcontractor1 = new Subcontractor( 20 | "Rebekah Jackson", 21 | "rebekah-jackson@abc.com", 22 | 3000, 23 | 15); 24 | Subcontractor subcontractor2 = new Subcontractor( 25 | "Harry Fitz", 26 | "harryfitz@def.com", 27 | 3000, 15); 28 | List collaborators = Arrays.asList(subcontractor1, subcontractor2); 29 | 30 | // Check SLA 31 | for (Subcontractor s : collaborators) { 32 | s.approveSLA(companySla); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/src/main/java/hr/main/CalculateEmployeeTaxesMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.logging.ConsoleLogger; 4 | import hr.persistence.EmployeeFileSerializer; 5 | import hr.persistence.EmployeeFileRepository; 6 | import hr.personnel.Employee; 7 | import hr.taxes.TaxCalculator; 8 | import hr.taxes.TaxCalculatorFactory; 9 | 10 | import java.text.NumberFormat; 11 | import java.util.List; 12 | import java.util.Locale; 13 | 14 | public class CalculateEmployeeTaxesMain { 15 | public static void main(String[] args) { 16 | // Create dependencies 17 | ConsoleLogger consoleLogger = new ConsoleLogger(); 18 | EmployeeFileSerializer employeeFileSerializer = new EmployeeFileSerializer(); 19 | EmployeeFileRepository repository = new EmployeeFileRepository(employeeFileSerializer); 20 | 21 | // Grab employees 22 | List employees = repository.findAll(); 23 | 24 | // Calculate taxes 25 | Locale locale = new Locale("en", "US"); 26 | NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(locale); 27 | 28 | double totalTaxes = 0; 29 | for (Employee employee: employees){ 30 | TaxCalculator taxCalculator = TaxCalculatorFactory.create(employee); 31 | 32 | // compute individual tax 33 | double tax = taxCalculator.calculate(employee); 34 | String formattedTax = currencyFormatter.format(tax); 35 | consoleLogger.writeInfo(employee.getFullName() + " taxes: " + formattedTax); 36 | 37 | // add to company total taxes 38 | totalTaxes += taxCalculator.calculate(employee); 39 | } 40 | consoleLogger.writeInfo("Total taxes = " + currencyFormatter.format(totalTaxes)); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/src/main/java/hr/main/ExportPayslipMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.documents.Payslip; 4 | import hr.logging.ConsoleLogger; 5 | import hr.persistence.EmployeeFileSerializer; 6 | import hr.persistence.EmployeeFileRepository; 7 | import hr.personnel.Employee; 8 | 9 | import java.time.Month; 10 | import java.util.List; 11 | 12 | public class ExportPayslipMain { 13 | public static void main(String[] args) { 14 | // Create dependencies 15 | ConsoleLogger consoleLogger = new ConsoleLogger(); 16 | EmployeeFileSerializer employeeFileSerializer = new EmployeeFileSerializer(); 17 | EmployeeFileRepository repository = new EmployeeFileRepository(employeeFileSerializer); 18 | 19 | // Grab employees 20 | List employees = repository.findAll(); 21 | 22 | for (Employee employee : employees){ 23 | Payslip payslip = new Payslip(employee , Month.AUGUST); 24 | 25 | String exportableText = payslip.toTxt().toUpperCase(); 26 | System.out.println(exportableText); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/src/main/java/hr/main/NatHolidayEmployeeTimeOffMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.logging.ConsoleLogger; 4 | import hr.persistence.EmployeeFileSerializer; 5 | import hr.persistence.EmployeeFileRepository; 6 | import hr.personnel.Employee; 7 | import hr.personnel.FullTimeEmployee; 8 | 9 | import java.util.List; 10 | 11 | public class NatHolidayEmployeeTimeOffMain { 12 | public static void main(String[] args) { 13 | // Create dependencies 14 | ConsoleLogger consoleLogger = new ConsoleLogger(); 15 | EmployeeFileSerializer employeeFileSerializer = new EmployeeFileSerializer(); 16 | EmployeeFileRepository repository = new EmployeeFileRepository(employeeFileSerializer); 17 | 18 | // Grab employees 19 | List employees = repository.findAll(); 20 | Employee manager = new FullTimeEmployee("Steve Jackson", 5000); 21 | 22 | // Request time off for each employee on 23 | // national holiday 24 | for (Employee employee : employees){ 25 | employee.requestTimeOff(1, manager); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/src/main/java/hr/main/PayEmployeesMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.notifications.EmailSender; 4 | import hr.notifications.EmployeeNotifier; 5 | import hr.payment.PaymentProcessor; 6 | import hr.persistence.EmployeeFileRepository; 7 | import hr.persistence.EmployeeFileSerializer; 8 | import hr.persistence.EmployeeRepository; 9 | 10 | public class PayEmployeesMain { 11 | 12 | /* 13 | Will take a couple of seconds to execute due to the 14 | sending of mails. 15 | */ 16 | 17 | public static void main(String[] args) { 18 | 19 | EmployeeFileSerializer serializer = new EmployeeFileSerializer(); 20 | EmployeeRepository employeeRepository = 21 | new EmployeeFileRepository(serializer); 22 | EmployeeNotifier employeeNotifier = new EmailSender(); 23 | PaymentProcessor paymentProcessor = new PaymentProcessor( 24 | employeeRepository, 25 | employeeNotifier); 26 | 27 | int totalPayments = paymentProcessor.sendPayments(); 28 | System.out.println("Total payments " + totalPayments); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/src/main/java/hr/main/SaveEmployeesMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.logging.ConsoleLogger; 4 | import hr.persistence.EmployeeFileSerializer; 5 | import hr.persistence.EmployeeFileRepository; 6 | import hr.personnel.Employee; 7 | 8 | import java.io.IOException; 9 | import java.util.List; 10 | 11 | public class SaveEmployeesMain { 12 | public static void main(String[] args) { 13 | // Grab employees 14 | EmployeeFileSerializer employeeFileSerializer = new EmployeeFileSerializer(); 15 | ConsoleLogger consoleLogger = new ConsoleLogger(); 16 | 17 | EmployeeFileRepository repository = new EmployeeFileRepository(employeeFileSerializer); 18 | List employees = repository.findAll(); 19 | 20 | // Save all 21 | for (Employee e : employees){ 22 | try { 23 | repository.save(e); 24 | consoleLogger.writeInfo("Saved employee " + e.toString()); 25 | } catch (IOException exception) { 26 | consoleLogger.writeError("Error saving employee", exception); 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/src/main/java/hr/notifications/EmployeeNotifier.java: -------------------------------------------------------------------------------- 1 | package hr.notifications; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public interface EmployeeNotifier { 6 | void notify(Employee employee); 7 | } 8 | -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/src/main/java/hr/payment/PaymentProcessor.java: -------------------------------------------------------------------------------- 1 | package hr.payment; 2 | 3 | import hr.notifications.EmployeeNotifier; 4 | import hr.persistence.EmployeeRepository; 5 | import hr.personnel.Employee; 6 | 7 | import java.util.List; 8 | 9 | public class PaymentProcessor { 10 | 11 | private EmployeeRepository employeeRepository; 12 | private EmployeeNotifier employeeNotifier; 13 | 14 | public PaymentProcessor(EmployeeRepository employeeRepository, 15 | EmployeeNotifier employeeNotifier){ 16 | this.employeeRepository = employeeRepository; 17 | this.employeeNotifier = employeeNotifier; 18 | } 19 | 20 | public int sendPayments(){ 21 | List employees = this.employeeRepository.findAll(); 22 | int totalPayments = 0; 23 | 24 | for(Employee employee : employees){ 25 | totalPayments += employee.getMonthlyIncome(); 26 | this.employeeNotifier.notify(employee); 27 | } 28 | 29 | return totalPayments; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/src/main/java/hr/persistence/EmployeeFileSerializer.java: -------------------------------------------------------------------------------- 1 | package hr.persistence; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public class EmployeeFileSerializer { 6 | public String serialize(Employee employee) { 7 | StringBuilder sb = new StringBuilder(); 8 | 9 | sb.append("### EMPLOYEE RECORD ####"); 10 | sb.append(System.lineSeparator()); 11 | sb.append("NAME: "); 12 | sb.append(employee.getFullName()); 13 | sb.append(System.lineSeparator()); 14 | sb.append("POSITION: "); 15 | sb.append(employee.getClass().getTypeName()); 16 | sb.append(System.lineSeparator()); 17 | sb.append("EMAIL: "); 18 | sb.append(employee.getEmail()); 19 | sb.append(System.lineSeparator()); 20 | sb.append("MONTHLY WAGE: "); 21 | sb.append(employee.getMonthlyIncome()); 22 | sb.append(System.lineSeparator()); 23 | 24 | return sb.toString(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/src/main/java/hr/persistence/EmployeeRepository.java: -------------------------------------------------------------------------------- 1 | package hr.persistence; 2 | 3 | import hr.personnel.Employee; 4 | 5 | import java.io.IOException; 6 | import java.util.List; 7 | 8 | public interface EmployeeRepository { 9 | List findAll(); 10 | void save(Employee employee) throws IOException; 11 | } 12 | -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/src/main/java/hr/personnel/FullTimeEmployee.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class FullTimeEmployee extends Employee { 4 | public FullTimeEmployee(String fullName, int monthlyIncome) { 5 | super(fullName, monthlyIncome); 6 | this.setNbHoursPerWeek(40); 7 | } 8 | 9 | @Override 10 | public void requestTimeOff(int nbDays, Employee manager) { 11 | /* 12 | HR business logic for time off for full time employees 13 | */ 14 | 15 | System.out.println("Time off request for full time employee " + 16 | this.getFullName() + 17 | "; Nb days " + nbDays + 18 | "; Requested from " + manager.getFullName()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/src/main/java/hr/personnel/Intern.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class Intern extends Employee { 4 | public Intern(String fullName, int monthlyIncome, int nbHours) { 5 | super(fullName, monthlyIncome); 6 | setNbHoursPerWeek(nbHours); 7 | } 8 | 9 | @Override 10 | public void requestTimeOff(int nbDays, Employee manager) { 11 | /* 12 | HR business logic for time off for interns 13 | */ 14 | 15 | System.out.println("Time off request for intern " + 16 | this.getFullName() + 17 | "; Nb days " + nbDays + 18 | "; Requested from " + manager.getFullName()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/src/main/java/hr/personnel/PartTimeEmployee.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class PartTimeEmployee extends Employee { 4 | public PartTimeEmployee(String fullName, int monthlyIncome) { 5 | super(fullName, monthlyIncome); 6 | this.setNbHoursPerWeek(20); 7 | } 8 | 9 | @Override 10 | public void requestTimeOff(int nbDays, Employee manager) { 11 | /* 12 | HR business logic for time off for part time employees 13 | */ 14 | 15 | System.out.println("Time off request for part time employee " + 16 | this.getFullName() + 17 | "; Nb days " + nbDays + 18 | "; Requested from " + manager.getFullName()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/src/main/java/hr/personnel/ServiceLicenseAgreement.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class ServiceLicenseAgreement { 4 | private int minUptimePercent; 5 | private int problemResolutionTimeDays; 6 | 7 | public ServiceLicenseAgreement(int minUptime, int problemResolutionTimeDays) { 8 | this.minUptimePercent = minUptime; 9 | this.problemResolutionTimeDays = problemResolutionTimeDays; 10 | } 11 | 12 | public int getMinUptimePercent() { 13 | return minUptimePercent; 14 | } 15 | 16 | public int getProblemResolutionTimeDays() { 17 | return problemResolutionTimeDays; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/src/main/java/hr/personnel/Subcontractor.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class Subcontractor { 4 | 5 | private final int monthlyIncome; 6 | private int nbHoursPerWeek; 7 | private String email; 8 | private String name; 9 | 10 | public Subcontractor(String name, 11 | String email, 12 | int monthlyIncome, 13 | int nbHoursPerWeek) { 14 | 15 | this.name = name; 16 | this.email = email; 17 | this.monthlyIncome = monthlyIncome; 18 | this.nbHoursPerWeek = nbHoursPerWeek; 19 | } 20 | 21 | public boolean approveSLA(ServiceLicenseAgreement sla) { 22 | boolean result = false; 23 | if (sla.getMinUptimePercent() >= 98 && 24 | sla.getProblemResolutionTimeDays() <= 2) { 25 | result = true; 26 | } 27 | 28 | System.out.println("SLA approval for " + this.name + ": " + result); 29 | return result; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/src/main/java/hr/taxes/FullTimeTaxCalculator.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public class FullTimeTaxCalculator implements TaxCalculator { 6 | private final int RETIREMENT_TAX_PERCENTAGE = 10; 7 | private final int INCOME_TAX_PERCENTAGE = 16; 8 | private final int BASE_HEALTH_INSURANCE = 100; 9 | 10 | 11 | public double calculate(Employee employee) { 12 | return BASE_HEALTH_INSURANCE + 13 | (employee.getMonthlyIncome() * RETIREMENT_TAX_PERCENTAGE) / 100 + 14 | (employee.getMonthlyIncome() * INCOME_TAX_PERCENTAGE) / 100; 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/src/main/java/hr/taxes/InternTaxCalculator.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public class InternTaxCalculator implements TaxCalculator { 6 | private final int INCOME_TAX_PERCENTAGE = 16; 7 | 8 | public double calculate(Employee employee) { 9 | int monthlyIncome = employee.getMonthlyIncome(); 10 | if (monthlyIncome < 350) { 11 | return 0; 12 | } else { 13 | return (monthlyIncome * INCOME_TAX_PERCENTAGE) / 100; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/src/main/java/hr/taxes/PartTimeTaxCalculator.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public class PartTimeTaxCalculator implements TaxCalculator { 6 | private final int RETIREMENT_TAX_PERCENTAGE = 5; 7 | private final int INCOME_TAX_PERCENTAGE = 16; 8 | private final int BASE_HEALTH_INSURANCE = 100; 9 | 10 | public double calculate(Employee employee) { 11 | int monthlyIncome = employee.getMonthlyIncome(); 12 | return BASE_HEALTH_INSURANCE + 13 | (monthlyIncome * RETIREMENT_TAX_PERCENTAGE) / 100 + 14 | (monthlyIncome * INCOME_TAX_PERCENTAGE) / 100; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/src/main/java/hr/taxes/TaxCalculator.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public interface TaxCalculator { 6 | double calculate(Employee employee); 7 | } 8 | -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/src/main/java/hr/taxes/TaxCalculatorFactory.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | import hr.personnel.FullTimeEmployee; 5 | import hr.personnel.Intern; 6 | import hr.personnel.PartTimeEmployee; 7 | 8 | public class TaxCalculatorFactory { 9 | public static TaxCalculator create(Employee employee) { 10 | if (employee instanceof FullTimeEmployee) { 11 | return new FullTimeTaxCalculator(); 12 | } 13 | 14 | if (employee instanceof PartTimeEmployee) { 15 | return new PartTimeTaxCalculator(); 16 | } 17 | 18 | if (employee instanceof Intern) { 19 | return new InternTaxCalculator(); 20 | } 21 | 22 | throw new RuntimeException("Invalid employee type"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/src/main/resources/employees.csv: -------------------------------------------------------------------------------- 1 | Name,Income,Nb Hours/Week 2 | Anna Smith,2000,40 3 | Billy Leach,920,40 4 | Steve Jones,800,20 5 | Magda Iovan,920,20, 6 | John Lee,300,10, 7 | Catherine Allison,500,15 8 | -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/src/main/resources/payment_business_requirements.txt: -------------------------------------------------------------------------------- 1 | #Business Requirement Document 2 | #Version 1.0 3 | 4 | We need a system that can retrieve all employees 5 | and pay their incomes. 6 | 7 | Upon completion, the total paid sum must be calculated in order 8 | to compare it with the finance department. 9 | 10 | Each employee should receive an email after the income payment 11 | was sent successfully. -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/src/main/resources/payslip_business_requirements.txt: -------------------------------------------------------------------------------- 1 | #Business Requirement Document 2 | #Version 1.0 3 | 4 | The team needs to implement an exportable document: payslip. 5 | It should contain the following information: 6 | - month of income 7 | - name of employee 8 | - income of employee for the given month 9 | 10 | At the moment we just want to export as text but it 11 | might be possible to extend this to other formats. -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/src/main/resources/subcontractor_business_requirements.txt: -------------------------------------------------------------------------------- 1 | #Business Requirement Document 2 | #Version 1.0 3 | 4 | A subcontractor is an entity that works similar to an employee 5 | for various projects. We need to implement this feature because in most 6 | companies employees work with external collaborators. 7 | 8 | We are interested in the contact info (name, own email), 9 | cost (monthly income) and nb of hours worked. 10 | 11 | They need to have an SLA approved before working. 12 | 13 | Because subcontractors are external, they are not eligible 14 | to time off. Nor do we need to calculate taxes for them. 15 | -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/src/main/resources/taxes_business_requirements.txt: -------------------------------------------------------------------------------- 1 | #Business Requirement Document 2 | #Version 1.0 3 | 4 | Taxes for employees are calculated like this: 5 | 6 | - Fixed $100 amount for base health insurance 7 | - 16% income tax 8 | - 10% retirement tax -------------------------------------------------------------------------------- /dip/refactored/GlobomanticsHR/src/main/resources/taxes_business_requirements_v2.txt: -------------------------------------------------------------------------------- 1 | #Business Requirement Document 2 | #Version 2.0 3 | 4 | Taxes for employees are calculated like this: 5 | 6 | 1) For full time employees 7 | 8 | - Fixed $100 amount for base health insurance 9 | - 16% income tax 10 | - 10% retirement tax 11 | 12 | 2) For part time employees 13 | 14 | - Fixed $100 amount for base health insurance 15 | - 16% income tax 16 | - 5% retirement tax 17 | 18 | 3) For interns 19 | - If income < 350 => no tax due to state aid 20 | - Else => only 16% income tax 21 | -------------------------------------------------------------------------------- /isp/before/GlobomanticsHR/.idea/.name: -------------------------------------------------------------------------------- 1 | hr -------------------------------------------------------------------------------- /isp/before/GlobomanticsHR/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /isp/before/GlobomanticsHR/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /isp/before/GlobomanticsHR/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /isp/before/GlobomanticsHR/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /isp/before/GlobomanticsHR/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /isp/before/GlobomanticsHR/GlobomanticsHR.iml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /isp/before/GlobomanticsHR/hr.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /isp/before/GlobomanticsHR/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | globomantics 8 | hr 9 | 1.0.0 10 | 11 | 12 | 1.8 13 | 1.8 14 | 15 | -------------------------------------------------------------------------------- /isp/before/GlobomanticsHR/src/main/java/hr/documents/ExportableDocument.java: -------------------------------------------------------------------------------- 1 | package hr.documents; 2 | 3 | /* 4 | Common interface used in application when there is 5 | a need for document exports 6 | */ 7 | public interface ExportableDocument { 8 | byte[] toPdf(); 9 | String toJson(); 10 | String toTxt(); 11 | } 12 | -------------------------------------------------------------------------------- /isp/before/GlobomanticsHR/src/main/java/hr/documents/Payslip.java: -------------------------------------------------------------------------------- 1 | package hr.documents; 2 | 3 | import hr.personnel.Employee; 4 | 5 | import java.time.Month; 6 | import java.util.Arrays; 7 | import java.util.List; 8 | 9 | public class Payslip implements ExportableDocument { 10 | private String employeeName; 11 | private int monthlyIncome; 12 | private Month month; 13 | 14 | public Payslip(Employee employee, Month month) { 15 | this.employeeName = employee.getFullName(); 16 | this.monthlyIncome = employee.getMonthlyIncome(); 17 | this.month = month; 18 | } 19 | 20 | public Month getMonth() { 21 | return month; 22 | } 23 | 24 | public int getMonthlyIncome() { 25 | return monthlyIncome; 26 | } 27 | 28 | public String getEmployeeName() { 29 | return employeeName; 30 | } 31 | 32 | @Override 33 | public String toTxt() { 34 | StringBuilder sb = new StringBuilder(); 35 | sb.append("MONTH: ").append(this.month); 36 | sb.append(System.lineSeparator()); 37 | sb.append("NAME: ").append(this.employeeName); 38 | sb.append(System.lineSeparator()); 39 | sb.append("INCOME: ").append(this.monthlyIncome); 40 | sb.append(System.lineSeparator()); 41 | 42 | return sb.toString(); 43 | } 44 | 45 | @Override 46 | public byte[] toPdf() { 47 | List list = Arrays.asList("ana","are"); 48 | list.re 49 | 50 | throw new UnsupportedOperationException(); 51 | } 52 | 53 | @Override 54 | public String toJson() { 55 | throw new UnsupportedOperationException(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /isp/before/GlobomanticsHR/src/main/java/hr/logging/ConsoleLogger.java: -------------------------------------------------------------------------------- 1 | package hr.logging; 2 | 3 | public class ConsoleLogger { 4 | public void writeInfo(String msg) { 5 | System.out.println("Info: " + msg); 6 | } 7 | 8 | public void writeError(String msg, Exception e) { 9 | System.err.println("Error: " + msg + ";" + e); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /isp/before/GlobomanticsHR/src/main/java/hr/main/ApproveSLAMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.logging.ConsoleLogger; 4 | import hr.persistence.EmployeeFileSerializer; 5 | import hr.persistence.EmployeeRepository; 6 | import hr.personnel.Employee; 7 | import hr.personnel.ServiceLicenseAgreement; 8 | import hr.personnel.Subcontractor; 9 | 10 | import java.util.Arrays; 11 | import java.util.List; 12 | 13 | public class ApproveSLAMain { 14 | public static void main(String[] args) { 15 | // Define SLA 16 | int minTimeOffPercent = 98; 17 | int maxResolutionDays = 2; 18 | ServiceLicenseAgreement companySla = new ServiceLicenseAgreement( 19 | minTimeOffPercent, 20 | maxResolutionDays); 21 | 22 | // Get collaborators from their own source 23 | Subcontractor subcontractor1 = new Subcontractor( 24 | "Rebekah Jackson", 25 | "rebekah-jackson@abc.com", 26 | 3000, 27 | 15); 28 | Subcontractor subcontractor2 = new Subcontractor( 29 | "Harry Fitz", 30 | "harryfitz@def.com", 31 | 3000, 15); 32 | List collaborators = Arrays.asList(subcontractor1, subcontractor2); 33 | 34 | // Check SLA 35 | for (Subcontractor s : collaborators) { 36 | s.approveSLA(companySla); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /isp/before/GlobomanticsHR/src/main/java/hr/main/CalculateEmployeeTaxesMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.logging.ConsoleLogger; 4 | import hr.persistence.EmployeeFileSerializer; 5 | import hr.persistence.EmployeeRepository; 6 | import hr.personnel.Employee; 7 | import hr.taxes.FullTimeTaxCalculator; 8 | import hr.taxes.TaxCalculator; 9 | import hr.taxes.TaxCalculatorFactory; 10 | 11 | import java.text.NumberFormat; 12 | import java.util.List; 13 | import java.util.Locale; 14 | 15 | public class CalculateEmployeeTaxesMain { 16 | public static void main(String[] args) { 17 | // Create dependencies 18 | ConsoleLogger consoleLogger = new ConsoleLogger(); 19 | EmployeeFileSerializer employeeFileSerializer = new EmployeeFileSerializer(); 20 | EmployeeRepository repository = new EmployeeRepository(employeeFileSerializer); 21 | 22 | // Grab employees 23 | List employees = repository.findAll(); 24 | 25 | // Calculate taxes 26 | Locale locale = new Locale("en", "US"); 27 | NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(locale); 28 | 29 | double totalTaxes = 0; 30 | for (Employee employee: employees){ 31 | TaxCalculator taxCalculator = TaxCalculatorFactory.create(employee); 32 | 33 | // compute individual tax 34 | double tax = taxCalculator.calculate(employee); 35 | String formattedTax = currencyFormatter.format(tax); 36 | consoleLogger.writeInfo(employee.getFullName() + " taxes: " + formattedTax); 37 | 38 | // add to company total taxes 39 | totalTaxes += taxCalculator.calculate(employee); 40 | } 41 | consoleLogger.writeInfo("Total taxes = " + currencyFormatter.format(totalTaxes)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /isp/before/GlobomanticsHR/src/main/java/hr/main/ExportPayslipMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.documents.Payslip; 4 | import hr.logging.ConsoleLogger; 5 | import hr.persistence.EmployeeFileSerializer; 6 | import hr.persistence.EmployeeRepository; 7 | import hr.personnel.Employee; 8 | 9 | import java.time.Month; 10 | import java.util.List; 11 | 12 | public class ExportPayslipMain { 13 | public static void main(String[] args) { 14 | // Create dependencies 15 | ConsoleLogger consoleLogger = new ConsoleLogger(); 16 | EmployeeFileSerializer employeeFileSerializer = new EmployeeFileSerializer(); 17 | EmployeeRepository repository = new EmployeeRepository(employeeFileSerializer); 18 | 19 | // Grab employees 20 | List employees = repository.findAll(); 21 | 22 | for (Employee employee : employees){ 23 | Payslip payslip = new Payslip(employee , Month.AUGUST); 24 | 25 | String exportableText = payslip.toTxt().toUpperCase(); 26 | System.out.println(exportableText); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /isp/before/GlobomanticsHR/src/main/java/hr/main/NatHolidayEmployeeTimeOffMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.logging.ConsoleLogger; 4 | import hr.persistence.EmployeeFileSerializer; 5 | import hr.persistence.EmployeeRepository; 6 | import hr.personnel.Employee; 7 | import hr.personnel.FullTimeEmployee; 8 | 9 | import java.util.List; 10 | 11 | public class NatHolidayEmployeeTimeOffMain { 12 | public static void main(String[] args) { 13 | // Create dependencies 14 | ConsoleLogger consoleLogger = new ConsoleLogger(); 15 | EmployeeFileSerializer employeeFileSerializer = new EmployeeFileSerializer(); 16 | EmployeeRepository repository = new EmployeeRepository(employeeFileSerializer); 17 | 18 | // Grab employees 19 | List employees = repository.findAll(); 20 | Employee manager = new FullTimeEmployee("Steve Jackson", 5000); 21 | 22 | // Request time off for each employee on 23 | // national holiday 24 | for (Employee employee : employees){ 25 | employee.requestTimeOff(1, manager); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /isp/before/GlobomanticsHR/src/main/java/hr/main/SaveEmployeesMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.logging.ConsoleLogger; 4 | import hr.persistence.EmployeeFileSerializer; 5 | import hr.persistence.EmployeeRepository; 6 | import hr.personnel.Employee; 7 | 8 | import java.io.IOException; 9 | import java.util.List; 10 | 11 | public class SaveEmployeesMain { 12 | public static void main(String[] args) { 13 | // Grab employees 14 | EmployeeFileSerializer employeeFileSerializer = new EmployeeFileSerializer(); 15 | ConsoleLogger consoleLogger = new ConsoleLogger(); 16 | 17 | EmployeeRepository repository = new EmployeeRepository(employeeFileSerializer); 18 | List employees = repository.findAll(); 19 | 20 | // Save all 21 | for (Employee e : employees){ 22 | try { 23 | repository.save(e); 24 | consoleLogger.writeInfo("Saved employee " + e.toString()); 25 | } catch (IOException exception) { 26 | consoleLogger.writeError("Error saving employee", exception); 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /isp/before/GlobomanticsHR/src/main/java/hr/persistence/EmployeeFileSerializer.java: -------------------------------------------------------------------------------- 1 | package hr.persistence; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public class EmployeeFileSerializer { 6 | public String serialize(Employee employee) { 7 | StringBuilder sb = new StringBuilder(); 8 | 9 | sb.append("### EMPLOYEE RECORD ####"); 10 | sb.append(System.lineSeparator()); 11 | sb.append("NAME: "); 12 | sb.append(employee.getFullName()); 13 | sb.append(System.lineSeparator()); 14 | sb.append("POSITION: "); 15 | sb.append(employee.getClass().getTypeName()); 16 | sb.append(System.lineSeparator()); 17 | sb.append("EMAIL: "); 18 | sb.append(employee.getEmail()); 19 | sb.append(System.lineSeparator()); 20 | sb.append("MONTHLY WAGE: "); 21 | sb.append(employee.getMonthlyIncome()); 22 | sb.append(System.lineSeparator()); 23 | 24 | return sb.toString(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /isp/before/GlobomanticsHR/src/main/java/hr/persistence/EmployeeRepository.java: -------------------------------------------------------------------------------- 1 | package hr.persistence; 2 | 3 | import hr.logging.ConsoleLogger; 4 | import hr.personnel.*; 5 | 6 | import java.io.IOException; 7 | import java.nio.file.Files; 8 | import java.nio.file.Path; 9 | import java.nio.file.Paths; 10 | import java.util.Arrays; 11 | import java.util.List; 12 | 13 | /* 14 | Helper method to perform CRUD operations on employees. In a production 15 | application we could use the database for persistence. In this demo, 16 | we are storing employees in the file system. 17 | */ 18 | 19 | public class EmployeeRepository { 20 | private EmployeeFileSerializer serializer; 21 | 22 | public EmployeeRepository(EmployeeFileSerializer serializer) { 23 | this.serializer = serializer; 24 | } 25 | 26 | public List findAll() { 27 | 28 | // Employees are kept in memory for simplicity 29 | Employee anna = new FullTimeEmployee("Anna Smith", 2000); 30 | Employee billy = new FullTimeEmployee("Billy Leech", 920); 31 | 32 | Employee steve = new PartTimeEmployee("Steve Jones", 800); 33 | Employee magda = new PartTimeEmployee("Magda Iovan", 920); 34 | 35 | Employee john = new Intern("John Lee", 300, 10); 36 | Employee catherine = new Intern("Catherine Allison", 500, 15); 37 | 38 | return Arrays.asList(anna, billy, steve, magda, john, catherine); 39 | } 40 | 41 | public void save(Employee employee) throws IOException { 42 | String serializedString = this.serializer.serialize(employee); 43 | 44 | Path path = Paths.get(employee.getFullName() 45 | .replace(" ", "_") + ".rec"); 46 | Files.write(path, serializedString.getBytes()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /isp/before/GlobomanticsHR/src/main/java/hr/personnel/FullTimeEmployee.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class FullTimeEmployee extends Employee { 4 | public FullTimeEmployee(String fullName, int monthlyIncome) { 5 | super(fullName, monthlyIncome); 6 | this.setNbHoursPerWeek(40); 7 | } 8 | 9 | @Override 10 | public void requestTimeOff(int nbDays, Employee manager) { 11 | /* 12 | HR business logic for time off for full time employees 13 | */ 14 | 15 | System.out.println("Time off request for full time employee " + 16 | this.getFullName() + 17 | "; Nb days " + nbDays + 18 | "; Requested from " + manager.getFullName()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /isp/before/GlobomanticsHR/src/main/java/hr/personnel/Intern.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class Intern extends Employee { 4 | public Intern(String fullName, int monthlyIncome, int nbHours) { 5 | super(fullName, monthlyIncome); 6 | setNbHoursPerWeek(nbHours); 7 | } 8 | 9 | @Override 10 | public void requestTimeOff(int nbDays, Employee manager) { 11 | /* 12 | HR business logic for time off for interns 13 | */ 14 | 15 | System.out.println("Time off request for intern " + 16 | this.getFullName() + 17 | "; Nb days " + nbDays + 18 | "; Requested from " + manager.getFullName()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /isp/before/GlobomanticsHR/src/main/java/hr/personnel/PartTimeEmployee.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class PartTimeEmployee extends Employee { 4 | public PartTimeEmployee(String fullName, int monthlyIncome) { 5 | super(fullName, monthlyIncome); 6 | this.setNbHoursPerWeek(20); 7 | } 8 | 9 | @Override 10 | public void requestTimeOff(int nbDays, Employee manager) { 11 | /* 12 | HR business logic for time off for part time employees 13 | */ 14 | 15 | System.out.println("Time off request for part time employee " + 16 | this.getFullName() + 17 | "; Nb days " + nbDays + 18 | "; Requested from " + manager.getFullName()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /isp/before/GlobomanticsHR/src/main/java/hr/personnel/ServiceLicenseAgreement.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class ServiceLicenseAgreement { 4 | private int minUptimePercent; 5 | private int problemResolutionTimeDays; 6 | 7 | public ServiceLicenseAgreement(int minUptime, int problemResolutionTimeDays) { 8 | this.minUptimePercent = minUptime; 9 | this.problemResolutionTimeDays = problemResolutionTimeDays; 10 | } 11 | 12 | public int getMinUptimePercent() { 13 | return minUptimePercent; 14 | } 15 | 16 | public int getProblemResolutionTimeDays() { 17 | return problemResolutionTimeDays; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /isp/before/GlobomanticsHR/src/main/java/hr/personnel/Subcontractor.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class Subcontractor { 4 | 5 | private final int monthlyIncome; 6 | private int nbHoursPerWeek; 7 | private String email; 8 | private String name; 9 | 10 | public Subcontractor(String name, 11 | String email, 12 | int monthlyIncome, 13 | int nbHoursPerWeek) { 14 | 15 | this.name = name; 16 | this.email = email; 17 | this.monthlyIncome = monthlyIncome; 18 | this.nbHoursPerWeek = nbHoursPerWeek; 19 | } 20 | 21 | public boolean approveSLA(ServiceLicenseAgreement sla) { 22 | boolean result = false; 23 | if (sla.getMinUptimePercent() >= 98 && 24 | sla.getProblemResolutionTimeDays() <= 2) { 25 | result = true; 26 | } 27 | 28 | System.out.println("SLA approval for " + this.name + ": " + result); 29 | return result; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /isp/before/GlobomanticsHR/src/main/java/hr/taxes/FullTimeTaxCalculator.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public class FullTimeTaxCalculator implements TaxCalculator { 6 | private final int RETIREMENT_TAX_PERCENTAGE = 10; 7 | private final int INCOME_TAX_PERCENTAGE = 16; 8 | private final int BASE_HEALTH_INSURANCE = 100; 9 | 10 | 11 | public double calculate(Employee employee) { 12 | return BASE_HEALTH_INSURANCE + 13 | (employee.getMonthlyIncome() * RETIREMENT_TAX_PERCENTAGE) / 100 + 14 | (employee.getMonthlyIncome() * INCOME_TAX_PERCENTAGE) / 100; 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /isp/before/GlobomanticsHR/src/main/java/hr/taxes/InternTaxCalculator.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public class InternTaxCalculator implements TaxCalculator { 6 | private final int INCOME_TAX_PERCENTAGE = 16; 7 | 8 | public double calculate(Employee employee) { 9 | int monthlyIncome = employee.getMonthlyIncome(); 10 | if (monthlyIncome < 350) { 11 | return 0; 12 | } else { 13 | return (monthlyIncome * INCOME_TAX_PERCENTAGE) / 100; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /isp/before/GlobomanticsHR/src/main/java/hr/taxes/PartTimeTaxCalculator.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public class PartTimeTaxCalculator implements TaxCalculator { 6 | private final int RETIREMENT_TAX_PERCENTAGE = 5; 7 | private final int INCOME_TAX_PERCENTAGE = 16; 8 | private final int BASE_HEALTH_INSURANCE = 100; 9 | 10 | public double calculate(Employee employee) { 11 | int monthlyIncome = employee.getMonthlyIncome(); 12 | return BASE_HEALTH_INSURANCE + 13 | (monthlyIncome * RETIREMENT_TAX_PERCENTAGE) / 100 + 14 | (monthlyIncome * INCOME_TAX_PERCENTAGE) / 100; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /isp/before/GlobomanticsHR/src/main/java/hr/taxes/TaxCalculator.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public interface TaxCalculator { 6 | double calculate(Employee employee); 7 | } 8 | -------------------------------------------------------------------------------- /isp/before/GlobomanticsHR/src/main/java/hr/taxes/TaxCalculatorFactory.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | import hr.personnel.FullTimeEmployee; 5 | import hr.personnel.Intern; 6 | import hr.personnel.PartTimeEmployee; 7 | 8 | public class TaxCalculatorFactory { 9 | public static TaxCalculator create(Employee employee) { 10 | if (employee instanceof FullTimeEmployee) { 11 | return new FullTimeTaxCalculator(); 12 | } 13 | 14 | if (employee instanceof PartTimeEmployee) { 15 | return new PartTimeTaxCalculator(); 16 | } 17 | 18 | if (employee instanceof Intern) { 19 | return new InternTaxCalculator(); 20 | } 21 | 22 | throw new RuntimeException("Invalid employee type"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /isp/before/GlobomanticsHR/src/main/resources/payslip_business_requirements.txt: -------------------------------------------------------------------------------- 1 | #Business Requirement Document 2 | #Version 1.0 3 | 4 | The team needs to implement an exportable document: payslip. 5 | It should contain the following information: 6 | - month of income 7 | - name of employee 8 | - income of employee for the given month 9 | 10 | At the moment we just want to export as text but it 11 | might be possible to extend this to other formats. -------------------------------------------------------------------------------- /isp/before/GlobomanticsHR/src/main/resources/subcontractor_business_requirements.txt: -------------------------------------------------------------------------------- 1 | #Business Requirement Document 2 | #Version 1.0 3 | 4 | A subcontractor is an entity that works similar to an employee 5 | for various projects. We need to implement this feature because in most 6 | companies employees work with external collaborators. 7 | 8 | We are interested in the contact info (name, own email), 9 | cost (monthly income) and nb of hours worked. 10 | 11 | They need to have an SLA approved before working. 12 | 13 | Because subcontractors are external, they are not eligible 14 | to time off. Nor do we need to calculate taxes for them. 15 | -------------------------------------------------------------------------------- /isp/before/GlobomanticsHR/src/main/resources/taxes_business_requirements.txt: -------------------------------------------------------------------------------- 1 | #Business Requirement Document 2 | #Version 1.0 3 | 4 | Taxes for employees are calculated like this: 5 | 6 | - Fixed $100 amount for base health insurance 7 | - 16% income tax 8 | - 10% retirement tax -------------------------------------------------------------------------------- /isp/before/GlobomanticsHR/src/main/resources/taxes_business_requirements_v2.txt: -------------------------------------------------------------------------------- 1 | #Business Requirement Document 2 | #Version 2.0 3 | 4 | Taxes for employees are calculated like this: 5 | 6 | 1) For full time employees 7 | 8 | - Fixed $100 amount for base health insurance 9 | - 16% income tax 10 | - 10% retirement tax 11 | 12 | 2) For part time employees 13 | 14 | - Fixed $100 amount for base health insurance 15 | - 16% income tax 16 | - 5% retirement tax 17 | 18 | 3) For interns 19 | - If income < 350 => no tax due to state aid 20 | - Else => only 16% income tax 21 | -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/.idea/.name: -------------------------------------------------------------------------------- 1 | hr -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/GlobomanticsHR.iml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/hr.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | globomantics 8 | hr 9 | 1.0.0 10 | 11 | 12 | 1.8 13 | 1.8 14 | 15 | -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/src/main/java/hr/documents/ExportableJson.java: -------------------------------------------------------------------------------- 1 | package hr.documents; 2 | 3 | public interface ExportableJson { 4 | String toJson(); 5 | } 6 | -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/src/main/java/hr/documents/ExportablePdf.java: -------------------------------------------------------------------------------- 1 | package hr.documents; 2 | 3 | public interface ExportablePdf { 4 | byte[] toPdf(); 5 | } 6 | -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/src/main/java/hr/documents/ExportableText.java: -------------------------------------------------------------------------------- 1 | package hr.documents; 2 | 3 | public interface ExportableText { 4 | String toTxt(); 5 | } 6 | -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/src/main/java/hr/documents/Payslip.java: -------------------------------------------------------------------------------- 1 | package hr.documents; 2 | 3 | import hr.personnel.Employee; 4 | 5 | import java.time.Month; 6 | 7 | public class Payslip implements ExportableText { 8 | private String employeeName; 9 | private int monthlyIncome; 10 | private Month month; 11 | 12 | public Payslip(Employee employee, Month month) { 13 | this.employeeName = employee.getFullName(); 14 | this.monthlyIncome = employee.getMonthlyIncome(); 15 | this.month = month; 16 | } 17 | 18 | public Month getMonth() { 19 | return month; 20 | } 21 | 22 | public int getMonthlyIncome() { 23 | return monthlyIncome; 24 | } 25 | 26 | public String getEmployeeName() { 27 | return employeeName; 28 | } 29 | 30 | @Override 31 | public String toTxt() { 32 | StringBuilder sb = new StringBuilder(); 33 | sb.append("MONTH: ").append(this.month); 34 | sb.append(System.lineSeparator()); 35 | sb.append("NAME: ").append(this.employeeName); 36 | sb.append(System.lineSeparator()); 37 | sb.append("INCOME: ").append(this.monthlyIncome); 38 | sb.append(System.lineSeparator()); 39 | 40 | return sb.toString(); 41 | } 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/src/main/java/hr/documents/WorkContract.java: -------------------------------------------------------------------------------- 1 | package hr.documents; 2 | 3 | public class WorkContract implements 4 | ExportableJson, 5 | ExportableText, 6 | ExportablePdf { 7 | private String content; 8 | 9 | public WorkContract(String content) { 10 | this.content = content; 11 | } 12 | 13 | @Override 14 | public byte[] toPdf() { 15 | // Test implementation, in reality this would 16 | // be more complex 17 | return content.getBytes(); 18 | } 19 | 20 | @Override 21 | public String toJson() { 22 | // Test implementation, in reality this would 23 | // be more complex 24 | return "{'content':'" + this.content + "'}"; 25 | } 26 | 27 | @Override 28 | public String toTxt() { 29 | // Test implementation, in reality this would 30 | // be more complex 31 | return this.content; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/src/main/java/hr/logging/ConsoleLogger.java: -------------------------------------------------------------------------------- 1 | package hr.logging; 2 | 3 | public class ConsoleLogger { 4 | public void writeInfo(String msg) { 5 | System.out.println("Info: " + msg); 6 | } 7 | 8 | public void writeError(String msg, Exception e) { 9 | System.err.println("Error: " + msg + ";" + e); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/src/main/java/hr/main/ApproveSLAMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.logging.ConsoleLogger; 4 | import hr.persistence.EmployeeFileSerializer; 5 | import hr.persistence.EmployeeRepository; 6 | import hr.personnel.Employee; 7 | import hr.personnel.ServiceLicenseAgreement; 8 | import hr.personnel.Subcontractor; 9 | 10 | import java.util.Arrays; 11 | import java.util.List; 12 | 13 | public class ApproveSLAMain { 14 | public static void main(String[] args) { 15 | // Define SLA 16 | int minTimeOffPercent = 98; 17 | int maxResolutionDays = 2; 18 | ServiceLicenseAgreement companySla = new ServiceLicenseAgreement( 19 | minTimeOffPercent, 20 | maxResolutionDays); 21 | 22 | // Get collaborators from their own source 23 | Subcontractor subcontractor1 = new Subcontractor( 24 | "Rebekah Jackson", 25 | "rebekah-jackson@abc.com", 26 | 3000, 27 | 15); 28 | Subcontractor subcontractor2 = new Subcontractor( 29 | "Harry Fitz", 30 | "harryfitz@def.com", 31 | 3000, 15); 32 | List collaborators = Arrays.asList(subcontractor1, subcontractor2); 33 | 34 | // Check SLA 35 | for (Subcontractor s : collaborators) { 36 | s.approveSLA(companySla); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/src/main/java/hr/main/CalculateEmployeeTaxesMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.logging.ConsoleLogger; 4 | import hr.persistence.EmployeeFileSerializer; 5 | import hr.persistence.EmployeeRepository; 6 | import hr.personnel.Employee; 7 | import hr.taxes.FullTimeTaxCalculator; 8 | import hr.taxes.TaxCalculator; 9 | import hr.taxes.TaxCalculatorFactory; 10 | 11 | import java.text.NumberFormat; 12 | import java.util.List; 13 | import java.util.Locale; 14 | 15 | public class CalculateEmployeeTaxesMain { 16 | public static void main(String[] args) { 17 | // Create dependencies 18 | ConsoleLogger consoleLogger = new ConsoleLogger(); 19 | EmployeeFileSerializer employeeFileSerializer = new EmployeeFileSerializer(); 20 | EmployeeRepository repository = new EmployeeRepository(employeeFileSerializer); 21 | 22 | // Grab employees 23 | List employees = repository.findAll(); 24 | 25 | // Calculate taxes 26 | Locale locale = new Locale("en", "US"); 27 | NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(locale); 28 | 29 | double totalTaxes = 0; 30 | for (Employee employee: employees){ 31 | TaxCalculator taxCalculator = TaxCalculatorFactory.create(employee); 32 | 33 | // compute individual tax 34 | double tax = taxCalculator.calculate(employee); 35 | String formattedTax = currencyFormatter.format(tax); 36 | consoleLogger.writeInfo(employee.getFullName() + " taxes: " + formattedTax); 37 | 38 | // add to company total taxes 39 | totalTaxes += taxCalculator.calculate(employee); 40 | } 41 | consoleLogger.writeInfo("Total taxes = " + currencyFormatter.format(totalTaxes)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/src/main/java/hr/main/ExportPayslipMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.documents.Payslip; 4 | import hr.logging.ConsoleLogger; 5 | import hr.persistence.EmployeeFileSerializer; 6 | import hr.persistence.EmployeeRepository; 7 | import hr.personnel.Employee; 8 | 9 | import java.time.Month; 10 | import java.util.List; 11 | 12 | public class ExportPayslipMain { 13 | public static void main(String[] args) { 14 | // Create dependencies 15 | ConsoleLogger consoleLogger = new ConsoleLogger(); 16 | EmployeeFileSerializer employeeFileSerializer = new EmployeeFileSerializer(); 17 | EmployeeRepository repository = new EmployeeRepository(employeeFileSerializer); 18 | 19 | // Grab employees 20 | List employees = repository.findAll(); 21 | 22 | for (Employee employee : employees){ 23 | Payslip payslip = new Payslip(employee , Month.AUGUST); 24 | 25 | String exportableText = payslip.toTxt().toUpperCase(); 26 | System.out.println(exportableText); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/src/main/java/hr/main/NatHolidayEmployeeTimeOffMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.logging.ConsoleLogger; 4 | import hr.persistence.EmployeeFileSerializer; 5 | import hr.persistence.EmployeeRepository; 6 | import hr.personnel.Employee; 7 | import hr.personnel.FullTimeEmployee; 8 | 9 | import java.util.List; 10 | 11 | public class NatHolidayEmployeeTimeOffMain { 12 | public static void main(String[] args) { 13 | // Create dependencies 14 | ConsoleLogger consoleLogger = new ConsoleLogger(); 15 | EmployeeFileSerializer employeeFileSerializer = new EmployeeFileSerializer(); 16 | EmployeeRepository repository = new EmployeeRepository(employeeFileSerializer); 17 | 18 | // Grab employees 19 | List employees = repository.findAll(); 20 | Employee manager = new FullTimeEmployee("Steve Jackson", 5000); 21 | 22 | // Request time off for each employee on 23 | // national holiday 24 | for (Employee employee : employees){ 25 | employee.requestTimeOff(1, manager); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/src/main/java/hr/main/SaveEmployeesMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.logging.ConsoleLogger; 4 | import hr.persistence.EmployeeFileSerializer; 5 | import hr.persistence.EmployeeRepository; 6 | import hr.personnel.Employee; 7 | 8 | import java.io.IOException; 9 | import java.util.List; 10 | 11 | public class SaveEmployeesMain { 12 | public static void main(String[] args) { 13 | // Grab employees 14 | EmployeeFileSerializer employeeFileSerializer = new EmployeeFileSerializer(); 15 | ConsoleLogger consoleLogger = new ConsoleLogger(); 16 | 17 | EmployeeRepository repository = new EmployeeRepository(employeeFileSerializer); 18 | List employees = repository.findAll(); 19 | 20 | // Save all 21 | for (Employee e : employees){ 22 | try { 23 | repository.save(e); 24 | consoleLogger.writeInfo("Saved employee " + e.toString()); 25 | } catch (IOException exception) { 26 | consoleLogger.writeError("Error saving employee", exception); 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/src/main/java/hr/persistence/EmployeeFileSerializer.java: -------------------------------------------------------------------------------- 1 | package hr.persistence; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public class EmployeeFileSerializer { 6 | public String serialize(Employee employee) { 7 | StringBuilder sb = new StringBuilder(); 8 | 9 | sb.append("### EMPLOYEE RECORD ####"); 10 | sb.append(System.lineSeparator()); 11 | sb.append("NAME: "); 12 | sb.append(employee.getFullName()); 13 | sb.append(System.lineSeparator()); 14 | sb.append("POSITION: "); 15 | sb.append(employee.getClass().getTypeName()); 16 | sb.append(System.lineSeparator()); 17 | sb.append("EMAIL: "); 18 | sb.append(employee.getEmail()); 19 | sb.append(System.lineSeparator()); 20 | sb.append("MONTHLY WAGE: "); 21 | sb.append(employee.getMonthlyIncome()); 22 | sb.append(System.lineSeparator()); 23 | 24 | return sb.toString(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/src/main/java/hr/persistence/EmployeeRepository.java: -------------------------------------------------------------------------------- 1 | package hr.persistence; 2 | 3 | import hr.logging.ConsoleLogger; 4 | import hr.personnel.*; 5 | 6 | import java.io.IOException; 7 | import java.nio.file.Files; 8 | import java.nio.file.Path; 9 | import java.nio.file.Paths; 10 | import java.util.Arrays; 11 | import java.util.List; 12 | 13 | /* 14 | Helper method to perform CRUD operations on employees. In a production 15 | application we could use the database for persistence. In this demo, 16 | we are storing employees in the file system. 17 | */ 18 | 19 | public class EmployeeRepository { 20 | private EmployeeFileSerializer serializer; 21 | 22 | public EmployeeRepository(EmployeeFileSerializer serializer) { 23 | this.serializer = serializer; 24 | } 25 | 26 | public List findAll() { 27 | 28 | // Employees are kept in memory for simplicity 29 | Employee anna = new FullTimeEmployee("Anna Smith", 2000); 30 | Employee billy = new FullTimeEmployee("Billy Leech", 920); 31 | 32 | Employee steve = new PartTimeEmployee("Steve Jones", 800); 33 | Employee magda = new PartTimeEmployee("Magda Iovan", 920); 34 | 35 | Employee john = new Intern("John Lee", 300, 10); 36 | Employee catherine = new Intern("Catherine Allison", 500, 15); 37 | 38 | return Arrays.asList(anna, billy, steve, magda, john, catherine); 39 | } 40 | 41 | public void save(Employee employee) throws IOException { 42 | String serializedString = this.serializer.serialize(employee); 43 | 44 | Path path = Paths.get(employee.getFullName() 45 | .replace(" ", "_") + ".rec"); 46 | Files.write(path, serializedString.getBytes()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/src/main/java/hr/personnel/FullTimeEmployee.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class FullTimeEmployee extends Employee { 4 | public FullTimeEmployee(String fullName, int monthlyIncome) { 5 | super(fullName, monthlyIncome); 6 | this.setNbHoursPerWeek(40); 7 | } 8 | 9 | @Override 10 | public void requestTimeOff(int nbDays, Employee manager) { 11 | /* 12 | HR business logic for time off for full time employees 13 | */ 14 | 15 | System.out.println("Time off request for full time employee " + 16 | this.getFullName() + 17 | "; Nb days " + nbDays + 18 | "; Requested from " + manager.getFullName()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/src/main/java/hr/personnel/Intern.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class Intern extends Employee { 4 | public Intern(String fullName, int monthlyIncome, int nbHours) { 5 | super(fullName, monthlyIncome); 6 | setNbHoursPerWeek(nbHours); 7 | } 8 | 9 | @Override 10 | public void requestTimeOff(int nbDays, Employee manager) { 11 | /* 12 | HR business logic for time off for interns 13 | */ 14 | 15 | System.out.println("Time off request for intern " + 16 | this.getFullName() + 17 | "; Nb days " + nbDays + 18 | "; Requested from " + manager.getFullName()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/src/main/java/hr/personnel/PartTimeEmployee.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class PartTimeEmployee extends Employee { 4 | public PartTimeEmployee(String fullName, int monthlyIncome) { 5 | super(fullName, monthlyIncome); 6 | this.setNbHoursPerWeek(20); 7 | } 8 | 9 | @Override 10 | public void requestTimeOff(int nbDays, Employee manager) { 11 | /* 12 | HR business logic for time off for part time employees 13 | */ 14 | 15 | System.out.println("Time off request for part time employee " + 16 | this.getFullName() + 17 | "; Nb days " + nbDays + 18 | "; Requested from " + manager.getFullName()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/src/main/java/hr/personnel/ServiceLicenseAgreement.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class ServiceLicenseAgreement { 4 | private int minUptimePercent; 5 | private int problemResolutionTimeDays; 6 | 7 | public ServiceLicenseAgreement(int minUptime, int problemResolutionTimeDays) { 8 | this.minUptimePercent = minUptime; 9 | this.problemResolutionTimeDays = problemResolutionTimeDays; 10 | } 11 | 12 | public int getMinUptimePercent() { 13 | return minUptimePercent; 14 | } 15 | 16 | public int getProblemResolutionTimeDays() { 17 | return problemResolutionTimeDays; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/src/main/java/hr/personnel/Subcontractor.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class Subcontractor { 4 | 5 | private final int monthlyIncome; 6 | private int nbHoursPerWeek; 7 | private String email; 8 | private String name; 9 | 10 | public Subcontractor(String name, 11 | String email, 12 | int monthlyIncome, 13 | int nbHoursPerWeek) { 14 | 15 | this.name = name; 16 | this.email = email; 17 | this.monthlyIncome = monthlyIncome; 18 | this.nbHoursPerWeek = nbHoursPerWeek; 19 | } 20 | 21 | public boolean approveSLA(ServiceLicenseAgreement sla) { 22 | boolean result = false; 23 | if (sla.getMinUptimePercent() >= 98 && 24 | sla.getProblemResolutionTimeDays() <= 2) { 25 | result = true; 26 | } 27 | 28 | System.out.println("SLA approval for " + this.name + ": " + result); 29 | return result; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/src/main/java/hr/taxes/FullTimeTaxCalculator.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public class FullTimeTaxCalculator implements TaxCalculator { 6 | private final int RETIREMENT_TAX_PERCENTAGE = 10; 7 | private final int INCOME_TAX_PERCENTAGE = 16; 8 | private final int BASE_HEALTH_INSURANCE = 100; 9 | 10 | 11 | public double calculate(Employee employee) { 12 | return BASE_HEALTH_INSURANCE + 13 | (employee.getMonthlyIncome() * RETIREMENT_TAX_PERCENTAGE) / 100 + 14 | (employee.getMonthlyIncome() * INCOME_TAX_PERCENTAGE) / 100; 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/src/main/java/hr/taxes/InternTaxCalculator.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public class InternTaxCalculator implements TaxCalculator { 6 | private final int INCOME_TAX_PERCENTAGE = 16; 7 | 8 | public double calculate(Employee employee) { 9 | int monthlyIncome = employee.getMonthlyIncome(); 10 | if (monthlyIncome < 350) { 11 | return 0; 12 | } else { 13 | return (monthlyIncome * INCOME_TAX_PERCENTAGE) / 100; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/src/main/java/hr/taxes/PartTimeTaxCalculator.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public class PartTimeTaxCalculator implements TaxCalculator { 6 | private final int RETIREMENT_TAX_PERCENTAGE = 5; 7 | private final int INCOME_TAX_PERCENTAGE = 16; 8 | private final int BASE_HEALTH_INSURANCE = 100; 9 | 10 | public double calculate(Employee employee) { 11 | int monthlyIncome = employee.getMonthlyIncome(); 12 | return BASE_HEALTH_INSURANCE + 13 | (monthlyIncome * RETIREMENT_TAX_PERCENTAGE) / 100 + 14 | (monthlyIncome * INCOME_TAX_PERCENTAGE) / 100; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/src/main/java/hr/taxes/TaxCalculator.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public interface TaxCalculator { 6 | double calculate(Employee employee); 7 | } 8 | -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/src/main/java/hr/taxes/TaxCalculatorFactory.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | import hr.personnel.FullTimeEmployee; 5 | import hr.personnel.Intern; 6 | import hr.personnel.PartTimeEmployee; 7 | 8 | public class TaxCalculatorFactory { 9 | public static TaxCalculator create(Employee employee) { 10 | if (employee instanceof FullTimeEmployee) { 11 | return new FullTimeTaxCalculator(); 12 | } 13 | 14 | if (employee instanceof PartTimeEmployee) { 15 | return new PartTimeTaxCalculator(); 16 | } 17 | 18 | if (employee instanceof Intern) { 19 | return new InternTaxCalculator(); 20 | } 21 | 22 | throw new RuntimeException("Invalid employee type"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/src/main/resources/payslip_business_requirements.txt: -------------------------------------------------------------------------------- 1 | #Business Requirement Document 2 | #Version 1.0 3 | 4 | The team needs to implement an exportable document: payslip. 5 | It should contain the following information: 6 | - month of income 7 | - name of employee 8 | - income of employee for the given month 9 | 10 | At the moment we just want to export as text but it 11 | might be possible to extend this to other formats. -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/src/main/resources/subcontractor_business_requirements.txt: -------------------------------------------------------------------------------- 1 | #Business Requirement Document 2 | #Version 1.0 3 | 4 | A subcontractor is an entity that works similar to an employee 5 | for various projects. We need to implement this feature because in most 6 | companies employees work with external collaborators. 7 | 8 | We are interested in the contact info (name, own email), 9 | cost (monthly income) and nb of hours worked. 10 | 11 | They need to have an SLA approved before working. 12 | 13 | Because subcontractors are external, they are not eligible 14 | to time off. Nor do we need to calculate taxes for them. 15 | -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/src/main/resources/taxes_business_requirements.txt: -------------------------------------------------------------------------------- 1 | #Business Requirement Document 2 | #Version 1.0 3 | 4 | Taxes for employees are calculated like this: 5 | 6 | - Fixed $100 amount for base health insurance 7 | - 16% income tax 8 | - 10% retirement tax -------------------------------------------------------------------------------- /isp/refactored/GlobomanticsHR/src/main/resources/taxes_business_requirements_v2.txt: -------------------------------------------------------------------------------- 1 | #Business Requirement Document 2 | #Version 2.0 3 | 4 | Taxes for employees are calculated like this: 5 | 6 | 1) For full time employees 7 | 8 | - Fixed $100 amount for base health insurance 9 | - 16% income tax 10 | - 10% retirement tax 11 | 12 | 2) For part time employees 13 | 14 | - Fixed $100 amount for base health insurance 15 | - 16% income tax 16 | - 5% retirement tax 17 | 18 | 3) For interns 19 | - If income < 350 => no tax due to state aid 20 | - Else => only 16% income tax 21 | -------------------------------------------------------------------------------- /isp/sourcecode_m6.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dangeabunea/pluralsight-solid-principles-java/745a3f35a6a31fb653fadabc42ec788cafda1ceb/isp/sourcecode_m6.zip -------------------------------------------------------------------------------- /lsp/before/GlobomanticsHR/.idea/.name: -------------------------------------------------------------------------------- 1 | hr -------------------------------------------------------------------------------- /lsp/before/GlobomanticsHR/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /lsp/before/GlobomanticsHR/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /lsp/before/GlobomanticsHR/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /lsp/before/GlobomanticsHR/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /lsp/before/GlobomanticsHR/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /lsp/before/GlobomanticsHR/GlobomanticsHR.iml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /lsp/before/GlobomanticsHR/hr.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /lsp/before/GlobomanticsHR/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | globomantics 8 | hr 9 | 1.0.0 10 | 11 | 12 | 1.8 13 | 1.8 14 | 15 | -------------------------------------------------------------------------------- /lsp/before/GlobomanticsHR/src/main/java/hr/documents/ExportableDocument.java: -------------------------------------------------------------------------------- 1 | package hr.documents; 2 | 3 | /* 4 | Common interface used in application when there is 5 | a need for document exports 6 | */ 7 | public interface ExportableDocument { 8 | byte[] toPdf(); 9 | String toJson(); 10 | String toTxt(); 11 | } 12 | -------------------------------------------------------------------------------- /lsp/before/GlobomanticsHR/src/main/java/hr/logging/ConsoleLogger.java: -------------------------------------------------------------------------------- 1 | package hr.logging; 2 | 3 | public class ConsoleLogger { 4 | public void writeInfo(String msg) { 5 | System.out.println("Info: " + msg); 6 | } 7 | 8 | public void writeError(String msg, Exception e) { 9 | System.err.println("Error: " + msg + ";" + e); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /lsp/before/GlobomanticsHR/src/main/java/hr/main/ApproveSLAMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.logging.ConsoleLogger; 4 | import hr.persistence.EmployeeFileSerializer; 5 | import hr.persistence.EmployeeRepository; 6 | import hr.personnel.Employee; 7 | import hr.personnel.ServiceLicenseAgreement; 8 | import hr.personnel.Subcontractor; 9 | 10 | import java.util.List; 11 | 12 | public class ApproveSLAMain { 13 | public static void main(String[] args) { 14 | // Create dependencies 15 | ConsoleLogger consoleLogger = new ConsoleLogger(); 16 | EmployeeFileSerializer employeeFileSerializer = new EmployeeFileSerializer(); 17 | EmployeeRepository repository = new EmployeeRepository(employeeFileSerializer); 18 | 19 | // Define SLA 20 | int minTimeOffPercent = 98; 21 | int maxResolutionDays = 2; 22 | ServiceLicenseAgreement companySla = new ServiceLicenseAgreement( 23 | minTimeOffPercent, 24 | maxResolutionDays); 25 | 26 | // Grab subcontractors 27 | List subcontractors = repository.findAll(); 28 | 29 | for (Employee e : subcontractors){ 30 | if(e instanceof Subcontractor){ 31 | Subcontractor s = (Subcontractor)e; 32 | s.approveSLA(companySla); 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /lsp/before/GlobomanticsHR/src/main/java/hr/main/CalculateEmployeeTaxesMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.logging.ConsoleLogger; 4 | import hr.persistence.EmployeeFileSerializer; 5 | import hr.persistence.EmployeeRepository; 6 | import hr.personnel.Employee; 7 | import hr.taxes.FullTimeTaxCalculator; 8 | import hr.taxes.TaxCalculator; 9 | import hr.taxes.TaxCalculatorFactory; 10 | 11 | import java.text.NumberFormat; 12 | import java.util.List; 13 | import java.util.Locale; 14 | 15 | public class CalculateEmployeeTaxesMain { 16 | public static void main(String[] args) { 17 | // Create dependencies 18 | ConsoleLogger consoleLogger = new ConsoleLogger(); 19 | EmployeeFileSerializer employeeFileSerializer = new EmployeeFileSerializer(); 20 | EmployeeRepository repository = new EmployeeRepository(employeeFileSerializer); 21 | 22 | // Grab employees 23 | List employees = repository.findAll(); 24 | 25 | // Calculate taxes 26 | Locale locale = new Locale("en", "US"); 27 | NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(locale); 28 | 29 | double totalTaxes = 0; 30 | for (Employee employee: employees){ 31 | TaxCalculator taxCalculator = TaxCalculatorFactory.create(employee); 32 | 33 | // compute individual tax 34 | double tax = taxCalculator.calculate(employee); 35 | String formattedTax = currencyFormatter.format(tax); 36 | consoleLogger.writeInfo(employee.getFullName() + " taxes: " + formattedTax); 37 | 38 | // add to company total taxes 39 | totalTaxes += taxCalculator.calculate(employee); 40 | } 41 | consoleLogger.writeInfo("Total taxes = " + currencyFormatter.format(totalTaxes)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /lsp/before/GlobomanticsHR/src/main/java/hr/main/NatHolidayEmployeeTimeOffMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.logging.ConsoleLogger; 4 | import hr.persistence.EmployeeFileSerializer; 5 | import hr.persistence.EmployeeRepository; 6 | import hr.personnel.Employee; 7 | import hr.personnel.FullTimeEmployee; 8 | 9 | import java.util.List; 10 | 11 | public class NatHolidayEmployeeTimeOffMain { 12 | public static void main(String[] args) { 13 | // Create dependencies 14 | ConsoleLogger consoleLogger = new ConsoleLogger(); 15 | EmployeeFileSerializer employeeFileSerializer = new EmployeeFileSerializer(); 16 | EmployeeRepository repository = new EmployeeRepository(employeeFileSerializer); 17 | 18 | // Grab employees 19 | List employees = repository.findAll(); 20 | Employee manager = new FullTimeEmployee("Steve Jackson", 5000); 21 | 22 | // Request time off for each employee on 23 | // national holiday 24 | for (Employee employee : employees){ 25 | employee.requestTimeOff(1, manager); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /lsp/before/GlobomanticsHR/src/main/java/hr/main/SaveEmployeesMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.logging.ConsoleLogger; 4 | import hr.persistence.EmployeeFileSerializer; 5 | import hr.persistence.EmployeeRepository; 6 | import hr.personnel.Employee; 7 | 8 | import java.io.IOException; 9 | import java.util.List; 10 | 11 | public class SaveEmployeesMain { 12 | public static void main(String[] args) { 13 | // Grab employees 14 | EmployeeFileSerializer employeeFileSerializer = new EmployeeFileSerializer(); 15 | ConsoleLogger consoleLogger = new ConsoleLogger(); 16 | 17 | EmployeeRepository repository = new EmployeeRepository(employeeFileSerializer); 18 | List employees = repository.findAll(); 19 | 20 | // Save all 21 | for (Employee e : employees){ 22 | try { 23 | repository.save(e); 24 | consoleLogger.writeInfo("Saved employee " + e.toString()); 25 | } catch (IOException exception) { 26 | consoleLogger.writeError("Error saving employee", exception); 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /lsp/before/GlobomanticsHR/src/main/java/hr/persistence/EmployeeFileSerializer.java: -------------------------------------------------------------------------------- 1 | package hr.persistence; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public class EmployeeFileSerializer { 6 | public String serialize(Employee employee) { 7 | StringBuilder sb = new StringBuilder(); 8 | 9 | sb.append("### EMPLOYEE RECORD ####"); 10 | sb.append(System.lineSeparator()); 11 | sb.append("NAME: "); 12 | sb.append(employee.getFullName()); 13 | sb.append(System.lineSeparator()); 14 | sb.append("POSITION: "); 15 | sb.append(employee.getClass().getTypeName()); 16 | sb.append(System.lineSeparator()); 17 | sb.append("EMAIL: "); 18 | sb.append(employee.getEmail()); 19 | sb.append(System.lineSeparator()); 20 | sb.append("MONTHLY WAGE: "); 21 | sb.append(employee.getMonthlyIncome()); 22 | sb.append(System.lineSeparator()); 23 | 24 | return sb.toString(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /lsp/before/GlobomanticsHR/src/main/java/hr/personnel/FullTimeEmployee.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class FullTimeEmployee extends Employee { 4 | public FullTimeEmployee(String fullName, int monthlyIncome) { 5 | super(fullName, monthlyIncome); 6 | this.setNbHoursPerWeek(40); 7 | } 8 | 9 | @Override 10 | public void requestTimeOff(int nbDays, Employee manager) { 11 | /* 12 | HR business logic for time off for full time employees 13 | */ 14 | 15 | System.out.println("Time off request for full time employee " + 16 | this.getFullName() + 17 | "; Nb days " + nbDays + 18 | "; Requested from " + manager.getFullName()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /lsp/before/GlobomanticsHR/src/main/java/hr/personnel/Intern.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class Intern extends Employee { 4 | public Intern(String fullName, int monthlyIncome, int nbHours) { 5 | super(fullName, monthlyIncome); 6 | setNbHoursPerWeek(nbHours); 7 | } 8 | 9 | @Override 10 | public void requestTimeOff(int nbDays, Employee manager) { 11 | /* 12 | HR business logic for time off for interns 13 | */ 14 | 15 | System.out.println("Time off request for intern " + 16 | this.getFullName() + 17 | "; Nb days " + nbDays + 18 | "; Requested from " + manager.getFullName()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /lsp/before/GlobomanticsHR/src/main/java/hr/personnel/PartTimeEmployee.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class PartTimeEmployee extends Employee { 4 | public PartTimeEmployee(String fullName, int monthlyIncome) { 5 | super(fullName, monthlyIncome); 6 | this.setNbHoursPerWeek(20); 7 | } 8 | 9 | @Override 10 | public void requestTimeOff(int nbDays, Employee manager) { 11 | /* 12 | HR business logic for time off for part time employees 13 | */ 14 | 15 | System.out.println("Time off request for part time employee " + 16 | this.getFullName() + 17 | "; Nb days " + nbDays + 18 | "; Requested from " + manager.getFullName()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /lsp/before/GlobomanticsHR/src/main/java/hr/personnel/ServiceLicenseAgreement.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class ServiceLicenseAgreement { 4 | private int minUptimePercent; 5 | private int problemResolutionTimeDays; 6 | 7 | public ServiceLicenseAgreement(int minUptime, int problemResolutionTimeDays) { 8 | this.minUptimePercent = minUptime; 9 | this.problemResolutionTimeDays = problemResolutionTimeDays; 10 | } 11 | 12 | public int getMinUptimePercent() { 13 | return minUptimePercent; 14 | } 15 | 16 | public int getProblemResolutionTimeDays() { 17 | return problemResolutionTimeDays; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /lsp/before/GlobomanticsHR/src/main/java/hr/personnel/Subcontractor.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class Subcontractor extends Employee { 4 | 5 | public Subcontractor(String fullName, int monthlyIncome) { 6 | super(fullName, monthlyIncome); 7 | } 8 | 9 | @Override 10 | public void requestTimeOff(int nbDays, Employee manager) { 11 | throw new RuntimeException("Not implemented"); 12 | } 13 | 14 | public boolean approveSLA(ServiceLicenseAgreement sla) { 15 | /* 16 | Business logic for approving a 17 | service license agreement for a 18 | for a subcontractor 19 | */ 20 | boolean result = false; 21 | if (sla.getMinUptimePercent() >= 98 22 | && sla.getProblemResolutionTimeDays() <= 2) { 23 | result= true; 24 | } 25 | 26 | System.out.println("SLA approval for " + this.getFullName() + ": " + result); 27 | return result; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lsp/before/GlobomanticsHR/src/main/java/hr/taxes/FullTimeTaxCalculator.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public class FullTimeTaxCalculator implements TaxCalculator { 6 | private final int RETIREMENT_TAX_PERCENTAGE = 10; 7 | private final int INCOME_TAX_PERCENTAGE = 16; 8 | private final int BASE_HEALTH_INSURANCE = 100; 9 | 10 | 11 | public double calculate(Employee employee) { 12 | return BASE_HEALTH_INSURANCE + 13 | (employee.getMonthlyIncome() * RETIREMENT_TAX_PERCENTAGE) / 100 + 14 | (employee.getMonthlyIncome() * INCOME_TAX_PERCENTAGE) / 100; 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /lsp/before/GlobomanticsHR/src/main/java/hr/taxes/InternTaxCalculator.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public class InternTaxCalculator implements TaxCalculator { 6 | private final int INCOME_TAX_PERCENTAGE = 16; 7 | 8 | public double calculate(Employee employee) { 9 | int monthlyIncome = employee.getMonthlyIncome(); 10 | if (monthlyIncome < 350) { 11 | return 0; 12 | } else { 13 | return (monthlyIncome * INCOME_TAX_PERCENTAGE) / 100; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /lsp/before/GlobomanticsHR/src/main/java/hr/taxes/PartTimeTaxCalculator.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public class PartTimeTaxCalculator implements TaxCalculator { 6 | private final int RETIREMENT_TAX_PERCENTAGE = 5; 7 | private final int INCOME_TAX_PERCENTAGE = 16; 8 | private final int BASE_HEALTH_INSURANCE = 100; 9 | 10 | public double calculate(Employee employee) { 11 | int monthlyIncome = employee.getMonthlyIncome(); 12 | return BASE_HEALTH_INSURANCE + 13 | (monthlyIncome * RETIREMENT_TAX_PERCENTAGE) / 100 + 14 | (monthlyIncome * INCOME_TAX_PERCENTAGE) / 100; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /lsp/before/GlobomanticsHR/src/main/java/hr/taxes/TaxCalculator.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public interface TaxCalculator { 6 | double calculate(Employee employee); 7 | } 8 | -------------------------------------------------------------------------------- /lsp/before/GlobomanticsHR/src/main/java/hr/taxes/TaxCalculatorFactory.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | import hr.personnel.FullTimeEmployee; 5 | import hr.personnel.Intern; 6 | import hr.personnel.PartTimeEmployee; 7 | 8 | public class TaxCalculatorFactory { 9 | public static TaxCalculator create(Employee employee) { 10 | if (employee instanceof FullTimeEmployee) { 11 | return new FullTimeTaxCalculator(); 12 | } 13 | 14 | if (employee instanceof PartTimeEmployee) { 15 | return new PartTimeTaxCalculator(); 16 | } 17 | 18 | if (employee instanceof Intern) { 19 | return new InternTaxCalculator(); 20 | } 21 | 22 | throw new RuntimeException("Invalid employee type"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /lsp/before/GlobomanticsHR/src/main/resources/subcontractor_business_requirements.txt: -------------------------------------------------------------------------------- 1 | #Business Requirement Document 2 | #Version 1.0 3 | 4 | A subcontractor is an entity that works similar to an employee 5 | for various projects. We need to implement this feature because in most 6 | companies employees work with external collaborators. 7 | 8 | We are interested in the contact info (name, own email), 9 | cost (monthly income) and nb of hours worked. 10 | 11 | They need to have an SLA approved before working. 12 | 13 | Because subcontractors are external, they are not eligible 14 | to time off. Nor do we need to calculate taxes for them. 15 | -------------------------------------------------------------------------------- /lsp/before/GlobomanticsHR/src/main/resources/taxes_business_requirements.txt: -------------------------------------------------------------------------------- 1 | #Business Requirement Document 2 | #Version 1.0 3 | 4 | Taxes for employees are calculated like this: 5 | 6 | - Fixed $100 amount for base health insurance 7 | - 16% income tax 8 | - 10% retirement tax -------------------------------------------------------------------------------- /lsp/before/GlobomanticsHR/src/main/resources/taxes_business_requirements_v2.txt: -------------------------------------------------------------------------------- 1 | #Business Requirement Document 2 | #Version 2.0 3 | 4 | Taxes for employees are calculated like this: 5 | 6 | 1) For full time employees 7 | 8 | - Fixed $100 amount for base health insurance 9 | - 16% income tax 10 | - 10% retirement tax 11 | 12 | 2) For part time employees 13 | 14 | - Fixed $100 amount for base health insurance 15 | - 16% income tax 16 | - 5% retirement tax 17 | 18 | 3) For interns 19 | - If income < 350 => no tax due to state aid 20 | - Else => only 16% income tax 21 | -------------------------------------------------------------------------------- /lsp/m5_sourcecode.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dangeabunea/pluralsight-solid-principles-java/745a3f35a6a31fb653fadabc42ec788cafda1ceb/lsp/m5_sourcecode.zip -------------------------------------------------------------------------------- /lsp/refactored/GlobomanticsHR/.idea/.name: -------------------------------------------------------------------------------- 1 | hr -------------------------------------------------------------------------------- /lsp/refactored/GlobomanticsHR/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /lsp/refactored/GlobomanticsHR/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /lsp/refactored/GlobomanticsHR/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /lsp/refactored/GlobomanticsHR/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /lsp/refactored/GlobomanticsHR/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /lsp/refactored/GlobomanticsHR/GlobomanticsHR.iml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /lsp/refactored/GlobomanticsHR/hr.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /lsp/refactored/GlobomanticsHR/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | globomantics 8 | hr 9 | 1.0.0 10 | 11 | 12 | 1.8 13 | 1.8 14 | 15 | -------------------------------------------------------------------------------- /lsp/refactored/GlobomanticsHR/src/main/java/hr/documents/ExportableDocument.java: -------------------------------------------------------------------------------- 1 | package hr.documents; 2 | 3 | /* 4 | Common interface used in application when there is 5 | a need for document exports 6 | */ 7 | public interface ExportableDocument { 8 | byte[] toPdf(); 9 | String toJson(); 10 | String toTxt(); 11 | } 12 | -------------------------------------------------------------------------------- /lsp/refactored/GlobomanticsHR/src/main/java/hr/logging/ConsoleLogger.java: -------------------------------------------------------------------------------- 1 | package hr.logging; 2 | 3 | public class ConsoleLogger { 4 | public void writeInfo(String msg) { 5 | System.out.println("Info: " + msg); 6 | } 7 | 8 | public void writeError(String msg, Exception e) { 9 | System.err.println("Error: " + msg + ";" + e); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /lsp/refactored/GlobomanticsHR/src/main/java/hr/main/ApproveSLAMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.logging.ConsoleLogger; 4 | import hr.persistence.EmployeeFileSerializer; 5 | import hr.persistence.EmployeeRepository; 6 | import hr.personnel.Employee; 7 | import hr.personnel.ServiceLicenseAgreement; 8 | import hr.personnel.Subcontractor; 9 | 10 | import java.util.Arrays; 11 | import java.util.List; 12 | 13 | public class ApproveSLAMain { 14 | public static void main(String[] args) { 15 | // Define SLA 16 | int minTimeOffPercent = 98; 17 | int maxResolutionDays = 2; 18 | ServiceLicenseAgreement companySla = new ServiceLicenseAgreement( 19 | minTimeOffPercent, 20 | maxResolutionDays); 21 | 22 | // Get collaborators from their own source 23 | Subcontractor subcontractor1 = new Subcontractor( 24 | "Rebekah Jackson", 25 | "rebekah-jackson@abc.com", 26 | 3000, 27 | 15); 28 | Subcontractor subcontractor2 = new Subcontractor( 29 | "Harry Fitz", 30 | "harryfitz@def.com", 31 | 3000, 15); 32 | List collaborators = Arrays.asList(subcontractor1, subcontractor2); 33 | 34 | // Check SLA 35 | for (Subcontractor s : collaborators) { 36 | s.approveSLA(companySla); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /lsp/refactored/GlobomanticsHR/src/main/java/hr/main/CalculateEmployeeTaxesMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.logging.ConsoleLogger; 4 | import hr.persistence.EmployeeFileSerializer; 5 | import hr.persistence.EmployeeRepository; 6 | import hr.personnel.Employee; 7 | import hr.taxes.FullTimeTaxCalculator; 8 | import hr.taxes.TaxCalculator; 9 | import hr.taxes.TaxCalculatorFactory; 10 | 11 | import java.text.NumberFormat; 12 | import java.util.List; 13 | import java.util.Locale; 14 | 15 | public class CalculateEmployeeTaxesMain { 16 | public static void main(String[] args) { 17 | // Create dependencies 18 | ConsoleLogger consoleLogger = new ConsoleLogger(); 19 | EmployeeFileSerializer employeeFileSerializer = new EmployeeFileSerializer(); 20 | EmployeeRepository repository = new EmployeeRepository(employeeFileSerializer); 21 | 22 | // Grab employees 23 | List employees = repository.findAll(); 24 | 25 | // Calculate taxes 26 | Locale locale = new Locale("en", "US"); 27 | NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(locale); 28 | 29 | double totalTaxes = 0; 30 | for (Employee employee: employees){ 31 | TaxCalculator taxCalculator = TaxCalculatorFactory.create(employee); 32 | 33 | // compute individual tax 34 | double tax = taxCalculator.calculate(employee); 35 | String formattedTax = currencyFormatter.format(tax); 36 | consoleLogger.writeInfo(employee.getFullName() + " taxes: " + formattedTax); 37 | 38 | // add to company total taxes 39 | totalTaxes += taxCalculator.calculate(employee); 40 | } 41 | consoleLogger.writeInfo("Total taxes = " + currencyFormatter.format(totalTaxes)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /lsp/refactored/GlobomanticsHR/src/main/java/hr/main/NatHolidayEmployeeTimeOffMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.logging.ConsoleLogger; 4 | import hr.persistence.EmployeeFileSerializer; 5 | import hr.persistence.EmployeeRepository; 6 | import hr.personnel.Employee; 7 | import hr.personnel.FullTimeEmployee; 8 | 9 | import java.util.List; 10 | 11 | public class NatHolidayEmployeeTimeOffMain { 12 | public static void main(String[] args) { 13 | // Create dependencies 14 | ConsoleLogger consoleLogger = new ConsoleLogger(); 15 | EmployeeFileSerializer employeeFileSerializer = new EmployeeFileSerializer(); 16 | EmployeeRepository repository = new EmployeeRepository(employeeFileSerializer); 17 | 18 | // Grab employees 19 | List employees = repository.findAll(); 20 | Employee manager = new FullTimeEmployee("Steve Jackson", 5000); 21 | 22 | // Request time off for each employee on 23 | // national holiday 24 | for (Employee employee : employees){ 25 | employee.requestTimeOff(1, manager); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /lsp/refactored/GlobomanticsHR/src/main/java/hr/main/SaveEmployeesMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.logging.ConsoleLogger; 4 | import hr.persistence.EmployeeFileSerializer; 5 | import hr.persistence.EmployeeRepository; 6 | import hr.personnel.Employee; 7 | 8 | import java.io.IOException; 9 | import java.util.List; 10 | 11 | public class SaveEmployeesMain { 12 | public static void main(String[] args) { 13 | // Grab employees 14 | EmployeeFileSerializer employeeFileSerializer = new EmployeeFileSerializer(); 15 | ConsoleLogger consoleLogger = new ConsoleLogger(); 16 | 17 | EmployeeRepository repository = new EmployeeRepository(employeeFileSerializer); 18 | List employees = repository.findAll(); 19 | 20 | // Save all 21 | for (Employee e : employees){ 22 | try { 23 | repository.save(e); 24 | consoleLogger.writeInfo("Saved employee " + e.toString()); 25 | } catch (IOException exception) { 26 | consoleLogger.writeError("Error saving employee", exception); 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /lsp/refactored/GlobomanticsHR/src/main/java/hr/persistence/EmployeeFileSerializer.java: -------------------------------------------------------------------------------- 1 | package hr.persistence; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public class EmployeeFileSerializer { 6 | public String serialize(Employee employee) { 7 | StringBuilder sb = new StringBuilder(); 8 | 9 | sb.append("### EMPLOYEE RECORD ####"); 10 | sb.append(System.lineSeparator()); 11 | sb.append("NAME: "); 12 | sb.append(employee.getFullName()); 13 | sb.append(System.lineSeparator()); 14 | sb.append("POSITION: "); 15 | sb.append(employee.getClass().getTypeName()); 16 | sb.append(System.lineSeparator()); 17 | sb.append("EMAIL: "); 18 | sb.append(employee.getEmail()); 19 | sb.append(System.lineSeparator()); 20 | sb.append("MONTHLY WAGE: "); 21 | sb.append(employee.getMonthlyIncome()); 22 | sb.append(System.lineSeparator()); 23 | 24 | return sb.toString(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /lsp/refactored/GlobomanticsHR/src/main/java/hr/persistence/EmployeeRepository.java: -------------------------------------------------------------------------------- 1 | package hr.persistence; 2 | 3 | import hr.logging.ConsoleLogger; 4 | import hr.personnel.*; 5 | 6 | import java.io.IOException; 7 | import java.nio.file.Files; 8 | import java.nio.file.Path; 9 | import java.nio.file.Paths; 10 | import java.util.Arrays; 11 | import java.util.List; 12 | 13 | /* 14 | Helper method to perform CRUD operations on employees. In a production 15 | application we could use the database for persistence. In this demo, 16 | we are storing employees in the file system. 17 | */ 18 | 19 | public class EmployeeRepository { 20 | private EmployeeFileSerializer serializer; 21 | 22 | public EmployeeRepository(EmployeeFileSerializer serializer) { 23 | this.serializer = serializer; 24 | } 25 | 26 | public List findAll() { 27 | 28 | // Employees are kept in memory for simplicity 29 | Employee anna = new FullTimeEmployee("Anna Smith", 2000); 30 | Employee billy = new FullTimeEmployee("Billy Leech", 920); 31 | 32 | Employee steve = new PartTimeEmployee("Steve Jones", 800); 33 | Employee magda = new PartTimeEmployee("Magda Iovan", 920); 34 | 35 | Employee john = new Intern("John Lee", 300, 10); 36 | Employee catherine = new Intern("Catherine Allison", 500, 15); 37 | 38 | return Arrays.asList(anna, billy, steve, magda, john, catherine); 39 | } 40 | 41 | public void save(Employee employee) throws IOException { 42 | String serializedString = this.serializer.serialize(employee); 43 | 44 | Path path = Paths.get(employee.getFullName() 45 | .replace(" ", "_") + ".rec"); 46 | Files.write(path, serializedString.getBytes()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /lsp/refactored/GlobomanticsHR/src/main/java/hr/personnel/FullTimeEmployee.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class FullTimeEmployee extends Employee { 4 | public FullTimeEmployee(String fullName, int monthlyIncome) { 5 | super(fullName, monthlyIncome); 6 | this.setNbHoursPerWeek(40); 7 | } 8 | 9 | @Override 10 | public void requestTimeOff(int nbDays, Employee manager) { 11 | /* 12 | HR business logic for time off for full time employees 13 | */ 14 | 15 | System.out.println("Time off request for full time employee " + 16 | this.getFullName() + 17 | "; Nb days " + nbDays + 18 | "; Requested from " + manager.getFullName()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /lsp/refactored/GlobomanticsHR/src/main/java/hr/personnel/Intern.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class Intern extends Employee { 4 | public Intern(String fullName, int monthlyIncome, int nbHours) { 5 | super(fullName, monthlyIncome); 6 | setNbHoursPerWeek(nbHours); 7 | } 8 | 9 | @Override 10 | public void requestTimeOff(int nbDays, Employee manager) { 11 | /* 12 | HR business logic for time off for interns 13 | */ 14 | 15 | System.out.println("Time off request for intern " + 16 | this.getFullName() + 17 | "; Nb days " + nbDays + 18 | "; Requested from " + manager.getFullName()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /lsp/refactored/GlobomanticsHR/src/main/java/hr/personnel/PartTimeEmployee.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class PartTimeEmployee extends Employee { 4 | public PartTimeEmployee(String fullName, int monthlyIncome) { 5 | super(fullName, monthlyIncome); 6 | this.setNbHoursPerWeek(20); 7 | } 8 | 9 | @Override 10 | public void requestTimeOff(int nbDays, Employee manager) { 11 | /* 12 | HR business logic for time off for part time employees 13 | */ 14 | 15 | System.out.println("Time off request for part time employee " + 16 | this.getFullName() + 17 | "; Nb days " + nbDays + 18 | "; Requested from " + manager.getFullName()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /lsp/refactored/GlobomanticsHR/src/main/java/hr/personnel/ServiceLicenseAgreement.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class ServiceLicenseAgreement { 4 | private int minUptimePercent; 5 | private int problemResolutionTimeDays; 6 | 7 | public ServiceLicenseAgreement(int minUptime, int problemResolutionTimeDays) { 8 | this.minUptimePercent = minUptime; 9 | this.problemResolutionTimeDays = problemResolutionTimeDays; 10 | } 11 | 12 | public int getMinUptimePercent() { 13 | return minUptimePercent; 14 | } 15 | 16 | public int getProblemResolutionTimeDays() { 17 | return problemResolutionTimeDays; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /lsp/refactored/GlobomanticsHR/src/main/java/hr/personnel/Subcontractor.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class Subcontractor { 4 | 5 | private final int monthlyIncome; 6 | private int nbHoursPerWeek; 7 | private String email; 8 | private String name; 9 | 10 | public Subcontractor(String name, 11 | String email, 12 | int monthlyIncome, 13 | int nbHoursPerWeek) { 14 | 15 | this.name = name; 16 | this.email = email; 17 | this.monthlyIncome = monthlyIncome; 18 | this.nbHoursPerWeek = nbHoursPerWeek; 19 | } 20 | 21 | public boolean approveSLA(ServiceLicenseAgreement sla) { 22 | boolean result = false; 23 | if (sla.getMinUptimePercent() >= 98 && 24 | sla.getProblemResolutionTimeDays() <= 2) { 25 | result = true; 26 | } 27 | 28 | System.out.println("SLA approval for " + this.name + ": " + result); 29 | return result; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /lsp/refactored/GlobomanticsHR/src/main/java/hr/taxes/FullTimeTaxCalculator.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public class FullTimeTaxCalculator implements TaxCalculator { 6 | private final int RETIREMENT_TAX_PERCENTAGE = 10; 7 | private final int INCOME_TAX_PERCENTAGE = 16; 8 | private final int BASE_HEALTH_INSURANCE = 100; 9 | 10 | 11 | public double calculate(Employee employee) { 12 | return BASE_HEALTH_INSURANCE + 13 | (employee.getMonthlyIncome() * RETIREMENT_TAX_PERCENTAGE) / 100 + 14 | (employee.getMonthlyIncome() * INCOME_TAX_PERCENTAGE) / 100; 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /lsp/refactored/GlobomanticsHR/src/main/java/hr/taxes/InternTaxCalculator.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public class InternTaxCalculator implements TaxCalculator { 6 | private final int INCOME_TAX_PERCENTAGE = 16; 7 | 8 | public double calculate(Employee employee) { 9 | int monthlyIncome = employee.getMonthlyIncome(); 10 | if (monthlyIncome < 350) { 11 | return 0; 12 | } else { 13 | return (monthlyIncome * INCOME_TAX_PERCENTAGE) / 100; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /lsp/refactored/GlobomanticsHR/src/main/java/hr/taxes/PartTimeTaxCalculator.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public class PartTimeTaxCalculator implements TaxCalculator { 6 | private final int RETIREMENT_TAX_PERCENTAGE = 5; 7 | private final int INCOME_TAX_PERCENTAGE = 16; 8 | private final int BASE_HEALTH_INSURANCE = 100; 9 | 10 | public double calculate(Employee employee) { 11 | int monthlyIncome = employee.getMonthlyIncome(); 12 | return BASE_HEALTH_INSURANCE + 13 | (monthlyIncome * RETIREMENT_TAX_PERCENTAGE) / 100 + 14 | (monthlyIncome * INCOME_TAX_PERCENTAGE) / 100; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /lsp/refactored/GlobomanticsHR/src/main/java/hr/taxes/TaxCalculator.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public interface TaxCalculator { 6 | double calculate(Employee employee); 7 | } 8 | -------------------------------------------------------------------------------- /lsp/refactored/GlobomanticsHR/src/main/java/hr/taxes/TaxCalculatorFactory.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | import hr.personnel.FullTimeEmployee; 5 | import hr.personnel.Intern; 6 | import hr.personnel.PartTimeEmployee; 7 | 8 | public class TaxCalculatorFactory { 9 | public static TaxCalculator create(Employee employee) { 10 | if (employee instanceof FullTimeEmployee) { 11 | return new FullTimeTaxCalculator(); 12 | } 13 | 14 | if (employee instanceof PartTimeEmployee) { 15 | return new PartTimeTaxCalculator(); 16 | } 17 | 18 | if (employee instanceof Intern) { 19 | return new InternTaxCalculator(); 20 | } 21 | 22 | throw new RuntimeException("Invalid employee type"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /lsp/refactored/GlobomanticsHR/src/main/resources/subcontractor_business_requirements.txt: -------------------------------------------------------------------------------- 1 | #Business Requirement Document 2 | #Version 1.0 3 | 4 | A subcontractor is an entity that works similar to an employee 5 | for various projects. We need to implement this feature because in most 6 | companies employees work with external collaborators. 7 | 8 | We are interested in the contact info (name, own email), 9 | cost (monthly income) and nb of hours worked. 10 | 11 | They need to have an SLA approved before working. 12 | 13 | Because subcontractors are external, they are not eligible 14 | to time off. Nor do we need to calculate taxes for them. 15 | -------------------------------------------------------------------------------- /lsp/refactored/GlobomanticsHR/src/main/resources/taxes_business_requirements.txt: -------------------------------------------------------------------------------- 1 | #Business Requirement Document 2 | #Version 1.0 3 | 4 | Taxes for employees are calculated like this: 5 | 6 | - Fixed $100 amount for base health insurance 7 | - 16% income tax 8 | - 10% retirement tax -------------------------------------------------------------------------------- /lsp/refactored/GlobomanticsHR/src/main/resources/taxes_business_requirements_v2.txt: -------------------------------------------------------------------------------- 1 | #Business Requirement Document 2 | #Version 2.0 3 | 4 | Taxes for employees are calculated like this: 5 | 6 | 1) For full time employees 7 | 8 | - Fixed $100 amount for base health insurance 9 | - 16% income tax 10 | - 10% retirement tax 11 | 12 | 2) For part time employees 13 | 14 | - Fixed $100 amount for base health insurance 15 | - 16% income tax 16 | - 5% retirement tax 17 | 18 | 3) For interns 19 | - If income < 350 => no tax due to state aid 20 | - Else => only 16% income tax 21 | -------------------------------------------------------------------------------- /ocp/before/GlobomanticsHR/.idea/.name: -------------------------------------------------------------------------------- 1 | hr -------------------------------------------------------------------------------- /ocp/before/GlobomanticsHR/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /ocp/before/GlobomanticsHR/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /ocp/before/GlobomanticsHR/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /ocp/before/GlobomanticsHR/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ocp/before/GlobomanticsHR/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /ocp/before/GlobomanticsHR/GlobomanticsHR.iml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /ocp/before/GlobomanticsHR/hr.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /ocp/before/GlobomanticsHR/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | globomantics 8 | hr 9 | 1.0.0 10 | 11 | 12 | 1.8 13 | 1.8 14 | 15 | -------------------------------------------------------------------------------- /ocp/before/GlobomanticsHR/src/main/java/hr/documents/ExportableDocument.java: -------------------------------------------------------------------------------- 1 | package hr.documents; 2 | 3 | /* 4 | Common interface used in application when there is 5 | a need for document exports 6 | */ 7 | public interface ExportableDocument { 8 | byte[] toPdf(); 9 | String toJson(); 10 | String toTxt(); 11 | } 12 | -------------------------------------------------------------------------------- /ocp/before/GlobomanticsHR/src/main/java/hr/logging/ConsoleLogger.java: -------------------------------------------------------------------------------- 1 | package hr.logging; 2 | 3 | public class ConsoleLogger { 4 | public void writeInfo(String msg) { 5 | System.out.println("Info: " + msg); 6 | } 7 | 8 | public void writeError(String msg, Exception e) { 9 | System.err.println("Error: " + msg + ";" + e); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /ocp/before/GlobomanticsHR/src/main/java/hr/main/CalculateTaxesMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.logging.ConsoleLogger; 4 | import hr.persistence.EmployeeFileSerializer; 5 | import hr.persistence.EmployeeRepository; 6 | import hr.personnel.Employee; 7 | import hr.taxes.TaxCalculator; 8 | 9 | import java.text.NumberFormat; 10 | import java.util.List; 11 | import java.util.Locale; 12 | 13 | public class CalculateTaxesMain { 14 | public static void main(String[] args) { 15 | // Create dependencies 16 | ConsoleLogger consoleLogger = new ConsoleLogger(); 17 | EmployeeFileSerializer employeeFileSerializer = new EmployeeFileSerializer(); 18 | EmployeeRepository repository = new EmployeeRepository(employeeFileSerializer); 19 | 20 | // Grab employees 21 | List employees = repository.findAll(); 22 | 23 | // Calculate taxes 24 | Locale locale = new Locale("en", "US"); 25 | NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(locale); 26 | TaxCalculator taxCalculator = new TaxCalculator(); 27 | 28 | double totalTaxes = 0; 29 | for (Employee employee: employees){ 30 | 31 | // compute individual tax 32 | double tax = taxCalculator.calculate(employee); 33 | String formattedTax = currencyFormatter.format(tax); 34 | consoleLogger.writeInfo(employee.getFullName() + " taxes: " + formattedTax); 35 | 36 | // add to company total taxes 37 | totalTaxes += taxCalculator.calculate(employee); 38 | } 39 | consoleLogger.writeInfo("Total taxes = " + currencyFormatter.format(totalTaxes)); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /ocp/before/GlobomanticsHR/src/main/java/hr/main/SaveEmployeesMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.logging.ConsoleLogger; 4 | import hr.persistence.EmployeeFileSerializer; 5 | import hr.persistence.EmployeeRepository; 6 | import hr.personnel.Employee; 7 | 8 | import java.io.IOException; 9 | import java.util.List; 10 | 11 | public class SaveEmployeesMain { 12 | public static void main(String[] args) { 13 | // Grab employees 14 | EmployeeFileSerializer employeeFileSerializer = new EmployeeFileSerializer(); 15 | ConsoleLogger consoleLogger = new ConsoleLogger(); 16 | 17 | EmployeeRepository repository = new EmployeeRepository(employeeFileSerializer); 18 | List employees = repository.findAll(); 19 | 20 | // Save all 21 | for (Employee e : employees){ 22 | try { 23 | repository.save(e); 24 | consoleLogger.writeInfo("Saved employee " + e.toString()); 25 | } catch (IOException exception) { 26 | consoleLogger.writeError("Error saving employee", exception); 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ocp/before/GlobomanticsHR/src/main/java/hr/persistence/EmployeeFileSerializer.java: -------------------------------------------------------------------------------- 1 | package hr.persistence; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public class EmployeeFileSerializer { 6 | public String serialize(Employee employee) { 7 | StringBuilder sb = new StringBuilder(); 8 | 9 | sb.append("### EMPLOYEE RECORD ####"); 10 | sb.append(System.lineSeparator()); 11 | sb.append("NAME: "); 12 | sb.append(employee.getFullName()); 13 | sb.append(System.lineSeparator()); 14 | sb.append("POSITION: "); 15 | sb.append(employee.getClass().getTypeName()); 16 | sb.append(System.lineSeparator()); 17 | sb.append("EMAIL: "); 18 | sb.append(employee.getEmail()); 19 | sb.append(System.lineSeparator()); 20 | sb.append("MONTHLY WAGE: "); 21 | sb.append(employee.getMonthlyIncome()); 22 | sb.append(System.lineSeparator()); 23 | 24 | return sb.toString(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /ocp/before/GlobomanticsHR/src/main/java/hr/personnel/FullTimeEmployee.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class FullTimeEmployee extends Employee { 4 | public FullTimeEmployee(String fullName, int monthlyIncome) { 5 | super(fullName, monthlyIncome); 6 | this.setNbHoursPerWeek(40); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /ocp/before/GlobomanticsHR/src/main/java/hr/personnel/Intern.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class Intern extends Employee { 4 | public Intern(String fullName, int monthlyIncome, int nbHours) { 5 | super(fullName, monthlyIncome); 6 | setNbHoursPerWeek(nbHours); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /ocp/before/GlobomanticsHR/src/main/java/hr/personnel/PartTimeEmployee.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class PartTimeEmployee extends Employee { 4 | public PartTimeEmployee(String fullName, int monthlyIncome) { 5 | super(fullName, monthlyIncome); 6 | this.setNbHoursPerWeek(20); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /ocp/before/GlobomanticsHR/src/main/java/hr/taxes/TaxCalculator.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public class TaxCalculator { 6 | private final int RETIREMENT_TAX_PERCENTAGE = 10; 7 | private final int INCOME_TAX_PERCENTAGE = 16; 8 | private final int BASE_HEALTH_INSURANCE = 100; 9 | 10 | 11 | public double calculate(Employee employee) { 12 | return BASE_HEALTH_INSURANCE + 13 | (employee.getMonthlyIncome() * RETIREMENT_TAX_PERCENTAGE) / 100 + 14 | (employee.getMonthlyIncome() * INCOME_TAX_PERCENTAGE) / 100; 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ocp/before/GlobomanticsHR/src/main/resources/taxes_business_requirements.txt: -------------------------------------------------------------------------------- 1 | #Business Requirement Document 2 | #Version 1.0 3 | 4 | Taxes for employees are calculated like this: 5 | 6 | - Fixed $100 amount for base health insurance 7 | - 16% income tax 8 | - 10% retirement tax -------------------------------------------------------------------------------- /ocp/before/GlobomanticsHR/src/main/resources/taxes_business_requirements_v2.txt: -------------------------------------------------------------------------------- 1 | #Business Requirement Document 2 | #Version 2.0 3 | 4 | Taxes for employees are calculated like this: 5 | 6 | 1) For full time employees 7 | 8 | - Fixed $100 amount for base health insurance 9 | - 16% income tax 10 | - 10% retirement tax 11 | 12 | 2) For part time employees 13 | 14 | - Fixed $100 amount for base health insurance 15 | - 16% income tax 16 | - 5% retirement tax 17 | 18 | 3) For interns 19 | - If income < 350 => no tax due to state aid 20 | - Else => only 16% income tax 21 | -------------------------------------------------------------------------------- /ocp/m4_sourcecode.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dangeabunea/pluralsight-solid-principles-java/745a3f35a6a31fb653fadabc42ec788cafda1ceb/ocp/m4_sourcecode.zip -------------------------------------------------------------------------------- /ocp/refactored/GlobomanticsHR/.idea/.name: -------------------------------------------------------------------------------- 1 | hr -------------------------------------------------------------------------------- /ocp/refactored/GlobomanticsHR/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /ocp/refactored/GlobomanticsHR/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /ocp/refactored/GlobomanticsHR/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /ocp/refactored/GlobomanticsHR/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ocp/refactored/GlobomanticsHR/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /ocp/refactored/GlobomanticsHR/GlobomanticsHR.iml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /ocp/refactored/GlobomanticsHR/hr.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /ocp/refactored/GlobomanticsHR/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | globomantics 8 | hr 9 | 1.0.0 10 | 11 | 12 | 1.8 13 | 1.8 14 | 15 | -------------------------------------------------------------------------------- /ocp/refactored/GlobomanticsHR/src/main/java/hr/documents/ExportableDocument.java: -------------------------------------------------------------------------------- 1 | package hr.documents; 2 | 3 | /* 4 | Common interface used in application when there is 5 | a need for document exports 6 | */ 7 | public interface ExportableDocument { 8 | byte[] toPdf(); 9 | String toJson(); 10 | String toTxt(); 11 | } 12 | -------------------------------------------------------------------------------- /ocp/refactored/GlobomanticsHR/src/main/java/hr/logging/ConsoleLogger.java: -------------------------------------------------------------------------------- 1 | package hr.logging; 2 | 3 | public class ConsoleLogger { 4 | public void writeInfo(String msg) { 5 | System.out.println("Info: " + msg); 6 | } 7 | 8 | public void writeError(String msg, Exception e) { 9 | System.err.println("Error: " + msg + ";" + e); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /ocp/refactored/GlobomanticsHR/src/main/java/hr/main/CalculateTaxesMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.logging.ConsoleLogger; 4 | import hr.persistence.EmployeeFileSerializer; 5 | import hr.persistence.EmployeeRepository; 6 | import hr.personnel.Employee; 7 | import hr.taxes.FullTimeTaxCalculator; 8 | import hr.taxes.TaxCalculator; 9 | import hr.taxes.TaxCalculatorFactory; 10 | 11 | import java.text.NumberFormat; 12 | import java.util.List; 13 | import java.util.Locale; 14 | 15 | public class CalculateTaxesMain { 16 | public static void main(String[] args) { 17 | // Create dependencies 18 | ConsoleLogger consoleLogger = new ConsoleLogger(); 19 | EmployeeFileSerializer employeeFileSerializer = new EmployeeFileSerializer(); 20 | EmployeeRepository repository = new EmployeeRepository(employeeFileSerializer); 21 | 22 | // Grab employees 23 | List employees = repository.findAll(); 24 | 25 | // Calculate taxes 26 | Locale locale = new Locale("en", "US"); 27 | NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(locale); 28 | 29 | double totalTaxes = 0; 30 | for (Employee employee: employees){ 31 | TaxCalculator taxCalculator = TaxCalculatorFactory.create(employee); 32 | 33 | // compute individual tax 34 | double tax = taxCalculator.calculate(employee); 35 | String formattedTax = currencyFormatter.format(tax); 36 | consoleLogger.writeInfo(employee.getFullName() + " taxes: " + formattedTax); 37 | 38 | // add to company total taxes 39 | totalTaxes += taxCalculator.calculate(employee); 40 | } 41 | consoleLogger.writeInfo("Total taxes = " + currencyFormatter.format(totalTaxes)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ocp/refactored/GlobomanticsHR/src/main/java/hr/main/SaveEmployeesMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.logging.ConsoleLogger; 4 | import hr.persistence.EmployeeFileSerializer; 5 | import hr.persistence.EmployeeRepository; 6 | import hr.personnel.Employee; 7 | 8 | import java.io.IOException; 9 | import java.util.List; 10 | 11 | public class SaveEmployeesMain { 12 | public static void main(String[] args) { 13 | // Grab employees 14 | EmployeeFileSerializer employeeFileSerializer = new EmployeeFileSerializer(); 15 | ConsoleLogger consoleLogger = new ConsoleLogger(); 16 | 17 | EmployeeRepository repository = new EmployeeRepository(employeeFileSerializer); 18 | List employees = repository.findAll(); 19 | 20 | // Save all 21 | for (Employee e : employees){ 22 | try { 23 | repository.save(e); 24 | consoleLogger.writeInfo("Saved employee " + e.toString()); 25 | } catch (IOException exception) { 26 | consoleLogger.writeError("Error saving employee", exception); 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ocp/refactored/GlobomanticsHR/src/main/java/hr/persistence/EmployeeFileSerializer.java: -------------------------------------------------------------------------------- 1 | package hr.persistence; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public class EmployeeFileSerializer { 6 | public String serialize(Employee employee) { 7 | StringBuilder sb = new StringBuilder(); 8 | 9 | sb.append("### EMPLOYEE RECORD ####"); 10 | sb.append(System.lineSeparator()); 11 | sb.append("NAME: "); 12 | sb.append(employee.getFullName()); 13 | sb.append(System.lineSeparator()); 14 | sb.append("POSITION: "); 15 | sb.append(employee.getClass().getTypeName()); 16 | sb.append(System.lineSeparator()); 17 | sb.append("EMAIL: "); 18 | sb.append(employee.getEmail()); 19 | sb.append(System.lineSeparator()); 20 | sb.append("MONTHLY WAGE: "); 21 | sb.append(employee.getMonthlyIncome()); 22 | sb.append(System.lineSeparator()); 23 | 24 | return sb.toString(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /ocp/refactored/GlobomanticsHR/src/main/java/hr/personnel/FullTimeEmployee.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class FullTimeEmployee extends Employee { 4 | public FullTimeEmployee(String fullName, int monthlyIncome) { 5 | super(fullName, monthlyIncome); 6 | this.setNbHoursPerWeek(40); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /ocp/refactored/GlobomanticsHR/src/main/java/hr/personnel/Intern.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class Intern extends Employee { 4 | public Intern(String fullName, int monthlyIncome, int nbHours) { 5 | super(fullName, monthlyIncome); 6 | setNbHoursPerWeek(nbHours); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /ocp/refactored/GlobomanticsHR/src/main/java/hr/personnel/PartTimeEmployee.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class PartTimeEmployee extends Employee { 4 | public PartTimeEmployee(String fullName, int monthlyIncome) { 5 | super(fullName, monthlyIncome); 6 | this.setNbHoursPerWeek(20); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /ocp/refactored/GlobomanticsHR/src/main/java/hr/taxes/FullTimeTaxCalculator.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public class FullTimeTaxCalculator implements TaxCalculator { 6 | private final int RETIREMENT_TAX_PERCENTAGE = 10; 7 | private final int INCOME_TAX_PERCENTAGE = 16; 8 | private final int BASE_HEALTH_INSURANCE = 100; 9 | 10 | 11 | public double calculate(Employee employee) { 12 | return BASE_HEALTH_INSURANCE + 13 | (employee.getMonthlyIncome() * RETIREMENT_TAX_PERCENTAGE) / 100 + 14 | (employee.getMonthlyIncome() * INCOME_TAX_PERCENTAGE) / 100; 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ocp/refactored/GlobomanticsHR/src/main/java/hr/taxes/InternTaxCalculator.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public class InternTaxCalculator implements TaxCalculator { 6 | private final int INCOME_TAX_PERCENTAGE = 16; 7 | 8 | public double calculate(Employee employee) { 9 | int monthlyIncome = employee.getMonthlyIncome(); 10 | if (monthlyIncome < 350) { 11 | return 0; 12 | } else { 13 | return (monthlyIncome * INCOME_TAX_PERCENTAGE) / 100; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ocp/refactored/GlobomanticsHR/src/main/java/hr/taxes/PartTimeTaxCalculator.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public class PartTimeTaxCalculator implements TaxCalculator { 6 | private final int RETIREMENT_TAX_PERCENTAGE = 5; 7 | private final int INCOME_TAX_PERCENTAGE = 16; 8 | private final int BASE_HEALTH_INSURANCE = 100; 9 | 10 | public double calculate(Employee employee) { 11 | int monthlyIncome = employee.getMonthlyIncome(); 12 | return BASE_HEALTH_INSURANCE + 13 | (monthlyIncome * RETIREMENT_TAX_PERCENTAGE) / 100 + 14 | (monthlyIncome * INCOME_TAX_PERCENTAGE) / 100; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ocp/refactored/GlobomanticsHR/src/main/java/hr/taxes/TaxCalculator.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public interface TaxCalculator { 6 | double calculate(Employee employee); 7 | } 8 | -------------------------------------------------------------------------------- /ocp/refactored/GlobomanticsHR/src/main/java/hr/taxes/TaxCalculatorFactory.java: -------------------------------------------------------------------------------- 1 | package hr.taxes; 2 | 3 | import hr.personnel.Employee; 4 | import hr.personnel.FullTimeEmployee; 5 | import hr.personnel.Intern; 6 | import hr.personnel.PartTimeEmployee; 7 | 8 | public class TaxCalculatorFactory { 9 | public static TaxCalculator create(Employee employee) { 10 | if (employee instanceof FullTimeEmployee) { 11 | return new FullTimeTaxCalculator(); 12 | } 13 | 14 | if (employee instanceof PartTimeEmployee) { 15 | return new PartTimeTaxCalculator(); 16 | } 17 | 18 | if (employee instanceof Intern) { 19 | return new InternTaxCalculator(); 20 | } 21 | 22 | throw new RuntimeException("Invalid employee type"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /ocp/refactored/GlobomanticsHR/src/main/resources/taxes_business_requirements.txt: -------------------------------------------------------------------------------- 1 | #Business Requirement Document 2 | #Version 1.0 3 | 4 | Taxes for employees are calculated like this: 5 | 6 | - Fixed $100 amount for base health insurance 7 | - 16% income tax 8 | - 10% retirement tax -------------------------------------------------------------------------------- /ocp/refactored/GlobomanticsHR/src/main/resources/taxes_business_requirements_v2.txt: -------------------------------------------------------------------------------- 1 | #Business Requirement Document 2 | #Version 2.0 3 | 4 | Taxes for employees are calculated like this: 5 | 6 | 1) For full time employees 7 | 8 | - Fixed $100 amount for base health insurance 9 | - 16% income tax 10 | - 10% retirement tax 11 | 12 | 2) For part time employees 13 | 14 | - Fixed $100 amount for base health insurance 15 | - 16% income tax 16 | - 5% retirement tax 17 | 18 | 3) For interns 19 | - If income < 350 => no tax due to state aid 20 | - Else => only 16% income tax 21 | -------------------------------------------------------------------------------- /srp/before/GlobomanticsHR/.idea/.name: -------------------------------------------------------------------------------- 1 | hr -------------------------------------------------------------------------------- /srp/before/GlobomanticsHR/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /srp/before/GlobomanticsHR/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /srp/before/GlobomanticsHR/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /srp/before/GlobomanticsHR/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /srp/before/GlobomanticsHR/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /srp/before/GlobomanticsHR/GlobomanticsHR.iml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /srp/before/GlobomanticsHR/hr.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /srp/before/GlobomanticsHR/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | globomantics 8 | hr 9 | 1.0.0 10 | 11 | 12 | 1.8 13 | 1.8 14 | 15 | -------------------------------------------------------------------------------- /srp/before/GlobomanticsHR/src/main/java/hr/documents/ExportableDocument.java: -------------------------------------------------------------------------------- 1 | package hr.documents; 2 | 3 | /* 4 | Common interface used in application when there is 5 | a need for document exports 6 | */ 7 | public interface ExportableDocument { 8 | byte[] toPdf(); 9 | String toJson(); 10 | String toTxt(); 11 | } 12 | -------------------------------------------------------------------------------- /srp/before/GlobomanticsHR/src/main/java/hr/main/SaveEmployeesMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.persistence.EmployeeRepository; 4 | import hr.personnel.Employee; 5 | 6 | import java.util.List; 7 | 8 | public class SaveEmployeesMain { 9 | public static void main(String[] args) { 10 | // Grab employees 11 | EmployeeRepository repository = new EmployeeRepository(); 12 | List employees = repository.findAll(); 13 | 14 | // Save all 15 | for (Employee e : employees){ 16 | Employee.save(e); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /srp/before/GlobomanticsHR/src/main/java/hr/persistence/EmployeeRepository.java: -------------------------------------------------------------------------------- 1 | package hr.persistence; 2 | 3 | import hr.personnel.Employee; 4 | import hr.personnel.FullTimeEmployee; 5 | import hr.personnel.PartTimeEmployee; 6 | 7 | import java.util.Arrays; 8 | import java.util.List; 9 | 10 | /* 11 | Helper method to perform CRUD operations on employees. In a production 12 | application we could use the database for persistence. In this demo, 13 | we are storing employees in the file system. 14 | */ 15 | 16 | public class EmployeeRepository { 17 | 18 | public List findAll(){ 19 | 20 | // Employees are kept in memory for simplicity 21 | Employee anna = new FullTimeEmployee("Anna Smith", 2000); 22 | Employee billy = new FullTimeEmployee("Billy Leech", 920); 23 | 24 | Employee steve = new PartTimeEmployee("Steve Jones", 800); 25 | Employee magda = new PartTimeEmployee("Magda Iovan", 920); 26 | 27 | return Arrays.asList(anna, billy, steve, magda); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /srp/before/GlobomanticsHR/src/main/java/hr/personnel/FullTimeEmployee.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class FullTimeEmployee extends Employee { 4 | public FullTimeEmployee(String fullName, int monthlyIncome) { 5 | super(fullName, monthlyIncome); 6 | this.setNbHoursPerWeek(40); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /srp/before/GlobomanticsHR/src/main/java/hr/personnel/Intern.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class Intern extends Employee { 4 | public Intern(String fullName, int monthlyIncome, int nbHours) { 5 | super(fullName, monthlyIncome); 6 | setNbHoursPerWeek(nbHours); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /srp/before/GlobomanticsHR/src/main/java/hr/personnel/PartTimeEmployee.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class PartTimeEmployee extends Employee { 4 | public PartTimeEmployee(String fullName, int monthlyIncome) { 5 | super(fullName, monthlyIncome); 6 | this.setNbHoursPerWeek(20); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /srp/m3-sourcecode.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dangeabunea/pluralsight-solid-principles-java/745a3f35a6a31fb653fadabc42ec788cafda1ceb/srp/m3-sourcecode.zip -------------------------------------------------------------------------------- /srp/refactored/GlobomanticsHR/.idea/.name: -------------------------------------------------------------------------------- 1 | hr -------------------------------------------------------------------------------- /srp/refactored/GlobomanticsHR/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /srp/refactored/GlobomanticsHR/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /srp/refactored/GlobomanticsHR/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /srp/refactored/GlobomanticsHR/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /srp/refactored/GlobomanticsHR/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /srp/refactored/GlobomanticsHR/Anna_Smith.rec: -------------------------------------------------------------------------------- 1 | ### EMPLOYEE RECORD #### 2 | NAME: Anna Smith 3 | POSITION: hr.personnel.FullTimeEmployee 4 | EMAIL: Anna.Smith@globomanticshr.com 5 | MONTHLY WAGE: 2000 6 | -------------------------------------------------------------------------------- /srp/refactored/GlobomanticsHR/Billy_Leech.rec: -------------------------------------------------------------------------------- 1 | ### EMPLOYEE RECORD #### 2 | NAME: Billy Leech 3 | POSITION: hr.personnel.FullTimeEmployee 4 | EMAIL: Billy.Leech@globomanticshr.com 5 | MONTHLY WAGE: 920 6 | -------------------------------------------------------------------------------- /srp/refactored/GlobomanticsHR/GlobomanticsHR.iml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /srp/refactored/GlobomanticsHR/Magda_Iovan.rec: -------------------------------------------------------------------------------- 1 | ### EMPLOYEE RECORD #### 2 | NAME: Magda Iovan 3 | POSITION: hr.personnel.PartTimeEmployee 4 | EMAIL: Magda.Iovan@globomanticshr.com 5 | MONTHLY WAGE: 920 6 | -------------------------------------------------------------------------------- /srp/refactored/GlobomanticsHR/Steve_Jones.rec: -------------------------------------------------------------------------------- 1 | ### EMPLOYEE RECORD #### 2 | NAME: Steve Jones 3 | POSITION: hr.personnel.PartTimeEmployee 4 | EMAIL: Steve.Jones@globomanticshr.com 5 | MONTHLY WAGE: 800 6 | -------------------------------------------------------------------------------- /srp/refactored/GlobomanticsHR/hr.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /srp/refactored/GlobomanticsHR/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | globomantics 8 | hr 9 | 1.0.0 10 | 11 | 12 | 1.8 13 | 1.8 14 | 15 | -------------------------------------------------------------------------------- /srp/refactored/GlobomanticsHR/src/main/java/hr/documents/ExportableDocument.java: -------------------------------------------------------------------------------- 1 | package hr.documents; 2 | 3 | /* 4 | Common interface used in application when there is 5 | a need for document exports 6 | */ 7 | public interface ExportableDocument { 8 | byte[] toPdf(); 9 | String toJson(); 10 | String toTxt(); 11 | } 12 | -------------------------------------------------------------------------------- /srp/refactored/GlobomanticsHR/src/main/java/hr/logging/ConsoleLogger.java: -------------------------------------------------------------------------------- 1 | package hr.logging; 2 | 3 | public class ConsoleLogger { 4 | public void writeInfo(String msg) { 5 | System.out.println("Info: " + msg); 6 | } 7 | 8 | public void writeError(String msg, Exception e) { 9 | System.err.println("Error: " + msg + ";" + e); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /srp/refactored/GlobomanticsHR/src/main/java/hr/main/SaveEmployeesMain.java: -------------------------------------------------------------------------------- 1 | package hr.main; 2 | 3 | import hr.logging.ConsoleLogger; 4 | import hr.persistence.EmployeeFileSerializer; 5 | import hr.persistence.EmployeeRepository; 6 | import hr.personnel.Employee; 7 | 8 | import java.io.IOException; 9 | import java.util.List; 10 | 11 | public class SaveEmployeesMain { 12 | public static void main(String[] args) { 13 | // Grab employees 14 | EmployeeFileSerializer employeeFileSerializer = new EmployeeFileSerializer(); 15 | ConsoleLogger consoleLogger = new ConsoleLogger(); 16 | 17 | EmployeeRepository repository = new EmployeeRepository(employeeFileSerializer); 18 | List employees = repository.findAll(); 19 | 20 | // Save all 21 | for (Employee e : employees){ 22 | try { 23 | repository.save(e); 24 | consoleLogger.writeInfo("Saved employee " + e.toString()); 25 | } catch (IOException exception) { 26 | consoleLogger.writeError("Error saving employee", exception); 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /srp/refactored/GlobomanticsHR/src/main/java/hr/persistence/EmployeeFileSerializer.java: -------------------------------------------------------------------------------- 1 | package hr.persistence; 2 | 3 | import hr.personnel.Employee; 4 | 5 | public class EmployeeFileSerializer { 6 | public String serialize(Employee employee) { 7 | StringBuilder sb = new StringBuilder(); 8 | 9 | sb.append("### EMPLOYEE RECORD ####"); 10 | sb.append(System.lineSeparator()); 11 | sb.append("NAME: "); 12 | sb.append(employee.getFullName()); 13 | sb.append(System.lineSeparator()); 14 | sb.append("POSITION: "); 15 | sb.append(employee.getClass().getTypeName()); 16 | sb.append(System.lineSeparator()); 17 | sb.append("EMAIL: "); 18 | sb.append(employee.getEmail()); 19 | sb.append(System.lineSeparator()); 20 | sb.append("MONTHLY WAGE: "); 21 | sb.append(employee.getMonthlyIncome()); 22 | sb.append(System.lineSeparator()); 23 | 24 | return sb.toString(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /srp/refactored/GlobomanticsHR/src/main/java/hr/persistence/EmployeeRepository.java: -------------------------------------------------------------------------------- 1 | package hr.persistence; 2 | 3 | import hr.logging.ConsoleLogger; 4 | import hr.personnel.Employee; 5 | import hr.personnel.FullTimeEmployee; 6 | import hr.personnel.PartTimeEmployee; 7 | 8 | import java.io.IOException; 9 | import java.nio.file.Files; 10 | import java.nio.file.Path; 11 | import java.nio.file.Paths; 12 | import java.util.Arrays; 13 | import java.util.List; 14 | 15 | /* 16 | Helper method to perform CRUD operations on employees. In a production 17 | application we could use the database for persistence. In this demo, 18 | we are storing employees in the file system. 19 | */ 20 | 21 | public class EmployeeRepository { 22 | private EmployeeFileSerializer serializer; 23 | 24 | public EmployeeRepository(EmployeeFileSerializer serializer) { 25 | this.serializer = serializer; 26 | } 27 | 28 | public List findAll() { 29 | 30 | // Employees are kept in memory for simplicity 31 | Employee anna = new FullTimeEmployee("Anna Smith", 2000); 32 | Employee billy = new FullTimeEmployee("Billy Leech", 920); 33 | 34 | Employee steve = new PartTimeEmployee("Steve Jones", 800); 35 | Employee magda = new PartTimeEmployee("Magda Iovan", 920); 36 | 37 | return Arrays.asList(anna, billy, steve, magda); 38 | } 39 | 40 | public void save(Employee employee) throws IOException { 41 | String serializedString = this.serializer.serialize(employee); 42 | 43 | Path path = Paths.get(employee.getFullName() 44 | .replace(" ", "_") + ".rec"); 45 | Files.write(path, serializedString.getBytes()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /srp/refactored/GlobomanticsHR/src/main/java/hr/personnel/FullTimeEmployee.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class FullTimeEmployee extends Employee { 4 | public FullTimeEmployee(String fullName, int monthlyIncome) { 5 | super(fullName, monthlyIncome); 6 | this.setNbHoursPerWeek(40); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /srp/refactored/GlobomanticsHR/src/main/java/hr/personnel/Intern.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class Intern extends Employee { 4 | public Intern(String fullName, int monthlyIncome, int nbHours) { 5 | super(fullName, monthlyIncome); 6 | setNbHoursPerWeek(nbHours); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /srp/refactored/GlobomanticsHR/src/main/java/hr/personnel/PartTimeEmployee.java: -------------------------------------------------------------------------------- 1 | package hr.personnel; 2 | 3 | public class PartTimeEmployee extends Employee { 4 | public PartTimeEmployee(String fullName, int monthlyIncome) { 5 | super(fullName, monthlyIncome); 6 | this.setNbHoursPerWeek(20); 7 | } 8 | } 9 | --------------------------------------------------------------------------------