hg merge release-2.0 (merge release2 into development)

This commit is contained in:
Carlos Ruiz 2014-04-23 18:20:20 -05:00
commit e7a19cb6b0
7 changed files with 92 additions and 39 deletions

View File

@ -0,0 +1,10 @@
SET SQLBLANKLINES ON
SET DEFINE OFF
-- Apr 8, 2014 3:18:45 PM CEST
-- IDEMPIERE-1891
INSERT INTO AD_Message (AD_Client_ID,AD_Message_ID,AD_Message_UU,AD_Org_ID,Created,CreatedBy,EntityType,IsActive,MsgText,MsgType,Updated,UpdatedBy,Value) VALUES (0,200269,'0b36ffa9-8364-4d93-8d9a-1e3eae4aa81b',0,TO_DATE('2014-04-08 15:18:44','YYYY-MM-DD HH24:MI:SS'),100,'D','Y','You cannot access process {0} with your role : {1}','I',TO_DATE('2014-04-08 15:18:44','YYYY-MM-DD HH24:MI:SS'),100,'CannotAccessProcess')
;
SELECT register_migration_script('201404081520_IDEMPIERE-1891.sql') FROM dual
;

View File

@ -0,0 +1,7 @@
-- Apr 8, 2014 3:18:45 PM CEST
-- IDEMPIERE-1891
INSERT INTO AD_Message (AD_Client_ID,AD_Message_ID,AD_Message_UU,AD_Org_ID,Created,CreatedBy,EntityType,IsActive,MsgText,MsgType,Updated,UpdatedBy,Value) VALUES (0,200269,'0b36ffa9-8364-4d93-8d9a-1e3eae4aa81b',0,TO_TIMESTAMP('2014-04-08 15:18:44','YYYY-MM-DD HH24:MI:SS'),100,'D','Y','You cannot access process {0} with your role : {1}','I',TO_TIMESTAMP('2014-04-08 15:18:44','YYYY-MM-DD HH24:MI:SS'),100,'CannotAccessProcess')
;
SELECT register_migration_script('201404081520_IDEMPIERE-1891.sql') FROM dual
;

View File

