Search in sources :

Example 1 with UpdateHelper

use of org.craftercms.commons.mongo.UpdateHelper 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 2 with UpdateHelper

use of org.craftercms.commons.mongo.UpdateHelper in project profile by craftercms.

the class ProfileServiceImpl method updateProfile.

protected Profile updateProfile(String profileId, UpdateCallback callback, String... attributesToReturn) throws ProfileException {
    // We need to filter the attributes after save, if not, the attributes to return will replace all the
    // attributes
    Profile profile = getNonNullProfile(profileId);
    UpdateHelper updateHelper = new UpdateHelper();
    ProfileUpdater profileUpdater = new ProfileUpdater(profile, updateHelper, profileRepository);
    callback.doWithProfile(profileUpdater);
    profileUpdater.setLastModified(new Date());
    try {
        profileUpdater.update();
    } catch (MongoDataException e) {
        throw new I10nProfileException(ERROR_KEY_UPDATE_PROFILE_ERROR, e, profileId);
    }
    return filterAttributes(profile, attributesToReturn);
}
Also used : UpdateHelper(org.craftercms.commons.mongo.UpdateHelper) ProfileUpdater(org.craftercms.profile.utils.db.ProfileUpdater) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) Profile(org.craftercms.profile.api.Profile) Date(java.util.Date)

Aggregations

MongoDataException (org.craftercms.commons.mongo.MongoDataException)2 UpdateHelper (org.craftercms.commons.mongo.UpdateHelper)2 I10nProfileException (org.craftercms.profile.api.exceptions.I10nProfileException)2 Date (java.util.Date)1 Profile (org.craftercms.profile.api.Profile)1 Tenant (org.craftercms.profile.api.Tenant)1 NoSuchTenantException (org.craftercms.profile.exceptions.NoSuchTenantException)1 ProfileUpdater (org.craftercms.profile.utils.db.ProfileUpdater)1 TenantUpdater (org.craftercms.profile.utils.db.TenantUpdater)1