001/*
002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Florent Guillaume
018 */
019
020package org.nuxeo.ecm.core.storage.sql;
021
022import java.io.Serializable;
023import java.util.Calendar;
024import java.util.Comparator;
025
026/**
027 * A simple value holding one row of the ACLs table.
028 *
029 * @author Florent Guillaume
030 */
031public class ACLRow implements Serializable {
032
033    private static final long serialVersionUID = 1L;
034
035    public final int pos;
036
037    public final String name;
038
039    public final boolean grant;
040
041    public final String permission;
042
043    public final String user;
044
045    public final String group;
046
047    /**
048     * @since 7.4
049     */
050    public final Calendar begin;
051
052    /**
053     * @since 7.4
054     */
055    public final Calendar end;
056
057    /**
058     * @since 7.4
059     */
060    public final String creator;
061
062    /**
063     * Status of the ACL row: null, 0, 1 or 2.
064     *
065     * @see org.nuxeo.ecm.core.api.security.ACE
066     * @since 7.4.
067     */
068    public final Long status;
069
070    /**
071     * @since 7.4
072     */
073    public ACLRow(int pos, String name, boolean grant, String permission, String user, String group, String creator,
074            Calendar begin, Calendar end, Long status) {
075        this.pos = pos;
076        this.name = name;
077        this.grant = grant;
078        this.permission = permission;
079        this.user = user;
080        this.group = group;
081        this.creator = creator;
082        this.begin = begin;
083        this.end = end;
084        this.status = status;
085    }
086
087    public ACLRow(int pos, String name, boolean grant, String permission, String user, String group) {
088        this(pos, name, grant, permission, user, group, null, null, null, null);
089    }
090
091    @Override
092    public String toString() {
093        return getClass().getSimpleName() + '(' + pos + ',' + name + ',' + (grant ? "GRANT" : "DENY") + ',' + permission
094                + ',' + user + ',' + group + ',' + begin + ',' + end + +',' + status + ')';
095    }
096
097    /**
098     * Comparator of {@link ACLRow}s according to their pos field.
099     */
100    public static class ACLRowPositionComparator implements Comparator<ACLRow> {
101
102        public static final ACLRowPositionComparator INSTANCE = new ACLRowPositionComparator();
103
104        @Override
105        public int compare(ACLRow acl1, ACLRow acl2) {
106            return acl1.pos - acl2.pos;
107        }
108    }
109
110}