Search in sources :

Example 1 with MRegistration

use of org.compiere.model.MRegistration in project adempiere by adempiere.

the class WebInfo method getRegistrations.

//	getExpense
/**
	 * 	Get Registrations
	 *	@return registrations
	 */
public ArrayList<MRegistration> getRegistrations() {
    m_infoMessage = null;
    ArrayList<MRegistration> list = new ArrayList<MRegistration>();
    String sql = "SELECT * FROM A_Registration " + "WHERE C_BPartner_ID=? " + "ORDER BY Created DESC";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, null);
        pstmt.setInt(1, getC_BPartner_ID());
        rs = pstmt.executeQuery();
        while (rs.next()) list.add(new MRegistration(m_ctx, rs, null));
    } catch (Exception e) {
        log.log(Level.SEVERE, sql, e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    log.fine("#" + list.size());
    return list;
}
Also used : ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) MRegistration(org.compiere.model.MRegistration)

Example 2 with MRegistration

use of org.compiere.model.MRegistration in project adempiere by adempiere.

the class WebInfo method getRegistration.

//	getRegistrations
/**
	 * 	Get Registration.
	 * 	Needs to have ID set first
	 *	@return invoice of BP with ID
	 */
public MRegistration getRegistration() {
    m_infoMessage = null;
    MRegistration retValue = null;
    String sql = "SELECT * FROM A_Registration WHERE C_BPartner_ID=? AND A_Registration_ID=?";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, null);
        pstmt.setInt(1, getC_BPartner_ID());
        pstmt.setInt(2, m_id);
        rs = pstmt.executeQuery();
        if (rs.next())
            retValue = new MRegistration(m_ctx, rs, null);
    } catch (Exception e) {
        log.log(Level.SEVERE, "A_Registration_ID=" + m_id, e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    //	new registration
    if (retValue == null)
        retValue = new MRegistration(m_ctx, 0, null);
    log.fine("A_Registration_ID=" + m_id + " - " + retValue);
    return retValue;
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) MRegistration(org.compiere.model.MRegistration)

Example 3 with MRegistration

use of org.compiere.model.MRegistration in project adempiere by adempiere.

the class RegistrationServlet method processSystemRegistration.

//  doGet
/**
	 * 	Process System Registration
	 *	@param request request
	 *	@param response response
	 *	@return true if System Registration
	 */
private boolean processSystemRegistration(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    //	System Info
    String name = WebUtil.getParameter(request, "Name");
    String userName = WebUtil.getParameter(request, "UserName");
    String password = WebUtil.getParameter(request, "Password");
    //	Not a System registration
    if ((name == null || name.length() == 0) && (userName == null || userName.length() == 0) && (password == null || password.length() == 0))
        return false;
    log.info("Name=" + name + ", User=" + userName);
    //	Registration Info
    String description = WebUtil.getParameter(request, "Description");
    boolean inProduction = WebUtil.getParameterAsBoolean(request, "IsInProduction", "Y");
    Timestamp startDate = WebUtil.getParameterAsDate(request, "StartProductionDate");
    if (startDate == null)
        startDate = new Timestamp(System.currentTimeMillis());
    boolean allowPublish = WebUtil.getParameterAsBoolean(request, "IsAllowPublish", "Y");
    boolean registered = WebUtil.getParameterAsBoolean(request, "IsRegistered", "Y");
    int Record_ID = WebUtil.getParameterAsInt(request, "Record_ID");
    //	Find User
    Properties ctx = JSPEnv.getCtx(request);
    MUser user = null;
    int AD_User_ID = DB.getSQLValue(null, "SELECT AD_User_ID FROM AD_User WHERE EMail=?", userName);
    if (AD_User_ID > 0)
        user = MUser.get(ctx, AD_User_ID);
    else
        log.warning("User Not found=" + userName);
    //	Registration
    MRegistration reg = null;
    if (Record_ID > 0) {
        reg = new MRegistration(ctx, Record_ID, null);
        if (reg.get_ID() != Record_ID) {
            log.warning("Registration Not found=" + Record_ID);
            reg = null;
        } else if (user != null) {
            if (reg.getC_BPartner_ID() != user.getC_BPartner_ID()) {
                log.warning("Registration for different BP - AD_User_ID=" + AD_User_ID + "(" + user.getEMail() + "), BP RegistrationBP=" + reg.getC_BPartner_ID() + "<>UserBP=" + user.getC_BPartner_ID());
                reg = null;
            }
            if (!password.equals(user.getPassword())) {
                log.warning("Password does not match - AD_User_ID=" + AD_User_ID + "(" + user.getEMail() + ")");
            //	??
            }
        }
    }
    if (reg == null) {
        log.fine("New Registration");
        reg = new MRegistration(ctx, name, allowPublish, inProduction, startDate, null);
        Record_ID = 0;
    }
    //	Common Update
    reg.setDescription(description);
    reg.setRemote_Addr(request.getRemoteAddr());
    reg.setRemote_Host(request.getRemoteHost());
    //	User
    if (user != null) {
        reg.setAD_User_ID(user.getAD_User_ID());
        reg.setC_BPartner_ID(user.getC_BPartner_ID());
    }
    if (reg.save()) {
        if (Record_ID == 0)
            //	new
            reg.loadAttributeValues(request);
        else
            //	existing
            reg.updateAttributeValues(request);
        sendAnswer(response, THANKS + " Record_ID=" + reg.getA_Registration_ID());
    } else {
        log.log(Level.SEVERE, "Registration not saved");
        sendAnswer(response, PROBLEM + " Record_ID=0");
    }
    return true;
}
Also used : Properties(java.util.Properties) Timestamp(java.sql.Timestamp) MUser(org.compiere.model.MUser) MRegistration(org.compiere.model.MRegistration)

Example 4 with MRegistration

use of org.compiere.model.MRegistration in project adempiere by adempiere.

the class RegistrationServlet method doPost.

//	sendAnswer
/**************************************************************************
	 *  Process the HTTP Post request
	 *
	 *  @param request request
	 *  @param response response
	 *  @throws ServletException
	 *  @throws IOException
	 */
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    log.info("From " + request.getRemoteHost() + " - " + request.getRemoteAddr());
    //  Get Session attributes
    HttpSession session = request.getSession(true);
    session.removeAttribute(WebSessionCtx.HDR_MESSAGE);
    //
    Properties ctx = JSPEnv.getCtx(request);
    WebUser wu = (WebUser) session.getAttribute(WebUser.NAME);
    if (wu == null) {
        log.warning("No web user");
        //	entry
        response.sendRedirect("loginServlet?ForwardTo=registration.jsp");
        return;
    }
    int A_Registration_ID = WebUtil.getParameterAsInt(request, P_REGISTRATION_ID);
    MRegistration reg = null;
    if (A_Registration_ID > 0)
        reg = new MRegistration(ctx, A_Registration_ID, null);
    if (reg == null) {
        reg = new MRegistration(ctx, 0, null);
        A_Registration_ID = 0;
    }
    //
    String name = WebUtil.getParameter(request, "Name");
    if (name == null || name.length() == 0) {
        WebUtil.createForwardPage(response, "Name is Mandatory", "registrations.jsp", 4);
        return;
    }
    reg.setC_BPartner_ID(wu.getBpartnerID());
    reg.setName(name);
    String description = WebUtil.getParameter(request, "Description");
    if (description != null && description.length() > 0)
        reg.setDescription(description);
    boolean isInProduction = WebUtil.getParameterAsBoolean(request, "IsInProduction");
    reg.setIsInProduction(isInProduction);
    Timestamp assetServiceDate = WebUtil.getParameterAsDate(request, "AssetServiceDate");
    if (assetServiceDate == null)
        assetServiceDate = new Timestamp(System.currentTimeMillis());
    reg.setAssetServiceDate(assetServiceDate);
    boolean isAllowPublish = WebUtil.getParameterAsBoolean(request, "IsAllowPublish");
    reg.setIsAllowPublish(isAllowPublish);
    if (reg.save()) {
        if (A_Registration_ID == 0)
            //	new
            reg.loadAttributeValues(request);
        else
            //	existing
            reg.updateAttributeValues(request);
        WebUtil.createForwardPage(response, THANKS, "registrations.jsp", 3);
    } else {
        log.log(Level.SEVERE, "Registration not saved");
        WebUtil.createForwardPage(response, PROBLEM, "registrations.jsp", 3);
    }
}
Also used : HttpSession(javax.servlet.http.HttpSession) WebUser(org.compiere.util.WebUser) Properties(java.util.Properties) Timestamp(java.sql.Timestamp) MRegistration(org.compiere.model.MRegistration)

Aggregations

MRegistration (org.compiere.model.MRegistration)4 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 Timestamp (java.sql.Timestamp)2 Properties (java.util.Properties)2 ArrayList (java.util.ArrayList)1 HttpSession (javax.servlet.http.HttpSession)1 MUser (org.compiere.model.MUser)1 WebUser (org.compiere.util.WebUser)1