Last active
February 24, 2020 07:29
-
-
Save ilgrosso/8abc6fd129d48441a40298213d098b77 to your computer and use it in GitHub Desktop.
AttributesEnrichingPropagationActions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AttributesEnrichingPropagationAction implements PropagationActions { | |
@Autowired | |
private UserDAO userDAO; | |
@Transactional(readonly = true) | |
@Override | |
public void before(final PropagationTask task, final ConnectorObject beforeObj) { | |
// do something only if propagating users | |
if (AnyTypeKind.USER == task.getAnyTypeKind()) { | |
// read the user being propagated | |
User user = userDAO.find(task.getEntityKey()); | |
if (user != null) { | |
// get the propagation attributes preparared according to the mapping provided | |
Set<Attribute> attributes = new HashSet<>(task.getAttributes()); | |
// add, replace of remove attributes | |
Set<String> groups = user.getMemberships().stream(). | |
map(memb -> memb.getRightEnd().getName()).collect(Collectors.toSet()); | |
attributes.add(AttributeBuilder.build("new_attribute_name", groups)); | |
// store the updated attributes for actual propagation | |
task.setAttributes(attributes); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment