📄 registersystem.java
字号:
/******************************************************************************
* The contents of this file are subject to the Compiere License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the License at http://www.compiere.org/license.html
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is Compiere ERP & CRM Smart Business Solution. The Initial
* Developer of the Original Code is Jorg Janke. Portions created by Jorg Janke
* are Copyright (C) 1999-2005 Jorg Janke.
* All parts are Copyright (C) 1999-2005 ComPiere, Inc. All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.process;
import java.io.*;
import java.net.*;
import java.util.logging.*;
import org.compiere.model.*;
import org.compiere.util.*;
/**
* System Registration
*
* @author Jorg Janke
* @version $Id: RegisterSystem.java,v 1.11 2005/12/13 00:15:27 jjanke Exp $
*/
public class RegisterSystem extends SvrProcess
{
/**
* Prepare - e.g., get Parameters.
*/
protected void prepare()
{
ProcessInfoParameter[] para = getParameter();
for (int i = 0; i < para.length; i++)
{
String name = para[i].getParameterName();
if (para[i].getParameter() == null)
;
else
log.log(Level.SEVERE, "prepare - Unknown Parameter: " + name);
}
} // prepare
/**
* DoIt
* @return Message
* @throws Exception
*/
protected String doIt() throws Exception
{
int AD_Registration_ID = getRecord_ID();
log.info("doIt - AD_Registration_ID=" + AD_Registration_ID);
// Check Ststem
MSystem sys = MSystem.get(getCtx());
if (sys.getName().equals("?") || sys.getName().length()<2)
throw new CompiereUserError("Set System Name in System Record");
if (sys.getUserName().equals("?") || sys.getUserName().length()<2)
throw new CompiereUserError("Set User Name (as in Web Store) in System Record");
if (sys.getPassword().equals("?") || sys.getPassword().length()<2)
throw new CompiereUserError("Set Password (as in Web Store) in System Record");
// Registration
M_Registration reg = new M_Registration (getCtx(), AD_Registration_ID, get_TrxName());
// Location
MLocation loc = null;
if (reg.getC_Location_ID() > 0)
{
loc = new MLocation (getCtx(), reg.getC_Location_ID(), get_TrxName());
if (loc.getCity() == null || loc.getCity().length() < 2)
throw new CompiereUserError("No City in Address");
}
if (loc == null)
throw new CompiereUserError("Please enter Address with City");
// Create Query String
String enc = WebEnv.ENCODING;
// Send GET Request
StringBuffer urlString = new StringBuffer ("http://www.compiere.com")
.append("/wstore/registrationServlet?");
// System Info
urlString.append("Name=").append(URLEncoder.encode(sys.getName(), enc))
.append("&UserName=").append(URLEncoder.encode(sys.getUserName(), enc))
.append("&Password=").append(URLEncoder.encode(sys.getPassword(), enc));
// Registration Info
if (reg.getDescription() != null && reg.getDescription().length() > 0)
urlString.append("&Description=").append(URLEncoder.encode(reg.getDescription(), enc));
urlString.append("&IsInProduction=").append(reg.isInProduction() ? "Y" : "N");
if (reg.getStartProductionDate() != null)
urlString.append("&StartProductionDate=").append(URLEncoder.encode(String.valueOf(reg.getStartProductionDate()), enc));
urlString.append("&IsAllowPublish=").append(reg.isAllowPublish() ? "Y" : "N")
.append("&NumberEmployees=").append(URLEncoder.encode(String.valueOf(reg.getNumberEmployees()), enc))
.append("&C_Currency_ID=").append(URLEncoder.encode(String.valueOf(reg.getC_Currency_ID()), enc))
.append("&SalesVolume=").append(URLEncoder.encode(String.valueOf(reg.getSalesVolume()), enc));
if (reg.getIndustryInfo() != null && reg.getIndustryInfo().length() > 0)
urlString.append("&IndustryInfo=").append(URLEncoder.encode(reg.getIndustryInfo(), enc));
if (reg.getPlatformInfo() != null && reg.getPlatformInfo().length() > 0)
urlString.append("&PlatformInfo=").append(URLEncoder.encode(reg.getPlatformInfo(), enc));
urlString.append("&IsRegistered=").append(reg.isRegistered() ? "Y" : "N")
.append("&Record_ID=").append(URLEncoder.encode(String.valueOf(reg.getRecord_ID()), enc));
// Address
urlString.append("&City=").append(URLEncoder.encode(loc.getCity(), enc))
.append("&C_Country_ID=").append(URLEncoder.encode(String.valueOf(loc.getC_Country_ID()), enc));
// Statistics
if (reg.isAllowStatistics())
{
urlString.append("&NumClient=").append(URLEncoder.encode(String.valueOf(
DB.getSQLValue(null, "SELECT Count(*) FROM AD_Client")), enc))
.append("&NumOrg=").append(URLEncoder.encode(String.valueOf(
DB.getSQLValue(null, "SELECT Count(*) FROM AD_Org")), enc))
.append("&NumBPartner=").append(URLEncoder.encode(String.valueOf(
DB.getSQLValue(null, "SELECT Count(*) FROM C_BPartner")), enc))
.append("&NumUser=").append(URLEncoder.encode(String.valueOf(
DB.getSQLValue(null, "SELECT Count(*) FROM AD_User")), enc))
.append("&NumProduct=").append(URLEncoder.encode(String.valueOf(
DB.getSQLValue(null, "SELECT Count(*) FROM M_Product")), enc))
.append("&NumInvoice=").append(URLEncoder.encode(String.valueOf(
DB.getSQLValue(null, "SELECT Count(*) FROM C_Invoice")), enc));
}
log.fine(urlString.toString());
// Send it
URL url = new URL (urlString.toString());
StringBuffer sb = new StringBuffer();
try
{
URLConnection uc = url.openConnection();
InputStreamReader in = new InputStreamReader(uc.getInputStream());
int c;
while ((c = in.read()) != -1)
sb.append((char)c);
in.close();
}
catch (Exception e)
{
log.log(Level.SEVERE, "Connect - " + e.toString());
throw new IllegalStateException("Cannot connect to Server - Please try later");
}
//
String info = sb.toString();
log.info("Response=" + info);
// Record at the end
int index = sb.indexOf("Record_ID=");
if (index != -1)
{
try
{
int Record_ID = Integer.parseInt(sb.substring(index+10));
reg.setRecord_ID(Record_ID);
reg.setIsRegistered(true);
reg.save();
//
info = info.substring(0, index);
}
catch (Exception e)
{
log.log(Level.SEVERE, "Record - ", e);
}
}
return info;
} // doIt
} // RegisterSystem
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -