OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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