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);
}
}
}
}
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());
}
Aggregations