diff --git a/migration/i1.0a-release/oracle/201302110600_IDEMPIERE-454.sql b/migration/i1.0a-release/oracle/201302110600_IDEMPIERE-454.sql new file mode 100644 index 0000000000..14fac9c1df --- /dev/null +++ b/migration/i1.0a-release/oracle/201302110600_IDEMPIERE-454.sql @@ -0,0 +1,73 @@ +-- Feb 11, 2013 5:42:41 PM COT +-- IDEMPIERE-454 Easy import +INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Client_ID,AD_Org_ID,Created) VALUES ('E','Table name {0} does not correspond to the parent''s table name {1}',200146,'D','18535f25-f9d7-47c0-9c21-de68afa04444','DiffTableName','Y',TO_DATE('2013-02-11 17:42:40','YYYY-MM-DD HH24:MI:SS'),100,100,0,0,TO_DATE('2013-02-11 17:42:40','YYYY-MM-DD HH24:MI:SS')) +; + +-- Feb 11, 2013 5:42:41 PM COT +-- IDEMPIERE-454 Easy import +INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Message_Trl_UU ) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200146 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID) +; + +-- Feb 11, 2013 5:43:20 PM COT +-- IDEMPIERE-454 Easy import +INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Client_ID,AD_Org_ID,Created) VALUES ('I','Record not processed, due to master record failure',200147,'D','ffc51041-2111-4944-9ac5-35d7688194ef','NotProcessed','Y',TO_DATE('2013-02-11 17:43:20','YYYY-MM-DD HH24:MI:SS'),100,100,0,0,TO_DATE('2013-02-11 17:43:20','YYYY-MM-DD HH24:MI:SS')) +; + +-- Feb 11, 2013 5:43:20 PM COT +-- IDEMPIERE-454 Easy import +INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Message_Trl_UU ) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200147 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID) +; + +-- Feb 11, 2013 5:45:35 PM COT +-- IDEMPIERE-454 Easy import +INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Client_ID,AD_Org_ID,Created) VALUES ('I','Different parent value: Master value {0} Detail value {1}',200148,'D','3516b3e0-6f8c-458d-af58-b6e22e6f0156','DiffParentValue','Y',TO_DATE('2013-02-11 17:45:35','YYYY-MM-DD HH24:MI:SS'),100,100,0,0,TO_DATE('2013-02-11 17:45:35','YYYY-MM-DD HH24:MI:SS')) +; + +-- Feb 11, 2013 5:45:35 PM COT +-- IDEMPIERE-454 Easy import +INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Message_Trl_UU ) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200148 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID) +; + +-- Mar 11, 2013 3:58:04 PM COT +-- IDEMPIERE-454 Easy import +INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Client_ID,AD_Org_ID,Created) VALUES ('E','Csv file must not contain ''>'' in header record {0}. ',200152,'D','1d9054fa-48d7-4e65-b74a-3164eaa156b8','WrongHeader','Y',TO_DATE('2013-03-11 15:58:02','YYYY-MM-DD HH24:MI:SS'),100,100,0,0,TO_DATE('2013-03-11 15:58:02','YYYY-MM-DD HH24:MI:SS')) +; + +-- Mar 11, 2013 3:58:04 PM COT +-- IDEMPIERE-454 Easy import +INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Message_Trl_UU ) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200152 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID) +; + +-- Mar 11, 2013 3:59:21 PM COT +-- IDEMPIERE-454 Easy import +INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Client_ID,AD_Org_ID,Created) VALUES ('E','No child tab was found with such table {0}. ',200153,'D','027a1bdf-7b45-4afc-93c5-a6113b5f1acb','NoChildTab','Y',TO_DATE('2013-03-11 15:59:20','YYYY-MM-DD HH24:MI:SS'),100,100,0,0,TO_DATE('2013-03-11 15:59:20','YYYY-MM-DD HH24:MI:SS')) +; + +-- Mar 11, 2013 3:59:21 PM COT +-- IDEMPIERE-454 Easy import +INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Message_Trl_UU ) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200153 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID) +; + +-- Mar 11, 2013 4:10:39 PM COT +-- IDEMPIERE-454 Easy import +INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Client_ID,AD_Org_ID,Created) VALUES ('E','Wrong detail name{0}, it must contain the character ''>'':{1} ',200154,'D','b82cafbc-f6d0-4002-b358-a4a9783f77c2','WrongDetailName','Y',TO_DATE('2013-03-11 16:10:38','YYYY-MM-DD HH24:MI:SS'),100,100,0,0,TO_DATE('2013-03-11 16:10:38','YYYY-MM-DD HH24:MI:SS')) +; + +-- Mar 11, 2013 4:10:39 PM COT +-- IDEMPIERE-454 Easy import +INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Message_Trl_UU ) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200154 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID) +; + +-- Mar 11, 2013 4:12:48 PM COT +-- IDEMPIERE-454 Easy import +INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Client_ID,AD_Org_ID,Created) VALUES ('E','Parent value cannot be deleted {0}!',200155,'D','31e87e31-75b2-4555-8251-5d5d7dfe7ada','NoParentDelete','Y',TO_DATE('2013-03-11 16:12:47','YYYY-MM-DD HH24:MI:SS'),100,100,0,0,TO_DATE('2013-03-11 16:12:47','YYYY-MM-DD HH24:MI:SS')) +; + +-- Mar 11, 2013 4:12:48 PM COT +-- IDEMPIERE-454 Easy import +INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Message_Trl_UU ) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200155 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID) +; + +SELECT register_migration_script('201302110600_IDEMPIERE-454.sql') FROM dual +; + diff --git a/migration/i1.0a-release/oracle/201303081134_IDEMPIERE-714.sql b/migration/i1.0a-release/oracle/201303081134_IDEMPIERE-714.sql new file mode 100644 index 0000000000..fad9a9f5ce --- /dev/null +++ b/migration/i1.0a-release/oracle/201303081134_IDEMPIERE-714.sql @@ -0,0 +1,42 @@ +-- Mar 8, 2013 11:17:42 AM COT +UPDATE AD_Field SET SeqNo=10, IsDisplayed='Y', XPosition=1,Updated=TO_DATE('2013-03-08 11:17:42','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=59414 +; + +-- Mar 8, 2013 11:17:42 AM COT +UPDATE AD_Field SET SeqNo=40, IsDisplayed='Y', XPosition=4,Updated=TO_DATE('2013-03-08 11:17:42','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=59416 +; + +-- Mar 8, 2013 11:17:42 AM COT +UPDATE AD_Field SET SeqNo=50,Updated=TO_DATE('2013-03-08 11:17:42','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=59448 +; + +-- Mar 8, 2013 11:17:42 AM COT +UPDATE AD_Field SET ColumnSpan=2, SeqNo=60, IsDisplayed='Y', XPosition=1,Updated=TO_DATE('2013-03-08 11:17:42','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=59418 +; + +-- Mar 8, 2013 11:17:42 AM COT +UPDATE AD_Field SET SeqNo=70,Updated=TO_DATE('2013-03-08 11:17:42','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=59415 +; + +-- Mar 8, 2013 11:17:42 AM COT +UPDATE AD_Field SET SeqNo=80, IsDisplayed='Y', XPosition=4,Updated=TO_DATE('2013-03-08 11:17:42','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=59417 +; + +-- Mar 8, 2013 11:17:42 AM COT +UPDATE AD_Field SET SeqNo=350,Updated=TO_DATE('2013-03-08 11:17:42','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=59446 +; + +-- Mar 8, 2013 11:17:42 AM COT +UPDATE AD_Field SET SeqNo=360,Updated=TO_DATE('2013-03-08 11:17:42','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=59447 +; + +-- Mar 8, 2013 11:17:42 AM COT +UPDATE AD_Field SET SeqNo=370,Updated=TO_DATE('2013-03-08 11:17:42','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=59449 +; + +-- Mar 8, 2013 11:17:42 AM COT +UPDATE AD_Field SET SeqNo=0,Updated=TO_DATE('2013-03-08 11:17:42','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=59445 +; + +SELECT register_migration_script('201303081134_IDEMPIERE-714.sql') FROM dual +; diff --git a/migration/i1.0a-release/postgresql/201302110600_IDEMPIERE-454.sql b/migration/i1.0a-release/postgresql/201302110600_IDEMPIERE-454.sql new file mode 100644 index 0000000000..93e31de144 --- /dev/null +++ b/migration/i1.0a-release/postgresql/201302110600_IDEMPIERE-454.sql @@ -0,0 +1,73 @@ +-- Feb 11, 2013 5:42:41 PM COT +-- IDEMPIERE-454 Easy import +INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Client_ID,AD_Org_ID,Created) VALUES ('E','Table name {0} does not correspond to the parent''s table name {1}',200146,'D','18535f25-f9d7-47c0-9c21-de68afa04444','DiffTableName','Y',TO_TIMESTAMP('2013-02-11 17:42:40','YYYY-MM-DD HH24:MI:SS'),100,100,0,0,TO_TIMESTAMP('2013-02-11 17:42:40','YYYY-MM-DD HH24:MI:SS')) +; + +-- Feb 11, 2013 5:42:41 PM COT +-- IDEMPIERE-454 Easy import +INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Message_Trl_UU ) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200146 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID) +; + +-- Feb 11, 2013 5:43:20 PM COT +-- IDEMPIERE-454 Easy import +INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Client_ID,AD_Org_ID,Created) VALUES ('I','Record not processed, due to master record failure',200147,'D','ffc51041-2111-4944-9ac5-35d7688194ef','NotProcessed','Y',TO_TIMESTAMP('2013-02-11 17:43:20','YYYY-MM-DD HH24:MI:SS'),100,100,0,0,TO_TIMESTAMP('2013-02-11 17:43:20','YYYY-MM-DD HH24:MI:SS')) +; + +-- Feb 11, 2013 5:43:20 PM COT +-- IDEMPIERE-454 Easy import +INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Message_Trl_UU ) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200147 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID) +; + +-- Feb 11, 2013 5:45:35 PM COT +-- IDEMPIERE-454 Easy import +INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Client_ID,AD_Org_ID,Created) VALUES ('I','Different parent value: Master value {0} Detail value {1}',200148,'D','3516b3e0-6f8c-458d-af58-b6e22e6f0156','DiffParentValue','Y',TO_TIMESTAMP('2013-02-11 17:45:35','YYYY-MM-DD HH24:MI:SS'),100,100,0,0,TO_TIMESTAMP('2013-02-11 17:45:35','YYYY-MM-DD HH24:MI:SS')) +; + +-- Feb 11, 2013 5:45:35 PM COT +-- IDEMPIERE-454 Easy import +INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Message_Trl_UU ) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200148 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID) +; + +-- Mar 11, 2013 3:58:04 PM COT +-- IDEMPIERE-454 Easy import +INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Client_ID,AD_Org_ID,Created) VALUES ('E','Csv file must not contain ''>'' in header record {0}. ',200152,'D','1d9054fa-48d7-4e65-b74a-3164eaa156b8','WrongHeader','Y',TO_TIMESTAMP('2013-03-11 15:58:02','YYYY-MM-DD HH24:MI:SS'),100,100,0,0,TO_TIMESTAMP('2013-03-11 15:58:02','YYYY-MM-DD HH24:MI:SS')) +; + +-- Mar 11, 2013 3:58:04 PM COT +-- IDEMPIERE-454 Easy import +INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Message_Trl_UU ) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200152 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID) +; + +-- Mar 11, 2013 3:59:21 PM COT +-- IDEMPIERE-454 Easy import +INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Client_ID,AD_Org_ID,Created) VALUES ('E','No child tab was found with such table {0}. ',200153,'D','027a1bdf-7b45-4afc-93c5-a6113b5f1acb','NoChildTab','Y',TO_TIMESTAMP('2013-03-11 15:59:20','YYYY-MM-DD HH24:MI:SS'),100,100,0,0,TO_TIMESTAMP('2013-03-11 15:59:20','YYYY-MM-DD HH24:MI:SS')) +; + +-- Mar 11, 2013 3:59:21 PM COT +-- IDEMPIERE-454 Easy import +INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Message_Trl_UU ) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200153 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID) +; + +-- Mar 11, 2013 4:10:39 PM COT +-- IDEMPIERE-454 Easy import +INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Client_ID,AD_Org_ID,Created) VALUES ('E','Wrong detail name{0}, it must contain the character ''>'':{1} ',200154,'D','b82cafbc-f6d0-4002-b358-a4a9783f77c2','WrongDetailName','Y',TO_TIMESTAMP('2013-03-11 16:10:38','YYYY-MM-DD HH24:MI:SS'),100,100,0,0,TO_TIMESTAMP('2013-03-11 16:10:38','YYYY-MM-DD HH24:MI:SS')) +; + +-- Mar 11, 2013 4:10:39 PM COT +-- IDEMPIERE-454 Easy import +INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Message_Trl_UU ) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200154 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID) +; + +-- Mar 11, 2013 4:12:48 PM COT +-- IDEMPIERE-454 Easy import +INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Client_ID,AD_Org_ID,Created) VALUES ('E','Parent value cannot be deleted {0}!',200155,'D','31e87e31-75b2-4555-8251-5d5d7dfe7ada','NoParentDelete','Y',TO_TIMESTAMP('2013-03-11 16:12:47','YYYY-MM-DD HH24:MI:SS'),100,100,0,0,TO_TIMESTAMP('2013-03-11 16:12:47','YYYY-MM-DD HH24:MI:SS')) +; + +-- Mar 11, 2013 4:12:48 PM COT +-- IDEMPIERE-454 Easy import +INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Message_Trl_UU ) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200155 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID) +; + +SELECT register_migration_script('201302110600_IDEMPIERE-454.sql') FROM dual +; + diff --git a/migration/i1.0a-release/postgresql/201303081134_IDEMPIERE-714.sql b/migration/i1.0a-release/postgresql/201303081134_IDEMPIERE-714.sql new file mode 100644 index 0000000000..b487ee2159 --- /dev/null +++ b/migration/i1.0a-release/postgresql/201303081134_IDEMPIERE-714.sql @@ -0,0 +1,42 @@ +-- Mar 8, 2013 11:17:42 AM COT +UPDATE AD_Field SET SeqNo=10, IsDisplayed='Y', XPosition=1,Updated=TO_TIMESTAMP('2013-03-08 11:17:42','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=59414 +; + +-- Mar 8, 2013 11:17:42 AM COT +UPDATE AD_Field SET SeqNo=40, IsDisplayed='Y', XPosition=4,Updated=TO_TIMESTAMP('2013-03-08 11:17:42','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=59416 +; + +-- Mar 8, 2013 11:17:42 AM COT +UPDATE AD_Field SET SeqNo=50,Updated=TO_TIMESTAMP('2013-03-08 11:17:42','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=59448 +; + +-- Mar 8, 2013 11:17:42 AM COT +UPDATE AD_Field SET ColumnSpan=2, SeqNo=60, IsDisplayed='Y', XPosition=1,Updated=TO_TIMESTAMP('2013-03-08 11:17:42','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=59418 +; + +-- Mar 8, 2013 11:17:42 AM COT +UPDATE AD_Field SET SeqNo=70,Updated=TO_TIMESTAMP('2013-03-08 11:17:42','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=59415 +; + +-- Mar 8, 2013 11:17:42 AM COT +UPDATE AD_Field SET SeqNo=80, IsDisplayed='Y', XPosition=4,Updated=TO_TIMESTAMP('2013-03-08 11:17:42','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=59417 +; + +-- Mar 8, 2013 11:17:42 AM COT +UPDATE AD_Field SET SeqNo=350,Updated=TO_TIMESTAMP('2013-03-08 11:17:42','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=59446 +; + +-- Mar 8, 2013 11:17:42 AM COT +UPDATE AD_Field SET SeqNo=360,Updated=TO_TIMESTAMP('2013-03-08 11:17:42','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=59447 +; + +-- Mar 8, 2013 11:17:42 AM COT +UPDATE AD_Field SET SeqNo=370,Updated=TO_TIMESTAMP('2013-03-08 11:17:42','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=59449 +; + +-- Mar 8, 2013 11:17:42 AM COT +UPDATE AD_Field SET SeqNo=0,Updated=TO_TIMESTAMP('2013-03-08 11:17:42','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=59445 +; + +SELECT register_migration_script('201303081134_IDEMPIERE-714.sql') FROM dual +; \ No newline at end of file diff --git a/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVExporter.java b/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVExporter.java index c6d51580ee..52a8cf29e8 100644 --- a/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVExporter.java +++ b/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVExporter.java @@ -24,6 +24,7 @@ import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.logging.Level; import org.adempiere.base.IGridTabExporter; import org.adempiere.exceptions.AdempiereException; @@ -31,16 +32,20 @@ import org.adempiere.model.MTabCustomization; import org.compiere.model.GridField; import org.compiere.model.GridTab; import org.compiere.model.GridTable; +import org.compiere.model.GridWindow; +import org.compiere.model.GridWindowVO; import org.compiere.model.MColumn; +import org.compiere.model.MLocation; import org.compiere.model.MQuery; import org.compiere.model.MRefList; +import org.compiere.model.MTab; import org.compiere.model.MTable; +import org.compiere.util.CLogger; import org.compiere.util.DB; import org.compiere.util.DisplayType; import org.compiere.util.Env; import org.compiere.util.Msg; import org.compiere.util.Util; -import org.jfree.util.Log; import org.supercsv.cellprocessor.FmtBool; import org.supercsv.cellprocessor.FmtDate; import org.supercsv.cellprocessor.FmtNumber; @@ -57,6 +62,9 @@ import org.supercsv.prefs.CsvPreference; */ public class GridTabCSVExporter implements IGridTabExporter { + /** Logger */ + private static CLogger log = CLogger.getCLogger(GridTabCSVExporter.class); + @Override public void export(GridTab gridTab, List childs, boolean currentRowOnly, File file) { @@ -66,9 +74,9 @@ public class GridTabCSVExporter implements IGridTabExporter MTable tableDetail = null; try { mapWriter = new CsvMapWriter(new FileWriter(file), CsvPreference.STANDARD_PREFERENCE); - String IsValidTab = IsValidTabToExport(gridTab); - if (IsValidTab!=null){ - Log.info(IsValidTab); + String isValidTab = isValidTabToExport(gridTab); + if (isValidTab!=null){ + if (log.isLoggable(Level.INFO)) log.info(isValidTab); return; } GridTable gt = gridTab.getTableModel(); @@ -76,10 +84,16 @@ public class GridTabCSVExporter implements IGridTabExporter List headArray = new ArrayList(); List procArray = new ArrayList(); table = MTable.get(Env.getCtx(), gridTab.getTableName()); + int specialHDispayType = 0; //master tab for (int idxfld = 0; idxfld < gridFields.length; idxfld++) { GridField field = gridFields[idxfld]; MColumn column = MColumn.get(Env.getCtx(), field.getAD_Column_ID()); + //Special Columns + if(DisplayType.Location == column.getAD_Reference_ID()){ + specialHDispayType = DisplayType.Location; + continue; + } String headName = resolveColumnName(table, column); headArray.add(headName); if (DisplayType.Date == column.getAD_Reference_ID()) { @@ -94,27 +108,42 @@ public class GridTabCSVExporter implements IGridTabExporter procArray.add(new Optional(new FmtNumber(nf))); } else if (DisplayType.YesNo == column.getAD_Reference_ID()) { procArray.add(new Optional(new FmtBool("Y", "N"))); - } else { // lookups and text - procArray.add(null); + } else { // lookups + procArray.add(new Optional()); } - } + } + + if(specialHDispayType > 0){ + for(String specialHeader:resolveSpecialColumnName(specialHDispayType)){ + headArray.add(specialHeader); + procArray.add(null); + } + } //Details up to tab level 1 - if(childs.size() > 0){ + if(childs.size() > 0){ + int specialDetDispayType = 0; for(GridTab detail: childs){ + //comment this line if you want to export all tabs + if(detail.getTabNo()>1) + break; - if (detail.getTabLevel()>1) - continue; - - IsValidTab = IsValidTabToExport(detail); - if (IsValidTab!=null){ - Log.info(IsValidTab); + if(detail.getTabLevel()>1) + continue; + + isValidTab = isValidTabToExport(detail); + if (isValidTab!=null){ + if (log.isLoggable(Level.INFO)) log.info(isValidTab); continue; } tableDetail = MTable.get(Env.getCtx(), detail.getTableName()); gridFields = getFields(detail); for(GridField field : gridFields){ MColumn columnDetail = MColumn.get(Env.getCtx(), field.getAD_Column_ID()); - String headNameDetail =detail.getTableName()+">"+resolveColumnName(tableDetail, columnDetail); + if(DisplayType.Location == columnDetail.getAD_Reference_ID()){ + specialDetDispayType = DisplayType.Location; + continue; + } + String headNameDetail= detail.getTableName()+">"+resolveColumnName(tableDetail, columnDetail); headArray.add(headNameDetail); if (DisplayType.Date == columnDetail.getAD_Reference_ID()) { procArray.add(new Optional(new FmtDate(DisplayType.DEFAULT_DATE_FORMAT))); @@ -129,9 +158,15 @@ public class GridTabCSVExporter implements IGridTabExporter } else if (DisplayType.YesNo == columnDetail.getAD_Reference_ID()) { procArray.add(new Optional(new FmtBool("Y", "N"))); } else { // lookups and text - procArray.add(null); + procArray.add(new Optional()); } } + if(specialDetDispayType > 0){ + for(String specialHeader:resolveSpecialColumnName(specialDetDispayType)){ + headArray.add(specialHeader); + procArray.add(null); + } + } tabMapDetails.put(detail,gridFields); } gridFields = null; @@ -156,16 +191,52 @@ public class GridTabCSVExporter implements IGridTabExporter int idxfld = 0; int index =0; int rowDetail=0; - + int record_Id = 0; + for(GridField field : getFields(gridTab)){ MColumn column = MColumn.get(Env.getCtx(), field.getAD_Column_ID()); + + if(DisplayType.Location == column.getAD_Reference_ID()){ + Object fResolved =resolveValue(gridTab, table, column, idxrow, column.getColumnName()); + + if (fResolved!=null) + record_Id= Integer.parseInt(fResolved.toString()); + + continue; + } + String headName = header[idxfld]; Object value = resolveValue(gridTab, table, column, idxrow, headName); - row.put(headName, value); + row.put(headName,value); idxfld++; index++; } + if(specialHDispayType > 0 && record_Id > 0){ + switch(specialHDispayType) { + case DisplayType.Location: + MLocation address = new MLocation (Env.getCtx(),record_Id,null); + for(String specialHeader:resolveSpecialColumnName(specialHDispayType)){ + String columnName = specialHeader.substring(specialHeader.indexOf(">")+1,specialHeader.length()); + Object sValue = null; + if (columnName.indexOf("[") >= 0 && columnName .endsWith("]")){ + int indx = columnName.indexOf("["); + String columnRef= columnName.substring(indx+1,columnName.length()-1); + String tableRef = columnName.substring(0,indx); + Object record_id= address.get_Value(tableRef); + if (record_id!=null) + sValue = queryExecute(columnRef,tableRef,record_id); + }else{ + sValue = address.get_Value(columnName); + } + row.put(specialHeader, sValue); + idxfld++; + index++; + } + break; + } + } + while(true){ if(childs.size()>0){ Map tmpRow = resolveMasterDetailRow(rowDetail,tabMapDetails,headArray,index,gridTab.getKeyID(idxrow), gridTab.getKeyColumnName()); @@ -176,7 +247,7 @@ public class GridTabCSVExporter implements IGridTabExporter row.put(detailColumn , value); } rowDetail++; - mapWriter.write(row, header, processors); + mapWriter.write(row, header,processors); }else{ break; } @@ -186,7 +257,7 @@ public class GridTabCSVExporter implements IGridTabExporter } if(rowDetail==0) - mapWriter.write(row, header, processors); + mapWriter.write(row, header,processors); idxfld=0; } @@ -201,18 +272,19 @@ public class GridTabCSVExporter implements IGridTabExporter } } } - } //add constraints to not allow certain tabs - private String IsValidTabToExport(GridTab gridTab){ + private String isValidTabToExport(GridTab gridTab){ String result=null; - - if(gridTab.isReadOnly()) + + MTab tab = new MTab(Env.getCtx(), gridTab.getAD_Tab_ID(), null); + + if (tab.isReadOnly()) result = Msg.getMsg(Env.getCtx(),"FieldIsReadOnly", new Object[] {gridTab.getName()}); - if(gridTab.getTableName().endsWith("_Acct")) - result = "Accounting Tab cannot be exported "+ gridTab.getName(); + if (gridTab.getTableName().endsWith("_Acct")) + result = "Accounting Tab are not exported by default: "+ gridTab.getName(); return result; } @@ -221,6 +293,7 @@ public class GridTabCSVExporter implements IGridTabExporter Map row = new HashMap(); Object value = null; boolean hasDetails = false; + int specialDetDispayType = 0; if (currentDetRow > 0 ) for(int j =0;j 0) { - for(GridField field : childTabDetail.getValue()){ + int specialRecordId = 0; + for(GridField field : childTabDetail.getValue()){ MColumn column = MColumn.get(Env.getCtx(), field.getAD_Column_ID()); - MTable tableDetail = MTable.get(Env.getCtx(), childTab.getTableName()); + if(DisplayType.Location == column.getAD_Reference_ID()){ + specialDetDispayType = DisplayType.Location; + Object fResolved = resolveValue(childTab, MTable.get(Env.getCtx(),childTab.getTableName()), column, currentDetRow,column.getColumnName()); + if(fResolved!=null) + specialRecordId = Integer.parseInt(fResolved.toString()); + + continue; + } + MTable tableDetail = MTable.get(Env.getCtx(), childTab.getTableName()); String headName = headArray.get(headArray.indexOf(childTab.getTableName()+">"+resolveColumnName(tableDetail,column))); value = resolveValue(childTab, MTable.get(Env.getCtx(),childTab.getTableName()), column, currentDetRow, headName.substring(headName.indexOf(">")+ 1,headName.length())); row.put(headName, value); if (value!=null) hasDetails = true; - } + } + if(specialDetDispayType > 0 && specialRecordId > 0){ + MLocation address = new MLocation (Env.getCtx(),specialRecordId,null); + for(String specialHeader:resolveSpecialColumnName(specialDetDispayType)){ + String columnName = specialHeader.substring(specialHeader.indexOf(">")+1,specialHeader.length()); + Object sValue = null; + if (columnName.indexOf("[") >= 0 && columnName .endsWith("]")){ + int indx = columnName.indexOf("["); + String columnRef= columnName.substring(indx+1,columnName.length()-1); + String tableRef = columnName.substring(0,indx); + Object record_id= address.get_Value(tableRef); + if(record_id!=null) + sValue = queryExecute(columnRef,tableRef,record_id); + }else{ + sValue = address.get_Value(columnName); + } + row.put(specialHeader, sValue); + } + } } } if (hasDetails) @@ -284,7 +384,17 @@ public class GridTabCSVExporter implements IGridTabExporter } return value; } - + + private Object queryExecute(String selectColumn,String tableName,Object record_id){ + + StringBuilder select = new StringBuilder("SELECT ") + .append(selectColumn).append(" FROM ") + .append(tableName.substring(0,tableName.length()-3)).append(" WHERE ") + .append(tableName).append("=?"); + + return DB.getSQLValueStringEx(null, select.toString(),record_id); + } + private String resolveColumnName(MTable table, MColumn column) { StringBuilder name = new StringBuilder(column.getColumnName()); if (DisplayType.isLookup(column.getAD_Reference_ID())) { @@ -305,7 +415,33 @@ public class GridTabCSVExporter implements IGridTabExporter } return name.toString(); } - + + private ArrayList resolveSpecialColumnName(int displayType){ + + ArrayList specialColumnNames = new ArrayList(); + if (DisplayType.Location == displayType ){ + GridWindowVO gWindowVO = Env.getMWindowVO(0,121,0); + GridWindow m_mWindow = new GridWindow (gWindowVO); + GridTab m_mTab = m_mWindow.getTab(0); + m_mWindow.initTab(0); + for(GridField locField:m_mTab.getFields()){ + if("AD_Client_ID".equals(locField.getColumnName())) + continue; + if("AD_Org_ID".equals(locField.getColumnName())) + continue; + if("IsActive".equals(locField.getColumnName())) + continue; + if(!locField.isDisplayed()) + continue; + + String fName = resolveColumnName(MTable.get(Env.getCtx(), m_mTab.getTableName()),MColumn.get(Env.getCtx(), locField.getAD_Column_ID())); + specialColumnNames.add(m_mTab.getTableName()+">"+ fName); + } + } + + return specialColumnNames; + } + @Override public String getFileExtension() { return "csv"; diff --git a/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVImporter.java b/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVImporter.java index 60f5594749..2df8fc4363 100644 --- a/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVImporter.java +++ b/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVImporter.java @@ -24,18 +24,24 @@ import java.sql.Timestamp; import java.text.DecimalFormatSymbols; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Arrays; import java.util.Calendar; +import java.util.Comparator; +import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Map.Entry; -import java.util.logging.Level; +import java.util.TreeMap; import java.util.UUID; +import java.util.logging.Level; import org.adempiere.base.IGridTabImporter; import org.adempiere.exceptions.AdempiereException; import org.compiere.model.GridField; import org.compiere.model.GridTab; +import org.compiere.model.GridWindow; +import org.compiere.model.GridWindowVO; import org.compiere.model.MColumn; +import org.compiere.model.MLocation; import org.compiere.model.MQuery; import org.compiere.model.MTable; import org.compiere.model.PO; @@ -54,7 +60,6 @@ import org.supercsv.cellprocessor.ParseBool; import org.supercsv.cellprocessor.ParseDate; import org.supercsv.cellprocessor.ParseInt; import org.supercsv.cellprocessor.constraint.StrMinMax; -import org.supercsv.cellprocessor.constraint.StrNotNullOrEmpty; import org.supercsv.cellprocessor.ift.CellProcessor; import org.supercsv.exception.SuperCsvCellProcessorException; import org.supercsv.io.CsvMapReader; @@ -76,182 +81,183 @@ public class GridTabCSVImporter implements IGridTabImporter private static CLogger log = CLogger.getCLogger(GridTabCSVImporter.class); boolean m_isError = false; - public File fileImport(GridTab gridTab, List childs, InputStream filestream, Charset charset , String importMode) { + public File fileImport(GridTab gridTab, List childs, InputStream filestream, Charset charset , String importMode) { ICsvMapReader mapReader = null; File errFile = null; File logFile = null; PrintWriter errFileW = null; PrintWriter logFileW = null; + GridTab currentDetailTab = null; CsvPreference csvpref = CsvPreference.STANDARD_PREFERENCE; String delimiter = String.valueOf((char) csvpref.getDelimiterChar()); String quoteChar = String.valueOf((char) csvpref.getQuoteChar()); IMPORT_MODE = importMode; - boolean isThereKey = false; + + if(!gridTab.isInsertRecord() && IMPORT_MODE.equals("I")) + throw new AdempiereException("Insert record disabled for Tab"); + try { String errFileName = FileUtil.getTempMailName("Import_" + gridTab.getTableName(), "_err.csv"); errFile = new File(errFileName); errFileW = new PrintWriter(errFile, charset.name()); mapReader = new CsvMapReader(new InputStreamReader(filestream, charset), csvpref); - - String[] header = mapReader.getHeader(true); + List header = Arrays.asList(mapReader.getHeader(true)); List readProcArray = new ArrayList(); - for (int idx = 0; idx < header.length; idx++) { - String headName = header[idx]; - if (headName.equals(ERROR_HEADER) || headName.equals(LOG_HEADER)) { - header[idx] = null; + Map tabMapIndexes = new HashMap(); + int indxDetail=0; + List locationFields = null; + boolean isThereKey = false; + //Mapping header + for(int idx = 0; idx < header.size(); idx++) { + String headName = header.get(idx); + if (headName.equals(ERROR_HEADER) || headName.equals(LOG_HEADER)){ + header.set(idx, null); readProcArray.add(null); continue; } - String columnName = headName; - boolean isKeyColumn = false; - if ( columnName.indexOf("/") > 0 ){ - if(columnName.endsWith("K")){ - isKeyColumn =true; - columnName = headName.substring(0,headName.length()-2); - }else{ - throw new AdempiereException(Msg.getMsg(Env.getCtx(), "ColumnKey", new Object[] {columnName})); - } - } - - boolean isForeign = columnName.indexOf("[") > 0 && columnName.endsWith("]"); - if (isForeign) { - int end = columnName.indexOf("["); - columnName = columnName.substring(0, end); + if (headName.indexOf(">") > 0) { + if(idx==0){ + throw new AdempiereException(Msg.getMsg(Env.getCtx(),"WrongHeader", new Object[] {headName})); + }else if (headName.contains(MTable.getTableName(Env.getCtx(), MLocation.Table_ID)) && locationFields==null){ + locationFields = getSpecialMColumn(header,MTable.getTableName(Env.getCtx(), MLocation.Table_ID),idx); + for(GridField sField:locationFields){ + readProcArray.add(getProccesorFromColumn(MColumn.get(Env.getCtx(),sField.getAD_Column_ID()))); + indxDetail++; + } + idx=indxDetail; + }else + break; + + }else{ + boolean isKeyColumn = headName.indexOf("/") > 0; + boolean isForeing = headName.indexOf("[") > 0 && headName.indexOf("]")>0; + String columnName = getColumnName (isKeyColumn,isForeing,false,headName); + GridField field = gridTab.getField(columnName); + + if (field == null) + throw new AdempiereException(Msg.getMsg(Env.getCtx(), "FieldNotFound")+" "+columnName); + else if(isKeyColumn && !isThereKey) + isThereKey =true; + + readProcArray.add(getProccesorFromColumn(MColumn.get(Env.getCtx(),field.getAD_Column_ID()))); + indxDetail++; } - - GridField field = gridTab.getField(columnName); - if (field == null) { - throw new AdempiereException(Msg.getMsg(Env.getCtx(), "FieldNotFound", new Object[] {columnName})); - }else if(isKeyColumn && !isThereKey){ - isThereKey =true; - } - MColumn column = MColumn.get(Env.getCtx(), field.getAD_Column_ID()); - // TODO: List columns can use RequireSubStr constraint - if (column.isMandatory()) { - if (DisplayType.Date == column.getAD_Reference_ID()) { - readProcArray.add(new ParseDate(DisplayType.DEFAULT_DATE_FORMAT)); - } else if (DisplayType.DateTime == column.getAD_Reference_ID()) { - readProcArray.add(new ParseDate(DisplayType.DEFAULT_TIMESTAMP_FORMAT)); - } else if (DisplayType.Time == column.getAD_Reference_ID()) { - readProcArray.add(new ParseDate("DisplayType.DEFAULT_TIME_FORMAT")); - } else if (DisplayType.Integer == column.getAD_Reference_ID()) { - readProcArray.add(new ParseInt()); - } else if (DisplayType.isNumeric(column.getAD_Reference_ID())) { - readProcArray.add(new ParseBigDecimal(new DecimalFormatSymbols(Language.getLoginLanguage().getLocale()))); - } else if (DisplayType.YesNo == column.getAD_Reference_ID()) { - readProcArray.add(new ParseBool("y", "n")); - } else if (DisplayType.isText(column.getAD_Reference_ID())) { - readProcArray.add(new StrMinMax(1, column.getFieldLength())); - } else { // mandatory lookups - readProcArray.add(new StrNotNullOrEmpty()); - } - } else { - if (DisplayType.Date == column.getAD_Reference_ID()) { - readProcArray.add(new Optional(new ParseDate(DisplayType.DEFAULT_DATE_FORMAT))); - } else if (DisplayType.DateTime == column.getAD_Reference_ID()) { - readProcArray.add(new Optional(new ParseDate(DisplayType.DEFAULT_TIMESTAMP_FORMAT))); - } else if (DisplayType.Time == column.getAD_Reference_ID()) { - readProcArray.add(new Optional(new ParseDate("DisplayType.DEFAULT_TIME_FORMAT"))); - } else if (DisplayType.Integer == column.getAD_Reference_ID()) { - readProcArray.add(new Optional(new ParseInt())); - } else if (DisplayType.isNumeric(column.getAD_Reference_ID())) { - readProcArray.add(new Optional(new ParseBigDecimal(new DecimalFormatSymbols(Language.getLoginLanguage().getLocale())))); - } else if (DisplayType.YesNo == column.getAD_Reference_ID()) { - readProcArray.add(new Optional(new ParseBool("y", "n"))); - } else if (DisplayType.isText(column.getAD_Reference_ID())) { - readProcArray.add(new Optional(new StrMinMax(1, column.getFieldLength()))); - } else { // optional lookups and text - readProcArray.add(null); - } - } - } - if((IMPORT_MODE.equals("U") || IMPORT_MODE.equals("M")) && !isThereKey){ - throw new AdempiereException(Msg.getMsg(Env.getCtx(), "NoKeyFound")); - } - CellProcessor[] processors = readProcArray.toArray(new CellProcessor[readProcArray.size()]); + } + + if((IMPORT_MODE.equals("U") || IMPORT_MODE.equals("M")) && !isThereKey) + throw new AdempiereException(gridTab.getTableName()+": "+Msg.getMsg(Env.getCtx(), "NoKeyFound")); + + tabMapIndexes.put(gridTab,indxDetail-1); + String childTableName = null; + String initTabName = null; + isThereKey = false; + locationFields = null; + //Mapping details + for(int idx = indxDetail; idx < header.size(); idx++) { + String detailName = header.get(idx); + if(detailName.indexOf(">") > 0){ + childTableName = detailName.substring(0,detailName.indexOf(">")); + + if (currentDetailTab==null){ + for(GridTab detail: childs){ + if(detail.getTableName().equals(childTableName)){ + currentDetailTab = detail; + initTabName = currentDetailTab.getTableName(); + break; + } + } + }else if (!childTableName.contains(MTable.getTableName(Env.getCtx(), MLocation.Table_ID)) + && !childTableName.equals(initTabName))//Process just one detail + break; + + if(currentDetailTab == null) + throw new AdempiereException(Msg.getMsg(Env.getCtx(),"NoChildTab",new Object[] {childTableName})); + + String columnName = detailName; + if (columnName.contains(MTable.getTableName(Env.getCtx(), MLocation.Table_ID)) && locationFields==null){ + locationFields = getSpecialMColumn(header,MTable.getTableName(Env.getCtx(), MLocation.Table_ID),idx); + for(GridField sField:locationFields){ + readProcArray.add(getProccesorFromColumn(MColumn.get(Env.getCtx(),sField.getAD_Column_ID()))); + idx++; + } + }else{ + boolean isKeyColumn= columnName.indexOf("/") > 0; + boolean isForeing = columnName.indexOf("[") > 0 && columnName.indexOf("]")>0; + columnName = getColumnName(isKeyColumn,isForeing,true,columnName); + GridField field = currentDetailTab.getField(columnName); + + if(field == null) + throw new AdempiereException(Msg.getMsg(Env.getCtx(), "FieldNotFound")+" "+columnName); + else if(isKeyColumn && !isThereKey) + isThereKey =true; + + readProcArray.add(getProccesorFromColumn(MColumn.get(Env.getCtx(),field.getAD_Column_ID()))); + } + }else + throw new AdempiereException(Msg.getMsg(Env.getCtx(),"WrongDetailName",new Object[] {idx,detailName})); + + } + + if(currentDetailTab!=null){ + if((IMPORT_MODE.equals("U") || IMPORT_MODE.equals("M")) && !isThereKey) + throw new AdempiereException(currentDetailTab.getTableName()+": "+Msg.getMsg(Env.getCtx(), "NoKeyFound")); + + tabMapIndexes.put(currentDetailTab,header.size()-1); + } + + TreeMap sortedtTabMapIndexes= null; + if (childs.size()>0 && !tabMapIndexes.isEmpty()){ + ValueComparator bvc = new ValueComparator(tabMapIndexes); + sortedtTabMapIndexes = new TreeMap(bvc); + sortedtTabMapIndexes.putAll(tabMapIndexes); + }else{ + sortedtTabMapIndexes = new TreeMap(); + sortedtTabMapIndexes.put(currentDetailTab,header.size()-1); + } + + CellProcessor[] processors = readProcArray.toArray(new CellProcessor[readProcArray.size()]); m_isError = false; // write the header String rawHeader = mapReader.getUntokenizedRow(); errFileW.write(rawHeader + delimiter + ERROR_HEADER + "\n"); - List> data = new ArrayList>(); List rawData = new ArrayList(); // pre-process to check for errors while (true) { Map map = null; - boolean isLineError = false; + boolean isLineError = false; StringBuilder errMsg = new StringBuilder(); - try { - map = mapReader.read(header, processors); + try { + map = mapReader.read((String [])header.toArray(), processors); } catch (SuperCsvCellProcessorException e) { int idx = e.getCsvContext().getColumnNumber() - 1; - errMsg.append(header[idx]).append(": ").append(e.getMessage()); + errMsg.append(header.get(idx)).append(": ").append(e.getMessage()); isLineError = true; } String rawLine = mapReader.getUntokenizedRow(); if (! isLineError) { - if (map == null) - break; - for (Entry set : map.entrySet()) { - StringBuilder lineError = new StringBuilder(); - String headName = set.getKey(); - Object value = set.getValue(); - if (log.isLoggable(Level.FINE)) log.fine("Setting " + headName + " to " + value); - - String columnName = headName; - - boolean isKeyColumn = headName.indexOf("/") > 0 && (headName.endsWith("K")); - if (isKeyColumn) - columnName = headName.substring(0,headName.length()-2); - - boolean isForeign = columnName.indexOf("[") > 0 && columnName.endsWith("]"); - String foreignColumn = null; - if (isForeign) { - int end = columnName.indexOf("["); - columnName = columnName.substring(0, end); - int startf = headName.indexOf("[")+1; - int endf = headName.indexOf("]"); - foreignColumn = headName.substring(startf, endf); - } - - GridField field = gridTab.getField(columnName); - if (field == null) { - lineError.append(Msg.getMsg(Env.getCtx(), "NotAWindowField", new Object[] {headName})); + if(map == null) + break; + + //Re-order information coming from map + List tmpRow = getOrderedRowFromMap(header,map); + //read master and detail + int initIndx= 0; + for(Map.Entry tabIndex : sortedtTabMapIndexes.entrySet()) { + GridTab tmpGrid = tabIndex.getKey(); + if(gridTab.equals(tmpGrid) && tmpRow.get(0)==null){ + initIndx = indxDetail; + continue; + } + int endindx = tabIndex.getValue(); + StringBuilder lineError = preprocessRow (tmpGrid,header,tmpRow,initIndx,endindx); + if( lineError!= null && lineError.length() > 0 ){ isLineError = true; - } - if (!isLineError && field.isReadOnly() && !field.isParentValue()) { - lineError.append(Msg.getMsg(Env.getCtx(), "FieldIsReadOnly", new Object[] {headName})); - isLineError = true; - } - if (!isLineError && ! ( field.isDisplayed() || field.isDisplayedGrid() )) { - lineError.append(Msg.getMsg(Env.getCtx(), "FieldNotDisplayed", new Object[] {headName})); - isLineError = true; - } - if (!isLineError) { - MColumn column = MColumn.get(Env.getCtx(), field.getAD_Column_ID()); - if (isForeign && value != null){ - String foreignTable = column.getReferenceTableName(); - String idS = null; - int id = -1; - if ("AD_Ref_List".equals(foreignTable)) { - idS = resolveForeignList(column, foreignColumn, value); - } else { - id = resolveForeign(foreignTable, foreignColumn, value); - } - if (idS == null && id < 0) { - lineError.append(Msg.getMsg(Env.getCtx(), "ForeignNotResolved", new Object[] {headName, value.toString()})); - isLineError = true; - } - } else { - // no validation here - // TODO: we could validate length of string or min/max - } - } - if (isLineError && lineError.length() > 0) { if (errMsg.length() > 0) errMsg.append(" / "); - errMsg.append(lineError); + errMsg.append(lineError); } + initIndx = endindx + 1; } } if (isLineError && ! m_isError) @@ -269,144 +275,162 @@ public class GridTabCSVImporter implements IGridTabImporter String logFileName = FileUtil.getTempMailName("Import_" + gridTab.getTableName(), "_log.csv"); logFile = new File(logFileName); logFileW = new PrintWriter(logFile, charset.name()); - // write the header logFileW.write(rawHeader + delimiter + LOG_HEADER + "\n"); - - // no errors found - then process + // no errors found - process header and then details + boolean isMasterok = true; + PO masterRecord = null; for (int idx = 0; idx < data.size(); idx++) { String rawLine = rawData.get(idx); - String trxName = null; + String trxName= null; String logMsg = null; + StringBuilder rowResult = new StringBuilder(); Trx trx = null; - boolean error = false; - try { - trxName = "Import_" + gridTab.getTableName() + "_" + UUID.randomUUID(); - trx = Trx.get(trxName, true); - Map map = data.get(idx); - gridTab.getTableModel().setImportingMode(true, trxName); - - if (isThereKey) - logMsg = areValidKeysAndColumns(gridTab,map,header); - - if (logMsg == null){ - - if (IMPORT_MODE.equals("I")) - gridTab.dataNew(false); - - for (String headName : header) { - if (headName == null) - continue; - Object value = map.get(headName); - String columnName = headName; + GridTab currentGridTab=null; + boolean error=false; + boolean isDetail=false ; + int currentColumn=0; + + if (rawLine.charAt(0)==',') + isDetail=true; - boolean isKeyColumn = headName.indexOf("/") > 0 && (headName.endsWith("K")); - if (isKeyColumn) { - if(IMPORT_MODE.equals("I")) - columnName = columnName.substring(0,headName.length()-2); - if(IMPORT_MODE.equals("U"))//Key Column never updated + //if master failed, then ignore any detail from it. + if (!isMasterok && isDetail){ + rawLine = rawLine + delimiter + quoteChar + Msg.getMsg(Env.getCtx(),"NotProccesed") + quoteChar + "\n"; + logFileW.write(rawLine); + continue; + } + + try { + Map map = data.get(idx); + isMasterok = true; + if(!isDetail) + masterRecord = null; + + for(Map.Entry tabIndex : sortedtTabMapIndexes.entrySet()) { + currentGridTab =tabIndex.getKey(); + + if(isDetail && gridTab.equals(currentGridTab)){ + currentColumn=indxDetail; + continue; + } + + trxName = "Import_" + currentGridTab.getTableName() + "_" + UUID.randomUUID(); + currentGridTab.getTableModel().setImportingMode(true,trxName); + trx = Trx.get(trxName,true); + int j = tabIndex.getValue(); + + logMsg = areValidKeysAndColumns(currentGridTab,map,header,currentColumn,j); + + if (logMsg == null){ + if (IMPORT_MODE.equals("I")){ + if(!currentGridTab.getTableModel().isOpen()) + currentGridTab.getTableModel().open(0); + + currentGridTab.dataNew(false); + } + + logMsg = proccessRow(currentGridTab,header,map,currentColumn,j,masterRecord); + currentColumn = j + 1; + + if(!(logMsg == null)){ + IMPORT_MODE =importMode; + //Ignore row since there is no data + if(logMsg.equals("NO_DATA_TO_IMPORT")){ + logMsg =""; + currentGridTab.dataIgnore(); continue; - } - boolean isForeign = columnName.indexOf("[") > 0 && columnName.endsWith("]"); - String foreignColumn = null; - if (isForeign) { - int end = columnName.indexOf("["); - columnName = columnName.substring(0, end); - int startf = headName.indexOf("[")+1; - int endf = headName.indexOf("]"); - foreignColumn = headName.substring(startf, endf); - } - GridField field = gridTab.getField(columnName); - if (field.isParentValue()) - continue; - - if (!field.isEditable(true)) { - logMsg = Msg.getMsg(Env.getCtx(), "FieldNotEditable", new Object[] {headName}); - error = true; - break; + }else + error =true; } - - MColumn column = MColumn.get(Env.getCtx(), field.getAD_Column_ID()); - Object setValue = null; - if (isForeign) { - String foreignTable = column.getReferenceTableName(); - if ("AD_Ref_List".equals(foreignTable)) { - String idS = resolveForeignList(column, foreignColumn, value); - setValue = idS; - } else { - int id = resolveForeign(foreignTable, foreignColumn, value); - setValue = id; - if (field.isParentValue()) { - int actualId = (Integer) field.getValue(); - if (actualId != id) { - logMsg = Msg.getMsg(Env.getCtx(), "ParentCannotChange", new Object[] {headName}); - error = true; - break; - } - } + }else { + error =true; + currentColumn = j + 1; + } + if (! error) { + if (currentGridTab.dataSave(false)){ + PO po = currentGridTab.getTableModel().getPO(currentGridTab.getCurrentRow()); + //Keep master record for details validation + if(currentGridTab.equals(gridTab)) + masterRecord = po; + + if(IMPORT_MODE.equals("I")) + logMsg = Msg.getMsg(Env.getCtx(), "Inserted")+" "+ po.toString(); + else + logMsg = Msg.getMsg(Env.getCtx(), "Updated")+" "+ po.toString(); + + trx.commit(); + if(isDetail){ + currentGridTab.refreshParentTabs(); + currentGridTab.getTableModel().dataRequery(masterRecord.get_WhereClause(true), false, 0); } + currentGridTab.dataRefreshAll(true); } else { - if (value != null) { - if (value != null && value instanceof java.util.Date) - value = new Timestamp(((java.util.Date)value).getTime()); - - setValue = value; - } + error = true; + ValueNamePair ppE = CLogger.retrieveWarning(); + if (ppE==null) + ppE = CLogger.retrieveError(); + + String info = null; + + if (ppE != null) + info = ppE.getName(); + if (info == null) + info = ""; + + logMsg = Msg.getMsg(Env.getCtx(), "Error") + " " + Msg.getMsg(Env.getCtx(), "SaveError") + " (" + info + ")"; + currentGridTab.dataIgnore(); + trx.rollback(); + + if(!isDetail && masterRecord==null){ + isMasterok = false; + break; + } } - if (setValue != null) { - gridTab.setValue(field,setValue); - } - } - }else { - error =true; - } - if (! error) { - if (gridTab.dataSave(false)) { - PO po = gridTab.getTableModel().getPO(gridTab.getCurrentRow()); - if(IMPORT_MODE.equals("I")){ - logMsg = Msg.getMsg(Env.getCtx(), "Inserted") + po.toString(); - }else{ - logMsg = Msg.getMsg(Env.getCtx(), "Updated") + po.toString(); - } } else { - error = true; - ValueNamePair ppE = CLogger.retrieveWarning(); - String info = null; - if (ppE != null) - info = ppE.getName(); - if (info == null) - info = ""; - logMsg = Msg.getMsg(Env.getCtx(), "Error") + " " + Msg.getMsg(Env.getCtx(), "SaveError") + " (" + info + ")"; - gridTab.dataIgnore(); - } - } else { - gridTab.dataIgnore(); + currentGridTab.dataIgnore(); + error = false; + trx.rollback(); + + rowResult.append("<"+currentGridTab.getTableName()+">: "); + rowResult.append(logMsg); + rowResult.append(" / "); + currentGridTab.getTableModel().setImportingMode(false, null); + + IMPORT_MODE = importMode; + //Master Failed, thus details cannot be imported + if(!isDetail && masterRecord==null){ + isMasterok = false; + break; + } + } + rowResult.append("<"+currentGridTab.getTableName()+">: "); + rowResult.append(logMsg); + rowResult.append(" / "); + currentGridTab.getTableModel().setImportingMode(false, null); + IMPORT_MODE =importMode; } } catch (Exception e) { - logMsg = Msg.getMsg(Env.getCtx(), "Error") + " " + e.getLocalizedMessage(); + rowResult.append("<"+currentGridTab.getTableName()+">: "); + rowResult.append(Msg.getMsg(Env.getCtx(), "Error") + " " + e.getLocalizedMessage()); + rowResult.append(" / "); + currentGridTab.dataIgnore(); + trx.rollback(); error = true; - } finally { - if (trx != null) { - if (error) { - trx.rollback(); - } else { - trx.commit(); - } - trx.close(); - trx = null; - } - gridTab.getTableModel().setImportingMode(false, null); - IMPORT_MODE =importMode; + } finally { + if (trx != null) { + trx.close(); + trx = null; + } + IMPORT_MODE =importMode; } // write - logMsg = logMsg.replaceAll(delimiter, ""); - rawLine = rawLine + delimiter + quoteChar + logMsg + quoteChar + "\n"; + rawLine = rawLine + delimiter + quoteChar + rowResult.toString().replaceAll(delimiter, "") + quoteChar + "\n"; logFileW.write(rawLine); } } - } catch (IOException e) { - throw new AdempiereException(e); + throw new AdempiereException(e); } finally { try { @@ -424,38 +448,391 @@ public class GridTabCSVImporter implements IGridTabImporter e.printStackTrace(); } } + gridTab.getTableModel().dataRequery("1=1",false,0); + gridTab.dataRefreshAll(); if (logFile != null) return logFile; else - return errFile; + return errFile; } + private String getColumnName(boolean isKey ,boolean isForeing ,boolean isDetail , String headName){ + + if(isKey){ + if(headName.indexOf("/") > 0){ + if(headName.endsWith("K")) + headName = headName.substring(0,headName.length()-2); + else + throw new AdempiereException(Msg.getMsg(Env.getCtx(), "ColumnKey")+" "+headName); + } + } + + if(isForeing) + headName = headName.substring(0, headName.indexOf("[")); + + if(isDetail) + headName = headName.substring(headName.indexOf(">")+ 1,headName.length()); + + return headName; + } + + private List getSpecialMColumn(List header, String tableName, int idx) { + + List lsField = new ArrayList(); + if (tableName.equals(MTable.getTableName(Env.getCtx(), MLocation.Table_ID))){ + GridWindowVO gWindowVO = Env.getMWindowVO(0,121,0); + GridWindow m_mWindow = new GridWindow (gWindowVO); + GridTab m_mTab = m_mWindow.getTab(0); + m_mWindow.initTab(0); + for(int i = idx;i< header.size();i++){ + if (header.get(i).contains(MTable.getTableName(Env.getCtx(), MLocation.Table_ID))) { + boolean isKeyColumn = header.get(i).indexOf("/") > 0; + boolean isForeing = header.get(i).indexOf("[") > 0 && header.get(i).indexOf("]")>0; + String columnName = getColumnName (isKeyColumn,isForeing,true,header.get(i)); + GridField field = m_mTab.getField(columnName); + if (field == null) + throw new AdempiereException(Msg.getMsg(Env.getCtx(), "FieldNotFound")+" "+header.get(i)); + + lsField.add(field); + }else + break; + } + } + return lsField; + } - private String areValidKeysAndColumns(GridTab gridTab, Map map,String[] header){ + private List getOrderedRowFromMap (List header,Map map){ + List tmpRow= new ArrayList(); + for (int i = 0; i < header.size(); i++) + tmpRow.add(null); + + for(Map.Entry record : map.entrySet()) { + String Column =record.getKey(); + Object value = record.getValue(); + int toIndx= header.indexOf(Column); + tmpRow.set(toIndx, value); + } + return tmpRow; + } + + private StringBuilder preprocessRow (GridTab gridTab,List header,List tmpRow,int startindx,int endindx){ + + boolean isEmptyRow = true; + boolean isAddressValidated = false ; + StringBuilder mandatoryColumns = new StringBuilder(); + for(int i = startindx; i < endindx +1; i++){ + String columnName = header.get(i); + Object value = tmpRow.get(i); + //Validate Address + if(header.get(i).contains(MTable.getTableName(Env.getCtx(),MLocation.Table_ID)) && !isAddressValidated){ + StringBuilder specialColumns = new StringBuilder(); + specialColumns = validateSpecialFields(gridTab,header,tmpRow,i,"C_Location_ID"); + isAddressValidated = true; + if(specialColumns==null) + continue; + else + return specialColumns; + }else if (header.get(i).contains(MTable.getTableName(Env.getCtx(),MLocation.Table_ID)) && isAddressValidated){ + continue; + } + + if(value!=null) + isEmptyRow=false; + + if (log.isLoggable(Level.FINE)) log.fine("Setting " + columnName + " to " + value); + + boolean isKeyColumn = columnName.indexOf("/") > 0; + boolean isForeing = columnName.indexOf("[") > 0 && columnName.indexOf("]")>0; + boolean isDetail = columnName.indexOf(">") > 0; + columnName = getColumnName(isKeyColumn,isForeing,isDetail,columnName); + String foreignColumn=null; + if(isForeing) + foreignColumn = header.get(i).substring(header.get(i).indexOf("[")+1, header.get(i).indexOf("]")); + + GridField field=gridTab.getField(columnName); + if (field == null) + return new StringBuilder(Msg.getMsg(Env.getCtx(), "NotAWindowField")+" "+header.get(i)); + + if (field.isParentValue()) + continue; + + if (field.isReadOnly() && !field.isParentValue()) + return new StringBuilder(Msg.getMsg(Env.getCtx(), "FieldIsReadOnly")+" "+header.get(i)); + + if (!(field.isDisplayed() || field.isDisplayedGrid())) + return new StringBuilder(Msg.getMsg(Env.getCtx(), "FieldNotDisplayed")+" "+header.get(i)); + + MColumn column = MColumn.get(Env.getCtx(), field.getAD_Column_ID()); + if((field.isMandatory(true) || column.isMandatory()) && value == null && field.getDefault()==null){ + mandatoryColumns.append(" / "); + mandatoryColumns.append(header.get(i)); + } + + if (isForeing && value != null && !value.equals("(null)")){ + String foreignTable = column.getReferenceTableName(); + String idS = null; + int id = -1; + if("AD_Ref_List".equals(foreignTable)) + idS= resolveForeignList(column,foreignColumn,value); + else + id = resolveForeign(foreignTable,foreignColumn,value); + + if(idS == null && id < 0) + return new StringBuilder(Msg.getMsg(Env.getCtx(), "ForeignNotResolved")+" "+header.get(i) +" - "+value); + } else { + // no validation here + // TODO: we could validate length of string or min/max + } + } + + if(mandatoryColumns.length()>1 && !isEmptyRow) + return new StringBuilder(Msg.getMsg(Env.getCtx(), "FillMandatory")+" "+mandatoryColumns); + else + return null; + } + + private StringBuilder validateSpecialFields(GridTab gridTab,List header,List tmpRow,int i,String sField){ + + GridField field = gridTab.getField(sField); + if(field == null) + return new StringBuilder(Msg.getMsg(Env.getCtx(), "NotAWindowField")+" "+sField); + + if(field.isReadOnly() && !field.isParentValue()) + return new StringBuilder(Msg.getMsg(Env.getCtx(), "FieldIsReadOnly")+" "+field.getColumnName()); + + if(!(field.isDisplayed() || field.isDisplayedGrid())) + return new StringBuilder(Msg.getMsg(Env.getCtx(), "FieldNotDisplayed")+" "+field.getColumnName()); + + if (header.get(i).contains(MTable.getTableName(Env.getCtx(),MLocation.Table_ID))) + { + //without Region or Country any address would be invalid + boolean thereIsCountry = false ; + boolean thereIsRegion = false; + boolean isEmptyRow = true; + for(int j= i;j< header.size();j++){ + if(!header.get(j).contains(MTable.getTableName(Env.getCtx(),MLocation.Table_ID))) + break; + + String columnName = header.get(j); + Object value = tmpRow.get(j); + if(value!=null){ + if(columnName.contains("RegionName")||columnName.contains("C_Region_ID")) + thereIsRegion = true; + if(columnName.contains("C_Country_ID")) + thereIsCountry= true; + }else + continue; + + boolean isKeyColumn = columnName.indexOf("/") > 0; + boolean isForeing = columnName.indexOf("[") > 0 && columnName.indexOf("]")>0; + boolean isDetail = columnName.indexOf(">") > 0; + String foreignColumn = null; + columnName = getColumnName(isKeyColumn,isForeing,isDetail,columnName); + if(isForeing) + foreignColumn = header.get(j).substring(header.get(j).indexOf("[")+1, header.get(j).indexOf("]")); + + if(isForeing && value!=null && !value.equals("(null)")){ + String foreignTable = columnName.substring(0,columnName.length()-3); + if(resolveForeign(foreignTable,foreignColumn,value) < 0) + return new StringBuilder(Msg.getMsg(Env.getCtx(), "ForeignNotResolved")+" "+header.get(j) +" - "+value); + } + isEmptyRow=false; + } + MColumn column = MColumn.get(Env.getCtx(), field.getAD_Column_ID()); + if((field.isMandatory(true) || column.isMandatory()) && !isEmptyRow && (!thereIsRegion || !thereIsCountry)) + return new StringBuilder(Msg.getMsg(Env.getCtx(), "FillMandatory")+" "+field.getColumnName()+"["+(thereIsRegion==true?"Region":"C_Country_ID")+"]"); + } + return null; + } + + private String proccessRow(GridTab gridTab,List header, Map map,int startindx,int endindx,PO masterRecord){ + + String logMsg = null; + boolean isThereRow = false; + MLocation address = null; + for(int i = startindx ; i < endindx + 1 ; i++){ + String columnName = header.get(i); + Object value = map.get(header.get(i)); + boolean isDetail = false; + if(value == null) + continue; + + boolean isKeyColumn= columnName.indexOf("/") > 0; + boolean isForeing = columnName.indexOf("[") > 0 && columnName.indexOf("]")>0; + isDetail = columnName.indexOf(">") > 0; + columnName = getColumnName(isKeyColumn,isForeing,isDetail,columnName); + String foreignColumn = null; + Object setValue = null; + + if(isForeing) + foreignColumn = header.get(i).substring(header.get(i).indexOf("[")+1,header.get(i).indexOf("]")); + + if(header.get(i).contains(MTable.getTableName(Env.getCtx(),MLocation.Table_ID))){ + + if(address == null){ + if(IMPORT_MODE.equals("I")){ + address = new MLocation (Env.getCtx(),0,null); + }else{ + Object location = gridTab.getValue("C_Location_ID")==null?0:gridTab.getValue("C_Location_ID").toString(); + int C_Location_ID = Integer.parseInt(location.toString()); + address = new MLocation (Env.getCtx(),C_Location_ID,null); + } + } + + if(!value.toString().trim().equals("(null)")){ + if(isForeing) { + String foreignTable = columnName.substring(0,columnName.length()-3); + setValue = resolveForeign(foreignTable,foreignColumn,value); + if(foreignTable.equals("C_City")) + address.setCity(value.toString()); + }else + setValue = value; + } + address.set_ValueOfColumn(columnName,setValue); + }else{ + if(isKeyColumn && IMPORT_MODE.equals("U")) + continue; + + GridField field = gridTab.getField(columnName); + if (field.isParentValue()){ + + if(value.toString().trim().equals("(null)")){ + logMsg = Msg.getMsg(Env.getCtx(),"NoParentDelete", new Object[] {header.get(i)}); + break; + } + + if(isForeing && masterRecord!=null){ + if (masterRecord.get_Value(foreignColumn).toString().equals(value)){ + gridTab.setValue(field,masterRecord.get_ID()); + }else{ + if(value!=null){ + logMsg = header.get(i)+" - " +Msg.getMsg(Env.getCtx(),"DiffParentValue", new Object[] {masterRecord.get_Value(foreignColumn).toString(),value}); + break; + } + } + }else if (masterRecord==null && isDetail){ + MColumn column = MColumn.get(Env.getCtx(),field.getAD_Column_ID()); + String foreignTable = column.getReferenceTableName(); + String idS = null; + int id = -1; + + if ("AD_Ref_List".equals(foreignTable)) + idS= resolveForeignList(column, foreignColumn, value); + else + id = resolveForeign(foreignTable, foreignColumn, value); + + if(id >= 0) + gridTab.setValue(field,id); + else if (idS != null) + gridTab.setValue(field,idS); + } + continue; + } + + if (!field.isEditable(true) && value!=null) { + logMsg = Msg.getMsg(Env.getCtx(), "FieldNotEditable", new Object[] {header.get(i)}) + "{" + value + "}"; + break; + } + if(value.toString().trim().equals("(null)")){ + gridTab.setValue(field,null); + }else{ + + MColumn column = MColumn.get(Env.getCtx(),field.getAD_Column_ID()); + if (isForeing){ + String foreignTable = column.getReferenceTableName(); + if ("AD_Ref_List".equals(foreignTable)) { + String idS = resolveForeignList(column, foreignColumn, value); + setValue = idS; + isThereRow =true; + } else { + int id = resolveForeign(foreignTable, foreignColumn, value); + setValue = id; + if (field.isParentValue()) { + int actualId = (Integer) field.getValue(); + if (actualId != id) { + logMsg = Msg.getMsg(Env.getCtx(), "ParentCannotChange")+" "+header.get(i); + break; + } + } + isThereRow =true; + } + }else{ + if(value != null) { + if(value instanceof java.util.Date) + value = new Timestamp(((java.util.Date)value).getTime()); + + setValue = value; + isThereRow =true; + } + } + + if(setValue != null) + gridTab.setValue(field,setValue); + } + } + } + + if(address!=null){ + if (!address.save()){ + logMsg = CLogger.retrieveError()+" Address : "+address; + }else { + gridTab.setValue("C_Location_ID",address.get_ID()); + isThereRow =true; + } + } + + if(!isThereRow) + logMsg ="NO_DATA_TO_IMPORT"; + + return logMsg; + } + + private CellProcessor getProccesorFromColumn(MColumn column) { + // TODO: List columns can use RequireSubStr constraint + if (DisplayType.Date == column.getAD_Reference_ID()) { + return (new Optional(new ParseDate(DisplayType.DEFAULT_DATE_FORMAT))); + } else if (DisplayType.DateTime == column.getAD_Reference_ID()) { + return (new Optional(new ParseDate(DisplayType.DEFAULT_TIMESTAMP_FORMAT))); + } else if (DisplayType.Time == column.getAD_Reference_ID()) { + return (new Optional(new ParseDate("DisplayType.DEFAULT_TIME_FORMAT"))); + } else if (DisplayType.Integer == column.getAD_Reference_ID()) { + return (new Optional(new ParseInt())); + } else if (DisplayType.isNumeric(column.getAD_Reference_ID())) { + return (new Optional(new ParseBigDecimal(new DecimalFormatSymbols(Language.getLoginLanguage().getLocale())))); + } else if (DisplayType.YesNo == column.getAD_Reference_ID()) { + return (new Optional(new ParseBool("y", "n"))); + } else if (DisplayType.isText(column.getAD_Reference_ID())) { + return (new Optional(new StrMinMax(1, column.getFieldLength()))); + } else { // optional lookups and text + return null; + } + } + + private String areValidKeysAndColumns(GridTab gridTab, Map map,List header,int startindx,int endindx){ MQuery pquery = new MQuery(gridTab.getAD_Table_ID()); String logMsg= null; Object tmpValue=null; String columnwithKey=null; Object setValue = null; //Process columnKeys + Foreign to add restrictions. - for (int i=0 ; i< header.length; i++){ - boolean isKeyColumn = header[i].indexOf("/") > 0 && header[i].endsWith("K"); - if(isKeyColumn){ - columnwithKey = header[i].substring(0,header[i].length()-2); - boolean isForeign = columnwithKey.indexOf("[") > 0 && columnwithKey.indexOf("]") > 0; - String foreignColumn = null; - if(isForeign) { - int end = columnwithKey.indexOf("["); - columnwithKey = columnwithKey.substring(0, end); - int startf = header[i].indexOf("[")+1; - int endf = header[i].indexOf("]"); - foreignColumn = header[i].substring(startf, endf); - - if (map.get(header[i]) instanceof java.util.Date) - tmpValue = new Timestamp(((java.util.Date)map.get(header[i])).getTime()); - else - tmpValue = map.get(header[i]); - + for (int i = startindx ; i < endindx + 1 ; i++){ + boolean isKeyColumn = header.get(i).indexOf("/") > 0 && header.get(i).endsWith("K"); + if(isKeyColumn && !header.get(i).contains(MTable.getTableName(Env.getCtx(),MLocation.Table_ID))){ + boolean isForeing = header.get(i).indexOf("[") > 0 && header.get(i).indexOf("]")>0; + boolean isDetail = header.get(i).indexOf(">") > 0; + columnwithKey = getColumnName(isKeyColumn,isForeing,isDetail,header.get(i)); + + if(map.get(header.get(i)) instanceof java.util.Date) + tmpValue = new Timestamp(((java.util.Date)map.get(header.get(i))).getTime()); + else + tmpValue = map.get(header.get(i)); + + if (tmpValue==null) + continue; + + String foreignColumn = null; + if(isForeing){ + foreignColumn = header.get(i).substring(header.get(i).indexOf("[")+1,header.get(i).indexOf("]")); MColumn column = MColumn.get(Env.getCtx(), gridTab.getField(columnwithKey).getAD_Column_ID()); String foreignTable = column.getReferenceTableName(); if ("AD_Ref_List".equals(foreignTable)) { @@ -464,45 +841,43 @@ public class GridTabCSVImporter implements IGridTabImporter }else { int id = resolveForeign(foreignTable, foreignColumn, tmpValue); setValue = id; - if (gridTab.getField(columnwithKey).isParentValue()) { - int actualId = (Integer) gridTab.getField(columnwithKey).getValue(); - if (actualId != id) { - logMsg = Msg.getMsg(Env.getCtx(), "ParentCannotChange", new Object[] {header[i]}); - break; - } - } - } + } }else{ - if (map.get(header[i]) instanceof java.util.Date) - tmpValue = new Timestamp(((java.util.Date)map.get(header[i])).getTime()); - else - tmpValue = map.get(header[i]); - setValue = tmpValue ; } - pquery.addRestriction(columnwithKey,MQuery.EQUAL,setValue); + pquery.addRestriction(columnwithKey,MQuery.EQUAL,setValue); } } - gridTab.setQuery(pquery); - gridTab.query(false); - if (IMPORT_MODE.equals("I")){ - if(gridTab.getRowCount()>=1) - logMsg = Msg.getMsg(Env.getCtx(), "AlreadyExists", new Object[] {pquery}); - } - if (IMPORT_MODE.equals("U")){ - if(gridTab.getRowCount()<=0) - logMsg = Msg.getMsg(Env.getCtx(), "not.found", new Object[] {pquery}); - else if(gridTab.getRowCount()>1) - logMsg = Msg.getMsg(Env.getCtx(),"SQLErrorNotUnique", new Object[] {pquery}); - } - if (IMPORT_MODE.equals("M")){ - if(gridTab.getRowCount()==1) - IMPORT_MODE = "U"; - else if(gridTab.getRowCount()<=0) - IMPORT_MODE = "I"; - else if(gridTab.getRowCount()>1) - logMsg = Msg.getMsg(Env.getCtx(),"TooManyRows", new Object[] {pquery}); + + if (pquery.getRestrictionCount() > 0){ + + gridTab.getTableModel().dataRequery(pquery.getWhereClause(),false,0); + gridTab.setCurrentRow(0,true); + + if (IMPORT_MODE.equals("I")){ + if(gridTab.getTableModel().getRowCount()>=1) + logMsg = Msg.getMsg(Env.getCtx(), "AlreadyExists")+" "+pquery; + else + return null; + } + if (IMPORT_MODE.equals("U")){ + if(gridTab.getTableModel().getRowCount()==1) + return null; + else if(gridTab.getTableModel().getRowCount()<=0) + logMsg = Msg.getMsg(Env.getCtx(), "not.found")+" "+pquery; + else if(gridTab.getTableModel().getRowCount()>1) + logMsg = Msg.getMsg(Env.getCtx(),"TooManyRows")+" "+pquery; + } + if (IMPORT_MODE.equals("M")){ + if(gridTab.getTableModel().getRowCount()==1) + IMPORT_MODE = "U"; + else if(gridTab.getTableModel().getRowCount()<=0) + IMPORT_MODE = "I"; + else if(gridTab.getTableModel().getRowCount()>1) + logMsg = Msg.getMsg(Env.getCtx(),"TooManyRows")+" "+pquery; + } } + return logMsg; } @@ -559,5 +934,18 @@ public class GridTabCSVImporter implements IGridTabImporter + "." + getFileExtension(); return localFile; } - + + class ValueComparator implements Comparator { + Map base; + public ValueComparator(Map base) { + this.base = base; + } + // Note: this comparator imposes orderings that are inconsistent with equals. + public int compare(GridTab a, GridTab b) { + if(base.get(a) >= base.get(b)) + return 1; + else + return -1; + } + } } diff --git a/org.adempiere.base/src/org/compiere/model/MLocation.java b/org.adempiere.base/src/org/compiere/model/MLocation.java index 576d58acbd..c44caac593 100644 --- a/org.adempiere.base/src/org/compiere/model/MLocation.java +++ b/org.adempiere.base/src/org/compiere/model/MLocation.java @@ -649,6 +649,21 @@ public class MLocation extends X_C_Location implements Comparator return false; } + //check city id + if (m_c != null && !m_c.isAllowCitiesOutOfList() && getC_City_ID() > 0) { + int city_id = DB.getSQLValue(get_TrxName(), + "SELECT C_City_ID "+ + " FROM C_City "+ + " WHERE C_Country_ID=? "+ + " AND COALESCE(C_Region_ID,0)=? " + + " AND C_City_ID =?", + new Object[] {getC_Country_ID(), getC_Region_ID(), getC_City_ID()}); + + if (city_id<0){ + log.saveError("CityNotFound",Msg.translate(getCtx(), "CityNotFound")+" C_City_ID["+getC_City_ID()+"]"); + return false; + } + } return true; } // beforeSave diff --git a/org.adempiere.base/src/org/compiere/util/Login.java b/org.adempiere.base/src/org/compiere/util/Login.java index 3be1f18c96..83fa5f6f51 100644 --- a/org.adempiere.base/src/org/compiere/util/Login.java +++ b/org.adempiere.base/src/org/compiere/util/Login.java @@ -1361,6 +1361,7 @@ public class Login .append(" INNER JOIN AD_Client cli on (ur.AD_Client_ID=cli.AD_Client_ID)") .append(" WHERE ur.IsActive='Y'") .append(" AND u.IsActive='Y'") + .append(" AND cli.IsActive='Y'") .append(" AND ur.AD_User_ID=?"); PreparedStatement pstmt=null; ResultSet rs=null; @@ -1561,6 +1562,7 @@ public class Login .append(" INNER JOIN AD_User u on (ur.AD_User_ID=u.AD_User_ID)") .append(" INNER JOIN AD_Client cli on (ur.AD_Client_ID=cli.AD_Client_ID)") .append(" WHERE ur.IsActive='Y'") + .append(" AND cli.IsActive='Y'") .append(" AND u.IsActive='Y'") .append(" AND u.AD_User_ID=?"); PreparedStatement pstmt = null; diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/RolePanel.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/RolePanel.java index 7cb07038cb..c046644e61 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/RolePanel.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/RolePanel.java @@ -321,7 +321,7 @@ public class RolePanel extends Window implements EventListener, Deferrabl { ComboItem ci = new ComboItem(m_clientKNPairs[i].getName(), m_clientKNPairs[i].getID()); String id = AdempiereIdGenerator.escapeId(ci.getLabel()); - if (ci.getFellowIfAny(id) == null) + if (lstClient.getFellowIfAny(id) == null) ci.setId(id); lstClient.appendChild(ci); if (m_clientKNPairs[i].getID().equals(initDefault)) @@ -369,9 +369,8 @@ public class RolePanel extends Window implements EventListener, Deferrabl { ComboItem ci = new ComboItem(roleKNPairs[i].getName(), roleKNPairs[i].getID()); String id = AdempiereIdGenerator.escapeId(ci.getLabel()); - if (lstRole.getFellowIfAny(id) == null) { + if (lstRole.getFellowIfAny(id) == null) ci.setId(id); - } lstRole.appendChild(ci); if (roleKNPairs[i].getID().equals(initDefault)) lstRole.setSelectedItem(ci); @@ -425,7 +424,7 @@ public class RolePanel extends Window implements EventListener, Deferrabl { ComboItem ci = new ComboItem(orgKNPairs[i].getName(), orgKNPairs[i].getID()); String id = AdempiereIdGenerator.escapeId(ci.getLabel()); - if (ci.getFellowIfAny(id) == null) + if (lstOrganisation.getFellowIfAny(id) == null) ci.setId(id); lstOrganisation.appendChild(ci); if(orgKNPairs[i].getID().equals(initDefault)) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/WRC2FieldOrderPanel.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/WRC2FieldOrderPanel.java index ba9ceef04f..0b8eb8d998 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/WRC2FieldOrderPanel.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/WRC2FieldOrderPanel.java @@ -282,8 +282,8 @@ public class WRC2FieldOrderPanel extends WRCTabPanel implements EventListener winExportFile = null; AMedia media = null; media = new AMedia(exporter.getSuggestedFileName(panel.getActiveGridTab()), null, exporter.getContentType(), file, true); - Filedownload.save(media, panel.getActiveGridTab().getName() + "." + ext); + Filedownload.save(media); } catch (Exception e) { throw new AdempiereException(e); } finally { diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/action/FileImportAction.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/action/FileImportAction.java index 1f20709592..e23dd48254 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/action/FileImportAction.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/action/FileImportAction.java @@ -313,7 +313,7 @@ public class FileImportAction implements EventListener AMedia media = null; media = new AMedia(importer.getSuggestedFileName(panel.getActiveGridTab()), null, importer.getContentType(), outFile, true); - Filedownload.save(media, panel.getActiveGridTab().getName() + "." + ext); + Filedownload.save(media); } catch (Exception e) { throw new AdempiereException(e); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WLocationDialog.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WLocationDialog.java index 5ecf41d7eb..0bc1684db1 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WLocationDialog.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WLocationDialog.java @@ -302,7 +302,7 @@ public class WLocationDialog extends Window implements EventListener if (MLocation.LOCATION_MAPS_URL_PREFIX == null) toLink.setVisible(false); pnlLinks.appendChild(toRoute); - if (MLocation.LOCATION_MAPS_ROUTE_PREFIX == null) + if (MLocation.LOCATION_MAPS_ROUTE_PREFIX == null || Env.getAD_Org_ID(Env.getCtx()) <= 0) toRoute.setVisible(false); pnlLinks.setWidth("100%"); pnlLinks.setStyle("text-align:left");