OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 156 Rev 182
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
9
 * language governing permissions and limitations under the License.
10
 * 
10
 * 
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.sql.users.rights;
14
 package org.openconcerto.sql.users.rights;
15
 
15
 
16
import static java.util.Arrays.asList;
16
import static java.util.Arrays.asList;
17
 
-
 
18
import org.openconcerto.sql.element.GlobalMapper;
17
import org.openconcerto.sql.element.GlobalMapper;
19
import org.openconcerto.sql.element.SQLComponent;
18
import org.openconcerto.sql.element.SQLComponent;
20
import org.openconcerto.sql.element.SQLElement;
19
import org.openconcerto.sql.element.SQLElement;
-
 
20
import org.openconcerto.sql.element.SQLElementDirectory;
21
import org.openconcerto.sql.model.DBRoot;
21
import org.openconcerto.sql.model.DBRoot;
22
import org.openconcerto.sql.model.SQLTable;
22
import org.openconcerto.sql.model.SQLTable;
23
import org.openconcerto.sql.utils.SQLCreateTable;
23
import org.openconcerto.sql.utils.SQLCreateTable;
-
 
24
import org.openconcerto.sql.view.list.action.ListEvent;
-
 
25
import org.openconcerto.sql.view.list.action.SQLRowValuesAction;
-
 
26
import org.openconcerto.sql.view.list.action.SQLRowValuesAction.PredicateRowAction;
24
 
27
 
-
 
28
import java.awt.Toolkit;
-
 
29
import java.awt.datatransfer.Clipboard;
25
import java.util.ArrayList;
30
import java.util.ArrayList;
26
import java.util.Collections;
31
import java.util.Collections;
27
import java.util.List;
32
import java.util.List;
28
import java.util.Set;
33
import java.util.Set;
29
 
34
 
30
public class UserRightSQLElement extends SQLElement {
35
public class UserRightSQLElement extends SQLElement {
31
    public static final String TABLE_NAME = "USER_RIGHT";
36
    public static final String TABLE_NAME = "USER_RIGHT";
32
 
37
 
33
    static public List<SQLCreateTable> getCreateTables(final SQLTable userT) {
38
    static public List<SQLCreateTable> getCreateTables(final SQLTable userT) {
34
        final DBRoot root = userT.getDBRoot();
39
        final DBRoot root = userT.getDBRoot();
35
        final SQLTable t = root.findTable(TABLE_NAME, false);
40
        final SQLTable t = root.findTable(TABLE_NAME, false);
36
        if (t != null) {
41
        if (t != null) {
37
            return Collections.emptyList();
42
            return Collections.emptyList();
38
        }
43
        }
39
 
44
 
40
        final List<SQLCreateTable> res = new ArrayList<SQLCreateTable>();
45
        final List<SQLCreateTable> res = new ArrayList<SQLCreateTable>();
41
        final SQLCreateTable create = new SQLCreateTable(root, TABLE_NAME);
46
        final SQLCreateTable create = new SQLCreateTable(root, TABLE_NAME);
42
        create.addForeignColumn(userT.getName());
47
        create.addForeignColumn(userT.getName());
43
        if (root.contains(RightSQLElement.TABLE_NAME)) {
48
        if (root.contains(RightSQLElement.TABLE_NAME)) {
44
            create.addForeignColumn(RightSQLElement.TABLE_NAME);
49
            create.addForeignColumn(RightSQLElement.TABLE_NAME);
45
        } else {
50
        } else {
46
            final SQLCreateTable createRight = RightSQLElement.getCreateTable(root);
51
            final SQLCreateTable createRight = RightSQLElement.getCreateTable(root);
47
            res.add(createRight);
52
            res.add(createRight);
48
            create.addForeignColumn(createRight);
53
            create.addForeignColumn(createRight);
49
        }
54
        }
50
        // NULL meaning any
55
        // NULL meaning any
51
        create.addColumn("OBJECT", "varchar(150) NULL DEFAULT NULL");
56
        create.addColumn("OBJECT", "varchar(150) NULL DEFAULT NULL");
52
        create.addColumn("HAVE_RIGHT", "boolean NOT NULL");
57
        create.addColumn("HAVE_RIGHT", "boolean NOT NULL");
53
        res.add(create);
58
        res.add(create);
54
 
59
 
55
        return res;
60
        return res;
56
    }
61
    }
57
 
62
 
-
 
63
    static private final SQLRowValuesAction COPY_ACTION = new PredicateRowAction(true, (le) -> {
-
 
64
        final Toolkit toolkit = Toolkit.getDefaultToolkit();
-
 
65
        final Clipboard systemClipboard = toolkit.getSystemClipboard();
-
 
66
        systemClipboard.setContents(new UserRightCopySelection(le.getSelectedRowAccessors()), null);
-
 
67
    }).setPredicate(ListEvent.getNonEmptySelectionPredicate()).setName("Copier");
-
 
68
 
58
    public UserRightSQLElement(final DBRoot r) {
69
    public UserRightSQLElement(final DBRoot r) {
59
        super(r.findTable(TABLE_NAME), null, "sql.user-right");
70
        super(r.findTable(TABLE_NAME), null, "sql.user-right");
-
 
71
 
60
        final UserRightGroup group = new UserRightGroup();
72
        final UserRightGroup group = new UserRightGroup();
61
        GlobalMapper.getInstance().map(UserRightSQLComponent.ID, group);
73
        GlobalMapper.getInstance().map(UserRightSQLComponent.ID, group);
62
        setDefaultGroup(group);
74
        setDefaultGroup(group);
-
 
75
        getRowValuesActions().add(COPY_ACTION);
63
    }
76
    }
64
 
77
 
65
    protected List<String> getListFields() {
78
    protected List<String> getListFields() {
66
        // don't display USER to avoid undefined
79
        // don't display USER to avoid undefined
67
        return asList("ID_RIGHT", "OBJECT", "HAVE_RIGHT");
80
        return asList("ID_RIGHT", "OBJECT", "HAVE_RIGHT");
68
    }
81
    }
69
 
82
 
70
    protected List<String> getComboFields() {
83
    protected List<String> getComboFields() {
71
        return getListFields();
84
        return getListFields();
72
    }
85
    }
73
 
86
 
74
    @Override
87
    @Override
75
    protected String getParentFFName() {
88
    protected String getParentFFName() {
76
        return "ID_USER_COMMON";
89
        return "ID_USER_COMMON";
77
    }
90
    }
78
 
91
 
79
    @Override
92
    @Override
80
    // r/o since we set it programmatically to prevent the edition of superuser rights
93
    // r/o since we set it programmatically to prevent the edition of superuser rights
81
    public Set<String> getReadOnlyFields() {
94
    public Set<String> getReadOnlyFields() {
82
        return Collections.singleton("ID_USER_COMMON");
95
        return Collections.singleton("ID_USER_COMMON");
83
    }
96
    }
84
 
97
 
85
    public SQLComponent createComponent() {
98
    public SQLComponent createComponent() {
86
        return new UserRightSQLComponent(this);
99
        return new UserRightSQLComponent(this);
87
    }
100
    }
88
}
101
}