OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 93 | Go to most recent revision | 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
 *
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
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;
156 ilm 17
 
93 ilm 18
import org.openconcerto.sql.element.GlobalMapper;
17 ilm 19
import org.openconcerto.sql.element.SQLComponent;
156 ilm 20
import org.openconcerto.sql.element.SQLElement;
73 ilm 21
import org.openconcerto.sql.model.DBRoot;
22
import org.openconcerto.sql.model.SQLTable;
23
import org.openconcerto.sql.utils.SQLCreateTable;
17 ilm 24
 
73 ilm 25
import java.util.ArrayList;
17 ilm 26
import java.util.Collections;
27
import java.util.List;
28
import java.util.Set;
29
 
156 ilm 30
public class UserRightSQLElement extends SQLElement {
73 ilm 31
    public static final String TABLE_NAME = "USER_RIGHT";
17 ilm 32
 
73 ilm 33
    static public List<SQLCreateTable> getCreateTables(final SQLTable userT) {
34
        final DBRoot root = userT.getDBRoot();
35
        final SQLTable t = root.findTable(TABLE_NAME, false);
36
        if (t != null) {
37
            return Collections.emptyList();
38
        }
39
 
40
        final List<SQLCreateTable> res = new ArrayList<SQLCreateTable>();
41
        final SQLCreateTable create = new SQLCreateTable(root, TABLE_NAME);
42
        create.addForeignColumn(userT.getName());
43
        if (root.contains(RightSQLElement.TABLE_NAME)) {
44
            create.addForeignColumn(RightSQLElement.TABLE_NAME);
45
        } else {
46
            final SQLCreateTable createRight = RightSQLElement.getCreateTable(root);
47
            res.add(createRight);
48
            create.addForeignColumn(createRight);
49
        }
50
        // NULL meaning any
51
        create.addColumn("OBJECT", "varchar(150) NULL DEFAULT NULL");
52
        create.addColumn("HAVE_RIGHT", "boolean NOT NULL");
53
        res.add(create);
54
 
55
        return res;
56
    }
57
 
156 ilm 58
    public UserRightSQLElement(final DBRoot r) {
59
        super(r.findTable(TABLE_NAME), null, "sql.user-right");
93 ilm 60
        final UserRightGroup group = new UserRightGroup();
61
        GlobalMapper.getInstance().map(UserRightSQLComponent.ID, group);
62
        setDefaultGroup(group);
17 ilm 63
    }
64
 
65
    protected List<String> getListFields() {
66
        // don't display USER to avoid undefined
67
        return asList("ID_RIGHT", "OBJECT", "HAVE_RIGHT");
68
    }
69
 
70
    protected List<String> getComboFields() {
71
        return getListFields();
72
    }
73
 
74
    @Override
75
    protected String getParentFFName() {
76
        return "ID_USER_COMMON";
77
    }
78
 
79
    @Override
80
    // r/o since we set it programmatically to prevent the edition of superuser rights
81
    public Set<String> getReadOnlyFields() {
82
        return Collections.singleton("ID_USER_COMMON");
83
    }
84
 
85
    public SQLComponent createComponent() {
93 ilm 86
        return new UserRightSQLComponent(this);
17 ilm 87
    }
88
}