package mx.nic.rdap.server.renderer.json;

import java.util.List;
import java.util.Map;

import javax.json.Json;
import javax.json.JsonArray;
import javax.json.JsonArrayBuilder;
import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;

import mx.nic.rdap.core.db.DsData;
import mx.nic.rdap.server.PrivacyStatus;
import mx.nic.rdap.server.PrivacyUtil;

public class DsDataParser {

	public static JsonArray getJsonArray(List<DsData> dsDataList, boolean isAuthenticated, boolean isOwner) {
		JsonArrayBuilder builder = Json.createArrayBuilder();

		Map<String, PrivacyStatus> privacySettings = PrivacyUtil.getDsDataPrivacySettings();
		for (DsData dsData : dsDataList) {
			getJsonObject(dsData, isAuthenticated, isOwner, privacySettings);
		}

		return builder.build();
	}

	public static JsonObject getJsonObject(DsData dsData, boolean isAuthenticated, boolean isOwner,
			Map<String, PrivacyStatus> privacySettings) {
		JsonObjectBuilder builder = Json.createObjectBuilder();
		String key = "keyTag";
		Integer intValue = dsData.getKeytag();
		if (PrivacyUtil.isObjectVisible(intValue, key, privacySettings.get(key), isAuthenticated, isOwner))
			builder.add(key, intValue);

		key = "algorithm";
		intValue = dsData.getAlgorithm();
		if (PrivacyUtil.isObjectVisible(intValue, key, privacySettings.get(key), isAuthenticated, isOwner))
			builder.add(key, intValue);

		key = "digest";
		String stringValue = dsData.getDigest();
		if (PrivacyUtil.isObjectVisible(stringValue, key, privacySettings.get(key), isAuthenticated, isOwner))
			builder.add(key, stringValue);

		key = "digestType";
		intValue = dsData.getDigestType();
		if (PrivacyUtil.isObjectVisible(intValue, key, privacySettings.get(key), isAuthenticated, isOwner))
			builder.add(key, intValue);

		key = "events";
		if (PrivacyUtil.isObjectVisible(dsData.getEvents(), key, privacySettings.get(key), isAuthenticated, isOwner))
			builder.add(key, EventParser.getJsonArray(dsData.getEvents(), isAuthenticated, isOwner,
					PrivacyUtil.getDomainEventPrivacySettings(), PrivacyUtil.getDomainLinkPrivacySettings()));

		key = "links";
		if (PrivacyUtil.isObjectVisible(dsData.getLinks(), key, privacySettings.get(key), isAuthenticated, isOwner))
			builder.add(key, LinkParser.getJsonArray(dsData.getLinks(), isAuthenticated, isOwner,
					PrivacyUtil.getDomainLinkPrivacySettings()));

		return builder.build();
	}

}

@@ -697,16 +697,28 @@
 ) %7B%0D%0A%09%09%09
+builder.add(
 getJsonO
@@ -773,16 +773,17 @@
 ettings)
+)
 ;%0D%0A%09%09%7D%0D%0A

Fix bug in DsData parser DsDatas were not being added to Json Builder