@ -326,7 +326,7 @@ public class ImportProduct extends SvrProcess implements ImportProcess
// Verify ProductType
sql = new StringBuilder ("UPDATE I_Product ")
.append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid ProductType,' ")
.append("WHERE ProductType NOT IN ('E','I','R','S')")
.append("WHERE ProductType NOT IN ('E','I','R','S','A')")
.append(" AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0)

View File

@ -19,6 +19,7 @@ package org.compiere.process;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.UnknownHostException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
@ -38,7 +39,9 @@ import javax.mail.Part;
import javax.mail.Session;
import javax.mail.Store;
import org.adempiere.exceptions.AdempiereException;
import org.compiere.model.MAttachment;
import org.compiere.model.MColumn;
import org.compiere.model.MRequest;
import org.compiere.model.MUser;
import org.compiere.util.CLogMgt;
@ -54,6 +57,7 @@ import org.compiere.util.EMailAuthenticator;
public class RequestEMailProcessor extends SvrProcess
{
protected String p_IMAPHost = null;
protected int p_IMAPPort = 143;
protected String p_IMAPUser = null;
protected String p_IMAPPwd = null;
protected String p_RequestFolder = null;
@ -133,7 +137,20 @@ public class RequestEMailProcessor extends SvrProcess
*/
protected String doIt() throws Exception
{
int portStartIndex = p_IMAPHost.lastIndexOf(":");
if (portStartIndex > 0){
String strPort = p_IMAPHost.substring(portStartIndex + 1, p_IMAPHost.length());
p_IMAPHost = p_IMAPHost.substring(0, portStartIndex);
try{
p_IMAPPort = Integer.parseInt(strPort);
}catch (Exception ex){
throw new AdempiereException("Error format port : " + strPort);
}
}else if (p_IMAPHost.startsWith("imap.gmail.com")){
p_IMAPPort = 993;
}
if (log.isLoggable(Level.INFO)) log.info("doIt - IMAPHost=" + p_IMAPHost +
" IMAPPort=" + p_IMAPPort +
" IMAPUser=" + p_IMAPUser +
// " IMAPPwd=" + p_IMAPPwd +
" RequestFolder=" + p_RequestFolder +
@ -145,21 +162,27 @@ public class RequestEMailProcessor extends SvrProcess
getSession();
getStore();
processInBox();
} catch (MessagingException mailEx) {
if (mailEx.getNextException() != null && mailEx.getNextException() instanceof UnknownHostException){
throw new AdempiereException("Error host : " + mailEx.getMessage());
} else {
throw new AdempiereException("Error when make connect to email server : " + mailEx.getMessage());
}
} catch (AdempiereException ae) {
throw ae;
}
catch (Exception e)
{
catch (Exception e) {
log.log(Level.SEVERE, "processInBox", e);
throw e;
}finally {
// Cleanup
try
{
if ( m_store != null && m_store.isConnected())
m_store.close();
} catch(Exception ex) {}
}
// Cleanup
try
{
if (m_store.isConnected())
m_store.close();
}
catch (Exception e)
{
}
StringBuilder msgreturn = new StringBuilder("processInBox - Total=").append(noProcessed)
.append(" - Requests=").append(noRequest)
.append(" - Errors=").append(noError);
@ -178,13 +201,14 @@ public class RequestEMailProcessor extends SvrProcess
// Session
Properties props = System.getProperties();
props.put("mail.store.protocol", "smtp");
props.put("mail.transport.protocol", "smtp");
props.put("mail.store.protocol", "imap");
props.put("mail.transport.protocol", "imap");
props.put("mail.host", p_IMAPHost);
props.put("mail.smtp.auth","true");
props.put("mail.imap.port", p_IMAPPort);
EMailAuthenticator auth = new EMailAuthenticator (p_IMAPUser, p_IMAPPwd);
//
m_session = Session.getDefaultInstance(props, auth);
m_session = Session.getInstance(props, auth);
m_session.setDebug(CLogMgt.isLevelFinest());
if (log.isLoggable(Level.FINE)) log.fine("getSession - " + m_session);
return m_session;
@ -204,7 +228,10 @@ public class RequestEMailProcessor extends SvrProcess
throw new IllegalStateException("No Session");
// Get IMAP Store
m_store = m_session.getStore("imap");
if (p_IMAPHost.startsWith("imap.gmail.com"))
m_store = m_session.getStore("imaps");
else
m_store = m_session.getStore("imap");
// Connect
m_store.connect();
//
@ -227,7 +254,7 @@ public class RequestEMailProcessor extends SvrProcess
// Open Inbox
Folder inbox = folder.getFolder(p_InboxFolder);
if (!inbox.exists())
throw new IllegalStateException("No Inbox");
throw new AdempiereException ("Wrong inbox name : " + p_InboxFolder);
inbox.open(Folder.READ_WRITE);
if (log.isLoggable(Level.FINE)) log.fine("processInBox - " + inbox.getName()
+ "; Messages Total=" + inbox.getMessageCount()
@ -236,7 +263,7 @@ public class RequestEMailProcessor extends SvrProcess
// Open Request
Folder requestFolder = folder.getFolder(p_RequestFolder);
if (!requestFolder.exists() && !requestFolder.create(Folder.HOLDS_MESSAGES))
throw new IllegalStateException("Cannot create Request Folder");
throw new AdempiereException ("Cannot create request folder : " + p_RequestFolder);
requestFolder.open(Folder.READ_WRITE);
// Open Workflow
@ -248,7 +275,7 @@ public class RequestEMailProcessor extends SvrProcess
// Open Error
Folder errorFolder = folder.getFolder(p_ErrorFolder);
if (!errorFolder.exists() && !errorFolder.create(Folder.HOLDS_MESSAGES))
throw new IllegalStateException("Cannot create Error Folder");
throw new AdempiereException ("Cannot create Error Folder : " + p_ErrorFolder);
errorFolder.open(Folder.READ_WRITE);
// Messages
@ -284,6 +311,8 @@ public class RequestEMailProcessor extends SvrProcess
Message[] deleted = inbox.expunge();
noRequest++;
} else {
noError++;
}
} catch (Exception e) {
if (log.isLoggable(Level.INFO)) log.info("message " + hdrs[0] + " threw error");
@ -344,20 +373,27 @@ public class RequestEMailProcessor extends SvrProcess
}
// Message-ID as documentNo
String[] hdrs = msg.getHeader("Message-ID");
// set DocumentNo
int maxlen = MColumn.get(getCtx(), MRequest.Table_Name, MRequest.COLUMNNAME_DocumentNo).getFieldLength();
String documentNo = hdrs[0];
if (documentNo.startsWith("<") && documentNo.endsWith(">"))
documentNo = documentNo.substring(1, documentNo.length()-1);
if (documentNo.length() > maxlen)
documentNo = documentNo.substring(0,30);
// Review if the e-mail was already created, comparing Message-ID+From+body
int retValuedup = 0;
String sqldup = "select r_request_id from r_request "
+ "where ad_client_id = ? "
+ "and documentno = ? "
+ "and startdate = ?";
String sqldup = "SELECT R_Request_ID FROM R_Request "
+ "WHERE AD_Client_ID = ? "
+ "AND DocumentNo = ? "
+ "AND StartDate = ?";
PreparedStatement pstmtdup = null;
ResultSet rsdup = null;
try
{
pstmtdup = DB.prepareStatement (sqldup, null);
pstmtdup.setInt(1, getAD_Client_ID());
pstmtdup.setString(2, hdrs[0].substring(0,30));
pstmtdup.setString(2, documentNo);
pstmtdup.setTimestamp(3, new Timestamp(msg.getSentDate().getTime()));
rsdup = pstmtdup.executeQuery ();
if (rsdup.next ())
@ -436,8 +472,7 @@ public class RequestEMailProcessor extends SvrProcess
msgreq = new StringBuilder("FROM: ") .append(from[0].toString()).append("\n").append(getMessage(msg));
req.setResult(msgreq.toString());
// Message-ID as documentNo
if (hdrs != null)
req.setDocumentNo(hdrs[0].substring(0,30));
req.setDocumentNo(documentNo);
// Default request type for this process
if (R_RequestType_ID > 0)
@ -528,9 +563,8 @@ public class RequestEMailProcessor extends SvrProcess
String disposition = part.getDisposition();
if ((disposition != null) &&
((disposition.equals(Part.ATTACHMENT) ||
(disposition.equals(Part.INLINE))))) {
if ( disposition != null
&& (disposition.equalsIgnoreCase(Part.ATTACHMENT) || disposition.equalsIgnoreCase(Part.INLINE))) {
MAttachment attach = req.createAttachment();

View File

@ -211,8 +211,7 @@ public class MPInstance extends X_AD_PInstance
MRole role = MRole.get(getCtx(), AD_Role_ID);
Boolean access = role.getProcessAccess(AD_Process_ID);
if (access == null || !access.booleanValue())
throw new IllegalAccessError("Cannot access Process " + AD_Process_ID
+ " with role: " + role.getName());
throw new IllegalAccessError(Msg.getMsg(getCtx(), "CannotAccessProcess", new Object[] {AD_Process_ID, role.getName()}));
}
super.setAD_Process_ID (AD_Process_ID);
} // setAD_Process_ID

View File

@ -2581,12 +2581,15 @@ public final class MRole extends X_AD_Role
while (rs.next()) {
String op = rs.getString(1);
String active=rs.getString(2);
if ("N".equals(active) && validOptions.contains(op)) {
validOptions.remove(op);
if ("N".equals(active)) {
if (validOptions.contains(op)) {
validOptions.remove(op);
}
} else {
if (!validOptions.contains(op))
validOptions.add(op);
}
if (!validOptions.contains(op)) {
validOptions.add(op);
}
}
}
}

View File

@ -926,7 +926,7 @@ public class MUser extends X_AD_User
}
}
if (newRecord || is_ValueChanged("Password")) {
if (getPassword() != null && getPassword().length() > 0 && (newRecord || is_ValueChanged("Password"))) {
// Validate password policies / IDEMPIERE-221
if (get_ValueOld("Salt") == null && get_Value("Salt") != null) { // being hashed
;