public Tenant() { this.configuration = new TenantConfiguration(); }
@Override public void updateConfiguration(TenantConfiguration configuration) { try { this.dao.updateConfiguration(getTenant(), configuration.getVersion(), convertConfigurationToJSON(configuration)); } catch (JsonProcessingException e) { throw new RuntimeException("", e); } }
public void updateSettings(String module, Map<String, Serializable> configuration) throws NoSuchModuleException { if (!this.exposedSettings.containsKey(module)) { throw new NoSuchModuleException(); } Tenant tenant = this.context.getTenant(); TenantConfiguration currentConfiguration = tenant.getConfiguration(); Map<String, Serializable> data = Maps.newHashMap(currentConfiguration.getData()); data.put(module, Maps.newHashMap(configuration)); this.updateSettings(data); }
@Override public Tenant create(Tenant tenant) throws EntityAlreadyExistsException, InvalidEntityException { if (this.dao.findBySlug(TENANT_TABLE_NAME, tenant.getSlug()) != null) { throw new EntityAlreadyExistsException(); } this.dao.begin(); TenantConfiguration configuration = tenant.getConfiguration(); try { String configurationAsJson = convertConfigurationToJSON(configuration); UUID id = UUID.randomUUID(); tenant.setId(id); this.dao.createEntity(tenant, TENANT_TABLE_NAME); this.dao.create(tenant, configuration.getVersion(), configurationAsJson); this.dao.createOrUpdateAddons(tenant); return tenant; } catch (JsonProcessingException e) { throw new RuntimeException("Failed to create tenant", e); } finally { this.dao.commit(); } }
TenantConfiguration configuration; if (Strings.isNullOrEmpty(result.getString("configuration"))) { configuration = new TenantConfiguration(configurationVersion, Collections.<String, Serializable>emptyMap()); } else { try { Map<String, Serializable> data = mapper.readValue(result.getString("configuration"), new TypeReference<Map<String, Object>>() {}); configuration = new TenantConfiguration(configurationVersion, data); } catch (IOException e) { final Logger logger = LoggerFactory.getLogger(TenantMapper.class); logger.error("Failed to load configuration for tenant with slug [{}]", e); configuration = new TenantConfiguration();
TenantConfiguration configuration; if (Strings.isNullOrEmpty(result.getString("tenant_entity_configuration"))) { configuration = new TenantConfiguration(configurationVersion, Collections.<String, Serializable>emptyMap()); } else { try { Map<String, Serializable> data = mapper.readValue(result.getString("tenant_entity_configuration"), new TypeReference<Map<String, Object>>(){}); configuration = new TenantConfiguration(configurationVersion, data); } catch (IOException e) { final Logger logger = LoggerFactory.getLogger(TenantMapper.class); logger.error("Failed to load configuration for tenant with slug [{}]", e); configuration = new TenantConfiguration();
@Override public Tenant createDefaultTenant() throws EntityAlreadyExistsException { if (this.tenantStore.get().findAll(1, 0).size() != 0) { throw new EntityAlreadyExistsException("Cannot create default tenant : a tenant already exists"); } String slug = multitenancySettings.getDefaultTenantSlug(); TenantConfiguration configuration = new TenantConfiguration(); Tenant tenant = new Tenant(slug, configuration); try { this.tenantStore.get().create(tenant); } catch (InvalidEntityException e) { } return this.tenantStore.get().findBySlug(slug); }
public void updateSettings(Map<String, Serializable> data) { ValidConfigurationEnforcer enforcer = new ValidConfigurationEnforcer(getExposedPlatformSettingsAsJson(), data); ValidConfigurationEnforcer.ValidationResult result = enforcer.enforce(); TenantConfiguration configuration = new TenantConfiguration(TenantConfiguration.CURRENT_VERSION, result.getResult()); this.tenantStore.get().updateConfiguration(configuration); // Invalidates the cached configuration for the tenant updating its configuration // TODO: do this from the configuration store instead this.configurations.invalidate(this.context.getTenant().getId()); // TODO throw an exception here when there are validation errors, so that it can be acknowledged to the // REST accounts consumer ? (meaning the operation has been partially successful only) }