private Map<String, Pair<RealmTO, List<RealmTO>>> reloadRealmParentMap(final List<RealmTO> realms) { tree.clear(); tree.put(null, Pair.<RealmTO, List<RealmTO>>of(realms.get(0), new ArrayList<>())); final Map<String, List<RealmTO>> cache = new HashMap<>(); realms.forEach(realm -> { final List<RealmTO> children = new ArrayList<>(); tree.put(realm.getKey(), Pair.<RealmTO, List<RealmTO>>of(realm, children)); if (cache.containsKey(realm.getKey())) { children.addAll(cache.get(realm.getKey())); cache.remove(realm.getKey()); } if (tree.containsKey(realm.getParent())) { tree.get(realm.getParent()).getRight().add(realm); } else if (cache.containsKey(realm.getParent())) { cache.get(realm.getParent()).add(realm); } else { cache.put(realm.getParent(), new ArrayList<>(Collections.singleton(realm))); } }); return tree; }
@PreAuthorize("hasRole('" + StandardEntitlement.REALM_CREATE + "')") public ProvisioningResult<RealmTO> create(final String parentPath, final RealmTO realmTO) { Realm parent; if (StringUtils.isBlank(realmTO.getParent())) { parent = realmDAO.findByFullPath(parentPath); if (parent == null) { parent = realmDAO.find(realmTO.getParent()); if (parent == null) { LOG.error("Could not find parent realm " + realmTO.getParent()); throw new NotFoundException(realmTO.getParent());
private List<ProvisioningReport> assign(final SyncDelta delta, final OrgUnit orgUnit) throws JobExecutionException { if (!profile.getTask().isPerformCreate()) { LOG.debug("PullTask not configured for create"); finalize(UnmatchingRule.toEventName(UnmatchingRule.ASSIGN), Result.SUCCESS, null, null, delta); return Collections.<ProvisioningReport>emptyList(); } RealmTO realmTO = connObjectUtils.getRealmTO(delta.getObject(), profile.getTask(), orgUnit); if (realmTO.getFullPath() == null) { if (realmTO.getParent() == null) { realmTO.setParent(profile.getTask().getDestinatioRealm().getFullPath()); } realmTO.setFullPath(realmTO.getParent() + "/" + realmTO.getName()); } realmTO.getResources().add(profile.getTask().getResource().getKey()); ProvisioningReport result = new ProvisioningReport(); result.setOperation(ResourceOperation.CREATE); result.setAnyType(REALM_TYPE); result.setStatus(ProvisioningReport.Status.SUCCESS); result.setName(realmTO.getFullPath()); if (profile.isDryRun()) { result.setKey(null); finalize(UnmatchingRule.toEventName(UnmatchingRule.ASSIGN), Result.SUCCESS, null, null, delta); } else { for (PullActions action : profile.getActions()) { action.beforeAssign(profile, delta, realmTO); } create(realmTO, delta, UnmatchingRule.ASSIGN, result); } return Collections.singletonList(result); }
private List<ProvisioningReport> provision(final SyncDelta delta, final OrgUnit orgUnit) throws JobExecutionException { if (!profile.getTask().isPerformCreate()) { LOG.debug("PullTask not configured for create"); finalize(UnmatchingRule.toEventName(UnmatchingRule.PROVISION), Result.SUCCESS, null, null, delta); return Collections.<ProvisioningReport>emptyList(); } RealmTO realmTO = connObjectUtils.getRealmTO(delta.getObject(), profile.getTask(), orgUnit); if (realmTO.getFullPath() == null) { if (realmTO.getParent() == null) { realmTO.setParent(profile.getTask().getDestinatioRealm().getFullPath()); } realmTO.setFullPath(realmTO.getParent() + "/" + realmTO.getName()); } ProvisioningReport result = new ProvisioningReport(); result.setOperation(ResourceOperation.CREATE); result.setAnyType(REALM_TYPE); result.setStatus(ProvisioningReport.Status.SUCCESS); result.setName(realmTO.getFullPath()); if (profile.isDryRun()) { result.setKey(null); finalize(UnmatchingRule.toEventName(UnmatchingRule.PROVISION), Result.SUCCESS, null, null, delta); } else { for (PullActions action : profile.getActions()) { action.beforeProvision(profile, delta, realmTO); } create(realmTO, delta, UnmatchingRule.PROVISION, result); } return Collections.singletonList(result); }