-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a736f7
commit bc89295
Showing
12 changed files
with
318 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 32 additions & 2 deletions
34
...croservice-hexagonal/src/main/java/com/example/hr/HrMicroserviceHexagonalApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,48 @@ | ||
package com.example.hr; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.ApplicationArguments; | ||
import org.springframework.boot.ApplicationRunner; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
import com.example.hr.adapter.EmployeeRepositoryMongoAdapter; | ||
import com.example.hr.document.EmployeeDocument; | ||
import com.example.hr.domain.Department; | ||
import com.example.hr.domain.Employee; | ||
import com.example.hr.domain.MoneyCurrency; | ||
import com.example.hr.repository.EmployeeMongoRepository; | ||
|
||
/** | ||
* | ||
* @author Binnur Kurt <binnur.kurt@gmail.com> | ||
* | ||
*/ | ||
@SpringBootApplication | ||
public class HrMicroserviceHexagonalApplication { | ||
|
||
public class HrMicroserviceHexagonalApplication implements ApplicationRunner { | ||
@Autowired private EmployeeRepositoryMongoAdapter mongoAdapter; | ||
@Autowired private EmployeeMongoRepository mongoRepo; | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(HrMicroserviceHexagonalApplication.class, args); | ||
} | ||
|
||
@Override | ||
public void run(ApplicationArguments args) throws Exception { | ||
/* | ||
Employee jack = new Employee.Builder("40310900232").fullname("jack", "bauer").birthYear(1956) | ||
.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BWgIVe/qBBwlMJgrcRfcHmhZ8CLEb2xtt+WsOriCNSTYd+BD51BeTGwP/5iKJ/wL+zNdRU9COwQVGUwN7uQ4NoOvLVmFxqUo+dkPpqTBjrRGow/53H1Wi6bzG8/2PK63rcOX+I/fmSLYDhDwbendMvcsIBuRMDlD6sfUztppKvMgUMnf/Mv8NIVU+cyYl6AAAAAElFTkSuQmCC" | ||
.getBytes()) | ||
.build(); | ||
mongoAdapter.save(jack); | ||
*/ | ||
List<EmployeeDocument> employees = mongoRepo.findAllByBirthYearBetweenAndDepartment(1950, 1960,Department.IT); | ||
System.err.println(employees); | ||
employees.forEach(System.out::println); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...ervice-hexagonal/src/main/java/com/example/hr/adapter/EmployeeRepositoryMongoAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.example.hr.adapter; | ||
|
||
import java.util.Optional; | ||
|
||
import org.modelmapper.ModelMapper; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import com.example.hr.document.EmployeeDocument; | ||
import com.example.hr.domain.Employee; | ||
import com.example.hr.domain.FullName; | ||
import com.example.hr.domain.TcKimlikNo; | ||
import com.example.hr.meta.Persistence; | ||
import com.example.hr.meta.PersistenceTarget; | ||
import com.example.hr.repository.EmployeeMongoRepository; | ||
import com.example.hr.repository.EmployeeRepository; | ||
|
||
@Repository | ||
@Persistence(PersistenceTarget.MONGO) | ||
public class EmployeeRepositoryMongoAdapter implements EmployeeRepository{ | ||
@Autowired | ||
private EmployeeMongoRepository empRepo; | ||
@Autowired | ||
private ModelMapper mapper; | ||
|
||
@Override | ||
public Optional<Employee> findByIdentity(TcKimlikNo identity) { | ||
Optional<EmployeeDocument> empDoc = empRepo.findById(identity.getValue()); | ||
if (!empDoc.isEmpty()) return Optional.empty(); | ||
Employee employee = mapper.map(empDoc.get(), Employee.class); | ||
return Optional.of(employee); | ||
} | ||
|
||
@Override | ||
public void save(Employee employee) { | ||
//EmployeeDocument empDoc= mapper.map(employee, EmployeeDocument.class); | ||
EmployeeDocument employeeDocument = new EmployeeDocument(); | ||
employeeDocument.setIdentity(employee.getIdentityNo().getValue()); | ||
FullName fullname = employee.getFullname(); | ||
employeeDocument.setFullname(fullname.getFirst() + " " + fullname.getLast()); | ||
employeeDocument.setSalary(employee.getSalary().getValue()); | ||
employeeDocument.setIban(employee.getIban().getValue()); | ||
employeeDocument.setPhoto(new String(employee.getPhoto().getValue())); | ||
employeeDocument.setBirthYear(employee.getBirthYear().getValue()); | ||
employeeDocument.setDepartment(employee.getDepartment()); | ||
employeeDocument.setFulltime(employee.isFulltime()); | ||
empRepo.save(employeeDocument); | ||
} | ||
|
||
@Override | ||
public void remove(Employee employee) { | ||
empRepo.deleteById(employee.getIdentityNo().getValue()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
hr-microservice-hexagonal/src/main/java/com/example/hr/document/EmployeeDocument.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
package com.example.hr.document; | ||
|
||
import javax.validation.constraints.Max; | ||
import javax.validation.constraints.Min; | ||
import javax.validation.constraints.Size; | ||
|
||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.mongodb.core.mapping.Document; | ||
|
||
import com.example.hr.domain.Department; | ||
import com.example.validation.Iban; | ||
import com.example.validation.TcKimlikNo; | ||
|
||
@Document(collection = "employees") | ||
public class EmployeeDocument { | ||
@TcKimlikNo | ||
@Id | ||
private String identity; | ||
@Size(min = 5) | ||
private String fullname; | ||
@Min(3_000) | ||
private Double salary; | ||
@Iban | ||
private String iban; | ||
private Boolean fulltime; | ||
@Max(2002) | ||
private int birthYear; | ||
private String photo; | ||
private Department department; | ||
|
||
public EmployeeDocument() { | ||
} | ||
|
||
public EmployeeDocument(String identity, @Size(min = 5) String fullname, @Min(3000) Double salary, String iban, | ||
Boolean fulltime, @Max(2002) int birthYear, Department department) { | ||
this.identity = identity; | ||
this.fullname = fullname; | ||
this.salary = salary; | ||
this.iban = iban; | ||
this.fulltime = fulltime; | ||
this.birthYear = birthYear; | ||
this.department = department; | ||
} | ||
|
||
public String getIdentity() { | ||
return identity; | ||
} | ||
|
||
public void setIdentity(String identity) { | ||
this.identity = identity; | ||
} | ||
|
||
public String getFullname() { | ||
return fullname; | ||
} | ||
|
||
public void setFullname(String fullname) { | ||
this.fullname = fullname; | ||
} | ||
|
||
public Double getSalary() { | ||
return salary; | ||
} | ||
|
||
public void setSalary(Double salary) { | ||
this.salary = salary; | ||
} | ||
|
||
public String getIban() { | ||
return iban; | ||
} | ||
|
||
public void setIban(String iban) { | ||
this.iban = iban; | ||
} | ||
|
||
public Boolean getFulltime() { | ||
return fulltime; | ||
} | ||
|
||
public void setFulltime(Boolean fulltime) { | ||
this.fulltime = fulltime; | ||
} | ||
|
||
public int getBirthYear() { | ||
return birthYear; | ||
} | ||
|
||
public void setBirthYear(int birthYear) { | ||
this.birthYear = birthYear; | ||
} | ||
|
||
public String getPhoto() { | ||
return photo; | ||
} | ||
|
||
public void setPhoto(String photo) { | ||
this.photo = photo; | ||
} | ||
|
||
public Department getDepartment() { | ||
return department; | ||
} | ||
|
||
public void setDepartment(Department department) { | ||
this.department = department; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
final int prime = 31; | ||
int result = 1; | ||
result = prime * result + ((identity == null) ? 0 : identity.hashCode()); | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) | ||
return true; | ||
if (obj == null) | ||
return false; | ||
if (getClass() != obj.getClass()) | ||
return false; | ||
EmployeeDocument other = (EmployeeDocument) obj; | ||
if (identity == null) { | ||
if (other.identity != null) | ||
return false; | ||
} else if (!identity.equals(other.identity)) | ||
return false; | ||
return true; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "EmployeeDocument [identity=" + identity + ", fullname=" + fullname + ", salary=" + salary + ", iban=" | ||
+ iban + ", fulltime=" + fulltime + ", birthYear=" + birthYear + ", department=" + department + "]"; | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
hr-microservice-hexagonal/src/main/java/com/example/hr/meta/Persistence.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.example.hr.meta; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import org.springframework.beans.factory.annotation.Qualifier; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.TYPE, ElementType.PARAMETER, ElementType.FIELD}) | ||
@Qualifier | ||
public @interface Persistence { | ||
PersistenceTarget value() ; | ||
} |
5 changes: 5 additions & 0 deletions
5
hr-microservice-hexagonal/src/main/java/com/example/hr/meta/PersistenceTarget.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.example.hr.meta; | ||
|
||
public enum PersistenceTarget { | ||
JPA_MYSQL, MONGO, CASSANDRA, REDIS, ELASTIC_SEARCH | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.