@Override public void delete(@Valid Tenant entity) throws EntityDoesNotExistException { this.dao.deleteEntityAndChildrenById(entity.getId()); }
@Override public Optional<GatewayTenantData> getTenantData(Tenant tenant, String gatewayId) { Key key = new Key(tenant.getId(), gatewayId, "tenant"); if (store.containsKey(key)) { return Optional.of((GatewayTenantData) store.get(key)); } return Optional.absent(); }
@Override public Optional<GatewayTenantData> getTenantData(Tenant tenant, String gatewayId) { GatewayTenantData result = dao.getTenantData(tenant.getId(), gatewayId); if (result == null) { return Optional.absent(); } return Optional.of(result); }
public Map<String, Serializable> getSettingsAsJson(final Tenant tenant) { if (tenant == null) { return Collections.emptyMap(); } try { return configurations.get(tenant.getId(), new Callable<Map<String, Serializable>>() { @Override public Map<String, Serializable> call() { synchronized (lock) { logger.debug("loading cache configuration value for tenant {}", tenant.getSlug()); Map<String, Serializable> tenantConfiguration = tenant.getConfiguration(); Map<String, Serializable> platformConfiguration = getExposedPlatformSettingsAsJson(); ConfigurationJsonMerger merger = new ConfigurationJsonMerger(platformConfiguration, tenantConfiguration); return merger.merge(); } } }); } catch (ExecutionException e) { throw new RuntimeException(e); } }
protected UUID getTenant() { if (this.context.getTenant() != null) { return this.context.getTenant().getId(); } return null; }
protected UUID getTenant() { return this.context.getTenant() != null ? this.context.getTenant().getId() : null; }
@GET @Authorized public Response getStats() { Map<String, Object> stats = Maps.newHashMap(); UUID tenantId = webContext.getTenant() != null ? webContext.getTenant().getId() : null; stats.put("daily", statsDAO.daily(tenantId)); stats.put("weekly", statsDAO.weekly(tenantId)); stats.put("monthly", statsDAO.monthly(tenantId)); stats.put("forever", statsDAO.forever(tenantId)); return Response.ok(stats).build(); }
public void index(final Entity entity, final Tenant tenant) throws SearchEngineException { try { Map<String, Object> source = entityIndexDocumentPurveyor.purveyDocument(entity, tenant); if (source.keySet().size() > 0) { String entityName = StringUtils.substringAfterLast(entity.getClass().getName(), ".").toLowerCase(); this.logger.debug("Indexing {} with id {}...", entityName, entity.getId()); IndexRequestBuilder builder = this.client.prepareIndex("entities", entityName, entity.getId().toString()).setSource(source); if (tenant != null && !Tenant.class.isAssignableFrom(entity.getClass())) { builder.setParent(tenant.getId().toString()); } IndexResponse response = builder.execute().actionGet(); this.logger.debug("" + response.getType()); } } catch (Exception e) { throw new SearchEngineException("Failed to index entity", e); } }
public Map<String, Object> purveyDocument(Tenant tenant) { Preconditions.checkNotNull(tenant); this.dao = this.dbi.get().onDemand(CollectionDAO.class); Map<String, Object> extracted = extractSourceFromEntity(tenant, tenant); List<Collection> collections = dao.findAll("collection", tenant.getId()); List<Map<String, Object>> collectionsSource = Lists.newArrayList(); for (Collection collection : collections) { Map<String, Object> collectionSource = extractSourceFromEntity(collection, tenant); collectionSource .put("api_url", urlHelper.getContextPlatformURL("/marketplace/api/shop/" + tenant.getSlug() + "/collections/" + collection.getSlug()).toString()); collectionsSource.add(collectionSource); } extracted.put("collections", collectionsSource); return extracted; } }
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) }
@Override public void update(Tenant tenant) throws InvalidEntityException, EntityDoesNotExistException { this.dao.begin(); Tenant originalProduct = this.findBySlug(tenant.getSlug()); if (originalProduct == null) { this.dao.commit(); throw new EntityDoesNotExistException(); } tenant.setId(originalProduct.getId()); Integer updatedRows = this.dao.update(tenant); this.dao.createOrUpdateAddons(tenant); this.dao.commit(); if (updatedRows <= 0) { throw new StoreException("No rows was updated when updating tenant"); } }