Search in sources :

Example 26 with AttributeData

use of org.gluu.persist.model.AttributeData in project oxCore by GluuFederation.

the class BaseEntryManager method setCustomObjectClasses.

protected void setCustomObjectClasses(Object entry, Class<?> entryClass, String[] objectClasses) {
    List<PropertyAnnotation> customObjectAnnotations = getEntryCustomObjectClassAnnotations(entryClass);
    for (PropertyAnnotation propertiesAnnotation : customObjectAnnotations) {
        String propertyName = propertiesAnnotation.getPropertyName();
        Setter setter = getSetter(entryClass, propertyName);
        if (setter == null) {
            throw new MappingException("Entry should has setter for property " + propertyName);
        }
        AttributeData attribute = new AttributeData(propertyName, objectClasses);
        setPropertyValue(propertyName, setter, entry, attribute, false);
        break;
    }
}
Also used : Setter(org.gluu.persist.reflect.property.Setter) AttributeData(org.gluu.persist.model.AttributeData) PropertyAnnotation(org.gluu.persist.model.PropertyAnnotation) MappingException(org.gluu.persist.exception.mapping.MappingException)

Example 27 with AttributeData

use of org.gluu.persist.model.AttributeData in project oxTrust by GluuFederation.

the class LdifService method performImport.

@SuppressWarnings("resource")
public void performImport(Class entryClass, InputStream inputStream) {
    final ArrayList<Entry> entryList = new ArrayList<Entry>();
    final LDIFReader reader = new LDIFReader(inputStream);
    while (true) {
        try {
            final Entry entry = reader.readEntry();
            if (entry == null) {
                break;
            } else {
                entryList.add(entry);
            }
        } catch (final Exception e) {
            log.error("", e);
        }
    }
    entryList.stream().forEach(e -> {
        Collection<Attribute> attributes = e.getAttributes();
        List<Attribute> values = new ArrayList<>();
        values.addAll(attributes);
        ArrayList<AttributeData> datas = new ArrayList<>();
        values.stream().forEach(value -> {
            datas.add(new AttributeData(value.getName(), value.getValues(), (value.getValues().length > 1) ? true : false));
        });
        try {
            persistenceManager.importEntry(e.getDN(), entryClass, datas);
        } catch (Exception ex) {
            log.info("=========", ex);
        }
    });
}
Also used : Entry(com.unboundid.ldap.sdk.Entry) Attribute(com.unboundid.ldap.sdk.Attribute) GluuAttribute(org.gluu.model.GluuAttribute) LDIFReader(com.unboundid.ldif.LDIFReader) ArrayList(java.util.ArrayList) IOException(java.io.IOException) LDAPException(com.unboundid.ldap.sdk.LDAPException) AttributeData(org.gluu.persist.model.AttributeData)

Aggregations

AttributeData (org.gluu.persist.model.AttributeData)27 ArrayList (java.util.ArrayList)16 MappingException (org.gluu.persist.exception.mapping.MappingException)15 PropertyAnnotation (org.gluu.persist.model.PropertyAnnotation)14 LdapJsonObject (org.gluu.site.ldap.persistence.annotation.LdapJsonObject)9 List (java.util.List)7 Annotation (java.lang.annotation.Annotation)6 LdapAttribute (org.gluu.site.ldap.persistence.annotation.LdapAttribute)6 LdapAttributesList (org.gluu.site.ldap.persistence.annotation.LdapAttributesList)6 HashMap (java.util.HashMap)4 EntryPersistenceException (org.gluu.persist.exception.mapping.EntryPersistenceException)4 AttributeDataModification (org.gluu.persist.model.AttributeDataModification)4 Attribute (com.unboundid.ldap.sdk.Attribute)3 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)3 ParseException (java.text.ParseException)3 LinkedList (java.util.LinkedList)3 AuthenticationException (org.gluu.persist.exception.operation.AuthenticationException)3 ConnectionException (org.gluu.persist.exception.operation.ConnectionException)3 SearchException (org.gluu.persist.exception.operation.SearchException)3 SearchScopeException (org.gluu.persist.exception.operation.SearchScopeException)3