private Attribute<?> getEmailAttributeFromRequest( RegistrationRequestState currentRequest, SqlSession sql) throws EngineException { List<Attribute<?>> attrs = currentRequest.getRequest().getAttributes(); if (attrs == null) return null; AttributeType at = attributesHelper.getAttributeTypeWithSingeltonMetadata( ContactEmailMetadataProvider.NAME, sql); if (at == null) return null; for (Attribute<?> ap : attrs) { if (ap == null) continue; if (ap.getName().equals(at.getName()) && ap.getGroupPath().equals("/")) return ap; } return null; }
private String getAddressFrom( List<VerifiableEmail> emailIds, Attribute<?> emailAttr, boolean useConfirmed) { for (VerifiableEmail id : emailIds) if (!useConfirmed || id.isConfirmed()) return id.getValue(); if (emailAttr != null && (!useConfirmed || emailAttr.getAttributeSyntax().isVerifiable())) for (Object emailO : emailAttr.getValues()) { if (!useConfirmed) { return emailO.toString(); } else if (emailAttr.getAttributeSyntax().isVerifiable()) { VerifiableEmail email = (VerifiableEmail) emailO; if (!useConfirmed || email.isConfirmed()) return email.getValue(); } } return null; }
protected <T> void fromJsonBase(ObjectNode main, Attribute<T> target) { target.setVisibility(AttributeVisibility.valueOf(main.get("visibility").asText())); if (main.has("translationProfile")) target.setTranslationProfile(main.get("translationProfile").asText()); if (main.has("remoteIdp")) target.setRemoteIdp(main.get("remoteIdp").asText()); ArrayNode values = main.withArray("values"); List<T> pValues = new ArrayList<T>(values.size()); Iterator<JsonNode> it = values.iterator(); AttributeValueSyntax<T> syntax = target.getAttributeSyntax(); try { while (it.hasNext()) pValues.add(syntax.deserialize(it.next().binaryValue())); } catch (Exception e) { throw new InternalException("Can't perform JSON deserialization", e); } target.setValues(pValues); }
protected <T> ObjectNode toJsonBase(Attribute<T> src) { ObjectNode root = mapper.createObjectNode(); root.put("visibility", src.getVisibility().name()); if (src.getRemoteIdp() != null) root.put("remoteIdp", src.getRemoteIdp()); if (src.getTranslationProfile() != null) root.put("translationProfile", src.getTranslationProfile()); ArrayNode values = root.putArray("values"); AttributeValueSyntax<T> syntax = src.getAttributeSyntax(); for (T value : src.getValues()) values.add(syntax.serialize(value)); return root; }