Search in sources :

Example 6 with TenantUpdater

use of org.craftercms.profile.utils.db.TenantUpdater in project profile by craftercms.

the class TenantServiceImpl method updateTenant.

protected Tenant updateTenant(String tenantName, UpdateCallback callback) throws ProfileException {
    Tenant tenant = getTenant(tenantName);
    if (tenant != null) {
        checkIfTenantActionIsAllowed(tenantName, TenantAction.UPDATE_TENANT);
        UpdateHelper updateHelper = new UpdateHelper();
        TenantUpdater tenantUpdater = new TenantUpdater(tenant, updateHelper, tenantRepository);
        callback.doWithTenant(tenantUpdater);
        try {
            tenantUpdater.update();
        } catch (MongoDataException e) {
            throw new I10nProfileException(ERROR_KEY_UPDATE_TENANT_ERROR, e, tenant.getName());
        }
    } else {
        throw new NoSuchTenantException(tenantName);
    }
    return tenant;
}
Also used : NoSuchTenantException(org.craftercms.profile.exceptions.NoSuchTenantException) UpdateHelper(org.craftercms.commons.mongo.UpdateHelper) Tenant(org.craftercms.profile.api.Tenant) TenantUpdater(org.craftercms.profile.utils.db.TenantUpdater) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException)

Example 7 with TenantUpdater

use of org.craftercms.profile.utils.db.TenantUpdater in project profile by craftercms.

the class TenantServiceImpl method removeAttributeDefinitions.

@Override
public Tenant removeAttributeDefinitions(final String tenantName, final Collection<String> attributeNames) throws ProfileException {
    for (String attributeName : attributeNames) {
        removeAttributeFromProfiles(tenantName, attributeName);
    }
    Tenant tenant = updateTenant(tenantName, new UpdateCallback() {

        @Override
        public void doWithTenant(TenantUpdater tenantUpdater) throws ProfileException {
            tenantUpdater.removeAttributeDefinitions(attributeNames);
        }
    });
    logger.debug(LOG_KEY_ATTRIBUTE_DEFINITIONS_REMOVED, attributeNames, tenantName);
    return tenant;
}
Also used : Tenant(org.craftercms.profile.api.Tenant) TenantUpdater(org.craftercms.profile.utils.db.TenantUpdater) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) ProfileException(org.craftercms.profile.api.exceptions.ProfileException)

Example 8 with TenantUpdater

use of org.craftercms.profile.utils.db.TenantUpdater in project profile by craftercms.

the class TenantServiceImpl method updateAttributeDefinitions.

@Override
public Tenant updateAttributeDefinitions(final String tenantName, final Collection<AttributeDefinition> attributeDefinitions) throws ProfileException {
    Tenant tenant = updateTenant(tenantName, new UpdateCallback() {

        @Override
        public void doWithTenant(TenantUpdater tenantUpdater) throws ProfileException {
            tenantUpdater.updateAttributeDefinitions(attributeDefinitions);
        }
    });
    logger.debug(LOG_KEY_ATTRIBUTE_DEFINITIONS_UPDATED, attributeDefinitions, tenantName);
    return tenant;
}
Also used : Tenant(org.craftercms.profile.api.Tenant) TenantUpdater(org.craftercms.profile.utils.db.TenantUpdater) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) ProfileException(org.craftercms.profile.api.exceptions.ProfileException)

Aggregations

Tenant (org.craftercms.profile.api.Tenant)8 I10nProfileException (org.craftercms.profile.api.exceptions.I10nProfileException)8 TenantUpdater (org.craftercms.profile.utils.db.TenantUpdater)8 ProfileException (org.craftercms.profile.api.exceptions.ProfileException)7 AttributeDefinition (org.craftercms.profile.api.AttributeDefinition)2 Collection (java.util.Collection)1 MongoDataException (org.craftercms.commons.mongo.MongoDataException)1 UpdateHelper (org.craftercms.commons.mongo.UpdateHelper)1 NoSuchTenantException (org.craftercms.profile.exceptions.NoSuchTenantException)1