You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2017/08/16 09:37:28 UTC
svn commit: r1805160 - in
/directory/studio/branches/studio-value/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core:
jobs/CopyEntriesRunnable.java jobs/ExportDsmlRunnable.java
model/impl/Value.java utils/Utils.java
Author: elecharny
Date: Wed Aug 16 09:37:27 2017
New Revision: 1805160
URL: http://svn.apache.org/viewvc?rev=1805160&view=rev
Log:
o Switched to LDAP API Value branch
o Moved to Java 8 (try-with-resources)
o Some sonar warning fixing
Modified:
directory/studio/branches/studio-value/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/CopyEntriesRunnable.java
directory/studio/branches/studio-value/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportDsmlRunnable.java
directory/studio/branches/studio-value/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/Value.java
directory/studio/branches/studio-value/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/Utils.java
Modified: directory/studio/branches/studio-value/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/CopyEntriesRunnable.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/studio-value/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/CopyEntriesRunnable.java?rev=1805160&r1=1805159&r2=1805160&view=diff
==============================================================================
--- directory/studio/branches/studio-value/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/CopyEntriesRunnable.java (original)
+++ directory/studio/branches/studio-value/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/CopyEntriesRunnable.java Wed Aug 16 09:37:27 2017
@@ -124,7 +124,7 @@ public class CopyEntriesRunnable impleme
*/
public Object[] getLockedObjects()
{
- List<IEntry> l = new ArrayList<IEntry>();
+ List<IEntry> l = new ArrayList<>();
l.add( parent );
l.addAll( Arrays.asList( entriesToCopy ) );
return l.toArray();
@@ -322,7 +322,7 @@ public class CopyEntriesRunnable impleme
dialog.setExistingEntry( targetBrowserConnection, newLdapDn );
dialog.open();
EntryExistsCopyStrategy strategy = dialog.getStrategy();
- // boolean rememberSelection = dialog.isRememberSelection();
+
if ( strategy != null )
{
dummyMonitor.reset();
@@ -338,7 +338,7 @@ public class CopyEntriesRunnable impleme
case OVERWRITE_AND_CONTINUE:
// create modification items
- List<ModificationItem> mis = new ArrayList<ModificationItem>();
+ List<ModificationItem> mis = new ArrayList<>();
NamingEnumeration<? extends Attribute> all = newAttributes.getAll();
while ( all.hasMore() )
{
@@ -399,7 +399,7 @@ public class CopyEntriesRunnable impleme
monitor.reportProgress( BrowserCoreMessages.bind( BrowserCoreMessages.model__copied_n_entries,
new String[]
- { "" + numberOfCopiedEntries } ) ); //$NON-NLS-1$
+ { Integer.toString( numberOfCopiedEntries ) } ) ); //$NON-NLS-1$
// copy recursively
if ( scope == SearchControls.ONELEVEL_SCOPE || scope == SearchControls.SUBTREE_SCOPE )
@@ -445,7 +445,7 @@ public class CopyEntriesRunnable impleme
Attribute attribute = attributes.get( atav.getType() );
if ( attribute != null )
{
- attribute.remove( atav.getValue().getNormValue() );
+ attribute.remove( atav.getValue().getNormalized() );
if ( attribute.size() == 0 )
{
attributes.remove( atav.getType() );
@@ -463,9 +463,9 @@ public class CopyEntriesRunnable impleme
attribute = new BasicAttribute( atav.getType() );
attributes.put( attribute );
}
- if ( !attribute.contains( atav.getValue().getNormValue() ) )
+ if ( !attribute.contains( atav.getValue().getNormalized() ) )
{
- attribute.add( atav.getValue().getNormValue() );
+ attribute.add( atav.getValue().getNormalized() );
}
}
}
Modified: directory/studio/branches/studio-value/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportDsmlRunnable.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/studio-value/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportDsmlRunnable.java?rev=1805160&r1=1805159&r2=1805160&view=diff
==============================================================================
--- directory/studio/branches/studio-value/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportDsmlRunnable.java (original)
+++ directory/studio/branches/studio-value/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportDsmlRunnable.java Wed Aug 16 09:37:27 2017
@@ -26,7 +26,6 @@ import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Iterator;
import java.util.List;
import javax.naming.NamingEnumeration;
@@ -111,7 +110,7 @@ public class ExportDsmlRunnable implemen
public enum ExportDsmlJobType
{
RESPONSE, REQUEST
- };
+ }
/**
@@ -134,7 +133,7 @@ public class ExportDsmlRunnable implemen
// Adding the name and OID of the 'ref' attribute to the list of returning attributes
// for handling externals correctly
- List<String> returningAttributes = new ArrayList<String>( Arrays.asList( searchParameter
+ List<String> returningAttributes = new ArrayList<>( Arrays.asList( searchParameter
.getReturningAttributes() ) );
returningAttributes.add( REF_ATTRIBUTETYPE_NAME );
returningAttributes.add( REF_ATTRIBUTETYPE_OID );
@@ -166,7 +165,7 @@ public class ExportDsmlRunnable implemen
*/
public Object[] getLockedObjects()
{
- List<String> l = new ArrayList<String>();
+ List<String> l = new ArrayList<>();
l.add( browserConnection.getUrl() + "_" + DigestUtils.shaHex( exportDsmlFilename ) ); //$NON-NLS-1$
return l.toArray();
}
@@ -204,6 +203,7 @@ public class ExportDsmlRunnable implemen
// Getting the DSML string associated to the search
// and the type of answer the user is expecting
String dsmlExportString = null;
+
switch ( type )
{
case RESPONSE:
@@ -213,18 +213,22 @@ public class ExportDsmlRunnable implemen
dsmlExportString = processAsDsmlRequest( ne, dummyMonitor );
break;
}
+
monitor.worked( 1 );
// Writing the DSML string to the final destination file.
if ( dsmlExportString != null )
{
- FileOutputStream fos = new FileOutputStream( exportDsmlFilename );
- OutputStreamWriter osw = new OutputStreamWriter( fos, "UTF-8" ); //$NON-NLS-1$
- BufferedWriter bufferedWriter = new BufferedWriter( osw );
- bufferedWriter.write( dsmlExportString );
- bufferedWriter.close();
- osw.close();
- fos.close();
+ try ( FileOutputStream fos = new FileOutputStream( exportDsmlFilename ) )
+ {
+ try ( OutputStreamWriter osw = new OutputStreamWriter( fos, "UTF-8" ) ) //$NON-NLS-1$
+ {
+ try ( BufferedWriter bufferedWriter = new BufferedWriter( osw ) )
+ {
+ bufferedWriter.write( dsmlExportString );
+ }
+ }
+ }
}
monitor.worked( 1 );
}
@@ -238,18 +242,12 @@ public class ExportDsmlRunnable implemen
/**
* Processes the {@link NamingEnumeration} as a DSML response.
*
- * @param ne
- * the naming enumeration
- * @param monitor
- * the monitor
- * @return
- * the associated DSML
- * @throws NamingException
- * @throws LdapURLEncodingException
+ * @param ne the naming enumeration
+ * @param monitor the monitor
+ * @return the associated DSML
* @throws LdapException
*/
- private String processAsDsmlResponse( StudioNamingEnumeration ne, StudioProgressMonitor monitor )
- throws NamingException, LdapURLEncodingException, LdapException
+ private String processAsDsmlResponse( StudioNamingEnumeration ne, StudioProgressMonitor monitor ) throws LdapException
{
// Creating the batch reponse
BatchResponseDsml batchResponse = new BatchResponseDsml();
@@ -274,7 +272,7 @@ public class ExportDsmlRunnable implemen
* @throws org.apache.directory.api.ldap.model.exception.LdapException
*/
public static void processAsDsmlResponse( StudioNamingEnumeration ne, BatchResponseDsml batchResponse,
- StudioProgressMonitor monitor, SearchParameter searchParameter ) throws LdapURLEncodingException, LdapException
+ StudioProgressMonitor monitor, SearchParameter searchParameter ) throws LdapException
{
// Creating and adding the search response
SearchResponseDsml sr = new SearchResponseDsml( codec );
@@ -289,8 +287,8 @@ public class ExportDsmlRunnable implemen
// Creating and adding a search result entry or reference for each result
while ( ne.hasMore() )
{
- SearchResult searchResult = ( SearchResult ) ne.next();
- sr.addResponse( convertSearchResultToDsml( searchResult, searchParameter ) );
+ SearchResult searchResult = ne.next();
+ sr.addResponse( convertSearchResultToDsml( searchResult ) );
count++;
monitor.reportProgress( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__export_progress,
@@ -340,15 +338,12 @@ public class ExportDsmlRunnable implemen
/**
* Converts the given {@link SearchResult} to a {@link SearchResultEntryDsml}.
*
- * @param searchResult
- * the search result
- * @return
- * the associated search result entry DSML
+ * @param searchResult the search result
+ * @return the associated search result entry DSML
* @throws org.apache.directory.api.ldap.model.exception.LdapException
*/
- private static DsmlDecorator<? extends Response> convertSearchResultToDsml( SearchResult searchResult,
- SearchParameter searchParameter )
- throws LdapException, LdapURLEncodingException
+ private static DsmlDecorator<? extends Response> convertSearchResultToDsml( SearchResult searchResult )
+ throws LdapException
{
Entry entry = AttributeUtils.toEntry( searchResult.getAttributes(),
new Dn( searchResult.getNameInNamespace() ) );
@@ -369,12 +364,10 @@ public class ExportDsmlRunnable implemen
// Adding references
if ( refAttribute != null )
{
- for ( Iterator<Value<?>> iterator = refAttribute.iterator(); iterator.hasNext(); )
- {
- Value<?> value = ( Value<?> ) iterator.next();
-
- srr.addSearchResultReference( new LdapUrl( ( String ) value.getValue() ) );
- }
+ for ( Value value : refAttribute )
+ {
+ srr.addSearchResultReference( new LdapUrl( ( String ) value.getValue() ) );
+ }
}
return srr;
@@ -449,7 +442,7 @@ public class ExportDsmlRunnable implemen
// Creating and adding an add request for each result
while ( ne.hasMore() )
{
- SearchResult searchResult = ( SearchResult ) ne.next();
+ SearchResult searchResult = ne.next();
AddRequestDsml arDsml = convertToAddRequestDsml( searchResult );
batchRequest.addRequest( arDsml );
Modified: directory/studio/branches/studio-value/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/Value.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/studio-value/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/Value.java?rev=1805160&r1=1805159&r2=1805160&view=diff
==============================================================================
--- directory/studio/branches/studio-value/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/Value.java (original)
+++ directory/studio/branches/studio-value/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/Value.java Wed Aug 16 09:37:27 2017
@@ -310,7 +310,7 @@ public class Value implements IValue
{
Ava ava = atavIterator.next();
if ( getAttribute().getDescription().equals( ava.getNormType() )
- && getStringValue().equals( ava.getValue().getNormValue() ) )
+ && getStringValue().equals( ava.getValue().getNormalized() ) )
{
return true;
}
Modified: directory/studio/branches/studio-value/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/Utils.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/studio-value/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/Utils.java?rev=1805160&r1=1805159&r2=1805160&view=diff
==============================================================================
--- directory/studio/branches/studio-value/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/Utils.java (original)
+++ directory/studio/branches/studio-value/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/Utils.java Wed Aug 16 09:37:27 2017
@@ -29,7 +29,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -89,17 +88,22 @@ public class Utils
*/
public static String getNormalizedOidString( Dn dn, Schema schema )
{
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
- Iterator<Rdn> it = dn.getRdns().iterator();
- while ( it.hasNext() )
+ boolean isFirst = true;
+
+ for ( Rdn rdn : dn )
{
- Rdn rdn = it.next();
- sb.append( getOidString( rdn, schema ) );
- if ( it.hasNext() )
+ if ( isFirst )
+ {
+ isFirst = false;
+ }
+ else
{
sb.append( ',' );
}
+
+ sb.append( getOidString( rdn, schema ) );
}
return sb.toString();
@@ -108,17 +112,22 @@ public class Utils
private static String getOidString( Rdn rdn, Schema schema )
{
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
- Iterator<Ava> it = rdn.iterator();
- while ( it.hasNext() )
+ boolean isFirst = true;
+
+ for ( Ava ava : rdn )
{
- Ava ava = it.next();
- sb.append( getOidString( ava, schema ) );
- if ( it.hasNext() )
+ if ( isFirst )
+ {
+ isFirst = false;
+ }
+ else
{
sb.append( '+' );
}
+
+ sb.append( getOidString( ava, schema ) );
}
return sb.toString();
@@ -129,8 +138,8 @@ public class Utils
{
String oid = schema != null ? schema.getAttributeTypeDescription( ava.getNormType() ).getOid() : ava
.getNormType();
- return Strings.toLowerCase( Strings.trim( oid ) )
- + "=" + Strings.trim( ava.getValue().getString() ).toLowerCase(); //$NON-NLS-1$
+ return Strings.toLowerCaseAscii( Strings.trim( oid ) )
+ + "=" + Strings.trim( ava.getValue().getValue() ).toLowerCase(); //$NON-NLS-1$
}
@@ -142,12 +151,14 @@ public class Utils
}
else
{
- StringBuffer sb = new StringBuffer( array[0] );
+ StringBuilder sb = new StringBuilder( array[0] );
+
for ( int i = 1; i < array.length; i++ )
{
sb.append( ", " ); //$NON-NLS-1$
sb.append( array[i] );
}
+
return sb.toString();
}
}
@@ -172,22 +183,21 @@ public class Utils
public static String getShortenedString( String value, int length )
{
-
- if ( value == null )
- return ""; //$NON-NLS-1$
-
- if ( value.length() > length )
+ StringBuilder sb = new StringBuilder();
+
+ if ( ( value != null ) && ( value.length() > length ) )
{
- value = value.substring( 0, length ) + "..."; //$NON-NLS-1$
+ sb.append( value.substring( 0, length ) ).append( "..." ); //$NON-NLS-1$
}
- return value;
+ return sb.toString();
}
public static String serialize( Object o )
{
ClassLoader ccl = Thread.currentThread().getContextClassLoader();
+
try
{
Thread.currentThread().setContextClassLoader( Utils.class.getClassLoader() );
@@ -195,8 +205,8 @@ public class Utils
XMLEncoder encoder = new XMLEncoder( baos );
encoder.writeObject( o );
encoder.close();
- String s = LdifUtils.utf8decode( baos.toByteArray() );
- return s;
+
+ return LdifUtils.utf8decode( baos.toByteArray() );
}
finally
{
@@ -208,6 +218,7 @@ public class Utils
public static Object deserialize( String s )
{
ClassLoader ccl = Thread.currentThread().getContextClassLoader();
+
try
{
Thread.currentThread().setContextClassLoader( Utils.class.getClassLoader() );
@@ -215,6 +226,7 @@ public class Utils
XMLDecoder decoder = new XMLDecoder( bais );
Object o = decoder.readObject();
decoder.close();
+
return o;
}
finally
@@ -233,15 +245,25 @@ public class Utils
public static String formatBytes( long bytes )
{
String size = ""; //$NON-NLS-1$
+
if ( bytes > 1024 * 1024 )
+ {
size += ( bytes / 1024 / 1024 )
+ " " + Messages.Utils_MegaBytes + " (" + bytes + " " + Messages.Utils_Bytes + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-6$
+ }
else if ( bytes > 1024 )
+ {
size += ( bytes / 1024 ) + " " + Messages.Utils_KiloBytes + " (" + bytes + " " + Messages.Utils_Bytes + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-6$
+ }
else if ( bytes > 1 )
+ {
size += bytes + " " + Messages.Utils_Bytes; //$NON-NLS-1$
+ }
else
+ {
size += bytes + " " + Messages.Utils_Byte; //$NON-NLS-1$
+ }
+
return size;
}
@@ -271,8 +293,8 @@ public class Utils
boolean spaceAfterColon = store.getBoolean( BrowserCoreConstants.PREFERENCE_LDIF_SPACE_AFTER_COLON );
int lineWidth = store.getInt( BrowserCoreConstants.PREFERENCE_LDIF_LINE_WIDTH );
String lineSeparator = store.getString( BrowserCoreConstants.PREFERENCE_LDIF_LINE_SEPARATOR );
- LdifFormatParameters ldifFormatParameters = new LdifFormatParameters( spaceAfterColon, lineWidth, lineSeparator );
- return ldifFormatParameters;
+
+ return new LdifFormatParameters( spaceAfterColon, lineWidth, lineSeparator );
}
@@ -291,6 +313,7 @@ public class Utils
public static LdapUrl getLdapURL( IBrowserConnection browserConnection )
{
LdapUrl url = new LdapUrl();
+
if ( browserConnection.getConnection() != null )
{
if ( browserConnection.getConnection().getEncryptionMethod() == EncryptionMethod.LDAPS )
@@ -301,9 +324,11 @@ public class Utils
{
url.setScheme( LdapUrl.LDAP_SCHEME );
}
+
url.setHost( browserConnection.getConnection().getHost() );
url.setPort( browserConnection.getConnection().getPort() );
}
+
return url;
}
@@ -325,6 +350,7 @@ public class Utils
{
LdapUrl url = getLdapURL( entry.getBrowserConnection() );
url.setDn( entry.getDn() );
+
return url;
}
@@ -349,12 +375,15 @@ public class Utils
{
LdapUrl url = getLdapURL( search.getBrowserConnection() );
url.setDn( search.getSearchBase() );
+
if ( search.getReturningAttributes() != null )
{
url.setAttributes( Arrays.asList( search.getReturningAttributes() ) );
}
+
url.setScope( search.getScope().getScope() );
url.setFilter( search.getFilter() );
+
return url;
}
@@ -377,11 +406,13 @@ public class Utils
ModifyOrder modifyAddDeleteOrder = oldEntry.getBrowserConnection().getModifyAddDeleteOrder();
// get all attribute descriptions
- Set<String> attributeDescriptions = new HashSet<String>();
+ Set<String> attributeDescriptions = new HashSet<>();
+
for ( IAttribute oldAttr : oldEntry.getAttributes() )
{
attributeDescriptions.add( oldAttr.getDescription() );
}
+
for ( IAttribute newAttr : newEntry.getAttributes() )
{
attributeDescriptions.add( newAttr.getDescription() );
@@ -389,6 +420,7 @@ public class Utils
// prepare the LDIF record containing the modifications
LdifChangeModifyRecord record = new LdifChangeModifyRecord( LdifDnLine.create( newEntry.getDn().getName() ) );
+
if ( newEntry.isReferral() )
{
record.addControl( LdifControlLine.create( StudioControl.MANAGEDSAIT_CONTROL.getOid(),
@@ -412,8 +444,9 @@ public class Utils
// get old an new values for comparison
IAttribute oldAttribute = oldEntry.getAttribute( attributeDescription );
- Set<String> oldValues = new HashSet<String>();
- Map<String, LdifAttrValLine> oldAttrValLines = new LinkedHashMap<String, LdifAttrValLine>();
+ Set<String> oldValues = new HashSet<>();
+ Map<String, LdifAttrValLine> oldAttrValLines = new LinkedHashMap<>();
+
if ( oldAttribute != null )
{
for ( IValue value : oldAttribute.getValues() )
@@ -423,9 +456,11 @@ public class Utils
oldAttrValLines.put( attrValLine.getUnfoldedValue(), attrValLine );
}
}
+
IAttribute newAttribute = newEntry.getAttribute( attributeDescription );
- Set<String> newValues = new HashSet<String>();
- Map<String, LdifAttrValLine> newAttrValLines = new LinkedHashMap<String, LdifAttrValLine>();
+ Set<String> newValues = new HashSet<>();
+ Map<String, LdifAttrValLine> newAttrValLines = new LinkedHashMap<>();
+
if ( newAttribute != null )
{
for ( IValue value : newAttribute.getValues() )
@@ -441,6 +476,7 @@ public class Utils
{
// attribute only exists in the old entry: delete all values
LdifModSpec modSpec;
+
if ( isReplaceForced )
{
// replace (empty value list)
@@ -452,6 +488,7 @@ public class Utils
// delete all
modSpec = LdifModSpec.createDelete( attributeDescription );
}
+
modSpec.finish( LdifModSpecSepLine.create() );
record.addModSpec( modSpec );
}
@@ -459,6 +496,7 @@ public class Utils
{
// attribute only exists in the new entry: add all values
LdifModSpec modSpec;
+
if ( isReplaceForced )
{
// replace (all values)
@@ -470,10 +508,12 @@ public class Utils
// add (all new values)
modSpec = LdifModSpec.createAdd( attributeDescription );
}
+
for ( IValue value : newAttribute.getValues() )
{
modSpec.addAttrVal( computeDiffCreateAttrValLine( value ) );
}
+
modSpec.finish( LdifModSpecSepLine.create() );
record.addModSpec( modSpec );
}
@@ -484,18 +524,20 @@ public class Utils
{
// replace (all new values)
LdifModSpec modSpec = LdifModSpec.createReplace( attributeDescription );
+
for ( IValue value : newAttribute.getValues() )
{
modSpec.addAttrVal( computeDiffCreateAttrValLine( value ) );
}
+
modSpec.finish( LdifModSpecSepLine.create() );
record.addModSpec( modSpec );
}
else
{
// compute diff
- List<LdifAttrValLine> toDel = new ArrayList<LdifAttrValLine>();
- List<LdifAttrValLine> toAdd = new ArrayList<LdifAttrValLine>();
+ List<LdifAttrValLine> toDel = new ArrayList<>();
+ List<LdifAttrValLine> toAdd = new ArrayList<>();
for ( Map.Entry<String, LdifAttrValLine> entry : oldAttrValLines.entrySet() )
{
@@ -504,6 +546,7 @@ public class Utils
toDel.add( entry.getValue() );
}
}
+
for ( Map.Entry<String, LdifAttrValLine> entry : newAttrValLines.entrySet() )
{
if ( !oldValues.contains( entry.getKey() ) )
@@ -528,16 +571,20 @@ public class Utils
{
// add/del del/add
LdifModSpec addModSpec = LdifModSpec.createAdd( attributeDescription );
+
for ( LdifAttrValLine attrValLine : toAdd )
{
addModSpec.addAttrVal( attrValLine );
}
+
addModSpec.finish( LdifModSpecSepLine.create() );
LdifModSpec delModSpec = LdifModSpec.createDelete( attributeDescription );
+
for ( LdifAttrValLine attrValLine : toDel )
{
delModSpec.addAttrVal( attrValLine );
}
+
delModSpec.finish( LdifModSpecSepLine.create() );
if ( modifyAddDeleteOrder == ModifyOrder.DELETE_FIRST )
@@ -546,6 +593,7 @@ public class Utils
{
record.addModSpec( delModSpec );
}
+
if ( addModSpec.getAttrVals().length > 0 )
{
record.addModSpec( addModSpec );
@@ -557,6 +605,7 @@ public class Utils
{
record.addModSpec( addModSpec );
}
+
if ( delModSpec.getAttrVals().length > 0 )
{
record.addModSpec( delModSpec );
@@ -567,10 +616,12 @@ public class Utils
{
// replace (all new values)
LdifModSpec modSpec = LdifModSpec.createReplace( attributeDescription );
+
for ( LdifAttrValLine attrValLine : newAttrValLines.values() )
{
modSpec.addAttrVal( attrValLine );
}
+
modSpec.finish( LdifModSpecSepLine.create() );
record.addModSpec( modSpec );
}
@@ -582,10 +633,12 @@ public class Utils
record.finish( LdifSepLine.create() );
LdifFile model = new LdifFile();
+
if ( record.isValid() && record.getModSpecs().length > 0 )
{
model.addContainer( record );
}
+
return model.getRecords().length > 0 ? model : null;
}
@@ -593,6 +646,7 @@ public class Utils
private static LdifAttrValLine computeDiffCreateAttrValLine( IValue value )
{
IAttribute attribute = value.getAttribute();
+
if ( attribute.isBinary() )
{
return LdifAttrValLine.create( attribute.getDescription(), value.getBinaryValue() );