OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
17 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
182 ilm 4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
17 ilm 5
 *
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
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.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 package org.openconcerto.sql.users.rights;
15
 
16
import static java.util.Arrays.asList;
93 ilm 17
import org.openconcerto.sql.element.GlobalMapper;
17 ilm 18
import org.openconcerto.sql.element.SQLComponent;
156 ilm 19
import org.openconcerto.sql.element.SQLElement;
182 ilm 20
import org.openconcerto.sql.element.SQLElementDirectory;
73 ilm 21
import org.openconcerto.sql.model.DBRoot;
22
import org.openconcerto.sql.model.SQLTable;
23
import org.openconcerto.sql.utils.SQLCreateTable;
182 ilm 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;
17 ilm 27
 
182 ilm 28
import java.awt.Toolkit;
29
import java.awt.datatransfer.Clipboard;
73 ilm 30
import java.util.ArrayList;
17 ilm 31
import java.util.Collections;
32
import java.util.List;
33
import java.util.Set;
34
 
156 ilm 35
public class UserRightSQLElement extends SQLElement {
73 ilm 36
    public static final String TABLE_NAME = "USER_RIGHT";
17 ilm 37
 
73 ilm 38
    static public List<SQLCreateTable> getCreateTables(final SQLTable userT) {
39
        final DBRoot root = userT.getDBRoot();
40
        final SQLTable t = root.findTable(TABLE_NAME, false);
41
        if (t != null) {
42
            return Collections.emptyList();
43
        }
44
 
45
        final List<SQLCreateTable> res = new ArrayList<SQLCreateTable>();
46
        final SQLCreateTable create = new SQLCreateTable(root, TABLE_NAME);
47
        create.addForeignColumn(userT.getName());
48
        if (root.contains(RightSQLElement.TABLE_NAME)) {
49
            create.addForeignColumn(RightSQLElement.TABLE_NAME);
50
        } else {
51
            final SQLCreateTable createRight = RightSQLElement.getCreateTable(root);
52
            res.add(createRight);
53
            create.addForeignColumn(createRight);
54
        }
55
        // NULL meaning any
56
        create.addColumn("OBJECT", "varchar(150) NULL DEFAULT NULL");
57
        create.addColumn("HAVE_RIGHT", "boolean NOT NULL");
58
        res.add(create);
59
 
60
        return res;
61
    }
62
 
182 ilm 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
 
156 ilm 69
    public UserRightSQLElement(final DBRoot r) {
70
        super(r.findTable(TABLE_NAME), null, "sql.user-right");
182 ilm 71
 
93 ilm 72
        final UserRightGroup group = new UserRightGroup();
73
        GlobalMapper.getInstance().map(UserRightSQLComponent.ID, group);
74
        setDefaultGroup(group);
182 ilm 75
        getRowValuesActions().add(COPY_ACTION);
17 ilm 76
    }
77
 
78
    protected List<String> getListFields() {
79
        // don't display USER to avoid undefined
80
        return asList("ID_RIGHT", "OBJECT", "HAVE_RIGHT");
81
    }
82
 
83
    protected List<String> getComboFields() {
84
        return getListFields();
85
    }
86
 
87
    @Override
88
    protected String getParentFFName() {
89
        return "ID_USER_COMMON";
90
    }
91
 
92
    @Override
93
    // r/o since we set it programmatically to prevent the edition of superuser rights
94
    public Set<String> getReadOnlyFields() {
95
        return Collections.singleton("ID_USER_COMMON");
96
    }
97
 
98
    public SQLComponent createComponent() {
93 ilm 99
        return new UserRightSQLComponent(this);
17 ilm 100
    }
101
}