-
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.
Signed-off-by: Thomas Vitale <[email protected]>
- Loading branch information
1 parent
e6f4682
commit fdf878e
Showing
15 changed files
with
426 additions
and
15 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
arconia-core/src/main/java/io/arconia/core/multitenancy/tenantdetails/Tenant.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,81 @@ | ||
package io.arconia.core.multitenancy.tenantdetails; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.springframework.util.Assert; | ||
|
||
/** | ||
* Default implementation to hold tenant details. | ||
*/ | ||
public class Tenant implements TenantDetails { | ||
|
||
private final String identifier; | ||
|
||
private final boolean enabled; | ||
|
||
private final Map<String, Object> attributes; | ||
|
||
public Tenant(String identifier, boolean enabled, Map<String, Object> attributes) { | ||
Assert.hasText(identifier, "identifier cannot be null or empty"); | ||
Assert.notNull(attributes, "attributes cannot be null"); | ||
|
||
this.identifier = identifier; | ||
this.enabled = enabled; | ||
this.attributes = attributes; | ||
} | ||
|
||
@Override | ||
public String getIdentifier() { | ||
return identifier; | ||
} | ||
|
||
@Override | ||
public boolean isEnabled() { | ||
return enabled; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> getAttributes() { | ||
return attributes; | ||
} | ||
|
||
public static Builder create() { | ||
return new Builder(); | ||
} | ||
|
||
public static class Builder { | ||
|
||
private String identifier; | ||
|
||
private boolean enabled; | ||
|
||
private Map<String, Object> attributes = new HashMap<>(); | ||
|
||
public Builder identifier(String identifier) { | ||
this.identifier = identifier; | ||
return this; | ||
} | ||
|
||
public Builder enabled(boolean enabled) { | ||
this.enabled = enabled; | ||
return this; | ||
} | ||
|
||
public Builder attributes(Map<String, Object> attributes) { | ||
this.attributes = attributes; | ||
return this; | ||
} | ||
|
||
public Builder addAttribute(String key, Object value) { | ||
attributes.put(key, value); | ||
return this; | ||
} | ||
|
||
public Tenant build() { | ||
return new Tenant(identifier, enabled, attributes); | ||
} | ||
|
||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
arconia-core/src/main/java/io/arconia/core/multitenancy/tenantdetails/TenantDetails.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,28 @@ | ||
package io.arconia.core.multitenancy.tenantdetails; | ||
|
||
import java.io.Serializable; | ||
import java.util.Map; | ||
|
||
/** | ||
* Provides core tenant information. | ||
*/ | ||
public interface TenantDetails extends Serializable { | ||
|
||
/** | ||
* Identifier for the tenant. | ||
*/ | ||
String getIdentifier(); | ||
|
||
/** | ||
* Whether the tenant is enabled. | ||
*/ | ||
boolean isEnabled(); | ||
|
||
/** | ||
* Additional information about the tenant. | ||
*/ | ||
default Map<String, Object> getAttributes() { | ||
return Map.of(); | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
...a-core/src/main/java/io/arconia/core/multitenancy/tenantdetails/TenantDetailsService.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,17 @@ | ||
package io.arconia.core.multitenancy.tenantdetails; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.lang.Nullable; | ||
|
||
/** | ||
* Loads tenant-specific data. It is used throughout the framework as a tenant DAO. | ||
*/ | ||
public interface TenantDetailsService { | ||
|
||
List<? extends TenantDetails> loadAllTenants(); | ||
|
||
@Nullable | ||
TenantDetails loadTenantByIdentifier(String identifier); | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
arconia-core/src/main/java/io/arconia/core/multitenancy/tenantdetails/package-info.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 @@ | ||
@NonNullApi | ||
@NonNullFields | ||
package io.arconia.core.multitenancy.tenantdetails; | ||
|
||
import org.springframework.lang.NonNullApi; | ||
import org.springframework.lang.NonNullFields; |
31 changes: 31 additions & 0 deletions
31
arconia-core/src/test/java/io/arconia/core/multitenancy/tenantdetails/TenantTests.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,31 @@ | ||
package io.arconia.core.multitenancy.tenantdetails; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
/** | ||
* Unit tests for {@link Tenant}. | ||
*/ | ||
class TenantTests { | ||
|
||
@Test | ||
void whenIdentifierIsNullThenThrow() { | ||
assertThatThrownBy(() -> Tenant.create().build()).isInstanceOf(IllegalArgumentException.class) | ||
.hasMessageContaining("identifier cannot be null or empty"); | ||
} | ||
|
||
@Test | ||
void whenIdentifierIsEmptyThenThrow() { | ||
assertThatThrownBy(() -> Tenant.create().identifier("").build()).isInstanceOf(IllegalArgumentException.class) | ||
.hasMessageContaining("identifier cannot be null or empty"); | ||
} | ||
|
||
@Test | ||
void whenAttributesIsNullThenThrow() { | ||
assertThatThrownBy(() -> Tenant.create().identifier("acme").attributes(null).build()) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessageContaining("attributes cannot be null"); | ||
} | ||
|
||
} |
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
39 changes: 39 additions & 0 deletions
39
...arconia/autoconfigure/multitenancy/core/tenantdetails/PropertiesTenantDetailsService.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,39 @@ | ||
package io.arconia.autoconfigure.multitenancy.core.tenantdetails; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.lang.Nullable; | ||
import org.springframework.util.Assert; | ||
|
||
import io.arconia.core.multitenancy.tenantdetails.TenantDetails; | ||
import io.arconia.core.multitenancy.tenantdetails.TenantDetailsService; | ||
|
||
/** | ||
* An implementation of {@link TenantDetailsService} that uses application properties as | ||
* the source for the tenant details. | ||
*/ | ||
public class PropertiesTenantDetailsService implements TenantDetailsService { | ||
|
||
private final TenantDetailsProperties tenantDetailsProperties; | ||
|
||
public PropertiesTenantDetailsService(TenantDetailsProperties tenantDetailsProperties) { | ||
this.tenantDetailsProperties = tenantDetailsProperties; | ||
} | ||
|
||
@Override | ||
public List<? extends TenantDetails> loadAllTenants() { | ||
return tenantDetailsProperties.getTenants(); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public TenantDetails loadTenantByIdentifier(String identifier) { | ||
Assert.hasText(identifier, "identifier cannot be null or empty"); | ||
return tenantDetailsProperties.getTenants() | ||
.stream() | ||
.filter(tenant -> tenant.getIdentifier().equals(identifier)) | ||
.findFirst() | ||
.orElse(null); | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
...ava/io/arconia/autoconfigure/multitenancy/core/tenantdetails/TenantDetailsProperties.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,50 @@ | ||
package io.arconia.autoconfigure.multitenancy.core.tenantdetails; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
import io.arconia.core.multitenancy.tenantdetails.Tenant; | ||
|
||
/** | ||
* Configuration properties for tenant details. | ||
*/ | ||
@ConfigurationProperties(prefix = TenantDetailsProperties.CONFIG_PREFIX) | ||
public class TenantDetailsProperties { | ||
|
||
public static final String CONFIG_PREFIX = "arconia.multitenancy.details"; | ||
|
||
/** | ||
* The source of tenant details. | ||
*/ | ||
private Source source = Source.PROPERTIES; | ||
|
||
/** | ||
* List of tenant details. | ||
*/ | ||
private List<Tenant> tenants = new ArrayList<>(); | ||
|
||
public Source getSource() { | ||
return source; | ||
} | ||
|
||
public void setSource(Source source) { | ||
this.source = source; | ||
} | ||
|
||
public List<Tenant> getTenants() { | ||
return tenants; | ||
} | ||
|
||
public void setTenants(List<Tenant> tenants) { | ||
this.tenants = tenants; | ||
} | ||
|
||
public enum Source { | ||
|
||
HTTP, JDBC, PROPERTIES | ||
|
||
} | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
.../src/main/java/io/arconia/autoconfigure/multitenancy/core/tenantdetails/package-info.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 @@ | ||
@NonNullApi | ||
@NonNullFields | ||
package io.arconia.autoconfigure.multitenancy.core.tenantdetails; | ||
|
||
import org.springframework.lang.NonNullApi; | ||
import org.springframework.lang.NonNullFields; |
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
4 changes: 4 additions & 0 deletions
4
...t-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json
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
Oops, something went wrong.