/***************************************************************************
                   Volume Information Class ( VolumeInfo.cpp )
                -----------------------------------------

	begin      : 2013/03/14
	copyright  : (C) 2013 Solbox Inc.
	author     : Development 1 Team
					- 2013/03/14 - 1st dadamin
	email      : dev1@solbox.com
	version    : 3.2.0

	CopyRight(C) 2005 Solbox Inc. All Rights reserved.
	Redistribution and use in source and binary forms, with or with out
	modification, are not permitted in outside of Solbox Inc.
***************************************************************************/
#include "rc_mngd.h"
#include "Job.h"
#include "VolumeInfo.h"
#include "JobData.h"
#include "Logger.h"

CVolumeInfo::CVolumeInfo()
{

}

CVolumeInfo::~CVolumeInfo()
{

}

int CVolumeInfo::run( CJobDataMap &jobData )
{
	int r = JOB_SUCCESS;
	_LOG( LDBG, "Job Volume Information running...");

	// rcdb
	CRCDBControl rcdb;

	if( rcdb.Init() != 0 )
	{
		LOG( LERR, "RCDB Initialization failed.");
		return JOB_ERR_CREATION_FAIL;
	}

	bool userexist = false, productexist = false; 
		
	while ( 1 )
	{
		int t = 0;
		// check info
		t = ExistInfo(rcdb, jobData);
		if ( t != 1 )
		{
			r = t;
			LOG( LERR, "Base information check error.");
			break;
		}

		// check password
		if( !CheckIdentify(jobData) )
		{
			r = JOB_ERR_MISS_PASSWROD;
			break;	
		}

		// find volume info
		if( !rcdb.GetVolumeInformation(jobData) )
		{
			r = JOB_ERR_GET_VOLUME_INFO;
			break;
		}

		break;
	}

	if(r != 0)
	{
		LOG(LERR, "Volume Information error.[%d][%s@%s]", r, 
			jobData[KEY_SP_SVC_ID].c_str(),	jobData[KEY_SP_USER_ID].c_str());
	}
	else
	{
		_LOG(LINF, "Volume Information success.[%s@%s]",
			jobData[KEY_SP_SVC_ID].c_str(),	jobData[KEY_SP_USER_ID].c_str());
	}

	rcdb.Final();

	_LOG( LDBG, "Job Volume Information End.");
	return r;
}
