Search in sources :

Example 1 with GPlainAttr

use of org.apache.syncope.core.persistence.api.entity.group.GPlainAttr in project syncope by apache.

the class AzurePropagationActions method after.

@Transactional
@Override
public void after(final PropagationTask task, final TaskExec execution, final ConnectorObject afterObj) {
    if (task.getOperation() == ResourceOperation.DELETE || task.getOperation() == ResourceOperation.NONE) {
        return;
    }
    if (AnyTypeKind.USER.equals(task.getAnyTypeKind())) {
        User user = userDAO.find(task.getEntityKey());
        if (user == null) {
            LOG.error("Could not find user {}, skipping", task.getEntityKey());
        } else {
            boolean modified = false;
            AnyUtils anyUtils = anyUtilsFactory.getInstance(user);
            // Azure User ID
            PlainSchema azureId = plainSchemaDAO.find(getAzureIdSchema());
            if (azureId == null) {
                LOG.error("Could not find schema {}, skipping", getAzureIdSchema());
            } else {
                // set back the __UID__ received by Azure
                UPlainAttr attr = user.getPlainAttr(getAzureIdSchema()).orElse(null);
                if (attr == null) {
                    attr = entityFactory.newEntity(UPlainAttr.class);
                    attr.setSchema(azureId);
                    attr.setOwner(user);
                    user.add(attr);
                    try {
                        attr.add(afterObj.getUid().getUidValue(), anyUtils);
                        modified = true;
                    } catch (InvalidPlainAttrValueException e) {
                        LOG.error("Invalid value for attribute {}: {}", azureId.getKey(), afterObj.getUid().getUidValue(), e);
                    }
                } else {
                    LOG.debug("User {} has already {} assigned: {}", user, azureId.getKey(), attr.getValuesAsStrings());
                }
            }
            if (modified) {
                userDAO.save(user);
            }
        }
    } else if (AnyTypeKind.GROUP.equals(task.getAnyTypeKind())) {
        Group group = groupDAO.find(task.getEntityKey());
        if (group == null) {
            LOG.error("Could not find group {}, skipping", task.getEntityKey());
        } else {
            boolean modified = false;
            AnyUtils anyUtils = anyUtilsFactory.getInstance(group);
            // Azure Group ID
            PlainSchema azureId = plainSchemaDAO.find(getAzureGroupIdSchema());
            if (azureId == null) {
                LOG.error("Could not find schema {}, skipping", getAzureGroupIdSchema());
            } else {
                // set back the __UID__ received by Azure
                GPlainAttr attr = group.getPlainAttr(getAzureGroupIdSchema()).orElse(null);
                if (attr == null) {
                    attr = entityFactory.newEntity(GPlainAttr.class);
                    attr.setSchema(azureId);
                    attr.setOwner(group);
                    group.add(attr);
                    try {
                        attr.add(afterObj.getUid().getUidValue(), anyUtils);
                        modified = true;
                    } catch (InvalidPlainAttrValueException e) {
                        LOG.error("Invalid value for attribute {}: {}", azureId.getKey(), afterObj.getUid().getUidValue(), e);
                    }
                } else {
                    LOG.debug("Group {} has already {} assigned: {}", group, azureId.getKey(), attr.getValuesAsStrings());
                }
            }
            if (modified) {
                groupDAO.save(group);
            }
        }
    }
}
Also used : Group(org.apache.syncope.core.persistence.api.entity.group.Group) GPlainAttr(org.apache.syncope.core.persistence.api.entity.group.GPlainAttr) User(org.apache.syncope.core.persistence.api.entity.user.User) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) UPlainAttr(org.apache.syncope.core.persistence.api.entity.user.UPlainAttr) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) InvalidPlainAttrValueException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidPlainAttrValueException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with GPlainAttr

use of org.apache.syncope.core.persistence.api.entity.group.GPlainAttr in project syncope by apache.

the class PlainSchemaTest method findAttrs.

@Test
public void findAttrs() {
    PlainSchema schema = plainSchemaDAO.find("icon");
    assertNotNull(schema);
    List<GPlainAttr> attrs = plainSchemaDAO.findAttrs(schema, GPlainAttr.class);
    assertNotNull(attrs);
    assertFalse(attrs.isEmpty());
}
Also used : GPlainAttr(org.apache.syncope.core.persistence.api.entity.group.GPlainAttr) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Aggregations

PlainSchema (org.apache.syncope.core.persistence.api.entity.PlainSchema)2 GPlainAttr (org.apache.syncope.core.persistence.api.entity.group.GPlainAttr)2 InvalidPlainAttrValueException (org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidPlainAttrValueException)1 AnyUtils (org.apache.syncope.core.persistence.api.entity.AnyUtils)1 Group (org.apache.syncope.core.persistence.api.entity.group.Group)1 UPlainAttr (org.apache.syncope.core.persistence.api.entity.user.UPlainAttr)1 User (org.apache.syncope.core.persistence.api.entity.user.User)1 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)1 Test (org.junit.jupiter.api.Test)1 Transactional (org.springframework.transaction.annotation.Transactional)1