private void setTemplates(final RealmTO realmTO, final Realm realm) { // validate JEXL expressions from templates and proceed if fine templateUtils.check(realmTO.getTemplates(), ClientExceptionType.InvalidRealm); realmTO.getTemplates().forEach((key, template) -> { AnyType type = anyTypeDAO.find(key); if (type == null) { LOG.debug("Invalid AnyType {} specified, ignoring...", key); } else { AnyTemplateRealm anyTemplate = realm.getTemplate(type).orElse(null); if (anyTemplate == null) { anyTemplate = entityFactory.newEntity(AnyTemplateRealm.class); anyTemplate.setAnyType(type); anyTemplate.setRealm(realm); realm.add(anyTemplate); } anyTemplate.set(template); } }); // remove all templates not contained in the TO realm.getTemplates(). removeIf(template -> !realmTO.getTemplates().containsKey(template.getAnyType().getKey())); }
@Override public RealmTO getRealmTO(final Realm realm, final boolean admin) { RealmTO realmTO = new RealmTO(); realmTO.setKey(realm.getKey()); realmTO.setName(realm.getName()); realmTO.setParent(realm.getParent() == null ? null : realm.getParent().getKey()); realmTO.setFullPath(realm.getFullPath()); if (admin) { realmTO.setAccountPolicy(realm.getAccountPolicy() == null ? null : realm.getAccountPolicy().getKey()); realmTO.setPasswordPolicy(realm.getPasswordPolicy() == null ? null : realm.getPasswordPolicy().getKey()); realm.getActions().forEach(action -> { realmTO.getActions().add(action.getKey()); }); realm.getTemplates().forEach(template -> { realmTO.getTemplates().put(template.getAnyType().getKey(), template.get()); }); realm.getResources().forEach(resource -> { realmTO.getResources().add(resource.getKey()); }); } return realmTO; }