/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package sikd.sikd5.sikd5service;

import java.util.Properties;

import javax.ejb.Stateless;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.naming.Context;

import sikd.sikd5.sikd5bean.fault.SIKDServiceException;
import sikd.sikd5.sikd5bean.tabel.mgr.TUserAccount;
import sikd.sikd5.sikd5bean.util.PropertiesLoader;
import sikd.sikd5.sikd5bean.util.ServerUtil;
import sikd.sikd5.sikd5bean.util.SikdSessionUtil;
import sikd.sikd5.sikd5ejb.session.login.LoginSessionBeanRemote;
import sikd.sikd5.sikd5service.util.XmlSikdUtil;

/**
 *
 * @author agus
 */
@WebService(serviceName = "SubregistryService")
@Stateless
public class SubregistryService {


	@WebMethod(operationName = "inputSubregistryPdf")
//    @SuppressWarnings("null")
	public String inputSubregistryPdf(@WebParam(name = "kodeSatker") String kodeSatker,
			@WebParam(name = "kodePemda") String kodePemda,
			@WebParam(name = "tahun") short tahun, 
			@WebParam(name = "userName") String userName,
			@WebParam(name = "password") String password, @WebParam(name = "berkasSubregistry") byte[] berkasSubregistry)
			throws SIKDServiceException {
	
		String result = "Gagal";
		try {
			short bulan = 1;
			Context ctxOffice = ServerUtil.getOfficeContextV3();
			LoginSessionBeanRemote sessionLogin = (LoginSessionBeanRemote) ctxOffice
					.lookup(SikdSessionUtil.LOGIN_SESSION);
			XmlSikdUtil.cekParamSimpatik(kodeSatker, kodePemda, tahun, bulan, userName, password);
			TUserAccount tuserAccount = sessionLogin.getUserAccountbyName(userName);
			XmlSikdUtil.cekLoginService(kodeSatker, kodePemda, userName, password, tuserAccount);
			String kdikd = "SUB";
			String uploadPath = ((Properties) PropertiesLoader.loadProperties("sikd.properties"))
					.getProperty("uploadPath");
			XmlSikdUtil.cekBerkasPdf(berkasSubregistry);
			String filename = XmlSikdUtil.copyInsertPdf(uploadPath, kdikd, bulan, kodeSatker, tahun, berkasSubregistry);
			
			result = "Berhasil";
			return result;
		} catch (Exception e) {
			result = e.getMessage();
			throw new SIKDServiceException(result);
		}
	}

	
}
