Search in sources :

Example 11 with AttributeDefinition

use of org.craftercms.profile.api.AttributeDefinition in project profile by craftercms.

the class TenantUpdater method addAttributeDefinitions.

public void addAttributeDefinitions(Collection<AttributeDefinition> attributeDefinitions) {
    List<AttributeDefinition> allDefinitions = tenant.getAttributeDefinitions();
    List<AttributeDefinition> pushValues = new ArrayList<>();
    for (AttributeDefinition definition : attributeDefinitions) {
        if (!allDefinitions.contains(definition)) {
            allDefinitions.add(definition);
            pushValues.add(definition);
        }
    }
    updateHelper.pushAll("attributeDefinitions", pushValues);
}
Also used : ArrayList(java.util.ArrayList) AttributeDefinition(org.craftercms.profile.api.AttributeDefinition)

Example 12 with AttributeDefinition

use of org.craftercms.profile.api.AttributeDefinition in project profile by craftercms.

the class TenantServiceIT method getGenderAttributeDefinition.

private AttributeDefinition getGenderAttributeDefinition() {
    AttributePermission permission = new AttributePermission(AttributePermission.ANY_APPLICATION);
    permission.allow(AttributePermission.ANY_ACTION);
    AttributeDefinition definition = new AttributeDefinition();
    definition.setName(GENDER_ATTRIBUTE_NAME);
    definition.addPermission(permission);
    return definition;
}
Also used : AttributePermission(org.craftercms.profile.api.AttributePermission) AttributeDefinition(org.craftercms.profile.api.AttributeDefinition)

Example 13 with AttributeDefinition

use of org.craftercms.profile.api.AttributeDefinition in project profile by craftercms.

the class TenantServiceImpl method addAttributeDefinitions.

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

        @Override
        public void doWithTenant(TenantUpdater tenantUpdater) throws ProfileException {
            tenantUpdater.addAttributeDefinitions(attributeDefinitions);
        }
    });
    for (AttributeDefinition definition : tenant.getAttributeDefinitions()) {
        addDefaultValue(tenantName, definition.getName(), definition.getDefaultValue());
    }
    logger.debug(LOG_KEY_ATTRIBUTE_DEFINITIONS_ADDED, attributeDefinitions, tenantName);
    return tenant;
}
Also used : Tenant(org.craftercms.profile.api.Tenant) TenantUpdater(org.craftercms.profile.utils.db.TenantUpdater) AttributeDefinition(org.craftercms.profile.api.AttributeDefinition) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) ProfileException(org.craftercms.profile.api.exceptions.ProfileException)

Example 14 with AttributeDefinition

use of org.craftercms.profile.api.AttributeDefinition in project profile by craftercms.

the class TenantUpdater method updateAttributeDefinitions.

public void updateAttributeDefinitions(Collection<AttributeDefinition> attributeDefinitions) {
    List<AttributeDefinition> allDefinitions = tenant.getAttributeDefinitions();
    for (AttributeDefinition definition : attributeDefinitions) {
        int idx = indexOfAttributeDefinition(definition.getName(), allDefinitions);
        if (idx >= 0) {
            allDefinitions.set(idx, definition);
            updateHelper.set("attributeDefinitions." + idx, definition);
        }
    }
}
Also used : AttributeDefinition(org.craftercms.profile.api.AttributeDefinition)

Example 15 with AttributeDefinition

use of org.craftercms.profile.api.AttributeDefinition in project profile by craftercms.

the class MellonAutoLoginProcessor method createProfileWithSsoInfo.

protected Profile createProfileWithSsoInfo(String username, Tenant tenant, HttpServletRequest request) throws ProfileException {
    Map<String, Object> attributes = null;
    List<AttributeDefinition> attributeDefinitions = tenant.getAttributeDefinitions();
    String email = request.getHeader(emailHeaderName);
    for (AttributeDefinition attributeDefinition : attributeDefinitions) {
        String attributeName = attributeDefinition.getName();
        String attributeValue = request.getHeader(mellonHeaderPrefix + attributeName);
        if (StringUtils.isNotEmpty(attributeValue)) {
            if (attributes == null) {
                attributes = new HashMap<>();
            }
            attributes.put(attributeName, attributeValue);
        }
    }
    logger.info("Creating new profile with SSO info: username={}, email={}, tenant={}, attributes={}", username, email, tenant.getName(), attributes);
    return profileService.createProfile(tenant.getName(), username, null, email, true, null, attributes, null);
}
Also used : AttributeDefinition(org.craftercms.profile.api.AttributeDefinition)

Aggregations

AttributeDefinition (org.craftercms.profile.api.AttributeDefinition)25 Tenant (org.craftercms.profile.api.Tenant)8 AttributePermission (org.craftercms.profile.api.AttributePermission)7 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 I10nProfileException (org.craftercms.profile.api.exceptions.I10nProfileException)3 Mockito.anyString (org.mockito.Mockito.anyString)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 Profile (org.craftercms.profile.api.Profile)2 VerificationToken (org.craftercms.profile.api.VerificationToken)2 ProfileException (org.craftercms.profile.api.exceptions.ProfileException)2 TenantUpdater (org.craftercms.profile.utils.db.TenantUpdater)2 Collection (java.util.Collection)1 Pattern (java.util.regex.Pattern)1 ObjectId (org.bson.types.ObjectId)1 DuplicateKeyException (org.craftercms.commons.mongo.DuplicateKeyException)1 MongoDataException (org.craftercms.commons.mongo.MongoDataException)1 AttributeNotDefinedException (org.craftercms.profile.exceptions.AttributeNotDefinedException)1 InvalidEmailAddressException (org.craftercms.profile.exceptions.InvalidEmailAddressException)1