/*
 * Copyright 2016 EPAM Systems
 * 
 * 
 * This file is part of EPAM Report Portal.
 * https://github.com/reportportal/service-api
 * 
 * Report Portal is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Report Portal is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Report Portal.  If not, see <http://www.gnu.org/licenses/>.
 */ 

package com.epam.ta.reportportal.ws.converter.builders;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.epam.ta.reportportal.database.entity.ServerSettings;
import com.epam.ta.reportportal.ws.model.settings.ServerEmailConfig;
import com.epam.ta.reportportal.ws.model.settings.ServerSettingsResource;

/**
 * Email server settings resource response assembler
 * 
 * @author Andrei_Ramanchuk
 */
@Service
@Scope("prototype")
public class ServerSettingsResourceBuilder extends ResourceBuilder<ServerSettingsResource> {

	public ServerSettingsResourceBuilder addServerSettings(ServerSettings doc) {
		ServerSettingsResource resource = getObject();
		resource.setProfile(doc.getId());
		resource.setActive(doc.getActive());
		ServerEmailConfig output = new ServerEmailConfig();
		output.setHost(doc.getServerEmailConfig().getHost());
		output.setPort(doc.getServerEmailConfig().getPort());
		output.setProtocol(doc.getServerEmailConfig().getProtocol());
		output.setAuthEnabled(doc.getServerEmailConfig().getAuthEnabled());
		output.setSslEnabled(doc.getServerEmailConfig().isSslEnabled());
		output.setStarTlsEnabled(doc.getServerEmailConfig().isStarTlsEnabled());
		if (doc.getServerEmailConfig().getAuthEnabled()) {
			output.setUsername(doc.getServerEmailConfig().getUsername());
			/* Password field not provided in response */
		}
		resource.setServerEmailConfig(output);
		return this;
	}

	@Override
	protected ServerSettingsResource initObject() {
		return new ServerSettingsResource();
	}
}
@@ -784,17 +784,16 @@
 s/%3E.%0A */
- 
 %0A%0Apackag
@@ -847,109 +847,8 @@
 s;%0A%0A
-import org.springframework.context.annotation.Scope;%0Aimport org.springframework.stereotype.Service;%0A%0A
 impo
@@ -1049,16 +1049,116 @@
 esource;
+%0Aimport org.springframework.context.annotation.Scope;%0Aimport org.springframework.stereotype.Service;
 %0A%0A/**%0A *
@@ -1210,17 +1210,16 @@
 mbler%0A *
- 
 %0A * @aut
@@ -1568,16 +1568,61 @@
 ive());%0A
+%09%09if (null != doc.getServerEmailConfig()) %7B%0A%09
 %09%09Server
@@ -1665,24 +1665,25 @@
 Config();%0A%09%09
+%09
 output.setHo
@@ -1720,24 +1720,25 @@
 getHost());%0A
+%09
 %09%09output.set
@@ -1779,24 +1779,25 @@
 tPort());%0A%09%09
+%09
 output.setPr
@@ -1842,24 +1842,25 @@
 rotocol());%0A
+%09
 %09%09output.set
@@ -1911,32 +1911,33 @@
 thEnabled());%0A%09%09
+%09
 output.setSslEna
@@ -1985,16 +1985,17 @@
 led());%0A
+%09
 %09%09output
@@ -2059,24 +2059,25 @@
 abled());%0A%09%09
+%09
 if (doc.getS
@@ -2115,16 +2115,17 @@
 ed()) %7B%0A
+%09
 %09%09%09outpu
@@ -2232,18 +2232,20 @@
 se */%0A%09%09
+%09
 %7D%0A
+%09
 %09%09resour
@@ -2277,16 +2277,21 @@
 utput);%0A
+%09%09%7D%0A%0A
 %09%09return

fix possible NPE in ServerSettingsResourceBuilder