
org.ow2.bonita.facade.privilege.impl.RuleImpl Maven / Gradle / Ivy
The newest version!
/**
* Copyright (C) 2010-2012 BonitaSoft S.A.
* BonitaSoft, 31 rue Gustave Eiffel - 38000 Grenoble
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation
* version 2.1 of the License.
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301, USA.
**/
package org.ow2.bonita.facade.privilege.impl;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import org.ow2.bonita.facade.def.majorElement.impl.DescriptionElementImpl;
import org.ow2.bonita.facade.privilege.Rule;
import org.ow2.bonita.facade.uuid.AbstractUUID;
import org.ow2.bonita.util.CopyTool;
import org.ow2.bonita.util.Misc;
/**
* @author Nicolas Chabanoles
*
*/
public class RuleImpl extends DescriptionElementImpl implements Rule {
private static final long serialVersionUID = -5403223858809095337L;
protected long dbid;
protected String uuid;
protected String name;
protected String label;
protected Set exceptions;
protected String type;
protected Set entities;
protected Set users;
protected Set roles;
protected Set groups;
protected Set memberships;
protected RuleImpl() {
super();
}
protected RuleImpl(final RuleType type) {
super();
Misc.checkArgsNotNull(type);
uuid = UUID.randomUUID().toString();
this.type = type.name();
}
protected RuleImpl(final String name, final String label, final String description, final RuleType type,
final Set extends AbstractUUID> items) {
super();
Misc.checkArgsNotNull(name, type);
uuid = UUID.randomUUID().toString();
this.name = name;
this.label = label;
if (items != null) {
exceptions = new HashSet();
for (final AbstractUUID abstractUUID : items) {
exceptions.add(abstractUUID.getValue());
}
} else {
exceptions = null;
}
this.type = type.name();
setDescription(description);
}
protected RuleImpl(final Rule src) {
super(src);
dbid = src.getId();
uuid = src.getUUID();
name = src.getName();
label = src.getLabel();
exceptions = new HashSet();
final Set items_ = src.getItems();
for (final String item : items_) {
exceptions.add(item);
}
type = src.getType().name();
entities = CopyTool.copy(src.getEntities());
users = CopyTool.copy(src.getUsers());
roles = CopyTool.copy(src.getRoles());
groups = CopyTool.copy(src.getGroups());
memberships = CopyTool.copy(src.getMemberships());
}
@Override
@Deprecated
public long getId() {
return dbid;
}
@Override
public String getUUID() {
return uuid;
}
@Override
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
@Override
public String getLabel() {
return label;
}
public void setLabel(final String label) {
this.label = label;
}
@Override
public Set getItems() {
if (exceptions == null) {
exceptions = new HashSet();
}
return exceptions;
}
public void setItems(final Set items) {
Misc.checkArgsNotNull(items);
exceptions = items;
}
@Override
public RuleType getType() {
return RuleType.valueOf(type);
}
/**
* @param exceptions
* must be not null
*/
protected void addExceptions(final Collection exceptions) {
Misc.checkArgsNotNull(exceptions);
if (this.exceptions == null) {
this.exceptions = new HashSet();
}
for (final AbstractUUID exception : exceptions) {
this.exceptions.add(exception.getValue());
}
}
/**
* @param exceptions
* must be not null
*/
protected void removeExceptions(final Collection exceptions) {
Misc.checkArgsNotNull(exceptions);
if (this.exceptions != null && !this.exceptions.isEmpty()) {
for (final AbstractUUID exception : exceptions) {
this.exceptions.remove(exception.getValue());
}
}
}
protected void setExceptions(final Set exceptions) {
Misc.checkArgsNotNull(exceptions);
final Set exceptionValues = new HashSet();
for (final AbstractUUID exception : exceptions) {
exceptionValues.add(exception.getValue());
}
this.exceptions = exceptionValues;
}
@Override
public Set getEntities() {
if (entities == null) {
entities = new HashSet();
}
return entities;
}
/**
* @param entities
* must be not null
*/
public void addEntities(final Collection entities) {
Misc.checkArgsNotNull(entities);
if (this.entities == null) {
this.entities = new HashSet();
}
this.entities.addAll(entities);
}
/**
* @param entities
* must be not null
*/
public void removeEntities(final Collection entities) {
Misc.checkArgsNotNull(entities);
if (this.entities != null && !this.entities.isEmpty()) {
this.entities.removeAll(entities);
}
}
@Override
public Set getGroups() {
if (groups == null) {
groups = new HashSet();
}
return groups;
}
/**
* @param groups
* must be not null
*/
public void addGroups(final Collection groups) {
Misc.checkArgsNotNull(groups);
if (this.groups == null) {
this.groups = new HashSet();
}
this.groups.addAll(groups);
}
/**
* @param groups
* must be not null
*/
public void removeGroups(final Collection groups) {
Misc.checkArgsNotNull(groups);
if (this.groups != null && !this.groups.isEmpty()) {
this.groups.removeAll(groups);
}
}
@Override
public Set getMemberships() {
if (memberships == null) {
memberships = new HashSet();
}
return memberships;
}
/**
* @param memberships
* must be not null
*/
public void addMemberships(final Collection memberships) {
Misc.checkArgsNotNull(memberships);
if (this.memberships == null) {
this.memberships = new HashSet();
}
this.memberships.addAll(memberships);
}
/**
* @param memberships
* must be not null
*/
public void removeMemberships(final Collection memberships) {
Misc.checkArgsNotNull(memberships);
if (this.memberships != null && !this.memberships.isEmpty()) {
this.memberships.removeAll(memberships);
}
}
@Override
public Set getRoles() {
if (roles == null) {
roles = new HashSet();
}
return roles;
}
/**
* @param roles
* must be not null
*/
public void addRoles(final Collection roles) {
Misc.checkArgsNotNull(roles);
if (this.roles == null) {
this.roles = new HashSet();
}
this.roles.addAll(roles);
}
/**
* @param roles
* must be not null
*/
public void removeRoles(final Collection roles) {
Misc.checkArgsNotNull(roles);
if (this.roles != null && !this.roles.isEmpty()) {
this.roles.removeAll(roles);
}
}
@Override
public Set getUsers() {
if (users == null) {
users = new HashSet();
}
return users;
}
/**
* @param users
* must be not null
*/
public void addUsers(final Collection users) {
Misc.checkArgsNotNull(users);
if (this.users == null) {
this.users = new HashSet();
}
this.users.addAll(users);
}
/**
* @param users
* must be not null
*/
public void removeUsers(final Collection users) {
Misc.checkArgsNotNull(users);
if (this.users != null && !this.users.isEmpty()) {
this.users.removeAll(users);
}
}
@Override
public String toString() {
return name + " - " + label + " - " + type;
}
public static Rule createRule(final Rule source) {
return new RuleImpl(source);
}
@Override
public int compareTo(final Rule rule) {
return getName().compareTo(rule.getName());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy