/*
 * Copyright 2011-2016 B2i Healthcare Pte Ltd, http://b2i.sg
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.b2international.snowowl.datastore.request;

import com.b2international.commons.options.OptionsBuilder;
import com.b2international.snowowl.core.ServiceProvider;
import com.b2international.snowowl.core.events.Request;
import com.b2international.snowowl.core.merge.Merge;
import com.b2international.snowowl.core.merge.MergeCollection;

/**
 * @since 4.6
 */
public class SearchMergeRequestBuilder {

	private final String repositoryId;
	private final OptionsBuilder optionsBuilder = OptionsBuilder.newBuilder();
	
	public SearchMergeRequestBuilder(String repositoryId) {
		this.repositoryId = repositoryId;
	}

	public SearchMergeRequestBuilder withSource(String source) {
		optionsBuilder.put("source", source);
		return this;
	}

	public SearchMergeRequestBuilder withTarget(String target) {
		optionsBuilder.put("target", target);
		return this;
	}

	public SearchMergeRequestBuilder withStatus(Merge.Status status) {
		optionsBuilder.put("status", status);
		return this;
	}

	public Request<ServiceProvider, MergeCollection> build() {
		return RepositoryRequests.wrap(repositoryId, new SearchMergeRequest(optionsBuilder.build()));
	}
}

@@ -677,16 +677,65 @@
 quest;%0A%0A
+import com.b2international.commons.CompareUtils;%0A
 import c
@@ -1348,24 +1348,64 @@
 g source) %7B%0A
+%09%09if (!CompareUtils.isEmpty(source)) %7B%0A%09
 %09%09optionsBui
@@ -1432,16 +1432,20 @@
 ource);%0A
+%09%09%7D%0A
 %09%09return
@@ -1513,24 +1513,64 @@
 g target) %7B%0A
+%09%09if (!CompareUtils.isEmpty(target)) %7B%0A%09
 %09%09optionsBui
@@ -1597,16 +1597,20 @@
 arget);%0A
+%09%09%7D%0A
 %09%09return
@@ -1688,16 +1688,56 @@
 atus) %7B%0A
+%09%09if (!CompareUtils.isEmpty(status)) %7B%0A%09
 %09%09option
@@ -1768,16 +1768,20 @@
 tatus);%0A
+%09%09%7D%0A
 %09%09return

Check empty value before adding search option for merge entries