-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes #426 Here are some things you should have thought about: **Multi-Tenancy** - [ ] Extended new entities with `AbstractTenantAwareEntity`? - [ ] New entity added to `TenantAwareDatabaseConfiguration`? - [x] Extended new entities with `AdminAware`? - [x] New entity added to `AdminAwareDatabaseConfiguration`? - [ ] Tested with `dev-multitenant` profile? <!-- Thanks for contributing to the zeiterfassung. Please review the following notes before submitting you pull request. Please look for other issues or pull requests which already work on this topic. Is somebody already on it? Do you need to synchronize? # Security Vulnerabilities 🛑 STOP! 🛑 If your contribution fixes a security vulnerability, please do not submit it. Instead, please write an E-Mail to [email protected] with all the information to recreate the security vulnerability. # Describing Your Changes If, having reviewed the notes above, you're ready to submit your pull request, please provide a brief description of the proposed changes. If they: 🐞 fix a bug, please describe the broken behaviour and how the changes fix it. Please label with 'type: bug' and 'status: new' 🎁 make an enhancement, please describe the new functionality and why you believe it's useful. Please label with 'type: enhancement' and 'status: new' If your pull request relates to any existing issues, please reference them by using the issue number prefixed with #. -->
- Loading branch information
Showing
28 changed files
with
912 additions
and
100 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
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
43 changes: 43 additions & 0 deletions
43
src/main/java/de/focusshift/zeiterfassung/absence/AbsenceTypeEntityEmbeddable.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,43 @@ | ||
package de.focusshift.zeiterfassung.absence; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embeddable; | ||
import jakarta.persistence.Enumerated; | ||
|
||
import static jakarta.persistence.EnumType.STRING; | ||
|
||
@Embeddable | ||
public class AbsenceTypeEntityEmbeddable { | ||
|
||
@Column(name = "type_category", nullable = false) | ||
@Enumerated(STRING) | ||
private AbsenceTypeCategory category; | ||
|
||
@Column(name = "type_source_id") | ||
private Long sourceId; | ||
|
||
public AbsenceTypeEntityEmbeddable(AbsenceTypeCategory category, Long sourceId) { | ||
this.category = category; | ||
this.sourceId = sourceId; | ||
} | ||
|
||
public AbsenceTypeEntityEmbeddable() { | ||
// for @Embeddable | ||
} | ||
|
||
public AbsenceTypeCategory getCategory() { | ||
return category; | ||
} | ||
|
||
public void setCategory(AbsenceTypeCategory category) { | ||
this.category = category; | ||
} | ||
|
||
public Long getSourceId() { | ||
return sourceId; | ||
} | ||
|
||
public void setSourceId(Long sourceId) { | ||
this.sourceId = sourceId; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/de/focusshift/zeiterfassung/absence/AbsenceTypeRepository.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,10 @@ | ||
package de.focusshift.zeiterfassung.absence; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Optional; | ||
|
||
interface AbsenceTypeRepository extends JpaRepository<AbsenceTypeEntity, Long> { | ||
|
||
Optional<AbsenceTypeEntity> findByTenantIdAndSourceId(String tenantId, Long sourceId); | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/de/focusshift/zeiterfassung/absence/AbsenceTypeService.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,6 @@ | ||
package de.focusshift.zeiterfassung.absence; | ||
|
||
public interface AbsenceTypeService { | ||
|
||
void updateAbsenceType(AbsenceTypeUpdate absenceTypeUpdate); | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/de/focusshift/zeiterfassung/absence/AbsenceTypeServiceImpl.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,33 @@ | ||
package de.focusshift.zeiterfassung.absence; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.HashMap; | ||
|
||
@Service | ||
class AbsenceTypeServiceImpl implements AbsenceTypeService { | ||
|
||
private final AbsenceTypeRepository repository; | ||
|
||
AbsenceTypeServiceImpl(AbsenceTypeRepository repository) { | ||
this.repository = repository; | ||
} | ||
|
||
@Override | ||
public void updateAbsenceType(AbsenceTypeUpdate absenceTypeUpdate) { | ||
|
||
final String tenantId = absenceTypeUpdate.tenantId().tenantId(); | ||
final Long sourceId = absenceTypeUpdate.sourceId(); | ||
|
||
final AbsenceTypeEntity entity = repository.findByTenantIdAndSourceId(tenantId, sourceId) | ||
.orElseGet(AbsenceTypeEntity::new); | ||
|
||
entity.setTenantId(tenantId); | ||
entity.setSourceId(sourceId); | ||
entity.setCategory(absenceTypeUpdate.category()); | ||
entity.setColor(absenceTypeUpdate.color()); | ||
entity.setLabelByLocale(new HashMap<>(absenceTypeUpdate.labelByLocale())); | ||
|
||
repository.save(entity); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/de/focusshift/zeiterfassung/absence/AbsenceTypeUpdate.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,24 @@ | ||
package de.focusshift.zeiterfassung.absence; | ||
|
||
import de.focusshift.zeiterfassung.tenancy.tenant.TenantId; | ||
|
||
import java.util.Locale; | ||
import java.util.Map; | ||
|
||
/** | ||
* Update {@linkplain AbsenceType} to the given values. | ||
* | ||
* @param tenantId {@linkplain TenantId} this {@linkplain AbsenceType} is linked to | ||
* @param sourceId external system source identifier of the absence type | ||
* @param category next {@linkplain AbsenceTypeCategory} | ||
* @param color next {@linkplain AbsenceColor} | ||
* @param labelByLocale next labels | ||
*/ | ||
public record AbsenceTypeUpdate( | ||
TenantId tenantId, | ||
Long sourceId, | ||
AbsenceTypeCategory category, | ||
AbsenceColor color, | ||
Map<Locale, String> labelByLocale | ||
) { | ||
} |
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
44 changes: 44 additions & 0 deletions
44
src/main/java/de/focusshift/zeiterfassung/absence/LabelByLocaleConverter.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,44 @@ | ||
package de.focusshift.zeiterfassung.absence; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import jakarta.persistence.AttributeConverter; | ||
import jakarta.persistence.Converter; | ||
import org.slf4j.Logger; | ||
|
||
import java.io.IOException; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
|
||
import static java.lang.invoke.MethodHandles.lookup; | ||
import static org.slf4j.LoggerFactory.getLogger; | ||
|
||
@Converter | ||
public final class LabelByLocaleConverter implements AttributeConverter<Map<Locale, String>, String> { | ||
|
||
private static final Logger LOG = getLogger(lookup().lookupClass()); | ||
|
||
private static final ObjectMapper om = new ObjectMapper(); | ||
|
||
@Override | ||
public String convertToDatabaseColumn(Map<Locale, String> attribute) { | ||
try { | ||
return om.writeValueAsString(attribute); | ||
} catch (JsonProcessingException ex) { | ||
LOG.error("could not write value as string", ex); | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public Map<Locale, String> convertToEntityAttribute(String dbData) { | ||
try { | ||
return om.readValue(dbData, new TypeReference<>() { | ||
}); | ||
} catch (IOException ex) { | ||
LOG.error("could not convert to entity attribute", ex); | ||
return Map.of(); | ||
} | ||
} | ||
} |
Oops, something went wrong.